/* stage.css: the desktop Q&A stage (pages/stage.js, #/stage, ADR 0023) · every colour and font from tokens.css.
   Grid: top bar 72 (title · guide status · knowledge + photos) / stage / captions band / dock. Stage = the guide at the
   full stage height (centre, or at a side while photos show) + the photo area (the rest). Cards and caption lines move with CSS
   transitions (not keyframes) so an interrupted answer can turn around mid-way; only transform, opacity and — during
   a transition only — a small blur (the 3D guide shares the GPU). */

body.stage-mode { background: var(--bg-deep); background-image: none; overflow: hidden; }
body.stage-mode main#view { padding: 0; margin: 0; max-width: none; min-height: 0; }

.stage {
  display: grid; grid-template-rows: 72px minmax(0, 1fr) auto auto; height: 100dvh;
  background: var(--bg-deep); color: var(--text); font-family: var(--font-ui);
}
.stage :focus-visible { outline: 2px solid var(--scan); outline-offset: 2px; }

/* ------------------------------------------------------------------ top bar */
.stage-top {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 24px;
  padding: 0 48px; border-bottom: 1px solid var(--line);
}
.stage-top .stage-meta { justify-self: end; }
.stage-count.off { visibility: hidden; }
.stage-title { margin: 0; font-family: var(--font-ui); font-size: 20px; font-weight: 600; letter-spacing: 0; }
.stage-meta { display: flex; align-items: center; gap: 28px; color: var(--muted); font-size: 14px; }
.stage-kb { display: inline-flex; align-items: center; gap: 8px; }
.stage-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.stage-dot.ok { background: var(--ok); }
.stage-count, .stage-kb-t { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ stage */
/* --stage-side = the guide's box: full stage height, about a third of the width. Home = centred; with photos it
   walks to a side (translateX by the distance to the edge: the stage is the full window width less 2 × 48 px) and
   the photo area takes the rest (owner 2026-11-17). */
.stage-main { position: relative; min-height: 0; margin: 8px 48px 0; --stage-side: clamp(320px, 28vw, 560px); }
.stage-guide {
  position: absolute; top: 0; bottom: 0; left: calc(50% - var(--stage-side) / 2); width: var(--stage-side);
  transition: transform var(--stage-walk-ms, 1600ms) cubic-bezier(.45, 0, .3, 1);
}
.stage-main.aside-left .stage-guide { transform: translateX(calc(-50vw + 48px + var(--stage-side) / 2)); }
.stage-main.aside-right .stage-guide { transform: translateX(calc(50vw - 48px - var(--stage-side) / 2)); }
.stage-body { position: relative; width: 100%; height: 100%; display: flex; justify-content: center; align-items: flex-end; }
.stage-body > .mb-sprite { height: 100%; width: auto; max-width: 100%; }
.stage-body > .mb { max-height: 100%; }

/* the photo area: the stage beside the guide · cards are placed by the page (lib/stage-photos.js layoutPhotos) */
.stage-photos { position: absolute; top: 0; bottom: 8px; left: 0; right: 0; }
.stage-main.aside-left .stage-photos { left: calc(var(--stage-side) + 32px); }
.stage-main.aside-right .stage-photos { right: calc(var(--stage-side) + 32px); }

/* image card: fades in from a little lower and smaller; leaves in place */
.stage-card {
  position: absolute; margin: 0; display: flex; flex-direction: column; overflow: hidden;
  border-radius: 18px; border: 1px solid var(--line); background: var(--panel-solid);
  opacity: 0; transform: translateY(16px) scale(.96); filter: blur(8px);
  transition: opacity 420ms var(--ease-out), transform 560ms var(--ease-out), filter 420ms var(--ease-out);
}
.stage-card.in { opacity: 1; transform: none; filter: none; }
.stage-card.out {
  opacity: 0; transform: scale(.97); filter: blur(6px);
  transition: opacity 240ms var(--ease-out), transform 240ms var(--ease-out), filter 240ms var(--ease-out);
}
.stage-img {
  flex: 1 1 auto; min-height: 0; width: 100%; display: block; padding: 0; border: 0; border-radius: 0;
  background: var(--track); cursor: zoom-in;
}
.stage-img img { width: 100%; height: 100%; object-fit: cover; display: block; user-select: none; }
.stage-img:focus-visible { outline-offset: -3px; }
.stage-cap {
  display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0 14px; height: 44px; flex: 0 0 44px;
  box-sizing: border-box; background: var(--panel-solid); font-size: 14px; line-height: 1.4;
}
.stage-cap-t { color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-src .th { font-family: var(--font-ui); letter-spacing: 0; text-transform: none; }
.stage-src .lbl { color: var(--muted); }
.stage-src {
  margin-left: auto; min-width: 0; color: var(--scan); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stage-badge {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--scan); color: var(--bg-deep); font: 600 12px/1 var(--font-hud);
}
.stage-badge.sm { min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; font-size: 11px; vertical-align: .2em; }

/* ------------------------------------------------------------------ captions band (under the stage) */
.stage-status {
  justify-self: center; margin: 0; padding: 6px 14px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--scan-soft); white-space: nowrap;
}
.stage-say { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 48px 0; min-width: 0; }
/* the question line keeps its space while hidden: nothing under the stage jumps when it appears */
.stage-asked { margin: 0; max-width: 100%; min-height: 1.6em; color: var(--muted); font-size: 16px; line-height: 1.6; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-asked.off { visibility: hidden; }
.stage-asked .lbl { color: var(--scan); }

/* captions: newest line at the bottom, older lines scroll up under a fade */
.stage-captions {
  position: relative; width: min(1100px, 100%); height: 104px; flex: 0 0 auto; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, var(--text) 32px);
  mask-image: linear-gradient(to bottom, transparent 0, var(--text) 32px);
}
.stage-hello { margin: 0; color: var(--muted); font-size: 18px; line-height: 1.6; text-align: center; }
.stage-hello[hidden] { display: none; }
.stage-lines { display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; }
.stage-line {
  margin: 0; color: var(--text); font-size: 22px; line-height: 1.5; text-align: center; overflow-wrap: anywhere;
  opacity: 0; transform: translateY(8px); filter: blur(2px);
  transition: opacity 280ms var(--ease-out), transform 280ms var(--ease-out), filter 280ms var(--ease-out), color 300ms ease;
}
.stage-line.in { opacity: 1; transform: none; filter: none; }
.stage-line.old { color: var(--muted); }
.stage-line.gone { opacity: 0; transition: opacity 240ms var(--ease-out); }
/* the guide's "please wait" line (plans/003): over the empty captions while it searches, gone when the answer starts */
.stage-filler {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0; pointer-events: none;
  color: var(--muted); font-size: 20px; line-height: 1.5; text-align: center;
  opacity: 0; transform: translateY(6px);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
.stage-filler.in { opacity: 1; transform: none; }
.stage-replay { flex: 0 0 auto; }
.stage-replay.off { visibility: hidden; }          /* keeps its space: the chips never shift */

/* ------------------------------------------------------------------ dock */
.stage-dock { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 48px 20px; }
.stage-chiprow { display: flex; align-items: center; justify-content: center; gap: 12px; max-width: 100%; min-height: var(--touch); }
.stage-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; max-width: 100%; min-height: var(--touch); }
.stage-chip {
  min-height: var(--touch); padding: 8px 18px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--panel); color: var(--text); font: 500 15px/1.4 var(--font-ui); cursor: pointer;
  transition: transform 160ms var(--ease-out), border-color 160ms ease;
}
.stage .stage-bar {
  position: static; width: min(760px, 100%); margin: 0; padding: 8px 8px 8px 20px;
  border: 1px solid var(--line-strong); border-radius: 32px; background: var(--panel-solid);
}
.stage-bar .qa-input { border-color: transparent; background: transparent; }
.stage-chip:active, .stage-replay:active, .stage .qa-send:active, .stage .qa-mic:active { transform: scale(.97); }
@media (hover: hover) and (pointer: fine) {
  .stage-chip:hover { border-color: var(--scan); }
  .stage-src:hover { text-decoration: underline; }
}

