/* minikalman lab: a bench notebook in light, an instrument panel in dark. */

:root {
  --paper: #e9eef1;
  --paper-line: rgba(31, 95, 209, 0.07);
  --panel: #f6f8f9;
  --screen: #fbfcfd;
  --grid: #d5dee4;
  --grid-strong: #b9c6cf;
  --ink: #142029;
  --ink-soft: #4c5b67;
  --rule: #c3ced6;
  --focus: #1f5fd1;

  /* Trace colours, one per role, used the same way in every experiment. */
  --truth: #5d6b76;
  --meas: #8f5a14;
  --c1: #c03a2b; /* the plain or first variant */
  --c2: #1f5fd1; /* the second variant */
  --c3: #0a7468; /* the third variant */
  --c4: #9a2f8a; /* a fourth variant */
  --flag: #c03a2b;

  --font: "Recursive Variable", ui-sans-serif, system-ui, sans-serif;
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.6rem;
  --step-3: 2.4rem;
  --step-4: clamp(2.6rem, 6vw, 4.4rem);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1821;
    --paper-line: rgba(120, 168, 255, 0.045);
    --panel: #142029;
    --screen: #09121a;
    --grid: #1c2a36;
    --grid-strong: #2b3c4a;
    --ink: #dce6ee;
    --ink-soft: #94a6b4;
    --rule: #2b3c4a;
    --focus: #7fb0ff;
    --truth: #9aabb8;
    --meas: #e0a855;
    --c1: #ff7a66;
    --c2: #78a8ff;
    --c3: #45cdb6;
    --c4: #e27fd4;
    --flag: #ff7a66;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #0f1821;
  --paper-line: rgba(120, 168, 255, 0.045);
  --panel: #142029;
  --screen: #09121a;
  --grid: #1c2a36;
  --grid-strong: #2b3c4a;
  --ink: #dce6ee;
  --ink-soft: #94a6b4;
  --rule: #2b3c4a;
  --focus: #7fb0ff;
  --truth: #9aabb8;
  --meas: #e0a855;
  --c1: #ff7a66;
  --c2: #78a8ff;
  --c3: #45cdb6;
  --c4: #e27fd4;
  --flag: #ff7a66;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  background-color: var(--paper);
  /* Graph paper: a 24 px grid, faint enough to read over. */
  background-image:
    linear-gradient(to right, var(--paper-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--paper-line) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.55;
  font-variation-settings: "CASL" 0, "MONO" 0;
}

a {
  color: inherit;
  text-decoration-color: var(--grid-strong);
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-color: currentColor;
}

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

code {
  font-variation-settings: "MONO" 1;
  font-size: 0.92em;
}

.wrap {
  max-width: 76rem;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ── Masthead ── */

.masthead {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  align-items: baseline;
  justify-content: space-between;
  padding-top: 1.25rem;
  padding-bottom: 0.75rem;
}

.masthead nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  font-size: var(--step--1);
  align-items: center;
}

.wordmark {
  font-weight: 750;
  font-variation-settings: "CASL" 1, "MONO" 1;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.theme-toggle {
  font: inherit;
  font-size: var(--step--1);
  color: inherit;
  background: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  cursor: pointer;
}

/* ── Hero: a live strip chart ── */

.hero {
  padding-block: 1.5rem 0.5rem;
}

.hero h1 {
  font-size: var(--step-4);
  line-height: 1.02;
  font-weight: 800;
  font-variation-settings: "CASL" 0.6, "MONO" 0;
  letter-spacing: -0.025em;
  margin: 0 0 0.75rem;
  max-width: 16ch;
}

.hero .lede {
  font-size: var(--step-1);
  color: var(--ink-soft);
  max-width: 44rem;
  margin: 0 0 1.5rem;
}

.hero .experiment {
  padding-top: 0;
  border-bottom: 0;
}

/* ── Index of experiments ── */

.bench {
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding-block: 1rem;
  margin-bottom: 1rem;
}

.bench ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.75rem 1.5rem;
}

.bench a {
  display: block;
  text-decoration: none;
  padding: 0.35rem 0;
}

.bench a strong {
  display: block;
  font-weight: 650;
}

.bench a span {
  color: var(--ink-soft);
  font-size: var(--step--1);
}

.bench a:hover strong {
  text-decoration: underline;
  text-decoration-color: var(--grid-strong);
  text-underline-offset: 0.2em;
}

/* ── One experiment: notes on the left, the instrument on the right ── */

.experiment {
  display: grid;
  grid-template-columns: minmax(0, 22rem) minmax(0, 1fr);
  gap: 1.5rem 2.5rem;
  padding-block: 3rem;
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: 1rem;
}

@media (max-width: 860px) {
  .experiment {
    grid-template-columns: minmax(0, 1fr);
    padding-block: 2rem;
  }
}

.experiment h2 {
  font-size: var(--step-2);
  line-height: 1.15;
  font-weight: 750;
  font-variation-settings: "CASL" 0.6, "MONO" 0;
  letter-spacing: -0.015em;
  margin: 0 0 0.5rem;
}

.experiment .api {
  margin: 0 0 1rem;
  font-size: var(--step--1);
  color: var(--ink-soft);
}

.notes p {
  margin: 0 0 0.85rem;
  max-width: 38rem;
}

.seeing {
  border-left: 3px solid var(--grid-strong);
  padding: 0.1rem 0 0.1rem 0.85rem;
  color: var(--ink-soft);
}

.seeing strong {
  color: var(--ink);
  font-weight: 650;
}

.source {
  font-size: var(--step--1);
}

.instrument {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* The scope: a screen with a fine grid drawn on canvas. */
.scope {
  position: relative;
  background: var(--screen);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}

.scope canvas {
  display: block;
  width: 100%;
  touch-action: pan-y;
}

/* Drawing on the basics plot must not scroll the page. */
#hero-plot {
  touch-action: none;
}

.scope canvas.radar {
  aspect-ratio: 16 / 9;
  height: auto;
  touch-action: none;
}

fieldset.knobs legend {
  padding: 0;
  margin-bottom: 0.25rem;
}

.scope-title {
  position: absolute;
  top: 0.4rem;
  left: 0.6rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  pointer-events: none;
  background: color-mix(in srgb, var(--screen) 80%, transparent);
  padding: 0 0.25rem;
  border-radius: 2px;
}

.scope-pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0.75rem;
}

