/* SQL Behind the Scenes — own design (study aid), light + dark */
/* Drafting table: graph paper, navy ink, a highlighter for the step that is running.
   Dark theme is the same drawing as a blueprint. */
:root {
  --bg: #e7ecf0;
  --panel: #fbfcfd;
  --panel-2: #f0f3f6;
  --ink: #13213a;
  --ink-2: #3d4b62;
  --ink-3: #66738a;
  --line: #c6d0d9;
  --line-2: #e0e6ec;
  --grid: rgb(19 33 58 / 7%);
  --accent: #2340c8;
  --accent-ink: #ffffff;
  --accent-soft: #e0e5fb;
  --pk: #8f5c00;
  --pk-soft: #f7eacd;
  --fk: #00776a;
  --fk-soft: #d1eee8;
  --keep: #1f7145;
  --keep-soft: #dcf0e3;
  --drop: #b02c2c;
  --drop-soft: #f8e0de;
  --warn: #b02c2c;
  --mark: #ffe34d;
  --console-bg: #13213a;
  --console-ink: #e3eaf5;
  --console-err: #ffa39b;
  --shadow: none;
  --mono: "Recursive", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Recursive", "IBM Plex Sans Thai", system-ui, sans-serif;
  --math: "STIX Two Math", "Cambria Math", "Latin Modern Math", "Times New Roman", serif;
  --r: 6px;
  --deck-h: 200px;
  --top-h: 63px; /* measured from .topbar by app.js */
  color-scheme: light;
}
/* UI size: everything outside the SVG diagrams is in rem, so one root size scales the page.
   On wider screens it follows the window (smaller window, more compact page); the −/+ control
   in the top bar multiplies it (--ui-scale, remembered in this browser). Phones keep 16px. */
:root { --fit: clamp(12px, min(0.9vw, 1.6vh), 16px); }
@media (max-width: 900px) { :root { --fit: 16px; } }
html { font-size: calc(var(--fit) * var(--ui-scale, 1)); }
:root[data-theme="dark"] {
  --bg: #0b1727;
  --panel: #102136;
  --panel-2: #14283f;
  --ink: #e6eef8;
  --ink-2: #b0c1d7;
  --ink-3: #8195b0;
  --line: #26405f;
  --line-2: #1b3049;
  --grid: rgb(140 185 255 / 8%);
  --accent: #93abff;
  --accent-ink: #0b1727;
  --accent-soft: #1f3468;
  --pk: #f2b84b;
  --pk-soft: #3b3018;
  --fk: #52d8c4;
  --fk-soft: #113a3a;
  --keep: #72d49d;
  --keep-soft: #143425;
  --drop: #ff8e88;
  --drop-soft: #3c1d22;
  --warn: #ff8e88;
  --mark: #75610f;
  --console-bg: #06101d;
  --console-ink: #d6e0ee;
  --console-err: #ffa39b;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 0.9375rem/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, select, input, textarea { font: inherit; color: inherit; }
h1, h2 { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -62.4375rem; top: 0.5rem; background: var(--accent); color: var(--accent-ink); padding: 0.5rem 0.75rem; border-radius: 8px; z-index: 10; }
.skip:focus { left: 0.75rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd { font: 500 0.75rem var(--mono); opacity: .75; margin-left: 0.25rem; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.back { color: var(--ink-2); text-decoration: none; font-weight: 500; white-space: nowrap; padding: 0.5rem 0.25rem; }
.back:hover { color: var(--accent); }
.topbar h1 { font-size: 1.125rem; font-weight: 700; letter-spacing: -0.01em; flex: 1; min-width: 0; }
.topbar h1 small { font-weight: 400; color: var(--ink-3); font-size: 0.875rem; margin-left: 0.5rem; }
.dbpick select, .examples select, .speed select {
  appearance: none; background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23808a9c' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center / 11px;
  border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 2.125rem 0.5rem 0.75rem; min-height: 2.5rem; cursor: pointer;
}
.icon-button { display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; }
.icon-button svg { width: 1.125rem; height: 1.125rem; }
.icon-button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.icon-button:disabled { opacity: .4; cursor: default; }
#themeBtn .i-moon { display: none; }
:root[data-theme="dark"] #themeBtn .i-sun { display: none; }
:root[data-theme="dark"] #themeBtn .i-moon { display: block; }

.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 0.5rem 0.875rem; min-height: 2.5rem; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-quiet { background: transparent; }
.btn-small { min-height: 2rem; padding: 0.25rem 0.625rem; font-size: 0.8125rem; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(21.25rem, 30%) 1fr; gap: 1rem; padding: 1rem 1.5rem; align-items: start; }
.pane { min-width: 0; }
.pane-sql { position: sticky; top: calc(var(--top-h) + 1.125rem); display: flex; flex-direction: column; gap: 0.75rem; max-height: calc(100vh - var(--top-h) - 2.125rem); }
.pane-h { display: flex; align-items: center; gap: 0.75rem; }
.pane-h h2, .console-h h2 { font-size: 0.8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); flex: 1; }
.pane-h h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink-3); margin-left: 0.375rem; font-size: 0.8125rem; }
.examples select { max-width: 14.375rem; }

