/* ============================================================
   a letter for you
   palette: warm paper, rosewood ink, blush and a little gold
   ============================================================ */

:root {
  --paper:      #fff7f1;
  --paper-deep: #f7e3d8;
  --card:       #fffaf6;
  --ink:        #3d2328;
  --ink-soft:   #8a6560;
  --rose:       #e4708a;
  --rose-deep:  #c2405f;
  --blush:      #ffd7de;
  --gold:       #d9a15b;

  --shadow-soft: 0 2px 6px rgba(97, 47, 52, .06),
                 0 12px 28px rgba(97, 47, 52, .09),
                 0 34px 60px -22px rgba(97, 47, 52, .22);
  --shadow-lift: 0 3px 10px rgba(97, 47, 52, .10),
                 0 20px 44px rgba(97, 47, 52, .16),
                 0 46px 80px -24px rgba(97, 47, 52, .28);

  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans:  "Karla", "Avenir Next", sans-serif;
  --hand:  "Caveat", "Segoe Script", cursive;

  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  position: relative;
}

/* ---------- atmosphere ------------------------------------ */

.sky {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .75;
}

.glow-a {
  width: 62vmax; height: 62vmax;
  top: -26vmax; left: -18vmax;
  background: radial-gradient(circle at 40% 40%, #ffd3dd 0%, rgba(255, 211, 221, 0) 68%);
  animation: drift-a 26s ease-in-out infinite;
}

.glow-b {
  width: 54vmax; height: 54vmax;
  bottom: -24vmax; right: -16vmax;
  background: radial-gradient(circle at 55% 45%, #ffe2c4 0%, rgba(255, 226, 196, 0) 70%);
  animation: drift-b 32s ease-in-out infinite;
}

.glow-c {
  width: 40vmax; height: 40vmax;
  top: 32%; left: 52%;
  background: radial-gradient(circle at 50% 50%, #f4dcff 0%, rgba(244, 220, 255, 0) 72%);
  opacity: .5;
  animation: drift-a 38s ease-in-out infinite reverse;
}

@keyframes drift-a {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(6vmax, 4vmax) scale(1.09); }
}
@keyframes drift-b {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(-5vmax, -5vmax) scale(1.12); }
}

/* drifting petals */
.petals { position: absolute; inset: 0; }

.petal {
  position: absolute;
  bottom: -8vh;
  width: 12px;
  height: 12px;
  color: var(--rose);
  opacity: .32;
  animation: rise linear infinite;
}

.petal svg { width: 100%; height: 100%; fill: currentColor; display: block; }

@keyframes rise {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 0; }
  8%   { opacity: var(--peak, .32); }
  90%  { opacity: var(--peak, .32); }
  100% { transform: translate3d(var(--sway, 40px), -112vh, 0) rotate(320deg); opacity: 0; }
}

.grain {
  position: fixed;
  inset: -50%;
  z-index: 60;
  pointer-events: none;
  opacity: .05;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain-shift 6s steps(5) infinite;
}

@keyframes grain-shift {
  0%,100% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -2%); }
  80% { transform: translate(3%, 1%); }
}

/* ---------- stages ---------------------------------------- */

.stage-wrap {
  position: relative;
  z-index: 10;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 5vh 22px 64px;
}

.stage {
  grid-area: 1 / 1;
  width: 100%;
  max-width: 620px;
  display: flex;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px) scale(.97);
  transition: opacity .7s var(--ease), transform .8s var(--ease), visibility .7s;
  pointer-events: none;
}

.stage.is-active {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
}

.stage.is-leaving {
  opacity: 0;
  transform: translateY(-22px) scale(.98);
}

/* ---------- 1. envelope ----------------------------------- */

.envelope-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}

.hint {
  margin: 0;
  font-family: var(--hand);
  font-size: 1.45rem;
  color: var(--ink-soft);
  letter-spacing: .01em;
}

.hint--top { transform: rotate(-2.2deg); }

.hint--bottom {
  color: var(--rose-deep);
  animation: breathe 2.6s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: .55; transform: translateY(0); }
  50%      { opacity: 1;   transform: translateY(-3px); }
}

.envelope {
  position: relative;
  width: min(76vw, 330px);
  aspect-ratio: 1.55 / 1;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 22px 34px rgba(120, 55, 60, .22));
  transition: transform .5s var(--ease), filter .5s var(--ease);
  animation: float-env 5.5s ease-in-out infinite;
}

