/* Laudentia Prep — theme tokens follow the validated reference palette.
   Light is defined on :root; dark overrides via media query (guarded so an
   explicit data-theme="light" wins) and via data-theme="dark". */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface2: #f0efec;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --g1: #2a78d6; --g2: #eb6834; --g3: #1baf7a; --g4: #eda100; --g5: #e87ba4;
  --good: #0ca30c;
  --good-text: #006300;
  --warn: #fab219;
  --serious: #ec835a;
  --crit: #d03b3b;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.12);
  --good-soft: rgba(12, 163, 12, 0.12);
  --crit-soft: rgba(208, 59, 59, 0.10);
  --shadow: 0 1px 3px rgba(11, 11, 11, 0.08), 0 8px 24px rgba(11, 11, 11, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface2: #242423;
    --ink: #ffffff;
    --ink2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --g1: #3987e5; --g2: #d95926; --g3: #199e70; --g4: #c98500; --g5: #d55181;
    --good: #0ca30c;
    --good-text: #0ca30c;
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --good-soft: rgba(12, 163, 12, 0.14);
    --crit-soft: rgba(208, 59, 59, 0.16);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface2: #242423;
  --ink: #ffffff;
  --ink2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --g1: #3987e5; --g2: #d95926; --g3: #199e70; --g4: #c98500; --g5: #d55181;
  --good: #0ca30c;
  --good-text: #0ca30c;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --good-soft: rgba(12, 163, 12, 0.14);
  --crit-soft: rgba(208, 59, 59, 0.16);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }   /* Safari must not inflate text */
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  /* room for the fixed ticker, plus the home-indicator strip on iPhone */
  padding-bottom: calc(52px + env(safe-area-inset-bottom));
  overflow-wrap: break-word;
}
button, select, input { -webkit-tap-highlight-color: var(--accent-soft); }
.hidden { display: none !important; }
.spacer { flex: 1; }
button { font: inherit; color: inherit; }
kbd {
  font: 11px/1 system-ui; border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 4px; padding: 2px 5px; opacity: .7; margin-left: 6px;
}
code { background: var(--surface2); border-radius: 4px; padding: 1px 5px; font-size: 0.92em; }

/* ------------------------------------------------------------- header */
#topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 30;
  flex-wrap: wrap;
}
.brand { font-size: 17px; white-space: nowrap; }
.brand .logo { font-size: 19px; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button {
  background: transparent; border: 0; padding: 7px 14px; cursor: pointer; color: var(--ink2);
}
.seg button.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.scores { display: flex; gap: 8px; }
.score-chip {
  background: var(--surface2); border-radius: 8px; padding: 4px 10px; font-size: 13px;
  color: var(--ink2);
}
.score-chip b { color: var(--ink); font-variant-numeric: tabular-nums; }
.usersel {
  background: var(--surface2); color: var(--ink); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 9px; font: inherit; max-width: 160px;
}
.whoami { color: var(--muted); font-size: 13px; white-space: nowrap; }
.whoami a { color: var(--muted); text-decoration: underline; }
.chip.pace-fast { color: var(--good-text); background: var(--good-soft); }
.chip.pace-slow { color: var(--crit); background: var(--crit-soft); }
.iconbtn {
  background: transparent; border: 1px solid var(--border); border-radius: 9px;
  padding: 6px 11px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center;
}

/* ------------------------------------------------------------- layout */
#layout { max-width: 1160px; margin: 22px auto; padding: 0 18px; }
#qcol { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
#qcol > #reviewBar { grid-column: 1 / -1; }
@media (max-width: 980px) { #qcol { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; box-shadow: var(--shadow);
}
.cardlabel { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

#reviewBar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: var(--accent-soft); border-radius: 10px; margin-bottom: 4px;
}

/* ----------------------------------------------------------- question */
#qMeta { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip {
  background: var(--accent-soft); color: var(--ink); border-radius: 20px;
  padding: 3px 12px; font-size: 12.5px; font-weight: 600;
}
.chip.subtle { background: var(--surface2); color: var(--ink2); font-weight: 500; }
.chip.review { background: var(--crit-soft); }
.timer { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }

