/* ============================================================
   THE OPENING SCENE
   Always exactly one screen tall — nothing to scroll.
   Sizes that depend on the screen (--D cake size, --bannerH,
   --tileH, decoration spots…) are set by layoutStage() in main.js.
   ============================================================ */
.stage {
  --D: 220px;
  --bannerH: 120px;
  --gw: clamp(64px, 19vw, 170px);   /* width of a gang column on phones */
  --side: 8px;                       /* message text inset */
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 540px;                 /* phones held sideways: scroll a little instead of squashing the scene */
  display: flex; flex-direction: column; align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 8px) max(16px, env(safe-area-inset-left, 0px));
  background-color: #000;
  transition: background-color 5s linear;
  overflow: hidden;
}
.stage.lights-on { background-color: var(--peach); }
.stage.party { animation: peach-alive 8s linear infinite; }
@keyframes peach-alive {
  0%, 50%, 100% { background-color: var(--peach); }
  25% { background-color: var(--peach-2); }
  75% { background-color: var(--peach-3); }
}
.stage > .bulbs, .banner-row, .cake-zone, .dance-floor, .controls { position: relative; z-index: 2; flex: none; }
.stage > .bulbs { padding-right: 34px; }        /* room for the music button */
.stage > .bulbs .bulb { width: clamp(28px, 7vw, 42px); }

/* ---------- banner ---------- */
.banner-row { height: var(--bannerH); margin-top: 4px; display: flex; justify-content: center; }
.banner {
  height: 100%; width: auto; max-width: none;
  filter: drop-shadow(0 8px 14px rgba(74, 47, 39, .18));
  transform: translateY(-160%) rotate(-6deg);
  opacity: 0;
}
.banner.down { animation: banner-come 4s ease-out forwards; }
@keyframes banner-come {
  0%   { transform: translateY(-160%) rotate(-6deg); opacity: 0; }
  40%  { opacity: 1; }
  70%  { transform: translateY(6%) rotate(2deg); opacity: 1; }
  85%  { transform: translateY(-2%) rotate(-1deg); opacity: 1; }
  100% { transform: none; opacity: 1; }
}

/* ---------- decorations (positions come from layoutStage) ---------- */
.decor-layer { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.decorated .decor.tappable { pointer-events: auto; -webkit-tap-highlight-color: transparent; }   /* only once they've popped in */
.decorated .decor.has-sound { cursor: pointer; }    /* the talking dog keeps a normal cursor: it's a secret */
.decor-layer.talking-now { z-index: 46; }
.decor-pop {
  position: absolute; z-index: 2; max-width: min(64vw, 260px); width: max-content; text-align: center;
  background: #fff; color: var(--ink); line-height: 1.25;
  font-family: var(--display); font-weight: 600; font-size: clamp(.72rem, 2.8vw, .9rem);
  padding: .35em .8em; border-radius: 14px;
  box-shadow: 0 4px 10px rgba(74, 47, 39, .22);
  animation: pop-in .35s cubic-bezier(.3, 1.6, .5, 1) both; transition: opacity .4s;
}
.decor-pop.bye { opacity: 0; }
.decor {
  position: absolute; left: var(--x); top: var(--y); width: var(--s); height: var(--s);
  object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(74, 47, 39, .2));
  opacity: 0; transform: scale(.3) rotate(0deg);
  transition: left .4s, top .4s, width .4s, height .4s;
}
.decorated .decor {
  animation: decor-pop .7s cubic-bezier(.3, 1.6, .5, 1) forwards, decor-sway 4s ease-in-out infinite;
  animation-delay: calc(var(--i) * .18s + .9s), calc(var(--i) * .18s + 1.6s);
}
@keyframes decor-pop { to { opacity: 1; transform: rotate(var(--rot)); } }
@keyframes decor-sway {
  0%, 100% { opacity: 1; transform: rotate(var(--rot)); }
  50% { opacity: 1; transform: rotate(calc(var(--rot) * -1)) translateY(-3px); }
}

/* ---------- middle: gang | neon text + cake | gang ---------- */
.cake-zone {
  width: 100%;
  flex: 1 1 0; min-height: 0;
  display: flex; justify-content: center;
}
.centre {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  width: calc(100% - 2 * var(--gw) - 4px);
  height: 100%;
}
.wide .centre { width: 44%; }

.bdtext {
  flex: 1 1 0; min-height: 0;
  width: 100%; max-width: 380px;
  object-fit: contain;
  opacity: 0; transform: scale(.6) rotate(-4deg);
  transition: opacity 1s, transform 1.1s cubic-bezier(.3, 1.5, .5, 1);
}
.bdtext.show { opacity: 1; transform: none; animation: neon 2.4s ease-in-out 1.2s infinite; }
.bdtext.show.quiet { opacity: 0; transition-duration: .5s; }
@keyframes neon { 0%, 100% { filter: drop-shadow(0 6px 10px rgba(74, 47, 39, .2)); transform: translateY(0) rotate(-1deg); } 50% { filter: drop-shadow(0 0 18px rgba(255, 255, 255, .9)); transform: translateY(-6px) rotate(1deg); } }

