/* ─── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --burgundy:       #5a2d3a;
  --burgundy-dark:  #3d1e27;
  --burgundy-light: #7a3d4e;
  --cream:          #f5efe6;
  --card-w:         420px;
  --card-ratio:     5 / 7;
  --env-w:          480px;
  --env-h:          320px;
  --shadow-card:    0 8px 40px rgba(90, 45, 58, 0.22), 0 2px 8px rgba(0,0,0,0.10);
  --shadow-card-up: 0 24px 64px rgba(90, 45, 58, 0.32), 0 8px 24px rgba(0,0,0,0.14);
}

html {
  scroll-behavior: auto;
}

body {
  background: var(--cream);
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(180,140,100,0.03) 0px,
      rgba(180,140,100,0.03) 1px,
      transparent 1px,
      transparent 8px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(180,140,100,0.03) 0px,
      rgba(180,140,100,0.03) 1px,
      transparent 1px,
      transparent 8px
    );
  font-family: 'Georgia', serif;
  overflow-x: hidden;
}

/* ─── Scroll container (200vh) + sticky scene ───────────────── */

#scrollContainer {
  height: 180vh;
  position: relative;
}

#stickyScene {
  position: sticky;
  top: 0;
  /*
   * 100vh on mobile Chrome includes the area behind the URL bar, so
   * bottom-anchored elements (like the scroll pill) get clipped. 100svh
   * (small viewport height) always reserves space for the URL bar.
   */
  height: 100vh;     /* fallback for old browsers */
  height: 100svh;
  overflow: hidden;
}

#scrollRunway {
  height: 80vh;
  pointer-events: none;
}

/* ─── Hero section ──────────────────────────────────────────── */
.hero-section {
  height: 100vh;     /* fallback */
  height: 100svh;    /* matches stickyScene — pill stays above mobile URL bar */
  position: relative;          /* positioning parent for cards */
  isolation: isolate;          /* own stacking context         */
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0;           /* Envelope pinned flush to viewport bottom */
}

/* ─── Scene — perspective container for the envelope ────────── */
.scene {
  perspective: 1200px;
  perspective-origin: 50% 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* ─── Envelope wrapper ──────────────────────────────────────── */
/*
 * Background element. JS animates translateY here so the envelope
 * sinks downward as the user scrolls. Cards are siblings in
 * hero-section, not children, so they don't move with it.
 */
.envelope-wrapper {
  position: relative;
  width: var(--env-w);
  height: var(--env-h);
  /*
   * Nudge the envelope 2px below the viewport bottom so its bottom edge
   * bleeds off-screen — kills the hairline that was visible where the
   * envelope met the page background.
   */
  transform: translateY(2px);
  /*
   * Establish a stacking context so internal z-indices (back z:1, cards
   * z:2/3, front z:4, flap z:6) reliably stack relative to each other.
   *
   * clip-path with negative top inset = clips ONLY at the bottom edge of
   * the wrapper. Cards extend above the wrapper (visible) but anything
   * below the envelope bottom is hidden. Replaces the old #bottomMask.
   */
  isolation: isolate;
  clip-path: inset(-9999px 0 0 0);  /* Clip anything below envelope bottom */
}

/* ─── Envelope back panel ───────────────────────────────────── */
.envelope-back {
  position: absolute;
  inset: 0;
  background: var(--burgundy-dark);
  background-image:
    repeating-linear-gradient(
      60deg,
      rgba(255,255,255,0.015) 0px,
      rgba(255,255,255,0.015) 1px,
      transparent 1px,
      transparent 6px
    );
  border-radius: 4px 4px 6px 6px;
  z-index: 1;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25), 0 1px 4px rgba(0,0,0,0.15);
}

/* ─── Card containers ───────────────────────────────────────── */
/*
 * Cards are position:absolute siblings of envelope in .scene, positioned
 * relative to hero-section. They sit at bottom: calc(15vh + 12px) so they
 * align with the envelope's card slot visually.
 *
 * z-index: 20 puts them on top of the envelope (z:1–6 range) so they're
 * always prominent. JS drives translateY to animate rising / exiting.
 *
 * Envelope sinks as user scrolls, but cards compensate for that sink
 * so they stay in the viewport while the envelope drifts downward.
 *
 * A masking div (z:19) hides the card portions that are inside the
 * envelope's visual bounds, creating the illusion they're emerging from it.
 */
