/*
 * The fleet of the decades city (js/decades-fleet.js): how a mover is
 * coloured, lit, gated to its eras and moved. The timing scale and the
 * curves are decades.css's (--ms-*, --ease-*), inherited from .timelapse.
 */

/* ── Colour: one token per vehicle, the faces mixed from it ──────────────
   Lit as the city lights its blocks: the +v face carries the colour, the
   +u face is in shade, the top takes the ground's light (and in the dark
   scheme the ground's dark). Route colours only on what runs on a route. */
.tl-traffic .mv { --mvc: var(--ink-3); }
.tl-traffic .c-red { --mvc: var(--line-red-lit); }
.tl-traffic .c-blue { --mvc: var(--line-blue-lit); }
.tl-traffic .c-green { --mvc: var(--line-green-lit); }
.tl-traffic .c-purple { --mvc: var(--line-purple-lit); }
.tl-traffic .c-bus { --mvc: var(--line-orange); }
.tl-traffic .c-brt { --mvc: var(--line-red-lit); }
.tl-traffic .c-rail { --mvc: var(--ink-3); }
.tl-traffic .c-ink { --mvc: var(--ink-2); }
.tl-traffic .c-car { --mvc: var(--tl-car); }
.tl-traffic .c-car2 { --mvc: var(--tl-car-2); }
.tl-traffic .c-car3 { --mvc: var(--ink-2); }
.tl-traffic .c-white { --mvc: var(--tl-glass-top); }
.tl-traffic .c-brick { --mvc: var(--tl-brick-2); }
.tl-traffic .c-horse { --mvc: var(--ink-3); }
.tl-traffic .c-plane { --mvc: var(--tl-plane); }

.tl-traffic .mv :is(.f-t, .f-u, .f-v, .f-flat, .f-g) {
  stroke: var(--ink);
  stroke-width: 0.8;
  stroke-linejoin: round;
}
.tl-traffic .f-t { fill: color-mix(in srgb, var(--mvc), var(--surface) 34%); }
.tl-traffic .f-v { fill: var(--mvc); }
.tl-traffic .f-u { fill: color-mix(in srgb, var(--mvc), #000 26%); }
.tl-traffic .f-flat { fill: var(--mvc); }
.tl-traffic .f-g { fill: var(--surface); opacity: 0.82; }
.tl-traffic .f-k { fill: var(--ink); stroke: none; }
/* A vehicle's shadow (f-s, first in its glyph): the city's shadow colour at the city's alpha — fill-opacity, not opacity, so it is no paint group of its own. */
.tl-traffic .f-s { fill: var(--tl-shadow); fill-opacity: var(--tl-shadow-a); stroke: none; }
.tl-traffic .f-p { fill: var(--ink); stroke: none; }
.tl-traffic .f-rider { fill: var(--tl-bike); stroke: none; }
.tl-traffic .f-ring { fill: none; stroke: var(--ink); stroke-width: 0.7; }
.tl-traffic .f-disc { fill: var(--ink-4); stroke: none; opacity: 0.7; }
.tl-traffic .f-rod { fill: none; stroke: var(--ink); stroke-width: 0.8; stroke-linecap: round; }
.tl-traffic .tl-smoke { fill: var(--tl-smoke); stroke: none; }

/* ── The layer ──────────────────────────────────────────────────────────
   The traffic is an HTML box over the city, the size of it; inside, the
   fleet's box is the city's 960 × 600 drawing box scaled to fit (--k, set
   by the script once per resize), so every mover is placed in box px. A
   mover is a 0 × 0 element at the origin carrying its glyph as a small
   SVG centred on its ground point; its keyframes translate it along its
   path. Transform and opacity only, so the compositor carries the whole
   fleet and no frame of traffic is painted on the main thread. */
.tl-traffic { overflow: hidden; }
.tl-fleet {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 0;
  inline-size: 960px;
  block-size: 600px;
  transform-origin: 0 0;
  transform: scale(var(--k, 0.72));
}
.tl-fleet .mv, .tl-fleet .puff {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 0;
  inline-size: 0;
  block-size: 0;
}
.tl-fleet .mv-g {
  position: absolute;
  overflow: visible;
  display: block;
  /* Its width/height attributes are its size: the site's svg { max-width: 100% } would make it 0 wide in a 0-wide mover. */
  max-inline-size: none;
  max-block-size: none;
}

/* ── Gating ─────────────────────────────────────────────────────────────
   Each mover's keyframes are generated by the script from its path (one
   rule per distinct path: a street, a lane, a line with its stops). Out of
   its eras a mover is paused and hidden and costs nothing per frame; the
   script sets .now on the current era's set. One leaving fades at the
   turn; one arriving waits the turn out and fades in as the year lands,
   already in the right place on its path; one in both eras has no
   transition at all and flows on. */
.tl-traffic .mv {
  visibility: hidden;
  opacity: 0;
  animation: tl-still 1s linear infinite;
  animation-play-state: paused;
  transition: opacity var(--ms-swap) var(--ease-swap), visibility 0s linear var(--ms-swap);
}
.tl-traffic .mv.now {
  visibility: visible;
  opacity: 1;
  animation-play-state: running;
  transition: opacity var(--ms-swap) var(--ease-land) var(--ms-turn), visibility 0s linear var(--ms-turn);
}
.tl-traffic[data-hand] .mv.now { transition-delay: 0ms; }
.tl-traffic .mv:not(.now) .puff { animation-play-state: paused; }
/* Smoke stands still (the stack's puffs) or rides its train; each puff drifts on its own cycle. */
.tl-traffic .mv--smoke { animation: none; }
.tl-traffic .puff { animation: tl-puff 3600ms linear infinite; }
@keyframes tl-still { from { opacity: 1; } to { opacity: 1; } }
@keyframes tl-puff {
  0% { transform: translate(0, 0) scale(0.6); opacity: 0.7; }
  100% { transform: translate(24px, -58px) scale(2.6); opacity: 0; }
}

/* Off screen, or with the tab hidden, nothing in the city moves. */
.tl-cam[data-still] .mv, .tl-cam[data-still] .puff { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  /* A still frame of each decade: the traffic stands where its cycle
     places it, nothing moves, the scrubber still changes the decade. */
  .tl-traffic .mv { transition: none; }
  .tl-traffic .mv, .tl-traffic .puff { animation-play-state: paused; }
}
