/* ================================================================
   CSS custom properties — dark default, light override via media
   ================================================================ */
:root {
    --bg:           #0e0e16;
    --surface:      #18182a;
    --surface-2:    #22223a;
    --surface-3:    #2a2a42;
    --border-thin:  #2e2e4e;
    --border-box:   #4444aa;
    --text:         #e8e8f6;
    --text-muted:   #9090c0;
    --text-given:   #e8e8f6;
    --text-user:    #7b9fff;
    --accent:       #6c63ff;
    --hl-unit:      rgba(108, 99, 255, 0.07);
    --hl-same:      rgba(108, 99, 255, 0.22);
    --hl-selected:  rgba(108, 99, 255, 0.42);
    --hl-hint:      rgba(255, 210, 40, 0.28);
    --error-text:   #ff5577;
    --error-bg:     rgba(255, 85, 119, 0.65);
    --note-color:   #c0c0f0;
    --btn-bg:       #22223a;
    --btn-hover:    #2a2a42;
    --btn-active-bg:   rgba(108, 99, 255, 0.18);
    --btn-active-txt:  #9e98ff;
    --success:      #4ade80;
    --radius:       10px;
    --radius-sm:    6px;
    --shadow:       0 4px 24px rgba(0,0,0,.5);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg:           #f0f0f8;
        --surface:      #ffffff;
        --surface-2:    #f5f5fe;
        --surface-3:    #ebebfa;
        --border-thin:  #d0d0e8;
        --border-box:   #8888cc;
        --text:         #18182a;
        --text-muted:   #5858a0;
        --text-given:   #18182a;
        --text-user:    #4040cc;
        --accent:       #5050e0;
        --hl-unit:      rgba(80, 80, 224, 0.06);
        --hl-same:      rgba(80, 80, 224, 0.18);
        --hl-selected:  rgba(80, 80, 224, 0.36);
        --hl-hint:      rgba(220, 160, 0, 0.22);
        --error-text:   #cc2244;
        --error-bg:     rgba(204, 34, 68, 0.55);
        --note-color:   #3535aa;
        --btn-bg:       #ebebfa;
        --btn-hover:    #e0e0f5;
        --btn-active-bg:   rgba(80, 80, 224, 0.14);
        --btn-active-txt:  #4646cc;
        --success:      #167a40;
        --shadow:       0 4px 24px rgba(0,0,0,.12);
    }
}

/* ================================================================
   Reset & base
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; font-size: 16px; }

body {
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    line-height: 1.4;
    overflow-x: hidden;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ================================================================
   App shell
   ================================================================ */
#app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ================================================================
   Hub
   ================================================================ */
.hub {
    max-width: 540px;
    margin: 0 auto;
    width: 100%;
    padding: 32px 16px 40px;
}

.hub-header { margin-bottom: 28px; }
.hub-header h1 {
    font-size: clamp(1.8rem, 6vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}
.hub-subtitle {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* 2-column grid on phone portrait; single column on wider screens */
.game-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

@media (min-width: 500px) {
    .game-grid { grid-template-columns: 1fr; gap: 12px; }
}

.game-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 12px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border-thin);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background .15s, transform .12s, box-shadow .15s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.game-card:hover {
    background: var(--surface-2);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}
.game-card:active { transform: translateY(0); }

/* Compact card: hide description and arrow on narrow screens */
.game-card .game-card-info p { display: none; }
.game-card .card-arrow        { display: none; }

/* Wide layout: horizontal card with description and arrow */
@media (min-width: 500px) {
    .game-card {
        flex-direction: row;
        align-items: center;
        text-align: left;
        gap: 16px;
        padding: 16px 18px;
    }
    .game-card .game-card-info p { display: block; }
    .game-card .card-arrow        { display: block; }
}

.game-card-icon {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 500px) {
    .game-card-icon { width: 56px; height: 56px; }
}

.mini-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    width: 42px;
    height: 42px;
}
.mini-grid span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    background: var(--surface);
    border-radius: 2px;
}
.mini-grid span.empty { color: var(--border-thin); }

.game-card-info { flex: 1; }
.game-card-info h2 { font-size: 1.05rem; font-weight: 600; }
.game-card-info p  { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

.card-arrow { width: 18px; height: 18px; color: var(--text-muted); flex-shrink: 0; }

/* ================================================================
   Loading screen
   ================================================================ */
.loading-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-thin);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   Sudoku view
   ================================================================ */
