:root {
  --paper: #f4ead5;
  --card: #fffaf0;
  --ink: #3a2a1e;
  --ink-soft: #6e5844;
  --line: rgba(110, 80, 50, 0.18);
  --wax: #8e2430;
  --wax-dark: #651620;
  --env: #e6d2aa;
  --env-front: #eedcb6;
  --env-flap: #dcc395;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --hand: "Caveat", "Segoe Script", "Bradley Hand", cursive;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: light; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* aged paper: soft vignette + grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse at 50% 30%, transparent 45%, rgba(120, 80, 40, 0.14) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .42 0 0 0 0 .3 0 0 0 0 .18 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

#app {
  position: relative;
  z-index: 1;
  max-width: 540px;
  margin: 0 auto;
  padding: max(36px, env(safe-area-inset-top)) 20px 110px;
}

a { color: inherit; }
.center { text-align: center; }
.hand { font-family: var(--hand); }

.kicker {
  font-size: 0.82rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: center;
}

h1 {
  font-weight: 400;
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  line-height: 1.1;
  text-align: center;
  margin: 8px 0 6px;
}

.sub {
  text-align: center;
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- polaroid ---------- */
.polaroid {
  position: relative;
  background: var(--card);
  padding: 12px 12px 0;
  margin: 28px auto 0;
  max-width: 420px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 14px 30px rgba(70, 40, 15, 0.2);
  transform: rotate(var(--tilt, -1.5deg));
}
.polaroid::before { /* washi tape */
  content: "";
  position: absolute;
  top: -13px;
  left: 50%;
  width: 96px;
  height: 26px;
  margin-left: -48px;
  background: rgba(214, 190, 150, 0.72);
  transform: rotate(-3deg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.polaroid img,
.ph {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #ddd0b5;
}
.ph {
  display: grid;
  place-items: center;
  font-family: var(--hand);
  font-size: 2rem;
  color: rgba(58, 42, 30, 0.45);
}
.polaroid figcaption {
  font-family: var(--hand);
  font-size: 1.6rem;
  line-height: 1.2;
  text-align: center;
  padding: 12px 8px 18px;
}
.polaroid:not(:has(figcaption)) { padding-bottom: 40px; }

.meta {
  text-align: center;
  margin-top: 22px;
  font-style: italic;
  color: var(--ink-soft);
}
.note {
  margin: 14px auto 0;
  max-width: 440px;
  text-align: center;
  font-size: 1.12rem;
}

/* ---------- buttons ---------- */
.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 34px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 26px;
  border: 1.5px solid var(--wax);
  border-radius: 999px;
  background: var(--card);          /* secondary: outline on solid cream, wax text = 8:1 contrast */
  color: var(--wax);
  font: inherit;
  font-size: 1.08rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}
.btn:hover { background: #f6e6dc; }
.btn:active { transform: scale(0.96); }
.btn:focus-visible,
.text-link:focus-visible,
.music:focus-visible,
.seal:focus-visible,
.voice:focus-visible {
  outline: 3px solid var(--wax);
  outline-offset: 3px;
}
.btn.primary {                       /* primary: solid wax, cream text = 8.9:1 contrast */
  background: var(--wax);
  border-color: var(--wax);
  color: #fbeee0;
  box-shadow: 0 6px 16px rgba(101, 22, 32, 0.25);
}
.btn.primary:hover { background: var(--wax-dark); border-color: var(--wax-dark); }
.text-link {
  color: var(--wax);
  font-size: 1.05rem;
  font-weight: 600;
  text-underline-offset: 4px;
}

.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px auto 0;
  min-height: 44px;
  padding: 8px 18px 8px 10px;
  border: 0;
  border-radius: 999px;
  background: rgba(142, 36, 48, 0.08);
  color: var(--wax);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}
.voice-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--wax);
  color: #fbeee0;
  font-size: 0.75rem;
}

/* ============================================================
   Day counter
   ============================================================ */
.counter {
  margin-top: 56px;
  text-align: center;
}
.counter-words {
  font-family: var(--hand);
  font-size: 1.5rem;
  line-height: 1.2;
  color: var(--ink-soft);
}
.counter-num {
  margin: 2px 0 4px;
  font-family: var(--serif);
  font-size: clamp(3rem, 16vw, 4rem);
  font-weight: 600;
  line-height: 1;
  color: var(--wax);
  font-variant-numeric: lining-nums tabular-nums;
}
.counter-hours {
  margin-top: 10px;
  font-size: 0.95rem;
  font-style: italic;
  color: var(--ink-soft);
}

