/* ─────────────────────────────────────────────────────────────
   Full-screen envelope reveal for the formal invitation
   Landscape envelope on wide screens, portrait on phones.
   ───────────────────────────────────────────────────────────── */
.env-stage {
  --paper: #f4efe5;
  --paper-tex: url("../img/textures/paper.jpg");
  --navy: #16223f;
  /* envelope geometry (landscape) */
  --env-aspect: 1.42;
  --env-w: min(80vw, calc(64vh * var(--env-aspect)));
  --flap-h: 54%;        /* how far the flap reaches down */
  --v-y: 56%;           /* where the side flaps meet */
  --b-y: 43%;           /* tip of the bottom flap */
  --seal: calc(var(--env-w) * 0.2);

  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.env-stage[hidden] { display: none; }

@media (max-aspect-ratio: 4/5) {
  .env-stage {
    --env-aspect: 0.74;
    --env-w: min(86vw, calc(70vh * var(--env-aspect)));
    --flap-h: 44%;
    --v-y: 48%;
    --b-y: 36%;
    --seal: calc(var(--env-w) * 0.32);
  }
}

/* The table the envelope rests on: warm linen under a soft spotlight */
.env-stage__table {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 50% 46%, rgba(255, 250, 240, .55), transparent 70%),
    radial-gradient(ellipse 120% 90% at 50% 50%, transparent 55%, rgba(40, 28, 18, .38) 100%),
    var(--linen-tex, url("../img/textures/linen.jpg")) 0 0 / 360px,
    #d8cfc2;
  background-blend-mode: normal, normal, multiply, normal;
}

/* Camera: everything that moves together */
.env-camera {
  position: relative;
  display: grid; place-items: center; gap: clamp(1.2rem, 4vh, 2.4rem);
  will-change: transform;
}

.env {
  position: relative;
  width: var(--env-w);
  aspect-ratio: var(--env-aspect);
  perspective: 1800px;
  cursor: pointer;
  outline: none;
  animation: env-float 6s ease-in-out infinite;
}
.env:focus-visible .env__seal-wrap { outline: 2px solid #8e2a22; outline-offset: 6px; border-radius: 50%; }
@keyframes env-float {
  0%, 100% { transform: translateY(0) rotate(-.25deg); }
  50% { transform: translateY(-6px) rotate(.25deg); }
}
.env-stage.is-opening .env { animation: none; }

.env > * { position: absolute; }

/* soft contact shadow on the linen */
.env__shadow {
  left: 4%; right: 4%; bottom: -5%; height: 22%;
  background: radial-gradient(ellipse at center, rgba(30, 20, 12, .45), transparent 70%);
  filter: blur(14px);
  animation: env-shadow 6s ease-in-out infinite;
}
@keyframes env-shadow { 50% { transform: scale(.96); opacity: .8; } }
.env-stage.is-opening .env__shadow { animation: none; }

/* paper surfaces */
.env__paper, .env__face i, .env__flap-front {
  background-color: var(--paper);
  background-image: var(--paper-tex);
  background-size: 420px;
  background-blend-mode: multiply;
}

.env__back {
  inset: 0;
  border-radius: 3px;
  box-shadow: 0 34px 60px -24px rgba(35, 24, 14, .55), 0 10px 20px -6px rgba(35, 24, 14, .25);
}

/* inside of the envelope: navy liner with tiny ivory polka dots */
.env__liner, .env__flap-back {
  background-color: var(--navy);
  background-image:
    radial-gradient(circle, rgba(236, 228, 214, .85) 0 1.1px, transparent 1.7px),
    radial-gradient(circle, rgba(236, 228, 214, .85) 0 1.1px, transparent 1.7px),
    linear-gradient(170deg, rgba(255, 255, 255, .06), rgba(0, 0, 0, .25));
  background-size: 18px 18px, 18px 18px, 100% 100%;
  background-position: 0 0, 9px 9px, 0 0;
}
.env__liner {
  left: 3.5%; right: 3.5%; top: 3%; height: calc(var(--v-y) + 6%);
  box-shadow: inset 0 18px 26px -10px rgba(0, 0, 0, .65);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}

/* the pocket: two side flaps and a bottom flap, each casting a fine edge shadow */
.env__face { inset: 0; filter: drop-shadow(0 -1px 1.5px rgba(70, 50, 30, .22)); }
.env__face i { position: absolute; inset: 0; display: block; }
.env__face--left i  { clip-path: polygon(0 0, 51% var(--v-y), 0 100%); }
.env__face--right i { clip-path: polygon(100% 0, 49% var(--v-y), 100% 100%); background-image: linear-gradient(255deg, rgba(0,0,0,.06), rgba(0,0,0,0) 60%), var(--paper-tex); }
.env__face--bottom i { clip-path: polygon(0 100%, 50% var(--b-y), 100% 100%); background-image: linear-gradient(0deg, rgba(255,255,255,.18), rgba(0,0,0,.04) 70%), var(--paper-tex); }
.env__face--left i { background-image: linear-gradient(105deg, rgba(255,255,255,.12), rgba(0,0,0,.03) 70%), var(--paper-tex); }
.env__face i { background-size: 100% 100%, 420px; background-blend-mode: normal, multiply; }

/* the guests' names, hand-lettered on the envelope, written on as it appears */
.env { --addr-y: 75%; --addr-size: calc(var(--env-w) * .066); }
@media (max-aspect-ratio: 4/5) { .env { --addr-y: 68%; --addr-size: calc(var(--env-w) * .095); } }
.env__address {
  left: 10%; right: 10%; top: var(--addr-y); z-index: 2;
  display: flex; justify-content: center;
  transform: translateY(-50%) rotate(-2deg);
  pointer-events: none;
}
.env__address span {
  font: 400 var(--addr-size)/1.3 var(--script); color: #2a2420;
  white-space: nowrap; padding: 0 .2em;
  clip-path: inset(-30% 100% -30% -5%);
  animation: write-on 2.2s 1s cubic-bezier(.45, .05, .35, 1) forwards;
}
@keyframes write-on { to { clip-path: inset(-30% -5% -30% -5%); } }

/* the flap */
.env__flap-shadow {
  left: 2%; right: 2%; top: 0; height: calc(var(--flap-h) + 3%);
  background: rgba(45, 30, 18, .35);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  filter: blur(5px);
  transform: translateY(3px);
}
.env__flap {
  left: 0; right: 0; top: 0; height: var(--flap-h);
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  z-index: 3;
}
.env__flap-front, .env__flap-back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  clip-path: polygon(0 0, 100% 0, 52.5% 97%, 50% 100%, 47.5% 97%);
}
.env__flap-front {
  background-image: linear-gradient(180deg, rgba(0, 0, 0, .07), rgba(255, 255, 255, .1) 70%), var(--paper-tex);
  background-size: 100% 100%, 420px;
  background-blend-mode: normal, multiply;
}
.env__flap-shade { position: absolute; inset: 0; background: rgba(20, 12, 6, .45); opacity: 0; }
.env__flap-back {
  transform: rotateX(180deg);
  /* drawn upside down because it is flipped over with the flap: once open, the point faces up */
  clip-path: polygon(50% 0, 52.5% 3%, 100% 100%, 0 100%, 47.5% 3%);
  box-shadow: inset 0 -16px 22px -12px rgba(0, 0, 0, .55);
}

