:root {
    color-scheme: dark;
    --text: #f4fbff;
    --muted: #8fb0c8;
    --cyan: #4ae6ff;
    --blue: #6f8cff;
    --danger: #ff6788;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #020711;
}

body {
    min-width: 0;
    min-height: 0;
    color: var(--text);
}

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

button {
    font: inherit;
}

.game-shell,
.game-stage {
    position: relative;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.game-stage {
    background: #020812;
}

#gameCanvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.top-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 8;
    display: grid;
    grid-template-columns: minmax(150px, 1.05fr) minmax(360px, 2.5fr) auto;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: linear-gradient(180deg, rgba(2, 8, 18, 0.94), rgba(2, 8, 18, 0.62), transparent);
    pointer-events: none;
}

.game-brand {
    min-width: 0;
    display: grid;
    gap: 1px;
}

.game-brand span {
    color: var(--cyan);
    font-size: 9px;
    font-weight: 900;
    letter-spacing: 0.2em;
}

.game-brand strong {
    overflow: hidden;
    color: #fff;
    font-size: clamp(15px, 2.2vw, 26px);
    line-height: 1;
    letter-spacing: 0.08em;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.hud {
    min-width: 0;
    display: grid;
    grid-template-columns: 1.25fr 1.25fr .8fr .8fr;
    gap: 7px;
}

.hud-item {
    min-width: 0;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 7px;
    padding: 7px 9px;
    border: 1px solid rgba(124, 191, 225, 0.16);
    border-radius: 10px;
    background: rgba(8, 25, 43, 0.78);
    box-shadow: 0 7px 22px rgba(0, 0, 0, 0.14);
}

.hud-item span {
    overflow: hidden;
    color: var(--muted);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.hud-item strong {
    color: #fff;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.sound-button {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 102px;
    padding: 8px 10px;
    border: 1px solid rgba(74, 230, 255, 0.25);
    border-radius: 10px;
    color: var(--text);
    background: rgba(18, 45, 67, 0.86);
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
}

.sound-button:hover {
    background: rgba(25, 61, 89, 0.94);
}

.sound-button.is-muted {
    color: #ffd5df;
    border-color: rgba(255, 103, 136, 0.34);
    background: rgba(83, 26, 48, 0.78);
}

.sound-icon {
    font-size: 15px;
}

.start-overlay,
.message-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: grid;
    place-items: center;
    padding: 72px 18px 38px;
    background: linear-gradient(180deg, rgba(2, 8, 18, 0.34), rgba(2, 7, 15, 0.72));
    backdrop-filter: blur(2px);
}

.start-panel,
.message-panel {
    width: min(610px, 82vw);
    max-height: calc(100vh - 112px);
    overflow: hidden;
    padding: clamp(16px, 3vh, 26px);
    border: 1px solid rgba(98, 211, 255, 0.24);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(8, 26, 44, 0.96), rgba(5, 16, 31, 0.97));
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
    text-align: center;
}

.start-kicker,
.message-kicker {
    color: var(--cyan);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.22em;
}

.start-panel h1,
.message-panel h2 {
    margin: 7px 0 6px;
    font-size: clamp(22px, 4vh, 34px);
    line-height: 1.05;
}

.start-panel p,
.message-panel p {
    max-width: 520px;
    margin: 0 auto;
    color: #a9c2d6;
    font-size: clamp(11px, 1.8vh, 14px);
    line-height: 1.45;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin: clamp(12px, 2.5vh, 19px) 0;
}

.control-card {
    min-width: 0;
    display: grid;
    gap: 5px;
    padding: 8px 6px;
    border: 1px solid rgba(126, 189, 223, 0.14);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.035);
    color: #a9c2d6;
    font-size: 10px;
}

.key-group {
    display: flex;
    justify-content: center;
    gap: 4px;
}

