:root {
    color-scheme: dark;
    --navy-950: #041326;
    --navy-900: #071c36;
    --blue: #4dd9ff;
    --gold: #ffd25a;
    --coral: #ff6f61;
    --mint: #66e6b7;
    --white: #f8fcff;
    --glass: rgba(7, 24, 46, .72);
    --line: rgba(255, 255, 255, .16);
    --safe-top: max(12px, env(safe-area-inset-top));
    --safe-right: max(12px, env(safe-area-inset-right));
    --safe-bottom: max(12px, env(safe-area-inset-bottom));
    --safe-left: max(12px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }

html,
body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--navy-950);
    font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button, a { font: inherit; }
button { -webkit-appearance: none; appearance: none; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
[hidden] { display: none !important; }

#gameCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    background: var(--navy-900);
}

.game-app { position: fixed; inset: 0; isolation: isolate; color: var(--white); }

.screen,
.overlay-screen {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    overflow: auto;
    padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 10px) calc(var(--safe-bottom) + 10px) calc(var(--safe-left) + 10px);
}

.screen-start {
    background:
        linear-gradient(115deg, rgba(2, 12, 27, .76), rgba(5, 25, 50, .28) 62%, rgba(4, 19, 38, .68)),
        radial-gradient(circle at 74% 32%, rgba(77, 217, 255, .18), transparent 30%);
}

.start-card,
.dialog-card {
    width: min(600px, 100%);
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 30px;
    background: linear-gradient(145deg, rgba(9, 37, 69, .94), rgba(4, 20, 40, .94));
    box-shadow: 0 30px 100px rgba(0, 0, 0, .46), inset 0 1px 0 rgba(255, 255, 255, .12);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
}

.start-card { padding: 28px 30px 24px; }
.brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-mark {
    width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px;
    color: var(--navy-950); background: var(--blue); font-size: 11px; font-weight: 950;
    letter-spacing: -.04em; box-shadow: 0 0 24px rgba(77, 217, 255, .35);
}
.brand-name { font-size: 10px; font-weight: 850; letter-spacing: .2em; color: rgba(248, 252, 255, .66); }
.icon-link {
    margin-left: auto; width: 44px; height: 44px; display: grid; place-items: center;
    border: 1px solid var(--line); border-radius: 13px; color: var(--white); text-decoration: none;
    background: rgba(255, 255, 255, .06); font-size: 22px;
}
.start-hero { display: flex; align-items: center; gap: 18px; }
.mascot-badge {
    flex: 0 0 auto; width: 84px; height: 84px; display: grid; place-items: center;
    border: 1px solid rgba(255, 210, 90, .42); border-radius: 25px;
    background: linear-gradient(145deg, rgba(255, 210, 90, .2), rgba(255, 111, 97, .1));
    font-size: 43px; transform: rotate(-3deg);
}
.eyebrow { margin: 0 0 5px; color: var(--blue); font-size: 10px; font-weight: 900; letter-spacing: .22em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(36px, 7vw, 58px); line-height: .98; letter-spacing: -.055em; }
h1 em { color: var(--gold); font-style: normal; text-shadow: 0 0 28px rgba(255, 210, 90, .22); }
.start-copy { margin-bottom: 0; color: rgba(248, 252, 255, .72); font-size: 14px; line-height: 1.55; }

.mission-strip {
    display: grid; grid-template-columns: 1fr 1px 1fr 1px 1fr; align-items: center;
    gap: 12px; margin: 24px 0 22px; padding: 14px 16px; border: 1px solid var(--line);
    border-radius: 18px; background: rgba(255, 255, 255, .055);
}
.mission-strip span { text-align: center; }
.mission-strip b { display: block; color: var(--gold); font-size: 20px; line-height: 1.1; }
.mission-strip small { color: rgba(248, 252, 255, .62); font-size: 10px; font-weight: 700; }
.mission-strip i { width: 1px; height: 26px; background: var(--line); }

