/* Layout: one narrow reading column (max 640px), sticky top bar, content as stacked panels.
   Type: Libre Caslon Text for headings and source passages (Caslon set the Declaration of
   Independence), Public Sans (the U.S. government's typeface) for UI, IBM Plex Mono for dates and tags. */
:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --ink: #18212e;
  --muted: #5a6577;
  --line: #d5dbe4;
  --accent: #1f4e8c;
  --accent-ink: #ffffff;
  --accent-soft: #dfe8f5;
  --brass: #8a6a1f;
  --good: #1d6b46;
  --good-soft: #dcefe4;
  --bad: #9b2c2c;
  --bad-soft: #f6e0e0;
  --paper: #f7f5ef;
  --shadow: 0 1px 2px rgba(24, 33, 46, .06), 0 4px 14px rgba(24, 33, 46, .06);

  --f-display: "Libre Caslon Text", "Iowan Old Style", Georgia, serif;
  --f-body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c; --surface: #18202b; --ink: #e5e9f0; --muted: #9aa5b6; --line: #2b3544;
    --accent: #8fb4ea; --accent-ink: #0f141c; --accent-soft: #1d2a3d; --brass: #d4b46a;
    --good: #7fd1a6; --good-soft: #17302a; --bad: #f0a0a0; --bad-soft: #3a1f22; --paper: #1c232e;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141c; --surface: #18202b; --ink: #e5e9f0; --muted: #9aa5b6; --line: #2b3544;
  --accent: #8fb4ea; --accent-ink: #0f141c; --accent-soft: #1d2a3d; --brass: #d4b46a;
  --good: #7fd1a6; --good-soft: #17302a; --bad: #f0a0a0; --bad-soft: #3a1f22; --paper: #1c232e;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--f-body);
  -webkit-text-size-adjust: 100%;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 10; background: var(--surface);
}
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 700; line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0; }

