/* EconGraph Lab: warm paper and ink by default, a warm chalkboard in dark mode. One screen (no page scroll)
 * on desktop and tablet. Editorial type: Source Serif 4 for headlines, Inter for the interface, JetBrains Mono
 * for numbers. Graph colours come from paint() in app.js (PAPER palette). */
:root {
  --bg: #f6f4ee;
  --panel: #fcfbf7;
  /* text is pure black in the light theme (headings, body, secondary and small print alike) */
  --ink: #000000;
  --ink-2: #000000;
  --muted: #000000;
  --stroke-muted: #807b71; /* grey for thin graph guides and placeholders, not for text */
  --line: #e2ddd1;
  --line-strong: #cfc8b9;
  --hover: #efebe2;
  --accent: #1e3a5f;
  --accent-soft: #e6ecf3;
  --accent-ink: #1e3a5f;
  --danger: #a63a24;
  --danger-soft: #f6e7e1;
  --up: #2d6a4f;
  --down: #a63a24;
  --shadow: 0 10px 30px rgba(45, 35, 15, .13), 0 1px 3px rgba(45, 35, 15, .08);
  --radius: 6px;
  --rail-w: 60px;
  --side-w: 312px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-display: "Source Serif 4", "Source Serif Pro", "Iowan Old Style", Georgia, serif;
  --rule: #c83e2b;
  --ink-strong: #000000;
  --card-bg: var(--panel);
  --card-line: var(--line);
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px color-mix(in srgb, var(--accent) 45%, transparent);
  --curve-d: #1e4a7a;
  --curve-s: #c84b31;
  --dot: rgba(28, 27, 25, .11);
  --view-ms: .42s;
  --font-math: "STIX Two Text", "Iowan Old Style", Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  color-scheme: light;
  font-family: var(--font);
  color: var(--ink);
}
:root[data-theme="dark"] {
  --bg: #181816;
  --panel: #1f1e1b;
  --ink: #ece8df;
  --ink-2: #c9c4b8;
  --muted: #8f8a7f;
  --stroke-muted: #8f8a7f;
  --line: #2e2c28;
  --line-strong: #3d3a35;
  --hover: #272622;
  --accent: #9db8db;
  --accent-soft: #1f2a37;
  --accent-ink: #b9cde6;
  --danger: #e08a74;
  --danger-soft: #33221d;
  --up: #7fbf9f;
  --down: #e08a74;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  --ink-strong: #faf7f0;
  --card-bg: rgba(255, 250, 240, .03);
  --card-line: rgba(255, 250, 240, .08);
  --curve-d: #8fb3d9;
  --curve-s: #e48b72;
  --dot: rgba(236, 232, 223, .075);
  --rule: #e0563f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; width: 100%; overflow-x: hidden; }
body {
  background: var(--bg); color: var(--ink); font-size: 14px;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
  display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden;
  background-image: radial-gradient(var(--dot) 1px, transparent 1.3px); background-size: 22px 22px;
}
body > * { min-width: 0; }
input, select, button, textarea { box-sizing: border-box; max-width: 100%; }
button, select, input { font: inherit; color: inherit; }
svg { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
code, kbd { font-family: var(--font-mono); font-size: .9em; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
/* focus: a soft ring instead of the browser's bright outline */
button:focus, select:focus, input:focus, textarea:focus, [tabindex]:focus { outline: none; }
button:focus-visible, select:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: none; box-shadow: var(--ring); }
#graph, #graphB { font-variant-numeric: tabular-nums; }

/* ---------- Top bar ---------- */
.topbar {
  flex: none; display: flex; align-items: center; gap: 8px; height: 50px; width: 100%; min-width: 0;
  padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; white-space: nowrap; margin-right: 6px; flex: none; color: var(--ink); }
button.brand { border: 0; background: transparent; padding: 5px 8px; margin-left: -8px; border-radius: 7px; cursor: pointer; }
button.brand:hover { background: var(--hover); }
#btnNotes { flex: none; }
.brand-mark { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
/* breadcrumb: Course › Lesson */
.crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; flex: 0 1 auto; overflow: hidden; }
.crumb-sep { color: var(--muted); margin: 0 4px 0 0; }
.crumb-chev { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; flex: none; }
.crumb {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent; border-radius: 6px;
  padding: 5px 8px; cursor: pointer; color: var(--ink-2); min-width: 0; max-width: 100%; text-overflow: ellipsis;
}
.crumb:hover, .crumb:focus-visible { background: var(--hover); outline: none; }
.crumb-lesson { color: var(--ink); font-weight: 500; flex: 0 1 auto; min-width: 60px; max-width: 420px; }
.crumb-course { flex: 0 1 auto; min-width: 48px; }
.top-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; flex: none; }
.icon-btn {
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; flex: none;
  border: 0; background: transparent; border-radius: var(--radius); cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: var(--hover); color: var(--ink); }
/* Link panels: a word next to the chain so it is not read as Share link; framed in the accent while linked */
#btnLink { width: auto; gap: 5px; padding: 0 9px 0 7px; border: 1px solid var(--line); margin: 0 3px; font-size: 12px; font-weight: 500; }
#btnLink[hidden] { display: none; }
#btnLink[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.icon-btn svg, .chip-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-btn .i-sun { display: none; }
:root[data-theme="dark"] .icon-btn .i-sun { display: block; }
:root[data-theme="dark"] .icon-btn .i-moon { display: none; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; white-space: nowrap;
  border: 1px solid transparent; background: transparent; border-radius: var(--radius); cursor: pointer; color: var(--ink-2); font-size: 13px;
}
.chip-btn svg { width: 16px; height: 16px; }
.chip-btn:hover, .chip-btn[aria-expanded="true"] { background: var(--hover); color: var(--ink); }
.chip-btn[aria-expanded="true"] { border-color: var(--line); }
.chip-btn:disabled { opacity: .4; cursor: default; background: transparent; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; flex: none; }

/* ---------- Workspace: rail | graph | panel ---------- */
.layout {
  flex: 1; min-height: 0; min-width: 0; width: 100%; position: relative;
  display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--side-w); gap: 10px; padding: 10px;
}

