/* ────────────────────────────────────────────────────────────────────
 * Y4 MCQ Bank
 *
 * Restored aesthetic per Rob's "best looking" reference: dark navy
 * canvas, cyan/teal accent, card-based question container, pill tags,
 * outlined teal action buttons, sans-serif throughout. SaaS-clinical
 * cleanliness without the cream-paper or scarlet-and-serif detours.
 *
 * Functional rules preserved:
 *   - question column always centred
 *   - reference panel is a right-side fixed overlay, no scrim, the
 *     main pane stays fully interactable while open
 *   - subtopic / category never revealed pre-answer (spoiler bug)
 *   - difficulty pill is fine pre-answer (general signal)
 *   - no horizontal scrollbar anywhere
 *   - no hammers, no boxed-kbd component
 * ──────────────────────────────────────────────────────────────────── */

:root {
  --bg:          #0a1929;
  --bg-2:        #0f2236;
  --surface:     #122a44;
  --surface-2:   #16345a;
  --line:        #1f3556;
  --line-strong: #2b4570;

  --ink:         #e8f1ff;
  --ink-2:       #c4d2e7;
  --ink-mute:    #8497b3;
  --ink-faint:   #5a6c89;

  --accent:      #0fcad4;
  --accent-2:    #5dd5df;
  --accent-bg:   rgba(15, 202, 212, 0.10);
  --accent-bd:   rgba(15, 202, 212, 0.36);

  --good:        #5ec97e;
  --good-bg:     rgba(94, 201, 126, 0.10);
  --good-bd:     rgba(94, 201, 126, 0.40);
  --bad:         #ff7a85;
  --bad-bg:      rgba(255, 122, 133, 0.10);
  --bad-bd:      rgba(255, 122, 133, 0.40);
  --warn:        #e8b34a;
  --warn-bg:     rgba(232, 179, 74, 0.10);

  --sans:        -apple-system, BlinkMacSystemFont, "SF Pro Text",
                 "Inter", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --display:     "SF Pro Display", -apple-system, BlinkMacSystemFont,
                 "Inter", "Helvetica Neue", sans-serif;
  --mono:        ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="light"] {
  --bg:          #f3f6fa;
  --bg-2:        #ffffff;
  --surface:     #ffffff;
  --surface-2:   #f6f9fc;
  --line:        #dde4ee;
  --line-strong: #c3cedd;

  --ink:         #0d1b2a;
  --ink-2:       #2f3e54;
  --ink-mute:    #6a7892;
  --ink-faint:   #a4afc1;

  --accent:      #0a9ba3;
  --accent-2:    #0d7b81;
  --accent-bg:   rgba(10, 155, 163, 0.08);
  --accent-bd:   rgba(10, 155, 163, 0.34);

  --good:        #197d3f;
  --good-bg:     rgba(25, 125, 63, 0.08);
  --good-bd:     rgba(25, 125, 63, 0.40);
  --bad:         #b3262f;
  --bad-bg:      rgba(179, 38, 47, 0.08);
  --bad-bd:      rgba(179, 38, 47, 0.40);
  --warn:        #8a5e1a;
  --warn-bg:     rgba(138, 94, 26, 0.10);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  -webkit-tap-highlight-color: rgba(15, 202, 212, 0.18);
}
.brand { cursor: pointer; }
.t-short { display: none; }
.t-long { display: inline; }

/* ── Access gate ──────────────────────────────────────────────────── */
/* Until the password is entered, the body is `.locked` and everything
 * except the gate is hidden. Pre-JS render therefore shows only the
 * gate, never the app behind it. */
