/* phase-0/assets/lesson.css
   Shared stylesheet for every lesson and reference sheet in this workspace.
   Tufte-leaning: one measure of serif text, generous leading, restrained colour, prints cleanly. */

:root {
  --bg: #fffdf8; --fg: #1c1b19; --muted: #6a655d; --rule: #ddd6c9;
  --accent: #8a3b12; --accent-soft: #f5e6da;
  --code-bg: #f3eee5;
  --ok: #2b7a3d; --ok-soft: #e0f1e3; --bad: #a33232; --bad-soft: #f8dcdc;
  --on: #b85c2c; --off: #e8e1d5;
  --measure: 46rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171619; --fg: #ebe7df; --muted: #a49e96; --rule: #363340;
    --accent: #e8965f; --accent-soft: #2f2119; --code-bg: #232028;
    --ok: #82d193; --ok-soft: #1c3322; --bad: #f09090; --bad-soft: #3b1f1f;
    --on: #e8965f; --off: #2c2a31;
  }
}
* { box-sizing: border-box; }
html { background: var(--bg); color: var(--fg); }
body { margin: 0; font: 18px/1.65 "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif; -webkit-font-smoothing: antialiased; }
.lesson, .sheet { max-width: var(--measure); margin: 0 auto; padding: 3rem 1.25rem 5rem; }
header.masthead { border-bottom: 1px solid var(--rule); margin-bottom: 2rem; padding-bottom: 1rem; }
.kicker { font-variant: small-caps; letter-spacing: .08em; color: var(--muted); margin: 0 0 .25rem; }
h1 { font-weight: 400; font-size: 2.4rem; line-height: 1.1; margin: 0 0 .5rem; }
h2 { font-weight: 400; font-size: 1.55rem; margin: 2.75rem 0 .75rem; line-height: 1.2; }
h3 { font-weight: 600; font-size: 1.05rem; margin: 1.75rem 0 .5rem; }
.subtitle { font-style: italic; color: var(--muted); margin: 0; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a.cite { font-size: .78em; vertical-align: super; line-height: 0; text-decoration: none; margin-left: 1px; }
blockquote { margin: 1.25rem 0; padding-left: 1rem; border-left: 2px solid var(--accent); font-style: italic; }
blockquote cite { display: block; font-style: normal; font-size: .85rem; color: var(--muted); margin-top: .25rem; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .86em; }
code { background: var(--code-bg); padding: .1em .35em; border-radius: 3px; }
pre { background: var(--code-bg); padding: .9rem 1rem; border-radius: 6px; overflow-x: auto; line-height: 1.5; }
pre code { background: none; padding: 0; }
table { border-collapse: collapse; width: 100%; margin: 1rem 0 1.5rem; font-size: .95rem; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .8rem; letter-spacing: .04em; text-transform: uppercase; }
.table-wrap { overflow-x: auto; }
figure { margin: 1.5rem 0; }
figcaption { font-size: .9rem; color: var(--muted); margin-top: .5rem; }
aside.note { font-size: .92rem; color: var(--muted); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: .6rem 0; margin: 1.25rem 0; }
.callout { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: .9rem 1.1rem; margin: 1.5rem 0; border-radius: 0 6px 6px 0; }
.callout p:first-child { margin-top: 0; } .callout p:last-child { margin-bottom: 0; }
.win { border: 1px solid var(--accent); border-radius: 6px; padding: 1rem 1.2rem; margin: 1.5rem 0; }
.win h3 { margin-top: 0; }
/* lists carry parallel items (rules, steps, inputs/outputs, reasons); prose is for narrative (roadmap rule 11) */
.lesson ul, .lesson ol { padding-left: 1.4rem; margin: .5rem 0 1rem; }
.lesson li { margin: .3rem 0; }
.lesson li > ul, .lesson li > ol { margin: .25rem 0; }
ol.rules > li, ul.rules > li { margin: .6rem 0; }
ol.rules > li::marker, ul.rules > li::marker { color: var(--accent); }
.try { background: var(--code-bg); border-radius: 6px; padding: .75rem 1rem; margin: .75rem 0 1.5rem; font-size: .95rem; }
.try ol { margin: .4rem 0 0; padding-left: 1.3rem; }
dl.terms { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: .75rem 0 1rem; font-size: .95rem; }
dl.terms dt { font-weight: 600; }
dl.terms dd { margin: 0; }
@media (max-width: 40rem) { dl.terms { grid-template-columns: 1fr; gap: .15rem 0; } dl.terms dd { margin: 0 0 .5rem 1rem; } }
.ask { border-top: 1px solid var(--rule); margin-top: 3rem; padding-top: 1rem; color: var(--muted); font-size: .95rem; }
footer.lesson-nav { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--rule); font-size: .95rem; }
ol.sources { font-size: .9rem; color: var(--muted); padding-left: 1.3rem; }
ol.sources li { margin-bottom: .3rem; overflow-wrap: anywhere; }
.muted { color: var(--muted); }

/* ---- simulators (assets/warp-sim.js) ---- */
.sim { display: block; margin: 1.25rem 0 .5rem; padding: 1rem; border: 1px solid var(--rule); border-radius: 8px; font-size: .92rem; }
.sim .controls { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: center; margin-bottom: .9rem; }
.sim label { display: inline-flex; align-items: center; gap: .4rem; }
.sim select, .sim input[type=number], .sim button { font: inherit; font-size: .9rem; padding: .25rem .45rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--bg); color: var(--fg); }
.sim input[type=number] { width: 4.2rem; }
.sim input[type=range] { width: 14rem; accent-color: var(--accent); }
.sim button { cursor: pointer; }
.sim-stats { margin: .75rem 0 0; }
.sim-code { margin: 0 0 .9rem; font-size: .82rem; }
.lane-grid { overflow-x: auto; }
.lane-row { display: grid; grid-template-columns: 2.6rem repeat(32, 1fr); gap: 2px; margin-bottom: 2px; min-width: 30rem; }
.lane-head { margin-bottom: 4px; }
.row-label, .lane-idx { font-family: ui-monospace, Menlo, monospace; font-size: .7rem; color: var(--muted); text-align: center; }
.row-label { text-align: right; padding-right: .4rem; }
.lane { display: block; height: .9rem; border-radius: 2px; }
.lane-on { background: var(--on); } .lane-off { background: var(--off); }
.mem-strip { display: flex; flex-wrap: wrap; gap: 3px; margin: .25rem 0; }
.seg { width: .9rem; height: .9rem; border-radius: 2px; background: var(--off); }
.seg-on { background: var(--on); }
.mem-legend { font-size: .8rem; color: var(--muted); margin: .25rem 0 0; }
.occ-bar { display: grid; grid-template-columns: repeat(32, 1fr); gap: 3px; margin: .5rem 0; }
.warp-slot { display: block; height: 1rem; border-radius: 2px; background: var(--off); }
.slot-on { background: var(--on); }

