:root {
    --bg: #050a12;
    --panel: rgba(9, 20, 32, 0.88);
    --text: #f4fbff;
    --soft: #c9e9f4;
    --muted: #8fb2bf;
    --cyan: #55e8ff;
    --pink: #ff5ec4;
    --amber: #ffd166;
    --green: #5dffb1;
    --violet: #9b72ff;
    --border: rgba(85, 232, 255, 0.28);
    --shadow: rgba(85, 232, 255, 0.2);
}

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

body {
    background:
        radial-gradient(circle at 16% 10%, rgba(85, 232, 255, 0.14), transparent 30%),
        radial-gradient(circle at 84% 18%, rgba(255, 94, 196, 0.12), transparent 28%),
        radial-gradient(circle at 50% 86%, rgba(93, 255, 177, 0.11), transparent 34%),
        linear-gradient(180deg, #030811 0%, #0b1824 56%, #050a12 100%);
    color: var(--text);
    font-family: Inter, "Segoe UI", system-ui, sans-serif;
    margin: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.game-shell {
    align-items: center;
    display: flex;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    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));
    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: 900px;
    min-height: 0;
    position: relative;
    max-width: 1080px;
    min-width: 0;
    overflow: hidden;
    width: 100%;
}

.game-topbar {
    align-items: center;
    background: linear-gradient(180deg, rgba(9, 20, 32, 0.96), rgba(3, 9, 16, 0.92));
    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,
.number-pad button,
.board-hud button,
.overlay-card button {
    background: rgba(3, 9, 16, 0.78);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--cyan);
    cursor: pointer;
    font: 800 11px/1.25 Inter, "Segoe UI", system-ui, sans-serif;
    letter-spacing: 0;
    padding: 10px 12px;
    text-decoration: none;
    touch-action: manipulation;
    text-transform: none;
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
button:disabled { opacity: .55; cursor: default; }
.overlay-scroll:focus-visible, .how-to-scroll:focus-visible, .side-panel:focus-visible, #statusText:focus-visible, .board-viewport:focus-visible { outline: 2px solid var(--cyan); outline-offset: -3px; }
.difficulty-select input:focus-visible + span { outline: 2px solid var(--cyan); outline-offset: 2px; }

.controls button.selected {
    background: linear-gradient(135deg, rgba(93, 255, 177, 0.22), rgba(3, 9, 16, 0.88));
    border-color: rgba(93, 255, 177, 0.58);
    color: var(--green);
}

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

.game-title {
    min-width: 0;
    text-align: center;
}

.game-title h1 {
    color: var(--text);
    font-size: 24px;
    line-height: 1.05;
    margin: 0;
    text-shadow: 0 0 16px rgba(85, 232, 255, 0.42), 0 0 22px rgba(93, 255, 177, 0.22);
    text-transform: uppercase;
}

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

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

.scoreboard div,
.run-stat {
    border: 1px solid rgba(85, 232, 255, 0.24);
    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: 800 10px/1 "SFMono-Regular", Consolas, monospace;
    text-transform: uppercase;
}

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

.scoreboard strong.score-milestone {
    animation: scoreMilestone 0.92s ease both;
    color: #ffe48a;
}

.arena-wrap {
    align-items: center;
    background:
        linear-gradient(rgba(85, 232, 255, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(93, 255, 177, 0.07) 1px, transparent 1px),
        radial-gradient(circle at 50% 48%, rgba(85, 232, 255, 0.12), transparent 40%),
        #030a12;
    background-size: 48px 48px, 48px 48px, auto, auto;
    display: flex;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
    padding: 8px;
    position: static;
}

.play-layout {
    align-items: stretch;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) 120px;
    height: 100%;
    justify-content: center;
    max-width: 930px;
    min-height: 0;
    min-width: 0;
    outline: none;
    width: 100%;
}

.play-layout.note-mode-active .board {
    box-shadow: 0 0 30px rgba(155, 114, 255, 0.2), inset 0 0 0 2px rgba(155, 114, 255, 0.32);
}

.play-layout.note-mode-active .board-hud span {
    border-color: rgba(155, 114, 255, 0.42);
    color: #d8ccff;
}

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

.board-hud { min-width: 0; }
.board-hud span { display: block; color: var(--soft); font: 700 11px/1.4 "SFMono-Regular", Consolas, monospace; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 3px 4px; }
.board-viewport { min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 6px; touch-action: pan-x pan-y; scrollbar-color: var(--cyan) #061420; scrollbar-width: thin; }

.board {
    aspect-ratio: 1;
    background:
        radial-gradient(circle at 50% 50%, rgba(85, 232, 255, 0.08), transparent 58%),
        rgba(3, 9, 16, 0.86);
    border: 2px solid rgba(85, 232, 255, 0.44);
    border-radius: 10px;
    box-shadow: 0 0 34px rgba(85, 232, 255, 0.16), inset 0 0 28px rgba(2, 6, 23, 0.62);
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    grid-template-rows: repeat(9, minmax(0, 1fr));
    width: calc(var(--cell-edge, 44px) * 9 + 12px);
    height: calc(var(--cell-edge, 44px) * 9 + 12px);
    margin: 0 auto;
    justify-self: center;
    padding: 4px;
    position: relative;
    touch-action: pan-x pan-y;
}

.board.board-complete {
    animation: boardComplete 1.1s ease both;
}

.board.board-complete::after {
    animation: boardSpark 1.1s ease both;
    background: url("../images/logic-spark.svg") center / contain no-repeat;
    content: "";
    filter: drop-shadow(0 0 22px rgba(255, 209, 102, 0.5));
    height: clamp(68px, 14vw, 118px);
    left: 50%;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.72);
    width: clamp(68px, 14vw, 118px);
    z-index: 3;
}

.cell {
    appearance: none;
    background: rgba(3, 9, 16, 0.76);
    border: 1px solid rgba(85, 232, 255, 0.15);
    color: var(--cyan);
    cursor: pointer;
    display: grid;
    min-height: 0;
    min-width: 0;
    padding: 0;
    place-items: center;
    position: relative;
}

.cell > * {
    position: relative;
    z-index: 1;
}

.cell:nth-child(3n) {
    border-right-color: rgba(255, 209, 102, 0.55);
}

.cell:nth-child(9n) {
    border-right-color: rgba(85, 232, 255, 0.15);
}

.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom-color: rgba(255, 209, 102, 0.55);
}

