/* Animated invitation: shown over the site when a guest opens their family's private link (/?h=…).
   An envelope with a wax seal opens, the card slides out with falling petals, and the card becomes
   the invitation with a button to their already filled-in RSVP. */

body.invite-open { overflow: hidden; }

.invite {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(55, 62, 97, 0.9), rgba(35, 37, 50, 1) 70%),
    var(--midnight);
  color: var(--midnight);
  transition: opacity 0.7s ease, visibility 0.7s;
}
.invite.closing { opacity: 0; visibility: hidden; }

/* Twinkling gold dust in the background */
.inv-dust { position: absolute; inset: 0; pointer-events: none; }
.inv-dust i {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: #e8c879;
  box-shadow: 0 0 6px 1px rgba(232, 200, 121, 0.6);
  opacity: 0;
  animation: inv-twinkle var(--d, 4s) ease-in-out var(--delay, 0s) infinite;
}
@keyframes inv-twinkle { 0%, 100% { opacity: 0; transform: scale(0.6); } 50% { opacity: 0.85; transform: scale(1); } }

.inv-skip {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 5;
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
  font: 400 0.68rem var(--sans);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
}
.inv-skip:hover, .inv-skip:focus-visible { background: rgba(255, 255, 255, 0.12); outline: none; }

/* ---------- The envelope ---------- */
.inv-stage {
  --w: min(86vw, 440px);
  --h: calc(var(--w) / 1.35);
  position: relative;
  width: var(--w);
  height: var(--h);
  perspective: 1400px;
  animation: inv-float 3.2s ease-in-out infinite;
}
.opened .inv-stage { animation: none; }
@keyframes inv-float { 0%, 100% { transform: translateY(0) rotate(-0.6deg); } 50% { transform: translateY(-8px) rotate(0.6deg); } }

/* The tap target over the closed envelope */
.inv-open {
  position: absolute;
  inset: -12px;
  z-index: 9;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 10px;
}
.inv-open:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }

.inv-back, .inv-pocket, .inv-flap { position: absolute; inset: 0; }
.inv-back {
  background: linear-gradient(160deg, #424a72, var(--navy) 55%, #2d3352);
  border-radius: 6px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.7);
}
/* The front pocket: left, right and bottom folds, drawn as one shape */
.inv-pocket {
  z-index: 3;
  border-radius: 6px;
  background: linear-gradient(175deg, #464e78, #3a4166 60%, #30365a);
  clip-path: polygon(0 0, 50% 50%, 100% 0, 100% 100%, 0 100%);
  box-shadow: inset 0 0 0 1px rgba(178, 122, 1, 0.35);
}
.inv-pocket::after {
  /* gold hairline along the folds */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom right, transparent calc(50% - 0.6px), rgba(178, 122, 1, 0.55) 50%, transparent calc(50% + 0.6px)) left / 50% 100% no-repeat,
              linear-gradient(to bottom left, transparent calc(50% - 0.6px), rgba(178, 122, 1, 0.55) 50%, transparent calc(50% + 0.6px)) right / 50% 100% no-repeat;
  clip-path: inherit;
}
.inv-to {
  position: absolute;
  left: 0; right: 0;
  bottom: 7%;
  z-index: 4;
  margin: 0;
  text-align: center;
  color: #f4ead8;
  font: italic 500 clamp(1.2rem, 5vw, 1.7rem)/1.1 var(--serif);
  pointer-events: none;
  transition: opacity 0.5s;
}
.inv-to small {
  display: block;
  margin-bottom: 0.3rem;
  font: 400 0.62rem var(--sans);
  font-style: normal;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: #d9b45c;
}
.opened .inv-to { opacity: 0; }

