/* ==========================================================================
   GAMIFY-01 — Adult-band gamification: HUD, theme engine, mini-games.

   Scoped to body.adult-mode so K-12 bands are completely unaffected.
   Theme tokens (--g-*) are written at runtime from the server's ALLOWLISTED
   theme palette (see gamification.py THEMES); the values below are the house
   "Signal" defaults and are what renders if the state call ever fails.
   ========================================================================== */
body.adult-mode {
    --g-accent:   var(--bcg-gold);
    --g-accent2:  var(--bcg-red);
    --g-surface:  var(--bcg-dark);
    --g-surface2: var(--card-bg);
    --g-text:     var(--bcg-light-gray);
    --g-glow:     rgba(219, 153, 65, 0.33);
}

/* ---- HUD strip -------------------------------------------------------- */
.gamify-hud {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 10px 14px;
    margin: 0 0 10px 0;
    background: linear-gradient(135deg, var(--g-surface) 0%, var(--g-surface2) 100%);
    border: 1px solid var(--border-color);
    border-left: 1px solid var(--g-accent);
    border-radius: 10px;
    color: var(--g-text);
    transition: border-color .3s ease, background .3s ease;
}

.gamify-level { display: flex; align-items: baseline; gap: 7px; white-space: nowrap; }
.gamify-level-num {
    font-size: 20px; font-weight: 800; line-height: 1;
    color: var(--g-accent); font-variant-numeric: tabular-nums;
}
.gamify-level-title {
    font-size: 12px; font-weight: 600; letter-spacing: .04em;
    text-transform: uppercase; opacity: .85;
}

.gamify-xp { flex: 1 1 180px; min-width: 140px; }
.gamify-xp-meta {
    display: flex; justify-content: space-between;
    font-size: 9px; letter-spacing: .05em; text-transform: uppercase;
    opacity: .7; margin-bottom: 2px; font-variant-numeric: tabular-nums;
}
.gamify-xp-track {
    height: 5px; background: rgba(0, 0, 0, .35);
    border-radius: 99px; overflow: hidden;
}
.gamify-xp-fill {
    height: 100%; width: 0; border-radius: 99px;
    background: linear-gradient(90deg, var(--g-accent2), var(--g-accent));
    box-shadow: 0 0 10px var(--g-glow);
    transition: width .7s cubic-bezier(.22, 1, .36, 1);
}

