:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #8a8984;
  --border: #e4e3df;
  --neutral: #f0efec;      /* a neuron at zero */
  --pos: #2a78d6;          /* positive activation / weight */
  --pos-max: #104281;      /* strongest activation */
  --neg: #e34948;          /* negative activation / weight */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --tint: #eef4fc;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #8f8e88;
    --border: #33332f;
    --neutral: #383835;
    --pos: #3987e5;
    --pos-max: #b7d3f6;
    --neg: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --tint: #1b2533;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8f8e88;
  --border: #33332f; --neutral: #383835; --pos: #3987e5; --pos-max: #b7d3f6; --neg: #e66767;
  --series-1: #3987e5; --series-2: #d95926; --tint: #1b2533;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hero, main { max-width: 1180px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.hero { padding-top: 40px; padding-bottom: 8px; }
h1 { font-size: clamp(30px, 4.5vw, 46px); line-height: 1.1; letter-spacing: -0.02em; margin: 0 0 12px; }
.lede { font-size: 18px; color: var(--ink-2); max-width: 760px; margin: 0; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 0; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
section[id] { scroll-margin-top: 12px; }
.loading { color: var(--ink-2); font-size: 15px; }
.loading.error { color: var(--neg); font-weight: 600; }
main { padding-bottom: 64px; transition: opacity .3s; }
body:not(.ready) main { opacity: .35; pointer-events: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin: 20px 0;
}
h2 { font-size: 22px; margin: 0 0 12px; display: flex; align-items: center; }
.step {
  display: inline-grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--pos); color: #fff; font-size: 15px; margin-right: 12px;
}
p { margin: 0 0 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.note { font-size: 14px; color: var(--muted); }
.formula { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 15px; }

/* ---- explainer ---- */
.intro { font-size: 17px; max-width: 820px; }
h3 { font-size: 18px; margin: 30px 0 10px; padding-top: 18px; border-top: 1px solid var(--border); }
var { font-style: italic; font-family: Georgia, "Times New Roman", serif; }
.eq { font-family: Georgia, "Times New Roman", serif; font-style: italic; white-space: nowrap; }
.eq.big { font-size: 19px; text-align: center; margin: 14px 0; white-space: normal; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 32px; align-items: start; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 14px; padding: 8px 0; font-size: 15px; color: var(--ink-2); }
.timeline li + li { border-top: 1px dashed var(--border); }
.timeline strong { color: var(--ink); }
.timeline .year { font-weight: 700; color: var(--pos); font-variant-numeric: tabular-nums; }

.parts { padding-left: 20px; }
.parts li { margin-bottom: 6px; }

.lab, .matrix-example { margin: 0; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.lab figcaption, .matrix-example figcaption { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
#neuron-svg { width: 100%; max-width: 420px; display: block; margin: 0 auto; }
#neuron-svg .syn { stroke-linecap: round; }
#neuron-svg .syn.pos { stroke: var(--pos); }
#neuron-svg .syn.neg { stroke: var(--neg); }
#neuron-svg .axon { stroke: var(--muted); stroke-width: 2; }
#neuron-svg .node { stroke: var(--border); stroke-width: 1.5; }
#neuron-svg .node-text { font: 600 12px system-ui, sans-serif; fill: var(--ink); }
#neuron-svg .node-text.on-dark { fill: #fff; }
#neuron-svg .node-sub { font: italic 11px Georgia, serif; fill: var(--ink-2); }
#neuron-svg .w-text { font: 12px system-ui, sans-serif; fill: var(--ink-2); }
#neuron-svg .caption { font: 11px system-ui, sans-serif; fill: var(--muted); }
.lab-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 18px; margin: 10px 0; }
.lab-slider { display: grid; grid-template-columns: 74px minmax(0, 1fr) 34px; align-items: center; gap: 8px; font-size: 13px; }
.lab-slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.lab-slider input { min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; margin: 6px 0; }
.lab-readout { white-space: normal; font-size: 15px; margin: 8px 0 0; line-height: 1.7; }
.slider-field.wide { display: flex; flex-direction: column; align-items: stretch; gap: 4px; margin-top: 8px; }
#loss-canvas { width: 100%; display: block; }

.matmul { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.mat { border-collapse: collapse; border-left: 2px solid var(--ink-2); border-right: 2px solid var(--ink-2); font-variant-numeric: tabular-nums; }
.mat caption { font: italic 15px Georgia, serif; color: var(--ink-2); padding-bottom: 2px; }
.mat td { padding: 3px 8px; text-align: right; font-size: 14px; }
.mat tr.hl td { background: var(--tint); font-weight: 700; }
.op { font-size: 18px; color: var(--ink-2); }
.shapes { margin: 6px 0 8px; padding-left: 20px; font-size: 15px; }

.setup-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 14px 0 10px; max-width: 320px; }
.field label { font-size: 14px; font-weight: 600; }
select, button { font: inherit; color: var(--ink); }
select {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
}
button, a.button {
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
a.button { display: inline-block; text-decoration: none; color: var(--ink); }
button.primary, a.button.primary { background: var(--pos); border-color: var(--pos); color: #fff; min-width: 150px; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--pos); outline-offset: 2px; }
input[type="range"] { accent-color: var(--pos); }

.act-plot { margin: 0; }
.act-plot canvas { width: 100%; display: block; }

.steps {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px;
  padding: 0; margin: 0 0 8px; list-style: none; counter-reset: step;
}
.steps li {
  counter-increment: step; font-size: 14px; color: var(--ink-2);
  border-top: 2px solid var(--border); padding-top: 8px;
}
.steps li::before { content: counter(step) ". "; font-weight: 700; color: var(--pos); }
.steps strong { color: var(--ink); }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin: 18px 0; }
.toolbar.tight { margin: 12px 0 0; }
.slider-field { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.slider-field output { font-weight: 400; color: var(--ink-2); min-width: 9.5em; font-variant-numeric: tabular-nums; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.stat .label { font-size: 13px; color: var(--ink-2); }
.stat .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat .sub { font-size: 12px; color: var(--muted); }

.net-wrap canvas { width: 100%; display: block; }
.sample-bar { display: flex; align-items: center; gap: 12px; margin-top: 12px; font-size: 14px; font-weight: 600; }
.sample-bar input { flex: 1; min-width: 0; }
.sample-info { font-variant-numeric: tabular-nums; margin: 6px 0 4px; min-height: 1.55em; }
.sample-info .ok { color: var(--pos); font-weight: 700; }
.sample-info .bad { color: var(--neg); font-weight: 700; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 13px; color: var(--ink-2); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.ramp { display: inline-block; width: 72px; height: 10px; border-radius: 3px; }
.ramp.pos { background: linear-gradient(90deg, var(--neutral), var(--pos), var(--pos-max)); }
.ramp.neg { background: linear-gradient(90deg, var(--neutral), var(--neg)); }
.line-swatch { display: inline-block; width: 20px; height: 0; border-top: 2px solid; }
.line-swatch.s1 { border-color: var(--series-1); }
.line-swatch.s2 { border-color: var(--series-2); }
.line-swatch.dashed { border-top-style: dashed; }
.line-swatch.neg { border-color: var(--neg); }
.dot-swatch { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.dot-swatch.s2 { background: var(--series-2); }
.boxed { border: 1.5px solid var(--ink); border-radius: 3px; padding: 0 4px; font-size: 12px; color: var(--ink); }

.callout {
  margin: 18px 0; padding: 12px 16px; border-left: 3px solid var(--pos);
  background: var(--tint); border-radius: 0 8px 8px 0; font-size: 15px;
}

.chart { margin: 8px 0 0; }
.chart figcaption { display: flex; flex-wrap: wrap; gap: 6px 24px; align-items: center; margin-bottom: 6px; }
.chart canvas { width: 100%; display: block; }

.draw-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 32px; align-items: start; margin-bottom: 12px; }
#pad {
  width: 280px; max-width: 100%; aspect-ratio: 1; display: block;
  background: #000; border-radius: 10px; touch-action: none; cursor: crosshair;
}
.preview { display: flex; align-items: center; gap: 10px; }
#pad-preview { width: 56px; height: 56px; image-rendering: pixelated; border: 1px solid var(--border); background: #000; flex: none; }
.guess-label { font-size: 14px; color: var(--ink-2); font-weight: 600; }
.guess-digit { font-size: 110px; font-weight: 750; line-height: 1; font-variant-numeric: tabular-nums; }
.guess-conf { font-size: 16px; color: var(--ink-2); }
.warning {
  margin-top: 16px; padding: 10px 14px; border: 1px solid var(--border); border-left: 3px solid var(--series-2);
  border-radius: 0 8px 8px 0; font-size: 14px; max-width: 520px;
}

.warning.alert { border-left-color: var(--neg); max-width: none; margin: 4px 0 16px; }

footer { margin-top: 24px; max-width: 760px; }
footer .further { margin-top: 14px; }
footer .author-link { margin-top: 12px; font-size: 15px; }

/* ---- links + author page ---- */
a { color: var(--pos); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
.back { margin: 0 0 18px; font-size: 15px; }
.author-page main { max-width: 820px; }
.author-page .hero { max-width: 820px; }
.author-page .card p { max-width: 70ch; }
.skills { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 20px; margin: 0; }
.skills dt { font-weight: 600; }
.skills dd { margin: 0; color: var(--ink-2); }
.contact { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.contact li { display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; }
.contact-label { width: 64px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
@media (max-width: 520px) {
  .skills { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .skills dd { margin-bottom: 8px; }
}

.tooltip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; line-height: 1.45; max-width: 270px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .14);
}
.tooltip img { display: block; width: 112px; height: 112px; image-rendering: pixelated; margin: 6px 0 4px; border-radius: 3px; }
.tooltip .muted { font-size: 12px; }
.tooltip .spaced { margin-top: 6px; }

@media (max-width: 820px) {
  .setup-grid, .draw-grid, .two-col { grid-template-columns: minmax(0, 1fr); }
  .lab-grid { grid-template-columns: minmax(0, 1fr); }
  .timeline li { grid-template-columns: 64px minmax(0, 1fr); }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 18px 16px; }
}
