:root {
  --vellum: #f1f3f8;
  --sheet: #fbfcfe;
  --ink: #131b36;
  --ink-2: #4a5270;
  --ink-3: #8a91a9;
  --rule: rgba(19, 27, 54, 0.12);
  --cobalt: #2340ff;
  --amber: #f59e0b;
  --jade: #0e9f72;
  --red: #ec3d2a;
  --focus: #2340ff;
  --panel-w: 372px;
  --ui: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --prose: "Literata", Georgia, "Times New Roman", serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0; background: var(--vellum); color: var(--ink);
  font: 400 15px/1.45 var(--ui); font-variant-numeric: tabular-nums;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------------ stage */
.stage { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); height: 100vh; height: 100dvh; min-height: 620px; }
.plot { position: relative; background: var(--sheet); overflow: hidden; border-right: 1px solid var(--rule); }
.plot canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#labels { pointer-events: none; }
.plot[data-edit="add"] #gl { cursor: crosshair; touch-action: none; }
.plot[data-edit="remove"] #gl { cursor: not-allowed; touch-action: none; }

.hud-title { position: absolute; left: 28px; top: 22px; right: 28px; pointer-events: none; max-width: 640px; }
.hud-title h1 {
  margin: 0; font-weight: 800; font-size: clamp(2.3rem, 5.2vw, 4.1rem); line-height: 0.95; letter-spacing: -0.025em;
  font-variation-settings: "wdth" 78, "opsz" 96;
}
.hud-title p { margin: 10px 0 0; max-width: 46ch; color: var(--ink-2); font-size: 15px; line-height: 1.4; }

.hud-links { position: absolute; right: 22px; top: 22px; display: flex; gap: 18px; font-size: 14px; font-weight: 500; }
.hud-links a { color: var(--ink); text-decoration: none; border-bottom: 1.5px solid var(--rule); padding-bottom: 1px; }
.hud-links a:hover { border-color: var(--ink); }

.caption {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); margin: 0;
  width: min(720px, calc(100% - 40px)); padding: 10px 14px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.86); border: 1px solid var(--rule); backdrop-filter: blur(6px);
  font-size: 14.5px; line-height: 1.4; text-align: left; pointer-events: none; min-height: 2.9em;
}

.nogl { position: absolute; inset: 0; display: grid; place-items: center; background: var(--sheet); padding: 24px; text-align: center; }
.nogl[hidden] { display: none; }
.nogl p { max-width: 38ch; font-size: 17px; }

/* ------------------------------------------------------------------ panel */
.panel { background: var(--vellum); overflow-y: auto; padding: 18px 18px 28px; display: flex; flex-direction: column; gap: 14px; }

