:root {
  --paper: #fdf6e3;
  --paper-hi: #fffaf0;
  --paper-lo: #f3e8cf;
  --ink: #3f3b2c;
  --ink-soft: #6a624f;
  --olive: #5f6a45;
  --olive-deep: #4a5335;
  --gold: #a8823a;
  --blush: #e8c9c1;
  --line: rgba(63, 59, 44, .16);
  --line-strong: rgba(63, 59, 44, .32);

  --env: #f1e7d4;
  --env-side: #ebdfc8;
  --env-side-2: #e7dac1;
  --env-bottom: #f4ebdb;
  --env-back: #e3d5ba;

  --serif: "Cormorant Garamond", Garamond, "Times New Roman", serif;
  --script: "Parisienne", "Segoe Script", cursive;

  color-scheme: light only;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper-lo);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.55;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; }
p { margin: 0; }
h1, h2 { margin: 0; font-weight: 400; }

.script { font-family: var(--script); font-weight: 400; }

.eyebrow {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: var(--olive);
}

/* Desktop: the invitation is a phone-width column over a soft blurred grove. */
.backdrop {
  position: fixed;
  inset: 0;
  background: url("img/backdrop.jpg") center / cover no-repeat;
}
.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(253, 246, 227, .45);
}

.page {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: 0 0 80px rgba(60, 45, 20, .18);
}

/* ---------- 1. Intro: envelope ---------- */

.intro { position: relative; height: 360vh; height: 360svh; }

.stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  background: radial-gradient(ellipse 90% 70% at 50% 42%, var(--paper-hi) 0%, var(--paper) 55%, var(--paper-lo) 100%);
  --ex: 0px; --ey: 0px; --ew: 0px; --eh: 0px; --drop: 0px;
}

.stage-bg {
  position: absolute;
  inset: -40px;
  background: url("img/backdrop.jpg") center / cover no-repeat;
  opacity: var(--bgfade, 0);
  pointer-events: none;
}
.stage-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(253, 246, 227, .35);
}

.grain {
  position: absolute;
  inset: 0;
  opacity: .22;
  mix-blend-mode: multiply;
  pointer-events: none;
  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 .45 0 0 0 0 .38 0 0 0 0 .25 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.intro-head {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--hy, 10%);
  text-align: center;
  z-index: 6;
  padding: 0 16px;
  will-change: opacity, transform;
}
.intro-head .eyebrow { margin-bottom: 6px; }
.intro-head h1 {
  font-size: clamp(64px, 19vw, 132px);
  line-height: 1.1;
  color: var(--ink);
}

/* Envelope parts share one box, set from JS. */
.env {
  position: absolute;
  left: var(--ex);
  top: var(--ey);
  width: var(--ew);
  height: var(--eh);
  transform: translate3d(0, var(--drop), 0);
}

.env-back {
  z-index: 1;
  border-radius: 6px;
  background: var(--env-back);
  box-shadow: 0 26px 40px -22px rgba(70, 52, 25, .45), 0 2px 6px rgba(70, 52, 25, .12);
}
.env-back::before {
  /* liner, seen through the open mouth of the envelope */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: url("img/liner.jpg") center top / 100% auto;
  clip-path: polygon(0 0, 100% 0, 50% 56%);
  opacity: .95;
}

.card-clip {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: var(--clip, 100%);
  overflow: hidden;
  z-index: 2;
  pointer-events: none;
}

