/* The opening gate: ivory doors with gold mouldings, the invitation's own flowers, sheer curtains
   and fairy lights. Everything sways in a soft breeze until the seal is tapped; then a warm light
   blooms, the curtains draw aside and the doors swing open with their flowers. */

/* ───────── Petals (drawn on a canvas by main.js; float above the gate) ───────── */
.petals { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* ───────── Frame ───────── */
.gate { display: none; }
.js .gate {
  --door-gold: rgba(184, 137, 58, .85);
  --door-gold-soft: rgba(184, 137, 58, .45);
  --door-open-ms: 2.1s;
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  perspective: 1700px;
  overflow: hidden;
  background: #EADBBE;
}

/* ───────── Doors ───────── */
/* Each door fills half the screen and is hinged at the screen edge, so they open from the outer edges.
   The sheer curtains hang in front of the doors' outer edges. */
.gate-door {
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  width: 50.2%;   /* the 0.2% overlap hides any hairline gap at the seam */
  /* Swing open, and fade out in the second half so no edge-on sliver is left over the invitation */
  transition: transform var(--door-open-ms) cubic-bezier(.68, 0, .22, 1) .35s, opacity .8s ease 1.25s;
  backface-visibility: hidden;
  transform-style: preserve-3d;
}
.gate-door--l {
  left: 0;
  transform-origin: left center;
  background: var(--paper-grain), linear-gradient(90deg, #EEDCB8 0%, #F8ECD3 28%, #FCF4E3 70%, #F3E3C3 100%);
  box-shadow: inset -12px 0 18px -14px rgba(110, 70, 25, .55);
}
.gate-door--r {
  right: 0;
  transform-origin: right center;
  background: var(--paper-grain), linear-gradient(270deg, #EEDCB8 0%, #F8ECD3 28%, #FCF4E3 70%, #F3E3C3 100%);
  box-shadow: inset 12px 0 18px -14px rgba(110, 70, 25, .55);
}

/* Raised gold moulding: an outer hairline and an inner one, like a carved door panel */
.door-panel {
  position: absolute;
  top: max(26px, calc(env(safe-area-inset-top, 0px) + 18px));
  bottom: max(26px, calc(env(safe-area-inset-bottom, 0px) + 18px));
  left: 12px;
  right: 12px;
  border: 1.5px solid var(--door-gold);
  border-radius: 3px;
  box-shadow: inset 0 0 0 6px transparent, inset 0 0 0 7.5px var(--door-gold-soft), 0 1px 0 rgba(255, 255, 255, .7);
}

/* ───────── Flowers: the front layer, over the curtains and doors ─────────
   Each bouquet is a fixed base (the dense heart of dahlias and peonies) plus separate parts:
   sprigs, strands and leaves cut from the same art. Only the parts move, each from the point
   where it joins the bouquet, at its own pace (--swing, --dur, --delay are set per part in the
   HTML, generated alongside the images). The .gf wrapper carries the opening move. */
.gate-flowers { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.gf {
  position: absolute;
  display: block;
  transition: transform 1.7s cubic-bezier(.6, 0, .25, 1) .25s, opacity 1.1s ease .7s;
}
.gf img { user-select: none; }
.gf-base { display: block; width: 100%; height: auto; }
.gf-part {
  position: absolute;
  height: auto;
  will-change: transform;
  animation: gf-breeze var(--dur, 5s) ease-in-out var(--delay, 0s) infinite;
}
/* Top garlands hang from the outer corners; the bottom bouquets are two different arrangements */
.gf-tl { top: -6px; left: -3%; width: 57%; }
.gf-tr { top: -6px; right: -3%; width: 57%; }
.gf-bl { bottom: -8px; left: -2%; width: 53%; }
.gf-br { bottom: -8px; right: -2%; width: 46%; }

/* A soft, uneven breeze: out, back past the middle, a small return, then rest */
@keyframes gf-breeze {
  0%, 100% { transform: rotate(calc(var(--swing, 2deg) * -1)); }
  45% { transform: rotate(var(--swing, 2deg)); }
  72% { transform: rotate(calc(var(--swing, 2deg) * .3)); }
}

/* ───────── Curtains ───────── */
.curtain-wrap {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 19%;
  z-index: 3;   /* over the doors, under the flowers */
  pointer-events: none;
  transition: transform 1.7s cubic-bezier(.68, 0, .22, 1) .15s, opacity 1.2s ease .6s;
}
.curtain-wrap--l { left: 0; }
.curtain-wrap--r { right: 0; }
/* The body ripples as one piece, so the holdback stays on the gathered fabric */
.curtain-body { position: relative; width: 100%; height: 100%; animation: drape 8s ease-in-out infinite; }
.curtain-wrap--l .curtain-body { transform-origin: 0 0; }
.curtain-wrap--r .curtain-body { transform-origin: 100% 0; animation-delay: -3s; }
.curtain {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  filter: drop-shadow(0 6px 10px rgba(110, 70, 25, .18));
}
.curtain-edge { fill: none; stroke: #C99A45; stroke-width: 1.2; vector-effect: non-scaling-stroke; opacity: .8; }

/* ───────── Royal holdback: gold band, ruby rosette, jewelled tassel ─────────
   The curtain is gathered across x 0–36% at 60% height; the band wraps that gather. */
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.holdback {
  position: absolute;
  top: 60%;
  width: 52px;
  height: auto;
  overflow: visible;
  transform: translate(-50%, -14%);
  filter: drop-shadow(0 3px 4px rgba(90, 55, 10, .45));
}
.curtain-wrap--l .holdback { left: 19%; }
.curtain-wrap--r .holdback { left: 81%; }
.hb-band, .hb-gold { fill: url(#hbGold); stroke: #7A4E14; stroke-width: .6; }
.hb-band-line { fill: none; stroke: #FFF4C4; stroke-width: .8; opacity: .7; }
.hb-ring { fill: none; stroke: #FFF1BC; stroke-width: 1.3; }
.hb-ruby { fill: url(#hbRuby); stroke: #F0CC78; stroke-width: .8; }
.hb-shine { fill: #FFFFFF; opacity: .85; }
.hb-cord { fill: none; stroke: #C9963F; stroke-width: 1.6; }
.hb-fringe { fill: none; stroke: #7A4E14; stroke-width: .55; opacity: .55; }
.hb-glint { fill: #FFFBE6; transform-box: fill-box; transform-origin: 50% 50%; animation: hb-glint 3.2s ease-in-out infinite; }
.hb-tassel { transform-box: fill-box; transform-origin: 50% 0; animation: hb-swing 3.8s ease-in-out infinite; }
.curtain-wrap--r .hb-glint { animation-delay: -1.6s; }
.curtain-wrap--r .hb-tassel { animation-delay: -1.9s; }
@keyframes hb-glint {
  0%, 60%, 100% { opacity: 0; transform: scale(.3) rotate(0deg); }
  75% { opacity: 1; transform: scale(1.2) rotate(45deg); }
}
@keyframes hb-swing {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}
@keyframes drape {
  0%, 100% { transform: skewX(0deg) scaleX(1); }
  50% { transform: skewX(1.1deg) scaleX(1.04); }
}

/* ───────── Fairy lights (spans added by main.js) ───────── */
.gate-lights { position: absolute; inset: 0; z-index: 5; pointer-events: none; transition: opacity .8s ease .2s; }
.fairy {
  position: absolute;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: #FFE9A8;
  box-shadow: 0 0 5px 2px rgba(255, 196, 92, .95), 0 0 14px 5px rgba(240, 170, 70, .45);
  animation: fairy var(--tw, 2.6s) ease-in-out var(--dl, 0s) infinite;
}
@keyframes fairy {
  0%, 100% { opacity: .25; transform: scale(.7); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* ───────── Centre: the seal, at the exact middle of the screen ───────── */
/* The centre box is exactly the seal, so the gate's grid centring puts the seal dead centre;
   the caption hangs below it without shifting it. */
.gate-center {
  position: relative;
  z-index: 6;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--ink);
  transition: opacity .6s ease, transform .9s var(--ease-out);
}
/* A soft pool of light behind the seal and caption keeps them clear of the flowers */
.gate-center::before {
  content: "";
  position: absolute;
  inset: -70px -90px -120px;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(253, 247, 234, .92), rgba(253, 247, 234, .6) 60%, rgba(253, 247, 234, 0));
}
.gate-caption {
  position: absolute;
  top: calc(100% + 26px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.gate-hint { font-family: var(--f-body); font-style: italic; font-size: 16px; color: var(--ink-soft); }
.gate-date { font-family: var(--f-caps); font-size: 12px; letter-spacing: .32em; color: var(--gold-lo); }

/* Maroon wax seal with a gold monogram */
.seal {
  position: relative;
  width: 112px;
  height: 112px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .5s var(--ease-out), opacity .5s ease;
}
.seal::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 1px solid rgba(142, 26, 44, .45);
  animation: halo 2.6s ease-out infinite;
}
@keyframes halo { 0% { transform: scale(.85); opacity: .9; } 100% { transform: scale(1.35); opacity: 0; } }
.seal-wax {
  position: absolute;
  inset: 0;
  border-radius: 47% 53% 50% 50% / 52% 48% 52% 48%;
  background: radial-gradient(circle at 34% 30%, #B8404F 0%, #8E1A2C 30%, #6E0F1E 62%, #44070F 100%);
  box-shadow: 0 12px 24px -8px rgba(74, 8, 18, .65), inset 0 -4px 10px rgba(40, 0, 6, .55), inset 0 3px 6px rgba(255, 190, 190, .35);
  display: grid;
  place-items: center;
  overflow: hidden;  /* keeps the sheen inside the wax */
  animation: seal-breathe 4.2s ease-in-out infinite;
  transition: transform .14s ease-in, box-shadow .14s ease-in, opacity .45s ease;
}
@keyframes seal-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.025); }
}
.seal-wax::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; border: 1px solid rgba(233, 200, 120, .5); }
.seal-mono { position: relative; z-index: 1; width: 70%; display: block; }
.seal-mono .mono-lines { stroke: #EBCB82; }
.seal:hover { transform: scale(1.04); }

/* A band of gold light sweeps across the wax and its monogram, then rests */
.seal-sheen {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(115deg,
    transparent 36%,
    rgba(214, 150, 50, .35) 44%,
    rgba(255, 212, 120, .8) 49%,
    rgba(255, 236, 180, .9) 50%,
    rgba(255, 212, 120, .8) 51%,
    rgba(214, 150, 50, .35) 56%,
    transparent 64%);
  background-size: 300% 100%;
  background-repeat: no-repeat;
  mix-blend-mode: screen;
  animation: seal-sheen 4.2s ease-in-out infinite;
}
@keyframes seal-sheen {
  0%        { background-position: 110% 0; }
  45%, 100% { background-position: -10% 0; }
}

/* Tap: the seal presses down like a button… */
.seal:active .seal-wax,
.seal.is-pressed .seal-wax {
  animation: none;
  transform: scale(.88) translateY(3px);
  box-shadow: 0 4px 8px -4px rgba(74, 8, 18, .6), inset 0 5px 14px rgba(30, 0, 4, .7);
}
/* …then pops off, leaving a ring of gold that spreads outward with the petals */
.seal::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(232, 190, 110, .95);
  box-shadow: 0 0 12px rgba(232, 190, 110, .7);
  opacity: 0;
  pointer-events: none;
}
.seal.is-popping { transform: none; }
.seal.is-popping::before { opacity: 0; }
.seal.is-popping .seal-wax {
  animation: none;
  transform: scale(1.32);
  opacity: 0;
  transition: transform .5s cubic-bezier(.2, .9, .3, 1.25), opacity .4s ease .08s;
}
.seal.is-popping::after { animation: seal-ring .8s ease-out forwards; }
@keyframes seal-ring {
  0%   { transform: scale(.9); opacity: 1; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ───────── Opening ───────── */
.gate-light {
  position: absolute;
  inset: -20%;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 246, 222, 1) 0%, rgba(255, 230, 175, .65) 22%, rgba(255, 220, 160, 0) 55%);
}
.is-open .gate-light { animation: gate-flash 1.9s ease-out forwards; }
@keyframes gate-flash {
  0% { opacity: 0; transform: scale(.4); }
  25% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.6); }
}

.is-open .seal { transform: scale(1.18); opacity: 0; }
.is-open .gate-center { opacity: 0; transform: scale(.94); transition-delay: .1s; }
.is-open .curtain-wrap--l { transform: translateX(-110%); opacity: 0; }
.is-open .curtain-wrap--r { transform: translateX(110%); opacity: 0; }
.is-open .gate-lights { opacity: 0; }
.is-open .gate-door--l { transform: rotateY(-104deg); opacity: 0; }
.is-open .gate-door--r { transform: rotateY(104deg); opacity: 0; }
/* The flowers part outward: garlands lift away to the top corners, bouquets sink to the bottom ones */
.is-open .gf { opacity: 0; }
.is-open .gf-tl { transform: translate(-34%, -28%) rotate(-6deg); }
.is-open .gf-tr { transform: translate(34%, -28%) rotate(6deg); }
.is-open .gf-bl { transform: translate(-34%, 30%) rotate(5deg); }
.is-open .gf-br { transform: translate(34%, 30%) rotate(-5deg); }
.is-open .gate { pointer-events: none; background: transparent; transition: background .6s ease .5s; }
