/* Shader Learn — set like a book: one column of serif prose, figures and
   listings. Two typefaces (serif + mono), ink on paper, one accent. */
:root {
  color-scheme: light;
  --paper: #f9f9f7;
  --ink: #1b1c1f;
  --soft: #54565c;
  --faint: #9a9ca3;
  --rule: #e3e4e7;
  --tint: #f0f1f3;
  --accent: #2f5fc4;
  --accent-soft: #e2eafb;
  --error: #c23a2b;
  --error-soft: #fbeaea;
  --figure: #111214;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Songti SC', 'Noto Serif SC', 'Source Han Serif SC', 'Noto Serif CJK SC', Georgia, serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --measure: 720px;
  --toc: 248px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.75 var(--serif); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; }
button:focus-visible, a:focus-visible, canvas:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
code, output, pre, kbd { font-family: var(--mono); }

/* Running head: phones and tablets only; wide screens show the contents. */
.running-head { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: calc(10px + env(safe-area-inset-top)) 24px 10px; background: var(--paper); border-bottom: 1px solid transparent; font-size: 14px; }
/* devjar renders the page into #__jar; .app carries the layout state classes. Neither adds a box. */
#__jar, .app { display: contents; }
.book-title { text-decoration: none; letter-spacing: .02em; font-style: italic; }
.head-start { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
/* Language switcher: reads as a small label, not a form field. */
.lang-switch { margin: 0; padding: 0 12px 0 0; border: 0; background: transparent; color: var(--faint); font: inherit; font-size: 13px; cursor: pointer; appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--faint) 50%), linear-gradient(-45deg, transparent 50%, var(--faint) 50%); background-position: right 4px center, right 0 center; background-size: 4px 4px; background-repeat: no-repeat; }
.lang-switch:hover, .lang-switch:focus-visible { color: var(--ink); }
#course-picker { color: var(--soft); }
#course-picker:hover { color: var(--ink); }
#progress { font: 12px var(--mono); color: var(--faint); margin-right: 6px; }

.page { max-width: 1280px; padding: 0 40px calc(48px + env(safe-area-inset-bottom)); }

/* Lesson heading. */
.lesson-heading { max-width: var(--measure); padding: 40px 0 28px; }
.kicker { margin: 0 0 14px; color: var(--faint); font-size: 13px; letter-spacing: .04em; }
h1 { margin: 0; font-weight: 500; font-size: clamp(28px, 4vw, 40px); line-height: 1.25; letter-spacing: -.01em; }
#description { margin: 14px 0 0; color: var(--soft); font-size: 18px; }

/* Spread: figure and controls on the left page, the listing on the right.
   Nothing is pinned over other content; the listing scrolls on its own. */
.workspace { display: grid; gap: 28px 56px; grid-template-columns: minmax(0, 1fr); }
.preview-panel, .control-panel, .code-panel, #lesson-notes { min-width: 0; }
/* Wide screens: the page is one screen tall. The canvas takes whatever
   height the heading and parameters leave; the listing scrolls on its own.
   If the left column cannot fit even with a 240px canvas, the content area
   scrolls; the heading and pager stay put. */
@media (min-width: 1280px) {
  .page { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100dvh; padding-bottom: 14px; }
  .lesson-heading { padding: 22px 0 16px; }
  .kicker { margin-bottom: 6px; }
  h1 { font-size: 30px; }
  #description { margin-top: 6px; font-size: 16px; }
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(240px, 1fr) auto; grid-template-areas: 'figure code' 'controls code'; gap: 16px 48px; min-height: 0; overflow-y: auto; }
  .preview-panel { grid-area: figure; display: flex; flex-direction: column; min-height: 0; }
  .canvas-wrap { flex: 1; min-height: 0; aspect-ratio: auto; max-height: none; }
  .control-panel { grid-area: controls; }
  .code-panel { grid-area: code; contain: size; overflow-y: auto; overscroll-behavior: contain; padding-right: 6px; }
  #challenge { margin-top: 10px; padding: 10px 0; }
}
}
#lesson-notes { margin-top: 22px; }