.difficulty-field { min-width: 0; margin: 0 0 18px; padding: 0; border: 0; }
.difficulty-field legend { margin-bottom: 9px; color: rgba(248, 252, 255, .72); font-size: 12px; font-weight: 800; }
.level-selector { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.level-btn {
    min-height: 44px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 13px;
    color: rgba(248, 252, 255, .72); background: rgba(255, 255, 255, .045);
    font-size: 12px; font-weight: 800; cursor: pointer;
    transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.level-btn:hover { transform: translateY(-1px); border-color: rgba(77, 217, 255, .5); }
.level-btn.is-active {
    border-color: var(--blue); color: #03192e; background: var(--blue);
    box-shadow: 0 7px 22px rgba(77, 217, 255, .2);
}

.primary-btn {
    width: 100%; min-height: 56px; display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 0 20px; border: 0; border-radius: 17px; color: #04172b;
    background: linear-gradient(105deg, var(--gold), #ffbd4a);
    box-shadow: 0 12px 32px rgba(255, 191, 74, .22), inset 0 1px 0 rgba(255, 255, 255, .55);
    font-size: 16px; font-weight: 950; cursor: pointer; transition: transform .15s ease, filter .15s ease;
}
.primary-btn:hover { filter: brightness(1.05); transform: translateY(-2px); }
.primary-btn:active { transform: translateY(1px) scale(.995); }
.primary-btn span:last-child { font-size: 23px; }

.start-footer {
    display: flex; justify-content: space-between; gap: 16px; margin-top: 15px;
    color: rgba(248, 252, 255, .48); font-size: 10px;
}
.start-footer p { margin-bottom: 0; }
.start-footer p:last-child { text-align: right; }
kbd { margin-right: 3px; padding: 2px 5px; border: 1px solid var(--line); border-radius: 5px; background: rgba(255, 255, 255, .07); font: inherit; }

.play-screen { position: absolute; inset: 0; z-index: 10; touch-action: none; }
.hud {
    position: absolute; z-index: 10; top: var(--safe-top); left: var(--safe-left); right: var(--safe-right);
    display: grid; grid-template-columns: minmax(180px, 1fr) minmax(180px, 320px) minmax(180px, 1fr);
    align-items: center; gap: 16px; pointer-events: none;
}
.hud-cluster { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.hud-right { justify-content: flex-end; }
.hud-icon, .hud-stat, .hearts, .mission-progress {
    border: 1px solid var(--line); background: var(--glass);
    box-shadow: 0 8px 28px rgba(0, 0, 0, .16), inset 0 1px 0 rgba(255, 255, 255, .08);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.hud-icon {
    width: 46px; height: 46px; display: grid; place-items: center; flex: 0 0 auto; padding: 0;
    border-radius: 15px; color: var(--white); font-size: 20px; font-weight: 900; cursor: pointer;
}
.hud-icon[aria-pressed="true"] { color: rgba(248, 252, 255, .4); }
.hud-stat { min-width: 102px; height: 46px; padding: 7px 14px; border-radius: 15px; }
.hud-stat small, .mission-progress-copy span {
    display: block; color: rgba(248, 252, 255, .48); font-size: 8px;
    font-weight: 900; letter-spacing: .14em;
}
.hud-stat strong { color: var(--gold); font-size: 18px; line-height: 1; }
.mission-progress { height: 46px; padding: 7px 12px; border-radius: 15px; }
.mission-progress-copy { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.mission-progress-copy span { display: inline; }
.mission-progress-copy b { font-size: 10px; }
.progress-track { height: 6px; overflow: hidden; border-radius: 99px; background: rgba(255, 255, 255, .12); }
.progress-track i {
    display: block; width: 0; height: 100%; border-radius: inherit;
    background: linear-gradient(90deg, var(--blue), var(--mint)); box-shadow: 0 0 15px rgba(77, 217, 255, .55);
    transition: width .35s ease;
}
.hearts {
    height: 46px; display: flex; align-items: center; padding: 0 14px; border-radius: 15px;
    color: var(--coral); font-size: 18px; letter-spacing: 2px; white-space: nowrap;
}

.question-card {
    position: absolute; z-index: 8; top: calc(var(--safe-top) + 70px); left: 50%;
    width: min(520px, calc(100% - 28px)); transform: translateX(-50%);
    padding: 13px 18px 15px; border: 1px solid rgba(255, 255, 255, .25); border-radius: 20px;
    color: var(--navy-950); background: rgba(249, 253, 255, .985);
    box-shadow: 0 14px 40px rgba(1, 12, 27, .28), inset 0 1px 0 #fff;
    text-align: center;
}
.question-meta { display: flex; align-items: center; justify-content: center; gap: 7px; margin-bottom: 2px; color: #60758b; font-size: 10px; font-weight: 850; }
.question-card > strong { display: block; font-size: clamp(18px, 3vw, 25px); line-height: 1.35; word-break: keep-all; }
.level-badge { padding: 3px 7px; border-radius: 99px; color: #06233e; background: #a6edff; font-size: 9px; }
.combo-badge {
    position: absolute; top: 50%; right: -12px; transform: translate(100%, -50%) rotate(3deg);
    padding: 8px 11px; border: 1px solid rgba(255, 210, 90, .42); border-radius: 12px;
    color: var(--gold); background: rgba(7, 24, 46, .85); box-shadow: 0 8px 22px rgba(0, 0, 0, .18);
    font-size: 12px; font-weight: 950; white-space: nowrap;
}

.lane-indicator {
    position: absolute; z-index: 7; left: 50%; bottom: calc(var(--safe-bottom) + 115px);
    display: flex; gap: 7px; transform: translateX(-50%);
}
.lane-indicator i { width: 7px; height: 7px; border-radius: 99px; background: rgba(255, 255, 255, .32); transition: width .18s ease, background .18s ease; }
.lane-indicator i.is-active { width: 24px; background: var(--gold); box-shadow: 0 0 14px rgba(255, 210, 90, .5); }
.touch-controls {
    position: absolute; z-index: 9; left: 50%; bottom: var(--safe-bottom);
    display: flex; align-items: center; gap: clamp(34px, 9vw, 108px); transform: translateX(-50%);
}
.touch-controls p { margin: 0; color: rgba(248, 252, 255, .48); font-size: 9px; font-weight: 800; line-height: 1.3; text-align: center; white-space: nowrap; }
.control-btn {
    width: 82px; height: 82px; display: grid; place-items: center; align-content: center; padding: 0;
    border: 1px solid rgba(255, 255, 255, .28); border-radius: 26px; color: var(--white);
    background: linear-gradient(145deg, rgba(20, 68, 110, .88), rgba(5, 27, 52, .92));
    box-shadow: 0 12px 34px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .14);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); cursor: pointer; user-select: none;
}
.control-btn span { height: 37px; font: 300 49px/31px Georgia, serif; }
.control-btn small { color: rgba(248, 252, 255, .52); font-size: 8px; font-weight: 900; letter-spacing: .16em; }
.control-btn:active { transform: scale(.94); background: rgba(77, 217, 255, .24); }

.feedback-toast {
    position: absolute; z-index: 20; left: 50%; top: 51%; min-width: min(320px, calc(100% - 32px));
    max-width: calc(100% - 32px); transform: translate(-50%, -50%); padding: 15px 20px;
    border: 1px solid rgba(255, 255, 255, .28); border-radius: 18px; color: var(--white);
    background: rgba(4, 19, 38, .9); box-shadow: 0 18px 55px rgba(0, 0, 0, .38);
    text-align: center; backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    animation: toast-in .25s ease both;
}
.feedback-toast.is-correct { border-color: rgba(102, 230, 183, .65); }
.feedback-toast.is-wrong { border-color: rgba(255, 111, 97, .7); }
.feedback-toast b { display: block; color: var(--gold); font-size: 19px; }
.feedback-toast span { color: rgba(248, 252, 255, .7); font-size: 11px; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -42%) scale(.94); } }

.overlay-screen {
    z-index: 40; background: rgba(2, 12, 26, .76);
    backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px);
}
.dialog-card { padding: 30px; text-align: center; }
.compact-card { width: min(410px, 100%); }
.dialog-icon {
    width: 64px; height: 64px; display: grid; place-items: center; margin: 0 auto 18px;
    border: 1px solid var(--line); border-radius: 21px; color: var(--gold);
    background: rgba(255, 255, 255, .06); font-size: 26px; font-weight: 800;
}
.dialog-card h2 { margin-bottom: 7px; font-size: 28px; letter-spacing: -.04em; }
.dialog-card > p:not(.eyebrow) { color: rgba(248, 252, 255, .62); font-size: 13px; }
.dialog-card .primary-btn { margin-top: 22px; }
.text-btn {
    display: inline-block; margin-top: 14px; padding: 8px; border: 0;
    color: rgba(248, 252, 255, .58); background: transparent; font-size: 12px;
    font-weight: 750; text-decoration: none; cursor: pointer;
}
.result-card { width: min(490px, 100%); padding-top: 24px; }
.result-medal {
    width: 70px; height: 70px; display: grid; place-items: center; margin: 0 auto 13px;
    border: 1px solid rgba(255, 210, 90, .45); border-radius: 50%; color: var(--gold);
    background: radial-gradient(circle, rgba(255, 210, 90, .24), rgba(255, 210, 90, .04));
    box-shadow: 0 0 35px rgba(255, 210, 90, .16); font-size: 34px;
}
.result-card h2 { margin-bottom: 4px; }
.result-message { margin-bottom: 18px; }
.result-score { padding: 14px; border: 1px solid var(--line); border-radius: 19px; background: rgba(255, 255, 255, .055); }
.result-score small { display: block; color: rgba(248, 252, 255, .46); font-size: 8px; font-weight: 900; letter-spacing: .18em; }
.result-score strong { display: block; color: var(--gold); font-size: 42px; line-height: 1.05; }
.result-score span { color: var(--blue); font-size: 10px; font-weight: 850; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 8px; }
.result-grid div { padding: 12px 5px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255, 255, 255, .035); }
.result-grid small { display: block; margin-bottom: 3px; color: rgba(248, 252, 255, .45); font-size: 9px; }
.result-grid strong { font-size: 16px; }
.learned-words { min-height: 18px; margin-top: 12px; color: rgba(248, 252, 255, .64); font-size: 10px; line-height: 1.5; }
.sr-only { position: fixed; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 720px) {
    .hud { grid-template-columns: 1fr auto; gap: 7px; }
    .mission-progress { position: absolute; top: 54px; left: 50%; width: min(250px, 58vw); transform: translateX(-50%); }
    .hud-stat { min-width: 84px; }
    .hearts { padding: 0 10px; font-size: 15px; }
    .question-card { top: calc(var(--safe-top) + 116px); }
    .combo-badge { top: auto; right: 10px; bottom: -13px; transform: rotate(2deg); }
}

@media (max-width: 480px) {
    .screen { align-items: center; padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 6px) calc(var(--safe-bottom) + 6px) calc(var(--safe-left) + 6px); }
    .start-card { padding: 17px 16px 15px; border-radius: 24px; }
    .brand-row { margin-bottom: 13px; }
    .brand-mark { width: 31px; height: 31px; }
    .brand-name { font-size: 8px; }
    .icon-link { width: 44px; height: 44px; }
    .start-hero { gap: 12px; }
    .mascot-badge { width: 64px; height: 64px; border-radius: 20px; font-size: 33px; }
    h1 { font-size: clamp(34px, 11vw, 45px); }
    .start-copy { font-size: 12px; }
    .mission-strip { gap: 6px; margin: 16px 0 15px; padding: 10px 7px; }
    .mission-strip b { font-size: 17px; }
    .mission-strip small { font-size: 8px; }
    .difficulty-field { margin-bottom: 13px; }
    .level-selector { grid-template-columns: repeat(5, 1fr); gap: 4px; }
    .level-btn { min-height: 44px; border-radius: 11px; font-size: 10px; }
    .primary-btn { min-height: 52px; border-radius: 15px; }
    .start-footer { margin-top: 10px; font-size: 8px; }
    .hud { left: var(--safe-left); right: var(--safe-right); }
    .hud-icon { width: 44px; height: 44px; border-radius: 13px; }
    .hud-stat { height: 44px; padding: 7px 10px; }
    .hud-stat strong { font-size: 16px; }
    .hearts { height: 44px; font-size: 13px; letter-spacing: 0; }
    .mission-progress { top: 49px; height: 42px; width: min(230px, 64vw); }
    .question-card { top: calc(var(--safe-top) + 101px); padding: 11px 13px 13px; border-radius: 17px; }
    .question-card > strong { font-size: 17px; }
    .question-meta { font-size: 9px; }
    .control-btn { width: 72px; height: 72px; border-radius: 23px; }
    .control-btn span { height: 33px; font-size: 44px; }
    .touch-controls { gap: clamp(27px, 8vw, 50px); }
    .lane-indicator { bottom: calc(var(--safe-bottom) + 101px); }
    .dialog-card { padding: 23px 18px 19px; border-radius: 24px; }
    .result-medal { width: 57px; height: 57px; margin-bottom: 10px; font-size: 27px; }
    .dialog-card h2 { font-size: 24px; }
    .result-message { margin-bottom: 12px; }
    .result-score { padding: 10px; }
    .result-score strong { font-size: 34px; }
    .result-grid div { padding: 9px 3px; }
    .dialog-card .primary-btn { margin-top: 14px; }
}

@media (max-height: 690px) and (orientation: landscape) {
    .start-card { width: min(780px, 100%); padding: 17px 22px 15px; }
    .brand-row { margin-bottom: 8px; }
    .start-hero { align-items: flex-start; }
    .mascot-badge { width: 60px; height: 60px; border-radius: 19px; font-size: 31px; }
    h1 { font-size: 37px; }
    .mission-strip { margin: 11px 0; padding: 8px 12px; }
    .difficulty-field { margin-bottom: 10px; }
    .level-btn { min-height: 39px; }
    .primary-btn { min-height: 49px; }
    .start-footer { margin-top: 8px; }
    .question-card { top: calc(var(--safe-top) + 58px); width: min(450px, 44vw); padding: 9px 15px 11px; }
    .question-card > strong { font-size: 18px; }
    .control-btn { width: 68px; height: 68px; border-radius: 22px; }
    .touch-controls { gap: clamp(40px, 12vw, 150px); }
    .lane-indicator { bottom: calc(var(--safe-bottom) + 82px); }
    .result-card { padding: 18px 24px 14px; }
    .result-medal { width: 50px; height: 50px; margin-bottom: 7px; font-size: 25px; }
    .result-card h2 { font-size: 23px; }
    .result-message { margin-bottom: 8px; }
    .result-score { padding: 7px 12px; }
    .result-score strong { font-size: 29px; }
    .result-grid { margin-top: 6px; }
    .result-grid div { padding: 7px 4px; }
    .learned-words { margin-top: 7px; }
    .dialog-card .primary-btn { min-height: 45px; margin-top: 9px; }
    .text-btn { margin-top: 5px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
