/* The stage and the two presentation modes: world (page-built ivory stage) and plaza (clay photo
   plate). Sizes use container units of the stage so desktop shows a centered phone-width column.
   The stage is exactly one screen tall; the written details follow below it (details.css). */
.stage {
  position: relative; height: 100vh; height: 100svh; margin: 0 auto; max-width: 520px; overflow: hidden;
  container-type: size; background: var(--ivory);
  /* Character geometry. --char-h is the couple's on-screen height (head to feet) and --feet-b
     the floor line under their feet, measured from the stage bottom (same values as the v1
     layout). The clip box (--rig-h, --rig-b) is derived from where the couple sits inside the
     clip (CONFIG.framing, set by main.js as --clip-feet / --clip-char): a zoomed-out clip is
     simply drawn bigger, its green margins are transparent and clipped by the stage. */
  --clip-feet: 0.84;
  --clip-char: 0.51;
  --clip-crop: 0.93; /* never show less than this share of the clip width (hands stay in) */
  --clip-cx: 0.485; /* horizontal center of the couple inside the clip */
  --char-h: calc(min(64cqh, 150cqw) * 0.74); /* wanted on-screen couple height (v1 size) */
  --feet-b: calc(12cqh + min(64cqh, 150cqw) * 0.125);
  --rig-h: min(calc(var(--char-h) / var(--clip-char)), calc(100cqw / var(--clip-crop) / 0.5625));
  --char-on: calc(var(--rig-h) * var(--clip-char)); /* actual on-screen couple height */
  --rig-w: calc(var(--rig-h) * 0.5625);
  --rig-b: calc(var(--feet-b) - var(--rig-h) * (1 - var(--clip-feet)));
  --clip-h: max(100cqh, 177.78cqw);
  --clip-w: calc(var(--clip-h) * 0.5625);
  --edge-l: calc(var(--space-2) + var(--safe-l));
  --edge-r: calc(var(--space-2) + var(--safe-r));
  --garland-h: calc(18.4cqw + var(--safe-t)); /* the garland SVG is 360 x 66 at full stage width */
}
.scenery { position: absolute; inset: 0; }
.plaza { display: none; }

/* ---------- world: ivory stage, gold rings behind the couple, a quiet floor ---------- */
.rings {
  position: absolute; left: 50%; bottom: calc(var(--feet-b) + var(--char-on) * 0.51);
  width: min(96cqw, calc(var(--char-on) * 1.22)); aspect-ratio: 1; translate: -50% 50%;
  border-radius: 50%; background: rgba(255, 253, 248, 0.75);
  border: 1px solid rgba(var(--gold-rgb), 0.5);
  box-shadow: 0 0 0 9px var(--ivory), 0 0 0 10px rgba(var(--gold-rgb), 0.28);
}
.rings::before, .rings::after {
  content: ""; position: absolute; border-radius: 50%; pointer-events: none;
}
.rings::before { inset: -9%; border: 1px solid rgba(var(--gold-rgb), 0.16); }
.rings::after { inset: 5%; border: 1px solid rgba(var(--gold-rgb), 0.22); }
.ground {
  position: absolute; left: 0; right: 0; bottom: 0; height: 24%; background: var(--ivory-deep);
  border-top: 1px solid rgba(var(--gold-rgb), 0.6);
}
.ground::before { /* second, fainter hairline: an engraved double rule */
  content: ""; position: absolute; left: 0; right: 0; top: 5px; height: 1px;
  background: rgba(var(--gold-rgb), 0.3);
}

