/* ==========================================================================
   ENVELOPE — shell, address side, inside, pocket, lid and seal.
   Colours come from theme.css.
   ========================================================================== */
.scene {
  position: relative;
  perspective: 1100px;
  width: var(--env-w); height: var(--env-h); max-width: 100%;
  transition: opacity .6s ease;                    /* fade-in once the name is known */
}

.envelope {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 2.7s ease-in-out;          /* flip speed */
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ---- waiting for the guest's name: envelope hidden, seal pulses ----
   Fade the .scene, never the .envelope: a semi-transparent 3D element
   shows both of its sides at once. */
.wrap { position: relative; }
.stage:not(.ready) .scene { opacity: 0; pointer-events: none; }
.loader {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--env-h) * .3);                 /* same spot as the envelope */
  height: var(--env-h);
  display: grid; place-items: center;
  pointer-events: none;
  transition: opacity .25s ease;
}
/* the two of us as kids, hopping in turn (Moli, then Edi) */
.loader { grid-auto-flow: column; justify-content: center; gap: calc(var(--env-w) * .035); }
.loader .kid {
  width: calc(var(--env-w) * .2);
  height: auto; aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--card);
  box-shadow: 0 6px 14px -6px rgba(40,50,30,.45);
  animation: loader-hop 1.1s ease-in-out infinite;
}
.loader .kid:last-child { animation-delay: .55s; }
.loader-amp { font-family: var(--body); font-size: calc(var(--env-w) * .07); color: var(--green); }
.ready .loader { opacity: 0; }
.ready .loader .kid { animation: none; }
@keyframes loader-hop {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(calc(var(--env-w) * -.06)); }
}
@media (prefers-reduced-motion: reduce) { .loader .kid { animation: none; } }
.envelope:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }

.face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 4px;
}

/* ---- address side, seen first ---- */
.address {
  background: var(--noise), linear-gradient(160deg, var(--paper), var(--paper-2));
  box-shadow: 0 30px 60px -18px rgba(45,55,35,.45), 0 8px 18px -6px rgba(45,55,35,.3),
              inset 0 0 0 1px rgba(255,255,255,.5), inset 0 0 24px rgba(120,100,60,.12);
  display: grid;
  place-items: center;
}
.address .to { text-align: center; display: grid; gap: .2em; color: var(--green); translate: 0 8%; }
.address .to small {
  font-family: var(--caps);
  font-size: calc(var(--env-w) * .024);
  letter-spacing: .3em;
  color: var(--ink-soft);
}
#guest-name { display: grid; justify-items: center; font-family: var(--script); }
#guest-name .nm { font-size: calc(var(--env-w) * .085); line-height: 1.05; }
/* the "&" matches the one between Moli & Edi on the invitation: Cormorant, upright, green, about half the name size */
#guest-name .amp { font-family: var(--body); font-style: normal; font-size: calc(var(--env-w) * .042); line-height: 1; color: var(--green); margin-block: .15em; }
/* one line: "Anna & Luca Bianchi" (same fonts and "&", side by side) */
#guest-name.line { display: block; white-space: nowrap; font-size: calc(var(--env-w) * .085); line-height: 1.05; margin-top: calc(var(--env-w) * .0045); }   /* same gap under "To" as the stacked names */
#guest-name.line .nm { display: inline; }
#guest-name.line .amp { display: inline; font-style: italic; margin: 0 .3em; vertical-align: .08em; }
#guest-name.many .nm { font-size: calc(var(--env-w) * .065); }   /* three or more names */
.address .to i { display: none; }   /* the line under the names: removed (Moli, 20 Nov) */

/* ---- flap side ---- */
.flapside { transform: rotateY(180deg); perspective: 900px; perspective-origin: 50% 0; }

.inner {
  position: absolute; inset: 0; z-index: 1;
  border-radius: 4px;
  background: var(--noise), linear-gradient(180deg, var(--inside-1) 0%, var(--inside-2) 18%, var(--inside-2) 45%, var(--inside-pocket) 52%);
  box-shadow: 0 30px 60px -18px rgba(45,55,35,.45), 0 8px 18px -6px rgba(45,55,35,.3);
}

/* ---- front pocket ---- */
.pocket { position: absolute; inset: 0; z-index: 4; pointer-events: none; border-radius: 4px; overflow: hidden; }
.pocket svg, .lid svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

/* ---- top lid ---- */
.lid {
  position: absolute; z-index: 5;
  left: 0; right: 0; top: 0;
  height: 91.5%;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  transform: rotateX(0deg);
  transition: transform .9s ease-in-out;           /* lid speed */
}
.lid > .out, .lid > .in { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.lid > .in { transform: rotateY(180deg); }
.lid .shade { fill: var(--lid-shade); transition: opacity .45s ease-in; }
.lid .out .shade { opacity: 0; }
.lid .in .shade { opacity: .45; transition: opacity .45s ease-out .45s; }

/* ---- wax seal ---- */
.seal {
  position: absolute;
  left: 50%; top: 86%;
  width: 17%;
  aspect-ratio: 1;
  translate: -50% -50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 47% 53% 50% 50% / 52% 48% 52% 48%;
  background: radial-gradient(circle at 36% 30%, var(--seal-hi), var(--green) 58%, var(--seal-lo) 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,.35), inset 0 -3px 5px rgba(0,0,0,.3), inset 0 2px 3px rgba(255,255,255,.12);
  display: grid; place-items: center;
  color: color-mix(in srgb, var(--gold) 85%, white);
  font-family: var(--monogram);
  font-size: calc(var(--env-w) * .06);
  /* Pinyon Script letters sit right of and above their box: nudge the ink to the true centre */
  padding: .11em .26em 0 0;
}
.seal::before { content: ""; position: absolute; inset: 12%; border-radius: 50%; border: 1px solid rgba(220,200,150,.35); }

/* ---- SVG paint, driven by theme tokens ---- */
.c-paper-hi { stop-color: var(--paper-hi); }
.c-paper    { stop-color: var(--paper); }
.c-paper-mid{ stop-color: var(--paper-mid); }
.c-paper-2  { stop-color: var(--paper-2); }
.c-paper-lo { stop-color: var(--paper-lo); }
.c-fold     { stop-color: var(--paper-fold); }
.c-in-1     { stop-color: var(--inside-1); }
.c-in-2     { stop-color: var(--inside-2); }
.c-in-3     { stop-color: var(--inside-3); }
.gum        { stroke: var(--gum); }
.fold-shadow{ flood-color: var(--fold-shadow); }

/* ---- animation states ---- */
.st-flip .envelope { transform: rotateY(180deg); }
.st-lid .lid { transform: rotateX(-160deg); }
.st-lid .lid .out .shade { opacity: .32; }
.st-lid .lid .in .shade { opacity: 0; }
.st-lidback .lid { z-index: 2; }