.card-container {
  position: absolute;
  left: 50%;
  bottom: 0;  /* Card bottom aligned with envelope bottom (which sits at viewport bottom) */
  transform: translateX(-50%) translateY(0px);
  width: var(--card-w);
  /*
   * Hide cards until JS has positioned them inside the envelope.
   * Without this, on first paint the cards sit at their CSS default
   * (translateY 0 = card bottom at envelope bottom, card top sticking
   * ~268px above envelope) and flash through the closed flap for one
   * frame before computeAnimParams() runs. JS removes .cards-armed
   * from the body once positioning is done.
   */
  visibility: hidden;
  /*
   * Card sits BEHIND the envelope-front (z:4) but ABOVE the back panel (z:1).
   * Now living INSIDE .envelope-wrapper (which is a stacking context via
   * isolation:isolate). Positioned absolute relative to the wrapper.
   * bottom: 0 aligns card bottom with envelope-wrapper bottom; cards extend
   * UPWARD beyond the wrapper (visible — wrapper's clip-path uses negative
   * top inset so nothing above is clipped, only below).
   */
  z-index: 2;
  will-change: transform;
}

/* Front card sits in front of back card */
#cardFront { z-index: 3; }

/* Kill the drop shadow on the front card — image already has its own
   decorative border. !important so it beats the JS inline shadow that
   slideCardUp() sets during the rise animation. */
#cardFront > img { box-shadow: none !important; }

/* Reveal cards once JS has positioned them hidden inside the envelope */
body.cards-armed .card-container { visibility: visible; }

.card-container > img,
.card-container > .card-back-content {
  width: 100%;
  aspect-ratio: var(--card-ratio);
  object-fit: cover;
  display: block;
  border-radius: 3px;
  box-shadow: var(--shadow-card);
  user-select: none;
  -webkit-user-drag: none;
}

/* ─── RSVP card (back) — HTML version w/ clickable URL ───────── */
/*
 * Replicates the look of the original card-back.jpg but as live HTML so
 * the URL is a real <a> link. Card dimensions/shadow/border-radius come
 * from the .card-back-content rule above.
 */
.card-back-content {
  background: #fdfaf3;            /* warm off-white paper */
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(180,140,100,0.04) 0px,
      rgba(180,140,100,0.04) 1px,
      transparent 1px,
      transparent 9px
    );
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: 11% 9% 8%;
  color: #2a1a20;
  font-family: 'Cormorant Garamond', 'Georgia', serif;
}

.rsvp-script {
  font-family: 'Pinyon Script', 'Great Vibes', cursive;
  font-size: clamp(3.4rem, 8.6vw, 5.4rem);
  line-height: 0.78;
  font-weight: 400;
  color: #1a0f14;
  margin-bottom: -0.18em;            /* let RSVP nest under the script */
  letter-spacing: 0.01em;
}

.rsvp-title {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-size: clamp(2.9rem, 7.4vw, 4.6rem);
  font-weight: 500;
  letter-spacing: 0.06em;
  line-height: 1;
  color: #1a0f14;
  margin-top: 0;
}

.rsvp-date {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-size: clamp(0.95rem, 1.9vw, 1.25rem);
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-top: 0.55em;
  color: #2a1a20;
}

.rsvp-body {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-size: clamp(0.78rem, 1.55vw, 1rem);
  line-height: 1.65;
  font-weight: 400;
  margin-top: 1.6em;
  color: #2a1a20;
  max-width: 90%;
}

.rsvp-qr {
  display: block;
  width: 38%;
  max-width: 160px;
  height: auto;
  aspect-ratio: 1 / 1;
  margin: 1.4em auto 0;              /* horizontal auto centers even outside flex */
  align-self: center;                /* belt-and-braces in flex column */
  object-fit: contain;
  /* Override the global .card-container > img rule */
  box-shadow: none !important;
  border-radius: 0 !important;
}

