/* ══════════════════════════════════════════════════════════════════════════
   QuantQuiz — "mental math as a sport"
   Hard-court blue, tennis-ball yellow, white court lines, scoreboard numerals.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Fonts (self-hosted, SIL Open Font License — see fonts/OFL-*.txt) ── */
@font-face {
    font-family: 'Big Shoulders Display';
    src: url('../fonts/big-shoulders-display.woff2') format('woff2');
    font-weight: 700 900;
    font-display: swap;
}
@font-face {
    font-family: 'Atkinson Hyperlegible Next';
    src: url('../fonts/atkinson-hyperlegible-next.woff2') format('woff2');
    font-weight: 400 800;
    font-display: swap;
}

/* ── Tokens: the only place colours, fonts and radii are defined ── */
:root {
    /* Palette — all text pairs meet WCAG AA on --court */
    --court:     #0C2340;   /* background: hard-court blue        */
    --court-2:   #13335C;   /* raised surfaces                     */
    --court-3:   #1B4275;   /* hover / pressed surfaces            */
    --inset:     #081A31;   /* input wells                         */
    --line:      #F4F7FB;   /* text and court lines        14.7:1  */
    --haze:      #9FB4D1;   /* secondary text               7.5:1  */
    --ball:      #DCFF4A;   /* lead colour: play, score    13.9:1  */
    --clay:      #FF7A50;   /* mistakes only                       */
    --rally:     #5CC8FF;   /* duel, opponent, info         8.4:1  */
    --amber:     #FFC53D;   /* time running low, streak at risk    */
    --hairline:  rgba(244, 247, 251, 0.14);
    --hairline-2: rgba(244, 247, 251, 0.26);

    --font-ui:  'Atkinson Hyperlegible Next', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-num: 'Big Shoulders Display', 'Arial Narrow', 'Roboto Condensed', sans-serif;

    --r-lg: 20px;   /* main cards, modals    */
    --r-md: 14px;   /* buttons, mode tiles   */
    --r-sm: 8px;    /* pills, inputs, badges */

    /* Names used by JS inline styles */
    --text:    var(--line);
    --muted:   var(--haze);
    --accent:  var(--ball);
    --accent2: var(--rally);
    --green:   var(--ball);
    --red:     var(--clay);
    --yellow:  var(--amber);
    --surface:  var(--court-2);
    --surface2: var(--inset);
    --border:   var(--hairline);
    --border2:  var(--hairline-2);
}

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
input, button { font-family: inherit; color: inherit; }
button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}
input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--ball); outline-offset: 2px; }

/* ── Base: top-aligned, so the menu is visible without scrolling ── */
html { background: var(--court); }
body {
    background: var(--court);
    color: var(--line);
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.45;
    min-height: 100vh;
    min-height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
    -webkit-font-smoothing: antialiased;
}

/* ── Screens ── */
.screen {
    display: none;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 460px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 2rem;
}
.screen.active { display: flex; }

/* ── Logo ── */
.logo h1 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-num);
    font-size: 2.3rem;
    font-weight: 900;
    line-height: 1;
    letter-spacing: -0.5px;
}
.logo-mark { height: 0.82em; width: auto; }
.logo p {
    color: var(--haze);
    font-size: 0.95rem;
    margin-top: 0.35rem;
}

/* ── Start screen ── */
.menu-header { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.tagline { color: var(--haze); font-size: 0.95rem; margin-top: -0.5rem; }

/* The one bold element: a ball-yellow block you can't miss */
.play-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    width: 100%;
    min-height: 132px;
    padding: 1.1rem 1.3rem 1.2rem;
    background: var(--ball);
    color: var(--court);
    border: none;
    border-radius: var(--r-lg);
    text-align: left;
    cursor: pointer;
    transition: transform 0.1s, filter 0.15s, box-shadow 0.1s;
}
.play-btn { position: relative; box-shadow: 0 6px 0 #9DBA1F; }   /* a solid base: it reads as pressable */
.play-btn:hover  { filter: brightness(1.05); }
.play-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #9DBA1F; }
/* The target sits in the button: best score, top right */
.play-best {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.8rem;
    font-weight: 700;
    opacity: 0.75;
}
.play-best strong {
    font-family: var(--font-num);
    font-size: 2rem;
    font-weight: 900;
    line-height: 1;
    opacity: 1;
}

/* Today strip: daily goal pips + play streak */
.today-strip {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 44px;
    padding: 0.55rem 0.9rem;
    background: var(--court-2);
    border-radius: var(--r-md);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--haze);
}
.today-strip:empty { display: none; }
.pips { display: flex; gap: 0.3rem; flex-shrink: 0; }
.pip {
    width: 0.8rem;
    height: 0.8rem;
    border-radius: 50%;
    border: 2px solid var(--haze);
    transition: background 0.3s, border-color 0.3s, transform 0.3s;
}
.pip.on { background: var(--ball); border-color: var(--ball); }
.today-text { flex: 1; min-width: 0; }
.today-streak {
    font-family: var(--font-num);
    font-size: 1.3rem;
    font-weight: 900;
    color: var(--amber);
    line-height: 1;
}
.today-strip.goal-done .today-text { color: var(--ball); }
.today-strip.at-risk { box-shadow: inset 0 0 0 2px var(--amber); color: var(--line); }
.today-strip.empty-round .today-text { color: var(--line); }
.play-label {
    font-family: var(--font-num);
    font-size: 4.6rem;
    font-weight: 900;
    line-height: 0.9;
}
.play-config { font-size: 0.95rem; font-weight: 700; }
.play-teaser {
    font-family: var(--font-num);
    font-size: 1.7rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.5px;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
}

