/* ==========================================================================
   Parallel Machines / twin.css
   The live twin stage (assets/js/twin/twin-stage.js), its static fallback,
   the "fig. 01–06" index and the caption (assets/js/twin/twin-ui.js).
   Solid = the machine / now; dots = the twin / the record.
   Reads the spec tokens (tokens.css) with fallbacks, so it also works alone.

   Markup:
     <figure class="twin-figure">
       <div class="twin-stage" role="img" aria-label="…">
         <canvas class="twin-stage__canvas" aria-hidden="true"></canvas>
         <!-- optional; twin-stage creates it when needed. No-JS: <noscript><img class="twin-stage__fallback" …></noscript> -->
       </div>
       <figcaption class="twin-meta">
         <span class="twin-figs__label">fig.</span><ol class="twin-figs"></ol>
         <p class="twin-caption">fig. 01 · 6-axis arm · solid: the machine · dots: its record</p>
       </figcaption>
     </figure>
   State: twin-stage sets data-twin-state="loading|live|still|fallback" on .twin-stage.
   ========================================================================== */

/* ---------- stage ---------- */
.twin-stage {
  position: relative;
  overflow: hidden;
  contain: layout paint;
  -webkit-tap-highlight-color: transparent;
}
/* give the stage a size from its parent (the page decides; these are safe defaults) */
.twin-stage--fill { position: absolute; inset: 0; }
.twin-stage--ratio { aspect-ratio: var(--twin-ratio, 1 / 1); width: 100%; }

.twin-stage__canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  opacity: 0;
  transition: opacity var(--dur-2, 480ms) var(--ease, cubic-bezier(.2,.7,.1,1));
}
.twin-stage[data-twin-state="live"] .twin-stage__canvas,
.twin-stage[data-twin-state="still"] .twin-stage__canvas { opacity: 1; }
.twin-stage[data-twin-state="fallback"] .twin-stage__canvas { display: none; }

/* the pre-rendered still (print + twin on transparency; the page's sky shows through) */
.twin-stage__fallback {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: var(--twin-fit, cover);
  object-position: var(--twin-pos, 50% 50%);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity var(--dur-2, 480ms) var(--ease, cubic-bezier(.2,.7,.1,1));
}
.twin-stage[data-twin-state="live"] .twin-stage__fallback,
.twin-stage[data-twin-state="still"] .twin-stage__fallback { opacity: 0; visibility: hidden; transition-property: opacity, visibility; transition-duration: var(--dur-2, 480ms), 0s; transition-delay: 0s, var(--dur-2, 480ms); }
/* plates carry their own sky: show them whole */
.twin-stage__fallback[src*="/img/devices/"] { --twin-fit: contain; }
/* hero stills (assets/img/hero/<id>.webp, 1600 x 1000) are framed like the live loop inside their central
   --twin-frame-aspect region (0.96, tools/prerender/jobs.json). That region is contained in the stage: on a stage of
   that aspect the still covers it exactly like the live frame; on narrower stages it scales with the width (as the
   live framing does), on wider ones with the height, and the device is never cropped. Container units (cqw/cqh) read
   the stage box. */
.twin-stage[data-twin-state="fallback"] { container-type: size; }
.twin-stage__fallback[src*="/img/hero/"] {
  inset: auto;
  left: 50%;
  top: 50%;
  width: min(160cqh, calc(160cqw / var(--twin-frame-aspect, .96)));
  height: min(100cqh, calc(100cqw / var(--twin-frame-aspect, .96)));
  object-fit: fill;
  transform: translate(-50%, -50%);
}

/* ---------- figure meta: fig. index + caption ---------- */
.twin-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: var(--space-4, 16px);
  row-gap: var(--space-2, 8px);
  color: var(--fg, #fff);
  font-family: var(--font-mono, "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace);
  font-size: var(--fs-label, .75rem);
  line-height: 1.4;
}

.twin-figs__label {
  text-transform: uppercase;
  letter-spacing: var(--tr-label, .08em);
  color: var(--fg-3, rgba(255,255,255,.86));
}

.twin-figs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.twin-figs > li { display: flex; }

.twin-fig {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 0 6px 6px;
  border: 0;
  border-radius: var(--r-1, 2px);
  background: none;
  color: var(--fg-3, rgba(255,255,255,.86));
  font: inherit;
  font-feature-settings: "tnum" 1, "zero" 0;
  letter-spacing: var(--tr-mono, .02em);
  cursor: pointer;
  transition: color var(--dur-1, 240ms) var(--ease, cubic-bezier(.2,.7,.1,1));
}
.twin-fig:hover { color: var(--fg, #fff); }
.twin-fig[aria-pressed="true"] { color: var(--fg, #fff); }
.twin-fig:focus-visible {
  outline: 2px solid var(--focus, #fff);
  outline-offset: 1px;
}
@media (pointer: coarse) { .twin-fig { min-width: 44px; min-height: 44px; } }

/* hairline under each number; the active one fills over the cycle interval (shape, not colour, marks it) */
.twin-fig__bar {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 8px;
  height: 1px;
  background: var(--line, rgba(255,255,255,.22));
  overflow: hidden;
}
.twin-fig__bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: 0 50%;
}
.twin-fig[aria-pressed="true"] .twin-fig__bar { height: 2px; bottom: 7px; }
.twin-fig[aria-pressed="true"] .twin-fig__bar::after { transform: scaleX(1); }
.twin-figs[data-cycle="on"] .twin-fig[aria-pressed="true"] .twin-fig__bar.is-filling::after {
  transform: scaleX(0);
  animation: twin-fig-fill var(--twin-interval, 9000ms) linear forwards;
}
.twin-figs[data-running="false"] .twin-fig__bar::after { animation-play-state: paused; }
/* while the switch runs, the new device's bar waits empty; it fills once the transition ends (twin-ui.js) */
.twin-figs[data-cycle="on"] .twin-fig[aria-pressed="true"] .twin-fig__bar.is-waiting::after { transform: scaleX(0); animation: none; }
/* driven by a Web Animation on the cycle clock (twin-ui.js): it starts empty, the animation fills it */
.twin-figs[data-cycle="on"] .twin-fig[aria-pressed="true"] .twin-fig__bar.is-timed::after { transform: scaleX(0); }
/* the short device name beside each number, from 1024 px ("01 arm  02 GPU …") */
.twin-fig__name { display: none; }
@media (min-width: 1024px) {
  .twin-fig__name { display: inline; margin-left: .5em; }
  .twin-fig { padding: 0 8px 6px; }
}
@keyframes twin-fig-fill { to { transform: scaleX(1); } }

.twin-caption {
  margin: 0;
  color: var(--fg-3, rgba(255,255,255,.86));
  letter-spacing: var(--tr-mono, .02em);
  text-wrap: balance;
}
.twin-caption b, .twin-caption strong { font-weight: 500; color: var(--fg, #fff); }

/* small legend chips: "— solid  ··· dots" */
.twin-legend {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3, 12px);
}
.twin-legend__solid,
.twin-legend__dots {
  display: inline-block;
  width: 18px;
  height: 2px;
  margin-right: 6px;
  vertical-align: middle;
  background: currentColor;
}
.twin-legend__dots {
  height: 2px;
  background: linear-gradient(90deg, currentColor 0 2px, transparent 2px 5px) 0 0 / 5px 2px repeat-x;
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .twin-stage__canvas,
  .twin-stage__fallback,
  .twin-fig { transition: none; }
  .twin-figs .twin-fig__bar::after { animation: none !important; }
}
