/* ============================================================
   Terry Academy — Base, layout & components
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-grad, none);   /* per-theme atmosphere layer */
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
h1,h2,h3,h4 { font-family: var(--font-display); line-height: var(--leading-tight); font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
.visually-hidden { position:absolute; width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration:.001ms!important; transition-duration:.001ms!important; scroll-behavior:auto!important; } }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.topbar {
  grid-column: 1 / -1; position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: var(--sp-2); font-weight: 800; letter-spacing: -.02em; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 800;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 4px 14px var(--ring);
}
.brand small { color: var(--text-mute); font-weight: 600; font-size: var(--text-xs); }
.topbar .spacer { flex: 1; }

.search { position: relative; flex: 0 1 340px; }
.search input {
  width: 100%; padding: 9px 14px 9px 36px; border-radius: var(--radius-full);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}
.search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-mute); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 60vh; overflow: auto; padding: var(--sp-2);
}
.search-results a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.search-results a:hover, .search-results a.active { background: var(--surface-2); }
.search-results .kind { font-size: var(--text-xs); color: var(--text-mute); }

.pill-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: var(--radius-full);
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; font-weight: 600; font-size: var(--text-sm);
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.pill-btn:hover { background: var(--bg-sunken); }
.pill-btn:active { transform: scale(.97); }
.streak { color: var(--rag-amber); }

.student-switch { position: relative; }
.student-switch .menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; min-width: 220px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: var(--sp-2); display: none;
}
.student-switch.open .menu { display: block; }
.student-switch .menu button { display: flex; width: 100%; align-items:center; gap: 10px; padding: 9px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; }
.student-switch .menu button:hover { background: var(--surface-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: var(--text-sm); background: var(--brand); }

/* ---------- Sidebar ---------- */
.sidebar { position: sticky; top: 58px; align-self: start; height: calc(100vh - 58px); overflow-y: auto; padding: var(--sp-4) var(--sp-3); border-right: 1px solid var(--border); background: var(--bg-elev); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text-soft); font-weight: 600; }
.nav a .ico { width: 20px; text-align: center; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.nav .group-label { padding: 14px 12px 6px; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--text-mute); }
.sidebar .tip { margin-top: var(--sp-5); padding: var(--sp-4); border-radius: var(--radius); background: var(--surface-2); font-size: var(--text-sm); color: var(--text-soft); border: 1px solid var(--border); }