.sudoku-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 540px;
    margin: 0 auto;
    padding: 0 8px 24px;
    gap: 10px;
    min-height: 100dvh;
}

/* --- Header --- */
.game-header {
    width: 100%;
    display: flex;
    align-items: center;
    padding: 10px 4px 6px;
    gap: 8px;
}

.btn-icon {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.btn-icon:hover { background: var(--btn-hover); color: var(--text); }
.btn-icon:disabled { opacity: 0.3; pointer-events: none; }
.btn-icon svg { width: 20px; height: 20px; }

.game-title {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: -0.01em;
}

.timer-group {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.timer {
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 44px;
    text-align: right;
}

/* --- Difficulty bar --- */
.diff-bar {
    display: flex;
    gap: 6px;
    width: 100%;
}
.diff-btn {
    flex: 1;
    padding: 7px 4px;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    background: var(--btn-bg);
    color: var(--text-muted);
    transition: background .15s, color .15s;
}
.diff-btn:hover { background: var(--btn-hover); color: var(--text); }
.diff-btn.active {
    background: var(--btn-active-bg);
    color: var(--btn-active-txt);
}

/* --- Board wrapper --- */
.board-wrap {
    position: relative;
    width: min(calc(100vw - 16px), 468px);
    height: min(calc(100vw - 16px), 468px);
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 4px;
}

/* --- Sudoku board grid --- */
.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 100%;
    height: 100%;
    background: var(--surface);
    border: 3px solid var(--border-box);
    border-radius: 4px;
}

/* --- Cells --- */
.cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--border-thin);
    border-bottom: 1px solid var(--border-thin);
    cursor: pointer;
    font-size: clamp(24px, 7.5vw, 36px);
    font-weight: 700;
    color: var(--text-given);
    user-select: none;
    transition: background .1s;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}
.cell:last-child          { border-right: none; }
.cell[data-col="8"]       { border-right: none; }
.cell[data-row="8"]       { border-bottom: none; }

/* Box boundaries — thick lines every 3 cells */
.cell[data-col="2"],
.cell[data-col="5"] { border-right: 2px solid var(--border-box); }
.cell[data-row="2"],
.cell[data-row="5"] { border-bottom: 2px solid var(--border-box); }

/* Cell states */
.cell.user       { color: var(--text-user); }
.cell.error      { color: var(--error-text); background: var(--error-bg) !important; }
.cell.hl-unit    { background: var(--hl-unit); }
.cell.hl-same    { background: var(--hl-same); }
.cell.selected   { background: var(--hl-selected) !important; box-shadow: inset 0 0 0 2px var(--accent); }
.cell.hint       { background: var(--hl-hint) !important; animation: pulse-hint 1s ease infinite alternate; }

@keyframes pulse-hint {
    from { background: var(--hl-hint); }
    to   { background: rgba(255, 210, 40, 0.44); }
}

/* --- Notes (pencil marks) --- */
.cell-notes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    padding: 1px;
}
.cell-notes span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(11px, 2.5vw, 14px);
    font-weight: 700;
    color: var(--note-color);
    line-height: 1;
}

/* --- Pause overlay --- */
.pause-overlay {
    position: absolute;
    inset: 0;
    background: rgba(14, 14, 22, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 600;
    border-radius: 4px;
}
.pause-overlay.hidden { display: none; }

/* ================================================================
   Controls
   ================================================================ */
.controls-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Control button row (Undo / Erase / Notes / Hint) */
.ctrl-row {
    display: flex;
    gap: 8px;
    width: 100%;
}
.ctrl-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 4px 8px;
    border-radius: var(--radius-sm);
    background: var(--btn-bg);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    transition: background .15s, color .15s;
}
.ctrl-btn svg { width: 20px; height: 20px; }
.ctrl-btn:hover { background: var(--btn-hover); color: var(--text); }
.ctrl-btn.active {
    background: var(--btn-active-bg);
    color: var(--btn-active-txt);
}

/* Number pad */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    width: 100%;
}
.num-btn {
    padding: 10px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--btn-bg);
    border-radius: var(--radius-sm);
    font-size: clamp(1.1rem, 5vw, 1.4rem);
    font-weight: 700;
    color: var(--text);
    transition: background .12s, transform .1s;
}
.num-btn:hover  { background: var(--btn-hover); }
.num-btn:active { transform: scale(0.93); }
.num-btn:disabled { opacity: 0.25; pointer-events: none; }

