:root {
  --paper: #f3eadc;
  --paper-2: #f7f1e6;
  --ink: #2c241c;
  --ink-soft: #6e6258;
  --wax: #7c2a38;
  --wax-deep: #5c1c28;
  --gold: #c6a36a;
  --serif: "Cormorant Garamond", "Times New Roman", serif;
  --script: "Caveat", "Segoe Script", cursive;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 500;
  overscroll-behavior: none;
}

body.is-sealed {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body.is-finale {
  overflow: hidden;
}

::selection {
  background: #e7c3c8;
  color: var(--ink);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  opacity: 0.18;
  background-image: url("grain.svg");
  background-size: 180px 180px;
  mix-blend-mode: multiply;
}

.cover {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: calc(1.25rem + var(--safe-top)) 1.25rem calc(1.5rem + var(--safe-bottom));
  background:
    radial-gradient(80% 46% at 50% 12%, rgba(255, 250, 242, 0.95), transparent 62%),
    var(--paper);
  transition: opacity 0.55s ease;
}

.cover.is-gone {
  opacity: 0;
  pointer-events: none;
}

.cover__center {
  width: min(100%, 26rem);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cover__kicker,
.letter__kicker {
  margin: 0 0 1.4rem;
  font-size: 0.78rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.cover__hint {
  margin: 1.6rem 0 0;
  font-family: var(--script);
  font-size: 1.7rem;
  color: var(--wax);
  animation: hint 2.4s ease-in-out infinite;
}

.is-breaking .cover__hint {
  animation: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

@keyframes hint {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.envelope {
  position: relative;
  width: min(86vw, 320px);
  height: 210px;
  perspective: 900px;
  transform-style: preserve-3d;
  filter: drop-shadow(0 22px 28px rgba(70, 45, 25, 0.22));
}

.envelope__back,
.envelope__slip,
.envelope__pocket,
.envelope__flap {
  position: absolute;
}

.envelope__back {
  inset: 0;
  border-radius: 3px;
  background: #d9c6ae;
  z-index: 0;
}

.envelope__slip {
  left: 7%;
  right: 7%;
  top: 14%;
  height: 64%;
  background: #fbf6ee;
  border-radius: 2px;
  z-index: 1;
  box-shadow: 0 0 0 1px rgba(90, 60, 30, 0.05);
  transition: transform 0.9s ease 0.12s;
}

.is-opening .envelope__slip {
  transform: translateY(-58%);
}

.envelope__pocket {
  inset: 0;
  z-index: 2;
  background: linear-gradient(#efe2cf, #e5d4bb);
  clip-path: polygon(0 40%, 50% 70%, 100% 40%, 100% 100%, 0 100%);
}

.envelope__flap {
  left: 0;
  right: 0;
  top: 0;
  height: 62%;
  z-index: 3;
  background: linear-gradient(#f6ecde, #e7d6c0);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: 50% 0;
  backface-visibility: hidden;
  transition: transform 0.85s cubic-bezier(0.55, 0.05, 0.25, 1);
}

.is-opening .envelope__flap {
  transform: rotateX(-188deg);
}

.envelope__name {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 73%;
  z-index: 4;
  margin: 0;
  text-align: center;
  font-family: var(--script);
  font-size: 2.15rem;
  line-height: 1;
  color: #3a2e28;
  pointer-events: none;
}

.seal {
  position: absolute;
  left: 50%;
  top: 49%;
  z-index: 5;
  width: 92px;
  height: 92px;
  transform: translate(-50%, -50%);
  touch-action: manipulation;
}

.seal:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
  border-radius: 50%;
}

.seal__face {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 48% 52% 50% 49% / 50% 48% 52% 50%;
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.38), transparent 28%),
    radial-gradient(circle at 50% 58%, #a34554, #6d2432 64%, #4e1620);
  box-shadow:
    0 10px 16px rgba(80, 18, 28, 0.28),
    inset 0 -7px 10px rgba(0, 0, 0, 0.2),
    inset 0 2px 3px rgba(255, 255, 255, 0.28);
}

.seal__glyph {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.7rem;
  color: #f6e6c9;
  transform: translateY(-1px);
}

.is-breaking .seal__face {
  animation: seal-pop 0.48s ease forwards;
}

@keyframes seal-pop {
  35% { transform: scale(1.05); }
  100% { transform: scale(0.7); opacity: 0; }
}

.shard {
  position: absolute;
  inset: 6%;
  z-index: 2;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.28), transparent 26%),
    radial-gradient(circle at 50% 50%, #9a3b4a, #641f2c);
  opacity: 0;
  pointer-events: none;
}

.is-breaking .shard {
  animation: shard-fly 0.72s ease forwards;
}

@keyframes shard-fly {
  0% { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--spin)); }
}

.letter {
  width: min(100%, 28rem);
  margin: 0 auto;
  padding: calc(1.6rem + var(--safe-top)) 1.35rem calc(2.8rem + var(--safe-bottom));
}

body.is-sealed .letter {
  visibility: hidden;
}

.letter__head {
  text-align: center;
  margin-bottom: 1.6rem;
}

.letter__kicker {
  margin-bottom: 0.35rem;
}

.letter__name {
  margin: 0;
  font-family: var(--script);
  font-size: 3.1rem;
  font-weight: 500;
  line-height: 1;
}

.letter__rule {
  width: 72px;
  height: 1px;
  margin: 0.9rem auto 0;
  background: var(--gold);
}

.prose {
  margin: 0 auto 0.4rem;
  max-width: 22rem;
  font-size: 1.48rem;
  line-height: 1.38;
  text-align: center;
}

.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 1s ease, transform 1s ease;
}

.reveal.is-in {
  opacity: 1;
  transform: translateY(0);
}

.reveal-ink.is-in {
  animation: ink 1.2s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

@keyframes ink {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(0 0 0 0); }
}

.polaroid {
  position: relative;
  width: min(86%, 340px);
  margin: 1.7rem auto;
  padding: 0.65rem 0.65rem 0.35rem;
  background: #fffdf9;
  box-shadow:
    0 16px 36px rgba(70, 48, 28, 0.16),
    0 1px 0 rgba(255, 255, 255, 0.8) inset;
  --tilt: -2deg;
  transform: translateY(22px) rotate(var(--tilt));
}

.polaroid.is-wide {
  width: min(100%, 400px);
}

.polaroid.is-in {
  transform: translateY(0) rotate(var(--tilt));
}

.polaroid img {
  display: block;
  width: 100%;
  height: auto;
  background: #efe6da;
}

.polaroid figcaption,
.film figcaption {
  margin: 0.55rem 0.35rem 0.7rem;
  text-align: center;
  font-family: var(--script);
  font-size: 1.42rem;
  line-height: 1.2;
  color: #3a312a;
}

.polaroid.has-tape::before {
  content: "";
  position: absolute;
  top: -11px;
  left: 50%;
  width: 74px;
  height: 22px;
  transform: translateX(-50%) rotate(-2deg);
  background: rgba(232, 214, 170, 0.62);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.film {
  width: min(92%, 380px);
  margin: 1.7rem auto;
}

.film__frame {
  position: relative;
  padding: 0.65rem 1.25rem 0.75rem;
  background: #1c1714;
  border-radius: 3px;
  box-shadow: 0 16px 36px rgba(40, 24, 16, 0.22);
}

.film__frame::before,
.film__frame::after {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  width: 11px;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 7px,
    #f4efe6 7px 13px,
    transparent 13px 21px
  );
}

.film__frame::before { left: 5px; }
.film__frame::after { right: 5px; }

.film video {
  display: block;
  width: 100%;
  max-height: 68vh;
  background: #000;
  object-fit: contain;
}

.film__play {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 68px;
  height: 68px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(243, 234, 220, 0.92);
  color: var(--wax);
  font-size: 1.35rem;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  touch-action: manipulation;
}

.film__play span {
  display: block;
  transform: translateX(2px);
}

.film.is-playing .film__play {
  opacity: 0;
  pointer-events: none;
}

.ask {
  margin-top: 2.2rem;
  text-align: center;
}

.ask__q {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(2.35rem, 10vw, 3.15rem);
  line-height: 1.05;
}

.ask__q::after {
  content: "";
  display: block;
  width: 72px;
  height: 1px;
  margin: 1rem auto 0;
  background: var(--gold);
}

.yes {
  width: 108px;
  height: 108px;
  margin: 1.5rem auto 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  touch-action: manipulation;
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.35), transparent 28%),
    radial-gradient(circle at 50% 58%, #a34554, #6d2432 64%, #4e1620);
  box-shadow:
    0 12px 20px rgba(80, 18, 28, 0.28),
    inset 0 -8px 12px rgba(0, 0, 0, 0.18),
    inset 0 2px 3px rgba(255, 255, 255, 0.28);
  transition: transform 0.25s ease;
}

