:root {
    --bg: #020617;
    --panel: rgba(15, 23, 42, 0.78);
    --text: #e5e7eb;
    --soft: #cbd5f5;
    --muted: #94a3b8;
    --cyan: #38bdf8;
    --green: #22c55e;
    --purple: #a78bfa;
    --amber: #f59e0b;
    --pink: #ec4899;
    --red: #ef4444;
    --border: rgba(34, 197, 94, 0.3);
    --shadow: rgba(34, 197, 94, 0.18);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    background:
        radial-gradient(circle at 16% 12%, rgba(34, 197, 94, 0.15), transparent 28%),
        radial-gradient(circle at 84% 18%, rgba(56, 189, 248, 0.13), transparent 28%),
        radial-gradient(circle at 50% 84%, rgba(245, 158, 11, 0.1), transparent 34%),
        linear-gradient(180deg, #020617 0%, #050816 52%, #020617 100%);
    color: var(--text);
    font-family: Inter, "Segoe UI", system-ui, sans-serif;
    margin: 0;
    min-height: 100vh;
    overflow: hidden;
}

.game-shell {
    align-items: center;
    display: flex;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: clamp(8px, 2.2vh, 24px);
    width: 100%;
}

.game-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 0 42px var(--shadow), inset 0 0 36px rgba(2, 6, 23, 0.42);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    margin: 0 auto;
    max-height: min(960px, calc(100dvh - clamp(16px, 4.4vh, 48px)));
    max-width: 1040px;
    min-width: 0;
    overflow: hidden;
    width: 100%;
}

.game-topbar {
    align-items: center;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.94), rgba(2, 6, 23, 0.86));
    border-bottom: 1px solid var(--border);
    display: grid;
    gap: 16px;
    grid-template-columns: auto 1fr auto;
    min-width: 0;
    padding: 14px 18px;
}

.back-link,
.controls button,
.board-hud button,
.overlay-card button {
    background: rgba(2, 6, 23, 0.78);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--green);
    cursor: pointer;
    font: 700 12px/1 Inter, "Segoe UI", system-ui, sans-serif;
    letter-spacing: 0;
    padding: 10px 12px;
    text-decoration: none;
}

.back-link:hover,
.controls button:hover,
.board-hud button:hover,
.overlay-card button:hover,
.back-link:focus-visible,
.controls button:focus-visible,
.board-hud button:focus-visible,
.overlay-card button:focus-visible {
    box-shadow: 0 0 16px var(--shadow);
    outline: 1px solid var(--green);
}

.game-title {
    min-width: 0;
}

.game-title h1 {
    color: var(--green);
    font-size: 22px;
    line-height: 1.1;
    margin: 0;
    text-shadow: 0 0 16px rgba(34, 197, 94, 0.36);
}

.game-title p {
    color: var(--muted);
    font: 600 12px/1.4 "SFMono-Regular", Consolas, monospace;
    margin: 4px 0 0;
}

.scoreboard {
    display: flex;
    gap: 10px;
    min-width: 0;
}

.scoreboard div,
.run-stat {
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: 7px;
    padding: 8px 10px;
}

.scoreboard div {
    min-width: 104px;
    text-align: right;
}

.scoreboard span,
.run-stat span {
    color: var(--muted);
    display: block;
    font: 700 10px/1 "SFMono-Regular", Consolas, monospace;
    text-transform: uppercase;
}

.scoreboard strong,
.run-stat strong {
    color: var(--cyan);
    display: block;
    font: 800 22px/1.1 "SFMono-Regular", Consolas, monospace;
    margin-top: 4px;
}

