/* Distribution Lab — shared styles.
   Colour roles follow the dataviz reference palette (light + dark, both selected). */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --axis-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --series-1: #2a78d6; /* simulated / empirical */
  --series-2: #eb6834; /* theoretical */
  --series-3: #1baf7a; /* second fitted model */
  --critical: #d03b3b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #a3a197;
    --axis-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --critical: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #242422;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #a3a197;
  --axis-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --critical: #e66767;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.55 var(--font);
}
a { color: var(--accent-ink); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.8em; }
code { font-family: var(--mono); font-size: 0.92em; }

/* ---------- site chrome ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.site-header .inner {
  max-width: 1240px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 20px; height: 56px;
}
.brand { font-weight: 650; color: var(--text-primary); text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
.nav a {
  color: var(--text-secondary); text-decoration: none;
  padding: 6px 12px; border-radius: 8px; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--text-primary); background: var(--surface-2); font-weight: 600; }
.theme-toggle {
  border: 1px solid var(--border); background: transparent; color: var(--text-secondary);
  border-radius: 8px; padding: 5px 10px; cursor: pointer; font: inherit; font-size: 13px;
}

main { max-width: 1240px; margin: 0 auto; padding: 24px 16px 64px; }
.page-intro { max-width: 760px; margin-bottom: 20px; color: var(--text-secondary); }
.page-intro h1 { color: var(--text-primary); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 880px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 0.95rem; font-weight: 600; margin: 0 0 2px; }
.card-sub { color: var(--text-secondary); font-size: 13px; margin: 0 0 10px; }
.stack > * + * { margin-top: 16px; }

/* ---------- controls ---------- */
.controls { position: sticky; top: 72px; }
@media (max-width: 880px) { .controls { position: static; } }
.control-group + .control-group { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.control-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 10px; }
label.field { display: block; margin-bottom: 12px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; }
.field-name { color: var(--text-secondary); }
.field-name b { color: var(--text-primary); font-weight: 600; }
.field-value {
  width: 76px; text-align: right; font: 13px var(--mono); font-variant-numeric: tabular-nums;
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px;
}
select, input[type="number"].plain {
  width: 100%; font: inherit; color: var(--text-primary);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 6px 0 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.btn {
  font: inherit; font-size: 14px; cursor: pointer; border-radius: 8px; padding: 8px 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
}
.btn:hover { border-color: var(--baseline); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: default; }
.hint { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }
.error { color: var(--critical); font-size: 13px; margin-top: 8px; }
.error:empty { display: none; }
.error::before { content: "⚠ "; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis-text { fill: var(--axis-muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .axis-title { fill: var(--text-secondary); font-size: 12px; }
.chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.chart .crosshair { stroke: var(--axis-muted); stroke-width: 1; pointer-events: none; }
.chart .note { fill: var(--text-muted); font-size: 11.5px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--text-secondary); margin: 0 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key-rect { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.key-line { width: 16px; height: 2px; border-radius: 1px; display: inline-block; }
.key-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 8px 10px; font-size: 12.5px; min-width: 140px;
  opacity: 0; transition: opacity 80ms;
}
.tooltip.show { opacity: 1; }
.tooltip .tt-head { color: var(--text-secondary); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; color: var(--text-primary); }
.tooltip .tt-row span.lbl { color: var(--text-secondary); }

/* ---------- tables ---------- */
table.stats { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.stats th, table.stats td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats th { color: var(--text-muted); font-weight: 500; font-size: 12px; }
table.stats td { font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

.formula { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.tex-fallback { font-family: var(--mono); font-size: 13px; color: var(--text-secondary); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid-2 > .card + .card { margin-top: 0; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

.pill { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); }

/* ---------- relationships page ---------- */
.graph-wrap { overflow-x: auto; }
.graph svg { display: block; width: 100%; min-width: 720px; height: auto; }
.graph .node rect { fill: var(--surface-1); stroke: var(--baseline); stroke-width: 1; }
.graph .node.discrete rect { fill: var(--surface-2); }
.graph .node text { fill: var(--text-primary); font-size: 13px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.graph .node { cursor: pointer; }
.graph .node:hover rect, .graph .node:focus rect { stroke: var(--accent); stroke-width: 2; outline: none; }
.graph .node.focus rect { stroke: var(--accent); stroke-width: 2; }
.graph .edge path.vis { fill: none; stroke: var(--axis-muted); stroke-width: 1.5; }
.graph .edge.limit path.vis { stroke-dasharray: 5 4; }
.graph .edge path.hit { fill: none; stroke: transparent; stroke-width: 16; cursor: pointer; }
.graph .edge:hover path.vis, .graph .edge.active path.vis { stroke: var(--accent); stroke-width: 2.5; }
.graph .edge.dim, .graph .node.dim { opacity: 0.22; }
.graph marker path { fill: var(--axis-muted); }
.graph marker.active path { fill: var(--accent); }
.graph-legend { display: flex; flex-wrap: wrap; gap: 18px; font-size: 12.5px; color: var(--text-secondary); margin-top: 8px; }
.graph-legend svg { vertical-align: middle; margin-right: 6px; }

.rel-list { list-style: none; margin: 0; padding: 0; max-height: 620px; overflow-y: auto; }
.rel-list li button {
  width: 100%; text-align: left; font: inherit; font-size: 13.5px; cursor: pointer;
  background: transparent; border: 0; border-radius: 8px; padding: 8px 10px; color: var(--text-primary);
}
.rel-list li button:hover { background: var(--surface-2); }
.rel-list li button[aria-pressed="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.rel-list .kind { display: block; font-size: 11.5px; color: var(--text-muted); font-weight: 400; }
.rel-list li[hidden] { display: none; }

/* ---------- learn page ---------- */
.learn-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 32px; align-items: start; }
@media (max-width: 880px) { .learn-layout { grid-template-columns: minmax(0, 1fr); } .toc { position: static !important; } }
.toc { position: sticky; top: 72px; font-size: 13.5px; max-height: calc(100vh - 90px); overflow-y: auto; }
.toc h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 14px 0 6px; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc a { display: block; padding: 3px 8px; border-radius: 6px; color: var(--text-secondary); text-decoration: none; }
.toc a:hover { background: var(--surface-2); color: var(--text-primary); }
.article { max-width: 860px; }
.article section { scroll-margin-top: 72px; }
.article > section + section { margin-top: 20px; }
.article ul { padding-left: 20px; margin: 0 0 0.8em; }
.article li { margin-bottom: 4px; }
.dist-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; justify-content: space-between; }
.dist-head h2 { margin: 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px 16px; margin: 12px 0; font-size: 13.5px; }
.facts div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; overflow-x: auto; }
.facts .wide { grid-column: 1 / -1; }
.facts .lbl { display: block; font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.callout { border-left: 3px solid var(--accent); background: var(--surface-2); padding: 10px 14px; border-radius: 0 8px 8px 0; margin: 0 0 0.8em; }
table.guide { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.guide th, table.guide td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.guide th { color: var(--text-muted); font-weight: 500; font-size: 12px; }

/* ---------- probability calculator ---------- */
.calc-controls { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 10px 14px; align-items: end; margin-bottom: 10px; }
@media (max-width: 700px) { .calc-controls { grid-template-columns: minmax(0, 1fr); } }
.calc-inputs { display: flex; gap: 10px; }
.calc-input { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.calc-input[hidden] { display: none; }
table.stats td .key-line, table.stats td .key-rect { vertical-align: middle; margin-right: 2px; }

/* ---------- fit page ---------- */
textarea.data {
  width: 100%; min-height: 150px; resize: vertical; font: 12.5px var(--mono);
  color: var(--text-primary); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px;
}
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; margin: 10px 0; color: var(--text-secondary); }
.check input { margin-top: 3px; accent-color: var(--accent); }
.check[hidden] { display: none; }
[hidden] { display: none !important; }
#rank-table td, #rank-table th { white-space: nowrap; }
#rank-table td:nth-child(2), #rank-table th:nth-child(2),
#rank-table td:nth-child(3), #rank-table th:nth-child(3) { text-align: left; }
#rank-table td:nth-child(3) { white-space: normal; min-width: 180px; }
table.stats tr.best td:first-child { font-weight: 600; }
table.stats tr.skipped td { color: var(--text-muted); }
table.stats td.name { white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; padding: 0 7px; border-radius: 999px; background: var(--accent); color: #fff; margin-left: 6px; vertical-align: 1px; }
.note-box { font-size: 13px; color: var(--text-secondary); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin-top: 10px; }
.note-box:empty { display: none; }
.verdict { font-size: 14.5px; margin: 0 0 10px; }

.facts .tile-sub { display: block; font-size: 12px; color: var(--text-muted); margin-top: 2px; }
table.tasks td, table.tasks th { padding: 4px; }
table.tasks .field-value { width: 64px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
