/* ============ lab-learn — Experiment 01, a network learning live ============
   The hero is a forward pass, live: the data on the left, the network drawn as light
   (learn-gl.js, behind the section) and its answer on the right. The side holds the one big number, the data,
   play, the loss curve and "Tune". Hairlines, mono for metadata, radius 0 (only true circles
   are round). Every colour is a token, so the experiment reads on paper or in the dark;
   nearly all of the data colour is drawn by canvas from the live model. */

.learn {
  --l-btn: 2.25rem;
  --l-micro: 0.6875rem;
  margin-top: clamp(1.25rem, 0.9rem + 1.2vw, 2rem);
  color: var(--ink);
}

.learn__nw { white-space: nowrap; }

.learn var { font-style: normal; text-transform: none; }
.learn sub { font-size: 0.72em; line-height: 0; vertical-align: -0.28em; }

/* shared small label voice */
.learn__k {
  font: 450 var(--fs-label) / 1.4 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.learn__k span { letter-spacing: 0.04em; text-transform: none; }

/* ---------- plate: hero (plane + story) | supporting figure + controls ---------- */

.learn__plate {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: start; /* opening "Tune" grows the side, never the hero */
  border-top: 1px solid var(--ink);
}

.learn__hero {
  display: grid;
  align-content: start;
  gap: 0.85rem;
  min-width: 0;
  margin: 0;
  padding: 1.1rem clamp(1.5rem, 0.8rem + 1.6vw, 2.75rem) 1.1rem 0;
}

.learn__side {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-self: stretch;
  min-width: 0;
  padding: 1.1rem 0 1rem clamp(1.5rem, 0.8rem + 1.6vw, 2.75rem);
  border-left: 1px solid var(--hairline);
}

/* ---------- the data: 300 dots and the boundary learned so far ---------- */

.learn__plane {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border: 1px solid var(--hairline-strong);
  cursor: crosshair;
  touch-action: pan-y;
}
.learn__plane canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.learn__plane:focus-visible { outline-offset: 3px; border-radius: 0; }

/* the model's answer at the probe, as a small label on the plane */
.learn__chip {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  padding: 0.3rem 0.55rem;
  background: var(--surface-1);
  border: 1px solid var(--ink);
  font-size: var(--l-micro);
  letter-spacing: 0.04em;
  text-transform: none;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--d-micro) var(--ease-ui);
}
.learn__chip.is-on { opacity: 1; }

.learn__ask { color: var(--ink-3); }

/* legend swatches */
.sw {
  display: inline-block;
  margin: 0 0.3em 0 0.08em;
  vertical-align: 0.02em;
}
.sw--a,
.sw--b,
.sw--t { width: 0.55em; height: 0.55em; border-radius: 50%; }
.sw--a { background: var(--ink); }
.sw--b { background: var(--signal); }
.sw--t { border: 1.5px solid var(--ink); }
.sw--field {
  width: 1.2em;
  height: 0.8em;
  vertical-align: -0.05em;
  border: 1px solid var(--hairline-strong);
  /* the field's two tints, side by side — data, not decoration */
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--ink) 12%, var(--bg)) 50%,
    color-mix(in srgb, var(--signal) 17%, var(--bg)) 50%);
}
.sw--line { width: 1.2em; height: 0; border-top: 1.6px solid var(--ink); vertical-align: 0.3em; }

.learn__score { display: grid; gap: 0.35rem; padding-bottom: 0.4rem; }
.learn__acc {
  font-size: clamp(3.25rem, 1.6rem + 3.6vw, 5.5rem);
  font-weight: 380;
  font-stretch: 108%;
  line-height: 0.92;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
}
.learn__acc-cap {
  max-width: 30ch;
  font-size: var(--fs-small);
  line-height: 1.45;
  color: var(--ink-2);
}
.learn__detail {
  margin-top: 0.35rem;
  font-size: var(--l-micro);
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--ink-3);
}

/* ---------- the network: columns of neuron maps, wired layer to layer ---------- */

