/* Spatial Flux Network — Prediction Atlas
   Tokens follow the validated reference palette (dataviz skill): categorical slots 1–5 pass
   CVD and normal-vision separation in both modes; light-mode aqua/yellow/magenta sit below
   3:1 on the surface, so every chart carries a legend or direct labels and a table view. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --div-pos: #2a78d6;
  --div-neg: #e34948;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --neutral: #898781;
  --good-ink: #006300;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --div-pos: #3987e5;
    --div-neg: #e66767;
    --good-ink: #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --div-pos: #3987e5;
  --div-neg: #e66767;
  --good-ink: #0ca30c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--accent); text-underline-offset: 2px; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.site-header .inner,
main {
  max-width: 1160px;
  margin: 0 auto;
  padding-inline: 20px;
}

.site-header .inner {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 56px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
}

.brand small { color: var(--muted); font-weight: 500; margin-left: 6px; }

.nav { display: flex; gap: 4px; flex-wrap: wrap; }

.nav a, .theme-toggle {
  color: var(--ink-2);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
  border: 0;
  background: none;
  font-family: inherit;
  cursor: pointer;
}

.nav a:hover, .theme-toggle:hover, .nav a[aria-current="page"] { background: var(--surface-2); color: var(--ink); }

main { padding-block: 28px 64px; }

h1 { font-size: 30px; line-height: 1.2; letter-spacing: -0.02em; margin: 6px 0 10px; }
h2 { font-size: 20px; letter-spacing: -0.01em; margin: 34px 0 12px; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 0 0 10px; }

.lede { color: var(--ink-2); max-width: 760px; font-size: 16px; }
.eyebrow { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--ink-2);
  font-size: 12px;
  background: var(--surface-2);
}

/* verdict badges: status color on the dot, label in ink (never color alone) */
.verdict {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.verdict::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--neutral);
  flex: none;
}

.verdict[data-v="supported"]::before { background: var(--good); }
.verdict[data-v="contradicted"]::before { background: var(--critical); }
.verdict[data-v="not_operationalizable"]::before { background: var(--warning); }
.verdict[data-v="ill_posed"]::before { background: var(--serious); }
.verdict[data-v="inconclusive"]::before { background: var(--warning); border-radius: 2px; }
.verdict[data-v="structural_identity"]::before,
.verdict[data-v="not_evaluable"]::before { background: var(--neutral); border-radius: 2px; }

.verdict .icon { font-size: 12px; color: var(--ink-2); }

/* scorecard */
.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

table.data th, table.data td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: top;
}

table.data th { color: var(--ink-2); font-weight: 600; font-size: 13px; }
table.data td.num { text-align: right; }
table.data tr.planned td { color: var(--muted); }
table.data a.cell-link { text-decoration: none; color: inherit; display: block; }
table.data a.cell-link:hover .verdict { text-decoration: underline; }

/* filter row */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  margin: 18px 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filters label { font-size: 13px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; }

select, input[type="range"] { font-family: inherit; }

select {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 14px;
}

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button {
  font: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border: 0;
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.seg button + button { border-left: 1px solid var(--border); }

/* verdict panel */
.verdict-panel { display: grid; gap: 10px; }
.verdict-panel .reason { color: var(--ink-2); }

/* stat tiles */
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; }
.tile .sub { color: var(--muted); font-size: 12px; }

