/* Dragon Academy — screen layout & components. Built on tokens.css (.blueprint, .btn,
   .tag, .field, .input, corner marks) + castle-theme.css overrides. Pixel values below
   are copied from design_handoff's prototype inline styles. */

html, body { height: 100%; }
body {
  font-family: var(--font-reading);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  display: flex; flex-direction: column;
  min-height: 100dvh;
  padding: 12px 18px 24px;
  position: relative;
}

.screen { display: flex; flex-direction: column; flex: 1; min-height: 0; }
[hidden] { display: none !important; }

/* — icon buttons (home/back) — */
.icon-btn { width: 40px; height: 40px; padding: 0; flex: none; }
.icon-btn svg { display: block; }
.back-btn { width: 44px; height: 44px; padding: 0; flex: none; }

/* ═══════════════════════ Home ═══════════════════════ */
.home-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 2px; }
.home-brand {
  font-family: var(--font-heading); font-weight: 600; font-size: 16px;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-accent-700);
}
.home-header-right { display: flex; gap: 8px; align-items: center; }
.chip-row { display: flex; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--color-divider); padding: 4px 10px; font-size: 14px; font-weight: 600;
}
.chip-pts { color: var(--color-accent-700); }

.hero-frame { margin-top: 16px; height: 132px; overflow: visible; }
.hero-frame img { width: 100%; height: 100%; object-fit: cover; object-position: center 34%; }

.pet-card {
  display: flex; align-items: center; gap: 16px; padding: 14px 16px; margin: 20px 0 22px;
  width: 100%; background: var(--color-accent-100); cursor: pointer; text-align: left;
  font-family: inherit; color: inherit; box-shadow: var(--shadow-sm); border: none;
}
.pet-art { flex: none; display: block; width: 64px; height: 64px; object-fit: contain; }
.pet-art.poke { animation: wiggle 0.5s ease; }
.pet-copy { display: flex; flex-direction: column; gap: 3px; }
.pet-title { font-family: var(--font-heading); font-weight: 600; font-size: 18px; }
.pet-msg { font-size: 13px; line-height: 1.5; color: var(--color-neutral-700); }

.subject-list { display: flex; flex-direction: column; gap: 18px; }
.subject-card {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 78px; padding: 16px;
  background: transparent; cursor: pointer; text-align: left; font-family: inherit; color: inherit;
}
.subject-icon {
  display: grid; place-items: center; width: 48px; height: 48px;
  border: 1px solid var(--color-accent); color: var(--color-accent-700); flex: none;
}
.subject-copy { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.subject-title { font-family: var(--font-heading); font-weight: 600; font-size: 23px; }
.subject-desc { font-size: 13px; color: var(--color-neutral-700); }
.subject-chevron { flex: none; }

.home-footer { margin: auto 0 0; padding-top: 24px; font-size: 12px; color: var(--color-neutral-600); text-align: center; }

/* ═══════════════════════ Session ═══════════════════════ */
/* Pinned to the real visual viewport (not #app's natural flow height) so the
   Submit/Hint/Skip footer stays reachable above the on-screen keyboard: the meta
   viewport's interactive-widget=resizes-content (index.html) makes the visual
   viewport actually shrink when the keyboard appears in modern Android Chrome, and
   position:fixed;inset:0 tracks that shrunk viewport directly — no JS needed. Only
   the middle (question/answer/feedback) scrolls; topbar and footer never move. */
.screen-fixed {
  position: fixed; inset: 0; z-index: 1;
  padding: 12px 18px 24px; background: var(--color-bg);
}
/* flex:0 (not 1) so this sizes to its own content by default — a short question
   (one line + a compact hint) shouldn't stretch to fill the viewport and strand
   the footer down at the bottom with a dead gap above it; card, input, and the
   Submit/Hint row should read as one group. flex-shrink:1 + min-height:0 still let
   it give up space and scroll internally on a long question or once the on-screen
   keyboard shrinks the viewport, so the footer never becomes unreachable either way. */
.session-scroll { flex: 0 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.session-footer { flex: none; }

.session-topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0 14px; }
.session-stars { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; min-width: 44px; justify-content: flex-end; }

.progress-segs { display: flex; gap: 6px; margin-bottom: 18px; }
.progress-seg { flex: 1; height: 6px; background: var(--color-neutral-300); }
.progress-seg.done { background: var(--color-accent); }

/* Reading comprehension only — see render.js's passageBlock. Sticky to the top of
   .session-scroll (which is the actual scroll container, overflow-y:auto above)
   so the passage stays visible while she reads the question and feedback below
   it, instead of scrolling out of view and turning the question into a memory
   test. */
/* A real passage is 150-200 words, which on a phone is taller than the screen —
   and position:sticky does nothing at all for an element taller than the viewport.
   Unbounded, it pushed the question and its choices below the fold, so she met a
   question about a story she never saw. Cap it and let it scroll inside itself:
   the story stays on screen, and the question is always visible beneath it. */
.comp-passage {
  position: sticky; top: 0; z-index: 5;
  max-height: 38vh; overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 16px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px;
  background: var(--color-surface);
}
.comp-passage-kicker {
  font-family: var(--font-heading); font-weight: 600; font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--color-accent-600);
}
.comp-passage-text { font-size: 15px; line-height: 1.55; margin: 0; white-space: pre-line; }

