:root {
  color-scheme: dark;
  --page: #121212;
  --surface: #1a1a19;
  --raised: #212120;
  --ink: #f4f4f2;
  --ink-2: #c3c2b7;
  --muted: #8f8d86;
  --grid: #2c2c2a;
  --axis: #43433f;
  --line: rgba(255, 255, 255, 0.1);
  --accent: #7aa7ff;
  --accent-hover: #9dbfff;
  --on-accent: #0e1a33;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #8a6cf0;
  --good: #0ca30c;
  --good-ink: #3fc13f;
  --critical: #e25555;
  --seq-lo: #1d2430;
  --seq-hi: #86b6ef;
  --neg: #3987e5;
  --pos: #e66767;
  --radius: 10px;
}

* { box-sizing: border-box; }
a, button, input, label, .tnode { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
html { scroll-padding-top: 4rem; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0 0 0.85em; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 76rem;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 3.25rem;
}
.brand {
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brand svg { color: var(--accent); }
.topnav {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
  margin-left: auto;
}
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  white-space: nowrap;
}
.topnav a.active { color: var(--ink); background: var(--raised); box-shadow: inset 0 0 0 1px var(--line); }
.topnav .n { color: var(--muted); margin-right: 0.3rem; font-variant-numeric: tabular-nums; }

main { max-width: 76rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

/* ---------- home ---------- */
.hero { padding: 2.5rem 0 2rem; max-width: 46rem; }
.hero h1 { font-size: clamp(1.9rem, 4.5vw, 2.8rem); letter-spacing: -0.02em; margin-bottom: 1rem; }
.hero p { font-size: 1.1rem; color: var(--ink-2); }
.cards {
  list-style: none;
  padding: 0;
  margin: 0 0 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 1rem;
}
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s;
}
.card:focus-within { border-color: var(--accent); }
.card .kicker { margin-bottom: 0.4rem; }
.card h2 { font-size: 1.15rem; margin-bottom: 0.5rem; }
.card h2 a { color: var(--ink); text-decoration: none; }
.card h2 a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.card p { color: var(--ink-2); font-size: 0.95rem; flex: 1; }
.card .tech { font-size: 0.85rem; color: var(--muted); margin: 0; }
.kicker, .hero .kicker, .card .kicker {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.5rem;
}
.disclaimer {
  border-left: 3px solid var(--axis);
  padding: 0.25rem 0 0.25rem 1rem;
  color: var(--ink-2);
  font-size: 0.92rem;
  max-width: 46rem;
}

/* ---------- chapter ---------- */
.chapter-head { max-width: 50rem; padding: 1rem 0 1.25rem; }
.chapter-head h1 { font-size: clamp(1.6rem, 3.6vw, 2.2rem); letter-spacing: -0.015em; margin-bottom: 0.6rem; }
.chapter-head .lede { color: var(--ink-2); font-size: 1.05rem; margin: 0; }

.stepper {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0.25rem 0 0.9rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
.pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem 0.4rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}
.pill .num {
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--grid);
  color: var(--ink-2);
  font-size: 0.8rem;
  font-weight: 600;
}
.pill.active { color: var(--ink); border-color: var(--accent); }
.pill.active .num { background: var(--accent); color: var(--on-accent); }

.step { padding-top: 1rem; }
.step-grid {
  display: grid;
  grid-template-columns: minmax(0, 20rem) minmax(0, 1fr);
  gap: 1.75rem;
  align-items: start;
}
.prose h2 { font-size: 1.35rem; margin-bottom: 0.8rem; }
.prose { color: var(--ink-2); font-size: 0.97rem; }
.prose strong { color: var(--ink); }
.prose ul { padding-left: 1.1rem; margin: 0 0 0.85em; }
.prose li { margin-bottom: 0.35em; }
.try {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  margin: 1rem 0;
  color: var(--ink);
}
.try b:first-child { display: block; font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.25rem; }
.stage { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem 1rem;
  min-width: 0;
}
.panel-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 0.2rem;
}
.panel-sub { font-size: 0.82rem; color: var(--muted); margin: 0 0 0.6rem; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.row.wide-left { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }

.step-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.step-foot .count { color: var(--muted); font-size: 0.85rem; }

/* ---------- plot ---------- */
.plot { position: relative; width: 100%; user-select: none; -webkit-user-select: none; }
.plot canvas { display: block; }
.tip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 5;
  background: var(--raised);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font-size: 0.8rem;
  line-height: 1.4;
  max-width: 17rem;
  font-variant-numeric: tabular-nums;
}
.tip b { font-weight: 600; }
.tip .k { color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; font-size: 0.82rem; color: var(--ink-2); margin: 0 0 0.5rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.sw.line { width: 14px; height: 2px; border-radius: 1px; }
.sw.sq { border-radius: 2px; }

/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.controls + .controls { margin-top: 0.6rem; }
.btn {
  appearance: none;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--page); flex-wrap: wrap; }