.cell.peer {
    background: rgba(85, 232, 255, 0.08);
}

.cell.selected {
    background:
        linear-gradient(rgba(12, 36, 30, 0.5), rgba(12, 36, 30, 0.5)),
        url("../images/cell-active.svg") center / cover no-repeat;
    box-shadow: inset 0 0 0 2px rgba(93, 255, 177, 0.78), 0 0 16px rgba(93, 255, 177, 0.2);
}

.cell:focus-visible {
    outline: 2px solid rgba(255, 209, 102, 0.88);
    outline-offset: -4px;
}

.note-mode-active .cell.selected {
    box-shadow: inset 0 0 0 2px rgba(155, 114, 255, 0.88), 0 0 18px rgba(155, 114, 255, 0.24);
}

.cell.given {
    background-image: url("../images/cell-given.svg");
    background-size: cover;
    color: var(--amber);
    font-weight: 900;
}

.cell.given.selected {
    background:
        linear-gradient(rgba(12, 36, 30, 0.34), rgba(12, 36, 30, 0.34)),
        url("../images/cell-active.svg") center / cover no-repeat;
}

.cell.matching:not(.selected) {
    background: linear-gradient(135deg, rgba(255, 209, 102, 0.16), rgba(3, 9, 16, 0.72));
    box-shadow: inset 0 0 0 1px rgba(255, 209, 102, 0.34), 0 0 10px rgba(255, 209, 102, 0.14);
}

.cell.wrong {
    color: var(--pink);
    text-shadow: 0 0 12px rgba(255, 94, 196, 0.8);
}

.cell.spark-lock {
    animation: lockPulse 0.52s ease-out both;
}

.cell.spark-wrong {
    animation: wrongDigitPulse 0.44s ease-out both;
}

.cell.unit-complete {
    animation: unitScan 0.82s ease-out both;
    overflow: hidden;
}

