@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap");

:root {
  color-scheme: dark;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  background: #0a0a0a;
  color: #e8e8e8;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --muted: #9a9a9a;
  --faint: #616161;
  --line: #242424;
  --line-strong: #383838;
  --surface: #0f0f0f;
  --surface-2: #151515;
  --positive: #57ec91;
  --negative: #ff6c74;
  --radius: 3px;
  --sidebar: 13.5rem;
  --s1: .25rem;
  --s2: .5rem;
  --s3: .75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2.5rem;
}

* { box-sizing: border-box; }
body { margin: 0; background: #0a0a0a; }
button, input { font: inherit; }
:focus-visible { outline: 1px solid #fff; outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }

/* ---------- Layout + sidebar ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: var(--s5) var(--s4);
  border-right: 1px solid var(--line);
  background: #070707;
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 0 var(--s2) var(--s5);
  color: #fff;
  text-decoration: none;
}
.logo { width: 30px; height: 30px; flex: none; fill: none; stroke: #fff; stroke-width: 1.1; stroke-linejoin: round; }
.cube-hidden { stroke-opacity: .3; }
.cube-top { fill: #fff; fill-opacity: .22; }
.cube-side { fill: #fff; fill-opacity: .1; }
.cube-front { fill: #fff; fill-opacity: .05; }
.cube-glint { stroke-opacity: .55; stroke-linecap: round; }
.brand:hover .cube-front { fill-opacity: .12; }
.brand-text { display: grid; gap: 1px; }
.brand-name { font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; }
.brand small { color: var(--faint); font-size: .7rem; line-height: 1.3; }
.nav-label, .kicker, .caption {
  margin: 0;
  color: var(--faint);
  font-family: var(--mono);
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.nav-label { padding: 0 var(--s2) var(--s2); }
.kicker.live { display: flex; align-items: center; gap: var(--s2); }
.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--positive);
  animation: pulse 1.6s ease-in-out infinite;
}
.paused .pulse { animation: none; background: var(--faint); }
@keyframes pulse { 50% { opacity: .2; } }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-list a {
  display: grid;
  gap: 2px;
  padding: var(--s2);
  border-left: 2px solid transparent;
  color: var(--muted);
  font-size: .9rem;
  text-decoration: none;
}
.nav-list a:hover { color: #fff; background: var(--surface-2); }
.nav-list a[aria-current="page"] { color: #fff; border-left-color: #fff; background: var(--surface-2); }
.nav-list small { color: var(--faint); font-size: .75rem; }

main { min-width: 0; width: 100%; padding: 0 var(--s6) var(--s6); }

/* ---------- Page header ---------- */
.page-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(24rem, 46rem);
  align-items: end;
  justify-content: space-between;
  gap: var(--s6);
  padding: var(--s6) 0 var(--s5);
}
.tagline { max-width: 34rem; margin: var(--s3) 0 0; color: #cfcfcf; font-size: 1.05rem; line-height: 1.55; }

/* ---------- Charts ---------- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
.metrics-note, .specimen-note { margin: 0; color: var(--muted); font-size: .8rem; }
.metrics-note { grid-column: 1 / -1; }
.charts figure { margin: 0; min-width: 0; padding-top: var(--s3); border-top: 1px solid currentColor; }
.loss-metric { color: var(--negative); }
.accuracy-metric { color: var(--positive); }
.charts figcaption { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s2); }
.charts figcaption span { color: var(--muted); font-size: .8rem; }
.charts output { font-family: var(--mono); font-size: clamp(1.2rem, 2.2vw, 1.6rem); font-weight: 500; line-height: 1; }
.charts svg { margin-top: var(--s3); }
.charts text { font-family: var(--mono); font-size: 13px; fill: var(--faint); }
.chart-grid line { stroke: var(--line); }
.metric-line { stroke: currentColor; stroke-width: 1.75; fill: none; stroke-linejoin: round; }
.metric-point { fill: currentColor; }
output, .probability { font-variant-numeric: tabular-nums; }

/* ---------- Panel + toolbar ---------- */
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2);
  border-bottom: 1px solid var(--line);
}
.tool {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  color: #ddd;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.tool svg { width: 14px; height: 14px; fill: currentColor; }
.tool.text { display: inline-flex; align-items: center; gap: .4rem; padding: 0 var(--s3); font-size: .85rem; font-weight: 500; white-space: nowrap; }
.tool:hover:not(:disabled), .tool.active { border-color: #777; color: #fff; background: var(--surface-2); }
.tool:disabled { opacity: .35; cursor: default; }
.progress { display: grid; gap: 6px; flex: 1; min-width: 0; padding-inline: var(--s3); }
#status { font-family: var(--mono); font-size: .78rem; color: #ddd; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track { display: block; height: 2px; background: var(--line-strong); }
#progress-fill { display: block; height: 100%; width: 0; background: #fff; transition: width .3s; }

.builder {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  gap: var(--s4);
  padding: var(--s4);
  border-bottom: 1px solid var(--line);
  background: #0c0c0c;
}
.builder label { display: grid; gap: var(--s1); color: var(--muted); font-size: .8rem; }
.builder input {
  width: 100%;
  height: 34px;
  padding: 0 .6rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #070707;
  color: #fff;
  font-family: var(--mono);
  font-size: .85rem;
}
.builder input:focus { border-color: #888; outline: none; }
.builder small { color: var(--faint); font-size: .72rem; }
.apply {
  height: 34px;
  margin-top: 1.3rem;
  padding: 0 var(--s4);
  border: 1px solid #fff;
  border-radius: var(--radius);
  background: #fff;
  color: #000;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}
.apply:hover { background: #d8d8d8; }

/* ---------- Stage ---------- */
.visual {
  display: grid;
  grid-template-columns: 8rem minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  gap: 0 var(--s5);
  align-items: center;
  padding: var(--s5);
}
#zoom-back {
  grid-column: 1;
  grid-row: 1;
  align-self: start;
  justify-self: center;
  justify-content: center;
  width: 100%;
  max-width: 7.5rem;
}
.specimen { grid-column: 1; grid-row: 2; }
.viewport { grid-column: 2; grid-row: 1 / span 2; }
.specimen { display: grid; justify-items: center; text-align: center; gap: var(--s2); }
.specimen-note { max-width: 16rem; }
canvas {
  width: 100%;
  max-width: 7.5rem;
  height: auto;
  margin-block: var(--s1);
  background: #000;
  border: 1px solid var(--line-strong);
  image-rendering: pixelated;
}
#label { font-size: .9rem; font-weight: 600; }
#prediction { color: var(--muted); font-size: .8rem; }
.viewport { min-width: 0; }
.diagram { overflow-x: auto; }
.diagram.zooming { overflow: hidden; }
#network { will-change: transform, opacity; }
svg { display: block; width: 100%; height: auto; }
#network, #step-network { max-height: min(46vw, 40rem); }
.scroll-hint { display: none; }

.panel-footer {
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
}
.legend { display: flex; gap: var(--s4); flex-wrap: wrap; }
.legend > span { display: inline-flex; align-items: center; gap: .4rem; }
.positive-key::before, .negative-key::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.positive-key { color: var(--positive); }
.negative-key { color: var(--negative); }

/* ---------- Network diagram ---------- */
.column-captions text { fill: var(--faint); font-family: var(--mono); font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.column-captions path { stroke: #2c2c2c; fill: none; }
.image-inputs { pointer-events: none; }
.image-inputs path { fill: none; stroke: #4a4a4a; stroke-dasharray: 3 4; }
.wire { stroke: #8a8a8a; stroke-opacity: .22; }
.signal, .halo { pointer-events: none; }
.signal.positive { stroke: var(--positive); }
.signal.negative { stroke: var(--negative); }
.halo.positive { fill: var(--positive); }
.halo.negative { fill: var(--negative); }
.node-track { fill: #050505; stroke: #d6d6d6; stroke-width: 1.5; }
.node.positive { fill: var(--positive); }
.node.negative { fill: var(--negative); }
.node.output, .node.winner { fill: #fff; }
.node.winner { stroke: #fff; stroke-width: 2; }
.output-label, .probability { fill: var(--muted); font-size: 16px; }
.output-label { font-weight: 700; }
text.winner { fill: #fff; font-weight: 750; }
.neuron { cursor: zoom-in; outline: none; }
.neuron .hit { fill: transparent; }
.neuron .node, .neuron .node-track {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform .18s cubic-bezier(.2, .8, .2, 1);
}
.neuron:is(:hover, :focus-visible) .node,
.neuron:is(:hover, :focus-visible) .node-track { transform: scale(1.35); }
.neuron:is(:hover, :focus-visible) .node-track { stroke: #fff; stroke-width: 2.5; }
.neuron:focus-visible .hit { stroke: #fff; stroke-dasharray: 3 3; }

/* ---------- Zoomed neuron ---------- */
#zoom-view { display: grid; gap: var(--s5); will-change: transform, opacity; }
.zoom-header { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.zoom-heading { display: grid; gap: var(--s1); margin-right: auto; }
.zoom-heading h2 { font-size: clamp(1.35rem, 2.6vw, 1.75rem); font-weight: 600; letter-spacing: -.02em; outline: none; }
.zoom-nav { display: flex; align-items: center; gap: var(--s2); }
#minimap { width: auto; height: 3.25rem; aspect-ratio: var(--ratio, 1); }
.mini { cursor: pointer; stroke: #555; stroke-width: .6; transition: r .15s; }
.mini.positive { fill: var(--positive); }
.mini.negative { fill: var(--negative); }
.mini.output { fill: #fff; }
.mini:hover { stroke: #fff; }
.mini.current { stroke: #fff; stroke-width: 1.2; fill-opacity: 1; }

#neuron-zoom {
  display: grid;
  grid-template-columns: minmax(15rem, 1.3fr) 2.5rem minmax(13rem, 1.1fr) 2.5rem minmax(8rem, .7fr);
  align-items: center;
}
.step-label {
  display: flex; align-items: center; gap: var(--s2);
  margin: 0 0 var(--s3);
  color: var(--muted);
  font-size: .8rem;
  font-weight: 550;
}
.step-label span {
  display: grid; place-items: center;
  width: 1.4rem; height: 1.4rem;
  border: 1px solid #444; border-radius: var(--radius);
  color: #fff; font-family: var(--mono); font-size: .7rem;
}
.zoom-inputs ul { display: grid; gap: var(--s1); list-style: none; padding: 0; margin: 0; }
.zoom-inputs li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .3rem var(--s3);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0a0a0a;
  font-size: .8rem;
}
.term-source { color: var(--muted); }
.zoom-inputs code { font-family: var(--mono); font-size: .78rem; font-variant-numeric: tabular-nums; }
.zoom-inputs li > code:first-of-type { text-align: right; color: #ddd; }
.term-bar { position: relative; height: 4px; border-radius: 2px; background: #1f1f1f; overflow: hidden; }
.term-bar::after {
  content: ""; position: absolute; inset: 0 auto 0 0;
  width: calc(var(--size) * 100%);
  border-radius: inherit;
  background: currentColor;
}
.zoom-inputs li.positive { color: var(--positive); }
.zoom-inputs li.negative { color: var(--negative); }
.term-product { text-align: right; font-weight: 650; }
.more { margin: var(--s2) 0 0; color: var(--faint); font-size: .8rem; }

.zoom-connector {
  position: relative;
  height: 1px;
  background: #555;
  align-self: center;
  margin-top: 1.6rem;
}
.zoom-connector::after {
  content: ""; position: absolute; right: 0; top: -3px;
  border: 3.5px solid transparent; border-left: 6px solid #555; border-right: 0;
}
.zoom-core { display: grid; justify-items: center; }
.zoom-neuron {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: var(--s2);
  width: 100%;
  max-width: 17rem;
  aspect-ratio: 1;
  padding: var(--s5);
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-family: var(--mono);
  text-align: center;
  background: #0a0a0a;
}
.neuron-sum {
  display: grid;
  grid-template-columns: auto auto;
  gap: .15rem var(--s3);
  margin: 0;
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}
.neuron-sum dt { color: var(--muted); text-align: left; }
.neuron-sum dd { margin: 0; color: #ddd; text-align: right; }
.neuron-sum dt:nth-last-of-type(1), .neuron-sum dd:last-of-type { color: #fff; font-weight: 650; }
.neuron-rule { width: 60%; height: 1px; background: color-mix(in srgb, currentColor 45%, transparent); }
.neuron-fn { color: var(--muted); font-size: .78rem; }
.zoom-neuron strong { font-size: clamp(1.5rem, 3vw, 2.1rem); font-weight: 500; line-height: 1; color: currentColor; }
.zoom-neuron.positive, .zoom-output.positive { color: var(--positive); }
.zoom-neuron.negative, .zoom-output.negative { color: var(--negative); }
.zoom-neuron.output, .zoom-output.output { color: #fff; }
.zoom-output { display: grid; gap: var(--s2); }
.zoom-output .step-label { margin-bottom: 0; }
.zoom-output > span { color: var(--muted); font-size: .9rem; line-height: 1.45; }

#inspector { display: grid; gap: var(--s4); padding-top: var(--s5); border-top: 1px solid var(--line); }
.equations { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
.equations div { padding: var(--s4); border: 1px solid var(--line); border-radius: var(--radius); background: #0a0a0a; min-width: 0; }
.equations h3 { color: var(--muted); font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.equations p { margin: var(--s2) 0 0; font-family: var(--mono); font-size: .9rem; overflow-wrap: anywhere; }
.equations .formula { color: var(--muted); }
.equations b { color: #fff; }
.input-explanation { margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.5; }
#inspector summary { cursor: pointer; color: var(--muted); font-size: .85rem; padding-block: var(--s2); }
#inspector summary:hover { color: #fff; }
.term-table { max-height: 20rem; overflow: auto; margin-top: var(--s2); border: 1px solid var(--line); border-radius: var(--radius); }
.term-table table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; text-align: right; font-size: .82rem; }
.term-table th, .term-table td { padding: .5rem .7rem; border-bottom: 1px solid #1d1d1d; }
.term-table th:first-child { text-align: left; color: var(--muted); font-weight: 450; }
.term-table thead { position: sticky; top: 0; background: var(--surface-2); }
.term-table thead th { color: #fff; font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 64rem) {
  #neuron-zoom { grid-template-columns: 1fr; justify-items: stretch; gap: var(--s2); }
  .zoom-connector { width: 1px; height: 1.5rem; margin: 0 auto; }
  .zoom-connector::after { right: -3px; top: auto; bottom: 0; border: 3.5px solid transparent; border-top: 6px solid #555; border-bottom: 0; }
  .zoom-neuron { width: min(75vw, 15rem); }
  .zoom-output { justify-items: center; text-align: center; }
  main { padding-inline: var(--s5); }
}

@media (max-width: 56rem) {
  .page-header { grid-template-columns: 1fr; gap: var(--s5); padding-top: var(--s5); }
}

@media (max-width: 48rem) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    display: flex;
    align-items: center;
    gap: var(--s4);
    padding: var(--s3) var(--s4);
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }
  .brand { padding: 0; flex: none; }
  .brand small { display: none; }
  .nav-label, .nav-list small { display: none; }
  .nav-list { display: flex; }
  .nav-list a { border-left: 0; border-bottom: 2px solid transparent; padding: var(--s1) var(--s2); white-space: nowrap; }
  .nav-list a[aria-current="page"] { border-bottom-color: #fff; background: none; }
  main { padding: 0 var(--s4) var(--s5); }
}

@media (max-width: 44rem) {
  .charts { gap: var(--s3); }
  .charts text { font-size: 18px; }
  .visual { grid-template-columns: 1fr; grid-template-rows: none; padding: var(--s4); gap: var(--s4); }
  .specimen { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: var(--s2) var(--s3); }
  .specimen .caption { display: none; }
  .specimen canvas { width: 3.5rem; order: -1; margin: 0; }
  #network { min-width: 34rem; max-height: none; }
  .scroll-hint { display: block; color: var(--faint); font-size: .8rem; margin: 0 var(--s4) var(--s3); }
  .visual:has(#zoom-view:not([hidden])) + .scroll-hint { display: none; }
  .equations { grid-template-columns: 1fr; }
  .zoom-header { gap: var(--s2); }
  .zoom-heading { order: -1; flex-basis: 100%; }
  #zoom-back, .specimen, .viewport { grid-column: auto; grid-row: auto; }
  #zoom-back { justify-self: start; width: auto; max-width: none; }
  .zoom-nav { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .neuron .node, .neuron .node-track, #progress-fill { transition: none; }
  .pulse { animation: none; }
}

/* ---------- One training step ---------- */
#training-update {
  display: grid;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
  background: #0c0c0c;
}
.ts-header { display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: var(--s3); }
.ts-title { display: grid; gap: var(--s2); }
#update-title { outline: none; }
.ts-stages { display: flex; flex-wrap: wrap; gap: 0; list-style: none; margin: 0; padding: 0; }
.ts-stages li + li::before { content: ""; display: inline-block; width: 1.25rem; height: 1px; margin: 0 .25rem; vertical-align: middle; background: var(--line-strong); }
.ts-stages button {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .3rem .2rem;
  border: 0;
  background: none;
  color: var(--faint);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
}
.ts-stages button span {
  display: grid; place-items: center;
  width: 1.4rem; height: 1.4rem;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-family: var(--mono);
  font-size: .7rem;
}
.ts-stages button:hover { color: #fff; }
.ts-stages button.done { color: var(--muted); }
.ts-stages button.done span { border-color: #666; }
.ts-stages button[aria-current="step"] { color: #fff; }
.ts-stages button[aria-current="step"] span { background: #fff; border-color: #fff; color: #000; }
.ts-controls { display: flex; gap: var(--s2); }
.ts-controls [data-play] { min-width: 5rem; }
.ts-caption { margin: 0; max-width: 62rem; color: #cfcfcf; font-size: .95rem; line-height: 1.55; min-height: 3.1em; }
.ts-caption b { color: #fff; font-weight: 600; }
.ts-caption { font-size: 1.02rem; font-weight: 500; color: #fff; min-height: 0; }
.ts-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem); gap: var(--s5); align-items: start; }
.ts-explain { max-width: 46rem; }
.ts-explain p { margin: 0 0 var(--s2); color: var(--muted); font-size: .9rem; line-height: 1.6; }
.ts-explain b { color: #fff; font-weight: 600; }
.ts-explain code { font-family: var(--mono); font-size: .82rem; color: #ddd; white-space: nowrap; }
.ts-eq {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s2) var(--s4);
  margin: var(--s2) 0 var(--s3);
  padding: var(--s3) var(--s4);
  border-left: 2px solid var(--line-strong);
  background: #080808;
}
.ts-eq .math {
  font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", Georgia, serif;
  font-size: 1.15rem;
  color: #f0f0f0;
  line-height: 1.2;
  white-space: nowrap;
  overflow-x: auto;
}
.ts-eq .math b { font-weight: 700; color: #fff; }
.ts-eq sub, .ts-eq sup { font-size: .68em; line-height: 0; }
.eq-note { color: var(--faint); font-size: .78rem; font-family: var(--mono); }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 .12em; font-size: .9em; }
.frac > span { padding: 0 .15em; line-height: 1.15; }
.frac > span:first-child { border-bottom: 1px solid currentColor; }
.ts-hint { color: var(--faint) !important; font-size: .82rem !important; }
.ts-steps { list-style: none; margin: var(--s2) 0; padding: 0; display: grid; gap: 2px; counter-reset: step; }
.ts-steps li {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  align-items: baseline;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  background: #0c0c0c;
  counter-increment: step;
}
.ts-steps li::before { content: counter(step); color: var(--faint); font-family: var(--mono); font-size: .75rem; }
.ts-steps li span { color: var(--muted); font-size: .84rem; }
.ts-steps code { font-family: var(--mono); font-size: .84rem; color: #ddd; text-align: right; }
.ts-steps li:last-child span { color: #fff; }
.ts-card .ts-eq { margin: var(--s2) 0 0; }
.ts-card > p { margin: 0 0 var(--s2); }
.fig-axis.wrong { fill: var(--negative); }
.fig-row.right .fig-value { fill: #fff; font-weight: 600; }
.ts-figure { margin: 0; padding: var(--s2); border: 1px solid var(--line); border-radius: var(--radius); background: #080808; }
.ts-figure svg { animation: bp-in .4s ease-out both; }
.fig-title { fill: var(--muted); font-family: var(--mono); font-size: 11px; }
.fig-axis { fill: var(--faint); font-family: var(--mono); font-size: 10px; }
.fig-axis.right { fill: var(--positive); font-weight: 600; }
.fig-value { fill: #ddd; font-family: var(--mono); font-size: 10px; }
.fig-rule { stroke: var(--line-strong); }
.fig-bar { fill: #d8d8d8; fill-opacity: .8; }
.fig-bar.right { fill: var(--positive); fill-opacity: 1; }
.fig-curve { fill: none; stroke: var(--negative); stroke-width: 1.75; }
.fig-drop { stroke: #666; stroke-dasharray: 2 3; }
.fig-point { fill: #fff; }
.fig-point.before { fill: var(--negative); }
.fig-point.after { fill: var(--positive); }
.fig-grad.positive { fill: var(--positive); }
.fig-grad.negative { fill: var(--negative); }
.gradient-label { font-size: 13px; }
.ts-card { padding: var(--s3) var(--s4); border: 1px solid var(--line); border-radius: var(--radius); background: #080808; }
.ts-card h3 { font-size: .95rem; font-weight: 600; margin-bottom: var(--s2); }
.ts-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
.ts-card p { margin: var(--s1) 0; color: var(--muted); font-size: .82rem; }
.ts-card code { display: block; margin-top: var(--s1); font-family: var(--mono); font-size: .82rem; color: #ddd; overflow-wrap: anywhere; }
.ts-card b { color: #fff; }
.ts-math summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.ts-math summary:hover { color: #fff; }
.ts-math p { color: var(--faint); font-size: .8rem; margin: var(--s2) 0 0; }

.ts-substeps { display: flex; flex-wrap: wrap; gap: var(--s1); list-style: none; margin: 0; padding: 0 0 0 1.9rem; }
.ts-substeps button {
  padding: .2rem .55rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: none;
  color: var(--faint);
  font-family: var(--mono);
  font-size: .74rem;
  cursor: pointer;
}
.ts-substeps button:hover { color: #fff; border-color: #777; }
.ts-substeps button.done { color: var(--muted); }
.ts-substeps button[aria-current="step"] { color: #000; background: #fff; border-color: #fff; }
.ts-backprop { margin: 0 0 var(--s3); padding: var(--s2) var(--s3) var(--s2) 2rem; border: 1px solid var(--line); border-radius: var(--radius); font-size: .84rem; color: var(--faint); }
.ts-backprop li { padding: .1rem 0; }
.ts-backprop li.done { color: var(--muted); }
.ts-backprop li.done::marker { content: "✓  "; color: var(--positive); }
.ts-backprop li.current { color: #fff; }
.ts-backprop li.current::marker { color: #fff; }
.ts-backprop b { font-weight: 600; }
.ts-howto { margin: 0 0 var(--s2); padding-left: 1.3rem; color: var(--muted); font-size: .9rem; line-height: 1.6; }
.ts-howto b { color: #fff; font-weight: 600; }
.ts-terms { max-height: 15rem; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.ts-terms table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .78rem; font-variant-numeric: tabular-nums; }
.ts-terms th, .ts-terms td { padding: .3rem .6rem; text-align: right; border-bottom: 1px solid #1b1b1b; white-space: nowrap; }
.ts-terms th:first-child { text-align: left; color: var(--muted); font-weight: 400; }
.ts-terms thead th { position: sticky; top: 0; background: var(--surface-2); color: var(--faint); font-weight: 500; }
.ts-terms tfoot th, .ts-terms tfoot td { color: #fff; font-weight: 600; border-bottom: 0; background: #101010; }
.ts-card p b { color: #fff; font-weight: 600; }
.ts-math-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: var(--s3); margin-top: var(--s3); }
.ts-math-row { padding: var(--s3); border: 1px solid var(--line); border-radius: var(--radius); background: #080808; }
.ts-math-row h4 { margin: 0; color: var(--muted); font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.ts-math-row .ts-eq { margin: var(--s2) 0; padding: var(--s2) 0; border-left: 0; background: none; }
.ts-math-row p { margin: 0; color: var(--muted) !important; font-size: .84rem !important; line-height: 1.5; }

/* Step diagram */
.bp-heading { fill: var(--faint); font-family: var(--mono); font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.bp-wire { stroke: #8a8a8a; stroke-opacity: .1; stroke-width: .6; }
.bp-lit, .bp-pulse { fill: none; pointer-events: none; }
.bp-lit.positive, .bp-pulse.positive { stroke: var(--positive); }
.bp-lit.negative, .bp-pulse.negative { stroke: var(--negative); }
#step-network[data-stage="error"] .bp-lit { stroke-opacity: .12; }
.bp-pulse {
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-dasharray: 10 200;
  stroke-dashoffset: 10;
  animation: bp-pulse 1.1s ease-in-out both;
  animation-delay: calc(var(--i) * 380ms);
}
@keyframes bp-pulse { from { stroke-dashoffset: 10; } to { stroke-dashoffset: -100; } }
.bp-lit, .bp-node .node, .bp-node .probability {
  animation: bp-in .55s ease-out both;
  animation-delay: calc(var(--i) * 380ms + 200ms);
}
@keyframes bp-in { from { opacity: 0; } }
.node.target { fill: #fff; stroke: var(--positive); stroke-width: 2.5; }
.bp-arrow { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; animation: bp-in .5s .3s both; }
.bp-arrow.positive { stroke: var(--positive); }
.bp-arrow.negative { stroke: var(--negative); }
.bp-target { fill: var(--positive); font-family: var(--mono); font-size: 12px; animation: bp-in .5s .3s both; }
.bp-node { outline: none; }
#step-network[data-stage="backward"] .bp-node, #step-network[data-stage="update"] .bp-node { cursor: pointer; }
.bp-node .hit { fill: transparent; }
.bp-node:focus-visible .node-track, .bp-node:hover .node-track { stroke: #fff; stroke-width: 2.5; }
.bp-band { fill: #fff; fill-opacity: .035; stroke: var(--line-strong); stroke-dasharray: 3 4; }
.bp-lit.done { animation: none; stroke-opacity: .18; }
.bp-node.done .node { animation: none; fill-opacity: .35; }
.bp-node.pending { pointer-events: none; }
.bp-node.pending .node-track { stroke: #444; }
.bp-grad-value { fill: #fff; font-family: var(--mono); font-size: 11px; paint-order: stroke; stroke: #0f0f0f; stroke-width: 4px; animation: bp-in .5s .3s both; }
.bp-ring { fill: none; stroke: #fff; stroke-width: 1.5; stroke-dasharray: 3 3; }
.bp-node:not(.selected) .bp-ring { display: none; }

@media (max-width: 44rem) {
  #training-update { padding: var(--s3) var(--s4); }
  .ts-card-grid, .ts-body { grid-template-columns: 1fr; }
  #step-network { min-width: 34rem; }
}
@media (prefers-reduced-motion: reduce) {
  .bp-pulse { display: none; }
  .bp-lit, .bp-node .node, .bp-node .probability, .bp-arrow, .bp-target, .bp-grad-value { animation: none; }
}
@media (max-width: 48rem) {
  .toolbar { flex-wrap: wrap; }
  .toolbar .progress { min-width: 5rem; }
}
