/* styles/animations.css — all motion lives here.
   Class names match js/main.js, js/gallery.js, js/letter.js, js/proposal.js */

/* ---------- Page entrance / exit ---------- */
@keyframes pageIn { from { opacity: 0; } to { opacity: 1; } }
body { animation: pageIn .7s var(--ease) both; }
body { transition: opacity .38s var(--ease); }
body.page-leaving { opacity: 0; }

/* ---------- Scroll reveal ---------- */
.reveal {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 1s var(--ease), transform 1s var(--ease);
}
.reveal.is-visible { opacity: 1; transform: none; }
.cards .reveal:nth-child(2), .nicknames .reveal:nth-child(2) { transition-delay: .12s; }
.cards .reveal:nth-child(3), .nicknames .reveal:nth-child(3) { transition-delay: .24s; }
.cards .reveal:nth-child(4) { transition-delay: .36s; }

@media (scripting: none) {
  .reveal { opacity: 1; transform: none; }
}

/* ---------- Hero / page entrance ---------- */
@keyframes riseIn { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes twinkleStar { 0%, 100% { opacity: .5; transform: scale(.9); } 50% { opacity: 1; transform: scale(1.15); } }

.hero-card > *, .page-heading > * { animation: riseIn 1.1s var(--ease) both; }
.hero-card > :nth-child(1) { animation-delay: .2s; }
.hero-card > :nth-child(2) { animation-delay: .45s; }
.hero-card > :nth-child(3) { animation-delay: .7s; }
.hero-card > :nth-child(4) { animation-delay: .9s; }
.hero-card > :nth-child(5) { animation-delay: 1.1s; }
.hero-card > :nth-child(6) { animation-delay: 1.3s; }
.page-heading > :nth-child(2) { animation-delay: .2s; }
.page-heading > :nth-child(3) { animation-delay: .4s; }
.arch-wrap { animation: riseIn 1.1s var(--ease) .45s both, floaty 6s ease-in-out 1.6s infinite; }
.sparkle { animation: twinkleStar 3s ease-in-out infinite; }
.sparkle.two { animation-delay: 1.2s; }

/* ---------- Hover details (only on devices with hover) ---------- */
@media (hover: hover) {
  .gallery__open:hover img,
  .gallery__open:hover video { transform: scale(1.06); }
  .card { transition: transform .5s var(--ease); }
  .card:hover { transform: translateY(-6px); }
}
.lightbox__nav, .lightbox__close { transition: background .3s var(--ease), border-color .3s var(--ease); }
.lightbox__nav:hover, .lightbox__close:hover { background: var(--wine); border-color: var(--gold); }
.lightbox__media { animation: pageIn .45s var(--ease) both; }

/* ---------- Floating petals ---------- */
@keyframes petalFall {
  0%   { transform: translate3d(0, -10vh, 0) rotate(0deg); opacity: 0; }
  8%   { opacity: .8; }
  92%  { opacity: .8; }
  100% { transform: translate3d(var(--drift, 0px), 112vh, 0) rotate(var(--spin, 360deg)); opacity: 0; }
}
.petal {
  animation: petalFall var(--dur, 16s) linear var(--delay, 0s) infinite;
}

/* ---------- Letter: envelope opening ---------- */
.envelope__flap {
  transition: transform .8s var(--ease), z-index 0s linear .4s;
}
.envelope { perspective: 900px; }
.envelope.is-open .envelope__flap {
  transform: rotateX(180deg);
  z-index: 2;
}
.envelope__seal { transition: opacity .5s var(--ease), transform .5s var(--ease); }
.envelope.is-open .envelope__seal { opacity: 0; transform: scale(.7) rotate(-20deg); pointer-events: none; }

.envelope__paper { transition: transform 1.4s var(--ease), box-shadow 1.4s var(--ease); }
.envelope.is-letter-out .envelope__paper {
  transform: translateY(calc(var(--rise) * -1));
  box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
}
.envelope.is-reading .envelope__paper { z-index: 8; }

/* Letter text writes in paragraph by paragraph */
.envelope__paper p { opacity: 0; transform: translateY(10px); }
.envelope.is-reading .envelope__paper p {
  opacity: 1;
  transform: none;
  transition: opacity 1s var(--ease), transform 1s var(--ease);
  transition-delay: calc(var(--i, 0) * .45s);
}

/* Gentle hint before opening */
@keyframes sealPulse {
  0%, 100% { box-shadow: 0 3px 8px rgba(0, 0, 0, .25), 0 0 0 0 rgba(200, 95, 131, .5); }
  50%      { box-shadow: 0 3px 8px rgba(0, 0, 0, .25), 0 0 0 14px rgba(200, 95, 131, 0); }
}
.envelope:not(.is-open) .envelope__seal { animation: sealPulse 2.8s ease-out infinite; }

#letter-continue { opacity: 0; transform: translateY(10px); transition: opacity 1s var(--ease), transform 1s var(--ease); }
#letter-continue.is-visible { opacity: 1; transform: none; }

/* ---------- Proposal: cinematic sequence ---------- */
/* 1. Dark burgundy atmosphere: everything starts hidden */
.scene .lights,
.scene .petal-layer,
.scene .spotlight,
.scene .ring__glow { opacity: 0; transition: opacity 2.4s var(--ease); }

.scene .ring {
  opacity: 0;
  transform: translateY(70px) scale(.9);
  transition: opacity 2.2s var(--ease), transform 2.6s var(--ease);
}
.scene .proposal__question,
.scene .proposal__subtitle {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 2s var(--ease), transform 2s var(--ease);
}
.scene .proposal__subtitle { transition-delay: .8s; }
.scene .proposal__actions {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 1.6s var(--ease), transform 1.6s var(--ease);
}

.scene.stage-start .lights { opacity: 1; }
.scene.stage-petals .petal-layer { opacity: 1; }          /* 2. petals */
.scene.stage-light .spotlight { opacity: 1; }             /* 3. champagne light */
.scene.stage-ring .ring { opacity: 1; transform: none; }  /* 4. ring rises */
.scene.stage-glow .ring__glow { opacity: 1; }             /* 6. glow */
.scene.stage-question .proposal__question,
.scene.stage-question .proposal__subtitle { opacity: 1; transform: none; }  /* 7. question */
.scene.stage-actions .proposal__actions { opacity: 1; transform: none; }

/* Soft flicker on the spotlight once visible */
@keyframes spotBreath { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.06); } }
.scene.stage-light .spotlight { animation: spotBreath 7s ease-in-out infinite; }

