@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@500;700;800;900&display=swap');

:root {
    --if-green: #1f8a45;
    --if-green-deep: #0f5f32;
    --if-red: #d83c32;
    --gold: #ffc94a;
    --sky: #87d9ff;
    --ink: #10243a;
    --paper: #fffaf1;
    --panel: rgba(255, 250, 241, 0.92);
    --shadow: rgba(12, 28, 46, 0.24);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overscroll-behavior: none;
}

body {
    margin: 0;
    overflow: hidden;
    color: var(--ink);
    background: var(--sky);
    font-family: 'Outfit', 'Segoe UI', Arial, sans-serif;
    user-select: none;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

#game-shell {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: var(--sky);
}



#game-canvas,
#game-canvas canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.ranking-editor-toggle {
    position: absolute;
    left: 18px;
    bottom: 18px;
    z-index: 26;
    width: 30px;
    height: 30px;
    display: none;
    place-items: center;
    border: 0;
    border-radius: 0;
    background: transparent;
    opacity: 0.2;
    pointer-events: auto;
}

.ranking-editor-toggle::before,
.ranking-editor-toggle::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 3px;
    border-radius: 999px;
    background: rgba(16, 36, 58, 0.72);
}

.ranking-editor-toggle::before {
    transform: rotate(45deg);
}

.ranking-editor-toggle::after {
    transform: rotate(-45deg);
}

.ranking-editor-toggle[aria-pressed="true"] {
    opacity: 0.34;
}

.ranking-editor-toggle[aria-pressed="true"]::before,
.ranking-editor-toggle[aria-pressed="true"]::after {
    background: rgba(216, 60, 50, 0.86);
}

.ranking-editor-toggle:hover {
    opacity: 0.46;
}

.ranking-editor-toggle[hidden] {
    display: none !important;
}

#game-shell[data-state="menu"] .ranking-editor-toggle {
    display: grid;
}

.ranking-drawer-toggle {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 47;
    min-height: 38px;
    padding: 0 14px;
    display: none;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    color: var(--ink);
    background: var(--gold);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.24);
    font-size: 0.72rem;
    font-weight: 900;
    text-transform: uppercase;
    pointer-events: auto;
}

#hud {
    position: absolute;
    top: 18px;
    left: 18px;
    right: 390px;
    z-index: 10;
    display: grid;
    grid-template-columns: auto;
    gap: 12px;
    align-items: start;
    pointer-events: none;
}

.hud-brand,
.hud-score,
.ranking-panel,
.result-panel {
    border: 2px solid rgba(16, 36, 58, 0.08);
    background: var(--panel);
    box-shadow: 0 16px 38px var(--shadow);
    backdrop-filter: blur(14px);
}

.hud-brand {
    width: fit-content;
    min-width: 260px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

#hud[data-state="menu"] .hud-brand,
#hud[data-state="customize"] .hud-brand,
#hud[data-state="gameover"] .hud-brand,
#hud[data-state="running"] .hud-brand,
#hud[data-state="paused"] .hud-brand,
#hud[data-state="quiz"] .hud-brand {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}

#hud[data-state="running"] .hud-brand,
#hud[data-state="paused"] .hud-brand,
#hud[data-state="quiz"] .hud-brand {
    display: none;
}

#hud[data-state="running"],
#hud[data-state="paused"],
#hud[data-state="quiz"] {
    grid-template-columns: auto;
    justify-content: start;
}

.hud-score,
.ranking-panel[data-state="customize"] {
    display: none;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: white;
    background:
        linear-gradient(90deg, transparent 46%, white 46%, white 54%, transparent 54%),
        linear-gradient(0deg, transparent 46%, white 46%, white 54%, transparent 54%),
        var(--if-green);
    font-weight: 900;
}

.hud-brand strong {
    display: block;
    font-size: 1.05rem;
    font-weight: 900;
}

.hud-brand span:last-child {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(16, 36, 58, 0.72);
}

.hud-score {
    min-width: 112px;
    padding: 10px 14px;
    border-radius: 8px;
    text-align: right;
}

.hud-score span {
    display: block;
    font-size: 0.72rem;
    font-weight: 800;
    color: rgba(16, 36, 58, 0.66);
    text-transform: uppercase;
}

.hud-score strong {
    display: block;
    font-size: 1.55rem;
    line-height: 1;
    font-weight: 900;
    color: var(--if-green-deep);
}

.pause-btn {
    min-height: 48px;
    padding: 0 18px;
    border: 2px solid rgba(16, 36, 58, 0.08);
    border-radius: 8px;
    color: var(--ink);
    background: var(--panel);
    box-shadow: 0 16px 38px var(--shadow);
    backdrop-filter: blur(14px);
    font-weight: 900;
    pointer-events: auto;
}

.pause-btn[hidden] {
    display: none;
}

.screen {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: grid;
    align-content: end;
    justify-items: start;
    padding: 94px 6vw 7vh;
    background:
        linear-gradient(180deg, rgba(10, 36, 54, 0.05), rgba(10, 36, 54, 0.36) 64%, rgba(10, 36, 54, 0.74)),
        linear-gradient(90deg, rgba(5, 20, 28, 0.62), rgba(5, 20, 28, 0.04) 62%);
    color: white;
}

.screen[hidden] {
    display: none;
}

.start-copy {
    max-width: 680px;
    text-shadow: 0 4px 18px rgba(0, 0, 0, 0.36);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--ink);
    background: var(--gold);
    font-size: 0.78rem;
    font-weight: 900;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    margin-top: 12px;
    font-size: 5rem;
    line-height: 0.94;
    font-weight: 900;
}

.start-copy p {
    max-width: 560px;
    margin-top: 16px;
    font-size: 1.18rem;
    line-height: 1.45;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.92);
}

.start-actions,
.end-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 26px;
}

.runner-card {
    width: min(560px, calc(100vw - 36px));
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
    margin-top: 22px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 12px;
    background: rgba(9, 25, 36, 0.5);
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(16px);
}

.runner-card div {
    min-width: 0;
}

.runner-card span {
    display: block;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    color: var(--gold);
    text-transform: uppercase;
}

.runner-card strong {
    display: block;
    margin-top: 2px;
    font-size: 1.25rem;
    font-weight: 900;
    color: white;
}

.runner-card p {
    margin-top: 4px;
    color: rgba(255, 255, 255, 0.82);
    font-size: 0.9rem;
    line-height: 1.25;
    font-weight: 700;
}

.primary-btn,
.ghost-btn,
.selector-btn {
    min-height: 46px;
    border: 0;
    border-radius: 8px;
    font-weight: 900;
    transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
}

