/* =========================================================================
   kit/figstep.css — styling for the derivation figure (kit/figstep.js).

   Kept OUT of kit.css on purpose, for the same reason peek.css is: kit.css
   is served immutable for a week and is referenced by ~250 built pages, so
   adding two hundred lines for a component only the maths track uses would
   force a cache bump on every one of them. A lab that wants derivations
   links this file as well; nothing else pays for it.

   Reads the kit's tokens (--bp-*, --mono, --sans) and nothing else.
   ========================================================================= */

/* The whole figure is one object: drawing, formula, sentence, transport.
   They are separated by rules rather than gaps, because a gap reads as
   "here is another thing" and these are four views of the same thing. */
.learn-fig.figstep {
  border: 1px solid var(--bp-line);
  border-radius: 10px;
  background: var(--bp-panel);
  padding: 0.9rem 0.9rem 0.75rem;
  margin: 1.5rem auto;
  text-align: left;
  outline: none;
}
.learn-fig.figstep:focus-visible {
  border-color: var(--bp-cyan);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--bp-cyan) 35%, transparent);
}
.learn-fig.figstep::before {
  content: attr(data-hint);
  display: block; font-family: var(--mono); font-size: 0.66rem;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--bp-cyan); opacity: 0.8; margin-bottom: 0.55rem;
}

/* ------------------------------------------------------------- the drawing */
.figstep-stage { min-height: 40px; text-align: center; }
.figstep-stage svg { max-width: 100%; height: auto; }

/* ------------------------------------------------------ the formula board

   The formula gets a surface of its own and a fixed minimum height. Without
   the minimum, a two-line step and a one-line step make the whole figure
   jump every time it advances, and the reader's eye chases the layout
   instead of the maths. */
.figstep-board {
  margin-top: 0.7rem;
  border-top: 1px solid var(--bp-line);
  padding-top: 0.7rem;
}
.figstep-math {
  font-family: var(--mono);
  font-size: 1.02rem;
  line-height: 1.85;
  color: var(--bp-ink);
  text-align: center;
  min-height: 2.4rem;
  padding: 0.45rem 0.5rem;
  border-radius: 7px;
  background: var(--bp-bg2);
  border: 1px solid var(--bp-line);
  overflow-x: auto;
}
.figstep-math .op { color: var(--bp-ink-dim); padding: 0 0.12em; }
.figstep-math .gh { opacity: 0.28; }          /* a term not yet written */
.figstep-math small { font-size: 0.72em; color: var(--bp-ink-dim); }
.figstep-math .box {
  display: inline-block; padding: 0.06em 0.4em; border-radius: 5px;
  border: 1px dashed var(--bp-line2);
}
.figstep-math .res {
  display: inline-block; padding: 0.06em 0.45em; border-radius: 5px;
  background: color-mix(in srgb, var(--bp-cyan) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--bp-cyan) 45%, transparent);
}

.figstep-say {
  margin: 0.55rem 0.1rem 0;
  font-size: 0.85rem; line-height: 1.62;
  color: var(--bp-ink-dim);
  min-height: 2.7em;
}
.figstep-say b, .figstep-say strong { color: var(--bp-ink); font-weight: 600; }

/* ---------------------------------------------------- terms and the picture

   A term in the formula and the thing it names in the drawing carry the same
   data-k. Pointing at either dims everything else. The transition is on
   opacity only — moving or resizing on hover would fight the animation. */
.figstep-term { cursor: help; font-style: normal; transition: opacity 0.16s; }
.figstep-stage [data-k], .figstep-math [data-k] { transition: opacity 0.16s; }
.figstep-stage [data-k] { cursor: help; }
.fs-dim { opacity: 0.2; }
.figstep-math .fs-hot {
  text-shadow: 0 0 10px currentColor;
}
.figstep-stage .fs-hot { filter: drop-shadow(0 0 4px currentColor); }

/* --------------------------------------------------------------- the rail */
.figstep-rail {
  display: flex; flex-wrap: wrap; gap: 0.28rem;
  margin-top: 0.7rem;
}
.figstep-dot {
  font-family: var(--mono); font-size: 0.68rem; line-height: 1;
  width: 1.5rem; height: 1.5rem; flex: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--bp-ink-dim);
  border: 1px solid var(--bp-line); border-radius: 5px;
  transition: 0.16s; padding: 0;
}
.figstep-dot:hover { color: var(--bp-ink); border-color: var(--bp-line2); }
.figstep-dot.past { color: var(--bp-cyan); border-color: color-mix(in srgb, var(--bp-cyan) 40%, var(--bp-line)); }
.figstep-dot.on {
  color: var(--bp-bg); background: var(--bp-cyan);
  border-color: var(--bp-cyan); font-weight: 700;
}

