/*  Large Language Models from the Beginning — design system
    ---------------------------------------------------------
    The Curionode editorial look: warm paper, Fraunces for display, Source
    Serif for prose, JetBrains Mono for numbers and tokens. A plate is a
    title, a lede, a workshop (panels on the left, controls and readings on
    the right), the prose, terms, try-its and the ten-question check.

    Colours are tokens; canvases read the --fig-* ones through js/figure.js.
    The dark values are written twice, once for a system preference and once
    for an explicit choice; tools/build.py fails if the two copies differ.
*/
@import url('../vendor/fonts/fonts.css');

:root {
    --paper: #faf7f1;  --paper-deep: #f2ece0;  --paper-rule: #e2d9c6;
    --ink: #1b1b20;  --ink-soft: #393940;  --ink-mute: #6b6b73;  --ink-faint: #99948a;
    --accent: #2f4fb3;  --accent-tint: #e5eaf7;  --red: #b4352f;  --red-tint: #f5e6e2;  --green: #2d6a4f;  --green-tint: #e0ede4;  --ochre: #b3791f;  --ochre-tint: #f4e6c8;
    --input: #fffefb;
    --fig-paper: #fffdf8;  --fig-grid: #d3cab6;  --fig-rule: #e8e0cf;  --fig-ink: #1b1b20;  --fig-muted: #6b6b73;  --fig-faint: #a39e93;
    --fig-blue: #2f4fb3;  --fig-red: #b4352f;  --fig-green: #2d6a4f;  --fig-teal: #0f6e6a;  --fig-plum: #6a3d8a;  --fig-ochre: #b3791f;  --fig-sienna: #a8530c;  --fig-olive: #5a5a1c;
    --shadow: 0 2px 6px rgba(27, 27, 32, 0.06);
    --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
    --font-body: 'Source Serif 4', 'Iowan Old Style', Georgia, 'Songti SC', 'Noto Serif CJK SC', serif;
    --font-mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
    --paper: #14141a;  --paper-deep: #1c1c24;  --paper-rule: #34343f;
    --ink: #e9e6de;  --ink-soft: #c6c2b8;  --ink-mute: #9893a0;  --ink-faint: #706c78;
    --accent: #8ea6f2;  --accent-tint: #1f2742;  --red: #e2726b;  --red-tint: #3a2120;  --green: #6cba8e;  --green-tint: #1a3026;  --ochre: #e2b257;  --ochre-tint: #3b3017;
    --input: #1a1a21;
    --fig-paper: #17171e;  --fig-grid: #3a3a46;  --fig-rule: #2a2a33;  --fig-ink: #e9e6de;  --fig-muted: #9893a0;  --fig-faint: #6e6a76;
    --fig-blue: #8ea6f2;  --fig-red: #e2726b;  --fig-green: #6cba8e;  --fig-teal: #4fb5ae;  --fig-plum: #bb95dc;  --fig-ochre: #e2b257;  --fig-sienna: #e28c48;  --fig-olive: #b8b86a;
    --shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    }
}
:root[data-theme="dark"] {
    --paper: #14141a;  --paper-deep: #1c1c24;  --paper-rule: #34343f;
    --ink: #e9e6de;  --ink-soft: #c6c2b8;  --ink-mute: #9893a0;  --ink-faint: #706c78;
    --accent: #8ea6f2;  --accent-tint: #1f2742;  --red: #e2726b;  --red-tint: #3a2120;  --green: #6cba8e;  --green-tint: #1a3026;  --ochre: #e2b257;  --ochre-tint: #3b3017;
    --input: #1a1a21;
    --fig-paper: #17171e;  --fig-grid: #3a3a46;  --fig-rule: #2a2a33;  --fig-ink: #e9e6de;  --fig-muted: #9893a0;  --fig-faint: #6e6a76;
    --fig-blue: #8ea6f2;  --fig-red: #e2726b;  --fig-green: #6cba8e;  --fig-teal: #4fb5ae;  --fig-plum: #bb95dc;  --fig-ochre: #e2b257;  --fig-sienna: #e28c48;  --fig-olive: #b8b86a;
    --shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* ─── Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.64 var(--font-body); font-optical-sizing: auto; }