/* ------------------------------------------------------------------ hands-free listening line (ADR 0029) */
/* calm: a dot + one line while it waits for the name; the wave + a thin line running out during the follow-up
   window (transform only); a short privacy line under the bar while the mic is open */
.stage-hf {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 12px;
  width: min(760px, 100%); min-height: 32px; padding-bottom: 6px;
  color: var(--muted); font-size: 16px; line-height: 1.5; text-align: center;
}
.stage-hf[hidden], .stage-hf [hidden] { display: none; }
.stage-hf-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--scan); }
.stage-hf[data-mode="answering"] .stage-hf-dot, .stage-hf[data-mode="check"] .stage-hf-dot { background: var(--muted); }
.stage-hf[data-mode="error"] .stage-hf-dot { background: var(--danger); }
.stage .stage-hf-wave { flex: 0 0 72px; height: 24px; }
.stage-hf-wave span { height: 18px; }
.stage-hf[data-mode="follow_up"] .stage-hf-line, .stage-hf[data-mode="capturing"] .stage-hf-line { color: var(--text); }
.stage-hf-quiet { color: var(--muted); font-size: 14px; }
.stage-hf-bar {
  position: absolute; left: 0; right: 0; bottom: 0; height: 2px; overflow: hidden; border-radius: 1px;
  background: var(--track);
}
.stage-hf-bar.off { visibility: hidden; }
.stage-hf-bar i { display: block; height: 100%; background: var(--amber); transform-origin: left center; transform: scaleX(1); }
.stage-hf-privacy { margin: -4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; text-align: center; }
.stage-hf-privacy.off { visibility: hidden; }
.stage-hf-privacy[hidden] { display: none; }

