:root {
    color-scheme: dark;
    --deep-space: rgb(8 10 26);
    --panel: rgb(28 32 58);
    --text: rgb(232 245 255);
    --muted-text: rgb(153 178 205);
    --cyan: rgb(73 220 255);
    --mint: rgb(92 255 188);
    --berry: rgb(255 92 173);
    --lemon: rgb(255 219 86);
    --coral: rgb(255 127 97);
    --outline: rgb(255 255 255 / 0.16);
    --shadow: rgb(0 0 0 / 0.58);
}

* {
    box-sizing: border-box;
}

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

body {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 18px;
    overflow: auto;
    background:
        radial-gradient(circle at top, rgb(29 49 88 / 0.72), transparent 40%),
        radial-gradient(circle at 20% 80%, rgb(255 92 173 / 0.12), transparent 35%),
        radial-gradient(circle at 80% 20%, rgb(73 220 255 / 0.15), transparent 32%),
        var(--deep-space);
    color: var(--text);
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.app-shell {
    --rail-width: 248px;
    display: grid;
    grid-template-columns: minmax(0, auto) var(--rail-width);
    align-items: center;
    gap: 24px;
    width: 100%;
    max-width: 1480px;
}

.stage-wrap {
    display: grid;
    place-items: center;
    min-width: 0;
}

#gameCanvas {
    display: block;
    width: min(calc(100vw - 84px - var(--rail-width)), calc((100vh - 36px) * 1.25));
    height: auto;
    max-width: 900px;
    max-height: calc(100vh - 36px);
    aspect-ratio: 5 / 4;
    background: #000;
    border: 1px solid var(--outline);
    box-shadow:
        0 0 0 1px rgb(73 220 255 / 0.08),
        0 24px 56px var(--shadow);
    cursor: default;
}

.side-rail {
    display: grid;
    gap: 18px;
    width: var(--rail-width);
}

.panel-card {
    padding: 18px;
    background: linear-gradient(180deg, rgb(16 20 40 / 0.92), rgb(9 12 29 / 0.98));
    border: 1px solid rgb(73 220 255 / 0.32);
    box-shadow:
        0 0 0 1px rgb(255 255 255 / 0.04),
        0 18px 34px rgb(0 0 0 / 0.34);
}

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

.brand-logo {
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
    isolation: isolate;
    padding: 12px;
    text-decoration: none;
    border: 1px solid rgb(255 255 255 / 0.1);
    background:
        radial-gradient(ellipse at 50% 82%, rgb(232 245 255 / 0.32), transparent 30%),
        radial-gradient(circle at 50% 74%, rgb(255 219 86 / 0.18), transparent 32%),
        radial-gradient(circle at 22% 18%, rgb(73 220 255 / 0.2), transparent 34%),
        radial-gradient(circle at 78% 24%, rgb(162 119 255 / 0.18), transparent 32%),
        radial-gradient(circle at 18% 80%, rgb(255 92 173 / 0.14), transparent 24%),
        linear-gradient(180deg, rgb(24 43 78 / 0.84), rgb(8 10 26 / 0.98));
}

.brand-logo::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 50% 79%, rgb(247 249 255 / 0.9), transparent 17%),
        radial-gradient(ellipse at 50% 83%, rgb(255 219 86 / 0.22), transparent 28%);
    pointer-events: none;
    z-index: 0;
}

.brand-logo:hover,
.brand-logo:focus-visible {
    border-color: rgb(73 220 255 / 0.56);
    box-shadow: 0 0 0 3px rgb(73 220 255 / 0.14);
    outline: none;
}

.brand-logo img {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: auto;
    filter:
        drop-shadow(0 8px 14px rgb(0 0 0 / 0.24))
        drop-shadow(0 0 9px rgb(255 255 255 / 0.42));
}

.home-button {
    display: block;
    padding: 11px 16px;
    color: var(--text);
    text-decoration: none;
    text-align: center;
    font-size: 17px;
    font-weight: 700;
    border: 2px solid rgb(255 255 255 / 0.62);
    background: rgb(8 10 26 / 0.96);
}

.home-button:hover,
.home-button:focus-visible {
    border-color: var(--cyan);
    background: rgb(73 220 255 / 0.14);
    outline: none;
}

.audio-panel {
    display: grid;
    gap: 12px;
}

.panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
}

.panel-title {
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
}

.volume-value {
    color: var(--lemon);
    font-family: Consolas, "Courier New", monospace;
    font-size: 18px;
    font-weight: 700;
}

.volume-slider {
    width: 100%;
    accent-color: rgb(73 220 255);
    cursor: pointer;
}

.panel-copy {
    margin: 0;
    color: var(--muted-text);
    font-size: 14px;
    line-height: 1.45;
}

.dialog-backdrop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgb(0 0 0 / 0.72);
    backdrop-filter: blur(6px);
}

.dialog-backdrop[hidden] {
    display: none !important;
}

.dialog-panel {
    width: min(100%, 340px);
    padding: 22px 22px 18px;
    background: linear-gradient(180deg, rgb(18 21 42 / 0.96), rgb(8 10 26 / 0.98));
    border: 2px solid rgb(73 220 255 / 0.5);
    box-shadow: 0 18px 40px rgb(0 0 0 / 0.45);
}

.dialog-panel h1 {
    margin: 0;
    color: var(--lemon);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: center;
}

.dialog-score {
    margin: 12px 0 10px;
    color: var(--text);
    font-family: Consolas, "Courier New", monospace;
    font-size: 24px;
    font-weight: 700;
    text-align: center;
}

.dialog-label {
    display: block;
    margin-bottom: 10px;
    color: var(--muted-text);
    font-size: 16px;
    text-align: center;
}

#initialsInput {
    display: block;
    width: 100px;
    margin: 0 auto;
    padding: 8px 10px;
    border: 2px solid rgb(255 255 255 / 0.55);
    background: rgb(8 10 26 / 0.96);
    color: var(--text);
    font-family: Consolas, "Courier New", monospace;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-align: center;
    text-transform: uppercase;
    outline: none;
}

#initialsInput:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgb(73 220 255 / 0.18);
}

.dialog-error {
    min-height: 1.4em;
    margin: 10px 0 0;
    color: var(--coral);
    font-size: 14px;
    text-align: center;
}

.dialog-actions {
    display: flex;
    justify-content: center;
    gap: 14px;
    margin-top: 14px;
}

.dialog-actions button {
    min-width: 90px;
    padding: 9px 16px;
    border: 2px solid rgb(255 255 255 / 0.64);
    background: rgb(8 10 26);
    color: var(--text);
    font-size: 18px;
    font-family: inherit;
    cursor: pointer;
}

.dialog-actions button:hover,
.dialog-actions button:focus-visible {
    border-color: var(--cyan);
    background: rgb(73 220 255 / 0.16);
    outline: none;
}

@media (max-width: 1220px) {
    body {
        align-items: flex-start;
    }

    .app-shell {
        --rail-width: min(100%, 760px);
        grid-template-columns: 1fr;
        justify-items: center;
    }

    #gameCanvas {
        width: min(calc(100vw - 36px), calc((100vh - 280px) * 1.25));
        max-height: none;
    }

    .side-rail {
        width: min(100%, 760px);
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }
}

@media (max-width: 720px) {
    body {
        padding: 12px;
    }

    .app-shell {
        gap: 16px;
    }

    #gameCanvas {
        width: min(calc(100vw - 24px), calc((100vh - 320px) * 1.25));
    }

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

    .brand-logo {
        padding: 10px;
    }
}
