
        /* ----- 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(120,210,170,0.35); 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: #c8e7d8; 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: #f4fbf7; transition: all 0.18s; }
        .setting-btn.active { background: linear-gradient(135deg, #4ade80, #10b981); color: #07241a; box-shadow: 0 2px 10px rgba(16,185,129,0.5); }
        .setting-btn:hover:not(.active):not(:disabled) { background: rgba(74,222,128,0.14); }
        .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(74,222,128,0.16) 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% 18%, #0c3b2a 0%, #051d14 70%, #020a07 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(6, 22, 16, 0.78);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            border: 1px solid rgba(74,222,128,0.3);
            color: #fff;
            border-radius: 16px;
            padding: 8px 12px;
            font-family: 'Orbitron', monospace;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        .hud-side {
            display: flex; align-items: center; gap: 6px;
            padding: 2px 6px; border-radius: 10px;
            transition: background 0.2s, box-shadow 0.2s;
        }
        .hud-side.active-turn {
            background: rgba(74,222,128,0.16);
            box-shadow: 0 0 10px rgba(74,222,128,0.3);
        }
        .hud-disc {
            display: inline-block; width: 16px; height: 16px; border-radius: 50%;
            box-shadow: inset 0 -2px 3px rgba(0,0,0,0.5), inset 0 2px 3px rgba(255,255,255,0.3);
            border: 1px solid rgba(255,255,255,0.12);
        }
        .hud-disc.black { background: radial-gradient(circle at 30% 30%, #4a4a55, #0a0a12 70%, #000); }
        .hud-disc.white { background: radial-gradient(circle at 30% 30%, #ffffff, #d8e0ea 70%, #a3adba); }
        .hud-count {
            font-size: 1.05rem;
            font-weight: 800;
            color: #fcfffa;
            min-width: 18px;
            text-align: center;
            text-shadow: 0 2px 8px rgba(0,0,0,0.5);
        }
        .hud-vs {
            font-size: 0.6rem;
            color: rgba(255,255,255,0.45);
            letter-spacing: 0.1em;
        }
        .hud-pause-btn {
            pointer-events: auto;
            width: 42px; height: 42px;
            border-radius: 12px;
            background: rgba(6, 22, 16, 0.78);
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            border: 1px solid rgba(74,222,128,0.3);
            color: #4ade80;
            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(6, 22, 16, 0.92); transform: scale(1.06); }
        .hud-pause-btn[hidden] { display: none; }
        .pause-icon::before { content: '⏸'; }
        .play-icon::before { content: '▶'; }

        /* Bottom status strip — turn + last-move flips */
        .hud-bottom {
            position: absolute; bottom: 10px; left: 10px; right: 10px;
            display: flex; justify-content: center; pointer-events: none;
        }
        .hud-turn-pill {
            background: rgba(6, 22, 16, 0.78);
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            border: 1px solid rgba(74,222,128,0.3);
            color: #f4fbf7;
            border-radius: 99px;
            padding: 6px 14px;
            font-family: 'Orbitron', monospace;
            font-size: 0.7rem;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            transition: opacity 0.2s, transform 0.2s;
        }
        .hud-turn-pill.dim { opacity: 0; transform: translateY(8px); }
        .hud-turn-pill .pill-disc { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
        .hud-turn-pill .pill-disc.black { background: radial-gradient(circle at 30% 30%, #4a4a55, #0a0a12 70%, #000); }
        .hud-turn-pill .pill-disc.white { background: radial-gradient(circle at 30% 30%, #ffffff, #d8e0ea 70%, #a3adba); }

        /* Overlays */
        .overlay {
            position: fixed;
            inset: 0;
            z-index: 10000;
            display: none;
            align-items: center;
            justify-content: center;
            background: linear-gradient(180deg, rgba(2, 10, 7, 0.4), rgba(2, 10, 7, 0.88));
            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(7, 28, 20, 0.92);
            border: 1px solid rgba(74,222,128,0.4);
            border-radius: 22px;
            padding: 28px 28px 24px;
            min-width: 270px;
            max-width: 400px;
            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: #4ade80;
            text-shadow: 0 2px 14px rgba(74,222,128,0.45);
        }
        .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, #4ade80, #10b981);
            color: #062013;
        }
        .overlay-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(16,185,129,0.45); }
        .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.16); }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 8px;
            margin: 12px 0 14px;
        }
        .stat-cell {
            padding: 10px 6px;
            background: rgba(255,255,255,0.05);
            border: 1px solid rgba(74,222,128,0.22);
            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: #4ade80;
        }

        /* Final score pill on game-over */
        .final-score {
            display: flex; justify-content: center; align-items: center; gap: 14px;
            margin: 4px 0 14px;
        }
        .final-side {
            display: flex; align-items: center; gap: 8px;
            padding: 8px 14px;
            border-radius: 12px;
            background: rgba(255,255,255,0.05);
            border: 1px solid rgba(255,255,255,0.12);
        }
        .final-side .final-disc {
            width: 22px; height: 22px; border-radius: 50%;
            box-shadow: inset 0 -3px 4px rgba(0,0,0,0.5), inset 0 3px 4px rgba(255,255,255,0.3);
        }
        .final-side .final-disc.black { background: radial-gradient(circle at 30% 30%, #4a4a55, #0a0a12 70%, #000); }
        .final-side .final-disc.white { background: radial-gradient(circle at 30% 30%, #ffffff, #d8e0ea 70%, #a3adba); }
        .final-side .final-num {
            font-family: 'Orbitron', monospace;
            font-size: 1.6rem;
            font-weight: 900;
            color: #fcfffa;
        }
        .final-side.winner {
            background: rgba(74,222,128,0.16);
            border-color: rgba(74,222,128,0.45);
            box-shadow: 0 0 18px rgba(74,222,128,0.35);
        }
        .final-side.winner .final-num { color: #4ade80; text-shadow: 0 0 12px rgba(74,222,128,0.5); }
        .final-vs {
            font-family: 'Orbitron', monospace;
            font-size: 0.74rem;
            color: rgba(255,255,255,0.5);
            letter-spacing: 0.12em;
        }

        /* Idle / start screen */
        .start-cta {
            background: linear-gradient(135deg, #4ade80, #10b981);
            color: #062013;
            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(16,185,129,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(16,185,129,0.5); }
            50% { transform: scale(1.06); box-shadow: 0 18px 44px rgba(16,185,129,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(74,222,128,0.3);
            color: #f4fbf7; 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(74,222,128,0.12); }
        .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(74,222,128,0.28); border-radius: 14px;
            color: #f4fbf7; 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: #4ade80; 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: #4ade80; 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(74,222,128,0.18); 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; }

        /* Flip count popup */
        .flip-pop {
            position: absolute;
            font-family: 'Orbitron', monospace;
            font-weight: 900;
            font-size: 1.4rem;
            color: #4ade80;
            text-shadow: 0 2px 12px rgba(0,0,0,0.6);
            pointer-events: none;
            animation: flipPopAnim 1.1s ease-out forwards;
            z-index: 5;
        }
        @keyframes flipPopAnim {
            0% { opacity: 0; transform: scale(0.5) translateY(0); }
            20% { opacity: 1; transform: scale(1.35) translateY(-12px); }
            100% { opacity: 0; transform: scale(0.9) translateY(-50px); }
        }

        /* Pass notification */
        .pass-notice {
            position: absolute;
            left: 50%; top: 50%;
            transform: translate(-50%, -50%);
            background: rgba(7, 28, 20, 0.92);
            border: 1px solid rgba(74,222,128,0.4);
            border-radius: 14px;
            padding: 14px 22px;
            font-family: 'Orbitron', monospace;
            font-size: 0.85rem;
            letter-spacing: 0.12em;
            text-transform: uppercase;
            color: #4ade80;
            box-shadow: 0 14px 40px rgba(0,0,0,0.5);
            pointer-events: none;
            opacity: 0;
            animation: passFade 1.7s ease-out forwards;
            z-index: 3;
        }
        @keyframes passFade {
            0% { opacity: 0; transform: translate(-50%, -45%); }
            18% { opacity: 1; transform: translate(-50%, -50%); }
            85% { opacity: 1; transform: translate(-50%, -50%); }
            100% { opacity: 0; transform: translate(-50%, -55%); }
        }

        /* ----- Reversi theme (green felt + emerald accents) ----- */
        body.game-page {
            --t-bg: #051d14;
            --t-bg-grad: radial-gradient(ellipse at 50% -20%, #0c3b2a 0%, #051d14 70%);
            --t-text: #f4fbf7;
            --t-text-muted: #c8e7d8;
            --t-text-subtle: #93b6a4;
            --t-primary: #4ade80;
            --t-primary-mid: #10b981;
            --t-primary-dark: #047857;
            --t-glass-bg: rgba(255,255,255,0.06);
            --t-glass-border: rgba(74,222,128,0.4);
            --t-card-bg: rgba(255,255,255,0.05);
            --t-card-border: rgba(74,222,128,0.3);
            --t-btn-grad: linear-gradient(135deg, #4ade80, #10b981);
        }
        body.game-page .game-name,
        body.game-page .score-value { color: #4ade80 !important; -webkit-text-fill-color: #4ade80 !important; background: none !important; }

        /* ============================================================
           Desktop layout — board fills the viewport HEIGHT; the leftover
           horizontal space becomes a side rail (setup / recent games /
           how to play). Previously the board floated as a small element in
           a sea of green, and the full-screen start & game-over overlays
           buried the difficulty selectors 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;
        }
        /* position:relative (NO transform/filter) so the overlays — kept as
           SIBLINGS of #gameContainer (whose .shake adds a transform that would
           trap a fixed descendant) — confine to the board on desktop and reach
           the viewport cleanly on mobile. */
        .game-main {
            position: relative; display: flex; flex-direction: column;
            align-items: center; min-width: 0; max-width: 100%;
        }
        .game-main .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(74,222,128,0.06);
            border: 1px solid rgba(74,222,128,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: #4ade80; 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; }
        /* Recent games + help live open 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;
        }

        /* Overlays: confine to the board (was full-screen `fixed`). .game-main
           is position:relative + the overlay gets border-radius so it clips to
           the rounded board; the rail stays clickable behind it on desktop. */
        .overlay {
            position: absolute;
            z-index: 20;
            overflow-y: auto;
            border-radius: 18px;
        }
        .overlay .overlay-box { margin: auto; }

        /* In-overlay 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 the panel beside it. */
        .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 0 14px;
            }
        }