body.locked > *:not(#gate):not(script) { display: none !important; }
.gate {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.gate[hidden] { display: none !important; }
.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 10px 40px -20px rgba(0,0,0,0.25);
}
[data-theme="dark"] .gate-card { box-shadow: 0 10px 40px -10px rgba(0,0,0,0.5); }

.gate-head { text-align: left; display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.gate-brand-row {
  display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit;
}
.gate-wordmark {
  font-family: var(--display);
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1;
}
.gate-wordmark .brand-glucose { font-size: 14px; font-weight: 500; color: var(--ink-mute); margin-left: 4px; letter-spacing: 0; font-style: italic; }
.gate-tagline {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-mute);
  line-height: 1.45;
}

.gate-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--line);
  margin: 0 -32px;
  padding: 0 32px;
}
.gate-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 8px 4px;
  margin-right: 20px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-mute);
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.gate-tab:hover { color: var(--ink); }
.gate-card[data-mode="signin"] .gate-tab[data-gate-switch="signin"],
.gate-card[data-mode="signup"] .gate-tab[data-gate-switch="signup"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.gate-card[data-mode="legacy"] .gate-tabs { display: none; }

.gate-pane { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.gate-pane[hidden] { display: none; }

.gate-field { display: flex; flex-direction: column; gap: 6px; }
.gate-field > span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.gate-field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  transition: border-color 0.12s ease, background 0.12s ease;
  box-sizing: border-box;
}
.gate-field input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.gate-primary {
  width: 100%;
  margin-top: 2px;
  padding: 11px 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.gate-err {
  color: var(--bad);
  font-size: 12.5px;
  margin: -4px 0 0;
}

.gate-card[data-mode="legacy"] [data-hide-in-legacy] { display: none; }

.gate-foot {
  display: flex; justify-content: center; align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
}
.gate-foot-link {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--ink-mute);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.12s ease, background 0.12s ease;
}
.gate-foot-link:hover { color: var(--ink); background: var(--surface-2); }
.gate-foot-link.gate-foot-primary { color: var(--ink); font-weight: 500; }
.gate-foot-sep { color: var(--ink-mute); opacity: 0.6; }
.gate-card[data-mode="legacy"] .gate-foot-link:not([data-gate-back]) { display: none; }
.gate-card[data-mode="legacy"] .gate-foot-link[data-gate-back] { display: inline-flex; }
.gate-card[data-mode="signin"] .gate-foot-link[data-gate-back],
.gate-card[data-mode="signup"] .gate-foot-link[data-gate-back] { display: none; }

.comm-stats { padding-top: 4px; }
.stats-bars { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.stats-row {
  display: grid;
  grid-template-columns: 18px 1fr 44px 36px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}
.stats-letter { font-weight: 700; color: var(--ink-mute); font-variant: small-caps; }
.stats-row.correct .stats-letter { color: var(--good, #2a8f4c); }
.stats-bar {
  position: relative;
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}
.stats-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.stats-row.correct .stats-bar-fill { background: var(--good, #2a8f4c); }
.stats-pct { text-align: right; font-variant-numeric: tabular-nums; }
.stats-n { text-align: right; }

/* Per-user stats modal */
.stats-modal-card { max-width: 640px; }
.stats-head {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
  margin-bottom: 22px;
}
.stats-head .stats-num {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.stats-num-value { font-family: var(--display); font-size: 26px; font-weight: 700; color: var(--ink); line-height: 1; font-variant-numeric: tabular-nums; }
.stats-num-label { font-size: 11px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.1em; }
.stats-section { margin-top: 22px; }
.stats-section h3 {
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-mute);
  margin: 0 0 10px;
}
.stats-table {
  display: grid;
  grid-template-columns: minmax(120px, 1.2fr) minmax(70px, auto) 1fr minmax(40px, auto);
  gap: 6px 12px;
  align-items: center;
  font-size: 13px;
}
.stats-table .stats-label { color: var(--ink); }
.stats-table .stats-count { color: var(--ink-mute); font-variant-numeric: tabular-nums; font-size: 12px; }
.stats-table .stats-bar-wrap {
  position: relative; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden;
}
.stats-table .stats-bar-wrap > span {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent);
  border-radius: 3px;
}
.stats-table .stats-pct-cell { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--ink-mute); }
.stats-empty { color: var(--ink-mute); font-size: 13.5px; line-height: 1.5; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
main { overflow-x: hidden; }
.stem, .lead-in, .comm-block p, .comm-block ul,
.sources li, .opt-rationale {
  overflow-wrap: anywhere;
  word-break: break-word;
}

::selection { background: var(--accent-bg); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Masthead ─────────────────────────────────────────────────────── */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-left: max(28px, env(safe-area-inset-left));
  padding-right: max(28px, env(safe-area-inset-right));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}
.masthead-left { display: flex; align-items: center; gap: 18px; line-height: 1; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; line-height: 1; padding: 4px 6px; border-radius: 6px; transition: background 0.12s ease; }
.brand:hover { background: var(--surface); text-decoration: none; }
.brand:hover .brand-title, .brand:hover .brand-sub, .brand:hover .brand-glucose { text-decoration: none; }
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  position: relative;
}
/* Stethoscope glyph: arched binaural with two earpieces at top,
   Y-junction at center, single tube curling down-right to the
   diaphragm bell. White-on-teal cutout via inline SVG. */
.brand-mark::before {
  content: "";
  display: block;
  width: 22px;
  height: 22px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'><path d='M6 4.5 C 6 9 8 11 12 11 C 16 11 18 9 18 4.5'/><circle cx='6' cy='4' r='1.4' fill='%23ffffff' stroke='none'/><circle cx='18' cy='4' r='1.4' fill='%23ffffff' stroke='none'/><path d='M12 11 V 14 Q 12 18 16 19'/><circle cx='16.5' cy='19' r='2.4' fill='%23ffffff' stroke='%23ffffff'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}
.brand-mark .cross { display: none; }
.brand-words { display: flex; flex-direction: column; line-height: 1; }
.brand-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.015em;
  color: var(--ink);
  line-height: 1;
}
.brand-sub { display: none; }
.session-meta {
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.masthead-tools { display: flex; gap: 6px; align-items: center; line-height: 1; }
.masthead-tools .link-btn { display: inline-flex; align-items: center; line-height: 1; }
.profile-chip {
  display: inline-flex; align-items: center; gap: 8px;
  margin-left: 12px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2, var(--surface));
  font-size: 12.5px;
  line-height: 1;
  color: var(--ink-2);
}
.profile-chip[hidden] { display: none; }
.profile-name { font-weight: 600; color: var(--ink); letter-spacing: 0.01em; line-height: 1; }
.profile-chip .ghost-link {
  font-size: 11.5px;
  color: var(--ink-mute);
  line-height: 1;
  text-decoration: none;
  padding: 3px 7px;
  border-radius: 5px;
  transition: background 0.12s ease, color 0.12s ease;
}
.profile-chip .ghost-link:hover {
  color: var(--ink);
  text-decoration: none;
  background: color-mix(in srgb, currentColor 14%, transparent);
}

/* Per-profile colour. Rob's chip is gold - a warm metallic look with
   a subtle gradient + inner highlight so it reads as polished metal,
   not just a yellow rectangle. Tuned separately for dark and light
   themes (gold needs different chroma on each background to feel
   "real"). Future profiles get their own block here. */
.profile-chip[data-profile-id="rob"], .profile-chip[data-pill-style="gold"] {
  --gold-1:  #ffd770;
  --gold-2:  #d9a020;
  --gold-bd: #c9941c;
  --gold-ink: #2a1d05;
  border-color: var(--gold-bd);
  background:
    linear-gradient(135deg,
      rgba(255, 223, 130, 0.95) 0%,
      rgba(243, 196, 75, 0.95) 45%,
      rgba(196, 145, 30, 0.95) 100%);
  color: var(--gold-ink);
  box-shadow:
    inset 0 1px 0 rgba(255, 246, 210, 0.7),
    inset 0 -1px 0 rgba(120, 80, 10, 0.35),
    0 1px 2px rgba(0, 0, 0, 0.25);
}
.profile-chip[data-profile-id="rob"] .profile-name,
.profile-chip[data-pill-style="gold"] .profile-name {
  color: var(--gold-ink);
  text-shadow: 0 1px 0 rgba(255, 248, 220, 0.45);
}
.profile-chip[data-profile-id="rob"] .ghost-link,
.profile-chip[data-pill-style="gold"] .ghost-link {
  color: var(--gold-ink);
  opacity: 0.75;
}
.profile-chip[data-profile-id="rob"] .ghost-link:hover,
.profile-chip[data-pill-style="gold"] .ghost-link:hover {
  color: var(--gold-ink);
  opacity: 1;
  text-decoration: none;
  background: rgba(120, 80, 10, 0.18);
}

[data-theme="light"] .profile-chip[data-profile-id="rob"],
[data-theme="light"] .profile-chip[data-pill-style="gold"] {
  /* Slightly deeper, more saturated gold on white so it doesn't wash
     out. Keeps the same metallic gradient shape. */
  --gold-bd: #a67510;
  --gold-ink: #3a2604;
  background:
    linear-gradient(135deg,
      #fbe089 0%,
      #e6b94a 45%,
      #b9831a 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 251, 220, 0.85),
    inset 0 -1px 0 rgba(120, 80, 10, 0.30),
    0 1px 2px rgba(140, 100, 30, 0.20);
}
.link-btn {
  background: transparent;
  border: none;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.link-btn:hover { background: var(--surface); color: var(--ink); }
.ghost-link {
  background: transparent;
  border: none;
  color: var(--ink-mute);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.12s ease, color 0.12s ease;
}
.ghost-link:hover { background: var(--surface); color: var(--ink); }
.ghost-x {
  background: transparent;
  border: none;
  color: var(--ink-mute);
  font-size: 18px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}
.ghost-x:hover { background: var(--surface); color: var(--ink); }

/* ── Main + question card ────────────────────────────────────────── */
main { max-width: 820px; margin: 0 auto; padding: 28px 24px 80px; }
body[data-screen="quiz"] main { padding-top: 16px; }

.prose { padding: 0 4px; }
.display {
  font-family: var(--display);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -0.015em;
  margin: 0 0 8px;
  color: var(--ink);
}
.greeting {
  font-family: var(--display);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 0 0 10px;
}
.greeting[hidden] { display: none; }
.subhead {
  font-size: 15px;
  color: var(--ink-mute);
  margin: 0 0 28px;
  max-width: 60ch;
}
.rule { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
.section-eyebrow {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Quiz card (the one Rob called "best looking") ───────────────── */
.quiz-topbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 18px;
  margin-top: 18px;
}
.quiz-topbar[hidden], .colophon[hidden] { display: none !important; }
.qt-inner { display: contents; }
.qt-step, .qt-counter {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.qt-step:hover, .qt-counter:hover { background: var(--surface-2); color: var(--ink); }
.qt-step:disabled { color: var(--ink-faint); cursor: not-allowed; }
.qt-counter {
  font-weight: 600;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.qt-caret { font-size: 9px; color: var(--ink-mute); }
.qt-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  margin: 0 18px;
  max-height: 280px;
  overflow-y: auto;
}
.qt-list ol {
  list-style: none;
  padding: 6px 14px 12px;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1px 16px;
}
.qt-list li {
  display: grid;
  grid-template-columns: 22px 22px 1fr;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink-2);
  align-items: baseline;
}
.qt-list li:hover { background: var(--surface-2); }
.qt-list li.current { background: var(--accent-bg); color: var(--ink); }
.qt-list li .qtl-status { font-family: var(--mono); text-align: center; font-weight: 700; }
.qt-list li.correct .qtl-status { color: var(--good); }
.qt-list li.incorrect .qtl-status { color: var(--bad); }
.qt-list li .qtl-num { font-family: var(--mono); color: var(--ink-mute); font-size: 11px; }
.qt-list li .qtl-stem { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qt-list li.flagged .qtl-stem::before { content: "⚐ "; color: var(--warn); }

.reading {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
  padding: 22px 24px 22px;
  margin-bottom: 24px;
}

.reading-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.folio { display: none; }
.folio-sep { display: none; }
.folio-subject {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-family: var(--sans);
  white-space: nowrap;
}

.stem {
  font-size: 16.5px;
  line-height: 1.65;
  color: var(--ink);
  margin: 4px 0 16px;
}
.lead-in {
  font-size: 15.5px;
  font-weight: 600;
  margin: 16px 0 14px;
  color: var(--ink);
}

.patient-table {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 18px;
  margin: 14px 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 22px;
  font-size: 14px;
  line-height: 1.55;
}
.patient-table dt {
  color: var(--ink-mute);
  font-weight: 500;
}
.patient-table dd { margin: 0; color: var(--ink); }

/* options */
.options { list-style: none; margin: 12px 0 0; padding: 0; }
.options li {
  display: grid;
  grid-template-columns: 36px 1fr 32px;
  align-items: baseline;
  gap: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 14.5px;
  line-height: 1.5;
  transition: border-color 0.1s, background 0.1s;
}
.options li:hover:not(.revealed) { border-color: var(--line-strong); }
.options li .opt-letter {
  font-family: var(--display);
  font-weight: 700;
  color: var(--accent-2);
  font-size: 16px;
  text-align: center;
}
.options li .opt-text { color: var(--ink); }
.options li .opt-strike {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-mute);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  align-self: center;
}
.options li .opt-strike:hover { background: var(--surface); color: var(--ink); }

.options li.selected {
  background: var(--accent-bg);
  border-color: var(--accent-bd);
}
.options li.struck .opt-text { text-decoration: line-through; opacity: 0.4; }

.options li.revealed { cursor: default; }
.options li.revealed.correct {
  background: var(--good-bg);
  border-color: var(--good-bd);
}
.options li.revealed.correct .opt-letter { color: var(--good); }
.options li.revealed.wrong {
  background: var(--bad-bg);
  border-color: var(--bad-bd);
}
.options li.revealed.wrong .opt-letter { color: var(--bad); }
.options li .opt-rationale {
  grid-column: 2 / 4;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-2);
  margin-top: 8px;
  display: none;
}
.options li.revealed .opt-rationale { display: block; }
.options li.revealed .opt-rationale b { color: var(--ink); }
.options li.revealed .opt-rationale .cite {
  font-size: 11px;
  color: var(--ink-mute);
  margin-top: 4px;
  display: block;
}

.action-row {
  display: flex; align-items: center; gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.action-row-spacer { flex: 1; }
.action-link {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  padding: 7px 12px;
  border-radius: 6px;
}
.action-link:hover { border-color: var(--accent-bd); color: var(--ink); }
.action-link.active { color: var(--accent); border-color: var(--accent-bd); }
.action-link.active.flag { color: var(--warn); border-color: var(--warn); }

.primary {
  background: var(--accent);
  color: var(--bg);
  border: 1px solid var(--accent);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 18px;
  cursor: pointer;
  border-radius: 6px;
  letter-spacing: 0.005em;
}
.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.primary:disabled {
  background: var(--surface-2);
  color: var(--ink-mute);
  border-color: var(--line);
  cursor: not-allowed;
}
.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-bd);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 18px;
  cursor: pointer;
  border-radius: 6px;
}
.secondary:hover { background: var(--accent-bg); }

/* setup form (home) */
.setup { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
.setup-row { display: grid; grid-template-columns: 120px 1fr; align-items: start; gap: 16px; }
.setup-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  padding-top: 8px;
  color: var(--ink-mute);
}
.setup-options { display: flex; flex-wrap: wrap; gap: 6px; }
.setup-options.narrow .opt { padding: 6px 12px; }
.opt {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  padding: 7px 14px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}
.opt:hover { border-color: var(--line-strong); color: var(--ink); }
.opt.selected {
  background: var(--accent-bg);
  border-color: var(--accent-bd);
  color: var(--accent-2);
}
.setup-options.multi .opt:not(.selected) { color: var(--ink-mute); }
.opt-head { font-weight: 600; }
.opt-note {
  display: block;
  font-size: 11px;
  color: var(--ink-mute);
  margin-top: 2px;
}
.setup-collapse {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-top: 6px;
}
.setup-collapse > summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 0;
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-mute);
}
.setup-collapse > summary::-webkit-details-marker { display: none; }
.setup-collapse > summary::before {
  content: "+"; display: inline-block; margin-right: 8px; color: var(--ink-mute);
  font-family: var(--mono);
}
.setup-collapse[open] > summary::before { content: "−"; }
.setup-collapse-actions { display: flex; gap: 10px; }
.tag-row { padding: 4px 0 14px; max-height: 240px; overflow-y: auto; }
.dim { color: var(--ink-mute); }
.small { font-size: 12px; }

.run-row { display: flex; align-items: baseline; gap: 18px; margin-top: 26px; }

/* commentary (post-reveal) */
.commentary {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.commentary .section-eyebrow { margin-top: 0; margin-bottom: 18px; }
.commentary .section-eyebrow .topic-tag {
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--accent-2);
  padding: 2px 8px;
  background: var(--accent-bg);
  border-radius: 4px;
}
.commentary .section-eyebrow .difficulty-tag {
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.comm-block { margin-bottom: 20px; }
.comm-block:last-child { margin-bottom: 0; }
.comm-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin: 0 0 6px;
}
.comm-block p { margin: 0 0 8px; font-size: 14.5px; line-height: 1.65; }
.comm-block ul { padding-left: 18px; margin: 6px 0; font-size: 14.5px; line-height: 1.65; }
.comm-block .pearl {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn);
  padding: 10px 14px;
  margin: 12px 0 0;
  font-size: 14px;
  border-radius: 4px;
}
.comm-block .pearl b { color: var(--warn); }
.comm-block .cite {
  font-size: 11.5px;
  color: var(--ink-mute);
  margin-top: 4px;
  display: block;
}
.sources { margin: 0; padding-left: 22px; font-size: 13px; }
.sources li { margin-bottom: 4px; line-height: 1.5; }
/* ── Reference panel (right slide-in, no scrim, no dim) ───────────── */
.ref-panel {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  height: 100dvh;
  width: 420px;
  max-width: 92vw;
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  z-index: 110;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.25);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-right: env(safe-area-inset-right);
}
.ref-panel[hidden] { display: flex !important; visibility: hidden; pointer-events: none; }
.ref-panel:not([hidden]) { transform: translateX(0); visibility: visible; pointer-events: auto; }

/* When the reference panel is open on a desktop-class viewport, shift
 * the reading column left by half the panel width so it stays centred
 * in the visible area to the left of the panel. The column doesn't
 * resize - just slides - so reading width and rhythm are preserved.
 * Below the threshold (1240px = 820 col + 420 panel) we don't shift,
 * since the overlap is unavoidable and the user can close the panel.
 */
/* When the reference panel is open, shrink the available width of the
 * reading column so the whole question stays visible to the left of the
 * 420 px panel. Use padding-right on <body> (avoids the previous
 * translate-only approach which still overlapped content). Below 920 px
 * the panel takes the full screen and the content scroll is locked. */
body.refs-open {
  padding-right: min(420px, 92vw);
  transition: padding-right 0.22s ease;
}
@media (max-width: 920px) {
  body.refs-open { padding-right: 0; overflow: hidden; }
}
.ref-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.ref-title {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--ink-mute);
}
.ref-search { padding: 12px 18px; border-bottom: 1px solid var(--line); }
.ref-search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  border-radius: 6px;
}
.ref-search input:focus { outline: 1px solid var(--accent); outline-offset: -1px; }
.ref-body { flex: 1; overflow-y: auto; padding: 14px 18px 24px; }
.ref-foot {
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  color: var(--ink-mute);
  margin: 0;
  line-height: 1.5;
}
.range-cat { margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.range-cat:last-child { border-bottom: none; }
.range-cat h3 {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--accent-2); margin: 0 0 8px;
}
.range-cat table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.range-cat td { padding: 4px 0; border-bottom: 1px dotted var(--line); vertical-align: top; }
.range-cat td.test { color: var(--ink-mute); width: 50%; padding-right: 10px; }
.range-cat td.value { color: var(--ink); font-family: var(--mono); font-size: 12px; }
.range-cat .range-note { font-size: 11.5px; color: var(--ink-mute); margin: 8px 0 0; line-height: 1.5; }
.range-cat.hidden { display: none; }

