/* StudentBench (FINAL) — polished, dependency-free styling (no build step).
 *
 * Design system + tutoring components are adapted from trial3 (the strongest UX
 * scaffold of the four). The server-rendered pages (landing / consent / test /
 * admin / break / complete) reuse the same tokens. Pure CSS, no framework.
 */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --ink: #1b1f2a;
  --ink-soft: #4a5160;
  --ink-faint: #828a9b;
  --brand: #3b5bdb;
  --brand-ink: #1c3aa9;
  --brand-soft: #e7ecfd;
  --accent: #0ca678;        /* correct / success */
  --accent-soft: #e3faf2;
  --warn: #e8590c;          /* timers low / extend */
  --warn-soft: #fff0e6;
  --danger: #e03131;
  --danger-soft: #ffe9e9;
  --line: #e3e6ee;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20,26,45,.06), 0 8px 24px rgba(20,26,45,.06);
  --shadow-lg: 0 12px 40px rgba(20,26,45,.16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --maxw: 980px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-faint); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.center { text-align: center; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px;
  background: rgba(255,255,255,.9); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 750; font-size: 18px; letter-spacing: -.02em; color: var(--brand-ink); }
.brand .muted { font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
/* ADMIN-ONLY resource quick-links (rendered only when is_admin) — compact + muted. */
.admin-nav { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.admin-nav a { color: var(--ink-faint); text-decoration: none; }
.admin-nav a:hover { color: var(--brand-ink); text-decoration: underline; }

/* ---------- layout ---------- */
.container { max-width: var(--maxw); margin: 0 auto; padding: 28px 22px 80px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; margin-bottom: 20px;
}
.card.narrow { max-width: 720px; margin-left: auto; margin-right: auto; }
.card.subtle { background: var(--surface-2); border-style: dashed; box-shadow: none; }
h1 { font-size: 26px; letter-spacing: -.02em; margin: 0 0 12px; }
h2 { font-size: 19px; letter-spacing: -.01em; margin: 18px 0 10px; }
h3 { font-size: 15px; margin: 14px 0 6px; color: var(--ink-soft); }
p { margin: 0 0 12px; color: var(--ink-soft); }
.lead { font-size: 16px; color: var(--ink-soft); }
ul.clean, ul { padding-left: 20px; }
li { margin-bottom: 6px; color: var(--ink-soft); }

/* ---------- forms / buttons ---------- */
label { display: block; margin: 14px 0 6px; font-weight: 650; font-size: 14px; color: var(--ink); }
label.check, label.field { font-weight: 600; }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; margin-top: 6px; padding: 11px 13px; font-size: 15px; font-family: var(--font);
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
/* Non-PII intake covariates: grouped yes/no + dropdown follow-up. */
fieldset.intake-group {
  margin: 14px 0 6px; padding: 12px 15px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface-2);
}
fieldset.intake-group legend { padding: 0 6px; font-weight: 650; font-size: 14px; color: var(--ink); }
label.radio {
  display: inline-flex; align-items: center; gap: 7px; margin: 4px 16px 4px 0;
  font-weight: 400; cursor: pointer;
}
label.radio input { width: 18px; height: 18px; }
input[type=radio], input[type=checkbox] { width: auto; margin-top: 0; accent-color: var(--brand); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 54px; }

button, .btn {
  cursor: pointer; font: inherit; font-weight: 650; font-size: 15px;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 11px 20px;
  background: var(--brand); color: #fff; transition: filter .15s, transform .05s, background .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:hover, .btn:hover { filter: brightness(1.06); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; filter: none; }
button.primary, .btn.primary { background: var(--brand); color: #fff; }
button.secondary, .btn.secondary { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
button.ghost, .btn.ghost { background: transparent; color: var(--brand-ink); border-color: var(--line); }
button.success { background: var(--accent); }
button.warn, .btn.warn { background: var(--warn); }
button.big, .btn.lg { font-size: 16px; padding: 14px 26px; }
.btn-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 18px; }

label.check {
  display: flex; gap: 11px; align-items: flex-start; padding: 13px 15px; margin: 12px 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2);
  font-weight: 400; cursor: pointer;
}
label.check input { margin-top: 3px; width: 18px; height: 18px; flex: 0 0 auto; }
/* Keep the label text as ONE flex item so the sentence flows normally instead of
   each <strong>/<u>/text-run becoming its own column. */
label.check .check-text { flex: 1 1 auto; line-height: 1.5; }
label.check.pledge { background: var(--warn-soft); border-color: #ffd8a8; }
label.check.pledge strong { color: var(--warn); }

/* ---------- badges / flashes ---------- */
.badge { display: inline-block; background: var(--brand-soft); color: var(--brand-ink); border-radius: 999px; padding: .15em .65em; font-size: .78rem; font-weight: 700; }
.badge.admin { background: #2b2f3a; color: #ffd43b; }
.badge.timer { background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums; }
.badge.timer.big { font-size: 1.05rem; padding: .3em .8em; }
.badge-soft { display:inline-block; font-size:11px; font-weight:700; padding:3px 9px; border-radius:999px; background: var(--brand-soft); color: var(--brand-ink); }
.diff-badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-faint); }
.flash { padding: .7em 1em; border-radius: var(--radius-sm); margin-bottom: 1em; }
.flash.error { background: var(--danger-soft); color: #b91c1c; border: 1px solid #fecaca; }
code.inline { font-family: var(--mono); background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.footer { text-align: center; padding: 18px; color: var(--ink-faint); font-size: 13px; }

/* ---------- test page ---------- */
.test-card { max-width: 820px; margin: 0 auto; }
.test-header { display: flex; justify-content: space-between; align-items: center; }
.test-meta { display: flex; gap: 8px; }
.qstem { margin: 16px 0; }
.qtag { display: inline-block; color: var(--ink-faint); font-size: .8rem; font-weight: 700; margin-bottom: .4em; }
.stem-text { font-size: 1.12rem; font-weight: 500; white-space: pre-wrap; }
.options { display: flex; flex-direction: column; gap: 9px; margin: 16px 0; }
.opt {
  display: flex; gap: 11px; align-items: center; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; transition: all .12s; font-size: 15px; font-weight: 400;
}
.opt:hover { border-color: var(--brand); background: var(--brand-soft); }
.opt .opt-letter, .opt .opt-key { font-weight: 750; color: var(--brand-ink); width: 20px; }
.opt.selected { border-color: var(--brand); background: var(--brand-soft); }
.opt.correct { border-color: var(--accent); background: var(--accent-soft); }
.opt.wrong { border-color: var(--danger); background: var(--danger-soft); }
.gridin { margin: 16px 0; max-width: 340px; }
.test-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }

/* ---------- tutoring: stepper rail ---------- */
.stepper-rail {
  position: sticky; top: 53px; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line); padding: 10px 22px; box-shadow: var(--shadow);
}
.stepper { display: flex; gap: 8px; max-width: 1100px; margin: 0 auto; overflow-x: auto; }
.step {
  flex: 1 1 0; min-width: 130px; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2);
}
.step .step-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.step .skill-tag { font-size: 10.5px; font-weight: 700; color: var(--ink-faint); letter-spacing: .04em; }
.step .step-name { font-size: 13px; font-weight: 650; color: var(--ink); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step .step-mins { font-size: 11.5px; color: var(--ink-faint); margin-top: 3px; }
.step.active { background: var(--brand-soft); border-color: var(--brand); }
.step.active .step-name { color: var(--brand-ink); }
.step.done { background: var(--accent-soft); border-color: var(--accent); }
.step.done .step-name::before { content: "✓ "; color: var(--accent); }

/* ---------- tutoring: two-pane ---------- */
.tutor-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 22px 80px; }
.tutor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 860px) { .tutor-grid { grid-template-columns: 1fr; } }