/* ---------- Main ---------- */
.main { padding: var(--sp-6) clamp(var(--sp-4), 4vw, var(--sp-7)); max-width: var(--maxw); width: 100%; margin: 0 auto; min-width: 0; } /* min-width:0 so wide scrollable content (calendars, palettes) scrolls internally instead of stretching the page on mobile */
.view { animation: rise var(--dur) var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head > div { min-width: 0; }                 /* let the title/subtitle wrap instead of clipping on mobile */
.page-head h1 { overflow-wrap: break-word; }
.page-head p.sub { color: var(--text-mute); margin-top: 4px; }
.breadcrumbs { font-size: var(--text-sm); color: var(--text-mute); margin-bottom: var(--sp-3); }
.breadcrumbs a { color: var(--text-mute); }

/* ---------- Grid helpers ---------- */
.grid { display: grid; gap: var(--sp-4); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.between { justify-content: space-between; }

/* ---------- Dashboard ---------- */
/* Mobile-first: hero action spans full width and comes first; readiness + streak sit
   as a compact 2-up beneath it. Desktop promotes them onto one row beside a wider hero. */
.dash-top { display: grid; gap: var(--sp-4); grid-template-columns: 1fr 1fr; align-items: stretch; }
.dash-top .dash-hero { grid-column: 1 / -1; }
.dash-hero { background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 16%, var(--surface)), var(--surface)); display: flex; flex-direction: column; }
.dash-hero h2 { margin: 4px 0 0; }
.dash-hero .btn { margin-top: auto; min-height: 52px; }   /* anchored CTA + thumb-friendly target */
.tap-row { min-height: 44px; }                            /* WCAG 2.2 target size for plan/exam rows */
.dash-check { width: 20px; height: 20px; accent-color: var(--brand); flex: 0 0 auto; cursor: pointer; }
.pred-row { display: block; padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.pred-row:last-child { border-bottom: 0; }
.pred-row:hover { background: var(--surface-2); border-radius: var(--radius-sm); padding-left: var(--sp-2); padding-right: var(--sp-2); }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (min-width: 901px) {
  .dash-top { grid-template-columns: 1.5fr 1fr 1fr; }
  .dash-top .dash-hero { grid-column: auto; }
}

/* ---------- Card ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-5); box-shadow: var(--shadow); }
.card.tight { padding: var(--sp-4); }
.pathway-strip .pathway-ico { font-size: var(--text-xl); line-height: 1; }
.card.link { cursor: pointer; transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur); text-decoration: none; color: inherit; display: block; }
.card.link:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.card h3 { margin-bottom: var(--sp-2); }
.card .eyebrow { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--text-mute); font-weight: 700; margin-bottom: 6px; }
.accent-bar { height: 4px; border-radius: 4px; margin: -4px 0 var(--sp-3); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 700; cursor: pointer; transition: transform var(--dur) var(--ease), filter var(--dur), background var(--dur); }
.btn:hover { filter: brightness(1.03); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border-color: transparent; color: #fff; box-shadow: 0 6px 20px var(--ring); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 12px; font-size: var(--text-sm); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--rag-red); border-color: color-mix(in srgb, var(--rag-red) 40%, var(--border)); }
.btn.danger:hover { background: color-mix(in srgb, var(--rag-red) 12%, var(--surface)); filter: none; }
.btn.danger:disabled { color: var(--text-mute); border-color: var(--border); }

/* ---------- Badges & chips ---------- */
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 700; background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border); }
.tag.red { background: color-mix(in srgb, var(--rag-red) 16%, transparent); color: var(--rag-red); border-color: transparent; }
.tag.amber { background: color-mix(in srgb, var(--rag-amber) 18%, transparent); color: var(--amber-fg); border-color: transparent; }
.tag.green { background: color-mix(in srgb, var(--rag-green) 16%, transparent); color: var(--rag-green); border-color: transparent; }
.tag.brand { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand); border-color: transparent; }
/* Predicted-grade confidence dots — shown inside gradePill when evidence is low/medium */
.conf-dots { display: inline-flex; gap: 3px; align-items: center; margin-left: 5px; }
.conf-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .25; }
.conf-dot.on { opacity: .8; }
.chip { padding: 6px 12px; border-radius: var(--radius-full); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: var(--text-sm); font-weight: 600; }
.chip.on { background: var(--brand); color: #fff; border-color: transparent; }
.badge-medal { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: radial-gradient(circle at 30% 25%, #fff6, transparent 60%), var(--badge-grad); color:#fff; box-shadow: var(--shadow); }
.badge-medal.locked { background: var(--surface-2); color: var(--text-mute); filter: grayscale(1); box-shadow:none; }

/* ---------- Progress bar / ring ---------- */
.bar { height: 10px; border-radius: var(--radius-full); background: var(--bg-sunken); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--rank-grad); transition: width 600ms var(--ease); }
.bar.red > span { background: var(--rag-red); }
.bar.amber > span { background: var(--rag-amber); }
.bar.green > span { background: var(--rag-green); }
.metric { font-size: var(--text-3xl); font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.metric small { font-size: var(--text-sm); color: var(--text-mute); font-weight: 600; }

.ring { --p: 0; --size: 96px; --c: var(--brand); width: var(--size); height: var(--size); border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(closest-side, var(--surface) 78%, transparent 79% 100%), conic-gradient(var(--c) calc(var(--p)*1%), var(--bg-sunken) 0); }
.ring .val { font-weight: 800; font-size: var(--text-xl); }
.ring .lbl { font-size: var(--text-xs); color: var(--text-mute); }

/* ---------- Tables ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data th { color: var(--text-mute); font-weight: 700; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .05em; }
table.data tr:last-child td { border-bottom: 0; }

/* ---------- Heatmap & calendar ---------- */
.heatmap { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 4px; }
.heatmap .cell { width: 14px; height: 14px; border-radius: 3px; background: var(--bg-sunken); }
.heatmap .cell.l1 { background: color-mix(in srgb, var(--brand) 30%, var(--bg-sunken)); }
.heatmap .cell.l2 { background: color-mix(in srgb, var(--brand) 55%, var(--bg-sunken)); }
.heatmap .cell.l3 { background: color-mix(in srgb, var(--brand) 80%, var(--bg-sunken)); }
.heatmap .cell.l4 { background: var(--brand); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--sp-2); }
.cal .day { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px; min-height: 76px; font-size: var(--text-sm); }
.cal .day .dn { color: var(--text-mute); font-size: var(--text-xs); font-weight: 700; }
.cal .day.today { border-color: var(--brand); box-shadow: 0 0 0 2px var(--ring); }
.cal .day .item { margin-top: 4px; padding: 2px 6px; border-radius: 6px; font-size: var(--text-xs); font-weight: 600; color: #fff; }

/* ---------- Forms ---------- */
label.field { display: block; font-weight: 600; font-size: var(--text-sm); margin-bottom: 6px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
textarea { min-height: 160px; resize: vertical; line-height: 1.55; font-family: var(--font-sans); }
input[type=range] { width: 100%; accent-color: var(--brand); }

/* ---------- Quiz / question ---------- */
.q-opt { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 14px 16px; border-radius: var(--radius-sm); border: 1.5px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; transition: border-color var(--dur), background var(--dur), transform var(--dur); margin-bottom: 10px; }
.q-opt:hover { border-color: var(--border-strong); }
.q-opt .key { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: var(--surface-2); font-weight: 800; font-size: var(--text-sm); }
.q-opt.correct { border-color: var(--rag-green); background: color-mix(in srgb, var(--rag-green) 12%, var(--surface)); }
.q-opt.wrong { border-color: var(--rag-red); background: color-mix(in srgb, var(--rag-red) 12%, var(--surface)); }
.q-opt.correct .key { background: var(--rag-green); color: #fff; }
.q-opt.wrong .key { background: var(--rag-red); color: #fff; }
.q-progress { display: flex; gap: 5px; margin-bottom: var(--sp-4); }
.q-progress .dot { flex: 1; height: 6px; border-radius: 4px; background: var(--bg-sunken); }
.q-progress .dot.done { background: var(--brand); }
.q-progress .dot.cur { background: var(--brand-2); }
.feedback { border-radius: var(--radius); padding: var(--sp-4); margin-top: var(--sp-4); border: 1px solid var(--border); background: var(--surface-2); }
.feedback.good { border-left: 4px solid var(--rag-green); }
.feedback.bad { border-left: 4px solid var(--rag-red); }
.markscheme { border-left: 4px solid var(--brand); padding-left: var(--sp-4); }
.tariff { font-weight: 800; color: var(--brand); }

/* ---------- Terry chat ---------- */
.chat { display: flex; flex-direction: column; gap: var(--sp-3); padding-bottom: var(--sp-5); }
.msg { max-width: 78%; padding: 12px 16px; border-radius: 16px; line-height: 1.55; }
.msg.terry { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg.me { align-self: flex-end; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-bottom-right-radius: 5px; }
.msg .who { font-size: var(--text-xs); font-weight: 800; opacity: .75; margin-bottom: 3px; }
.chat-input { position: sticky; bottom: 0; display: flex; gap: 10px; padding-top: var(--sp-3); background: linear-gradient(transparent, var(--bg) 30%); }
.quick-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--sp-3); }

/* ---------- Exam mode ---------- */
body.exam-mode .sidebar, body.exam-mode .topbar .search, body.exam-mode .topbar .nav { display: none; }
/* sidebar is hidden, so collapse the grid to one column or main lands in the empty track */
body.exam-mode .app { grid-template-columns: 1fr; }
body.exam-mode .main { max-width: 1100px; }
body.exam-mode .main .grid { min-width: 0; }
body.exam-mode .main .grid > * { min-width: 0; }
.exam-timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: var(--text-xl); }
.exam-timer.warn { color: var(--rag-amber); }
.exam-timer.danger { color: var(--rag-red); }
.q-palette { display: flex; flex-wrap: wrap; gap: 6px; }
.q-palette button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; cursor: pointer; }
.q-palette button.answered { background: color-mix(in srgb, var(--rag-green) 22%, var(--surface)); border-color: var(--rag-green); }
.q-palette button.flagged { background: color-mix(in srgb, var(--rag-amber) 22%, var(--surface)); border-color: var(--rag-amber); }
.q-palette button.cur { outline: 2px solid var(--brand); }

/* ---------- Meet the Team (personas) ---------- */
.persona-emoji { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 24px; background: var(--surface-2); border: 1px solid var(--border); flex: 0 0 auto; }
.persona-card { transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease); }
.persona-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.team-flow { display: flex; align-items: stretch; gap: var(--sp-2); flex-wrap: wrap; }
.team-flow-step { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; }
.team-flow-arrow { display: grid; place-items: center; color: var(--text-mute); font-weight: 800; }

/* ---------- Misc ---------- */
.muted { color: var(--text-mute); }
.soft { color: var(--text-soft); }
.center { text-align: center; }
.divider { height: 1px; background: var(--border); margin: var(--sp-5) 0; }
.empty { text-align: center; padding: var(--sp-7); color: var(--text-mute); }
.empty .big { font-size: 40px; margin-bottom: var(--sp-3); }
.kpi { display:flex; flex-direction:column; gap:4px; }
.kpi.center { align-items: center; }   /* centre rings/tags/medals, not just text */
.note-prose p { margin-bottom: var(--sp-3); }
.note-prose ul, .note-prose ol { margin: 0 0 var(--sp-3) var(--sp-5); }
.note-prose li { margin-bottom: 6px; }
.note-prose strong { color: var(--text); }
.callout { border-radius: var(--radius); padding: var(--sp-4); border: 1px solid var(--border); }
.callout.tip { background: color-mix(in srgb, var(--info) 8%, var(--surface)); border-left: 4px solid var(--info); }
.callout.warn { background: color-mix(in srgb, var(--rag-amber) 8%, var(--surface)); border-left: 4px solid var(--rag-amber); }
.callout.g9 { background: color-mix(in srgb, var(--brand) 8%, var(--surface)); border-left: 4px solid var(--brand); }
/* The seeded sample student (REQ-ONBOARD-FIRST-RUN-01) — tokens only, so every theme reads it. */
.sample-banner { background: color-mix(in srgb, var(--rag-amber) 10%, var(--surface)); border-left: 4px solid var(--rag-amber); }
.sample-banner .btn { white-space: nowrap; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: var(--radius-full); box-shadow: var(--shadow-lg); z-index: 100; font-weight: 600; animation: rise var(--dur) var(--ease); }
.toplink { display:flex; align-items:center; gap:12px; }

/* ---------- Exam Technique Academy (Dojo) ---------- */
.dojo-medal { border-radius: 50%; border: 2px solid var(--border-strong); flex: 0 0 auto; box-shadow: inset 0 -3px 6px rgba(0,0,0,.18); }
.dojo-card { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--brand); border-radius: var(--radius-sm); padding: var(--sp-3); margin-top: var(--sp-3); }
.dojo-drill-ico { width: 34px; height: 34px; border-radius: var(--radius-sm); display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); font-size: 18px; flex: 0 0 auto; }
.dojo-badge { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; background: color-mix(in srgb, var(--brand) 14%, var(--surface)); border: 1px solid var(--border); }
.dojo-badge.locked { filter: grayscale(1); opacity: .4; }
.dojo-answer { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-3); margin-top: 8px; font-size: var(--text-sm); line-height: 1.6; }
.dojo-tree { display: flex; flex-wrap: wrap; gap: 8px; margin-top: var(--sp-3); }
.dojo-node { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: var(--radius-full); border: 1px solid var(--border); background: var(--surface-2); font-size: var(--text-sm); font-weight: 600; min-height: 40px; color: inherit; }
.dojo-node .dojo-node-ico { width: 16px; text-align: center; }
.dojo-node.mastered { border-color: var(--rag-green); background: color-mix(in srgb, var(--rag-green) 14%, var(--surface)); }
.dojo-node.progress { border-color: var(--rag-amber); background: color-mix(in srgb, var(--rag-amber) 12%, var(--surface)); }

