:root {
  --bg: #fff5f6;
  --bg2: #fbe4e8;
  --rose: #e86a87;
  --rose-deep: #c2456a;
  --blush: #f7c6d0;
  --ink: #5a3a44;
  --muted: #a07a85;
  --paper: #fffdfb;
  --gold: #d8a86b;
  --shadow: 0 10px 30px rgba(194, 69, 106, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.script { font-family: "Great Vibes", cursive; font-weight: 400; color: var(--rose-deep); }
.muted { color: var(--muted); font-size: 0.9rem; }

/* ---------- Petals ---------- */
#petals { position: fixed; inset: 0; pointer-events: none; z-index: 1; overflow: hidden; }
.petal {
  position: absolute; top: -40px; user-select: none;
  animation: fall linear forwards;
  opacity: 0.85;
}
@keyframes fall {
  to { transform: translate(var(--dx), 110vh) rotate(var(--rot)); opacity: 0.2; }
}
.burst {
  position: fixed; pointer-events: none; z-index: 60;
  animation: burst 1.4s ease-out forwards;
}
@keyframes burst {
  to { transform: translate(var(--dx), var(--dy)) scale(0.4); opacity: 0; }
}

/* ---------- Secret question gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 55;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, #fff 0%, var(--bg2) 80%);
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  transition: opacity 0.6s ease;
}
.gate.gone { opacity: 0; pointer-events: none; }
.gate-box { width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 14px; }
.gate-lock { font-size: 3rem; animation: bob 3s ease-in-out infinite; }
.gate-q { font-family: "Cormorant Garamond", serif; font-size: 1.6rem; font-weight: 600; line-height: 1.25; color: var(--rose-deep); }
.gate form { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.gate input {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in on focus */
  padding: 14px 18px; border-radius: 999px; border: 2px solid var(--blush);
  background: rgba(255, 255, 255, 0.9); color: var(--ink); text-align: center; outline: none;
}
.gate input:focus { border-color: var(--rose); }
.gate .btn:disabled { opacity: 0.6; }
.gate-msg { min-height: 1.4em; color: var(--muted); font-size: 0.95rem; }
.gate.shake .gate-box { animation: shake 0.45s; }
@keyframes shake {
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

/* ---------- Intro / envelope ---------- */
.intro {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.5rem;
  background: radial-gradient(circle at 50% 40%, #fff 0%, var(--bg2) 75%);
  /* Fades out after the letter has risen (see the 2500ms removal in script.js) */
  transition: opacity 0.7s ease 1.7s, visibility 0s linear 2.4s;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
.intro.open { opacity: 0; visibility: hidden; }
.intro-note { font-family: "Cormorant Garamond", serif; font-size: 1.5rem; font-style: italic; color: var(--rose-deep); transition: opacity 0.4s; }
.intro-hint { font-size: 0.8rem; letter-spacing: 0.25em; text-transform: uppercase; color: var(--muted); animation: pulse 2s ease-in-out infinite; transition: opacity 0.3s; }
.intro.open .intro-hint, .intro.open .intro-note { opacity: 0; animation: none; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* Layers, back to front: back (1) → open flap (1) → letter (2) → pocket (3) → closed flap (4) → seal (5) */
.envelope {
  --w: min(78vw, 320px); --h: calc(var(--w) * 0.64);
  position: relative; width: var(--w); height: var(--h);
  margin-top: calc(var(--h) * 0.5); /* room for the letter to rise */
  perspective: 800px;
  filter: drop-shadow(0 18px 25px rgba(194, 69, 106, 0.25));
  animation: bob 3s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-8px); } }
.env-back, .env-front, .env-flap, .env-letter { position: absolute; left: 0; width: 100%; }
.env-back { inset: 0; height: 100%; background: var(--rose-deep); border-radius: 8px; z-index: 1; }
.env-letter {
  left: 6%; width: 88%; height: 88%; bottom: 6%; z-index: 2;
  background: var(--paper); border-radius: 6px; box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px; padding-top: 8%;
  transition: transform 0.8s cubic-bezier(.2, .8, .2, 1) 0.6s;
}
.env-heart { font-size: 2rem; }
.env-to { font-family: "Great Vibes", cursive; font-size: 1.7rem; color: var(--rose-deep); }
/* Pocket: covers the sides and bottom, with a V-shaped opening at the top */
.env-front {
  inset: 0; height: 100%; z-index: 3; border-radius: 8px;
  background: linear-gradient(to right, #f7c0cd, #f4b0c1);
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
}
.env-front::after {
  content: ""; position: absolute; inset: 0; border-radius: 8px;
  background: #f29bb0;
  clip-path: polygon(0 100%, 50% 48%, 100% 100%);
}
.env-flap {
  top: 0; height: 58%; z-index: 4;
  background: linear-gradient(to bottom, #ef8ea4, #e9798f);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
  /* Drops behind the letter once it's edge-on, halfway through the flip */
  transition: transform 0.5s ease 0.15s, z-index 0s linear 0.4s;
}
.env-seal {
  position: absolute; left: 50%; top: 56%; transform: translate(-50%, -50%);
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--rose-deep); color: #fff; display: grid; place-items: center; font-size: 1.3rem;
  box-shadow: 0 3px 8px rgba(0,0,0,0.2); z-index: 5; transition: opacity 0.25s, transform 0.25s;
}
.intro.open .envelope { animation: none; }
.intro.open .env-seal { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
.intro.open .env-flap { transform: rotateX(180deg); z-index: 1; }
.intro.open .env-letter { transform: translateY(-58%); }

/* ---------- Card ---------- */
.card { position: relative; z-index: 2; max-width: 560px; margin: 0 auto; padding: 0 16px calc(48px + env(safe-area-inset-bottom)); }
.hero {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 0.75rem; padding-top: env(safe-area-inset-top);
}
.eyebrow { text-transform: uppercase; letter-spacing: 0.3em; font-size: 0.75rem; color: var(--muted); }
.hero h1 { font-size: clamp(3.2rem, 16vw, 5rem); line-height: 1.05; }
.hero h1 span { display: inline-block; color: var(--rose); animation: glow 3s ease-in-out infinite; }
@keyframes glow { 50% { text-shadow: 0 0 18px rgba(232, 106, 135, 0.45); } }
.hero-sub { font-family: "Cormorant Garamond", serif; font-size: 1.25rem; font-style: italic; }
.scroll-cue { margin-top: 2rem; font-size: 2rem; color: var(--rose); animation: bob 1.8s ease-in-out infinite; }

.section { padding: 56px 0 8px; text-align: center; }
.section h2 { font-size: 2.6rem; margin-bottom: 1rem; }

.reveal { opacity: 0; transform: translateY(30px); transition: opacity 0.9s ease, transform 0.9s ease; }
.reveal.in { opacity: 1; transform: none; }

/* Counter */
.counter { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 0.75rem; }
.counter div { background: rgba(255,255,255,0.75); border-radius: 16px; padding: 14px 4px; box-shadow: var(--shadow); }
.counter b { display: block; font-size: 1.6rem; color: var(--rose-deep); font-variant-numeric: tabular-nums; }
.counter span { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }

/* Letter */
.letter {
  text-align: left; background: var(--paper); border-radius: 18px; padding: 28px 22px;
  box-shadow: var(--shadow); min-height: 220px;
  background-image: repeating-linear-gradient(transparent 0 31px, #f6dfe4 31px 32px);
  background-position: 0 22px;
}
.letter p {
  font-family: "Cormorant Garamond", serif; font-size: 1.2rem; line-height: 32px; margin-bottom: 32px;
}
.letter p.typing::after { content: "|"; color: var(--rose); animation: pulse 0.8s steps(1) infinite; }
.signoff { font-size: 2rem; text-align: right; opacity: 0; transition: opacity 1s; }
.signoff.in { opacity: 1; }

/* Gallery */
.gallery {
  display: flex; gap: 14px; overflow-x: auto; scroll-snap-type: x mandatory;
  margin: 0 -16px; padding: 8px 16px 18px; scrollbar-width: none;
}
.gallery::-webkit-scrollbar { display: none; }
.polaroid {
  flex: 0 0 82%; scroll-snap-align: center;
  background: #fff; padding: 12px 12px 16px; border-radius: 6px; box-shadow: var(--shadow);
  transform: rotate(var(--tilt));
}
.polaroid .ph {
  aspect-ratio: 4 / 5; border-radius: 3px; overflow: hidden;
  background: linear-gradient(135deg, var(--blush), #fde9ee); display: grid; place-items: center; font-size: 3rem;
}
.polaroid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.polaroid figcaption { font-family: "Great Vibes", cursive; font-size: 1.6rem; color: var(--ink); margin-top: 10px; min-height: 2.2rem; }
.dots { display: flex; justify-content: center; gap: 8px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--blush); transition: all 0.3s; }
.dots i.on { background: var(--rose); width: 22px; border-radius: 4px; }
.dots i.heart { background: none; width: auto; height: auto; font-style: normal; font-size: 10px; line-height: 8px; color: var(--blush); }
.dots i.heart::before { content: "♥"; }
.dots i.heart.on { color: var(--rose); font-size: 14px; }

/* Final "ask" slide after the last photo */
.polaroid .ask-body {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px;
  font-size: 1rem; /* .ph sets a large emoji size for placeholders */
  background: radial-gradient(circle at 50% 30%, #fff 0%, #fde9ee 55%, var(--blush) 100%); text-align: center;
}
.ask-ring { font-size: 3rem; animation: bob 2.4s ease-in-out infinite; }
.ask-q { font-size: 2.3rem; line-height: 1.15; }
.ask-btns { display: flex; flex-direction: column; gap: 12px; width: 80%; }
.ask-btns .btn { font-size: 1rem; }
.ask-btns .btn:last-child { background: var(--rose-deep); font-size: 1.15rem; padding: 16px 28px; }
.ask-done { font-size: 2rem; line-height: 1.2; color: var(--rose); animation: pop 0.6s ease; }
.ask.pop { animation: askpop 0.7s ease; }
@keyframes askpop { 50% { transform: rotate(var(--tilt)) scale(1.04); } }
.said-yes .ask-ring { animation: pop 0.6s ease 3, bob 2.4s ease-in-out 1.8s infinite; }

/* Timeline */
.timeline { list-style: none; text-align: left; position: relative; padding-left: 28px; }
.timeline::before { content: ""; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: linear-gradient(var(--blush), var(--rose)); }
.timeline li { position: relative; margin-bottom: 18px; background: rgba(255,255,255,0.8); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.timeline li::before {
  content: "♥"; position: absolute; left: -28px; top: 14px; width: 20px; height: 20px;
  display: grid; place-items: center; font-size: 0.7rem; color: #fff; background: var(--rose); border-radius: 50%;
}
.timeline time { font-size: 0.75rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--rose); font-weight: 700; }
.timeline h3 { font-family: "Cormorant Garamond", serif; font-size: 1.35rem; margin: 2px 0; }
.timeline p { font-size: 0.95rem; color: var(--muted); }

/* Reasons scratch cards */
.reasons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 1rem; }
.reason { aspect-ratio: 1; position: relative; border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); outline: none; }
.reason:focus-visible { box-shadow: 0 0 0 3px var(--rose); }
.reason .back {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 12px; background: var(--paper); font-family: "Cormorant Garamond", serif; font-size: 1.15rem; line-height: 1.3;
}
.reason:not(.ready) .back { visibility: hidden; }
.reason .back em { font-size: 1.8rem; font-style: normal; margin-bottom: 6px; }
.reason.revealed .back em { animation: pop 0.5s ease; }
@keyframes pop { 50% { transform: scale(1.4); } }
/* touch-action: none so her finger scratches instead of scrolling the page */
.foil { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; transition: opacity 0.6s ease; }
.foil.cleared { opacity: 0; pointer-events: none; }

/* Closing */
.closing { text-align: center; padding: 72px 0 24px; }
.closing-line { font-size: 2.4rem; line-height: 1.2; margin-bottom: 1.5rem; }
.btn {
  background: var(--rose); color: #fff; padding: 14px 28px; border-radius: 999px; font-weight: 700;
  box-shadow: 0 8px 20px rgba(232, 106, 135, 0.4); transition: transform 0.15s;
}
.btn:active { transform: scale(0.95); }

/* Music button */
.music-btn {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 40;
  width: 48px; height: 48px; border-radius: 50%; background: #fff; color: var(--rose-deep);
  font-size: 1.4rem; box-shadow: var(--shadow);
}
.music-btn.playing { animation: spin 4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 600px) {
  .polaroid { flex-basis: 70%; }
  .reasons { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