.primary-btn {
    padding: 0 24px;
    color: white;
    background: linear-gradient(135deg, var(--if-green), #21b768);
    box-shadow: 0 12px 24px rgba(31, 138, 69, 0.32);
}

.ghost-btn {
    padding: 0 20px;
    color: var(--ink);
    background: var(--paper);
}

.selector-btn {
    width: 48px;
    color: white;
    background: linear-gradient(135deg, rgba(31, 138, 69, 0.92), rgba(255, 201, 74, 0.9));
    box-shadow: 0 12px 22px rgba(0, 0, 0, 0.18);
}

.customize-panel {
    position: absolute;
    inset: 0;
    z-index: 32;
    display: grid;
    align-items: center;
    justify-items: end;
    padding: 84px 6vw 46px;
    color: white;
    background:
        radial-gradient(circle at 45% 50%, rgba(255, 244, 205, 0.2), transparent 32%),
        linear-gradient(90deg, rgba(6, 18, 29, 0.03), rgba(6, 18, 29, 0.2) 52%, rgba(6, 18, 29, 0.74));
    pointer-events: auto;
}

.customize-panel[hidden] {
    display: none;
}

.customize-card {
    position: relative;
    width: min(430px, calc(100vw - 36px));
    max-height: calc(100vh - 48px);
    padding: 18px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    background: rgba(9, 25, 36, 0.68);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(18px);
    overflow: auto;
}

.customize-card h2 {
    margin-top: 10px;
    font-size: 1.8rem;
    font-weight: 900;
}

.customize-card p {
    margin: 8px 0 16px;
    color: rgba(255, 255, 255, 0.76);
    font-size: 0.94rem;
    line-height: 1.35;
    font-weight: 700;
}

.customize-close {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    color: var(--ink);
    background: var(--paper);
    font-weight: 900;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
}

.customize-row {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    gap: 10px;
    align-items: center;
    margin-top: 8px;
    padding: 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
}

.customize-row[hidden] {
    display: none;
}

.customize-row .selector-btn {
    width: 44px;
    min-height: 42px;
}

.customize-row span {
    display: block;
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    color: var(--gold);
    text-transform: uppercase;
}

.customize-row strong {
    display: block;
    margin-top: 2px;
    font-size: 1rem;
    color: white;
    font-weight: 900;
}

.customize-card > .primary-btn {
    width: 100%;
    margin-top: 12px;
}

.pause-panel {
    position: absolute;
    inset: 0;
    z-index: 34;
    display: grid;
    place-items: center;
    padding: 24px;
    color: var(--ink);
    background:
        radial-gradient(circle at 50% 42%, rgba(255, 201, 74, 0.18), transparent 30%),
        rgba(6, 18, 29, 0.42);
    backdrop-filter: blur(5px);
}

.pause-panel[hidden] {
    display: none;
}

.pause-card {
    width: min(430px, calc(100vw - 36px));
    padding: 26px;
    border: 2px solid rgba(16, 36, 58, 0.08);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
    text-align: center;
}

.pause-card h2 {
    margin-top: 12px;
    font-size: 2.4rem;
    font-weight: 900;
}

.pause-card p {
    margin: 10px auto 20px;
    max-width: 320px;
    color: rgba(16, 36, 58, 0.72);
    font-weight: 800;
    line-height: 1.35;
}

.pause-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.primary-btn:hover,
.ghost-btn:hover,
.selector-btn:hover,
.pause-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.03);
}

.quiz-panel {
    position: absolute;
    inset: 0;
    z-index: 48;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(12, 28, 46, 0.48);
    color: var(--ink);
    pointer-events: auto;
}

.quiz-panel[hidden] {
    display: none;
}

.quiz-window {
    width: min(760px, calc(100vw - 28px));
    max-height: calc(100vh - 42px);
    padding: 24px;
    border: 2px solid rgba(16, 36, 58, 0.08);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(14px);
    overflow: auto;
}

.quiz-body {
    margin-top: 16px;
}

.quiz-content {
    min-width: 0;
}

.quiz-window h2 {
    margin-top: 12px;
    font-size: clamp(1.5rem, 4vw, 2.1rem);
    line-height: 1.05;
    font-weight: 900;
    color: var(--ink);
}

.quiz-difficulty {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 12px;
    border-radius: 8px;
    color: #176d39;
    background: rgba(31, 138, 69, 0.14);
    font-size: 0.76rem;
    font-weight: 900;
    text-transform: uppercase;
}

.quiz-difficulty[data-difficulty="easy"] {
    color: #0f6b36;
    background: rgba(31, 138, 69, 0.16);
    box-shadow: inset 0 0 0 2px rgba(31, 138, 69, 0.16);
}

.quiz-difficulty[data-difficulty="medium"] {
    color: #5d4300;
    background: #f0bf3b;
    box-shadow: inset 0 0 0 2px rgba(92, 67, 0, 0.12);
}

.quiz-difficulty[data-difficulty="hard"] {
    color: white;
    background: #9f211d;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.16);
}

.quiz-timer {
    height: 9px;
    margin-top: 12px;
    border-radius: 999px;
    background: rgba(16, 36, 58, 0.1);
    overflow: hidden;
}

.quiz-timer[hidden] {
    display: none;
}

.quiz-timer span {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--if-green), #ffc94a, #d83c32);
    transform: scaleX(1);
    transform-origin: left center;
}

.quiz-timer[data-warning="true"] span {
    background: linear-gradient(90deg, #ffc94a, #d83c32);
}

.quiz-content p {
    color: var(--ink);
}

#quiz-question {
    margin-top: 14px;
    padding: 18px 20px 20px;
    border: 3px solid rgba(16, 36, 58, 0.82);
    border-bottom: 0;
    border-radius: 14px 14px 0 0;
    background: rgba(16, 36, 58, 0.075);
    box-shadow: inset 0 -1px 0 rgba(16, 36, 58, 0.1);
    font-size: clamp(0.95rem, 2.2vw, 1.08rem);
    line-height: 1.4;
    font-weight: 900;
}

#quiz-question::after {
    content: "";
    display: block;
    width: min(520px, 74%);
    height: 4px;
    margin-top: 14px;
    border-radius: 999px;
    background: var(--ink);
    opacity: 0.86;
}

.quiz-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    margin-top: 0;
    padding: 0 18px 18px;
    border: 3px solid rgba(16, 36, 58, 0.82);
    border-top: 0;
    border-radius: 0 0 14px 14px;
    background: rgba(255, 255, 255, 0.36);
    box-shadow: 0 18px 38px rgba(16, 36, 58, 0.14);
}

.quiz-option {
    min-height: 58px;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px;
    padding: 12px 13px;
    border: 0;
    border-radius: 0;
    color: var(--ink);
    background: white;
    box-shadow: inset 0 -2px 0 rgba(16, 36, 58, 0.08);
    text-align: left;
    font-size: clamp(0.88rem, 1.9vw, 0.98rem);
    line-height: 1.28;
    font-weight: 900;
}

.quiz-option:first-child {
    border-radius: 8px 8px 0 0;
}

.quiz-option:last-child {
    border-radius: 0 0 8px 8px;
}