/* the wax seal (two halves so it can crack) */
.env__seal-wrap {
  left: 50%; top: var(--flap-h);
  width: var(--seal); aspect-ratio: 1;
  transform: translate(-50%, -62%);
  z-index: 5;
  pointer-events: none;
}
.env__seal-half {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.env__seal-half svg { width: 100%; height: 100%; display: block; overflow: visible; }
.env__seal-half--top { clip-path: var(--crack-top); }
.env__seal-half--bottom { clip-path: var(--crack-bottom); }
.env__seal-pulse {
  position: absolute; inset: 6%; border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(142, 42, 34, .35);
  animation: seal-pulse 2.6s ease-out infinite 1.2s;
}
@keyframes seal-pulse {
  0% { box-shadow: 0 0 0 0 rgba(142, 42, 34, .32); }
  70%, 100% { box-shadow: 0 0 0 calc(var(--seal) * .28) rgba(142, 42, 34, 0); }
}
.env-stage.is-opening .env__seal-pulse { display: none; }
.env:hover .env__seal-wrap { filter: brightness(1.06); }

/* call to action */
.env-cta {
  font: 500 .74rem/1 var(--sans);
  letter-spacing: .34em; text-transform: uppercase;
  color: #2b2620;
  background: none; border: 0; padding: .9rem 1.2rem;
  display: inline-flex; align-items: center; gap: .9rem;
  cursor: pointer;
  animation: cta-in 1.2s .5s var(--ease-out) both, cta-breathe 3.2s 1.7s ease-in-out infinite;
}
.env-cta::before, .env-cta::after { content: ""; width: 2.2rem; height: 1px; background: currentColor; opacity: .45; }
@keyframes cta-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes cta-breathe { 50% { opacity: .55; } }
.env-stage.is-opening .env-cta { opacity: 0; transition: opacity .35s; animation: none; }

/* layer the invitation pieces pour out into */
.env-pour { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
.env-pour > * { position: fixed !important; margin: 0 !important; will-change: transform, opacity; transform-origin: 50% 50%; }

/* real collage pieces stay hidden while their stand-ins are flying */
.collage.is-pouring > * { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  .env, .env__shadow, .env__seal-pulse, .env-cta { animation: none !important; }
  .env__address span { animation: none; clip-path: none; }
}
