/* Stage: envelope and the unrolling letter share one grid cell */
/* Nothing in here changes size or position between phases, so the page never jumps. */
.stage {
  --pad-top: 36px;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  align-content: start;
  padding: var(--pad-top) 16px 60px;
  position: relative;
}
.stage > .scene, .stage > .desk { grid-area: 1 / 1; }

.stage-hint {
  position: absolute;
  left: 50%;
  width: min(92vw, 520px);
  transform: translateX(-50%);
  bottom: calc(100% + 40px);
  margin: 0;
  text-align: center;
  font-style: italic;
  font-size: 1.2rem;
  color: #d8cba6;
  transition: opacity .5s ease;
}
.stage-hint span { color: var(--gold); animation: pulse 2.2s ease-in-out infinite; }
.stage:not([data-phase="sealed"]) .stage-hint, .stage:not([data-phase="sealed"]) .skip { opacity: 0; pointer-events: none; }

@keyframes pulse { 50% { opacity: .35; } }

.skip {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 90px);
  background: none;
  border: 0;
  font: inherit;
  color: #a99c7c;
  font-style: italic;
  font-size: .95rem;
  text-decoration: underline;
  cursor: pointer;
  transition: opacity .4s ease;
}

/* The desk holds the scroll; comments and photos drift around it */
.desk {
  width: min(100%, 620px);
  min-width: 0;
  position: relative;
}

/* 3D envelope */
.scene {
  --w: min(86vw, 500px);
  width: var(--w);
  height: calc(var(--w) * .66);
  perspective: 1300px;
  position: relative;
  margin-top: max(70px, calc(50svh - var(--w) * .33 - var(--pad-top)));
  animation: float 5.5s ease-in-out infinite;
  transition: opacity .7s ease, transform .8s cubic-bezier(.5, 0, .9, .4);
}
@keyframes float { 50% { translate: 0 -12px; } }

.envelope {
  --rx: 6deg;
  --ry: -9deg;
  --flip: 0deg;
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateX(var(--rx)) rotateY(calc(var(--ry) + var(--flip)));
  transition: transform .25s ease-out;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
.envelope:focus-visible .env-front { box-shadow: 0 0 0 3px var(--gold); }
.stage:not([data-phase="sealed"]) .envelope {
  --rx: 4deg;
  --ry: 0deg;
  --flip: 180deg;
  transition: transform 1s cubic-bezier(.6, 0, .25, 1);
  cursor: default;
}

.env-front, .env-back, .env-inner, .env-pocket, .env-flap, .env-letter { position: absolute; inset: 0; }

.env-front {
  transform: translateZ(1px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--grain), linear-gradient(160deg, var(--parch-light), var(--parch) 55%, var(--parch-dark));
  border-radius: 4px;
  box-shadow: inset 0 0 40px rgba(120, 85, 30, .35);
  display: grid;
  place-items: center;
  color: var(--emerald);
}

.address {
  margin: 6% 0 0;
  display: grid;
  gap: .05em;
  text-align: center;
  font-style: italic;
  font-size: calc(var(--w) * .04);
  line-height: 1.35;
}
.address .to { font-family: var(--script); font-style: normal; font-size: calc(var(--w) * .085); line-height: 1.1; }

.stamp {
  position: absolute;
  top: 7%;
  right: 5%;
  width: 17%;
  aspect-ratio: .82;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4%;
  color: var(--wax);
  border: 2px dotted var(--wax);
  background: rgba(124, 29, 29, .07);
  transform: rotate(4deg);
}
.stamp svg { width: 52%; }
.stamp span { font-family: var(--caps); font-size: calc(var(--w) * .021); letter-spacing: .05em; white-space: nowrap; }
.postmark {
  position: absolute;
  top: 9%;
  right: 17%;
  width: 17%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(42, 28, 15, .32);
  box-shadow: inset 0 0 0 5px transparent, inset 0 0 0 6px rgba(42, 28, 15, .25);
  transform: rotate(-12deg);
}

.env-back { transform: rotateY(180deg); transform-style: preserve-3d; }

.env-inner {
  transform: translateZ(1px);
  background: linear-gradient(180deg, #8f7a4c, #b9a36d 60%);
  border-radius: 4px;
}

.env-letter {
  inset: 6% 5% 4%;
  transform: translateZ(2px);
  background: var(--grain), linear-gradient(180deg, #fbf2d8, var(--parch-light));
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(0, 0, 0, .25);
  padding: 9% 12%;
  display: grid;
  align-content: start;
  gap: 9%;
  transition: transform .9s cubic-bezier(.3, .8, .3, 1);
}
.env-letter i { display: block; height: 3px; background: rgba(29, 74, 56, .4); border-radius: 2px; }
.env-letter i:first-child { width: 45%; margin: 0 auto 4%; height: 4px; }
.env-letter i:last-child { width: 60%; }

.env-pocket {
  transform: translateZ(3px);
  background: var(--grain), linear-gradient(175deg, var(--parch) 30%, var(--parch-dark));
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
  border-radius: 4px;
}
.env-pocket::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), rgba(90, 60, 20, .35) 50%, transparent calc(50% + 1px)) left bottom / 50% 46% no-repeat,
    linear-gradient(to top left, transparent calc(50% - 1px), rgba(90, 60, 20, .35) 50%, transparent calc(50% + 1px)) right bottom / 50% 46% no-repeat;
}