.quiz-option-letter {
    min-width: 32px;
    color: rgba(16, 36, 58, 0.74);
    font-weight: 900;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

.quiz-option-text {
    min-width: 0;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
    text-decoration-color: rgba(16, 36, 58, 0.24);
}

.quiz-option:hover {
    color: white;
    background: linear-gradient(135deg, var(--if-green), #21b768);
    box-shadow: 0 12px 24px rgba(31, 138, 69, 0.22);
    outline: none;
}

.quiz-option:focus-visible {
    outline: 3px solid rgba(255, 201, 74, 0.82);
    outline-offset: 2px;
}

.quiz-option:disabled {
    cursor: default;
}

.quiz-option[data-selected="true"] {
    box-shadow: inset 0 0 0 3px rgba(16, 36, 58, 0.18);
}

.quiz-option[data-correct="true"] {
    color: white;
    background: linear-gradient(135deg, var(--if-green), #21b768);
    box-shadow: 0 12px 24px rgba(31, 138, 69, 0.22);
}

.quiz-option[data-reveal="true"] {
    color: var(--ink);
    background: #37d86a;
    animation: quiz-correct-reveal 0.62s ease-in-out infinite;
}

.quiz-option:hover .quiz-option-letter,
.quiz-option:hover .quiz-option-text,
.quiz-option[data-correct="true"] .quiz-option-letter,
.quiz-option[data-correct="true"] .quiz-option-text,
.quiz-option[data-wrong="true"] .quiz-option-letter,
.quiz-option[data-wrong="true"] .quiz-option-text {
    color: inherit;
    text-decoration-color: currentColor;
}

.quiz-option[data-wrong="true"] {
    color: white;
    background: linear-gradient(135deg, #d83c32, #a62420);
}

.quiz-feedback {
    min-height: 24px;
    margin-top: 12px;
    font-size: 0.92rem;
    font-weight: 900;
}

.quiz-feedback[data-kind="ok"] {
    color: #176d39;
}

.quiz-feedback[data-kind="bad"] {
    color: #9f211d;
}

@keyframes quiz-correct-reveal {
    0%,
    100% {
        box-shadow: inset 0 0 0 2px rgba(8, 12, 10, 0.82), 0 10px 22px rgba(31, 138, 69, 0.18);
    }

    50% {
        box-shadow: inset 0 0 0 2px rgba(8, 12, 10, 0.96), 0 0 0 4px rgba(255, 201, 74, 0.48), 0 14px 26px rgba(31, 138, 69, 0.22);
    }
}

#game-over {
    align-content: center;
    justify-items: center;
    background: rgba(12, 28, 46, 0.48);
}

.result-panel {
    width: min(620px, calc(100% - 28px));
    padding: 26px;
    border-radius: 8px;
    color: var(--ink);
}

.result-panel h2 {
    margin-top: 12px;
    font-size: 2.1rem;
    font-weight: 900;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.result-stats div {
    min-height: 78px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(16, 36, 58, 0.07);
}

.result-stats span {
    display: block;
    font-size: 0.76rem;
    font-weight: 900;
    color: rgba(16, 36, 58, 0.62);
    text-transform: uppercase;
}

.result-stats strong {
    display: block;
    margin-top: 6px;
    font-size: 1.45rem;
    font-weight: 900;
    color: var(--if-green-deep);
}

.score-form label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.84rem;
    font-weight: 900;
    color: rgba(16, 36, 58, 0.72);
    text-transform: uppercase;
}

.score-form div {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.score-form input {
    min-width: 0;
    min-height: 48px;
    padding: 0 14px;
    border: 2px solid rgba(16, 36, 58, 0.14);
    border-radius: 8px;
    color: var(--ink);
    background: white;
    font-weight: 900;
    outline: none;
    text-transform: uppercase;
}

.score-form[data-saved="true"] {
    padding: 12px;
    border-radius: 10px;
    background: rgba(179, 230, 190, 0.46);
    box-shadow: inset 0 0 0 2px rgba(31, 138, 69, 0.16);
}

.score-form[data-saved="true"] label {
    color: #176d39;
}

.score-form[data-saved="true"] input,
.score-form[data-saved="true"] button {
    opacity: 0.72;
}

.confirm-panel {
    position: absolute;
    inset: 0;
    z-index: 42;
    display: grid;
    place-items: center;
    padding: 24px;
    color: var(--ink);
    background: rgba(6, 18, 29, 0.48);
    backdrop-filter: blur(6px);
}

.confirm-panel[hidden] {
    display: none;
}

.confirm-card {
    width: min(430px, calc(100vw - 36px));
    padding: 24px;
    border: 2px solid rgba(16, 36, 58, 0.08);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
}

.confirm-card h2 {
    margin-top: 12px;
    font-size: 2rem;
    font-weight: 900;
}

.confirm-card p {
    margin-top: 8px;
    color: rgba(16, 36, 58, 0.72);
    font-weight: 800;
    line-height: 1.35;
}

.confirm-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

.ranking-panel {
    position: absolute;
    right: 18px;
    top: 18px;
    z-index: 24;
    width: min(340px, calc(100% - 36px));
    max-height: calc(100vh - 36px);
    padding: 14px;
    border-radius: 12px;
    overflow: visible;
}

.ranking-panel[data-mode="live"] {
    width: min(320px, calc(100% - 36px));
    pointer-events: none;
}

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

.ranking-head h2 {
    font-size: 1.1rem;
    font-weight: 900;
}

.ranking-head span {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
    border-radius: 999px;
    color: var(--ink);
    background: var(--gold);
    font-size: 0.72rem;
    font-weight: 900;
    text-transform: uppercase;
}

#ranking-list {
    display: grid;
    gap: 6px;
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}

#ranking-list li {
    display: grid;
    grid-template-columns: 30px 1fr auto auto;
    gap: 8px;
    align-items: center;
    min-height: 42px;
    padding: 7px 9px;
    border-radius: 8px;
    background: rgba(16, 36, 58, 0.07);
    font-weight: 900;
}

#ranking-list li span:nth-child(2) {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ranking-delete {
    display: none;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    color: white;
    background: #d83c32;
    font-weight: 900;
    pointer-events: auto;
}

.ranking-delete[hidden] {
    display: none;
}

.ranking-panel[data-editor="true"] .ranking-delete {
    display: grid;
    place-items: center;
}

.ranking-panel[data-editor="true"] {
    box-shadow: 0 16px 38px var(--shadow), inset 0 0 0 3px rgba(216, 60, 50, 0.22);
}

.music-player {
    position: absolute;
    top: 18px;
    left: 18px;
    z-index: 46;
    width: min(320px, calc(100% - 36px));
    display: none;
    gap: 10px;
    padding: 12px;
    border: 2px solid rgba(16, 36, 58, 0.08);
    border-radius: 12px;
    color: var(--ink);
    background: rgba(255, 250, 241, 0.94);
    box-shadow: 0 16px 38px var(--shadow);
    backdrop-filter: blur(14px);
    pointer-events: auto;
}

@media (max-height: 920px) {
    .ranking-panel {
        padding: 12px;
    }

    .ranking-head h2 {
        font-size: 1rem;
    }

    .ranking-head span {
        min-height: 24px;
        padding: 0 9px;
        font-size: 0.68rem;
    }

    #ranking-list {
        gap: 5px;
        margin-top: 10px;
    }

    #ranking-list li {
        min-height: 38px;
        padding: 6px 9px;
    }

    .rank-number {
        width: 22px;
        height: 22px;
        font-size: 0.8rem;
    }

    .music-player {
        gap: 8px;
        padding: 10px;
    }

    .music-player-controls {
        grid-template-columns: 38px 1fr 38px 46px;
        gap: 7px;
    }

    .music-player button {
        min-height: 34px;
    }
}

#game-shell[data-state="menu"] .music-player,
#game-shell[data-state="paused"] .music-player {
    display: grid;
}

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

.music-player-head span {
    font-size: 0.72rem;
    font-weight: 900;
    color: rgba(16, 36, 58, 0.62);
    text-transform: uppercase;
}

.music-player-head strong {
    color: var(--if-green-deep);
    font-size: 0.92rem;
    font-weight: 900;
}

.music-player-controls {
    display: grid;
    grid-template-columns: 42px 1fr 42px 50px;
    gap: 8px;
}

.music-player button {
    min-width: 0;
    min-height: 38px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    color: var(--ink);
    background: rgba(16, 36, 58, 0.08);
    font-size: 0.76rem;
    font-weight: 900;
}

.music-player button:hover,
.music-player button:focus-visible {
    color: white;
    background: var(--if-green);
    outline: none;
}

.music-player button[aria-pressed="true"] {
    color: white;
    background: var(--if-green-deep);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.26);
}

.shuffle-icon {
    width: 19px;
    height: 19px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.music-main-control {
    background: var(--gold) !important;
}

.music-volume {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 10px;
}

.music-volume span {
    color: rgba(16, 36, 58, 0.62);
    font-size: 0.72rem;
    font-weight: 900;
    text-transform: uppercase;
}

.music-volume input {
    width: 100%;
    accent-color: var(--if-green);
}

.rank-number {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: white;
    background: var(--if-green);
}

#ranking-list li.current-run {
    background: linear-gradient(135deg, rgba(255, 201, 74, 0.34), rgba(31, 138, 69, 0.18));
    box-shadow: inset 0 0 0 2px rgba(255, 201, 74, 0.38);
}

#ranking-list li.current-run .rank-number {
    color: var(--ink);
    background: var(--gold);
}

#ranking-list li.current-run .score-time strong {
    color: #0b6b37;
}

#ranking-list .meta {
    display: block;
    font-size: 0.72rem;
    color: rgba(16, 36, 58, 0.62);
    text-transform: uppercase;
}

#ranking-list .score-time {
    display: grid;
    justify-items: end;
    gap: 2px;
}

#ranking-list .score-time strong {
    line-height: 1;
    color: var(--if-green-deep);
}

#ranking-list .time {
    color: rgba(16, 36, 58, 0.58);
    font-size: 0.72rem;
    font-weight: 900;
}