@keyframes float-env {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50%      { transform: translateY(-10px) rotate(1deg); }
}

.envelope:hover  { filter: drop-shadow(0 30px 44px rgba(120, 55, 60, .3)); }
.envelope:active { transform: scale(.985); }

.env-back, .env-front, .env-flap, .env-letter {
  position: absolute;
  border-radius: 10px;
}

.env-back {
  inset: 0;
  background: linear-gradient(160deg, #ffeadf 0%, #fbd5c6 100%);
}

.env-letter {
  left: 7%;
  right: 7%;
  bottom: 12%;
  height: 86%;
  background: var(--card);
  border-radius: 8px 8px 4px 4px;
  box-shadow: 0 -3px 14px rgba(120, 55, 60, .12);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  z-index: 2;
  transition: transform 1s var(--ease);
}

.env-letter-line {
  height: 7px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--blush), #ffeef1);
}
.env-letter-line.short { width: 52%; }

.env-front {
  inset: 0;
  z-index: 3;
  background: linear-gradient(175deg, #fbd9cb 0%, #f6c6b6 100%);
  clip-path: polygon(0 32%, 50% 74%, 100% 32%, 100% 100%, 0 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6);
}

.env-flap {
  top: 0;
  left: 0;
  right: 0;
  height: 62%;
  z-index: 5;
  background: linear-gradient(185deg, #f9d0c0 0%, #f0b8a6 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform .85s var(--ease), z-index 0s .42s;
}

.env-seal {
  position: absolute;
  z-index: 6;
  top: 50%;
  left: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #e8637f, #b93555 70%);
  box-shadow: 0 5px 14px rgba(150, 40, 65, .38),
              inset 0 -2px 5px rgba(90, 15, 35, .4),
              inset 0 2px 5px rgba(255, 255, 255, .34);
  transition: transform .45s var(--ease), opacity .45s var(--ease);
}

.env-seal svg { width: 26px; height: 26px; fill: #ffe6ec; opacity: .95; }

.envelope.is-open .env-flap  { transform: rotateX(180deg); z-index: 1; }
.envelope.is-open .env-seal  { transform: scale(.4) translateY(-16px); opacity: 0; }
.envelope.is-open .env-letter { transform: translateY(-58%) scale(1.03); }

/* ---------- the card -------------------------------------- */

.card {
  position: relative;
  width: 100%;
  padding: clamp(34px, 6vw, 56px) clamp(26px, 5.6vw, 52px) clamp(30px, 5vw, 44px);
  background:
    linear-gradient(180deg, #fffdfb 0%, var(--card) 46%, #fff1e9 100%);
  border-radius: 26px;
  box-shadow: var(--shadow-soft);
  text-align: center;
  transform: rotate(-.5deg);
}

.card::before {
  content: "";
  position: absolute;
  inset: 11px;
  border-radius: 18px;
  border: 1px solid rgba(196, 118, 118, .2);
  pointer-events: none;
}

.card-tape {
  position: absolute;
  top: -13px;
  left: 50%;
  width: 108px;
  height: 26px;
  margin-left: -54px;
  background: linear-gradient(100deg, rgba(255, 214, 222, .85), rgba(255, 235, 214, .85));
  border-left: 1px dashed rgba(255, 255, 255, .8);
  border-right: 1px dashed rgba(255, 255, 255, .8);
  transform: rotate(-2.4deg);
  box-shadow: 0 2px 5px rgba(120, 55, 60, .1);
}

.eyebrow {
  margin: 0 0 14px;
  font-family: var(--hand);
  font-size: 1.36rem;
  color: var(--rose-deep);
  letter-spacing: .015em;
}

.headline {
  margin: 0 0 20px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.35rem, 8.4vw, 3.5rem);
  line-height: 1.02;
  letter-spacing: -.028em;
  font-variation-settings: "opsz" 120;
}

.headline .line { display: block; }

.headline .line--em {
  font-style: italic;
  font-weight: 400;
  color: var(--rose-deep);
}

.body {
  margin: 0 auto 22px;
  max-width: 40ch;
  font-size: clamp(1rem, 2.5vw, 1.075rem);
  line-height: 1.72;
  color: var(--ink-soft);
  font-weight: 400;
}

.question {
  margin: 0 0 28px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.35rem, 4.6vw, 1.7rem);
  color: var(--ink);
  letter-spacing: -.015em;
}

/* ---------- buttons --------------------------------------- */

.choices {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  min-height: 62px;
}

.btn {
  position: relative;
  font-family: var(--sans);
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 15px 34px;
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  transition: transform .32s var(--ease), box-shadow .32s var(--ease),
              background .3s ease, color .3s ease, opacity .4s ease;
  will-change: transform;
}

.btn:focus-visible {
  outline: 2px solid var(--rose-deep);
  outline-offset: 4px;
}

.btn--yes {
  color: #fff8f9;
  background: linear-gradient(165deg, #f0819a 0%, var(--rose-deep) 100%);
  box-shadow: 0 6px 16px rgba(194, 64, 95, .3),
              0 14px 34px -8px rgba(194, 64, 95, .42),
              inset 0 1px 0 rgba(255, 255, 255, .35);
  transform: scale(var(--grow, 1));
  transform-origin: center;
}

.btn--yes:hover {
  box-shadow: 0 8px 20px rgba(194, 64, 95, .38),
              0 20px 44px -10px rgba(194, 64, 95, .5),
              inset 0 1px 0 rgba(255, 255, 255, .35);
  transform: scale(calc(var(--grow, 1) * 1.045)) translateY(-2px);
}

.btn--yes:active { transform: scale(calc(var(--grow, 1) * .98)); }

.btn--no {
  color: var(--ink-soft);
  background: #fdeee7;
  box-shadow: inset 0 0 0 1px rgba(180, 118, 110, .28);
}

.btn--no:disabled {
  cursor: not-allowed;
  opacity: .55;
  padding-right: 52px;
}

.btn--no:not(:disabled):hover {
  color: var(--ink);
  background: #fbe3d9;
}

.btn--no.is-loose {
  position: relative;
  z-index: 40;
  transition: transform .38s var(--ease), background .3s ease, color .3s ease;
}

.timer {
  position: absolute;
  right: 15px;
  top: 50%;
  width: 24px;
  height: 24px;
  margin-top: -12px;
  transform: rotate(-90deg);
  opacity: 1;
  transition: opacity .3s ease;
}

.btn--no:not(:disabled) .timer { opacity: 0; }

.timer circle {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
}

.timer-track { stroke: rgba(180, 118, 110, .22); }

.timer-fill {
  stroke: var(--rose);
  stroke-dasharray: 106.8;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset .95s linear;
}

.whisper {
  margin: 22px 0 0;
  min-height: 1.4em;
  font-family: var(--hand);
  font-size: 1.24rem;
  color: var(--ink-soft);
  opacity: .9;
  transition: opacity .25s ease;
}

.whisper.is-flick { opacity: 0; }

/* ---------- 3. thanks ------------------------------------- */

.card--thanks { transform: rotate(.45deg); }

.hearts-crest {
  width: 54px;
  height: 54px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe3e9, #ffc9d4);
  box-shadow: 0 6px 16px rgba(194, 64, 95, .18);
  animation: pulse 2.4s ease-in-out infinite;
}

.hearts-crest svg { width: 28px; height: 28px; fill: var(--rose-deep); }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  35%      { transform: scale(1.11); }
  55%      { transform: scale(1.02); }
}

.headline--thanks {
  font-size: clamp(1.92rem, 6.6vw, 2.85rem);
  line-height: 1.06;
}

/* the pet name that keeps changing its mind */
.nickname {
  position: relative;
  display: inline-block;
  vertical-align: baseline;
  text-align: left;
  color: var(--rose-deep);
  font-style: italic;
  white-space: nowrap;
  transition: width .55s var(--ease);
}

.nickname::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -.06em;
  height: .085em;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(228, 112, 138, 0), var(--rose) 22%, var(--rose) 78%, rgba(228, 112, 138, 0));
  opacity: .55;
}

