
        /* ===== Tic-Tac-Toe 3D — blue X / red O on cinematic dark glass ===== */
        body.game-page {
            --t-bg: #0f172a;
            --t-bg-grad: radial-gradient(ellipse at 50% -20%, #1e293b 0%, #0f172a 70%);
            --t-text: #f1f5f9;
            --t-text-muted: #cbd5e1;
            --t-text-subtle: #94a3b8;
            --t-primary: #3b82f6;
            --t-primary-mid: #60a5fa;
            --t-primary-dark: #ef4444;
            --t-glass-bg: rgba(59,130,246,0.08);
            --t-glass-border: rgba(99,154,247,0.4);
            --t-card-bg: rgba(255,255,255,0.05);
            --t-card-border: rgba(255,255,255,0.18);
            --t-btn-grad: linear-gradient(135deg, #60a5fa, #3b82f6 55%, #2563eb);
            --t-correct: #10b981;
        }

        /* ----- Settings bar (mode + difficulty) ----- */
        .settings-bar {
            display: flex; flex-wrap: wrap; gap: 0.5rem;
            justify-content: center; margin-bottom: 0.7rem;
            max-width: 460px;
        }
        .setting-group {
            display: flex; align-items: center; gap: 0.3rem;
            background: rgba(15,23,42,0.55);
            border: 1px solid rgba(255,255,255,0.12);
            backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
            border-radius: 30px; padding: 0.25rem 0.4rem;
            box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 4px 12px rgba(0,0,0,0.2);
        }
        .setting-label {
            font-family: 'Orbitron', monospace; font-size: 0.5rem;
            text-transform: uppercase; letter-spacing: 0.08em;
            color: var(--t-text-subtle); padding-left: 0.4rem;
        }
        .setting-btn {
            padding: 0.35rem 0.75rem; border: none; border-radius: 20px;
            font-family: inherit; font-size: 0.7rem; font-weight: 600;
            cursor: pointer; background: transparent; color: var(--t-text);
            transition: all 0.18s;
        }
        .setting-btn.active {
            background: var(--t-btn-grad); color: #fff;
            box-shadow: 0 2px 10px rgba(59,130,246,0.45);
        }
        .setting-btn:hover:not(.active):not(:disabled) {
            background: rgba(59,130,246,0.18);
        }
        .setting-btn:disabled { opacity: 0.4; cursor: not-allowed; }

        /* ----- Canvas container + overlays ----- */
        .game-container {
            position: relative;
            width: 100%;
            max-width: min(720px, 96vw);
            margin: 0 auto;
            border-radius: 22px;
            overflow: hidden;
            padding: 0;
            background: transparent;
            border: 0;
            box-shadow:
              0 20px 60px rgba(0,0,0,0.45),
              0 0 0 1px rgba(99,154,247,0.25);
        }
        #canvas3d {
            display: block;
            border-radius: 22px;
            touch-action: manipulation;
            cursor: pointer;
            background:
              radial-gradient(ellipse at 50% 0%, rgba(59,130,246,0.18) 0%, transparent 65%),
              linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
        }

        /* HUD bar — turn indicator + pause */
        .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-turn-box {
            pointer-events: none;
            background: rgba(15,23,42,0.65);
            backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
            border: 1px solid rgba(255,255,255,0.18);
            color: #fff;
            border-radius: 16px;
            padding: 8px 14px;
            font-family: 'Orbitron', monospace;
            display: flex;
            align-items: center;
            gap: 8px;
            min-height: 28px;
        }
        .hud-turn-pill {
            width: 22px; height: 22px; border-radius: 50%;
            display: inline-flex; align-items: center; justify-content: center;
            font-weight: 900; font-size: 0.85rem;
            box-shadow: 0 0 14px currentColor;
        }
        .hud-turn-pill.x { color: #60a5fa; background: rgba(59,130,246,0.25); }
        .hud-turn-pill.o { color: #f87171; background: rgba(239,68,68,0.25); }
        .hud-turn-label {
            font-size: 0.7rem;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            color: rgba(255,255,255,0.92);
        }
        .hud-pause-btn {
            pointer-events: auto;
            width: 44px; height: 44px;
            border-radius: 12px;
            background: rgba(15,23,42,0.65);
            backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
            border: 1px solid rgba(255,255,255,0.18);
            color: #fff;
            font-size: 1.2rem;
            cursor: pointer;
            display: flex; align-items: center; justify-content: center;
            transition: transform 0.15s, background 0.15s;
        }
        .hud-pause-btn:hover { background: rgba(15,23,42,0.85); transform: scale(1.05); }
        .hud-pause-btn[hidden] { display: none; }
        .pause-icon::before { content: '⏸'; }
        .play-icon::before { content: '▶'; }

        /* Stat row UNDER canvas — wins / streak / draws */
        .stats-row {
            display: flex; gap: 1rem; justify-content: center; margin-top: 0.9rem;
            padding: 0.55rem 1rem;
            background: rgba(15,23,42,0.55);
            border: 1px solid rgba(255,255,255,0.12);
            backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
            border-radius: 16px;
            max-width: 420px; width: 100%;
            box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 4px 12px rgba(0,0,0,0.2);
        }
        .stat { text-align: center; flex: 1; }
        .stat-label {
            font-family: 'Orbitron', monospace; font-size: 0.5rem;
            text-transform: uppercase; letter-spacing: 0.1em;
            color: var(--t-text-subtle);
        }
        .stat-value {
            font-family: 'Orbitron', monospace; font-size: 1.05rem; font-weight: 700;
            color: var(--t-text);
            text-shadow: 0 0 8px rgba(59,130,246,0.4);
        }

        /* Overlays (start / pause / gameover) — viewport-fixed so they
           cover the whole screen and don't get trapped inside the
           backdrop-filter containing block of .game-container. */
        .overlay {
            position: fixed; inset: 0;
            display: none; align-items: center; justify-content: center;
            background: linear-gradient(180deg, rgba(15,23,42,0.55), rgba(15,23,42,0.85));
            text-align: center; color: #fff;
            font-family: 'Orbitron', monospace;
            padding: 24px;
            backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
            z-index: 10000;
        }
        .overlay.active { display: flex; }
        .overlay-box {
            background: rgba(15,23,42,0.78);
            border: 1px solid rgba(99,154,247,0.35);
            border-radius: 22px;
            padding: 28px 28px 24px;
            min-width: 260px; max-width: 360px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.5);
        }
        .overlay-title {
            font-size: 1.5rem; font-weight: 900; letter-spacing: 0.04em;
            margin: 0 0 6px;
            background: linear-gradient(135deg, #60a5fa, #2563eb);
            -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
            text-shadow: 0 2px 10px rgba(0,0,0,0.4);
        }
        .overlay-title.win {
            background: linear-gradient(135deg, #fcd663, #f59e0b);
            -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
        }
        .overlay-title.lose {
            background: linear-gradient(135deg, #fda4af, #ef4444);
            -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
        }
        .overlay-sub {
            margin: 0 0 18px;
            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: var(--t-btn-grad); color: #fff;
        }
        .overlay-btn-primary:hover {
            transform: translateY(-1px);
            box-shadow: 0 10px 22px rgba(59,130,246,0.45);
        }
        .overlay-btn-ghost {
            background: rgba(255,255,255,0.08);
            border: 1px solid rgba(255,255,255,0.25);
            color: #fff;
        }
        .overlay-btn-ghost:hover { background: rgba(255,255,255,0.15); }

        /* Game-over stats grid */
        .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.06);
            border: 1px solid rgba(255,255,255,0.12);
            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.05rem; font-weight: 800;
            color: #60a5fa;
        }
        .stat-cell-value.win { color: #fcd663; }
        .stat-cell-value.streak.fire { color: #fb923c; }

        /* Start CTA (idle pulse) */
        .start-cta {
            background: var(--t-btn-grad);
            color: #fff;
            padding: 16px 36px; border-radius: 99px;
            font-family: 'Orbitron', monospace;
            font-weight: 800; font-size: 1.0rem;
            letter-spacing: 0.16em; text-transform: uppercase;
            box-shadow: 0 14px 36px rgba(59,130,246,0.5);
            animation: startPulse 1.6s ease-in-out infinite;
            cursor: pointer; border: 0;
        }
        @keyframes startPulse {
            0%, 100% { transform: scale(1); box-shadow: 0 14px 36px rgba(59,130,246,0.5); }
            50% { transform: scale(1.05); box-shadow: 0 18px 44px rgba(59,130,246,0.7); }
        }
        .start-sub {
            display: block; margin-top: 14px;
            font-size: 0.8rem;
            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);
        }

        /* Screen-shake utility */
        @keyframes screenShake {
            0%, 100% { transform: translate(0, 0); }
            10% { transform: translate(-6px, -3px); }
            25% { transform: translate(5px, -2px); }
            40% { transform: translate(-4px, 4px); }
            55% { transform: translate(4px, 3px); }
            70% { transform: translate(-3px, -2px); }
            85% { transform: translate(2px, 2px); }
        }
        .shake { animation: screenShake 0.55s cubic-bezier(.36,.07,.19,.97); }

        /* Help panel */
        .help-toggle, .history-toggle {
            display: block; margin: 0.7rem auto 0;
            padding: 0.4rem 1.1rem;
            background: none; border: 1px solid rgba(255,255,255,0.25);
            color: var(--t-text); 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(255,255,255,0.08); }
        .help-panel, .history-panel {
            display: none; max-width: 460px; margin: 0.8rem auto 0;
            padding: 1rem 1.2rem;
            background: rgba(15,23,42,0.7);
            border: 1px solid rgba(99,154,247,0.25);
            border-radius: 14px;
            color: var(--t-text);
            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: 0 0 6px;
            font-family: 'Orbitron', monospace; font-size: 0.85rem;
            color: var(--t-primary-mid);
        }
        .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: var(--t-primary-mid); 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-radius: 8px;
            font-size: 0.78rem; margin-bottom: 4px;
        }
        .history-result { font-family: 'Orbitron', monospace; font-weight: 700; }
        .history-result.win { color: #fcd663; }
        .history-result.loss { color: #f87171; }
        .history-result.draw { color: #94a3b8; }
        .history-meta { color: var(--t-text-subtle); font-size: 0.72rem; }
        .history-empty {
            text-align: center; color: rgba(255,255,255,0.45);
            font-size: 0.84rem; padding: 12px;
        }

        /* ============================================================
           Desktop layout — board FILLS the viewport height; the side
           rail consumes the leftover horizontal space (settings / stats
           / history / how-to-play) so the board no longer floats as a
           small square in a sea of black. Mirrors snake.html.
           Overlays are CONFINED to the board column (.game-main, a
           position:relative non-transformed wrapper) so the rail stays
           clickable on desktop — previously the full-screen start &
           game-over overlays buried the mode/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;
        }
        .game-main {
            position: relative; display: flex; flex-direction: column;
            align-items: center; min-width: 0; max-width: 100%;
        }
        .game-main .game-container { margin: 0; }

        .game-rail {
            width: 340px; flex-shrink: 0;
            display: flex; flex-direction: column; gap: 14px;
        }
        .rail-card {
            background: rgba(59,130,246,0.07);
            border: 1px solid rgba(99,154,247,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: var(--t-primary-mid); 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; }
        /* Stats fill the rail row */
        .game-rail .stats-row {
            margin: 0; max-width: none; width: 100%;
            background: none; border: none; padding: 0;
            box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none;
            gap: 8px;
        }
        /* 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 column (was full-screen `fixed`).
           .game-main is position:relative, so an absolutely-positioned
           overlay clips to the board area while the rail stays clickable. */
        .overlay {
            position: absolute;
            z-index: 20;
            overflow-y: auto;
            border-radius: 22px;
        }
        .overlay .overlay-box { margin: auto; }

        /* In-overlay mode + difficulty re-pick — MOBILE only (desktop uses
           the always-visible rail). Lets the end screen launch a new run at
           a different difficulty without hunting for the panel below. */
        .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;
            }
        }