::selection { background: var(--ochre-tint); }
a { color: var(--accent); text-underline-offset: 2px; }
code, kbd, .mono { font-family: var(--font-mono); font-size: 0.86em; }
p code, li code, dd code, .prose code, .lede code, .marginalia code, .try-q code, .quiz-q code { background: var(--paper-deep); border: 1px solid var(--paper-rule); border-radius: 3px; padding: 0 0.28em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
sub, sup { line-height: 0; }
.btn { border: 1px solid var(--ink-soft); background: var(--ink); color: var(--paper); padding: 5px 14px; border-radius: 3px; cursor: pointer; font: 13px var(--font-mono); }
.btn:hover { background: var(--ink-soft); }
.btn-quiet { background: transparent; color: var(--ink-soft); border-color: var(--paper-rule); }
.btn-quiet:hover { background: var(--paper-deep); }

/* ─── Top bar ──────────────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 20px; background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--paper-rule); font: 13px var(--font-mono); }
.topbar a { color: var(--ink-soft); text-decoration: none; }
.topbar a:hover { color: var(--accent); }
.topbar-left { display: flex; gap: 14px; align-items: center; min-width: 0; }
.topbar-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-mute); }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.lang-btn, .theme-btn { border: 1px solid var(--paper-rule); background: var(--paper); border-radius: 3px; padding: 2px 10px; cursor: pointer; font: 13px var(--font-mono); color: var(--ink-soft); }

/* ─── Plate ────────────────────────────────────────────────── */
.main-content { max-width: 1120px; margin: 0 auto; padding: 26px 28px 60px; }
.plate-meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font: 12.5px var(--font-mono); color: var(--ink-mute); border-bottom: 2px solid var(--ink); padding-bottom: 6px; }
.thread { display: inline-block; margin-left: 6px; padding: 0 6px; border: 1px solid var(--ink-faint); border-radius: 2px; font-size: 11px; color: var(--ink-soft); }
.plate-title { font: 400 44px/1.1 var(--font-display); letter-spacing: -0.01em; margin: 22px 0 8px; }
.plate-title em { color: var(--accent); font-style: italic; }
.plate-deck { font: italic 20px/1.45 var(--font-body); color: var(--ink-soft); margin: 0 0 20px; max-width: 46em; }
.lede { border-left: 3px solid var(--accent); padding: 2px 0 2px 18px; margin: 18px 0; max-width: 48em; }
.lede p { margin: 0 0 10px; }
.lede .preview { color: var(--ink-mute); font-size: 15.5px; }
.formula-group { display: flex; flex-wrap: wrap; gap: 6px 30px; justify-content: center; margin: 16px 0; overflow-x: auto; }
.formula { min-height: 1.6em; }
.learning-objectives { background: var(--paper-deep); border: 1px solid var(--paper-rule); padding: 12px 18px; border-radius: 3px; margin: 18px 0; max-width: 48em; }
.learning-objectives-title, .section-title { font: 600 11px/1 var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); margin: 6px 0 10px; }
.learning-objectives ul { margin: 0; padding-left: 20px; }
.figure { margin: 10px 0 24px; }
.figure-caption { font-size: 14.5px; color: var(--ink-mute); margin-top: 8px; max-width: 52em; }
h2 { font: 400 27px/1.2 var(--font-display); margin: 34px 0 10px; }
.prose { max-width: 46em; }
.prose p { margin: 0 0 14px; }
.marginalia { font-size: 15px; color: var(--ink-mute); border-top: 1px solid var(--paper-rule); border-bottom: 1px solid var(--paper-rule); padding: 10px 0; margin: 20px 0; max-width: 46em; font-style: italic; }
.terms { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; max-width: 50em; margin: 0; }
.terms dt { font-weight: 600; }
.terms dd { margin: 0; color: var(--ink-soft); }
.key-idea { background: var(--accent-tint); border-radius: 3px; padding: 12px 18px; margin: 24px 0; max-width: 48em; }
.sources { font-size: 14px; color: var(--ink-mute); max-width: 50em; }
.sources li { margin-bottom: 4px; }
.closer { border: 1px solid var(--paper-rule); border-radius: 3px; padding: 6px 16px; margin: 20px 0; max-width: 48em; }
.closer summary { cursor: pointer; font: 600 12px var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-mute); padding: 6px 0; }
.asof { display: inline-block; font: 12px var(--font-mono); color: var(--red); border: 1px solid var(--red); border-radius: 2px; padding: 0 6px; margin-left: 8px; }
.plate-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; padding-top: 14px; border-top: 2px solid var(--ink); font: 14px var(--font-mono); }
.plate-nav a { text-decoration: none; }
.plate-footer { display: flex; gap: 18px; flex-wrap: wrap; justify-content: space-between; font: 12.5px var(--font-mono); color: var(--ink-faint); margin-top: 18px; }
.plate-footer a { color: var(--ink-mute); }

