:root {
    --bg-color: #000;
    --text-color: #fff;
    --ui-bg: rgba(10, 10, 10, 0.7);
    --ui-border: rgba(255, 255, 255, 0.15);
    --canvas-bg-inner: #050510;
    --canvas-bg-outer: #000;
    --btn-bg: rgba(255, 255, 255, 0.1);
    --btn-border: rgba(255, 255, 255, 0.2);
    --btn-hover: rgba(255, 255, 255, 0.2);
    --btn-hover-border: rgba(255, 255, 255, 0.4);
    --title-overlay: rgba(0, 0, 0, 0.85);
    --text-shadow-color: rgba(255, 255, 255, 0.2);
    --neon-blue: rgba(0, 150, 255, 0.4);
    --neon-glow: rgba(0, 150, 255, 0.8);
    --press-enter-color: #FF0;
    --press-enter-glow: rgba(255, 255, 0, 0.8);
}

body.light-mode {
    --bg-color: #f0f4f8;
    --text-color: #333;
    --ui-bg: rgba(255, 255, 255, 0.7);
    --ui-border: rgba(0, 0, 0, 0.15);
    --canvas-bg-inner: #ffffff;
    --canvas-bg-outer: #e2e8f0;
    --btn-bg: rgba(0, 0, 0, 0.05);
    --btn-border: rgba(0, 0, 0, 0.1);
    --btn-hover: rgba(0, 0, 0, 0.1);
    --btn-hover-border: rgba(0, 0, 0, 0.2);
    --title-overlay: rgba(255, 255, 255, 0.85);
    --text-shadow-color: rgba(0, 0, 0, 0.1);
    --press-enter-color: #0077ff;
    --press-enter-glow: rgba(0, 119, 255, 0.8);
}

*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100dvh; /* dvh respects mobile address bars */
    transition: background-color 0.3s, color 0.3s;
}

.game-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
}

/* ─── TOP UI BAR ─────────────────────────────────────────────── */
#ui {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(4px, 1vh, 15px) clamp(8px, 2vw, 30px);
    background-color: var(--ui-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--ui-border);
    font-size: clamp(10px, 1.8vw, 22px);
    font-weight: 600;
    flex-shrink: 0;
    letter-spacing: 1px;
    text-shadow: 0 0 10px var(--text-shadow-color);
    transition: background-color 0.5s, border-color 0.5s;
    z-index: 100;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

#stats {
    display: flex;
    gap: clamp(4px, 1vw, 20px);
    flex-wrap: nowrap;
    align-items: center;
}

#lang-toggle {
    display: flex;
    align-items: center;
    gap: clamp(2px, 0.5vw, 10px);
    flex-wrap: nowrap;
}

/* ─── GAME AREA ──────────────────────────────────────────────── */
.game-container {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 1vh 1vw;
    background: radial-gradient(circle at center, var(--canvas-bg-inner) 0%, var(--canvas-bg-outer) 100%);
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

/* Retro CRT Scanline Overlay */
.game-container::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%);
    background-size: 100% 4px;
    z-index: 5;
    pointer-events: none;
    opacity: 0.6;
}

body.light-mode .game-container::after {
    opacity: 0.2;
}

/* ─── CANVAS ─────────────────────────────────────────────────── */
canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 40px rgba(0, 100, 255, 0.15);
    touch-action: none;
}

/* ─── TITLE & HIGHSCORE OVERLAYS ─────────────────────────────── */
#title-screen, #highscore-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--title-overlay);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 10;
    overflow-y: auto;
    padding: clamp(10px, 3vh, 30px) clamp(10px, 3vw, 30px);
    transition: background-color 0.3s;
}

#title-logo {
    font-size: clamp(28px, 7vw, 100px);
    margin: 0 0 clamp(6px, 1.5vh, 20px) 0;
    font-family: 'Courier New', monospace;
    letter-spacing: clamp(2px, 1vw, 10px);
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

#highscore-logo {
    font-size: clamp(24px, 5vw, 80px);
    margin: 0 0 clamp(6px, 1.5vh, 20px) 0;
    font-family: 'Courier New', monospace;
    letter-spacing: clamp(2px, 0.8vw, 5px);
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

/* ─── HELP TEXT ──────────────────────────────────────────────── */
.quickstart-box {
    font-size: clamp(11px, 2vw, 26px);
    color: var(--text-color);
    line-height: 1.5;
    margin-bottom: clamp(8px, 2vh, 40px);
    text-align: left;
    display: inline-block;
    font-weight: 500;
    max-width: 90vw;
}

/* ─── PRESS TO START ─────────────────────────────────────────── */
#press-enter {
    font-size: clamp(16px, 4vw, 40px);
    color: var(--press-enter-color);
    animation: glow-pulse 2s infinite ease-in-out;
    font-weight: 700;
    letter-spacing: clamp(1px, 0.5vw, 2px);
    transition: color 0.3s;
    cursor: pointer;
}

/* ─── DIFFICULTY BUTTONS ─────────────────────────────────────── */
#difficulty-selector, #hs-tabs {
    display: flex;
    gap: clamp(8px, 2vw, 20px);
    justify-content: center;
    flex-wrap: wrap;
}

.diff-btn, .hs-tab-btn {
    cursor: pointer;
    font-size: clamp(12px, 2.5vw, 24px);
    font-weight: bold;
    color: rgba(255, 255, 255, 0.5);
    transition: all 0.2s ease;
    padding: clamp(4px, 1vh, 8px) 0;
    min-width: 44px; /* minimum tap target */
    text-align: center;
}

.light-mode .diff-btn, .light-mode .hs-tab-btn {
    color: rgba(0, 0, 0, 0.5);
}