.passage {
  background: var(--surface2); border-left: 3px solid var(--baseline);
  padding: 12px 16px; border-radius: 0 10px 10px 0; margin-bottom: 14px;
  color: var(--ink); font-size: 15px;
}
.passage p { margin: 0 0 10px; } .passage p:last-child { margin-bottom: 0; }
.stem { font-size: 16px; margin-bottom: 14px; }
.stem p { margin: 0 0 10px; }

.graphbox { display: flex; justify-content: center; margin: 6px 0 16px; overflow-x: auto; }
.graphbox svg { max-width: 100%; height: auto; }

.choices { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.choice {
  display: flex; gap: 12px; align-items: baseline; text-align: left;
  border: 1.5px solid var(--border); border-radius: 11px; background: transparent;
  padding: 11px 14px; cursor: pointer; transition: border-color .12s, background .12s;
}
.choice .letter {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid var(--baseline); display: inline-flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 13px; align-self: center;
}
.choice.sel { border-color: var(--accent); background: var(--accent-soft); }
.choice.sel .letter { border-color: var(--accent); background: var(--accent); color: #fff; }
.choice.correct { border-color: var(--good); background: var(--good-soft); }
.choice.correct .letter { border-color: var(--good); background: var(--good); color: #fff; }
.choice.wrong { border-color: var(--crit); background: var(--crit-soft); }
.choice.wrong .letter { border-color: var(--crit); background: var(--crit); color: #fff; }
.choice:disabled { cursor: default; }
.choice .ctext { min-width: 0; }
.choice .ctext p { margin: 0; }

/* Answer eliminator — mirrors Bluebook: an "ABC" strikethrough toggle in the
   question toolbar, then a per-choice marker that crosses the choice out and
   flips to "Undo". A crossed-out choice cannot be picked until it is undone. */
.elimtoggle .abc { text-decoration: line-through; font-weight: 700; font-size: 13px; letter-spacing: .04em; }
.elimtoggle.on { border-color: var(--accent); background: var(--accent-soft); }
.choicerow { display: flex; align-items: center; gap: 8px; }
.choicerow .choice { flex: 1 1 auto; }
.strike {
  flex: 0 0 auto; min-width: 32px; height: 30px; padding: 0 9px; border-radius: 15px;
  border: 1.5px solid var(--border); background: transparent; color: var(--ink2);
  cursor: pointer; font-size: 12px; font-weight: 700; line-height: 1;
}
.strike .sl { text-decoration: line-through; }
.choice.elim { opacity: .45; }
.choice.elim .letter, .choice.elim .ctext { text-decoration: line-through; }
.choice.elim.correct { opacity: 1; }
.choice.elim.correct .letter, .choice.elim.correct .ctext { text-decoration: none; }
.elimtag { flex: 0 0 auto; font-size: 11.5px; color: var(--muted); white-space: nowrap; }

.spr { margin-bottom: 14px; }
.spr label { display: block; color: var(--ink2); font-size: 13.5px; margin-bottom: 6px; }
.spr input {
  width: 220px; font-size: 18px; padding: 9px 12px; border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--surface2); color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.spr input:focus { outline: none; border-color: var(--accent); }
.spr.correct input { border-color: var(--good); background: var(--good-soft); }
.spr.wrong input { border-color: var(--crit); background: var(--crit-soft); }

#qActions, #fbActions { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.btn {
  border: 1px solid var(--border); background: var(--surface2); border-radius: 10px;
  padding: 9px 16px; cursor: pointer; font-weight: 600;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary kbd { border-color: rgba(255,255,255,.4); color: #fff; opacity: .85; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.big { padding: 12px 22px; font-size: 16px; }

/* ----------------------------------------------------------- feedback */
#fbHead { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.badge { font-weight: 800; font-size: 17px; padding: 5px 14px; border-radius: 9px; }
.badge.good { color: var(--good-text); background: var(--good-soft); }
.badge.bad { color: var(--crit); background: var(--crit-soft); }
.badge.neutral { color: var(--ink2); background: var(--surface2); }
#fbAnswerLine { color: var(--ink2); }
#fbAnswerLine b { color: var(--ink); }

.gotchacard { background: var(--crit-soft); border: 1px solid var(--crit); border-radius: 11px; padding: 13px 16px; margin-bottom: 12px; }
.gotchacard .cardlabel { color: var(--crit); }
.gotchacard p { margin: 0 0 9px; } .gotchacard p:last-child { margin: 0; }
.rulecard { background: var(--good-soft); border: 1px solid var(--good); border-radius: 11px; padding: 13px 16px; margin-bottom: 12px; }
.explcard { background: var(--surface2); border-radius: 11px; padding: 13px 16px; margin-bottom: 12px; }
.explcard p, .rulecard p { margin: 0 0 9px; } .explcard p:last-child, .rulecard p:last-child { margin: 0; }
details { margin-bottom: 12px; }
details summary { cursor: pointer; color: var(--ink2); font-weight: 600; padding: 4px 0; }
details > div { padding: 10px 4px; }
details .dlist p { margin: 0 0 8px; }

/* --------------------------------------------------------------- chat */
#chat { border-top: 1px dashed var(--border); margin-top: 8px; padding-top: 12px; }
#chatMsgs {
  display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px;
  /* Its own scroll box: a long tutor answer must not push the page, and
     auto-follow while streaming stays inside these bounds. */
  max-height: min(52vh, 460px); overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.msg { max-width: 92%; border-radius: 12px; padding: 9px 13px; font-size: 14.5px; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin: 0; }
.msg.user { align-self: flex-end; background: var(--accent-soft); }
.msg.tutor { align-self: flex-start; background: var(--surface2); }
.msg.tutor.streaming::after { content: "▌"; animation: blink 1s step-end infinite; color: var(--accent); }
.msg.err { align-self: flex-start; background: var(--crit-soft); color: var(--crit); }
@keyframes blink { 50% { opacity: 0; } }
#chatRow { display: flex; gap: 8px; }
#chatInput {
  flex: 1; border: 1.5px solid var(--border); border-radius: 10px; padding: 9px 13px;
  background: var(--surface2); color: var(--ink); min-width: 0;
}
#chatInput:focus { outline: none; border-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* -------------------------------------------------------------- empty */
#qEmpty { text-align: center; padding: 30px 10px; }
#qEmpty h2 { margin: 0 0 8px; }
#qEmpty p { color: var(--ink2); margin: 0 auto 16px; max-width: 46ch; }

/* ------------------------------------------------------------ history */
#historyDrawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(430px, 92vw); z-index: 40;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.drawerhead { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.drawerhead .hint { flex-basis: 100%; margin: 0; }
#historyList { overflow-y: auto; padding: 8px; }
.hitem {
  display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left;
  background: transparent; border: 0; border-bottom: 1px solid var(--border);
  padding: 11px 10px; cursor: pointer; border-radius: 8px;
}
.hitem .hmark { font-size: 15px; line-height: 1.4; }
.hitem .hmark.good { color: var(--good-text); } .hitem .hmark.bad { color: var(--crit); }
.hitem .hbody { min-width: 0; }
.hitem .hskill { font-size: 12.5px; color: var(--ink2); font-weight: 600; }
.hitem .hstem { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------------------------------------------------------- dashboard */
#dashModal {
  position: fixed; inset: 0; z-index: 50; background: var(--page);
  overflow-y: auto;
}
.dashinner { max-width: 1160px; margin: 0 auto; padding: 12px 18px 40px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 14px 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 13px 16px; }
.tile .tv { font-size: 26px; font-weight: 750; }
.tile .tl { font-size: 12px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.tile .ts { font-size: 12px; color: var(--ink2); }
.coach { margin-bottom: 14px; border-left: 3px solid var(--accent); }
.dashcols { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .dashcols { grid-template-columns: minmax(0, 1fr); } }
.dashside { display: flex; flex-direction: column; gap: 14px; }

.domrow { margin: 14px 0 4px; font-weight: 700; font-size: 13.5px; color: var(--ink2); display: flex; gap: 8px; align-items: baseline; }
.domrow small { color: var(--muted); font-weight: 500; }
table.cov { width: 100%; border-collapse: collapse; font-size: 13px; }
table.cov th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; padding: 4px 8px; border-bottom: 1px solid var(--grid); }
table.cov td { padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.cov td.num { font-variant-numeric: tabular-nums; text-align: right; color: var(--ink2); }
.mbar { background: var(--surface2); border-radius: 4px; height: 8px; width: 110px; overflow: hidden; }
.mbar i { display: block; height: 100%; background: var(--g1); border-radius: 4px; }
.stock { display: inline-flex; gap: 4px; }
.stock i { font-style: normal; font-size: 11px; background: var(--surface2); border-radius: 4px; padding: 1px 6px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.stock i.low { background: var(--crit-soft); color: var(--crit); }

.agentfeed { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.aline { display: flex; gap: 8px; align-items: baseline; }
.aline .aago { color: var(--muted); font-size: 11.5px; flex: 0 0 52px; font-variant-numeric: tabular-nums; }
.aline .aname { font-weight: 700; flex: 0 0 auto; }
.aline .aname.generator { color: var(--g1); } .aline .aname.validator { color: var(--g3); }
.aline .aname.coach { color: var(--g5); } .aline .aname.enricher { color: var(--g4); }
.aline .aname.tutor { color: var(--g2); } .aline .aname.app, .aline .aname.llm { color: var(--muted); }
.aline .amsg { color: var(--ink2); min-width: 0; }

.deficit { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 5px 0; border-bottom: 1px solid var(--grid); }
.deficit small { color: var(--muted); font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- ticker */
#ticker {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-top: 1px solid var(--border);
  font-size: 13px; color: var(--ink2);
  padding: 8px max(16px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.llm { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.llm .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.llm.ok .dot { background: var(--good); }
.llm.loading .dot, .llm.starting .dot { background: var(--warn); animation: blink 1.2s infinite; }
.llm.down .dot { background: var(--crit); }
#llmBusy { display: inline-flex; align-items: center; gap: 7px; }
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(.7); opacity: .5; } 50% { transform: scale(1.15); opacity: 1; } }
#tickerText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------- misc */
#toasts {
  position: fixed; bottom: calc(60px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px;
  width: min(420px, calc(100vw - 24px));
}
.toast {
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-left: 3px solid var(--crit); border-radius: 10px; padding: 10px 16px;
  box-shadow: var(--shadow); animation: rise .18s ease-out;
}
.toast.info { border-left-color: var(--accent); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

table.md { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
table.md th, table.md td { border: 1px solid var(--baseline); padding: 5px 12px; text-align: center; }
table.md th { background: var(--surface2); }
ul.md { margin: 8px 0; padding-left: 22px; }
.katex { font-size: 1.05em; }
.math-slot.math-blk {
  display: block; text-align: center; margin: 10px 0;
  overflow-x: auto; overflow-y: hidden; max-width: 100%;
}
.math-slot.math-blk .katex-display { display: inline-block; margin: 0; }
.math-slot.math-blk .katex { font-size: 1.18em; }
.math-slot.math-blk .mtail { margin-left: 3px; font-size: 1.05em; }

/* ---------------------------------------- leaf (testing point) drill-down */
.cov tr.skillrow { cursor: pointer; }
.leafcell .low { color: var(--crit); background: var(--crit-soft); border-radius: 4px; padding: 1px 6px; }
tr.leafdetail > td { background: var(--surface2); padding: 8px 10px 10px; }
.leaflist { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.leaflist li { font-size: 12.5px; padding: 3px 8px; border-left: 3px solid var(--surface2); border-radius: 3px; }
.leaflist li b { font-weight: 600; }
.leaflist li small { color: var(--muted); }
.leaflist li.gap { border-left-color: var(--crit); background: var(--crit-soft); }
.leaflist li.unseen { border-left-color: var(--muted); }
.leaflist li.done { border-left-color: var(--good); }

/* =====================================================================
   Pointer capability — hover styling only where a pointer can hover, so
   a tap on iOS does not leave a highlight stuck on the last thing touched.
   ===================================================================== */
@media (hover: hover) {
  .iconbtn:hover { background: var(--surface2); }
  .choice:hover { border-color: var(--accent); }
  .choice.elim:hover { border-color: var(--border); }
  .strike:hover { border-color: var(--accent); color: var(--ink); }
  .btn:hover:not(:disabled) { filter: brightness(1.05); border-color: var(--accent); }
  .hitem:hover { background: var(--surface2); }
  .cov tr.skillrow:hover { background: var(--surface2); }
}
/* Touch gets press feedback instead. */
@media (hover: none) {
  .choice:active:not(:disabled) { background: var(--surface2); }
  .btn:active:not(:disabled), .iconbtn:active, .strike:active { transform: scale(.98); }
  .hitem:active { background: var(--surface2); }
  kbd { display: none; }              /* no physical keyboard to hint at */
}

/* =====================================================================
   Phone layout (iPhone-class widths). The topbar collapses to two rows —
   identity + tools, then mode + student — every control keeps a 44px tap
   target, and all fixed furniture respects the safe-area insets.
   ===================================================================== */
@media (max-width: 640px) {
  #topbar {
    gap: 8px; row-gap: 8px;
    padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
  }
  /* Reflow without touching the DOM: a full-width pseudo-element breaks the
     flex line, and `order` sorts the controls either side of the break. */
  #topbar::after { content: ""; flex-basis: 100%; height: 0; order: 5; }
  .brand { order: 1; }
  .brand b { display: none; }                       /* keep the 🎯, drop the words */
  .seg { order: 2; flex: 1 1 auto; }
  #btnHistory { order: 3; }
  #btnDashboard { order: 4; }
  .scores { order: 6; gap: 6px; }
  #topbar .spacer { order: 7; }
  .usersel { order: 8; }
  #btnAddUser { order: 9; }
  #btnTheme { order: 10; }

  .score-chip { padding: 5px 9px; font-size: 12.5px; }
  .iconbtn { min-height: 44px; min-width: 44px; justify-content: center; padding: 6px 10px; }
  #btnHistory span, #btnDashboard span { display: none; }   /* emoji-only tool buttons */
  .seg button { flex: 1 1 0; min-height: 44px; padding: 7px 6px; font-size: 13px; text-align: center; }
  /* flex-basis auto + a floor, so the student name stays readable next to a
     growing spacer instead of collapsing to a stub. */
  .usersel { min-height: 44px; flex: 0 1 auto; min-width: 118px; max-width: 40vw; font-size: 16px; }

  #layout {
    margin: 12px auto;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  #qcol { gap: 12px; }
  .card { padding: 14px; border-radius: 12px; }
  .passage { padding: 11px 13px; }
  .stem { font-size: 16px; }
  /* Keep the eliminator toggle and the clock together at the right edge, on
     whichever line the chips leave them. */
  #qMeta { row-gap: 6px; }
  #qMeta .spacer { display: none; }
  #btnElim { margin-left: auto; }

  /* Choices: full-width rows, thumb-sized eliminator markers. */
  .choice { padding: 13px 12px; gap: 10px; }
  .strike { min-width: 44px; height: 44px; border-radius: 22px; font-size: 12.5px; }
  .elimtag { font-size: 11px; white-space: normal; max-width: 64px; text-align: right; }

  #qActions, #fbActions, #chatRow, #reviewBar { flex-wrap: wrap; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  .btn.big { padding: 13px 20px; }
  #btnSubmit, #btnNext { flex: 1 1 auto; }          /* the primary action is a wide target */

  .spr input { width: 100%; max-width: 100%; font-size: 18px; min-height: 46px; }
  #chatInput { font-size: 16px; min-height: 44px; }
  #btnAsk, #btnStopAsk { min-height: 44px; }
  .msg { max-width: 100%; }

  /* Long-form content must scroll inside itself, never push the page wide. */
  table.md { display: block; width: max-content; max-width: 100%; overflow-x: auto; }

  /* Drawer and dashboard become full-screen sheets. */
  #historyDrawer {
    width: 100%; border-left: 0;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  #historyList { -webkit-overflow-scrolling: touch; }
  .drawerhead { padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top)); }
  .drawerhead b { flex: 1 1 auto; }
  .drawerhead .hint { order: 3; }                   /* close button stays on the title row */
  #btnCloseHistory, #btnCloseDash { min-height: 44px; min-width: 44px; }
  #dashModal { -webkit-overflow-scrolling: touch; }
  .dashinner {
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) calc(30px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; margin: 10px 0; }
  .tile { padding: 11px 13px; }
  .tile .tv { font-size: 22px; }
  .dashcols { gap: 12px; }
  /* The coverage matrix keeps all six columns: bars and stock pills shrink so
     it fits a phone, and the container scrolls sideways if a skill name is
     long enough to push it wider anyway. */
  #dashCoverage { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.cov { font-size: 12.5px; }
  table.cov th, table.cov td { padding: 5px 4px; }
  table.cov th { font-size: 10.5px; letter-spacing: .03em; }
  .mbar { width: 46px; }
  .stock { gap: 2px; }
  .stock i { padding: 1px 4px; font-size: 10.5px; }
  .agentfeed { max-height: 220px; }

  #ticker { gap: 8px; font-size: 12px; }
  #ticker .btn.small { min-height: 32px; }
}

/* Phone in landscape: the viewport is wide but short, so the two-row phone
   topbar would eat a quarter of the screen. Collapse the labels instead and
   keep everything on one row, and trim the vertical rhythm. */
@media (max-height: 480px) and (orientation: landscape) {
  #topbar {
    row-gap: 5px;
    padding: 5px max(10px, env(safe-area-inset-right)) 5px max(10px, env(safe-area-inset-left));
  }
  #topbar::after { display: none; }                 /* no forced line break here */
  .brand b { display: none; }
  #btnHistory span, #btnDashboard span { display: none; }
  .iconbtn { min-height: 40px; min-width: 40px; justify-content: center; }
  .seg button { min-height: 40px; }
  .usersel { min-height: 40px; font-size: 16px; }
  #layout {
    margin: 10px auto;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  .card { padding: 12px 14px; }
  #ticker { padding-top: 5px; }
  body { padding-bottom: calc(44px + env(safe-area-inset-bottom)); }
}

/* =====================================================================
   Sign-in page (served by app/oidc.py, same tokens as the app).
   ===================================================================== */
body.loginpage {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; padding: 24px; padding-bottom: 24px;
}
.logincard { width: min(400px, 100%); text-align: center; }
.logincard .brand { font-size: 22px; margin-bottom: 6px; }
/* The phone topbar drops the wordmark to save a row; the login page has no
   such pressure, and the name is the whole point of it. */
.logincard .brand b { display: inline; }
.logincard .sub { color: var(--ink2); margin: 0 0 20px; font-size: 14.5px; }
.logincard .err {
  background: var(--crit-soft); border: 1px solid var(--crit); color: var(--crit);
  border-radius: 10px; padding: 10px 14px; margin: 0 0 16px; font-size: 14px;
  text-align: left;
}
.logincard .hint { margin: 18px 0 0; font-size: 12.5px; }
.pbtn {
  display: flex; align-items: center; justify-content: center; min-height: 46px;
  margin-bottom: 10px; border: 1.5px solid var(--border); border-radius: 11px;
  background: var(--surface2); color: var(--ink); font-weight: 600;
  text-decoration: none; padding: 0 16px;
}
.pbtn:last-of-type { margin-bottom: 0; }
@media (hover: hover) { .pbtn:hover { border-color: var(--accent); } }
@media (hover: none) { .pbtn:active { transform: scale(.98); } }