/* ── Colophon ─────────────────────────────────────────────────────── */
.colophon {
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding: 11px 28px;
  padding-bottom: calc(11px + env(safe-area-inset-bottom));
  padding-left: max(28px, env(safe-area-inset-left));
  padding-right: max(28px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  font-size: 12.5px;
  position: sticky;
  bottom: 0;
  z-index: 40;
}
.colophon-block { display: flex; align-items: center; gap: 10px; }
.colophon-center { justify-content: center; }
.colophon-right { justify-content: flex-end; }
.colophon-sep { color: var(--line); }
#sessionTime, #questionTime {
  font-family: var(--mono); font-size: 12px;
  color: var(--ink-2); font-variant-numeric: tabular-nums;
}
#questionTime.warn { color: var(--warn); }
#questionTime.danger { color: var(--bad); }

/* ── Summary ──────────────────────────────────────────────────────── */
body[data-screen="summary"] main { max-width: 760px; }
.score-strip { display: grid; grid-template-columns: 170px 1fr; gap: 28px; align-items: start; margin: 24px 0; }
.score-figure {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  text-align: center;
}
.score-num {
  display: block;
  font-family: var(--display);
  font-size: 48px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.score-cap {
  font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-mute);
}
.score-breakdown { display: flex; flex-direction: column; gap: 8px; }
.topic-row {
  display: grid; grid-template-columns: 1fr 80px 60px;
  gap: 12px; align-items: center;
  font-size: 13px;
  border-bottom: 1px solid var(--line); padding-bottom: 5px;
}
.topic-row .bar-track { height: 3px; background: var(--line); border-radius: 3px; }
.topic-row .bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.topic-row .topic-pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-mute); }