/* ================================================================
   Toast notification
   ================================================================ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-thin);
    border-radius: var(--radius);
    padding: 10px 18px;
    font-size: 0.85rem;
    max-width: calc(100vw - 32px);
    text-align: center;
    box-shadow: var(--shadow);
    opacity: 0;
    transition: opacity .25s, transform .25s;
    pointer-events: none;
    z-index: 100;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.hidden { display: none; }

/* ================================================================
   Win overlay
   ================================================================ */
.win-overlay {
    position: absolute;
    inset: 0;
    background: rgba(14, 14, 22, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 0;
    transition: opacity .35s;
    border-radius: 4px;
}
.win-overlay.visible { opacity: 1; }

.win-card {
    background: var(--surface);
    border: 1px solid var(--border-thin);
    border-radius: var(--radius);
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    box-shadow: var(--shadow);
    max-width: 280px;
    width: 90%;
    transform: translateY(16px);
    transition: transform .35s;
}
.win-overlay.visible .win-card { transform: translateY(0); }

.win-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--btn-active-bg);
    color: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 4px;
}
.win-icon.lose-icon { color: var(--text-muted); }
.win-card h2 { font-size: 1.3rem; font-weight: 700; }
.win-meta { font-size: 0.9rem; color: var(--text-muted); }
.win-answer { font-size: 1.6rem; font-weight: 700; letter-spacing: 0.08em; color: var(--text); margin: 0; }

.win-btn-row { display: flex; flex-direction: column; gap: 8px; width: 100%; margin-top: 8px; }

.btn-primary, .btn-secondary {
    padding: 11px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: opacity .15s;
    width: 100%;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .88; }
.btn-secondary {
    background: var(--btn-bg);
    color: var(--text-muted);
}
.btn-secondary:hover { background: var(--btn-hover); color: var(--text); }

/* ================================================================
   Utility
   ================================================================ */
.hidden { display: none !important; }

/* ================================================================
   Responsive tweaks
   ================================================================ */
@media (min-width: 500px) {
    .numpad { gap: 7px; }
    .ctrl-row { gap: 10px; }
}

@media (max-height: 680px) {
    .sudoku-view { gap: 6px; }
    .game-header { padding: 6px 4px 2px; }
    .diff-btn { padding: 5px 4px; font-size: 0.74rem; }
    .ctrl-btn { padding: 7px 4px 6px; }
}

/* ================================================================
   Card game shared styles
   Cards always use light backgrounds so they look like real cards,
   regardless of the app's dark/light theme.
   ================================================================ */

/* ── Card element ─────────────────────────────────────────────── */
.card {
    width:  var(--card-w);
    height: var(--card-h);
    background: #fafafa;
    border: 1px solid #bbb;
    border-radius: clamp(3px, 0.6vw, 6px);
    box-shadow: 0 1px 3px rgba(0,0,0,.22);
    position: relative;
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;  /* required for pointer capture to work on Samsung/Android browsers */
}
.card.red { color: #c0392b; }
.card.blk { color: #1a1a2a; }

/* Face-down card — blue diagonal pattern */
.card.back {
    background: repeating-linear-gradient(
        135deg, #1a3888 0 3px, #1e42a0 3px 6px
    );
    border-color: #1530cc;
    cursor: default;
    box-shadow: 0 1px 3px rgba(0,0,0,.35);
}

/* Empty pile placeholder */
.card.empty {
    background: rgba(255,255,255,0.04);
    border: 2px dashed rgba(255,255,255,0.18);
    box-shadow: none;
    cursor: default;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.22);
    font-size: calc(var(--card-w) * 0.32);
}
.card.empty.clickable { cursor: pointer; }
.card.empty.clickable:hover { border-color: rgba(255,255,255,0.4); }

/* Selected card highlight */
.card.selected {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    box-shadow: 0 0 8px rgba(108,99,255,.55);
    z-index: 2;
}

/* Drag-and-drop ghost and source */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    opacity: 0.92;
    filter: drop-shadow(0 6px 16px rgba(0,0,0,.45));
}
.drag-source { opacity: 0.25; }

/* ── Card text layout ─────────────────────────────────────────── */
/* Top-left and bottom-right corners */
.cc {
    position: absolute;
    font-size: calc(var(--card-w) * 0.30);
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
}
.cc.tl { top: 2px; left: 4px; }
.cc.br { bottom: 2px; right: 4px; transform: rotate(180deg); }

