/* The room: a framed whiteboard for graphics and the chalkboard for notes, between wooden rails. */
.stage { position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.board-wrap { position: relative; flex: 1 1 0; min-height: 0; min-width: 0; }
.board-wrap::after { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; border-style: solid; border-color: var(--wood) transparent var(--wood-dark); border-width: 3px 0 5px; }
.board {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-image: var(--dust), var(--board-light);
  font-family: var(--chalk-font);
  font-size: 19px;
  line-height: 1.28;
}
.room { position: absolute; inset: 3px 0 5px; display: grid; gap: 6px; padding: 6px; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, var(--wb, 56%)) minmax(0, 1fr); }
.room[data-mix="notes"], .room[data-mix="review"] { grid-template-rows: minmax(0, 1fr); }
.room:has(> .surface-white > .code-dock[data-compute-open]) { --wb: 78% !important; }
.room:not([data-mix="both"]) .surface-white { display: none; }
.surface { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.surface-view { position: relative; flex: 1 1 0; min-height: 0; min-width: 0; overflow: hidden auto; overscroll-behavior: contain; outline-offset: -2px; }
.sheet { position: relative; display: flex; flex-direction: column; min-height: 100%; width: 100%; margin: 0 auto; transform-origin: 0 0; }

/* Marker colors. Every renderer draws through these tokens, so it works on either surface. No green. */
.surface-white {
  --chalk: #1b1e23;
  --chalk-dim: #5a6068;
  --yellow: #a85f00;
  --blue: #1560b8;
  --pink: #c22a5c;
  --peach: #b94e12;
  --board: #fbfaf6;
  --board-raised: #f0efe9;
  --line: #cfd0cc;
  --danger: #c4281c;
  color: var(--chalk);
  background: var(--board);
  border: 4px solid #0a0b0d;
  border-radius: 8px;
  box-shadow: 0 0 0 1px var(--hairline), 0 2px 12px rgb(0 0 0 / .42);
}
.surface-black { --no: #ff9d8a; }
.surface-white { --no: #c4281c; }

.b-section { position: relative; padding: 12px 14px 14px 24px; min-width: 0; }
.b-section:last-child { flex: 1 0 auto; }
.surface-black .b-section + .b-section { border-top: 1px dashed var(--line); }
.side .b-section + .b-section:last-child { min-height: var(--view, 100%); }
.surface-white .b-section { display: flex; flex-wrap: wrap; align-content: flex-start; align-content: safe center; justify-content: center; gap: 12px 24px; min-height: var(--view, 100%); padding-top: 30px; }
.surface-white .b-section > .block { flex: 1 1 100%; margin: 0; }
.surface-white .b-section > .block.half { flex: 1 1 calc(50% - 12px); }
.surface-white .section-title { position: absolute; top: 9px; left: 14px; right: 14px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-title { margin: 0 0 10px; font-family: var(--font-ui); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--chalk-dim); }
.arrows { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.arrow { fill: none; stroke: var(--blue); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.block { position: relative; margin: 0 0 14px; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.block > * { margin-top: 0; margin-bottom: 0; }
.block.gone { display: none; }
.block.leaving { margin: 0; pointer-events: none; }
.block.hl-all > :not(.b-tag, .t-status) { outline: 2px solid var(--yellow); outline-offset: 4px; border-radius: 6px; }
.block.picked, .surface-white .picked { outline: 2px dashed var(--blue); outline-offset: 2px; }
.surface-white .block[data-element-id] { cursor: pointer; }
.w { display: inline-block; max-width: 100%; }
.b-tag { display: inline-block; margin-bottom: 4px !important; padding: 0 6px; border: 1px solid var(--blue); border-radius: 5px; color: var(--blue); font-size: .72em; }

/* Text */
.b-eyebrow { display: block; font-family: var(--font-ui); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--chalk-dim); }
.b-question-text { margin: 2px 0 0; font-size: 1.14em; color: var(--yellow); }
.b-assumption { margin: 6px 0 0; font-size: .8em; color: var(--chalk-dim); }
.b-heading {
  display: inline;
  font-size: 1.42em;
  font-weight: 400;
  line-height: 1.3;
  padding-bottom: 2px;
  background: linear-gradient(var(--yellow), var(--yellow)) left bottom / 100% 2px no-repeat;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.b-text { line-height: 1.3; }
.tone-accent { color: var(--yellow); }
.tone-muted { color: var(--chalk-dim); }
.b-note { margin: 4px 0 0; font-size: .76em; color: var(--chalk-dim); }
.b-bullets { margin: 0; padding: 0; list-style: none; }
.b-bullets li { position: relative; padding-left: 20px; margin-bottom: 6px; border-radius: 4px; }
.b-bullets li::before { content: ""; position: absolute; left: 3px; top: .55em; width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); }
.b-bullets li.hl, .box.hl, .cell.hl, .var.hl, tr.hl, .c-row.hl { background: color-mix(in srgb, var(--yellow) 22%, transparent); box-shadow: 0 0 0 1.5px var(--yellow); }

/* Math */
.tex { font-size: 1.02em; text-align: center; font-family: inherit; line-height: 1.5; }
.tex .katex-display { margin: 2px 0; }
.tex .katex { color: var(--chalk); }
.tex-plain { font-family: var(--font-mono); font-size: .76em; overflow-wrap: anywhere; }
.b-math { padding: 2px 0; }
.b-math .b-note { text-align: center; }
.b-result { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; padding: 8px 12px; border: 1.5px solid var(--peach); border-radius: 12px 4px 12px 4px; }
.b-result-label { flex: 1 1 100%; font-size: .78em; color: var(--chalk-dim); }
.b-result-value { flex: 1 1 auto; min-width: 0; font-size: 1.14em; color: var(--peach); }
.b-result .tex { flex: 1 1 0; min-width: 0; text-align: left; }
.b-result .tex .katex, .b-result .tex .katex-display { text-align: left; color: var(--peach); }
.b-computed { font-family: var(--font-ui); font-size: 11px; font-weight: 600; color: var(--peach); }
.b-computed::before { content: "\2713\00a0"; }
.b-computed.unverified { color: var(--chalk-dim); font-weight: 500; }
.b-computed.unverified::before { content: none; }

/* Boxes */
.b-boxes { display: grid; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); gap: 10px; }
.b-boxes[data-flow] { display: flex; align-items: stretch; gap: 0; }
.b-boxes[data-flow="column"] { flex-direction: column; align-items: stretch; }
.b-boxes[data-flow="row"] .box { flex: 1 1 0; }
.box { display: flex; flex-direction: column; justify-content: center; min-width: 0; padding: 8px 10px; border: 1.6px solid var(--chalk); border-radius: 14px 5px 12px 6px / 6px 12px 5px 14px; text-align: center; }
.box strong { font-weight: 400; }
.box-sub { font-size: .76em; color: var(--chalk-dim); }
.conn { display: grid; place-items: center; flex: 0 0 24px; color: var(--blue); }
.b-boxes[data-flow="column"] .conn { transform: rotate(90deg); flex-basis: 24px; }

/* Graph and figures */
.b-graph svg, .b-figure svg { display: block; max-width: 100%; margin: 0 auto; overflow: visible; }
.b-graph text, .b-figure text { font-family: var(--chalk-font); fill: var(--chalk); }
.node path { fill: var(--board-raised); stroke: var(--chalk); stroke-width: 1.6; }
.node text { font-size: 15px; }
.node.hl path { stroke: var(--yellow); stroke-width: 2.5; }
.node.hl text { fill: var(--yellow); }
.edge { fill: none; stroke: var(--blue); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.edge-label rect { fill: var(--board); }
.edge-label text { font-size: 13px; fill: var(--blue); }
.b-figure-title { margin: 0 0 4px; text-align: center; font-size: .86em; }
.axis { fill: none; stroke: var(--chalk-dim); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.grid { stroke: var(--line); stroke-width: 1; }
.curve { fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.mark-line { fill: none; stroke: var(--pink); stroke-width: 1.6; stroke-dasharray: 6 5; stroke-linecap: round; }
.mark-gap { fill: none; stroke: var(--yellow); stroke-width: 3.2; stroke-linecap: round; }
.mark-band { fill: var(--yellow); opacity: .13; }
.mark-dot { fill: var(--yellow); stroke: var(--board); stroke-width: 1.5; }
.mark-shift { fill: none; stroke-width: 2; stroke-dasharray: 5 5; stroke-linecap: round; opacity: .8; }
.mark-arrow { fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.b-figure text.mark-label { font-size: 14px; fill: var(--yellow); paint-order: stroke; stroke: var(--board); stroke-width: 3px; stroke-linejoin: round; }
.b-figure text.tick { font-size: 13px; fill: var(--chalk-dim); }
.b-figure text.axis-label { font-size: 14px; fill: var(--chalk-dim); }
.b-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; margin-top: 4px; font-size: .76em; }
.key::before { content: ""; display: inline-block; width: 16px; height: 3px; margin-right: 6px; vertical-align: middle; border-radius: 2px; background: var(--ink); }

/* Tracing */
.b-name { display: block; margin-bottom: 2px; font-size: .82em; color: var(--chalk-dim); }
.cells { display: flex; flex-wrap: wrap; gap: 4px; }
.cell { display: flex; flex-direction: column; align-items: center; flex: 0 1 auto; min-width: 38px; max-width: 100%; border-radius: 4px; }
.cell-v { display: block; width: 100%; padding: 3px 6px; border: 1.5px solid var(--chalk); border-radius: 4px; text-align: center; }
.cell-i { font-family: var(--font-ui); font-size: 11px; color: var(--chalk-dim); }
.b-vars { display: inline-grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); max-width: 100%; border: 1.5px solid var(--line); border-radius: 8px; overflow: hidden; }
.var { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; }
.var-n, .var-v { padding: 3px 10px; border-bottom: 1px solid var(--line); min-width: 0; }
.var-n { color: var(--chalk-dim); border-right: 1px solid var(--line); }
.var-v { color: var(--yellow); }
.var:last-child > * { border-bottom: 0; }
.var.hl > * { background: color-mix(in srgb, var(--yellow) 22%, transparent); }
.b-table { font-size: .84em; }
.b-table table { width: 100%; table-layout: fixed; border-collapse: collapse; }
.b-table th, .b-table td { padding: 5px 6px; border: 1px solid var(--line); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.b-table th { font-weight: 400; color: var(--yellow); }

/* Sim slider and figure state buttons sit on the whiteboard under what they control. */
.sim-slider { display: block; width: min(100%, 420px); height: 28px; margin: 4px auto 0; accent-color: var(--blue); }
.fig-states { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 8px; font-family: var(--font-ui); }
.fig-state { min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--board); color: var(--chalk); font-size: 13px; }
.fig-state[aria-pressed="true"] { border-color: var(--blue); color: var(--blue); font-weight: 600; }

/* Traces: a row pointer and band, marks, and lines between rows. Match is blue with a check, no match red with a cross. */
.traced { position: relative; }
.t-band { position: absolute; left: 0; top: 0; z-index: 0; border-radius: 4px; background: color-mix(in srgb, var(--yellow) 16%, transparent); box-shadow: 0 0 0 1.5px var(--yellow); pointer-events: none; }
.t-ptr { position: absolute; left: 0; top: 0; width: 0; height: 0; border-style: solid; border-width: 7px 0 7px 11px; border-color: transparent transparent transparent var(--yellow); pointer-events: none; }
.t-status { margin: 0 0 3px !important; font-size: .78em; color: var(--yellow); }
.t-mark { display: inline-flex; align-items: baseline; gap: 3px; margin-left: 6px; font-family: var(--font-ui); font-size: .8em; font-weight: 700; }
.t-mark-label { font-weight: 500; font-size: .86em; }
.m-match, .m-keep { background: color-mix(in srgb, var(--blue) 14%, transparent); }
.m-match .t-mark, .m-keep .t-mark { color: var(--blue); }
.m-nomatch { background: color-mix(in srgb, var(--no) 13%, transparent); }
.m-nomatch .t-mark { color: var(--no); }
.m-drop { opacity: .5; text-decoration: line-through; }
.m-drop .t-mark { color: var(--no); text-decoration: none; }
.t-link { fill: none; stroke: var(--chalk-dim); stroke-width: 1.7; stroke-linecap: round; }
.t-link.match { stroke: var(--blue); }
.t-link.nomatch { stroke: var(--no); stroke-dasharray: 5 5; }
.t-link-glyph { font-family: var(--font-ui); font-size: 14px; font-weight: 700; paint-order: stroke; stroke: var(--board); stroke-width: 3px; }
.t-link-glyph.match { fill: var(--blue); }
.t-link-glyph.nomatch { fill: var(--no); }

/* On a phone, tables being traced share the screen: inputs two across, the output under them. */
@media (max-width: 899.98px) {
  .surface-white .b-section.tracing { gap: 8px 12px; padding-left: 16px; padding-right: 10px; }
  .surface-white .b-section.tracing > .block[data-op="table"] { flex: 1 1 calc(50% - 6px); }
  .tracing .b-table { font-size: .72em; }
  .tracing .t-link-glyph { display: none; } /* the gap is narrow, and the rows carry their own marks */
  .tracing .b-table th, .tracing .b-table td { padding: 2px 4px; }
  .room[data-mix="both"][data-strip] .nb-head { display: none; }
  .room[data-mix="both"][data-strip] .surface-black { font-size: .82em; }
  .room[data-mix="both"][data-strip] .surface-black .b-section { padding: 2px 10px 2px 14px; }
  .room[data-mix="both"][data-strip] .surface-black .block { margin-bottom: 4px; }
}

/* Compare: columns share row lines through subgrid and wrap two by two on a phone. */
.b-compare { font-size: .8em; }
.c-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 0 14px; }
.c-col { position: relative; display: grid; grid-template-rows: subgrid; grid-row: span var(--span); align-content: start; margin-bottom: 10px; }
.b-compare.tight .c-col { margin-bottom: 4px; }
.b-compare.tight .c-cell { padding-block: 0; }
.b-compare.tight .c-head { font-size: 1em; }
.b-compare.tight .b-figure-title { margin-bottom: 0; }
.c-title { margin: 0 0 3px; color: var(--yellow); font-size: 1.05em; }
.c-row { display: grid; grid-template-columns: repeat(var(--cells, 1), minmax(0, 1fr)); align-items: start; border-bottom: 1px solid var(--line); }
.c-row.c-head { color: var(--chalk-dim); border-bottom-width: 1.5px; font-size: .92em; }
.c-row.c-empty { border-bottom-color: transparent; }
.c-cell { min-width: 0; padding: 2px 5px; }
.c-cell.null, td.null { color: var(--chalk-dim); font-style: italic; }
.c-note { margin: 4px 0 0; color: var(--chalk-dim); font-size: .88em; }
.c-row.diff { position: relative; background: color-mix(in srgb, var(--pink) 12%, transparent); box-shadow: inset 3px 0 0 var(--pink); }

/* Running notes */
.nb-head { flex: none; padding: 8px 14px 6px 20px; border-bottom: 1px dashed var(--line); font-family: var(--font-ui); font-size: 12.5px; line-height: 1.35; }
.nb-outline { margin: 0; padding: 0; list-style: none; color: var(--chalk-dim); }
.nb-outline li { padding: 1px 0; }
.nb-outline li:not(.now) { display: none; }
.nb-outline li.done { opacity: .55; }
.nb-outline li.now { color: var(--chalk); font-weight: 600; }
.nb-outline li.now::marker { color: var(--yellow); }
.nb-sofar { display: flex; align-items: center; gap: 6px; margin-top: 6px; overflow-x: auto; scrollbar-width: none; }
.nb-sofar-label { flex: none; color: var(--chalk-dim); }
.nb-chip { flex: none; min-height: 28px; padding: 0 10px; border: 1px solid var(--hairline); border-radius: 999px; background: none; color: var(--chalk-dim); font-size: 12px; }
.nb-chip:hover { border-color: var(--line); color: var(--chalk); }
.b-n { padding: 3px 0 3px 12px; border-left: 2.5px solid var(--line); }
.block[data-tap] { cursor: pointer; border-radius: 4px; }
.block[data-tap]:hover .b-n { border-left-color: var(--yellow); }
.n-word { display: block; font-weight: 400; color: var(--yellow); }
.n-def { border-left-color: var(--blue); }
.n-formula { border-left-color: var(--peach); }
.n-formula .tex { text-align: left; }
.n-formula .tex .katex-display, .n-result .tex .katex-display { text-align: left; }
.n-step .n-num { color: var(--yellow); margin-right: 6px; }
.n-result { border-left-color: var(--peach); color: var(--peach); }
.n-text { display: inline; }

/* Review sheet at the end of a lesson */
.rv-section { display: flex; flex-direction: column; gap: 16px; }
.rv-sheet { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px 34px; align-items: start; }
.rv-title { margin: 0 0 6px; font-family: var(--font-ui); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--chalk-dim); }
.rv-item { padding: 3px 4px; border-radius: 4px; cursor: pointer; min-width: 0; overflow-wrap: anywhere; }
.rv-item:hover { background: var(--board-raised); }
.rv-item + .rv-item { margin-top: 5px; }
.rv-item > * { margin: 0; }

/* Waiting, recap and errors */
.thinking { display: flex; align-items: center; gap: 10px; padding: 8px 0; color: var(--chalk-dim); font-size: .9em; }
.dots { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--chalk); margin-right: 18px; box-shadow: 13px 0 0 var(--chalk), 26px 0 0 var(--chalk); animation: chalk-pulse 1.2s ease-in-out infinite; }
@keyframes chalk-pulse { 50% { opacity: .3; } }
.b-recap { padding: 14px; border: 1.5px solid var(--line); border-radius: 12px; }
.b-recap .b-heading { display: block; margin: 0 0 10px; background: none; }
.recap-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; font-family: var(--font-ui); }
.b-error { padding: 14px; border: 1.5px solid var(--danger); border-radius: 12px; }
.b-error p { margin: 0 0 10px; }
.b-error button { font-family: var(--font-ui); }
.jump-latest { position: absolute; left: 50%; bottom: 10px; z-index: 2; transform: translateX(-50%); min-height: 36px; padding: 0 14px; background: var(--board-raised); border: 1px solid var(--line); font-family: var(--font-ui); font-size: 13px; color: var(--chalk); }

/* The side answer: one chalk surface, sliding in over the lesson. */
.side .room { inset: 0; padding: 0; }
.side { animation: side-in .26s cubic-bezier(.22, .8, .2, 1); }
@keyframes side-in { from { opacity: 0; transform: translateY(16px); } }

/* Closed, the dock stays rendered off to the side so its sandbox keeps running. Open, it sits on the whiteboard. */
.code-dock { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.code-dock:where(:has(.compute-status:not([hidden])), [data-compute-open]) {
  position: relative;
  flex: none;
  width: auto;
  height: auto;
  min-width: 0;
  padding: 6px 8px;
  overflow: hidden;
  opacity: 1;
  pointer-events: auto;
  border-top: 1px solid var(--line);
}
.surface-white > .code-dock[data-compute-open] { flex: 0 0 62%; min-height: 0; padding: 0; }
.code-dock[data-compute-open] .compute { height: 100%; }
.code-dock[data-compute-open] .compute-panel { flex: 1 1 0; max-height: none; }

@media (min-width: 900px) {
  .board { font-size: 22px; }
  .room { inset: 3px 0 5px; gap: 12px; padding: 12px 14px; grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
  .room[data-mix="notes"], .room[data-mix="review"] { grid-template-columns: minmax(0, 1fr); }
  .b-section { padding: 18px 26px 20px 34px; }
  .surface-white .b-section { padding-top: 36px; gap: 16px 32px; }
  .surface-white .b-section > .block.half { flex-basis: calc(50% - 16px); }
  .nb-head { padding: 10px 20px 8px 26px; font-size: 13.5px; }
  .nb-outline { padding-left: 18px; list-style: decimal; }
  .nb-outline li:not(.now) { display: list-item; }
  .surface-black .b-section { padding: 14px 18px 16px 26px; }
  .surface-black { font-size: .92em; }
  .sim-slider { height: 22px; }

  /* With no graphics in play the chalkboard takes the room, and equations sit two across. */
  .room[data-mix="notes"] .surface-black { font-size: 1.14em; }
  .room[data-mix="notes"] .sheet, .room[data-mix="notes"] .nb-head { width: min(100%, 1120px); margin-inline: auto; }
  .room[data-mix="notes"] .nb-head { border-bottom: 0; }
  .room[data-mix="notes"] .nb-outline { display: flex; flex-wrap: wrap; gap: 2px 26px; }
  .room[data-mix="notes"] .b-section:not(.rv-section) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 40px; align-content: start; }
  .room[data-mix="notes"] .b-section > :not(.block[data-op="math"], .block[data-op="result"], .block[data-op="note"], .arrows) { grid-column: 1 / -1; }
  .room[data-mix="review"] .sheet { width: min(100%, 1120px); }
  .room[data-mix="review"] .rv-sheet { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .surface-white > .code-dock[data-compute-open] { flex-basis: 46%; }
  .stage { flex-direction: row; }
  .code-dock:not([data-compute-open]):has(.compute-status:not([hidden])) { position: absolute; right: 22px; top: 22px; flex: none; border: 0; padding: 0; z-index: 2; }
  .side .board { font-size: 20px; }
  @keyframes side-in { from { opacity: 0; transform: translateX(20px); } }
}
@media (max-width: 899.98px) and (max-height: 720px) {
  .nb-sofar { display: none; }
}
@media (min-width: 1200px) {
  .surface-white:has(> .code-dock[data-compute-open]) { flex-direction: row; }
  .surface-white > .code-dock[data-compute-open] { border-top: 0; border-left: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  .dots, .side { animation: none; }
}