@media (max-width: 1024px) {
    #hud {
        top: 12px;
        left: 12px;
        right: 300px;
    }

    .hud-brand {
        min-width: 220px;
        gap: 10px;
        padding: 8px 10px;
    }

    .brand-mark {
        width: 34px;
        height: 34px;
        border-radius: 7px;
        font-size: 0.82rem;
    }

    .hud-brand strong {
        font-size: 0.92rem;
    }

    .hud-brand span:last-child {
        font-size: 0.68rem;
    }

    .pause-btn {
        min-height: 40px;
        padding: 0 14px;
        font-size: 0.82rem;
    }

    .screen {
        padding: 70px 5.4vw 5.2vh;
    }

    .eyebrow {
        height: 24px;
        padding: 0 10px;
        border-radius: 7px;
        font-size: 0.68rem;
    }

    h1 {
        margin-top: 10px;
        font-size: 4rem;
    }

    .start-copy {
        max-width: 560px;
    }

    .start-copy p {
        max-width: 500px;
        margin-top: 12px;
        font-size: 1rem;
        line-height: 1.32;
    }

    .runner-card {
        width: min(500px, calc(100vw - 330px));
        gap: 10px;
        margin-top: 16px;
        padding: 10px;
        border-radius: 10px;
    }

    .runner-card span {
        font-size: 0.64rem;
    }

    .runner-card strong {
        font-size: 1.04rem;
    }

    .runner-card p {
        font-size: 0.78rem;
    }

    .start-actions,
    .end-actions {
        gap: 10px;
        margin-top: 18px;
    }

    .primary-btn,
    .ghost-btn,
    .selector-btn {
        min-height: 40px;
        border-radius: 7px;
        font-size: 0.9rem;
    }

    .primary-btn {
        padding: 0 20px;
    }

    .ghost-btn {
        padding: 0 16px;
    }

    .customize-panel {
        padding: 54px 5vw 28px;
    }

    .customize-card {
        width: min(370px, calc(100vw - 52px));
        max-height: calc(100vh - 64px);
        padding: 14px;
        border-radius: 12px;
    }

    .customize-card h2 {
        margin-top: 8px;
        font-size: 1.48rem;
    }

    .customize-close {
        top: 16px;
        right: 16px;
        width: 38px;
        height: 38px;
        font-size: 0.92rem;
    }

    .customize-row {
        grid-template-columns: 38px 1fr 38px;
        gap: 8px;
        margin-top: 6px;
        padding: 6px;
        border-radius: 10px;
    }

    .customize-row .selector-btn {
        width: 38px;
        min-height: 36px;
    }

    .customize-row span {
        font-size: 0.6rem;
    }

    .customize-row strong {
        font-size: 0.86rem;
    }

    .customize-card > .primary-btn {
        margin-top: 10px;
    }

    .pause-card,
    .confirm-card {
        width: min(370px, calc(100vw - 40px));
        padding: 18px;
        border-radius: 10px;
    }

    .pause-card h2,
    .confirm-card h2 {
        margin-top: 8px;
        font-size: 1.7rem;
    }

    .pause-card p,
    .confirm-card p {
        margin-top: 8px;
        font-size: 0.86rem;
        line-height: 1.28;
    }

    .result-panel {
        width: min(540px, calc(100% - 32px));
        padding: 20px;
    }

    .result-panel h2 {
        margin-top: 10px;
        font-size: 1.78rem;
    }

    .result-stats {
        gap: 8px;
        margin: 14px 0;
    }

    .result-stats div {
        min-height: 66px;
        padding: 10px;
    }

    .result-stats span,
    .score-form label {
        font-size: 0.68rem;
    }

    .result-stats strong {
        margin-top: 4px;
        font-size: 1.25rem;
    }

    .score-form input {
        min-height: 42px;
    }

    .quiz-window {
        width: min(660px, calc(100vw - 32px));
        max-height: calc(100vh - 36px);
        padding: 20px;
    }

    .quiz-body {
        margin-top: 12px;
    }

    .quiz-window h2 {
        margin-top: 10px;
        font-size: 1.75rem;
    }

    .quiz-difficulty {
        min-height: 26px;
        padding: 0 10px;
        font-size: 0.68rem;
    }

    #quiz-question {
        margin-top: 12px;
        padding: 14px 16px 16px;
        font-size: 0.94rem;
    }

    #quiz-question::after {
        height: 3px;
        margin-top: 12px;
    }

    .quiz-options {
        padding: 0 14px 14px;
    }

    .quiz-option {
        min-height: 50px;
        padding: 10px 11px;
        font-size: 0.88rem;
    }

    .ranking-panel {
        right: 10px;
        top: 10px;
        width: min(270px, calc(100% - 20px));
        max-height: calc(100vh - 20px);
        padding: 9px;
        border-radius: 10px;
    }

    .ranking-head {
        gap: 8px;
    }

    .ranking-head h2 {
        font-size: 0.92rem;
    }

    .ranking-head span {
        min-height: 22px;
        padding: 0 8px;
        font-size: 0.62rem;
    }

    #ranking-list {
        gap: 4px;
        margin-top: 8px;
    }

    #ranking-list li {
        grid-template-columns: 24px 1fr auto auto;
        gap: 6px;
        min-height: 32px;
        padding: 5px 7px;
        border-radius: 7px;
        font-size: 0.82rem;
    }

    .rank-number {
        width: 20px;
        height: 20px;
        border-radius: 7px;
        font-size: 0.72rem;
    }

    #ranking-list .score-time {
        gap: 0;
    }

    #ranking-list .score-time strong {
        font-size: 0.88rem;
    }

    #ranking-list .time {
        font-size: 0.62rem;
    }

    .ranking-panel[data-mode="live"] {
        width: 184px;
        padding: 7px;
        opacity: 0.92;
    }

    .ranking-panel[data-mode="live"] .ranking-head {
        gap: 8px;
    }

    .ranking-panel[data-mode="live"] .ranking-head h2 {
        font-size: 0.78rem;
    }

    .ranking-panel[data-mode="live"] .ranking-head span {
        min-height: 22px;
        padding: 0 8px;
        font-size: 0.62rem;
    }

    .ranking-panel[data-mode="live"] #ranking-list {
        gap: 4px;
        margin-top: 7px;
    }

    .ranking-panel[data-mode="live"] #ranking-list li {
        grid-template-columns: 22px 1fr auto;
        gap: 5px;
        min-height: 28px;
        padding: 4px 6px;
        border-radius: 7px;
        font-size: 0.76rem;
    }

    .ranking-panel[data-mode="live"] .rank-number {
        width: 18px;
        height: 18px;
        border-radius: 7px;
        font-size: 0.66rem;
    }

    .ranking-panel[data-mode="live"] #ranking-list .score-time {
        gap: 0;
    }

    .ranking-panel[data-mode="live"] #ranking-list .score-time strong {
        font-size: 0.72rem;
    }

    .ranking-panel[data-mode="live"] #ranking-list .time {
        display: none;
    }

    .music-player {
        top: 10px;
        left: 10px;
        width: min(292px, calc(100% - 20px));
        gap: 7px;
        padding: 9px;
        border-radius: 10px;
    }

    .music-player-head {
        gap: 8px;
    }

    .music-player-head span {
        font-size: 0.62rem;
    }

    .music-player-head strong {
        font-size: 0.8rem;
    }

    .music-player-controls {
        grid-template-columns: 34px 1fr 34px 40px;
        gap: 6px;
    }

    .music-player button {
        min-height: 32px;
        border-radius: 7px;
        font-size: 0.68rem;
    }

    .shuffle-icon {
        width: 17px;
        height: 17px;
    }

    .music-volume {
        gap: 8px;
    }

    .music-volume span {
        font-size: 0.62rem;
    }
}

@media (max-width: 1024px) and (min-width: 641px) {
    #game-over {
        justify-items: start;
        padding: 56px 300px 42px 42px;
    }

    #game-over .result-panel {
        width: min(500px, 100%);
    }

    #game-shell[data-state="gameover"] .ranking-panel {
        display: block;
        top: 10px;
        right: 10px;
        width: 270px;
        max-height: calc(100vh - 20px);
    }
}

