/* ---------- Fonts (self-hosted, SIL Open Font License; see /assets/fonts) ---------- */
@font-face { font-family: "Literata"; src: url("/assets/fonts/literata.woff2") format("woff2"); font-weight: 200 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Literata"; src: url("/assets/fonts/literata-italic.woff2") format("woff2"); font-weight: 200 900; font-style: italic; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("/assets/fonts/public-sans.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }

/* ---------- Tokens ---------- */
:root {
  --paper: #f3f6f8;
  --sheet: #ffffff;
  --ink: #15233f;
  --ink-2: #4b5b75;
  --ink-3: #6f7e94;
  --rule: #d3dce5;
  --rule-soft: #e6ecf1;
  --teal: #1c7a66;
  --teal-soft: #ddefea;
  --mark: #f6d04d;
  --mark-ink: #15233f;
  --red: #b4303f;
  --red-soft: #f8e3e5;
  --focus: #2f6fdb;
  --btn-bg: #15233f;
  --btn-ink: #ffffff;

  --serif: "Literata", Georgia, "Times New Roman", serif;
  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --s-1: 0.8125rem;   /* 13 */
  --s0: 1rem;         /* 16 */
  --s1: 1.1875rem;    /* 19 */
  --s2: 1.5rem;       /* 24 */
  --s3: 2.25rem;      /* 36 */
  --s4: 3.25rem;      /* 52 */

  --measure: 66ch;
  --page: 72rem;
  --radius: 6px;
  --radius-lg: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1729;
    --sheet: #152238;
    --ink: #e6edf5;
    --ink-2: #a9b7ca;
    --ink-3: #8696ad;
    --rule: #2b3b57;
    --rule-soft: #1e2d47;
    --teal: #5cc5ab;
    --teal-soft: #173a33;
    --mark: #e5c13d;
    --red: #f0828d;
    --red-soft: #3d1f27;
    --focus: #7aa7ff;
    --btn-bg: #e6edf5;
    --btn-ink: #0e1729;
  }
}
:root[data-theme="dark"] {
  --paper: #0e1729; --sheet: #152238; --ink: #e6edf5; --ink-2: #a9b7ca; --ink-3: #8696ad;
  --rule: #2b3b57; --rule-soft: #1e2d47; --teal: #5cc5ab; --teal-soft: #173a33; --mark: #e5c13d;
  --red: #f0828d; --red-soft: #3d1f27; --focus: #7aa7ff; --btn-bg: #e6edf5; --btn-ink: #0e1729;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--s0);
  line-height: 1.55;
  overflow-x: hidden;
}
img, svg { max-width: 100%; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 0.5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(2.1rem, 5.2vw, var(--s4)); }
h2 { font-size: clamp(1.6rem, 3.4vw, var(--s3)); }
h3 { font-size: var(--s2); }
p { margin: 0 0 1em; }
.lede { font-size: var(--s1); color: var(--ink-2); max-width: 46ch; }
.muted { color: var(--ink-2); }
.small { font-size: var(--s-1); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: var(--page); margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 32px; } }

/* The one bold device: a highlighter swipe behind computed results. */
.mark {
  background: linear-gradient(transparent 52%, var(--mark) 52%, var(--mark) 90%, transparent 90%);
  color: var(--mark-ink);
  padding: 0 0.15em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* ---------- Header / footer ---------- */
.site-header { border-bottom: 1px solid var(--rule); background: var(--paper); }
.site-header .wrap { display: flex; align-items: center; gap: 24px; min-height: 64px; flex-wrap: wrap; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.3rem; text-decoration: none; letter-spacing: -0.01em; }
.site-nav { display: flex; gap: 20px; margin-left: auto; flex-wrap: wrap; }
.site-nav a { text-decoration: none; color: var(--ink-2); font-weight: 500; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--ink); text-decoration: underline; }
.site-footer { border-top: 1px solid var(--rule); margin-top: 88px; padding: 32px 0 48px; color: var(--ink-2); font-size: var(--s-1); }
.site-footer .wrap { display: flex; gap: 16px 32px; flex-wrap: wrap; align-items: baseline; }
.site-footer nav { display: flex; gap: 16px; flex-wrap: wrap; }
.site-footer .note { flex-basis: 100%; }