.rsvp-link {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-size: clamp(0.95rem, 1.95vw, 1.25rem);
  font-weight: 600;
  letter-spacing: 0.015em;
  margin-top: 0.7em;
  color: #1a0f14;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color 200ms ease;
  cursor: pointer;
}

.rsvp-link:hover {
  color: var(--burgundy);
}

.rsvp-closing {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-style: italic;
  font-size: clamp(0.82rem, 1.6vw, 1.05rem);
  margin-top: auto;
  padding-top: 1.4em;
  color: #2a1a20;
}

/* ─── Bottom mask ────────────────────────────────────────────────── */
/*
 * Static cream strip at the bottom of hero-section. Covers the card
 * portions that extend below the envelope's bottom edge so the cards
 * appear to emerge cleanly from inside the envelope.
 *
 * Sits at z:25 — above cards (z:20) but below scroll hint (z:30).
 * Painted cream + page texture so it blends with the body background.
 */
#bottomMask {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(15vh + 10px);
  background: var(--cream);
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(180,140,100,0.03) 0px,
      rgba(180,140,100,0.03) 1px,
      transparent 1px,
      transparent 8px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(180,140,100,0.03) 0px,
      rgba(180,140,100,0.03) 1px,
      transparent 1px,
      transparent 8px
    );
  z-index: 25;
  pointer-events: none;
}

/* ─── Envelope front body ───────────────────────────────────── */
/*
 * Sits at z-index 4 within envelope-wrapper's stacking context.
 * Cards are outside the wrapper so they're never occluded by this.
 */
.envelope-front {
  position: absolute;
  inset: 0;
  background: var(--burgundy);
  background-image:
    repeating-linear-gradient(
      60deg,
      rgba(255,255,255,0.025) 0px,
      rgba(255,255,255,0.025) 1px,
      transparent 1px,
      transparent 6px
    ),
    repeating-linear-gradient(
      -60deg,
      rgba(0,0,0,0.04) 0px,
      rgba(0,0,0,0.04) 1px,
      transparent 1px,
      transparent 6px
    );
  border-radius: 4px 4px 6px 6px;
  z-index: 4;
  box-shadow:
    0 2px 12px rgba(0,0,0,0.18),
    inset 0 1px 0 rgba(255,255,255,0.06);
  /*
   * V-shaped opening at top — matches the flap's triangle.
   * When the flap opens, this V is revealed and cards behind become visible.
   * Polygon: top-left → center-middle (V apex) → top-right → bottom corners.
   */
  clip-path: polygon(0% 0%, 50% 50%, 100% 0%, 100% 100%, 0% 100%);
}

/* Diagonal fold lines */
.fold-left,
.fold-right {
  position: absolute;
  bottom: 0;
  height: 100%;
  width: 50%;
  pointer-events: none;
}
.fold-left {
  left: 0;
  background: linear-gradient(
    to bottom right,
    transparent 49.5%,
    rgba(0,0,0,0.08) 49.5%,
    rgba(0,0,0,0.08) 50.5%,
    transparent 50.5%
  );
}
.fold-right {
  right: 0;
  background: linear-gradient(
    to bottom left,
    transparent 49.5%,
    rgba(0,0,0,0.08) 49.5%,
    rgba(0,0,0,0.08) 50.5%,
    transparent 50.5%
  );
}
.fold-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(
    to top,
    rgba(0,0,0,0.06) 0%,
    transparent 60%
  );
  pointer-events: none;
}

/* ─── Wax seal ──────────────────────────────────────────────── */
/*
 * Starts visible while the envelope is "sealed" at load. Fades out
 * once the scroll hint pill appears (which now sits in the same spot)
 * — JS adds .wax-seal-hidden to the body at the same beat the pill
 * appears (T+2800ms).
 */