/* ---------- title ---------- */
.title {
  position: absolute; z-index: 5; left: var(--edge-l); right: var(--edge-r);
  top: calc(var(--garland-h) + 2px); /* just under the garland */
  text-align: center; transition: opacity 0.25s ease;
}
.title h1 {
  font-size: clamp(2.5rem, 12.5cqw, 3.75rem); margin: 0; overflow-wrap: anywhere; color: var(--ink);
  line-height: 1.12;
}
.title p { margin: 0; }
.for { /* "Una invitación especial para", above the guest's name */
  color: var(--ink-soft); font-size: var(--text-xs); font-weight: 600;
  letter-spacing: var(--track); text-transform: uppercase; line-height: 1.4;
  padding-left: var(--track); /* tracking leaves a trailing space: keep it centred */
}
.date {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  margin-top: 0.125rem !important; color: var(--ink-soft);
  font-size: var(--text-sm); font-weight: 600; letter-spacing: var(--track); text-transform: uppercase;
}
.date::before, .date::after { content: ""; width: 1.75rem; height: 1px; background: rgba(var(--gold-rgb), 0.8); }
.date::after { margin-left: calc(-1 * var(--track)); } /* tracking leaves a trailing space */

/* ---------- characters ---------- */
.rig { /* above the garland (4) and title (5): a raised hand is never covered by them */
  position: absolute; z-index: 6; bottom: var(--rig-b); translate: -50% 0;
  left: calc(50% + (0.5 - var(--clip-cx)) * var(--rig-w)); /* the couple's center on the stage center */
  height: var(--rig-h); aspect-ratio: 9 / 16;
}
.actors {
  position: absolute; inset: 0;
  transform: translateY(115%); transition: transform 0.9s cubic-bezier(.2, 1.15, .4, 1);
}
.actors.in { transform: none; }
.actors canvas { position: relative; width: 100%; height: 100%; display: block; }
/* Soft contact shadow centered on the feet line (CONFIG.framing.feetY). */
.shadow {
  position: absolute; left: 50%; bottom: calc((1 - var(--clip-feet)) * 100%);
  width: calc(var(--char-on) * 0.6); height: calc(var(--char-on) * 0.068); translate: -50% 50%;
  border-radius: 50%; background: rgba(var(--ink-rgb), 0.22); filter: blur(7px);
}

/* ---------- bubble placement: above the heads (~24% from the clip top) ---------- */
.bubble { z-index: 7; bottom: calc(var(--feet-b) + var(--char-on) * 0.89); }
.bubble[data-speaker="manuel"] { left: max(var(--edge-l), calc(50cqw - var(--char-on) * 0.47)); }
.bubble[data-speaker="carolina"] { right: max(var(--edge-r), calc(50cqw - var(--char-on) * 0.47)); }