/* ---------- Theme selector (Settings) ---------- */
.theme-grid { display: grid; gap: var(--sp-3); grid-template-columns: 1fr; margin-top: var(--sp-4); }
@media (min-width: 560px) { .theme-grid { grid-template-columns: 1fr 1fr; } }
.theme-card {
  display: flex; gap: var(--sp-3); align-items: stretch; text-align: left; width: 100%;
  padding: var(--sp-3); border: 1.5px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.theme-card:hover { border-color: var(--border-strong); }
.theme-card:active { transform: scale(.99); }
.theme-card.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--ring); }
.theme-card.locked { opacity: .55; cursor: not-allowed; }
.theme-card .theme-swatches { display: grid; grid-template-rows: repeat(4, 1fr); width: 16px; min-height: 56px; border-radius: 6px; overflow: hidden; flex: 0 0 auto; border: 1px solid var(--border); }
.theme-card .theme-swatches .sw { display: block; }
.theme-card .theme-meta { flex: 1; min-width: 0; }
.theme-card .theme-arche { display: flex; flex-wrap: wrap; gap: 6px; }
.theme-card .theme-arche .tag { font-size: var(--text-xs); }
.theme-card .theme-vocab { font-size: var(--text-xs); margin-top: 8px; overflow-wrap: anywhere; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .search { display: none; }
  .bottom-tabs { display: flex; }
  .main { padding-bottom: 84px; }
}
@media (min-width: 901px) { .bottom-tabs { display: none; } }
.bottom-tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; background: color-mix(in srgb, var(--bg-elev) 95%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--border); justify-content: space-around; padding: 8px env(safe-area-inset-right) calc(8px + env(safe-area-inset-bottom)) env(safe-area-inset-left); }
.bottom-tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; font-weight: 700; color: var(--text-mute); padding: 4px 10px; }
.bottom-tabs a.active { color: var(--brand); }
.bottom-tabs a .ico { font-size: 18px; }

/* ---------- Mobile action utilities (shared) ---------- */
/* Stack a row of buttons/chips into full-width, thumb-friendly controls on phones. */
@media (max-width: 600px) {
  .actions-stack { flex-direction: column; align-items: stretch; }
  .actions-stack > .btn, .actions-stack > .chip { width: 100%; }
}

/* ===== Practice (quiz) — mobile additions go directly below this line ===== */

/* --- Chooser: smart card lays copy above a full-width CTA --- */
.qz-smart { display: flex; flex-direction: column; gap: var(--sp-4); }
.qz-smart-title { font-size: var(--text-lg); }

/* Field grouping: label sits above its scrollable chip row */
.qz-field { margin-top: var(--sp-4); }
.qz-fieldlabel { display: block; font-size: var(--text-sm); font-weight: 700; color: var(--text-soft); margin-bottom: var(--sp-2); }
/* Keep chips on one horizontal scroll line; don't let .row wrap them */
.qz-chiprow { flex-wrap: nowrap; gap: var(--sp-2); padding-bottom: var(--sp-1); scroll-snap-type: x proximity; }
.qz-chiprow .qz-chip { scroll-snap-align: start; }
/* Thumb-friendly filter chips: >=44px tap target, never shrink in the scroller */
.qz-chip { min-height: 44px; display: inline-flex; align-items: center; flex: 0 0 auto; white-space: nowrap; }
.qz-summary { margin-top: var(--sp-4); }

/* --- Runner head: title block can shrink so the End button stays put --- */
.qz-runhead { align-items: flex-start; gap: var(--sp-3); }
.qz-runhead-copy { min-width: 0; }
.qz-end { flex: 0 0 auto; min-height: 44px; }

/* --- Progress --- */
.qz-progress-wrap { margin-bottom: var(--sp-4); }
.qz-progress-label { margin-bottom: var(--sp-2); }
.qz-progress-count { font-size: var(--text-sm); }
.qz-progress-sub { font-size: var(--text-sm); }
/* Dots variant (<=20 questions): a touch taller and rounder than the base .dot */
.qz-dots { margin-bottom: 0; }
.qz-dots .dot { height: 8px; transition: background var(--dur) var(--ease); }

/* --- Question card --- */
.qz-qmeta { flex-wrap: wrap; gap: var(--sp-2); }
.qz-qmeta-subj { min-width: 0; }
.qz-prompt { line-height: var(--leading-tight); overflow-wrap: break-word; }

/* --- Fill-in: input full width, Check button below (block) --- */
.qz-fill { display: flex; flex-direction: column; gap: var(--sp-3); }
.qz-fill-input { width: 100%; }
.qz-fill-ok { border-color: var(--rag-green) !important; }
.qz-fill-no { border-color: var(--rag-red) !important; }

/* --- Written feedback --- */
.qz-score-head { gap: var(--sp-3); }
/* Mark-scheme self-check: ~20px boxes, 44px rows so each toggle is tappable */
.qz-checklist { margin-top: var(--sp-2); }
.qz-check { display: flex; align-items: flex-start; gap: var(--sp-3); min-height: 44px; padding: var(--sp-1) 0; cursor: pointer; }
.qz-check-box { width: 20px; height: 20px; flex: 0 0 auto; margin-top: 2px; accent-color: var(--brand); cursor: pointer; }
.qz-check-label { line-height: var(--leading); }

/* --- Faded worked examples (completion effect) --- */
.qz-faded { margin-top: var(--sp-3); border-top: 1px dashed var(--border); padding-top: var(--sp-3); }
.qz-faded-worked { background: color-mix(in srgb, var(--brand) 6%, var(--surface)); border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-3); }
.qz-faded-cap { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; margin-bottom: 6px; }
.qz-faded-gap { margin-top: var(--sp-3); }
.qz-faded-stem { line-height: var(--leading); margin-bottom: 6px; }
.qz-faded-input { width: 100%; }
.qz-faded-model { margin-top: 6px; padding: var(--sp-2) var(--sp-3); border-left: 3px solid var(--brand); background: var(--surface-2); border-radius: 8px; line-height: var(--leading); }
.qz-faded-tick.ok { color: var(--rag-green); font-weight: 700; }
.qz-faded-tick.no { color: var(--text-mute); font-weight: 700; }
.qz-faded-fb { margin-top: var(--sp-2); font-size: var(--text-sm); }

/* --- Model-answer viewer (grade 4–9 switcher) — token-driven, themes for free --- */
.mv-title { margin-bottom: var(--sp-2); }
.mv-grades { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--sp-2); }
.mv-grade {
  padding: 6px 12px; border-radius: var(--radius-full); border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: var(--text-sm); font-weight: 700;
  color: var(--text); min-height: 36px; line-height: 1; transition: background .12s, border-color .12s;
}
.mv-grade:hover { border-color: var(--brand); }
.mv-grade.on { background: var(--brand); color: #fff; border-color: transparent; }
.mv-grade:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.mv-note { font-size: var(--text-xs); margin: 0 0 var(--sp-2); }
.mv-body { white-space: pre-wrap; }
.mv-details { margin-top: var(--sp-3); }
@media (max-width: 600px) {
  .mv-grade { flex: 1 0 auto; text-align: center; min-height: 44px; }
}

/* --- Shared reading passage (KS2 booklet panel) — token-driven, themes for free --- */
.reading-passage { margin-bottom: var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); background: color-mix(in srgb, var(--brand) 4%, var(--surface)); }
.reading-passage-head { cursor: pointer; font-weight: 700; padding: var(--sp-3) var(--sp-4); }
.reading-passage-body { max-height: 46vh; overflow: auto; padding: var(--sp-2) var(--sp-4) var(--sp-3); line-height: var(--leading); }
.reading-passage-body p { margin: 0 0 var(--sp-3); }
.reading-passage-body p:last-child { margin-bottom: 0; }
.reading-passage-body.poem p { padding-left: var(--sp-2); }
/* Subheadings inside a non-fiction reading text (authored as **Heading** — see readingPassage). */
.reading-subhead { margin: var(--sp-4) 0 var(--sp-2); font-size: .95rem; font-weight: 700; color: var(--fg); }
.reading-subhead:first-child { margin-top: 0; }

