/* ---------------------------------------------------------------------------
   TSC Prep. A study desk: calm paper-and-ink surfaces, one teal accent for
   whatever you can act on. Same palette and faces as the Tag Gateway Field
   Guide, so the two read as one set.
--------------------------------------------------------------------------- */

:root {
  --bg: #f2f5f4;
  --surface: #ffffff;
  --sunk: #e8eeeb;
  --ink: #14201c;
  --muted: #56665f;
  --line: #d2dcd7;
  --accent: #0a7769;
  --accent-ink: #ffffff;
  --accent-wash: color-mix(in srgb, var(--accent) 12%, transparent);
  --warn: #b86e00;
  --danger: #c3352c;

  --display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --body: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;

  --gutter: 20px;
  --measure: 44rem;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #151e1b;
    --sunk: #1b2622;
    --ink: #e3ecec;
    --muted: #94a49d;
    --line: #2a3833;
    --accent: #3cc2ae;
    --accent-ink: #0e1412;
    --warn: #f0a83a;
    --danger: #f06a5e;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 1.0625rem/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
.num { font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter) 64px;
  padding-top: env(safe-area-inset-top, 0px);
}

/* --- top bar --------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 60px;
  border-bottom: 1px solid var(--line);
}
.wordmark {
  font: 800 1.15rem/1 var(--display);
  font-stretch: 112%;
  text-decoration: none;
  letter-spacing: -0.01em;
}
.wordmark b { color: var(--accent); }
.topnav { display: flex; gap: 4px; margin-right: auto; }
.topnav a {
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
}
.topnav a:hover { color: var(--ink); }
.topnav a[aria-current="page"] { color: var(--ink); background: var(--sunk); }
.topbar form { margin: 0; }
/* Three sections plus Lock is just too wide for a 375px phone at full padding. */
@media (max-width: 420px) {
  .topbar { gap: 8px; }
  .topnav { gap: 0; }
  .topnav a { padding: 10px 8px; }
}
.topbar > .wordmark:only-child { margin-right: auto; }