/* The top flap folds up and back when opened */
.inv-flap {
  z-index: 5;
  height: 55%;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(.5, 0, .3, 1), z-index 0s 0.45s;
}
.inv-flap::before, .inv-flap::after {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  backface-visibility: hidden;
  border-radius: 6px 6px 0 0;
}
.inv-flap::before { background: linear-gradient(180deg, #4b5380, #3d4470); filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35)); }
.inv-flap::after { background: linear-gradient(0deg, #2f3554, #262b45); transform: rotateX(180deg); }
.opened .inv-flap { transform: rotateX(180deg); z-index: 1; }

/* The wax seal sits on the tip of the flap */
.inv-seal {
  position: absolute;
  left: 50%;
  top: 55%;
  z-index: 6;
  width: clamp(58px, 16vw, 78px);
  aspect-ratio: 1;
  margin: calc(clamp(58px, 16vw, 78px) / -2) 0 0 calc(clamp(58px, 16vw, 78px) / -2);
  pointer-events: none;
}
.inv-seal span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 47% 53% 50% 50% / 52% 48% 52% 48%;
  background: radial-gradient(circle at 35% 30%, #93454d, var(--burgundy) 55%, #4a2126);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.45), inset 0 0 0 5px rgba(0, 0, 0, 0.12), inset 0 0 0 7px rgba(255, 255, 255, 0.06);
  transition: transform 0.7s cubic-bezier(.4, 0, .6, 1), opacity 0.7s;
}
.inv-seal svg { width: 74%; height: 74%; color: #e7c27a; filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.4)); }
/* The seal breaks in two: each half keeps its side */
.inv-seal .l { clip-path: polygon(0 0, 54% 0, 46% 35%, 56% 60%, 44% 100%, 0 100%); }
.inv-seal .r { clip-path: polygon(54% 0, 100% 0, 100% 100%, 44% 100%, 56% 60%, 46% 35%); }
.inv-seal::after {
  /* soft pulse that invites a tap */
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 1px solid rgba(231, 194, 122, 0.6);
  animation: inv-pulse 2s ease-out infinite;
}
@keyframes inv-pulse { from { transform: scale(0.8); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }
.opened .inv-seal::after { display: none; }
.opened .inv-seal .l { transform: translate(-40px, 60px) rotate(-35deg); opacity: 0; }
.opened .inv-seal .r { transform: translate(40px, 70px) rotate(30deg); opacity: 0; }

.inv-hint {
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 1.6rem);
  margin: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font: 400 0.7rem var(--sans);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  animation: inv-blink 2.4s ease-in-out infinite;
  transition: opacity 0.4s;
}
@keyframes inv-blink { 50% { opacity: 0.35; } }
.opened .inv-hint { opacity: 0 !important; animation: none; }

/* ---------- The card ---------- */
.inv-slot {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  top: -260%;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}
.revealed .inv-slot { overflow: visible; z-index: 7; }
.inv-card {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: calc(var(--h) * 0.04);
  pointer-events: auto;
  /* tucked inside the envelope: its top sits just below the envelope's top edge */
  transform: translateY(49%);
  aspect-ratio: 5 / 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7% 8%;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 0%, #fff, #fbf6ef 70%),
    #fbf6ef;
  border-radius: 3px;
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.55);
  transform-origin: 50% 50%;
  transition: transform 1.1s cubic-bezier(.45, 0, .2, 1);
}
.inv-card::before {
  /* double gold keyline */
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(178, 122, 1, 0.55);
  outline: 1px solid rgba(178, 122, 1, 0.25);
  outline-offset: 3px;
  pointer-events: none;
}
.inv-card > * { position: relative; margin: 0; }
.inv-card .inv-kicker { font: 400 0.6rem var(--sans); letter-spacing: 0.28em; text-transform: uppercase; color: var(--sage); }
.inv-card .inv-names { margin: 0.5rem 0 0.35rem; font: 500 clamp(1.9rem, 8.6vw, 2.7rem)/1.05 var(--serif); color: var(--midnight); }
.inv-card .inv-names em { font-size: 0.75em; color: var(--gold); margin: 0 0.12em; }
.inv-card .inv-request { font: italic 400 1rem/1.35 var(--serif); color: var(--navy); }
.inv-card .inv-rule { width: 56px; height: 1px; margin: 0.8rem auto; background: var(--gold); }
.inv-card .inv-date { font: 500 0.72rem/1.6 var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--midnight); }
.inv-card .inv-venue { margin-top: 0.55rem; font: 500 1.15rem/1.2 var(--serif); color: var(--burgundy); }
.inv-card .inv-address { font-size: 0.74rem; color: var(--muted); line-height: 1.4; }
.inv-card .inv-dear { margin-top: 0.9rem; font: italic 400 1rem/1.3 var(--serif); color: var(--navy); }
.inv-card .inv-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; width: 100%; margin-top: 0.9rem; }
.inv-card .btn { min-height: 44px; padding: 0.6rem 0.4rem; font-size: 0.6rem; letter-spacing: 0.16em; }
.inv-card .inv-deadline { margin-top: 0.55rem; font-size: 0.68rem; color: var(--muted); letter-spacing: 0.04em; }

/* Before the card is fully out, only its top is seen above the pocket, so the rest stays hidden */
.inv-card .inv-late { opacity: 0; transition: opacity 0.6s 0.5s; }
.revealed .inv-card .inv-late { opacity: 1; }
.invite:not(.revealed) .inv-card { pointer-events: none; }

/* 1. card slides up out of the pocket */
.sliding .inv-card { transform: translateY(0); }
/* 2. envelope drops away, the card comes forward (JS sets --tx, --ty and --s to centre it) */
.revealed .inv-card { transform: translate(var(--tx, 0), var(--ty, 0)) scale(var(--s, 1)); }
.revealed .inv-back, .revealed .inv-pocket, .revealed .inv-flap, .revealed .inv-seal {
  transition: transform 0.9s cubic-bezier(.6, 0, .4, 1), opacity 0.7s 0.15s;
  transform: translateY(70vh) rotate(4deg);
  opacity: 0;
}

/* ---------- Falling petals ---------- */
.inv-petals { position: absolute; inset: 0; z-index: 8; pointer-events: none; overflow: hidden; }
.inv-petals i {
  position: absolute;
  top: -8vh;
  left: var(--x);
  width: var(--size);
  height: calc(var(--size) * 0.75);
  background: var(--c);
  border-radius: 0 100% 0 100%;
  opacity: 0.9;
  animation: inv-fall var(--dur) linear var(--delay) forwards;
}
@keyframes inv-fall {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.95; }
  100% { transform: translate(var(--drift), 115vh) rotate(var(--spin)); opacity: 0.6; }
}

/* Short screens (phones held sideways): a smaller envelope */
@media (max-height: 560px) {
  .inv-stage { --w: min(70vh, 340px); }
}

@media (prefers-reduced-motion: reduce) {
  .invite *, .invite *::before, .invite *::after { animation: none !important; transition-duration: 0.01s !important; transition-delay: 0s !important; }
  .inv-petals { display: none; }
}