/* icon rail */
.rail {
  display: flex; flex-direction: column; gap: 4px; padding: 6px 4px; align-self: start;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.rail-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px 6px; width: 100%;
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--ink-2);
}
.rail-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn span { font-size: 10.5px; letter-spacing: .01em; }
.rail-btn:hover { background: var(--hover); color: var(--ink); }
.rail-btn.on { background: var(--accent-soft); color: var(--accent-ink); }
.rail-btn:disabled { opacity: .35; cursor: default; background: transparent; }

/* centre column: graph fills what is left, equation bar under it */
.center { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
/* one canvas, or two side by side (Split view) */
.stages { flex: 1; min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.stages.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.stage[hidden] { display: none; }
.canvas-tag { display: none; position: absolute; top: 8px; left: 10px; z-index: 2; font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; background: var(--panel); pointer-events: none; }
.stages.split .canvas-tag { display: block; }
.stages.split .stage.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.stages.split .stage.active .canvas-tag { color: var(--accent-ink); border-color: var(--accent); }

/* practice card: sits above the graph, never on top of it. Two rows: header, then question + actions. */
.practice-card {
  flex: none; position: relative; background: var(--card-bg); border: 1px solid var(--card-line);
  border-radius: 10px; padding: 6px 8px 10px 10px; font-size: 13px; color: var(--ink-2);
}
.practice-card[hidden] { display: none; }
.pc-head { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.pc-head .icon-btn { width: 26px; height: 26px; }
.pc-head .icon-btn svg { width: 15px; height: 15px; }
.pc-topic { position: relative; flex: none; }
.pc-topic-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 6px 0 8px;
  border: 1px solid var(--card-line); border-radius: 7px; background: transparent; cursor: pointer;
  font-size: 12.5px; font-weight: 500; color: var(--ink); white-space: nowrap; max-width: 260px;
}
.pc-topic-btn > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.pc-topic-btn:hover, .pc-topic-btn[aria-expanded="true"] { background: var(--hover); border-color: var(--line-strong); }
.pc-topic-btn svg { width: 14px; height: 14px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pc-topic-n { font-size: 11.5px; color: var(--muted); }
.pc-divider { width: 1px; height: 16px; background: var(--card-line); flex: none; }
.pc-tag { font-size: 11.5px; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pc-num { font-size: 11.5px; color: var(--muted); flex: none; }
.pc-num.solved::after { content: ' ✓'; color: var(--up); }
.pc-tag[hidden] { display: none; }
.pc-spacer { flex: 1; }
.pc-nav { display: flex; align-items: center; gap: 2px; flex: none; }
.pc-count { font-size: 12px; color: var(--ink-2); min-width: 54px; text-align: center; }
.pc-body { display: flex; align-items: flex-start; gap: 16px; padding: 2px 2px 0 0; }
.pc-main { flex: 1; min-width: 0; }
.pc-title { margin: 2px 0 2px; font-size: 14px; font-weight: 600; letter-spacing: -.01em; color: var(--ink-strong); }
.pc-text { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--ink); }
.pc-hint { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); background: var(--hover); border-radius: 7px; padding: 5px 9px; }
.pc-feedback { margin: 8px 0 0; padding: 6px 10px; border-radius: 8px; font-size: 13px; line-height: 1.45; border: 1px solid transparent; }
.pc-feedback.right { background: color-mix(in srgb, var(--up) 12%, transparent); border-color: color-mix(in srgb, var(--up) 40%, transparent); color: var(--ink); }
.pc-feedback.wrong { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--ink); }
.pc-feedback.warn { background: color-mix(in srgb, #d69e2e 12%, transparent); border-color: color-mix(in srgb, #d69e2e 45%, transparent); color: var(--ink); }
.pc-feedback b { font-weight: 600; }
.pc-change { margin-top: 4px; font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); }
.pc-actions { display: flex; align-items: center; gap: 6px; flex: none; padding-top: 2px; }
.pc-actions .btn { height: 30px; padding: 0 12px; font-size: 13px; border-radius: 7px; }
/* derivations card: same look as practice, plus step tabs (the derivation is picked in the course menu) */
.dv-steps { display: flex; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.dv-step { height: 26px; padding: 0 9px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-size: 12.5px; white-space: nowrap; cursor: pointer; }
.dv-step:hover { background: var(--hover); color: var(--ink); }
.dv-step[aria-selected="true"] { border-color: var(--card-line); background: var(--hover); color: var(--ink-strong); font-weight: 500; }
@media (max-width: 560px) {
  #derivationCard .pc-head { flex-wrap: wrap; }
  .dv-steps { order: 1; flex-basis: 100%; }
}
.btn.ghost { background: transparent; border-color: var(--card-line); color: var(--ink-2); }
.btn.ghost:hover { background: var(--hover); color: var(--ink); }
/* topic popover */
.pc-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; width: 280px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px;
}
.pc-pop[hidden] { display: none; }
.pc-pop input[type="search"] {
  width: 100%; height: 30px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg);
  padding: 0 9px; font-size: 13px; color: var(--ink);
}
.pc-pop input[type="search"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pc-pop-list { max-height: min(56vh, 420px); overflow-y: auto; margin-top: 6px; }
.pc-pop-group { font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 8px 8px 4px; }
.pc-opt {
  display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; cursor: pointer;
  text-align: left; padding: 6px 8px; border-radius: 6px; font-size: 13px; color: var(--ink);
}
.pc-opt:hover, .pc-opt.hl { background: var(--hover); }
.pc-opt[aria-selected="true"] { color: var(--accent-ink); font-weight: 500; }
.pc-opt span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-opt .mono { font-size: 11.5px; color: var(--muted); flex: none; }
.pc-opt .mono.done { color: var(--up); }
.pc-empty { padding: 10px 8px; font-size: 12.5px; color: var(--muted); }
@media (max-width: 760px) {
  .pc-body { flex-direction: column; gap: 8px; }
  .pc-num, .pc-divider { display: none; }
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--ink); border-color: var(--ink); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #10151c; }
.btn:disabled { opacity: .45; cursor: default; }
.stage {
  position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; overflow: hidden;
}
.stage.drop-ok { outline: 2px dashed var(--accent); outline-offset: -5px; }
#graph, #graphB { width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
#graph [data-id] { cursor: grab; }
#graph [data-part^="h"], #graph [data-part^="v"] { cursor: move; }
#graph.dragging, #graph.dragging * { cursor: grabbing !important; }
#graph [data-edit] { cursor: text; }
.inline-editor {
  position: absolute; z-index: 30; font-size: 14px; padding: 4px 8px; border: 1px solid var(--accent);
  border-radius: 6px; min-width: 120px; background: var(--panel); color: var(--ink);
  box-shadow: 0 0 0 3px var(--accent-soft); outline: none;
}

/* equation bar */
.eq-bar {
  flex: none; position: relative; display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px 5px 4px 12px;
}
.eq-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.eq-label { font-family: var(--font-math); font-style: italic; font-size: 16px; color: var(--muted); white-space: nowrap; user-select: none; }
.eq-label span { font-size: 13px; }
.eq-bar input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--ink); font-family: var(--font-mono); font-size: 13.5px; padding: 6px 2px; }
.eq-bar input::placeholder { color: var(--stroke-muted); opacity: .9; font-family: var(--font); font-size: 13.5px; }
.eq-msg {
  position: absolute; left: 10px; bottom: calc(100% + 6px); margin: 0; max-width: calc(100% - 20px); z-index: 25;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px;
  font-size: 12.5px; color: var(--ink-2); box-shadow: var(--shadow);
}
.eq-msg.err { color: var(--danger); border-color: var(--danger-soft); }

