:root {
    --brand: #6c4fd6;
    --brand-2: #9b6bf2;
    --accent: #ff6b8a;
    --gold: #f5b942;
    --bg: #f4f1fb;
    --surface: #ffffff;
    --text: #201a33;
    --text-dim: #6c6480;
    --border: #e6e0f5;
    --good: #29b06e;
    --bad: #e0435a;
    --radius: 20px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --shadow: 0 8px 28px rgba(70, 40, 140, .12);
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14101f; --surface: #1e1830; --text: #f1edfb; --text-dim: #a79cc4;
        --border: #322a48; --shadow: 0 8px 28px rgba(0, 0, 0, .4);
    }
}
* {
    box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
[hidden] { display: none !important; }
html, body { height: 100%; overscroll-behavior: none; }
body {
    font-family: var(--font); background: var(--bg); color: var(--text);
    -webkit-font-smoothing: antialiased; overflow: hidden;
}
.boot-loader { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 200; }
.boot-loader span { width: 38px; height: 38px; border: 4px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: boot-spin .8s linear infinite; }
.boot-loader[hidden] { display: none; }
.app.booting { visibility: hidden; pointer-events: none; }
@keyframes boot-spin { to { transform: rotate(360deg); } }
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
input { font-family: inherit; -webkit-user-select: text; user-select: text; }

.app {
    max-width: min(100vw, 480px); margin: 0 auto; height: 100vh; height: 100dvh;
    display: flex; flex-direction: column;
    padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
        max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    position: relative;
}

.screen { display: none; flex: 1; min-height: 0; flex-direction: column; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }
.screen.active { display: flex; }

.top { display: flex; align-items: center; gap: 10px; padding: 4px 0 16px; }
.top h2 { font-size: 18px; font-weight: 800; flex: 1; text-align: center; }
.top .spacer { width: 44px; }
.top-home { justify-content: space-between; }
.icon-btn {
    width: 44px; height: 44px; border-radius: 14px; background: var(--surface);
    border: 1px solid var(--border); font-size: 16px; display: flex; align-items: center; justify-content: center;
    flex: none;
}
.back-btn { font-size: 20px; font-weight: 700; }
.match-actions { display: flex; gap: 6px; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-badge {
    width: 48px; height: 48px; border-radius: 16px; font-size: 24px;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(155deg, var(--brand), var(--brand-2)); box-shadow: var(--shadow);
}
.brand h1 { font-size: 21px; font-weight: 800; }
.brand .sub { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; }

.stat-row { display: flex; gap: 10px; margin: 14px 0; }
.stat-pill {
    background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
    padding: 7px 13px; font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 5px;
    flex: 1; justify-content: center;
}

.daily-card {
    width: 100%; min-height: 68px; display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border: 1px solid rgba(245,185,66,.55);
    border-radius: var(--radius); background: linear-gradient(110deg, rgba(245,185,66,.14), var(--surface) 58%);
    text-align: left; box-shadow: var(--shadow);
}
.daily-card:active { transform: scale(.985); }
.daily-mark {
    width: 42px; height: 42px; flex: none; display: grid; place-items: center;
    border-radius: 13px; background: var(--gold); color: #2b1d00; font-size: 20px; font-weight: 950;
}
.daily-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.daily-title { font-size: 15px; font-weight: 850; }
.daily-sub { color: var(--text-dim); font-size: 12px; line-height: 1.3; }
.daily-streak { min-width: 32px; font-size: 12px; font-weight: 850; color: var(--gold); text-align: right; }

.mode-cards { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }
.mode-card {
    display: flex; align-items: center; gap: 14px; text-align: left;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow); transition: transform .08s ease;
}
.mode-card:active { transform: scale(.98); }
.mode-ico { font-size: 30px; flex: none; width: 52px; height: 52px; border-radius: 16px;
    display: flex; align-items: center; justify-content: center; }
.mode-battle .mode-ico { background: linear-gradient(155deg, #6c4fd6, #9b6bf2); }
.mode-solo .mode-ico { background: linear-gradient(155deg, #ff6b8a, #ffa06b); }
.mode-body { flex: 1; min-width: 0; }
.mode-title { font-size: 17px; font-weight: 800; }
.mode-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; line-height: 1.35; }
.mode-go { font-size: 22px; color: var(--brand); font-weight: 800; flex: none; }

.home-links { display: flex; justify-content: center; gap: 22px; margin-top: 18px; }
.link-btn {
    min-height: 44px; font-size: 13.5px; font-weight: 700; color: var(--brand);
    padding: 8px; display: inline-flex; align-items: center; justify-content: center;
}

.panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.field-label { font-size: 12.5px; font-weight: 700; color: var(--text-dim); margin: 10px 0 8px; text-transform: uppercase; letter-spacing: .03em; }
.field-label:first-child { margin-top: 0; }

.segmented { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; }
.segmented button { flex: 1; padding: 9px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--text-dim); }
.segmented button.active { background: var(--brand); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    padding: 8px 13px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border);
    font-size: 13px; font-weight: 700; color: var(--text-dim);
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.btn-primary, .btn-secondary {
    width: 100%; padding: 14px; border-radius: 15px; font-weight: 800; font-size: 15px; margin-top: 12px;
}
.btn-primary { background: linear-gradient(155deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: var(--shadow); }
.btn-primary:active { transform: scale(.98); }
.btn-secondary { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.btn-primary:disabled { opacity: .45; }

.join-row { display: flex; gap: 8px; }
.join-row input {
    flex: 1; padding: 12px 14px; border-radius: 13px; border: 1px solid var(--border); background: var(--bg);
    font-size: 18px; font-weight: 800; letter-spacing: .12em; text-align: center; text-transform: uppercase; color: var(--text);
}
.join-row .btn-secondary { width: auto; margin-top: 0; padding: 12px 18px; }

.hint { font-size: 12.5px; color: var(--text-dim); text-align: center; margin-top: 10px; line-height: 1.4; }

.lobby-code { text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 22px; box-shadow: var(--shadow); }
.lobby-code-label { font-size: 12.5px; color: var(--text-dim); font-weight: 700; }
.lobby-code-val { font-size: 42px; font-weight: 900; letter-spacing: .15em; color: var(--brand); margin: 6px 0; }
.lobby-code-hint { font-size: 12px; color: var(--text-dim); }

.seats { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.seat-row { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 11px 14px; }
.seat-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--bg); display: flex; align-items: center;
    justify-content: center; font-size: 15px; flex: none; }
.seat-name { flex: 1; font-weight: 700; font-size: 14px; }
.seat-empty { color: var(--text-dim); font-style: normal; }
.seat-host-badge { font-size: 11px; color: var(--gold); font-weight: 800; }

.match-top { justify-content: space-between; }
.round-badge { font-weight: 800; font-size: 14px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 999px; padding: 7px 13px; }
.timer-ring {
    width: 42px; height: 42px; border-radius: 50%; border: 3px solid var(--border);
    display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px;
    transition: border-color .2s ease; flex: none;
}
.timer-ring.warn { border-color: var(--bad); color: var(--bad); }

.scoreboard { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.score-chip { flex: 1; min-width: 64px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    padding: 7px 9px; text-align: center; }
.score-chip.me { border-color: var(--brand); }
.score-chip .sc-name { font-size: 10.5px; color: var(--text-dim); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-chip .sc-val { font-size: 16px; font-weight: 900; }
.score-chip.answered { box-shadow: inset 0 0 0 2px var(--good); }
.score-chip.left { opacity: .4; }

.question-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 22px 18px; box-shadow: var(--shadow); text-align: center; min-height: 92px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.question-cat { font-size: 11px; font-weight: 800; color: var(--brand); text-transform: uppercase; letter-spacing: .05em; }
.question-text { font-size: 17px; font-weight: 700; line-height: 1.35; }
.flag-card { padding: 26px; }
.flag-emoji { font-size: 84px; line-height: 1; }

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.answer-btn {
    background: var(--surface); border: 1px solid var(--border); border-radius: 15px;
    padding: 15px 10px; min-height: 54px; font-weight: 700; font-size: 14px; text-align: center; line-height: 1.3;
}
.answer-btn:active { transform: scale(.97); }
.answer-btn.picked { border-color: var(--brand); box-shadow: inset 0 0 0 2px var(--brand); }
.answer-btn.correct { background: var(--good); border-color: var(--good); color: #fff; }
.answer-btn.wrong { background: var(--bad); border-color: var(--bad); color: #fff; }
.answer-btn:disabled { opacity: .7; cursor: default; }

.match-status { text-align: center; font-size: 13.5px; color: var(--text-dim); font-weight: 700; margin-top: 14px; }
.reveal { text-align: center; font-size: 13.5px; margin-top: 10px; font-weight: 700; }
.reveal .r-good { color: var(--good); }
.reveal .r-bad { color: var(--bad); }

.standings { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 18px; }
.standing-row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 13px 16px; box-shadow: var(--shadow); }
.standing-row.place-1 { border-color: var(--gold); background: linear-gradient(90deg, rgba(245,185,66,.14), transparent); }
.standing-medal { font-size: 22px; width: 32px; text-align: center; flex: none; }
.standing-name { flex: 1; font-weight: 800; font-size: 15px; }
.standing-score { font-weight: 900; font-size: 16px; color: var(--brand); }
.result-actions { display: flex; flex-direction: column; }
.result-hero {
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    padding: 18px; text-align: center; box-shadow: var(--shadow); margin-bottom: 14px;
}
.result-kicker { color: var(--brand); font-size: 12px; font-weight: 850; letter-spacing: .04em; text-transform: uppercase; }
.result-score { margin-top: 4px; font-size: 32px; line-height: 1.1; font-weight: 950; }
.result-detail { margin-top: 6px; color: var(--text-dim); font-size: 13px; line-height: 1.35; }
.daily-result-hero { border-color: rgba(245,185,66,.55); }
.result-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.result-metric { min-width: 0; padding: 10px 6px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); text-align: center; }
.result-metric strong { display: block; font-size: 16px; font-weight: 900; }
.result-metric span { display: block; margin-top: 2px; color: var(--text-dim); font-size: 10.5px; line-height: 1.2; }

.solo-hero { font-size: 68px; text-align: center; margin: 10px 0; }
.solo-stats { display: flex; gap: 8px; margin-bottom: 6px; }
.solo-stats .stat-pill { font-size: 12.5px; }
.solo-streak { text-align: center; font-weight: 900; font-size: 15px; margin-bottom: 8px; }
.solo-run-label { min-height: 18px; text-align: center; color: var(--brand); font-size: 12px; font-weight: 850; margin: -6px 0 6px; }
.lives-row { display: flex; gap: 4px; font-size: 18px; }

.over-card {
    margin: auto; text-align: center; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 28px 22px; box-shadow: var(--shadow); max-width: 340px;
}
.over-ico { font-size: 50px; margin-bottom: 6px; }
.over-card h2 { font-size: 19px; font-weight: 800; margin-bottom: 8px; }
.over-stat { color: var(--text-dim); font-size: 14px; margin-bottom: 6px; }

.frames-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.frame-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 12px 8px;
    text-align: center; box-shadow: var(--shadow);
}
.frame-circle {
    width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 8px; display: flex; align-items: center;
    justify-content: center; font-size: 22px; background: var(--bg);
}
.frame-circle.locked { opacity: .3; filter: grayscale(1); }
.frame-circle.f-bronze { box-shadow: 0 0 0 4px #b5793a; }
.frame-circle.f-silver { box-shadow: 0 0 0 4px #c7cbd6; }
.frame-circle.f-gold { box-shadow: 0 0 0 4px #f5b942; }
.frame-circle.f-neon { box-shadow: 0 0 0 4px #37e0d6; }
.frame-circle.f-fire { box-shadow: 0 0 0 4px #ff6b3d; }
.frame-circle.f-cosmic { box-shadow: 0 0 0 4px #9b6bf2, 0 0 14px 2px #9b6bf2; }
.frame-name { font-size: 11.5px; font-weight: 700; margin-bottom: 6px; }
.frame-equip { font-size: 11px; font-weight: 800; color: var(--brand); padding: 4px; }
.frame-equip.on { color: var(--good); }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(10, 6, 20, .55); display: flex; align-items: center;
    justify-content: center; padding: 20px; z-index: 50;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--surface); border-radius: var(--radius); padding: 24px 20px; max-width: 360px; width: 100%;
    box-shadow: var(--shadow); text-align: center; max-height: calc(100dvh - 40px); overflow-y: auto;
}
.modal h2 { font-size: 18px; font-weight: 800; margin-bottom: 14px; }
.rules-list { text-align: left; list-style: none; display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.rules-list li { font-size: 13.5px; line-height: 1.4; color: var(--text-dim); padding-left: 18px; position: relative; }
.rules-list li::before { content: '•'; position: absolute; left: 2px; color: var(--brand); font-weight: 900; }
.chest-ico { font-size: 54px; }
.chest-modal p { color: var(--text-dim); font-size: 14px; margin-bottom: 6px; }

.coach {
    position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
    width: min(440px, calc(100vw - 24px)); z-index: 90; padding: 14px 52px 14px 16px;
    border-radius: 16px; border: 1px solid var(--brand); background: var(--surface);
    box-shadow: 0 14px 42px rgba(32, 20, 70, .3); text-align: left;
}
.coach-step { color: var(--brand); font-size: 10.5px; font-weight: 900; letter-spacing: .05em; text-transform: uppercase; }
.coach-text { margin-top: 3px; font-size: 13.5px; font-weight: 700; line-height: 1.35; }
.coach-skip { position: absolute; right: 8px; top: 8px; min-width: 44px; min-height: 44px; color: var(--text-dim); font-size: 11px; font-weight: 750; }
.coach-target { outline: 3px solid var(--gold) !important; outline-offset: 3px; position: relative; z-index: 89; }

@media (max-width: 350px) {
    .app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
    .brand .sub { font-size: 11.5px; }
    .mode-card { padding: 14px; gap: 10px; }
    .answers { grid-template-columns: 1fr; gap: 8px; }
    .flag-emoji { font-size: 68px; }
    .join-row { flex-direction: column; }
    .join-row .btn-secondary { width: 100%; }
}

@media (max-height: 600px) {
    .top { padding-bottom: 8px; }
    .question-card { padding-top: 14px; padding-bottom: 14px; min-height: 72px; }
    .flag-card { padding: 14px; }
    .flag-emoji { font-size: 64px; }
    .answers { margin-top: 9px; gap: 8px; }
    .answer-btn { padding-top: 10px; padding-bottom: 10px; min-height: 46px; }
    .coach { bottom: max(8px, env(safe-area-inset-bottom)); padding-top: 10px; padding-bottom: 10px; }
    .result-hero { padding: 12px; margin-bottom: 8px; }
    .result-score { font-size: 26px; }
}

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