.q-card {
  padding: 20px 18px; display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px;
  animation: fadeq-a 0.55s ease both;
}
.q-card.alt { animation-name: fadeq-b; }
.q-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.q-kicker {
  font-family: var(--font-heading); font-weight: 600; font-size: 12px;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-accent-700);
}
.q-worth { font-size: 12px; font-weight: 600; flex: none; }
.q-prompt { font-size: var(--q-size); line-height: 1.5; font-weight: 500; text-wrap: pretty; white-space: pre-line; }

.q-audio-btn {
  align-self: center; display: inline-flex; align-items: center; gap: 8px;
  font-size: 15px; padding: 10px 18px;
}

.mcq-list { display: flex; flex-direction: column; gap: 10px; }
.mcq-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 12px 14px;
  font-family: inherit; font-size: 19px; color: var(--color-text); text-align: left; cursor: pointer;
  background: transparent; border: 1px solid var(--color-divider); border-radius: 0;
}
.mcq-opt.selected { border: 1.5px solid var(--color-accent); background: var(--color-accent-100); }
.mcq-opt.correct { background: var(--color-accent); color: var(--color-bg); border-color: var(--color-accent); }
.mcq-opt.wrong { background: var(--color-neutral-200); border: 1.5px dashed var(--color-neutral-600); }
.mcq-key {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none; font-size: 14px; font-weight: 600;
  border: 1px solid var(--color-divider); color: var(--color-neutral-700);
}
.mcq-opt.selected .mcq-key { border: 1.5px solid var(--color-accent); color: var(--color-accent-700); }
.mcq-opt.correct .mcq-key { color: var(--color-bg); border: 1.5px solid var(--color-bg); }

.typed-field input { min-height: 56px; font-size: 22px; font-family: var(--font-reading); }

.feedback-row {
  display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 12px 14px; font-size: 15px;
}
.feedback-row.wrong {
  align-items: flex-start; background: var(--color-neutral-200); border: 1px solid var(--color-divider);
  line-height: 1.5; color: var(--color-neutral-800);
}
.feedback-row.correct {
  background: var(--color-accent-100); border: 1px solid var(--color-accent-300);
  font-weight: 600; color: var(--color-accent-800);
}
.feedback-art { width: 48px; height: 48px; flex: none; object-fit: contain; }
.feedback-row.wrong .feedback-art { width: 44px; height: 44px; align-self: center; }

.hint-row {
  display: flex; align-items: flex-start; gap: 10px; margin-top: 14px; padding: 12px 14px;
  border: 1px dashed var(--color-accent-400); font-size: 15px; line-height: 1.55; color: var(--color-accent-800);
}
.hint-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--color-accent-600); margin-bottom: 4px;
}

.actions-row { display: flex; gap: 12px; padding-top: 20px; }
.hint-btn { min-height: 52px; font-size: 16px; padding-inline: 14px; }
.submit-btn { flex: 1; min-height: 52px; font-size: 17px; }

/* Only rendered after a first wrong answer (see render.js showSkipLink) — never her
   first move, but understated even once it appears so it's not the tempting one. */
.skip-link {
  display: block; margin: 14px auto 0; background: none; border: none; padding: 8px;
  font-size: 12px; color: var(--color-neutral-600); text-decoration: underline;
  text-underline-offset: 2px; cursor: pointer; font-family: inherit;
}
.skip-link:active { color: var(--color-neutral-700); }