/* ---------- final screen: Sí / No, details link, replay (absent until the S09 loop starts) ---------- */
.final {
  position: absolute; z-index: 8; left: 0; right: 0; bottom: calc(var(--safe-b) + var(--space-2));
  display: flex; flex-direction: column; align-items: center; gap: var(--space-1);
  padding: 0 var(--edge-r) 0 var(--edge-l);
}
.final[hidden] { display: none; }
.to-details {
  display: inline-flex; align-items: center; gap: 0.5rem; min-height: 44px; padding: 0 var(--space-2) 0 calc(var(--space-2) + var(--track));
  color: var(--ink); text-decoration: none; font-size: var(--text-sm); font-weight: 700;
  letter-spacing: var(--track); text-transform: uppercase;
  border-radius: 999px; background: rgba(255, 253, 248, 0.86);
}
.to-details svg { width: 12px; height: 8px; color: var(--rose); animation: nudge 1.8s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(3px); } }
.replay {
  position: absolute; right: calc(var(--safe-r) + 12px); bottom: 0;
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 1px solid rgba(var(--gold-rgb), 0.7); background: rgba(255, 253, 248, 0.92);
  font: 600 1.25rem/1 var(--serif); color: var(--ink); display: grid; place-items: center;
}
.final.pop .btn-yes { animation: rise 0.7s var(--ease-out) 0.05s backwards; }
.final.pop .btn-no { animation: rise 0.7s var(--ease-out) 0.25s backwards; }
.final.pop :is(.to-details, .replay) { animation: rise 0.6s var(--ease-out) 0.6s backwards; }
.final.pop .to-details svg { animation: nudge 1.8s ease-in-out 1.2s infinite; }
.final .btn.pressed { animation: squish 0.35s var(--ease-out); } /* after the rise so a tap wins */
@keyframes rise {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

/* ---------- mute toggle (bottom-left; replay mirrors it bottom-right) ---------- */
.mute {
  position: absolute; z-index: 11; left: calc(var(--safe-l) + 12px); bottom: calc(var(--safe-b) + var(--space-2));
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 1px solid rgba(var(--gold-rgb), 0.7); background: rgba(255, 253, 248, 0.92);
  font-size: 1.125rem; line-height: 1; display: grid; place-items: center;
}
[data-phase="envelope"] .mute { display: none; }

/* ---------- debug skip (?debug only; shown while clips play toward an answer box) ---------- */
.debug-skip {
  display: none; position: absolute; z-index: 12; right: calc(var(--safe-r, 0px) + 12px);
  top: calc(var(--safe-t) + 12px); min-height: 44px; padding: 0 var(--space-2); cursor: pointer;
  border: 1px dashed #c0392b; border-radius: 22px; background: rgba(255, 253, 248, 0.92);
  color: #c0392b; font: 600 0.875rem/1 system-ui, sans-serif;
}
:is([data-phase="show"], [data-phase="party"]) .debug-skip { display: block; }

/* ---------- plaza mode: full-bleed clay plate, title on an ivory card ---------- */
[data-mode="plaza"] .stage { background: #e9c9a3; }
[data-mode="plaza"] .plaza {
  display: block; position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: center bottom;
}
[data-mode="plaza"] :is(.rings, .garland, .ground) { display: none; }
/* The green clips are framed ~1.3x tighter than the plate, so the rig is scaled to stand the
   couple where the plate's own figures stood (feet ~18% above its bottom edge). */
[data-mode="plaza"] .stage { --char-h: calc(var(--clip-h) * 0.5624); --feet-b: calc(var(--clip-h) * 0.176); }
[data-mode="plaza"] .actors { transform: none; opacity: 0; transition: opacity 0.8s ease; }
[data-mode="plaza"] .actors.in { opacity: 1; }
[data-mode="plaza"] .title {
  top: calc(var(--safe-t) + var(--space-2)); width: fit-content; max-width: calc(100% - 2 * var(--space-2));
  margin: 0 auto; padding: var(--space-1) var(--space-3);
  background: rgba(255, 253, 248, 0.94); border: 1px solid rgba(var(--gold-rgb), 0.7); border-radius: 14px;
  box-shadow: 0 12px 26px -16px rgba(var(--ink-rgb), 0.55);
}
[data-mode="plaza"] .title h1 { font-size: clamp(2rem, 10cqw, 3rem); }
[data-mode="plaza"] :is(.date, .for) { color: var(--ink); }

/* ---------- short screens: tighter title so the heads keep their room ---------- */
@container (max-height: 700px) {
  [data-phase="show"] .date { display: none; }
  [data-mode="plaza"][data-bubble="on"] .title { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .actors, [data-mode="plaza"] .actors { transform: none; transition: opacity 0.3s ease; }
  .actors:not(.in) { opacity: 0; }
  .final.pop :is(.btn-yes, .btn-no, .to-details, .replay) { animation: rise 0.3s ease backwards; }
  .final .btn.pressed, .to-details svg, .final.pop .to-details svg { animation: none; }
}

/* Camera punch-in on the "¡Espérate!" cut (scenes.json "punch"). */
#screen.punch { animation: punch 0.45s cubic-bezier(.2, .9, .3, 1); }
@keyframes punch {
  0% { transform: scale(1.12); filter: brightness(1.15); }
  100% { transform: scale(1); filter: none; }
}
@media (prefers-reduced-motion: reduce) { #screen.punch { animation: none; } }

/* Softened cut into a clip whose start pose doesn't match (scenes.json "soften"): a warm ivory
   flash that covers the change and fades out. */
.soft-flash {
  position: absolute; inset: 0; z-index: 6; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 55%, #fffaf0 0%, #fbf3e4 55%, rgba(251, 243, 228, 0.9) 100%);
}
.soft-flash.on { animation: soft-flash 0.65s ease-out; }
@keyframes soft-flash {
  0% { opacity: 0.95; }
  35% { opacity: 0.7; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .soft-flash.on { animation-duration: 0.3s; } }