/* editor: textarea over a backdrop that paints the current clause */
.editor-wrap { position: relative; height: clamp(11.25rem, 34vh, 22.5rem); border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.editor, .editor-back { position: absolute; inset: 0; margin: 0; padding: 0.875rem 1rem; font: 0.875rem/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 2; border: 0; overflow: auto; }
.editor-back { color: transparent; pointer-events: none; }
.editor-back mark { background: var(--mark); color: transparent; border-radius: 3px; box-shadow: 0 0 0 2px var(--mark); transition: background .2s; }
.editor { background: transparent; resize: none; color: var(--ink); caret-color: var(--accent); }
.editor:focus { outline: none; }
.editor-wrap:focus-within { border-color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.dbnote { margin: 0; font-size: 0.8125rem; color: var(--ink-3); }
.vars { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: var(--r); padding: 0.75rem; display: grid; gap: 0.5rem; }
.vars p { margin: 0; font-size: 0.875rem; }
.vars label { display: grid; gap: 0.25rem; font: 0.8125rem var(--mono); }
.vars input { border: 1px solid var(--line); border-radius: 6px; padding: 0.5rem; background: var(--panel); font-family: var(--mono); }
.console-h { display: flex; align-items: center; }
.console { margin: 0; flex: 1; min-height: 10rem; overflow: auto; background: var(--console-bg); color: var(--console-ink); border-radius: var(--r); padding: 0.75rem 0.875rem; font: 0.7812rem/1.45 var(--mono); white-space: pre; }
.console .blk { padding: 2px 0.375rem; margin: 0 -0.375rem; border-radius: 6px; border-left: 3px solid transparent; }
.console .blk.has-frames { cursor: pointer; }
.console .blk.has-frames:hover { background: rgb(255 255 255 / 5%); }
.console .blk.is-current { border-left-color: #ffcf5a; background: rgb(255 207 90 / 8%); }
.console .blk.is-err { color: var(--console-err); }
.console .blk.is-plus { color: #9fb0c8; }

/* ---------- narration ---------- */
.pane-show { display: flex; flex-direction: column; gap: 0.75rem; }
.narr { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0.875rem 1.125rem; box-shadow: var(--shadow); border-left: 5px solid var(--accent); min-height: 7.5rem; }
.narr.is-warn { border-left-color: var(--warn); }
.narr-top { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.narr h2 { font-size: 1.125rem; font-weight: 650; letter-spacing: -.01em; flex: 1; min-width: 12.5rem; }
.narr p { margin: 0.375rem 0 0; color: var(--ink-2); max-width: 78ch; }
.phase { font: 600 0.75rem var(--mono); letter-spacing: .04em; padding: 0.1875rem 0.5rem; border-radius: 6px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.phase.is-warn { background: var(--drop-soft); color: var(--drop); }
.read { font-size: 0.75rem; color: var(--ink-3); border: 1px solid var(--line); border-radius: 99px; padding: 2px 0.625rem; white-space: nowrap; }
.hints { margin: 0.625rem 0 0; padding: 0; list-style: none; display: grid; gap: 0.375rem; }
.hints li { font-size: 0.8125rem; padding: 0.375rem 0.625rem; border-radius: 6px; background: var(--pk-soft); }
.hints li.hint-warn { background: var(--drop-soft); }
.hints li::before { content: "Hint · "; font-weight: 600; }
.hints li.hint-warn::before { content: "Watch out · "; }

/* evaluation trace: innermost part first */
.trace { margin: 0.625rem 0 0; padding: 0.625rem 0.75rem 0.625rem 2.125rem; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 0.1875rem; font: 0.7812rem/1.45 var(--mono); max-height: 13.75rem; overflow: auto; }
.trace li { animation: tr-in .35s ease-out backwards; animation-delay: calc(var(--d) * 260ms); }
.trace li::marker { color: var(--ink-3); }
.trace code { font: inherit; color: var(--ink-2); }
.trace .arrow { color: var(--ink-3); margin: 0 0.375rem; }
.trace b { font-weight: 600; color: var(--accent); }
.trace li.is-true b { color: var(--keep); }
.trace li.is-false b { color: var(--drop); }
@keyframes tr-in { from { opacity: 0; transform: translateX(-6px); } }

/* ---------- timeline ---------- */
.timeline { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0.625rem 0.75rem; display: grid; gap: 0.5rem; }
.tl-row { display: flex; align-items: center; gap: 0.5rem; }
.play { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.play:hover:not(:disabled) { color: var(--accent-ink) !important; filter: brightness(1.08); }
.play .i-pause { display: none; }
.play.is-playing .i-pause { display: block; }
.play.is-playing .i-play { display: none; }
#scrub { flex: 1; accent-color: var(--accent); min-width: 5rem; height: 2rem; }
.pos { font: 0.75rem var(--mono); color: var(--ink-3); white-space: nowrap; min-width: 5.75rem; text-align: right; }
.speed select { min-height: 2.25rem; padding: 0.25rem 1.875rem 0.25rem 0.625rem; }
.tl-chips { flex-wrap: wrap; justify-content: space-between; }
.chips { display: flex; flex-wrap: wrap; gap: 0.375rem; align-items: center; }
.chip { border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-2); border-radius: 99px; padding: 0.25rem 0.75rem; min-height: 1.875rem; font: 600 0.75rem var(--mono); cursor: pointer; position: relative; }
.chip + .chip::before { content: ""; position: absolute; left: -0.4375rem; top: 50%; width: 0.375rem; height: 1px; background: var(--line); }
.chip.is-done { color: var(--ink); border-color: var(--ink-3); }
.chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.is-warn { border-color: var(--warn); color: var(--warn); }
.chip.is-on.is-warn { background: var(--warn); color: var(--panel); }
.stmtnav { display: flex; align-items: center; gap: 0.375rem; }
.stmtlabel { font-size: 0.8125rem; color: var(--ink-3); }

/* ---------- ERD + stage ---------- */
.split { display: grid; grid-template-columns: minmax(22.5rem, 1fr) minmax(0, 1.15fr); gap: 0.75rem; align-items: start; }
.split.is-erd-only { grid-template-columns: minmax(0, 1fr); }
.split.is-erd-only .stage-pane { display: none; }
.erd-pane, .stage-pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0.75rem; min-width: 0; }
.erd-pane { position: sticky; top: calc(var(--top-h) + 1.125rem); }
.erd-scroll { overflow: auto; max-height: calc(100vh - 23.75rem); min-height: 16.25rem; margin-top: 0.5rem; border-radius: 8px; background: var(--panel-2); }
.erd { height: auto; display: block; touch-action: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 0.25rem 0.625rem; min-height: 2rem; font-size: 0.75rem; cursor: pointer; color: var(--ink-2); }
.seg button.is-on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 0.25rem 0.875rem; margin: 0.5rem 0 0; font-size: 0.75rem; color: var(--ink-3); }
.lg-pk { color: var(--pk); } .lg-fk { color: var(--fk); }

.erd-empty { fill: var(--ink-3); font: 14px var(--sans); }
.erd-rect { fill: var(--panel); stroke: var(--line); stroke-width: 1.2; transition: stroke .25s, fill .25s; }
.erd-sep { stroke: var(--line); }
.erd-title { font: 700 13px var(--sans); fill: var(--ink); letter-spacing: .02em; }
.erd-rowcount { font: 11px var(--mono); fill: var(--ink-3); }
.erd-colname { font: 12px var(--mono); fill: var(--ink-2); }
.erd-type { font: 10.5px var(--mono); fill: var(--ink-3); }
.erd-colbg { fill: transparent; transition: fill .25s; }
.erd-col.is-pk .erd-colname { fill: var(--ink); font-weight: 600; }
.erd-col.is-fk .erd-colname { fill: var(--fk); }
.erd-underline { stroke: var(--ink); stroke-width: 1; }
.erd-key { stroke: var(--pk); stroke-width: 1.6; stroke-linecap: round; }
.erd-col.is-lit .erd-colbg { fill: var(--pk-soft); }
.erd-col.is-fk.is-lit .erd-colbg { fill: var(--fk-soft); }
.erd-col.is-lit .erd-colname { fill: var(--ink); font-weight: 700; }
.erd-box { cursor: grab; transition: opacity .3s; }
.erd-box:active { cursor: grabbing; }
.erd-box.is-active .erd-rect { stroke: var(--accent); stroke-width: 2.4; fill: var(--accent-soft); }
.erd-box.is-dim { opacity: .38; }
.erd-line { fill: none; stroke: var(--ink-3); stroke-width: 1.4; }
.erd-hit { fill: none; stroke: transparent; stroke-width: 10; }
.erd-edge.is-disabled .erd-line { stroke-dasharray: 5 4; }
.erd-edge.is-dim { opacity: .3; }
.erd-edge.is-active .erd-line { stroke: var(--fk); stroke-width: 3; stroke-dasharray: 8 6; animation: flow 0.9s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -14; } }
.erd-card { font: 600 11px var(--mono); fill: var(--ink-2); }
.erd-rel { font: italic 11px var(--sans); fill: var(--ink-3); paint-order: stroke; stroke: var(--panel-2); stroke-width: 4px; }
.erd-edge.is-active .erd-card { fill: var(--fk); }
.erd-crow path { stroke: var(--ink-3); stroke-width: 1.4; }
.erd-crow-o { fill: var(--panel); stroke: var(--ink-3); stroke-width: 1.4; }
.erd-edge.is-active .erd-crow path, .erd-edge.is-active .erd-crow-o { stroke: var(--fk); }

.stage { position: relative; overflow: auto; max-height: calc(100vh - 20.625rem); min-height: 18.75rem; }
.links { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 2; overflow: visible; }
.link { fill: none; stroke-width: 2; stroke-linecap: round; opacity: .85; }
.link-join { stroke: var(--fk); }
.link-fk { stroke: var(--pk); stroke-width: 2.5; }
.link.is-off { stroke-dasharray: 3 4; opacity: .5; }
.cards { display: flex; flex-wrap: wrap; gap: 0.875rem 1.75rem; align-items: flex-start; }
.cards[data-count="1"] .tcard { flex-basis: 100%; }
.tcard { flex: 1 1 17.5rem; min-width: 0; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.tcard.is-out { flex-basis: 100%; border-color: var(--accent); }
.tcard-h { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.5rem 0.75rem; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.tcard-name { font: 600 0.8125rem var(--mono); }
.tcard-count { font-size: 0.75rem; color: var(--ink-3); white-space: nowrap; }
.tscroll { overflow: auto; max-height: 26.25rem; }
.tcard table { border-collapse: collapse; width: 100%; font: 0.7812rem/1.35 var(--mono); }
.tcard th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 600; padding: 0.375rem 0.625rem; border-bottom: 1.5px solid var(--line); white-space: nowrap; color: var(--ink-2); z-index: 1; }
.tcard th.num, .tcard td.num { text-align: right; }
.tcard th .badge { display: inline-grid; place-items: center; margin-right: 0.25rem; vertical-align: -2px; }
.badge.pk svg { width: 0.9375rem; height: 0.625rem; fill: none; stroke: var(--pk); stroke-width: 1.8; stroke-linecap: round; }
.badge.fk { color: var(--fk); font-weight: 700; }
.tcard th.is-lit { background: var(--pk-soft); color: var(--ink); }
.tcard td { padding: 0.25rem 0.625rem; border-bottom: 1px solid var(--line-2); white-space: nowrap; max-width: 16.25rem; overflow: hidden; text-overflow: ellipsis; }
.tcard td.is-lit { background: color-mix(in srgb, var(--pk-soft) 70%, transparent); font-weight: 600; }
.tcard td.is-linked { box-shadow: inset 0 0 0 2px var(--fk); }
.tcard td.is-null { color: var(--ink-3); font-style: italic; opacity: .7; }
.tcard td.note, .tcard th.note { font-family: var(--sans); font-size: 0.75rem; color: var(--ink-3); white-space: normal; min-width: 9.375rem; max-width: 17.5rem; }
.tcard tr { transition: background .25s, opacity .25s; }
.tcard tr.has-g td:first-child { box-shadow: inset 4px 0 0 hsl(var(--g) 65% 52%); }
.tcard tr.has-g { background: hsl(var(--g) 70% 50% / 9%); }
.tcard tr.st-keep, .tcard tr.st-kept, .tcard tr.st-match, .tcard tr.st-new { background: var(--keep-soft); }
.tcard tr.st-keep td.note, .tcard tr.st-kept td.note, .tcard tr.st-new td.note { color: var(--keep); }
.tcard tr.st-drop, .tcard tr.st-dropped, .tcard tr.st-skip, .tcard tr.st-deleted, .tcard tr.st-dup { background: var(--drop-soft); }
.tcard tr.st-drop td:not(.note), .tcard tr.st-dropped td:not(.note), .tcard tr.st-deleted td:not(.note), .tcard tr.st-dup td:not(.note) { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--drop) 60%, transparent); opacity: .7; }
.tcard tr.st-drop td.note, .tcard tr.st-dropped td.note, .tcard tr.st-deleted td.note { color: var(--drop); }
.tcard tr.st-outer { background: var(--pk-soft); }
.tcard tr.st-changed { background: var(--accent-soft); }
.tcard tr.is-src { outline: 2px solid var(--accent); outline-offset: -2px; }
.tcard tr.is-cur { outline: 2.5px solid var(--accent); outline-offset: -2px; position: relative; z-index: 1; animation: cur-in .4s ease-out; }
.tcard tr.is-cur td:first-child { box-shadow: inset 5px 0 0 var(--accent); }
@keyframes cur-in { from { background: var(--accent-soft); } }
.tcard tr.st-pending td { opacity: .32; }
.tcard th.is-hl { background: var(--accent-soft); color: var(--accent); }
.tcard td.is-hl { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.tcard-more, .tcard-none { margin: 0; padding: 0.375rem 0.75rem; font-size: 0.75rem; color: var(--ink-3); }
.stage-empty { color: var(--ink-3); padding: 1.5rem; text-align: center; margin: 0; }

.foot { padding: 0.5rem 1.5rem 2rem; color: var(--ink-3); font-size: 0.8125rem; max-width: 110ch; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .split { grid-template-columns: 1fr; }
  .erd-pane { position: static; }
  .erd-scroll { max-height: 26.25rem; }
  .stage { max-height: none; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 0.75rem 1rem; }
  .pane-sql { position: static; max-height: none; }
  .console { max-height: 20rem; }
  .topbar { padding: 0.625rem 1rem; gap: 0.625rem; flex-wrap: wrap; }
  .topbar h1 small { display: none; }
}
@media (max-width: 560px) {
  .back-t { display: none; }
  .topbar h1 { font-size: 1rem; }
  .dbpick { order: 3; width: 100%; }
  .dbpick select { width: 100%; }
  .examples select { max-width: 10.625rem; }
  .pos { min-width: 0; font-size: 0.6875rem; }
  .topbar { position: static; }
  .tl-row { gap: 0.375rem; }
  .speed { display: none; }
  .tl-row:first-child { flex-wrap: wrap; }
  .narr h2 { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .trace li, .tcard tr.is-cur { animation: none; }
  .erd-edge.is-active .erd-line { animation: none; }
  * { transition: none !important; }
}

/* ---------- relational algebra view ---------- */
.pane-gap { flex: 1; }
.alg { display: grid; gap: 0.625rem; grid-template-columns: minmax(0, 1fr); min-width: 0; }
#algBody { display: grid; gap: 0.625rem; grid-template-columns: minmax(0, 1fr); min-width: 0; }
#algBody[hidden] { display: none; }
.alg-empty { color: var(--ink-3); font-size: 0.8125rem; padding: 1.5rem 0.25rem; }
.alg-formula { margin: 0; padding: 0.625rem 0.75rem; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; font: 0.9375rem/1.9 var(--math); color: var(--ink); overflow-x: auto; }
.alg-formula .f-line { display: block; white-space: nowrap; }
.alg-formula b { font: 600 0.8125rem var(--mono); }
.alg-formula sub, .alg-node sub { font: 0.6875rem var(--mono); color: var(--ink-2); }
.alg-def { font: 600 0.8125rem var(--mono); color: var(--accent); }
.f-op { border-radius: 4px; padding: 0 2px; transition: background .2s, color .2s; }
.f-op.is-done { color: var(--ink-3); }
.f-op.is-done sub { color: var(--ink-3); }
.f-op.is-cur { background: var(--mark); color: var(--ink); }
.f-op.is-cur sub { color: var(--ink); }
.alg-trees { display: flex; flex-wrap: wrap; gap: 0.875rem; align-items: flex-start; overflow-x: auto; padding-bottom: 0.25rem; max-height: 32.5rem; }
.alg-tree { flex: 0 1 auto; overflow-x: auto; }
.alg-tree { margin: 0; padding: 0.625rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); min-width: 0; }
.alg-tree figcaption { font: 600 0.75rem var(--mono); color: var(--accent); margin-bottom: 0.375rem; }
.alg-note { margin: 0; font-size: 0.8125rem; line-height: 1.5; color: var(--ink-2); min-height: 1.5em; }

/* query tree: root on top, children below, joined by lines */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; display: flex; justify-content: center; }
.tree ul { padding-top: 1rem; position: relative; }
.tree li { display: flex; flex-direction: column; align-items: center; position: relative; padding: 1rem 0.375rem 0; }
.tree > li { padding-top: 0; }
.tree ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 1rem; border-left: 1.5px solid var(--ink-3); }
.tree li::before, .tree li::after { content: ""; position: absolute; top: 0; height: 1rem; width: 50%; border-top: 1.5px solid var(--ink-3); }
.tree li::before { right: 50%; }
.tree li::after { left: 50%; border-left: 1.5px solid var(--ink-3); }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:only-child { padding-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border-top: 0; }
.tree li:last-child::before { border-right: 1.5px solid var(--ink-3); }
.tree li:last-child::after { border-left: 0; }
.tree > li::before, .tree > li::after { display: none; }
.alg-node { font: 0.875rem var(--math); color: var(--ink); background: var(--panel); border: 1.5px solid var(--line); border-radius: 8px; padding: 0.25rem 0.5625rem; max-width: 16.25rem; cursor: pointer; text-align: center; line-height: 1.35; transition: background .2s, border-color .2s, opacity .2s; }
.alg-node .sym { font-size: 1.125rem; }
.alg-node sub { display: inline; overflow-wrap: anywhere; }
.alg-node b { font: 600 0.7812rem var(--mono); }
.alg-node.op-rel { border-style: dashed; }
.alg-node:hover { border-color: var(--accent); }
.alg-node:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.alg-node.is-done { background: var(--keep-soft); border-color: var(--keep); }
.alg-node.is-cur { background: var(--mark); border-color: var(--pk); color: var(--ink); box-shadow: 0 0 0 4px color-mix(in srgb, var(--mark) 45%, transparent); }
.alg-node.is-cur sub { color: var(--ink); }
.alg-badge { font: 600 0.75rem var(--math); border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-2); border-radius: 999px; padding: 0.1875rem 0.625rem; cursor: pointer; }
.alg-badge:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- example browser ---------- */
.ex-btn { display: inline-flex; align-items: center; gap: 0.4375rem; }
.ex-btn .n { font: 600 0.6875rem var(--mono); background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 0.4375rem; }
.exb { width: min(53.75rem, calc(100vw - 2rem)); max-height: min(86vh, 56.25rem); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 30%); }
.exb[open] { display: flex; flex-direction: column; }
.exb::backdrop { background: rgb(10 14 22 / 45%); }
.exb-head { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 1.25rem 0.5rem; }
.exb-head h2 { flex: 1; margin: 0; font-size: 1.125rem; }
.exb-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.625rem; padding: 0.25rem 1.25rem 0.75rem; border-bottom: 1px solid var(--line); }
.exb-searchwrap { flex: 1 1 15rem; }
.exb-search { width: 100%; min-height: 2.375rem; padding: 0.375rem 0.75rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--ink); font: 0.875rem var(--sans); }
.exb-search:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.exb-count { font-size: 0.75rem; color: var(--ink-3); margin-left: auto; }
.exb-list { overflow: auto; padding: 0.5rem 0.75rem 1rem; }
.exb-group { border-bottom: 1px solid var(--line-2); }
.exb-group summary { display: flex; align-items: baseline; gap: 0.625rem; padding: 0.75rem 0.5rem; cursor: pointer; list-style: none; flex-wrap: wrap; }
.exb-group summary::-webkit-details-marker { display: none; }
.exb-group summary::before { content: "▸"; color: var(--ink-3); width: 0.625rem; transition: transform .15s; }
.exb-group[open] summary::before { transform: rotate(90deg); }
.exb-gname { font-weight: 600; font-size: 0.9375rem; }
.exb-gn { font: 600 0.6875rem var(--mono); color: var(--ink-3); background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 0.4375rem; }
.exb-ghint { font-size: 0.7812rem; color: var(--ink-3); }
.exb-group ul { list-style: none; margin: 0 0 0.625rem; padding: 0 0 0 1.125rem; display: grid; gap: 2px; }
.exb-item { width: 100%; text-align: left; display: grid; gap: 0.1875rem; padding: 0.5rem 0.625rem; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--ink); cursor: pointer; font: inherit; }
.exb-item:hover { background: var(--panel-2); border-color: var(--line); }
.exb-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.exb-item.is-last { border-color: var(--accent); }
.exb-title { font-size: 0.875rem; line-height: 1.35; }
.exb-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; font-size: 0.75rem; color: var(--ink-3); min-width: 0; }
.exb-meta code { font: 0.75rem var(--mono); color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tag { font: 600 0.6875rem var(--sans); padding: 1px 0.4375rem; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; max-width: 16.25rem; overflow: hidden; text-overflow: ellipsis; }
.tag-lec { background: var(--pk-soft); border-color: transparent; color: var(--pk); }
.tag-mine { background: var(--fk-soft); border-color: transparent; color: var(--fk); }
.exb-none { padding: 1.5rem 0.5rem; color: var(--ink-3); }
@media (max-width: 560px) {
  .exb { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .exb-count { width: 100%; margin: 0; }
}

/* previous / next example */
.ex-nav { display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.5rem; }
.ex-now { flex: 1; min-width: 0; margin: 0; display: grid; font-size: 0.8125rem; line-height: 1.35; }
.ex-now b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-now span { font-size: 0.75rem; color: var(--ink-3); }
.console .blk.is-note { color: #9fd3a8; white-space: pre-wrap; }

/* ---------- ERD as in class (Chen) ---------- */
.chen-box { fill: var(--panel); stroke: var(--ink-2); stroke-width: 1.3; }
.chen-assoc { fill: none; stroke: var(--ink-2); stroke-width: 1; }
.chen-name { font: 600 15px var(--sans); fill: var(--ink); letter-spacing: .02em; }
.chen-name.is-assoc { font-size: 12px; }
.chen-line { fill: none; stroke: var(--ink-2); stroke-width: 1.3; }
.chen-diamond { fill: var(--panel); stroke: var(--ink-2); stroke-width: 1.3; }
.chen-verb { font: 13px var(--sans); fill: var(--ink); }
.chen-verb.is-fk { font: 11px var(--mono); fill: var(--fk); }
.chen-card { font: 12px var(--sans); fill: var(--ink-2); }
.chen-rel.is-missing .chen-line, .chen-rel.is-missing .chen-diamond { stroke-dasharray: 4 3; }
.chen-ent.is-absent { opacity: .45; }
.chen-ent.is-extra .chen-box { stroke-dasharray: 5 3; }
.chen-ent, .chen-rel { transition: opacity .25s; }
.chen-ent.is-dim, .chen-rel.is-dim { opacity: .3; }
.chen-ent.is-active .chen-box { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2.2; }
.chen-ent.is-active .chen-assoc { stroke: var(--accent); }
.chen-rel.is-active .chen-line { stroke: var(--fk); stroke-width: 2.6; }
.chen-rel.is-active .chen-diamond { fill: var(--fk-soft); stroke: var(--fk); stroke-width: 2.2; }
.chen-rel.is-active .chen-card { fill: var(--fk); font-weight: 600; }
.erd-schema { margin: 0.625rem 2px 0; display: grid; gap: 0.25rem; font: 0.8125rem/1.5 var(--sans); color: var(--ink-2); }
.erd-schema p { margin: 0; padding: 2px 0.375rem; border-radius: 6px; transition: opacity .25s, background .25s; }
.erd-schema b { color: var(--ink); letter-spacing: .02em; }
.erd-schema sup { color: var(--fk); font-size: 0.625rem; margin-left: 1px; }
.erd-schema .sc { border-radius: 3px; }
.erd-schema .sc.is-lit { background: var(--mark); color: var(--ink); }
.erd-schema p.is-active { background: var(--accent-soft); }
.erd-schema p.is-dim { opacity: .45; }
.erd-source { margin: 0.375rem 2px 0; font-size: 0.75rem; color: var(--ink-3); }

.erd-pane.is-chen .lg-drag, .erd-pane.is-chen .lg-pk { display: none; }

/* As in class: the handout figure is wide and short, so it gets the full width with the tables below */
.split.is-chen { grid-template-columns: minmax(0, 1fr); }
.split.is-chen .erd-pane { position: static; }
.erd-pane.is-chen .erd-scroll { min-height: 0; max-height: none; }
.erd-pane.is-chen .erd-schema { grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr)); column-gap: 0.875rem; }

/* Data flow (L21–L22, local lecture file only): the lecture's "Oracle instance" figure, one step at a time */
.flow { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5rem; width: 100%; min-width: 0; align-content: start; }
.flow[hidden] { display: none; }
.flow-steps { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.375rem; }
.flow-steps-l { font: 600 0.75rem var(--mono); color: var(--ink-3); margin-left: 0.375rem; }
.flow-steps-l:first-child { margin-left: 0; }
.flow-steps .btn.is-on { background: var(--mark); border-color: var(--ink-2); color: var(--ink); }
.flow-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem 1rem; }
.flow-cap { display: flex; align-items: center; gap: 0.5rem; min-height: 2rem; flex: 1 1 16rem; min-width: 0; }
.flow-cap p { margin: 0; flex: 1; min-width: 0; font-size: 0.875rem; }
.flow-cap p span { color: var(--ink-3); margin-left: 0.25rem; }
.ex-slide { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
.ex-slide:hover { color: var(--ink); }
.flow-cap .ex-slide { margin-left: 0.25rem; }
.flow-scroll { overflow: auto; background-color: var(--panel); background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 16px 16px; border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem; }
.flow-svg { display: block; width: 100%; min-width: 38rem; height: auto; }
.flow-cyl path, .flow-cyl ellipse { fill: var(--panel); stroke: var(--ink-2); stroke-width: 1.2; }
.flow-cyl.is-big path, .flow-cyl.is-big ellipse { fill: var(--panel-2); }
.flow-cyl-t { font: 13px var(--sans); fill: var(--ink); }
.flow-cyl.is-big .flow-cyl-t { font-size: 17px; letter-spacing: 0.02em; }
.flow-band { fill: var(--mark); opacity: 0.55; stroke: var(--ink-2); stroke-width: 1; }
.flow-brace { fill: none; stroke: var(--ink-2); stroke-width: 1.1; }
.flow-edge { fill: none; stroke: var(--ink-2); stroke-width: 1.1; }
.flow-edge.is-lit { stroke: var(--accent); stroke-width: 2.4; }
.flow-head { fill: var(--ink-2); }
.flow-head.is-lit { fill: var(--accent); }
.flow-node rect, .flow-node path { fill: var(--panel); stroke: var(--ink-2); stroke-width: 1.1; }
.flow-node .flow-rim { fill: none; }
.flow-node.is-mark rect, .flow-node.is-mark path:not(.flow-rim) { fill: var(--mark); }
.flow-node.is-lit rect, .flow-node.is-lit path:not(.flow-rim) { stroke: var(--accent); stroke-width: 2.6; }
.flow-node.is-active:not(.is-mark) rect { fill: var(--accent-soft); }
.flow-node.is-pick { cursor: pointer; }
.flow-node.is-pick:hover rect, .flow-node.is-pick:hover path:not(.flow-rim) { stroke: var(--accent); }
.flow-node.is-pick:focus-visible { outline: none; }
.flow-node.is-pick:focus-visible rect, .flow-node.is-pick:focus-visible path:not(.flow-rim) { stroke: var(--accent); stroke-width: 3; }
.flow-label { font: 12.5px var(--mono); fill: var(--ink); }
.flow-label.is-italic { font-style: italic; }
.flow-small { font: 11px var(--sans); fill: var(--ink); }

/* =====================================================================
   Drafting-table pass. Overrides earlier rules on purpose; keep it last.
   ===================================================================== */

/* one family, two voices: Recursive Sans for words, Recursive Mono for SQL and data */
.editor, .editor-back, .console, kbd, code, .trace, .pos, .phase, .chip, .tcard-name, .tcard table,
.vars label, .vars input, .ex-btn .n, .exb-gn, .alg-formula b, .alg-formula sub, .alg-node sub, .alg-node b,
.alg-def, .alg-tree figcaption, .erd-rowcount, .erd-colname, .erd-type, .erd-card, .chen-verb.is-fk,
.rd-ref, .rd-count, .char-codes, .flow-label, .flow-steps-l {
  font-variation-settings: "MONO" 1;
}
body { font-size: 0.9375rem; line-height: 1.55; }
.brand { font-variation-settings: "CASL" 1; font-weight: 800; letter-spacing: -.015em; }

/* top bar: a ruled title block, like the corner of a drawing sheet */
.topbar { background: var(--panel); border-bottom: 2px solid var(--ink); padding: 0.625rem 1.5rem; }
.topbar h1 { font-size: 1.1875rem; }
.topbar h1 small { color: var(--ink-3); font-weight: 400; }

/* controls: square-ish, hairline, no shadows */
.btn, .icon-button, .dbpick select, .speed select, .seg { border-radius: var(--r); }
.btn { background: var(--panel); border-color: var(--line); font-weight: 550; }
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.btn-primary:hover:not(:disabled) { filter: none; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.icon-button { background: var(--panel); }
.icon-button:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.seg { background: var(--panel); }
.seg button { font-weight: 500; }
.seg button.is-on { background: var(--ink); color: var(--panel); font-weight: 600; }

/* section headings: plain sentence case, no tracked capitals */
.pane-h h2, .console-h h2 { font-size: 0.9375rem; font-weight: 650; text-transform: none; letter-spacing: 0; color: var(--ink); }

/* the script: a sheet clipped to the board */
.editor-wrap { border: 1px solid var(--line); border-top: 3px solid var(--ink); border-radius: 0 0 var(--r) var(--r); box-shadow: none; }
.editor, .editor-back { font-size: 0.9062rem; line-height: 1.65; }
.editor-back mark { background: var(--mark); box-shadow: 0 0 0 2px var(--mark); border-radius: 2px; }
.console { border-radius: var(--r); font-size: 0.7812rem; }
.console .blk.is-current { border-left-color: var(--mark); background: rgb(255 227 77 / 9%); }

/* previous / next example: one quiet strip */
.ex-nav { padding: 0.375rem 0.375rem 0.375rem 0.375rem; border: 1px dashed var(--line); border-radius: var(--r); margin: 0; }

/* ---------- the deck: what is happening now, and the controls, always in view ---------- */
.deck { position: sticky; top: var(--top-h); z-index: 4; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 10px 18px -16px rgb(19 33 58 / 45%); }
.deck .narr { border: 0; border-radius: 0; box-shadow: none; background: transparent; border-left: 0; padding: 0.875rem 1.125rem 0.625rem; min-height: 0; max-height: 34vh; overflow: auto; }
.deck .timeline { border: 0; border-top: 1px solid var(--line-2); border-radius: 0; background: transparent; padding: 0.625rem 0.875rem 0.75rem; }
.narr h2 { font-size: 1.1875rem; font-weight: 700; letter-spacing: -.01em; }
.narr p { color: var(--ink-2); }
.phase { background: var(--ink); color: var(--panel); border-radius: 4px; font-weight: 600; }
.phase.is-warn { background: var(--drop); color: #fff; }
.narr.is-warn + .timeline, .deck:has(.narr.is-warn) { border-color: var(--drop); }
.play { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.play:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink) !important; filter: none; }
#scrub { accent-color: var(--ink); }

/* the clause order as a line with stations: the one bold thing on the page */
.tl-chips { align-items: flex-end; }
.chips { flex-wrap: nowrap; gap: 0; overflow-x: auto; position: relative; padding: 2px 2px 0.25rem; scrollbar-width: thin; }
.chip { border: 0; background: none; border-radius: 0; min-height: 0; padding: 1.25rem 0.875rem 2px; font-size: 0.75rem; font-weight: 600; color: var(--ink-3); white-space: nowrap; }
.chip::after { content: ""; position: absolute; top: 0.25rem; left: 50%; width: 0.75rem; height: 0.75rem; margin-left: -0.375rem; border-radius: 50%; border: 2px solid var(--ink-3); background: var(--panel); box-sizing: border-box; transition: transform .2s, background .2s; }
.chip::before, .chip + .chip::before { content: ""; position: absolute; top: 0.5625rem; left: 0; right: 0; width: auto; height: 2px; background: var(--line); }
.chip:first-child::before { left: 50%; }
.chip:last-child::before { right: 50%; }
.chip:only-child::before { display: none; }
.chip.is-done { color: var(--ink); border: 0; }
.chip.is-done::after { background: var(--ink); border-color: var(--ink); }
.chip.is-done::before { background: var(--ink); }
.chip.is-on::before { background: linear-gradient(90deg, var(--ink) 50%, var(--line) 50%); }
.chip.is-on { background: none; color: var(--ink); }
.chip.is-on::after { background: var(--mark); border-color: var(--ink); transform: scale(1.5); }
.chip.is-on { text-decoration: underline 3px var(--mark); text-underline-offset: 4px; }
.chip:hover { color: var(--ink); }
.chip:hover::after { border-color: var(--ink); }
.chip.is-warn, .chip.is-on.is-warn { color: var(--drop); background: none; }
.chip.is-warn::after { border-color: var(--drop); }
.chip.is-on.is-warn::after { background: var(--drop); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- drawing surfaces sit on graph paper ---------- */
.erd-scroll, .stage, .alg-trees {
  background-color: var(--panel-2);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 20px 20px;
}
.stage { border-radius: var(--r); padding: 0.75rem; }
.erd-pane, .stage-pane { border-radius: var(--r); background: var(--panel); }
.stage-pane { padding: 0.5rem; }
.erd-pane { position: sticky; top: calc(var(--top-h) + var(--deck-h) + 0.75rem); }
.erd-scroll { max-height: calc(100vh - var(--top-h) - var(--deck-h) - 7.5rem); min-height: 15rem; }
.stage { max-height: calc(100vh - var(--top-h) - var(--deck-h) - 2.5rem); min-height: 17.5rem; }
.cards:empty::before { content: "Run a query and its tables appear here, one step at a time."; display: block; padding: 2.5rem 0.75rem; text-align: center; color: var(--ink-3); }

/* intermediate tables: index cards pinned to the paper */
.tcard { border-color: var(--line); border-radius: 4px; box-shadow: 0 1px 0 var(--line); }
.tcard-h { background: var(--panel); border-bottom: 2px solid var(--ink); }
.tcard-name { font-weight: 700; }
.tcard.is-out { border-color: var(--ink); border-width: 1.5px; }
.tcard.is-out .tcard-h { background: var(--ink); color: var(--panel); }
.tcard.is-out .tcard-count { color: var(--panel); opacity: .75; }
.tcard th { background: var(--panel-2); color: var(--ink-2); border-bottom: 1px solid var(--line); }
.tcard tr.is-cur, .tcard tr.is-src { outline-color: var(--ink); }
.tcard tr.is-cur td:first-child { box-shadow: inset 5px 0 0 var(--mark); }
@keyframes cur-in { from { background: var(--mark); } }

/* ERD ink */
.erd-rect { stroke: var(--ink-3); }
.erd-box.is-active .erd-rect { stroke: var(--ink); fill: var(--accent-soft); stroke-width: 2.2; }
.chen-ent.is-active .chen-box { stroke: var(--ink); }
.legend { color: var(--ink-3); }

/* example browser */
.exb { border-radius: 8px; border: 1px solid var(--ink); }
.exb-head { border-bottom: 0; }
.exb-item.is-last { border-color: var(--ink); background: var(--panel-2); }
.ex-btn .n { background: var(--ink); color: var(--panel); }

.foot { border-top: 1px solid var(--line); margin: 1rem 1.5rem 0; padding: 0.875rem 0 2rem; }

@media (max-width: 1280px) {
  .erd-pane { position: static; }
  .erd-scroll { max-height: 27.5rem; }
  .stage { max-height: none; }
}
@media (max-width: 900px) {
  /* phones and tablets: the explanation scrolls with the page; the controls ride along at the bottom, under the thumb */
  .deck { display: contents; }
  /* placed last in the column so `sticky; bottom: 0` keeps it on screen through the tables and the diagram */
  .pane-show > .split { order: 1; }
  .deck .timeline { order: 2; }
  .deck .narr { max-height: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0.75rem 0.875rem; }
  .deck .timeline { position: sticky; bottom: 0; z-index: 4; background: var(--panel); border: 1px solid var(--line); border-top: 2px solid var(--ink); border-radius: var(--r) var(--r) 0 0; padding: 0.5rem 0.625rem calc(0.5rem + env(safe-area-inset-bottom)); box-shadow: 0 -10px 18px -14px rgb(0 0 0 / 45%); }
  /* on a phone the tables come before the diagram */
  .split .stage-pane { order: -1; }
  .stage { padding: 0.5rem; }
  .foot { margin: 1rem; }
}
@media (max-width: 560px) {
  .narr h2 { font-size: 1rem; }
  .narr p { font-size: 0.875rem; }
  .chip { padding: 1.25rem 0.625rem 2px; font-size: 0.7188rem; }
}
@media (prefers-reduced-motion: reduce) {
  .chip::after { transition: none; }
}
.seg button { white-space: nowrap; }
.erd-pane > .pane-h { flex-wrap: wrap; row-gap: 0.5rem; }
/* keep the station line inside its row (it scrolls sideways itself) */
.tl-chips { flex-wrap: nowrap; }
.chips { flex: 1 1 auto; min-width: 0; }
.stmtnav { flex: none; }
/* one line per row: the "why" note scrolls with the table instead of making rows tall */
.tcard td.note { white-space: nowrap; max-width: none; }
@media (max-width: 560px) {
  .tl-row:first-child { display: grid; grid-template-columns: 2.5rem 2.5rem 2.5rem minmax(0, 1fr) auto; gap: 0.375rem; }
  .tl-row:first-child .seg { grid-column: 1 / -1; justify-self: start; }
  #scrub { min-width: 0; width: 100%; }
  .tl-chips { flex-wrap: wrap; }
  .deck .timeline { margin: 0 -1rem; border-left: 0; border-right: 0; border-radius: 0; }
}
.timeline { grid-template-columns: minmax(0, 1fr); }
.tl-row { min-width: 0; }

/* Steady deck: its height must not change from step to step, or the ERD and tables below jump while playing.
   The explanation gets a fixed box (it scrolls inside when a step says more) and the station row keeps its height before a run. */
.deck .narr { height: 9.25rem; max-height: none; overflow-y: auto; scrollbar-gutter: stable; }
.tl-chips { min-height: 2.75rem; }
@media (max-width: 900px) {
  .deck .narr { height: auto; min-height: 10.5rem; overflow: visible; }
}

/* ---- narration: lead sentence + "more"; glossary terms ---- */
.narr-toggle { border: 0; background: none; padding: 0 2px; font: inherit; font-size: .92em; font-weight: 600; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.narr-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
dfn.gl { font-style: normal; text-decoration: underline dotted; text-decoration-thickness: 1.5px; text-underline-offset: 3px; cursor: help; }
dfn.gl:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 2px; }
.gl-tip { position: fixed; z-index: 50; padding: 0.5rem 0.6875rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font-size: 0.8125rem; line-height: 1.45; box-shadow: 0 8px 24px rgb(0 0 0 / 18%); pointer-events: none; }

/* ---- reading companion ---- */
.pane-h .ex-btn + .ex-btn { margin-left: -0.25rem; }
.rd .rd-weeks button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }
/* 13 weeks: wrap onto a second line instead of running off the dialog */
.rd .rd-weeks { flex-wrap: wrap; max-width: 100%; }
.rd-body { padding: 0.25rem 1.125rem 1.125rem; }
.rd-intro { padding: 0.5rem 0 0.75rem; border-bottom: 1px solid var(--line); margin-bottom: 0.375rem; }
.rd-title { margin: 0; font-weight: 650; font-size: 1rem; }
.rd-chapters { margin: 2px 0 0.625rem; color: var(--ink-2); font-size: 0.875rem; }
.rd-progress { height: 0.375rem; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.rd-progress span { display: block; height: 100%; background: var(--mark, var(--accent)); border-radius: inherit; transition: width .3s; }
.rd-count { margin: 0.375rem 0 0; font-size: 0.75rem; color: var(--ink-3); }
.rd-list { list-style: none; margin: 0; padding: 0; }
.rd-ref { margin: 0.875rem 0 0.25rem; font-size: 0.75rem; font-weight: 600; letter-spacing: .04em; color: var(--ink-3); text-transform: uppercase; }
.rd-item { display: grid; grid-template-columns: 2rem minmax(0, 1fr) auto; align-items: center; gap: 0.375rem 0.625rem; padding: 0.5rem 0.375rem; border-radius: 8px; }
.rd-item:hover { background: var(--panel-2); }
.rd-check { display: grid; place-items: center; width: 2rem; height: 2rem; cursor: pointer; }
.rd-check input { width: 1.125rem; height: 1.125rem; accent-color: var(--ink); cursor: pointer; }
.rd-text { display: grid; gap: 1px; min-width: 0; }
.rd-text b { font-weight: 600; }
.rd-text span { color: var(--ink-2); font-size: 0.875rem; }
.rd-item.is-done .rd-text b { text-decoration: line-through; text-decoration-color: var(--ink-3); color: var(--ink-2); }
.rd-run { white-space: nowrap; min-height: 2rem; }
/* Optional character reference: standard codes, independently laid out. */
.pane-sql > .pane-h { flex-wrap: wrap; gap: 0.5rem; }
.char-ref { width: min(60rem, calc(100vw - 2rem)); }
.char-options { display: flex; flex-wrap: wrap; gap: 0.5rem 1.125rem; width: 100%; }
.char-options label { display: inline-flex; align-items: center; gap: 0.4375rem; min-height: 2rem; font-size: 0.875rem; cursor: pointer; }
.char-options input { width: 1.125rem; height: 1.125rem; accent-color: var(--ink); }
.char-count { font-size: 0.75rem; color: var(--ink-2); }
.char-note { margin: 0; padding: 0.625rem 1.25rem; font-size: 0.8125rem; line-height: 1.5; color: var(--ink-2); }
.char-sources { border-top: 1px solid var(--line); }
.char-sources a { color: var(--accent); }
.char-body { min-height: 6.25rem; }
.char-body h3 { margin: 0.5rem 0.25rem; font-size: 0.875rem; }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.75rem, 1fr)); list-style: none; padding: 0; margin: 0 0 1.125rem; gap: 0.375rem; }
.char-grid li { min-width: 0; padding: 0.625rem 0.5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); }
.char-glyph { display: block; min-height: 2.375rem; font-size: 1.5rem; line-height: 1.5; overflow-wrap: anywhere; }
.char-grid-rx { grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); }
.char-grid-rx li { display: grid; gap: 0.25rem; align-content: start; }
.char-glyph-rx { font-family: var(--mono); font-variation-settings: "MONO" 1; font-size: 1.25rem; color: var(--accent); white-space: pre; }
.char-meaning { font-size: 0.8125rem; color: var(--ink-2); line-height: 1.4; }
.char-example { font: 0.75rem var(--mono); font-variation-settings: "MONO" 1; color: var(--ink-3); overflow-wrap: anywhere; }
.char-glyph-thai { font-family: "Thonburi", "Leelawadee UI", "Noto Sans Thai", sans-serif; }
.char-codes { display: grid; font: 0.75rem/1.5 var(--mono); }
.char-name { display: block; margin-top: 0.1875rem; font-size: 0.625rem; color: var(--ink-2); overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .char-ref { width: 100vw; }
  .char-note { padding: 0.5rem 0.75rem; font-size: 0.75rem; }
  .char-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rd-item { grid-template-columns: 2rem minmax(0, 1fr); }
  .rd-run { grid-column: 2; justify-self: start; }
  .pane-h { flex-wrap: wrap; }
}