/* ═══════════════════════ Fire overlays ═══════════════════════ */
.fire-overlay { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 60; }
/* max-width:100% in tokens.css is a sensible global reset, and it silently
   clamped these to the container width — so the flames covered the left of the
   screen and left the right bare. They are deliberately wider than the viewport
   so the fire runs off both edges; opt out of the reset explicitly. */
.fire-overlay img { position: absolute; left: -12%; bottom: -6%; width: 132%; max-width: none;
  object-fit: cover; object-position: top; }
.fire-overlay img.mid { left: -16%; width: 140%; }
.fire-small.fire-back  { height: 60%; animation: fire-small 1.6s ease-in-out both; }
.fire-small.fire-mid   { height: 56%; animation: fire-small 1.45s ease-in-out 0.08s both; }
.fire-small.fire-front { height: 52%; animation: fire-small 1.3s ease-in-out 0.16s both; }
.fire-big.fire-back  { height: 124%; animation: fire-big 2.2s ease-in-out both; }
.fire-big.fire-mid   { height: 120%; animation: fire-big 2s ease-in-out 0.1s both; }
.fire-big.fire-front { height: 116%; animation: fire-big 1.8s ease-in-out 0.2s both; }

/* ═══════════════════════ Bonus easter egg ═══════════════════════ */
.bonus-banner {
  text-align: center; font-family: var(--font-heading); font-size: 22px;
  color: var(--color-accent-700); padding: 6px 0 14px; animation: stage-in 0.5s ease both;
}
.bonus-banner-win { font-size: 26px; }
.bonus-card { padding: 22px 18px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.bonus-kicker {
  font-family: var(--font-heading); font-size: 13px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--color-accent-600);
}
.bonus-fact-text, .bonus-q-prompt { font-size: 18px; line-height: 1.6; margin: 0; }
.bonus-win-line { font-size: 16px; color: var(--color-accent-700); margin: 6px 0 0; }

/* Over the top on purpose — the one moment restraint is the wrong instinct.
   prefers-reduced-motion is handled globally in castle-theme.css (animation
   durations collapse to ~0), so no separate calm-mode markup is needed here —
   she still gets the moment, just without the motion. */
.bonus-rain { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 65; }
.bonus-rain .rain-item {
  /* Percentages in translateY resolve against the element's own height, so the
     old 650% moved a 30px glyph about 230px — it stopped a third of the way down
     and hung there. Viewport units make it fall all the way off the bottom. */
  position: absolute; top: -14vh; font-size: 34px; line-height: 1;
  animation-name: bonus-rain-fall; animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1); animation-fill-mode: both;
}
.bonus-rain .rain-egg { width: 46px; height: auto; max-width: none; }
.bonus-won .bonus-card { animation: stage-in 0.4s ease both; }

/* ═══════════════════════ Level-up takeover ═══════════════════════ */
.levelup-boom {
  position: absolute; inset: 0; z-index: 70; overflow: hidden; pointer-events: none;
  display: grid; place-items: center;
}
.levelup-boom img { grid-area: 1 / 1; }
.levelup-boom img.ball-1 { width: 45%; animation: fireball-zoom 1.3s ease-in both; }
.levelup-boom img.ball-2 { width: 40%; animation: fireball-zoom-b 1.3s ease-in 0.12s both; }

.levelup-reveal {
  position: absolute; inset: 0; z-index: 70; display: grid; place-items: center;
  background: rgba(20, 15, 10, 0.92); pointer-events: none;
}
.levelup-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding: 24px; }
.levelup-img { width: 170px; height: 170px; object-fit: contain; animation: stage-in 0.7s ease both; }
.levelup-title { font-family: var(--font-heading); font-size: 34px; color: var(--color-accent-700); }
.levelup-line { font-size: 17px; color: var(--color-text); }

/* ═══════════════════════ Results ═══════════════════════ */
.results-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; gap: 18px; text-align: center; padding: 20px 6px;
}
.results-stages { display: flex; align-items: flex-end; gap: 14px; justify-content: center; min-height: 104px; }
.results-stages img { object-fit: contain; animation: stage-in 0.6s ease both; }
.results-kicker {
  font-family: var(--font-heading); font-size: 14px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--color-accent-700);
}
.star-row { display: flex; gap: 12px; }
.results-title { font-size: 34px; margin: 0; }
.results-copy { font-size: 16px; line-height: 1.6; color: var(--color-neutral-700); margin: 0; max-width: 280px; }
.results-actions { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 280px; margin-top: 10px; }
.results-actions .btn { min-height: 52px; font-size: 17px; }