/* ─── Workshop ─────────────────────────────────────────────── */
.workshop { display: grid; grid-template-columns: minmax(0, 1fr) 260px; border: 1px solid var(--paper-rule); background: var(--fig-paper); border-radius: 3px; }
.ws-stage { position: relative; display: flex; flex-wrap: wrap; align-content: flex-start; border-right: 1px solid var(--paper-rule); min-width: 0; }
.ws-panel { min-width: 240px; padding: 6px; }
.ws-panel canvas { display: block; }
.ws-panel-title { font: 600 11px var(--font-mono); color: var(--ink-mute); padding: 2px 4px 4px; letter-spacing: 0.04em; }
.ws-rail { padding: 10px 14px; font: 12.5px/1.45 var(--font-mono); background: var(--paper); min-width: 0; }
.ws-controls { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.ws-ctl { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; color: var(--ink-mute); }
.ws-ctl input[type="range"], .ws-ctl select, .ws-ctl input[type="text"], .ws-ctl textarea { grid-column: 1 / -1; width: 100%; }
.ws-ctl select, .ws-ctl input[type="text"], .ws-ctl textarea { border: 1px solid var(--paper-rule); background: var(--input); border-radius: 3px; padding: 3px 6px; font: 13px var(--font-mono); }
.ws-ctl textarea { resize: vertical; }
.ws-val { color: var(--ink); font-weight: 500; text-align: right; }
.ws-check { grid-template-columns: auto 1fr; cursor: pointer; }
.ws-button .btn { width: 100%; }
.ws-reset { align-self: flex-start; padding: 2px 10px; font-size: 11.5px; }
.rail-stats { border-top: 1px solid var(--paper-rule); padding-top: 10px; display: flex; flex-direction: column; gap: 5px; }
.rail-stats .stat { display: flex; justify-content: space-between; gap: 10px; }
.stat-k { color: var(--ink-mute); }
.stat-v { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ws-note { padding: 10px 14px; border: 1px solid var(--paper-rule); border-top: none; background: var(--paper); font: 15px/1.55 var(--font-body); color: var(--ink-soft); border-radius: 0 0 3px 3px; }
.ws-note:empty { display: none; }
.ws-error { display: none; padding: 8px 14px; background: var(--red-tint); color: var(--red); font: 13px var(--font-mono); }

/* ─── Try-its, drills, projects ────────────────────────────── */
.try-block { margin: 20px 0; max-width: 50em; }
.try { border: 1px solid var(--paper-rule); border-radius: 3px; padding: 10px 14px; margin-bottom: 10px; background: var(--paper); }
.try-q { margin-bottom: 8px; }
.try-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.try-opt { border: 1px solid var(--paper-rule); background: var(--input); border-radius: 3px; padding: 4px 12px; cursor: pointer; font-size: 15px; text-align: left; }
.try-opt:hover:not(:disabled) { border-color: var(--accent); }
.try-opt.right { background: var(--green-tint); border-color: var(--green); }
.try-opt.wrong { background: var(--red-tint); border-color: var(--red); }
.try-why { margin-top: 8px; font-size: 15px; color: var(--ink-soft); }
.try-src { font: 11.5px var(--font-mono); color: var(--ink-faint); }
.drill-head { font: 13px var(--font-mono); color: var(--ink-mute); margin-bottom: 10px; }
.project-box { border: 2px solid var(--ink); border-radius: 3px; padding: 10px 16px; margin: 16px 0; }
.brief { list-style: none; padding: 0; margin: 0 0 10px; font: 14px var(--font-mono); }
.brief li.ok { color: var(--green); }
.brief li.no { color: var(--red); }
.verdict { font-weight: 600; }
.verdict.pass { color: var(--green); }
.verdict.fail { color: var(--ink-mute); }
.journey-sum { font: 14px var(--font-mono); margin-bottom: 14px; }
.journey-vol { display: grid; grid-template-columns: 300px 1fr; gap: 10px; align-items: center; margin-bottom: 6px; }
.journey-name { font-size: 14px; text-decoration: none; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.journey-cells { display: flex; gap: 3px; flex-wrap: wrap; }
.jcell { width: 18px; height: 18px; border: 1px solid var(--paper-rule); background: var(--paper); border-radius: 2px; }
.jcell.seen { background: var(--accent-tint); border-color: var(--accent); }
.jcell.passed { background: var(--accent); }

/* ─── Knowledge check ──────────────────────────────────────── */
.quiz { margin-top: 36px; max-width: 50em; }
.quiz-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--ink); margin-bottom: 12px; }
.quiz-head h3 { font: 400 25px var(--font-display); margin: 0 0 4px; }
.quiz-score { font: 13px var(--font-mono); color: var(--ink-mute); }
.quiz-q { margin-bottom: 14px; }
.quiz-q p { margin: 0 0 6px; }
.quiz-q .n { font: 13px var(--font-mono); color: var(--ink-faint); margin-right: 4px; }
.quiz-opts { display: flex; flex-direction: column; gap: 5px; }
.quiz-opts button { text-align: left; border: 1px solid var(--paper-rule); background: var(--input); border-radius: 3px; padding: 5px 12px; cursor: pointer; font-size: 15.5px; }
.quiz-opts button:hover:not(:disabled) { border-color: var(--accent); }
.quiz-opts button.right { background: var(--green-tint); border-color: var(--green); }
.quiz-opts button.wrong { background: var(--red-tint); border-color: var(--red); }
.quiz-why { font-size: 15px; color: var(--ink-soft); margin-top: 6px; }
.quiz-foot { margin-top: 10px; }

/* ─── Report dialog ────────────────────────────────────────── */
.report-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 90; }
.report-dialog { position: fixed; z-index: 91; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(520px, 92vw); background: var(--paper); border: 1px solid var(--paper-rule); border-radius: 4px; padding: 16px 20px; box-shadow: var(--shadow); }
.report-dialog h3 { font: 400 22px var(--font-display); margin: 0 0 8px; }
.report-note { font-size: 14px; color: var(--ink-mute); }
.report-sel { font-size: 14px; border-left: 3px solid var(--ochre); margin: 8px 0; padding-left: 10px; color: var(--ink-soft); max-height: 6em; overflow: auto; }
.report-dialog textarea, .report-dialog input { width: 100%; border: 1px solid var(--paper-rule); background: var(--input); border-radius: 3px; padding: 6px 8px; margin-top: 6px; font: 14px var(--font-body); }
.report-hp { position: absolute; left: -9999px; width: 1px; height: 1px; }
.report-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 10px; }
.report-status { flex: 1; font: 12.5px var(--font-mono); color: var(--ink-mute); }