/* Two-pane reading on wide screens: passage pinned (sticky) beside the question.
   Below 901px it collapses to a single column (passage stacked above the question).
   minmax(0,1fr) + min-width:0 let the columns shrink so long text wraps (no clipping). */
.reading-2pane { display: grid; gap: var(--sp-4); grid-template-columns: minmax(0, 1fr); }
.reading-2pane > * { min-width: 0; }
@media (min-width: 901px) {
  .reading-2pane { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; }
  .reading-2pane > .reading-passage { position: sticky; top: 140px; align-self: start; margin-bottom: 0; }
  .reading-2pane > .reading-passage .reading-passage-body { max-height: calc(100vh - 210px); }
}

/* --- Mobile (<=600px) thumb-zone tuning --- */
@media (max-width: 600px) {
  /* Large-session progress text wraps onto its own line, drop the right-hand caption */
  .qz-progress-sub { display: none; }
  /* True/false: two big side-by-side targets read fine; ensure they're tall enough */
  .qz-tf-opt { min-height: 48px; }
  /* Summary buttons stack full-width and centre cleanly */
  .qz-summary-actions { align-items: stretch; }
}

/* ===== Topic page — mobile additions go directly below this line ===== */
/* Maya pass: mobile-first (390px) layout, single-row scrollable sub-nav,
   thumb-friendly CTAs, comfortable reading. All .tp- prefixed; tokens only. */

/* Header */
.tp-head-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.tp-head-title { min-width: 0; flex: 1 1 auto; }       /* let long titles wrap, not clip */
.tp-title { margin: 0; overflow-wrap: break-word; }
.tp-meta { margin: var(--sp-1) 0 0; font-size: var(--text-sm); }
.tp-status { flex: 0 0 auto; }                          /* RAG tag never squashed */
.tp-mastery { margin-top: var(--sp-4); }
.tp-actions { margin-top: var(--sp-4); }

/* Sub-nav — single horizontally scrollable row (no wrap) on mobile */
.tp-subnav { margin: 0; }
.tp-subnav-track {
  display: flex; flex-wrap: nowrap; gap: var(--sp-2);
  padding: var(--sp-1) 0;
  scroll-snap-type: x proximity;
  scrollbar-width: none;                                /* Firefox */
}
.tp-subnav-track::-webkit-scrollbar { display: none; } /* WebKit */
.tp-subnav-link {
  flex: 0 0 auto; white-space: nowrap;
  display: inline-flex; align-items: center;
  min-height: 44px;                                     /* WCAG 2.2 target size */
  scroll-snap-align: start;
}
.tp-subnav-link:hover { background: var(--surface-2); text-decoration: none; }

/* Sticky only on desktop, where the topbar is a stable ~58px line */
@media (min-width: 901px) {
  .tp-subnav {
    position: sticky; top: 58px; z-index: 20;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(8px);
    margin: calc(var(--sp-2) * -1) calc(var(--sp-1) * -1);
    padding: var(--sp-2) var(--sp-1);
    border-radius: var(--radius-sm);
  }
  .tp-subnav-track { padding: 0; }
}

/* Sections — give anchored sections clearance from the desktop sticky bar */
@media (min-width: 901px) { .tp-section { scroll-margin-top: 116px; } }
@media (max-width: 900px) { .tp-section { scroll-margin-top: var(--sp-4); } }
.tp-h2 { margin: 0; }
.tp-prose { margin-top: var(--sp-3); }
/* Callout sections: tighten heading-to-list gap */
.callout.tp-section .tp-h2 { margin-bottom: var(--sp-2); }

/* Concepts — definition list reads as comfortable stacked rows on mobile */
.tp-concepts { margin-top: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-3); }
.tp-concept { padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border); }
.tp-concept:last-child { padding-bottom: 0; border-bottom: 0; }
.tp-concept-term { font-weight: 800; }
.tp-concept-def { margin: var(--sp-1) 0 0; color: var(--text-soft); line-height: var(--leading); }

/* Worked examples — comfortable indents and step spacing at 390px */
.tp-worked { margin-top: var(--sp-4); }
.tp-worked:first-of-type { margin-top: var(--sp-3); }
.tp-worked-q { font-weight: 700; margin-bottom: var(--sp-2); }
.tp-worked-steps { margin: 0 0 var(--sp-3); padding-left: var(--sp-5); }
.tp-worked-steps li { margin-bottom: var(--sp-2); line-height: var(--leading); }
.tp-worked-ans { display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--sp-1); }

/* Content lists (mistakes / insights / tips) — readable indent on mobile */
.tp-list { margin-top: var(--sp-3); padding-left: var(--sp-5); }
.tp-list li { margin-bottom: var(--sp-2); line-height: var(--leading); }

/* Footer CTA — full-width, thumb-friendly */
.tp-footer-copy { margin: 0 0 var(--sp-3); }
.tp-footer-cta { min-height: 52px; }

/* Phone refinements (≤600px) */
@media (max-width: 600px) {
  .tp-head-top { flex-wrap: nowrap; }                  /* keep title + status on one line */
  .tp-worked-steps, .tp-list { padding-left: var(--sp-4); }
}

/* ===== Subject hub — mobile additions go directly below this line ===== */
/* Maya pass: mobile-first (390px) subject LIST + OVERVIEW. All .sub- prefixed;
   tokens only. Responsive exam-structure (table → stacked cards), thumb-friendly
   stacked hero CTAs, overflow-safe card internals at 390px. */

/* --- Subject LIST cards: let flex children shrink so nothing overflows --- */
.sub-card-head { gap: var(--sp-3); align-items: flex-start; }
.sub-card-id { min-width: 0; flex: 1 1 auto; }          /* badge + name block can shrink */
.sub-card-name { min-width: 0; }                        /* name/board wrap, never clip */
.sub-card-name h3 { overflow-wrap: break-word; }
.sub-card-head > .tag { flex: 0 0 auto; }               /* grade pill keeps its size */
.sub-card-foot { gap: var(--sp-2); }
.sub-card-foot .tag { flex: 0 1 auto; }

/* --- Subject OVERVIEW hero: badge+title block, then ring+predicted block --- */
.sub-hero-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; gap: var(--sp-4);
}
.sub-hero-id { min-width: 0; flex: 1 1 auto; }          /* title block shrinks before stats */
.sub-hero-title { min-width: 0; }
.sub-hero-title h1 { overflow-wrap: break-word; }
.sub-hero-stats { flex: 0 0 auto; }                     /* ring + predicted stay together */

/* --- Responsive exam structure: table on desktop, stacked cards on phone --- */
.sub-struct-list { display: none; list-style: none; padding: 0; margin: 0; }
@media (max-width: 600px) {
  .sub-struct-table { display: none; }                  /* 4-col table squeezes at 390px */
  .sub-struct-list { display: flex; flex-direction: column; gap: var(--sp-3); }
}
.sub-paper {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: var(--sp-3);
}
.sub-paper-head {
  display: flex; align-items: baseline; flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-2); margin-bottom: var(--sp-2);
}
.sub-paper-name { font-weight: 800; }
.sub-paper-focus { font-size: var(--text-sm); }
.sub-paper-meta { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* --- Topic cards: title can shrink/wrap beside the RAG tag --- */
.sub-topic-head { gap: var(--sp-2); align-items: flex-start; }
.sub-topic-name { min-width: 0; flex: 1 1 auto; overflow-wrap: break-word; }
.sub-topic-head > .tag { flex: 0 0 auto; }

/* --- Phone refinements (≤600px) --- */
@media (max-width: 600px) {
  /* Hero stats span the full width and sit left-aligned beneath the title */
  .sub-hero-stats { width: 100%; }
}

/* ===== Revision — mobile additions go directly below this line ===== */
/* Maya pass: mobile-first (390px) layout. Calendar becomes a swipeable row of
   legible day cards on phones (desktop keeps the 7-col grid); plan rows, chips,
   CTAs and slider are all thumb-friendly; heatmap can't force page overflow.
   All .rev- prefixed; tokens only; never edits the shared .cal/.heatmap/.chip base. */

/* --- Controls --- */
/* Plan-type chips: >=44px tap target, no sub-44px wrapping rows */
.rev-chiprow { gap: var(--sp-2); }
.rev-chip { min-height: 44px; display: inline-flex; align-items: center; }
/* Minutes slider field: comfortable label + a taller, easier-to-drag track on touch */
.rev-mins { min-width: 0; }
.rev-mins-label { display: flex; align-items: baseline; gap: var(--sp-1); flex-wrap: wrap; }
.rev-range { height: 44px; }   /* taller hit area for the thumb on touch */
/* Generate-plan button: thumb-friendly height; goes full-width on phones */
.rev-generate { min-height: 48px; }

/* --- Today's checklist --- */
.rev-today-head { gap: var(--sp-3); flex-wrap: wrap; }
.rev-today-title { min-width: 0; }
/* Plan rows: ~20px checkbox in a >=44px tap row (WCAG 2.2 target size) */
.rev-tasks { gap: var(--sp-2); }
.rev-task { min-height: 44px; gap: var(--sp-3); cursor: pointer; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); background: var(--surface-2); }
.rev-task:hover { background: var(--bg-sunken); }
.rev-task-check { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--brand); cursor: pointer; }
.rev-task-label { flex: 1; min-width: 0; overflow-wrap: break-word; }
.rev-task-mins { flex: 0 0 auto; }
/* Primary next action: full-width, thumb-friendly recall CTA */
.rev-recall { min-height: 48px; margin-top: var(--sp-4); }