.daily-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    width: 100%;
    padding: 1rem 1.2rem;
    background: var(--court-2);
    border: none;
    border-left: 4px solid var(--ball);     /* yellow = something to start */
    border-radius: var(--r-md);
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}
.daily-card:hover { background: var(--court-3); }
.daily-card.done  { cursor: default; border-left-color: var(--rally); }   /* blue = info */
.daily-card.done:hover { background: var(--court-2); }
.daily-top   { display: flex; align-items: baseline; gap: 0.6rem; }
.daily-title { font-family: var(--font-num); font-size: 1.9rem; font-weight: 900; line-height: 1; }
.daily-date  { color: var(--haze); font-size: 0.9rem; font-weight: 600; }
.daily-desc  { color: var(--haze); font-size: 0.9rem; }

/* Options: everything that used to fill the menu, folded away */
.options {
    border-top: 1px solid var(--hairline);
    border-bottom: 1px solid var(--hairline);
}
.options summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
}
.options summary::-webkit-details-marker { display: none; }
.options summary::after {
    content: '+';
    font-family: var(--font-num);
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--haze);
    transition: transform 0.2s;
}
.options[open] summary::after { transform: rotate(45deg); }
.options-body { display: flex; flex-direction: column; gap: 1rem; padding-bottom: 1rem; }
.options .settings-row { flex-direction: column; gap: 1rem; }
.pill-btn small { display: block; font-size: 0.72rem; font-weight: 400; color: var(--haze); }

/* ── Section headings: plain sentence case ── */
.section { display: flex; flex-direction: column; gap: 0.5rem; }
h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--haze);
}

/* ── Settings row (difficulty + time side by side) ── */
.settings-row { display: flex; gap: 0.75rem; }
.settings-row .section { flex: 1; }

/* ── Mode tiles ── */
.modes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}
.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    padding: 0.8rem 0.9rem;
    background: var(--court-2);
    border: 2px solid transparent;
    border-radius: var(--r-md);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
}
.mode-btn:hover  { background: var(--court-3); }
.mode-btn.active { border-color: var(--ball); }
.mode-name { display: block; font-weight: 800; font-size: 0.95rem; }
.mode-desc { display: block; font-size: 0.78rem; color: var(--haze); line-height: 1.3; }