.secret {
  margin-top: 38px;
  padding: 26px 20px;
  text-align: center;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.secret p {
  font-family: var(--hand);
  font-size: 1.6rem;
  line-height: 1.25;
  margin-bottom: 18px;
}

.hint {
  text-align: center;
  font-style: italic;
  color: var(--ink-soft);
  margin-top: 16px;
}

/* ---------- story ---------- */
.year {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 64px 0 4px;
  font-family: var(--hand);
  font-weight: 400;
  font-size: 2.4rem;
  color: var(--wax);
}
.year::before,
.year::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.story-item { margin-top: 44px; }
/* ============================================================
   Finale (end of the story wall)
   ============================================================ */
.finale {
  position: relative;
  margin-top: 90px;
  padding: 40px 0 10px;
  text-align: center;
}
.finale-line {
  font-family: var(--hand);
  font-size: 2rem;
  line-height: 1.2;
  color: var(--ink-soft);
}
.finale-title {
  margin-top: 26px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  line-height: 1.08;
  color: var(--wax);
}
.finale .text-link,
.finale .hint { display: inline-block; margin-top: 30px; }
.petals {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- envelope ---------- */
.stage {
  min-height: calc(100svh - 160px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 26px;
}
.envelope {
  position: relative;
  width: min(86vw, 380px);
  aspect-ratio: 3 / 2;
  perspective: 1200px;
  margin-top: clamp(120px, 40vw, 160px);   /* room for the flap and letter above it */
}
.env-back,
.env-front,
.env-flap,
.env-slip { position: absolute; }
.env-back {
  inset: 0;
  background: var(--env);
  border-radius: 6px;
  box-shadow: 0 18px 40px rgba(70, 40, 15, 0.25);
}
.env-slip {
  left: 6%;
  right: 6%;
  top: 6%;
  bottom: 6%;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 12px;
  background: var(--card);
  font-family: var(--hand);
  font-size: 1.7rem;
  line-height: 1.15;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: transform 1s ease 0.55s;
}
.env-front {
  inset: 0;
  z-index: 2;
  background: var(--env-front);
  border-radius: 6px;
  clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 9%;
}
.env-to { font-family: var(--hand); font-size: 1.8rem; color: var(--ink); }
.env-flap {
  left: 0;
  right: 0;
  top: 0;
  height: 58%;
  z-index: 3;
  background: var(--env-flap);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform 0.7s ease, z-index 0s linear 0.35s;
}
.seal {
  position: absolute;
  z-index: 4;
  top: calc(58% - 38px);
  left: calc(50% - 38px);
  width: 76px;
  height: 76px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b8404d, var(--wax) 55%, var(--wax-dark));
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.3), 0 5px 12px rgba(0, 0, 0, 0.28);
  color: #f2d6c2;
  font-family: var(--hand);
  font-size: 2.1rem;
  cursor: pointer;
  transition: opacity 0.4s ease, transform 0.4s ease;
  animation: pulse 2.4s ease-in-out infinite;
}
.envelope.open .seal { opacity: 0; transform: scale(0.6); pointer-events: none; animation: none; }
.envelope.open .env-flap { transform: rotateX(180deg); z-index: 0; }
.envelope.open .env-slip { transform: translateY(-62%); }

/* letter page: envelope is already open, only the letter slides out */
.envelope.flap-open .env-flap { transform: rotateX(180deg); z-index: 0; transition: none; }
.envelope.flap-open .env-slip { transition: transform 1.2s cubic-bezier(.2, .7, .2, 1) 0.15s; }
.envelope.flap-open.open .env-slip { transform: translateY(-70%); }

@keyframes pulse {
  0%, 100% { box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.3), 0 5px 12px rgba(0, 0, 0, 0.28), 0 0 0 0 rgba(142, 36, 48, 0.35); }
  50% { box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.3), 0 5px 12px rgba(0, 0, 0, 0.28), 0 0 0 14px rgba(142, 36, 48, 0); }
}

.fade-out { opacity: 0; transition: opacity 0.6s ease; }

/* ---------- letter ---------- */
/* One unit (--line-h) drives the text line height, the ruled lines and
   every vertical gap, so the writing always sits on the lines.
   --ink-drop nudges the rules down onto the handwriting baseline. */
