:root {
  --cream: #d8c9af;
  --cream-light: #ece0cf;
  --ink: #4a4033;
  --gold: #b0843f;
  --gold-soft: #c9a15a;
  --ease-luxury: cubic-bezier(.22, 1, .36, 1);

  /* Envelope placement on the empty.png stage. Both the sealed and open
   * crops use the SAME width and the SAME bottom anchor, so their bodies
   * occupy the exact same box — only the flap differs. Nothing moves. */
  --env-w: 50%;
  --env-cx: 50%;
  --env-bottom: 22%;
}

*, *::before, *::after { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: Georgia, serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

/* ---------------- *
 * Stage            *
 * ---------------- */
.experience {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(130% 120% at 26% 20%, var(--cream-light), transparent 55%),
    linear-gradient(150deg, #e2d4bd, var(--cream) 50%, #cdbd9f);
}

.stage {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* the framed artwork; the envelope crops sit inside it */
.scene-frame {
  position: relative;
  width: min(96vw, calc(94vh * 1.5));
  aspect-ratio: 1536 / 1024;
  overflow: hidden;
}

/* static background: gold frame, monogram, prompt, envelope shadow */
.scene-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------------- *
 * Envelope         *
 * ---------------- */
/* On desktop/landscape the stack simply fills the frame, so the envelope
 * and seal keep the exact frame-relative coordinates they had before.
 * The portrait layout re-purposes it as a sized, centered envelope box. */
.env-stack {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.env {
  position: absolute;
  left: var(--env-cx);
  bottom: var(--env-bottom);
  width: var(--env-w);
  height: auto;
  transform: translateX(-50%);
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 1s var(--ease-luxury);
}

/* the open envelope waits behind; the sealed one covers it until tapped */
.env--open   { z-index: 1; opacity: 0; }
.env--closed { z-index: 2; opacity: 1; }

.experience.is-open .env--closed { opacity: 0; }
.experience.is-open .env--open   { opacity: 1; }

/* ---------------- *
 * Monogram + prompt (portrait only; baked into empty.png on desktop) *
 * ---------------- */
.mono,
.prompt {
  display: none;   /* shown only in the portrait layout below */
}

/* ---------------- *
 * Photo + invite   *
 * ---------------- */
.card {
  position: absolute;
  left: 50%;
  top: 46%;
  z-index: 5;
  height: min(64%, 560px);
  width: auto;
  max-width: 82%;
  object-fit: contain;
  border-radius: 3px;
  background: #f4efe4;
  box-shadow:
    0 10px 24px rgba(74, 55, 32, .16),
    0 34px 80px rgba(74, 55, 32, .34);
  transform: translate(-50%, -40%) scale(.9);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity .9s var(--ease-luxury),
    transform 1.05s var(--ease-luxury);
  will-change: transform, opacity;
}

.card--photo  { z-index: 6; }
.card--invite { z-index: 7; }

.experience.is-photo .card--photo {
  opacity: 1;
  transform: translate(-50%, -46%) scale(1);
}

.experience.is-invite .card--photo {
  opacity: 0;
  transform: translate(-50%, -50%) scale(.98);
}
.experience.is-invite .card--invite {
  opacity: 1;
  transform: translate(-50%, -46%) scale(1);
}

/* ---------------- *
 * Seal tap target  *
 * ---------------- */
.seal-button {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 58%;                 /* over the wax seal on the sealed envelope */
  width: 13%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .5s var(--ease-luxury), opacity .4s ease;
}

.seal-button:focus-visible { outline: none; }
.seal-button:active { transform: translate(-50%, -50%) scale(.94); }

.experience.is-open .seal-button {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ---------------- *
 * Sparkles         *
 * ---------------- */
.sparkles {
  position: fixed;
  inset: 0;
  z-index: 9;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s var(--ease-luxury) .4s;
}
.experience.is-open .sparkles { opacity: 1; }

/* ---------------- *
 * Portrait layout  *
 * ---------------- *
 * The baked empty.png scene is landscape (1536×1024); on a portrait phone
 * it collapses to a tiny band. In portrait we drop the baked frame and lay
 * the envelope, cards, monogram and prompt out relative to the viewport so
 * the whole thing fills the screen and stays readable. Desktop is untouched. */
@media (orientation: portrait) {
  .stage { padding: 0; }

  .scene-frame {
    width: 100vw;
    height: 100svh;
    aspect-ratio: auto;
    overflow: visible;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(22px, 6vh, 60px);
    padding: max(env(safe-area-inset-top), 4vh) 6vw
             max(env(safe-area-inset-bottom), 4vh);
  }

  /* drop the baked landscape scene; the cream gradient backs the layout */
  .scene-bg { display: none; }

  /* monogram, above the envelope */
  .mono {
    display: flex;
    align-items: center;
    gap: .3em;
    margin: 0;
    font-family: Georgia, serif;
    font-weight: 400;
    font-size: clamp(2rem, 12vw, 3.4rem);
    letter-spacing: .1em;
    color: #b6a17c;
    text-indent: .1em;
    transition: opacity .8s var(--ease-luxury);
  }
  .mono i {
    font-style: normal;
    font-size: .85em;
    font-weight: 300;
    color: var(--gold-soft);
    opacity: .65;
  }

  /* the envelope box, sized to the sealed-envelope crop so the seal tap
   * target lands exactly on the wax seal */
  .env-stack {
    position: relative;
    inset: auto;
    flex: none;
    width: min(78vw, 380px);
    aspect-ratio: 864 / 549;      /* closed_cropped.png */
    filter: drop-shadow(0 20px 38px rgba(74, 55, 32, .26));
  }

  /* sealed envelope fills the box; open envelope shares its width + bottom
   * so the bodies coincide and only the flap rises above */
  .env-stack .env--closed,
  .env-stack .env--open {
    left: 0;
    bottom: 0;
    width: 100%;
    transform: none;
  }
  .env-stack .env--closed { height: 100%; }
  .env-stack .env--open   { height: auto; }

  /* seal tap target over the wax seal (~58% down the sealed envelope) */
  .env-stack .seal-button {
    top: 58%;
    width: 24%;
  }

  /* photo + invitation, sized to the viewport and centered on screen */
  .card {
    top: 50%;
    height: auto;
    width: min(76vw, 340px);
    max-width: none;
  }

  /* prompt, below the envelope */
  .prompt {
    display: block;
    margin: 0;
    font-family: Georgia, serif;
    font-size: clamp(.66rem, 3.4vw, .8rem);
    letter-spacing: .3em;
    text-transform: uppercase;
    color: #a2916f;
    transition: opacity .8s var(--ease-luxury);
  }

  /* the invitation is open — the "tap to open" cues bow out */
  .experience.is-open .mono,
  .experience.is-open .prompt { opacity: 0; }
}

/* ---------------- *
 * Reduced motion   *
 * ---------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-delay: 0ms !important;
    transition-duration: .01ms !important;
  }
}
