/*
 * Mohar — Sealed With A Kiss (Boyfriend Day family).
 * Ported verbatim from the original single-file design; the only change is
 * that the wax seal's initial comes from data-initial instead of a fixed "R".
 * Fonts (Fraunces, Caveat) are linked from the page head.
 */
:root {
  --bg: #FBF3E4;
  --paper: #FFFDF8;
  --ink: #2B2118;
  --wax: #B85C48;
  --wax-dark: #9E4A38;
  --gold: #C9A86A;
  --sage: #8A9B7C;
  --kraft: #E0CBA4;
  --kraft-dark: #C9AF83;
  --kraft-light: #EADCC0;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: 'Caveat', cursive;
  color: var(--ink);
  background:
    radial-gradient(130% 90% at 50% 0%, #FFFDF6 0%, var(--bg) 48%, #F2E4C9 100%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- paper grain (pure CSS/SVG, no external assets) ---------- */
.grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .06;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(120% 120% at 50% 40%, transparent 60%, rgba(43, 33, 24, .10) 100%);
}

/* ================= SCREEN 1 · ENVELOPE ================= */
.stage-wrap {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage {
  width: min(480px, 100%);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  transition: opacity .6s var(--ease), transform .6s var(--ease), visibility 0s .6s;
}

.stage-wrap.away .stage {
  opacity: 0;
  transform: scale(.96);
  visibility: hidden;
  pointer-events: none;
}

.envelope-btn {
  background: none;
  border: 0;
  padding: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-radius: 16px;
}

.envelope-btn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 4px;
}

.envelope-scene {
  perspective: 1100px;
  width: min(320px, 78vw);
}

.envelope {
  position: relative;
  width: 100%;
  aspect-ratio: 320 / 208;
  transform-style: preserve-3d;
}

.env-back {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(175deg, var(--kraft-light) 0%, var(--kraft) 70%);
  border-radius: 6px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .5) inset,
    0 18px 34px -12px rgba(43, 33, 24, .35);
}

.letter-mini {
  position: absolute;
  left: 6%;
  top: 7%;
  width: 88%;
  height: 86%;
  z-index: 2;
  background: linear-gradient(180deg, #FFFDF8 0%, #FDF6E9 100%);
  border-radius: 3px;
  box-shadow: 0 2px 8px rgba(43, 33, 24, .18);
  transition: transform .8s var(--ease) .3s;
}

.letter-mini::after {
  /* faint ruled lines peeking at the top of the letter */
  content: "";
  position: absolute;
  inset: 10px 14px auto 14px;
  height: 26px;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 8px,
    rgba(43, 33, 24, .14) 8px 9px
  );
}

.env-front {
  position: absolute;
  inset: 0;
  z-index: 3;
  background:
    linear-gradient(180deg, var(--kraft) 0%, var(--kraft-dark) 100%);
  clip-path: polygon(0 0, 50% 58%, 100% 0, 100% 100%, 0 100%);
  border-radius: 6px;
  box-shadow: 0 -1px 0 rgba(255, 255, 255, .35) inset;
}

.env-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 62%;
  z-index: 4;
  background: linear-gradient(180deg, var(--kraft-dark) 0%, var(--kraft) 85%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  backface-visibility: hidden;
  transition:
    transform .7s var(--ease),
    z-index 0s .35s;
}

.envelope-scene.opened .env-flap {
  transform: rotateX(180deg);
  z-index: 1;
}

.envelope-scene.opened .letter-mini {
  transform: translateY(-78%);
}

.wax-seal {
  position: absolute;
  left: 50%;
  bottom: -6%;
  width: 62px;
  height: 62px;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 32% 28%, #CE7460 0%, var(--wax) 55%, var(--wax-dark) 100%);
  border-radius: 47% 53% 51% 49% / 52% 48% 53% 48%;
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, .35),
    inset 0 -3px 5px rgba(0, 0, 0, .3),
    0 5px 10px rgba(43, 33, 24, .3);
}

.wax-seal::before {
  /* the sender's initial, from data-initial (was a hardcoded "R") */
  content: attr(data-initial);
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 26px;
  color: #7E3325;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .25);
}

