/* Palette inherited from the portfolio site (see ../../index.html :root):
   cool technical — blue-shifted paper, deep navy ink, electric indigo as the
   single accent, cyan as a live signal, violet as the forward-looking tone. */
:root {
  --bg: #f4f6fb;                       /* --paper  */
  --surface: #ffffff;                  /* --surface */
  --surface-2: #e9edf6;                /* --tint   */
  --border: #dee4f0;                   /* --rule   */
  --text: #0e1626;                     /* --ink    */
  --muted: #606b82;                    /* --ink-3, contrast-checked */
  --accent: #2337cf;                   /* --brand  */
  --accent-soft: rgba(35, 55, 207, .07); /* --brand-wash */
  --grid: rgba(35, 55, 207, .07);      /* --grid-line */
  /* Series colours. The site's three tones are all cool, so the second
     categorical series takes a warm counterpart: two classes have to be
     told apart at a glance, which needs separation in hue, not just value. */
  --class0: #2337cf;                   /* indigo  — train / class 0 */
  --class1: #d2691e;                   /* amber   — test / class 1  */
  --fit: #7b3ff0;                       /* --accent-2 violet — the fitted model */
  --truth: #7a869d;                    /* muted navy — the true function */
  --good: #067a94;                     /* deepened --accent cyan — best in column */
  --radius: 10px;
  color-scheme: light;
}
/* The portfolio page is light-only; this keeps the lab usable at night in the
   same hues — navy ground, the same indigo/cyan/violet family lifted for contrast. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b111c;
    --surface: #131c2c;
    --surface-2: #1b2536;
    --border: #273248;
    --text: #e7ecf7;
    --muted: #97a3bb;
    --accent: #8598ff;
    --accent-soft: rgba(133, 152, 255, .13);
    --grid: rgba(133, 152, 255, .10);
    --class0: #6f86ff;
    --class1: #f0914f;
    --fit: #a97cff;
    --truth: #7c8aa6;
    --good: #35c3de;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
h1, h2 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 13px; font-weight: 600; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.tagline { margin: 2px 0 0; color: var(--muted); }
.tasks { display: flex; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.tasks button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 500;
  padding: 6px 14px; border-radius: 6px; cursor: pointer;
}
.tasks button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(14, 22, 38, .12); }

.layout {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px;
  padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto;
}
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; padding: 16px; } }

.sidebar { display: flex; flex-direction: column; gap: 16px; }
.panel, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.panel h2 { text-transform: uppercase; font-size: 11px; letter-spacing: 0.06em; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span, .field > label { display: flex; justify-content: space-between; font-weight: 500; }
.field output { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; }
select, input[type="number"] {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; width: 100%;
}
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0; }
.seed-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
.seed-row label { grid-column: 1 / -1; font-weight: 500; }
.hint { margin: 0; color: var(--muted); font-size: 12.5px; }

.btn {
  font: inherit; font-weight: 500; border-radius: 6px; padding: 6px 12px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--surface); white-space: nowrap;
}
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.btn:hover { filter: brightness(1.08); }

.main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card { padding: 14px 16px; }
.card-head { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.card-head h2 { font-size: 15px; }
.canvas-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: 520px; }
.canvas-wrap.short { aspect-ratio: auto; height: 180px; }
canvas { display: block; width: 100%; height: 100%; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12.5px; }
.legend i { display: inline-block; width: 14px; height: 10px; margin-right: 5px; vertical-align: middle; border-radius: 2px; }
.legend i.dot { width: 9px; height: 9px; border-radius: 50%; }
.legend i.ring { width: 9px; height: 9px; border-radius: 50%; background: transparent !important; border: 1.5px solid; }
.legend i.line { height: 3px; }
.legend i.dash { height: 0; border-top: 2px dashed; background: transparent !important; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric .value.small { font-size: 14px; line-height: 1.45; padding: 3px 0; }
.metric .sub { color: var(--muted); font-size: 12px; }
.metric.warn .value { color: var(--class1); }

.two-col { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
.prose h2 { font-size: 16px; margin-bottom: 6px; }
.prose p { margin: 0 0 10px; }
.prose dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; }
.prose dt { color: var(--muted); font-weight: 500; }
.prose dd { margin: 0; }
.formula {
  font-family: "STIX Two Math", "Cambria Math", Georgia, serif; font-size: 15px;
  background: var(--surface-2); border-radius: 6px; padding: 8px 12px; margin: 0 0 12px; overflow-x: auto; white-space: nowrap;
}
.try { background: var(--accent-soft); border-radius: 6px; padding: 8px 12px; margin-top: 12px; }
.try strong { color: var(--accent); }
.fitted {
  margin: 0; font: 12.5px/1.6 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre-wrap;
  background: var(--surface-2); border-radius: 6px; padding: 10px 12px; overflow-x: auto;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tr.current td:first-child { font-weight: 600; color: var(--accent); }
td.best { color: var(--good); font-weight: 600; }
.bar { display: inline-block; height: 6px; background: var(--accent); opacity: 0.35; border-radius: 3px; margin-left: 8px; vertical-align: middle; }