.cell.unit-complete::after {
    animation: unitSweep 0.82s ease-out both;
    background: linear-gradient(90deg, transparent, rgba(93, 255, 177, 0.52), rgba(85, 232, 255, 0.42), transparent);
    content: "";
    inset: 0;
    pointer-events: none;
    position: absolute;
    transform: translateX(-110%);
    z-index: 2;
}

.cell.milestone-glow {
    animation: milestoneCellGlow 0.92s ease-out both;
}

.cell.milestone-glow::before {
    animation: milestoneCellSweep 0.92s ease-out both;
    background: linear-gradient(135deg, transparent, rgba(255, 225, 110, 0.36), transparent);
    content: "";
    inset: 0;
    pointer-events: none;
    position: absolute;
    z-index: 2;
}

.cell.duplicate-conflict {
    background:
        linear-gradient(135deg, rgba(255, 94, 196, 0.22), rgba(3, 9, 16, 0.72)),
        repeating-linear-gradient(135deg, transparent 0 9px, rgba(255, 94, 196, 0.14) 9px 11px);
    box-shadow: inset 0 0 0 2px rgba(255, 94, 196, 0.46), 0 0 12px rgba(255, 94, 196, 0.18);
}

.cell.check-conflict {
    animation: checkConflictPulse 0.95s ease both;
    box-shadow: inset 0 0 0 2px rgba(255, 94, 196, 0.78), 0 0 18px rgba(255, 94, 196, 0.32);
}

.cell.spark {
    overflow: visible;
}

.logic-spark {
    background: url("../images/logic-spark.svg") center / contain no-repeat;
    filter: drop-shadow(0 0 12px rgba(255, 209, 102, 0.72));
    height: 86%;
    left: 50%;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.42) rotate(-8deg);
    width: 86%;
    z-index: 2;
}

.cell.spark-lock .logic-spark {
    animation: cellSpark 0.52s ease-out both;
}

.cell.spark-hint .logic-spark {
    animation: hintSpark 0.62s ease-out both;
}

.digit {
    font: 900 var(--digit-size, 24px)/1 "SFMono-Regular", Consolas, monospace;
}

.notes {
    color: var(--muted);
    display: grid;
    font: 700 var(--note-size, 11px)/1 "SFMono-Regular", Consolas, monospace;
    gap: 1px;
    grid-template-columns: repeat(3, 1fr);
    height: 86%;
    opacity: 0.86;
    width: 86%;
}

.notes i {
    display: grid;
    font-style: normal;
    place-items: center;
}

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

.run-stat {
    background: rgba(3, 9, 16, 0.58);
}

.countdown-overlay {
    align-items: center;
    background: radial-gradient(circle at center, rgba(85, 232, 255, 0.2), transparent 42%), rgba(3, 9, 16, 0.28);
    display: flex;
    flex-direction: column;
    gap: 12px;
    inset: 0;
    justify-content: center;
    pointer-events: none;
    position: absolute;
    z-index: 9;
}

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

