/* Ceremonial openings: longer travel, gentle acceleration, no layout animation. */
:root {
  --opening-ease: cubic-bezier(.45, 0, .2, 1);
  --opening-fade: 1.4s;
}

.opening {
  contain: layout paint;
  will-change: opacity;
  transition: opacity var(--opening-fade) ease-in-out,
    visibility 0s var(--opening-fade);
}

/* Paint the invitation behind the opaque cover before the final crossfade.
   The inert attribute still keeps its controls and content inaccessible. */
main[inert] { visibility: visible; }

.glitter-cover {
  will-change: opacity;
  transform: none;
  transition: opacity 2.8s var(--opening-ease);
}
.glitter-cover.falling {
  transform: none;
  transition-delay: .65s;
}

#glitter,
#glitterMotion {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#glitter {
  transition: transform 3.1s var(--opening-ease), opacity 2.7s .4s ease-in-out;
}
.falling #glitter {
  transform: translate3d(0, 15vh, 0);
  opacity: 0;
}

.curtain {
  transition: transform 3.6s .8s var(--opening-ease);
  backface-visibility: hidden;
}
.curtain:after,
.valance:after {
  /* Fine woven lines replace a procedural SVG filter on moving fabric. */
  background-image: repeating-linear-gradient(0deg, #fff1 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, #0002 0 1px, transparent 1px 3px);
  mix-blend-mode: normal;
}
.valance {
  transition: transform 2.8s .9s var(--opening-ease);
  backface-visibility: hidden;
}
.envelope-stage {
  transition: opacity 2s 1.7s ease-in-out;
}

/* Keep the letter behind the envelope as it rises out of the sleeve. */
.envelope {
  filter: none;
  box-shadow: 0 30px 35px #10020780;
  perspective: 1100px;
}
.envelope-flap {
  filter: none;
  backface-visibility: hidden;
  transition: transform 1.9s .35s var(--opening-ease);
}
.seal-broken .envelope-flap {
  z-index: 4;
}
.wax-seal {
  transition: transform .85s ease-in-out, opacity .85s ease-in-out;
}
.seal-broken .wax-seal {
  transform: translate3d(-50%, 12px, 0) rotate(8deg) scale(.97);
}
.letter-peek {
  transition: transform 2.2s 1.2s var(--opening-ease);
}
.seal-broken .letter-peek {
  z-index: 1;
  transform: translate3d(0, -62%, 0);
}
.envelope-intro,
.envelope-caption,
.envelope-stage > .small-caps {
  transition: opacity .9s ease-in-out;
}
.seal-broken .envelope-intro,
.seal-broken .envelope-caption,
.seal-broken .envelope-stage > .small-caps {
  opacity: 0;
  transition: opacity .9s ease-in-out;
}

/* Promote moving layers only for the short opening, then release them. */
.opening:not(.finished) .curtain,
.opening:not(.finished) .valance,
.is-animating .curtain,
.is-animating .valance,
.is-animating .letter-peek,
.is-animating .envelope-flap {
  will-change: transform;
}
.is-animating .glitter-cover,
.is-animating #glitter,
.is-animating .wax-seal {
  will-change: transform, opacity;
}

body.is-locked .scroll-line,
.scroll-cue.is-offscreen .scroll-line,
.opening.finished .touch-icon,
.falling .touch-icon {
  animation-play-state: paused;
}
.opening.resetting,
.opening.resetting * {
  transition: none !important;
  animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .opening,
  .opening * {
    transition-duration: .01ms !important;
    transition-delay: 0ms !important;
  }
  .falling #glitter { transform: none; }
}

/* Give the letter room. It rises out of the envelope, so the envelope sits lower and
   scales with screen height; once opened, the whole envelope settles further down. */
.envelope-stage { padding-top: max(70px, 9vh); }
.envelope { height: clamp(190px, min(46vw, 40vh), 340px); }
.envelope-wrap { transition: transform 1.7s .25s var(--opening-ease); }
.seal-broken .envelope-wrap { transform: translate3d(0, clamp(40px, 12vh, 120px), 0); }
.seal-broken .letter-peek { transform: translate3d(0, -84%, 0); }
@media (prefers-reduced-motion: reduce) {
  .envelope-wrap { transition-duration: .01ms !important; }
}