/* --- Weekly calendar --- */
/* Desktop keeps the shared 7-col .cal grid. On phones, .rev-cal turns the week
   into a horizontal-scroll row of fixed-width day cards you swipe across. */
@media (max-width: 900px) {
  .rev-cal {
    display: flex; flex-wrap: nowrap; gap: var(--sp-2);
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: var(--sp-2);                 /* room for the scrollbar */
    margin: var(--sp-3) calc(var(--sp-5) * -1) 0; /* bleed to card edges so cards can scroll off */
    padding-left: var(--sp-5); padding-right: var(--sp-5);
  }
  .rev-cal .day {
    flex: 0 0 auto; width: 8.5rem; scroll-snap-align: start;
    min-height: auto;
  }
  .rev-cal .day .item { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
/* Empty-day hint inside a calendar cell (not colour-only) */
.rev-cal-empty { margin-top: var(--sp-1); color: var(--text-mute); font-size: var(--text-xs); }

/* --- Heatmap --- */
/* Wrap the heatmap so a long 12-week grid scrolls instead of forcing page overflow */
.rev-heatmap-scroll { padding-bottom: var(--sp-1); }

/* --- Phone refinements (<=600px) --- */
@media (max-width: 600px) {
  /* Plan-type chip row scrolls on one line rather than wrapping into stubby chips */
  .rev-chiprow { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--sp-1); scroll-snap-type: x proximity; }
  .rev-chiprow .rev-chip { flex: 0 0 auto; white-space: nowrap; scroll-snap-align: start; }
}

/* ===== Exam simulator — mobile additions go directly below this line ===== */
/* Maya pass: mobile-first (390px). Question stacks full-width above a
   horizontal-scroll palette strip; desktop (>=901px) restores the side rail.
   All .ex- prefixed; tokens only; never colour-only signalling. */

/* --- Top bar: subject block + timer + submit wrap cleanly, stay sticky --- */
.ex-bar { flex-wrap: wrap; gap: var(--sp-3) var(--sp-4); }
.ex-bar-id { min-width: 0; flex: 1 1 auto; }            /* subject/marks block can shrink */
.ex-bar-id strong { overflow-wrap: break-word; }
.ex-bar-timer { flex: 0 0 auto; margin-left: auto; }    /* timer + submit hug the right, never wrap off-screen */
.ex-submit { flex: 0 0 auto; min-height: 44px; }

/* --- Layout: single column on mobile (question first), side rail on desktop --- */
.ex-layout { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; align-items: start; }
.ex-main { min-width: 0; order: 1; }                     /* question first on mobile; prevent overflow crush */
.ex-side { min-width: 0; order: 2; }                     /* palette below the question on mobile */

/* --- Palette: horizontal-scroll strip on mobile --- */
.ex-palette-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.ex-palette-head h2 { font-size: var(--text-lg); margin: 0; }
.ex-palette { flex-wrap: nowrap; padding-bottom: var(--sp-1); scroll-snap-type: x proximity; }
.ex-palette button { flex: 0 0 auto; width: 44px; height: 44px; scroll-snap-align: start; position: relative; }
/* Non-colour-only state: answered = check glyph, flagged = corner flag glyph */
.ex-palette button.answered::after {
  content: "✓"; position: absolute; top: 1px; right: 3px;
  font-size: 11px; line-height: 1; font-weight: 800; color: var(--rag-green);
}
.ex-palette button.flagged::before {
  content: "⚑"; position: absolute; bottom: 0; left: 3px;
  font-size: 11px; line-height: 1; color: var(--rag-amber);
}
.ex-palette-key { font-size: var(--text-xs); margin-top: var(--sp-3); }
.ex-palette-key .ex-k { display: inline-flex; align-items: center; gap: 4px; margin-right: var(--sp-3); white-space: nowrap; }

/* --- Question card meta + prompt wrap at 390px --- */
.ex-qhead { flex-wrap: wrap; gap: var(--sp-2); }
.ex-qmeta { min-width: 0; }
.ex-qtools { flex: 0 0 auto; }
.ex-flag { min-height: 44px; }
.ex-prompt { overflow-wrap: break-word; }

/* --- Fill input full-width on mobile (was inline maxWidth:360px) --- */
.ex-fill { width: 100%; max-width: 420px; }

/* --- Question nav: thumb-friendly, two-up that fills the row --- */
.ex-nav { gap: var(--sp-3); margin-top: var(--sp-4); }
.ex-nav .btn { min-height: 44px; flex: 1 1 0; }

/* --- Result: boundary table scrolls horizontally if cramped --- */
.ex-boundary-scroll { margin-top: var(--sp-2); }
.ex-boundary-scroll table.data { min-width: 320px; }

/* --- Phone refinements (<=600px) --- */
@media (max-width: 600px) {
  .ex-bar-id strong { font-size: var(--text-base); }
}

/* --- Desktop (>=901px): restore side rail, sticky palette, no scroll strip --- */
@media (min-width: 901px) {
  .ex-layout { grid-template-columns: 1fr 220px; }
  .ex-side { order: 0; position: sticky; top: 140px; }
  .ex-main { order: 0; }
  .ex-palette { flex-wrap: wrap; padding-bottom: 0; }
  .ex-palette button { width: 36px; height: 36px; }
}

/* ===== Parent Portal — mobile additions go directly below this line ===== */

/* --- Print action: a comfortable >=44px tap target; full width on phones --- */
.par-print-btn { min-height: 44px; }
@media (max-width: 600px) {
  /* pageHead actions sit in a .row; let the single action span the width
     so the print target is unmistakable and easy to hit one-handed. */
  .page-head .row { width: 100%; }
  .par-print-btn { width: 100%; }
}

/* --- Headline: keep the "x% ready" tag from crowding the status copy --- */
.par-headline > div:first-child { min-width: 0; }     /* let the sentence wrap, not clip */
.par-headline > .tag { flex: 0 0 auto; align-self: flex-start; }

/* --- "How each subject is looking" rows ---
   Give each subject card room to breathe and let the two halves
   (badge+name / grade+verdict) wrap as whole blocks at narrow widths. */
.par-subject-top { gap: var(--sp-3) var(--sp-4); align-items: flex-start; }
.par-subject-head { gap: var(--sp-3); min-width: 0; flex: 1 1 auto; }
.par-subject-name { min-width: 0; }                   /* allow long subject names to wrap */
.par-subject-name strong { overflow-wrap: break-word; }
.par-subject-status { gap: var(--sp-2); flex: 0 0 auto; }
.par-subject-status .tag { flex: 0 0 auto; }
.par-subject-bar { margin-top: var(--sp-3); }

/* Phone: stack the status block under the name with a clear tap gap so the
   grade pill + verdict never crush against the subject name at 390px. */
@media (max-width: 480px) {
  .par-subject-top { flex-direction: column; align-items: stretch; gap: var(--sp-2); }
  .par-subject-status { flex-wrap: wrap; }
}

/* --- Lists (Strengths / Where to focus / At home): readable indent + rhythm ---
   Scoped as .note-prose.par-list to match .note-prose ul specificity (0,2,0)
   and win by source order, so the responsive indent actually applies. */
.note-prose.par-list { margin-left: var(--sp-5); }
.note-prose.par-list li { line-height: var(--leading); }
@media (max-width: 480px) {
  .note-prose.par-list { margin-left: var(--sp-4); }  /* pull bullets in so wrapped text isn't cramped */
}

/* ===== Reports — mobile additions go directly below this line ===== */
/* All rules token-only + .rep- prefixed; theme-driven so they shine in every theme. */

/* Tab + range chips: thumb-friendly (≥44px) and a clean wrap row.
   The base .chip is unchanged elsewhere. */
.rep-chiprow { gap: var(--sp-2); flex-wrap: wrap; }
.rep-chip { min-height: 44px; display: inline-flex; align-items: center; padding-block: 0; padding-inline: var(--sp-4); }

/* KPI stat cards: 2-up (2×2) on mobile so they stay glanceable; desktop keeps 4-up.
   Overrides the shared @900px `.grid.cols-4 → 1fr` collapse, scoped to reports only. */
@media (max-width: 900px) {
  .rep-kpis.grid.cols-4 { grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
}

/* "By subject": table on desktop, stacked per-subject card list on mobile. */
.rep-subj-list { display: none; }
@media (max-width: 600px) {
  .rep-subj-table { display: none; }
  .rep-subj-list { display: flex; flex-direction: column; gap: var(--sp-3); margin-top: var(--sp-3); }
  .rep-subj-card {
    display: flex; flex-direction: column; gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--surface-2);
    color: inherit; text-decoration: none;
  }
  .rep-subj-card:hover { border-color: var(--border-strong); }
  .rep-subj-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
  .rep-subj-top > .tag { flex: 0 0 auto; }                 /* predicted-grade pill keeps its size */
  .rep-subj-name { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
}

/* Tutor priority actions: give the inline links real tap targets (buttons, ≥44px). */
.rep-actions li { margin-bottom: var(--sp-3); }
.rep-actions li:last-child { margin-bottom: 0; }
.rep-action-text { margin-bottom: var(--sp-2); }
.rep-action-links { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.rep-action-links .btn { min-height: 44px; display: inline-flex; align-items: center; }
@media (max-width: 600px) {
  .rep-action-links { gap: var(--sp-3); }
  .rep-action-links .btn { flex: 1 1 0; justify-content: center; }
}

/* ===== Terry chat — mobile additions go directly below this line ===== */
/* Maya pass: mobile-first (390px) + theme-polish. Composer floats clearly above
   the fixed .bottom-tabs on phones; thumb-friendly input + Send; comfortable
   quick-chips; premium Terry voice in every theme. All .tc- prefixed; tokens
   only; never edits the shared .chat / .msg / .chat-input / .bottom-tabs base. */

/* --- View fills the viewport so the chat history pushes the composer down --- */
.tc-view { min-height: calc(100dvh - 120px); }

/* --- Chat history: flex-grow so it owns the vertical space --- */
.tc-chat { flex: 1; }

/* --- Quick chips: comfortable >=44px tap targets on one scrollable line --- */
.tc-chips {
  flex-wrap: nowrap;
  gap: var(--sp-2);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  padding-bottom: var(--sp-1);
  margin-bottom: var(--sp-3);
  scrollbar-width: none;                          /* Firefox */
}
.tc-chips::-webkit-scrollbar { display: none; }   /* WebKit */
.tc-chip {
  flex: 0 0 auto; white-space: nowrap;
  min-height: 44px; display: inline-flex; align-items: center;
  scroll-snap-align: start;
}

/* --- Composer: layered on the shared .chat-input (sticky bottom:0) --- */
/* Premium input dock; the fade band is theme-driven via --bg. */
.tc-composer {
  gap: var(--sp-2);
  align-items: flex-end;
  background: linear-gradient(transparent, var(--bg) 45%);
}
.tc-field { flex: 1; min-width: 0; }
.tc-input {
  width: 100%; min-height: 48px;
  border-radius: var(--radius-full);
  padding: 12px 18px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.tc-input::placeholder { color: var(--text-mute); }
/* On-brand focus cue (the global :focus-visible ring still applies for keyboard) */
.tc-composer:focus-within .tc-input { border-color: var(--brand); }
/* Send: thumb-friendly pill, icon + label, never crowds the input */
.tc-send {
  flex: 0 0 auto;
  min-height: 48px; min-width: 48px;
  border-radius: var(--radius-full);
  padding: 0 var(--sp-5);
}
.tc-send .tc-send-ico { font-size: 1.05em; line-height: 1; }

/* --- In-message action buttons: ensure a tappable row --- */
.tc-actions { gap: var(--sp-2); margin-top: var(--sp-3); }
.tc-actions .btn.sm { min-height: 40px; }

/* --- Mobile (<=900px): float the composer ABOVE the fixed bottom tab bar --- */
/* THE BIG BUG fix: .chat-input is sticky bottom:0, so it sits UNDER .bottom-tabs.
   Lift it by the tab-bar height (icon+label+padding ~64px) + the safe area, and
   pad the chat so the floating composer never covers the last message. */
@media (max-width: 900px) {
  .tc-composer {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    padding-bottom: var(--sp-3);
    background: linear-gradient(transparent, var(--bg) 35%);
  }
  .tc-chat { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
}

/* --- Phone refinements (<=600px) --- */
@media (max-width: 600px) {
  /* Tighten Send so it never crowds the field, while staying a clear target */
  .tc-send { padding: 0 var(--sp-4); }
}

@media print {
  .topbar, .sidebar, .bottom-tabs, .btn, .no-print { display: none !important; }
  .app { display: block; }
  .main { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  body { background: #fff; }
}
@media (max-width: 600px) { :root { --text-3xl: 1.9rem; } .msg { max-width: 90%; } }

/* ============================================================
   Student avatar (views/avatar.js) — an animal in a karate gi.
   Pure SVG, so it scales crisply and inherits nothing that could clip it.
   ============================================================ */
.tav { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; line-height: 0; }
.tav-svg { display: block; overflow: visible; }
.av-preview { width: 76px; flex: 0 0 auto; }
.av-sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border); display: inline-block; margin-right: 6px; vertical-align: -1px; }
.av-editor .qz-field { margin-top: var(--sp-2); }

/* Dashboard greeting row: avatar + title. Stacks naturally on narrow screens. */
.dash-greet { display: flex; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-2); }
.dash-greet h1 { line-height: var(--leading-tight); }
@media (max-width: 420px) { .dash-greet { gap: var(--sp-3); } .dash-greet .tav { width: 56px !important; height: 65px !important; } }
/* Identity card (REQ-HUB-IDENTITY-CARD-01): avatar + greeting + the level row, first on the page. */
.dash-id .dash-greet { margin-bottom: 0; }
/* Avatars off: the initial circle must not flex-shrink into an oval on a narrow phone. */
.dash-id .dash-greet .avatar { flex: 0 0 auto; }
@media (max-width: 420px) { .dash-id .dash-greet .avatar { width: 56px !important; height: 56px !important; font-size: 24px !important; } }
.dash-level { margin-top: var(--sp-3); }
.dash-level-title { font-family: var(--font-display); font-weight: 800; font-size: var(--text-lg); margin: 0 0 var(--sp-2); }

/* ============================================================
   Arcade (views/arcade.js) — earned play.
   ============================================================ */
.arcade-balance { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); }
@media (min-width: 640px) { .arcade-balance { grid-template-columns: 1.2fr 1fr; align-items: center; } }
.arcade-balance-main { display: flex; align-items: center; gap: var(--sp-4); min-width: 0; }
.arcade-tokens { font-family: var(--font-display); font-size: var(--text-3xl); font-weight: 800; line-height: 1; }
.arcade-token-n { color: var(--brand); }
.arcade-next { min-width: 0; }

.arcade-game { display: flex; flex-direction: column; }
.arcade-game-art { font-size: 44px; line-height: 1; margin-bottom: var(--sp-2); }
.arcade-soon { opacity: .6; }
.arcade-rule { gap: var(--sp-3); padding: var(--sp-2) 0; border-bottom: 1px solid var(--border); }
.arcade-rule:last-child { border-bottom: 0; }

.dash-arcade-live { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }

/* ============================================================
   Terry Invaders (games/invaders.js)
   ============================================================ */
.arcade-stage { padding: var(--sp-3); }
.inv-stage { display: flex; justify-content: center; }
.inv-canvas { display: block; max-width: 420px; width: 100%; border-radius: var(--radius-sm); background: var(--bg); touch-action: none; outline: none; }
.inv-canvas:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.inv-hud { display: flex; gap: var(--sp-4); align-items: center; flex-wrap: wrap; font-family: var(--font-mono); font-size: var(--text-sm); margin-bottom: var(--sp-2); }
.inv-hud-k { color: var(--text-mute); font-size: var(--text-xs); letter-spacing: .08em; }
.inv-lives { margin-left: auto; letter-spacing: 2px; }
.inv-pad { display: flex; gap: var(--sp-2); margin-top: var(--sp-3); }
.inv-btn {
  flex: 1; min-height: 56px; font-size: var(--text-lg); font-weight: 700;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2);
  color: var(--text); cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.inv-btn:active { background: var(--brand); color: #fff; }
.inv-fire { flex: 1.6; }
.inv-hint { font-size: var(--text-xs); margin: var(--sp-2) 0 0; text-align: center; }
/* The touch pad is only useful without a keyboard — keep it, but quieter on desktop. */
@media (hover: hover) and (pointer: fine) { .inv-pad { opacity: .55; } .inv-pad:hover { opacity: 1; } }

/* ============================================================
   Fluency Mode (views/fluency.js)
   Timed rapid-recall. Big, calm type; the countdown is a bar, never a
   flashing number — pressure should motivate, not panic.
   ============================================================ */
.fl-timercard { padding: var(--sp-3) var(--sp-4); }
.fl-timers { gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-2); }
.fl-timer.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.fl-deck { display: flex; flex-direction: column; }
.fl-deck-icon { font-size: var(--text-xl); }
.fl-deck-meta { flex-wrap: wrap; }
.fl-official { white-space: nowrap; }
.fl-best { font-size: var(--text-sm); }
.fl-skill + .fl-skill { margin-top: var(--sp-2); }
.fl-hist { padding: 4px 0; border-bottom: 1px solid var(--border); }
.fl-hist:last-child { border-bottom: 0; }

.fl-progress { margin-bottom: var(--sp-3); }
.fl-timer-text { font-variant-numeric: tabular-nums; }
/* The last third of the countdown goes amber — a warning, not an alarm. */
.fl-progress .bar.fl-urgent > span { background: var(--rag-amber); }
.fl-card { text-align: center; }
.fl-prompt {
  font-size: clamp(var(--text-2xl), 7vw, 40px); font-weight: 700;
  margin: var(--sp-2) 0 var(--sp-4); line-height: 1.25;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.fl-fill { max-width: 420px; margin: 0 auto; }
.fl-input { font-size: var(--text-xl); text-align: center; font-variant-numeric: tabular-nums; }
/* Locked-answer state (fast-entry fix, 2026-09-01): the input stays focused and enabled through the
   feedback beat — never `disabled`, which would force a browser blur and defeat the whole point of
   keeping the keyboard open for the rest of the sprint. A dead caret is the "paused, not broken" cue;
   `cursor:default` (not not-allowed, which reads punitive to a child) plus the RAG border below plus
   the adjacent feedback text are three simultaneous channels, so nothing here relies on colour alone. */
.fl-input.locked { caret-color: transparent; cursor: default; }
.fl-opts { display: grid; gap: var(--sp-2); max-width: 480px; margin: 0 auto; text-align: left; }
.fl-fb { margin-top: var(--sp-3); text-align: left; min-height: 64px; }
/* Prompt swap (fast-entry fix): the same <h2> node is reused for every question now, so a fast-typing
   child glancing at their fingers gets no cue the prompt changed unless something draws the eye — an
   opacity-only fade (repaint, not reflow) rather than silence. Retriggered via a forced reflow in
   drawQ(); see the mobile-nav sheet gotcha this mirrors (CLAUDE.md, 2026-08-08). */
@keyframes fl-prompt-in { from { opacity: .35; } to { opacity: 1; } }
.fl-prompt.fl-prompt-in { animation: fl-prompt-in var(--dur) var(--ease); }
.fl-stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.fl-wrong {
  font-size: var(--text-sm); padding: 6px 0; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: var(--sp-3); overflow-wrap: anywhere;
}
.fl-wrong:last-child { border-bottom: 0; }
.fl-wrong strong { color: var(--rag-green); white-space: nowrap; }

@media (max-width: 560px) {
  .fl-head h1 { font-size: var(--text-xl); }
  /* The keyboard now stays open for the WHOLE sprint (fast-entry fix), not a per-question flicker —
     so the visible viewport above it is a steady-state constraint, not a brief one. Trimming the
     prompt font and reserving .fl-fb's height keep the card's total height stable across questions,
     so the one scroll-into-view the browser does on first focus stays valid at question 25, not just
     question 1 — there is no second focus() call left to trigger a re-correction. */
  .fl-prompt { margin: var(--sp-2) 0 var(--sp-3); font-size: clamp(var(--text-xl), 6vw, 32px); }
  .fl-fb { min-height: 56px; }
}
/* Auto-advance is a transition, not an animation — but respect the preference anyway. */
@media (prefers-reduced-motion: reduce) {
  .fl-progress .bar > span { transition: none; }
  .fl-prompt.fl-prompt-in { animation: none; }
}

/* ---------- Mastery Heatmap (requirements/2026-07-16-mastery-heatmap.md) ---------- */
/* Tokens-only: every colour derives from --rag-* / --surface-* / --border, so all 6
   themes plus Legacy light/dark re-skin this for free and nothing is hardcoded.
   The band colour is deliberately a TINTED SURFACE with a saturated left edge rather
   than a solid fill — a solid RAG block cannot hold WCAG-AA body text across eight
   themes, and the accent edge carries no text so it can stay fully saturated. */
.mh { display: grid; gap: var(--sp-3); }
.mh-summary { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.mh-group-head { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-2); }
.mh-dot { width: 10px; height: 10px; border-radius: var(--radius-full); flex: none; }

/* auto-fill + minmax reflows from 1 column at 390px up to many on desktop, so the grid
   never forces horizontal page scroll (house gate). min-width:0 lets long topic names wrap. */
.mh-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-2); }
.mh-cell {
  display: grid; grid-template-columns: auto 1fr; grid-template-areas: 'glyph label' 'glyph meta';
  gap: 0 var(--sp-2); align-content: center;
  min-width: 0; padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); text-decoration: none;
}
.mh-glyph { grid-area: glyph; font-size: var(--text-lg); line-height: 1; align-self: center; }
.mh-label { grid-area: label; font-weight: 700; font-size: var(--text-sm); min-width: 0; overflow-wrap: anywhere; }
/* --text-soft, NOT --text-mute. This line carries the band word and the percentage —
   the two channels that make the grid readable without colour — so it is load-bearing
   accessibility content, not decoration. Measured on a tinted cell background across
   all 8 registered themes, --text-mute lands at 3.1–4.4:1 (below WCAG AA 4.5:1) in
   every one of them; --text-soft clears it everywhere. */
.mh-meta  { grid-area: meta; font-size: var(--text-xs); color: var(--text-soft); font-weight: 600; }

.mh-secure     { border-left-color: var(--rag-green); background: color-mix(in srgb, var(--rag-green) 10%, var(--surface-2)); }
.mh-developing { border-left-color: var(--amber-fg);  background: color-mix(in srgb, var(--rag-amber) 12%, var(--surface-2)); }
.mh-priority   { border-left-color: var(--rag-red);   background: color-mix(in srgb, var(--rag-red) 10%, var(--surface-2)); }
.mh-none       { border-left-color: var(--border); background: var(--surface-2); opacity: .75; }
/* Fading = stale but not weak. A dashed edge is a THIRD channel (not colour, not word),
   so "needs a refresh" survives greyscale and colour-blind viewing. */
.mh-fading { border-left-style: dashed; }

.mh-actionable { cursor: pointer; transition: transform var(--dur, .15s) var(--ease, ease), box-shadow var(--dur, .15s) var(--ease, ease); }
.mh-actionable:hover { transform: translateY(-1px); box-shadow: 0 2px 10px rgba(0,0,0,.14); }
.mh-actionable:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .mh-actionable { transition: none; } .mh-actionable:hover { transform: none; } }