/* Large centre suit symbol */
.ctr {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: calc(var(--card-w) * 0.48);
    line-height: 1;
    pointer-events: none;
}

/* Spider cards are narrower so use slightly larger relative font sizes */
.spider-view .cc  { font-size: calc(var(--card-w) * 0.34); }
.spider-view .ctr { font-size: calc(var(--card-w) * 0.52); }

/* ── Card stacking offsets ────────────────────────────────────── */
/* Negative top-margin creates the fanned-column look.
   Values are calculated from --card-h so they scale with card size. */
.card.mt-dn { margin-top: calc(-1 * (var(--card-h) - 18px)); }
.card.mt-up { margin-top: calc(-1 * (var(--card-h) - 24px)); }

/* ── Shared game view chrome ──────────────────────────────────── */
.card-game-view {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 0 6px 16px;
    min-height: 100dvh;
    gap: 6px;
    touch-action: none;  /* let JS handle all pointer gestures; required for drag on mobile */
}

.game-info-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 2px;
    font-size: 0.82rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}
.game-info-row .timer { font-variant-numeric: tabular-nums; font-weight: 600; }

.ctrl-btn-sm {
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    background: var(--btn-bg);
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    margin-left: auto;
}
.ctrl-btn-sm:hover { background: var(--btn-hover); color: var(--text); }

/* ================================================================
   Klondike Solitaire
   ================================================================ */
.klondike-view {
    --card-w: clamp(42px, calc((100vw - 40px) / 7.4), 68px);
    --card-h: calc(var(--card-w) * 1.42);
}
@media (orientation: landscape) and (max-height: 500px) {
    .klondike-view {
        --card-w: clamp(36px, calc((100vh - 32px) / 5.2), 58px);
    }
    .card-game-view { min-height: unset; padding-bottom: 8px; gap: 4px; }
}

/* Top row: stock · waste · spacer · 4 foundations */
.k-top-row {
    display: flex;
    align-items: flex-start;
    gap: 4px;
}
.kpile { position: relative; flex-shrink: 0; }
.kwaste { min-width: var(--card-w); }
/* Second waste card peeking underneath */
.w-under {
    position: absolute;
    top: 0; left: -3px;
    opacity: 0.6;
    z-index: 0;
}
.kwaste > *:not(.w-under) { position: relative; z-index: 1; }
/* 3-draw waste fan */
.kwaste-3 { min-width: calc(var(--card-w) + 16px); min-height: var(--card-h); }
.kwaste-3 > .card { position: absolute; top: 0; }
.kwaste-3 > .w-f0 { left: 0;    z-index: 0; opacity: 0.55; }
.kwaste-3 > .w-f1 { left: 8px;  z-index: 1; opacity: 0.75; }
.kwaste-3 > .w-f2 { left: 16px; z-index: 2; }

.k-draw-btns { display: flex; gap: 4px; margin-left: auto; }
.k-draw-btns .diff-btn { padding: 4px 8px; font-size: 0.74rem; }

.k-spacer { flex: 1; }
.kfound-row { display: flex; gap: 4px; }

/* Tableau row */
.k-tab-row {
    display: flex;
    gap: 4px;
    flex: 1;
    align-items: flex-start;
}
.ktab-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ================================================================
   Spider Solitaire
   ================================================================ */
.spider-view {
    --card-w: clamp(26px, calc((100vw - 24px - 9 * 3px) / 10), 54px);
    --card-h: calc(var(--card-w) * 1.45);
    /* Tighter offsets for the smaller cards */
}
.spider-view .card.mt-dn { margin-top: calc(-1 * (var(--card-h) - 13px)); }
.spider-view .card.mt-up { margin-top: calc(-1 * (var(--card-h) - 18px)); }
@media (orientation: landscape) and (max-height: 500px) {
    .spider-view {
        --card-w: clamp(22px, calc((100vw - 24px - 9 * 3px) / 10), 44px);
    }
}

/* Deal control row */
.sp-control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 2px 0;
    border-top: 1px solid var(--border-thin);
    margin-top: 4px;
}
.sp-completed {
    display: flex;
    gap: 4px;
    flex: 1;
}
.sp-comp {
    font-size: 1.1rem;
    color: var(--border-thin);
    transition: color .25s;
}
.sp-comp.done { color: var(--success); }

.btn-deal {
    padding: 6px 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}