/* ---- pipeline simulators (assets/pipeline-sim.js) ---- */
:root { --alt: #2f8a99; --hatch: #b9b1a3; }
@media (prefers-color-scheme: dark) { :root { --alt: #5bc0cf; --hatch: #4d4956; } }
.stages { display: block; margin: 1.25rem 0 1.5rem; }
.stage-track { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; margin-bottom: .75rem; }
.stage-btn { font: inherit; font-size: .8rem; line-height: 1.2; padding: .35rem .55rem; border: 1px solid var(--rule); border-radius: 6px; background: var(--bg); color: var(--fg); cursor: pointer; display: inline-flex; flex-direction: column; align-items: flex-start; gap: .1rem; }
.stage-btn .stage-kind { font-size: .66rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.stage-btn.kind-shader { border-color: var(--accent); }
.stage-btn.kind-shader .stage-kind { color: var(--accent); }
.stage-btn.kind-memory { border-style: dashed; }
.stage-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.stage-arrow { color: var(--muted); font-size: .9rem; }
.stage-card { border: 1px solid var(--rule); border-radius: 8px; padding: .9rem 1.1rem; font-size: .93rem; }
.stage-card h4 { margin: 0 0 .25rem; font-size: 1.05rem; font-weight: 600; }
.stage-card .stage-kind-long { font-weight: 400; font-size: .9rem; }
.stage-card dl.terms { margin: .5rem 0 0; }
.stage-nav { display: flex; gap: .5rem; margin-top: .75rem; }
.stage-nav button { font: inherit; font-size: .85rem; padding: .25rem .6rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--bg); color: var(--fg); cursor: pointer; }
.stage-nav button:disabled { opacity: .45; cursor: default; }

.raster-svg { width: 100%; height: auto; display: block; touch-action: none; user-select: none; -webkit-user-select: none; font-family: ui-monospace, Menlo, monospace; }
.raster-svg .px { fill: var(--bg); stroke: var(--rule); stroke-width: .03; }
.raster-svg .px.cov { fill: var(--on); }
.raster-svg .px.cov-b { fill: var(--alt); }
.raster-svg .px.both { fill: var(--bad); }
.raster-svg .hatch { fill: var(--hatch); }
.raster-svg .centre { fill: var(--muted); pointer-events: none; }
.raster-svg .tri { fill: none; stroke: var(--fg); stroke-width: .07; stroke-linejoin: round; pointer-events: none; }
.raster-svg .tri-b { stroke-dasharray: .35 .2; }
.raster-svg .tri.culled { stroke-dasharray: .12 .12; opacity: .5; }
.raster-svg .quad { fill: none; stroke: var(--accent); stroke-width: .09; pointer-events: none; }
.raster-svg .handle { cursor: grab; stroke: var(--bg); stroke-width: .1; }
.raster-svg .handle:active { cursor: grabbing; }
.raster-svg .handle-label { font-size: .6px; fill: var(--fg); pointer-events: none; }
.raster-svg .tick { font-size: .5px; fill: var(--muted); }
.raster .controls label { font-size: .88rem; }

.ndc .panels { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; margin-top: .25rem; }
.ndc .panel { flex: 1 1 17rem; min-width: 0; }
.ndc svg { width: 100%; height: auto; display: block; touch-action: none; user-select: none; -webkit-user-select: none; font-family: ui-monospace, Menlo, monospace; }
.ndc .ndc-square { fill: var(--accent-soft); stroke: var(--accent); stroke-width: .015; }
.ndc .canvas-rect { fill: none; stroke: var(--fg); stroke-width: calc(2px * var(--fb-unit, 1)); }
.ndc .vp-rect { fill: var(--accent-soft); stroke: var(--accent); stroke-width: calc(1.5px * var(--fb-unit, 1)); }
.ndc .axis { stroke: var(--muted); stroke-width: .012; }
.ndc .axis-arrow { fill: var(--muted); }
.ndc .tick { stroke: var(--muted); stroke-width: .012; }
.ndc .fb-svg .tick { stroke-width: calc(1.5px * var(--fb-unit, 1)); }
.ndc .lbl { fill: var(--muted); font-size: .1px; }
.ndc .fb-svg .lbl { font-size: calc(16px * var(--fb-unit, 1)); }
.ndc .lbl.title { fill: var(--fg); font-size: .11px; }
.ndc .fb-svg .lbl.title { font-size: calc(17px * var(--fb-unit, 1)); }
.ndc .lbl.vlabel { fill: var(--fg); pointer-events: none; }
.ndc .tri { fill: none; stroke: var(--fg); stroke-width: .02; stroke-linejoin: round; pointer-events: none; }
.ndc .fb-svg .tri { stroke-width: calc(2.5px * var(--fb-unit, 1)); }
.ndc .handle { cursor: grab; stroke: var(--bg); stroke-width: .02; }
.ndc .fb-svg .handle { stroke-width: calc(2.5px * var(--fb-unit, 1)); }
.ndc .handle.focus { stroke: var(--fg); }
.ndc .handle:active { cursor: grabbing; }
.ndc table { font-size: .88rem; margin: 1rem 0 .5rem; }
.ndc td { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .8rem; cursor: pointer; }
.ndc tr.focus td { background: var(--accent-soft); }
.ndc td input[type=number] { width: 4.4rem; font-size: .8rem; padding: .1rem .3rem; }
.ndc td .zlab { margin-left: .6rem; }
.ndc .formula { margin: 0 0 .75rem; font-size: .78rem; line-height: 1.55; }
.ndc .depth-svg { max-width: 30rem; }
.ndc .depth-svg .lbl { font-size: 2.8px; }
.ndc .depth-svg .axis { stroke-width: .5; }
.ndc .depth-range { fill: var(--on); opacity: .5; }
.ndc .depth-link { stroke: var(--muted); stroke-width: .4; stroke-dasharray: 1 1; }
.ndc .depth-dot { stroke: var(--bg); stroke-width: .5; }

.merge .frag-row { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center; margin: .35rem 0; font-size: .9rem; }
.merge .frag-row input[type=color] { width: 2.4rem; height: 1.6rem; padding: 0; border: 1px solid var(--rule); border-radius: 4px; background: none; }
.merge .frag-row input[type=number] { width: 4.6rem; }
.merge table { font-size: .86rem; margin: .75rem 0 .25rem; }
.merge td { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .8rem; }
.swatch { display: inline-block; width: 1.1em; height: 1.1em; border-radius: 3px; border: 1px solid var(--rule); vertical-align: -.2em; }

/* ---- object-model simulators (assets/object-sim.js) ---- */
.objmap { display: block; margin: 1.25rem 0 1.5rem; }
.obj-row { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; margin-bottom: .45rem; }
.obj-row-label { flex: 0 0 5.6rem; font-size: .66rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stage-btn.kind-memory { border-style: dashed; }
.stage-btn.kind-binding { border-color: var(--alt); }
.stage-btn.kind-binding .stage-kind { color: var(--alt); }
.stage-btn.kind-action { border-color: var(--accent); background: var(--accent-soft); }
.objmap .stage-card { margin-top: .5rem; }
.objmap dl.terms { grid-template-columns: 8.5rem 1fr; }
@media (max-width: 40rem) { .objmap dl.terms { grid-template-columns: 1fr; } }

.sockets .slot { border: 1px solid var(--rule); border-radius: 6px; padding: .55rem .8rem; margin: .5rem 0; }
.sockets .slot-ok { border-color: var(--ok); } .sockets .slot-bad { border-color: var(--bad); }
.sockets .slot-head { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.sockets .slot-body { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem 1rem; margin-top: .4rem; font-size: .86rem; }
@media (max-width: 40rem) { .sockets .slot-body { grid-template-columns: 1fr; } }
.sockets ul.shape { list-style: none; padding: 0; margin: .2rem 0 0; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .78rem; }
.sockets ul.shape li { margin: .15rem 0; }
.sockets ul.shape li.bad { color: var(--bad); }
.sockets .slot-verdict { margin: .4rem 0 0; font-size: .88rem; }
.sockets .ok { color: var(--ok); } .sockets .bad { color: var(--bad); }
.sockets table.fit { font-size: .8rem; margin: .75rem 0 0; }
.sockets table.fit td { text-align: center; font-family: ui-monospace, Menlo, monospace; }
.sockets table.fit td:first-child { text-align: left; }
.sockets table.fit td.yes { background: var(--ok-soft); color: var(--ok); }
.sockets table.fit td.no { color: var(--muted); }

.timeline .tl-note { margin: -.4rem 0 .75rem; font-size: .9rem; min-height: 1.4em; }
.timeline .tl-lanes { border-top: 1px solid var(--rule); }
.timeline .tl-lane { display: grid; grid-template-columns: 9rem 1fr; gap: .5rem; align-items: start; padding: .5rem 0; border-bottom: 1px solid var(--rule); }
@media (max-width: 40rem) { .timeline .tl-lane { grid-template-columns: 1fr; } }
.timeline .tl-name { font-size: .82rem; line-height: 1.3; }
.timeline .tl-chips { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.timeline .tl-chip { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .72rem; line-height: 1.3; padding: .2rem .5rem; border-radius: 999px; border: 1px solid var(--rule); background: var(--code-bg); }
.timeline .tl-chip.new { border-color: var(--accent); background: var(--accent-soft); }
.timeline .tl-chip.pending { border-style: dashed; }
.timeline .tl-chip.done { border-color: var(--ok); background: var(--ok-soft); }
.timeline .tl-chip.error { border-color: var(--bad); background: var(--bad-soft); }
.timeline .tl-state { margin-top: .75rem; }
.timeline .tl-canvas { display: flex; align-items: center; gap: .6rem; }
.timeline .tl-canvas svg { border: 1px solid var(--rule); border-radius: 3px; flex: none; }
.timeline .fb-untouched { fill: var(--off); }
.timeline .fb-drawn { fill: #000; }
.timeline .tl-canvas .lbl { fill: var(--muted); font-size: 9px; font-family: ui-monospace, Menlo, monospace; }

.obj-row-later .stage-btn { opacity: .45; cursor: default; border-style: dotted; }
.obj-row-later .obj-row-label { opacity: .6; }

/* ---- runnable snippets (assets/gpu-try.js) ---- */
.try-run { display: block; margin: 1.25rem 0 1.5rem; border: 1px solid var(--accent); border-radius: 8px; padding: .75rem 1rem .9rem; }
.try-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin-bottom: .6rem; font-size: .85rem; }
.try-label { font-variant: small-caps; letter-spacing: .08em; color: var(--accent); font-weight: 600; }
.try-head button { font: inherit; font-size: .85rem; padding: .25rem .7rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--bg); color: var(--fg); cursor: pointer; }
.try-head button.try-run-btn { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.try-head button:disabled { opacity: .5; cursor: default; }
.try-status { flex-basis: 100%; }
textarea.try-code { display: block; width: 100%; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .8rem; line-height: 1.5; padding: .7rem .9rem; border: 1px solid var(--rule); border-radius: 6px; background: var(--code-bg); color: var(--fg); tab-size: 2; white-space: pre; overflow-x: auto; }
textarea.try-code:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.try-expect { font-size: .9rem; margin: .6rem 0 0; color: var(--muted); }
.try-expect strong { color: var(--fg); }
.try-result { margin-top: .5rem; font-size: .9rem; }
.try-result pre { margin: .4rem 0; font-size: .78rem; }
.try-result .try-value { border-left: 3px solid var(--rule); }
.try-result .try-log { color: var(--muted); }
.try-nodes { margin: .4rem 0; }
.try-nodes canvas { border: 1px solid var(--rule); border-radius: 3px; display: block; }
.try-err { background: var(--bad-soft); color: var(--bad); border-radius: 4px; padding: .4rem .7rem; margin: .4rem 0; font-size: .85rem; overflow-wrap: anywhere; }
.try-win { background: var(--ok-soft); color: var(--ok); border-radius: 4px; padding: .45rem .7rem; margin: .5rem 0 0; font-weight: 600; }
.try-miss { margin: .4rem 0 0; }

/* "what you can do now": the win box, restated as achieved */
.done { border: 1px solid var(--ok); border-radius: 6px; padding: .9rem 1.2rem; margin: 1.5rem 0; }
.done h3 { margin-top: 0; color: var(--ok); }
.done ul { list-style: none; padding-left: 0; }
.done li::before { content: "✓ "; color: var(--ok); font-weight: 600; }
.progress { font-size: .85rem; color: var(--muted); margin: -.5rem 0 1.5rem; }
.progress b { color: var(--fg); font-weight: 600; }

/* ---- quiz and recall (assets/quiz.js) ---- */
.quiz-q { border: 1px solid var(--rule); border-radius: 8px; padding: .9rem 1.1rem 1rem; margin: 1rem 0; }
.quiz-q legend { padding: 0 .4rem; font-weight: 600; }
.quiz-q label { display: block; padding: .3rem .5rem; border-radius: 4px; cursor: pointer; }
.quiz-q label:hover { background: var(--code-bg); }
.quiz-q label.correct { background: var(--ok-soft); color: var(--ok); }
.quiz-q label.wrong { background: var(--bad-soft); color: var(--bad); }
.quiz-q input { margin-right: .5rem; accent-color: var(--accent); }
.quiz-q .explain { margin: .6rem 0 0; font-size: .92rem; color: var(--muted); border-top: 1px dashed var(--rule); padding-top: .5rem; }
.quiz-score { font-style: italic; color: var(--muted); }
.recall { border-left: 3px solid var(--rule); padding: .2rem 0 .2rem 1rem; margin: 1rem 0; }
.recall .prompt { font-weight: 600; margin: 0 0 .4rem; }
.recall .answer { font-size: .95rem; margin: .5rem 0; }
.recall-bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .4rem; }
.recall-bar button { font: inherit; font-size: .85rem; padding: .25rem .6rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--bg); color: var(--fg); cursor: pointer; }
.recall-status { font-size: .82rem; color: var(--muted); }
.recall-ok { border-left-color: var(--ok); } .recall-again { border-left-color: var(--bad); }

@media print {
  html { background: #fff; color: #000; }
  body { font-size: 11pt; }
  .lesson, .sheet { max-width: none; padding: 0; }
  .sim .controls, .recall-bar, .quiz-score, .try-head button, .try-result, .no-print { display: none !important; }
  .recall .answer[hidden] { display: block !important; }
  a, a.cite { color: inherit; }
  .sim, .quiz-q, .recall, .callout { break-inside: avoid; }
  h2, h3 { break-after: avoid; }
}