.letter-page .kicker { margin-bottom: 22px; }
.letter-paper {
  --line-h: 36px;
  --ink-drop: 7px;
  position: relative;
  padding: var(--line-h) 24px var(--line-h);   /* ends one line after the signature */
  background-color: var(--card);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 calc(var(--line-h) - 1px),
    var(--line) calc(var(--line-h) - 1px) var(--line-h)
  );
  background-position: 0 calc(-1 * var(--ink-drop));
  background-attachment: local;
  font-family: var(--hand);
  font-size: 1.6rem;
  line-height: var(--line-h);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1), 0 16px 34px rgba(70, 40, 15, 0.18);
  transform: rotate(-0.6deg);
}
.letter-paper p { margin: 0 0 var(--line-h); }
.letter-paper p:last-child { margin-bottom: 0; }
.letter-paper .write {
  opacity: 0;
  animation: write 1.4s ease forwards;
  animation-delay: var(--d, 0s);
}
.letter-sign { text-align: right; }
.letter-img img {
  display: block;
  width: 100%;
  background: var(--card);
  box-shadow: 0 16px 34px rgba(70, 40, 15, 0.2);
}
@keyframes write {
  from { opacity: 0; transform: translateY(8px); filter: blur(2px); }
  to { opacity: 1; transform: none; filter: none; }
}

/* ---------- countdown ---------- */
.countdown .seal { position: static; animation: pulse 2.4s ease-in-out infinite; cursor: default; }
.clock {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}
.clock div {
  min-width: 70px;
  padding: 12px 6px 8px;
  background: var(--card);
  text-align: center;
  box-shadow: 0 6px 16px rgba(70, 40, 15, 0.12);
}
.clock b {
  display: block;
  font-size: 2rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.clock span {
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ---------- music button ---------- */
.music {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  width: 50px;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 1.4rem;
  box-shadow: 0 6px 16px rgba(70, 40, 15, 0.18);
  cursor: pointer;
}
/* paused: muted icon with a strike-through */
.music::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  top: 50%;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transform: rotate(-45deg);
}
/* playing: burgundy icon with a slow pulsing ring */
.music.playing { color: var(--wax); }
.music.playing::after { display: none; }
.music.playing::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 2px solid var(--wax);
  opacity: 0;
}
@keyframes ring {
  0% { transform: scale(1); opacity: 0.55; }
  100% { transform: scale(1.6); opacity: 0; }
}

.toast {
  position: fixed;
  right: 76px;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 8px));
  z-index: 10;
  max-width: calc(100vw - 100px);
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #fbeee0;
  font-size: 0.98rem;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.toast.show { opacity: 1; }

/* ---------- scroll reveal ----------
   Content is visible by default; it only fades in when motion is allowed. */
@media (prefers-reduced-motion: no-preference) {
  .reveal { opacity: 0; transform: translateY(18px); transition: opacity 0.9s ease, transform 0.9s ease; }
  .reveal.in { opacity: 1; transform: none; }
  .polaroid.reveal.in { transform: rotate(var(--tilt, -1.5deg)); }
  /* buttons: quick, so they're readable right away */
  .actions.reveal, .secret.reveal, .finale .reveal:has(.text-link) {
    transform: translateY(8px);
    transition: opacity 0.35s ease, transform 0.35s ease;
  }
  .actions.reveal.in, .secret.reveal.in, .finale .reveal.in:has(.text-link) { transform: none; }
  .music.playing::before { animation: ring 2.4s ease-out infinite; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .letter-paper .write { opacity: 1; transform: none; filter: none; }
}

/* ---------- tag helper page ---------- */
.tags-list { list-style: none; margin-top: 24px; }
.tags-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.tags-list .num { width: 34px; font-weight: 600; }
.tags-list code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 0.85rem; }
.tags-list .btn { min-height: 36px; padding: 4px 14px; font-size: 0.9rem; }
.tags-list .special { color: var(--wax); font-style: italic; }

/* Preview-mode reminder (only shows before the birthday) */
.preview-badge {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%);
  z-index: 50; padding: 6px 14px; border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font: 600 13px/1.3 system-ui, sans-serif; text-decoration: none;
  opacity: .85; white-space: nowrap;
}