.countdown-ring {
    --countdown-accent: var(--green);
    align-items: center;
    aspect-ratio: 1;
    background: linear-gradient(#050a12, #050a12) 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(3, 9, 16, 0.72);
    border: 1px solid rgba(85, 232, 255, 0.28);
    border-radius: 999px;
    color: var(--soft);
    font: 900 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(--amber);
}

.controls {
    background: rgba(3, 9, 16, 0.74);
    border-top: 1px solid var(--border);
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(428px, 1fr) repeat(5, minmax(44px, 70px));
    justify-content: center;
    padding: 8px;
    min-width: 0;
}

.number-pad {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(9, minmax(0, 1fr));
}

.number-pad button,
.controls > button {
    min-height: 44px;
    padding: 8px 7px;
}

.number-pad button {
    color: var(--amber);
    display: grid;
    font-size: 15px;
    gap: 2px;
    justify-items: center;
    line-height: 1;
    overflow: hidden;
}

.number-pad button.pad-active {
    background: linear-gradient(135deg, rgba(255, 209, 102, 0.24), rgba(3, 9, 16, 0.9));
    border-color: rgba(255, 209, 102, 0.72);
    box-shadow: 0 0 16px rgba(255, 209, 102, 0.18), inset 0 0 0 1px rgba(255, 209, 102, 0.18);
    color: var(--amber);
}

.number-pad button.pad-complete,
.number-pad button:disabled {
    border-color: rgba(143, 178, 191, 0.18);
    box-shadow: none;
    color: rgba(143, 178, 191, 0.48);
    cursor: default;
    opacity: 0.58;
}

.pad-digit {
    font: 950 15px/1 "SFMono-Regular", Consolas, monospace;
}

.pad-count {
    color: var(--muted);
    font: 900 9px/1 "SFMono-Regular", Consolas, monospace;
    text-transform: uppercase;
}

.number-pad button.pad-active .pad-count {
    color: rgba(255, 244, 209, 0.9);
}

.number-pad button.pad-complete .pad-count {
    color: rgba(143, 178, 191, 0.55);
}

.number-pad.note-mode-active button:not(:disabled) {
    background: linear-gradient(135deg, rgba(155, 114, 255, 0.18), rgba(3, 9, 16, 0.88));
    border-color: rgba(155, 114, 255, 0.42);
    color: #d8ccff;
}

.number-pad.note-mode-active button.pad-active {
    border-color: rgba(155, 114, 255, 0.8);
    box-shadow: 0 0 16px rgba(155, 114, 255, 0.26), inset 0 0 0 1px rgba(155, 114, 255, 0.24);
}

.number-pad.note-mode-active .pad-count {
    color: rgba(216, 204, 255, 0.72);
}

.overlay {
    align-items: center;
    background: radial-gradient(circle at 30% 28%, rgba(85, 232, 255, 0.16), transparent 30%), radial-gradient(circle at 72% 64%, rgba(93, 255, 177, 0.12), transparent 28%), rgba(3, 9, 16, 0.9);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: clamp(8px, 2vw, 18px);
    position: absolute;
    z-index: 10;
}

.overlay-card {
    background: linear-gradient(135deg, rgba(9, 20, 32, .99), rgba(3, 9, 16, .96));
    border: 1px solid rgba(85, 232, 255, .38);
    border-radius: 10px;
    box-shadow: 0 0 34px var(--shadow), inset 0 0 28px rgba(2, 6, 23, .62);
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
    min-width: 0;
    max-height: 100%;
    max-width: 860px;
    overflow: hidden;
    width: 100%;
}
.overlay-scroll { display: grid; align-items: center; grid-template-columns: minmax(140px, .48fr) minmax(0, 1fr); gap: 22px; padding: 22px; min-height: 0; min-width: 0; overflow: auto; overscroll-behavior: contain; }
.overlay-content { min-width: 0; }

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

.overlay-visual {
    aspect-ratio: 1;
    align-self: center;
    background: rgba(3, 9, 16, 0.42);
    border: 1px solid rgba(85, 232, 255, 0.16);
    border-radius: 10px;
    min-width: 0;
    padding: 10px;
}

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

.overlay-card h2 {
    color: var(--cyan);
    font-size: clamp(30px, 4.8vw, 48px);
    line-height: 1.05;
    margin: 0 0 8px;
    text-transform: uppercase;
}

.overlay-card p {
    color: var(--soft);
    font-size: 15px;
    line-height: 1.45;
    margin: 0 0 14px;
    max-width: 480px;
}

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

.overlay-stats div,
.puzzle-identity,
.difficulty-select span {
    background: rgba(3, 9, 16, 0.62);
    border: 1px solid rgba(85, 232, 255, 0.24);
    border-radius: 7px;
    display: block;
    min-width: 0;
    padding: 9px 10px;
}

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

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

.puzzle-identity {
    margin: 0 0 10px;
}

.puzzle-identity strong {
    color: var(--green);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.difficulty-select {
    border: 0;
    padding: 0;
}

.difficulty-select legend {
    margin-bottom: 7px;
}

.difficulty-select label {
    cursor: pointer;
    display: block;
    min-width: 0;
    position: relative;
}

.difficulty-select input {
    width: 100%;
    height: 100%;
    inset: 0;
    margin: 0;
    opacity: 0;
    position: absolute;
    cursor: pointer;
}

.difficulty-select input:checked + span {
    background: linear-gradient(135deg, rgba(93, 255, 177, 0.2), rgba(3, 9, 16, 0.88));
    border-color: rgba(93, 255, 177, 0.56);
    box-shadow: 0 0 18px rgba(93, 255, 177, 0.18);
}

.difficulty-select strong {
    color: var(--text);
    display: block;
    font-size: 13px;
    line-height: 1.1;
}

.difficulty-select small {
    color: var(--muted);
    display: block;
    font: 800 10px/1.2 "SFMono-Regular", Consolas, monospace;
    margin-top: 4px;
    overflow-wrap: anywhere;
}

.overlay-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    margin: 0;
    padding: 10px;
    border-top: 1px solid var(--border);
    background: #040d18;
    flex-wrap: wrap;
}
.overlay-actions > * { flex: 1 1 110px; }

.overlay-card button {
    background: linear-gradient(135deg, rgba(93, 255, 177, 0.22), rgba(3, 9, 16, 0.88));
    border-color: rgba(93, 255, 177, 0.42);
    min-width: 44px;
}

.overlay-card .how-to-button {
    background: linear-gradient(135deg, rgba(85, 232, 255, 0.14), rgba(3, 9, 16, 0.88));
    border-color: rgba(85, 232, 255, 0.36);
    color: var(--cyan);
    margin: 0;
}

.how-to-overlay {
    align-items: center;
    background: radial-gradient(circle at 28% 22%, rgba(85, 232, 255, 0.14), transparent 32%), rgba(2, 6, 14, 0.86);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: clamp(8px, 2vw, 18px);
    position: absolute;
    z-index: 12;
}

.how-to-overlay.hidden {
    display: none;
}

.how-to-card {
    background: linear-gradient(135deg, rgba(9, 20, 32, 0.99), rgba(3, 9, 16, 0.96));
    border: 1px solid rgba(85, 232, 255, 0.38);
    border-radius: 10px;
    box-shadow: 0 0 36px rgba(85, 232, 255, 0.2), inset 0 0 26px rgba(2, 6, 23, 0.64);
    max-height: 100%;
    min-height: 0;
    min-width: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    max-width: 860px;
    overflow: hidden;
    width: 100%;
}

.how-to-header {
    align-items: center;
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.how-to-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 14px; }
.how-to-instructions { color: var(--soft); font-size: 14px; line-height: 1.5; margin: 0 0 14px; }

.how-to-header span {
    color: var(--green);
    font: 900 11px/1 "SFMono-Regular", Consolas, monospace;
    text-transform: uppercase;
}

.how-to-header button {
    background: rgba(3, 9, 16, 0.72);
    border: 1px solid rgba(85, 232, 255, 0.34);
    border-radius: 7px;
    color: var(--cyan);
    cursor: pointer;
    font: 900 10px/1 "SFMono-Regular", Consolas, monospace;
    padding: 9px 11px;
    min-height: 44px;
    min-width: 44px;
    text-transform: uppercase;
}

.how-to-card h2 {
    color: var(--cyan);
    font-size: clamp(28px, 3.8vw, 40px);
    line-height: 1;
    margin: 10px 0 14px;
    text-transform: uppercase;
}

.how-to-body {
    display: grid;
    gap: 14px;
    grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
}

.how-to-board-panel {
    background: rgba(3, 9, 16, 0.48);
    border: 1px solid rgba(85, 232, 255, 0.2);
    border-radius: 10px;
    display: grid;
    gap: 10px;
    padding: 12px;
}

.mini-board {
    aspect-ratio: 1;
    background: rgba(3, 9, 16, 0.78);
    border: 2px solid rgba(85, 232, 255, 0.46);
    border-radius: 8px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    justify-self: center;
    max-width: 242px;
    overflow: hidden;
    padding: 6px;
    width: 100%;
}

.mini-cell {
    align-items: center;
    background: rgba(3, 9, 16, 0.86);
    border: 1px solid rgba(85, 232, 255, 0.22);
    color: var(--cyan);
    display: grid;
    font: 900 clamp(17px, 2.4vw, 21px)/1 "SFMono-Regular", Consolas, monospace;
    justify-items: center;
    min-height: 0;
}

.mini-given {
    background: rgba(255, 209, 102, 0.1);
    color: var(--amber);
}

.mini-peer {
    background: rgba(85, 232, 255, 0.08);
}

.mini-selected {
    background: rgba(93, 255, 177, 0.16);
    box-shadow: inset 0 0 0 2px rgba(93, 255, 177, 0.76);
    color: var(--green);
}

.mini-note {
    color: var(--muted);
    display: grid;
    font-size: 10px;
    gap: 2px;
    grid-template-columns: repeat(3, 1fr);
    padding: 8px;
}

.mini-note i {
    font-style: normal;
}

.mini-conflict {
    background: rgba(255, 94, 196, 0.16);
    color: var(--pink);
}

.mini-hint {
    background: rgba(255, 209, 102, 0.13);
    box-shadow: inset 0 0 0 2px rgba(255, 209, 102, 0.52);
    color: #ffe48a;
}

.mini-controls {
    align-content: center;
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-pad {
    background: rgba(3, 9, 16, 0.68);
    border: 1px solid rgba(85, 232, 255, 0.28);
    border-radius: 8px;
    color: var(--cyan);
    display: grid;
    font: 900 13px/1 "SFMono-Regular", Consolas, monospace;
    min-height: 42px;
    place-items: center;
    text-transform: uppercase;
}

.mini-notes {
    border-color: rgba(155, 114, 255, 0.5);
    color: #d8ccff;
}

.mini-hint-control {
    border-color: rgba(255, 209, 102, 0.54);
    color: var(--amber);
}

.mini-check {
    border-color: rgba(255, 94, 196, 0.45);
    color: var(--pink);
}

.how-to-legend {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: stretch;
}

.how-to-legend div {
    background: rgba(3, 9, 16, 0.56);
    border: 1px solid rgba(85, 232, 255, 0.22);
    border-radius: 8px;
    min-width: 0;
    padding: 10px 11px;
    position: relative;
}

.how-to-legend strong {
    color: var(--text);
    display: block;
    font: 900 12px/1 "SFMono-Regular", Consolas, monospace;
    margin: 0 0 6px 18px;
    text-transform: uppercase;
}

.how-to-legend p {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.3;
    margin: 0;
}

.legend-dot {
    border-radius: 50%;
    height: 9px;
    left: 10px;
    position: absolute;
    top: 11px;
    width: 9px;
}

.legend-dot.given { background: var(--amber); }
.legend-dot.selected { background: var(--green); }
.legend-dot.note { background: var(--violet); }
.legend-dot.conflict { background: var(--pink); }
.legend-dot.hint { background: #ffe48a; }
.legend-dot.check { background: var(--cyan); }

.overlay-fail .overlay-card {
    border-color: rgba(255, 94, 196, 0.48);
    box-shadow: 0 0 34px rgba(255, 94, 196, 0.18), inset 0 0 28px rgba(2, 6, 23, 0.62);
}

.overlay-fail .overlay-mode,
.overlay-fail .overlay-card h2 {
    color: var(--pink);
}

.overlay-fail .overlay-card button {
    background: linear-gradient(135deg, rgba(255, 94, 196, 0.2), rgba(3, 9, 16, 0.88));
    border-color: rgba(255, 94, 196, 0.46);
    color: var(--pink);
}

@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); }
}

