:root {
  --bg: #ffffff; --panel: rgba(255,255,255,0.92); --panel-border: #d8dde3; --text: #1b1f24; --muted: #5b6470;
  --accent: #1f7a4d; --accent-2: #b3261e; --input-bg: #ffffff; --shadow: 0 4px 18px rgba(0,0,0,0.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #ffffff; --panel: rgba(24,28,34,0.92); --panel-border: #3a414b; --text: #e8ecf1; --muted: #a2abb6;
    --accent: #5cc48f; --accent-2: #ff6b5e; --input-bg: #10141a; --shadow: 0 4px 18px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  --bg: #ffffff; --panel: rgba(24,28,34,0.92); --panel-border: #3a414b; --text: #e8ecf1; --muted: #a2abb6;
  --accent: #5cc48f; --accent-2: #ff6b5e; --input-bg: #10141a; --shadow: 0 4px 18px rgba(0,0,0,0.5);
}
html, body { height: 100%; width: 100%; overflow: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#view { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
#view canvas { display: block; max-width: 100%; }

/* top bar: nothing in it may be wider than the viewport, so the select has a fixed width and the info line wraps */
#topbar { position: fixed; top: 0; left: 0; right: 0; max-width: 100vw; box-sizing: border-box; padding: 8px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--panel-border); backdrop-filter: blur(6px); z-index: 5; box-shadow: var(--shadow); }
#topbar input[type=text] { flex: 1 1 220px; min-width: 0; font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid var(--panel-border); border-radius: 8px; background: var(--input-bg); color: var(--text); }
#topbar select, #topbar button, #panel button, #panel select { font: inherit; font-size: 14px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--panel-border); background: var(--input-bg); color: var(--text); cursor: pointer; }
#topbar button { flex: 0 0 auto; }
#topbar select { flex: 0 0 auto; width: 9.5em; min-width: 0; max-width: calc(100vw - 16px); box-sizing: border-box; }
#topbar button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
#topbar .seg { display: inline-flex; flex: 0 0 auto; border: 1px solid var(--panel-border); border-radius: 8px; overflow: hidden; background: var(--input-bg); }
#topbar .seg button { border: 0; border-radius: 0; padding: 8px 10px; background: transparent; color: var(--muted); }
#topbar .seg button + button { border-left: 1px solid var(--panel-border); }
#topbar .seg button.active { background: var(--accent); color: #fff; }
#animbar { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 13px; color: var(--muted); }
#animbar[hidden] { display: none; }
#animbar button { padding: 3px 9px; font-size: 12px; }
#animbar input[type=range] { flex: 1 1 140px; min-width: 80px; accent-color: var(--accent); }
#animbar #speed { flex: 0 1 120px; }
#animbar .val { color: var(--text); font-variant-numeric: tabular-nums; min-width: 3.2em; }
#info { flex-basis: 100%; min-width: 0; font-size: 13px; color: var(--muted); min-height: 1.2em; white-space: normal; overflow-wrap: anywhere; }
#info b { color: var(--text); font-weight: 600; }
#info .err { color: var(--accent-2); }
#info .ok { color: var(--accent); }

/* options drawer: slides in from the left, below the top bar (whose height is measured into --topbar-h),
   never taller than the space under it; the two tabs ride on its right edge */
#drawer { position: fixed; left: 0; top: calc(var(--topbar-h, 64px) + 8px); bottom: 8px; z-index: 6; width: min(300px, 85vw);
  display: flex; flex-direction: column; align-items: stretch; pointer-events: none;
  transform: translateX(-100%); transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); will-change: transform; }
#drawer.open { transform: none; }
#drawer > * { pointer-events: auto; }
#panel { box-sizing: border-box; width: 100%; max-height: 100%; overflow: auto; background: var(--panel); border: 1px solid var(--panel-border); border-left: 0;
  border-radius: 0 12px 12px 0; padding: 10px 12px; box-shadow: var(--shadow); backdrop-filter: blur(6px); }
#panel section[hidden] { display: none; }
#drawer .tabs { position: absolute; left: 100%; top: 4px; margin-left: -1px; display: flex; flex-direction: column; gap: 8px; }
/* each tab's text runs vertically, reading bottom to top; the button is rotated, so its logical right edge is the
   visible left edge that touches the panel */
#drawer .tab { writing-mode: vertical-rl; transform: rotate(180deg);
  padding: 14px 9px; border: 1px solid var(--panel-border); border-right: 0; border-radius: 10px 0 0 10px;
  background: var(--panel); color: var(--text); font: inherit; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; font-size: 12px; cursor: pointer;
  box-shadow: var(--shadow); backdrop-filter: blur(6px); white-space: nowrap; }
#drawer .tab:hover, #drawer .tab:focus-visible { color: var(--accent); }
#drawer .tab.active { color: var(--accent); background: var(--input-bg); }
#panel h3 { margin: 4px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
#panel label { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 8px; margin: 6px 0; font-size: 13px; }
#panel label input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
#panel label input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
#panel label[hidden] { display: none; }
#panel button.mini { padding: 1px 7px; font-size: 11px; border-radius: 6px; margin-left: 6px; }
#panel button.mini.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#panel label select { min-width: 0; max-width: 100%; }
#panel .val { color: var(--muted); font-variant-numeric: tabular-nums; }
#panel .row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
#panel .row button { flex: 1 1 auto; }
#panel .help { font-size: 12px; color: var(--muted); margin: 2px 0 6px; line-height: 1.35; }
.katex { font-size: 1.05em; }
#info .eq .katex { font-size: 1.15em; }
#panel label .tex { display: inline; }
#panel label .name { display: inline; }             /* one grid cell for a label with math in it */
#topbar .seg .katex { font-size: 1em; }
#panel .val input[type=number] { width: 5.5em; font: inherit; font-size: 13px; padding: 2px 4px; border: 1px solid var(--panel-border); border-radius: 6px; background: var(--input-bg); color: var(--text); text-align: right; }
#lattice-plot { display: block; width: 100%; height: auto; border: 1px solid var(--panel-border); border-radius: 8px; margin: 4px 0 8px; background: var(--input-bg); }
@media (prefers-reduced-motion: reduce) { #drawer { transition: none; } }

/* the analyser's remarks about how a typed curve was brought to a plottable model, over the top of the canvas */
#remarks { position: fixed; right: 8px; bottom: 8px; max-width: min(560px, 60vw);
  z-index: 4; padding: 5px 10px; font-size: 12.5px; line-height: 1.4; text-align: right; color: var(--muted);
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px; box-shadow: var(--shadow); backdrop-filter: blur(6px); }
#remarks[hidden] { display: none; }
#hint { position: fixed; left: 8px; bottom: 8px; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 8px; z-index: 4; max-width: 60vw; }
#hint[hidden] { display: none; }
#busy { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 16px; z-index: 7; box-shadow: var(--shadow); }
#busy[hidden] { display: none; }
@media (max-width: 640px) {
  #hint { display: none; }
}