.gamify-streak {
    display: flex; align-items: center; gap: 5px;
    font-size: 13px; font-weight: 700; white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.gamify-streak.is-cold { opacity: .45; font-weight: 600; }

.gamify-hud-actions { display: flex; gap: 6px; }
.gamify-chip {
    background: rgba(255, 255, 255, .06);
    border: 1px solid var(--border-color);
    color: var(--g-text);
    border-radius: 99px; padding: 5px 11px;
    font-size: 11px; font-weight: 600; cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}
.gamify-chip:hover { background: rgba(255, 255, 255, .12); border-color: var(--g-accent); }
.gamify-chip:focus-visible { outline: 2px solid var(--g-accent); outline-offset: 2px; }

/* ---- Theme selector --------------------------------------------------- */
.gamify-theme-grid {
    display: grid; gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.gamify-theme-card {
    text-align: left; padding: 12px; border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-secondary, var(--bcg-light-gray));
    cursor: pointer; transition: transform .12s ease, border-color .15s ease;
}
.gamify-theme-card:hover { transform: translateY(-2px); }
.gamify-theme-card[aria-pressed="true"] {
    border-color: var(--g-accent); box-shadow: 0 0 0 1px var(--g-accent);
}
.gamify-theme-card:focus-visible { outline: 2px solid var(--g-accent); outline-offset: 2px; }
.gamify-theme-name { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.gamify-theme-blurb { font-size: 11px; opacity: .7; line-height: 1.35; }
.gamify-swatches { display: flex; gap: 4px; margin-top: 8px; }
.gamify-swatch { width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(255,255,255,.15); }

/* ---- Badges ----------------------------------------------------------- */
.gamify-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.gamify-badge {
    display: flex; align-items: center; gap: 6px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px; padding: 7px 10px; font-size: 11px;
}
.gamify-badge-icon { font-size: 15px; }

/* ---- Mini-games ------------------------------------------------------- */
.gamify-round { margin-bottom: 12px; }
.gamify-round-prompt {
    font-size: 15px; font-weight: 700; letter-spacing: .13em;
    color: var(--g-accent); margin-bottom: 5px;
}
.gamify-round input {
    width: 100%; padding: 9px 11px; border-radius: 8px;
    background: var(--card-bg); color: var(--text-primary, var(--bcg-white));
    border: 1px solid var(--border-color); font-size: 14px;
}
.gamify-round input:focus-visible { outline: 2px solid var(--g-accent); outline-offset: 1px; }
.gamify-round.is-right input { border-color: var(--success); }
.gamify-round.is-wrong input { border-color: var(--bcg-red); }
.gamify-answer-note { font-size: 11px; margin-top: 4px; opacity: .8; }

/* ---- Level-up celebration --------------------------------------------- */
.gamify-levelup {
    position: fixed; inset: 0; z-index: 1200;
    display: flex; align-items: center; justify-content: center;
    background: rgba(8, 8, 10, .82);
    animation: gamifyFade .28s ease both;
}
.gamify-levelup-card {
    text-align: center; padding: 30px 40px; border-radius: 16px; max-width: 90vw;
    background: linear-gradient(135deg, var(--g-surface) 0%, var(--g-surface2) 100%);
    border: 1px solid var(--g-accent);
    box-shadow: 0 0 44px var(--g-glow);
    animation: gamifyPop .45s cubic-bezier(.25, 1, .5, 1) both;   /* ease-out-quart, was elastic overshoot */
}
.gamify-levelup-kicker {
    font-size: 11px; letter-spacing: .22em; text-transform: uppercase;
    color: var(--g-accent); margin-bottom: 6px;
}
.gamify-levelup-num { font-size: 52px; font-weight: 900; line-height: 1; color: var(--g-accent); }
.gamify-levelup-title { font-size: 19px; font-weight: 700; margin-top: 6px; color: var(--g-text); }

@keyframes gamifyFade { from { opacity: 0 } to { opacity: 1 } }
@keyframes gamifyPop  { from { opacity: 0; transform: scale(.86) } to { opacity: 1; transform: scale(1) } }

/* Accessibility: honor reduced-motion for every animated affordance. */
@media (prefers-reduced-motion: reduce) {
    .gamify-xp-fill { transition: none; }
    .gamify-theme-card:hover { transform: none; }
    .gamify-levelup, .gamify-levelup-card { animation: none; }
}

@media (max-width: 600px) {
    /* GAMIFY-22: tightened — this row sits between the tutor header and the
   gameplay, and every px it gives back is a px the stage can use. */
.gamify-hud { gap: 8px; padding: 6px 10px; margin-bottom: 6px; }
    .gamify-level-num { font-size: 17px; }
    .gamify-level-title { display: none; }   /* keep the strip single-line on phones */
}

/* ---- Mode switch (Chat | Game) ---------------------------------------- */
.gamify-modes {
    display: inline-flex;
    background: rgba(0, 0, 0, .3);
    border: 1px solid var(--border-color);
    border-radius: 99px;
    padding: 3px;
    gap: 2px;
}
.gamify-mode-btn {
    border: none; cursor: pointer; border-radius: 99px;
    padding: 5px 14px; font-size: 11px; font-weight: 700;
    letter-spacing: .04em; background: transparent;
    color: var(--g-text, var(--bcg-light-gray)); opacity: .6;
    transition: background .15s ease, opacity .15s ease;
}
.gamify-mode-btn[aria-pressed="true"] {
    background: var(--g-accent, var(--bcg-gold)); color: var(--ink-deep); opacity: 1;
}
.gamify-mode-btn:focus-visible { outline: 2px solid var(--g-accent); outline-offset: 2px; }

/* ---- Game mode panel (replaces the chat panel) ------------------------ */
.gamify-game {
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* no min-height: it fought fitGameStage() for the same vertical space */
}

/* Canvas host — the engine sizes its canvas to this box. */
.gamify-stage {
    position: relative;
    height: clamp(220px, 34vh, 340px);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--g-surface, var(--bcg-dark));
}
.gamify-canvas { display: block; width: 100%; height: 100%; }

/* An arcade game needs more room than the ambient canvas does.
   GAMIFY-15: the box must carry the GAME'S aspect ratio, not a fixed height.
   With a fixed height the stage was 1098x291 (3.77:1) while the game renders
   800x520 (1.54:1), so Phaser's FIT letterboxed the canvas to 542x352 and left
   556px of dead bars - over half the stage - plus a negative top margin that
   pushed the canvas out of its own container.
   Width is the definite dimension here and height derives from the ratio, so
   the stage can never exceed ~60vh and never needs a max-height clamp that
   would break the ratio again. */
.gamify-stage.is-game {
    height: auto;
    /* GAMIFY-17: 52vh not 60vh - the run controls sit above the stage now,
       and the whole panel has to fit a 768px-tall laptop without scrolling. */
    /* GAMIFY-20: size from the height LEFT OVER after the header, HUD and
       encounter, not from a share of the viewport. A vh fraction ignores
       everything stacked above the stage, which is why the bottom of the
       scene kept falling below the fold. dvh because mobile chrome retracts. */
    width: min(100%, 860px, calc((100dvh - 400px) * 800 / 520));
    aspect-ratio: 800 / 520;
    margin-inline: auto;
    /* The stage host is a COLUMN flex container, so without these the flex
       algorithm owns the main size and aspect-ratio is ignored - measured:
       height collapsed to 20px while the ratio was correctly computed. Taking
       the stage out of flex sizing is what actually removes the letterboxing.
       Measured before: canvas 542x352 in a 1098px box = 556px of dead bars.
       Measured after:  canvas 678x441 in a 678px box = 0. */
    flex: 0 0 auto;
    align-self: center;
}

/* ── Waiting card (GAMIFY-05) ─────────────────────────────────────────────
   Phaser is ~1.1 MB. This is what stands in for the game while it arrives —
   named for the game that is coming, so the pause reads as anticipation
   rather than as something being broken. */
.gamify-waiting {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px; padding: 20px; text-align: center;
    background: var(--g-surface, #12191F);
    color: var(--g-text, var(--bcg-light-gray));
}
.gamify-waiting-kicker {
    font-size: 11px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase;
    color: var(--g-accent2, var(--bcg-gold));
}
.gamify-waiting-title { font-size: clamp(22px, 4vw, 34px); font-weight: 800; line-height: 1.1; }
.gamify-waiting-blurb { font-size: 14px; opacity: .82; max-width: 34ch; }
.gamify-waiting-note {
    margin-top: 4px; font-size: 12px; letter-spacing: .1em; text-transform: uppercase;
    color: var(--g-accent, var(--cyan-soft));
}
.gamify-waiting-bar {
    margin-top: 10px; width: min(240px, 60%); height: 3px; border-radius: 2px;
    background: rgba(255, 255, 255, .12); overflow: hidden;
}
.gamify-waiting-bar span {
    display: block; width: 38%; height: 100%; border-radius: 2px;
    background: var(--g-accent, var(--cyan-soft));
    animation: gamify-waiting-slide 1.15s ease-in-out infinite;
}
@keyframes gamify-waiting-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(320%); }
}
@media (prefers-reduced-motion: reduce) {
    .gamify-waiting-bar span { animation: none; width: 100%; opacity: .6; }
}