/* ── Pills ── */
.pill-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.pill-btn {
    flex: 1;
    min-width: 2.8rem;
    min-height: 44px;
    padding: 0.5rem 0.4rem;
    background: var(--court-2);
    border: 2px solid transparent;
    border-radius: var(--r-sm);
    color: var(--haze);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.pill-btn:hover  { color: var(--line); background: var(--court-3); }
.pill-btn.active { border-color: var(--ball); color: var(--line); }

/* ── Buttons ── */
.btn-primary {
    width: 100%;
    min-height: 56px;
    padding: 0.9rem 1rem;
    background: var(--ball);
    border: none;
    border-radius: var(--r-md);
    color: var(--court);
    font-size: 1.15rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.1s, filter 0.15s;
}
.btn-primary:hover  { filter: brightness(1.06); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
    min-height: 44px;
    background: var(--court-2);
    border: none;
    border-radius: var(--r-sm);
    color: var(--line);
    padding: 0.55rem 0.95rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-secondary:hover { background: var(--court-3); }

.btn-ghost {
    min-height: 40px;
    background: none;
    border: 1px solid var(--hairline-2);
    border-radius: var(--r-sm);
    color: var(--haze);
    padding: 0.45rem 1.1rem;
    font-size: 0.9rem;
    cursor: pointer;
    align-self: center;
    transition: border-color 0.15s, color 0.15s;
}
.btn-ghost:hover { border-color: var(--line); color: var(--line); }
.btn-ghost.small { min-height: 44px; padding: 0.3rem 0.75rem; font-size: 0.82rem; }

/* Start + duel row */
.action-row { display: flex; gap: 0.5rem; align-items: stretch; }
.action-row .btn-primary { flex: 1; }
.action-row .btn-duel { width: auto; padding: 0.9rem 1.1rem; flex-shrink: 0; }

.btn-duel {
    width: 100%;
    min-height: 56px;
    padding: 0.85rem;
    background: none;
    border: 2px solid var(--rally);
    border-radius: var(--r-md);
    color: var(--rally);
    font-size: 1.05rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-duel:hover  { background: var(--rally); color: var(--court); }

/* ── Best score ── */
.best-label { color: var(--haze); font-size: 0.9rem; display: flex; align-items: baseline; gap: 0.4rem; }
.best-label strong { color: var(--line); font-family: var(--font-num); font-size: 1.15rem; letter-spacing: 0.3px; }

/* ── Countdown overlay ── */
.countdown-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--court);
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.countdown-overlay.active { display: flex; }
.countdown-number {
    font-family: var(--font-num);
    font-size: 11rem;
    font-weight: 900;
    color: var(--ball);
    line-height: 1;
    animation: countPop 0.88s ease forwards;
}
@keyframes countPop {
    0%   { transform: scale(1.6); opacity: 0; }
    25%  { transform: scale(1);   opacity: 1; }
    75%  { transform: scale(1);   opacity: 1; }
    100% { transform: scale(0.85); opacity: 0; }
}

/* ── Game HUD ── */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}
.hud-stat { display: flex; flex-direction: column; gap: 0.1rem; }
.hud-stat.center { align-items: center; }
.hud-stat.right  { align-items: flex-end; }
.hud-label { font-size: 0.78rem; color: var(--haze); }
.hud-value {
    font-family: var(--font-num);
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.hud-value.accent { font-size: 2.8rem; color: var(--ball); }
.hud-value.beat { animation: beat 0.5s ease-out; }
@keyframes beat { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
.progress-fill { transition: width 1s linear, background 0.3s; }
.level-val { transition: color 0.3s, transform 0.3s; }

/* Progress: a court line that shrinks */
.progress-bar { height: 4px; background: var(--hairline); border-radius: 2px; overflow: hidden; }
.progress-fill {
    height: 100%;
    background: var(--line);
    transition: width 1s linear;
    width: 100%;
}

/* ── Question card: the scoreboard ── */
.question-card {
    background: var(--court-2);
    border-radius: var(--r-lg);
    padding: 2.25rem 1.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
}
.question {
    font-family: var(--font-num);
    font-size: 4.2rem;
    font-weight: 800;
    line-height: 1;
    min-height: 4.2rem;
    display: flex;
    align-items: center;
    letter-spacing: 0.5px;
    font-variant-numeric: tabular-nums;
}
.answer-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    justify-content: center;
    width: 100%;
}

#answer-input, #duel-input {
    flex: 1;
    min-width: 0;
    max-width: 220px;
    padding: 0.5rem 0.75rem;
    background: var(--inset);
    border: 2px solid var(--hairline);
    border-radius: var(--r-sm);
    color: var(--line);
    font-family: var(--font-num);
    font-size: 2.2rem;
    font-weight: 800;
    text-align: center;
    outline: none;
    transition: border-color 0.15s;
    -moz-appearance: textfield;
    font-variant-numeric: tabular-nums;
}
#answer-input::-webkit-outer-spin-button,
#answer-input::-webkit-inner-spin-button,
#duel-input::-webkit-outer-spin-button,
#duel-input::-webkit-inner-spin-button { -webkit-appearance: none; }
#answer-input:focus,   #duel-input:focus   { border-color: var(--line); }
input::placeholder { color: var(--haze); opacity: 1; }
#answer-input.correct, #duel-input.correct { border-color: var(--ball); color: var(--ball); }
#answer-input.wrong,   #duel-input.wrong   { border-color: var(--clay); color: var(--clay); }

.btn-submit {
    min-width: 4.5rem;
    flex-shrink: 0;
    background: var(--ball);
    border: none;
    border-radius: var(--r-sm);
    color: var(--court);
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.1s;
}
.btn-submit:active { transform: scale(0.94); }

.feedback {
    font-size: 1rem;
    font-weight: 700;
    min-height: 1.45rem;
}
.feedback.correct { color: var(--ball); }
.feedback.wrong   { color: var(--clay); }

/* ── Number pad: touch screens only, in the thumb zone at the bottom ── */
.numpad { display: none; }
@media (pointer: coarse) {
    #screen-game.active { min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
    /* The duel screen's own padding (1.5rem + 2rem) is outside this phase */
    #duel-active:not(.hidden) {
        min-height: calc(100dvh - 3.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        justify-content: flex-start;
        gap: 0.8rem;
    }
    .numpad {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        width: 100%;
        margin-top: auto;           /* pushed down to the thumbs */
    }
    .answer-row .btn-submit { display: none; }   /* the pad has its own Enter */
    .question-card { padding: 1.5rem 1.25rem 1rem; gap: 0.8rem; }
}
.key {
    min-height: 56px;
    background: var(--court-2);
    border: none;
    border-radius: var(--r-md);
    color: var(--line);
    font-family: var(--font-num);
    font-size: 1.9rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.1s, transform 0.08s;
}
.key:active { background: var(--court-3); transform: scale(0.95); }
.key[data-key="minus"], .key[data-key="del"] { color: var(--haze); }
.key-enter {
    grid-column: 1 / -1;
    background: var(--ball);
    color: var(--court);
    font-family: var(--font-ui);
    font-size: 1.15rem;
}
.key-enter:active { background: var(--ball); filter: brightness(0.92); }

/* ── Game feel ── */
.game-footer { display: flex; justify-content: center; gap: 0.6rem; }
.game-footer .btn-ghost { align-self: auto; }

/* Typing: each digit gives the field a small kick */
#answer-input.typed, #duel-input.typed { animation: typed 0.12s ease-out; }
@keyframes typed { 50% { transform: scale(1.04); } }

/* Answer verdict on the scoreboard card */
.question-card { position: relative; border: 2px solid transparent; }
.question-card.hit  { animation: hit 0.35s ease-out; }
.question-card.miss { animation: miss 0.32s ease-in-out; }
@keyframes hit {
    0%   { border-color: var(--ball); box-shadow: 0 0 0 0 rgba(220, 255, 74, 0.45); }
    100% { border-color: transparent; box-shadow: 0 0 0 14px rgba(220, 255, 74, 0); }
}
@keyframes miss {
    0%, 100% { transform: translateX(0); border-color: transparent; }
    20%      { transform: translateX(-8px); border-color: var(--clay); }
    40%      { transform: translateX(7px);  border-color: var(--clay); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(2px); }
}

/* Combo: a tab on the card's top edge, clear of the question */
.combo {
    position: absolute;
    top: -0.85rem;
    right: 1rem;
    font-family: var(--font-num);
    font-size: 1.25rem;
    font-weight: 900;
    color: var(--court);
    background: var(--ball);
    border-radius: var(--r-sm);
    padding: 0.05rem 0.5rem;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.15s, transform 0.15s;
}
.combo.on  { opacity: 1; transform: scale(1); }
.combo.pop { animation: comboPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes comboPop { 0% { transform: scale(0.5); } 100% { transform: scale(1); } }

/* Streak fire: heats up in the multiplier steps */
.streak-val { transition: color 0.2s, transform 0.2s; }
.streak-val[data-heat="1"] { color: var(--line); }
.streak-val[data-heat="2"] { color: var(--amber); transform: scale(1.08); }
.streak-val[data-heat="3"] { color: var(--ball); transform: scale(1.15); }
.streak-val:not([data-heat="0"])::after {
    content: '🔥';
    display: inline-block;
    font-size: 0.55em;
    margin-left: 0.15em;
    vertical-align: super;
    animation: flicker 0.9s ease-in-out infinite alternate;
}
@keyframes flicker {
    from { transform: scale(0.9) rotate(-6deg); }
    to   { transform: scale(1.1) rotate(6deg); }
}

/* Floating score pop */
.score-pop {
    position: fixed;
    font-family: var(--font-num);
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--ball);
    pointer-events: none;
    z-index: 50;
    animation: scoreFloat 0.85s ease forwards;
    white-space: nowrap;
}
@keyframes scoreFloat {
    0%   { opacity: 1; transform: translateY(0) scale(1.1); }
    100% { opacity: 0; transform: translateY(-48px) scale(0.9); }
}

/* ── Results ── */
.results-sub { color: var(--haze); font-size: 0.9rem; }
/* One hero number; everything else is supporting detail */
.result-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.25rem;
    padding: 1.4rem 1rem 1.2rem;
    background: var(--court-2);
    border-radius: var(--r-lg);
    border: 2px solid transparent;
}
.results-title {
    font-family: var(--font-num);
    font-size: 2rem;
    font-weight: 900;
    line-height: 1;
    color: var(--haze);
}
.hero-score { display: flex; align-items: baseline; gap: 0.4rem; }
.hero-value {
    font-family: var(--font-num);
    font-size: 6.5rem;
    font-weight: 900;
    line-height: 0.95;
    color: var(--ball);
    font-variant-numeric: tabular-nums;
}
.hero-label { font-size: 1rem; font-weight: 700; color: var(--haze); }
.res-delta { font-size: 0.95rem; font-weight: 700; color: var(--line); min-height: 1.4rem; }