.linkish {
  background: none;
  border: 0;
  padding: 10px 4px;
  min-height: var(--tap);
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.linkish:hover { color: var(--ink); }

/* --- type ------------------------------------------------------------------ */
.page { padding-top: 32px; display: grid; gap: 20px; }
h1, h2 { font-family: var(--display); text-wrap: balance; margin: 0; line-height: 1.1; }
h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 820; font-stretch: 116%; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; font-weight: 760; font-stretch: 108%; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
p { margin: 0; max-width: 66ch; }
.lede { color: var(--muted); font-size: 1.1rem; }
.count { font: 600 0.85rem/1 var(--body); color: var(--muted); }
.hint { color: var(--muted); font-size: 0.95rem; }
.block { display: grid; gap: 14px; padding-top: 12px; }

/* --- controls -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: 700 1rem/1 var(--body);
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { color: var(--danger); }
.controls { display: flex; gap: 10px; flex-wrap: wrap; }

/* --- forms ----------------------------------------------------------------- */
.form { display: grid; gap: 22px; }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
label, legend { font-weight: 700; padding: 0; }
input[type="text"], input[type="password"], textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
textarea { resize: vertical; }
.error { color: var(--danger); font-weight: 600; }

.choices { display: grid; gap: 8px; }
.choice {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.choice input { margin-top: 5px; accent-color: var(--accent); }
.choice-hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.92rem; }

.danger { border-top: 1px solid var(--line); padding-top: 14px; }
.danger summary { cursor: pointer; color: var(--muted); padding: 10px 0; }
.danger form { display: grid; gap: 10px; justify-items: start; }

/* --- login ----------------------------------------------------------------- */
.gate { padding-top: 56px; display: grid; gap: 24px; max-width: 24rem; }
.gate h1 b { color: var(--accent); }
.gate form { display: grid; gap: 16px; }

/* --- home ------------------------------------------------------------------ */
.sections { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.section {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.section a, .section-soon { display: grid; gap: 4px; padding: 16px 18px; text-decoration: none; }
.section a:hover { background: var(--accent-wash); border-radius: 12px; }
.section-name { font: 760 1.1rem/1.2 var(--display); font-stretch: 106%; }
.section-note { color: var(--muted); }
.section-soon { opacity: 0.62; border-style: dashed; }

/* --- story bank ------------------------------------------------------------ */
.story-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.story-list a {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none;
}
.story-list a:hover { border-color: var(--accent); }
.story-title { font: 760 1.05rem/1.25 var(--display); font-stretch: 106%; }
.story-metric { color: var(--muted); }
.story-tail { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font: 600 0.78rem/1 var(--body);
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--accent-wash);
  color: var(--accent);
}
.tag-open { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.story-list a:active, .map-stories a:active, .filter-row a:active { background: var(--sunk); }
.story-head { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.story-head .story-title { min-width: 0; overflow-wrap: anywhere; }

.filters { display: grid; gap: 8px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-row a {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--muted); font-weight: 600; font-size: 0.92rem; text-decoration: none;
}
.filter-row a:hover { color: var(--ink); border-color: var(--accent); }
.filter-row a[aria-current="true"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
/* Eight sections wrap to half a phone screen: one row that scrolls instead. */
@media (max-width: 560px) {
  .filter-row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
  .filter-row a { flex: none; white-space: nowrap; }
}

.map-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.map-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; align-items: center;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.map-question { min-width: 0; overflow-wrap: anywhere; }
.map-stories { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.map-stories a {
  display: inline-flex; align-items: center; gap: 4px; min-height: var(--tap); padding: 0 12px;
  border-radius: 8px; background: var(--accent-wash); color: var(--accent); font-weight: 600; text-decoration: none;
}
@media (max-width: 520px) {
  .map-list li { grid-template-columns: 1fr; }
  .map-stories { justify-content: flex-start; }
}

.star { margin: 0; display: grid; gap: 10px; }
.star-part {
  display: grid; gap: 6px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.star-part dt { display: flex; gap: 10px; align-items: baseline; font-weight: 700; }
.star-letter { font: 820 1.2rem/1 var(--display); font-stretch: 112%; color: var(--accent); }
.star-part dd { margin: 0; max-width: 66ch; line-height: 1.5; overflow-wrap: anywhere; }
.star-part code { font-size: 0.9em; padding: 1px 5px; border-radius: 5px; background: var(--sunk); }
/* A blank still to fill: reads as open, like the "to fill" tag. */
mark.placeholder {
  color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent);
  padding: 0 3px; border-radius: 4px; box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.star-compact .star-part { padding: 10px 14px; }
.guide > .star { padding: 0 12px 12px; }

/* --- rehearsal ---------------------------------------------------------------- */
.recorder { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.recorder .btn:active, .controls .btn:active { filter: brightness(0.94); }
.mic { margin: 0; display: inline-flex; align-items: center; gap: 8px; color: var(--danger); font-weight: 600; }
.mic-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .mic-dot { animation: none; } }
.record-status { display: grid; gap: 6px; }
.record-status p { margin: 0; }
.record-label { font-weight: 600; }
.big-sep { color: var(--muted); margin: 0 2px; }
.fix { margin: 0; font-size: 1.1rem; font-weight: 600; max-width: 60ch; }
.plain-list { margin: 0; padding-left: 1.2rem; display: grid; gap: 4px; max-width: 66ch; }
.transcript { white-space: pre-wrap; }
.star-part dt .tag { margin-left: auto; }
.recorder-wrap { display: grid; gap: 8px; }
.recorder-wrap > .hint { margin: 0; }

/* --- today and the mock round ------------------------------------------------ */
.section-today { border-color: var(--accent); }
.today-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.today-step a, .today-empty {
  display: grid; gap: 6px; padding: 14px 16px; min-height: var(--tap);
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-decoration: none;
}
.today-step a:hover { border-color: var(--accent); }
.today-step a:active { background: var(--sunk); }
.today-step.is-done a, .today-step.is-done .today-empty { opacity: 0.7; }
.today-empty { color: var(--muted); }
.choice-pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-weight: 600; cursor: pointer;
}
.choice-pill:has(input:checked) { border-color: var(--accent); background: var(--accent-wash); color: var(--accent); }
.choice-line { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-weight: 600; }
.choice-pill input, .choice-line input { width: 18px; height: 18px; accent-color: var(--accent); }
.mock-question { font-size: 1.15rem; line-height: 1.35; }
.mock-told { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mock-item { border-top: 1px solid var(--line); padding-top: 18px; }
.end-early { margin: 0; }
.end-early .linkish { min-height: var(--tap); }

/* --- practice: think-aloud, time-up and the review ------------------------- */
.reveal { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--warn); font-weight: 600; }
.think-aloud-body { display: grid; gap: 10px; padding: 0 16px 14px; }
.think-aloud-body > .hint { margin: 0; }
.followup label { font-weight: 600; line-height: 1.4; }
.review p { margin: 0; }

.story-fits { color: var(--muted); margin: 0; }
.story-fits .eyebrow { margin-right: 6px; }

/* --- technical practice ----------------------------------------------------- */
.mono, code, pre, .code-input { font-family: ui-monospace, "Cascadia Code", "SF Mono", Consolas, Menlo, monospace; }
.eyebrow { font: 600 0.78rem/1 var(--body); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.big { font: 820 1.7rem/1 var(--display); font-stretch: 112%; color: var(--ink); }

.progress { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.progress > div {
  display: grid; gap: 4px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  color: var(--muted); font-size: 0.9rem;
}
.progress .is-warn .big { color: var(--warn); }
@media (max-width: 520px) { .progress { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.note-good { color: var(--accent); font-weight: 600; }

.exercise-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.exercise-list a {
  display: grid; grid-template-columns: 2.2rem minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); text-decoration: none; min-height: var(--tap);
}
.exercise-list a:hover { border-color: var(--accent); }
.ex-number { color: var(--muted); font-weight: 700; }
.ex-title { font-weight: 600; overflow-wrap: anywhere; }

.status {
  font: 600 0.76rem/1 var(--body); padding: 5px 8px; border-radius: 6px; white-space: nowrap;
  background: var(--sunk); color: var(--muted);
}
.status-solid { background: var(--accent-wash); color: var(--accent); }
.status-review { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.status-attempted { background: var(--sunk); color: var(--ink); }

.guide { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.guide > summary { cursor: pointer; padding: 12px 16px; font-weight: 700; min-height: var(--tap); display: flex; align-items: center; gap: 10px; }
.guide > .prose, .guide > .attempts { padding: 0 16px 14px; }

.ex-head { display: grid; gap: 10px; justify-items: start; }

/* The Markdown comes out as prose, code blocks and lists. */
.prose { display: grid; gap: 12px; max-width: 66ch; }
.prose > * { margin: 0; }
.prose ul, .prose ol { padding-left: 1.3rem; display: grid; gap: 6px; }
.prose code {
  font-size: 0.88em; padding: 1px 5px; border-radius: 5px; background: var(--sunk);
}
.prose pre, pre.mine {
  margin: 0; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--sunk); overflow-x: auto; font-size: 0.88rem; line-height: 1.5; tab-size: 2;
}
.prose pre code, pre.mine code { padding: 0; background: none; font-size: inherit; white-space: pre; }
.prompt { padding: 16px 18px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); max-width: none; }
.prompt > * { max-width: 66ch; }
.prompt pre { max-width: none; }
.solution { padding-top: 2px; max-width: none; }
.solution > * { max-width: 66ch; }
.solution pre { max-width: none; }

.code-input { font-size: 0.92rem; line-height: 1.5; tab-size: 2; white-space: pre; overflow-x: auto; }

.timer { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.timer-face { font: 800 1.9rem/1 var(--display); font-stretch: 112%; min-width: 4.2ch; }
.timer.is-over .timer-face { color: var(--warn); }
.timer-over { color: var(--warn); font-weight: 600; }

.rating { display: flex; flex-wrap: wrap; gap: 10px; }
.attempts { list-style: none; margin: 0; display: grid; gap: 12px; }
.attempts li { display: grid; gap: 6px; justify-items: start; }
.pager { display: flex; justify-content: space-between; padding-top: 8px; border-top: 1px solid var(--line); }
.pager a { padding: 12px 4px; font-weight: 700; text-decoration: none; color: var(--muted); }
.pager a:hover { color: var(--ink); }

/* --- topics and flashcards ---------------------------------------------------- */
.topic-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.topic-list a {
  display: grid; gap: 8px; padding: 14px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); text-decoration: none;
}
.topic-list a:hover { border-color: var(--accent); }
.topic-summary { color: var(--muted); font-size: 0.95rem; }
.tag-quiet { background: var(--sunk); color: var(--muted); }

/* The notes are long-form: headings get air, tables scroll inside themselves. */
.topic-body { max-width: none; }
.topic-body > * { max-width: 66ch; }
.topic-body h2 { font-size: 1.35rem; padding-top: 18px; }
.topic-body h3 { font: 760 1.05rem/1.25 var(--display); font-stretch: 106%; padding-top: 6px; }
.topic-body hr { border: 0; border-top: 1px solid var(--line); width: 100%; max-width: none; }
.topic-body pre { max-width: none; }
.prose table {
  display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.95rem;
}
.prose th, .prose td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); min-width: 9rem; }
.prose td:last-child { min-width: 15rem; }
.prose th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.prose a { color: var(--accent); text-underline-offset: 3px; }

.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card-list summary { justify-content: space-between; }
.card-q { font-weight: 600; }

.review-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.review-counts { display: flex; gap: 14px; color: var(--muted); font-weight: 600; }
.flashcard {
  display: grid; gap: 14px; padding: 22px 20px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); min-height: 9rem;
}
.card-question { font: 700 1.2rem/1.35 var(--display); font-stretch: 104%; }
.card-question code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-weight: 600; }
.card-rule { border: 0; border-top: 1px dashed var(--line); margin: 0; width: 100%; }
.grades { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.grade { flex-direction: column; gap: 4px; padding: 10px 6px; min-height: 60px; }
.grade-when { font: 600 0.8rem/1 var(--body); opacity: 0.8; }
.grade-again { color: var(--danger); }
@media (max-width: 420px) { .grades { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