/* Readouts float over the scene; the canvas itself stays aria-hidden. */
.gamify-stage-hud {
    position: absolute; inset: 10px 12px auto 12px;
    display: flex; justify-content: space-between; align-items: flex-start;
    pointer-events: none; font-size: 11px; letter-spacing: .1em;
    text-transform: uppercase; color: var(--g-text, var(--bcg-light-gray));
    text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
}
.gamify-stage-name { font-weight: 800; color: var(--g-accent, var(--bcg-gold)); }
.gamify-lives { letter-spacing: .18em; color: var(--g-accent, var(--bcg-gold)); }

/* Stage progress pips */
.gamify-pips { display: flex; gap: 5px; margin-top: 6px; }
.gamify-pip {
    width: 22px; height: 4px; border-radius: 99px;
    background: rgba(255, 255, 255, .18);
}
.gamify-pip.is-done { background: var(--g-accent, var(--bcg-gold)); }
.gamify-pip.is-boss { width: 32px; }

/* ---- Encounter / question card ---------------------------------------- */
.gamify-encounter {
    background: var(--g-surface2, var(--card-bg));
    border: 1px solid var(--border-color);
    border-left: 1px solid var(--g-accent, var(--bcg-gold));
    border-radius: 12px;
    padding: 16px 18px;
    color: var(--g-text, var(--bcg-light-gray));
}
.gamify-encounter-kicker {
    font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
    color: var(--g-accent, var(--bcg-gold)); margin-bottom: 8px;
}
.gamify-encounter-prompt {
    font-size: clamp(20px, 4vw, 30px); font-weight: 800;
    letter-spacing: .05em; margin-bottom: 14px; word-break: break-word;
}
.gamify-answer-row { display: flex; gap: 8px; flex-wrap: wrap; }
.gamify-answer-row input {
    flex: 1 1 180px; padding: 12px 14px; border-radius: 9px; font-size: 16px;
    background: rgba(255, 255, 255, .06); color: var(--g-text, var(--bcg-light-gray));
    border: 1px solid var(--border-color);
}
.gamify-answer-row input:focus-visible { outline: 2px solid var(--g-accent); outline-offset: 1px; }
.gamify-answer-row button {
    padding: 12px 22px; border-radius: 9px; border: none; cursor: pointer;
    font-weight: 800; font-size: 14px;
    background: var(--g-accent, var(--bcg-gold)); color: var(--ink-deep);
}
.gamify-answer-row button:focus-visible { outline: 2px solid var(--g-text); outline-offset: 2px; }

