/* ============================================================
   infradb.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 dendrite.sh's stage (css/home.css there), recoloured
   with InfraDB's dark tokens (css/site.css :root).
   ============================================================ */

.stage {
  position: relative;
  margin: 0;
  overflow: hidden;
  text-align: left;
  border-radius: 20px;
  border: 1px solid rgba(199, 212, 195, 0.1);
  background:
    radial-gradient(80% 55% at 50% 0%, rgba(180, 196, 176, 0.1), transparent 70%),
    radial-gradient(circle at 1px 1px, rgba(245, 246, 242, 0.045) 1px, transparent 0) 0 0 / 24px 24px,
    var(--stage-bg);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  color: var(--ink);
}

/* Caption: "01/06" 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-family: var(--font-mono); font-size: 12px; font-weight: 500; letter-spacing: 0.02em;
  color: var(--sage-text);
}
.stage-text { min-height: 1.5em; font-size: 16px; line-height: 1.5; color: rgba(245, 246, 242, 0.88); }
.stage-text.in { animation: stage-cap-in 0.5s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes stage-cap-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 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;
  border-radius: 12px; border: 1px solid var(--line);
}

/* 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 rgba(245, 246, 242, 0.06);
}
.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: rgba(245, 246, 242, 0.09); color: var(--ink);
  transition: background 0.15s ease;
}
.stage-play:hover { background: rgba(245, 246, 242, 0.17); }
.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: 3px; border-radius: 3px; overflow: hidden; background: rgba(245, 246, 242, 0.11); }
.chip-bar i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--sage), var(--accent));
  transform: scaleX(0); transform-origin: left;
}
.chip-label {
  display: block; margin-top: 8px;
  font-size: 12.5px; font-weight: 500; color: var(--ink-subtle);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color 0.2s ease;
}
.stage-chips button:hover .chip-label { color: var(--ink-muted); }
.stage-chips button[aria-current] .chip-label { color: var(--ink); }

/* ---------- Optional chrome demos may use ----------
   A browser window:  .stage-window > .stage-window-bar (.stage-lights + .stage-url) + .stage-window-body
   A terminal window: .stage-window.is-term (same parts; the body is the demo's own palette) */
.stage-window {
  max-width: 1120px; margin: 0 auto; overflow: hidden;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 30px 80px rgba(0, 0, 0, 0.45);
}
.stage-window-bar {
  position: relative; display: flex; align-items: center; gap: 12px;
  height: 34px; padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.stage-lights { display: flex; gap: 6px; flex: none; }
.stage-lights i { width: 10px; height: 10px; border-radius: 50%; background: #3a444d; }
.stage-url {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 0; max-width: 60%; margin: 0 auto; padding: 2px 14px;
  border-radius: 6px; background: var(--bg); color: var(--ink-subtle);
  font-family: var(--font-mono); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stage-window-bar::after { content: ""; flex: none; width: 42px; } /* balances the lights so the URL sits centred */
.stage-window-body { position: relative; overflow: hidden; }
.stage-window.is-term .stage-window-bar { background: #0f1629; border-bottom-color: #26345a; }
.stage-window.is-term { background: #0b1020; border-color: #26345a; }

/* 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(--line); border-radius: 12px; background: rgba(15, 20, 25, 0.6);
  color: var(--ink-muted); font-size: 15px; text-align: center;
}
.stage-fallback pre {
  margin: 0; font-family: var(--font-mono); font-size: 12px; line-height: 1.45;
  color: #c9d3ea; text-align: left; white-space: pre; overflow: hidden;
}

/* 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: 16px; }
  .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 41px-tall
     tap target (negative margins take it back, so the bar stays put) and widen it into
     the gap (4px gap + 3px padding a side keeps 10px between the bars). */
  .stage-chips { gap: 4px; }
  .stage-chips button { padding: 19px 3px; margin: -13px 0; }
  .stage-play { width: 40px; height: 40px; }
  .stage-url { max-width: 70%; }
}

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