.review-filters { display: flex; gap: 6px; margin: 12px 0; }
.review-list {
  list-style: none; margin: 0; padding: 0;
  border-top: 1px solid var(--line);
}
.review-list li {
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 13px;
  display: grid;
  grid-template-columns: 24px 100px 1fr;
  gap: 12px;
}
.review-list li:hover { background: var(--surface-2); }
.review-list .rv-status { font-family: var(--mono); font-weight: 700; }
.review-list li.incorrect .rv-status { color: var(--bad); }
.review-list li.correct   .rv-status { color: var(--good); }
.review-list li.unanswered .rv-status { color: var(--ink-mute); }
.review-list li.flagged { background: var(--warn-bg); }
.review-list .rv-id { font-family: var(--mono); font-size: 11.5px; color: var(--ink-mute); }
.review-list .rv-stem { color: var(--ink-2); }

/* ── Modal (How-to) ───────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(5, 10, 18, 0.65);
  display: grid; place-items: center;
  z-index: 200; padding: 18px;
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: 560px;
  width: 100%;
}
.modal-card-wide { max-width: 760px; max-height: 86vh; display: flex; flex-direction: column; }
.modal-card-wide .modal-body { overflow-y: auto; }
.modal-head {
  border-bottom: 1px solid var(--line);
  padding: 14px 22px;
  display: flex; justify-content: space-between; align-items: center;
}
.modal-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 18px;
  font-weight: 700;
}
.modal-body { padding: 18px 22px; font-size: 14.5px; line-height: 1.6; }
.modal-body code {
  font-family: var(--mono);
  font-size: 12.5px; padding: 1px 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 3px;
}
.modal-body ol { padding-left: 20px; }
.modal-body li { margin-bottom: 8px; }
.prompt-actions { display: flex; align-items: center; gap: 12px; margin: 12px 0 8px; flex-wrap: wrap; }
.paste-box {
  width: 100%;
  min-height: 140px;
  max-height: 260px;
  resize: vertical;
  background: var(--bg);
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  box-sizing: border-box;
}
.paste-box:focus {
  outline: none;
  border-color: var(--accent-bd);
  background: var(--bg-2);
}
.local-bank-row {
  display: flex; align-items: center; gap: 14px;
  margin: 4px 0 6px;
}
#pasteStatus.ok    { color: var(--good); }
#pasteStatus.bad   { color: var(--bad); }
#copyPromptStatus.ok { color: var(--good); }
#copyPromptBtn.copied {
  background: var(--good);
  border-color: var(--good);
  color: #0a1929;
  box-shadow: 0 0 0 3px var(--good-bg);
  transition: background 120ms ease, box-shadow 120ms ease;
}
#copyPromptBtn.copy-failed {
  background: var(--bad);
  border-color: var(--bad);
  color: #0a1929;
}

/* "(+ glucose)" - the joke parenthetical, used only in the masthead
   logo. The whole bit is the med-student joke about forgetting BSL on
   the primary survey; we treat it like an aside, not a co-equal
   wordmark. App title everywhere else is "A to E". */
