
        /* ----- Settings bar ----- */
        .settings-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin-bottom: 0.6rem; max-width: 520px; }
        .setting-group { display: flex; align-items: center; gap: 0.3rem; background: rgba(255,255,255,0.06); border: 1px solid rgba(252,211,77,0.3); border-radius: 30px; padding: 0.25rem 0.4rem; }
        .setting-label { font-family: 'Orbitron', monospace; font-size: 0.5rem; text-transform: uppercase; letter-spacing: 0.08em; color: #c2d4ee; padding-left: 0.4rem; }
        .setting-btn { padding: 0.3rem 0.7rem; border: none; border-radius: 20px; font-family: inherit; font-size: 0.7rem; font-weight: 600; cursor: pointer; background: transparent; color: #f4f8ff; transition: all 0.18s; }
        .setting-btn.active { background: linear-gradient(135deg, #fcd34d, #f59e0b); color: #1a1207; box-shadow: 0 2px 10px rgba(245,158,11,0.45); }
        .setting-btn:hover:not(.active):not(:disabled) { background: rgba(252,211,77,0.12); }
        .setting-btn:disabled { opacity: 0.4; cursor: not-allowed; }

        /* ----- Canvas container + overlays ----- */
        .game-container {
            position: relative;
            width: 100%;
            max-width: min(820px, 96vw);
            margin: 0 auto;
            border-radius: 18px;
            overflow: hidden;
            box-shadow: 0 20px 60px rgba(0,0,0,0.55), 0 0 0 3px rgba(252,211,77,0.12) inset;
            transition: transform 0.08s;
        }
        .game-container.shake { animation: shake 0.5s; }
        @keyframes shake {
            0%, 100% { transform: translate(0, 0); }
            10% { transform: translate(-6px, -3px) rotate(-0.4deg); }
            20% { transform: translate(7px, 2px) rotate(0.4deg); }
            30% { transform: translate(-5px, 3px); }
            40% { transform: translate(6px, -3px); }
            50% { transform: translate(-4px, 2px); }
            60% { transform: translate(4px, -2px); }
            70% { transform: translate(-3px, 1px); }
            80% { transform: translate(3px, -1px); }
            90% { transform: translate(-2px, 0); }
        }
        #canvas3d {
            display: block;
            border-radius: 18px;
            touch-action: none;
            cursor: pointer;
            background: radial-gradient(ellipse at 50% 20%, #1e3a6e 0%, #0c1d36 70%, #050d1a 100%);
        }

        /* HUD bar */
        .game-hud { position: absolute; inset: 0; pointer-events: none; }
        .hud-top {
            position: absolute; top: 10px; left: 10px; right: 10px;
            display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
        }
        .hud-score-box {
            pointer-events: none;
            background: rgba(13, 10, 20, 0.7);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            border: 1px solid rgba(252,211,77,0.25);
            color: #fff;
            border-radius: 16px;
            padding: 8px 14px;
            font-family: 'Orbitron', monospace;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        .hud-chip {
            display: inline-block; width: 14px; height: 14px; border-radius: 50%;
            box-shadow: inset 0 -2px 3px rgba(0,0,0,0.4), inset 0 2px 3px rgba(255,255,255,0.25);
        }
        .hud-chip.red { background: radial-gradient(circle at 30% 30%, #fca5a5, #ef4444 35%, #b91c1c 75%); }
        .hud-chip.yellow { background: radial-gradient(circle at 30% 30%, #fef3c7, #fcd34d 35%, #d97706 75%); }
        .hud-turn-label {
            font-size: 0.7rem;
            letter-spacing: 0.12em;
            text-transform: uppercase;
            color: #fcd34d;
            text-shadow: 0 0 8px rgba(252,211,77,0.5);
        }
        .hud-streak {
            margin-left: 10px;
            padding-left: 10px;
            border-left: 1px solid rgba(255,255,255,0.18);
            font-size: 0.62rem;
            letter-spacing: 0.14em;
            color: rgba(255,255,255,0.7);
            text-transform: uppercase;
        }
        .hud-streak strong { color: #fcd34d; font-size: 0.78rem; }

        .hud-pause-btn {
            pointer-events: auto;
            width: 42px; height: 42px;
            border-radius: 12px;
            background: rgba(13, 10, 20, 0.7);
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            border: 1px solid rgba(252,211,77,0.25);
            color: #fcd34d;
            font-size: 1.1rem;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: transform 0.15s, background 0.15s;
        }
        .hud-pause-btn:hover { background: rgba(13, 10, 20, 0.9); transform: scale(1.06); }
        .hud-pause-btn[hidden] { display: none; }
        .pause-icon::before { content: '⏸'; }
        .play-icon::before { content: '▶'; }

        /* Overlays */
        .overlay {
            position: fixed;
            inset: 0;
            z-index: 10000;
            display: none;
            align-items: center;
            justify-content: center;
            background: linear-gradient(180deg, rgba(5, 13, 26, 0.4), rgba(5, 13, 26, 0.85));
            text-align: center;
            color: #fff;
            font-family: 'Orbitron', monospace;
            padding: 24px;
            backdrop-filter: blur(3px);
            -webkit-backdrop-filter: blur(3px);
            z-index: 4;
        }
        .overlay.active { display: flex; }
        .overlay-box {
            background: rgba(12, 29, 54, 0.85);
            border: 1px solid rgba(252,211,77,0.35);
            border-radius: 22px;
            padding: 28px 28px 24px;
            min-width: 260px;
            max-width: 380px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.6);
        }
        .overlay-title {
            font-size: 1.5rem;
            font-weight: 900;
            letter-spacing: 0.04em;
            margin: 0 0 8px;
            color: #fcd34d;
            text-shadow: 0 2px 14px rgba(252,211,77,0.4);
        }
        .overlay-sub {
            margin: 0 0 16px;
            color: rgba(255,255,255,0.78);
            font-family: -apple-system, sans-serif;
            font-size: 0.92rem;
            line-height: 1.5;
        }
        .overlay-btn-row {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            justify-content: center;
        }
        .overlay-btn {
            padding: 11px 20px;
            border-radius: 99px;
            border: 0;
            cursor: pointer;
            font-family: 'Orbitron', monospace;
            font-size: 0.78rem;
            font-weight: 800;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            transition: transform 0.15s, box-shadow 0.15s;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
        }
        .overlay-btn-primary {
            background: linear-gradient(135deg, #fcd34d, #f59e0b);
            color: #1a1207;
        }
        .overlay-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(245,158,11,0.4); }
        .overlay-btn-ghost {
            background: rgba(255,255,255,0.08);
            border: 1px solid rgba(255,255,255,0.22);
            color: #fff;
        }
        .overlay-btn-ghost:hover { background: rgba(255,255,255,0.15); }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 8px;
            margin: 12px 0 18px;
        }
        .stat-cell {
            padding: 10px 6px;
            background: rgba(255,255,255,0.05);
            border: 1px solid rgba(252,211,77,0.18);
            border-radius: 10px;
        }
        .stat-cell-label {
            font-size: 0.55rem;
            letter-spacing: 0.14em;
            color: rgba(255,255,255,0.55);
            margin-bottom: 4px;
        }
        .stat-cell-value {
            font-size: 1.1rem;
            font-weight: 800;
            color: #fcd34d;
        }

        /* Idle / start screen */
        .start-cta {
            background: linear-gradient(135deg, #fcd34d, #f59e0b);
            color: #1a1207;
            padding: 16px 38px;
            border-radius: 99px;
            font-family: 'Orbitron', monospace;
            font-weight: 800;
            font-size: 1.05rem;
            letter-spacing: 0.16em;
            text-transform: uppercase;
            border: none;
            box-shadow: 0 14px 36px rgba(245,158,11,0.5);
            animation: startPulse 1.6s ease-in-out infinite;
            cursor: pointer;
        }
        @keyframes startPulse {
            0%, 100% { transform: scale(1); box-shadow: 0 14px 36px rgba(245,158,11,0.5); }
            50% { transform: scale(1.06); box-shadow: 0 18px 44px rgba(245,158,11,0.7); }
        }
        .start-sub {
            display: block;
            margin-top: 14px;
            font-size: 0.84rem;
            color: rgba(255,255,255,0.85);
            font-weight: 500;
            letter-spacing: 0.06em;
            font-family: -apple-system, sans-serif;
            text-shadow: 0 2px 8px rgba(0,0,0,0.5);
        }

        /* Help + history panels */
        .help-toggle, .history-toggle {
            display: block; margin: 0.7rem auto 0; padding: 0.4rem 1.1rem;
            background: rgba(255,255,255,0.04); border: 1px solid rgba(252,211,77,0.25);
            color: #f4f8ff; border-radius: 20px; font-family: 'Orbitron', monospace; font-size: 0.66rem;
            cursor: pointer; letter-spacing: 0.12em; text-transform: uppercase;
        }
        .help-toggle:hover, .history-toggle:hover { background: rgba(252,211,77,0.1); }
        .help-panel, .history-panel {
            display: none; max-width: 480px; margin: 0.8rem auto 0; padding: 1rem 1.2rem;
            background: rgba(255,255,255,0.04); border: 1px solid rgba(252,211,77,0.25); border-radius: 14px;
            color: #f4f8ff; font-family: -apple-system, sans-serif; font-size: 0.86rem; line-height: 1.55;
        }
        .help-panel.active, .history-panel.active { display: block; }
        .help-panel h3 { margin: 8px 0 6px; font-family: 'Orbitron', monospace; font-size: 0.8rem; color: #fcd34d; letter-spacing: 0.08em; text-transform: uppercase; }
        .help-panel h3:first-child { margin-top: 0; }
        .help-panel ul { margin: 0 0 10px; padding-left: 20px; }
        .help-panel li { margin: 3px 0; }
        .history-title { font-family: 'Orbitron', monospace; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em; color: #fcd34d; text-align: center; margin-bottom: 8px; }
        .history-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; background: rgba(255,255,255,0.04); border: 1px solid rgba(252,211,77,0.15); border-radius: 8px; font-size: 0.78rem; margin-bottom: 4px; }
        .history-result { font-family: 'Orbitron', monospace; font-weight: 700; }
        .history-result.win { color: #4ade80; }
        .history-result.lose { color: #f87171; }
        .history-result.draw { color: #fcd34d; }
        .history-meta { color: rgba(255,255,255,0.55); font-size: 0.72rem; }
        .history-empty { text-align: center; color: rgba(255,255,255,0.4); font-size: 0.84rem; padding: 12px; }

        /* Score chip pop */
        .score-pop {
            position: absolute;
            font-family: 'Orbitron', monospace;
            font-weight: 900;
            font-size: 1.4rem;
            color: #fcd34d;
            text-shadow: 0 2px 12px rgba(0,0,0,0.6);
            pointer-events: none;
            animation: scorePop 1.1s ease-out forwards;
            z-index: 5;
        }
        @keyframes scorePop {
            0% { opacity: 0; transform: scale(0.6) translateY(0); }
            20% { opacity: 1; transform: scale(1.4) translateY(-10px); }
            100% { opacity: 0; transform: scale(0.9) translateY(-50px); }
        }

        /* ----- Connect 4 theme ----- */
        body.game-page {
            --t-bg: #0c1d36;
            --t-bg-grad: radial-gradient(ellipse at 50% -20%, #1e3a6e 0%, #0c1d36 70%);
            --t-text: #f4f8ff;
            --t-text-muted: #c2d4ee;
            --t-text-subtle: #93acce;
            --t-primary: #fcd34d;
            --t-primary-mid: #f59e0b;
            --t-primary-dark: #dc2626;
            --t-glass-bg: rgba(255,255,255,0.06);
            --t-glass-border: rgba(252,211,77,0.4);
            --t-card-bg: rgba(255,255,255,0.05);
            --t-card-border: rgba(252,211,77,0.3);
            --t-btn-grad: linear-gradient(135deg, #fcd34d, #f59e0b);
        }
        body.game-page .game-name,
        body.game-page .score-value { color: #fcd34d !important; -webkit-text-fill-color: #fcd34d !important; background: none !important; }

        /* ============================================================
           Desktop layout: board fills the viewport HEIGHT; the leftover
           horizontal space is consumed by a side rail (setup / stats /
           recent games / how-to). Overlays are CONFINED to the board
           (position:absolute) so the rail stays clickable — previously
           the full-screen start & game-over overlays buried the
           mode/difficulty selectors above the board, so you could never
           start a new game at a different difficulty.
           ============================================================ */
        .game-layout {
            display: flex; gap: 22px; align-items: flex-start;
            justify-content: center; width: 100%;
            max-width: 1400px; margin: 0 auto; padding: 0 18px;
        }
        .game-main {
            position: relative; display: flex; flex-direction: column;
            align-items: center; min-width: 0; max-width: 100%;
        }
        /* Board hugs the canvas (no empty strip beside it). */
        .game-container {
            width: fit-content; max-width: 100%; margin: 0;
        }

        .game-rail {
            width: 340px; flex-shrink: 0;
            display: flex; flex-direction: column; gap: 14px;
        }
        .rail-card {
            background: rgba(255,255,255,0.05);
            border: 1px solid rgba(252,211,77,0.22);
            border-radius: 16px; padding: 14px 16px;
            backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
        }
        .rail-card-title {
            font-family: 'Orbitron', monospace; font-size: 0.6rem;
            text-transform: uppercase; letter-spacing: 0.14em;
            color: #fcd34d; margin-bottom: 10px;
        }
        /* Settings stack full-width in the rail */
        .game-rail .settings-bar {
            flex-direction: column; align-items: stretch;
            gap: 10px; margin: 0; max-width: none;
        }
        .game-rail .setting-group { justify-content: space-between; flex-wrap: wrap; }
        /* Recent games + help live in the rail */
        .game-rail .history-toggle, .game-rail .help-toggle {
            display: block; width: 100%; margin: 0; text-align: left;
        }
        .game-rail .history-panel, .game-rail .help-panel {
            max-width: none; margin: 10px 0 0; background: none;
            border: none; padding: 0;
        }

        /* Live HUD streak readout, mirrored into the rail */
        .rail-stat-row { display: flex; gap: 8px; }
        .rail-stat-cell {
            flex: 1; min-width: 0; text-align: center;
            padding: 8px 6px; background: rgba(255,255,255,0.04);
            border: 1px solid rgba(252,211,77,0.18); border-radius: 10px;
        }
        .rail-stat-label {
            font-size: 0.52rem; letter-spacing: 0.14em;
            color: rgba(255,255,255,0.55); margin-bottom: 4px;
            text-transform: uppercase; font-family: 'Orbitron', monospace;
        }
        .rail-stat-value { font-size: 1.05rem; font-weight: 800; color: #fcd34d; font-family: 'Orbitron', monospace; }

        /* Overlays: confine to the board (was full-screen `fixed`). The
           container is position:relative + overflow:hidden, so the overlay
           clips to the rounded board and scrolls internally if needed. */
        .overlay {
            position: absolute;
            inset: 0;
            z-index: 20;
            overflow-y: auto;
            border-radius: 18px;
        }
        .overlay .overlay-box { margin: auto; }

        /* In-overlay mode/difficulty re-pick — MOBILE only (desktop uses the
           always-visible rail). Lets the start + end screens launch a new run
           at a different difficulty without hunting for a panel. */
        .overlay-settings { display: none; }

        @media (max-width: 899px) {
            .game-layout { flex-direction: column; align-items: center; gap: 14px; padding: 0 12px; }
            .game-rail { width: 100%; max-width: 480px; }
            .game-rail .settings-bar { flex-direction: row; flex-wrap: wrap; justify-content: center; }
            .game-rail .setting-group { justify-content: center; }
            /* Mobile: overlays go full-screen (no rail beside the board to
               preserve), so the start / end screens get the whole viewport. */
            .overlay { position: fixed; border-radius: 0; }
            .overlay-settings {
                display: flex; flex-wrap: wrap; gap: 8px;
                justify-content: center; margin: 4px auto 14px; max-width: 520px;
            }
        }