/* the picture cake (plain → candles). Also used by the ending section. */
.cake-img {
  position: relative; flex: none;
  width: var(--D); aspect-ratio: 560 / 694;
  padding: 0; border: 0; background: none;
  opacity: 0; transform: translateY(20px);
  transition: opacity 1.2s, transform 1.2s;
}
.cake-img.show, .cake-img.cake-final { opacity: 1; transform: none; }
.cake-img img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; }
.cake-img .cake-lit { opacity: 0; transition: opacity .9s; }
.cake-img.lit .cake-lit { opacity: 1; }
.cake-img::after { /* warm candle glow */
  content: ''; position: absolute; left: 32%; right: 32%; top: -8%; height: 24%;
  background: radial-gradient(ellipse at center, rgba(255, 200, 90, .55), rgba(255, 200, 90, 0) 70%);
  opacity: 0; transition: opacity .9s; pointer-events: none;
}
.cake-img.lit::after { opacity: 1; animation: flicker 1.4s ease-in-out infinite alternate; }
@keyframes flicker { from { transform: scale(1); opacity: .75; } to { transform: scale(1.08) translateY(-3px); opacity: 1; } }

/* the gang */
.gang {
  position: absolute; top: 0; bottom: 0; width: var(--gw);
  display: flex; flex-direction: column; justify-content: space-evenly;
  pointer-events: none; z-index: 3;
  transition: opacity .6s;
}
.gang-left { left: 0; }
.gang-right { right: 0; }
.gang-member {
  position: relative; margin: 0; flex: 1 1 0; min-height: 0;
  opacity: 0; transform: translateY(40px) scale(.5);
}
.gang-member img {
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(74, 47, 39, .22));
}
.has-gang .gang-member {
  animation: gang-pop .8s cubic-bezier(.3, 1.6, .5, 1) forwards;
  animation-delay: calc(var(--i) * .22s);
}
.has-gang .gang-member img {
  animation: gang-bob 2.6s ease-in-out infinite;
  animation-delay: calc(var(--i) * .3s + 1s);
}
@keyframes gang-pop { to { opacity: 1; transform: none; } }
@keyframes gang-bob { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg) translateY(-4px); } }
.gang-says {
  position: absolute; top: 0; z-index: 1;
  background: #fff; color: var(--ink);
  font-family: var(--display); font-weight: 600; font-size: clamp(.66rem, 2.5vw, .9rem);
  white-space: nowrap; padding: .25em .7em; border-radius: 999px;
  box-shadow: 0 4px 10px rgba(74, 47, 39, .18);
  opacity: 0;
}
.gang-left .gang-says { left: 0; }
.gang-right .gang-says { right: 0; }
.has-gang .gang-says {
  animation: says 7s ease forwards;
  animation-delay: calc(var(--i) * 1.2s + 1s);     /* one by one */
}
/* pops in, stays ~6 seconds, then fades */
@keyframes says { 0% { opacity: 0; transform: translateY(6px) scale(.8); } 5%, 92% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* wide screens: the gang stands in a row on each side of the cake */
.wide .gang {
  top: auto; bottom: 0; height: var(--gangH, 200px);
  width: calc(50% - var(--D) / 2 - 24px);
  flex-direction: row; align-items: flex-end; gap: 8px;
}
.wide .gang-left { justify-content: flex-end; }
.wide .gang-right { justify-content: flex-start; }
.wide .gang-member { flex: 0 1 auto; height: 100%; max-width: 33%; }
.wide .gang-member:nth-child(2) { height: 86%; }
.wide .gang-member img { width: auto; max-width: 100%; object-position: bottom; }

/* while the message plays, the gang steps back so the words are clear */
.talking .gang { opacity: .28; }

/* the line-by-line message — sits only over the middle column */
.message {
  position: absolute; top: 0; bottom: 0; left: var(--side); right: var(--side);
  display: grid; place-items: center;
  pointer-events: none; z-index: 4;
}
.message p {
  margin: 0;
  font-family: var(--display); font-weight: 600;
  font-size: clamp(1.15rem, 5vw, 2.2rem); line-height: 1.25;
  text-transform: uppercase; text-align: center;
  color: var(--ink);
  text-shadow: 0 0 12px var(--peach), 0 0 4px var(--peach);
  opacity: 0; transform: translateY(10px);
  transition: opacity .8s, transform .8s;
}
.message p.show { opacity: 1; transform: none; }

.dark-intro {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  color: #fff; padding: 0 8px; transition: opacity 1.5s;
}
.dark-intro h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(1.7rem, 6vw, 2.6rem); margin: .2rem 0 .4rem; }
.dark-intro p { margin: 0; opacity: .8; }
.dark-intro .hand { color: var(--peach); opacity: 1; font-size: 1.8rem; }
.stage.lights-on .dark-intro { opacity: 0; pointer-events: none; }

