/* ==================== PAPER THEATRE STAGE ====================
   Everything inside the stage is positioned by the film engine once per
   stop-motion frame, so nothing here uses smooth transitions on transform. */
.cinema-section {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 640px;
  max-height: 920px;
  overflow: hidden;
  background: var(--parchment-warm);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- Corner controls ---------- */
.corner-controls { position: absolute; top: 14px; right: 14px; z-index: 80; display: none; gap: 7px; }
.cinema-section.is-gate-opened .corner-controls { display: flex; }
.ink-icon-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid rgba(252, 248, 240, 0.52);
  background: rgba(58, 35, 27, 0.42);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  color: #fcf6ec; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.ink-icon-btn:hover { background: rgba(171, 40, 45, 0.78); border-color: #f4dfb3; }
.ink-icon-btn:active { transform: translateY(1px); }
.ink-icon-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layered paper set ---------- */
.paper-set { position: absolute; inset: 0; z-index: 1; pointer-events: none; }

.backdrop-plate { position: absolute; top: 0; left: 0; height: 100%; will-change: transform; }
.backdrop-plate img { height: 100%; width: auto; max-width: none; display: block; }

/* One cut-out piece. The wrapper carries parallax + pop-up pose, the image carries the hand jitter. */
.cutout {
  position: absolute;
  opacity: 0;
  transform-origin: 50% 100%;
  will-change: transform, opacity;
  backface-visibility: hidden;
}
.cutout.hangs-from-top { transform-origin: 50% 0%; }
.cutout img {
  display: block; width: 100%; height: auto;
  transform: translate(var(--jx, 0px), var(--jy, 0px)) rotate(var(--jr, 0deg));
}
.cutout.is-mirrored img { transform: translate(var(--jx, 0px), var(--jy, 0px)) rotate(var(--jr, 0deg)) scaleX(-1); }

/* ---------- Scene copy (stamped line by line) ---------- */
.scene-copy {
  position: absolute; top: 13.5%; left: 0; right: 0; z-index: 16;
  padding: 0 24px; text-align: center; pointer-events: none;
  will-change: transform;
}
.stamp-line { opacity: 0; will-change: transform, opacity; }

.type-kicker-italic {
  font-style: italic; font-weight: 400; font-size: clamp(16px, 4.3vw, 18.5px);
  color: var(--ink-mid); line-height: 1.3;
  text-shadow: 0 1px 10px rgba(252, 246, 236, 0.75);
}
/* The couple's names: script, set on a diagonal like the printed card below. */
.type-script {
  font-family: var(--font-script); font-size: clamp(58px, 16vw, 74px); line-height: 0.92;
  color: var(--vermilion); margin-top: 8px;
  text-shadow: 0 1px 12px rgba(252, 246, 236, 0.8);
}
.type-script .name-line { display: block; }
.type-script .name-line:first-child { text-align: left; padding-left: 9%; }
.type-script .name-line:last-child { text-align: right; padding-right: 7%; }
.type-display {
  font-weight: 500; font-size: clamp(30px, 8vw, 38px); color: var(--ink);
  line-height: 1.12; margin-top: 6px;
  text-shadow: 0 1px 14px rgba(252, 246, 236, 0.7);
}
.type-display.is-date { font-size: clamp(42px, 11.5vw, 54px); color: var(--vermilion); font-variant-numeric: lining-nums; }
.type-lotus-rule {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin: 10px auto 8px; color: var(--ochre);
}
.type-lotus-rule::before, .type-lotus-rule::after {
  content: ''; width: 36px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--ochre), transparent);
}
.type-meta { font-size: clamp(14.5px, 4vw, 16.5px); color: var(--ink); line-height: 1.5; overflow-wrap: anywhere; }

/* ---------- Characters (4-frame sprite strips, frame chosen by the engine) ---------- */
.sprite-box { position: relative; overflow: hidden; display: block; }
.sprite-strip {
  position: absolute; top: 0; left: 0; width: 400%; height: 100%;
  max-width: none; display: block; pointer-events: none;
  transform: translateX(calc(var(--sprite-frame, 0) * -25%));
}

