/* ================================================================
   MOTION — illustrative animated scenes (page-scoped stylesheet)
   Contract: docs/animation/00-quality-bar.md
   The stage reserves its box with aspect-ratio before any JS runs,
   so scenes never shift layout. Colours come from theme tokens.
   ================================================================ */

.scene {
  margin: 8px 0 36px;
  width: min(100%, 920px);
}

/* In the single-column project layout the scene spans the facts row. */
.article-layout--single .scene {
  width: min(100%, 1000px);
}

.scene__stage {
  position: relative;
  /* per-scene ratio set inline (--aspect) so the box is reserved pre-JS */
  aspect-ratio: var(--aspect, 2.25);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(var(--accent-rgb), 0.05), transparent 60%),
    var(--bg-secondary);
  overflow: hidden;
}

@media (max-width: 559px) {
  .scene__stage {
    /* phones default to 4:3; a scene may reserve a taller box (--aspect-compact) */
    aspect-ratio: var(--aspect-compact, 4 / 3);
  }
}

.scene__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* No-JS fallback image (if a page provides one) fills the stage. */
.scene__stage > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Without JS a canvas-only scene would be an empty box: hide it. */
html:not(.js) .scene[data-requires-js],
.scene--failed[data-requires-js] {
  display: none;
}

.scene .evidence-caption {
  margin-top: 10px;
}

/* ----- Pause / play control (WCAG 2.2.2) ----- */
.scene__toggle {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 50%;
}

.scene__toggle svg {
  width: 28px;
  height: 28px;
  padding: 6px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.scene__toggle:hover svg {
  color: var(--accent);
  border-color: var(--accent);
}

.scene__toggle:focus-visible {
  outline: none;
}

.scene__toggle:focus-visible svg {
  box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent);
}

.scene__toggle .i-play { display: none; fill: currentColor; stroke: none; }
.scene__toggle--paused .i-play { display: inline; }
.scene__toggle--paused .i-pause { display: none; }

/* ----- Home hero loop (SVG enhancement) ----- */
.hero__artifact .loop-toggle {
  position: static;
  width: 44px;
  height: 44px;
  margin: -12px -10px -12px 0;
  flex: none;
}

.hero__artifact figcaption.loop-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hl-dim { transition: opacity 0.4s ease; }

@media (prefers-reduced-motion: reduce) {
  .scene__toggle { display: none; }
}

/* Chapter timelines stack by their actual column width, including when
   the handbook sidebar leaves a narrow stage on a desktop viewport. */
.scene[data-scene^="audio-"] {
  container-type: inline-size;
}

@container (width < 680px) {
  .scene[data-scene^="audio-"] > .scene__stage {
    aspect-ratio: var(--aspect-compact, 4 / 3);
  }
}

@container (400px <= width < 680px) {
  .scene[data-scene^="audio-"] > .scene__stage { aspect-ratio: 1.7; }
  .scene[data-scene="audio-incident"] > .scene__stage { aspect-ratio: 1.4; }
}