@media (max-width: 768px) and (min-width: 641px) {
    #hud {
        top: 8px;
        left: 8px;
        right: 250px;
    }

    .screen {
        padding: 58px 252px 34px 36px;
    }

    h1 {
        font-size: 3.15rem;
    }

    .start-copy {
        max-width: 390px;
    }

    .start-copy p {
        max-width: 360px;
        margin-top: 10px;
        font-size: 0.86rem;
        line-height: 1.25;
    }

    .runner-card {
        width: min(390px, calc(100vw - 288px));
        grid-template-columns: 1fr auto;
        gap: 8px;
        margin-top: 12px;
        padding: 8px;
    }

    .runner-card p {
        display: block;
        font-size: 0.7rem;
    }

    .runner-card strong {
        font-size: 0.94rem;
    }

    .start-actions,
    .end-actions {
        margin-top: 14px;
    }

    .primary-btn,
    .ghost-btn,
    .selector-btn {
        min-height: 36px;
        font-size: 0.82rem;
    }

    .ranking-panel {
        top: 8px;
        right: 8px;
        width: 236px;
        max-height: calc(100vh - 16px);
        padding: 8px;
    }

    .ranking-head h2 {
        font-size: 0.82rem;
    }

    .ranking-head span {
        min-height: 20px;
        padding: 0 7px;
        font-size: 0.58rem;
    }

    #ranking-list {
        gap: 4px;
        margin-top: 7px;
    }

    #ranking-list li {
        grid-template-columns: 22px 1fr auto auto;
        gap: 5px;
        min-height: 28px;
        padding: 4px 6px;
        font-size: 0.72rem;
    }

    .rank-number {
        width: 18px;
        height: 18px;
        font-size: 0.64rem;
    }

    #ranking-list .score-time strong {
        font-size: 0.76rem;
    }

    #ranking-list .time {
        font-size: 0.56rem;
    }

    .ranking-panel[data-mode="live"] {
        width: 168px;
    }

    .ranking-panel[data-mode="live"] .ranking-head h2 {
        font-size: 0.72rem;
    }

    .ranking-panel[data-mode="live"] .ranking-head span {
        min-height: 19px;
        padding: 0 6px;
        font-size: 0.55rem;
    }

    .ranking-panel[data-mode="live"] #ranking-list li {
        grid-template-columns: 20px 1fr auto;
        min-height: 25px;
        padding: 3px 5px;
        font-size: 0.68rem;
    }

    .ranking-panel[data-mode="live"] .rank-number {
        width: 16px;
        height: 16px;
        font-size: 0.58rem;
    }

    .ranking-panel[data-mode="live"] #ranking-list .score-time strong {
        font-size: 0.66rem;
    }

    .music-player {
        top: 8px;
        left: 8px;
        width: min(260px, calc(100% - 16px));
        padding: 8px;
    }

    .music-player-controls {
        grid-template-columns: 30px 1fr 30px 36px;
        gap: 5px;
    }

    .music-player button {
        min-height: 30px;
        font-size: 0.62rem;
    }

    .music-player-head span,
    .music-volume span {
        font-size: 0.58rem;
    }

    .music-player-head strong {
        font-size: 0.72rem;
    }

    .customize-panel {
        align-items: center;
        justify-items: end;
        padding: 46px 18px 24px 12px;
    }

    .customize-card {
        width: 300px;
        max-height: calc(100vh - 70px);
        padding: 12px;
    }

    .customize-card h2 {
        margin-top: 7px;
        font-size: 1.22rem;
    }

    .customize-close {
        top: 14px;
        right: 14px;
        width: 36px;
        height: 36px;
    }

    .customize-row {
        grid-template-columns: 34px 1fr 34px;
        gap: 6px;
        margin-top: 5px;
        padding: 5px;
    }

    .customize-row .selector-btn {
        width: 34px;
        min-height: 33px;
    }

    .customize-row span {
        font-size: 0.54rem;
    }

    .customize-row strong {
        font-size: 0.74rem;
    }

    .customize-card > .primary-btn {
        margin-top: 8px;
    }

    #game-over {
        padding: 52px 252px 34px 28px;
    }

    #game-over .result-panel {
        width: min(420px, 100%);
        padding: 16px;
    }
}

/* Final mobile fit pass: keep the main character, ranking, quiz and result panels usable on narrow screens. */
@media (max-width: 738px) {
    #game-shell[data-state="gameover"] .ranking-drawer-toggle {
        display: inline-flex;
        top: 12px;
        right: 12px;
        z-index: 55;
    }

    #game-shell[data-state="gameover"] .ranking-panel[data-mode="full"] {
        top: 62px;
        right: 10px;
        left: auto;
        bottom: auto;
        width: min(318px, calc(100vw - 20px));
        max-height: calc(100vh - 76px);
        opacity: 0;
        overflow: hidden;
        pointer-events: none;
        transform: translateX(calc(100% + 18px));
        transition: opacity 160ms ease, transform 160ms ease;
        z-index: 50;
    }

    #game-shell[data-state="gameover"][data-ranking-open="true"] .ranking-panel[data-mode="full"] {
        opacity: 1;
        overflow: auto;
        pointer-events: auto;
        transform: translateX(0);
    }

    #game-over {
        justify-items: center;
        align-content: center;
        padding: 24px 12px;
    }

    #game-over .result-panel {
        width: min(500px, calc(100vw - 24px));
        max-width: none;
    }
}

@media (max-width: 675px) and (min-width: 509px) {
    #game-shell[data-state="customize"] .customize-panel {
        align-items: center;
        justify-items: start;
        padding: 44px 12px 20px;
        background: linear-gradient(90deg, rgba(10, 22, 32, 0.28), rgba(10, 22, 32, 0.04) 56%, rgba(10, 22, 32, 0));
    }

    #game-shell[data-state="customize"] .customize-card {
        width: 258px;
        max-height: calc(100vh - 76px);
        padding: 10px;
    }

    #game-shell[data-state="customize"] .customize-card h2 {
        margin-top: 7px;
        font-size: 1.05rem;
    }

    #game-shell[data-state="customize"] .customize-row {
        grid-template-columns: 31px 1fr 31px;
        gap: 5px;
        margin-top: 5px;
        padding: 5px;
    }

    #game-shell[data-state="customize"] .customize-row .selector-btn {
        width: 31px;
        min-height: 31px;
    }

    #game-shell[data-state="customize"] .customize-row span {
        font-size: 0.5rem;
    }

    #game-shell[data-state="customize"] .customize-row strong {
        font-size: 0.68rem;
    }

    #game-shell[data-state="customize"] .customize-card > .primary-btn {
        margin-top: 8px;
        min-height: 44px;
        font-size: 0.82rem;
    }
}

@media (max-width: 642px) {
    #game-shell[data-state="menu"] .ranking-drawer-toggle,
    #game-shell[data-state="gameover"] .ranking-drawer-toggle {
        display: inline-flex;
        z-index: 55;
    }

    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"],
    #game-shell[data-state="gameover"] .ranking-panel[data-mode="full"] {
        right: 10px;
        left: auto;
        bottom: auto;
        width: min(318px, calc(100vw - 20px));
        opacity: 0;
        overflow: hidden;
        pointer-events: none;
        transform: translateX(calc(100% + 18px));
        transition: opacity 160ms ease, transform 160ms ease;
        z-index: 50;
    }

    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"] {
        top: 64px;
        max-height: calc(100vh - 74px);
    }

    #game-shell[data-state="gameover"] .ranking-panel[data-mode="full"] {
        top: 62px;
        max-height: calc(100vh - 76px);
    }

    #game-shell[data-ranking-open="true"] .ranking-drawer-toggle {
        color: var(--ink);
        background: var(--paper);
    }

    #game-shell[data-ranking-open="true"] .ranking-panel[data-mode="full"] {
        opacity: 1;
        overflow: auto;
        pointer-events: auto;
        transform: translateX(0);
    }

    .ranking-panel[data-mode="live"] {
        width: 166px;
    }
}

@media (max-width: 553px) {
    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"] {
        top: 126px;
        max-height: calc(100vh - 136px);
    }
}