.env-flap {
  bottom: 40%;
  transform-origin: 50% 0;
  transform: translateZ(4px) rotateX(0deg);
  background: var(--grain), linear-gradient(180deg, var(--parch-light), var(--parch-dark));
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  filter: drop-shadow(0 3px 3px rgba(60, 40, 10, .5));
  transition: transform .8s cubic-bezier(.5, 0, .3, 1);
}

.seal {
  position: absolute;
  left: 50%;
  top: 58%;
  width: 21%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) translateZ(6px);
  transform-style: preserve-3d;
}
.seal-half {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 46% 54% 51% 49% / 52% 47% 53% 48%;
  background: radial-gradient(circle at 35% 30%, var(--wax-light), var(--wax) 55%, #4f1010);
  box-shadow: inset 0 0 0 5px rgba(0, 0, 0, .12), inset 0 0 14px rgba(0, 0, 0, .4);
  color: #e9b8a8;
  transition: transform .7s cubic-bezier(.2, .7, .3, 1), opacity .6s ease .15s;
}
.seal-half b { font-family: var(--script); font-weight: 400; font-size: calc(var(--w) * .075); text-shadow: 0 1px 0 rgba(0, 0, 0, .45); }
.seal-l { clip-path: polygon(0 0, 54% 0, 46% 24%, 56% 47%, 45% 72%, 52% 100%, 0 100%); }
.seal-r { clip-path: polygon(54% 0, 100% 0, 100% 100%, 52% 100%, 45% 72%, 56% 47%, 46% 24%); }

.env-shadow {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -19%;
  height: 12%;
  border-radius: 50%;
  background: rgba(0, 0, 0, .5);
  filter: blur(14px);
}

/* Phase choreography */
.stage[data-phase="cracking"] .seal-l, .stage[data-phase="opening"] .seal-l, .stage[data-phase="rising"] .seal-l, .stage[data-phase="unrolling"] .seal-l { transform: translate(-70%, 45%) rotate(-28deg); opacity: 0; }
.stage[data-phase="cracking"] .seal-r, .stage[data-phase="opening"] .seal-r, .stage[data-phase="rising"] .seal-r, .stage[data-phase="unrolling"] .seal-r { transform: translate(70%, 55%) rotate(34deg); opacity: 0; }
.stage[data-phase="opening"] .env-flap, .stage[data-phase="rising"] .env-flap, .stage[data-phase="unrolling"] .env-flap { transform: translateZ(.5px) rotateX(180deg); filter: none; }
.stage[data-phase="rising"] .env-letter, .stage[data-phase="unrolling"] .env-letter { transform: translateZ(2px) translateY(-64%); }
.stage[data-phase="unrolling"] .scene { opacity: 0; transform: translateY(46vh) scale(.8); animation: none; pointer-events: none; }
.stage[data-phase="reading"] .scene { visibility: hidden; }

/* The scroll */
.parchment {
  position: relative;
  width: 100%;
  margin-top: 12px;
  color: var(--ink);
  transform-origin: 50% 0;
  transition: transform 1.2s cubic-bezier(.2, .8, .2, 1), opacity .5s ease;
  filter: drop-shadow(0 26px 34px rgba(0, 0, 0, .55));
}
.parchment.rolled { transform: translateY(8vh) scale(.72); opacity: 0; }
.parchment.unrolling { transform: none; opacity: 1; }

.sheet {
  position: relative;
  min-height: 710px;
  margin: 0 12px;
  padding: 46px clamp(22px, 7vw, 58px) 54px;
  background:
    var(--grain),
    radial-gradient(ellipse at 20% 10%, rgba(255, 250, 225, .6), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(150, 110, 50, .28), transparent 55%),
    linear-gradient(180deg, var(--parch-light), var(--parch) 40%, #e2cf9f);
  box-shadow: inset 0 0 70px rgba(125, 88, 30, .42), inset 0 0 6px rgba(80, 50, 10, .5);
  clip-path: inset(0 0 0 0);
  transition: clip-path 1.7s cubic-bezier(.45, 0, .2, 1) .25s;
}
.parchment.rolled .sheet { clip-path: inset(0 0 calc(100% - 70px) 0); }
.parchment.open .sheet { clip-path: none; transition: none; }

.rod {
  position: absolute;
  left: 0;
  right: 0;
  height: 24px;
  border-radius: 12px;
  background: linear-gradient(180deg, #7a6234, #e9d7a6 30%, #cdb57a 55%, #6d5529);
  box-shadow: 0 4px 8px rgba(0, 0, 0, .45);
  z-index: 2;
}
.rod::before, .rod::after {
  content: '';
  position: absolute;
  top: -4px;
  width: 14px;
  height: 32px;
  border-radius: 6px;
  background: linear-gradient(180deg, #3d2a12, #8a6a35 40%, #2f1f0c);
}
.rod::before { left: -8px; }
.rod::after { right: -8px; }
.rod-top { top: -12px; }
.rod-bottom { top: calc(100% - 12px); transition: top 1.7s cubic-bezier(.45, 0, .2, 1) .25s; }
.parchment.rolled .rod-bottom { top: 58px; }

/* Letter copy */
.letter, .quiz { animation: ink-in .9s ease both; }
@keyframes ink-in { from { opacity: 0; filter: blur(3px); } }

.crest { text-align: center; color: var(--emerald); margin-bottom: 26px; }
.crest svg { width: 54px; margin: 0 auto 8px; display: block; }
.office { margin: 0; font-family: var(--caps); font-size: 1.05rem; letter-spacing: .2em; text-transform: uppercase; }
.office-sub { margin: 2px 0 0; font-style: italic; font-size: .95rem; color: var(--ink-soft); }
.crest::after { content: ''; display: block; width: 120px; height: 1px; margin: 18px auto 0; background: linear-gradient(90deg, transparent, var(--emerald), transparent); }

.salute { font-family: var(--script); font-size: 2.3rem; line-height: 1; margin: 0 0 14px; color: var(--emerald); }
.letter p { margin: 0 0 14px; }
.lead { font-size: 1.16rem; }
.lead::first-letter { font-family: var(--script); font-size: 3.1rem; line-height: .7; float: left; padding: .12em .1em 0 0; color: var(--wax); }
.letter strong { font-weight: 400; font-family: var(--caps); letter-spacing: .03em; color: #3a1410; }
.sign { margin: 22px 0 26px !important; font-style: italic; }
.sign span { display: block; font-family: var(--script); font-style: normal; font-size: 2.4rem; line-height: 1.15; color: var(--emerald); }
.letter .btn { display: block; margin: 0 auto; }

/* Questionnaire */
.sheet { display: flex; flex-direction: column; }
.quiz { text-align: center; margin: auto 0; }
.letter { margin: auto 0; }

.reaction { margin: 26px 0 30px; font-family: var(--script); font-size: clamp(2.4rem, 8vw, 3.4rem); line-height: 1.1; color: var(--wax); animation: ink-in .6s ease both; }
.reaction-next { display: block; margin: 0 auto; }
.reaction-skip { margin-top: 10px; background: none; border: 0; font: inherit; font-style: italic; color: var(--ink-soft); text-decoration: underline; cursor: pointer; }

.yes-video { width: min(100%, 330px); margin: 0 auto; padding: 8px; background: #f7f3e6; box-shadow: 0 12px 26px rgba(40, 20, 0, .45); transform: rotate(-1.5deg); }
.yes-video video { display: block; width: 100%; height: auto; aspect-ratio: 1136 / 1340; background: #000; }
.yes-caption { margin: 16px 0 0; font-family: var(--script); font-size: 2.2rem; line-height: 1.1; color: var(--wax); }

.cameo {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 50;
  width: auto;
  height: min(88vh, 760px);
  max-width: 94vw;
  object-fit: contain;
  pointer-events: none;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .6), 0 0 60px rgba(0, 0, 0, .8);
  opacity: 0;
  transform: translate(-50%, 60%) rotate(-12deg) scale(.5);
  transition: transform .5s cubic-bezier(.3, 1.4, .5, 1), opacity .3s ease;
}
.cameo.in { opacity: 1; transform: translate(-50%, -50%) rotate(-3deg) scale(1); }

.gifts { display: grid; gap: 8px; margin-top: 14px; text-align: left; }
.gift { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 8px 10px; border: 1px dashed rgba(42, 28, 15, .45); }
.gift-head { display: grid; gap: 6px; justify-items: start; }
.gift-name { font-family: var(--caps); font-size: 1.1rem; letter-spacing: .05em; }
.gift .btn { flex: none; padding: .45em .8em; font-size: .86rem; }
.gift-previews { display: flex; gap: 8px; }
.gift-preview { width: 100px; display: grid; gap: 1px; color: var(--ink); text-decoration: none; transition: transform .18s ease; }
.gift-preview:hover { transform: translateY(-3px); }
.gift-preview img { width: 100%; height: 66px; object-fit: contain; background: #fff; border: 1px solid rgba(42, 28, 15, .4); }
.gift-label { font-size: .74rem; line-height: 1.15; font-style: italic; }
.gift-price { font-family: var(--caps); font-size: .8rem; color: var(--wax); }
.gift-other input { flex: 1; min-width: 0; font: inherit; font-size: 1.02rem; color: var(--ink); padding: .45em .6em; background: rgba(255, 252, 238, .65); border: 1.5px solid rgba(42, 28, 15, .6); border-radius: 2px; }

.attend-extras { min-height: 176px; margin-top: 8px; }
.alt-trio { margin: 0 auto; width: min(100%, 400px); }
.alt-trio div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.alt-trio span { padding: 6px; background: #f7f3e6; box-shadow: 0 8px 18px rgba(40, 20, 0, .4); animation: drop-in .45s cubic-bezier(.3, 1.5, .5, 1) both; }
.alt-trio span:nth-child(1) { transform: rotate(-4deg); }
.alt-trio span:nth-child(2) { transform: rotate(2deg); animation-delay: .12s; }
.alt-trio span:nth-child(3) { transform: rotate(-1.5deg); animation-delay: .24s; }
.alt-trio img { width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; }
.alt-trio img.contain { object-fit: contain; background: #000; }
.alt-trio figcaption { margin-top: 12px; font-style: italic; color: var(--ink); }

.done-facts { margin: 18px auto 0; padding: 14px 0 0; max-width: 380px; border-top: 1px dashed rgba(42, 28, 15, .4); display: grid; gap: 6px; }
.done-facts div { display: flex; gap: 12px; justify-content: space-between; text-align: right; }
.done-facts dt { font-family: var(--caps); font-size: .8rem; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-soft); padding-top: .25em; }
.done-facts dd { margin: 0; }
.done-more { display: inline-block; margin-top: 20px; color: var(--emerald); font-style: italic; }
.quiz-count { margin: 0 0 6px; font-family: var(--caps); letter-spacing: .28em; font-size: .85rem; color: var(--ink-soft); text-transform: uppercase; }
.quiz-q { margin: 0 0 8px; font-family: var(--script); font-weight: 400; font-size: clamp(2.3rem, 7.5vw, 3.2rem); line-height: 1.08; color: var(--emerald); outline: none; }
.quiz-sub { margin: 0; font-style: italic; color: var(--ink-soft); }
.options { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 18px; }
.options.stack { flex-direction: column; align-items: center; }
.options.stack .btn { width: min(100%, 360px); }

.no-slot { display: inline-block; position: relative; }
.no-btn { position: relative; z-index: 5; transition: transform .22s cubic-bezier(.3, 1.4, .5, 1), background .2s ease; }
.no-btn:hover { transform: none; box-shadow: 2px 2px 0 rgba(42, 28, 15, .55); }

.taunt { min-height: 1.6em; margin: 16px 0 0; font-style: italic; color: var(--wax); }
@keyframes drop-in { from { opacity: 0; transform: translateY(-30px) rotate(6deg) scale(.8); } }

.hype { margin: 22px auto 0; max-width: 400px; }
.hype input { width: 100%; accent-color: var(--wax); height: 34px; }
.hype-labels { display: flex; justify-content: space-between; font-family: var(--caps); font-size: .85rem; letter-spacing: .08em; color: var(--ink-soft); }

.quiz-form { display: grid; gap: 14px; max-width: 400px; margin: 24px auto 0; text-align: left; }
.quiz-form label, .comment-form label { display: grid; gap: 5px; font-family: var(--caps); font-size: .85rem; letter-spacing: .14em; text-transform: uppercase; }
.quiz-form input, .quiz-form textarea, .comment-form input, .comment-form textarea {
  font: inherit;
  font-family: var(--serif);
  font-size: 1.05rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  padding: .5em .65em;
  background: rgba(255, 252, 238, .65);
  border: 1.5px solid rgba(42, 28, 15, .6);
  border-radius: 2px;
  resize: vertical;
}
.quiz-form input:focus, .quiz-form textarea:focus, .comment-form input:focus, .comment-form textarea:focus { outline: 2px solid var(--emerald); outline-offset: 1px; }
.quiz-form .btn { justify-self: center; margin-top: 6px; }
.field-error { margin: 0; color: var(--wax); font-style: italic; min-height: 1.4em; text-align: center; }

.done-seal {
  width: 96px;
  aspect-ratio: 1;
  margin: 6px auto 18px;
  display: grid;
  place-items: center;
  border-radius: 46% 54% 51% 49% / 52% 47% 53% 48%;
  background: radial-gradient(circle at 35% 30%, var(--wax-light), var(--wax) 55%, #4f1010);
  box-shadow: inset 0 0 14px rgba(0, 0, 0, .4), 0 5px 10px rgba(60, 20, 0, .4);
  color: #e9b8a8;
  font-family: var(--script);
  font-size: 2.2rem;
  animation: stamp .5s cubic-bezier(.3, 1.6, .5, 1) both;
}
@keyframes stamp { from { transform: scale(2.4) rotate(-20deg); opacity: 0; } }
.done-text { margin: 0 0 12px; }
.done-fine { font-style: italic; color: var(--ink-soft); font-size: .95rem; margin: 0 0 24px; }

@media (max-width: 480px) {
  body { font-size: 17.5px; }
  .sheet { padding: 28px 18px 36px; }
  .gift { padding: 8px; }
  .gift-head { display: flex; width: 100%; align-items: center; justify-content: space-between; }
  .gift-previews { width: 100%; }
  .gift-preview { flex: 1 1 0; width: auto; min-width: 0; max-width: 112px; }
  .gift-preview img { height: 58px; }
  .hype input { width: calc(100% - 8px); }
  .crest { margin-bottom: 16px; }
  .crest svg { width: 42px; }
  .crest::after { margin-top: 12px; }
  .office { font-size: .92rem; letter-spacing: .1em; }
  .salute { font-size: 2rem; margin-bottom: 8px; }
  .lead { font-size: 1.06rem; }
  .letter p { margin-bottom: 10px; }
  .sign { margin: 14px 0 18px !important; }
}

/* Phones: the scroll fills the screen under the ticker, questions sit at the top of it, and everything is thumb-sized. */
@media (max-width: 640px) {
  .stage { --pad-top: 36px; padding-left: 10px; padding-right: 10px; padding-bottom: 28px; }
  .sheet { padding-top: 28px; }
  .chatter { margin-left: -10px; margin-right: -10px; }
  .parchment { margin-top: 10px; }
  .sheet { margin: 0 8px; min-height: max(470px, calc(100svh - 236px)); }
  .quiz { margin: auto 0; }
  .quiz-q { font-size: clamp(2.2rem, 10vw, 2.8rem); }
  .btn { min-height: 50px; padding: .7em 1.1em; font-size: 1.05rem; }
  .options { gap: 10px; margin-top: 20px; }
  .options.stack .btn, .options:not(.attend) .btn { width: 100%; }
  .options.attend { gap: 8px; }
  .options.attend .btn { padding-left: .9em; padding-right: .9em; }
  .gift .btn { min-height: 44px; font-size: .9rem; }
  .gift-other { flex-wrap: nowrap; }
  .quiz-form { margin-top: 18px; }
  .quiz-form input { min-height: 50px; font-size: 1.1rem; }
  .quiz-form .btn { width: 100%; }
  .hype input { height: 48px; }
  .reaction { margin: 40px 0 34px; }
  .reaction-next { width: 100%; }
  .yes-video { width: min(100%, 270px); }
  .alt-trio { width: 100%; }
  .attend-extras { min-height: 150px; }
  .done-facts div { flex-direction: column; gap: 0; text-align: left; }
  .cameo { height: auto; width: 96vw; max-height: 86svh; }
}
}
