/* ==========================================================================
   FIG. 03 "tracks": target classes, plan view.
   Built by js/figures/tracks.js. Every selector starts with .fg-tracks.

   --u is set by the script: the number of drawing units in one screen pixel.
   Writing a line weight as calc(var(--u) * 1.25px) therefore always gives a
   line 1.25 pixels thick on screen, however large the drawing is shown.
   ========================================================================== */

.fg-tracks {
  --u: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* ---------- One cell: the drawing with its track block underneath ------ */

.fg-tracks__cell {
  min-width: 0;
  padding-bottom: 12px;
  border-left: 1px solid var(--line);
}
.fg-tracks__cell:first-child {
  border-left: 0;
}

.fg-tracks__svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* ---------- Linework --------------------------------------------------- */

.fg-tracks__ln,
.fg-tracks__fd,
.fg-tracks__bracket {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Object lines: the aircraft outline. */
.fg-tracks__obj {
  stroke: var(--trace);
  stroke-width: calc(var(--u) * 1.25px);
}

/* Detail lines: canopy, hinge lines, rotor blades. Thinner and dimmer. */
.fg-tracks__det {
  stroke: var(--trace-2);
  stroke-width: calc(var(--u) * 1px);
}

/* Dashed lines: the discs swept by the rotor and the propeller. */
.fg-tracks__dash {
  stroke: var(--trace-2);
  stroke-width: calc(var(--u) * 1px);
  stroke-linecap: butt;
  stroke-dasharray: calc(var(--u) * 4px) calc(var(--u) * 3px);
}

/* Centre line: the long-dash, short-dash pattern used on drawings. */
.fg-tracks__centre {
  stroke: var(--trace-3);
  stroke-width: calc(var(--u) * 1px);
  stroke-linecap: butt;
  stroke-dasharray:
    calc(var(--u) * 14px) calc(var(--u) * 3px)
    calc(var(--u) * 2px) calc(var(--u) * 3px);
}

/* Target brackets: the one use of the accent colour in this figure. */
.fg-tracks__bracket {
  stroke: var(--amber);
  stroke-width: calc(var(--u) * 1.25px);
  stroke-linecap: square;
  stroke-linejoin: miter;
}

/* The brief flash inside the brackets at the moment of lock-on.
   Invisible except during that animation. */
.fg-tracks__flash {
  fill: var(--amber-glow);
  stroke: none;
  opacity: 0;
}

/* ---------- Track block ------------------------------------------------ */

.fg-tracks__tag {
  position: relative;
  /* 10% is where the left-hand brackets sit, so the block lines up with them. */
  margin-left: calc(10% - 0.5px);
  padding-left: 10px;
  border-left: 1px solid var(--line-2);
  font: 500 11px/1.6 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Leader line: carries the block's left rule up to the corner of the
   brackets, the way a track block is tied to its target on a radar display.
   --gap (set by the script) is the height it has to cover. */
.fg-tracks__tag::before {
  content: "";
  position: absolute;
  left: -1px;
  bottom: 100%;
  width: 1px;
  height: var(--gap, 0px);
  background: var(--line-2);
}
.fg-tracks__row {
  display: block;
}
.fg-tracks__key {
  margin-right: 0.8em;
  color: var(--ink-3);
}
.fg-tracks__id {
  color: var(--amber);
}
.fg-tracks__val {
  color: var(--ink);
}

/* ---------- Narrow stages: cells stacked, track block beside the drawing */

.fg-tracks--stack {
  grid-template-columns: minmax(0, 1fr);
}
.fg-tracks--stack .fg-tracks__cell {
  display: grid;
  grid-template-columns: minmax(0, 42%) minmax(0, 1fr);
  align-items: center;
  padding-bottom: 0;
  border-left: 0;
  border-top: 1px solid var(--line);
}
.fg-tracks--stack .fg-tracks__cell:first-child {
  border-top: 0;
}
.fg-tracks--stack .fg-tracks__tag {
  margin-left: 2px;
}
.fg-tracks--stack .fg-tracks__tag::before {
  display: none;
}

/* ---------- Reveal ------------------------------------------------------
   The script adds .is-armed while the figure waits off screen, then
   .is-live to play the sequence, then removes both. Each line carries its
   own start delay in --d; each cell carries its lock-on time in --lock.   */

/* Waiting: everything hidden. Every solid path has pathLength="1", so a
   dash of 1 covers the whole path and an offset of 1 slides it out of view. */
.fg-tracks.is-armed .fg-tracks__ln {
  stroke-dasharray: 1 2;
  stroke-dashoffset: 1.001;
}
.fg-tracks.is-armed .fg-tracks__fd,
.fg-tracks.is-armed .fg-tracks__lock,
.fg-tracks.is-armed .fg-tracks__tag {
  opacity: 0;
}

/* Playing: solid lines draw in, dashed lines fade in. */
.fg-tracks.is-live .fg-tracks__ln {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.95s cubic-bezier(0.45, 0, 0.15, 1) var(--d, 0s);
}
.fg-tracks.is-live .fg-tracks__fd {
  opacity: 1;
  transition: opacity 0.6s ease var(--d, 0s);
}

/* Then each cell locks on: the brackets close in, flash once, and the
   track block appears. */
.fg-tracks.is-live .fg-tracks__lock {
  animation: fg-tracks-lock 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) var(--lock, 0s) both;
}
.fg-tracks.is-live .fg-tracks__flash {
  animation: fg-tracks-flash 0.8s ease-out var(--lock, 0s) both;
}
.fg-tracks.is-live .fg-tracks__tag {
  opacity: 1;
  transition: opacity 0.4s ease var(--lock, 0s);
}

@keyframes fg-tracks-lock {
  0%   { opacity: 0; transform: scale(1.2); }
  30%  { opacity: 1; }
  55%  { transform: scale(1); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes fg-tracks-flash {
  0%, 45% { opacity: 0; }
  60%     { opacity: 1; }
  100%    { opacity: 0; }
}

/* Belt and braces: the script never starts the reveal when the visitor
   prefers reduced motion, and this makes sure nothing can move regardless. */
@media (prefers-reduced-motion: reduce) {
  .fg-tracks *,
  .fg-tracks {
    transition: none !important;
    animation: none !important;
  }
}

/* On paper the drawing is always complete, even if it was still waiting
   to be revealed when the page was printed. */
@media print {
  .fg-tracks.is-armed .fg-tracks__ln {
    stroke-dasharray: none;
    stroke-dashoffset: 0;
  }
  .fg-tracks.is-armed .fg-tracks__fd,
  .fg-tracks.is-armed .fg-tracks__lock,
  .fg-tracks.is-armed .fg-tracks__tag {
    opacity: 1;
  }
  .fg-tracks *,
  .fg-tracks {
    transition: none !important;
    animation: none !important;
  }
}