.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw, 100%);
  height: var(--ch, 100%);
  transform-origin: 0 0;
  transform: translate3d(var(--cx, 0), var(--cy, 0), 0) scale(var(--cs, 1));
  border-radius: var(--cr, 0);
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 18px 50px rgba(60, 45, 20, var(--cshadow, .3));
  will-change: transform;
  pointer-events: auto;
}
.card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 30%;
}
.card-border {
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(168, 130, 58, .55);
  border-radius: 4px;
  pointer-events: none;
  opacity: var(--cborder, 1);
}
.card-text {
  position: absolute;
  left: 0;
  right: 0;
  top: 7%;
  text-align: center;
  padding: 0 12%;
  color: var(--ink);
  text-shadow: 0 0 18px rgba(253, 246, 227, .95), 0 0 4px rgba(253, 246, 227, .8);
  transform: scale(var(--ct, 1));
  transform-origin: 50% 0;
}
.card-lead {
  max-width: 250px;
  margin: 0 auto;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.7;
  letter-spacing: .24em;
  margin-right: auto;
  color: var(--olive-deep);
}
.card-names {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  margin: 10px 0 6px;
}
.card-names .script { font-size: clamp(56px, 16vw, 80px); line-height: 1.05; }
.card-names .amp {
  font-family: var(--serif);
  font-style: italic;
  font-size: 30px;
  color: var(--gold);
  margin: -2px 0 -4px;
}
.rule {
  display: block;
  width: 56px;
  height: 1px;
  margin: 12px auto 14px;
  background: var(--gold);
  opacity: .7;
}
.card-place, .card-date, .card-time {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: .24em;
  margin-right: -.24em;
}

.card-down {
  position: absolute;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  margin-left: -22px;
  opacity: var(--cdown, 0);
  pointer-events: none;
}
.card-down::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 10px;
  width: 12px;
  height: 12px;
  border-right: 1.5px solid var(--paper-hi);
  border-bottom: 1.5px solid var(--paper-hi);
  transform: rotate(45deg);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35));
  animation: nudge 2.2s ease-in-out infinite;
}