.gamify-game-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.gamify-game-actions .gamify-chip { padding: 9px 16px; font-size: 12px; }

/* Pre-run briefing (GAMIFY-10). This is instructions, so it is set as prose —
   the encounter-prompt style it used to borrow is a 30px/800 headline, which
   made two ordinary sentences look like a warning label. */
.gamify-brief {
    font-size: 15px; line-height: 1.5; font-weight: 500;
    color: var(--g-text, var(--bcg-light-gray)); opacity: .92;
    margin-bottom: 14px; max-width: 60ch;
}

/* Start buttons say what the run IS, not just "Start · Math". */
.gamify-start {
    display: flex; flex-direction: column; gap: 3px; align-items: flex-start;
    text-align: left; padding: 12px 18px; min-width: 200px;
    border: 1px solid var(--g-accent, var(--bcg-gold)); border-radius: 12px;
    background: color-mix(in srgb, var(--g-accent, var(--bcg-gold)) 12%, transparent);
    color: var(--g-text, var(--bcg-light-gray)); cursor: pointer;
    transition: background .15s ease, transform .15s ease;
}
.gamify-start:hover { background: color-mix(in srgb, var(--g-accent, var(--bcg-gold)) 24%, transparent); }
.gamify-start:active { transform: translateY(1px); }
.gamify-start:focus-visible { outline: 2px solid var(--g-text, var(--bcg-light-gray)); outline-offset: 2px; }
.gamify-start-label { font-size: 15px; font-weight: 800; }
.gamify-start-sub { font-size: 12px; opacity: .78; font-weight: 500; }


@media (prefers-reduced-motion: reduce) {
    .gamify-start { transition: none; }
}

/* Results */
.gamify-result-score {
    font-size: 30px; font-weight: 900; color: var(--g-accent, var(--bcg-gold));
    margin-bottom: 6px;
}
.gamify-result-misses { font-size: 12px; opacity: .85; line-height: 1.5; }

@media (prefers-reduced-motion: reduce) {
    .gamify-mode-btn { transition: none; }
}

/* GAMIFY-15: inline SVG inside the HUD chips, replacing emoji. */
.gamify-mode-btn { display: inline-flex; align-items: center; gap: 7px; }
.gamify-mode-btn svg { width: 15px; height: 15px; flex: 0 0 auto; }

/* ==========================================================================
   UI-10 — $impeccable distill: the GAME-MODE CHROME
   Added 2026-08-03.

   The game stage was computing to 258x168 because four fixed regions were
   competing for one 749px-tall container: header 157 + HUD 86 + run banner 156
   + footer 153 = 552. The fit logic was correct; the budget was the problem.

   Every rule here is scoped to `body.game-mode`, which gamifyApplyLearningMode()
   toggles. The chat surface carries no such class, so nothing below can reach it.
   Nothing is REMOVED from the product — the one deletion is a duplicate.
   ========================================================================== */

/* The subtitle is redundant while playing: the same sentence is (or was) also in
   the footer, and the HUD one row down already says where you are. The h1 brand
   line stays. */
body.game-mode .header { padding-top: 10px; padding-bottom: 8px; }
body.game-mode .header .subtitle { display: none; }

/* ⚠️ THE DUPLICATE. `.footer-mission` and the header `.subtitle` are the same
   string, rendered at the same time. The footer copy is the one that goes: the
   header line is what applyAdultMode() rewrites for adult learners, so it carries
   state that this one does not. */
body.game-mode .footer-mission { display: none; }

/* Five stacked lines plus a logo, for one sentence of attribution. Hector needs
   the org info VISIBLE, not tall — so it becomes one wrapping row. Every
   remaining item is kept: attribution, URL, city, 501(c)(3), Privacy, About. */
body.game-mode .footer { padding: 6px 14px; }
body.game-mode .footer-branding { align-items: center; gap: 10px; }
body.game-mode .footer-logo { height: 22px; }
body.game-mode .footer-text {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  line-height: 1.35;
}
body.game-mode .footer-text br { display: none; }
/* Inline prose links inside a sentence are exempt from the 44px target floor
   (WCAG 2.5.5 inline exception). Without this the coarse-pointer rule from UI-07
   item 5 gave the About button a 44px box and it dominated the compact row. */
@media (pointer: coarse) {
  body.game-mode .footer-text button { min-height: 0; }
}

/* The run banner keeps both run buttons — they are the primary action — and loses
   only padding now that the kicker is gone. */
body.game-mode .gamify-encounter { padding: 10px 14px; }
