/* ============================================================
   digiview.sh: the demo stage.
   The frame every scripted demo plays in. js/engine.js (mountStage)
   adds the caption, the step chips and the play button around the
   figure's .stage-view; the demo module fills .stage-view.
   Adapted from infradb.sh's stage, recoloured with Digiview's tokens.
   ============================================================ */

.stage {
  position: relative;
  margin: 0;
  overflow: hidden;
  text-align: left;
  border-radius: 24px;
  border: 1px solid var(--border);
  background:
    radial-gradient(80% 55% at 50% 0%, var(--glow), transparent 70%),
    radial-gradient(circle at 1px 1px, var(--dot-grid) 1px, transparent 0) 0 0 / 24px 24px,
    var(--stage-bg);
  box-shadow: var(--elev-lg);
  color: var(--text);
}

/* Caption: "01/05" and one sentence on what the viewer is seeing. */
.stage-caption { display: flex; gap: 14px; align-items: flex-start; padding: 22px 28px 0; }
.stage-count {
  flex: none; padding-top: 3px;
  font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em; font-feature-settings: "tnum";
  color: var(--text-brand);
}
.stage-text { min-height: 1.5em; font-size: 16px; line-height: 1.5; color: var(--text); }
.stage-text.in { animation: dv-fade-in var(--dur-crossfade) var(--curve-out), dv-rise var(--dur-spring-snappy) var(--spring-snappy); }

/* The demo itself. Demos give their body a fixed height so the page never reflows. */
.stage-view { position: relative; padding: 18px 28px 22px; }
.stage-poster { display: block; width: 100%; height: auto; }
.stage-view picture { display: block; }

/* Controls: play/pause and one chip per step (a progress bar + label). */
.stage-controls { display: flex; align-items: center; gap: 16px; padding: 14px 28px; border-top: 1px solid var(--line-soft); }
.stage-play {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-subtle); color: var(--text-brand);
  transition: background-color var(--dur-fade) var(--curve-out), scale var(--dur-spring-snappy) var(--spring-snappy);
}
.stage-play:hover { background: color-mix(in srgb, var(--brand) 22%, var(--brand-subtle)); }
.stage-play:active { scale: var(--motion-press-icon); transition-duration: var(--dur-press); }
.stage-play:focus-visible, .stage-chips button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; border-radius: 6px; }
.stage-play:focus-visible { border-radius: 50%; }
.stage-chips { list-style: none; display: flex; flex: 1; gap: 10px; min-width: 0; margin: 0; padding: 0; }
.stage-chips li { flex: 1; min-width: 0; }
.stage-chips button { display: block; width: 100%; padding: 6px 0; border: 0; background: none; cursor: pointer; font: inherit; text-align: left; }
.chip-bar { display: block; height: 4px; border-radius: 4px; overflow: hidden; background: var(--line-soft); }
.chip-bar i { display: block; height: 100%; border-radius: 4px; background: var(--brand); transform: scaleX(0); transform-origin: left; }
.chip-label {
  display: block; margin-top: 8px;
  font-size: 12.5px; font-weight: 500; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color var(--dur-fade) var(--curve-out);
}
.stage-chips button:hover .chip-label { color: var(--text); }
.stage-chips button[aria-current] .chip-label { color: var(--text); font-weight: 600; }

/* No-JS fallback content inside .stage-view (replaced when the demo mounts). */
.stage-fallback {
  display: grid; place-items: center; min-height: 260px; padding: 28px;
  border: 1px dashed var(--border); border-radius: 14px; background: var(--surface);
  color: var(--text-muted); font-size: 15px; text-align: center;
}

/* Demo failed to load: keep the frame tidy (home.js adds .is-failed). */
.stage.is-failed .stage-view { opacity: 1 !important; }

@media (max-width: 760px) {
  .stage { border-radius: 18px; }
  .stage-caption { padding: 16px 18px 0; }
  .stage-text { min-height: 3em; font-size: 15px; }
  .stage-view { padding: 14px 10px 12px; }
  .stage-controls { gap: 12px; padding: 12px 16px; }
  .chip-label { display: none; }
  /* Labels are hidden here, so each chip is just its bar: pad the button to a 44px-tall tap target. */
  .stage-chips { gap: 4px; }
  .stage-chips button { padding: 20px 3px; margin: -14px 0; }
  .stage-play { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .stage-text.in { animation: none; }
}