/* Figure. */
.preview-panel { margin: 0; }
.canvas-wrap { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 62vh; overflow: hidden; background: var(--figure); border-radius: 2px; }
canvas { display: block; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: pan-y; }
.can-rotate canvas, canvas.can-rotate { cursor: grab; }
.is-dragging { cursor: grabbing; }
.is-debugging canvas#canvas { cursor: crosshair; }
#canvas-message { position: absolute; inset: 40% 10% auto; text-align: center; color: #eee; font-size: 14px; }
/* One line of fixed height: nothing the debugger shows may wrap it, or the canvas above and the controls below would move. */
.canvas-footer { display: flex; align-items: center; gap: 12px; height: 34px; padding: 8px 0 0; color: var(--faint); font-size: 13px; white-space: nowrap; }
#demo-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.is-debugging #demo-hint { display: none; }
#coordinates { flex: none; min-width: 19ch; font-size: 12px; font-variant-numeric: tabular-nums; }
.figure-tools { display: flex; flex: none; gap: 16px; margin-left: auto; }
.figure-tools button { color: var(--soft); font-size: 13px; }
.figure-tools button:hover { color: var(--ink); }
.figure-tools button[aria-pressed='true'] { color: var(--accent); }
#debug-view { flex: 0 1 auto; min-width: 0; max-width: 12em; height: 22px; margin: 0; padding: 0 12px 0 0; border: 0; background: transparent; color: var(--accent); font: 13px var(--mono); cursor: pointer; appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(-45deg, transparent 50%, var(--accent) 50%); background-position: right 4px center, right 0 center; background-size: 4px 4px; background-repeat: no-repeat; text-overflow: ellipsis; }
#probe { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#probe-dot { fill: none; stroke: #fff; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
#probe.pinned #probe-dot { stroke: #9fc0ff; stroke-width: 2; }
#split-labels { position: absolute; left: 0; right: 0; bottom: 12px; display: grid; grid-template-columns: 1fr 1fr; pointer-events: none; }
#split-labels span { justify-self: center; color: #ddd; font-size: 13px; text-shadow: 0 1px 3px #000; }

/* Live values under the figure. */
#variable-readout { display: flex; flex-wrap: wrap; gap: 4px 24px; padding-top: 6px; font-size: 13px; color: var(--soft); }
.variable-chip > div, .coordinate-chip { display: flex; gap: 10px; align-items: baseline; }
.variable-chip code, .coordinate-chip code { color: var(--faint); font-size: 12px; }
.variable-chip output, .coordinate-chip output { color: var(--ink); font-size: 14px; font-variant-numeric: tabular-nums; }

/* Overlay drawn on the figure. */
#scene-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#scene-overlay line { stroke: #ffffff80; stroke-width: 1; stroke-dasharray: 4 3; }
#scene-overlay text { font: 11px var(--mono); fill: #e6e7ea; paint-order: stroke; stroke: #111; stroke-width: 3; stroke-linejoin: round; }
#scene-overlay .axis-0, #scene-overlay .axis-label-0 { stroke: #e39a7f; }
#scene-overlay .axis-1 { stroke: #9cc7a8; }
#scene-overlay .axis-2 { stroke: #9dc0d8; }
#scene-overlay .axis-label-0 { fill: #e39a7f; stroke: #111; }
#scene-overlay .axis-label-1 { fill: #9cc7a8; }
#scene-overlay .axis-label-2 { fill: #9dc0d8; }
#scene-overlay .active-axis { stroke-width: 3; stroke-dasharray: none; }
#scene-overlay .component-path { stroke-width: 2; stroke-dasharray: none; }
#scene-overlay .coordinate-guide { stroke: #ffffff70; }
#scene-overlay .selected-coordinate { fill: none; stroke: #bcd3ff; stroke-width: 1.5; }
#scene-overlay .selected-cell { fill: #ffffff14; stroke: #bcd3ff; stroke-width: 2; }
#scene-overlay .point-label { fill: #c9ccd2; }
#scene-overlay .selected-point { fill: #bcd3ff; font-size: 14px; }
#scene-overlay .brightness-divider { stroke: #ffffff60; stroke-dasharray: none; }
#scene-overlay .ndc-axis { stroke: #ffffff30; stroke-dasharray: 4 5; }
#scene-overlay .ndc-vertex { fill: #bcd3ff; }