/* Countdown guard (stick man + knife) */
.guard { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
html.guarding body { touch-action: none; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
html.knife, html.knife * { cursor: none !important; }
.countdown .hint b { font-style: normal; color: var(--wax); }
.countdown .actions { margin-top: 22px; }
.surprise-btn { transition: opacity 0.35s ease, visibility 0.35s; }
.surprise-btn.gone { opacity: 0; visibility: hidden; }
.surprise-btn.nope { animation: nope 0.45s ease; }
@keyframes nope {
  20% { transform: translateX(-7px) rotate(-2deg); }
  40% { transform: translateX(6px) rotate(2deg); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

/* ============================================================
   Romantic details
   ============================================================ */

/* hearts & petals drifting behind every page */
.ambient { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

/* little hearts wherever she taps */
.tap-heart {
  position: fixed; z-index: 60; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  pointer-events: none; opacity: 0;
  animation: tapheart 0.95s ease-out forwards;
}
.tap-heart svg { display: block; width: 100%; height: 100%; }
@keyframes tapheart {
  0%   { opacity: 1; transform: translate(0, 0) scale(0.2); }
  55%  { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(var(--s)) rotate(var(--r)); }
}

/* secret note on the back of each photo */
.polaroid { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.polaroid img { -webkit-user-drag: none; }
.polaroid::before { z-index: 2; }              /* washi tape stays on top of the back */
.pol-back {
  position: absolute; inset: 0; z-index: 1;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: 14% 12%;
  background-color: var(--card);
  background-image: repeating-linear-gradient(to bottom, transparent 0 33px, rgba(110, 80, 50, 0.12) 33px 34px);
  font-family: var(--hand); font-size: clamp(1.7rem, 7vw, 2.2rem); line-height: 1.25;
  text-align: center; color: var(--ink);
}
.pol-back-sign { font-size: 0.75em; color: var(--wax); }
.polaroid.flipped .pol-back { display: flex; }
.polaroid.reveal.in.holding { transform: rotate(var(--tilt, -1.5deg)) scale(0.97); transition: transform 0.6s ease; }
.hold-hint {
  margin-top: 18px; text-align: center;
  font-family: var(--hand); font-size: 1.4rem; line-height: 1.2; color: var(--ink-soft);
}
.hold-hint.fade-out { opacity: 0 !important; transition: opacity 0.5s ease; }

/* red thread tying the memories together */
.thread { display: block; width: 44px; height: 72px; margin: 26px auto 0; }
.thread svg { display: block; width: 100%; height: 100%; overflow: visible; }
.thread .string { fill: none; stroke: var(--wax); stroke-width: 1.6; stroke-linecap: round; opacity: 0.7; }
.thread .knot { fill: var(--wax); opacity: 0.9; }
.thread + .story-item { margin-top: 18px; }
.thread + .year { margin-top: 12px; }

/* finale: all the photos in a heart */
.heart-wall {
  position: relative; width: 100%; max-width: 440px; margin: 0 auto 46px;
  aspect-ratio: 34 / 31; container-type: inline-size;
}
.mini {
  position: absolute; width: 12.5%;
  padding: 1cqw 1cqw 2.8cqw;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15), 0 4px 10px rgba(70, 40, 15, 0.22);
  transform: translate(-50%, -50%) rotate(var(--r));
}
.mini.big { width: 19%; z-index: 2; }
.mini img, .mini .ph { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; font-size: 0.7rem; }

/* lipstick kiss on the letter */
.letter-paper p:last-of-type { margin-bottom: 0; }
.letter-img { position: relative; }
.kiss {
  position: absolute; left: 14px; bottom: 16px; width: 96px;
  transform: rotate(-14deg); opacity: 0.85; mix-blend-mode: multiply; pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .thread.reveal .string { stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset 1.3s ease 0.1s; }
  .thread.reveal.in .string { stroke-dashoffset: 0; }
  .thread.reveal .knot { transform-origin: 22px 36px; transform: scale(0); transition: transform 0.5s cubic-bezier(.3, 1.6, .5, 1) 0.8s; }
  .thread.reveal.in .knot { transform: none; }

  .heart-wall .mini { transition: transform 1.3s cubic-bezier(.2, .8, .25, 1) var(--d), opacity 0.4s ease var(--d); }
  .heart-wall.reveal:not(.in) .mini {
    opacity: 0;
    transform: translate(-50%, -50%) translate(calc(var(--sx) * 1cqw), calc(var(--sy) * 1cqw)) rotate(var(--r0)) scale(0.4);
  }
  .heart-wall.reveal { transform: none; }      /* the tiles do the moving */

  .kiss { opacity: 0; animation: kiss 0.45s ease-out forwards; animation-delay: var(--kiss-d, 1.2s); }
  @keyframes kiss {
    0%   { opacity: 0; transform: rotate(-14deg) scale(1.4); }
    100% { opacity: 0.85; transform: rotate(-14deg) scale(1); }
  }
}