/* ---------- dance floor (GIF videos) — space is reserved from the start ---------- */
.dance-floor {
  width: 100%; height: var(--danceH, 0px);
  text-align: center;
  visibility: hidden;
  transition: opacity 1s;
}
.dance-floor.on { visibility: visible; }
.dance-floor > .hand { margin: 4px 0 2px; font-size: 1.25rem; line-height: 20px; height: 22px; opacity: 0; transition: opacity .6s; }
.dance-floor.on > .hand { opacity: 1; }
.dance-grid { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.dance-row { display: flex; justify-content: center; align-items: center; gap: 8px; }
.dance-tile {
  width: calc(var(--tileH) * var(--ar) + 10px);
  background: #fff; padding: 5px; border-radius: 8px;
  box-shadow: 0 6px 14px rgba(74, 47, 39, .18);
  opacity: 0; transform: translateY(30px) scale(.7) rotate(var(--r));
}
.dance-floor.on .dance-tile {
  animation: tile-in .7s cubic-bezier(.3, 1.5, .5, 1) forwards;
  animation-delay: calc(var(--i) * .15s);
}
@keyframes tile-in { to { opacity: 1; transform: rotate(var(--r)); } }
.dance-floor.gone { opacity: 0; transition: opacity .8s; }
.dance-tile .tenor-gif-embed { border-radius: 4px; overflow: hidden; }
.dance-tile .tenor-gif-embed a { font-size: .7rem; color: var(--ink-soft); }

/* ---------- the step button ---------- */
.controls { height: 64px; display: flex; align-items: center; justify-content: center; }
.btn-stage { opacity: 0; transition: opacity .6s; white-space: nowrap; }
.btn-stage.visible { opacity: 1; }

/* ---------- balloons ---------- */
/* the four that stay: drift slowly *behind* everything so they never cover anything */
.balloon-layer { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.balloon-one {
  position: absolute; left: 0; top: 0; width: var(--bw, 50px);
  transition: transform 9s ease-in-out;
  filter: drop-shadow(0 6px 8px rgba(74, 47, 39, .15));
}
.balloon-one img { width: 100%; animation: bob 3.2s ease-in-out infinite; transform-origin: 50% 100%; }
.balloon-one:nth-child(even) img { animation-duration: 4s; }
@keyframes bob { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg) translateY(-6px); } }

/* the big release: bunches float up across the whole screen, in front */
.bunch-layer { position: absolute; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.bunch { position: absolute; top: 100%; filter: drop-shadow(0 8px 12px rgba(74, 47, 39, .18)); }

/* easter egg: each tap on the "19" gives it a little boop */
.bdtext.show.boop { animation: boop .35s ease, neon 2.4s ease-in-out .4s infinite; }
@keyframes boop { 40% { transform: scale(.9) rotate(-4deg); } 70% { transform: scale(1.06) rotate(2deg); } }

/* "Skip intro" — top-left pill, only for returning visitors */
.skip-intro {
  position: absolute; left: 10px; top: calc(env(safe-area-inset-top, 0px) + 10px); z-index: 45;
  border: 1.5px solid rgba(255, 255, 255, .55); background: rgba(255, 255, 255, .12);
  color: #fff; border-radius: 999px; padding: .4rem .9rem;
  font-family: var(--display); font-weight: 600; font-size: .85rem;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  transition: background .2s;
}
@media (hover: hover) { .skip-intro:hover { background: rgba(255, 255, 255, .25); } }

/* tap a gang member → wiggle + speech bubble */
.has-gang .gang-member { pointer-events: auto; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.gang-member img.wiggle { animation: wiggle .6s ease !important; }
@keyframes wiggle {
  0%, 100% { transform: rotate(0) scale(1); }
  20% { transform: rotate(-14deg) scale(1.08); } 40% { transform: rotate(12deg) scale(1.1); }
  60% { transform: rotate(-8deg) scale(1.05); } 80% { transform: rotate(5deg); }
}
.gang-pop {
  position: absolute; top: -6px; z-index: 5;
  background: #fff; color: var(--ink); white-space: nowrap;
  font-family: var(--display); font-weight: 600; font-size: clamp(.68rem, 2.6vw, .9rem);
  padding: .3em .75em; border-radius: 999px;
  box-shadow: 0 4px 10px rgba(74, 47, 39, .22);
  animation: pop-in .35s cubic-bezier(.3, 1.6, .5, 1) both; transition: opacity .4s, transform .4s;
}
.gang-left .gang-pop { left: 0; }
.gang-right .gang-pop { right: 0; }
.wide .gang-pop { left: 50%; right: auto; transform: translateX(-50%); }
.gang-pop.bye { opacity: 0; }
@keyframes pop-in { from { opacity: 0; scale: .6; } to { opacity: 1; scale: 1; } }
.gang.talking-now { z-index: 6; }