@keyframes cellSpark {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.32) rotate(-14deg); }
    42% { opacity: 0.95; transform: translate(-50%, -50%) scale(1.02) rotate(8deg); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.28) rotate(18deg); }
}

@keyframes hintSpark {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.34) rotate(0deg); }
    35% { opacity: 0.9; transform: translate(-50%, -50%) scale(0.92) rotate(90deg); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.18) rotate(180deg); }
}

@keyframes lockPulse {
    0% { box-shadow: inset 0 0 0 1px rgba(85, 232, 255, 0.2); transform: scale(1); }
    42% { background-color: rgba(93, 255, 177, 0.22); box-shadow: inset 0 0 0 2px rgba(93, 255, 177, 0.84), 0 0 16px rgba(85, 232, 255, 0.34); transform: scale(1.035); }
    100% { box-shadow: inset 0 0 0 1px rgba(85, 232, 255, 0.15); transform: scale(1); }
}

@keyframes wrongDigitPulse {
    0%, 100% { transform: translateX(0) scale(1); }
    18% { background-color: rgba(255, 94, 196, 0.3); box-shadow: inset 0 0 0 2px rgba(255, 94, 196, 0.8), 0 0 16px rgba(255, 94, 196, 0.3); transform: translateX(-2px) scale(1.02); }
    38% { transform: translateX(2px) scale(1.02); }
    58% { background-color: rgba(255, 209, 102, 0.14); transform: translateX(-1px) scale(1.01); }
}

