:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --bg-0: #050816;
    --bg-1: #0a1024;
    --panel: rgba(13, 21, 45, 0.94);
    --panel-soft: rgba(17, 27, 55, 0.8);
    --line: rgba(159, 176, 220, 0.16);
    --line-strong: rgba(157, 180, 238, 0.48);
    --text: #f7f9ff;
    --muted: #9aa8ca;
    --accent: #7c6cff;
    --accent-2: #43d7ff;
    --success: #5de8a5;
    --danger: #ff6f91;
    --warning: #ffd166;
    --shadow: 0 28px 80px rgba(0, 0, 0, 0.46);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-0);
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    font: inherit;
}

.game-shell {
    width: 100%;
    height: 100%;
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: clamp(10px, 1.8vw, 22px);
    background:
        radial-gradient(circle at 18% 12%, rgba(67, 215, 255, 0.16), transparent 30%),
        radial-gradient(circle at 88% 78%, rgba(124, 108, 255, 0.2), transparent 34%),
        linear-gradient(145deg, var(--bg-0), var(--bg-1));
}

.game-card {
    width: min(100%, 1160px);
    height: min(100%, 760px);
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
    border: 1px solid rgba(164, 181, 229, 0.18);
    border-radius: 24px;
    background: linear-gradient(160deg, rgba(17, 27, 57, 0.97), rgba(8, 13, 31, 0.98));
    box-shadow: var(--shadow);
}

.topbar {
    min-height: 82px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(7, 12, 29, 0.6);
}

.brand-block {
    min-width: 0;
}

.eyebrow,
.panel-kicker {
    display: block;
    margin-bottom: 2px;
    color: var(--accent-2);
    font-size: 0.67rem;
    font-weight: 850;
    letter-spacing: 0.15em;
}

.brand-block h1,
.panel-head h2,
.board-state h2 {
    margin: 0;
    color: var(--text);
}