.learn__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
}
.learn__arch {
  font-size: var(--l-micro);
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

.learn__stage {
  position: relative;
  height: clamp(21rem, 52vh, 28.5rem);
}
/* rings on the data, values at the inputs (and, without WebGL, the whole network) */
.learn__edges { position: absolute; left: 0; top: 0; z-index: 3; width: 100%; height: 100%; pointer-events: none; }

/* one invisible round button over each neuron: hover, focus and tap target */
.learn__neuron {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 4;
  border-radius: 50%;
  background: transparent;
}
.learn__neuron:focus-visible { outline: 1.5px solid var(--signal); outline-offset: 2px; }

/* column labels: what each layer is for, in plain words */
.learn__cols { position: absolute; inset: 0 0 auto 0; pointer-events: none; }
.learn__col {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  gap: 0.2rem;
  white-space: nowrap;
}
.learn__col--n { justify-items: center; text-align: center; }
.learn__col b {
  font: 500 var(--l-micro) / 1.2 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
}
.learn__col span {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.8125rem;
  line-height: 1.2;
  color: var(--ink-3);
}

/* the answer, beside the output neuron */
.learn__verdict {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  display: grid;
  gap: 0.3rem;
  pointer-events: none;
}
.learn__vword {
  font-size: clamp(1.7rem, 1rem + 1.5vw, 2.6rem);
  font-weight: 560;
  line-height: 1;
  letter-spacing: -0.035em;
  color: var(--ink);
  transition: color 300ms var(--ease-ui);
}
.learn__verdict.is-orange .learn__vword { color: var(--signal); }
/* phones: the answer in one line under the network */
.learn__verdict.is-below { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem 0.9rem; padding-top: 0.75rem; border-top: 1px solid var(--hairline); }
.learn__verdict.is-below .learn__meter { order: 3; flex: 1 0 100%; }
.learn__vsure,
.learn__vtruth {
  font-size: var(--l-micro);
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--ink-2);
}
.learn__vtruth { color: var(--ink-3); }
.learn__verdict.is-wrong .learn__vtruth { color: var(--signal); }
/* p(ink) on a line: orange at the left end, ink at the right */
.learn__meter {
  position: relative;
  display: block;
  height: 2px;
  margin: 0.35rem 0 0.2rem;
  background: linear-gradient(90deg, var(--signal), color-mix(in srgb, var(--ink) 25%, transparent) 50%, var(--ink));
  opacity: 0.85;
}
.learn__meter i {
  position: absolute;
  top: -4px;
  left: calc(var(--p, 0.5) * 100%);
  width: 2px;
  height: 10px;
  margin-left: -1px;
  background: var(--ink);
  transition: left 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* the readout under the network */
.learn__read {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem 1.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--hairline);
}
.learn__readout {
  flex: 1 1 26rem;
  max-width: 62ch;
  min-height: 2.9em;
  font-size: var(--fs-small);
  line-height: 1.45;
  color: var(--ink-2);
  text-wrap: pretty;
}
.learn__readout b { font-weight: 560; color: var(--ink); }
.learn__readout .mono { font-size: var(--l-micro); letter-spacing: 0.04em; text-transform: none; color: var(--ink-3); white-space: nowrap; }
.learn__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  font-size: var(--l-micro);
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
.learn__legend span { display: inline-flex; align-items: center; white-space: nowrap; }

/* ---------- data + run ---------- */

.learn__run {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--hairline);
}

.learn__data { min-width: 0; margin: 0; padding: 0; border: 0; }
.learn__data legend { float: left; width: 100%; margin-bottom: 0.5rem; padding: 0; }
.lchips {
  clear: both;
  display: grid;
  grid-template-columns: repeat(4, 3.25rem);
  gap: 0.5rem;
}
.lchip { display: grid; gap: 0.35rem; cursor: pointer; }
.lchip__thumb {
  display: block;
  aspect-ratio: 1;
  background: var(--surface-1);
  border: 1px solid var(--hairline-strong);
  transition: border-color var(--d-micro) var(--ease-ui);
}
.lchip__thumb canvas { width: 100%; height: 100%; }
.lchip__name {
  font: 450 0.625rem / 1.2 var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.lchip:hover .lchip__thumb { border-color: var(--ink-3); }
.lchip input:checked ~ .lchip__thumb { border-color: var(--ink); outline: 1px solid var(--ink); outline-offset: -2px; }
.lchip input:checked ~ .lchip__name { color: var(--ink); }
.lchip input:focus-visible ~ .lchip__thumb { outline: 1.5px solid var(--signal-text); outline-offset: 3px; }

.learn__ctl { display: grid; gap: 0.55rem; justify-items: end; }
.learn__transport { display: flex; gap: 0.5rem; }

.lbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  height: var(--l-btn);
  padding: 0 0.95rem;
  border: 1px solid var(--hairline-strong);
  font: 500 var(--fs-label) / 1 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
  transition: border-color var(--d-micro) var(--ease-ui), background-color var(--d-micro) var(--ease-ui), color var(--d-micro) var(--ease-ui);
}
.lbtn:hover { border-color: var(--ink); }
.lbtn--primary { min-width: 6.5rem; background: var(--ink); border-color: var(--ink); color: var(--bg); }
.lbtn--primary:hover { background: transparent; color: var(--ink); }