/* ---------- Buttons and forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border-radius: var(--radius); border: 1.5px solid var(--btn-bg);
  background: var(--btn-bg); color: var(--btn-ink);
  font: 600 var(--s0)/1.2 var(--sans); text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn.secondary:hover { border-color: var(--ink-2); filter: none; }
.btn.quiet { background: transparent; color: var(--ink); border-color: transparent; padding-left: 10px; padding-right: 10px; }
.btn.quiet:hover { background: var(--rule-soft); filter: none; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn.listening { background: var(--red); border-color: var(--red); color: #fff; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

label { display: block; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 18px; }
.field .hint { font-weight: 400; color: var(--ink-2); font-size: var(--s-1); }
input[type="text"], input[type="email"], input[type="date"], input[type="password"], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1.5px solid var(--rule); border-radius: var(--radius);
  background: var(--sheet); color: var(--ink); font: var(--s0)/1.4 var(--sans);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 5px; width: 18px; height: 18px; flex: none; }
.status { padding: 12px 14px; border-radius: var(--radius); border-left: 4px solid var(--ink-3); background: var(--sheet); }
.status.ok { border-color: var(--teal); background: var(--teal-soft); }
.status.err { border-color: var(--red); background: var(--red-soft); }

/* ---------- Sections ---------- */
.section { padding-top: 72px; }
.section-head { max-width: var(--measure); margin-bottom: 28px; }
.rule-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.rule-list > li { border-bottom: 1px solid var(--rule); padding: 20px 0; }

/* ---------- Home ---------- */
.hero { padding-top: 56px; padding-bottom: 8px; }
.hero-grid { display: grid; gap: 40px; align-items: center; }
@media (min-width: 900px) { .hero-grid { grid-template-columns: 1fr 1.05fr; gap: 56px; } }
.hero h1 { max-width: 15ch; }
.hero .actions { margin-top: 28px; }

.sheet {
  background-color: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
}
/* Graph paper: a quiet dot grid behind worked math. */
.ruled {
  background-image: radial-gradient(circle, var(--rule) 1px, transparent 1.3px);
  background-size: 22px 22px;
  background-position: 11px 11px;
}
.demo { padding: 24px; }
.demo-q { font-family: var(--serif); font-size: var(--s1); margin-bottom: 18px; }
.demo-controls { display: grid; gap: 14px; grid-template-columns: 1fr; margin-bottom: 18px; }
@media (min-width: 520px) { .demo-controls { grid-template-columns: 1fr 1fr; } }
.demo-controls label { display: flex; justify-content: space-between; font-weight: 500; color: var(--ink-2); margin-bottom: 2px; }
.demo-controls output { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--teal); min-height: 28px; }
.demo-result { font-family: var(--serif); font-size: clamp(1.15rem, 2.6vw, 1.45rem); line-height: 1.6; font-variant-numeric: tabular-nums; }
.demo-note { margin: 14px 0 0; color: var(--ink-2); font-size: var(--s-1); }

.steps { list-style: none; counter-reset: step; padding: 0; margin: 0; display: grid; gap: 28px; }
@media (min-width: 820px) { .steps { grid-template-columns: repeat(3, 1fr); gap: 40px; } }
.steps li { counter-increment: step; }
.steps li::before {
  content: counter(step);
  display: inline-grid; place-items: center; width: 34px; height: 34px; margin-bottom: 10px;
  border: 1.5px solid var(--ink); border-radius: 50%;
  font: 700 var(--s0)/1 var(--serif);
}
.steps h3 { font-size: 1.25rem; margin-bottom: 6px; }

.path-row { display: grid; gap: 6px 24px; }
@media (min-width: 760px) { .path-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1.1fr); align-items: baseline; } }
.path-row h3 { margin: 0; font-size: 1.3rem; }
.path-row h3 a { text-decoration: none; }
.path-row h3 a:hover { text-decoration: underline; }
.path-meta { color: var(--ink-2); font-variant-numeric: tabular-nums; }

.split { display: grid; gap: 32px; }
@media (min-width: 860px) { .split { grid-template-columns: 1fr 1fr; gap: 56px; } }
.plain-list { padding-left: 1.2em; margin: 0; }
.plain-list li { margin-bottom: 8px; }

.cta-band { margin-top: 80px; padding-top: 40px; padding-bottom: 40px; border-top: 1px solid var(--rule); }
.cta-band + .site-footer, main:has(> .cta-band:last-child) + .site-footer { margin-top: 0; }