.brand-block h1 {
    font-size: clamp(1.55rem, 2.5vw, 2.15rem);
    letter-spacing: -0.045em;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stat-chip,
.sound-button {
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(16, 25, 51, 0.9);
}

.stat-chip {
    min-width: 98px;
    display: grid;
    align-content: center;
    padding: 7px 13px;
}

.stat-chip span {
    color: var(--muted);
    font-size: 0.65rem;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.stat-chip strong {
    margin-top: 1px;
    color: var(--text);
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

.sound-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    color: var(--text);
    cursor: pointer;
    font-weight: 780;
    transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.sound-button:hover,
.sound-button:focus-visible {
    border-color: rgba(67, 215, 255, 0.55);
    background: rgba(25, 38, 72, 0.94);
    outline: none;
}

.sound-button:active {
    transform: translateY(1px);
}

.game-layout {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 292px;
    gap: 18px;
    padding: 18px;
}

.board-panel {
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
}

.board-frame {
    position: relative;
    width: min(100%, 610px);
    aspect-ratio: 1;
    border-radius: 20px;
    padding: 10px;
    background: linear-gradient(150deg, rgba(124, 108, 255, 0.38), rgba(67, 215, 255, 0.14));
    box-shadow: inset 0 0 0 1px rgba(180, 194, 237, 0.16), 0 20px 42px rgba(0, 0, 0, 0.24);
}

.sudoku-grid {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    grid-template-rows: repeat(9, minmax(0, 1fr));
    overflow: hidden;
    border: 2px solid rgba(207, 217, 249, 0.75);
    border-radius: 13px;
    background: rgba(7, 12, 28, 0.96);
}

.cell {
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
    position: relative;
    border: 0;
    border-right: 1px solid rgba(157, 177, 225, 0.19);
    border-bottom: 1px solid rgba(157, 177, 225, 0.19);
    background: rgba(14, 23, 47, 0.68);
    color: var(--text);
    cursor: pointer;
    font-size: clamp(1rem, 3.2vw, 2rem);
    font-weight: 790;
    font-variant-numeric: tabular-nums;
    transition: background 110ms ease, color 110ms ease, box-shadow 110ms ease;
}

.cell:nth-child(9n) {
    border-right: 0;
}

.cell:nth-child(n+73) {
    border-bottom: 0;
}

.cell.box-right {
    border-right: 2px solid rgba(207, 217, 249, 0.72);
}

.cell.box-bottom {
    border-bottom: 2px solid rgba(207, 217, 249, 0.72);
}

.cell:hover,
.cell:focus-visible {
    z-index: 1;
    background: rgba(55, 73, 127, 0.45);
    outline: none;
}

.cell.is-peer {
    background: rgba(40, 52, 93, 0.34);
}

.cell.is-same {
    background: rgba(124, 108, 255, 0.2);
    color: #ded9ff;
}

.cell.is-selected {
    z-index: 2;
    background: rgba(67, 215, 255, 0.18);
    box-shadow: inset 0 0 0 2px rgba(67, 215, 255, 0.86);
}

.cell.is-given {
    color: #eef2ff;
    font-weight: 870;
}

.cell.is-user {
    color: #64ddff;
}

.cell.is-wrong {
    color: #fff;
    background: rgba(255, 111, 145, 0.5);
    animation: wrongPulse 440ms ease;
}

.cell.is-complete {
    animation: solvedPulse 800ms ease;
}

@keyframes wrongPulse {
    0%, 100% { transform: scale(1); }
    45% { transform: scale(0.84); }
}

@keyframes solvedPulse {
    0% { background: rgba(14, 23, 47, 0.68); }
    45% { background: rgba(93, 232, 165, 0.34); }
    100% { background: rgba(14, 23, 47, 0.68); }
}

.board-state {
    position: absolute;
    inset: 10px;
    z-index: 20;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 8px;
    padding: 30px;
    text-align: center;
    border: 1px solid rgba(174, 190, 234, 0.18);
    border-radius: 13px;
    background: rgba(6, 10, 25, 0.9);
    backdrop-filter: blur(10px);
}

.board-state[hidden] {
    display: none;
}

.state-icon {
    width: 66px;
    height: 66px;
    display: grid;
    place-items: center;
    margin-bottom: 6px;
    border-radius: 22px;
    background: rgba(93, 232, 165, 0.14);
    color: var(--success);
    font-size: 2rem;
    font-weight: 900;
    box-shadow: inset 0 0 0 1px rgba(93, 232, 165, 0.35);
}

.board-state h2 {
    font-size: 1.7rem;
}

.board-state p {
    max-width: 360px;
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.control-panel {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 13px;
    padding: 18px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: linear-gradient(165deg, rgba(21, 32, 63, 0.87), rgba(12, 20, 42, 0.8));
}

.panel-head h2 {
    font-size: 1.45rem;
    letter-spacing: -0.03em;
}

.panel-head p,
.keys-help p,
.score-info p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.5;
}

.mistakes-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 13px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(8, 14, 33, 0.58);
}

.mistakes-card span,
.keys-help > span,
.score-info > span {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.mistakes-card strong {
    display: block;
    margin-top: 1px;
    color: var(--text);
    font-size: 0.96rem;
}

.mistake-dots {
    display: flex;
    gap: 6px;
}

.mistake-dots i {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
}

.mistake-dots i.is-used {
    background: var(--danger);
    box-shadow: 0 0 16px rgba(255, 111, 145, 0.45);
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.number-pad button,
.erase-button {
    border: 1px solid var(--line);
    border-radius: 13px;
    color: var(--text);
    cursor: pointer;
    transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.number-pad button {
    min-height: 48px;
    background: rgba(21, 31, 62, 0.92);
    font-size: 1.12rem;
    font-weight: 850;
}

.number-pad button:hover,
.number-pad button:focus-visible,
.erase-button:hover,
.erase-button:focus-visible {
    border-color: rgba(124, 108, 255, 0.75);
    background: rgba(45, 57, 103, 0.9);
    outline: none;
}

.number-pad button:active,
.erase-button:active {
    transform: translateY(1px) scale(0.985);
}

.number-pad button[disabled],
.erase-button[disabled] {
    opacity: 0.38;
    cursor: default;
    transform: none;
}

.erase-button {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 14px;
    background: rgba(14, 21, 44, 0.9);
    font-weight: 770;
}

.keys-help,
.score-info {
    padding: 12px 13px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(8, 14, 33, 0.5);
}

kbd {
    display: inline-block;
    min-width: 23px;
    padding: 1px 5px;
    border: 1px solid rgba(170, 188, 233, 0.22);
    border-bottom-color: rgba(170, 188, 233, 0.42);
    border-radius: 5px;
    background: rgba(29, 41, 77, 0.86);
    color: #dfe7ff;
    font: inherit;
    font-size: 0.72rem;
    text-align: center;
}

.score-info {
    margin-top: auto;
}

.score-info > span {
    color: var(--success);
    font-size: 0.92rem;
}

.game-footer {
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 20px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    background: rgba(7, 12, 29, 0.56);
    font-size: 0.72rem;
}

.game-footer a {
    color: #bbc7e8;
    text-decoration: none;
}

.game-footer a:hover,
.game-footer a:focus-visible {
    color: #fff;
    text-decoration: underline;
    outline: none;
}

@media (max-width: 820px), (max-height: 650px) {
    .game-shell {
        padding: 6px;
    }

    .game-card {
        border-radius: 16px;
    }

    .topbar {
        min-height: 64px;
        padding: 9px 12px;
    }

    .brand-block h1 {
        font-size: 1.35rem;
    }

    .eyebrow {
        display: none;
    }

    .topbar-actions {
        gap: 6px;
    }

    .stat-chip {
        min-width: 74px;
        min-height: 42px;
        padding: 5px 9px;
    }

    .sound-button {
        min-height: 42px;
        padding: 0 10px;
    }

    #soundLabel {
        display: none;
    }

    .game-layout {
        grid-template-columns: minmax(0, 1fr) 220px;
        gap: 8px;
        padding: 8px;
    }

    .board-frame {
        padding: 6px;
        border-radius: 14px;
    }

    .control-panel {
        gap: 8px;
        padding: 10px;
        border-radius: 14px;
    }

    .panel-head p,
    .keys-help,
    .score-info {
        display: none;
    }

    .number-pad {
        gap: 5px;
    }

    .number-pad button {
        min-height: 38px;
    }

    .game-footer {
        min-height: 30px;
        padding: 5px 10px;
    }
}

@media (max-width: 560px) {
    html,
    body {
        overflow: auto;
    }

    .game-shell {
        height: auto;
        min-height: 100%;
        place-items: start center;
    }

    .game-card {
        height: auto;
        min-height: 100vh;
    }

    .topbar {
        align-items: flex-start;
    }

    .stat-chip:first-child {
        display: none;
    }

    .game-layout {
        grid-template-columns: 1fr;
    }

    .board-frame {
        width: 100%;
    }

    .control-panel {
        overflow: visible;
    }

    .panel-head,
    .mistakes-card {
        display: none;
    }

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

    .number-pad button {
        min-height: 36px;
        font-size: 0.95rem;
        border-radius: 9px;
    }

    .erase-button {
        min-height: 38px;
    }

    .game-footer {
        flex-wrap: wrap;
    }
}

/* Multi-Level */
.level-chip {
    min-width: 88px;
}

.level-progress {
    display: grid;
    gap: 7px;
    margin-top: 14px;
}

.level-progress > span {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.level-progress-track {
    height: 7px;
    overflow: hidden;
    border: 1px solid rgba(159, 176, 220, 0.18);
    border-radius: 999px;
    background: rgba(5, 8, 22, 0.72);
}

.level-progress-track i {
    display: block;
    width: 10%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    box-shadow: 0 0 16px rgba(67, 215, 255, 0.38);
    transition: width 260ms ease;
}

.board-state.is-level-up {
    backdrop-filter: blur(5px);
}

@media (max-width: 760px) {
    .level-chip {
        display: none;
    }
}