.concept-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.concept-why { background: var(--brand-soft); border-radius: var(--radius-sm); padding: 12px 14px; margin: 10px 0 16px;
  color: var(--brand-ink); font-size: 14px; }
.purpose-banner { display: flex; gap: 10px; align-items: flex-start; background: var(--accent-soft);
  border: 1px solid #b7ecd9; border-radius: var(--radius-sm); padding: 11px 14px; margin-bottom: 16px; font-size: 13.5px; color: #0b6b50; }

/* timers */
.timers { display: flex; gap: 12px; align-items: center; }
.timer-chip { text-align: center; padding: 7px 13px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--line); min-width: 100px; }
.timer-chip .t-label { font-size: 10.5px; color: var(--ink-faint); font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.timer-chip .t-val { font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--ink); }
.timer-chip.low .t-val { color: var(--warn); }
.timer-chip.total .t-val { color: var(--brand-ink); }
.progress-bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 10px 0 4px; }
.progress-bar > span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .4s ease; }
.progress-bar.low > span { background: var(--warn); }

/* practice problem pane */
.problem .stem { font-size: 16px; color: var(--ink); margin-bottom: 14px; white-space: pre-wrap; }
.problem-meta { display:flex; justify-content: space-between; align-items:center; margin-bottom: 10px; }
.feedback { margin-top: 12px; padding: 11px 14px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; min-height: 1em; }
.feedback:empty { display: none; }
.feedback.correct { background: var(--accent-soft); color: var(--accent); }
.feedback.wrong { background: var(--warn-soft); color: var(--warn); }