/* ---------- Right panel: tabs ---------- */
.sidebar {
  min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.tabs { flex: none; display: flex; gap: 2px; padding: 4px; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1 1 0; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 0; background: transparent; border-radius: 7px; padding: 7px 6px; cursor: pointer;
  color: var(--muted); font-size: 13px; font-weight: 500;
}
.tab:hover { color: var(--ink); background: var(--hover); }
.tab.on { color: var(--ink); background: var(--hover); box-shadow: inset 0 -2px 0 var(--accent); }
.tab-body { flex: 1; min-height: 0; min-width: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 12px 12px 12px 14px; scrollbar-width: thin; }
.pane { min-width: 0; }
.pane-h { font-size: 11.5px; color: var(--muted); margin: 14px 0 4px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.empty { color: var(--muted); font-size: 13px; margin: 0 0 8px; }

.field { display: grid; grid-template-columns: 82px minmax(0, 1fr); align-items: center; gap: 8px; margin: 7px 0; font-size: 13px; }
.field > * { min-width: 0; }
.field > span { color: var(--muted); }
.field input[type=text], .field input[type=number], .field select {
  width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input[type=color] { width: 40px; height: 26px; border: 1px solid var(--line); border-radius: 6px; padding: 1px; background: var(--panel); }
input[type=range], .layers input, .field input[type=checkbox] { accent-color: var(--accent); }
.field .range { display: flex; align-items: center; gap: 8px; }
.field .range input { flex: 1; min-width: 0; }
.field .range output { min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.btn {
  border: 1px solid var(--line); background: transparent; border-radius: 7px; padding: 4px 10px;
  cursor: pointer; font-size: 12.5px; color: var(--ink-2); white-space: nowrap;
}
.btn:hover { background: var(--hover); color: var(--ink); border-color: var(--line-strong); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.insp-title { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 6px; }
.insp-title small { font-weight: 400; color: var(--muted); }
.swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.eqn { font-family: var(--font-mono); font-size: 12.5px; background: var(--hover); border-radius: 6px; padding: 5px 9px; margin: 8px 0; overflow-wrap: anywhere; }
.eqn-or { font-style: normal; color: var(--muted); margin: 0 4px; }
.note { font-size: 12.5px; color: var(--muted); margin: 6px 0; }

/* compact shift / slope controls */
.ctl { display: grid; grid-template-columns: 82px minmax(0, 1fr); align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; }
.ctl > span { color: var(--muted); }
.ctl-row { display: flex; align-items: center; gap: 4px; min-width: 0; }
.ctl-row input[type=range] { flex: 1; min-width: 0; }
.sq {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; flex: none;
  border: 1px solid var(--line); background: transparent; border-radius: 7px; cursor: pointer; color: var(--ink-2);
}
.sq:hover { background: var(--hover); color: var(--ink); border-color: var(--line-strong); }
.sq svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* analysis */
.analysis { font-size: 13.5px; line-height: 1.5; color: var(--ink-2); }
.analysis .row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.analysis .row:first-child { padding-top: 0; }
.analysis .row:last-child { border-bottom: 0; padding-bottom: 0; }
.analysis .k { font-weight: 600; color: var(--ink); }
.analysis b { color: var(--ink); }
.analysis small { color: var(--muted); }
.analysis .up { color: var(--up); font-weight: 600; }
.analysis .down { color: var(--down); font-weight: 600; }
.analysis table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; margin-top: 4px; }
.analysis td { padding: 2px 0; }
.analysis td:last-child { text-align: right; color: var(--ink); }

/* layers & objects */
.layers label, .objects .obj { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 2px; color: var(--ink-2); }
.layers label { cursor: pointer; }
.layers .group { font-size: 11.5px; color: var(--muted); margin: 12px 0 2px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.layers .group:first-child { margin-top: 0; }
.objects .obj { border-radius: 6px; cursor: pointer; padding: 4px 6px; }
.objects .obj:hover { background: var(--hover); }
.objects .obj.sel { background: var(--accent-soft); }
.objects .obj .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.objects .obj .nm b { color: var(--ink); font-weight: 600; }
.objects .obj small { color: var(--muted); }
.objects .eye { border: 0; background: none; cursor: pointer; padding: 2px 4px; color: var(--muted); border-radius: 4px; }
.objects .eye:hover { color: var(--ink); }
.objects .eye svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ---------- Popovers (tools, export, help) ---------- */
.pop {
  position: fixed; z-index: 120; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 12px; box-shadow: var(--shadow);
}
.tool-pop { width: 248px; padding: 6px; max-height: 70vh; max-height: 70dvh; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.tool-pop.two { width: 470px; max-width: calc(100vw - 90px); }
.tool-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 6px; }
.tool-cols > div { min-width: 0; }
.tool-pop.two .block small { display: none; }  /* one line per tool; the description is in the tooltip */
.tool-pop h4 { margin: 4px 8px 4px; font-size: 11.5px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.block {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; background: transparent; border-radius: 8px; padding: 6px 8px; margin: 0;
  color: var(--ink-2); font-size: 13.5px; cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none;
}
.block small { display: block; font-size: 11.5px; color: var(--muted); }
.block:hover { background: var(--hover); color: var(--ink); }
.block:active { cursor: grabbing; }
.glyph { width: 20px; height: 16px; flex: none; overflow: visible; }
.block-ghost {
  position: fixed; pointer-events: none; z-index: 130; width: auto; opacity: .95;
  background: var(--panel); border: 1px solid var(--line-strong); box-shadow: var(--shadow);
}
.pop-foot { border-top: 1px solid var(--line); margin-top: 6px; padding: 8px 8px 4px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 30px; height: 18px; border-radius: 9px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .15s; flex: none; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(12px); }

.menu-pop { min-width: 220px; padding: 4px; }
/* export: format, size, background, grid */
.export-pop { width: 270px; padding: 8px; }
.exp-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 2px 4px 8px; font-size: 12.5px; color: var(--muted); }
.exp-row[hidden] { display: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 3px 12px; border-radius: 6px; cursor: pointer; font-size: 12.5px; color: var(--ink-2); }
.seg button.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.menu-pop .seg button { display: inline-block; width: auto; padding: 3px 9px; }
.exp-col { margin: 2px 4px 6px; font-size: 12.5px; color: var(--muted); }
.exp-col > span { display: block; margin-bottom: 4px; }
.radio { display: grid; grid-template-columns: 18px 1fr; column-gap: 6px; align-items: center; padding: 4px 4px; border-radius: 7px; cursor: pointer; color: var(--ink); font-size: 13px; }
.radio:hover { background: var(--hover); }
.radio input { margin: 0; accent-color: var(--accent); grid-row: span 2; }
.radio b { font-weight: 500; }
.radio small { grid-column: 2; color: var(--muted); font-size: 11.5px; }
.exp-switch { margin: 6px 4px 8px; }
.menu-pop .exp-go { display: block; width: 100%; text-align: center; padding: 7px 10px; font-size: 13px; }
.menu-pop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.menu-pop button small { display: block; color: var(--muted); font-size: 11.5px; }
.menu-pop button:hover { background: var(--hover); }

/* ---------- Dropdowns drawn by the page (js/dropdown.js) ---------- */
select.dd-native { position: absolute; width: 1px; height: 1px; min-width: 0; padding: 0; border: 0; margin: 0; opacity: 0; pointer-events: none; overflow: hidden; clip-path: inset(50%); }
.dd-btn { display: inline-flex; align-items: center; gap: 3px; text-align: left; white-space: nowrap; }
.dd-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dd-chev { width: 14px; height: 14px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; opacity: .55; transition: transform .15s ease, opacity .15s ease; }
.dd-btn:hover .dd-chev, .dd-btn[aria-expanded="true"] .dd-chev { opacity: 1; }
.dd-btn[aria-expanded="true"] .dd-chev { transform: rotate(180deg); }
.crumb.dd-btn[aria-expanded="true"] { background: var(--hover); }
.field .dd-btn {
  width: 100%; justify-content: space-between; padding: 5px 6px 5px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); cursor: pointer; font-size: 13px; color: var(--ink);
}
.field .dd-btn:hover { border-color: var(--line-strong); }
.field .dd-btn[aria-expanded="true"] { border-color: var(--line-strong); }
.dd-list {
  position: fixed; z-index: 200; box-sizing: border-box; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
  padding: 4px; background: var(--panel); border: 0; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13.5px; color: var(--ink); outline: none; animation: dd-in .12s ease-out;
}
@keyframes dd-in { from { opacity: 0; transform: translateY(-3px); } }
.dd-list:focus, .dd-list:focus-visible { outline: none; box-shadow: var(--shadow); } /* no focus ring: the highlighted row shows where the keys are */
.dd-grp + .dd-grp { border-top: 1px solid var(--line); margin-top: 4px; }
.dd-grp-title { padding: 8px 10px 3px; font-family: var(--font-display); font-style: italic; font-size: 13.5px; color: var(--muted); }
.dd-opt {
  position: relative; padding: 6px 30px 6px 10px; border-radius: 6px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; user-select: none; -webkit-user-select: none;
}
.dd-opt.active { background: var(--hover); }
.dd-opt[aria-selected="true"] { color: var(--accent-ink); font-weight: 500; }
.dd-opt[aria-selected="true"]::after {
  content: ''; position: absolute; right: 11px; top: 50%; width: 9px; height: 5px;
  border: solid currentColor; border-width: 0 0 1.75px 1.75px; transform: translateY(-70%) rotate(-45deg);
}
@media (pointer: coarse) { .dd-opt { padding-top: 11px; padding-bottom: 11px; font-size: 15px; } }
@media (prefers-reduced-motion: reduce) { .dd-list { animation: none; } .dd-chev { transition: none; } }
.menu-sep { height: 1px; background: var(--line); margin: 4px 2px; }

.help-pop { width: 360px; max-width: calc(100vw - 24px); padding: 6px 16px 12px; font-size: 13px; color: var(--ink-2); line-height: 1.5; max-height: calc(100dvh - 80px); overflow-y: auto; }
.help-pop h3 { font-size: 11.5px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; margin: 12px 0 4px; }
.help-pop ul { margin: 0; padding-left: 18px; }
.help-pop li { margin: 3px 0; }
.help-pop b { color: var(--ink); font-weight: 600; }
.help-pop kbd { border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--hover); }
.help-pop .keys { list-style: none; padding-left: 0; }

/* hover tooltip on shaded regions */
.region-tip {
  position: fixed; z-index: 140; pointer-events: none; max-width: 260px;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow);
  padding: 8px 11px; font-size: 12.5px; color: var(--ink-2); line-height: 1.45;
}
.region-tip .tip-h { display: flex; align-items: center; gap: 7px; font-weight: 600; color: var(--ink); font-size: 13px; }
.region-tip .tip-v { margin-top: 5px; font-variant-numeric: tabular-nums; color: var(--ink); }
.region-tip .tip-v b { font-weight: 600; }

/* ---------- Notes drawer ---------- */
.drawer {
  /* as tall as its text, never taller than the workspace; drag the header to move it sideways */
  position: absolute; z-index: 60; top: 10px; max-height: calc(100% - 20px);
  left: calc(var(--rail-w) + 20px); width: min(420px, calc(100% - var(--rail-w) - 40px));
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 12px; box-shadow: var(--shadow); overflow: visible; /* the resize handles reach past the border */
}
.drawer[hidden] { display: none; }
.drawer-head {
  flex: none; display: flex; gap: 6px; align-items: center; padding: 8px; border-bottom: 1px solid var(--line);
  cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none;
}
.drawer.dragging .drawer-head { cursor: grabbing; }
.drawer.dragging { box-shadow: 0 16px 40px rgba(0, 0, 0, .22); }
.drawer-grip { width: 16px; height: 16px; flex: none; margin-right: 6px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.drawer-head .icon-btn { cursor: pointer; width: 30px; height: 30px; }
/* resize handles on the left and right edges */
.drawer-edge { position: absolute; top: 10px; bottom: 10px; width: 14px; cursor: ew-resize; touch-action: none; z-index: 2; }
.drawer-edge.left { left: -7px; }
.drawer-edge.right { right: -7px; }
.drawer-edge::after { content: ""; position: absolute; top: 50%; width: 3px; height: 36px; margin-top: -18px; border-radius: 2px; background: var(--line-strong); opacity: 0; transition: opacity .15s; }
.drawer-edge.left::after { left: 5px; }
.drawer-edge.right::after { right: 5px; }
.drawer:hover .drawer-edge::after, .drawer.resizing .drawer-edge::after { opacity: 1; }
.drawer.resizing { user-select: none; -webkit-user-select: none; }
.drawer-title { flex: 1; padding-left: 2px; font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.lesson-card { flex: 0 1 auto; min-height: 0; overflow-y: auto; border-radius: 0 0 12px 12px; padding: 4px 16px 16px; line-height: 1.6; color: var(--ink-2); overscroll-behavior: contain; }
.lesson-card h2 { margin: 12px 0 4px; font-family: var(--font-display); font-size: 21px; line-height: 1.2; font-weight: 600; letter-spacing: -.015em; color: var(--ink-strong); }
.lesson-card .tag { font-size: 12px; color: var(--muted); }
.lesson-card p { margin: 6px 0; }
.lesson-card b { color: var(--ink); font-weight: 600; }
.lesson-card .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.lesson-card h4 { margin: 12px 0 4px; font-size: 13px; color: var(--ink); font-weight: 600; }
.lesson-card ul { margin: 4px 0; padding-left: 20px; }
.lesson-card li { margin: 3px 0; }
.lesson-card .key { border-left: 2px solid var(--accent); padding: 4px 12px; margin: 10px 0; color: var(--ink); }

/* ---------- Context menu, toast, footer ---------- */
.ctx-menu {
  position: fixed; z-index: 150; min-width: 170px; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 8px; box-shadow: var(--shadow); padding: 4px; font-size: 13.5px;
}
.ctx-menu .ctx-title { padding: 6px 10px 6px; font-weight: 600; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.ctx-menu .ctx-title small { font-weight: 400; color: var(--muted); }
.ctx-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.ctx-menu button:hover { background: var(--hover); }
.ctx-menu button.danger { color: var(--danger); }
.ctx-menu button.danger:hover { background: var(--danger-soft); }
.toast {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel);
  padding: 9px 16px; border-radius: 8px; font-size: 13.5px; z-index: 200; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* ---------- Help text: mouse vs. touch ---------- */
.hint-touch { display: none; }
@media (pointer: coarse) {
  .hint-mouse { display: none; }
  .hint-touch { display: inline; }
}

/* ---------- Narrower screens ---------- */
@media (max-width: 1440px) {
  .chip-btn span, .chip-btn .kbd-badge { display: none; }      /* baseline + notes become icon buttons (names in their tooltips) */
  .chip-btn { padding: 0 8px; }
}
@media (max-width: 1280px) {
  :root { --side-w: 290px; }
}
@media (max-width: 1024px) {
  :root { --side-w: 264px; --rail-w: 54px; }
  .topbar .brand span { display: none; }
  .crumb-lesson { max-width: 260px; }
  .layout { gap: 8px; padding: 8px; }
}
/* phones and portrait tablets: one column, the page scrolls */
@media (max-width: 900px) {
  body { height: auto; min-height: 100dvh; overflow: auto; }
  .topbar { position: sticky; top: 0; flex-wrap: wrap; height: auto; padding: 6px 10px; row-gap: 4px; }
  .crumbs { order: 3; flex: 1 1 100%; }
  .crumb-sep { display: none; }
  .crumb-lesson { flex: 1; max-width: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .rail { flex-direction: row; align-self: stretch; justify-content: space-around; }
  .rail-btn { width: auto; flex: 1; }
  .stage { flex: none; aspect-ratio: 760 / 560; }
  .sidebar { max-height: none; }
  .tab-body { overflow: visible; }
  .drawer { position: fixed; top: 60px; max-height: calc(100dvh - 70px); left: 10px !important; right: 10px; width: auto; }
  .drawer-head { cursor: default; }
  .drawer-grip, .drawer-edge { display: none; }
  .stages.split { grid-template-columns: minmax(0, 1fr); }
  .stages .stage { aspect-ratio: 760 / 560; }
  .drawer { width: auto !important; }
  .lesson-card .grid2 { grid-template-columns: 1fr; }
}

/* phones: three rows in the top bar (name + notes/practice, course › lesson, the tools spread across the width) */
@media (max-width: 560px) {
  .topbar { padding: 6px 8px; column-gap: 4px; }
  .topbar .brand span { display: inline; font-size: 17px; }
  #btnNotes { margin-left: auto; }
  .crumbs { margin-left: -4px; }
  .top-actions { order: 4; flex: 1 1 100%; margin-left: 0; gap: 0; justify-content: space-between; }
  .top-actions .sep { display: none; }
  .top-actions .icon-btn, .top-actions .chip-btn { flex: 1 1 0; min-width: 0; width: auto; height: 40px; padding: 0; justify-content: center; }
  /* no room for "Linked": the accent fill shows the state, the label stays in aria-label */
  #btnLink .link-badge { display: none; }
  /* A / B tags move to the top-right corner, clear of the y-axis numbers */
  .canvas-tag { left: auto; right: 8px; top: 6px; }
}

/* ---------- Touch screens: bigger targets, no iOS zoom on inputs ---------- */
@media (pointer: coarse) {
  input[type=text], input[type=number], select, .inline-editor { font-size: 16px; }
  .eq-bar input { font-size: 16px; }
  .icon-btn { width: 40px; height: 40px; }
  .block { padding: 10px 10px; }
  .btnrow .btn { padding: 8px 11px; font-size: 13.5px; }
  .sq { width: 40px; height: 38px; }
  .layers label, .objects .obj { padding: 7px 4px; }
  .layers input[type=checkbox], .field input[type=checkbox] { width: 20px; height: 20px; }
  input[type=range] { height: 28px; }
  .objects .eye { padding: 6px 8px; }
  .ctx-menu button, .menu-pop button { padding: 11px 12px; font-size: 15px; }
}

/* ---------- masthead and keyboard badges ---------- */
.topbar .brand span { font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: -.02em; }
.kbd-badge {
  font-family: var(--font-mono); font-size: 10.5px; line-height: 1; padding: 2px 5px 1px; margin-left: 2px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; color: var(--muted); background: var(--panel);
}
.chip-btn:disabled .kbd-badge { opacity: .7; }

/* ================================================================== */
/*  Welcome page: an editorial front page                               */
/* ================================================================== */
.welcome {
  position: fixed; inset: 0; z-index: 100; color: var(--ink);
  background-color: var(--bg); background-image: radial-gradient(var(--dot) 1px, transparent 1.3px); background-size: 22px 22px;
  display: flex; flex-direction: column; overflow-x: hidden; overflow-y: auto;
  transition: opacity var(--view-ms) ease, transform var(--view-ms) cubic-bezier(.2, .7, .2, 1), visibility 0s linear 0s;
}
:root[data-view="app"] .welcome {
  opacity: 0; transform: scale(1.012); visibility: hidden; pointer-events: none;
  transition: opacity var(--view-ms) ease, transform var(--view-ms) cubic-bezier(.2, .7, .2, 1), visibility 0s linear var(--view-ms);
}
.topbar, .layout { transition: opacity var(--view-ms) ease, transform calc(var(--view-ms) + .08s) cubic-bezier(.2, .7, .2, 1); }
:root[data-view="welcome"] .topbar, :root[data-view="welcome"] .layout { opacity: 0; transform: scale(.985); }

.wl-top, .wl-main, .wl-foot { width: 100%; max-width: 1200px; margin: 0 auto; padding-left: 40px; padding-right: 40px; }
.wl-top { flex: none; display: flex; align-items: center; height: 60px; }
.wl-brand { font-family: var(--font-display); font-size: 21px; font-weight: 600; color: var(--ink-strong); letter-spacing: -.02em; }
.wl-top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* buttons: ink on paper, navy on hover */
.wl-cta {
  display: inline-flex; align-items: center; justify-content: center; border-radius: 3px; cursor: pointer; white-space: nowrap;
  font: inherit; font-weight: 500; border: 1px solid var(--ink); background: transparent; color: var(--ink);
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.wl-cta.primary { background: var(--ink); color: var(--bg); }
.wl-cta.primary:hover { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.wl-cta:not(.primary):hover { background: var(--hover); }
.wl-cta { height: 46px; padding: 0 22px; font-size: 15px; }

.wl-main {
  flex: 1 0 auto; display: flex; flex-direction: column; justify-content: center;
  gap: clamp(24px, 4.5vh, 52px); padding-top: clamp(4px, 1.5vh, 16px); padding-bottom: 4px;
}
.wl-hero { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: clamp(36px, 5.5vw, 88px); align-items: center; }
.wl-copy h1 {
  margin: 0; max-width: 17ch; color: var(--ink-strong);
  font-family: var(--font-display); font-weight: 600; font-size: clamp(2rem, 3.2vw, 2.8rem); line-height: 1.15; letter-spacing: -.02em;
  text-wrap: balance;
}
/* the short red rule of an editorial masthead */
.wl-copy h1::before { content: ""; display: block; width: 36px; height: 3px; margin-bottom: 18px; background: var(--rule); }
.wl-lede { margin: 20px 0 0; max-width: 46ch; font-size: 16.5px; line-height: 1.6; color: var(--ink-2); text-wrap: pretty; }
.wl-ctas { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }

/* Figure 1: an open figure, ruled above, captioned below */
.wl-figure { margin: 0; border-top: 1px solid var(--ink); padding-top: 10px; }
.wl-fig-head { display: flex; align-items: center; gap: 12px; min-height: 24px; }
.wl-read { font-size: 13px; color: var(--muted); white-space: nowrap; display: flex; gap: 9px; align-items: baseline; }
.wl-read i { font-family: var(--font-math); font-size: 15px; color: var(--ink-2); }
.wl-read sup { font-size: 10px; line-height: 0; color: var(--ink-2); margin-left: 1px; }
.wl-read b { display: inline-block; font-weight: 500; color: var(--ink-strong); min-width: 3ch; }
.wl-read-sep { color: var(--muted); }
.wl-graph { width: 100%; height: auto; max-height: min(40vh, 380px); margin: 2px 0 4px; overflow: visible; user-select: none; -webkit-user-select: none; }
.wl-fx { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 9px; font-size: 13px; color: var(--ink); }
.wl-figure figcaption { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); font-size: 13.5px; line-height: 1.5; color: var(--ink-2); }
.wl-fig-n { font-weight: 600; color: var(--ink-strong); }

.wg-grid line { stroke: var(--line); stroke-width: 1; }
.wg-axis { fill: none; stroke: var(--ink); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.wg-math { font-family: var(--font-math); font-style: italic; font-size: 17px; fill: var(--ink-2); }
.wg-tick { font-size: 14px; fill: var(--muted); }
.wg-d, .wg-s { stroke-width: 2.4; stroke-linecap: round; pointer-events: none; }
.wg-d { stroke: var(--curve-d); }
.wg-s { stroke: var(--curve-s); }
.wg-dl { fill: var(--curve-d); }
.wg-sl { fill: var(--curve-s); }
.wg-old { stroke-dasharray: 6 6; stroke-width: 1.7; }
.wg-old, .wg-oldlab, .wg-e0, .wg-e0lab { opacity: 0; transition: opacity .35s ease; }
.wg-shifted .wg-old, .wg-shifted .wg-oldlab { opacity: .5; }
.wg-shifted .wg-old-s { opacity: 0; }
.wg-shifted-s .wg-old-s { opacity: .5; }
.wg-shifted .wg-e0, .wg-shifted-s .wg-e0 { opacity: .75; }
.wg-shifted .wg-e0lab, .wg-shifted-s .wg-e0lab { opacity: .65; }
.wg-e0lab { fill: var(--muted); text-anchor: middle; transition: none; } /* gone at once on the way back, or it sits on E for a moment */
.wg-shifted .wg-e0lab, .wg-shifted-s .wg-e0lab { transition: opacity .35s ease; }
.wg-guide { stroke: var(--stroke-muted); stroke-width: 1; stroke-dasharray: 2 4; }
.wg-cs { fill: color-mix(in srgb, var(--curve-d) 8%, transparent); }
.wg-e { fill: var(--ink-strong); }
.wg-e0 { fill: var(--bg); stroke: var(--stroke-muted); stroke-width: 1.5; }
.wg-el { fill: var(--ink); }
/* first paint: the curves draw in, then the labels and the note appear */
.wg-intro .wg-s, .wg-intro .wg-d { stroke-dasharray: 1; stroke-dashoffset: 1; animation: wg-draw .9s cubic-bezier(.4, 0, .2, 1) forwards; }
.wg-intro .wg-d { animation-delay: .2s; }
.wg-intro .wg-old { animation: none; }
.wg-intro .wg-e, .wg-intro .wg-el, .wg-intro .wg-guide, .wg-intro .wg-cs, .wg-intro .wg-tick, .wg-intro .wg-dl, .wg-intro .wg-sl { opacity: 0; animation: wg-fade .4s ease .9s forwards; }
@keyframes wg-draw { to { stroke-dashoffset: 0; } }
@keyframes wg-fade { to { opacity: 1; } }

/* the index: four ways in, ruled like a contents page */
.wl-index { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); }
.wl-entry {
  display: flex; flex-direction: column; align-items: flex-start; text-align: left; min-width: 0;
  padding: 20px 28px 20px; margin: 0; border: 0; background: transparent; color: inherit; font: inherit;
  transition: background-color .15s ease;
}
.wl-entry:first-child { padding-left: 0; }
.wl-entry + .wl-entry { border-left: 1px solid var(--line); }
button.wl-entry { cursor: pointer; }
button.wl-entry:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
button.wl-entry:focus-visible { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.wl-sym { height: 20px; display: flex; align-items: flex-end; font-family: var(--font-display); font-size: 18px; line-height: 1; color: var(--accent); margin-bottom: 8px; } /* one height for every symbol, so the titles line up */
.wl-sym i { font-style: italic; }
.wl-sym-delta { font-family: var(--font); font-size: 20px; font-weight: 400; } /* the serif Δ is very narrow; the body sans has a wide, even one */
.wl-sym-ab { font-family: var(--font-mono); font-size: 15px; letter-spacing: -.02em; }
.wl-entry-title { font-family: var(--font-display); font-size: 21px; font-weight: 600; line-height: 1.2; letter-spacing: -.02em; color: var(--ink-strong); transition: color .15s ease; }
.wl-entry-text { margin-top: 8px; max-width: 38ch; font-size: 14px; line-height: 1.55; color: var(--ink-2); }
.wl-count { display: block; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.wl-go {
  display: inline-flex; align-items: center; gap: 7px; margin-top: auto; padding-top: 16px;
  font-size: 14px; font-weight: 500; color: var(--ink); transition: color .15s ease;
}
.wl-go span { transition: transform .18s ease; }
button.wl-entry:hover .wl-entry-title, button.wl-entry:hover .wl-go { color: var(--accent-ink); }
button.wl-entry:hover .wl-go span, button.wl-entry:focus-visible .wl-go span { transform: translateX(4px); }
/* ready models: small ruled tags */
.wl-links { display: flex; flex-wrap: wrap; gap: 6px; }
.wl-links button, .wl-models .wl-go {
  border: 0; background: transparent; padding: 0; font: inherit; cursor: pointer; color: var(--ink);
}
.wl-links button {
  font-size: 13px; line-height: 1.4; padding: 2px 8px; border: 1px solid var(--line-strong); border-radius: 4px; text-decoration: none;
  transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.wl-links button:hover { color: var(--accent-ink); border-color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.wl-models .wl-go { font-size: 14px; font-weight: 500; padding-top: 16px; }
.wl-models .wl-go:hover { color: var(--accent-ink); }
.wl-models .wl-go:hover span { transform: translateX(4px); }

.wl-foot { flex: none; padding-top: 14px; padding-bottom: 18px; font-family: var(--font-display); font-style: italic; font-size: 15px; color: var(--muted); }

@media (max-height: 820px) and (min-width: 861px) {
  .wl-top { height: 54px; }
  .wl-main { gap: clamp(16px, 3vh, 32px); }
  .wl-copy h1::before { margin-bottom: 14px; }
  .wl-lede { margin-top: 14px; font-size: 15.5px; }
  .wl-ctas { margin-top: 20px; }
  .wl-cta { height: 42px; }
  .wl-graph { max-height: 33vh; }
  .wl-figure figcaption { margin-top: 6px; padding-top: 7px; }
  .wl-entry { padding-top: 14px; padding-bottom: 14px; }
  .wl-entry-text { margin-top: 5px; }
  .wl-go, .wl-models .wl-go { padding-top: 10px; }
  .wl-foot { padding-top: 10px; padding-bottom: 12px; }
}
@media (max-width: 1100px) {
  .wl-entry { padding-left: 20px; padding-right: 20px; }
}
/* medium screens tall enough for it: the index as two rows of two (short laptops keep one row, so the page fits 1024 x 700) */
@media (max-width: 1040px) and (min-width: 861px) and (min-height: 860px) {
  .wl-index { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wl-entry:nth-child(odd) { padding-left: 0; border-left: 0; }
  .wl-entry:nth-child(n + 3) { border-top: 1px solid var(--line); }
}
@media (max-width: 1100px) and (max-height: 820px) and (min-width: 861px) {
  .wl-lede { font-size: 15px; }
  .wl-graph { max-height: 30vh; }
  .wl-entry-text { font-size: 13.5px; }
}
@media (max-width: 860px) {
  .wl-top, .wl-main, .wl-foot { padding-left: 18px; padding-right: 18px; }
  .wl-main { justify-content: flex-start; gap: 34px; padding-top: 10px; }
  .wl-hero { grid-template-columns: minmax(0, 1fr); gap: 34px; }
  .wl-copy h1 { font-size: clamp(1.9rem, 7vw, 2.6rem); max-width: 18ch; }
  .wl-graph { max-height: none; }
  .wl-index { grid-template-columns: minmax(0, 1fr); }
  .wl-entry, .wl-entry:first-child { padding-left: 0; padding-right: 0; }
  .wl-entry + .wl-entry { border-left: 0; border-top: 1px solid var(--line); }
  .wl-foot { padding-top: 18px; }
}
@media (max-width: 420px) {
  .wl-cta { flex: 1 1 100%; }
  .wl-read { gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .welcome, :root[data-view="app"] .welcome, .topbar, .layout { transition: none; }
  .wg-old, .wg-oldlab, .wg-e0, .wg-e0lab, .wl-go span { transition: none; }
}
/* axis range: min "to" max on one row */
.field .minmax { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 6px; }
.field .minmax i { font-style: normal; color: var(--muted); font-size: 12px; }
/* curve and area names can be dragged on their own */
.stage svg text[data-label] { cursor: move !important; }
/* TikZ export: copy and download side by side */
.exp-two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.exp-two[hidden], .export-pop [data-only][hidden] { display: none; }
.menu-pop .exp-two .btn { width: auto; text-align: center; padding: 7px 6px; font-size: 12.5px; }
.menu-pop .exp-two .btn:not(.primary) { border: 1px solid var(--line); }
/* model parameters: the label on its own line, then a slider and a number box */
.field.field-stack { grid-template-columns: minmax(0, 1fr); gap: 3px; margin: 9px 0; }
.field-stack .range input.num { flex: 0 0 64px; width: 64px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); font: 12.5px/1.2 'JetBrains Mono', ui-monospace, monospace; }
.analysis .btnrow { margin: 8px 0 2px; }
