/* ===========================================================================
   The drawing board.

   Nine boards on one pad. Scroll is the pen: every stroke, label and mark on
   every board is driven from --p, the leg's own 0-to-1 progress, written once
   per frame by the page onto the segment element.

   Nothing here animates on a timer. If the reader stops, the drawing stops
   exactly where they left it, and scrolling back un-draws it. That is the whole
   point of a scroll-driven board, and it is why this is code rather than
   generated video: a clip can only ever play back at its own pace.

   Every board finishes drawing at about 0.55 of its leg and then holds. That
   settle is deliberate: it is what lets the waypoint map land a reader on a
   COMPLETED board rather than half way through one still being drawn.
   =========================================================================== */

/* Typed so it inherits as a real number rather than a token stream, which is
   what lets every descendant do arithmetic against it in plain calc(). */
@property --p {
  syntax: "<number>";
  initial-value: 0;
  inherits: true;
}

.board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Every animated element declares WHEN it starts (--at) and HOW LONG it takes
   (--dur), both in units of the leg's own progress, and derives its own local
   0-to-1 from them. One expression, reused by every effect below. */
.a {
  --at: 0;
  --dur: 0.3;
  --t: clamp(0, calc((var(--p) - var(--at)) / var(--dur)), 1);
}

/* Draw a stroke on. Every shape carries pathLength="1", so the dash maths is
   the same whether the path is a 40px tick or a 3000px timeline, and nothing
   has to be measured in JS. */
.draw {
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--t));
}

.fade { opacity: var(--t); }

.rise {
  opacity: var(--t);
  transform: translateY(calc(18px * (1 - var(--t))));
}

/* Slide along the board. --dx is the distance it travels to reach home. */
.slide {
  --dx: 60px;
  opacity: var(--t);
  transform: translateX(calc(var(--dx) * (1 - var(--t))));
}

/* ---------------------------------------------------------------- ink ----
   On a paper ground the accent must be FOREST, not mint. Mint measures 1.54:1
   on this canvas: here it is a fill colour only and can never be a stroke or a
   label. Forest is 5.99:1 and carries both. One hue, two lightnesses, keyed to
   the ground, which is the single two-stop accent taste.md allows. */
.bd-rule    { fill: none; stroke: var(--sc-hairline-strong); stroke-width: 1.5; }
.bd-ink     { fill: none; stroke: var(--sc-ink);      stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.bd-soft    { fill: none; stroke: var(--sc-ink-soft); stroke-width: 2;   stroke-linecap: round; stroke-linejoin: round; }
.bd-mint    { fill: none; stroke: var(--sc-accent);   stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.bd-mint-fill { fill: var(--sc-accent); }
.bd-soft-fill { fill: var(--sc-ink-soft); }
.bd-plate   { fill: var(--sc-surface); stroke: var(--sc-hairline-strong); stroke-width: 1.5; }

/* Friction is drawn the way friction deserves: dashed, unmeasured, never quite
   closing. Seamless is one solid unbroken stroke. That contrast is the whole
   argument of the page, carried in stroke style alone. */
/* The braid trick: a thick canvas-coloured stroke painted just under a strand
   erases whatever is beneath it, so draw order becomes over-and-under. */
.bd-halo  { fill: none; stroke: var(--sc-canvas); stroke-width: 14; stroke-linecap: round; }

.bd-guess { fill: none; stroke: var(--sc-ink-soft); stroke-width: 2; stroke-dasharray: 7 7; opacity: 0.7; }

/* A route is the path taken; a trace is a measurement of one. They share a
   colour, so weight has to carry the difference or a straight route and a flat
   trace read as two identical lines. Declared after the ink classes above, and
   again in the phone block below, because an inline stroke-width would opt out
   of the phone scaling entirely. */
.bd-route { stroke-width: 3.5; }
.bd-trace { stroke-width: 1.8; }

.bd-t {
  font-family: var(--sc-font-text);
  font-size: 21px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  fill: var(--sc-ink-soft);
}
.bd-t--ink  { fill: var(--sc-ink); }
.bd-t--mint { fill: var(--sc-accent); }
.bd-t--num {
  font-family: var(--sc-font-mono, ui-monospace, monospace);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  font-size: 23px;
}

/* Reduced motion: the boards ARE the content, so they must be fully drawn and
   readable rather than merely stilled. Everything lands at its finished state
   and nothing moves. */
/* The old-browser net's other half. A browser without @property computes no
   --t at all, so every stroke would keep its initial value and the page would
   look sparse rather than broken - the worse failure, because nobody reports
   it. Forced to the finished state instead, which is exactly what reduced
   motion asks for below. */
[data-fallback] .a     { --t: 1; }
[data-fallback] .draw  { stroke-dashoffset: 0; }
[data-fallback] .fade  { opacity: 1; }
[data-fallback] .rise  { opacity: 1; transform: none; }
[data-fallback] .slide { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .a { --t: 1; }
  .draw  { stroke-dashoffset: 0; }
  .fade  { opacity: 1; }
  .rise  { opacity: 1; transform: none; }
  .slide { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- phones --
   A 1600-unit-wide board cannot be sliced into a 390px viewport: the crop keeps
   roughly the middle 500 units, which threw away the whole left half of every
   comparison. These boards ARE the argument, so losing half of one is losing
   the point.

   So the board is fitted rather than sliced, which forces a scale of about
   0.24, and everything that has to stay readable at that scale is enlarged to
   compensate. Fitted to width it renders about 390x220 whatever box it is
   given, and it centres in that box, so the box height is the only lever on
   where it lands: 97% drops the figure just above where the copy begins. */
@media (max-width: 700px) {
  .board { inset: 0 0 auto 0; height: 97%; }

  .bd-t      { font-size: 51px; letter-spacing: 0.06em; }
  .bd-t--num { font-size: 53px; }

  /* A 2px stroke reduced by 0.24 is a quarter of a pixel and disappears. */
  .bd-rule  { stroke-width: 4; }
  .bd-ink   { stroke-width: 6; }
  .bd-soft  { stroke-width: 5; }
  .bd-mint  { stroke-width: 6; }
  .bd-guess { stroke-width: 5; stroke-dasharray: 16 16; }
  .bd-halo  { stroke-width: 30; }
  .bd-route { stroke-width: 8; }
  .bd-trace { stroke-width: 4; }
}