@keyframes unitScan {
    0%, 100% { box-shadow: inset 0 0 0 1px rgba(85, 232, 255, 0.15); }
    48% { background-color: rgba(85, 232, 255, 0.12); box-shadow: inset 0 0 0 2px rgba(93, 255, 177, 0.5), 0 0 12px rgba(85, 232, 255, 0.2); }
}

@keyframes unitSweep {
    0% { opacity: 0; transform: translateX(-120%); }
    30% { opacity: 0.9; }
    100% { opacity: 0; transform: translateX(120%); }
}

@keyframes milestoneCellGlow {
    0%, 100% { box-shadow: inset 0 0 0 1px rgba(85, 232, 255, 0.15); }
    42% { background-color: rgba(255, 209, 102, 0.18); box-shadow: inset 0 0 0 2px rgba(255, 225, 110, 0.64), 0 0 14px rgba(255, 209, 102, 0.22); }
}

@keyframes milestoneCellSweep {
    0% { opacity: 0; transform: scaleX(0.1); }
    34% { opacity: 0.9; }
    100% { opacity: 0; transform: scaleX(1.05); }
}

@keyframes checkConflictPulse {
    0%, 100% { transform: scale(1); }
    24%, 68% { background-color: rgba(255, 94, 196, 0.24); transform: scale(1.035); }
    46% { background-color: rgba(255, 209, 102, 0.16); transform: scale(1.01); }
}

