/* Shared course stylesheet: Tufte-inspired, prints cleanly, light/dark aware. */
@import url("https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,600;1,8..60,400&family=JetBrains+Mono:wght@400;600&family=Inter:wght@500;600&display=swap");

:root {
  --bg: #fffff8;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --rule: #d9d6cc;
  --accent: #a3342a;
  --accent-soft: #f4e7e3;
  --code-bg: #f3f1e8;
  --ok: #2f6b3a;
  --ok-soft: #e4f0e4;
  --bad: #9a2c22;
  --bad-soft: #f6e2df;
  --l1: #e9e4d4; --l2: #dfe6d6; --l3: #d6e2ea; --l4: #e6dbe9; --l5: #f0dcd2;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171714; --fg: #e8e6df; --muted: #9a978d; --rule: #3a3933;
    --accent: #e0806f; --accent-soft: #3a2622; --code-bg: #24231f;
    --ok: #8fcf98; --ok-soft: #1f3322; --bad: #f09a8c; --bad-soft: #3c2320;
    --l1: #2e2c24; --l2: #263024; --l3: #222d35; --l4: #2f2634; --l5: #3a2a22;
  }
}
:root[data-theme="dark"] {
  --bg: #171714; --fg: #e8e6df; --muted: #9a978d; --rule: #3a3933;
  --accent: #e0806f; --accent-soft: #3a2622; --code-bg: #24231f;
  --ok: #8fcf98; --ok-soft: #1f3322; --bad: #f09a8c; --bad-soft: #3c2320;
  --l1: #2e2c24; --l2: #263024; --l3: #222d35; --l4: #2f2634; --l5: #3a2a22;
}

* { box-sizing: border-box; }
html { font-size: 18px; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--serif); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 42rem; margin: 0 auto; padding: 3rem 16px 5rem; }

.kicker { font-family: var(--sans); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin: 0 0 .4rem; }
h1 { font-weight: 400; font-size: 2.3rem; line-height: 1.15; margin: 0 0 .6rem; }
.subtitle { font-style: italic; color: var(--muted); font-size: 1.15rem; margin: 0 0 2rem; }
h2 { font-weight: 400; font-style: italic; font-size: 1.55rem; margin: 2.8rem 0 .6rem; }
h3 { font-family: var(--sans); font-weight: 600; font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; margin: 1.8rem 0 .4rem; color: var(--muted); }
p, li { font-size: 1rem; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }
strong { font-weight: 600; }
code { font-family: var(--mono); font-size: .82em; background: var(--code-bg); padding: .1em .3em; border-radius: 3px; }
pre { font-family: var(--mono); font-size: .8rem; background: var(--code-bg); padding: 1rem; border-radius: 4px; overflow-x: auto; line-height: 1.5; }
pre code { background: none; padding: 0; }

/* Citations: small superscript links. */
.cite { font-family: var(--sans); font-size: .62rem; vertical-align: super; text-decoration: none; margin-left: 1px; }

/* Callouts */
.win, .note, .source, .ask {
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  padding: .8rem 1rem; margin: 1.5rem 0; border-radius: 0 4px 4px 0;
}
.win p, .note p, .source p, .ask p { margin: .3rem 0; }
.note { border-color: var(--muted); background: var(--code-bg); }
.label { font-family: var(--sans); font-size: .7rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.note .label { color: var(--muted); }

/* Pull quote */
blockquote { margin: 1.5rem 0; padding: 0 0 0 1.2rem; border-left: 1px solid var(--rule); font-style: italic; color: var(--muted); }
blockquote cite { display: block; font-style: normal; font-family: var(--sans); font-size: .72rem; margin-top: .3rem; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: .9rem; margin: 1rem 0; }
th { font-family: var(--sans); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); text-align: left; font-weight: 600; border-bottom: 1px solid var(--fg); padding: .4rem .5rem; }
td { border-bottom: 1px solid var(--rule); padding: .55rem .5rem; vertical-align: top; }
.table-wrap { overflow-x: auto; }