.mh-key { font-size: var(--text-xs); margin: 0; }
.mh-roster { margin-top: var(--sp-2); }
.mh-roster > summary { cursor: pointer; font-size: var(--text-sm); font-weight: 600; color: var(--text-mute); }
.mh-roster[open] > summary { margin-bottom: var(--sp-2); }

/* AI marking in-progress spinner (js/views/quiz.js). Honours reduced motion. */
.qz-ai-spin {
  width: 16px; height: 16px; flex: none; border-radius: var(--radius-full);
  border: 2px solid var(--border); border-top-color: var(--brand);
  animation: qz-ai-spin 0.7s linear infinite;
}
@keyframes qz-ai-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .qz-ai-spin { animation: none; border-top-color: var(--border-strong); } }

/* ---------- "More" sheet (mobile navigation) ----------
   The bottom bar carries four primary destinations; everything else in the
   sidebar lives here, rendered from the same navSections() source so a new
   feature is reachable on a phone automatically. Phone-only: at ≥901px the
   sidebar is back and the whole thing is inert. */
.tablink-more { background: none; border: 0; cursor: pointer; font-family: inherit; }
.bottom-tabs button.tablink-more { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; font-weight: 700; color: var(--text-mute); padding: 4px 10px; }
.bottom-tabs button.tablink-more.active { color: var(--brand); }
.bottom-tabs button.tablink-more .ico { font-size: 18px; line-height: 1; }