.brand-glucose {
  font-family: var(--serif, var(--display));
  font-style: italic;
  font-weight: 400;
  color: var(--ink-mute);
  letter-spacing: 0;
  font-size: 0.78em;
  margin-left: 6px;
  position: relative;
  top: -0.18em;
}

.prompt-pre {
  background: var(--bg);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  padding: 14px 16px;
  margin: 0;
  white-space: pre;
  overflow-x: auto;
  max-height: 360px;
  overflow-y: auto;
  color: var(--ink-2);
  border-radius: 6px;
}

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .masthead {
    padding: 12px 18px;
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }
  main { padding: 22px 16px 60px; }
  .reading { padding: 18px 16px; border-radius: 0 0 8px 8px; }
  .setup-row { grid-template-columns: 1fr; gap: 8px; }
  .setup-label { padding-top: 0; }
  .colophon {
    padding: 10px 18px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    grid-template-columns: auto 1fr auto;
    gap: 8px;
  }
  .colophon-center { justify-content: center; }
  .colophon-right { justify-content: flex-end; }
  .ref-panel { width: 100%; max-width: 100%; }
  .score-strip { grid-template-columns: 1fr; }
  .quiz-topbar { border-radius: 8px 8px 0 0; padding: 10px 12px; }
}

/* ── Phone-tight (iPhone 13 mini at 375pt and similar) ───────────── */
@media (max-width: 480px) {
  /* Compact masthead: keep the brand mark + a shorter title, give the
     three tool buttons enough room without wrapping. */
  .masthead { padding: 10px 14px; gap: 8px; }
  .masthead {
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .masthead-left { gap: 10px; min-width: 0; flex: 0 1 auto; }
  .brand { gap: 9px; min-width: 0; }
  .brand-title { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .session-meta { display: none; }
  .t-long { display: none; }
  .t-short { display: inline; }
  .masthead-tools { gap: 0; flex-shrink: 0; flex-wrap: nowrap; }
  .masthead-tools .link-btn { padding: 8px 9px; font-size: 12.5px; white-space: nowrap; }

  main { padding: 18px 14px 56px; }
  body[data-screen="quiz"] main { padding-top: 12px; }

  .display { font-size: 26px; }
  .subhead { font-size: 14px; margin-bottom: 22px; }

  /* Quiz card: shrink margins, keep stems readable. */
  .reading { padding: 16px 14px; }
  .stem { font-size: 16px; line-height: 1.6; }
  .lead-in { font-size: 15px; }
  .patient-table {
    grid-template-columns: 1fr;
    gap: 4px 0;
    padding: 12px 14px;
    font-size: 13.5px;
  }
  .patient-table dt { margin-top: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
  .patient-table dt:first-child { margin-top: 0; }

  /* Options: bigger tap targets, eliminator button hits 32x32 min. */
  .options li {
    grid-template-columns: 30px 1fr 36px;
    gap: 10px;
    padding: 13px 12px;
    font-size: 14.5px;
  }
  .options li .opt-letter { font-size: 15px; }
  .options li .opt-strike {
    width: 32px; height: 32px; font-size: 14px;
  }

  /* Buttons that act as primary tap targets need ~44pt height. */
  .primary, .secondary {
    padding: 12px 18px;
    font-size: 14px;
    min-height: 44px;
  }

  /* Primary actions (Submit, Next, Begin, New session, Copy prompt,
     etc.) live on the RIGHT of the screen on phones - right-thumb
     reach when holding the phone one-handed. */
  .action-row { gap: 8px; flex-wrap: wrap; }
  .action-row #submitBtn,
  .action-row #nextBtn {
    order: -1;
    margin-left: auto;
  }
  .action-row-spacer { flex-basis: 100%; height: 0; order: 0; }
  .action-link {
    padding: 10px 12px;
    font-size: 12.5px;
    min-height: 40px;
    order: 1;
  }

  .run-row { flex-wrap: wrap; gap: 12px; }
  .run-row .primary { margin-left: auto; }

  .prompt-actions { flex-wrap: wrap; }
  .prompt-actions .primary { margin-left: auto; }

  /* Quiz topbar: keep prev / counter / next legible, larger taps. */
  .quiz-topbar { padding: 8px 10px; }
  .qt-step, .qt-counter { padding: 8px 10px; font-size: 13px; min-height: 40px; }
  .qt-counter { gap: 4px; }
  #qtNumber { font-size: 13px; }

  /* Question-list dropdown: single column, taller rows. */
  .qt-list { margin: 0 10px; max-height: 60vh; }
  .qt-list ol { grid-template-columns: 1fr; padding: 6px 10px 10px; }
  .qt-list li { padding: 9px 6px; font-size: 13.5px; }

  /* Setup: keep options easily tappable, prevent crowding. */
  .setup-options { gap: 7px; }
  .opt { padding: 10px 14px; font-size: 13.5px; min-height: 40px; }
  .setup-options.narrow .opt { padding: 9px 14px; }
  .setup-collapse > summary { padding: 12px 0; }

  /* Colophon: 3 columns at narrow widths is too much. Stack a
     compact two-row layout: top row = exit + end, bottom = timers. */
  .colophon {
    padding: 8px 14px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    grid-template-columns: 1fr auto 1fr;
    gap: 6px;
  }
  .colophon .link-btn { padding: 8px 10px; font-size: 12.5px; min-height: 40px; }
  .colophon-block { gap: 8px; }
  #sessionTime, #questionTime { font-size: 12px; }

  /* Ghost-x bigger on touch. */
  .ghost-x { width: 36px; height: 36px; font-size: 20px; }

  /* Modal: full-bleed on phones, scrollable. */
  .modal { padding: 0; align-items: stretch; }
  .modal-card, .modal-card-wide {
    max-width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    display: flex;
    flex-direction: column;
  }
  .modal-card-wide .modal-body { flex: 1; }
  .modal-head {
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top));
  }
  .modal-body {
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .prompt-pre { font-size: 11px; max-height: 50vh; }

  /* Reference panel: full bleed, native-app feel. */
  .ref-panel { box-shadow: none; }

  /* Summary review rows: tighter, full-width stems. */
  .review-list li { grid-template-columns: 22px 1fr; gap: 10px; }
  .review-list .rv-id { display: none; }
  .score-num { font-size: 40px; }
}

/* ── Question image (optional, e.g. dermatology / radiology) ────── */
.q-image {
  margin: 16px 0;
  text-align: center;
}
.q-image img {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: inline-block;
}
.q-image-caption {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--ink-mute);
}

