/* ==========================================================================
   FIG. 05  "neural"  -  animated feed-forward neural network diagram
   Script: js/figures/neural.js

   Every selector starts with .fg-neural (the class on the figure's root
   element), so nothing here can leak into the rest of the site.
   Colours and fonts come from the design tokens defined on :root in
   css/site.css. Positions, sizes and the font size of the labels inside the
   drawing are set by the script, because they depend on the stage width.
   ========================================================================== */

.fg-neural {
  display: block;
  width: 100%;
  font-family: var(--font-mono);
  color: var(--ink-3);
}

/* Zero-height strip the script measures to learn the figure's width */
.fg-neural__ruler {
  height: 0;
}

/* ---------- Header strip: pass readout, weight count, play/pause ---------- */

.fg-neural__head {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 0 16px;
  min-height: 35px;               /* same height with or without the button */
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* The running pass number, e.g. "03" */
.fg-neural__num {
  color: var(--ink);
}

/* "112 weights", separated from the readout by a hairline */
.fg-neural__meta {
  padding-left: 16px;
  border-left: 1px solid var(--line-2);
}

/* Play / pause button (hidden when the visitor prefers reduced motion) */
.fg-neural__toggle {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 24px;
  min-width: 26px;
  margin: 0 0 0 auto;             /* pushes the button to the right edge */
  padding: 0 9px;
  border: 1px solid var(--trace-2);
  border-radius: 0;
  background: transparent;
  color: var(--ink-3);
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.fg-neural__toggle[hidden] {
  display: none;
}

/* With a mouse or trackpad only. On a touch screen a tap leaves a hover look
   switched on until the next tap somewhere else, so the button would still
   look pressed. (The site does this for every control that switches on and
   off: see .nav-toggle:hover in css/site.css.) */
@media (hover: hover) {
  .fg-neural__toggle:hover {
    border-color: var(--trace);
    background: var(--bg-3);
    color: var(--ink);
  }
}

/* Visible keyboard focus */
.fg-neural__toggle:focus {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.fg-neural__toggle:focus:not(:focus-visible) {
  outline: none;                  /* no ring after a mouse click */
}

.fg-neural__icon {
  flex: none;
  width: 8px;
  height: 10px;
  fill: currentColor;
}

/* ---------- The drawing ---------- */

.fg-neural__svg {
  display: block;
  width: 100%;
  height: auto;                   /* height follows the viewBox set by the script */
  margin-top: 6px;
  overflow: visible;
}

/* Dash-dot centre line through each layer, as on an engineering drawing */
.fg-neural__axis {
  fill: none;
  stroke: var(--trace-3);
  stroke-width: 1;
}

/* Connections. Opacity and width are set per line from its weight. */
.fg-neural__edge {
  fill: none;
  stroke: var(--trace);
}

/* Travelling pulses. Their stroke is a fade (see-through tail, solid head)
   that the script creates for each figure; this sets its colour. */
.fg-neural__pulse {
  fill: none;
  stroke-linecap: round;
}

.fg-neural__stop {
  stop-color: var(--amber);
}

/* A node is three stacked circles: soft halo, steel outline, amber "lit" disc */
.fg-neural__halo {
  fill: var(--amber-glow);
}

.fg-neural__node {
  fill: var(--bg-2);
  stroke: var(--trace);
  stroke-width: 1;
}

.fg-neural__lit {
  fill: var(--amber);
  stroke: var(--amber);
  stroke-width: 1;
}

/* Ring around the winning output node */
.fg-neural__ring {
  fill: none;
  stroke: var(--amber);
  stroke-width: 1;
}

/* Text inside the drawing */
.fg-neural__label,
.fg-neural__var,
.fg-neural__val {
  fill: var(--ink-3);
  font-family: var(--font-mono);
}

/* Layer names under the columns (letter-spacing is set by the script) */
.fg-neural__label {
  font-weight: 500;
  text-anchor: middle;
}

/* Same style, starting at its x position: the heading over the bars */
.fg-neural__label--left {
  text-anchor: start;
}

/* Winning output: its name and value turn white */
.fg-neural__var.is-top,
.fg-neural__val.is-top {
  fill: var(--ink);
}

/* Output value bars: hairline track, steel fill, amber fill for the winner */
.fg-neural__track {
  fill: none;
  stroke: var(--line-2);
  stroke-width: 1;
}

.fg-neural__bar {
  fill: var(--trace-2);
}

.fg-neural__bar--top {
  fill: var(--amber);
}

/* ---------- Compact layout (narrow stages; class set by the script) ---------- */

.fg-neural--compact .fg-neural__head {
  gap: 0 12px;
  font-size: 10px;
}

.fg-neural--compact .fg-neural__meta {
  padding-left: 12px;
}

/* Icon-only button; its accessible name comes from aria-label.
   A finger needs a target of at least 44 x 44px, but the drawn box should
   stay small (26 x 24px). So here the button itself is an invisible
   44 x 44px square, and its ::before draws the small outlined box in the
   middle of it. The negative margins hand the extra 10px above and below
   and 9px on the right back to the layout: the header strip keeps its
   height and the drawn box still ends at the right-hand edge. */
.fg-neural--compact .fg-neural__toggle {
  position: relative;
  width: 44px;
  height: 44px;
  margin: -10px -9px -10px auto;
  padding: 0;
  border: 0;
}

.fg-neural--compact .fg-neural__toggle::before {
  content: "";
  box-sizing: border-box;
  position: absolute;
  top: 10px;
  left: 9px;
  width: 26px;
  height: 24px;
  border: 1px solid var(--trace-2);
}

/* The icon is drawn on top of the small box */
.fg-neural--compact .fg-neural__icon {
  position: relative;
}

/* Hover and keyboard focus are shown on the small box, as on the wide layout
   (hover with a mouse or trackpad only, as above) */
@media (hover: hover) {
  .fg-neural--compact .fg-neural__toggle:hover {
    background: transparent;
  }

  .fg-neural--compact .fg-neural__toggle:hover::before {
    border-color: var(--trace);
    background: var(--bg-3);
  }
}

.fg-neural--compact .fg-neural__toggle:focus {
  outline: none;
}

.fg-neural--compact .fg-neural__toggle:focus::before {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.fg-neural--compact .fg-neural__toggle:focus:not(:focus-visible)::before {
  outline: none;
}

.fg-neural--compact .fg-neural__toggle-text {
  display: none;
}

/* Very narrow stages: no room for the weight count */
.fg-neural--tiny .fg-neural__meta {
  display: none;
}