kbd {
    display: inline-grid;
    min-width: 26px;
    height: 23px;
    place-items: center;
    padding: 0 6px;
    border: 1px solid rgba(119, 214, 255, 0.38);
    border-bottom-width: 2px;
    border-radius: 6px;
    color: #effbff;
    background: rgba(15, 42, 64, 0.95);
    font-family: inherit;
    font-size: 9px;
    font-weight: 900;
}

.start-button {
    width: min(320px, 100%);
    padding: 11px 16px;
    border: 0;
    border-radius: 11px;
    color: #02131c;
    background: linear-gradient(135deg, #74efff, #75a8ff);
    font-weight: 900;
    letter-spacing: 0.03em;
    cursor: pointer;
    box-shadow: 0 12px 35px rgba(59, 196, 255, 0.2);
}

.message-panel {
    width: min(470px, 82vw);
}

.final-score {
    display: grid;
    gap: 3px;
    margin-top: 14px;
    padding: 12px;
    border: 1px solid rgba(74, 230, 255, 0.18);
    border-radius: 12px;
    background: rgba(8, 30, 48, 0.64);
}

.final-score span {
    color: var(--muted);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.final-score strong {
    color: var(--cyan);
    font-size: 28px;
    font-variant-numeric: tabular-nums;
}

.is-hidden {
    display: none !important;
}

.mobile-controls {
    position: absolute;
    left: 50%;
    bottom: 31px;
    z-index: 10;
    display: none;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 8px;
    width: min(420px, calc(100% - 24px));
    transform: translateX(-50%);
}

.touch-button {
    min-height: 46px;
    border: 1px solid rgba(113, 209, 255, 0.24);
    border-radius: 11px;
    color: #dff9ff;
    background: rgba(14, 40, 62, 0.88);
    font-weight: 900;
    cursor: pointer;
    user-select: none;
    touch-action: none;
}

.touch-fire {
    color: #06111f;
    border-color: rgba(119, 235, 255, 0.7);
    background: linear-gradient(135deg, #72f0ff, #80a8ff);
}

.bottom-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 10px;
    color: #6f91aa;
    background: linear-gradient(0deg, rgba(2, 7, 17, 0.94), rgba(2, 7, 17, 0.4), transparent);
    font-size: 9px;
    pointer-events: none;
}

.bottom-overlay a {
    color: #8fd3e7;
    text-decoration: none;
    white-space: nowrap;
    pointer-events: auto;
}

@media (max-width: 760px), (pointer: coarse) {
    .top-overlay {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
        padding: 7px 8px;
    }

    .game-brand {
        display: none;
    }

    .hud {
        grid-column: 1;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 4px;
    }

    .hud-item {
        display: grid;
        gap: 1px;
        justify-content: initial;
        padding: 5px 6px;
    }

    .hud-item span {
        font-size: 7px;
    }

    .hud-item strong {
        font-size: 11px;
    }

    .sound-button {
        grid-column: 2;
        min-width: 42px;
        padding: 8px;
    }

    .sound-button span:last-child {
        display: none;
    }

    .start-overlay,
    .message-overlay {
        padding: 58px 10px 84px;
    }

    .start-panel,
    .message-panel {
        width: min(560px, 94vw);
        max-height: calc(100vh - 146px);
        padding: 14px;
    }

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

    .control-card {
        padding: 6px;
    }

    .mobile-controls {
        display: grid;
    }

    .desktop-help {
        display: none;
    }

    .bottom-overlay {
        justify-content: flex-end;
    }
}

@media (max-height: 430px) {
    .start-overlay,
    .message-overlay {
        padding-top: 54px;
        padding-bottom: 28px;
    }

    .start-panel,
    .message-panel {
        max-height: calc(100vh - 82px);
        padding: 10px 14px;
    }

    .start-panel h1,
    .message-panel h2 {
        margin: 4px 0;
        font-size: 20px;
    }

    .controls-grid {
        margin: 7px 0;
    }

    .control-card {
        padding: 5px;
    }

    .start-button {
        padding: 8px 14px;
    }
}