@media (max-width: 508px) {
    #game-shell[data-state="customize"] .customize-panel {
        align-items: end;
        justify-items: center;
        padding: 78px 8px 10px;
        background: linear-gradient(180deg, rgba(10, 22, 32, 0.04), rgba(10, 22, 32, 0.42));
    }

    #game-shell[data-state="customize"] .customize-card {
        width: calc(100vw - 16px);
        max-height: 52vh;
        padding: 12px;
        overflow-y: auto;
    }

    #game-shell[data-state="customize"] .customize-card h2 {
        margin-top: 8px;
        font-size: 1.14rem;
    }

    #game-shell[data-state="customize"] .customize-row {
        grid-template-columns: 38px 1fr 38px;
        gap: 7px;
        margin-top: 7px;
        padding: 7px;
    }

    #game-shell[data-state="customize"] .customize-row .selector-btn {
        width: 38px;
        min-height: 38px;
    }

    #game-shell[data-state="customize"] .customize-row span {
        font-size: 0.58rem;
    }

    #game-shell[data-state="customize"] .customize-row strong {
        font-size: 0.78rem;
    }

    #game-shell[data-state="customize"] .customize-card > .primary-btn {
        min-height: 46px;
        font-size: 0.88rem;
    }
}

@media (max-width: 426px) {
    .quiz-panel {
        padding: 8px;
    }

    .quiz-window {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        padding: 12px;
        overflow-y: auto;
    }

    .quiz-window h2 {
        font-size: 1.34rem;
        line-height: 1.04;
    }

    .quiz-badge {
        padding: 8px 12px;
        font-size: 0.62rem;
    }

    #quiz-difficulty {
        margin-top: 10px;
        font-size: 0.68rem;
    }

    #quiz-question {
        margin-top: 10px;
        padding: 10px 10px 13px;
        font-size: 0.84rem;
        line-height: 1.18;
    }

    #quiz-question::after {
        width: 82%;
        height: 3px;
    }

    .quiz-options {
        padding: 0 6px 8px;
    }

    .quiz-option {
        min-height: 44px;
        gap: 8px;
        padding: 8px 10px;
        font-size: 0.78rem;
        line-height: 1.18;
    }
}

@media (max-width: 330px) {
    #game-over {
        align-content: start;
        padding: 6px;
        overflow-y: auto;
    }

    #game-over .result-panel {
        width: calc(100vw - 12px);
        max-height: calc(100vh - 12px);
        padding: 10px;
        overflow-y: auto;
    }

    #game-over .result-panel h2 {
        font-size: 1.5rem;
        line-height: 1.05;
    }

    .result-stats {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .score-form div {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .score-form input,
    .score-form .primary-btn {
        min-height: 42px;
    }

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

@media (max-width: 320px) {
    #game-shell[data-state="menu"] .ranking-drawer-toggle {
        top: 122px;
    }

    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"] {
        top: 166px;
        max-height: calc(100vh - 176px);
    }
}

@media (max-width: 737px) {
    #game-shell[data-state="gameover"] .ranking-drawer-toggle {
        display: inline-flex;
    }

    #game-shell[data-state="gameover"] .ranking-panel[data-mode="full"] {
        top: 58px;
        right: 10px;
        left: auto;
        bottom: auto;
        width: min(320px, calc(100vw - 20px));
        max-height: calc(100vh - 68px);
        padding: 10px;
        overflow: auto;
        opacity: 0;
        pointer-events: none;
        transform: translateX(calc(100% + 24px));
        z-index: 46;
    }

    #game-shell[data-ranking-open="true"][data-state="gameover"] .ranking-panel[data-mode="full"] {
        opacity: 1;
        pointer-events: auto;
        transform: translateX(0);
    }

    #game-over {
        padding: 28px 14px;
    }
}

@media (max-width: 674px) and (min-width: 507px) {
    #game-shell[data-state="customize"] .customize-panel {
        align-items: center;
        justify-items: start;
        padding: 44px 12px 20px;
        background:
            radial-gradient(circle at 68% 46%, rgba(255, 244, 205, 0.18), transparent 30%),
            linear-gradient(90deg, rgba(6, 18, 29, 0.64), rgba(6, 18, 29, 0.08) 52%, rgba(6, 18, 29, 0.02));
    }

    #game-shell[data-state="customize"] .customize-card {
        width: 258px;
        max-height: calc(100vh - 76px);
        padding: 10px;
    }

    #game-shell[data-state="customize"] .customize-card h2 {
        font-size: 1.05rem;
    }

    #game-shell[data-state="customize"] .customize-row {
        grid-template-columns: 30px 1fr 30px;
        gap: 5px;
        margin-top: 5px;
        padding: 5px;
    }

    #game-shell[data-state="customize"] .customize-row .selector-btn {
        width: 30px;
        min-height: 30px;
    }

    #game-shell[data-state="customize"] .customize-row span {
        font-size: 0.5rem;
    }

    #game-shell[data-state="customize"] .customize-row strong {
        font-size: 0.68rem;
    }
}

@media (max-width: 640px) {
    #game-shell[data-state="menu"] .ranking-drawer-toggle,
    #game-shell[data-state="gameover"] .ranking-drawer-toggle {
        display: inline-flex;
    }

    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"],
    #game-shell[data-state="gameover"] .ranking-panel[data-mode="full"] {
        top: 58px;
        right: 10px;
        left: auto;
        bottom: auto;
        width: min(320px, calc(100vw - 20px));
        max-height: calc(100vh - 68px);
        padding: 10px;
        overflow: auto;
        opacity: 0;
        pointer-events: none;
        transform: translateX(calc(100% + 24px));
        z-index: 46;
    }

    #game-shell[data-ranking-open="true"][data-state="menu"] .ranking-panel[data-mode="full"],
    #game-shell[data-ranking-open="true"][data-state="gameover"] .ranking-panel[data-mode="full"] {
        opacity: 1;
        pointer-events: auto;
        transform: translateX(0);
    }

    #game-shell .ranking-panel[data-mode="live"] {
        top: 8px;
        right: 8px;
        left: auto;
        width: 166px;
        max-height: calc(100vh - 16px);
        padding: 7px;
    }
}

@media (max-width: 552px) {
    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"] {
        top: 124px;
        max-height: calc(100vh - 134px);
    }
}

@media (max-width: 506px) {
    #game-shell[data-state="customize"] .customize-panel {
        align-items: end;
        justify-items: center;
        padding: 78px 10px 10px;
        background:
            linear-gradient(180deg, rgba(6, 18, 29, 0.04), rgba(6, 18, 29, 0.22) 46%, rgba(6, 18, 29, 0.72));
    }

    #game-shell[data-state="customize"] .customize-card {
        width: calc(100vw - 20px);
        max-height: 48vh;
        padding: 12px;
        border-radius: 10px;
    }

    #game-shell[data-state="customize"] .customize-card h2 {
        font-size: 1.18rem;
    }

    #game-shell[data-state="customize"] .customize-row {
        grid-template-columns: 34px 1fr 34px;
        gap: 7px;
        padding: 6px;
    }

    #game-shell[data-state="customize"] .customize-row .selector-btn {
        width: 34px;
        min-height: 34px;
    }

    #game-shell[data-state="customize"] .customize-row span {
        font-size: 0.54rem;
    }

    #game-shell[data-state="customize"] .customize-row strong {
        font-size: 0.78rem;
    }
}

@media (max-width: 425px) {
    .quiz-panel {
        padding: 8px;
    }

    .quiz-window {
        width: calc(100vw - 12px);
        max-height: calc(100vh - 12px);
        padding: 12px;
        border-radius: 8px;
    }

    .quiz-window h2 {
        margin-top: 8px;
        font-size: 1.34rem;
    }

    #quiz-question {
        margin-top: 10px;
        padding: 11px 12px 13px;
        border-width: 2px;
        border-bottom: 0;
        font-size: 0.84rem;
        line-height: 1.3;
    }

    .quiz-options {
        padding: 0 8px 10px;
        border-width: 2px;
        border-top: 0;
    }

    .quiz-option {
        min-height: 44px;
        gap: 6px;
        padding: 8px 9px;
        font-size: 0.78rem;
    }
}