@keyframes boardComplete {
    0%, 100% { box-shadow: 0 0 34px rgba(85, 232, 255, 0.16), inset 0 0 28px rgba(2, 6, 23, 0.62); }
    45% { box-shadow: 0 0 42px rgba(255, 209, 102, 0.36), 0 0 62px rgba(93, 255, 177, 0.22), inset 0 0 30px rgba(85, 232, 255, 0.24); }
}

@keyframes boardSpark {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6) rotate(-12deg); }
    35% { opacity: 0.95; transform: translate(-50%, -50%) scale(1.05) rotate(8deg); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.42) rotate(24deg); }
}

@keyframes scoreMilestone {
    0%, 100% { text-shadow: 0 0 0 rgba(255, 209, 102, 0); transform: translateY(0) scale(1); }
    38% { text-shadow: 0 0 18px rgba(255, 225, 110, 0.86), 0 0 30px rgba(85, 232, 255, 0.22); transform: translateY(-1px) scale(1.08); }
}

/* Adapt the surrounding chrome; the original 9x9 board never reorders. */
@media (max-width: 900px) {
    .controls { grid-template-columns: repeat(5, minmax(44px, 1fr)); gap: 4px; }
    .number-pad { grid-column: 1 / -1; }
}
@media (max-width: 780px) {
    .game-topbar { gap: 6px; grid-template-columns: auto minmax(0, 1fr); padding: 6px 8px; }
    .game-title h1 { font-size: 20px; }
    .game-title p { font-size: 10px; }
    .scoreboard { grid-column: 1 / -1; gap: 6px; }
    .scoreboard div { display: flex; align-items: center; justify-content: space-between; flex: 1; min-width: 0; padding: 4px 6px; gap: 6px; }
    .scoreboard strong { font-size: 16px; margin: 0; }
    .play-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 4px; }
    .side-panel { display: flex; gap: 4px; overflow-x: auto; overscroll-behavior: contain; scrollbar-width: thin; }
    .run-stat { flex: 1 0 70px; padding: 4px 6px; }
    .run-stat span { font-size: 9px; }
    .run-stat strong { font-size: 13px; margin-top: 2px; }
    .overlay-scroll { grid-template-columns: minmax(0, 1fr); padding: 16px; }
    .overlay-visual { display: none; }
    .overlay-card h2 { font-size: 30px; }
    .how-to-body { grid-template-columns: minmax(0, 1fr); }
    .how-to-board-panel { grid-template-columns: minmax(120px, 200px) minmax(0, 1fr); align-items: center; }
}
@media (max-width: 560px) {
    .number-pad { grid-template-columns: repeat(5, minmax(44px, 1fr)); gap: 4px; }
    .game-title h1 { font-size: 17px; }
    .game-title p { display: none; }
    .back-link { padding: 8px; }
    .controls button { padding: 6px 2px; }
    .arena-wrap { padding: 4px; }
    .difficulty-select { grid-template-columns: minmax(0, 1fr); }
    .difficulty-select span { min-height: 44px; }
    .overlay-stats { grid-template-columns: minmax(0, 1fr); }
    .overlay-stats div { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .overlay-stats strong { margin: 0; overflow-wrap: anywhere; }
    .how-to-body, .how-to-legend { grid-template-columns: minmax(0, 1fr); }
    .how-to-board-panel { grid-template-columns: minmax(0, 1fr); }
    .mini-board { max-width: 190px; }
}
@media (max-height: 500px) {
    .game-title p { display: none; }
    .game-topbar { padding: 4px 6px; gap: 4px 8px; }
    .game-title h1 { font-size: 16px; }
    .overlay-scroll { padding: 12px; }
    .overlay-card h2 { font-size: 26px; }
    .overlay-actions { padding: 8px; }
    .board-hud span { padding: 0 2px; font-size: 10px; }
    .arena-wrap { padding: 4px; }
}
@media (min-width: 480px) and (max-height: 500px) {
    .game-panel { grid-template-columns: minmax(0, 1fr) 244px; grid-template-rows: auto minmax(0, 1fr); }
    .game-topbar { grid-column: 1 / -1; grid-template-columns: auto minmax(0, 1fr) auto; }
    .scoreboard { grid-column: auto; gap: 4px; }
    .scoreboard div { display: block; min-width: 64px; padding: 3px 4px; }
    .scoreboard strong { font-size: 14px; margin-top: 2px; }
    .arena-wrap { grid-column: 1; grid-row: 2; }
    .play-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 4px; }
    .side-panel { display: flex; gap: 4px; overflow-x: auto; overscroll-behavior: contain; scrollbar-width: thin; }
    .run-stat { flex: 1 0 70px; padding: 4px 6px; }
    .run-stat span { font-size: 9px; }
    .run-stat strong { font-size: 13px; margin-top: 2px; }
    .controls { grid-column: 2; grid-row: 2; grid-template-columns: repeat(5, minmax(44px, 1fr)); gap: 4px; align-content: center; padding: 4px; border-top: 0; border-left: 1px solid var(--border); }
    .number-pad { grid-template-columns: repeat(3, minmax(44px, 1fr)); gap: 4px; }
    .controls button { padding: 6px 2px; }
    .overlay-scroll { grid-template-columns: minmax(0, 1fr); }
    .overlay-visual { display: none; }
}
@media (max-width: 479px) and (max-height: 500px) {
    .game-topbar { grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px; }
    .game-topbar > .back-link { grid-row: 1 / 3; }
    .game-title { grid-column: 2; }
    .scoreboard { grid-column: 2; gap: 4px; }
    .scoreboard div { display: block; padding: 2px 4px; text-align: left; }
    .scoreboard span { font-size: 8px; }
    .scoreboard strong { font-size: 12px; margin-top: 2px; }
    .controls { padding: 4px; }
    .number-pad { display: flex; overflow-x: auto; overscroll-behavior: contain; scrollbar-width: thin; }
    .number-pad button { flex: 0 0 44px; }
}
.game-panel.paused .cell, .game-panel.paused .cell::before, .game-panel.paused .cell::after, .game-panel.paused .logic-spark, .game-panel.paused #score { animation-play-state: paused; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
    .logic-spark, .cell.unit-complete::after, .cell.milestone-glow::before, .board-complete::after { display: none; }
    .cell.spark-lock, .cell.spark-hint, .cell.unit-complete { box-shadow: inset 0 0 0 2px var(--green); }
    .cell.check-conflict, .cell.spark-wrong { box-shadow: inset 0 0 0 2px var(--pink); }
    .board-complete { border-color: var(--green); }
}
.save-controls { margin: 12px 0; font-size: 13px; }
.save-controls label { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.save-controls input { flex: 0 0 22px; width: 22px; height: 22px; }
.save-controls p { overflow-wrap: anywhere; }