.env-pocket { z-index: 3; overflow: visible; }
.env-pocket path { stroke: rgba(120, 96, 60, .2); stroke-width: 1; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.pk-l { fill: var(--env-side); }
.pk-r { fill: var(--env-side-2); }
.pk-b { fill: var(--env-bottom); }

.flap-shadow {
  z-index: 4;
  height: calc(var(--eh) * .6);
  filter: blur(5px);
  opacity: var(--fshadow, .35);
  transform: translate3d(0, calc(var(--drop) + 4px), 0);
}
.flap-shadow div {
  width: 100%;
  height: 100%;
  background: #6d5a3a;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.env-flap {
  z-index: var(--flapz, 5);
  height: calc(var(--eh) * .58);
  transform-origin: 50% 0;
  transform: translate3d(0, var(--drop), 0) perspective(1000px) rotateX(var(--flap, 0deg));
  transform-style: preserve-3d;
}
.flap-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flap-front {
  background: linear-gradient(180deg, var(--env) 0%, #eee2cc 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.flap-back {
  transform: rotateX(180deg);
  background: url("img/liner.jpg") center / cover;
  clip-path: polygon(0 100%, 100% 100%, 50% 0);
}

/* The seal sits on the tip of the flap. */
.seal {
  position: absolute;
  z-index: 7;
  left: calc(var(--ex) + var(--ew) / 2);
  top: calc(var(--ey) + var(--eh) * .58);
  width: min(calc(var(--ew) * .42), 200px);
  height: min(calc(var(--ew) * .42), 200px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--paper-hi);
  box-shadow: 0 0 0 1px rgba(168, 130, 58, .45), 0 0 0 5px var(--paper-hi), 0 0 0 6px rgba(168, 130, 58, .3), 0 8px 18px rgba(70, 52, 25, .28);
  transform: translate(-50%, -50%) scale(var(--seals, 1));
  opacity: var(--sealo, 1);
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  animation: breathe 3.2s ease-in-out infinite;
}
.seal img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  mix-blend-mode: multiply;
  border-radius: 50%;
}
.seal-letters { display: none; }
.seal--drawn {
  background: radial-gradient(circle at 38% 32%, #7d8860 0%, var(--olive) 45%, var(--olive-deep) 100%);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .08), inset 0 -6px 12px rgba(0, 0, 0, .25), 0 8px 18px rgba(70, 52, 25, .35);
}
.seal--drawn .seal-letters {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-family: var(--script);
  font-size: calc(var(--ew) * .1);
  color: #f3ead2;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .3);
}
.seal--drawn .seal-letters i { font-family: var(--serif); font-size: .6em; margin: 0 .12em; }
.seal:focus-visible { outline: 2px solid var(--olive); outline-offset: 8px; }

.hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(26px + env(safe-area-inset-bottom));
  z-index: 6;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.hint span {
  display: block;
  width: 1px;
  height: 34px;
  margin: 10px auto 0;
  background: linear-gradient(var(--ink-soft), transparent);
  animation: drip 2s ease-in-out infinite;
  transform-origin: top;
}

.petals { position: absolute; inset: 0; z-index: 0; pointer-events: none; opacity: var(--petals, 1); }
.petal {
  position: absolute;
  top: -40px;
  width: var(--sz);
  height: calc(var(--sz) * 1.25);
  background: radial-gradient(ellipse at 50% 30%, #fbeae6 0%, #f1cfc8 60%, #e6b8b0 100%);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  opacity: .8;
  animation: fall var(--dur) linear var(--delay) infinite;
}

@keyframes fall {
  0%   { transform: translate3d(0, -5vh, 0) rotate(0deg); }
  25%  { transform: translate3d(var(--sway), 25vh, 0) rotate(90deg); }
  50%  { transform: translate3d(calc(var(--sway) * -.4), 55vh, 0) rotate(180deg); }
  75%  { transform: translate3d(var(--sway), 85vh, 0) rotate(260deg); }
  100% { transform: translate3d(0, 115vh, 0) rotate(340deg); }
}
@keyframes breathe { 50% { box-shadow: 0 0 0 1px rgba(168, 130, 58, .45), 0 0 0 5px var(--paper-hi), 0 0 0 9px rgba(168, 130, 58, .18), 0 10px 22px rgba(70, 52, 25, .3); } }
@keyframes drip { 0% { transform: scaleY(0); opacity: 1; } 70% { transform: scaleY(1); opacity: 1; } 100% { transform: scaleY(1); opacity: 0; } }
@keyframes nudge { 50% { transform: translateY(6px) rotate(45deg); } }

@media (prefers-reduced-motion: reduce) {
  .petals, .hint span { display: none; }
  .seal, .card-down::before { animation: none; }
}

/* ---------- 2. Invitation text in the branch frame ---------- */

.invite {
  position: relative;
  aspect-ratio: 944 / 1680;
  background: url("img/frame.jpg") center / 112% auto no-repeat var(--paper);
  display: grid;
  place-items: center;
  padding: 0 19%;
  text-align: center;
}
.invite-text p { font-size: 20px; line-height: 1.6; }
.invite-text p + p { margin-top: .9em; }
.invite-text .sign { font-size: 34px; line-height: 1.2; margin-top: 1.1em; color: var(--ink); white-space: nowrap; }

/* ---------- Shared section layout ---------- */

.section {
  position: relative;
  padding: 84px 28px;
  text-align: center;
  overflow: hidden;
}
.section > * { position: relative; }
.section + .section { border-top: 1px solid var(--line); }

.big {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(34px, 9.5vw, 44px);
  line-height: 1.15;
  margin: 14px 0 6px;
}
.sub { color: var(--ink-soft); font-size: 19px; }
.label {
  margin: 34px 0 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
address { font-style: normal; margin-top: 10px; }

.corner {
  position: absolute !important;
  width: 34%;
  mix-blend-mode: multiply;
  pointer-events: none;
  opacity: .95;
}
.corner-tl { left: 0; top: 0; }
.corner-br { right: 0; bottom: 0; width: 32%; }

.when { padding-top: 150px; }
.where { padding-bottom: 200px; }

/* Countdown */
.countdown {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 330px;
  margin: 30px auto 0;
}
.countdown div {
  padding: 12px 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 250, 240, .7);
}
.countdown span {
  display: block;
  font-size: 32px;
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
}
.countdown small {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* Buttons */
.btns {
  display: grid;
  gap: 10px;
  max-width: 300px;
  margin: 0 auto;
}
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 250, 240, .75);
  color: var(--ink);
  font: 600 16px/1 var(--serif);
  letter-spacing: .06em;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .2s, border-color .2s, transform .2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--olive); }
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--olive); outline-offset: 3px; }
.btn-primary { background: var(--olive); border-color: var(--olive); color: var(--paper-hi); }
.btn-primary:hover { background: var(--olive-deep); border-color: var(--olive-deep); }