@media (max-width: 329px) {
    #game-over {
        padding: 8px;
    }

    #game-over .result-panel {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        padding: 12px;
        overflow: auto;
    }

    .result-panel h2 {
        margin-top: 8px;
        font-size: 1.28rem;
    }

    .result-stats {
        grid-template-columns: 1fr;
        gap: 6px;
        margin: 10px 0;
    }

    .result-stats div {
        min-height: 0;
        padding: 8px;
    }

    .score-form input {
        min-height: 38px;
        padding: 0 10px;
    }
}

@media (max-width: 319px) {
    #game-shell[data-state="menu"] .ranking-drawer-toggle {
        top: 122px;
    }

    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"] {
        top: 166px;
        max-height: calc(100vh - 176px);
    }
}

@media (max-width: 737px) {
    #game-shell[data-state="gameover"] .ranking-drawer-toggle {
        display: inline-flex;
    }

    #game-shell[data-state="gameover"] .ranking-panel[data-mode="full"] {
        top: 58px;
        right: 10px;
        left: auto;
        bottom: auto;
        width: min(320px, calc(100vw - 20px));
        max-height: calc(100vh - 68px);
        padding: 10px;
        overflow: auto;
        opacity: 0;
        pointer-events: none;
        transform: translateX(calc(100% + 24px));
        transition: transform 0.22s ease, opacity 0.22s ease;
        z-index: 46;
    }

    #game-shell[data-ranking-open="true"][data-state="gameover"] .ranking-panel[data-mode="full"] {
        opacity: 1;
        pointer-events: auto;
        transform: translateX(0);
    }

    #game-over {
        padding: 28px 14px;
    }

    #game-over .result-panel {
        width: min(420px, calc(100vw - 28px));
    }
}

@media (max-width: 674px) and (min-width: 506px) {
    .customize-panel {
        align-items: center;
        justify-items: start;
        padding: 44px 12px 20px;
        background:
            radial-gradient(circle at 68% 46%, rgba(255, 244, 205, 0.18), transparent 30%),
            linear-gradient(90deg, rgba(6, 18, 29, 0.64), rgba(6, 18, 29, 0.08) 52%, rgba(6, 18, 29, 0.02));
    }

    .customize-card {
        width: 258px;
        max-height: calc(100vh - 76px);
        padding: 10px;
    }

    .customize-card h2 {
        font-size: 1.05rem;
    }

    .customize-row {
        grid-template-columns: 30px 1fr 30px;
        gap: 5px;
        margin-top: 5px;
        padding: 5px;
    }

    .customize-row .selector-btn {
        width: 30px;
        min-height: 30px;
    }

    .customize-row span {
        font-size: 0.5rem;
    }

    .customize-row strong {
        font-size: 0.68rem;
    }
}

@media (max-width: 640px) {
    #game-shell[data-state="menu"] .ranking-drawer-toggle,
    #game-shell[data-state="gameover"] .ranking-drawer-toggle {
        display: inline-flex;
    }

    #game-shell[data-ranking-open="true"] .ranking-drawer-toggle {
        color: var(--ink);
        background: var(--paper);
    }

    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"],
    #game-shell[data-state="gameover"] .ranking-panel[data-mode="full"] {
        top: 58px;
        right: 10px;
        left: auto;
        bottom: auto;
        width: min(320px, calc(100vw - 20px));
        max-height: calc(100vh - 68px);
        padding: 10px;
        overflow: auto;
        opacity: 0;
        pointer-events: none;
        transform: translateX(calc(100% + 24px));
        transition: transform 0.22s ease, opacity 0.22s ease;
        z-index: 46;
    }

    #game-shell[data-ranking-open="true"][data-state="menu"] .ranking-panel[data-mode="full"],
    #game-shell[data-ranking-open="true"][data-state="gameover"] .ranking-panel[data-mode="full"] {
        opacity: 1;
        pointer-events: auto;
        transform: translateX(0);
    }

    #game-shell .ranking-panel[data-mode="live"] {
        top: 8px;
        right: 8px;
        left: auto;
        width: 166px;
        max-height: calc(100vh - 16px);
        padding: 7px;
    }

    #game-shell .ranking-panel[data-mode="live"] #ranking-list li {
        grid-template-columns: 20px 1fr auto;
        min-height: 25px;
        padding: 3px 5px;
        font-size: 0.68rem;
    }

    #game-shell .ranking-panel[data-mode="live"] .rank-number {
        width: 16px;
        height: 16px;
        font-size: 0.58rem;
    }

    #game-shell .ranking-panel[data-mode="live"] #ranking-list .score-time strong {
        font-size: 0.66rem;
    }
}

@media (max-width: 552px) {
    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"] {
        top: 124px;
        max-height: calc(100vh - 134px);
    }
}

@media (max-width: 505px) {
    .customize-panel {
        align-items: end;
        justify-items: center;
        padding: 78px 10px 10px;
        background:
            linear-gradient(180deg, rgba(6, 18, 29, 0.04), rgba(6, 18, 29, 0.22) 46%, rgba(6, 18, 29, 0.72));
    }

    .customize-card {
        width: calc(100vw - 20px);
        max-height: 48vh;
        padding: 12px;
        border-radius: 10px;
    }

    .customize-card h2 {
        font-size: 1.18rem;
    }

    .customize-row {
        grid-template-columns: 34px 1fr 34px;
        gap: 7px;
        padding: 6px;
    }

    .customize-row .selector-btn {
        width: 34px;
        min-height: 34px;
    }

    .customize-row span {
        font-size: 0.54rem;
    }

    .customize-row strong {
        font-size: 0.78rem;
    }
}

@media (max-width: 425px) {
    .quiz-panel {
        padding: 8px;
    }

    .quiz-window {
        width: calc(100vw - 12px);
        max-height: calc(100vh - 12px);
        padding: 12px;
        border-radius: 8px;
    }

    .quiz-window h2 {
        margin-top: 8px;
        font-size: 1.34rem;
    }

    .quiz-body {
        margin-top: 10px;
    }

    .quiz-difficulty {
        min-height: 24px;
        padding: 0 9px;
        font-size: 0.62rem;
    }

    #quiz-question {
        margin-top: 10px;
        padding: 11px 12px 13px;
        border-width: 2px;
        border-bottom: 0;
        font-size: 0.84rem;
        line-height: 1.3;
    }

    #quiz-question::after {
        width: 88%;
        height: 3px;
        margin-top: 10px;
    }

    .quiz-options {
        padding: 0 8px 10px;
        border-width: 2px;
        border-top: 0;
    }

    .quiz-option {
        min-height: 44px;
        gap: 6px;
        padding: 8px 9px;
        font-size: 0.78rem;
    }

    .quiz-option-letter {
        min-width: 26px;
    }

    .quiz-feedback {
        min-height: 20px;
        margin-top: 8px;
        font-size: 0.8rem;
    }
}

@media (max-width: 329px) {
    #game-over {
        padding: 8px;
    }

    #game-over .result-panel {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        padding: 12px;
        overflow: auto;
    }

    .result-panel h2 {
        margin-top: 8px;
        font-size: 1.28rem;
    }

    .result-stats {
        grid-template-columns: 1fr;
        gap: 6px;
        margin: 10px 0;
    }

    .result-stats div {
        min-height: 0;
        padding: 8px;
    }

    .result-stats strong {
        font-size: 1.1rem;
    }

    .score-form input {
        min-height: 38px;
        padding: 0 10px;
    }

    .end-actions {
        gap: 8px;
        margin-top: 10px;
    }
}

@media (max-width: 319px) {
    #game-shell[data-state="menu"] .ranking-drawer-toggle {
        top: 122px;
    }

    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"] {
        top: 166px;
        max-height: calc(100vh - 176px);
    }
}

@media (max-width: 640px) {
    #game-shell .ranking-panel[data-mode="live"] {
        top: 8px;
        right: 8px;
        left: auto;
        width: 166px;
        max-height: calc(100vh - 16px);
        padding: 7px;
    }
}