/* on-the-fly extra practice ("Give me another problem") */
.extra-practice-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.extra-practice-row button.small { padding: 6px 12px; }

/* chat pane */
.chat { display: flex; flex-direction: column; height: 520px; }
.chat-log { flex: 1 1 auto; overflow-y: auto; padding: 4px; display: flex; flex-direction: column; gap: 10px; }
.chat-log.static { height: auto; max-height: 420px; }
.msg, .chat-msg { max-width: 88%; font-size: 14.5px; white-space: pre-wrap; line-height: 1.5; }
.chat-msg .who { display:block; font-size: 10.5px; font-weight: 700; opacity:.65; margin-bottom:2px; text-transform: uppercase; letter-spacing:.04em; }
.chat-msg .bubble { padding: 10px 13px; border-radius: 13px; }
.chat-msg.tutor { align-self: flex-start; }
.chat-msg.tutor .bubble { background: var(--surface-2); color: var(--ink); border-bottom-left-radius: 4px; }
.chat-msg.student { align-self: flex-end; }
.chat-msg.student .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.system { align-self: center; max-width: 92%; }
.chat-msg.system .bubble { background: transparent; color: var(--ink-faint); font-size: 12.5px; font-style: italic; }
.chat-msg.thinking .bubble { opacity: .6; }
/* Rendered (markdown) tutor/system bubbles: the JS renderer emits its own
   <p>/<br>/<li> block tags, so disable pre-wrap here (otherwise the source
   newlines would double the spacing) and give lists/paragraphs subtle layout. */
.chat-msg .bubble.md { white-space: normal; }
.chat-msg .bubble.md p { margin: 0 0 .5em; }
.chat-msg .bubble.md p:last-child { margin-bottom: 0; }
.chat-msg .bubble.md ul, .chat-msg .bubble.md ol { margin: .3em 0 .3em 1.1em; padding-left: .9em; }
.chat-msg .bubble.md li { margin: .15em 0; }
.chat-msg .bubble.md code { background: rgba(0,0,0,.08); padding: .05em .35em; border-radius: 4px; font-size: .92em; }
.chat-form { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; }
.chat-form textarea { flex: 1 1 auto; min-height: 44px; max-height: 120px; margin-top: 0; }

/* ---------- admin ---------- */
.stat-grid { display: flex; gap: 14px; flex-wrap: wrap; margin: 16px 0; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 22px; text-align: center; min-width: 110px; }
.stat .num { display: block; font-size: 1.6rem; font-weight: 800; color: var(--brand-ink); }
.stat .lbl { font-size: .8rem; color: var(--ink-faint); }
.inline-form { display: flex; gap: 8px; align-items: center; max-width: 460px; }
.inline-form select { width: auto; flex: 1; margin-top: 0; }
.admin-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; margin: 10px 0; }
.data-table th, .data-table td { text-align: left; padding: .45em .6em; border-bottom: 1px solid var(--line); }
.data-table.small { font-size: .8rem; }
/* Wide admin data tables scroll horizontally instead of breaking the layout; the admin
   pages also widen the page container. A header cell with a tooltip shows a help cursor. */