.arch {
  display: block;
  width: 120px;
  margin: 22px auto 4px;
  fill: none;
  stroke: var(--olive);
  stroke-width: 1.4;
  stroke-linecap: round;
  opacity: .85;
}

/* ---------- 5. RSVP form ---------- */

.form {
  max-width: 380px;
  margin: 34px auto 0;
  text-align: left;
}
.field { display: block; margin-bottom: 22px; }
.field > span, .choice legend {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.field small, .choice legend small {
  font-size: 12px;
  letter-spacing: .02em;
  text-transform: none;
  font-weight: 500;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: rgba(255, 250, 240, .9);
  color: var(--ink);
  font: 500 18px/1.4 var(--serif);
  appearance: none;
  -webkit-appearance: none;
}
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.field textarea { resize: vertical; min-height: 90px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(95, 106, 69, .18);
}

.choice { border: 0; padding: 0; margin: 0 0 22px; }
.choice legend { padding: 0; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice legend { grid-column: 1 / -1; }
.choice--stack { grid-template-columns: 1fr; }
.choice label { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 250, 240, .75);
  font-size: 17px;
  text-align: center;
  transition: background-color .2s, border-color .2s, color .2s;
}
.choice input:checked + span { background: var(--olive); border-color: var(--olive); color: var(--paper-hi); }
.choice input:focus-visible + span { outline: 2px solid var(--olive); outline-offset: 3px; }
.choice.is-invalid span, .field.is-invalid input { border-color: #b0564a; }

.if-yes[hidden] { display: none; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.btn-submit { width: 100%; margin-top: 6px; font-size: 17px; }
.btn-submit[disabled] { opacity: .6; cursor: progress; }
.form-msg { min-height: 1.5em; margin-top: 12px; text-align: center; font-size: 17px; color: #9a4a3f; }
.form-msg.ok { color: var(--olive-deep); }
.fine { margin-top: 6px; text-align: center; font-size: 14px; color: var(--ink-soft); }

.done { margin-top: 30px; }
.done:focus { outline: none; }
.done-title { font-size: 48px; line-height: 1.2; }
.link {
  margin-top: 18px;
  padding: 8px;
  border: 0;
  background: none;
  color: var(--olive-deep);
  font: 600 16px var(--serif);
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

/* ---------- 6. Closing ---------- */

.closing { padding: 150px 28px 170px; }
.closing-title { font-size: clamp(48px, 14vw, 64px); line-height: 1.2; margin-bottom: 14px; }
.closing-date { margin-top: 8px; color: var(--ink-soft); }

/* Scroll reveals */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity .9s ease, transform .9s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal { transform: none; transition: opacity .4s; }
}

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  .backdrop { display: none; }

  .page {
    max-width: none;
    box-shadow: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .intro, .invite, .rsvp, .closing { grid-column: 1 / -1; }

  .intro { height: 290vh; height: 290svh; }

  .hint { font-size: 14px; }

  /* The invitation text becomes a framed card on the paper. */
  .invite {
    --iw: min(560px, 52vh, 90vw);
    justify-self: center;
    width: var(--iw);
    /* % padding would be measured against the page, not the card */
    padding-inline: calc(var(--iw) * .19);
    margin-block: 96px;
    border-radius: 14px;
    box-shadow: 0 30px 70px -30px rgba(60, 45, 20, .45), 0 2px 8px rgba(60, 45, 20, .08);
  }

  /* Date and venue side by side. */
  .when, .where { padding: 110px 48px; }
  .where { padding-bottom: 200px; }
  .section.where { border-top: 0; border-left: 1px solid var(--line); }
  .corner { width: min(34%, 240px); }
  .corner-br { width: min(32%, 220px); }

  .rsvp { padding-block: 110px; }
  .form { max-width: 460px; }

  .closing { padding-block: 170px 190px; }
  .closing .corner { width: min(24%, 300px); }
}