/* ─── Index ────────────────────────────────────────────────── */
.masthead { max-width: 1120px; margin: 0 auto; padding: 40px 28px 10px; }
.masthead h1 { font: 400 56px/1.05 var(--font-display); margin: 0 0 10px; letter-spacing: -0.015em; }
.masthead h1 em { color: var(--accent); }
.masthead .sub { font: italic 21px/1.45 var(--font-body); color: var(--ink-soft); max-width: 44em; margin: 0; }
.masthead .counts { font: 13px var(--font-mono); color: var(--ink-mute); margin-top: 14px; }
.index-tools { max-width: 1120px; margin: 0 auto; padding: 10px 28px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.index-tools input[type="search"] { flex: 1 1 280px; border: 1px solid var(--paper-rule); background: var(--input); border-radius: 3px; padding: 7px 12px; font: 15px var(--font-body); }
.continue { font: 14px var(--font-mono); }
.search-results { max-width: 1120px; margin: 0 auto; padding: 0 28px; }
.search-results a { display: block; padding: 6px 0; border-bottom: 1px solid var(--paper-rule); text-decoration: none; color: var(--ink); }
.search-results small { color: var(--ink-mute); font-family: var(--font-mono); }
.catalog { max-width: 1120px; margin: 0 auto; padding: 0 28px 60px; }
.part-head { font: 600 12px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--red); margin: 34px 0 6px; border-bottom: 2px solid var(--ink); padding-bottom: 6px; }
.vol { border-bottom: 1px solid var(--paper-rule); padding: 12px 0; }
.vol summary { cursor: pointer; list-style: none; display: grid; grid-template-columns: 64px 1fr 120px; gap: 12px; align-items: baseline; }
.vol summary::-webkit-details-marker { display: none; }
.vol-roman { font: 13px var(--font-mono); color: var(--ink-mute); }
.vol-name { font: 400 23px/1.25 var(--font-display); }
.vol-desc { display: block; font: italic 15.5px var(--font-body); color: var(--ink-mute); }
.vol-bar { height: 6px; background: var(--paper-deep); border-radius: 3px; overflow: hidden; align-self: center; }
.vol-bar span { display: block; height: 100%; background: var(--accent); }
.vol ol { margin: 10px 0 4px 76px; padding: 0; columns: 2; column-gap: 30px; }
.vol li { font-size: 15.5px; margin-bottom: 3px; break-inside: avoid; }
.vol li a { text-decoration: none; color: var(--ink); }
.vol li a:hover { color: var(--accent); }
.vol li.done a::after { content: ' ✓'; color: var(--green); }
.settings { max-width: 1120px; margin: 0 auto; padding: 10px 28px 40px; font: 13.5px var(--font-mono); color: var(--ink-mute); }
.settings label { margin-right: 18px; }
.colophon { max-width: 1120px; margin: 0 auto; padding: 16px 28px 40px; font-size: 14px; color: var(--ink-mute); border-top: 1px solid var(--paper-rule); }

@media (max-width: 820px) {
    .workshop { grid-template-columns: minmax(0, 1fr); }
    .ws-stage { border-right: none; border-bottom: 1px solid var(--paper-rule); }
    .plate-title { font-size: 34px; }
    .masthead h1 { font-size: 40px; }
    .vol ol { columns: 1; margin-left: 0; }
    .vol summary { grid-template-columns: 48px 1fr; }
    .vol-bar { display: none; }
    .journey-vol { grid-template-columns: 1fr; }
    .main-content { padding: 18px 16px 50px; }
    .terms { grid-template-columns: 1fr; }
}
@media print { .topbar, .ws-rail, .quiz, .try-block, .plate-footer { display: none; } }
.ws-busy { display: none; position: absolute; margin: 8px; padding: 3px 10px; background: var(--ochre-tint); color: var(--ink); font: 12px var(--font-mono); border-radius: 3px; }