/* Figures */
figure { margin: 2rem 0; }
figure svg { width: 100%; height: auto; display: block; }
figcaption { font-size: .82rem; color: var(--muted); font-style: italic; margin-top: .5rem; }

/* Zoom-level ladder */
.ladder { list-style: none; padding: 0; margin: 1.5rem 0; }
.ladder li { padding: .7rem 1rem; margin: 0 0 .35rem; border-radius: 4px; }
.ladder li:nth-child(1) { background: var(--l1); margin-left: 0; }
.ladder li:nth-child(2) { background: var(--l2); margin-left: .8rem; }
.ladder li:nth-child(3) { background: var(--l3); margin-left: 1.6rem; }
.ladder li:nth-child(4) { background: var(--l4); margin-left: 2.4rem; }
.ladder li:nth-child(5) { background: var(--l5); margin-left: 3.2rem; }
.ladder .term { font-family: var(--sans); font-weight: 600; font-size: .85rem; }
.ladder .q { font-style: italic; }
@media (max-width: 520px) { .ladder li { margin-left: 0 !important; } }

/* Lesson nav */
.lesson-nav { display: flex; justify-content: space-between; gap: 1rem; font-family: var(--sans); font-size: .8rem; margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.muted { color: var(--muted); }

/* Quiz component (assets/quiz.js) */
.quiz-q { margin: 1.6rem 0; }
.quiz-q .prompt { margin-bottom: .6rem; }
.quiz-q .num { font-family: var(--sans); font-size: .7rem; font-weight: 600; color: var(--muted); letter-spacing: .1em; }
.quiz-opts { display: grid; gap: .4rem; }
.quiz-opts button {
  font: inherit; font-size: .95rem; text-align: left; cursor: pointer;
  background: transparent; color: var(--fg); border: 1px solid var(--rule);
  border-radius: 4px; padding: .5rem .8rem;
}
.quiz-opts button:hover:not(:disabled) { border-color: var(--fg); }
.quiz-opts button:disabled { cursor: default; }
.quiz-opts button.correct { background: var(--ok-soft); border-color: var(--ok); }
.quiz-opts button.wrong { background: var(--bad-soft); border-color: var(--bad); }
.quiz-fb { font-size: .9rem; margin-top: .5rem; display: none; }
.quiz-fb.show { display: block; }
.quiz-fb .verdict { font-family: var(--sans); font-weight: 600; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; }
.quiz-fb.ok .verdict { color: var(--ok); }
.quiz-fb.no .verdict { color: var(--bad); }
.quiz-score { font-family: var(--sans); font-size: .85rem; padding: .7rem 1rem; background: var(--code-bg); border-radius: 4px; }

/* Recall component */
.recall textarea { width: 100%; min-height: 9rem; font: inherit; font-size: .95rem; padding: .7rem; background: var(--bg); color: var(--fg); border: 1px solid var(--rule); border-radius: 4px; }
.recall button, .btn { font-family: var(--sans); font-size: .8rem; font-weight: 600; cursor: pointer; background: var(--fg); color: var(--bg); border: 0; border-radius: 4px; padding: .5rem 1rem; margin-top: .5rem; }
.recall .answer { display: none; margin-top: 1rem; }
.recall .answer.show { display: block; }

@media print {
  html { font-size: 11pt; }
  body { background: #fff; color: #000; }
  main { max-width: none; padding: 0; }
  .quiz-opts button, .recall textarea, .recall button, .btn, .lesson-nav { display: none; }
  .recall .answer, .quiz-fb { display: block !important; }
  a { color: #000; }
  h2 { break-after: avoid; }
  table, figure, .ladder li { break-inside: avoid; }
}

/* Pattern diagrams (assets/patterns.js) */
.pattern { margin: .6rem 0 1rem; }
.pattern svg { width: 100%; height: auto; display: block; max-width: 560px; }
.pattern-card { border-top: 1px solid var(--rule); padding-top: .4rem; margin-top: 1.6rem; }
.pattern-card h3 { margin-top: .6rem; color: var(--fg); }
.pattern-card .use { font-size: .92rem; }
@media print { .pattern-card { break-inside: avoid; } }

/* 2x2 concept grid */
.grid2 { display: grid; grid-template-columns: auto 1fr 1fr; gap: 2px; font-size: .88rem; margin: 1.2rem 0; }
.grid2 > div { padding: .6rem .7rem; background: var(--code-bg); }
.grid2 .h { font-family: var(--sans); font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: transparent; }
.grid2 .c1 { background: var(--l3); } .grid2 .c2 { background: var(--l2); }
.grid2 .c3 { background: var(--l4); } .grid2 .c4 { background: var(--l5); }
@media print { .grid2 { break-inside: avoid; } }

/* Main-flow diagram (assets/flow.js) */
.flow { margin: 1.5rem 0; font-size: .88rem; }
.flow-node { display: flex; flex-direction: column; gap: .15rem; padding: .55rem .8rem; border: 1px solid var(--rule); border-left: 3px solid var(--accent); border-radius: 4px; background: var(--bg); }
.flow-node code { background: none; padding: 0; font-weight: 600; font-size: .85rem; }
.flow-node span { color: var(--muted); font-size: .82rem; line-height: 1.4; }
.flow-arrow { text-align: center; color: var(--muted); line-height: 1.4; }
.flow-side { margin: .35rem 0 0 1.5rem; }
.flow-side .flow-node { border-left-style: dashed; }
.flow-q { font-style: italic; text-align: center; margin: .2rem 0 .5rem; }
.flow-branch { display: grid; grid-template-columns: 3fr 2fr; gap: .8rem; }
.flow-col { display: flex; flex-direction: column; }
.flow-tag { font-family: var(--sans); font-size: .68rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: .3rem; }
.flow-inside { margin-top: .8rem; padding: .6rem; background: var(--code-bg); border-radius: 4px; font-family: var(--sans); font-size: .72rem; color: var(--muted); display: grid; gap: .4rem; }
.flow-focus .flow-node { opacity: .45; }
.flow-focus .flow-node.on { opacity: 1; background: var(--accent-soft); }
@media (max-width: 520px) { .flow-branch { grid-template-columns: 1fr; } }
@media print { .flow { break-inside: avoid; } .flow-focus .flow-node { opacity: 1; } }

/* Skill chips for reference pages */
.inv { font-family: var(--sans); font-size: .62rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: .1rem .35rem; border-radius: 3px; white-space: nowrap; }
.inv.user { background: var(--accent-soft); color: var(--accent); }
.inv.model { background: var(--l3); color: var(--fg); }

/* Sorting drill (assets/sort.js) */
.sort-item { padding: .8rem 0; border-bottom: 1px solid var(--rule); }
.sort-text { margin-bottom: .5rem; }
.sort-opts { display: flex; flex-wrap: wrap; gap: .4rem; }
.sort-opts button { font-family: var(--sans); font-size: .78rem; cursor: pointer; background: transparent; color: var(--fg); border: 1px solid var(--rule); border-radius: 4px; padding: .35rem .7rem; }
.sort-opts button:hover:not(:disabled) { border-color: var(--fg); }
.sort-opts button:disabled { cursor: default; }
.sort-opts button.correct { background: var(--ok-soft); border-color: var(--ok); }
.sort-opts button.wrong { background: var(--bad-soft); border-color: var(--bad); }
@media print { .sort-opts { display: none; } .sort-item .quiz-fb { display: block !important; } }

/* Design tree (plain nested list) */
.tree, .tree ul { list-style: none; padding-left: 1.1rem; margin: .2rem 0; }
.tree { padding-left: 0; font-size: .92rem; }
.tree li { position: relative; padding: .15rem 0 .15rem .9rem; border-left: 1px solid var(--rule); }
.tree li::before { content: ""; position: absolute; left: 0; top: .95rem; width: .6rem; border-top: 1px solid var(--rule); }
.tree .k { font-family: var(--sans); font-size: .7rem; font-weight: 600; color: var(--muted); margin-right: .3rem; }

/* Slice grid: layers × features, one ticket highlighted (horizontal row vs vertical column) */
.slices { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; margin: 1.5rem 0 .5rem; }
.slab { display: grid; grid-template-columns: auto repeat(4, 1fr); gap: 3px; font-family: var(--sans); font-size: .66rem; }
.slab .cap { grid-column: 1 / -1; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: .2rem; }
.slab .lyr { color: var(--muted); padding: .3rem .4rem .3rem 0; text-align: right; }
.slab .cell { background: var(--code-bg); border: 1px solid transparent; border-radius: 2px; min-height: 1.6rem; }
.slab .cell.on { background: var(--accent-soft); border-color: var(--accent); }
.slab .verdict { grid-column: 1 / -1; font-size: .74rem; color: var(--fg); margin-top: .3rem; line-height: 1.4; }
@media (max-width: 520px) { .slices { grid-template-columns: 1fr; } }
@media print { .slices { break-inside: avoid; } }

/* Ticket list: numbered tickets with their blocking edges */
.tickets { list-style: none; padding: 0; margin: 1.2rem 0; font-size: .92rem; }
.tickets li { display: grid; grid-template-columns: 2.2rem 1fr; gap: .1rem .6rem; padding: .55rem 0; border-bottom: 1px solid var(--rule); }
.tickets .id { font-family: var(--mono); font-size: .8rem; font-weight: 600; color: var(--accent); padding-top: .1rem; }
.tickets .by { grid-column: 2; font-family: var(--sans); font-size: .72rem; color: var(--muted); }
@media print { .tickets li { break-inside: avoid; } }

/* Decision-tree walk (assets/walk.js) */
.walk-sc { margin: 1.6rem 0; padding-bottom: 1rem; border-bottom: 1px solid var(--rule); }
.walk-sc .prompt { margin-bottom: .6rem; }
.walk-sc .num { font-family: var(--sans); font-size: .7rem; font-weight: 600; color: var(--muted); letter-spacing: .1em; }
.walk-step { padding: .45rem 0 .45rem .9rem; border-left: 1px solid var(--rule); }
.walk-q { font-size: .92rem; margin-bottom: .35rem; }
.walk-n { font-family: var(--sans); font-size: .68rem; font-weight: 600; color: var(--muted); margin-right: .2rem; }
.walk-out { font-family: var(--sans); font-size: .85rem; margin: .5rem 0 0 .9rem; color: var(--accent); }
@media print { .walk-sc { break-inside: avoid; } .walk-step .sort-opts { display: none; } }

/* Deep vs shallow module figure: .depth > .mod(.deep|.shallow) > .iface + .impl */
.depth { display: flex; gap: 2rem; flex-wrap: wrap; align-items: flex-end; margin: 1.4rem 0; }
.depth .mod { flex: 1 1 200px; max-width: 280px; }
.depth .iface, .depth .impl { font-family: var(--sans); font-size: .72rem; padding: .35rem .6rem; }
.depth .iface { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); }
.depth .impl { background: var(--code-bg); color: var(--muted); border: 1px solid var(--rule); border-top: 0; }
.depth .deep .iface { width: 45%; margin: 0 auto; }
.depth .deep .impl { height: 7.5rem; }
.depth .shallow .iface { height: 4.6rem; }
.depth .shallow .impl { height: 1.8rem; }
.depth .cap { font-size: .85rem; margin-top: .4rem; }
@media print { .depth { break-inside: avoid; } }

/* Pipeline: a vertical numbered sequence of stages with a connecting rule. */
.pipe { list-style: none; counter-reset: pipe; margin: 1.2rem 0; padding: 0; }
.pipe > li { counter-increment: pipe; position: relative; padding: 0 0 .9rem 2.4rem; margin: 0; }
.pipe > li::before { content: counter(pipe); position: absolute; left: 0; top: .1rem; width: 1.55rem; height: 1.55rem; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-family: var(--sans); font-size: .72rem; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.pipe > li:not(:last-child)::after { content: ""; position: absolute; left: .76rem; top: 1.75rem; bottom: .15rem; border-left: 1px solid var(--rule); }
.pipe > li .who { font-family: var(--sans); font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-left: .35rem; }
