/* OVec demo. Colours are tokens; the canvas and the chart read them at draw time. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.12);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --s1: #2a78d6;
  --s2: #eb6834;
  --critical: #d03b3b;
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100;
  --c5: #e87ba4; --c6: #008300; --c7: #6250d6; --c8: #e34948;
  --region-alpha: 0.10;
  --region-probed-alpha: 0.30;
  --boundary-alpha: 0.35;
  --point-dim-alpha: 0.22;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 8px 24px rgba(11, 11, 11, 0.06);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a9890;
    --grid: #2c2c2a;
    --axis: #45453f;
    --border: rgba(255, 255, 255, 0.12);
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --s1: #3987e5;
    --s2: #d95926;
    --critical: #e05a5a;
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
    --c5: #d55181; --c6: #1f9a1f; --c7: #9085e9; --c8: #e66767;
    --region-alpha: 0.13;
    --region-probed-alpha: 0.34;
    --boundary-alpha: 0.45;
    --point-dim-alpha: 0.25;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

a { color: var(--accent); text-underline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--surface-2); padding: 0.05em 0.35em; border-radius: 4px; }
h1, h2 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- layout ---------- */

.intro, .workspace, .curve, .how {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

.intro { padding-top: 40px; padding-bottom: 24px; }
.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.intro h1 { font-size: clamp(32px, 6vw, 44px); letter-spacing: -0.02em; }
.lede { max-width: 68ch; margin: 12px 0 10px; color: var(--ink-2); font-size: 16px; }
.lede strong { color: var(--ink); font-weight: 600; }
.links { margin: 0; display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 880px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- plot ---------- */

.stage { min-width: 0; }

.plot {
  position: relative;
  width: 100%;
  max-width: 720px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

#plane {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--border), var(--shadow);
  cursor: crosshair;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#plane:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 24px;
  border-radius: var(--radius);
  background: var(--surface);
}
.loader[hidden] { display: none; }
.loader-title { margin: 0 0 14px; font-weight: 600; font-size: 17px; }
.loader-foot { margin: 14px 0 0; font-size: 13px; }
.loader-slow { margin: 10px 0 0; max-width: 42ch; font-size: 13px; color: var(--ink-2); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.steps li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.steps li .muted { margin-left: 4px; font-size: 13px; }
.steps li.active, .steps li.done { color: var(--ink); }

.tick {
  flex: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--axis);
  position: relative;
}
.steps li.active .tick {
  border-color: var(--accent);
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
.steps li.done .tick { border-color: var(--accent); background: var(--accent); }
.steps li.done .tick::after {
  content: "";
  position: absolute;
  left: 3.5px; top: 0.5px;
  width: 4px; height: 8px;
  border: solid var(--accent-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
@keyframes spin { to { transform: rotate(360deg); } }

.loader-error { margin-top: 16px; max-width: 42ch; }
.loader-error p { margin: 0 0 10px; color: var(--critical); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  justify-content: center;
  margin: 12px auto 0;
  max-width: 720px;
  font-size: 13px;
  color: var(--ink-2);
  min-height: 20px;
}
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { flex: none; overflow: visible; }

.note {
  max-width: 720px;
  margin: 12px auto 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 14px;
}
.note strong { color: var(--ink); }

/* ---------- panel ---------- */

.panel { min-width: 0; display: grid; gap: 16px; }

.controls {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--border);
}
.controls:disabled { opacity: 0.55; }

.group { padding: 14px 16px; display: grid; gap: 10px; }
.group + .group { border-top: 1px solid var(--grid); }
.group h2 { font-size: 14px; font-weight: 600; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.group-head .mono { font-size: 12px; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  gap: 2px;
  border-radius: 9px;
  background: var(--surface-2);
}
.segmented label { position: relative; min-width: 0; }
.segmented input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segmented span {
  display: block;
  padding: 6px 4px;
  border-radius: 7px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.segmented input:checked + span {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--border), 0 1px 2px rgba(0, 0, 0, 0.08);
}
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.slider { display: grid; gap: 4px; }
.slider-head { display: flex; justify-content: space-between; font-size: 14px; }
.slider-head .muted { font-size: 13px; }
.slider input { width: 100%; margin: 0; accent-color: var(--accent); }
.slider.inactive { opacity: 0.45; }

.button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.button:disabled { cursor: default; opacity: 0.6; }
.button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.button.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.button.ghost { background: transparent; }
.button.primary.invite { animation: invite 2.2s ease-in-out infinite; }
@keyframes invite {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .button.primary.invite, .steps li.active .tick { animation: none; }
}

.status { margin: 0; font-size: 13px; color: var(--ink-2); }

/* ---------- results ---------- */

.results {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--border);
  padding: 14px 16px;
  font-size: 14px;
  min-height: 120px;
}
.results h2 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.results .where { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.dispatch {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 6px;
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--ink-2);
}
.dispatch code { color: var(--ink); }

.compare { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.compare th, .compare td { padding: 6px 0; text-align: right; vertical-align: baseline; }
.compare th:first-child, .compare td:first-child { text-align: left; color: var(--ink-2); font-weight: 400; }
.compare thead th { font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--grid); }
.compare tbody tr + tr td { border-top: 1px solid var(--grid); }
.compare td .sub { display: block; font-size: 12px; color: var(--muted); }
.compare td.none { color: var(--muted); }
.results .hint { margin: 12px 0 0; font-size: 13px; color: var(--ink-2); }

/* ---------- curve ---------- */

.curve { margin-top: 40px; }
.curve-inner { min-width: 0; }
.curve-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.curve-head h2 { font-size: 20px; }
.curve-head p { margin: 0; font-size: 14px; }
.headline { margin: 8px 0 0; max-width: 72ch; color: var(--ink-2); min-height: 1.55em; }
.headline strong { color: var(--ink); }

.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 12px 0 6px; font-size: 13px; color: var(--ink-2); }
.chart-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 16px; height: 2px; border-radius: 1px; }
.swatch.s1 { background: var(--s1); }
.swatch.s2 { background: var(--s2); }

.chart {
  position: relative;
  height: 280px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--border);
  overflow: hidden;
}
.chart svg { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.chart .c-tick { font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .c-title { font-size: 12px; fill: var(--muted); }
.chart .c-marker { font-size: 12px; font-weight: 600; fill: var(--ink-2); }
.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  background: var(--surface);
}
.chart-empty[hidden] { display: none; }
.chart.busy svg { opacity: 0.35; transition: opacity 0.2s; }
.chart-busy {
  position: absolute;
  top: 10px; right: 12px;
  font-size: 12px;
  color: var(--ink-2);
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--border);
}

.tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 2;
  min-width: 180px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--border), var(--shadow);
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.tooltip .t-head { font-weight: 600; margin-bottom: 2px; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .t-row b { margin-left: auto; padding-left: 12px; color: var(--ink); font-weight: 600; }
.tooltip .t-foot { margin-top: 4px; font-size: 12px; color: var(--muted); }

.table-view { margin-top: 10px; font-size: 14px; }
.table-view summary { cursor: pointer; color: var(--accent); width: max-content; }
.table-scroll { overflow-x: auto; margin-top: 8px; }
.table-view table { border-collapse: collapse; font-variant-numeric: tabular-nums; min-width: 100%; }
.table-view th, .table-view td { padding: 4px 12px 4px 0; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.table-view th { color: var(--muted); font-weight: 600; font-size: 12px; }
.table-view tr.current td { font-weight: 600; }

/* ---------- footer ---------- */

.how { margin-top: 48px; padding-top: 24px; padding-bottom: 48px; border-top: 1px solid var(--grid); }
.how h2 { font-size: 16px; margin-bottom: 8px; }
.how p { max-width: 75ch; color: var(--ink-2); font-size: 14px; margin: 0 0 10px; }