@media (max-width: 640px) {
    #game-shell[data-state="menu"] .ranking-drawer-toggle,
    #game-shell[data-state="gameover"] .ranking-drawer-toggle {
        display: inline-flex;
    }

    #game-shell[data-ranking-open="true"] .ranking-drawer-toggle {
        color: var(--ink);
        background: var(--paper);
    }

    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"],
    #game-shell[data-state="gameover"] .ranking-panel[data-mode="full"] {
        top: 58px;
        right: 10px;
        left: auto;
        bottom: auto;
        width: min(320px, calc(100vw - 20px));
        max-height: calc(100vh - 68px);
        padding: 10px;
        overflow: auto;
        opacity: 0;
        pointer-events: none;
        transform: translateX(calc(100% + 24px));
        transition: transform 0.22s ease, opacity 0.22s ease;
        z-index: 46;
    }

    #game-shell[data-ranking-open="true"][data-state="menu"] .ranking-panel[data-mode="full"],
    #game-shell[data-ranking-open="true"][data-state="gameover"] .ranking-panel[data-mode="full"] {
        opacity: 1;
        pointer-events: auto;
        transform: translateX(0);
    }

    .ranking-panel[data-mode="live"] {
        top: 8px;
        right: 8px;
        left: auto;
        width: 166px;
        max-height: calc(100vh - 16px);
        padding: 7px;
    }

    .ranking-panel[data-mode="live"] #ranking-list li {
        grid-template-columns: 20px 1fr auto;
        min-height: 25px;
        padding: 3px 5px;
        font-size: 0.68rem;
    }

    .ranking-panel[data-mode="live"] .rank-number {
        width: 16px;
        height: 16px;
        font-size: 0.58rem;
    }

    .ranking-panel[data-mode="live"] #ranking-list .score-time strong {
        font-size: 0.66rem;
    }
}

@media (max-width: 640px) {
    #game-shell[data-state="menu"] .ranking-drawer-toggle,
    #game-shell[data-state="gameover"] .ranking-drawer-toggle {
        display: inline-flex;
    }

    #game-shell[data-ranking-open="true"] .ranking-drawer-toggle {
        color: var(--ink);
        background: var(--paper);
    }

    #game-shell[data-state="menu"] .ranking-panel[data-mode="full"],
    #game-shell[data-state="gameover"] .ranking-panel[data-mode="full"] {
        top: 58px;
        right: 10px;
        left: auto;
        bottom: auto;
        width: min(320px, calc(100vw - 20px));
        max-height: calc(100vh - 68px);
        padding: 10px;
        overflow: auto;
        opacity: 0;
        pointer-events: none;
        transform: translateX(calc(100% + 24px));
        transition: transform 0.22s ease, opacity 0.22s ease;
        z-index: 46;
    }

    #game-shell[data-ranking-open="true"][data-state="menu"] .ranking-panel[data-mode="full"],
    #game-shell[data-ranking-open="true"][data-state="gameover"] .ranking-panel[data-mode="full"] {
        opacity: 1;
        pointer-events: auto;
        transform: translateX(0);
    }

    .ranking-panel[data-mode="live"] {
        top: 8px;
        right: 8px;
        width: 166px;
        max-height: calc(100vh - 16px);
        padding: 7px;
    }

    .ranking-panel[data-mode="live"] #ranking-list li {
        grid-template-columns: 20px 1fr auto;
        min-height: 25px;
        padding: 3px 5px;
        font-size: 0.68rem;
    }

    .ranking-panel[data-mode="live"] .rank-number {
        width: 16px;
        height: 16px;
        font-size: 0.58rem;
    }

    .ranking-panel[data-mode="live"] #ranking-list .score-time strong {
        font-size: 0.66rem;
    }
}

@media (max-width: 720px) {
    #hud {
        grid-template-columns: auto;
        gap: 8px;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .hud-brand {
        min-width: 0;
        padding: 8px;
    }

    .hud-brand div {
        display: none;
    }

    .hud-score {
        min-width: 0;
        padding: 8px;
    }

    .hud-score strong {
        font-size: 1.2rem;
    }

    .pause-btn {
        min-height: 44px;
        padding: 0 10px;
        font-size: 0.78rem;
    }

    .screen {
        padding: 86px 18px 34px;
    }

    h1 {
        font-size: 3.4rem;
    }

    .start-copy p {
        font-size: 1rem;
    }

    .runner-card {
        grid-template-columns: 1fr;
        gap: 8px;
        margin-top: 16px;
    }

    .runner-card p {
        display: none;
    }

    .selector-btn {
        width: 42px;
    }

    .customize-panel {
        align-items: end;
        justify-items: center;
        padding: 72px 12px 18px;
    }

    .customize-card {
        padding: 16px;
    }

    .customize-card h2 {
        font-size: 1.55rem;
    }

    .result-panel {
        padding: 18px;
    }

    .quiz-panel {
        padding: 14px;
    }

    .quiz-window {
        padding: 18px;
    }

    .quiz-window h2 {
        font-size: 1.65rem;
    }

    #quiz-question {
        font-size: 0.98rem;
        padding: 14px 14px 16px;
    }

    #quiz-question::after {
        width: 86%;
        height: 3px;
    }

    .quiz-options {
        padding: 0 10px 12px;
    }

    .quiz-option {
        min-height: 54px;
        grid-template-columns: auto 1fr;
    }

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

    .score-form div {
        grid-template-columns: 1fr;
    }

    .ranking-panel {
        top: 150px;
        right: 10px;
        left: 10px;
        bottom: auto;
        width: auto;
        max-height: calc(100vh - 160px);
        overflow: visible;
    }

    .ranking-panel[data-mode="live"] {
        top: 10px;
        right: 10px;
        left: auto;
        width: 190px;
        max-height: calc(100vh - 20px);
    }

    .music-player {
        top: 10px;
        left: 10px;
        width: auto;
    }

    .ranking-editor-toggle {
        left: 10px;
        bottom: 10px;
    }
}

@media (max-width: 768px) and (min-width: 641px) {
    #hud {
        top: 8px;
        left: 8px;
        right: 250px;
    }

    .screen {
        padding: 58px 252px 34px 36px;
    }

    h1 {
        font-size: 3.15rem;
    }

    .start-copy p {
        max-width: 360px;
        margin-top: 10px;
        font-size: 0.86rem;
        line-height: 1.25;
    }

    .runner-card {
        width: min(390px, calc(100vw - 288px));
        grid-template-columns: 1fr auto;
        gap: 8px;
        margin-top: 12px;
        padding: 8px;
    }

    .runner-card p {
        display: block;
        font-size: 0.7rem;
    }

    .ranking-panel {
        top: 8px;
        right: 8px;
        left: auto;
        bottom: auto;
        width: 236px;
        max-height: calc(100vh - 16px);
        padding: 8px;
        overflow: visible;
    }

    .ranking-panel[data-mode="live"] {
        top: 8px;
        right: 8px;
        left: auto;
        width: 168px;
        max-height: calc(100vh - 16px);
    }

    .music-player {
        top: 8px;
        left: 8px;
        width: min(260px, calc(100% - 16px));
    }

    .customize-panel {
        align-items: center;
        justify-items: end;
        padding: 46px 18px 24px 12px;
    }

    .customize-card {
        width: 260px;
        max-height: calc(100vh - 70px);
        padding: 10px;
    }

    .customize-card h2 {
        font-size: 1.08rem;
    }

    .customize-row {
        grid-template-columns: 31px 1fr 31px;
        gap: 5px;
        margin-top: 5px;
        padding: 5px;
    }

    .customize-row .selector-btn {
        width: 31px;
        min-height: 31px;
    }

    .customize-row span {
        font-size: 0.5rem;
    }

    .customize-row strong {
        font-size: 0.68rem;
    }

    #game-over {
        padding: 52px 252px 34px 28px;
    }

    #game-over .result-panel {
        width: min(420px, 100%);
        padding: 16px;
    }
}