.table-scroll { overflow-x: auto; }
.data-table th[title] { cursor: help; }
body.admin-wide .container { max-width: 1400px; }

/* Compensation notice — shown to ADULT participants (home page + a short reminder on the
   consent gate). A positive, success-toned callout so the $50 incentive stands out. */
.compensation-notice { margin: 16px 0 20px; padding: 14px 16px; background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px; }
.compensation-notice h2 { margin: 0 0 6px; font-size: 16px; color: var(--accent); }
.compensation-notice p { margin: 0 0 8px; color: var(--ink-soft); }
.compensation-notice ol { margin: 0; padding-left: 20px; }
.compensation-notice li { color: var(--ink-soft); }

/* One-sitting / no-resume expectation callout (amber attention). Shown up front so a
   student sets aside the full ~2–2.5h: once they start, the clock keeps running. */
.sitting-note { margin: 14px 0; padding: 12px 14px; background: #fff7e6; border: 1px solid #f0b429; border-radius: 10px; color: var(--ink-soft); }
.sitting-note strong { color: var(--ink); }
.kv { border-collapse: collapse; }
.kv th { text-align: left; padding: .3em 1em .3em 0; color: var(--ink-faint); font-weight: 700; vertical-align: top; }
.code { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; font-size: .8rem; white-space: pre-wrap; max-height: 360px; overflow-y: auto; font-family: var(--mono); }
details { margin: 10px 0; }
summary { cursor: pointer; color: var(--brand); font-weight: 650; }

/* ---------- provenance banner (sample-plan viewer) ---------- */
.provenance { font-weight: 650; padding: 12px 16px; border-radius: var(--radius-sm); margin: 14px 0; }
.provenance.live { background: var(--accent-soft); border: 1px solid #b7ecd9; color: #0b6b50; }
.provenance.mock { background: var(--warn-soft); border: 1px solid #ffd8a8; color: var(--warn); }

/* ---------- misc ---------- */
.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color:#fff; border-radius: 50%;
  display:inline-block; animation: spin .7s linear infinite; }
button.secondary .spinner, button.ghost .spinner { border-color: rgba(0,0,0,.2); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }
.big-center { max-width: 620px; margin: 40px auto; text-align: center; }
.big-center .emoji { font-size: 44px; margin-bottom: 8px; }

/* Utility + the capped "break / generating" screen (background plan gen). */
.sb-hidden { display: none !important; }
/* Countdown chip pinned to the TOP-RIGHT of the break card. */
.break-wrap { position: relative; }
.break-timer { position: absolute; top: 14px; right: 14px; text-align: center;
  padding: 7px 13px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--line); min-width: 96px; }
.break-timer .t-label { font-size: 10.5px; color: var(--ink-faint); font-weight: 700;
  letter-spacing: .03em; text-transform: uppercase; }
.break-timer .t-val { font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--ink); }
.break-timer.low .t-val { color: var(--warn); }
.gen-status { margin: 14px 0; color: var(--ink-faint); }
.gen-status .spinner { width: 15px; height: 15px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%;
  display: inline-block; animation: spin .7s linear infinite; }

/* Pre-test results review on the break: the questions the student missed, with
   their (wrong) answer in RED and the correct answer in GREEN. Pre-test answers
   only — never post-test content. */
.missed-list { list-style: decimal; padding-left: 1.4em; margin: .4em 0 0; }
.missed-item { margin: 0 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.missed-item:last-child { border-bottom: none; }
.missed-meta { margin-bottom: 3px; }
.missed-stem { margin: 2px 0 8px; white-space: pre-wrap; }
.missed-answers .ans-row { margin: 2px 0; }
.ans-label { display: inline-block; min-width: 118px; color: var(--ink-faint); font-size: .92em; }
.ans-correct { color: #0b6b50; background: var(--accent-soft); font-weight: 650;
  border-radius: 5px; padding: 1px 7px; }
.ans-wrong { color: #c92a2a; background: #ffe3e3; font-weight: 650;
  border-radius: 5px; padding: 1px 7px; }
