/* ===========================================================================
   Topic-question AI-checker  (.qg)
   ---------------------------------------------------------------------------
   Page-scoped (loaded only on question_index.html). Dark is the canonical base;
   light is colour-only overrides under html.theme-light. Royal blue is the only
   accent. New --esa-* tokens are ADDED here (page-scoped); no global token VALUES
   are edited. Animation runs through Motion (grader.js / pager); CSS holds layout
   + state colours. Idle = question card + pager; the AI-grading card is hidden
   and revealed after "Mark answer".
   =========================================================================== */

:root {
  --esa-success:        #34d399;
  --esa-success-bg:     rgba(52, 211, 153, 0.12);
  --esa-success-border: rgba(52, 211, 153, 0.34);
  --esa-result-muted:   rgba(148, 163, 184, 0.55);
  /* Pager grade-state fills — opaque + dark ink, so they read clearly and stay
     AA in BOTH themes (verified: ink #0b1220 on each fill ≥ 7:1). */
  --esa-grade-full:    #34d399;
  --esa-grade-partial: #fbbf24;
  --esa-grade-zero:    #f87171;
  --esa-grade-ink:     #0b1220;
  --tq-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  /* Elevation + motion system (page-scoped; extends, never overwrites globals) */
  --tq-border-hairline: rgba(255, 255, 255, 0.09);
  --tq-border-strong:   rgba(255, 255, 255, 0.14);
  --tq-edge-top:        inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --tq-shadow-ambient:  0 18px 48px -14px rgba(0, 0, 0, 0.60), 0 2px 8px rgba(0, 0, 0, 0.32);
  --tq-ease-out:        cubic-bezier(0.22, 1, 0.36, 1);
  --tq-ease:            cubic-bezier(0.40, 0, 0.20, 1);
  --tq-dur:             0.26s;
  --tq-dur-fast:        0.14s;
}
html.theme-light {
  --esa-success:        #047857;  /* AA on light surfaces (5.5:1 on #fff) */
  --esa-success-bg:     #ecfdf5;
  --esa-success-border: rgba(5, 150, 105, 0.28);
  --esa-result-muted:   rgba(100, 116, 139, 0.5);
  --tq-border-hairline: rgba(15, 23, 42, 0.10);
  --tq-border-strong:   rgba(15, 23, 42, 0.16);
  --tq-edge-top:        inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --tq-shadow-ambient:  0 1px 2px rgba(15, 23, 42, 0.05), 0 14px 34px -10px rgba(15, 23, 42, 0.16);
}

.qg,
.qg-pager {
  --qg-card-bg: linear-gradient(180deg, rgba(18, 22, 36, 0.62) 0%, rgba(11, 15, 26, 0.92) 100%);
  --qg-card-border: var(--tq-border-hairline);
  --qg-card-border-hover: rgba(132, 182, 255, 0.32);
  --qg-card-shadow: var(--tq-shadow-ambient), var(--tq-edge-top);
  --qg-well-inset: inset 0 1px 3px rgba(0, 0, 0, 0.28);
  --qg-sub-bg: rgba(255, 255, 255, 0.022);
  --qg-sub-bg-2: rgba(255, 255, 255, 0.05);
  --qg-sub-border: var(--qc-border, rgba(148, 163, 184, 0.16));
  --qg-ink: var(--qc-text-strong, #eef4ff);
  --qg-ink-2: var(--qc-text, rgba(232, 238, 255, 0.92));
  --qg-body: rgba(214, 223, 242, 0.82);
  --qg-muted: var(--text-muted, rgba(220, 226, 245, 0.66));
  --qg-faint: var(--text-faint, rgba(220, 226, 245, 0.40));
  --qg-accent: var(--accent, #5b8cff);
  --qg-accent-text: var(--text-link, #84b6ff);
  --qg-accent-soft: var(--accent-soft, rgba(91, 140, 255, 0.16));
  --qg-accent-border: var(--accent-border, rgba(169, 190, 255, 0.28));
  --qg-input-bg: rgba(8, 11, 20, 0.5);
  --qg-btn-grad: linear-gradient(135deg, #4f7cff 0%, #3f63f5 100%);
  --qg-btn-glow: 0 8px 24px rgba(63, 99, 245, 0.45);
  --qg-sk-bg: rgba(120, 168, 255, 0.09);
  --qg-sk-shine: rgba(140, 212, 255, 0.50);
  --qg-sk-shine-edge: rgba(96, 150, 255, 0.16);

  /* ── Stage-redesign tokens (mirror the mockup :root; page-scoped, dark base).
     The mockup uses --line / --line-strong / --grade-* / --input-bg / radii /
     --panel-bg / --bottom-h that DON'T exist globally — define them here so no
     border ever falls back to transparent. NEVER edit a global token VALUE. */
  --tq-line:          rgba(255, 255, 255, 0.11);
  --tq-line-strong:   var(--qg-card-border-hover);   /* periwinkle */
  --tq-r-card:        20px;
  --tq-r-lg:          16px;
  --tq-r-md:          12px;
  --tq-r-pill:        999px;
  --tq-grade-bg:      rgba(45, 212, 191, 0.10);
  --tq-grade-border:  rgba(45, 212, 191, 0.28);
  --tq-grade-text:    #9ff5e9;
  --tq-input-bg:      rgba(255, 255, 255, 0.035);
  --tq-bottom-h:      82px;
  --tq-panel-bg:
    radial-gradient(900px 360px at 82% -8%, rgba(91, 140, 255, 0.12), transparent 62%),
    radial-gradient(680px 300px at 0% 0%, rgba(45, 212, 191, 0.07), transparent 58%),
    linear-gradient(180deg, rgba(24, 30, 48, 0.98), rgba(17, 22, 38, 0.98));
}
.qg { display: block; }

/* one-question-per-page (JS adds .is-paged; no-JS shows all) */
.question-list.is-paged > .qg { display: none; }
.question-list.is-paged > .qg.is-current { display: block; }
.question-list.is-paged .qg:focus { outline: none; }
/* Anti-flash: html.tq-js is set synchronously in <head>, so before the deferred
   pager module runs (and adds .is-paged) only the first question shows — the
   others never flash stacked on load. With no JS, html.tq-js is absent → all show. */
html.tq-js .question-list:not(.is-paged) > .qg:not(:first-child) { display: none; }

/* Anti-flash (topic nav): when 2+ questions are present the deferred pager module
   hides this server-rendered Previous/Next topic nav and builds .qg-pager instead
   (question-pager.js gates on totalCount >= 2). Pre-hide it under html.tq-js so the
   old "Next ->" button never flashes before the module runs. No-JS users (no
   html.tq-js) and single-question pages (no 2nd .qg) keep the nav. */
html.tq-js .tq-shell .noteviewer-main-inner:has(.question-list > .qg:nth-child(2)) .note-pagination { display: none; }

/* ══════════════════════════════════════════════════════════════════════════
   Exam-paper sheet — the question lives on the page, no card box. A number in
   the left margin, marks in the right margin, a rule, then the answer space,
   then the "mark scheme" reveal. The paper reads through structure + serif, not
   decoration (no texture, no cream — dark is canonical).
   ══════════════════════════════════════════════════════════════════════════ */
.tq-paper {
  max-width: 720px;
  margin-inline: auto;
  padding: clamp(4px, 1vw, 12px) 0 2px;
}

/* Question line: [no.]   question   [marks] */
.tq-q-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  column-gap: clamp(14px, 2.4vw, 28px);
  align-items: baseline;
}
.tq-q-no {
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.5rem, 1.15rem + 1.3vw, 2.3rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--qg-faint);
}
.tq-q-main { min-width: 0; }
.tq-q-kicker {
  margin: 0 0 7px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--qg-faint);
}
/* marks in the right margin, like a real paper */
.tq-q-marks {
  white-space: nowrap;
  align-self: start;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--qg-muted);
  font-variant-numeric: tabular-nums;
}
.tq-q-marks b { font-weight: 800; color: var(--qg-ink-2); }
/* premium: a score division in the margin (— / 3 → 2 / 3). The score is the only
   bit that fills + colours on marking; the slash and total stay quiet. */