.wax-seal {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 36%, #8b3a4a, #5a1e2a 60%, #3d1220);
  box-shadow:
    0 2px 6px rgba(0,0,0,0.35),
    0 0 0 2px rgba(255,255,255,0.07),
    inset 0 1px 2px rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,230,220,0.88);
  font-size: 0.65rem;
  font-family: 'Georgia', serif;
  letter-spacing: 0.1em;
  font-style: italic;
  z-index: 5;
  pointer-events: none;
  opacity: 1;
  transition: opacity 500ms ease;
}

body.wax-seal-hidden .wax-seal {
  opacity: 0;
}

/* ─── Flap ──────────────────────────────────────────────────── */
.envelope-flap-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  perspective: 900px;
  perspective-origin: 50% 0%;
  z-index: 6;
  pointer-events: none;
}

.envelope-flap {
  width: 100%;
  height: 100%;
  transform-origin: top center;
  transform: rotateX(0deg);
  transform-style: preserve-3d;
  transition: transform 800ms cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
  background: var(--burgundy-dark);
  background-image:
    repeating-linear-gradient(
      60deg,
      rgba(255,255,255,0.02) 0px,
      rgba(255,255,255,0.02) 1px,
      transparent 1px,
      transparent 6px
    );
  box-shadow: 0 4px 8px rgba(0,0,0,0.12);
}

.flap-inner {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--burgundy-light);
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
  opacity: 0.5;
  transform: rotateX(180deg);
}

.envelope-flap.open {
  transform: rotateX(-178deg);
}

/*
 * Once flap is open, lower its containing wrapper's z-index so it
 * doesn't occlude the card as it rises out of the envelope.
 * The flap visually hangs back in 3D space; this matches that intent.
 */
.envelope-flap-wrapper.flap-open {
  z-index: 1;
}

/* ─── Pulse keyframe ────────────────────────────────────────── */
@keyframes envelopePulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.012); }
}

.envelope-wrapper.pulse {
  animation: envelopePulse 600ms ease-in-out;
}

/* ─── Scroll hint — pill button ─────────────────────────────── */
/*
 * Sits above the envelope after the front card has risen.
 * Pill shape on a translucent cream background so it reads as a CTA
 * against the card behind it. Clickable — scrolls the page smoothly.
 */
.scroll-hint {
  position: absolute;
  /*
   * 20px above the bottom of the visible viewport. env(safe-area-inset-bottom)
   * accounts for iOS home indicator / chin so the pill never gets clipped.
   */
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  padding: 10px 22px;
  background: rgba(253, 250, 243, 0.92);
  border: 1px solid var(--burgundy);
  border-radius: 999px;
  color: var(--burgundy);
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  pointer-events: none;                /* enabled by .visible */
  opacity: 0;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow:
    0 4px 16px rgba(90, 45, 58, 0.18),
    0 1px 3px rgba(0,0,0,0.08);
  transition:
    opacity 600ms ease,
    transform 600ms cubic-bezier(0.4, 0, 0.2, 1),
    background-color 200ms ease,
    color 200ms ease,
    box-shadow 200ms ease;
  z-index: 30;
}

.scroll-hint .arrow {
  display: inline-block;
  font-size: 1.05em;
  line-height: 1;
  animation: scrollHintBob 1600ms ease-in-out infinite;
}

@keyframes scrollHintBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(3px); }
}

.scroll-hint.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.scroll-hint:hover {
  background: var(--burgundy);
  color: var(--cream);
  box-shadow:
    0 6px 20px rgba(90, 45, 58, 0.28),
    0 2px 6px rgba(0,0,0,0.12);
}

/* ─── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .envelope-flap { transition: none; }
  .card-container { transition: none !important; }
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 540px) {
  :root {
    --card-w:  85vw;
    --env-w:   96vw;
    --env-h:   220px;
  }

  .wax-seal {
    width: 42px;
    height: 42px;
    font-size: 0.55rem;
    bottom: 16px;
  }
}

@media (min-width: 541px) and (max-width: 720px) {
  :root {
    --card-w: 380px;
    --env-w:  440px;
    --env-h:  290px;
  }
}