/* Controls: a quiet list, label left and value right. */
#controls { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 32px; }
/* One line per control: name · slider · value. */
.control { display: grid; grid-template-columns: minmax(4.5em, 1fr) minmax(0, 1.5fr) 3.4em; align-items: center; column-gap: 12px; min-width: 0; padding: 3px 0; }
.control label { display: contents; font-size: 14px; color: var(--soft); }
.control label > span:first-child { grid-column: 1; grid-row: 1; font-size: 14px; color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.control output { grid-column: 3; grid-row: 1; text-align: right; font-size: 13px; color: var(--ink); font-variant-numeric: tabular-nums; }
.control input[type='range'] { grid-column: 2; grid-row: 1; }
.control[data-active='true'] label > span:first-child { color: var(--ink); }
input[type='range'] { width: 100%; height: 26px; margin: 0; accent-color: var(--ink); cursor: ew-resize; }
.range-extents { display: none; }
.select-control select { grid-column: 2 / 4; grid-row: 1; }
.select-control select { width: 100%; margin: 0; padding: 4px 0; border: 0; border-bottom: 1px solid var(--rule); border-radius: 0; background: transparent; font-size: 15px; appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--faint) 50%), linear-gradient(-45deg, transparent 50%, var(--faint) 50%); background-position: right 6px center, right 1px center; background-size: 5px 5px; background-repeat: no-repeat; }
.switch-control { grid-template-columns: 1fr; }
.switch-control label { position: relative; display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 32px; cursor: pointer; }
.switch-control label > span:first-child { flex: 1; }
.switch-control output { display: none; }
.switch-control input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch-track { position: relative; flex: none; width: 34px; height: 20px; border-radius: 10px; background: var(--rule); transition: background .15s; }
.switch-track::before { content: ''; position: absolute; left: 3px; top: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--paper); transition: transform .15s; }
.switch-control input:checked + .switch-track { background: var(--ink); }
.switch-control input:checked + .switch-track::before { transform: translateX(14px); }
.switch-control input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Exercise. */
#challenge { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 14px; align-items: start; margin-top: 14px; padding: 12px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
#challenge-target { width: 56px; height: 56px; image-rendering: pixelated; background: var(--figure); }
.challenge-head { display: flex; align-items: baseline; gap: 10px; font-size: 14px; }
.challenge-head strong { font-weight: 600; }
#challenge-kind { color: var(--faint); font-size: 13px; }
#challenge-score { margin-left: auto; font-size: 12px; color: var(--soft); }
#challenge-prompt { margin: 0 0 6px; font-size: 15px; line-height: 1.6; }
#challenge-meter { position: relative; height: 2px; background: var(--rule); }
#challenge-meter i { position: absolute; inset: 0 auto 0 0; width: calc(var(--score, 0) * 100%); background: var(--ink); transition: width .25s; }
#challenge-reveal { margin-top: 4px; color: var(--faint); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
#challenge-answer { display: none; margin: 6px 0 0; white-space: pre-wrap; font: 12px/1.7 var(--mono); color: var(--soft); }
#challenge.show-answer #challenge-answer { display: block; }
#challenge.is-passed #challenge-score, #challenge.is-passed .challenge-head strong { color: var(--accent); }
#challenge.is-passed #challenge-meter i { background: var(--accent); }
#challenge.just-passed { animation: settle .8s ease; }
@keyframes settle { 30% { transform: translateY(-2px); } }

/* Notes: takeaway and tasks. */
.lesson-summary { margin: 0; padding-left: 18px; border-left: 2px solid var(--accent); font-style: italic; color: var(--soft); }
#tasks h2 { margin: 24px 0 6px; font-size: 15px; font-weight: 600; }
#tasks ul { margin: 0; padding: 0 0 0 1.1em; }
#tasks li { padding: 2px 0; font-size: 15px; color: var(--soft); }
#tasks li::marker { color: var(--faint); }