/* chart cards */
.chart-card { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.chart-card .plot { width: 100%; height: 340px; }
.chart-card .note { color: var(--muted); font-size: 12.5px; }
.chart-card .actions { display: flex; gap: 8px; justify-content: flex-end; }

.link-button {
  font: inherit;
  font-size: 12.5px;
  color: var(--accent);
  background: none;
  border: 0;
  cursor: pointer;
  padding: 2px 4px;
}

.table-view { max-height: 260px; overflow: auto; }
.table-view table.data { font-size: 12.5px; }

/* text blocks */
.statement h3 { color: var(--ink-2); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.statement p { margin-bottom: 0; }

.equation { overflow-x: auto; padding: 6px 0; }
.equation .fallback { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); }
.equation-note { color: var(--muted); font-size: 12.5px; }

/* live figure controls */
.controls { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.control { display: grid; gap: 2px; font-size: 13px; color: var(--ink-2); }
.control output { color: var(--ink); font-variant-numeric: tabular-nums; }
.control input[type="range"] { width: 100%; accent-color: var(--accent); }

.notice {
  border-left: 3px solid var(--warning);
  background: var(--surface);
  padding: 10px 14px;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 14px;
}

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }

footer.build {
  margin-top: 48px;
  color: var(--muted);
  font-size: 12.5px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

@media (max-width: 560px) {
  h1 { font-size: 24px; }
  .chart-card .plot { height: 300px; }
  .brand small { display: none; }
}

/* ------------------------------------------------------------------ cell view */
main.cell-page { max-width: 1360px; }
.small { font-size: 12.5px; }

.cell-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin: 18px 0 14px;
  padding: 10px 14px;
}
.cell-toolbar label { font-size: 13px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; min-width: 0; max-width: 100%; }
.cell-toolbar select { min-width: 0; max-width: 100%; flex: 1 1 auto; text-overflow: ellipsis; }
.cell-toolbar-sep { width: 1px; align-self: stretch; background: var(--border); }
.cell-clock { font-variant-numeric: tabular-nums; min-width: 9.5em; font-size: 14px; }
.cell-clock output { font-weight: 600; }

.cell-btn {
  font: inherit;
  font-size: 13px;
  padding: 5px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}
.cell-btn:hover { border-color: var(--axis); }
.cell-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 5.2em; font-weight: 600; }

.cell-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 16px;
  align-items: start;
}
@media (max-width: 1080px) { .cell-layout { grid-template-columns: minmax(0, 1fr); } }

.cell-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1000 / 640;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--page);
}
.cell-layer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
canvas.cell-layer { pointer-events: none; }
#layer-base { pointer-events: none; }
.cell-status {
  position: absolute;
  left: 12px;
  bottom: 10px;
  margin: 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--critical);
  font-size: 13px;
}

/* compartments */
.cm-outside { fill: var(--page); }
.cm-cell { fill: var(--surface); stroke: var(--axis); stroke-width: 5; }
.cm-nucleus { fill: color-mix(in srgb, var(--surface-2) 55%, transparent); stroke: var(--axis); stroke-width: 3; stroke-dasharray: 22 5; }
.cm-nucleolus { fill: color-mix(in srgb, var(--series-5) 13%, var(--surface)); stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 2 3; }
.cm-lysosome { fill: color-mix(in srgb, var(--series-2) 10%, var(--surface)); stroke: var(--axis); stroke-width: 4; }
.cm-mito { fill: color-mix(in srgb, var(--series-1) 9%, var(--surface)); stroke: var(--axis); stroke-width: 4; }
.cm-cristae { fill: none; stroke: color-mix(in srgb, var(--axis) 70%, transparent); stroke-width: 2; stroke-linejoin: round; }
.cm-label {
  fill: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 4px;
  stroke-linejoin: round;
}
.cm-sublabel { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.muted-label { fill: var(--muted); font-weight: 500; }

/* arrows, reactions, regulation */
#layer-arrows .hit-comp { fill: transparent; stroke: none; cursor: pointer; outline: none; }
#layer-arrows .hit-comp:focus-visible { stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 4; }
.strand { cursor: pointer; outline: none; }
.strand .line { fill: none; stroke-linecap: round; opacity: 0.8; }
.strand .halo { fill: none; stroke: var(--ink); stroke-linecap: round; opacity: 0; }
.strand .hit { fill: none; stroke: transparent; stroke-width: 22; stroke-linecap: round; }
.strand .head { opacity: 0.92; }
.strand:hover .halo, .strand:focus-visible .halo { opacity: 0.18; }
.strand.selected .halo { opacity: 0.32; }
.strand.off .line { stroke-dasharray: 2 5; opacity: 0.5; }
.strand.off .head { opacity: 0.25; }
.strand.dim { opacity: 0.25; }
#layer-arrows.has-selection .strand:not(.selected) { opacity: 0.55; }
#layer-arrows.has-selection .strand.dim:not(.selected) { opacity: 0.18; }

.glyph { cursor: pointer; outline: none; }
.glyph rect { fill: var(--surface); stroke: var(--ink-2); stroke-width: 1.3; }
.glyph text { fill: var(--ink); font-size: 11.5px; font-weight: 600; font-family: var(--font); pointer-events: none; }
.glyph:hover rect, .glyph:focus-visible rect { stroke: var(--accent); stroke-width: 2; }
.glyph.selected rect { stroke: var(--accent); stroke-width: 2.6; }
.glyph.gate rect { fill: var(--surface-2); stroke: var(--ink); stroke-width: 1.6; }

.arrow-label {
  fill: var(--ink-2);
  font-size: 11.5px;
  font-family: var(--font);
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 4px;
  stroke-linejoin: round;
  pointer-events: none;
}
.sink { fill: var(--surface); stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 2 2; }
.sink-text { fill: var(--muted); font-size: 10px; font-family: var(--font); pointer-events: none; }

.reg-edge path { fill: none; stroke: var(--ink-2); stroke-width: 1.3; stroke-dasharray: 5 4; opacity: 0.55; }
.reg-edge .tip { fill: var(--ink-2); opacity: 0.7; }
.reg-edge .bar { stroke: var(--ink-2); stroke-width: 2.4; opacity: 0.75; }
.reg-edge .reg-sign {
  fill: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font);
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 4px;
}
.reg-layer { pointer-events: none; }