/* ----------------------------------------------------------- the transport */
.figstep-bar {
  display: flex; align-items: center; gap: 0.4rem;
  margin-top: 0.5rem;
}
.figstep-play {
  font-family: var(--mono); font-size: 0.72rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: transparent; color: var(--bp-ink-dim); flex: none;
  border: 1px solid var(--bp-line); border-radius: 5px; padding: 0.24rem 0.55rem;
  transition: 0.18s; min-width: 5.6rem;
}
.figstep-play .figstep-ico { font-size: 0.66rem; }
.figstep-play:hover { color: var(--bp-cyan); border-color: var(--bp-cyan); }
.figstep-play.on { color: var(--bp-cyan); border-color: var(--bp-cyan); }

.figstep-nav {
  font-size: 0.62rem; cursor: pointer; flex: none;
  background: transparent; color: var(--bp-ink-dim);
  border: 1px solid var(--bp-line); border-radius: 5px;
  width: 1.65rem; height: 1.65rem; padding: 0;
  transition: 0.18s;
}
.figstep-nav:hover { color: var(--bp-cyan); border-color: var(--bp-cyan); }

.figstep-scrub {
  flex: 1 1 auto; min-width: 4rem;
  accent-color: var(--bp-cyan);
}
.figstep-count {
  font-family: var(--mono); font-size: 0.7rem; color: var(--bp-ink-dim);
  flex: none; min-width: 2.8rem; text-align: right;
}

/* --------------------------------------------------------- optional sliders */
.figstep-controls {
  margin-top: 0.6rem; padding-top: 0.55rem;
  border-top: 1px dashed var(--bp-line);
  display: flex; flex-direction: column; gap: 0.3rem;
}
.figstep-row {
  display: grid; grid-template-columns: minmax(5.5rem, auto) 1fr 4rem;
  gap: 0.6rem; align-items: center;
}
.figstep-row label {
  font-family: var(--mono); font-size: 0.75rem;
  color: var(--bp-ink-dim); text-align: right;
}
.figstep-row input[type="range"] { width: 100%; accent-color: var(--bp-cyan); }
.figstep-val {
  font-family: var(--mono); font-size: 0.75rem;
  color: var(--bp-cyan); text-align: right;
}
.figstep-foot { display: flex; justify-content: flex-end; margin-top: 0.1rem; }
.figstep-reset {
  font-family: var(--mono); font-size: 0.7rem; cursor: pointer;
  background: transparent; color: var(--bp-ink-dim);
  border: 1px solid var(--bp-line); border-radius: 5px; padding: 0.16rem 0.5rem;
  transition: 0.18s;
}
.figstep-reset:hover { color: var(--bp-cyan); border-color: var(--bp-cyan); }

/* ------------------------------------------------------- the static version

   _build-pages.cjs bakes the finished drawing plus every step's line of
   maths, because a crawler and a printed page both want the whole
   derivation at once rather than the last frame of it. */
.figstep-static { margin-top: 0.7rem; border-top: 1px solid var(--bp-line); padding-top: 0.6rem; }
.figstep-static ol { margin: 0; padding-left: 1.4rem; }
.figstep-static li { margin-bottom: 0.6rem; }
.figstep-static .figstep-math {
  text-align: left; font-size: 0.9rem; min-height: 0; line-height: 1.7;
}
.figstep-static .figstep-say { min-height: 0; margin-top: 0.3rem; }

@media (max-width: 640px) {
  .learn-fig.figstep { padding: 0.7rem 0.6rem 0.6rem; }
  .figstep-math { font-size: 0.88rem; line-height: 1.7; }
  .figstep-play { min-width: 0; }
  .figstep-play span:not(.figstep-ico) { display: none; }
  .figstep-row { grid-template-columns: 4.2rem 1fr 3.4rem; gap: 0.4rem; }
  .figstep-row label { font-size: 0.7rem; }
  .figstep-count { font-size: 0.65rem; min-width: 2.4rem; }
}