.nickname-word {
  display: inline-block;
  transition: opacity .34s var(--ease), transform .34s var(--ease), filter .34s var(--ease);
}

.nickname-word.is-out {
  opacity: 0;
  transform: translateY(-.34em) rotate(-3deg);
  filter: blur(5px);
}

.nickname-word.is-in {
  opacity: 0;
  transform: translateY(.34em) rotate(3deg);
  filter: blur(5px);
  transition: none;
}

/* invisible twin, used only to measure the next word */
.nickname-ghost {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: nowrap;
}

.body--thanks { margin-bottom: 15px; }

.body--thanks:first-of-type {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.15rem, 3.6vw, 1.34rem);
  line-height: 1.5;
  color: var(--ink);
  letter-spacing: -.012em;
}

.phrase {
  color: var(--rose-deep);
  font-weight: 600;
}

.emoji {
  display: inline-block;
  font-size: .92em;
  font-style: normal;
  animation: sniffle 3.4s ease-in-out infinite;
}

@keyframes sniffle {
  0%, 62%, 100% { transform: rotate(0deg) translateY(0); }
  70%           { transform: rotate(-7deg) translateY(-2px); }
  78%           { transform: rotate(6deg) translateY(0); }
  86%           { transform: rotate(-4deg) translateY(-1px); }
}