/* legend */
.cell-legend { display: grid; gap: 8px; margin: 10px 2px 14px; }
.cell-species { display: flex; flex-wrap: wrap; gap: 6px; }
.species-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.species-toggle[aria-pressed="false"] { color: var(--muted); background: var(--surface-2); }
.species-toggle[aria-pressed="false"] .swatch { opacity: 0.3; }
.cell-legend-controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 13px; }
.cell-check { display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2); }
.cell-note { color: var(--muted); font-size: 12.5px; margin: 0; max-width: 820px; }

.swatch {
  --swatch: var(--neutral);
  display: inline-block;
  width: 10px;
  height: 10px;
  flex: none;
  background: var(--swatch);
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: -1px;
}
.swatch[data-shape="square"] { border-radius: 1px; }
.swatch[data-shape="diamond"] { border-radius: 1px; transform: rotate(45deg) scale(0.85); }
.swatch[data-shape="triangle"] { border-radius: 0; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.swatch[data-shape="ring"] { background: transparent; border: 3px solid var(--swatch); }

/* readouts */
.cell-readouts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 168px), 1fr)); }
.cell-tile { padding: 10px 12px; }
.cell-tile .value { font-size: 21px; }
.spark { display: block; width: 100%; height: 34px; margin-top: 4px; }
.spark.wide { height: 44px; }

/* side panels */
.cell-side { display: grid; gap: 16px; }
.cell-panel h2 { margin: 2px 0 8px; font-size: 17px; }
.cell-panel h3 { margin: 16px 0 6px; font-size: 13px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.05em; }
.cell-presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 12px; }
.cell-controls { display: grid; gap: 12px; }
.cell-controls .control output { font-weight: 600; }
.cell-events { margin-top: 12px; border-top: 1px solid var(--grid); padding-top: 8px; }
.cell-event-list { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); }
.cell-event-list .mono { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.cell-flux, .cell-state { padding: 8px 0; border-bottom: 1px solid var(--grid); }
.cell-flux .label, .cell-state .label { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.cell-flux .value, .cell-state .value { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.cell-flux .sub, .cell-state .sub { color: var(--muted); font-size: 12px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 4px 0; }
.kv .k { color: var(--ink-2); }
.stoich { margin: 0; padding-left: 0; list-style: none; font-size: 13px; display: grid; gap: 3px; }
.link-list { margin: 0; padding-left: 16px; }
.param-list { display: grid; gap: 10px; }
.param { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.param.edited { border-color: var(--accent); }
.param-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.param-head .name { font-weight: 600; color: var(--ink); }
.param-head output { color: var(--ink-2); margin-right: auto; }
.param-desc { color: var(--ink-2); margin: 2px 0 4px; }
.param input[type="range"] { width: 100%; accent-color: var(--accent); }
.param-meta { overflow-wrap: anywhere; }
.cell-panel .equation .katex { font-size: 1.18em; }