.arena-wrap {
    align-items: center;
    background:
        linear-gradient(rgba(34, 197, 94, 0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(56, 189, 248, 0.08) 1px, transparent 1px),
        radial-gradient(circle at 50% 48%, rgba(34, 197, 94, 0.12), transparent 38%),
        #030712;
    background-size: 54px 54px, 54px 54px, auto, auto;
    display: flex;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
    padding: clamp(10px, 2vh, 18px);
    position: relative;
}

.play-layout {
    align-items: stretch;
    display: grid;
    gap: clamp(12px, 2vw, 18px);
    grid-template-columns: minmax(0, 1fr) minmax(104px, 138px);
    height: 100%;
    justify-content: center;
    max-width: 820px;
    min-width: 0;
    outline: none;
    width: 100%;
}

.board-column {
    display: grid;
    gap: clamp(8px, 1.5vh, 14px);
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 0;
    min-width: 0;
}

.board-viewport {
    container-type: size;
    display: grid;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    place-items: safe center;
    scrollbar-color: var(--green) var(--bg);
    scrollbar-width: thin;
    border-radius: 10px;
}

.board-scroll-hint {
    color: var(--soft);
    font: 500 12px/1.3 "SFMono-Regular", Consolas, monospace;
    margin: 0;
}

.board-column:not(.is-scrollable) .board-scroll-hint {
    visibility: hidden;
}

.play-layout:focus-visible,
.difficulty-select input:focus-visible + span {
    outline: 2px solid var(--cyan);
    outline-offset: -2px;
}

.board-hud {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.board-hud span {
    background: rgba(2, 6, 23, 0.72);
    border: 1px solid rgba(34, 197, 94, 0.24);
    border-radius: 999px;
    color: var(--soft);
    font: 800 11px/1 "SFMono-Regular", Consolas, monospace;
    padding: clamp(8px, 1.4vh, 10px) 13px;
    text-transform: uppercase;
}

.board {
    --grid-size: 9;
    aspect-ratio: 1;
    background:
        radial-gradient(circle at 50% 50%, rgba(34, 197, 94, 0.08), transparent 58%),
        rgba(2, 6, 23, 0.82);
    border: 1px solid rgba(34, 197, 94, 0.38);
    border-radius: 10px;
    box-shadow: 0 0 34px rgba(34, 197, 94, 0.16), inset 0 0 28px rgba(2, 6, 23, 0.62);
    display: grid;
    gap: clamp(3px, 0.65vw, 6px);
    grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
    grid-template-rows: repeat(var(--grid-size), minmax(0, 1fr));
    height: min(100cqw, 100cqh, 560px);
    width: min(100cqw, 100cqh, 560px);
    justify-self: center;
    padding: clamp(8px, 1.5vw, 12px);
    touch-action: manipulation;
}

.tile {
    appearance: none;
    background-color: #0f172a;
    background-image: url("../images/tile.svg");
    background-size: cover;
    border: 1px solid rgba(34, 197, 94, 0.24);
    border-radius: 7px;
    color: var(--green);
    cursor: pointer;
    font: 900 clamp(11px, 2.2vw, 20px)/1 "SFMono-Regular", Consolas, monospace;
    min-width: 0;
    padding: 0;
    position: relative;
    text-shadow: 0 0 12px currentColor;
}

.tile.cursor {
    outline: 2px solid rgba(248, 250, 252, 0.8);
    outline-offset: -2px;
}

.tile.revealed {
    background: rgba(2, 6, 23, 0.78);
    border-color: rgba(56, 189, 248, 0.2);
    cursor: default;
}

.tile.flagged::before,
.tile.mine::before,
.tile.exploded::after {
    background-position: center;
    background-repeat: no-repeat;
    background-size: 76% 76%;
    content: "";
    inset: 0;
    pointer-events: none;
    position: absolute;
}

.tile.flagged::before {
    background-image: url("../images/flag.svg");
}

.tile.mine::before {
    background-image: url("../images/mine.svg");
}

.tile.exploded::after {
    background-image: url("../images/blast.svg");
    animation: blastPop 0.32s ease both;
    inset: -14%;
}

.tile[data-count="1"] {
    color: #38bdf8;
}

.tile[data-count="2"] {
    color: #22c55e;
}

.tile[data-count="3"] {
    color: #f59e0b;
}

.tile[data-count="4"],
.tile[data-count="5"],
.tile[data-count="6"],
.tile[data-count="7"],
.tile[data-count="8"] {
    color: #ec4899;
}

.side-panel {
    display: grid;
    gap: 10px;
    grid-auto-rows: max-content;
    min-width: 0;
}

.run-stat {
    background: rgba(2, 6, 23, 0.56);
}

.countdown-overlay {
    align-items: center;
    background:
        radial-gradient(circle at center, rgba(34, 197, 94, 0.2), transparent 42%),
        rgba(2, 6, 23, 0.26);
    display: flex;
    flex-direction: column;
    gap: 12px;
    inset: 0;
    justify-content: center;
    pointer-events: none;
    position: absolute;
    z-index: 9;
}

.countdown-overlay.hidden {
    display: none;
}

.countdown-ring {
    --countdown-accent: var(--green);
    align-items: center;
    aspect-ratio: 1;
    background:
        linear-gradient(#020617, #020617) padding-box,
        conic-gradient(from -90deg, var(--countdown-accent), var(--cyan), var(--amber), var(--countdown-accent)) border-box;
    border: 4px solid transparent;
    border-radius: 50%;
    box-shadow: 0 0 34px color-mix(in srgb, var(--countdown-accent) 45%, transparent), inset 0 0 24px rgba(2, 6, 23, 0.9);
    display: grid;
    justify-items: center;
    width: clamp(118px, 20vw, 178px);
}

.countdown-ring span {
    color: var(--text);
    font: 950 clamp(48px, 9vw, 86px)/1 "SFMono-Regular", Consolas, monospace;
    text-shadow: 0 0 16px var(--countdown-accent), 0 4px 0 rgba(2, 6, 23, 0.72);
}

.countdown-overlay small {
    background: rgba(2, 6, 23, 0.72);
    border: 1px solid rgba(34, 197, 94, 0.28);
    border-radius: 999px;
    color: var(--soft);
    font: 800 11px/1 "SFMono-Regular", Consolas, monospace;
    padding: 9px 13px;
    text-transform: uppercase;
}

.countdown-overlay.pulse .countdown-ring {
    animation: countdownPop 0.7s ease both;
}

.countdown-overlay.go .countdown-ring {
    --countdown-accent: var(--cyan);
}

.countdown-overlay.go .countdown-ring span {
    color: var(--cyan);
}

[hidden] { display: none !important; }
.tile.wrong-flag { color: #f8fafc; background: #7f1d1d; font-weight: 900; }
.tile.wrong-flag::before, .tile.wrong-flag::after { display: none; }

.controls {
    background: rgba(2, 6, 23, 0.72);
    border-top: 1px solid var(--border);
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    padding: clamp(8px, 1.6vh, 12px) 18px;
}

.controls button {
    min-height: clamp(34px, 5vh, 38px);
    min-width: 0;
}

.overlay {
    align-items: center;
    background:
        radial-gradient(circle at 30% 28%, rgba(34, 197, 94, 0.18), transparent 30%),
        radial-gradient(circle at 72% 64%, rgba(56, 189, 248, 0.16), transparent 28%),
        linear-gradient(135deg, rgba(2, 6, 23, 0.92), rgba(2, 6, 23, 0.64));
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 18px;
    position: absolute;
    z-index: 10;
}

.overlay.hidden {
    display: none;
}

.overlay-card {
    align-items: center;
    background:
        linear-gradient(135deg, rgba(15, 23, 42, 0.94), rgba(2, 6, 23, 0.84)),
        radial-gradient(circle at 14% 16%, rgba(34, 197, 94, 0.16), transparent 34%);
    border: 1px solid rgba(34, 197, 94, 0.38);
    border-radius: 10px;
    box-shadow: 0 0 34px rgba(34, 197, 94, 0.2), inset 0 0 28px rgba(2, 6, 23, 0.62);
    display: grid;
    gap: 22px;
    grid-template-columns: minmax(160px, 0.55fr) minmax(300px, 1fr);
    grid-template-areas: "visual content" "visual actions";
    grid-template-rows: minmax(0, 1fr) auto;
    max-height: 100%;
    max-width: 800px;
    overflow: hidden;
    padding: 22px;
    position: relative;
    width: min(92vw, 800px);
}

.overlay-end .overlay-card {
    border-color: rgba(245, 158, 11, 0.42);
    box-shadow: 0 0 36px rgba(245, 158, 11, 0.2), inset 0 0 30px rgba(127, 29, 29, 0.16);
}

.overlay-card::before {
    background: linear-gradient(90deg, transparent, rgba(34, 197, 94, 0.75), transparent);
    content: "";
    height: 1px;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
}

.overlay-visual {
    grid-area: visual;
    aspect-ratio: 1;
    min-width: 0;
}

.overlay-preview {
    display: block;
    filter: drop-shadow(0 0 24px rgba(34, 197, 94, 0.28));
    height: 100%;
    object-fit: contain;
    width: 100%;
}

.overlay-content {
    grid-area: content;
    align-self: stretch;
    min-height: 0;
    min-width: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    padding: 2px;
}

.overlay-actions {
    grid-area: actions;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.overlay-card .overlay-actions > * {
    flex: 1 1 95px; min-width: 0; min-height: 44px;
    padding-inline: 4px; line-height: 1.25; overflow-wrap: anywhere;
}

.overlay-content:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; }

.overlay-actions .back-link { display: flex; align-items: center; justify-content: center; }

.overlay-actions button {
    min-height: 44px;
}

.overlay-mode {
    color: var(--green);
    display: block;
    font: 800 11px/1.2 "SFMono-Regular", Consolas, monospace;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.overlay-end .overlay-mode {
    color: var(--amber);
}

.overlay-card h2 {
    color: var(--cyan);
    font-size: clamp(30px, 5vw, 52px);
    line-height: 1.1;
    margin: 0 0 10px;
}

.overlay-card p {
    color: var(--soft);
    line-height: 1.55;
    margin: 0 0 18px;
    max-width: 470px;
}

.overlay-stats {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0 0 14px;
}

.overlay-stats div {
    background: rgba(2, 6, 23, 0.62);
    border: 1px solid rgba(34, 197, 94, 0.24);
    border-radius: 7px;
    padding: 10px;
}

.overlay-stats span {
    color: var(--muted);
    display: block;
    font: 800 10px/1 "SFMono-Regular", Consolas, monospace;
    text-transform: uppercase;
}

.overlay-stats strong {
    color: var(--green);
    display: block;
    font: 800 18px/1.1 "SFMono-Regular", Consolas, monospace;
    margin-top: 6px;
}

.difficulty-select {
    border: 0;
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0 0 14px;
    padding: 0;
}

.difficulty-select legend {
    color: var(--muted);
    font: 800 10px/1 "SFMono-Regular", Consolas, monospace;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.difficulty-select label {
    cursor: pointer;
}

.difficulty-select input {
    inline-size: 1px;
    opacity: 0;
    position: absolute;
}

.difficulty-select span {
    background: rgba(2, 6, 23, 0.62);
    border: 1px solid rgba(34, 197, 94, 0.22);
    border-radius: 8px;
    display: grid;
    gap: 4px;
    padding: 10px;
}

.difficulty-select input:checked + span {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(2, 6, 23, 0.88));
    border-color: rgba(34, 197, 94, 0.56);
    box-shadow: 0 0 18px rgba(34, 197, 94, 0.18);
}

.difficulty-select strong {
    color: var(--text);
    font-size: 13px;
}

.difficulty-select small {
    color: var(--muted);
    font: 700 10px/1.2 "SFMono-Regular", Consolas, monospace;
}

.rules-panel {
    background: rgba(2, 6, 23, 0.54);
    border: 1px solid rgba(56, 189, 248, 0.24);
    border-radius: 8px;
    margin: 0 0 18px;
    padding: 12px 14px;
}

.rules-panel strong {
    color: var(--cyan);
    display: block;
    font: 800 11px/1 "SFMono-Regular", Consolas, monospace;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.rules-panel ul {
    color: var(--soft);
    display: grid;
    gap: 7px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.rules-panel li {
    font-size: 13px;
    line-height: 1.35;
    padding-left: 16px;
    position: relative;
}

.rules-panel li::before {
    background: var(--green);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.58);
    content: "";
    height: 6px;
    left: 0;
    position: absolute;
    top: 0.48em;
    width: 6px;
}

.overlay-card button {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.22), rgba(2, 6, 23, 0.88));
    border-color: rgba(34, 197, 94, 0.42);
    box-shadow: 0 0 18px rgba(34, 197, 94, 0.12);
    min-width: 132px;
}

.overlay-end .overlay-card h2,
.overlay-end .overlay-stats strong,
.overlay-end .overlay-card button {
    color: var(--amber);
}

@keyframes blastPop {
    0% {
        opacity: 0;
        transform: scale(0.55) rotate(-12deg);
    }

    60% {
        opacity: 1;
        transform: scale(1.08) rotate(6deg);
    }

    100% {
        opacity: 0.72;
        transform: scale(1) rotate(0);
    }
}

@keyframes countdownPop {
    0% {
        opacity: 0;
        transform: scale(0.72) rotate(-5deg);
    }

    55% {
        opacity: 1;
        transform: scale(1.08) rotate(2deg);
    }

    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@media (max-width: 780px) {
    .game-shell {
        min-height: 100dvh;
        padding: 8px;
    }

    .game-panel {
        max-width: calc(100dvw - 16px);
    }

    .game-topbar {
        gap: 10px;
        grid-template-columns: auto 1fr;
        padding: 10px 12px;
    }

    .back-link,
    .game-title {
        grid-row: 1;
    }

    .scoreboard {
        grid-column: 1 / -1;
        justify-content: space-between;
    }

    .scoreboard div {
        flex: 1;
        min-width: 0;
    }

    .play-layout {
        grid-template-columns: minmax(0, 1fr) minmax(82px, 104px);
    }

    .board {
        height: min(100cqw, 100cqh, 520px);
        width: min(100cqw, 100cqh, 520px);
    }

    .controls {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        padding: 10px;
    }

    .overlay-card {
        grid-template-columns: 1fr;
        grid-template-areas: "content" "actions";
        max-height: 100%;
        max-width: 560px;
        text-align: center;
    }

    .overlay-visual {
        display: none;
    }
}

@media (max-width: 520px) {
    .game-shell {
        padding: 6px;
    }

    .game-panel {
        border-radius: 8px;
        max-width: min(390px, calc(100dvw - 12px));
        width: min(390px, calc(100dvw - 12px));
    }

    .game-title h1 {
        font-size: 19px;
    }

    .game-title p {
        font-size: 11px;
    }

    .scoreboard strong {
        font-size: 19px;
    }

    .arena-wrap {
        padding: 8px;
    }

    .play-layout {
        gap: 8px;
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .side-panel {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        order: 2;
    }

    .board-hud {
        gap: 8px;
    }

    .board-hud span,
    .board-hud button {
        padding: 8px 9px;
    }

    .board {
        gap: 3px;
        height: min(100cqw, 100cqh, 342px);
        width: min(100cqw, 100cqh, 342px);
        padding: 7px;
    }

    .run-stat {
        padding: 7px;
    }

    .run-stat strong {
        font-size: 18px;
    }

    .controls button {
        padding: 10px 6px;
    }

    .overlay {
        padding: 12px;
    }

    .overlay-card {
        gap: 12px;
        max-height: 100%;
        max-width: min(342px, calc(100dvw - 44px));
        padding: 16px;
        width: min(342px, calc(100dvw - 44px));
    }

    .overlay-card h2 {
        font-size: 30px;
        margin-bottom: 8px;
    }

    .overlay-card p {
        font-size: 14px;
        line-height: 1.35;
        margin-bottom: 12px;
    }

    .overlay-stats,
    .difficulty-select {
        grid-template-columns: 1fr;
        margin-bottom: 12px;
    }

    .overlay-stats div {
        align-items: center;
        display: flex;
        justify-content: space-between;
        padding: 8px 10px;
    }

    .overlay-stats strong {
        margin-top: 0;
    }

    .rules-panel {
        margin-bottom: 12px;
        padding: 10px;
        text-align: left;
    }
}

/* Keep shell chrome bounded; only the minefield and dialog content scroll. */
@media (max-width: 780px), (max-height: 600px) {
    .game-shell {
        min-height: 0;
        padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    }

    .game-panel { max-height: 100%; }
    .game-topbar { gap: 6px; padding: 6px 8px; }
    .back-link { display: flex; align-items: center; justify-content: center; }
    .back-link, .board-hud button, .controls button { min-height: 44px; }
    .scoreboard div { padding: 4px 8px; }
    .scoreboard span, .run-stat span { font-size: 11px; }
    .arena-wrap { padding: 6px; }
    .board-column { gap: 5px; }
    .play-layout { gap: 5px; }
    .side-panel { gap: 5px; }
    .run-stat { padding: 4px 6px; }
    .run-stat strong { font-size: 16px; }
    .controls { gap: 5px; padding: 6px; }
    .controls button { padding: 6px 3px; line-height: 1.2; overflow-wrap: anywhere; }
    .board { min-width: calc(var(--grid-size) * 28px + 16px); min-height: calc(var(--grid-size) * 28px + 16px); }
    .overlay {
        position: fixed;
        padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }
    .overlay-card {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "content" "actions";
        gap: 10px;
        max-width: 560px;
        width: 100%;
        max-height: 100%;
        padding: 14px;
    }
    .overlay-visual { display: none; }
    .overlay-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .overlay-stats div { display: block; padding: 8px 4px; }
    .overlay-stats strong { font-size: 16px; margin-top: 5px; }
    .difficulty-select { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .difficulty-select span { min-height: 52px; padding: 8px 4px; }
    .overlay-actions button { width: 100%; }
}

@media (pointer: coarse) {
    .board {
        gap: 3px;
        padding: 7px;
        min-width: calc(var(--grid-size) * 47px + 13px);
        min-height: calc(var(--grid-size) * 47px + 13px);
    }
    .back-link, .board-hud button, .controls button { min-height: 44px; }
}

@media (max-height: 500px) and (min-width: 480px) {
    .game-panel { width: 100%; max-width: 1040px; }
    .game-topbar { grid-template-columns: auto minmax(0, 1fr) auto; }
    .game-title h1 { font-size: 17px; }
    .game-title p { font-size: 11px; }
    .scoreboard { grid-column: auto; gap: 4px; }
    .scoreboard div { min-width: 54px; }
    .scoreboard strong { font-size: 16px; }
    .play-layout { grid-template-columns: minmax(0, 1fr) 76px; grid-template-rows: minmax(0, 1fr); }
    .side-panel { grid-template-columns: 1fr; }
    .controls { grid-template-columns: repeat(8, minmax(0, 1fr)); }
    .board-hud span { padding: 5px; }
    .board-scroll-hint { font-size: 11px; }
    .countdown-ring { width: 90px; }
    .countdown-ring span { font-size: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* Very short narrow windows keep the field beside, not underneath, eight controls. */
@media (max-width: 479px) and (max-height: 500px) {
    .game-panel {
        width: 100%; max-width: 1040px;
        grid-template-columns: minmax(0, 1fr) 104px;
        grid-template-rows: auto minmax(0, 1fr);
    }
    .game-topbar { grid-column: 1 / -1; }
    .game-title h1 { font-size: 17px; }
    .game-title p { display: none; }
    .scoreboard div { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
    .scoreboard strong { margin: 0; font-size: 16px; }
    .arena-wrap { grid-column: 1; grid-row: 2; padding: 5px; }
    .controls {
        grid-column: 2; grid-row: 2; grid-template-columns: repeat(2, minmax(44px, 1fr));
        align-content: center; gap: 4px; padding: 4px;
        border-top: 0; border-left: 1px solid var(--border);
    }
    .controls button { font-size: 11px; }
    /* Restart exposes exactly the same settings action in the adjacent control bank. */
    .board-hud #newGameButton { display: none; }
    .board-hud span { width: 100%; padding: 5px; line-height: 1.2; overflow-wrap: anywhere; }
    .board-scroll-hint { font-size: 11px; line-height: 1.2; }
    .side-panel { gap: 3px; }
    .run-stat { padding: 4px 2px; }
    .run-stat span { font-size: 10px; }
    .run-stat strong { font-size: 12px; }
}