/* Listing: the code panel. */
.code-panel { min-width: 0; }
.shader-bar { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-bottom: 6px; border-bottom: 1px solid var(--ink); font-size: 14px; }
#shader-stage { padding: 0 18px 0 0; border: 0; background: transparent; font-weight: 600; appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--soft) 50%), linear-gradient(-45deg, transparent 50%, var(--soft) 50%); background-position: right 6px center, right 1px center; background-size: 5px 5px; background-repeat: no-repeat; cursor: pointer; }
.bar-actions { display: flex; gap: 16px; }
.bar-actions button { color: var(--soft); font-size: 13px; }
.bar-actions button:hover { color: var(--ink); }
#code-restore { color: var(--accent); }
.code-caption { margin: 6px 0 0; color: var(--faint); font-size: 13px; }
.is-board #code, .is-board .term-card, .is-listing .term-card { display: none; }
.is-board .shader-bar { margin-bottom: 4px; }
#code-title { font-weight: 600; }
#code-hint:not([hidden])::before { content: ' · '; }
#code-caption:empty + #code-hint::before { content: ''; }

/* Editor. The textarea and highlight layer share every metric. */
#code { --code-px: 13; --lh-px: 22; --code-pad: 14px; --gutter: 30px; position: relative; font-size: calc(var(--code-px) * 1px); }
#code .editor-inner { position: relative; }
#code .code-highlight, #code .code-input {
  margin: 0; border: 0; border-radius: 0; width: 100%;
  padding: var(--code-pad) 0 var(--code-pad) var(--gutter);
  font-family: var(--mono); font-size: calc(var(--code-px) * 1px); line-height: calc(var(--lh-px) * 1px); letter-spacing: 0; tab-size: 2;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; font-variant-ligatures: none; font-weight: 400;
}
/* Only source lines preserve whitespace; Sugar High separates them with LF. */
#code .code-highlight { white-space: normal; position: relative; z-index: 1; overflow: visible; pointer-events: none; color: var(--ink); background: transparent; }
#code .code-input { position: absolute; inset: 0; z-index: 0; height: 100%; resize: none; overflow: hidden; outline: none; background: transparent; color: transparent; caret-color: var(--accent); }
#code .code-input::selection { background: #d3e0fa; color: transparent; }
#code.is-readonly .code-input { caret-color: transparent; }
#code .code-line { white-space: pre-wrap; position: relative; display: block; min-height: calc(var(--lh-px) * 1px); }
#code .code-line::before { content: attr(data-line); position: absolute; left: calc(-1 * var(--gutter)); width: calc(var(--gutter) - 10px); text-align: right; color: #c6c8cd; font-size: calc(var(--code-px) * 1px - 2px); user-select: none; }
#code .sh__token--keyword, #code .type-keyword, #code .keyword { color: var(--ink); font-weight: 600; }
#code .builtin { color: #5a5c63; }
#code .sh__token--comment { color: var(--faint); font-style: italic; }
#code .term { text-decoration: underline dotted #c4c6cc; text-underline-offset: 3px; }
#code.is-over-term .code-input { cursor: help; }
#code .selected { background: var(--tint); }
#code .number { color: var(--accent); }
#code .number.scrub { display: inline; pointer-events: auto; cursor: ew-resize; }
#code .number.scrub:hover { background: var(--accent-soft); }
#code .bound { border-bottom: 1px solid var(--accent); }
#code .bound.binding-active { background: var(--accent-soft); }
#code .error-line { background: var(--error-soft); }
#code .error-line::before { color: var(--error); }
#code .line-anchor { position: relative; display: inline-block; width: 0; height: 0; }
#code .line-note { position: absolute; left: 2ch; top: calc(var(--lh-px) * -0.68px); white-space: nowrap; padding: 0 6px; background: var(--tint); color: var(--soft); font-size: calc(var(--code-px) * 1px - 1px); line-height: calc(var(--lh-px) * 1px - 4px); pointer-events: none; }
#code .line-note.is-error { background: var(--error-soft); color: var(--error); }
#code .swatch { display: inline-block; width: 9px; height: 9px; margin-right: 5px; vertical-align: -1px; box-shadow: inset 0 0 0 1px #0002; }
body.is-scrubbing, body.is-scrubbing * { cursor: ew-resize !important; user-select: none; }