/* ---------- Path page ---------- */
.page-head { padding-top: 48px; padding-bottom: 8px; }
.facts { display: grid; gap: 4px 28px; grid-template-columns: max-content 1fr; margin: 24px 0; max-width: 40rem; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.price { font-family: var(--serif); font-size: var(--s3); font-weight: 600; }
.module-list { counter-reset: mod; }
.module-row { display: grid; gap: 8px 20px; grid-template-columns: 2.2rem 1fr; align-items: baseline; }
@media (min-width: 760px) { .module-row { grid-template-columns: 2.2rem 1fr 5rem auto; } }
.module-row .num { font-family: var(--serif); font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.module-row .hours { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.module-row .title { font-weight: 600; }
.module-row .blurb { display: block; font-weight: 400; color: var(--ink-2); }
.module-row .go { grid-column: 2 / -1; }
@media (min-width: 760px) { .module-row .go { grid-column: auto; } }
.tag { display: inline-block; font-size: var(--s-1); font-weight: 600; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--rule); color: var(--ink-2); white-space: nowrap; }
.tag.live { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }

/* ---------- Lecture room ---------- */
.room { display: grid; gap: 24px; padding: 24px 0 0; }
@media (min-width: 1000px) { .room { grid-template-columns: 15rem 1fr; gap: 32px; } }
.lesson-nav h2 { font-size: 1.1rem; font-family: var(--sans); margin-bottom: 10px; }
.lesson-nav ol { list-style: none; margin: 0; padding: 0; }
.lesson-nav li a { display: block; padding: 8px 10px; border-radius: var(--radius); text-decoration: none; color: var(--ink-2); }
.lesson-nav li a[aria-current="page"] { background: var(--sheet); color: var(--ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--ink); }
.lesson-nav li a:hover { color: var(--ink); background: var(--rule-soft); }
.lesson-nav .done::after { content: " ✓"; color: var(--teal); }

.lecture-title { margin-bottom: 4px; font-size: clamp(1.7rem, 3.6vw, 2.5rem); }
.board { position: relative; min-height: 22rem; padding: 28px 24px 32px; overflow-x: auto; }
@media (min-width: 720px) { .board { padding: 36px 44px; min-height: 26rem; } }
.board > * + * { margin-top: 20px; }
.board > :first-child { margin-top: 0; }
.board .b-heading { font-family: var(--serif); font-size: clamp(1.3rem, 2.8vw, 1.7rem); font-weight: 600; margin-bottom: 0; }
.board .b-note { font-size: var(--s1); color: var(--ink-2); max-width: 52ch; margin-bottom: 0; }
.board .b-formula { font-family: var(--serif); font-size: clamp(1.25rem, 3vw, 1.75rem); font-style: italic; margin-bottom: 0; }
.board .b-plug { font-family: var(--serif); font-size: clamp(1.05rem, 2.3vw, 1.3rem); font-variant-numeric: tabular-nums; margin-bottom: 0; }
.board .b-plug b { color: var(--mark-ink); font-weight: 700; background: linear-gradient(transparent 52%, var(--mark) 52%, var(--mark) 90%, transparent 90%); padding: 0 0.15em; }
.board .b-list { font-family: var(--serif); font-size: var(--s1); padding-left: 1.2em; margin-bottom: 0; }
.board .b-list li { margin-bottom: 6px; }
.board table { background: var(--sheet); border-collapse: collapse; font-variant-numeric: tabular-nums; min-width: 18rem; }
.board caption { text-align: left; font-weight: 600; padding-bottom: 8px; color: var(--ink-2); }
.board th, .board td { padding: 6px 16px 6px 0; text-align: right; border-bottom: 1px solid var(--rule); }
.board th:first-child, .board td:first-child { text-align: left; }
.board th { font-weight: 600; color: var(--ink-2); font-size: var(--s-1); }
.board .b-timeline { width: 100%; max-width: 40rem; height: auto; display: block; }
.board .appear { animation: appear 420ms ease-out both; }
@keyframes appear { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .board .appear { animation: none; } }

.caption-bar { margin-top: 14px; min-height: 4.8em; font-family: var(--serif); font-size: var(--s1); line-height: 1.55; max-width: 70ch; }
.caption-bar .who { font-family: var(--sans); font-weight: 700; font-size: var(--s-1); color: var(--ink-2); display: block; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule); }
.controls .progress { margin-left: auto; color: var(--ink-2); font-size: var(--s-1); font-variant-numeric: tabular-nums; }
.controls select { width: auto; min-height: 40px; padding: 6px 8px; }
.speed-label { font-weight: 500; color: var(--ink-2); margin: 0; display: inline-flex; gap: 6px; align-items: center; }

.checkpoint { margin-top: 18px; padding: 20px; border: 1.5px solid var(--ink); border-radius: var(--radius-lg); background: var(--sheet); }
.checkpoint h3 { font-family: var(--sans); font-size: var(--s0); margin-bottom: 6px; color: var(--ink-2); }
.checkpoint .q { font-family: var(--serif); font-size: var(--s1); }
.checkpoint .options { display: grid; gap: 8px; margin: 12px 0; }
.checkpoint .options .btn { justify-content: flex-start; text-align: left; }
.answer-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.answer-row input { flex: 1 1 12rem; width: auto; font-variant-numeric: tabular-nums; }
.feedback { margin-top: 12px; }

.ask-panel { margin-top: 24px; }
.ask-panel h2 { font-size: 1.25rem; }
.thread { display: grid; gap: 12px; margin-bottom: 14px; }
.msg { max-width: 62ch; padding: 12px 14px; border-radius: var(--radius-lg); line-height: 1.5; }
.msg.student { justify-self: end; background: var(--rule-soft); }
.msg.tutor { background: var(--sheet); border: 1px solid var(--rule); font-family: var(--serif); font-size: 1.06rem; }
.msg.tutor .who, .msg.student .who { display: block; font: 700 var(--s-1)/1.4 var(--sans); color: var(--ink-2); margin-bottom: 2px; }
.msg.thinking { color: var(--ink-2); font-style: italic; }
.msg .cite { font: 600 0.7em/1 var(--sans); color: var(--teal); margin-left: 1px; }
.msg .sources { display: block; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--rule-soft); font: 400 var(--s-1)/1.5 var(--sans); color: var(--ink-2); }
.msg .sources .source { display: block; }
.msg .sources .cite { margin-right: 4px; }
.ask-form { display: flex; gap: 8px; flex-wrap: wrap; }
.ask-form input { flex: 1 1 14rem; width: auto; }
.voice-note { font-size: var(--s-1); color: var(--ink-2); margin-top: 8px; }