/* play ▸ / pause ‖ drawn, not typed — the subset font has neither glyph */
.lbtn__ico {
  flex: none;
  width: 8px;
  height: 9px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}
.lbtn.is-playing .lbtn__ico {
  background: none;
  clip-path: none;
  border-left: 2.5px solid currentColor;
  border-right: 2.5px solid currentColor;
}

.learn__state {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: var(--l-micro);
  letter-spacing: 0.08em;
  color: var(--ink-2);
  white-space: nowrap;
}
.learn__dot {
  flex: none;
  width: 7px;
  height: 7px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  transition: background-color var(--d-micro) var(--ease-ui);
}
.learn.is-training .learn__dot { background: var(--ink); }

/* ---------- loss sparkline ---------- */

.learn__curve { padding-top: 0.75rem; border-top: 1px solid var(--hairline); }
.learn__curve canvas { display: block; width: 100%; height: 1.875rem; margin-top: 0.4rem; }
.learn__curve-k {
  display: flex;
  gap: 1rem;
  font-size: var(--l-micro);
  letter-spacing: 0.08em;
  color: var(--ink-3);
}
.k {
  display: inline-block;
  width: 14px;
  height: 0;
  margin-right: 0.45rem;
  vertical-align: 0.28em;
}
.k--tr { border-top: 1.5px solid var(--ink); }
.k--te { border-top: 1.25px dashed var(--ink-3); }

/* ---------- tune (collapsed) ---------- */

.learn__tune { border-top: 1px solid var(--hairline); }
.learn__tune > summary {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1rem;
  padding: 0.75rem 1.75rem 0 0;
  list-style: none;
  cursor: pointer;
  font-size: var(--fs-small);
  font-weight: 500;
}
.learn__tune > summary::-webkit-details-marker { display: none; }
.learn__tune > summary::after {
  content: "+";
  position: absolute;
  right: 0.1rem;
  top: 0.65rem;
  font: 400 1rem / 1 var(--font-mono);
  color: var(--ink-2);
}
.learn__tune[open] > summary::after { content: "\2212"; }
.learn__tune > summary:focus-visible { outline-offset: 2px; }
.learn__tune-k {
  font-size: var(--l-micro);
  font-weight: 450;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

.learn__tune-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.1rem 1.5rem;
  padding: 1rem 0 0.25rem;
}

.lf { min-width: 0; margin: 0; padding: 0; border: 0; }
.lf__k {
  display: block;
  float: left; /* lets a <legend> lay out like a block label */
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0;
  font: 450 var(--l-micro) / 1.4 var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.lf__row { display: flex; align-items: baseline; justify-content: space-between; }
.lf__row .lf__k { float: none; width: auto; margin: 0; }
.lf__v { font: 450 var(--l-micro) / 1.4 var(--font-mono); font-variant-numeric: tabular-nums; }
.lf--arch { grid-column: 2; grid-row: 1 / span 3; }
.lf--step {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

.lrange {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 1.5rem;
  background: transparent;
  cursor: pointer;
}
.lrange::-webkit-slider-runnable-track { height: 1px; background: var(--ink-4); }
.lrange::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -5px;
  background: var(--ink);
  border: 0;
  border-radius: 0;
}
.lrange::-moz-range-track { height: 1px; background: var(--ink-4); }
.lrange::-moz-range-progress { height: 1px; background: var(--ink); }
.lrange::-moz-range-thumb { width: 11px; height: 11px; background: var(--ink); border: 0; border-radius: 0; }
.lrange:focus-visible { outline-offset: 2px; }

.lseg {
  clear: both;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  border: 1px solid var(--hairline-strong);
}
.lseg__opt { position: relative; cursor: pointer; }
.lseg__opt + .lseg__opt { border-left: 1px solid var(--hairline-strong); }
.lseg__opt span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2rem;
  font: 450 0.6875rem / 1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  transition: background-color var(--d-micro) var(--ease-ui), color var(--d-micro) var(--ease-ui);
}
.lseg__opt:hover span { color: var(--ink); background: var(--surface-1); }
.lseg__opt input:checked + span { background: var(--ink); color: var(--bg); }
.lseg__opt input:focus-visible + span { position: relative; z-index: 1; outline: 1.5px solid var(--signal-text); outline-offset: 2px; }