#shader-error { margin: 0 0 12px; padding: 10px 0 10px 14px; border-left: 2px solid var(--error); color: var(--error); font: 12px/1.7 var(--mono); white-space: pre-wrap; }
.term-card { margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--rule); font-size: 14px; color: var(--soft); }
.term-card h3 { display: inline; margin: 0 8px 0 0; font: 600 13px var(--mono); color: var(--ink); }
.term-card p { display: inline; margin: 0; }
#live-inputs { margin-top: 18px; }
.live-title { display: block; color: var(--faint); font-size: 13px; }
#input-values { display: block; padding-top: 4px; font-size: 12px; line-height: 1.8; color: var(--soft); white-space: pre; overflow-x: auto; }

/* Explanation board (concept lessons) reads as prose with small listings. */
#concept-board { display: flex; flex-direction: column; gap: 20px; font-size: 16px; }
.concept-code { margin: 0; padding: 14px 16px; background: var(--tint); font: 13px/1.8 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.concept-code-line { display: block; }
.concept-code .keyword { font-weight: 600; }
.concept-code .builtin { color: #5a5c63; }
.concept-code .number { color: var(--accent); }
.code-bound { font: inherit; color: var(--accent); border-bottom: 1px solid var(--accent); cursor: ew-resize; touch-action: none; }
.code-bound.binding-active { background: var(--accent-soft); }
.binding-line { background: #eef1f6; }
.concept-note { margin: 0; color: var(--soft); font-size: 15px; }
.definitions { display: grid; }
.definition-row { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--rule); font-size: 15px; }
.definition-row:last-child { border-bottom: 0; }
.definition-row code { font-size: 13px; color: var(--ink); }
.definition-row span { color: var(--soft); }
.compact-flow { display: flex; flex-wrap: wrap; gap: 4px 0; margin: 0; padding: 0; list-style: none; color: var(--soft); font-size: 15px; }
.compact-flow li:not(:last-child)::after { content: '→'; margin: 0 10px; color: var(--faint); }
.gain-presets { display: flex; gap: 18px; }
.gain-presets button { color: var(--soft); text-decoration: underline; text-underline-offset: 3px; }
.gain-presets button[aria-pressed='true'] { color: var(--ink); text-decoration-color: var(--accent); }
.buffer-bytes { display: flex; flex-wrap: wrap; gap: 10px; align-items: baseline; color: var(--soft); font-size: 15px; }
.buffer-bytes code { color: var(--ink); }
.output-card { padding-bottom: 4px; opacity: .55; transition: opacity .2s; }
.output-card.enabled { opacity: 1; }
.output-card > div code { font-size: 13px; font-weight: 600; }
.output-card p { margin: 4px 0 0; color: var(--soft); font-size: 14px; }
.output-card .concept-code { margin-top: 6px; }
.vertex-table { display: grid; }
.vertex-row { display: grid; grid-template-columns: 3em repeat(3, 1fr); padding: 4px 6px; font: 13px var(--mono); text-align: right; color: var(--soft); }
.vertex-row > span:first-child { text-align: left; color: var(--faint); }
.vertex-row.active { background: var(--tint); color: var(--ink); }
.vertex-row:hover { background: var(--tint); }
.triangle-pair svg { display: block; width: 100%; max-width: 260px; }
.triangle-pair .tri-a { fill: #eceef1; stroke: var(--soft); }
.triangle-pair .tri-b { fill: #dde0e6; stroke: var(--soft); }
.triangle-pair .winding { fill: none; stroke: var(--accent); stroke-dasharray: 5 4; }
.triangle-pair text { font: 11px var(--mono); fill: var(--soft); }
.triangle-pair > span { display: block; color: var(--soft); font-size: 14px; }
.compare-code { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.compare-code section { opacity: .45; transition: opacity .2s; }
.compare-code section.active { opacity: 1; }
.compare-code h4 { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
/* The headings switch the mode: the inactive one reads as a link to the other. */
.compare-code h4 button { font-weight: inherit; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; }
.compare-code h4 button:hover, .compare-code h4 button:focus-visible { text-decoration-color: var(--accent); }
.compare-code h4 button[aria-pressed='true'] { cursor: default; text-decoration-color: var(--accent); }
.compare-code section:not(.active):hover { opacity: .7; }
.compare-code .concept-code { font-size: 12px; }
.live-counter { display: flex; gap: 6px; align-items: baseline; margin-top: 6px; color: var(--soft); font-size: 14px; }
.live-counter output { color: var(--ink); font-variant-numeric: tabular-nums; }
.welcome-intro p { margin: 0; font-size: 17px; }
.welcome-intro strong { font-weight: 600; }
.welcome-route { margin: 0; padding: 0; list-style: none; columns: 2; column-gap: 32px; }
.welcome-route li { break-inside: avoid; }
.welcome-route a { display: flex; gap: 12px; padding: 5px 0; text-decoration: none; font-size: 15px; }
.welcome-route a:hover { color: var(--accent); }
.welcome-route span { color: var(--faint); font: 12px/2.1 var(--mono); }

/* Page turn. */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--rule); }
.pager button { display: flex; flex-direction: column; gap: 2px; text-align: left; min-width: 0; }
.pager #next { grid-column: 2; text-align: right; align-items: flex-end; }
.pager small { color: var(--faint); font-size: 13px; }
.pager span { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.pager button:hover span { color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 30; transform: translateX(-50%); padding: 8px 14px; background: var(--ink); color: var(--paper); font-size: 14px; }

/* Contents: a fixed column on wide screens, a slide-in panel below 900px. */
.toc { position: fixed; inset: 0 auto 0 0; z-index: 40; display: flex; flex-direction: column; width: var(--toc); padding: 26px 0 0; background: var(--paper); border-right: 1px solid var(--rule); }
.toc-header { display: flex; justify-content: space-between; align-items: baseline; padding: 0 24px 14px; font-size: 15px; }
#course-close { display: none; color: var(--soft); font-size: 14px; }
#course-search { margin: 0 24px 6px; padding: 4px 0; border: 0; border-bottom: 1px solid var(--rule); border-radius: 0; background: transparent; font-size: 14px; outline: none; }
#course-search:focus { border-color: var(--ink); }
#course-options { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 24px 20px; }
#course-options h3 { display: flex; gap: 10px; margin: 18px 0 2px; font-size: 13px; font-weight: 600; }
#course-options h3 span { color: var(--faint); font: 11px/1.9 var(--mono); }
.course-choice { display: flex; gap: 10px; padding: 3px 0; color: var(--faint); text-decoration: none; font-size: 14px; line-height: 1.5; }
.course-choice span { flex: none; width: 1.9em; color: #b5b7bd; font: 11px/1.9 var(--mono); }
.course-choice:hover, .course-choice.visited { color: var(--soft); }
.course-choice[aria-current='page'] { color: var(--accent); }
.course-choice[aria-current='page'] span { color: var(--accent); }
.course-choice.done::after { content: '✓'; margin-left: auto; color: var(--accent); }
#course-empty { padding: 0 24px; color: var(--faint); font-size: 14px; }
/* The author link: at the bottom of the contents, and after the welcome page's notes. */
.author { margin: 0; padding: 12px 24px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--rule); color: var(--faint); font-size: 13px; }
.author a { color: var(--soft); text-decoration: none; }
.author a:hover { color: var(--accent); }
#lesson-notes .author { margin-top: 28px; padding: 14px 0 0; }
.toc-scrim { display: none; }
@media (min-width: 900px) {
  .running-head { display: none; }
  .page { margin-left: var(--toc); }
}
@media (max-width: 899px) {
  .toc { width: min(320px, 86vw); transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; }
  .toc-open .toc { transform: none; box-shadow: 0 0 40px #0002; }
  #course-close { display: inline; }
  .toc-scrim { position: fixed; inset: 0; z-index: 35; background: #1b1c1f33; }
  .toc-open .toc-scrim { display: block; }
  .toc-open { overflow: hidden; }
  #course-search { font-size: 16px; }
  .page { max-width: none; padding: 0 24px calc(48px + env(safe-area-inset-bottom)); }
}

/* Phones: one column, the figure stays pinned while you scroll the code. */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .running-head, .page { padding-left: 18px; padding-right: 18px; }
  .lesson-heading { padding: 18px 0 18px; }
  #description { font-size: 16px; }
  .workspace { gap: 20px; }
  .preview-panel { position: sticky; top: 42px; z-index: 5; margin: 0 -18px; padding: 0 18px 6px; background: var(--paper); }
  .canvas-wrap { aspect-ratio: auto; height: clamp(190px, 38vh, 320px); }
  #controls { grid-template-columns: 1fr; }
  .select-control select { font-size: 16px; }
  .lang-switch { font-size: 16px; }
  #debug-view { flex: none; font-size: 16px; }
  /* On phones the menu matters more than the pixel coordinates. */
  #coordinates { flex: 0 1 19ch; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  #code { --code-px: 12.5; --lh-px: 21; --gutter: 26px; }
  /* Text inputs need 16px to avoid focus zoom; scale the textarea back down. */
  #code .code-input { font-size: 16px; line-height: calc(var(--lh-px) / var(--code-px) * 16px); transform: scale(calc(var(--code-px) / 16)); transform-origin: 0 0; width: calc(100% * 16 / var(--code-px)); height: calc(100% * 16 / var(--code-px)); padding: calc(var(--code-pad) * 16 / var(--code-px)) 0 calc(var(--code-pad) * 16 / var(--code-px)) calc(var(--gutter) * 16 / var(--code-px)); }
  .compare-code { grid-template-columns: 1fr; }
  .welcome-route { columns: 1; }
  .definition-row { grid-template-columns: 6em minmax(0, 1fr); }
  .pager { margin-top: 40px; }
  .pager span { font-size: 15px; }
}
@media (min-width: 721px) and (max-width: 1279px) {
  .canvas-wrap { aspect-ratio: 16 / 10; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* The contents column already lists the chapters on wide screens. */
@media (min-width: 900px) { .welcome-route { display: none; } }
/* Debugger notes may run past the line end; never widen the page. */
#code { overflow-x: clip; }

@media (min-width: 1280px) {
  .page .pager { margin-top: 12px; padding-top: 10px; }
  .page .pager button { flex-direction: row; align-items: baseline; gap: 10px; }
  .page .pager #next { flex-direction: row-reverse; justify-content: flex-start; }
  .page .pager span { font-size: 15px; }
}

/* Cheat sheet: function chips grouped by purpose. */
#lesson-panel { margin-top: 8px; }
.sheet-group { display: grid; grid-template-columns: 5.5em minmax(0, 1fr); gap: 8px; align-items: baseline; padding: 3px 0; }
.sheet-group > span { color: var(--faint); font-size: 13px; }
.sheet-group > div { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.sheet-group button { font: 13px/1.7 var(--mono); color: var(--soft); }
.sheet-group button:hover { color: var(--ink); }
.sheet-group button[aria-pressed='true'] { color: var(--accent); text-decoration: underline; text-underline-offset: 4px; }
.sheet-use { margin: 10px 0 0; font-size: 14px; color: var(--soft); }
.sheet-use code { margin-right: 8px; color: var(--ink); font-weight: 600; font-size: 13px; }
.sheet-note { display: block; margin-top: 2px; color: var(--accent); }
.sheet-index { margin-top: 24px; }
.sheet-index h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.sheet-index ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(15em, 1fr)); gap: 6px 16px; margin: 0; padding: 0; list-style: none; }
/* Each row: a picture of the feature, its name, and the technique. The thumbnail keeps its size before the engine paints it. */
.sheet-index a { display: grid; grid-template-columns: 40px minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 3px 0; text-decoration: none; color: var(--ink); }
.sheet-thumb { grid-row: span 2; width: 40px; height: 40px; background: #111a24; }
.sheet-see { font-size: 14px; line-height: 1.35; }
.sheet-index code { font-size: 12px; line-height: 1.4; color: var(--soft); overflow-wrap: anywhere; }
.sheet-index a:hover .sheet-see, .sheet-index a:focus-visible .sheet-see { color: var(--accent); }
.sheet-index a:hover code { color: var(--ink); }