.signoff {
  margin: 26px 0 0;
  font-family: var(--hand);
  font-size: 1.75rem;
  color: var(--rose-deep);
  transform: rotate(-3deg);
}

.signoff-heart {
  width: .78em;
  height: .78em;
  fill: var(--rose);
  vertical-align: -.04em;
  margin-left: .12em;
  transform-origin: center;
  animation: beat 1.9s ease-in-out infinite;
}

@keyframes beat {
  0%, 100% { transform: scale(1); }
  22%      { transform: scale(1.22); }
  40%      { transform: scale(1.02); }
  58%      { transform: scale(1.14); }
}

/* staggered entrance for the thanks card */
.stage--thanks.is-active .hearts-crest,
.stage--thanks.is-active .headline--thanks,
.stage--thanks.is-active .body--thanks,
.stage--thanks.is-active .signoff {
  animation-name: rise-in;
  animation-duration: .85s;
  animation-timing-function: var(--ease);
  animation-fill-mode: both;
}

.stage--thanks.is-active .hearts-crest {
  animation-name: rise-in, pulse;
  animation-duration: .85s, 2.4s;
  animation-delay: .05s, .9s;
  animation-iteration-count: 1, infinite;
  animation-fill-mode: both, none;
}

.stage--thanks.is-active .headline--thanks { animation-delay: .16s; }
.stage--thanks.is-active .body--thanks:nth-of-type(1) { animation-delay: .32s; }
.stage--thanks.is-active .body--thanks:nth-of-type(2) { animation-delay: .46s; }
.stage--thanks.is-active .body--thanks:nth-of-type(3) { animation-delay: .58s; }
.stage--thanks.is-active .signoff { animation-delay: .74s; }

@keyframes rise-in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- footer ---------------------------------------- */

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  padding: 14px 16px 18px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 247, 241, 0), rgba(255, 247, 241, .78) 62%);
}

.footer-text {
  font-family: var(--hand);
  font-size: 1.16rem;
  line-height: 1;
  color: var(--ink-soft);
  opacity: .72;
  letter-spacing: .012em;
  display: inline-flex;
  align-items: center;
  gap: .28em;
  transition: opacity .4s ease;
  animation: rise-in .9s var(--ease) 1.1s both;
}

.footer-heart {
  width: .82em;
  height: .82em;
  fill: var(--rose);
  animation: beat 1.9s ease-in-out infinite;
}

/* ---------- heart burst ----------------------------------- */

.burst {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  overflow: hidden;
}

.spark {
  position: absolute;
  color: var(--rose);
  animation: pop 1.5s cubic-bezier(.16, .84, .44, 1) forwards;
}

.spark svg { width: 100%; height: 100%; fill: currentColor; display: block; }

@keyframes pop {
  0%   { transform: translate(0, 0) scale(.2) rotate(0deg); opacity: 1; }
  70%  { opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(1) rotate(var(--tr)); opacity: 0; }
}

/* ---------- responsive ------------------------------------ */

@media (max-width: 460px) {
  .stage-wrap { padding: 4vh 16px 58px; }
  .footer-text { font-size: 1.05rem; }
  .card { border-radius: 22px; }
  .btn { padding: 14px 28px; font-size: .98rem; }
  .choices { gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .12s !important;
  }
  .petals, .grain { display: none; }
}