.readout { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding: 14px; background: var(--sheet); border: 1px solid var(--rule); border-radius: 12px; }
.readout div { min-width: 0; }
.readout .wide { grid-column: 1 / -1; }
.readout dt { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.readout dd { margin: 1px 0 0; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.readout dd.big { font-size: 34px; line-height: 1.05; font-weight: 700; letter-spacing: -0.01em; font-variation-settings: "wdth" 85; }
#sGap[data-better="true"] { color: var(--jade); }

.warn { margin: 0; padding: 8px 10px; border-radius: 8px; background: #fff3d6; border: 1px solid #f0cf86; font-size: 13px; }
.warn[hidden] { display: none; }

/* controls */
.playback { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
.icon {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%;
  background: var(--sheet); border: 1px solid var(--rule); padding: 0;
}
.icon svg { width: 20px; height: 20px; fill: var(--ink); stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon:hover:not(:disabled) { border-color: var(--ink); }
.icon.primary { width: 50px; height: 50px; background: var(--ink); border-color: var(--ink); }
.icon.primary svg { fill: #fff; stroke: #fff; }
#play[data-state="playing"] .i-play, #play[data-state="paused"] .i-pause { display: none; }
.text { height: 36px; padding: 0 14px; border-radius: 999px; background: var(--sheet); border: 1px solid var(--rule); font-weight: 500; font-size: 14px; }
.text:hover:not(:disabled) { border-color: var(--ink); }

.slider { display: block; }
.slider > span, .field > span { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); font-weight: 500; margin-bottom: 3px; }
.slider output { color: var(--ink); font-weight: 600; }
input[type="range"] { width: 100%; margin: 0; height: 28px; accent-color: var(--ink); background: transparent; }

.group { margin: 0; padding: 12px 14px 14px; border: 1px solid var(--rule); border-radius: 12px; background: var(--sheet); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
details.group { display: block; }
details.group > * + * { margin-top: 10px; }
.group > legend, .group > summary { font-weight: 700; font-size: 14.5px; padding: 0 4px; }
details.group > summary { padding: 0; cursor: pointer; list-style-position: inside; }

.field { display: block; min-width: 0; }
select, input[type="number"] {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--rule);
  background: #fff; color: var(--ink); font: inherit; font-size: 14px;
}
.row { display: flex; gap: 8px; align-items: flex-end; }
.row .grow { flex: 1; }
.row .text { height: 36px; flex: none; padding: 0 12px; }

.check { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { margin: 3px 0 0; accent-color: var(--ink); width: 16px; height: 16px; flex: none; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.seg-label { flex-basis: 100%; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.seg button { height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--rule); background: #fff; font-size: 13.5px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.hint { margin: 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13.5px; }
.legend li { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center; }
.sw { display: block; height: 0; border-top: 3.4px solid var(--c); border-radius: 2px; }
.sw.dash { border-top-style: dashed; }
.sw.arrow { position: relative; }
.sw.arrow::after { content: ""; position: absolute; right: -2px; top: -7px; border-left: 9px solid var(--c); border-top: 5.5px solid transparent; border-bottom: 5.5px solid transparent; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 2px solid var(--ink); justify-self: center; }
.dot.hollow { background: #fff; }

/* ------------------------------------------------------------------ article */
.prose { max-width: 1040px; margin: 0 auto; padding: 72px 28px 24px; font-family: var(--prose); font-size: 18px; line-height: 1.68; }
.prose > * { max-width: 66ch; }
.prose > .split, .prose > .table-wrap { max-width: none; }
.prose h2 {
  margin: 2.6em 0 0.5em; font-family: var(--ui); font-weight: 750; font-size: clamp(1.7rem, 3.2vw, 2.3rem); line-height: 1.08;
  letter-spacing: -0.02em; font-variation-settings: "wdth" 84, "opsz" 72;
}
.prose h2:first-child { margin-top: 0; }
.prose p { margin: 0 0 1em; }
.prose a { color: var(--cobalt); text-underline-offset: 3px; }
.prose code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.85em; background: rgba(19, 27, 54, 0.07); padding: 1px 6px; border-radius: 5px; }
.prose sup { font-size: 0.7em; line-height: 0; }

.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 36px; align-items: start; margin-bottom: 1em; }
.steps { margin: 0 0 1em; padding-left: 1.3em; }
.steps li { margin-bottom: 0.6em; padding-left: 0.3em; }
.steps li::marker { font-family: var(--ui); font-weight: 700; color: var(--cobalt); }
.fig { margin: 8px 0 0; padding: 14px; background: var(--sheet); border: 1px solid var(--rule); border-radius: 14px; }
.fig svg { display: block; width: 100%; height: auto; }
.fig-t { font: 600 15px var(--ui); fill: var(--ink); }
.fig-t.blue { fill: var(--cobalt); }
.fig-t.amber { fill: #b36b00; }
.fig figcaption { margin-top: 8px; font: 400 13.5px/1.45 var(--ui); color: var(--ink-2); }

.presets { margin: 0 0 1em; padding-left: 1.2em; }
.presets li { margin-bottom: 0.3em; }

.table-wrap { overflow-x: auto; margin: 0 0 1.2em; border: 1px solid var(--rule); border-radius: 12px; background: var(--sheet); max-width: 760px !important; }
table { border-collapse: collapse; width: 100%; font: 500 15px var(--ui); font-variant-numeric: tabular-nums; }
th, td { padding: 11px 16px; text-align: right; border-bottom: 1px solid var(--rule); white-space: nowrap; }
thead th { font-weight: 600; color: var(--ink-2); font-size: 13.5px; white-space: normal; vertical-align: bottom; }
tbody th { font-weight: 700; text-align: left; }
thead th:first-child { text-align: left; }
tbody tr:last-child > * { border-bottom: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.foot { max-width: 1040px; margin: 0 auto; padding: 32px 28px 56px; color: var(--ink-2); font-size: 14px; }
.foot a { color: inherit; }

/* ------------------------------------------------------------------ small screens */
@media (max-width: 1000px) {
  .stage { display: block; height: auto; min-height: 0; }
  .plot { height: 78vh; height: 78dvh; min-height: 460px; border-right: 0; border-bottom: 1px solid var(--rule); }
  .panel { overflow: visible; padding: 16px 14px 26px; }
  .hud-links { top: auto; bottom: 86px; right: 14px; gap: 14px; font-size: 13px; }
  .hud-title { left: 16px; top: 16px; }
  .caption { bottom: 12px; }
  .split { grid-template-columns: 1fr; gap: 12px; }
  .prose { padding: 52px 18px 16px; font-size: 17px; }
}
@media (max-width: 520px) {
  .hud-links { display: none; }
  .hud-title p { font-size: 13.5px; }
  .caption { font-size: 13.5px; }
}