.film-actor {
  position: absolute; bottom: 2.5%; left: 0; z-index: 22;
  opacity: 0; pointer-events: none; will-change: transform, opacity;
  filter: drop-shadow(-14px 8px 0 rgba(72, 42, 28, 0.22));
}
.actor-trasen { width: 52%; max-width: 225px; aspect-ratio: 751 / 1196; }
.actor-betrap { width: 54%; max-width: 235px; aspect-ratio: 798 / 1200; }
.actor-couple {
  width: 58%; max-width: 240px; aspect-ratio: 718 / 1184;
  left: 50%; bottom: 5.5%;
  transform-origin: 50% 100%; /* the engine adds translateX(-50%) to centre it */
}

/* ---------- Overlays ---------- */
#blossom-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 28; pointer-events: none; }

.film-grain {
  position: absolute; inset: -4px; z-index: 31; pointer-events: none;
  background-image: url('../assets/film/paper-grain-tile.webp'); background-size: 220px 220px;
  mix-blend-mode: multiply; opacity: 0.35;
}
.film-flicker { position: absolute; inset: 0; z-index: 32; pointer-events: none; background: #fff3d6; opacity: 0; }

.theatrical-spotlight {
  position: absolute; inset: 0; z-index: 30; pointer-events: none;
  background:
    radial-gradient(ellipse 84% 68% at 50% 42%, rgba(255, 250, 238, 0.14) 0%, rgba(255, 246, 230, 0) 58%, rgba(74, 42, 28, 0.3) 100%),
    linear-gradient(180deg, rgba(64, 34, 22, 0.16) 0%, transparent 14%, transparent 86%, rgba(62, 32, 20, 0.32) 100%);
}

/* ---------- Scene dots + scroll cue ---------- */
.scene-dots { position: absolute; bottom: 62px; left: 0; right: 0; z-index: 44; display: flex; justify-content: center; gap: 9px; }
.scene-dot {
  width: 8px; height: 8px; padding: 0; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(58, 35, 27, 0.55); background: rgba(252, 248, 240, 0.7);
}
.scene-dot.is-current { background: var(--vermilion); border-color: var(--vermilion); }

.scroll-down-cue { position: absolute; bottom: 16px; left: 0; right: 0; z-index: 42; display: flex; justify-content: center; visibility: hidden; }
.scroll-down-cue.is-visible { visibility: visible; }
.scroll-cue-btn {
  background: var(--parchment); border: none; color: var(--ink);
  border-radius: 3px; padding: 9px 18px;
  font-size: 15px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: -4px 4px 0 rgba(46, 26, 20, 0.28);
  animation: steppedBounce 1.6s steps(4, end) infinite;
}
.scroll-cue-btn:active { background: #fff; }
.scroll-cue-btn svg { width: 13px; height: 13px; stroke: var(--vermilion); fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
@keyframes steppedBounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(4px); } }

/* ---------- Opening gate ---------- */
.intro-scene {
  position: absolute; inset: 0; z-index: 60;
  transform-origin: 50% 68%; will-change: transform, opacity; cursor: pointer;
}
.intro-doors-stage {
  position: absolute; left: 25.6%; top: 49%; width: 48.8%; height: 39%;
  perspective: 1200px; transform-style: preserve-3d; z-index: 2;
}
.sliced-door { position: absolute; top: 0; height: 100%; width: 50.3%; object-fit: fill; display: block; will-change: transform; backface-visibility: hidden; }
.sliced-door.left { left: 0; transform-origin: left center; }
.sliced-door.right { right: 0; transform-origin: right center; }
.intro-gate-frame { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; z-index: 4; display: block; }

/* Night sky above the roof: stars twinkle in steps, a shooting star crosses now and then. */
.gate-sky { position: absolute; top: 0; left: 0; right: 0; height: 17%; z-index: 5; overflow: hidden; pointer-events: none; }
.gate-star {
  position: absolute; border-radius: 50%; background: #fff4cf;
  box-shadow: 0 0 5px 1px rgba(255, 240, 190, 0.75);
  animation: starTwinkle 2.2s steps(4, end) infinite;
}
.gate-star.is-sparkle {
  border-radius: 0; box-shadow: none;
  clip-path: polygon(50% 0, 58% 42%, 100% 50%, 58% 58%, 50% 100%, 42% 58%, 0 50%, 42% 42%);
  filter: drop-shadow(0 0 3px rgba(255, 240, 190, 0.9));
}
@keyframes starTwinkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.15; transform: scale(0.55); }
}
.gate-shooting-star {
  position: absolute; top: 8%; left: 104%; width: 74px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, #fff7dc, rgba(255, 247, 220, 0));
  transform: rotate(-24deg); opacity: 0;
  animation: shootingStar 7s steps(60, end) 1.5s infinite;
}
/* Visible for the first ~12% of each cycle, then waits off-stage. */
@keyframes shootingStar {
  0%   { transform: translate(0, 0) rotate(-24deg); opacity: 0; }
  2%   { opacity: 1; }
  10%  { opacity: 1; }
  13%  { transform: translate(-330px, 146px) rotate(-24deg); opacity: 0; }
  100% { transform: translate(-330px, 146px) rotate(-24deg); opacity: 0; }
}
/* Nothing in the sky keeps animating once the gate has opened. */
.cinema-section.is-film-running .gate-star, .cinema-section.is-film-running .gate-shooting-star { animation-play-state: paused; }