/* ---------- Practice ---------- */
.practice-grid { display: grid; gap: 32px; padding-top: 24px; }
@media (min-width: 980px) { .practice-grid { grid-template-columns: 1fr 17rem; } }
.problem { padding: 28px 24px; }
@media (min-width: 720px) { .problem { padding: 36px 40px; } }
.problem .topic { color: var(--ink-2); font-weight: 600; margin-bottom: 8px; }
.problem .prompt { font-family: var(--serif); font-size: clamp(1.15rem, 2.4vw, 1.35rem); line-height: 1.55; max-width: 60ch; }
.solution { margin-top: 16px; font-family: var(--serif); font-variant-numeric: tabular-nums; }
.solution ol { padding-left: 1.3em; }
.mastery h2 { font-size: 1.1rem; font-family: var(--sans); }
.mastery ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.mastery .bar { height: 8px; border-radius: 99px; background: var(--rule-soft); overflow: hidden; margin-top: 4px; }
.mastery .bar span { display: block; height: 100%; background: var(--teal); border-radius: 99px; transition: width 300ms ease; }
.mastery .row { display: flex; justify-content: space-between; gap: 8px; font-size: var(--s-1); }
.mastery .row b { font-weight: 600; }
.score { margin-top: 18px; color: var(--ink-2); font-size: var(--s-1); }

/* ---------- Prose pages ---------- */
.prose { max-width: var(--measure); }
.prose h2 { font-size: var(--s2); margin-top: 1.8em; }
.prose li { margin-bottom: 6px; }
.form-card { padding: 28px 24px; max-width: 36rem; }
@media (min-width: 720px) { .form-card { padding: 32px; } }
.hp { position: absolute; left: -9999px; }

/* Dark mode: a half-height swipe leaves dark digits on a dark page, so use a full marker block. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mark,
  :root:not([data-theme="light"]) .board .b-plug b { background: var(--mark); border-radius: 3px; }
}
:root[data-theme="dark"] .mark,
:root[data-theme="dark"] .board .b-plug b { background: var(--mark); border-radius: 3px; }