.tq-q-marks--score { font-size: 0.95rem; color: var(--qg-muted); font-variant-numeric: tabular-nums; }
.tq-q-marks--score .qg-score { font-weight: 800; font-size: 1.12em; color: var(--qg-faint); }
.tq-q-slash { color: var(--qg-faint); }
.qg[data-grade="full"]    .tq-q-marks--score .qg-score { color: var(--esa-success); }
.qg[data-grade="partial"] .tq-q-marks--score .qg-score { color: var(--warning, #fbbf24); }
.qg[data-grade="zero"]    .tq-q-marks--score .qg-score { color: var(--esa-grade-zero, #f87171); }

/* The question — serif, calm weight: the signature exam-paper note.
   div[role=heading] escapes .noteviewer-body h2; the resets keep any stray
   bar / gradient / margin leak out. */
.tq-question {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  border-radius: 0;
  box-shadow: none;
  font-family: var(--tq-serif);
  font-weight: 500;
  font-size: clamp(1.3rem, 1.05rem + 0.9vw, 1.7rem);
  line-height: 1.35;
  letter-spacing: -0.005em;
  color: var(--qg-ink);
  text-wrap: pretty;
}
.tq-question p { margin: 0; font: inherit; letter-spacing: inherit; }
.tq-question p + p { margin-top: 0.6em; }

/* Rule separating the question from the answer space. */
.tq-rule {
  height: 1px;
  margin: clamp(16px, 2.4vw, 24px) 0 clamp(18px, 2.6vw, 26px);
  background: var(--tq-line);
}

/* Mark-scheme toggle: a borderless ruled row (label left, chevron right) — not a box. */
.tq-reveal { width: 100%; margin-top: 16px; border-top: 1px solid var(--tq-line); }
.tq-reveal-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 13px 0 12px;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--qg-accent-text);          /* accent so it clearly reads as a reveal action */
  font: inherit;
  font-size: 1rem;
  font-weight: 750;
  cursor: pointer;
  transition: color 0.18s ease;
}
/* an eye glyph before the label makes "reveal" obvious to a student */
.tq-reveal-btn::before {
  content: "";
  width: 18px; height: 18px; flex: 0 0 auto;
  background: currentColor;
  -webkit-mask: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");
          mask: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");
}
.tq-reveal-btn:hover { color: var(--qg-accent); text-decoration: underline; text-underline-offset: 4px; }
.tq-reveal-btn:focus-visible { outline: 2px solid var(--focus-ring, #5b8cff); outline-offset: 3px; border-radius: 4px; }
.tq-reveal-chevron { margin-left: auto; color: currentColor; transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1); }
.tq-reveal.is-open .tq-reveal-chevron { transform: rotate(180deg); }

/* Mark scheme — set off by a rule, not a box, and the answer in serif to match
   the question. Reads as part of the exam paper, not a card. */
.tq-reveal-panel {
  margin: 0 0 2px;
  padding: 4px 0 6px;
  border: 0;
  background: none;
  border-radius: 0;
}
.tq-reveal-panel[hidden] { display: none; }

/* answer — the form is the "response area": pushed to the bottom of the column */
.qg-form { margin-top: auto; padding-top: 26px; }
.tq-answer-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.tq-answer-label { display: block; font-size: 0.9375rem; font-weight: 600; color: var(--qg-ink-2); }
.tq-char-count { font-size: 0.75rem; color: var(--qg-muted); font-variant-numeric: tabular-nums; flex: 0 0 auto; transition: color 0.18s ease; }
/* approaching the 500-char cap: amber from 450, danger at the limit — state feedback, not decoration */
.tq-char-count.is-near { color: var(--warning, #fbbf24); }
.tq-char-count.is-max { color: var(--danger, #ef4444); font-weight: 700; }
.tq-input-wrap { border-radius: var(--tq-r-md); }
/* Open ruled writing area — exam answer lines. line-height matches the 32px
   gradient pitch so typed text sits on the rules; background-attachment:local
   scrolls the lines with the text. */
.qg-input {
  width: 100%;
  display: block;
  min-height: 132px;
  resize: vertical;
  padding: 12px 15px;
  border-radius: var(--tq-r-md);
  border: 1px solid var(--tq-line);
  background-color: var(--tq-input-bg);
  color: var(--qg-ink);
  font-family: var(--tq-serif);     /* write on the paper in the paper's hand */
  font-size: 1.02rem;
  line-height: 1.6;
  transition: border-color var(--tq-dur, 0.26s) var(--tq-ease, ease), box-shadow var(--tq-dur, 0.26s) var(--tq-ease, ease), opacity 0.18s ease;
}
.qg-input::placeholder { color: var(--qg-muted); }
.qg-input:focus, .qg-input:focus-visible { outline: 2px solid transparent; outline-offset: 2px; border-color: var(--qg-accent); box-shadow: 0 0 0 4px var(--qg-accent-soft); }
.qg-input.is-locked { cursor: default; opacity: 0.78; }
.qg[data-state="grading"] .qg-input { opacity: 0.7; pointer-events: none; }
.qg[data-state="error"] .qg-input { border-color: var(--danger, #ef4444); }

.qg-hint { margin: 10px 0 0; font-size: 0.8125rem; color: var(--danger, #ef4444); }
.qg-hint[hidden] { display: none; }

.tq-answer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.tq-foot-meta { display: inline-flex; align-items: center; gap: 12px; font-size: 0.875rem; color: var(--qg-muted); flex-wrap: wrap; }
.tq-worth { display: inline-flex; align-items: center; gap: 8px; }
.tq-worth svg { color: var(--qg-accent-text); flex-shrink: 0; }
.qg-saved { display: inline-flex; align-items: center; gap: 8px; color: var(--qg-muted); }
.qg-saved[hidden] { display: none; }
.qg-saved svg { color: var(--qg-muted); flex-shrink: 0; }
.tq-foot-sep { width: 1px; height: 16px; background: var(--qg-card-border); margin-right: 4px; }

/* gradient Mark button */
.tq-mark-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 26px;
  border: 0;
  border-radius: 12px;
  background: var(--qg-btn-grad);
  color: #fff;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 650;
  cursor: pointer;
  box-shadow: var(--qg-btn-glow);
  transition: filter 0.18s ease, box-shadow 0.2s ease, opacity 0.18s ease, transform var(--tq-dur-fast, 0.14s) var(--tq-ease-out, ease-out);
}
.tq-mark-btn:hover { background: var(--qg-btn-grad); filter: brightness(1.08); box-shadow: 0 12px 30px rgba(63, 99, 245, 0.52); transform: translateY(var(--lift-sm, -1px)); }
.tq-mark-btn:active { transform: translateY(0) scale(0.985); }
.tq-mark-btn:focus-visible { outline: 2px solid var(--focus-ring, #5b8cff); outline-offset: 3px; }
.tq-mark-btn:disabled { opacity: 0.6; cursor: default; transform: none; }
.tq-mark-icon { flex-shrink: 0; }
.qg[data-state="grading"] .tq-mark-icon { display: none; }
.qg-spinner {
  width: 16px; height: 16px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  display: none;
  animation: qg-spin 0.7s linear infinite;
}
.qg[data-state="grading"] .qg-spinner { display: inline-block; }
@keyframes qg-spin { to { transform: rotate(360deg); } }

/* Answer/upgrade note — sits under the question as the "answer" slot (no label). */
/* Free/non-gradable: a quiet note where the answer space would be — no box. */
.tq-signin-hint {
  margin: 2px 0 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--qg-muted);
}

/* Mark-scheme checks: placeholder only while idle; grade card replaces it. */
.tq-scheme-placeholder { display: none; margin-top: 10px; font-size: 0.88rem; line-height: 1.4; color: var(--qg-muted); }
.qg[data-state="idle"] .tq-scheme-placeholder { display: block; }

/* ══════════════════════════════════════════════════════════════════════════
   AI grading card — hidden until Mark, then revealed with the results
   ══════════════════════════════════════════════════════════════════════════ */
/* Relocated INSIDE the status panel: no standalone card chrome (the panel already
   provides the frame) — it just reveals the keypoint rows + total once graded. */
.tq-grade-card {
  margin-top: 22px;
  padding: 20px 0 0;
  border: 0;
  border-top: 1px solid var(--tq-line);
  background: none;
  box-shadow: none;
}
.tq-grade-card[hidden] { display: none; }
/* Marked-answer header: a faint label like the other sections — no app-y badge. */
.tq-grade-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.tq-grade-badge { display: none; }
.tq-grade-head-text { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.tq-grade-title { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.09em; text-transform: uppercase; color: var(--qg-faint); }
.tq-grade-sub { font-size: 0.8rem; color: var(--qg-muted); }
/* Reset — sits flush-right in the marked-answer header; clears the answer, the
   marked result, and this question's pager-chip colour/state. Only present once
   the grade card shows; hidden mid-grade so a reset can't race the result. */
.tq-grade-reset {
  margin-left: auto;
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 9px;
  border: 1px solid var(--qg-sub-border);
  background: transparent;
  color: var(--qg-muted);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease, background 0.16s ease, transform 0.14s var(--tq-ease-out, ease-out);
}
.tq-grade-reset svg { flex-shrink: 0; }
.tq-grade-reset:hover { color: var(--qg-ink); border-color: var(--qg-card-border-hover); background: var(--qg-sub-bg); transform: translateY(-1px); }
.tq-grade-reset:active { transform: translateY(0); }
.tq-grade-reset:focus-visible { outline: 2px solid var(--focus-ring, #5b8cff); outline-offset: 2px; }
.qg[data-state="grading"] .tq-grade-reset { display: none; }

.tq-grade-body { display: flex; flex-direction: column; gap: clamp(16px, 1.8vw, 22px); }

/* Keypoint rows — mockup .mini-point look: teal dot + muted text, no boxed row.
   Matched points flip to the success token (tick colour + emphasised text).
   The dot is drawn on .tq-kp-label::before (NOT .tq-kp::before, which collides
   with the inherited .noteviewer-body ul>li::before list-marker, suppressed
   below via the existing .tq-shell .tq-kp::before{content:none} rule). */
.tq-kp-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.tq-kp { display: flex; align-items: flex-start; gap: 9px; padding: 0; border: 0; border-radius: 0; background: none; }
.tq-kp-label {
  flex: 1; min-width: 0;
  position: relative;
  padding-left: 24px;
  font-family: var(--tq-serif);
  font-size: 1rem;
  line-height: 1.45;
  color: var(--qg-body);
}
/* Examiner marks in the margin: ✕ not awarded, ✓ awarded. */
.tq-kp-label::before {
  content: "\2715";        /* ✕ */
  position: absolute;
  left: 0;
  top: 0;
  font-size: 0.85em;
  font-weight: 700;
  line-height: 1.55;
  color: var(--qg-faint);
}
.tq-kp.is-matched .tq-kp-label::before { content: "\2713"; color: var(--esa-success); }  /* ✓ */
.tq-kp-status { flex-shrink: 0; font-size: 0.8125rem; color: var(--qg-faint); }
.tq-kp.is-matched .tq-kp-label { color: var(--qg-ink); }
.tq-kp.is-matched .tq-kp-status { color: var(--esa-success); font-weight: 600; }
/* matched key-points ease their colour + check-mark in (the JS cascade handles scale/opacity) — grade-reveal polish */
.tq-kp-label, .tq-kp-label::before, .tq-kp-status { transition: color 0.3s var(--tq-ease-out, ease); }

/* (total score moved to the margin division .tq-q-marks--score) */

/* Feedback band (LEFT column, mockup .grade-band): teal grade-tinted panel,
   hidden until graded; teal eyebrow on the accent block-title. */
/* Examiner feedback: no box — a ruled section with a faint label + serif body. */
.tq-feedback-band { margin-top: 20px; padding: 18px 0 2px; border: 0; border-top: 1px solid var(--tq-line); background: none; border-radius: 0; }
.tq-feedback-band[hidden] { display: none; }
.tq-block-title { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.09em; text-transform: uppercase; color: var(--qg-faint); }
.tq-block-title--accent { color: var(--qg-faint); }
.tq-block-title svg { display: none; }
.tq-block-body { margin: 0; font-family: var(--tq-serif); font-size: 1.02rem; line-height: 1.6; color: var(--qg-ink-2); text-wrap: pretty; }
.tq-feedback-band .tq-block-body { color: var(--qg-ink-2); }
.tq-block-body p:first-child { margin-top: 0; }
.tq-block-body p:last-child { margin-bottom: 0; }
.tq-model-body { font-family: var(--tq-serif); font-size: 1.02rem; line-height: 1.6; color: var(--qg-ink-2); }

/* ── Loading skeleton — Motion shimmer placeholder shown while the grade runs ─
   Mirrors the real layout (N keypoint rows + score + feedback band) so the card
   appears instantly and morphs in place with no size jump. .is-loading swaps it
   for the real .tq-grade-body. Base fill is CSS; the sweep is a Motion-animated
   .tq-sk-shine injected per surface (none injected under reduced motion). */
.tq-grade-skeleton { display: none; }
.tq-grade-card.is-loading .tq-grade-skeleton { display: flex; flex-direction: column; gap: clamp(16px, 1.8vw, 22px); }
.tq-grade-card.is-loading .tq-grade-body { display: none; }
.tq-sk-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.tq-sk-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--qg-card-border); background: var(--qg-sub-bg); }
.tq-sk-bar { height: 12px; border-radius: 999px; }
.tq-sk-row .tq-sk-bar { flex: 1; }
.tq-sk-row:nth-child(odd) .tq-sk-bar { max-width: 90%; }
.tq-sk-row:nth-child(even) .tq-sk-bar { max-width: 72%; }
.tq-sk-total { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-top: 1px solid var(--qg-card-border); }
.tq-sk-total .tq-sk-bar--label { width: 96px; }
.tq-sk-chip { width: 54px; height: 18px; border-radius: 999px; }
.tq-sk-band { padding: clamp(16px, 2vw, 20px) clamp(18px, 2.2vw, 24px); border-radius: 14px; border: 1px solid var(--qg-accent-border); background: var(--qg-accent-soft); display: flex; flex-direction: column; gap: 12px; }
.tq-sk-band .tq-sk-bar--title { width: 110px; height: 11px; }
.tq-sk-line { height: 11px; border-radius: 999px; width: 100%; }
.tq-sk-line--short { width: 62%; }
.tq-sk-bar, .tq-sk-chip, .tq-sk-line { position: relative; overflow: hidden; background: var(--qg-sk-bg); }
.tq-sk-shine { position: absolute; inset: 0; transform: translateX(-130%); pointer-events: none; background: linear-gradient(90deg, transparent 0%, var(--qg-sk-shine-edge) 32%, var(--qg-sk-shine) 50%, var(--qg-sk-shine-edge) 68%, transparent 100%); }

.qg-sr {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ══════════════════════════════════════════════════════════════════════════
   Mode toggle — normalise teal/green resource accents to royal blue
   ══════════════════════════════════════════════════════════════════════════ */
.questions-mode-tab:hover { background: var(--accent-soft, rgba(91, 140, 255, 0.10)); color: var(--text, rgba(245, 248, 255, 0.96)); }
.questions-mode-tab.is-active,
.questions-mode-tab.is-active:hover,
.questions-mode-tab--topic.is-active,
.questions-mode-tab--topic.is-active:hover,
.questions-mode-tab--mcq.is-active,
.questions-mode-tab--mcq.is-active:hover {
  color: var(--text-link, #84b6ff);
  background: var(--accent-soft, rgba(91, 140, 255, 0.14));
  border-color: var(--accent-border, rgba(132, 182, 255, 0.40));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 10px rgba(91, 140, 255, 0.12);
}
.questions-mode-tab:focus-visible { outline: 2px solid var(--focus-ring, #5b8cff); outline-offset: 2px; }

/* ══════════════════════════════════════════════════════════════════════════
   Pager bar
   ══════════════════════════════════════════════════════════════════════════ */
.qg-pager { display: flex; align-items: center; gap: 16px; margin-top: 24px; padding: clamp(14px, 1.6vw, 18px) clamp(16px, 2vw, 22px); border-radius: 18px; border: 1px solid var(--qg-card-border); background: var(--qg-card-bg); box-shadow: var(--qg-card-shadow); }
.qg-pager-center { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qg-pager-btn { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 14px; border-radius: 9px; font: inherit; font-size: 0.875rem; font-weight: 600; cursor: pointer; transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, filter 0.18s ease, opacity 0.18s ease; }
.qg-pager-btn:focus-visible { outline: 2px solid var(--focus-ring, #5b8cff); outline-offset: 2px; }
.qg-pager-btn:disabled { opacity: 0.4; cursor: default; }
.qg-pager-prev { border: 1px solid var(--qg-sub-border); background: var(--qg-sub-bg-2); color: var(--qg-ink-2); }
.qg-pager-prev:not(:disabled):hover { background: var(--qg-sub-bg-2); border-color: var(--qg-card-border-hover); color: var(--qg-ink); }
.qg-pager-next { border: 0; background: var(--qg-btn-grad); color: #fff; box-shadow: var(--qg-btn-glow); }
/* Keep the gradient + white label on hover in EVERY state (incl. disabled on the
   last question) so the global button:hover white-wash can never hide the text. */
.qg-pager-next:hover { background: var(--qg-btn-grad); color: #fff; }
.qg-pager-next:not(:disabled):hover { filter: brightness(1.08); }
.qg-pager-nums { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; justify-content: center; }
.qg-pager-num { min-width: 30px; height: 30px; padding: 0 5px; border-radius: 8px; border: 1px solid var(--qg-sub-border); background: transparent; color: var(--qg-muted); font: inherit; font-size: 0.875rem; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer; transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease; }
.qg-pager-num:hover { background: var(--qg-sub-bg); border-color: var(--qg-card-border-hover); color: var(--qg-ink); }
.qg-pager-num:focus-visible { outline: 2px solid var(--focus-ring, #5b8cff); outline-offset: 2px; }
.qg-pager-num.is-current { background: var(--qg-accent-soft); border-color: var(--qg-accent-border); color: var(--qg-accent-text); }

/* ── Pager number graded states (cosmetic; from the server score bucket) ──── */
.qg-pager-num { position: relative; overflow: hidden; }
.qg-pager-num-n { position: relative; z-index: 1; }
/* active ring — coexists with a graded fill (box-shadow isn't clipped by overflow) */
.qg-pager-num.is-current { box-shadow: 0 0 0 2px var(--qg-accent); }
/* --pf-color drives the particle/fill colour: set transiently via data-pf during
   the animation, and permanently via data-grade-state */
.qg-pager-num[data-pf="full"],    .qg-pager-num[data-grade-state="full"]    { --pf-color: var(--esa-grade-full); }
.qg-pager-num[data-pf="partial"], .qg-pager-num[data-grade-state="partial"] { --pf-color: var(--esa-grade-partial); }
.qg-pager-num[data-pf="zero"],    .qg-pager-num[data-grade-state="zero"]    { --pf-color: var(--esa-grade-zero); }
.qg-pager-num[data-grade-state] { color: var(--esa-grade-ink); border-color: rgba(0, 0, 0, 0.22); box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.10); }
.qg-pager-num[data-grade-state="full"]    { background: var(--esa-grade-full); }
.qg-pager-num[data-grade-state="partial"] { background: var(--esa-grade-partial); }
.qg-pager-num[data-grade-state="zero"]    { background: var(--esa-grade-zero); }
/* keep the graded look + ink on hover (beats .qg-pager-num:hover and the global button:hover) */
.qg-pager-num[data-grade-state]:hover { background: var(--pf-color); color: var(--esa-grade-ink); filter: brightness(1.06); }
/* graded + current: grade fill + ink win, plus the accent ring signals "active" */
.qg-pager-num.is-current[data-grade-state] { color: var(--esa-grade-ink); box-shadow: 0 0 0 2px var(--qg-accent), inset 0 0 10px rgba(0, 0, 0, 0.10); }
/* particle-fill nodes (JS-injected, removed after the run) */
.qg-pf-fill { position: absolute; inset: 0; background: var(--pf-color); transform: scaleY(0); transform-origin: bottom; border-radius: inherit; pointer-events: none; z-index: 0; }
.qg-pf-dot { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--pf-color); opacity: 0; pointer-events: none; z-index: 0; }
.qg-pager-gap { color: var(--qg-faint); padding: 0 2px; user-select: none; }
.qg-pager-progress { position: relative; width: 100%; max-width: 540px; display: flex; align-items: center; justify-content: center; min-height: 18px; }
.qg-pager-track { position: absolute; left: 0; right: 0; top: 50%; height: 3px; transform: translateY(-50%); border-radius: 999px; background: var(--qg-sub-bg-2); overflow: hidden; }
.qg-pager-fill { display: block; height: 100%; border-radius: 999px; background: var(--qg-accent); transition: width 0.32s cubic-bezier(0.22, 1, 0.36, 1); }
.qg-pager-count { position: relative; padding: 0 14px; background: var(--qg-card-bg); font-size: 0.8125rem; color: var(--qg-muted); font-variant-numeric: tabular-nums; }
.qg-pager-count b { color: var(--qg-ink-2); font-weight: 700; }

/* ══════════════════════════════════════════════════════════════════════════
   Light theme — colour-only overrides
   ══════════════════════════════════════════════════════════════════════════ */
html.theme-light .qg,
html.theme-light .qg-pager {
  --qg-card-bg: #ffffff;
  --qg-card-border: var(--tq-border-hairline);
  --qg-card-border-hover: rgba(59, 82, 208, 0.30);
  --qg-card-shadow: var(--tq-shadow-ambient), var(--tq-edge-top);
  --qg-sub-bg: #f7f9fc;
  --qg-sub-bg-2: rgba(15, 23, 42, 0.05);
  --qg-sub-border: rgba(15, 23, 42, 0.08);
  --qg-ink: #0f172a;
  --qg-ink-2: #1f2940;
  --qg-body: #3a455c;
  --qg-muted: var(--text-muted);
  --qg-faint: var(--text-faint);
  --qg-input-bg: #ffffff;
  --qg-well-inset: inset 0 1px 2px rgba(15, 23, 42, 0.06);
  --qg-btn-grad: linear-gradient(135deg, #3b52d0 0%, #4f64e0 100%);
  --qg-btn-glow: 0 8px 22px rgba(59, 82, 208, 0.3);
  --qg-sk-bg: rgba(91, 140, 255, 0.10);
  --qg-sk-shine: rgba(186, 230, 255, 0.92);
  --qg-sk-shine-edge: rgba(120, 170, 255, 0.30);

  /* Stage-redesign tokens — light (colour-only) */
  --tq-line:          rgba(21, 26, 45, 0.10);
  --tq-line-strong:   var(--qg-card-border-hover);
  --tq-grade-bg:      rgba(11, 143, 131, 0.10);
  --tq-grade-border:  rgba(11, 117, 110, 0.24);
  --tq-grade-text:    #0B756E;
  --tq-input-bg:      #ffffff;
  --tq-panel-bg:
    radial-gradient(860px 340px at 82% -8%, rgba(59, 82, 208, 0.08), transparent 62%),
    linear-gradient(180deg, #ffffff, #f7f9ff);
}

/* ══════════════════════════════════════════════════════════════════════════
   Premium polish — hover lift, active dot, label
   ══════════════════════════════════════════════════════════════════════════ */

/* Hover-lift micro-interaction (transform-only) on interactive controls */
.tq-reveal-btn, .qg-pager-btn, .qg-pager-num {
  transition-property: background, border-color, color, box-shadow, filter, opacity, transform;
  transition-duration: var(--tq-dur-fast, 0.14s);
  transition-timing-function: var(--tq-ease-out, ease-out);
}
.tq-reveal-btn:hover, .qg-pager-prev:not(:disabled):hover, .qg-pager-num:hover { transform: translateY(-1px); }

/* uppercase-tracked answer label */
.tq-answer-label { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; text-transform: none; }
html.theme-light .tq-q-of { color: #6b778c; }


/* "Thinking" badge — gentle pulse + restrained blue/cyan glow while loading */
@keyframes tq-badge-pulse { 0%, 100% { transform: scale(1); opacity: 0.82; } 50% { transform: scale(1.09); opacity: 1; } }
@keyframes tq-badge-glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(96, 150, 255, 0); } 50% { box-shadow: 0 0 14px 1px rgba(120, 200, 255, 0.40); } }
.tq-grade-card.is-loading .tq-grade-badge { animation: tq-badge-pulse 1.3s ease-in-out infinite, tq-badge-glow 1.6s ease-in-out infinite; }
.tq-grade-card.is-loading .tq-grade-badge svg { filter: drop-shadow(0 0 3px rgba(140, 210, 255, 0.55)); }

/* ══════════════════════════════════════════════════════════════════════════
   Reduced motion
   ══════════════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .qg-spinner { animation: none; }
  .qg-input, .tq-mark-btn, .tq-reveal-btn, .tq-reveal-chevron, .qg-pager-btn, .qg-pager-num, .qg-pager-fill, .tq-grade-reset { transition: none; }
  .tq-reveal-btn:hover, .qg-pager-prev:not(:disabled):hover, .qg-pager-num:hover, .tq-grade-reset:hover, .tq-mark-btn:hover, .tq-mark-btn:active { transform: none; }
  .tq-grade-card.is-loading .tq-grade-badge { animation: none; }
  .tq-grade-card.is-loading .tq-grade-badge svg { filter: none; }
}

/* ══════════════════════════════════════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════════════════════════════════════ */
/* ── The single-column card stacks at every width; on small screens just tighten
   the padding and make the mark button full-width. The question size is the base
   clamp (no separate mobile override needed). ── */
@media (max-width: 860px) {
  .question-stage { padding: 22px 18px; }
  .tq-answer-foot { gap: 12px; }
  .tq-mark-btn { width: 100%; justify-content: center; }
}
/* Touch devices: the tiny number jumper is awkward to tap and won't fit the
   narrow bar — hide it (Prev/Next remain), and keep the other targets ~44px. */
@media (pointer: coarse) {
  .tq-shell .qg-pager-nums { display: none; }
  .qg-pager-btn { min-height: 44px; }
  .questions-mode-tab { min-height: 44px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   App-shell — single viewport, pinned pager. PAGE-SCOPED via .tq-shell so no
   other page is affected (global html/body scroll is only altered when this
   page is present, via :has). A flex column fills the viewport under the
   sticky 72/64px topbar (auto-adapting to its real height); the header +
   segmented toggle stay pinned at the top, the pager is pinned at the bottom,
   and ONLY .noteviewer-body scrolls internally when its content overflows —
   so the footer never moves and nothing is ever clipped.
   ══════════════════════════════════════════════════════════════════════════ */
/* 2026-06-20: single-viewport lock removed — the page scrolls naturally and the
   pager is sticky at the bottom (below). Footer stays hidden to keep the focused
   study screen; the rest of the app-shell rules just become harmless no-ops. */
body:has(.tq-shell) { min-height: 100dvh; }
body:has(.tq-shell) > .main-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}
body:has(.tq-shell) > .site-footer { display: none; }   /* marketing footer off the app screen */

.tq-shell {                       /* = .nv-canvas on this page */
  width: 100%;
  align-items: stretch;
}
.tq-shell .noteviewer-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.tq-shell .noteviewer-main-inner {
  display: flex;
  flex-direction: column;
}
/* Override the >=1280 themed reading-lane padding-bottom. theme-dark.css sets it
   at specificity (0,4,1); match that with a theme-qualified selector so source
   order (grader.css loads after theme-dark.css) wins in BOTH themes. */
html.theme-dark .nv-canvas.tq-shell .noteviewer-main-inner,
html.theme-light .nv-canvas.tq-shell .noteviewer-main-inner { padding-bottom: clamp(14px, 1.6vw, 20px); }
.tq-shell .fc-page-header,
.tq-shell .questions-mode-tabs { flex: 0 0 auto; }
.tq-shell .fc-page-header { margin-bottom: 16px; }
.tq-shell .questions-mode-tabs { margin-bottom: 16px; }

/* the ONLY scroll region — the question + grading results */
.tq-shell .noteviewer-body { overflow-x: clip; }
/* sticky-topbar offset so pager navigation (scrollIntoView) doesn't tuck the
   target question up under the sticky topbar */
.tq-shell .qg { scroll-margin-top: calc(var(--nv-topbar-h, 64px) + 16px); }
html:has(.tq-shell) { scroll-padding-top: calc(var(--nv-topbar-h, 64px) + 16px); }
.tq-shell .noteviewer-body::-webkit-scrollbar { width: 10px; }
.tq-shell .noteviewer-body::-webkit-scrollbar-thumb { background: var(--qg-card-border-hover, rgba(132, 182, 255, 0.3)); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
.tq-shell .noteviewer-body::-webkit-scrollbar-track { background: transparent; }

/* ══════════════════════════════════════════════════════════════════════════
   Fixed floating pager (mockup .bottom-nav)
   ----------------------------------------------------------------------------
   The pager floats over the page, docked between the left rail and the right
   edge, glass-blurred. OVERRIDES the prior sticky positioning. The windowed
   number list + [data-grade-state] dots are kept — just re-fit to the bar.
   Page-scoped via .tq-shell so only the questions surface is affected. ── */
.tq-shell .qg-pager {
  /* a clean ruled row at the bottom of the content (no glass box) — matches the
     sheet. Previous hugs the left, Next the right, numbers centred. Thin. */
  position: static;
  max-width: 720px;
  margin: clamp(22px, 3.5vw, 34px) auto 2px;
  border: 0;
  border-top: 1px solid var(--tq-line);
  border-radius: 0;
  background: none;
  box-shadow: none;
  padding: 14px 0 0;
  gap: 12px;
  justify-content: space-between;
}
/* drop the "Question N of M" + progress line — the numbers already show position */
.tq-shell .qg-pager-progress { display: none; }

/* The windowed number row only fits the capped bar on a roomy desktop; below
   that the rail squeezes the bar, so show just Previous / progress / Next and
   drop the numbers (no wrap, no overlap). Mobile already hides them too. */
@media (max-width: 1199px) {
  .tq-shell .qg-pager-nums { display: none; }
}

/* The pager is in flow now; just a little breathing room at the page bottom. */
html.theme-dark .nv-canvas.tq-shell .noteviewer-main-inner,
html.theme-light .nv-canvas.tq-shell .noteviewer-main-inner { padding-bottom: clamp(16px, 2vw, 24px); }

/* App-shell floating controls must clear the fixed pager. Every OTHER page puts
   the theme toggle bottom-right (24px) and the mobile Chapters trigger
   bottom-left; here those corners belong to the bar. The pager bottom edge is
   16px + ~82px ≈ 98px tall, so on desktop the toggle is lifted above it; on
   mobile both controls sit in the top band below the topbar. Page-scoped via
   :has(.tq-shell); specificity (0,2,1) beats the styles.css default. */
@media (max-width: 860px) {
  body:has(.tq-shell) .nv-rail-trigger { bottom: auto; top: calc(var(--nv-topbar-h, 64px) + 10px); }
  /* Two corner controls (Chapters pill top-left, theme toggle top-right) own the
     band below the topbar; drop the breadcrumb beneath them so it never sits
     under either — clears the HOME link the pill used to overlap. */
  body:has(.tq-shell) .note-breadcrumbs { margin-top: 56px; }
}

/* Mobile: numbers are already hidden ≤1199, so the empty centre is just the
   spacer that keeps Previous at the left and Next at the right. */
@media (max-width: 860px) {
  .tq-shell .qg-pager { gap: 10px; }
}
@media (max-width: 520px) {
  /* hide the number list on tiny screens so the in-flow bar stays short */
  .tq-shell .qg-pager-nums { display: none; }
}

/* ── Fit the idle question in one viewport (e.g. real 1920x1080 ~937px tall) so
   there is NO internal scroll there. Tighten the pinned header + pager + card
   spacing; the GRADED state still scrolls (safety net) as it adds a whole
   results card. Page-scoped via .tq-shell. ── */
.tq-shell .fc-page-header { margin-bottom: 10px; }
.tq-shell .fc-page-action-row { margin-top: 8px; padding-bottom: 8px; }
/* Section title is NOT demoted here — the questions header uses the standard
   centered, full-size .fc-page-h1, matching the flashcards/mcq/notes header. */
.tq-shell .questions-mode-tabs { margin-bottom: 10px; }
/* match theme-dark/-light (0,4,1) so source order wins */
html.theme-dark .nv-canvas.tq-shell .noteviewer-main-inner,
html.theme-light .nv-canvas.tq-shell .noteviewer-main-inner { padding-top: 16px; }
/* (single-viewport squeeze retired with the two-column stage; the textarea uses
   the mockup's 124px base + grows naturally inside the stage.) */

/* ── Topic-questions light mode (Phase 1.5) ───────────────────────────────────
   Reachable theme toggle in the header action row (the floating #ft-theme-toggle
   stays hidden here; one handler in theme-toggle.js binds this via
   [data-theme-toggle]). Reuses the themed .note-resource-back-btn ghost button
   so it themes correctly in both modes. ── */
/* Grade card: drop the inherited list-marker (.noteviewer-body ul > li::before)
   from the keypoint rows AND the loading-skeleton rows (flex rows, not lists). */
.tq-shell .tq-kp::before,
.tq-shell .tq-sk-row::before { content: none; }

/* Emphasised key terms in the AI feedback (rendered as <strong> via DOM, never innerHTML). */
.tq-feedback-band .tq-block-body strong { font-weight: 700; color: var(--qg-ink); }

/* Light-mode: soften the graded pager chips' dark border/inset shadow on the
   white surface (the opaque colour fill + dark ink already pass AA). */
html.theme-light .qg-pager-num[data-grade-state] { border-color: rgba(0, 0, 0, 0.12); box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.06); }
html.theme-light .qg-pager-num.is-current[data-grade-state] { box-shadow: 0 0 0 2px var(--qg-accent), inset 0 0 8px rgba(0, 0, 0, 0.06); }