/* UI size control in the top bar */
.uisize { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.uisize button { border: 0; background: none; color: var(--ink-2); cursor: pointer; min-width: 2.25rem; min-height: 2.375rem; padding: 0 0.5rem; font-weight: 600; }
.uisize button:hover:not(:disabled) { color: var(--ink); }
.uisize button:disabled { opacity: .35; cursor: default; }
.uisize .uisize-val { min-width: 3.5rem; font: 600 0.75rem var(--mono); font-variation-settings: "MONO" 1; border-inline: 1px solid var(--line-2); }
@media (max-width: 560px) { .uisize { display: none; } }
.pane-sql > .pane-h h2 { white-space: nowrap; flex: 0 0 auto; margin-right: auto; }

/* ---- REGEXP: which part of the pattern matched which characters ---- */
:root { --rx-s: 90%; --rx-l: 82%; }
:root[data-theme="dark"] { --rx-s: 55%; --rx-l: 32%; }
.trace li:has(.rx) { list-style-position: outside; }
.rx { margin: 0.375rem 0 0.25rem; display: grid; gap: 0.25rem; font-family: var(--sans); }
.rx-row { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; min-width: 0; }
.rx-k { font: 600 0.6875rem var(--sans); color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; min-width: 4.25rem; }
.rx-line { font: 0.875rem/1.9 var(--mono); font-variation-settings: "MONO" 1; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.rx-p { border-radius: 3px; padding: 0.0625rem 0; color: var(--ink); }
.rx-c0 { background: hsl(45 var(--rx-s) var(--rx-l)); }
.rx-c1 { background: hsl(170 var(--rx-s) var(--rx-l)); }
.rx-c2 { background: hsl(275 var(--rx-s) var(--rx-l)); }
.rx-c3 { background: hsl(350 var(--rx-s) var(--rx-l)); }
.rx-c4 { background: hsl(210 var(--rx-s) var(--rx-l)); }
.rx-c5 { background: hsl(100 var(--rx-s) var(--rx-l)); }
.rx-line .rx-p + .rx-p { margin-left: 1px; }
.rx-op { color: var(--accent); font-weight: 700; padding: 0 1px; }
.rx-sp { opacity: .45; }
.rx-skip { color: var(--ink-3); opacity: .6; }
/* the match the function uses is boxed; other matches are paler */
.rx-line .rx-first { border-top-left-radius: 4px; border-bottom-left-radius: 4px; box-shadow: -2px 0 0 var(--ink); }
.rx-line .rx-last { border-top-right-radius: 4px; border-bottom-right-radius: 4px; box-shadow: 2px 0 0 var(--ink); }
.rx-line .rx-first.rx-last { box-shadow: -2px 0 0 var(--ink), 2px 0 0 var(--ink); }
.rx-line .rx-other { opacity: .5; box-shadow: none; }
.rx-sum { font-size: 0.75rem; color: var(--ink-3); }
.rx-legend { list-style: none; margin: 0.125rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem 0.875rem; font-size: 0.75rem; color: var(--ink-2); }
.rx-legend li { animation: none; }
.rx-legend .rx-p, .rx-legend .rx-op { font: 0.75rem var(--mono); font-variation-settings: "MONO" 1; padding: 0.0625rem 0.25rem; }
.rx-more { border-top: 1px dashed var(--line); padding-top: 0.25rem; }
.rx-pin { font-weight: 700; padding: 0.0625rem 0.125rem; margin-right: 0.4375rem; border-radius: 3px; color: var(--ink); outline: 1px dashed var(--ink-3); outline-offset: -1px; }
.rx-p.rx-anc { font-weight: 700; }
.rx-flag { font: 0.75rem var(--mono); font-variation-settings: "MONO" 1; color: var(--ink-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 0.5rem; }
.rx-try { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.1875rem; font-size: 0.8125rem; color: var(--ink-2); }
.rx-try li { animation: none; display: flex; align-items: baseline; gap: 0.375rem; flex-wrap: wrap; }
.rx-try code { font: 0.8125rem var(--mono); font-variation-settings: "MONO" 1; padding: 0.0625rem 0.25rem; }
.rx-try .rx-mark { width: 0.875rem; text-align: center; font-weight: 700; }
.rx-try .is-ok .rx-mark { color: var(--ok, #2f8a4e); }
.rx-try .is-no .rx-mark { color: var(--bad, #c0392b); }
.rx-try .is-no code, .rx-try .is-skip { opacity: .7; }
.rx-case { flex-basis: 100%; padding-left: 1.25rem; font-size: 0.75rem; color: var(--ink-3); }
.rx-more .rx-line { line-height: 1.6; }

/* ---- One window (desktop): the page is exactly the window's height; each panel scrolls inside itself.
   The ERD is scaled to fit its box (erd/render.js fit), "As in class" stacks the diagram over the tables. ---- */
@media (min-width: 901px) {
  body { overflow: hidden; }
  .layout { height: calc(100vh - var(--top-h)); align-items: stretch; padding-top: 0.75rem; padding-bottom: 0.75rem; }
  .pane-sql { position: static; height: 100%; max-height: none; min-height: 0; overflow: auto; }
  .editor-wrap { height: clamp(7.5rem, 30vh, 22.5rem); flex: none; }
  .console { min-height: 6rem; }
  .pane-show { height: 100%; min-height: 0; display: flex; flex-direction: column; gap: 0.625rem; }
  .deck { position: static; flex: none; }
  .split { flex: 1 1 0; min-height: 0; align-items: stretch; grid-template-rows: minmax(0, 1fr); }
  .erd-pane, .stage-pane { position: static; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  .erd-pane > * { flex: none; }
  .erd-scroll { flex: 1 1 0; min-height: 0; max-height: none; display: flex; }
  .erd-scroll > .erd { margin: auto; flex: none; }
  .erd-pane > .erd-only:has(#erdSchema) { max-height: 3.4rem; overflow: auto; scrollbar-width: thin; }
  .erd-pane > .erd-only:has(#erdSchema) .erd-schema { margin-top: 0.375rem; }
  #algPane:not([hidden]) { flex: 1 1 0; min-height: 0; overflow: auto; }
  /* the figure fits the box like the ERD: whole drawing visible, scaled to the smaller of width and height */
  #flowPane:not([hidden]) { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  #flowPane > * { flex: none; }
  #flowPane > .legend { display: none; } /* in the caption's tooltip: the figure needs the height */
  #flowPane > .flow-scroll { flex: 1 1 0; min-height: 0; display: flex; }
  #flowPane .flow-svg { flex: 1 1 0; width: 100%; height: 100%; min-width: 0; min-height: 0; }
  .stage-pane > * { flex: none; }
  .stage-pane > .stage { flex: 1 1 0; min-height: 0; max-height: none; }
  .split.is-chen, .split:not(.is-erd-only) { grid-template-rows: minmax(0, 1fr); }
  .split.is-chen:not(.is-erd-only) { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, var(--erd-a, 62fr)) 0.625rem minmax(0, var(--erd-b, 38fr)); row-gap: 0; }
  .split.is-chen:not(.is-erd-only) .split-handle { display: block; }
  .split.is-chen .erd-pane { padding-bottom: 0.375rem; }
  .split.is-chen .stage-pane { display: flex; }
  .foot { display: none; }
  /* a REGEXP picture needs more room than the usual one-line explanation */
  .deck .narr:has(.rx) { height: auto; max-height: min(18rem, 32vh); }
  .deck .narr .trace:has(.rx) { max-height: none; }
}
@media (min-width: 901px) and (max-width: 1280px) {
  .split:not(.is-erd-only) { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, var(--erd-a, 55fr)) 0.625rem minmax(0, var(--erd-b, 45fr)); row-gap: 0; }
  .split:not(.is-erd-only) .split-handle { display: block; }
}

.split-handle { display: none; cursor: row-resize; position: relative; touch-action: none; }
.split-handle::after { content: ""; position: absolute; left: 50%; top: 50%; width: 3rem; height: 4px; margin: -2px 0 0 -1.5rem; border-radius: 99px; background: var(--line); }
.split-handle:hover::after, .split-handle:focus-visible::after, .split-handle.is-drag::after { background: var(--ink-3); }
.split-handle:focus-visible { outline: none; }

/* ---- "As in class" on desktop: the schema list moves beside the figure, so the figure gets the full height ---- */
@media (min-width: 901px) {
  .erd-pane.is-chen { display: grid; grid-template-columns: minmax(0, 1fr) minmax(13rem, 24%); grid-template-rows: auto minmax(0, 1fr) auto; column-gap: 0.75rem; }
  .erd-pane.is-chen > .pane-h { grid-column: 1 / -1; }
  .erd-pane.is-chen > .erd-scroll { grid-column: 1; grid-row: 2; margin-top: 0.5rem; }
  .erd-pane.is-chen > .erd-only:has(#erdSchema) { grid-column: 2; grid-row: 2 / 4; max-height: none; min-height: 0; overflow: auto; margin-top: 0.5rem; }
  .erd-pane.is-chen > .erd-only:has(#erdSchema) .erd-schema { grid-template-columns: minmax(0, 1fr); margin-top: 0; font-size: 0.75rem; line-height: 1.4; }
  .erd-pane.is-chen > .legend { grid-column: 1; grid-row: 3; }
  .erd-pane.is-chen > #algPane { grid-column: 1 / -1; grid-row: 2 / -1; }
  .erd-pane.is-chen > #flowPane { grid-column: 1 / -1; grid-row: 2 / -1; }
}

/* ---- full screen: the whole page (top-bar button) ---- */
.fs-btn svg { width: 1.125rem; height: 1.125rem; }
.fs-btn .i-exit, :root:fullscreen #pageFull .i-enter { display: none; }
:root:fullscreen #pageFull .i-exit { display: inline; }
@media (max-width: 560px) { #pageFull { display: none; } }

/* diagram size control */
.zoom { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.zoom button { border: 0; background: none; color: var(--ink-2); cursor: pointer; min-width: 2rem; min-height: 2rem; padding: 0 0.5rem; font: 600 0.8125rem var(--sans); }
.zoom button:hover:not(:disabled) { color: var(--ink); }
.zoom button:disabled { opacity: .35; cursor: default; }
#erdZoomFit { min-width: 3.25rem; border-inline: 1px solid var(--line-2); font-family: var(--mono); font-variation-settings: "MONO" 1; font-size: 0.75rem; }

/* Diagram zoomed below Fit: its box hugs the drawing and the tables take the freed space (render.js fit) */
@media (min-width: 901px) {
  .split.is-erd-shrunk:not(.is-other-view) .erd-scroll { flex: none; height: calc(var(--erd-fit-h) + 0.5rem); }
  .split.is-erd-shrunk:not(.is-other-view).is-chen:not(.is-erd-only) { grid-template-rows: auto 0.625rem minmax(0, 1fr); }
  .split.is-erd-shrunk:not(.is-other-view).is-chen .erd-pane { grid-template-rows: auto auto auto; grid-template-columns: auto minmax(13rem, 1fr); }
  .split.is-erd-shrunk:not(.is-other-view).is-chen .erd-scroll { width: calc(var(--erd-fit-w) + 0.5rem); }
  /* the schema column scrolls inside the drawing's height instead of setting it */
  .split.is-erd-shrunk:not(.is-other-view).is-chen .erd-pane > .erd-only:has(#erdSchema) { contain: size; }
}
@media (min-width: 901px) and (max-width: 1280px) {
  .split.is-erd-shrunk:not(.is-other-view):not(.is-erd-only) { grid-template-rows: auto 0.625rem minmax(0, 1fr); }
}
@media (min-width: 1281px) {
  .split.is-erd-shrunk:not(.is-other-view):not(.is-chen):not(.is-erd-only) { grid-template-columns: fit-content(calc(var(--erd-fit-w) + 3rem)) minmax(0, 1fr); }
  .split.is-erd-shrunk:not(.is-other-view):not(.is-chen) .erd-pane .pane-h { flex-wrap: wrap; }
  .split.is-erd-shrunk:not(.is-other-view):not(.is-chen) .erd-pane { min-width: 0; }
  .split.is-erd-shrunk:not(.is-other-view):not(.is-chen) .erd-scroll { width: calc(var(--erd-fit-w) + 0.5rem); height: auto; flex: 1 1 0; }
}

/* output width toggle beside the console heading */
.console-h .out-mode { margin-left: auto; margin-right: 0.5rem; }
.console-h .out-mode button { min-height: 1.75rem; }

/* drag bar between the SQL / output side and the diagram side (one-window layout) */
.side-handle { display: none; }
@media (min-width: 901px) {
  .layout { grid-template-columns: minmax(18rem, var(--sql-w, 30%)) 1rem minmax(24rem, 1fr); column-gap: 0; }
  .side-handle { display: block; cursor: col-resize; position: relative; touch-action: none; align-self: stretch; }
  .side-handle::after { content: ""; position: absolute; top: 50%; left: 50%; width: 4px; height: 3rem; margin: -1.5rem 0 0 -2px; border-radius: 99px; background: var(--line); }
  .side-handle:hover::after, .side-handle:focus-visible::after, .side-handle.is-drag::after { background: var(--ink-3); }
  .side-handle:focus-visible { outline: none; }
}

/* "why" column: each condition marked TRUE / FALSE / NULL; patterns and matched characters coloured by part */
td.note .why-leaf { border-radius: 4px; padding: 0.0625rem 0.25rem; }
td.note .why-leaf.is-true { background: color-mix(in srgb, var(--ok, #2f8a4e) 16%, transparent); color: var(--ink); box-shadow: inset 0 -2px 0 var(--ok, #2f8a4e); }
td.note .why-leaf.is-false { opacity: .6; }
td.note .why-leaf.is-null { opacity: .75; font-style: italic; }
td.note .why-v { font-size: 0.6875rem; font-weight: 700; margin-left: 0.375rem; letter-spacing: .03em; }
td.note .why-leaf.is-true .why-v { color: var(--ok, #2f8a4e); }
td.note .why-op { font-weight: 700; color: var(--ink-2); }
td.note .rx-p, td.has-marks .rx-p { padding: 0.0625rem 0; border-radius: 2px; }
tr.st-drop td.has-marks .rx-p { text-decoration: line-through; }
td.note .why-dim { opacity: .4; }
.why-cut { opacity: .55; }
td.has-marks { white-space: nowrap; }

/* resizable table columns: drag a header's right edge (stage/tables.js) */
.tcard th { position: sticky; }
.tcard th .col-grip { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 2; touch-action: none; }
.tcard th .col-grip::after { content: ""; position: absolute; top: 25%; bottom: 25%; left: 3px; width: 1px; background: var(--line); }
.tcard th:hover .col-grip::after, .tcard th .col-grip:hover::after { background: var(--ink-3); width: 2px; }
.tcard td[style*="max-width"] { overflow: hidden; text-overflow: ellipsis; }
.tcard td.note[style*="max-width"] { white-space: nowrap; }
body.is-col-drag, body.is-col-drag * { cursor: col-resize !important; user-select: none; }

/* "In words": a plain-English reading of the statement being played (engine/plain.js) */
.in-words { margin: 0 0 0.5rem; padding: 0.375rem 0.625rem; border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 0 6px 6px 0; font-size: 0.875rem; line-height: 1.45; color: var(--ink); }
.in-words-k { font: 600 0.6875rem var(--sans); text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin-right: 0.25rem; }

/* data files for external tables */
.data-files { margin: 0.25rem 0 0; font-size: 0.8125rem; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; align-items: center; }
.data-file { display: inline-flex; align-items: center; gap: 0.125rem; border: 1px solid var(--line); border-radius: 6px; padding: 0 0 0 0.375rem; background: var(--panel-2); }
.data-file button { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; min-width: 1.5rem; min-height: 1.5rem; font-size: 0.875rem; }
.data-file button:hover { color: var(--ink); }
.tcard tr.st-aside td { color: var(--ink-3); font-style: italic; }

.sign-in { font-size: 0.8125rem; color: var(--muted, inherit); text-decoration: none; padding: 0.25rem 0.5rem; border-radius: 6px; white-space: nowrap; }
.sign-in:hover { text-decoration: underline; }

/* ---- Fold and move the page's parts (his call, 2026-11-18): classes on .layout, set from the Layout menu and the
   chevrons (app.js "panels"). f-* folds a part to its header; l-* moves parts (wide screens only). ---- */
.fold { display: inline-grid; place-items: center; width: 1.625rem; height: 1.625rem; flex: none; padding: 0; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--ink-2); cursor: pointer; }
.fold svg { width: 0.875rem; height: 0.875rem; transition: transform .15s; }
.fold:hover { border-color: var(--line); color: var(--ink); background: var(--panel-2); }
.fold[aria-expanded="false"] svg { transform: rotate(-90deg); }
.pane-h .fold-side { margin-left: -0.25rem; }
.narr-top .fold { align-self: center; margin-right: -0.375rem; }
.console-h .fold { margin-right: 0.375rem; }
.stage-h { gap: 0.375rem; margin-bottom: 0.25rem; }
.stage-h h2 { flex: 1; }
.layout-menu { position: relative; }
.layout-menu > summary { list-style: none; cursor: pointer; }
.layout-menu > summary::-webkit-details-marker { display: none; }
.layout-pop { position: absolute; right: 0; top: calc(100% + 0.375rem); z-index: 20; display: grid; gap: 0.25rem; min-width: 15rem; padding: 0.625rem 0.75rem 0.75rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 28px -12px rgb(19 33 58 / 45%); }
.layout-pop label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8125rem; min-height: 1.75rem; cursor: pointer; }
.layout-pop .lp-h { margin: 0.25rem 0 0; font-size: 0.6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.layout-pop .lp-h small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.layout-pop #layoutReset { justify-self: start; margin-top: 0.375rem; }
.sql-tab { display: none; }

/* folds (every width) */
.layout.f-editor .pane-sql > :is(.editor-wrap, .vars, .actions, .dbnote, .data-files) { display: none !important; }
.layout.f-output .pane-sql > .console { display: none; }
.layout.f-narr #inWords, .layout.f-narr .deck .narr > :not(.narr-top) { display: none !important; }
.layout.f-narr .deck .narr { height: auto !important; padding-bottom: 0.5rem; }
.layout.f-diagram .erd-pane > :not(.pane-h) { display: none !important; }
.layout.f-diagram .erd-pane > .pane-h > :not(.fold, .seg-view) { display: none !important; }
.layout.f-tables .stage-pane > :not(.stage-h) { display: none !important; }
.layout.f-tables .stage-h { margin-bottom: 0; }
.layout.f-sql > .pane-sql { display: none; }
.layout.f-sql > .sql-tab { display: flex; align-items: center; justify-content: center; gap: 0.375rem; font: 600 0.8125rem var(--sans); color: var(--ink-2); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; padding: 0.5rem; }
.layout.f-sql > .sql-tab:hover { color: var(--accent); border-color: var(--accent); }

@media (min-width: 901px) {
  /* an unfolded editor takes the room a folded output leaves */
  .layout.f-output .editor-wrap { flex: 1 1 auto; height: auto; min-height: 7.5rem; }
  /* SQL side folded: a narrow tab at its edge */
  .layout.f-sql { grid-template-columns: max(28px, 2.25rem) 0.75rem minmax(24rem, 1fr); }
  .layout.f-sql > .sql-tab { writing-mode: vertical-rl; align-self: stretch; }
  .layout.f-sql > .side-handle { visibility: hidden; pointer-events: none; }
  /* SQL side on the right */
  .layout.l-right { grid-template-columns: minmax(24rem, 1fr) 1rem minmax(18rem, var(--sql-w, 30%)); }
  .layout.l-right.f-sql { grid-template-columns: minmax(24rem, 1fr) 0.75rem max(28px, 2.25rem); }
  .layout.l-right > .pane-show { order: -1; }
  .layout.l-right > :is(.pane-sql, .sql-tab) { order: 1; }
  /* the step deck under the diagram and tables */
  .layout.l-deck-bottom .pane-show > .deck { order: 2; }
  /* tables above the diagram: placed first, and every stacked row list reversed */
  .layout.l-tf .split > .stage-pane { order: -1; }
  .layout.l-tf .split > .split-handle { order: 0; }
  .layout.l-tf .split > .erd-pane { order: 1; }
  .layout.l-tf .split.is-chen:not(.is-erd-only) { grid-template-rows: minmax(0, var(--erd-b, 38fr)) 0.625rem minmax(0, var(--erd-a, 62fr)); }
  .layout.l-tf .split.is-erd-shrunk:not(.is-other-view):not(.is-erd-only) { grid-template-rows: minmax(0, 1fr) 0.625rem auto; }
  .layout.l-tf .split.is-erd-shrunk:not(.is-other-view):not(.is-chen):not(.is-erd-only) { grid-template-columns: minmax(0, 1fr) fit-content(calc(var(--erd-fit-w) + 3rem)); }
  /* diagram or tables folded: stacked, the folded one only as tall as its header */
  .layout:is(.f-diagram, .f-tables) .split { grid-template-columns: minmax(0, 1fr) !important; row-gap: 0 !important; }
  .layout:is(.f-diagram, .f-tables) .split > .split-handle { display: block !important; visibility: hidden; pointer-events: none; }
  .layout:is(.f-diagram, .f-tables) .split > .stage-pane { display: flex !important; }
  .layout.f-diagram .split { grid-template-rows: auto 0.625rem minmax(0, 1fr) !important; }
  .layout.f-tables .split { grid-template-rows: minmax(0, 1fr) 0.625rem auto !important; }
  .layout.f-diagram.f-tables .split { grid-template-rows: auto 0.625rem auto !important; align-content: start; }
  .layout.l-tf.f-diagram .split { grid-template-rows: minmax(0, 1fr) 0.625rem auto !important; }
  .layout.l-tf.f-tables .split { grid-template-rows: auto 0.625rem minmax(0, 1fr) !important; }
  .layout.f-diagram.f-tables .split { grid-template-rows: auto 0.625rem auto !important; }
}
@media (min-width: 901px) and (max-width: 1280px) {
  .layout.l-tf .split:not(.is-erd-only) { grid-template-rows: minmax(0, var(--erd-b, 45fr)) 0.625rem minmax(0, var(--erd-a, 55fr)); }
}
@media (max-width: 900px) {
  .layout.f-sql > .sql-tab { min-height: 2.75rem; }
}
.layout.l-right .fold-side svg { transform: scaleX(-1); } /* the arrow points to the edge the side folds into */
