:root {
    color-scheme: dark;
    --bg: #101923;
    --panel: #172435;
    --panel-strong: #20334b;
    --text: #f4f7fb;
    --muted: #a9b6c8;
    --accent: #27d2a1;
    --accent-2: #ffd166;
    --danger: #ff5c7a;
    --line: rgba(255, 255, 255, 0.12);
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 15% 10%, rgba(39, 210, 161, 0.22), transparent 28rem),
        linear-gradient(135deg, #101923 0%, #111f2d 52%, #18293a 100%);
    color: var(--text);
}

button,
input {
    font: inherit;
}

button {
    border: 0;
    border-radius: 8px;
    min-height: 44px;
    padding: 0 18px;
    background: var(--accent);
    color: #082018;
    font-weight: 800;
    cursor: pointer;
}

button:hover {
    filter: brightness(1.08);
}

button.secondary,
button.tiny {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    border: 1px solid var(--line);
}

button.tiny {
    min-height: 34px;
    padding: 0 12px;
    font-size: 0.85rem;
}

.app-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: 18px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: var(--accent);
    color: #082018;
    font-weight: 900;
    font-size: 1.45rem;
}

h1,
h2,
p {
    margin-top: 0;
}

.brand h1 {
    margin: 0;
    font-size: clamp(1.45rem, 3vw, 2.15rem);
    line-height: 1;
}

.brand p {
    margin: 4px 0 0;
    color: var(--muted);
}

.game-stats {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    z-index: 4;
    display: none;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    pointer-events: none;
}

.is-playing .game-stats {
    display: flex;
}

.game-stats div {
    min-width: 72px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    padding: 5px 8px;
    background: rgba(12, 22, 34, 0.58);
    backdrop-filter: blur(4px);
    text-align: left;
}

.game-stats div:nth-child(2) {
    margin-left: auto;
}

.game-stats span {
    display: block;
    font-weight: 900;
    font-size: 0.92rem;
    line-height: 1;
}

.game-stats small {
    display: block;
    color: var(--muted);
    font-size: 0.66rem;
    line-height: 1.1;
}

#speedStatBox {
    display: none;
}

.is-hint-mode #speedStatBox {
    display: block;
}

.game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 18px;
    align-items: start;
}

.game-panel {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: min(76vh, 800px);
    background: #0d1420;
    box-shadow: var(--shadow);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: min(76vh, 800px);
    min-height: 520px;
    touch-action: none;
}

.is-playing .app-shell {
    width: 100%;
    padding: 0;
}

.is-playing .topbar,
.is-playing .side-panel {
    display: none;
}

.is-playing .game-layout {
    grid-template-columns: 1fr;
    gap: 0;
}

.is-playing .game-panel {
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
}

.is-playing #gameCanvas {
    height: 100dvh;
    min-height: 100dvh;
}

.overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(5, 10, 18, 0.62);
    backdrop-filter: blur(6px);
    z-index: 5;
}

.overlay.is-visible {
    display: flex;
}

.modal {
    width: min(460px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    background: rgba(23, 36, 53, 0.96);
    box-shadow: var(--shadow);
}

.modal h2 {
    margin-bottom: 10px;
    font-size: clamp(1.55rem, 5vw, 2.35rem);
    line-height: 1.05;
}

.modal p {
    color: var(--muted);
    line-height: 1.45;
}

.kicker {
    margin-bottom: 8px;
    color: var(--accent-2) !important;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.78rem;
}

label {
    display: block;
    margin: 16px 0 7px;
    color: var(--muted);
    font-weight: 700;
}

input {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 14px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    outline: none;
}

input:focus {
    border-color: var(--accent);
}

.two-player-option {
    display: none;
    margin-top: 12px;
}

.choice-line {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    color: var(--text);
    cursor: pointer;
}

.choice-line input {
    width: 18px;
    min-height: 18px;
    accent-color: var(--accent);
}

.player-two-fields label {
    margin-top: 12px;
}

@media (min-width: 760px) and (pointer: fine) {
    .two-player-option {
        display: block;
    }
}

.modal button {
    width: 100%;
    margin-top: 14px;
}

.result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.side-panel {
    display: grid;
    gap: 14px;
}

.scoreboard,
.help-box {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    background: rgba(23, 36, 53, 0.86);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
}

.scoreboard h2,
.help-box h2 {
    margin-bottom: 8px;
    font-size: 1.05rem;
}

.help-box p {
    color: var(--muted);
    line-height: 1.45;
}

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

#scoreList {
    padding-left: 0;
    margin: 12px 0 0;
    list-style: none;
    display: grid;
    gap: 8px;
}

#scoreList li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.07);
}

#scoreList strong,
#scoreList span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#scoreList span {
    color: var(--accent-2);
    font-weight: 900;
}

.hidden {
    display: none;
}

#emptyScores {
    color: var(--muted);
}

@media (max-width: 900px) {
    .app-shell {
        padding: 10px;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

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

    .side-panel {
        grid-template-columns: 1fr;
    }

    #gameCanvas {
        height: 68vh;
        min-height: 500px;
    }
}

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

    .topbar {
        padding: 12px;
        margin-bottom: 0;
    }

    .brand-mark {
        width: 42px;
        height: 42px;
    }

    .game-panel {
        border-left: 0;
        border-right: 0;
        border-radius: 0;
        min-height: 0;
    }

    #gameCanvas {
        height: 70vh;
        min-height: 460px;
    }

    .side-panel {
        padding: 10px;
    }

    .modal {
        padding: 20px;
    }

    .result-actions {
        grid-template-columns: 1fr;
    }
}
