@font-face {
  font-family: "Source Serif 4";
  src: url("/fonts/source-serif-4-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Serif 4";
  src: url("/fonts/source-serif-4-latin-wght-italic.woff2") format("woff2");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
}

:root {
  --paper: #fbfaf7;
  --paper-raised: #ffffff;
  --listing: #f3f0e8;
  --ink: #1f1d1a;
  --ink-2: #57514a;
  --ink-3: #7d766b;
  --rule: #e4ded2;
  --rule-strong: #cfc7b8;
  --accent: #8c2b2b;
  --accent-ink: #ffffff;
  --accent-wash: #f4e8e4;
  --right: #24683f;
  --right-wash: #e7f1ea;
  --wrong: #a3302b;
  --wrong-wash: #f7e6e3;
  --tok-keyword: #8c2b2b;
  --tok-string: #3b6b3b;
  --tok-symbol: #5a4a9e;
  --tok-constant: #845a0f;
  --tok-number: #845a0f;
  --tok-comment: #8a8273;
  --tok-method: #1f5a85;
  --tok-ivar: #7a3f6e;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --body-w: 680px;
  --margin-w: 288px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171614;
    --paper-raised: #1f1d1a;
    --listing: #22201c;
    --ink: #ece7dd;
    --ink-2: #b9b1a4;
    --ink-3: #8f877a;
    --rule: #2f2c27;
    --rule-strong: #45413a;
    --accent: #e08a7e;
    --accent-ink: #171614;
    --accent-wash: #33211e;
    --right: #7fc795;
    --right-wash: #1b2b20;
    --wrong: #f08f86;
    --wrong-wash: #33201e;
    --tok-keyword: #e59a8f;
    --tok-string: #9ccc8f;
    --tok-symbol: #b9a7f0;
    --tok-constant: #e3b66b;
    --tok-number: #e3b66b;
    --tok-comment: #857d70;
    --tok-method: #8fc0e8;
    --tok-ivar: #dba3cf;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 18px/1.6 var(--serif);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-wash); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--listing);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  overflow-wrap: anywhere;
}

/* Top bar */
.bar {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 0 40px;
  height: 56px;
  border-bottom: 1px solid var(--rule);
  font: 14px/1 var(--sans);
  color: var(--ink-2);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 2;
}
.brand { color: var(--ink); font: 600 17px/1 var(--serif); text-decoration: none; letter-spacing: -0.01em; }
.views { display: flex; gap: 4px; margin-right: auto; }
.view-link {
  border: 0;
  background: none;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
a.view-link { text-decoration: none; }
.view-link:hover { color: var(--ink); background: var(--listing); }
.view-link[aria-current="page"] { color: var(--ink); font-weight: 600; }
.count {
  font: 500 12px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.count:empty { display: none; }
.quiet { border: 0; background: none; color: var(--ink-3); padding: 8px 4px; }
.quiet:hover { color: var(--ink); }
.signout { margin: 0; }

.session-rule { height: 2px; background: transparent; }
.session-rule span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 400ms cubic-bezier(0.16, 1, 0.3, 1); }

/* Page: reading column plus margin */
.page {
  display: grid;
  grid-template-columns: minmax(0, var(--body-w)) var(--margin-w);
  gap: 0 56px;
  justify-content: center;
  padding: 56px 40px 96px;
}
.body { min-width: 0; }
.margin { font: 14px/1.55 var(--sans); color: var(--ink-2); padding-top: 4px; }
.margin > * + * { margin-top: 20px; }

.folio {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font: 13px/1.4 var(--sans);
  color: var(--ink-3);
  margin: 0 0 14px;
}
.folio .topic { color: var(--accent); font-weight: 600; }
.folio .pos { font-variant-numeric: tabular-nums; }

.title { font-size: 34px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 28px; }
.question {
  font-size: 26px;
  line-height: 1.35;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 28px;
  text-wrap: pretty;
  white-space: pre-line;
}
.question code { font-size: 0.78em; font-weight: 500; }

/* Code listing */
.listing {
  margin: 0 0 32px;
  background: var(--listing);
  border-radius: 8px;
  padding: 16px 0;
  overflow-x: auto;
  font: 14px/1.65 var(--mono);
  font-variant-ligatures: none;
  tab-size: 2;
}
.listing code { background: none; padding: 0; font-size: inherit; display: block; min-width: max-content; }
.line { display: block; padding: 0 20px 0 0; }
.ln {
  display: inline-block;
  width: 3.2em;
  padding-right: 1.2em;
  text-align: right;
  color: var(--ink-3);
  opacity: 0.7;
  user-select: none;
  font-variant-numeric: tabular-nums;
}
.tok-keyword { color: var(--tok-keyword); font-weight: 600; }
.tok-string { color: var(--tok-string); }
.tok-symbol { color: var(--tok-symbol); }
.tok-constant { color: var(--tok-constant); }
.tok-number { color: var(--tok-number); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-method, .tok-method-def { color: var(--tok-method); }
.tok-method-def { font-weight: 600; }
.tok-ivar { color: var(--tok-ivar); }

/* Choices */
.choices { list-style: none; margin: 0 0 32px; padding: 0; display: grid; gap: 2px; }
.choice {
  width: 100%;
  display: grid;
  grid-template-columns: 2em 1fr 20px;
  gap: 4px;
  align-items: start;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: none;
  padding: 12px 14px 12px 8px;
  line-height: 1.5;
  transition: background-color 120ms ease;
}
.choice:hover:not(:disabled) { background: var(--listing); }
.choice .num { font: 500 14px/1.9 var(--mono); color: var(--ink-3); text-align: center; font-variant-numeric: tabular-nums; }
.choice .mark { width: 20px; height: 20px; margin-top: 3px; }
.choice:disabled { cursor: default; color: var(--ink-3); }
.choice.is-right { background: var(--right-wash); color: var(--ink); }
.choice.is-right .num, .choice.is-right .mark { color: var(--right); }
.choice.is-wrong { background: var(--wrong-wash); color: var(--ink); }
.choice.is-wrong .num, .choice.is-wrong .mark { color: var(--wrong); }
.choice.is-wrong .text { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--wrong) 60%, transparent); }

/* Open answer */
.attempt { margin: 0 0 24px; }
.attempt textarea {
  width: 100%;
  min-height: 7.5em;
  resize: vertical;
  border: 0;
  border-bottom: 1px solid var(--rule-strong);
  background: none;
  padding: 4px 0 8px;
  line-height: 1.6;
}
.attempt textarea:focus { outline: none; border-bottom-color: var(--accent); }
.attempt textarea::placeholder { color: var(--ink-3); font-style: italic; }

/* Margin notes */
.note { margin: 0; }
.note-head { font: 600 13px/1.4 var(--sans); color: var(--ink); margin: 0 0 6px; }
.verdict { display: flex; align-items: center; gap: 8px; font: 600 15px/1.3 var(--sans); }
.verdict svg { width: 18px; height: 18px; }
.verdict.right { color: var(--right); }
.verdict.wrong { color: var(--wrong); }
.explanation { font: 16px/1.6 var(--serif); color: var(--ink); white-space: pre-line; }
.explanation code { font-size: 0.8em; }
.refs { list-style: none; margin: 0; padding: 12px 0 0; border-top: 1px solid var(--rule); display: grid; gap: 6px; }
.refs li { font: 12.5px/1.45 var(--mono); color: var(--ink-2); overflow-wrap: anywhere; }
.meta-list { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.meta-list dt { color: var(--ink-3); }
.meta-list dd { margin: 0; font-variant-numeric: tabular-nums; }
.keys { color: var(--ink-3); }
kbd {
  font: 500 11.5px/1 var(--mono);
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 5px;
  color: var(--ink-2);
  background: var(--paper-raised);
}

/* Buttons */
.primary, .secondary {
  font: 500 15px/1 var(--sans);
  border-radius: 8px;
  padding: 11px 18px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { filter: brightness(1.08); }
.secondary { background: var(--paper-raised); border-color: var(--rule-strong); color: var(--ink); }
.secondary:hover { border-color: var(--ink-3); }
.primary kbd { background: transparent; color: inherit; border-color: color-mix(in srgb, currentColor 45%, transparent); }

.grades { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-top: 24px; border-top: 1px solid var(--rule); }
.grades .hint { font: 13px/1.4 var(--sans); color: var(--ink-3); margin-left: auto; }
.grade { display: grid; gap: 4px; justify-items: start; text-align: left; padding: 10px 16px; }
.grade small { font: 12px/1 var(--sans); opacity: 0.75; }

.inline-answer { display: none; margin: 0 0 28px; }

/* Empty state */
.rest { padding-top: 24px; }
.rest p { color: var(--ink-2); max-width: 52ch; }

/* Progress: table of contents */
.summary { font-size: 19px; color: var(--ink-2); margin: 0 0 40px; max-width: 58ch; }
.summary strong { color: var(--ink); font-weight: 600; }
.toc { list-style: none; margin: 0 0 48px; padding: 0; }
.toc li { display: flex; align-items: baseline; gap: 10px; padding: 10px 0; }
.toc .name { font-weight: 600; }
.toc .leader { flex: 1; border-bottom: 1px dotted var(--rule-strong); transform: translateY(-5px); min-width: 24px; }
.toc .figs { font: 14px/1 var(--mono); font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.toc .figs b { color: var(--ink); font-weight: 600; }
.known { height: 2px; background: color-mix(in srgb, var(--rule) 70%, transparent); border-radius: 2px; margin-top: -4px; overflow: hidden; }
.known span { display: block; height: 100%; background: var(--right); }
.section-head { font-size: 20px; font-weight: 600; margin: 0 0 14px; }
.missed { margin: 0; padding-left: 1.2em; }
.missed li { margin-bottom: 10px; }
.missed .times { font: 13px var(--mono); color: var(--wrong); margin-left: 6px; white-space: nowrap; }
.figure { font: 600 28px/1.1 var(--serif); color: var(--ink); font-variant-numeric: tabular-nums; display: block; margin-bottom: 2px; }
.stat + .note { padding-top: 16px; border-top: 1px solid var(--rule); }

/* Browse: index entries */
.entry { border-bottom: 1px solid var(--rule); }
.entry summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  grid-template-columns: 4.6em 1fr;
  gap: 12px;
  padding: 14px 0;
  line-height: 1.45;
}
.entry summary::-webkit-details-marker { display: none; }
.entry summary:hover .prompt { color: var(--accent); }
.entry .cid { font: 12.5px/1.9 var(--mono); color: var(--ink-3); }
.entry[open] summary .prompt { font-weight: 600; }
.entry .inner { padding: 4px 0 24px 5.35em; }
.entry .inner .listing { margin-bottom: 20px; }
.entry ol { padding-left: 1.2em; margin: 0 0 16px; }
.entry ol li.answer { color: var(--right); font-weight: 600; }
.entry .state { font: 13px var(--sans); color: var(--ink-3); margin: 12px 0 0; }
.entry .explanation { margin: 0 0 12px; }
.empty-list { color: var(--ink-3); padding: 24px 0; }

/* Forms */
.form { display: grid; gap: 22px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0 0 24px; min-width: 0; }
.form .field { margin: 0; }
.label { font: 500 13px/1.3 var(--sans); color: var(--ink-2); padding: 0; }
input[type="search"], input[type="text"], select, textarea {
  width: 100%;
  background: var(--paper-raised);
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  padding: 10px 12px;
  font: 16px/1.5 var(--sans);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
textarea.mono { font: 14px/1.6 var(--mono); }
.choice-input { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; margin-bottom: 8px; }
.choice-input input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.actions { display: flex; align-items: center; gap: 16px; }
.status { font: 14px var(--sans); color: var(--ink-2); }
.status.error { color: var(--wrong); }

/* Login: a title page */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.title-page { width: 100%; max-width: 380px; }
.title-page h1 { font-size: 40px; line-height: 1.1; letter-spacing: -0.02em; margin: 0 0 8px; }
.title-page .sub { color: var(--ink-2); margin: 0 0 36px; font-style: italic; }
.title-page form { display: grid; gap: 16px; }
.title-page .field { margin: 0; }
.title-page input { font: 16px var(--sans); padding: 11px 12px; width: 100%; border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--paper-raised); }
.title-page .primary { justify-content: center; }
.error { color: var(--wrong); font: 14px var(--sans); margin: 0 0 4px; }

/* Narrow: the margin folds under the reading column */
@media (max-width: 1080px) {
  .page { grid-template-columns: minmax(0, var(--body-w)); padding: 40px 24px 80px; }
  .margin { padding-top: 0; }
  #review-margin { order: 2; border-top: 1px solid var(--rule); padding-top: 24px; margin-top: 8px; }
  #review-margin .verdict, #review-margin .explanation, #review-margin .refs { display: none; }
  .inline-answer { display: block; }
}
@media (max-width: 640px) {
  body { font-size: 17px; }
  .bar { gap: 12px; padding: 0 16px; height: auto; min-height: 52px; flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
  .views { order: 3; width: 100%; overflow-x: auto; margin: 0 -8px; }
  .page { padding: 28px 16px 64px; }
  .question { font-size: 21px; }
  .title { font-size: 28px; }
  .listing { margin-left: -16px; margin-right: -16px; border-radius: 0; font-size: 13px; }
  .pair { grid-template-columns: 1fr; }
  .grades .hint { display: none; }
  .grade { flex: 1 1 calc(50% - 8px); }
  .entry .inner { padding-left: 0; }
  .choice { grid-template-columns: 1.5em 1fr 20px; padding-left: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.refs .dir { display: block; color: var(--ink-3); font-size: 11.5px; }
.refs .file { color: var(--ink); }
.refs .lines { color: var(--accent); }

/* Server-rendered widths: CSP forbids inline styles, so bars snap to 5% steps. */
.session-rule span, .known span { width: 0; }
.fill-0 { width: 0%; }
.fill-5 { width: 5%; }
.fill-10 { width: 10%; }
.fill-15 { width: 15%; }
.fill-20 { width: 20%; }
.fill-25 { width: 25%; }
.fill-30 { width: 30%; }
.fill-35 { width: 35%; }
.fill-40 { width: 40%; }
.fill-45 { width: 45%; }
.fill-50 { width: 50%; }
.fill-55 { width: 55%; }
.fill-60 { width: 60%; }
.fill-65 { width: 65%; }
.fill-70 { width: 70%; }
.fill-75 { width: 75%; }
.fill-80 { width: 80%; }
.fill-85 { width: 85%; }
.fill-90 { width: 90%; }
.fill-95 { width: 95%; }
.fill-100 { width: 100%; }
.toc li.wrap { flex-wrap: wrap; }
.toc li.wrap .known { flex-basis: 100%; }

/* The add form shows choices only for multiple choice, without script. */
.add-form .choices-field { display: none; }
.add-form:has(.type-select option[value="mcq"]:checked) .choices-field { display: grid; }
.topic-filter { margin: 0; }
.search { margin: 0; }
.entry form { margin: 12px 0 0; }

/* API access */
.token-created { border: 1px solid var(--rule-strong); border-radius: 8px; padding: 20px; margin: 0 0 40px; background: var(--paper-raised); }
.token-created .secret { font-size: 13px; user-select: all; }
.instructions { font-size: 12.5px; white-space: pre; padding: 16px 20px; margin: 0 0 12px; }
.scope { display: flex; gap: 10px; align-items: baseline; font: 15px/1.5 var(--sans); padding: 4px 0; }
.scope input { accent-color: var(--accent); }
.tokens-head { margin-top: 48px; }
.token-list { list-style: none; margin: 0; padding: 0; }
.token-list li { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.token-list .state { display: block; font: 13px var(--sans); color: var(--ink-3); }
.token-list form { margin: 0; }