/* ------------------------------------------------------------------ mic check (owner) */
.stage-check-open[hidden] { display: none; }
.stage-check {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 48px;
  background: var(--scrim); opacity: 0; transition: opacity 200ms var(--ease-out);
}
.stage-check.in { opacity: 1; }
.stage-check-card {
  width: min(680px, 100%); max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: 14px;
  padding: 24px 28px; border-radius: 18px; border: 1px solid var(--line-strong); background: var(--panel-solid);
}
.stage-check-card h2 { margin: 0; color: var(--scan); }
.stage-check-step { margin: 0; color: var(--text); font-size: 18px; line-height: 1.6; }
.stage-check-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.stage-check-row { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.stage-check-row .lbl { color: var(--muted); }
.stage-check-v { color: var(--text); font: 600 18px/1.2 var(--font-hud); font-variant-numeric: tabular-nums; }
.stage-check-tries { margin: 0; padding-left: 24px; display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow: auto; font-size: 15px; }
.stage-check-tries:empty { display: none; }
.stage-check-tries li.ok .lbl { color: var(--ok); }
.stage-check-tries li.no .lbl { color: var(--danger); }
.stage-check-note { margin: 0; color: var(--muted); font-size: 13px; }
.stage-check-act { display: flex; flex-wrap: wrap; gap: 10px; }
.stage-check-act [hidden] { display: none; }

/* ------------------------------------------------------------------ zoom dialog */
.stage-zoom {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 48px;
  background: var(--scrim); opacity: 0; transition: opacity 250ms var(--ease-out);
}
.stage-zoom.in { opacity: 1; }
.stage-zoom.out { opacity: 0; transition: opacity 180ms var(--ease-out); }
.stage-zoom-fig {
  margin: 0; max-width: min(1280px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden;
  border-radius: 18px; border: 1px solid var(--line); background: var(--panel-solid);
  transform: scale(.96); transition: transform 250ms var(--ease-out);
}
.stage-zoom.in .stage-zoom-fig { transform: none; }
.stage-zoom.out .stage-zoom-fig { transform: scale(.98); transition: transform 180ms var(--ease-out); }
.stage-zoom-fig img { display: block; max-width: 100%; max-height: calc(100dvh - 96px - 44px); object-fit: contain; }
.stage-zoom-x {
  position: absolute; top: 20px; right: 20px; width: 48px; height: 48px; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--panel-solid); color: var(--text);
  transition: transform 160ms var(--ease-out);
}
.stage-zoom-x:active { transform: scale(.97); }

/* ------------------------------------------------------------------ narrow / touch: no stage */
.stage-narrow { display: flex; flex-direction: column; align-items: flex-start; gap: 16px; }

/* reduced motion: opacity only (the guide keeps its own still frames) */
@media (prefers-reduced-motion: reduce) {
  .stage-guide { transition: none; }
  .stage-card, .stage-card.out, .stage-line,
  .stage-zoom-fig, .stage-zoom.out .stage-zoom-fig { transform: none; filter: none; }
  .stage-chip:active, .stage-replay:active, .stage .qa-send:active, .stage .qa-mic:active, .stage-zoom-x:active { transform: none; }
  .stage-filler { transform: none; }   /* opacity stays: it carries the meaning */
  /* hands-free: no running line, no moving wave; the words say it */
  .stage-hf-bar { display: none; }
  .stage-hf-bar i, .stage-hf-wave span { transition: none; transform: none; }
  .stage-check { transition: none; }
}