.lstep-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--hairline);
}
.lstep-row:first-child { padding-top: 0; }
.lstep-row[hidden] { display: none; }
.lstep-row__k { font: 450 var(--l-micro) / 1.2 var(--font-mono); letter-spacing: 0.04em; color: var(--ink-2); }
.lstep { display: inline-flex; align-items: center; }
.lstep__b {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid var(--hairline-strong);
  font: 400 0.9375rem / 1 var(--font-mono);
  transition: border-color var(--d-micro) var(--ease-ui), color var(--d-micro) var(--ease-ui);
}
.lstep__b:hover { border-color: var(--ink); }
.lstep__b[aria-disabled="true"] { color: var(--ink-4); border-color: var(--hairline); cursor: default; }
.lstep__v { min-width: 2rem; text-align: center; font: 500 0.8125rem / 1 var(--font-mono); font-variant-numeric: tabular-nums; }

.learn__spec { font-size: 0.625rem; letter-spacing: 0.06em; line-height: 1.6; color: var(--ink-3); }

/* ---------- footnote ---------- */

.learn__foot {
  padding-top: 0.7rem;
  border-top: 1px solid var(--hairline-strong);
  font-size: var(--l-micro);
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

/* ---------- wide: the caption joins the side, so both columns end together ----------
   The side (score, data, loss, tune) is shorter than the network plus its caption, which left a
   hole under "Tune". Here the hero dissolves into the plate's grid: its head and stage stay left,
   its caption ("Watch it think") moves under the controls. Row 2 is flexible and both the side
   and the stage cross it, so it takes up whichever is taller while the head row stays one label
   high; the caption sits on the plate's floor. The divider is drawn by the plate, since the side
   no longer reaches the bottom. The stage keeps its height, so opening "Tune" still grows the
   side, never the network. Narrower plates keep the caption under the network. */

@media (min-width: 1300px) {
  .learn__plate {
    --l-pad: clamp(1.5rem, 0.8rem + 1.6vw, 2.75rem);
    grid-template-rows: auto 1fr auto;
    row-gap: 0.85rem;
    background: linear-gradient(var(--hairline), var(--hairline)) 60% 0 / 1px 100% no-repeat;
  }
  .learn__hero { display: contents; }
  .learn__hero > .learn__head { grid-column: 1; grid-row: 1; padding: 1.1rem var(--l-pad) 0 0; }
  .learn__stage { grid-column: 1; grid-row: 2 / 4; margin-right: var(--l-pad); }
  .learn__side { grid-column: 2; grid-row: 1 / 3; padding-bottom: 0; border-left: 0; }
  .learn__read { grid-column: 2; grid-row: 3; align-self: end; margin: 0 0 1.1rem var(--l-pad); }
}

/* mid widths: the network's column is too narrow for the sub-labels ("6 neurons", "ink or
   orange?") — they ran into one another. Keep the layer names only, as phones do. */
@media (min-width: 1101px) and (max-width: 1379px) {
  .learn__col span { display: none; }
}

/* ---------- tablet: the network on top, score and controls side by side below ---------- */

@media (max-width: 1100px) {
  .learn__plate { grid-template-columns: minmax(0, 1fr); }
  .learn__hero { padding-right: 0; border-bottom: 1px solid var(--hairline); }
  .learn__side {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    column-gap: 2.5rem;
    row-gap: 1.15rem;
    padding-left: 0;
    border-left: 0;
  }
  .learn__score { grid-column: 1; grid-row: 1 / span 2; align-content: start; }
  .learn__run { grid-column: 2; grid-row: 1; padding-top: 0; border-top: 0; }
  .learn__curve { grid-column: 2; grid-row: 2; }
  .learn__tune { grid-column: 1 / -1; }
}

/* ---------- mobile: the network, the plane full width under it, then the controls ---------- */

@media (max-width: 760px) {
  .learn { --l-btn: 2.75rem; }

  .learn__hero { padding-top: 1.1rem; }
  .learn__col span { display: none; }
  .learn__acc { font-size: 4rem; }

  .learn__side { display: flex; padding-top: 1.25rem; }
  .learn__score { order: 0; }
  .learn__run { order: 1; flex-direction: column; align-items: stretch; padding-top: 0.9rem; border-top: 1px solid var(--hairline); }
  .learn__curve { order: 2; }
  .learn__tune { order: 3; }

  .lchips { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.6rem; }
  .lchip__name { text-align: center; }
  .learn__ctl { justify-items: stretch; }
  .learn__transport .lbtn { flex: 1 1 0; }
  .learn__transport .lbtn--primary { flex-grow: 1.5; }
  .learn__state { justify-content: center; }

  .learn__tune-body { grid-template-columns: minmax(0, 1fr); }
  .lf--arch { grid-column: auto; grid-row: auto; }
  .lrange { height: var(--l-btn); }
  .lseg__opt span { height: var(--l-btn); font-size: 0.75rem; }
  .lstep__b { width: var(--l-btn); height: var(--l-btn); }
  .learn__tune > summary { min-height: var(--l-btn); }
}