.btn-deal:hover { opacity: .88; }
.btn-deal.disabled, .btn-deal:disabled { opacity: .35; cursor: default; }
.deal-count { font-weight: 700; }

.sp-suit-btns { display: flex; gap: 4px; margin-left: auto; }
.sp-suit-btns .diff-btn { padding: 4px 8px; font-size: 0.74rem; }

/* Spider tableau */
.sp-tab-row {
    display: flex;
    gap: 3px;
    flex: 1;
    align-items: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
}
.sptab-col {
    flex: 1;
    min-width: var(--card-w);
    display: flex;
    flex-direction: column;
}

/* ================================================================
   2048
   ================================================================ */
.t2-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 12px 24px;
    min-height: 100dvh;
    gap: 10px;
}
.t2-view .game-header { width: 100%; }

.t2-scores {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 420px;
}
.t2-score-box {
    flex: 1;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    text-align: center;
}
.t2-score-lbl { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em; color: var(--text-muted); }
.t2-score-val { font-size: 1.15rem; font-weight: 700; }

.t2-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    padding: 8px;
    background: #3a3a5c;
    border-radius: 12px;
    width: 100%;
    max-width: 420px;
    aspect-ratio: 1;
    position: relative;
    touch-action: none;
}

.t2-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: #4e4e72;
    font-weight: 800;
    font-size: clamp(14px, 5vw, 28px);
    user-select: none;
}