.seg button {
  appearance: none;
  font: inherit;
  font-size: 0.85rem;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.seg button[aria-pressed="true"] { background: var(--raised); color: var(--ink); box-shadow: 0 0 0 1px var(--line); font-weight: 600; }
.ctl { display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.75rem; align-items: baseline; font-size: 0.88rem; color: var(--ink-2); }
.ctl input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); margin: 0.2rem 0 0; }
.ctl output { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.ctls { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0.8rem 1.25rem; }
.check { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.88rem; color: var(--ink-2); cursor: pointer; }
.check input { accent-color: var(--accent); width: 1rem; height: 1rem; }

/* ---------- readouts ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: 0.6rem; }
.stat { background: var(--page); border-radius: 8px; padding: 0.5rem 0.7rem; min-width: 0; }
.stage > .stats .stat { background: var(--surface); border: 1px solid var(--line); }
.stat-label { display: block; font-size: 0.76rem; color: var(--muted); }
.stat-value { display: block; font-size: 1.25rem; font-weight: 600; color: var(--ink); }
.stat-note { display: block; font-size: 0.75rem; color: var(--muted); }
.formula {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  background: var(--page);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  color: var(--ink);
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  min-height: 3.6rem;
}
.callout { font-size: 0.88rem; color: var(--ink-2); margin: 0.6rem 0 0; }
.good-text { color: var(--good-ink); font-weight: 600; }
.bad-text { color: var(--critical); font-weight: 600; }

table.data { width: 100%; border-collapse: collapse; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: right; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--line); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { font-weight: 600; color: var(--muted); font-size: 0.78rem; }

/* 2x2 / 3x3 confusion matrix */
.cm { display: grid; gap: 2px; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.cm .h { color: var(--muted); font-size: 0.74rem; display: flex; align-items: center; justify-content: center; text-align: center; padding: 0.2rem; }
.cm .h.rowh { justify-content: flex-end; text-align: right; }
.cm .c { border-radius: 6px; padding: 0.45rem 0.3rem; text-align: center; background: var(--page); color: var(--ink); }
.cm .c b { display: block; font-size: 1.15rem; }
.cm .c small { color: var(--ink-2); font-size: 0.72rem; }

/* tree diagram */
.tree-wrap { overflow-x: auto; }
.tree-wrap svg { display: block; margin: 0 auto; }
.tnode { cursor: pointer; }
.tnode rect.box { fill: var(--page); stroke: var(--line); stroke-width: 1; }
.tnode.sel rect.box { stroke: var(--accent); stroke-width: 2; }
.tnode.path rect.box { stroke: var(--ink); stroke-width: 2; }
.tnode text { font-size: 11px; fill: var(--ink-2); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.tnode text.q { fill: var(--ink); font-weight: 600; }
.tedge { stroke: var(--axis); stroke-width: 1.5; fill: none; }
.tedge.path { stroke: var(--ink); stroke-width: 2.5; }
.tlabel { font-size: 10px; fill: var(--muted); }

.rules { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; line-height: 1.6; background: var(--page); border-radius: 8px; padding: 0.6rem 0.75rem; overflow-x: auto; white-space: pre; margin: 0; color: var(--ink-2); }
.rules .hit { color: var(--ink); font-weight: 700; }

/* probability bars */
.pbars { display: grid; gap: 0.5rem; }
.pbar { display: grid; grid-template-columns: 5.5rem 1fr 3.2rem; gap: 0.6rem; align-items: center; font-size: 0.88rem; }
.pbar .track { height: 12px; background: var(--grid); border-radius: 0 4px 4px 0; overflow: hidden; }
.pbar .fill { height: 100%; border-radius: 0 4px 4px 0; transition: width 0.15s; }
.pbar .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.pbar.top .lbl { color: var(--ink); font-weight: 600; }

/* cluster profile cards */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.6rem; }
.profile { background: var(--page); border-radius: 8px; padding: 0.6rem 0.75rem; font-size: 0.84rem; color: var(--ink-2); }
.profile b { color: var(--ink); display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.2rem; }
.profile svg { flex: none; }

.neurons { display: grid; grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); gap: 0.5rem; }
.neurons .plot { background: var(--page); border-radius: 6px; }

/* ---------- responsible use ---------- */
.checklist { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr)); gap: 1rem; }
.checklist li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; color: var(--ink-2); font-size: 0.95rem; }
.checklist h3 { font-size: 1rem; color: var(--ink); margin-bottom: 0.4rem; }
.checklist .where { font-size: 0.84rem; margin: 0.5rem 0 0; }

footer.site {
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

@media (max-width: 980px) {
  .step-grid { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
  .prose { max-width: 42rem; }
}
@media (max-width: 640px) {
  main { padding-top: 1rem; }
  .row, .row.wide-left { grid-template-columns: minmax(0, 1fr); }
  .brand span { display: none; }
  .panel { padding: 0.75rem; }
  .step-foot .count { display: none; }
}
/* Hover styles only where there is real hover; on touch they stick after a tap. */
@media (hover: hover) {
  a:hover { color: var(--accent-hover); }
  .topnav a:hover { color: var(--ink); background: var(--raised); }
  .card:hover { border-color: var(--accent); }
  .pill:hover { color: var(--ink); border-color: var(--axis); }
  .btn:hover { border-color: var(--axis); color: var(--ink); }
  .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
  .btn:disabled:hover { border-color: var(--line); }
  .btn.primary:disabled:hover { background: var(--accent); border-color: var(--accent); }
}
/* Finger-sized targets (about 44px) on touch screens. */
@media (pointer: coarse) {
  .btn { min-height: 2.75rem; padding: 0.55rem 1rem; }
  .seg { padding: 3px; }
  .seg button { min-height: 2.5rem; padding: 0.45rem 0.85rem; }
  .pill { min-height: 2.75rem; padding-right: 0.95rem; }
  .topnav a { display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0 0.8rem; }
  .check { min-height: 2.75rem; }
  .check input { width: 1.35rem; height: 1.35rem; }
  .ctl input[type="range"] { height: 2.25rem; margin: 0; }
  .ctls { gap: 0.6rem 1.25rem; }
  .tip { font-size: 0.85rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
