/*
 * The envelope intro (envelope.js), on the save-the-date or the website (only while it's the one playing: .intro-envelope,
 * js/intros.js): an envelope covered in white lace, floating in 3D over the dock photo
 * (blurred, dark), tilting towards the pointer, its pointed flap folded down and closed with a gold seal (seal3d.js).
 * A tap
 * breaks the seal and lifts the flap, and the envelope gives way to the save-the-date itself (the dock photo, its words
 * rising into place, or the website's) as a butterfly flutters out ("butterfly") or rose petals burst out ("flowers").
 */
.env { display: none; }
.intro-on:where(.intro-envelope) .env { display: block; position: fixed; inset: 0; z-index: 80; overflow: hidden; cursor: pointer; perspective: 1600px; background: #e9e4da; } /* (:where, so .is-open below still wins) */
/* (behind it, the dock photo, soft and dark, as if on a table in the evening) */
.env::before {
  content: ""; position: absolute; inset: -40px; pointer-events: none;
  background: url("/images/hero.jpg") 50% 60% / cover no-repeat; filter: blur(16px) brightness(.5) saturate(.9);
}
/* the envelope itself: filling the screen (a little larger, so its edges never show as it tilts: --rx, --ry,
   envelope.js), its flap and seal standing a little off it */
.env__stage {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transform: scale(1.07) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
}
.env__stage > .env__flap { transform: translateZ(2px); }
.env__stage > .env__seal { transform: translate(-50%, -50%) translateZ(16px); }
.intro-on.intro-envelope, .intro-on.intro-envelope body { overflow: hidden; }
.env.is-open { cursor: default; pointer-events: none; } /* (opening: the page underneath is the page) */
.env.is-done { opacity: 0; transition: opacity .6s ease; }

/* the paper: ivory, covered in raised white lace (a 19th-century needle-lace shawl, public domain, its threads shaded
   and casting shadows: images/save-the-date/lace.webp, tools/save-the-date/lace.py), the same lace running on across
   the flap; a soft light from above */
.env__paper, .env__face {
  position: absolute; inset: 0; overflow: hidden;
  background:
    radial-gradient(ellipse 120% 90% at 50% 25%, rgba(255, 252, 244, .16), rgba(255, 252, 244, 0) 55%, rgba(70, 55, 30, .1)),
    url("/images/save-the-date/lace.webp") 50% 0 / max(820px, 120%) auto repeat #d8cfbf;
}
.env__face { filter: brightness(1.04); }
.env__paper::after, .env__face::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .55; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .5 0 0 0 0 .42 0 0 0 .16 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.env.is-open .env__stage { animation: env-away 1.1s cubic-bezier(.5, 0, .3, 1) .55s forwards; }
.env.is-open::before { transition: opacity 1.1s ease .55s; opacity: 0; }
.env.is-open { background: transparent; transition: background-color 1.1s ease .55s; }
@keyframes env-away { to { opacity: 0; transform: scale(1.16) rotateX(0) rotateY(0); } }

/* the flap: lace, its edge scalloped, coming down to a little tab, lifting open from the top; its shadow below it */
.env__flap {
  position: absolute; inset: 0; z-index: 2; transform-origin: 50% 0; backface-visibility: hidden;
  filter: drop-shadow(0 10px 12px rgba(70, 58, 35, .28)) drop-shadow(0 2px 2px rgba(70, 58, 35, .2));
  transition: transform 1.1s cubic-bezier(.5, .05, .3, 1) .2s, opacity .4s ease .85s;
}
/* (cut to its scalloped edge by envelope.js; until then, a plain point) */
.env__flap .env__face { clip-path: polygon(0 0, 100% 0, 100% 36%, 50% 52%, 0 36%); }
.env__trim { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; filter: drop-shadow(0 1px 1px rgba(90, 75, 50, .35)); }
.env__edge { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.env:not(.env--classic) .env__edge { display: none; }
.env.is-open .env__stage > .env__flap { transform: translateZ(2px) rotateX(105deg); opacity: 0; }

/* the seal: oval, champagne gold, on the flap's tab (--seal-y: envelope.js) */
.env__seal {
  position: absolute; z-index: 5; left: 50%; top: var(--seal-y, 55%); width: clamp(104px, 29vmin, 156px); aspect-ratio: 1; transform: translate(-50%, -50%);
  filter: drop-shadow(0 18px 16px rgba(50, 38, 12, .38)) drop-shadow(0 3px 3px rgba(50, 38, 12, .35));
  transition: transform .5s cubic-bezier(.3, 1.4, .5, 1), opacity .45s ease .05s;
}
.env__seal svg { display: block; width: 100%; height: 100%; overflow: visible; transform: scaleX(.8); } /* (oval) */
/* (in 3D, once it's ready: seal3d.js; the drawn one fades out under it) */
.env__seal3d { position: absolute; left: -6%; top: -6%; }
.env__seal svg { transition: opacity .4s ease; }
.env__seal.is-3d svg { opacity: 0; }
.env.is-open .env__stage > .env__seal { transform: translate(-50%, -50%) translateZ(16px) scale(1.15) rotate(-6deg); opacity: 0; }

/* "Tap to open" */
.env__tap {
  position: absolute; z-index: 6; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + clamp(1.8rem, 4.5svh, 2.8rem)); transform: translateX(-50%);
  margin: 0; display: flex; align-items: center; gap: .7rem; white-space: nowrap; pointer-events: none;
  font: 500 .66rem var(--sans); letter-spacing: .3em; text-transform: uppercase; color: #7d735f; transition: opacity .4s ease;
  /* (on a soft cream pill, to read over the lace) */
  padding: .7em 1.4em; border-radius: 999px; background: rgba(250, 247, 240, .88); box-shadow: 0 4px 14px -6px rgba(60, 45, 20, .35);
}
.env__ring { width: 13px; height: 13px; border-radius: 50%; border: 1px solid currentColor; position: relative; }
.env__ring::after { content: ""; position: absolute; inset: -1px; border-radius: 50%; border: 1px solid currentColor; animation: env-ring 2.4s ease-out infinite; }
@keyframes env-ring { from { transform: scale(1); opacity: .9; } to { transform: scale(3.2); opacity: 0; } }
.env.is-open .env__tap { opacity: 0; transition: opacity .35s ease; }

/* the butterfly: its two wings either side of its body (the same wing, mirrored for the left), beating in 3D, slowly as it
   rests, quickly in flight; a soft shadow under it */
.env__fly {
  position: absolute; z-index: 4; left: 50%; top: 50%; width: clamp(150px, 36vmin, 260px); aspect-ratio: 660 / 447; margin: 0;
  opacity: 0; perspective: 500px; pointer-events: none; filter: drop-shadow(0 14px 10px rgba(0, 0, 0, .35));
}
.env__fly .wing { position: absolute; top: 0; width: 50%; height: 100%; }
.env__fly .wing img { display: block; width: 100%; height: 100%; }
.env__fly .wing--l { left: 0; transform-origin: 100% 50%; animation: flap-l 1.5s ease-in-out infinite alternate; }
.env__fly .wing--l img { transform: scaleX(-1); }
.env__fly .wing--r { right: 0; transform-origin: 0 50%; animation: flap-r 1.5s ease-in-out infinite alternate; }
.env__fly.is-flying .wing { animation-duration: .16s; }
.env__fly .body { position: absolute; left: 50%; top: 0; width: 4.4%; height: 100%; transform: translateX(-50%); }
@keyframes flap-l { from { transform: rotateY(-8deg); } to { transform: rotateY(62deg); } }
@keyframes flap-r { from { transform: rotateY(8deg); } to { transform: rotateY(-62deg); } }

/* the petals and roses ("flowers"), tumbling in 3D */
.env__petal { position: absolute; z-index: 4; left: 50%; top: 50%; height: auto; pointer-events: none; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .3)); }