/* ═══════════════════════ Parent dashboard ═══════════════════════ */
.parent-header { display: flex; align-items: center; gap: 12px; padding: 4px 0 18px; }
.parent-header h2 { font-size: 28px; margin: 0; }
.parent-stats { display: flex; gap: 10px; margin-bottom: 18px; }
.stat-tile { flex: 1; border: 1px solid var(--color-divider); padding: 10px 12px; text-align: center; }
.stat-tile-value { font-family: var(--font-heading); font-size: 26px; color: var(--color-accent-700); }
.stat-tile-label { font-size: 12px; color: var(--color-neutral-700); }
.parent-footnote { padding-top: 20px; font-size: 12px; color: var(--color-neutral-600); text-align: center; }

.dash-summary {
  padding: 14px 16px; margin-bottom: 18px; background: var(--color-accent-100);
  border: 1px solid var(--color-accent-300); font-size: 14px; line-height: 1.55; color: var(--color-accent-800);
}
.dash-section { margin-bottom: 22px; }
.dash-h3 {
  font-family: var(--font-heading); font-weight: 600; font-size: 15px;
  letter-spacing: 0.04em; color: var(--color-accent-700); margin: 0 0 10px;
}

.rating-cards { display: flex; flex-direction: column; gap: 10px; }
.rating-card { border: 1px solid var(--color-divider); padding: 12px 14px; }
.rating-card-top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.rating-card-name { font-family: var(--font-heading); font-size: 16px; }
.rating-card-value { font-family: var(--font-heading); font-size: 20px; color: var(--color-accent-700); }
.rating-card-note { font-size: 12px; color: var(--color-neutral-700); margin-top: 6px; }
.sparkline { display: block; width: 100%; height: 44px; }
.sparkline-empty { font-size: 12px; color: var(--color-neutral-600); height: 44px; display: flex; align-items: center; }

.weakspot-list { display: flex; flex-direction: column; gap: 8px; }
.weakspot-row {
  padding: 10px 12px; background: var(--color-neutral-200); border-left: 3px solid var(--color-hot);
  font-size: 13px; line-height: 1.5;
}
.weakspot-name { font-weight: 600; margin-right: 6px; }
.weakspot-detail { color: var(--color-neutral-800); }

.type-table { display: flex; flex-direction: column; gap: 10px; }
.type-row { border: 1px solid var(--color-divider); padding: 10px 12px; }
.type-row-top { display: flex; align-items: baseline; justify-content: space-between; }
.type-row-name { font-size: 14px; font-weight: 600; }
.type-row-acc { font-family: var(--font-heading); font-size: 16px; color: var(--color-accent-700); }
.type-row-meta { font-size: 12px; color: var(--color-neutral-700); margin-top: 4px; }

.missed-list { display: flex; flex-direction: column; gap: 10px; }
.missed-row { border: 1px solid var(--color-divider); padding: 10px 12px; }
.missed-row-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.missed-when { font-size: 11px; color: var(--color-neutral-600); }
.missed-prompt { font-size: 14px; line-height: 1.4; margin-bottom: 4px; white-space: pre-line; }
.missed-answers { font-size: 12px; color: var(--color-neutral-700); }
.missed-answers strong { color: var(--color-text); }

.sync-card { border: 1px solid var(--color-divider); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.sync-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.sync-label { color: var(--color-neutral-700); }
.sync-status { font-size: 12px; color: var(--color-neutral-700); margin: 0; text-align: center; }
.sync-hint { font-size: 11px; color: var(--color-neutral-600); margin: 0; line-height: 1.4; }

/* ═══════════════════════ PIN gate ═══════════════════════ */
.pin-screen { align-items: stretch; }
.pin-header { display: flex; align-items: center; gap: 12px; padding: 4px 0 24px; }
.pin-header h2 { font-size: 24px; margin: 0; }
.pin-body { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 40px; }
.pin-prompt { font-size: 14px; color: var(--color-neutral-700); text-align: center; max-width: 260px; margin: 0; }
.pin-input {
  width: 160px; min-height: 56px; font-size: 28px; text-align: center;
  letter-spacing: 0.5em; text-indent: 0.5em;
}
.pin-error { font-size: 13px; color: var(--color-hot); margin: 0; }

/* ═══════════════════════ Diagrams ═══════════════════════ */
.q-diagram { align-self: center; }