.is-best .result-hero  { border-color: var(--ball); animation: heroGlow 1.6s ease-out 0.3s; }
.is-best .results-title { color: var(--ball); font-size: 2.6rem; animation: comboPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }
.is-best .res-delta    { color: var(--ball); }
.is-close .results-title { color: var(--amber); }
@keyframes heroGlow {
    0%   { box-shadow: 0 0 0 0 rgba(220, 255, 74, 0.5); }
    100% { box-shadow: 0 0 0 22px rgba(220, 255, 74, 0); }
}

/* Confetti bits fly out from the hero number */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i {
    position: absolute;
    width: 8px;
    height: 12px;
    border-radius: 2px;
    animation: confetti 1.4s cubic-bezier(0.2, 0.7, 0.4, 1) forwards;
}
@keyframes confetti {
    0%   { transform: translate(-50%, -50%) rotate(0); opacity: 1; }
    70%  { opacity: 1; }
    100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy) + 140px)) rotate(var(--rot)); opacity: 0; }
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--hairline);       /* court lines between the cells */
    border-radius: var(--r-lg);
    overflow: hidden;
}
.stat-card {
    background: var(--court-2);
    padding: 0.9rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.stat-label { font-size: 0.78rem; color: var(--haze); }
.stat-value {
    font-family: var(--font-num);
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.stats-grid .stat-value { font-size: 1.8rem; }
.stats-grid .stat-label { white-space: nowrap; }
.stat-value.green { color: var(--ball); }
.stat-value.red   { color: var(--clay); }
.save-status { font-size: 0.88rem; min-height: 1.2rem; }
.result-actions { display: flex; flex-direction: column; gap: 0.6rem; }
.result-actions-row { display: flex; gap: 0.5rem; }
.result-actions-row .btn-secondary,
.result-actions-row .btn-primary { flex: 1; }

/* ── Streak + rank badges ── */
.user-left { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.streak-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-family: var(--font-num);
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--ball);
}
.rank-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: var(--r-sm);
    padding: 0.1rem 0.45rem;
    border: 1px solid;
    white-space: nowrap;
}
.rank-bronze  { color: #E3A06B; border-color: rgba(227, 160, 107, 0.5); }
.rank-silver  { color: #D5DCE6; border-color: rgba(213, 220, 230, 0.5); }
.rank-silver2 { color: #C9D8FF; border-color: rgba(201, 216, 255, 0.55); }
.rank-gold    { color: #FFD45C; border-color: rgba(255, 212, 92, 0.55); }

/* ── Daily done marker ── */
.daily-badge {
    position: absolute;
    top: 0.9rem;
    right: 1rem;
    background: var(--rally);
    color: var(--court);
    font-size: 0.75rem;
    font-weight: 800;
    border-radius: 50%;
    width: 1.4rem;
    height: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Menu bottom ── */
.menu-bottom { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.menu-bottom-btns { display: flex; gap: 0.5rem; width: 100%; }
.menu-bottom-btns .btn-secondary { flex: 1; }

/* Header: sound switch next to Sign in */
.header-actions { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--hairline-2);
    border-radius: var(--r-sm);
    color: var(--haze);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.icon-btn:hover { border-color: var(--line); color: var(--line); }
.icon-btn[aria-pressed="false"] { color: var(--haze); opacity: 0.8; }
.icon-btn[aria-pressed="true"]  { color: var(--line); }

/* ── User bar (top right of the start screen) ── */
.user-bar  { min-width: 0; }
.user-info { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; min-width: 0; }
.user-name { font-size: 0.95rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-name.muted { color: var(--haze); font-weight: 400; }

/* ── Modals ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 15, 30, 0.82);
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--court-2);
    border-radius: var(--r-lg);
    padding: 1.75rem 1.5rem;
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}
.modal h2 { text-align: center; font-size: 1.05rem; color: var(--line); }
.modal-tabs { display: flex; gap: 0.4rem; background: var(--inset); padding: 0.25rem; border-radius: var(--r-sm); }
.modal-tab {
    flex: 1;
    min-height: 40px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--haze);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.modal-tab.active { background: var(--court-3); color: var(--line); }
.modal-pane { display: none; flex-direction: column; gap: 0.8rem; }
.modal-pane.active { display: flex; }

.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label { font-size: 0.85rem; color: var(--haze); }
.form-group input {
    min-height: 46px;
    padding: 0.6rem 0.85rem;
    background: var(--inset);
    border: 2px solid var(--hairline);
    border-radius: var(--r-sm);
    font-size: 1rem;           /* ≥16px: no iOS zoom on focus */
    outline: none;
}
.form-group input:focus { border-color: var(--line); }
.auth-error { font-size: 0.85rem; color: var(--clay); min-height: 1.2rem; }

/* ── Leaderboard / history ── */
.lb-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.lb-title { font-family: var(--font-num); font-size: 2rem; font-weight: 900; line-height: 1; }
.lb-list { display: flex; flex-direction: column; max-height: 58vh; overflow-y: auto; }
.lb-empty { color: var(--haze); font-size: 0.95rem; padding: 2rem 0; text-align: center; }

.lb-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.25rem;
    border-bottom: 1px solid var(--hairline);
}
.lb-row-me { background: rgba(220, 255, 74, 0.08); border-radius: var(--r-sm); }
.lb-rank { font-family: var(--font-num); font-size: 1.2rem; font-weight: 800; min-width: 2rem; text-align: center; color: var(--haze); }
.lb-name { flex: 1; font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-scores { display: flex; flex-direction: column; align-items: flex-end; }
.lb-primary { font-family: var(--font-num); font-size: 1.35rem; font-weight: 800; line-height: 1.1; }
.lb-secondary { font-size: 0.78rem; color: var(--haze); }
.lb-name-link { background: none; border: none; padding: 0.35rem 0; font: inherit; text-align: left; max-width: 100%; overflow: hidden; text-overflow: ellipsis; cursor: pointer; text-decoration: underline; text-decoration-color: var(--hairline-2); text-underline-offset: 3px; }
.lb-name-link:hover { color: var(--ball); }

.history-entry {
    padding: 0.8rem 0.25rem;
    border-bottom: 1px solid var(--hairline);
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.history-header { display: flex; justify-content: space-between; align-items: baseline; }
.history-mode  { font-weight: 700; font-size: 0.95rem; }
.history-score { font-family: var(--font-num); font-size: 1.35rem; font-weight: 800; color: var(--ball); }
.history-meta  { font-size: 0.8rem; color: var(--haze); line-height: 1.4; }
.history-toggle {
    background: none; border: none; color: var(--haze);
    font-size: 0.8rem; cursor: pointer; padding: 0.2rem 0; align-self: flex-start;
}
.history-toggle:hover { color: var(--line); }
.history-qa { display: none; flex-direction: column; gap: 0.2rem; margin-top: 0.3rem; }
.history-entry.expanded .history-qa { display: flex; }
.history-qa-item { display: flex; justify-content: space-between; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.history-qa-item.correct-q { color: var(--ball); }
.history-qa-item.wrong-q   { color: var(--clay); }

/* ── Profile modal ── */
.profile-body { display: flex; flex-direction: column; align-items: center; gap: 0.8rem; }
.profile-username { font-family: var(--font-num); font-size: 2rem; font-weight: 900; line-height: 1; }
.profile-stats { display: flex; gap: 0.5rem; width: 100%; }
.profile-stat {
    flex: 1;
    background: var(--inset);
    border-radius: var(--r-sm);
    padding: 0.7rem 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

/* ── Submit-a-problem modal ── */
.submit-equation { display: flex; align-items: center; justify-content: center; gap: 0.6rem; flex-wrap: wrap; }
.submit-equation input {
    width: 5.5rem;
    min-height: 52px;
    background: var(--inset);
    border: 2px solid var(--hairline);
    border-radius: var(--r-sm);
    font-family: var(--font-num);
    font-size: 1.8rem;
    font-weight: 800;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}
.submit-equation input::-webkit-outer-spin-button,
.submit-equation input::-webkit-inner-spin-button { -webkit-appearance: none; }
.submit-equation input:focus { border-color: var(--line); }
.submit-op      { font-family: var(--font-num); font-size: 1.8rem; font-weight: 800; color: var(--haze); }
.submit-preview { font-family: var(--font-num); font-size: 1.8rem; font-weight: 800; color: var(--ball); min-width: 4rem; }

/* ── Duel ── */
.duel-phase {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    width: 100%;
}
.duel-sword        { font-size: 3rem; }
.duel-search-title { font-family: var(--font-num); font-size: 2.4rem; font-weight: 900; line-height: 1; text-align: center; }
.duel-search-sub   { color: var(--haze); font-size: 0.95rem; text-align: center; max-width: 300px; }
#duel-pre-search   { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.btn-challenge     { padding: 0.6rem 1.2rem; }

.duel-dots { display: flex; gap: 0.45rem; }
.duel-dots span {
    width: 9px; height: 9px;
    background: var(--ball);
    border-radius: 50%;
    animation: dotBounce 1.2s ease-in-out infinite;
}
.duel-dots span:nth-child(2) { animation-delay: 0.2s; }
.duel-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
    0%, 80%, 100% { transform: translateY(0);    opacity: 0.4; }
    40%           { transform: translateY(-6px); opacity: 1; }
}

.duel-found-label   { font-size: 0.95rem; color: var(--haze); text-align: center; }
.duel-opp-found     { font-family: var(--font-num); font-size: 2rem; font-weight: 900; color: var(--rally); text-align: center; }
.duel-countdown-big { font-family: var(--font-num); font-size: 8rem; font-weight: 900; line-height: 1; color: var(--ball); }

.duel-scores {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: var(--court-2);
    border-radius: var(--r-lg);
    padding: 0.9rem 1.1rem;
}
.duel-pscore { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.duel-pscore.right { align-items: flex-end; text-align: right; }
.duel-pname   { font-size: 0.82rem; color: var(--haze); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 9rem; }
.duel-pts     { font-family: var(--font-num); font-size: 2.4rem; font-weight: 800; line-height: 1; transition: color 0.3s; }
.duel-correct { font-size: 0.8rem; color: var(--ball); }
.duel-center  { display: flex; flex-direction: column; align-items: center; }
.duel-vs      { font-size: 0.8rem; color: var(--haze); }
.duel-timer   { font-family: var(--font-num); font-size: 2.4rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
/* Timer reads as a clock, not a third score: icon + "s", one colour for all three */
.duel-clock   { display: inline-flex; align-items: baseline; gap: 0.15rem; color: var(--line); transition: color 0.3s; }
.duel-clock svg { align-self: center; color: inherit; opacity: 0.8; margin-right: 0.1rem; }
.duel-unit    { font-family: var(--font-num); font-size: 1.1rem; font-weight: 800; }

.duel-result-icon  { font-size: 3.5rem; }
.duel-result-title { font-family: var(--font-num); font-size: 3rem; font-weight: 900; line-height: 1; text-align: center; }
.duel-result-scores { display: flex; align-items: center; justify-content: center; gap: 1.5rem; width: 100%; }
.duel-result-player { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; }
.duel-result-name   { font-size: 0.85rem; color: var(--haze); }
.duel-result-pts    { font-family: var(--font-num); font-size: 2.8rem; font-weight: 900; line-height: 1; }

.reaction-bar { display: flex; gap: 0.5rem; justify-content: center; }
.reaction-btn {
    font-size: 1.5rem;
    background: var(--court-2);
    border: none;
    border-radius: var(--r-sm);
    width: 3rem;
    height: 3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.reaction-btn:active { transform: scale(0.9); }
.reaction-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 400; }
.reaction-float {
    position: absolute;
    font-size: 4rem;
    animation: reactionPop 1.8s ease forwards;
    pointer-events: none;
}
@keyframes reactionPop {
    0%   { opacity: 0; transform: translateY(0) scale(0.5); }
    20%  { opacity: 1; transform: translateY(-20px) scale(1.2); }
    80%  { opacity: 1; transform: translateY(-80px) scale(1); }
    100% { opacity: 0; transform: translateY(-120px) scale(0.8); }
}

/* ── Rank-up overlay ── */
.rankup-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 15, 30, 0.9);
    align-items: center;
    justify-content: center;
    z-index: 300;
}
.rankup-overlay.active { display: flex; }
.rankup-content { position: relative; text-align: center; animation: rankUpPop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
.rankup-ring {
    position: absolute;
    left: 50%;
    top: 2.5rem;
    width: 9rem;
    height: 9rem;
    margin-left: -4.5rem;
    margin-top: -4.5rem;
    border: 4px solid var(--ball);
    border-radius: 50%;
    animation: ring 1.1s ease-out 0.15s both;
    pointer-events: none;
}
@keyframes ring {
    0%   { transform: scale(0.3); opacity: 1; }
    100% { transform: scale(2.4); opacity: 0; }
}
.rankup-icon  { font-size: 5rem; line-height: 1; }
.rankup-title { font-size: 1rem; color: var(--haze); margin-top: 0.6rem; }
.rankup-name  { font-family: var(--font-num); font-size: 3.6rem; font-weight: 900; color: var(--ball); line-height: 1; }
@keyframes rankUpPop {
    0%   { opacity: 0; transform: scale(0.4); }
    70%  { opacity: 1; transform: scale(1.06); }
    100% { opacity: 1; transform: scale(1); }
}

/* ── Utility ── */
.hidden { display: none !important; }
.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}
h1[tabindex="-1"]:focus:not(:focus-visible) { outline: none; }
#main:focus { outline: none; }

/* Skip link: off-screen until focused */
.skip-link {
    position: absolute;
    left: 1rem;
    top: -4rem;
    z-index: 500;
    padding: 0.6rem 1rem;
    background: var(--ball);
    color: var(--court);
    font-weight: 800;
    border-radius: var(--r-sm);
    text-decoration: none;
}
.skip-link:focus { top: calc(0.75rem + env(safe-area-inset-top)); }

/* ── Small phones ── */
@media (max-width: 380px) {
    .screen        { padding: 1.1rem 0.9rem 1.5rem; gap: 0.8rem; }
    .question      { font-size: 3.4rem; min-height: 3.4rem; }
    .question-card { padding: 1.75rem 1rem 1.25rem; }
    .stats-grid    { grid-template-columns: 1fr 1fr; }
    .hud-value     { font-size: 1.9rem; }
    .hud-value.accent { font-size: 2.4rem; }
    .duel-pts, .duel-timer { font-size: 2rem; }
    .logo h1       { font-size: 2rem; }
    .play-label    { font-size: 4rem; }
    .play-btn      { min-height: 118px; }
    .hero-value    { font-size: 5.2rem; }
}
@media (max-width: 340px) {
    .settings-row { flex-direction: column; }
}

/* Short phones (iPhone SE and similar): tighter pad and card so Enter stays on screen */
@media (pointer: coarse) and (max-height: 720px) {
    #screen-game.active, #screen-duel.active { padding-top: 0.9rem; padding-bottom: 0.9rem; gap: 0.6rem; }
    #duel-active:not(.hidden) { min-height: calc(100dvh - 1.8rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)); gap: 0.5rem; }
    .key { min-height: 46px; font-size: 1.6rem; }
    .numpad { gap: 0.4rem; }
    .question-card { padding: 1rem 1rem 0.6rem; gap: 0.5rem; }
    .question { font-size: 3.2rem; min-height: 3.2rem; }
    #answer-input, #duel-input { font-size: 1.8rem; padding: 0.3rem 0.6rem; }
    .duel-scores { padding: 0.5rem 0.9rem; }
    .duel-pts, .duel-timer { font-size: 2rem; }
}

@media (pointer: coarse) and (max-height: 600px) {
    .key { min-height: 40px; font-size: 1.4rem; }
    .question { font-size: 2.6rem; min-height: 2.6rem; }
    .hud-value, .duel-pts, .duel-timer { font-size: 1.6rem; }
    .hud-value.accent { font-size: 1.9rem; }
    .game-footer .btn-ghost, .game-footer .icon-btn, #forfeit-btn { min-height: 40px; height: 40px; }
    .question-card { padding: 0.6rem 0.8rem 0.4rem; gap: 0.3rem; }
    .feedback { font-size: 0.9rem; min-height: 1.2rem; }
    .duel-scores { padding: 0.35rem 0.8rem; }
    .duel-pname, .duel-correct, .duel-vs { font-size: 0.72rem; }
}

/* ── Motion: respect the system setting ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── Legal footer (every screen) and legal pages ── */
.legal-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 1rem;
    max-width: 460px;
    margin: 0 auto;
    padding: 0.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
    color: var(--haze);
    font-size: 0.85rem;
}
.legal-footer a, .auth-legal a, .legal a { color: var(--haze); text-underline-offset: 3px; }
.legal-footer a { display: inline-flex; align-items: center; min-height: 44px; }
.legal-footer a:hover, .auth-legal a:hover, .legal a:hover { color: var(--line); }
.auth-legal { color: var(--haze); font-size: 0.8rem; text-align: center; line-height: 1.6; }

.legal {
    max-width: 680px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
    line-height: 1.6;
}
.legal-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.legal-top .logo h1, .legal-brand { font-family: var(--font-num); font-size: 1.8rem; font-weight: 900; line-height: 1; color: var(--line); text-decoration: none; display: flex; align-items: center; gap: 0.45rem; }
.legal-back { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; }
.legal h1 { font-family: var(--font-num); font-size: clamp(2rem, 10vw, 2.6rem); font-weight: 900; line-height: 1.05; margin-bottom: 1rem; overflow-wrap: anywhere; hyphens: auto; }
.legal .legal-brand { color: var(--line); }
.legal h2 { font-size: 1.15rem; font-weight: 800; color: var(--line); margin: 2rem 0 0.5rem; }
.legal h3 { font-size: 1rem; font-weight: 700; margin: 1.2rem 0 0.3rem; }
.legal p, .legal ul { margin-bottom: 0.8rem; color: var(--line); }
.legal ul { padding-left: 1.2rem; }
.legal li { margin-bottom: 0.3rem; }
.legal .summary {
    background: var(--court-2);
    border-left: 4px solid var(--rally);
    border-radius: var(--r-md);
    padding: 1rem 1.2rem;
    margin-bottom: 1.5rem;
}
.legal .summary h2 { margin-top: 0; }
.legal .muted { color: var(--haze); font-size: 0.9rem; }

/* ── In-app dialog and toast (no native confirm / alert / prompt) ── */
.app-dialog { gap: 0.9rem; text-align: center; }
.app-dialog h2 {
    font-family: var(--font-num);
    font-size: 2rem;
    font-weight: 900;
    line-height: 1.05;
    color: var(--line);
}
.app-dialog-body { color: var(--haze); font-size: 0.95rem; line-height: 1.5; }
.app-dialog-body:empty { display: none; }
.app-dialog-body strong { color: var(--line); }
.app-dialog-body .warn {
    display: block;
    margin-top: 0.3rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--r-sm);
    background: rgba(255, 197, 61, 0.12);
    color: var(--amber);
    font-weight: 700;
}
.copy-field {
    width: 100%;
    min-height: 6.5rem;
    margin-top: 0.4rem;
    padding: 0.6rem 0.75rem;
    background: var(--inset);
    border: 2px solid var(--hairline);
    border-radius: var(--r-sm);
    color: var(--line);
    font: inherit;
    font-size: 0.9rem;
    text-align: left;
    resize: none;
    user-select: text;
    -webkit-user-select: text;
}
.copy-field:focus { border-color: var(--line); outline: none; }
.btn-text {
    align-self: center;
    min-height: 44px;
    padding: 0.4rem 1rem;
    background: none;
    border: none;
    color: var(--haze);
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.btn-text:hover { color: var(--line); }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(1.25rem + env(safe-area-inset-bottom));
    z-index: 450;
    max-width: min(420px, calc(100vw - 2rem));
    padding: 0.8rem 1.1rem;
    background: var(--line);
    color: var(--court);
    border-radius: var(--r-md);
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    transform: translate(-50%, 1rem);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast:empty { visibility: hidden; }

/* While the leave dialog is open the round is paused: hide the question */
.paused .question, .paused #duel-question { filter: blur(14px); }