.yes span {
  font-family: var(--script);
  font-size: 2.3rem;
  color: #f6e6c9;
  line-height: 1;
}

.yes:active,
.yes.is-lit {
  transform: scale(0.94);
}

.yes:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

.finale {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: calc(1.5rem + var(--safe-top)) 1.4rem calc(1.5rem + var(--safe-bottom));
  background: #f6f0e6;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.7s ease, visibility 0.7s ease;
}

.finale.is-on {
  opacity: 1;
  visibility: visible;
}

.finale__hearts {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.heart {
  position: absolute;
  bottom: -24px;
  opacity: 0;
  animation: rise linear infinite;
}

.heart svg {
  display: block;
  width: 100%;
  height: auto;
  fill: var(--wax);
}

@keyframes rise {
  0% { transform: translateY(10px); opacity: 0; }
  12% { opacity: 0.4; }
  100% { transform: translateY(-105vh); opacity: 0; }
}

.finale__card {
  position: relative;
  z-index: 1;
  width: min(100%, 22rem);
  text-align: center;
}

.finale__name {
  margin: 0;
  font-family: var(--script);
  font-size: 3rem;
  line-height: 1;
  opacity: 0;
  transform: translateY(8px);
}

.finale__phrase {
  margin: 0.8rem 0 0;
  font-style: italic;
  font-weight: 600;
  font-size: 1.85rem;
  line-height: 1.25;
  white-space: pre-line;
  opacity: 0;
  transform: translateY(10px);
}

.finale.is-on .finale__name,
.finale.is-on .finale__phrase {
  opacity: 1;
  transform: none;
  transition: opacity 0.9s ease, transform 0.9s ease;
}

.finale.is-on .finale__phrase {
  transition-delay: 0.22s;
}

.finale__back {
  margin-top: 2rem;
  font-family: var(--script);
  font-size: 1.35rem;
  color: var(--ink-soft);
  opacity: 0;
}

.finale.is-on .finale__back {
  opacity: 1;
  transition: opacity 0.8s ease 0.55s;
}

@media (prefers-reduced-motion: reduce) {
  .cover__hint,
  .reveal,
  .polaroid,
  .finale,
  .finale__name,
  .finale__phrase,
  .finale__back,
  .envelope__flap,
  .envelope__slip {
    animation: none !important;
    transition: none !important;
  }

  .heart { display: none; }
}