/* The only words on the gate. */
.intro-sky-title {
  position: absolute; top: 7%; left: 4%; right: 4%; z-index: 6; text-align: center;
  font-family: var(--font-script); font-size: clamp(54px, 15.5vw, 70px); line-height: 1; white-space: nowrap;
  color: var(--gold-bright); text-shadow: 0 3px 18px rgba(10, 10, 30, 0.9);
  visibility: hidden; /* shown once the script font has loaded, so it never jumps between fonts */
}
.fonts-ready .intro-sky-title { visibility: visible; }

/* Tapping finger in the middle of the doors; appears once the film's images have loaded. */
.tap-hint {
  position: absolute; left: 50%; top: 68.5%; z-index: 8; width: 60px; height: 60px;
  transform: translate(-50%, -50%); display: none; pointer-events: none; opacity: 0.8;
}
.cinema-section.is-ready .tap-hint { display: block; }
.cinema-section.intro-play .tap-hint { display: none; }
.tap-hint-ring {
  position: absolute; left: 15px; top: 4px; width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid var(--gold-bright);
  animation: tapRipple 1.2s steps(5, end) infinite;
}
.tap-hint-finger {
  position: absolute; left: 14px; top: 12px; width: 38px; height: 38px;
  /* Outline only, in the same gold as the title, so it reads as a hint rather than a sticker on the door. */
  fill: none; stroke: var(--gold-bright); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 1px 3px rgba(20, 6, 8, 0.7));
  animation: tapPress 1.2s steps(4, end) infinite;
}
@keyframes tapPress {
  0%, 100% { transform: translateY(5px); }
  35%      { transform: translateY(0) scale(0.95); }
  60%      { transform: translateY(5px); }
}
@keyframes tapRipple {
  0%, 30% { transform: scale(0.4); opacity: 0; }
  40%     { transform: scale(0.6); opacity: 0.9; }
  100%    { transform: scale(1.6); opacity: 0; }
}

.light-bloom { position: absolute; inset: 0; z-index: 65; background: #fcf6ec; opacity: 0; pointer-events: none; }

/* Door swing, push-in and bloom all move in visible steps, like the rest of the film. */
.cinema-section.intro-play .intro-scene { pointer-events: none; animation: dollyZoom 1.35s steps(14, end) 0.88s forwards; }
.cinema-section.intro-play .sliced-door.left  { animation: openDoorL 1.05s steps(10, end) 0.5s forwards; }
.cinema-section.intro-play .sliced-door.right { animation: openDoorR 1.05s steps(10, end) 0.5s forwards; }
.cinema-section.intro-play .light-bloom { animation: bloomFlash 0.95s steps(9, end) 1.65s forwards; }

@keyframes openDoorL { from { transform: rotateY(0deg); } to { transform: rotateY(-106deg); } }
@keyframes openDoorR { from { transform: rotateY(0deg); } to { transform: rotateY(106deg); } }
@keyframes dollyZoom {
  0%   { transform: scale(1); opacity: 1; }
  70%  { transform: scale(2.55); opacity: 1; }
  100% { transform: scale(3.25); opacity: 0; visibility: hidden; }
}
@keyframes bloomFlash { 0% { opacity: 0; } 38% { opacity: 0.88; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .film-grain, .film-flicker { display: none; }
  .scroll-cue-btn, .tap-hint-ring, .tap-hint-finger, .gate-star, .gate-shooting-star { animation: none; }
  .tap-hint-ring { opacity: 1; }
}