/* ───────────── The earlier envelope ("classic", switched on in the admin page: envelope.js): a card floating over the dock
   photo (blurred, dark), its paper thick enough to show along its edges, covered in deeper lace on darker paper, its
   folds showing, its flap a plain point, a round bright-gold seal where it meets the envelope ───────────── */
.env:not(.env--classic)::before { content: none; }
.intro-on .env.env--classic:not(.is-open) { background: #1a1a14; }
.env--classic .env__stage {
  inset: max(3.5vmin, 14px); border-radius: 4px; transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  box-shadow: 0 1px 0 #e3dccb, 0 2px 0 #d6cdb8, 0 3px 0 #cbc1a9, 0 4px 0 #bfb49a, 0 30px 50px -10px rgba(0, 0, 0, .65), 0 10px 18px rgba(0, 0, 0, .35);
}
.env--classic .env__paper { border-radius: 4px; }
.env--classic .env__paper, .env--classic .env__face {
  background:
    radial-gradient(ellipse 120% 90% at 50% 25%, rgba(255, 252, 244, .16), rgba(255, 252, 244, 0) 55%, rgba(70, 55, 30, .1)),
    url("/images/save-the-date/lace-deep.webp") 50% 0 / max(820px, 120%) auto repeat #d8cfbf;
}
/* (its folds: the sides meeting under the seal, the bottom flap over them) */
.env--classic .env__paper::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to top right, transparent calc(50% - 3px), rgba(90, 75, 50, .1) calc(50% - 1px), rgba(90, 75, 50, .3) 50%, rgba(255, 255, 255, .75) calc(50% + 1px), rgba(255, 255, 255, .15) calc(50% + 3px), transparent calc(50% + 5px)) 0 100% / 50% 48% no-repeat,
    linear-gradient(to top left, transparent calc(50% - 3px), rgba(90, 75, 50, .1) calc(50% - 1px), rgba(90, 75, 50, .3) 50%, rgba(255, 255, 255, .75) calc(50% + 1px), rgba(255, 255, 255, .15) calc(50% + 3px), transparent calc(50% + 5px)) 100% 100% / 50% 48% no-repeat;
}
.env--classic .env__flap .env__face { clip-path: polygon(0 0, 100% 0, 100% var(--side, 2%), 50% 52%, 0 var(--side, 2%)); }
.env--classic .env__trim { display: none; }
.env--classic .env__seal { top: 52%; width: clamp(118px, 34vmin, 180px); }
.env--classic .env__seal svg { transform: none; }