.more-sheet { position: fixed; inset: 0; z-index: 60; }
.more-sheet[hidden] { display: none; }
.more-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); opacity: 0; transition: opacity 180ms ease; }
.more-sheet.open .more-backdrop { opacity: 1; }

.more-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 82vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg-elev); border-top: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 8px var(--sp-3) calc(var(--sp-3) + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 200ms ease;
}
.more-sheet.open .more-panel { transform: translateY(0); }

.more-grip { width: 40px; height: 4px; border-radius: var(--radius-full); background: var(--border-strong, var(--border)); margin: 4px auto 10px; }
.more-head { align-items: center; margin-bottom: var(--sp-2); }

/* The topbar search is hidden on phones for space, which also hid the only
   full-content search. Re-enable it inside the sheet, full width. */
.more-search { display: block; flex: none; width: 100%; margin-bottom: var(--sp-2); }
.more-search input { width: 100%; }

.more-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.more-nav .group-label { grid-column: 1 / -1; margin-top: var(--sp-2); }
.more-link {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 10px; border-radius: var(--radius-md);
  background: var(--surface-2); color: var(--text); text-decoration: none;
  font-weight: 600; font-size: var(--text-sm);
  min-height: 48px;                 /* comfortable thumb target */
  overflow-wrap: anywhere;
}
.more-link.active { background: var(--brand); color: #fff; }
.more-link .ico { font-size: 18px; flex: none; }

/* Stop the page scrolling behind the open sheet. */
body.more-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .more-backdrop, .more-panel { transition: none; }
}