/* Tile colours — match classic 2048 palette */
.t2-v2    { background: #eee4da; color: #776e65; }
.t2-v4    { background: #ede0c8; color: #776e65; }
.t2-v8    { background: #f2b179; color: #fff; }
.t2-v16   { background: #f59563; color: #fff; }
.t2-v32   { background: #f67c5f; color: #fff; }
.t2-v64   { background: #f65e3b; color: #fff; }
.t2-v128  { background: #edcf72; color: #fff; font-size: clamp(12px, 4.2vw, 24px); }
.t2-v256  { background: #edcc61; color: #fff; font-size: clamp(12px, 4.2vw, 24px); }
.t2-v512  { background: #edc850; color: #fff; font-size: clamp(12px, 4.2vw, 24px); }
.t2-v1024 { background: #edc53f; color: #fff; font-size: clamp(10px, 3.5vw, 20px); }
.t2-v2048 { background: #edc22e; color: #fff; font-size: clamp(10px, 3.5vw, 20px); box-shadow: 0 0 18px rgba(237,194,46,.45); }
.t2-v4096, .t2-v8192, .t2-v16384 { background: #3c3a32; color: #fff; font-size: clamp(9px, 3vw, 17px); }

.t2-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(14,14,22,0.72);
    border-radius: 12px;
    z-index: 10;
}
.t2-win-ol { background: rgba(14,14,22,0.60); }
.t2-ol-msg { font-size: 1.3rem; font-weight: 700; }
.t2-ol-btn {
    padding: 10px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
}
.t2-ol-btn:hover { opacity: 0.88; }

.t2-hint { font-size: 0.78rem; color: var(--text-muted); text-align: center; }

/* Hub mini-icon for 2048 */
.mini-2048 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    width: 44px;
    height: 44px;
}
.m2t {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
}
.m2t-2048 { background: #edc22e; color: #fff; font-size: 7px; }
.m2t-128  { background: #edcf72; color: #fff; }
.m2t-8    { background: #f2b179; color: #fff; }
.m2t-32   { background: #f67c5f; color: #fff; }

@media (prefers-color-scheme: light) {
    .t2-board { background: #bbada0; }
    .t2-cell  { background: #cdc1b4; }
    .t2-overlay { background: rgba(240,240,248,0.72); }
    .t2-win-ol  { background: rgba(240,240,248,0.60); }
}

/* ── Hub mini-icons for new games ────────────────────────────── */
.mini-suits {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
}
.mini-suits .s, .mini-suits .c { color: #1a1a2a; }
.mini-suits .h, .mini-suits .d { color: #c0392b; }

/* ================================================================
   Fossick
   ================================================================ */
.fossick-view {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    width: 100%;
}
.fossick-view .game-info-row { width: 100%; }

/* Board */
.wl-board {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin: 0 auto;
}
.wl-row {
    display: grid;
    grid-template-columns: repeat(var(--wl-cols, 5), 1fr);
    gap: 5px;
}
.wl-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.1rem, 5vw, 1.8rem);
    font-weight: 700;
    border: 2px solid var(--border-thin);
    border-radius: 4px;
    color: var(--text);
    user-select: none;
    transition: border-color .08s;
}
.wl-cell[data-state="tbd"]  { border-color: var(--border-box); }
.wl-cell.revealed[data-state="correct"] { background: #1a6fb5; color: #fff; border-color: #1a6fb5; }
.wl-cell.revealed[data-state="present"] { background: #c2673c; color: #fff; border-color: #c2673c; }
.wl-cell.revealed[data-state="absent"]  { background: var(--surface-3); color: var(--text-muted); border-color: var(--surface-3); }

/* Colour legend */
.wl-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}
.wl-legend-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 3px;
}
.wl-legend-swatch[data-state="correct"] { background: #1a6fb5; }
.wl-legend-swatch[data-state="present"] { background: #c2673c; }

/* On-screen keyboard */
.wl-keyboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    max-width: 480px;
}
.wl-kbd-row {
    display: flex;
    justify-content: center;
    gap: 5px;
}
.wl-key {
    height: 56px;
    flex: 1;
    max-width: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 700;
    background: var(--btn-bg);
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: background .1s, color .1s, transform .08s;
    -webkit-tap-highlight-color: transparent;
}
.wl-key.wide { flex: 1.5; max-width: 62px; font-size: 0.72rem; }
.wl-key:hover  { background: var(--btn-hover); }
.wl-key:active { transform: scale(0.93); }
.wl-key[data-state="correct"] { background: #1a6fb5; color: #fff; }
.wl-key[data-state="present"] { background: #c2673c; color: #fff; }
.wl-key[data-state="absent"]  { background: var(--surface-3); color: var(--text-muted); opacity: 0.32; cursor: default; pointer-events: none; text-decoration: line-through; }

/* Word-length buttons */
.wl-len-btns { display: flex; gap: 4px; margin-left: auto; }
.wl-len-btns .diff-btn { padding: 4px 10px; font-size: 0.74rem; }

/* Animations */
@keyframes wl-flip-out { from { transform: rotateX(0);     } to { transform: rotateX(-90deg); } }
@keyframes wl-flip-in  { from { transform: rotateX(90deg); } to { transform: rotateX(0);      } }
.wl-flip-out { animation: wl-flip-out 0.25s ease forwards; }
.wl-flip-in  { animation: wl-flip-in  0.25s ease forwards; }

@keyframes wl-shake {
    0%,100% { transform: translateX(0);  }
    16%      { transform: translateX(-5px); }
    33%      { transform: translateX(5px);  }
    50%      { transform: translateX(-5px); }
    66%      { transform: translateX(5px);  }
    83%      { transform: translateX(-3px); }
}
.wl-shake { animation: wl-shake 0.5s ease; }

@keyframes wl-bounce {
    0%,100% { transform: translateY(0);   }
    40%      { transform: translateY(-18px); }
    70%      { transform: translateY(-8px);  }
}
.wl-bounce { animation: wl-bounce 0.5s ease; }

@keyframes wl-pop {
    0%,100% { transform: scale(1);    }
    50%      { transform: scale(1.12); }
}
.wl-cell[data-state="tbd"] { animation: wl-pop 0.1s ease; }

/* Hub fossick icon — 5×2 mini guess grid */
.mini-fossick {
    display: grid;
    grid-template-columns: repeat(5, 9px);
    grid-template-rows: repeat(4, 9px);
    gap: 2px;
}
.mini-fossick span { border-radius: 1px; }
.mini-fossick .wc { background: #1a6fb5; }
.mini-fossick .wp { background: #c2673c; }
.mini-fossick .wa { background: var(--surface); border: 1px solid var(--border-box); }

/* ================================================================
   Black Box
   ================================================================ */
.bx-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 12px 24px;
    min-height: 100dvh;
    gap: 10px;
}
.bx-view .game-header { width: 100%; }

.bx-info {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 420px;
}
.bx-stat {
    flex: 1;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
}
.bx-stat-lbl { font-size: 0.62rem; font-weight: 700; letter-spacing: 0.06em; color: var(--text-muted); }
.bx-stat-val { font-size: 1.1rem; font-weight: 700; }

.bx-board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 2px;
    background: #14142a;
    border-radius: 8px;
    padding: 3px;
    width: 100%;
    max-width: 420px;
    aspect-ratio: 1;
}

.bx-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    font-size: clamp(7px, 2vw, 11px);
    font-weight: 800;
    user-select: none;
    line-height: 1;
}

.bx-corner { background: #14142a; }

.bx-edge {
    background: #22223a;
    color: var(--text-muted);
    cursor: default;
}
.bx-edge-active {
    cursor: pointer;
    transition: background .1s;
}
.bx-edge-active:hover { background: #2e2e50; }
.bx-edge-used { border: 1px solid transparent; border-radius: 3px; }

.bx-ray-hit     { background: #2d1212; color: #ff6b6b; border-color: #ff4444 !important; cursor: default; }
.bx-ray-reflect { background: #2d2a0a; color: #ffd700; border-color: #e6b800 !important; cursor: default; }
.bx-ray-num     { background: #0e1a2d; cursor: default; }

.bx-inner {
    background: #2a2a46;
    cursor: pointer;
    transition: background .1s;
}
.bx-inner:hover         { background: #363660; }
.bx-inner.bx-guess      { background: var(--accent); color: #fff; }
.bx-inner.bx-correct    { background: #14532d; color: #4ade80; }
.bx-inner.bx-missed     { background: #1e1e1e; color: #666; border: 1px solid #444; }
.bx-inner.bx-wrong      { background: #3d1212; color: #ff6b6b; }

.bx-result {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    font-size: 0.88rem;
}
.bx-result-score { font-weight: 700; }
.bx-result-ok    { color: #4ade80; }
.bx-result-bad   { color: #ff6b6b; }

.bx-submit {
    width: 100%;
    max-width: 420px;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity .15s;
}
.bx-submit:disabled { opacity: 0.4; cursor: not-allowed; }
.bx-submit:not(:disabled):hover { opacity: 0.88; }

.bx-hint { font-size: 0.78rem; color: var(--text-muted); text-align: center; }

/* Hub mini-icon for Black Box */
.mini-bx-svg { width: 44px; height: 44px; display: block; }

/* ================================================================
   Snake
   ================================================================ */
.sk-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 12px 24px;
    min-height: 100dvh;
    gap: 10px;
}
.sk-view .game-header { width: 100%; }

.sk-scores {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 340px;
}
.sk-score-box {
    flex: 1;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    text-align: center;
}
.sk-score-lbl { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em; color: var(--text-muted); }
.sk-score-val { font-size: 1.15rem; font-weight: 700; }

.sk-board-wrap {
    width: 100%;
    max-width: 340px;
}
.sk-board-wrap canvas {
    width: 100%;
    height: auto;
    border-radius: 10px;
    display: block;
    touch-action: none;
}

/* D-pad */
.sk-dpad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    gap: 4px;
    place-items: center;
}
.sk-dpad-btn[data-dir="up"]    { grid-area: 1 / 2; }
.sk-dpad-btn[data-dir="left"]  { grid-area: 2 / 1; }
.sk-dpad-btn[data-dir="right"] { grid-area: 2 / 3; }
.sk-dpad-btn[data-dir="down"]  { grid-area: 3 / 2; }
.sk-dpad-btn {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background .1s, transform .08s;
    touch-action: manipulation;
}
.sk-dpad-btn:hover  { background: var(--btn-hover); }
.sk-dpad-btn:active { transform: scale(0.88); }

/* Hub mini-icon for Snake */
.mini-snake-svg { width: 44px; height: 44px; display: block; }

/* ================================================================
   Help / Instructions overlay (shared across all games)
   ================================================================ */
.help-overlay {
    position: fixed;
    inset: 0;
    background: rgba(14, 14, 22, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transition: opacity .2s;
}
.help-overlay.visible { opacity: 1; }

.help-card {
    background: var(--surface);
    border: 1px solid var(--border-thin);
    border-radius: var(--radius);
    padding: 24px 24px 20px;
    max-width: 360px;
    width: calc(100% - 32px);
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
    box-shadow: var(--shadow);
    transform: translateY(12px);
    transition: transform .2s;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.help-overlay.visible .help-card { transform: translateY(0); }

.help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.help-header h2 { font-size: 1.1rem; font-weight: 700; }

.help-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    flex-shrink: 0;
    font-size: 1.3rem;
    line-height: 1;
    transition: background .15s, color .15s;
}
.help-close:hover { background: var(--btn-hover); color: var(--text); }

.help-body { display: flex; flex-direction: column; gap: 10px; font-size: 0.9rem; line-height: 1.5; }
.help-body h3 { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-top: 4px; }
.help-body ul { padding-left: 1.2em; display: flex; flex-direction: column; gap: 4px; }
.help-body li { color: var(--text); }
.help-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }

/* ================================================================
   Minesweeper
   ================================================================ */
.ms-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 0 12px 32px;
    min-height: 100dvh;
    gap: 10px;
}
.ms-view .game-header { width: 100%; }

.ms-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 480px;
    padding: 6px 4px;
}

.ms-counter, .ms-timer-wrap {
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
    font-weight: 700;
    min-width: 72px;
    color: var(--text);
}
.ms-timer-wrap { text-align: right; }

.ms-face {
    font-size: 1.6rem;
    line-height: 1;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
}
.ms-face:hover  { background: var(--btn-hover); }
.ms-face:active { transform: scale(0.88); }

.ms-board-wrap {
    overflow-x: auto;
    width: 100%;
    display: flex;
    justify-content: center;
}

.ms-board {
    display: inline-grid;
    grid-template-columns: repeat(var(--ms-cols), var(--ms-cs));
    gap: 2px;
    padding: 4px;
    background: #0c0c1a;
    border: 1px solid var(--border-thin);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.ms-cell {
    width: var(--ms-cs);
    height: var(--ms-cs);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #3c3c68;
    border: 1px solid #5858a8;
    border-radius: 3px;
    font-size: calc(var(--ms-cs) * 0.5);
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background .1s, transform .08s;
    touch-action: manipulation;
}
.ms-cell:not(.ms-revealed):hover  { background: #4a4a7e; }
.ms-cell:not(.ms-revealed):active { transform: scale(0.88); }

.ms-cell.ms-revealed {
    background: #12121e;
    border-color: transparent;
    cursor: default;
}
.ms-cell.ms-flagged { background: #3c3c68; }

.ms-cell.ms-exploded      { background: #5a1010; }
.ms-cell.ms-mine-revealed { background: #1e1e30; }
.ms-cell.ms-wrong-flag    { background: #5a1010; }

@media (prefers-color-scheme: light) {
    .ms-board { background: #a8a8c8; }
    .ms-cell  { background: #c0c0dc; border-color: #9898c0; }
    .ms-cell:not(.ms-revealed):hover { background: #cacae8; }
    .ms-cell.ms-revealed      { background: #e8e8f8; border-color: transparent; }
    .ms-cell.ms-flagged       { background: #c0c0dc; }
    .ms-cell.ms-exploded      { background: #f87171; border-color: #ef4444; }
    .ms-cell.ms-mine-revealed { background: #dcdcf0; }
    .ms-cell.ms-wrong-flag    { background: #f87171; border-color: #ef4444; }
}

/* Adjacency number colours */
.ms-cell.ms-n1 { color: #4a90ff; }
.ms-cell.ms-n2 { color: #4ade80; }
.ms-cell.ms-n3 { color: #ff5577; }
.ms-cell.ms-n4 { color: #a855f7; }
.ms-cell.ms-n5 { color: #f97316; }
.ms-cell.ms-n6 { color: #06b6d4; }
.ms-cell.ms-n7 { color: #ec4899; }
.ms-cell.ms-n8 { color: var(--text-muted); }

@media (prefers-color-scheme: light) {
    .ms-cell.ms-n1 { color: #1d4ed8; }
    .ms-cell.ms-n2 { color: #15803d; }
    .ms-cell.ms-n3 { color: #b91c1c; }
    .ms-cell.ms-n4 { color: #6d28d9; }
    .ms-cell.ms-n5 { color: #c2410c; }
    .ms-cell.ms-n6 { color: #0e7490; }
    .ms-cell.ms-n7 { color: #9d174d; }
    .ms-cell.ms-n8 { color: var(--text-muted); }
}

.ms-result {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    width: 100%;
    max-width: 480px;
    flex-wrap: wrap;
}
.ms-win  { background: rgba(74, 222, 128, 0.12); color: var(--success); }
.ms-loss { background: rgba(255, 85, 119, 0.12); color: var(--error-text); }

.ms-play-again {
    margin-left: auto;
    padding: 6px 14px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 700;
    transition: opacity .15s;
}
.ms-play-again:hover { opacity: 0.85; }

/* Hub mini-icon for Minesweeper */
.mini-ms-svg { width: 44px; height: 44px; display: block; }