.diff-btn:hover, .hs-tab-btn:hover {
    color: var(--text-color);
}

.diff-btn.active, .hs-tab-btn.active {
    color: var(--text-color);
    text-shadow: 0 0 10px var(--neon-glow);
}

/* ─── HIGHSCORE LIST ─────────────────────────────────────────── */
#hs-ol {
    min-width: clamp(200px, 60vw, 350px);
    padding-left: 0;
    list-style-position: inside;
}

#hs-ol li {
    display: flex;
    justify-content: space-between;
    margin-bottom: clamp(4px, 1vh, 12px);
    border-bottom: 1px solid var(--btn-border);
    padding-bottom: clamp(4px, 0.8vh, 8px);
    font-size: clamp(12px, 2.5vw, 28px);
    animation: slideIn 0.3s ease-out var(--delay, 0s) forwards;
    opacity: 0;
}

/* ─── TOP BAR BUTTONS ────────────────────────────────────────── */
.lang-btn {
    text-decoration: none;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.3s ease;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 8px;
    padding: clamp(4px, 0.8vh, 8px) clamp(6px, 1vw, 16px);
    font-size: clamp(12px, 2vw, 18px);
    backdrop-filter: blur(5px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    text-shadow: none;
    min-width: 36px;
    min-height: 36px;
}

.lang-btn:hover {
    background: var(--btn-hover);
    border-color: var(--btn-hover-border);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.lang-btn.active {
    background: rgba(0, 150, 255, 0.2);
    border-color: rgba(0, 150, 255, 0.6);
    box-shadow: 0 0 15px var(--neon-blue);
    opacity: 1;
}

/* ─── ANIMATIONS ─────────────────────────────────────────────── */
@keyframes glow-pulse {
    0%   { text-shadow: 0 0 5px var(--press-enter-glow), 0 0 10px var(--press-enter-glow); opacity: 0.8; }
    50%  { text-shadow: 0 0 20px var(--press-enter-glow), 0 0 30px var(--press-enter-glow), 0 0 40px var(--press-enter-glow); opacity: 1; transform: scale(1.02); }
    100% { text-shadow: 0 0 5px var(--press-enter-glow), 0 0 10px var(--press-enter-glow); opacity: 0.8; }
}

@keyframes shake {
    0%   { transform: translate(2px, 2px) rotate(0deg); }
    10%  { transform: translate(-2px, -3px) rotate(-1deg); }
    20%  { transform: translate(-4px, 0px) rotate(1deg); }
    30%  { transform: translate(4px, 3px) rotate(0deg); }
    40%  { transform: translate(2px, -2px) rotate(1deg); }
    50%  { transform: translate(-2px, 3px) rotate(-1deg); }
    60%  { transform: translate(-4px, 2px) rotate(0deg); }
    70%  { transform: translate(4px, 2px) rotate(-1deg); }
    80%  { transform: translate(-2px, -2px) rotate(1deg); }
    90%  { transform: translate(2px, 3px) rotate(0deg); }
    100% { transform: translate(0px, 0px) rotate(0deg); }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to   { opacity: 1; transform: translateX(0); }
}

.shake { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; }

/* ─── UTILS ──────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.mr-20   { margin-right: clamp(8px, 1.5vw, 20px); }
.mt-20   { margin-top: clamp(10px, 2vh, 20px); }
.mb-10   { margin-bottom: clamp(6px, 1.5vh, 10px); }

/* ─── PORTRAIT PHONE SPECIFIC ────────────────────────────────── */
@media (max-width: 600px) and (orientation: portrait) {
    #ui {
        flex-wrap: wrap;
        gap: 4px;
    }

    #stats {
        font-size: 10px;
        gap: 6px;
        width: 100%;
        justify-content: space-between;
    }

    #lang-toggle {
        width: 100%;
        justify-content: flex-end;
    }

    .lang-btn {
    text-decoration: none;
        font-size: 14px;
        padding: 5px 8px;
        min-width: 34px;
        min-height: 34px;
    }

    #title-logo {
        font-size: clamp(22px, 10vw, 48px);
        letter-spacing: 3px;
    }

    .quickstart-box {
        font-size: clamp(12px, 3.5vw, 18px);
        line-height: 1.4;
    }

    #press-enter {
        font-size: clamp(18px, 5vw, 28px);
    }

    .diff-btn, .hs-tab-btn {
        font-size: clamp(13px, 4vw, 18px);
    }

    #hs-ol li {
        font-size: clamp(13px, 3.5vw, 18px);
    }

    .game-container {
        padding: 0;
    }

    canvas {
        border-radius: 0;
    }
}

/* ─── LANDSCAPE PHONE SPECIFIC ───────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    #ui {
        padding: 4px 12px;
    }

    #stats {
        font-size: 11px;
        gap: 8px;
    }

    .lang-btn {
    text-decoration: none;
        font-size: 13px;
        padding: 3px 8px;
        min-height: 30px;
    }

    .game-container {
        padding: 0;
    }

    canvas {
        border-radius: 0;
    }

    #title-screen {
        overflow-y: scroll;
        justify-content: flex-start;
        padding-top: 10px;
    }

    #title-logo {
        font-size: clamp(20px, 4vh, 40px);
        margin-bottom: 6px;
    }

    .quickstart-box {
        font-size: clamp(11px, 1.8vh, 16px);
        margin-bottom: 8px;
        line-height: 1.3;
    }

    #press-enter {
        font-size: clamp(14px, 3vh, 24px);
    }
}

#title-logo.game-over { color: #FF3333; text-shadow: 0 0 30px rgba(255, 0, 0, 0.8); }