/* Belt and braces: the sheet is a phone affordance. If the viewport is wide
   enough for the sidebar, never show it — even if something left it open. */
@media (min-width: 901px) {
  .more-sheet { display: none; }
}

/* ---------- Terry Crossing — 4-way pad ----------
   Swipe on the field is the primary touch control; this pad is the always-visible
   accessibility fallback for anyone who can't or would rather not swipe. Inherits
   .inv-btn's 56px min-height, so every target clears the 48px floor. */
.xg-pad { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); margin-top: var(--sp-3); }
.xg-pad-row { display: flex; gap: var(--sp-2); justify-content: center; }
.xg-btn { min-width: 64px; font-size: 18px; line-height: 1; }
@media (hover: hover) and (pointer: fine) { .xg-pad { opacity: .55; } .xg-pad:hover { opacity: 1; } }

/* ---------- Mark my work (#/mark) — "Bring Your Own Paper" ----------
   Attached pages are shown as thumbnails of the DOWNSCALED image, so what the
   student checks for legibility is byte-for-byte what the marker receives. The
   grid is auto-fill rather than a fixed column count because there are only
   ever one to three of them, and one full-width page on a phone is easier to
   read than three postage stamps. */
.mw-file { padding: 10px 12px; }
.mw-thumbs {
  display: grid; gap: var(--sp-3); margin-top: var(--sp-3);
  grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
}
.mw-thumb { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.mw-thumb img {
  width: 100%; height: auto; display: block; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
}
.mw-thumb figcaption { font-size: var(--text-xs); }

/* ── Add Content / content library (#/library) ───────────────────────────── */
/* Token-only, like every other component: a theme changes these by changing
   its tokens, never by a rule in here. */
.lib-pickers { gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-3); }
/* The file input is the label's own control, visually replaced by the button.
   `position:absolute; opacity:0` rather than `display:none` — a hidden input is
   unreachable from the keyboard in some engines, which would leave the camera
   and the picker mouse-only. */
.lib-pick { position: relative; overflow: hidden; cursor: pointer; }
.lib-pick .lib-file {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}
.lib-pick:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }

.lib-thumbs {
  display: grid; gap: var(--sp-3); margin-top: var(--sp-3);
  /* auto-fill, so one page is not stretched across the whole card and eight
     wrap into rows without a media query. */
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.lib-thumb {
  border: 1px solid var(--line); border-radius: var(--r-2);
  padding: var(--sp-2); background: var(--surface-2);
  display: flex; flex-direction: column; gap: var(--sp-2); align-items: stretch;
}
.lib-thumb img {
  width: 100%; height: 120px; object-fit: cover;
  border-radius: var(--r-1); background: var(--surface-3);
}
.lib-thumb-meta { font-size: var(--fs-xs); color: var(--text-soft); word-break: break-word; }
.lib-thumb-missing {
  height: 120px; display: grid; place-items: center;
  font-size: var(--fs-xs); color: var(--text-soft);
  border: 1px dashed var(--line); border-radius: var(--r-1);
}
.lib-status { margin: var(--sp-2) 0 0; }
.lib-item { border-top: 1px solid var(--line); padding-top: var(--sp-3); margin-top: var(--sp-3); }
.lib-item:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.lib-item-head { gap: var(--sp-3); flex-wrap: wrap; }
.lib-actions { gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-3); }

@media (max-width: 480px) {
  /* Two columns at phone width keeps thumbnails tappable without a scroller. */
  .lib-thumbs { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .lib-pick { flex: 1 1 100%; text-align: center; }
}

/* ── Add Content: the AI scan block ─────────────────────────────────────── */
.lib-scan {
  margin-top: var(--sp-3); padding-top: var(--sp-3);
  border-top: 1px dashed var(--line);
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.lib-scan-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-3); flex-wrap: wrap; }
.lib-scan-when { font-size: var(--fs-xs); }
.lib-scan-summary { margin: 0; }
.lib-scan-note { margin: 0; font-size: var(--fs-sm); }
.lib-keypoints { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: var(--sp-1); }
.lib-keypoints li { line-height: 1.5; }
.lib-proposal { margin: 0; padding: var(--sp-3); }

/* ── Revision: recall over the student's own key points ─────────────────── */
.lib-recall { background: var(--surface-2); }
.lib-recall-head { gap: var(--sp-3); flex-wrap: wrap; }
.lib-recall-point {
  margin: var(--sp-3) 0; font-size: var(--fs-lg); line-height: 1.5;
}
.lib-recall-ratings { gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-2); }
/* Ratings are the primary action here — keep them thumb-sized on a phone. */
@media (max-width: 480px) { .lib-recall-ratings .btn { flex: 1 1 calc(50% - var(--sp-2)); } }