/* ── Author / model tag (LLM attribution) ───────────────────────── */
.model-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-mute);
  background: var(--surface-2);
}

/* ── Report button + modal ──────────────────────────────────────── */
.action-link.has-report { color: var(--accent); }
.report-text {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Reports admin (Rob only) ───────────────────────────────────── */
.admin-only.has-pending { color: var(--accent); }

/* Defence-in-depth: nothing class="admin-only" ever paints unless the body
   has the is-admin class. Set/unset by app.js after auth resolves. */
body:not(.is-admin) .admin-only { display: none !important; }

/* Per-user pill colour palette. Twelve hues chosen for legibility on both
   the light and dark backgrounds. The chosen index is set via the
   --pill-hue inline style at the .profile-chip element by app.js. */
.profile-chip {
  --pill-bg: hsl(var(--pill-hue, 200), 60%, 70%);
  --pill-fg: #0e1421;
  background: var(--pill-bg);
  color: var(--pill-fg);
  padding: 4px 12px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
[data-theme="dark"] .profile-chip {
  --pill-bg: hsl(var(--pill-hue, 200), 55%, 32%);
  --pill-fg: #f3f6fb;
}
.profile-chip .profile-name { font-weight: 600; }
.profile-chip .ghost-link { color: inherit; opacity: 0.7; }
.profile-chip .ghost-link:hover { opacity: 1; }

.admin-only .badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin-left: 4px;
  font-size: 11px;
  line-height: 1.4;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  text-align: center;
  font-weight: 600;
}
.admin-only .badge:empty { display: none; }

.reports-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.reports-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.report-row {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.report-row:hover { background: var(--surface-2); }
.report-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  font-size: 12.5px;
}
.report-id { font-family: var(--font-mono, monospace); color: var(--ink-mute); }
.report-status {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.report-status.status-open      { background: var(--accent); color: var(--bg); }
.report-status.status-fixed     { background: #2a7d44; color: #fff; }
.report-status.status-dismissed { background: var(--ink-mute); color: var(--bg); }
.report-q { margin: 4px 0 6px; font-size: 13px; }
.report-issue {
  white-space: pre-wrap;
  font-size: 13.5px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 6px 6px 0;
}
.report-resolution { margin-top: 6px; }

/* ── Audit dashboard ────────────────────────────────────────────── */
.audit-intro {
  padding: 10px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.55;
}
.audit-intro p { margin: 0; }
.audit-llm-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.audit-llm-picker label { font-weight: 600; }
.audit-llm-picker select {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: inherit;
}

.audit-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.audit-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 14px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink-mute);
  cursor: pointer;
  margin-bottom: -1px;
}
.audit-tab:hover { color: var(--ink-2); }
.audit-tab.selected {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.audit-tab .badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin-left: 4px;
  font-size: 11px;
  line-height: 1.4;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  text-align: center;
  font-weight: 600;
}
.audit-tab .badge:empty { display: none; }

.audit-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.audit-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px 14px;
}
.audit-row-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.audit-row-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1 1 auto;
}
.audit-row-name {
  font-family: var(--font-mono, monospace);
  font-size: 13px;
  font-weight: 600;
  word-break: break-all;
}
.audit-row-meta { flex: 0 0 auto; }
.audit-row-toggle { flex-shrink: 0; white-space: nowrap; }
.audit-flow {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.audit-steps {
  list-style: decimal inside;
  padding: 0;
  margin: 0;
}
.audit-steps > li {
  margin-bottom: 14px;
  font-size: 13.5px;
}
.audit-steps > li > b { margin-right: 8px; }
.audit-copy, .audit-apply { margin-right: 8px; }
.audit-response {
  width: 100%;
  min-height: 160px;
  margin-top: 8px;
  font-family: var(--font-mono, monospace);
  font-size: 12px;
}
.audit-copy-status.ok, .audit-apply-status.ok { color: var(--accent); }
.audit-copy-status.bad, .audit-apply-status.bad { color: #c44; }

.audit-bulk { margin-left: auto; }
.audit-live-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.report-select { cursor: pointer; transform: translateY(1px); }
.report-audit-one, .report-jump { margin-left: auto; font-size: 12px; }

/* ── Disable hover restyles on touch-only devices to prevent
     "stuck" hover states after a tap. ─────────────────────── */
@media (hover: none) {
  .options li:hover:not(.revealed) { border-color: var(--line); }
  .opt:hover { border-color: var(--line); color: var(--ink-2); }
  .setup-options.multi .opt:not(.selected):hover { color: var(--ink-mute); }
  .link-btn:hover { background: transparent; color: var(--ink-2); }
  .qt-step:hover, .qt-counter:hover { background: transparent; color: var(--ink-2); }
  .ghost-x:hover { background: transparent; color: var(--ink-mute); }
  .ghost-link:hover { color: var(--ink-mute); }
  .action-link:hover { border-color: var(--line); color: var(--ink-2); }
  .qt-list li:hover { background: transparent; }
  .review-list li:hover { background: transparent; }
}

/* ── Stem clue highlights (post-reveal) ──────────────────────────── */
mark.stem-clue {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* ── Difficulty toggles (Section: Difficulty) ────────────────────── */
.setup-options[data-name="difficulties"] .opt {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* ── House quote toast (every 50 questions) ──────────────────────── */
.house-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  background: var(--surface-2, var(--surface));
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 14px 18px;
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.18);
  font-family: var(--serif, var(--display));
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  z-index: 9999;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.28s ease, transform 0.28s ease;
  cursor: pointer;
}
.house-toast.show { opacity: 1; transform: translateY(0); }
.house-toast .hq-quote { font-style: italic; }
.house-toast .hq-attrib {
  display: block;
  margin-top: 8px;
  font-style: normal;
  font-family: var(--sans, inherit);
  font-size: 11.5px;
  color: var(--ink-mute);
  text-align: right;
}
@media (max-width: 540px) {
  .house-toast { right: 12px; left: 12px; max-width: none; }
}

/* Cloud-only elements show only when a cloud user is signed in. Set by
   app.js refreshCloudBodyClass() based on the cloudUser state. */
body:not(.is-cloud) .cloud-only { display: none !important; }

/* ── Account / admin tables (rendered into the unified Admin modal) ── */
.account-users-table {
  display: grid;
  grid-template-columns: 1fr 1fr 70px 80px 70px 70px;
  gap: 6px 12px;
  font-size: 12px;
  align-items: center;
}
.account-users-table .ah {
  font-weight: 600;
  color: var(--ink-mute);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  font-size: 11px;
}
.account-users-table .ar { padding: 6px 0; border-bottom: 1px solid var(--line); }
.account-users-table .ar.is-self { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.account-users-table .btn-mini {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-mute);
  cursor: pointer;
}
.account-users-table .btn-mini.danger:hover { border-color: #c0392b; color: #c0392b; }
.account-users-table .btn-mini.promote:hover { border-color: var(--accent); color: var(--accent); }
.account-self-delete {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.account-self-delete .danger-btn {
  margin-top: 8px;
  font-size: 12px;
  padding: 6px 12px;
  border: 1px solid #c0392b;
  background: transparent;
  color: #c0392b;
  border-radius: 6px;
  cursor: pointer;
}
.account-self-delete .danger-btn:hover { background: #c0392b; color: white; }
.account-quality-table {
  display: grid;
  grid-template-columns: 1fr 60px 70px;
  gap: 4px 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.account-quality-table .qh { font-weight: 600; color: var(--ink-mute); font-size: 11px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.account-quality-table .qr { padding: 4px 0; border-bottom: 1px solid var(--line); }
.account-quality-table .qid { font-family: var(--mono); font-size: 11px; }

/* ── Inline reference ranges (post-reveal) ───────────────────────── */
.inline-ranges {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 4px 16px;
  font-size: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.inline-ranges .ir-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}
.inline-ranges .ir-key { color: var(--ink-mute); }
.inline-ranges .ir-val { color: var(--ink); }

/* ── Rebuilt reference panel (search-first, scrollable, dense) ───── */
.ref-search { position: relative; }
.ref-search-hit {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.ref-jump {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  white-space: nowrap;
}
.ref-jump::-webkit-scrollbar { display: none; }
.ref-pill {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-family: inherit;
  color: var(--ink-mute);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.ref-pill:hover { background: var(--surface); color: var(--ink); border-color: var(--ink-mute); }
.ref-body { padding: 10px 14px 24px; }
.range-cat { margin: 0 0 16px; padding: 0 0 12px; border-bottom: 1px solid var(--line); }
.range-cat:last-child { border-bottom: none; }
.range-cat h3 {
  position: sticky;
  top: 0;
  margin: 0 0 6px;
  padding: 8px 0 6px;
  background: var(--surface);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  z-index: 1;
}
.range-cat .rrs { display: flex; flex-direction: column; }
.range-cat .rr {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px dotted var(--line);
  font-size: 12.5px;
  align-items: baseline;
}
.range-cat .rr:last-child { border-bottom: none; }
.range-cat .rr .test { color: var(--ink-mute); }
.range-cat .rr .value { color: var(--ink); font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.range-cat .rr.rr-hidden { display: none; }
.range-cat.hidden { display: none; }

/* ── Unified Admin modal ─────────────────────────────────────────── */
.modal-card-xwide { max-width: 1080px; }
/* Admin modal locks to a stable size so tab switches never reflow the
   surrounding chrome. The content pane scrolls internally instead. */
.admin-modal-card {
  display: flex;
  flex-direction: column;
  width: min(1080px, 96vw);
  height: min(820px, 88vh);
  max-height: 88vh;
  padding: 0;
}
.admin-modal-card .modal-head { flex: 0 0 auto; padding: 18px 24px; border-bottom: 1px solid var(--line); }
.admin-layout {
  display: grid;
  grid-template-columns: 184px 1fr;
  gap: 0;
  min-height: 0;
  flex: 1 1 auto;
  background: var(--surface);
}
.admin-sidebar {
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
  min-width: 0;
  overflow-y: auto;
  gap: 1px;
}
.admin-tab {
  appearance: none;
  background: transparent;
  border: none;
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink-mute);
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-tab-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: var(--ink-mute);
  font-size: 12px;
  opacity: 0.7;
}
.admin-tab-label { flex: 1; }
.admin-tab:hover { background: var(--surface); color: var(--ink); }
.admin-tab.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
  box-shadow: inset 3px 0 0 var(--accent);
}
.admin-tab.active .admin-tab-icon { color: var(--accent); opacity: 1; }
.admin-main {
  padding: 16px 22px 22px;
  overflow-y: auto;
  min-height: 0;
}
.admin-main h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
  margin: 18px 0 10px;
}
.admin-main h3:first-child { margin-top: 0; }
.ag-stat {
  display: flex; flex-direction: column;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.ag-stat-val { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ag-stat-lbl { font-size: 11px; color: var(--ink-mute); margin-top: 2px; }

/* Inside admin panels, suppress legacy modal padding/heads since the
   admin frame already provides them. */
.admin-main .audit-intro,
.admin-main .audit-tabs,
.admin-main .audit-tab-panel { padding: 0; }
.admin-main .audit-tabs { display: none; }
.admin-main .audit-tab-panel { display: block !important; }
.admin-main .howto-steps { padding-left: 0; margin: 0; list-style: none; }

@media (max-width: 720px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 8px;
  }
  .admin-tab { flex: 0 0 auto; }
}

/* Step-style HowTo (preserved when re-parented under the Admin add tab) */
.howto-steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 20px; }
.howto-step { padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.howto-step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.howto-step-head h3 { margin: 0; font-size: 14px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--ink); }
.howto-num {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700; font-size: 12px;
  display: grid; place-items: center;
}
.howto-step-note { font-size: 12.5px; color: var(--ink-mute); margin: 0 0 10px; line-height: 1.55; }

/* ── Admin pane rebuild (round 2) ─────────────────────────────────── */
.admin-pane { display: flex; flex-direction: column; gap: 18px; }
.admin-pane-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.admin-pane-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.admin-pane-section { display: flex; flex-direction: column; gap: 8px; }
.admin-pane-section h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
}
.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}
.ag-stat-val.warn { color: #c0392b; }
.admin-bar-rows { display: flex; flex-direction: column; gap: 6px; }
.ab-row {
  display: grid;
  grid-template-columns: 160px 1fr 90px;
  gap: 14px;
  align-items: center;
  font-size: 12.5px;
}
.ab-label { color: var(--ink); }
.ab-bar-wrap { background: var(--surface-2); border-radius: 999px; overflow: hidden; height: 6px; }
.ab-bar-wrap > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.ab-val { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Legacy-admin migration affordances ──────────────────────────── */

/* Admins see the Admin masthead button. Hide the Account duplicate
   for them - the Account tab inside the admin modal covers the same
   surface. Non-admin cloud users keep the Account button. */
body.is-admin #accountBtn { display: none !important; }

/* Inline-ranges category blocks (post-reveal, in the rationale area) */
.ir-cat { margin-top: 14px; }
.ir-cat-head {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
  margin-bottom: 6px;
}
.ir-cat .inline-ranges { border-top: none; padding-top: 0; margin-top: 0; }
