:root {
  --plum: #6b2a5c;
  --plum-deep: #4a1a3d;
  --plum-ink: #3a1430;
  --gold: #b8893e;
  --gold-deep: #9c6f2e;
  --gold-light: #e9cf94;
  --ivory: #fbf6ee;
  --paper: #fffcf6;
  --cream: #f3ebdf;
  --foil: linear-gradient(100deg, #9c6f2e 0%, #e9cf94 28%, #b8893e 50%, #f3e2b5 72%, #9c6f2e 100%);
  --serif: "Cormorant Garamond", "Times New Roman", serif;
  --script: "Pinyon Script", "Snell Roundhand", cursive;
  --sans: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-io: cubic-bezier(.65, 0, .35, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--serif);
  color: var(--plum-ink);
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, #fffaf2 0%, rgba(255, 250, 242, 0) 70%),
    radial-gradient(ellipse 60% 50% at 85% 10%, #efe2d2 0%, rgba(239, 226, 210, 0) 70%),
    radial-gradient(ellipse 70% 60% at 10% 95%, #ecdfcf 0%, rgba(236, 223, 207, 0) 70%),
    #f5ede2;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body.stage-envelope { overflow: hidden; height: 100svh; }

/* ---------- Backdrop ---------- */
.backdrop { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.backdrop::after { /* faint paper grain */
  content: ""; position: absolute; inset: 0; opacity: .35; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .45 0 0 0 0 .38 0 0 0 .08 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
#dust { position: absolute; inset: 0; width: 100%; height: 100%; }

.ribbon {
  position: absolute; width: 70vmax; height: clamp(46px, 7vmin, 80px); border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.18) 0%, rgba(255,255,255,0) 30%, rgba(0,0,0,.22) 100%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.04) 0 2px, rgba(0,0,0,.04) 2px 4px),
    linear-gradient(90deg, #4a1a3d 0%, #7a2e68 35%, #5c2150 60%, #8a3a76 80%, #4a1a3d 100%);
  box-shadow: 0 18px 30px -12px rgba(58, 20, 48, .45);
  opacity: .92;
}
.ribbon-tl { top: 4vmin; left: -30vmax; transform: rotate(-32deg); }
.ribbon-br { bottom: 6vmin; right: -32vmax; transform: rotate(-32deg); }

.blossom { /* soft, out-of-focus baby's breath */
  position: absolute; width: 34vmin; height: 34vmin; filter: blur(2.5px); opacity: .8;
  background:
    radial-gradient(circle at 20% 30%, #fff 0 4%, transparent 5%),
    radial-gradient(circle at 35% 18%, #fbf3e6 0 3.5%, transparent 4.5%),
    radial-gradient(circle at 48% 36%, #fff 0 3%, transparent 4%),
    radial-gradient(circle at 30% 50%, #f7ead6 0 4%, transparent 5%),
    radial-gradient(circle at 60% 22%, #fff 0 2.5%, transparent 3.5%),
    radial-gradient(circle at 15% 60%, #fff 0 3%, transparent 4%),
    radial-gradient(circle at 55% 55%, #f3e3cb 0 3%, transparent 4%),
    radial-gradient(circle at 42% 70%, #fff 0 2.5%, transparent 3.5%);
}
.blossom-tr { top: -4vmin; right: -2vmin; }
.blossom-bl { bottom: -6vmin; left: -4vmin; transform: rotate(160deg); }

.eyebrow {
  position: fixed; top: max(16px, env(safe-area-inset-top)); left: 0; right: 0; z-index: 3;
  margin: 0; text-align: center; font-family: var(--sans); font-size: 10.5px; font-weight: 500;
  letter-spacing: .42em; text-transform: uppercase; color: var(--plum);
  opacity: .8; transition: opacity .6s;
}
body:not(.stage-envelope) .eyebrow { position: absolute; }

/* ---------- Scene / envelope ---------- */
.scene {
  position: fixed; inset: 0; z-index: 2; display: grid; place-items: center;
  padding: 24px; transition: opacity .8s var(--ease-out);
}
.scene.is-gone { opacity: 0; pointer-events: none; }
.scene-inner { --w: min(86vw, 560px, 68svh); display: flex; flex-direction: column; align-items: center; gap: clamp(20px, 4vh, 36px); transform: translateY(6vh);
  transition: transform 1s var(--ease-io), opacity .8s; }
.scene.is-opening .scene-inner { transform: translateY(calc(6vh + var(--w) * .19)); }
.scene.is-opening .addressee { opacity: 0 !important; animation: none; transition: opacity .5s; }
.scene-logo {
  display: block; width: min(210px, 48vw, 24svh); height: auto; margin-bottom: calc(clamp(20px, 4vh, 36px) * -0.5);
  background: transparent; opacity: 0; animation: fadeUp 1.2s .15s var(--ease-out) forwards;
  filter: drop-shadow(0 6px 14px rgba(74, 26, 61, .12));
}
.scene.is-opening .scene-logo { opacity: 0 !important; animation: none; transition: opacity .5s; }

.scene-inner.is-dropping, .scene.is-opening .scene-inner.is-dropping { transform: translateY(70vh) rotate(3deg); opacity: 0; }

.addressee {
  margin: 0; font-family: var(--script); font-size: clamp(28px, 5.4vw, 40px); color: var(--plum);
  line-height: 1.1; text-align: center; opacity: 0; animation: fadeUp 1.2s .3s var(--ease-out) forwards;
}

.envelope {
  position: relative; width: var(--w); aspect-ratio: 3 / 2;
  perspective: 1400px;
  opacity: 0; animation: envIn 1.3s .1s var(--ease-out) forwards;
}

.env-back {
  position: absolute; inset: 0; border-radius: 6px; z-index: 0;
  background: linear-gradient(160deg, #3d1233, #2e0d27);
  box-shadow: 0 40px 60px -30px rgba(46, 13, 39, .7), 0 12px 24px -10px rgba(46, 13, 39, .35);
}

.env-letter {
  position: absolute; left: 5%; right: 5%; top: 5%; height: 90%; z-index: 2;
  background: var(--paper); border-radius: 3px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  transition: transform 1.1s var(--ease-out), opacity .3s;
}
.env-letter-frame {
  position: absolute; inset: 7px; border: 1px solid rgba(184, 137, 62, .55);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 7%;
  gap: 4%;
}
.env-letter-frame img { width: 46%; height: auto; }
.env-letter-frame span { font-family: var(--serif); font-size: clamp(14px, 3.2vw, 22px); color: var(--gold-deep); letter-spacing: .02em; }
.envelope.letter-out .env-letter { transform: translateY(-64%); }

.env-pocket { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; border-radius: 6px; overflow: hidden;
  filter: drop-shadow(0 -2px 4px rgba(0, 0, 0, .15)); }

.env-flap {
  position: absolute; left: 0; right: 0; top: 0; height: 62%; z-index: 4;
  transform-origin: 50% 0; transform: rotateX(0deg);
  transition: transform .9s var(--ease-io);
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .25));
}
.env-flap svg { width: 100%; height: 100%; display: block; }
.envelope.flap-open .env-flap { transform: rotateX(180deg); filter: none; }
.envelope.flap-behind .env-flap { z-index: 1; }

.seal {
  position: absolute; z-index: 6; left: 50%; top: 62%; width: clamp(84px, 19vw, 118px); aspect-ratio: 1;
  transform: translate(-50%, -58%); padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: 50%; -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 6px 8px rgba(40, 12, 34, .45));
  transition: transform .5s var(--ease-out), opacity .45s, filter .3s;
}
.seal svg { width: 100%; height: 100%; display: block; overflow: visible; }
.seal::before { /* pulse ring */
  content: ""; position: absolute; inset: -10%; border-radius: 50%;
  border: 1.5px solid rgba(233, 207, 148, .85); opacity: 0;
  animation: pulse 2.4s 1.6s infinite;
}
.seal:hover { transform: translate(-50%, -58%) scale(1.05); }
.seal:focus-visible { outline: 2px solid var(--gold-light); outline-offset: 6px; }
.seal-mono { font-family: var(--script); font-size: 54px; fill: #f6e4b4; }
.seal-mono-shadow { fill: #6e4a1b; opacity: .55; }
.envelope.is-opening .seal { transform: translate(-50%, -58%) scale(1.25); opacity: 0; pointer-events: none; }
.envelope.is-opening .seal::before { animation: none; }

.hint {
  margin: 0; font-family: var(--sans); font-size: 11px; font-weight: 500; letter-spacing: .32em;
  text-transform: uppercase; color: var(--plum); opacity: 0;
  animation: fadeUp 1s 1.2s var(--ease-out) forwards;
  transition: opacity .4s;
}
.hint span { animation: breathe 2.4s 2.2s ease-in-out infinite; display: inline-block; }
.scene.is-opening .hint { opacity: 0 !important; animation: none; }

/* ---------- Card (the letter) ---------- */
.card-wrap { position: relative; z-index: 1; padding: clamp(56px, 9vh, 88px) 16px 28px; min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; }
.card {
  position: relative; width: min(100%, 600px); background: var(--paper); border-radius: 4px;
  box-shadow: 0 50px 80px -40px rgba(58, 20, 48, .45), 0 18px 40px -20px rgba(58, 20, 48, .25), 0 0 0 1px rgba(184, 137, 62, .12);
  visibility: hidden; transform-origin: 0 0;
}
.card::before { /* paper texture */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, .9), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(240, 228, 210, .55), transparent 60%);
}
.card.is-visible { visibility: visible; }
.card.is-morphing { transition: transform 1s var(--ease-out); }

.card-frame { position: absolute; inset: 12px; border: 1px solid rgba(184, 137, 62, .6); pointer-events: none; }
.card-frame::after { content: ""; position: absolute; inset: 5px; border: 1px solid rgba(184, 137, 62, .28); }
.card-frame i { position: absolute; width: 22px; height: 22px; border-color: var(--gold); border-style: solid; }
.card-frame i:nth-child(1) { top: -5px; left: -5px; border-width: 2px 0 0 2px; }
.card-frame i:nth-child(2) { top: -5px; right: -5px; border-width: 2px 2px 0 0; }
.card-frame i:nth-child(3) { bottom: -5px; left: -5px; border-width: 0 0 2px 2px; }
.card-frame i:nth-child(4) { bottom: -5px; right: -5px; border-width: 0 2px 2px 0; }

.card-body { position: relative; padding: clamp(40px, 8vw, 64px) clamp(28px, 8vw, 68px) clamp(40px, 7vw, 56px);
  text-align: center; transition: height .5s var(--ease-io); }

.panel { transition: opacity .4s, transform .4s var(--ease-out); }
.panel.is-leaving { opacity: 0; transform: translateY(-8px); }
.panel.is-entering { opacity: 0; transform: translateY(10px); }

/* staggered reveal of the letter content */
.card .r { opacity: 0; transform: translateY(12px); }
.card.is-revealed .r { opacity: 1; transform: none; transition: opacity .9s var(--ease-out), transform .9s var(--ease-out); }
.card.is-revealed .r:nth-child(1) { transition-delay: .05s; }
.card.is-revealed .r:nth-child(2) { transition-delay: .2s; }
.card.is-revealed .r:nth-child(3) { transition-delay: .3s; }
.card.is-revealed .r:nth-child(4) { transition-delay: .45s; }
.card.is-revealed .r:nth-child(5) { transition-delay: .6s; }
.card.is-revealed .r:nth-child(6) { transition-delay: .72s; }
.card.is-revealed .r:nth-child(7) { transition-delay: .86s; }
.card.is-revealed .r:nth-child(8) { transition-delay: 1s; }
.card.is-revealed .r:nth-child(9) { transition-delay: 1.15s; }

.card-logo { width: min(220px, 56%); height: auto; display: block; margin: 0 auto 14px; }
.card-logo.small { width: min(150px, 42%); margin-bottom: 10px; }

.kicker {
  margin: 0; font-family: var(--sans); font-size: 11px; font-weight: 600; letter-spacing: .38em;
  text-transform: uppercase; color: var(--gold-deep);
  background: var(--foil); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.panel-title { margin: 6px 0 0; font-family: var(--serif); font-weight: 500; font-size: clamp(30px, 6vw, 40px); color: var(--plum-deep); line-height: 1.1; }

.flourish { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 18px auto 22px; max-width: 260px; }
.flourish span { flex: 1; height: 1px; background: var(--foil); }
.flourish b { font-weight: 400; font-size: 11px; color: var(--gold); }

.salutation { margin: 0 0 14px; font-family: var(--script); font-size: clamp(30px, 6.4vw, 40px); color: var(--plum); line-height: 1.2; }
.copy { margin: 0 auto 14px; max-width: 30em; font-size: clamp(17px, 3.6vw, 19.5px); line-height: 1.55; color: var(--plum-ink); }

.details {
  margin: 22px auto 28px; padding: 20px 0 0; display: grid; grid-template-columns: 1fr 1fr; row-gap: 16px;
  border-top: 1px solid rgba(184, 137, 62, .45); border-bottom: 1px solid rgba(184, 137, 62, .45);
}
.details > div { padding: 0 6px; }
.details > div:nth-child(2) { border-left: 1px solid rgba(184, 137, 62, .3); }
.details > div:nth-child(3) { grid-column: 1 / -1; padding: 16px 6px 20px; border-top: 1px solid rgba(184, 137, 62, .22); }
.details dd br { display: none; }
.details dt { font-family: var(--sans); font-size: 10px; font-weight: 600; letter-spacing: .3em; text-transform: uppercase; color: var(--gold-deep); margin-bottom: 6px; }
.details dd { margin: 0; font-size: clamp(18px, 3.8vw, 21px); font-weight: 600; color: var(--plum-deep); line-height: 1.3; }
.details.compact { margin: 22px auto; padding-top: 16px; }

.copy.lead { font-size: clamp(19px, 4vw, 22px); max-width: 24em; }
.closing { margin: 0 0 26px; font-style: italic; font-size: clamp(18px, 3.8vw, 21px); color: var(--plum); }

.actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.actions.row { flex-direction: row; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.already { margin: 0; font-family: var(--sans); font-size: 12px; color: var(--plum); opacity: .8; }

/* ---------- Buttons ---------- */
.btn-gold {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center;
  min-width: 240px; height: 54px; padding: 0 34px; border: 0; border-radius: 2px; cursor: pointer;
  font-family: var(--sans); font-size: 12px; font-weight: 600; letter-spacing: .26em; text-transform: uppercase;
  color: #fff8ea; background: linear-gradient(135deg, #5c2150, #7a2e68 55%, #4a1a3d);
  box-shadow: inset 0 0 0 1px rgba(233, 207, 148, .55), 0 14px 26px -12px rgba(74, 26, 61, .7);
  transition: transform .25s var(--ease-out), box-shadow .25s;
}
.btn-gold::before { /* inner gold hairline */
  content: ""; position: absolute; inset: 4px; border: 1px solid rgba(233, 207, 148, .45); pointer-events: none;
}
.btn-gold::after { /* sheen */
  content: ""; position: absolute; top: 0; bottom: 0; width: 40%; left: -60%;
  background: linear-gradient(100deg, transparent, rgba(255, 240, 210, .35), transparent);
  transform: skewX(-20deg); animation: sheen 4.5s 2.5s infinite;
}
.btn-gold:hover { transform: translateY(-2px); box-shadow: inset 0 0 0 1px rgba(233, 207, 148, .8), 0 18px 30px -12px rgba(74, 26, 61, .75); }
.btn-gold:active { transform: translateY(0); }
.btn-gold:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.btn-gold[disabled] { cursor: progress; opacity: .85; }
.btn-gold.is-loading span { opacity: 0; }
.btn-gold.is-loading::before {
  inset: auto; width: 18px; height: 18px; border: 2px solid rgba(255, 248, 234, .35); border-top-color: #fff8ea;
  border-radius: 50%; animation: spin .8s linear infinite;
}

.btn-outline {
  display: inline-flex; align-items: center; justify-content: center; height: 46px; padding: 0 22px;
  font-family: var(--sans); font-size: 11px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase;
  color: var(--plum-deep); text-decoration: none; border: 1px solid rgba(184, 137, 62, .7); border-radius: 2px;
  background: rgba(255, 255, 255, .5); transition: background .25s, color .25s;
}
.btn-outline:hover { background: var(--plum-deep); color: #fff8ea; }

.btn-text {
  display: block; margin: 14px auto 0; padding: 6px; border: 0; background: none; cursor: pointer;
  font-family: var(--sans); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--plum); opacity: .75;
}
.btn-text:hover { opacity: 1; text-decoration: underline; text-underline-offset: 4px; }

/* ---------- Form ---------- */
form { max-width: 380px; margin: 0 auto; text-align: left; }
.field { margin-bottom: 18px; }
.field label {
  display: block; margin-bottom: 8px; font-family: var(--sans); font-size: 10.5px; font-weight: 600;
  letter-spacing: .26em; text-transform: uppercase; color: var(--gold-deep);
}
.field input {
  width: 100%; height: 52px; padding: 0 16px; font-family: var(--serif); font-size: 20px; color: var(--plum-ink);
  background: rgba(255, 255, 255, .7); border: 1px solid rgba(184, 137, 62, .45); border-radius: 2px;
  transition: border-color .2s, box-shadow .2s, background .2s; -webkit-appearance: none; appearance: none;
}
.field input::placeholder { color: rgba(58, 20, 48, .35); }
.field input:focus { outline: none; border-color: var(--plum); background: #fff; box-shadow: 0 0 0 3px rgba(107, 42, 92, .12); }
.field.has-error input { border-color: #b4233f; }
.phone { display: flex; }
.phone .cc {
  display: inline-flex; align-items: center; padding: 0 14px; font-family: var(--serif); font-size: 20px; font-weight: 600;
  color: var(--plum); background: var(--cream); border: 1px solid rgba(184, 137, 62, .45); border-right: 0; border-radius: 2px 0 0 2px;
}
.phone input { border-radius: 0 2px 2px 0; letter-spacing: .04em; }
.err { margin: 6px 0 0; min-height: 0; font-family: var(--sans); font-size: 12px; color: #b4233f; }
.err:empty { display: none; }
.form-err { text-align: center; margin-bottom: 12px; }
form .btn-gold { width: 100%; margin-top: 8px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Success ---------- */
.check { width: 76px; height: 76px; display: block; margin: 0 auto 16px; }
.check circle { fill: none; stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 227; stroke-dashoffset: 227; }
.check path { fill: none; stroke: var(--plum); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 50; stroke-dashoffset: 50; }
#panelSuccess.is-active .check circle { animation: draw 1s .15s var(--ease-out) forwards; }
#panelSuccess.is-active .check path { animation: draw .6s .9s var(--ease-out) forwards; }

.foot { margin: 22px 0 0; font-family: var(--sans); font-size: 10.5px; letter-spacing: .16em; color: var(--plum); opacity: 0; transition: opacity 1s 1.4s; }
body:not(.stage-envelope) .foot { opacity: .6; }

/* ---------- Keyframes ---------- */
@keyframes envIn { from { opacity: 0; transform: translateY(40px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0% { opacity: .9; transform: scale(.9); } 70%, 100% { opacity: 0; transform: scale(1.35); } }
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes sheen { 0% { left: -60%; } 30%, 100% { left: 130%; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes draw { to { stroke-dashoffset: 0; } }

@media (max-width: 520px) {
  .ribbon-tl { top: -3vmin; left: -40vmax; }
  .ribbon-br { bottom: 0; right: -42vmax; }
  .eyebrow { letter-spacing: .3em; }
  .details dd br { display: inline; }
  .btn-gold { min-width: 0; width: 100%; padding: 0 18px; letter-spacing: .2em; }
  .actions.row .btn-outline { flex: 1 1 100%; }
  .card-frame { inset: 8px; }
}

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