/* Legend: a swatch drawn like the trace it names. */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.1rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--step--1);
  color: var(--ink-soft);
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.swatch {
  display: inline-block;
  width: 1.4rem;
  height: 0;
  border-top: 2.5px solid var(--color);
}

.swatch.dashed {
  border-top-style: dashed;
  border-top-width: 2px;
}

.swatch.dot {
  width: 0.45rem;
  height: 0.45rem;
  border: 0;
  border-radius: 50%;
  background: var(--color);
}

.swatch.tick {
  width: 2px;
  height: 0.8rem;
  border: 0;
  background: var(--color);
}

/* Knobs: the bench's controls. */
.knobs {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.6rem;
  margin: 1.25rem 0;
  padding: 0;
  border: 0;
}

.knob {
  display: grid;
  grid-template-columns: minmax(7.5rem, auto) minmax(0, 1fr) minmax(4.75rem, auto);
  align-items: center;
  gap: 0.75rem;
  font-size: var(--step--1);
}

.knob output {
  text-align: right;
  font-variation-settings: "MONO" 1;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: var(--ink);
  height: 1.5rem;
  margin: 0;
}

.switches {
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  font-size: var(--step--1);
}

.switches label {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}

/* The radar's controls: after the base knob rules, which they refine. */
.radar-knobs {
  margin-top: 0;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  column-gap: 2rem;
}

.radar-knobs .knob {
  grid-template-columns: 7rem minmax(5rem, 1fr) 8rem;
}

.radar-knobs output {
  white-space: nowrap;
}

.radar-knobs select {
  grid-column: 2 / -1;
}

@media (max-width: 520px) {
  .radar-knobs .knob {
    grid-template-columns: 6rem minmax(4rem, 1fr) 8rem;
  }
}

.radar-knobs .hint,
.radar-knobs .switches {
  grid-column: 1 / -1;
}

.actions {
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

button,
select {
  font: inherit;
  font-size: var(--step--1);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--grid-strong);
  border-radius: 4px;
  padding: 0.3rem 0.75rem;
  min-height: 2rem;
}

button:not(:disabled) {
  cursor: pointer;
}

button:not(:disabled):hover {
  border-color: var(--ink-soft);
}

button:disabled {
  opacity: 0.5;
}

/* Readouts: measured numbers, each tagged with the trace it belongs to. */
.readouts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.5rem;
  margin: 0;
}

.readout {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--color, var(--rule));
  border-radius: 4px;
  padding: 0.4rem 0.6rem 0.45rem;
  min-width: 0;
}

.readout dt {
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.3;
}

.readout dd {
  margin: 0.1rem 0 0;
  font-size: var(--step-1);
  line-height: 1.2;
  font-variation-settings: "MONO" 1;
  font-variant-numeric: tabular-nums;
  font-weight: 560;
  overflow-wrap: anywhere;
}

.readout dd small {
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-weight: 400;
}

.readout.best dd::after {
  content: " ◂ best";
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-weight: 400;
}

.status {
  font-size: var(--step--1);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  margin: 0;
}

.hint {
  font-size: var(--step--1);
  color: var(--ink-soft);
  margin: 0;
}

.fallback {
  border: 1px solid var(--flag);
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
}

/* A small results table: one row per variant. */
.table-wrap {
  overflow-x: auto;
}

.matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step--1);
}

.matrix caption {
  text-align: left;
  color: var(--ink-soft);
  padding-bottom: 0.25rem;
}

.matrix th,
.matrix td {
  text-align: right;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
}

.matrix td {
  font-variation-settings: "MONO" 1;
}

.matrix th:first-child,
.matrix td:first-child {
  text-align: left;
}

.matrix thead th {
  font-weight: 500;
  color: var(--ink-soft);
}

.matrix tbody th {
  font-weight: 600;
  white-space: nowrap;
  border-left: 3px solid var(--color, transparent);
}

.matrix .bad {
  color: var(--flag);
  font-weight: 650;
}

/* Narrow screens: after the base table rules, which these override. */
@media (max-width: 520px) {
  .matrix {
    font-size: 0.78rem;
  }

  .matrix th,
  .matrix td {
    padding: 0.3rem;
  }

  .matrix tbody th {
    white-space: normal;
  }
}

/* Attitude: three horizon dials. */
.dials {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.dial {
  text-align: center;
  font-size: var(--step--1);
  color: var(--ink-soft);
  margin: 0;
}

.scrub {
  grid-template-columns: auto minmax(0, 1fr) 4.75rem;
}

.dial canvas {
  width: 100%;
  max-width: 11rem;
  aspect-ratio: 1;
  display: block;
  margin: 0 auto 0.25rem;
}

footer {
  padding-block: 2.5rem 3rem;
  color: var(--ink-soft);
  font-size: var(--step--1);
}

footer p {
  max-width: 44rem;
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