.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.bar-in { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 10px; min-height: 52px; }
.bar-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title small { display: block; font: 500 .72rem/1.2 var(--f-mono); color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.back {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  width: 36px; height: 36px; display: grid; place-items: center; flex: none; font-size: 1.1rem;
}

main {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 48px;
}
.wrap { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.eyebrow { font: 500 .72rem/1.2 var(--f-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.lede { color: var(--muted); max-width: 60ch; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }

/* Course and unit lists */
.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 14px; align-items: center;
  padding: 14px 16px; border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left; width: 100%;
}
.item:first-child { border-top: 0; }
.item:disabled { cursor: default; opacity: .55; }
.item:not(:disabled):hover { background: var(--accent-soft); }
.item .num { font: 600 .82rem var(--f-mono); color: var(--brass); width: 2.2em; }
.item .meta { min-width: 0; }
.item .t { font-weight: 600; display: block; }
.item .s { font-size: .85rem; color: var(--muted); display: block; }
.item .end { font: 500 .78rem var(--f-mono); color: var(--muted); text-align: right; }
.meter { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--accent); }

/* Mode tiles */
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.mode {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r);
  padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 108px;
}
.mode:hover { border-color: var(--accent); }
.mode .t { font-weight: 700; }
.mode .s { font-size: .84rem; color: var(--muted); flex: 1; }
.mode .c { font: 500 .76rem var(--f-mono); color: var(--accent); }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 10px 18px; font-weight: 600; min-height: 44px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.btn.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.btn.wide { flex: 1; }
.btn:disabled { opacity: .5; cursor: default; }

/* Flashcard */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 22px 20px; min-height: 260px; display: flex; flex-direction: column; gap: 12px; text-align: left; width: 100%;
}
.card .front { font-family: var(--f-display); font-size: 1.45rem; line-height: 1.25; text-wrap: balance; flex: 1; display: flex; align-items: center; }
.card .hint { font-size: .82rem; color: var(--muted); }
.card .answer { font-size: 1rem; }
.card .why { border-top: 1px solid var(--line); padding-top: 10px; font-size: .92rem; color: var(--muted); }
.card .why b { color: var(--ink); }
.tag { display: inline-block; font: 500 .72rem var(--f-mono); color: var(--brass); letter-spacing: .03em; }
.progress { font: 500 .8rem var(--f-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.dots { display: flex; gap: 4px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--brass); }

/* Stimulus */
.stim { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.stim .body { font-family: var(--f-display); font-size: 1rem; line-height: 1.6; }
.stim .body p + p { margin-top: .7em; }
.stim .src { font-size: .8rem; color: var(--muted); }
.stim table { border-collapse: collapse; width: 100%; font-size: .9rem; font-variant-numeric: tabular-nums; }
.stim th, .stim td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.stim th { font-size: .78rem; color: var(--muted); font-weight: 600; }
.scroll { overflow-x: auto; }
.chart svg { width: 100%; height: auto; display: block; }

/* MCQ */
.q { font-weight: 600; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 12px 14px;
  text-align: left; display: grid; grid-template-columns: auto 1fr; gap: 10px; width: 100%;
}
.choice .l { font: 600 .9rem var(--f-mono); color: var(--muted); }
.choice:not(:disabled):hover { border-color: var(--accent); }
.choice:disabled { cursor: default; }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice .why { grid-column: 2; font-size: .88rem; color: var(--muted); }
.choice.right .why, .choice.wrong .why { color: var(--ink); }
.verdict { font-weight: 700; }
.verdict.ok { color: var(--good); }
.verdict.no { color: var(--bad); }
.skill { font-size: .8rem; color: var(--muted); }

/* SAQ / essay */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
textarea { width: 100%; min-height: 120px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 10px 12px; resize: vertical; line-height: 1.5; }
.checks { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.checks label { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; font-size: .94rem; }
.checks input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }
.bullets { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 6px; font-size: .94rem; }
.score { font: 600 .9rem var(--f-mono); color: var(--accent); }
.note { font-size: .82rem; color: var(--muted); border-left: 3px solid var(--line); padding-left: 10px; }
.done { text-align: center; padding: 28px 16px; }
.done .big { font-family: var(--f-display); font-size: 2.4rem; color: var(--accent); }
footer.foot { font-size: .76rem; color: var(--muted); max-width: 640px; margin: 8px auto 0; }

@media (max-width: 380px) { .modes { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: no-preference) {
  .card, .choice, .mode, .item { transition: background-color .15s, border-color .15s; }
}

/* Guided session, steps, timed round */
.item.plain { grid-template-columns: 1fr auto; }
.panel.hero { border-color: var(--accent); }
.steps { display: flex; gap: 6px; }
.step { flex: 1; border-top: 3px solid var(--line); padding-top: 4px; font: 500 .72rem var(--f-mono); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.step.done { border-top-color: var(--accent); color: var(--ink); }
.step.now { border-top-color: var(--brass); color: var(--ink); }
.btn.two { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; line-height: 1.2; min-height: 56px; }
.btn small { font-weight: 400; font-size: .72rem; opacity: .9; }
.strength { display: flex; align-items: center; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stats .big { font-size: 1.9rem; }
.big2 { font-family: var(--f-display); font-size: 1.6rem; color: var(--accent); margin: 0; }
.timer { display: flex; flex-direction: column; gap: 8px; }
.tbar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.tbar i { display: block; height: 100%; width: 100%; background: var(--accent); transition: width .15s linear; }
.def { font-family: var(--f-display); font-size: 1.1rem; line-height: 1.5; }
.steps .step { text-align: left; }

/* Feedback */
.fb { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 12px; font: 600 .8rem var(--f-body); min-height: 36px; flex: none; }
.fb:hover { border-color: var(--accent); }
.sheet-back {
  position: fixed; inset: 0; z-index: 20; background: rgba(12, 17, 25, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); color: var(--ink); width: 100%; max-width: 640px; max-height: 92%; overflow-y: auto;
  border-radius: 16px 16px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 8px 14px; font-size: .88rem; min-height: 40px; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }
.chk { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; font-size: .88rem; color: var(--muted); }
.chk input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); }
.chk b { color: var(--ink); font-weight: 600; }
.sheet textarea { min-height: 110px; }