.sender {
  font-family: 'Fraunces', serif;
  font-variant: small-caps;
  letter-spacing: .14em;
  font-size: 15px;
  color: rgba(43, 33, 24, .78);
}

.sender strong {
  font-weight: 600;
  color: var(--ink);
}

.hint {
  font-size: 19px;
  color: rgba(43, 33, 24, .55);
  animation: pulse 2.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: .45; }
  50%      { opacity: 1; }
}

/* ================= SCREEN 2 & 3 · LETTER ================= */
.letter-screen {
  position: fixed;
  inset: 0;
  z-index: 5;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(7vh, 40px) 20px max(9vh, 48px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .55s var(--ease), visibility 0s .55s;
}

.letter-screen.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity .55s var(--ease);
}

.letter-paper {
  width: min(480px, 100%);
  margin: 0 auto;
  background:
    linear-gradient(180deg, #FFFDF8 0%, #FEF9EC 60%, #FBF1DC 100%);
  border-radius: 4px;
  padding: clamp(28px, 6vw, 48px) clamp(22px, 6vw, 44px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .8) inset,
    0 24px 48px -16px rgba(43, 33, 24, .35),
    0 4px 12px rgba(43, 33, 24, .12);
  transform: translateY(6vh) scale(.94);
  transition: transform .7s var(--ease);
}

.letter-screen.show .letter-paper { transform: none; }

.letter-paper .salutation,
.letter-paper p,
.signoff {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity .6s var(--ease), transform .6s var(--ease);
  transition-delay: calc(250ms + var(--i) * 600ms);
}

.letter-screen.show .salutation,
.letter-screen.show p,
.letter-screen.show .signoff {
  opacity: 1;
  transform: none;
}

.salutation {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 500;
  font-size: 27px;
  margin-bottom: 18px;
  color: var(--ink);
}

.letter-body p {
  font-size: 22px;
  line-height: 1.7;
  margin-bottom: 18px;
}

.letter-body p:last-of-type { margin-bottom: 26px; }

.signoff { text-align: center; }

.flourish {
  display: block;
  width: 190px;
  margin: 0 auto 14px;
  overflow: visible;
}

.flourish path {
  fill: none;
  stroke: var(--wax);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 1.1s var(--ease) calc(250ms + var(--i, 5) * 600ms + 250ms);
}

.letter-screen.show .flourish path { stroke-dashoffset: 0; }

.signoff .forever {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 22px;
  color: var(--ink);
}

.signoff .who {
  display: block;
  font-size: 21px;
  margin-top: 6px;
  color: rgba(43, 33, 24, .75);
}

.date-line {
  margin-top: 20px;
  font-family: 'Fraunces', serif;
  font-variant: small-caps;
  letter-spacing: .14em;
  font-size: 13.5px;
  color: var(--sage);
}

.replay {
  margin-top: 26px;
  font-family: 'Fraunces', serif;
  font-variant: small-caps;
  letter-spacing: .12em;
  font-size: 14.5px;
  color: var(--wax);
  background: transparent;
  border: 1.5px solid var(--wax);
  border-radius: 999px;
  padding: 11px 26px;
  cursor: pointer;
  transition: background .3s var(--ease), color .3s var(--ease), transform .3s var(--ease);
}

.replay:hover { background: var(--wax); color: #FFF6EE; }
.replay:active { transform: scale(.97); }
.replay:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ================= REDUCED MOTION ================= */
@media (prefers-reduced-motion: reduce) {
  .env-flap,
  .letter-mini,
  .stage,
  .letter-screen,
  .letter-paper,
  .salutation,
  .letter-paper p,
  .signoff,
  .flourish path {
    transition-duration: .01ms !important;
    transition-delay: 0ms !important;
  }
  .env-flap { transform: none !important; }
  .envelope-scene.opened .env-flap { transform: rotateX(180deg) !important; }
  .letter-mini { transform: none !important; }
  .envelope-scene.opened .letter-mini { transform: translateY(-78%) !important; }
  .hint { animation: none; }
  .flourish path { stroke-dashoffset: 0 !important; }
}