/* Very gentle ring float */
@keyframes ringFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.scene.stage-ring .ring img { animation: ringFloat 6s ease-in-out 2.6s infinite; }

@keyframes glowPulse { 0%, 100% { opacity: .8; transform: scale(1); } 50% { opacity: 1; transform: scale(1.08); } }
.scene.stage-glow .ring__glow { animation: glowPulse 5s ease-in-out infinite; }

/* Distant lights twinkle */
@keyframes twinkle { 0%, 100% { opacity: .1; } 50% { opacity: .85; } }
.light { opacity: .1; animation: twinkle var(--d, 6s) ease-in-out var(--delay, 0s) infinite; }

/* Diamond glint: a small star that appears and fades */
@keyframes glint {
  0%   { transform: scale(0) rotate(0deg); opacity: 0; }
  35%  { transform: scale(1) rotate(45deg); opacity: 1; }
  100% { transform: scale(0) rotate(90deg); opacity: 0; }
}
.glint { animation: glint 1.2s ease-out both; }

/* Celebration: brighter ring and glow */
.scene.is-celebrating .ring img { filter: brightness(1.18) drop-shadow(0 0 22px rgba(213, 180, 119, .75)); transition: filter 1s var(--ease); }
.scene.is-celebrating .ring__glow { opacity: 1; transform: scale(1.25); transition: transform 1.2s var(--ease); }

/* Answer panels */
.panel { opacity: 0; transition: opacity .7s var(--ease); }
.panel.is-visible { opacity: 1; }
.scene.is-answered .proposal__actions { opacity: 0; pointer-events: none; }

/* Pause decorative loops when the tab is hidden */
.scene.is-paused *, .scene.is-paused *::before, .scene.is-paused *::after { animation-play-state: paused !important; }

/* ---------- Respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  .reveal { opacity: 1; transform: none; }
  .petal { display: none; }
  .envelope__paper p { opacity: 1; transform: none; }
  .light { opacity: .5; }
}
