/* =========================================================================
   DESIGN TOKENS
   Palette  : cream paper #FFF8F1 · wine #6B2737 · dusty rose #D8A7B1
              muted gold #C9A66B · ink #3A2323 · blush #F6D9DE
   Type     : Cormorant Garamond (display/serif) + Quicksand (body/UI)
              Caveat (handwritten accents — dates, signature)
   Concept  : a physical scrapbook / diary being paged through. Paper grain,
              torn edges, tape, polaroids, handwritten notes.
   ========================================================================= */

:root {
  --cream: #FFF8F1;
  --paper: #FFFCF8;
  --wine: #6B2737;
  --wine-deep: #4A1B27;
  --rose: #D8A7B1;
  --blush: #F6D9DE;
  --gold: #C9A66B;
  --ink: #3A2323;
  --ink-soft: #6b5555;
  --shadow: rgba(74, 27, 39, 0.18);

  --font-display: 'Cormorant Garamond', serif;
  --font-body: 'Quicksand', sans-serif;
  --font-hand: 'Caveat', cursive;

  --ease-soft: cubic-bezier(.22,.9,.32,1);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--ink);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

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

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

/* ---- floating ambient hearts ---------------------------------------- */
.floating-hearts {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}
.floating-hearts span {
  position: absolute;
  bottom: -10%;
  font-size: 14px;
  color: var(--rose);
  opacity: 0.5;
  animation: floatUp linear forwards;
}
@keyframes floatUp {
  to { transform: translateY(-115vh) translateX(var(--drift, 20px)) rotate(30deg); opacity: 0; }
}

/* ---- music toggle ----------------------------------------------------- */
.music-toggle {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--rose);
  background: var(--paper);
  color: var(--wine);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px var(--shadow);
  cursor: pointer;
}
.music-toggle.playing .music-icon { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%,100%{ transform: scale(1);} 50%{ transform: scale(1.25);} }

/* =========================================================================
   PHASES / SECTIONS
   ========================================================================= */
.phase {
  display: none;
  min-height: 100svh;
  position: relative;
  padding: 64px 20px 80px;
}
.phase.active { display: block; animation: phaseIn .6s var(--ease-soft); }
@keyframes phaseIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.section-inner {
  max-width: 880px;
  margin: 0 auto;
  text-align: center;
}
.section-inner.narrow { max-width: 560px; }
.section-inner.center-flex {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70svh;
}

.eyebrow {
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--wine);
  margin: 0 0 4px;
}
.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(32px, 8vw, 52px);
  margin: 0 0 8px;
  color: var(--wine-deep);
  letter-spacing: 0.3px;
}
.section-sub {
  font-size: 15px;
  color: var(--ink-soft);
  margin: 0 0 40px;
}

/* scroll reveal */
.reveal-up {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity .8s var(--ease-soft), transform .8s var(--ease-soft);
}
.reveal-up.is-visible { opacity: 1; transform: translateY(0); }

/* buttons -------------------------------------------------------------- */
.btn-primary {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  color: var(--paper);
  background: var(--wine);
  border: none;
  padding: 15px 34px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 24px -8px var(--shadow);
  transition: transform .25s var(--ease-soft), box-shadow .25s var(--ease-soft);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn-primary:active { transform: scale(0.96); }
.btn-primary .arrow { transition: transform .3s var(--ease-soft); }
.btn-primary:hover .arrow { transform: translateX(4px); }

.btn-restart {
  margin-top: 56px;
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--wine);
  background: transparent;
  border: 1.5px dashed var(--rose);
  padding: 12px 28px;
  border-radius: 999px;
  cursor: pointer;
}
.btn-restart:active { transform: scale(0.96); }

/* =========================================================================
   PHASE 1 — GIFT
   ========================================================================= */
#phase-gift {
  align-items: center;
  justify-content: center;
  min-height: 100svh;
  background:
    radial-gradient(ellipse at 50% 20%, var(--blush) 0%, transparent 55%),
    linear-gradient(180deg, var(--cream) 0%, #FBEFE6 100%);
  overflow: hidden;
}
#phase-gift.active { display: flex; }
.gift-scene {
  text-align: center;
  padding: 0 24px;
  position: relative;
  z-index: 2;
}
.gift-title {
  font-family: var(--font-display);
  font-size: clamp(28px, 8vw, 44px);
  color: var(--wine-deep);
  margin: 4px 0 6px;
  font-weight: 600;
}
.gift-title span { color: var(--wine); font-style: italic; }
.gift-sub { font-size: 14px; color: var(--ink-soft); margin: 0 0 36px; }
#tapCount { font-weight: 700; color: var(--wine); }

.gift-wrap {
  position: relative;
  width: 190px;
  height: 190px;
  margin: 0 auto;
  cursor: pointer;
  perspective: 800px;
}
.gift-glow {
  position: absolute;
  inset: -30px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201,166,107,0.35) 0%, transparent 70%);
  z-index: 0;
  opacity: 0;
  transition: opacity .3s;
}
.gift-wrap.pulsing .gift-glow { opacity: 1; animation: glowPulse .6s var(--ease-soft); }
@keyframes glowPulse { 0%{ transform: scale(0.8);} 60%{ transform: scale(1.15);} 100%{ transform: scale(1);} }

.gift-box {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 1;
  transform-style: preserve-3d;
  transition: transform .35s var(--ease-soft);
}
.gift-wrap.shake .gift-box { animation: shakeBox .38s ease; }
@keyframes shakeBox {
  0%,100% { transform: rotate(0deg) scale(1); }
  20% { transform: rotate(-6deg) scale(1.03); }
  40% { transform: rotate(5deg) scale(1.05); }
  60% { transform: rotate(-4deg) scale(1.03); }
  80% { transform: rotate(3deg) scale(1.01); }
}
.gift-base {
  position: absolute;
  left: 15px; right: 15px; bottom: 0;
  height: 62%;
  background: linear-gradient(135deg, var(--wine) 0%, #8a3a4c 100%);
  border-radius: 6px 6px 10px 10px;
  box-shadow: 0 22px 40px -14px var(--shadow);
}
.gift-lid {
  position: absolute;
  left: 4px; right: 4px;
  top: 30%;
  height: 22%;
  background: linear-gradient(135deg, #7c3244 0%, var(--wine) 100%);
  border-radius: 8px;
  box-shadow: 0 8px 16px -6px rgba(74,27,39,0.35);
  transition: transform .55s var(--ease-soft), opacity .5s;
  transform-origin: 50% 100%;
}
.gift-ribbon-v {
  position: absolute;
  left: 50%; top: 0; bottom: 0;
  width: 22px;
  margin-left: -11px;
  background: linear-gradient(90deg, var(--gold), #e6c98a, var(--gold));
  z-index: 2;
}
.gift-ribbon-h {
  position: absolute;
  top: 34%; left: 4px; right: 4px;
  height: 20px;
  background: linear-gradient(180deg, var(--gold), #e6c98a, var(--gold));
  z-index: 2;
}
.gift-bow {
  position: absolute;
  top: 20%; left: 50%;
  width: 56px; height: 34px;
  margin-left: -28px;
  z-index: 3;
}
.gift-bow::before, .gift-bow::after {
  content: "";
  position: absolute;
  width: 28px; height: 28px;
  background: var(--gold);
  border-radius: 50% 50% 50% 4px;
  top: 0;
}
.gift-bow::before { left: 0; transform: rotate(-15deg); }
.gift-bow::after { right: 0; transform: rotate(15deg) scaleX(-1); border-radius: 50% 50% 50% 4px; }

.tap-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 34px;
}
.tap-dots span {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: rgba(107,39,55,0.2);
  transition: background .3s, transform .3s;
}
.tap-dots span.filled { background: var(--wine); transform: scale(1.25); }

/* gift open transition */
.gift-wrap.opening .gift-lid {
  transform: translateY(-140px) rotate(-35deg);
  opacity: 0;
}
.gift-wrap.opening .gift-box {
  transform: scale(1.08);
}
.unwrap-flash {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 55%, #fff 0%, var(--blush) 40%, transparent 75%);
  opacity: 0;
  pointer-events: none;
  z-index: 500;
}
.unwrap-flash.flash { animation: flashOut 1s var(--ease-soft) forwards; }
@keyframes flashOut { 0%{ opacity:0;} 35%{ opacity:1;} 100%{ opacity:0;} }

#phase-gift.leaving { animation: giftLeave .5s var(--ease-soft) forwards; }
@keyframes giftLeave {
  to { opacity: 0; }
}

/* =========================================================================
   PHASE 2 — TIMELINE
   ========================================================================= */
.timeline { position: relative; padding: 20px 0 10px; }
.timeline-line {
  position: absolute;
  left: 50%;
  top: 0; bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: repeating-linear-gradient(180deg, var(--rose) 0 8px, transparent 8px 16px);
}
.tl-item {
  position: relative;
  width: 50%;
  padding: 0 34px 46px;
}
.tl-item[data-side="left"] { left: 0; text-align: right; }
.tl-item[data-side="right"] { left: 50%; text-align: left; }
.tl-dot {
  position: absolute;
  top: 4px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid var(--cream);
  box-shadow: 0 0 0 2px var(--rose);
}
.tl-item[data-side="left"] .tl-dot { right: -8px; }
.tl-item[data-side="right"] .tl-dot { left: -8px; }
.tl-dot-live { background: var(--wine); animation: livePulse 1.6s ease-in-out infinite; }
@keyframes livePulse {
  0%,100% { box-shadow: 0 0 0 2px var(--rose); }
  50% { box-shadow: 0 0 0 7px rgba(216,167,177,0.35); }
}
.tl-card {
  display: inline-block;
  background: var(--paper);
  border: 1px solid rgba(107,39,55,0.08);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: 0 12px 28px -16px var(--shadow);
  max-width: 320px;
  text-align: left;
}
.tl-date {
  font-family: var(--font-hand);
  color: var(--wine);
  font-size: 18px;
}
.tl-card h3 {
  font-family: var(--font-display);
  font-size: 21px;
  margin: 2px 0 6px;
  color: var(--wine-deep);
}
.tl-card p { margin: 0; font-size: 13.5px; color: var(--ink-soft); line-height: 1.55; }
.tl-card-live { border-color: var(--gold); }
#dayCounter { font-family: var(--font-hand); font-size: 20px; color: var(--wine); }

@media (max-width: 640px) {
  .timeline-line { left: 18px; }
  .tl-item, .tl-item[data-side="right"] { width: 100%; left: 0; text-align: left; padding: 0 0 40px 46px; }
  .tl-item[data-side="left"] { text-align: left; }
  .tl-item[data-side="left"] .tl-dot, .tl-item[data-side="right"] .tl-dot { left: 12px; }
  .tl-card { max-width: 100%; }
}

/* =========================================================================
   PHASE 3 — FLIP CARDS
   ========================================================================= */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 44px;
}
@media (min-width: 640px) { .cards-grid { grid-template-columns: repeat(3, 1fr); gap: 20px; } }

.flip-card {
  perspective: 1000px;
  aspect-ratio: 3/4;
  cursor: pointer;
}
.flip-inner {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .65s var(--ease-soft);
}
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  text-align: center;
}
.flip-front {
  background: linear-gradient(150deg, var(--wine) 0%, #8a3a4c 100%);
  box-shadow: 0 14px 26px -14px var(--shadow);
  flex-direction: column;
  gap: 6px;
}
.flip-front .num {
  font-family: var(--font-display);
  font-size: 34px;
  color: var(--gold);
  font-weight: 600;
}
.flip-front .heart { color: rgba(255,255,255,0.7); font-size: 18px; }
.flip-back {
  background: var(--paper);
  border: 1px solid var(--rose);
  transform: rotateY(180deg);
  font-family: var(--font-hand);
  font-size: 17px;
  line-height: 1.4;
  color: var(--ink);
  overflow-y: auto;
}

/* =========================================================================
   PHASE 4 — QUIZ
   ========================================================================= */
.quiz-q {
  background: var(--paper);
  border-radius: 18px;
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: 0 10px 24px -16px var(--shadow);
  text-align: left;
  opacity: 0;
  transform: translateY(16px);
  animation: qIn .5s var(--ease-soft) forwards;
}
@keyframes qIn { to { opacity: 1; transform: translateY(0); } }
.quiz-q h4 {
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--wine-deep);
  margin: 0 0 14px;
}
.quiz-opt {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--cream);
  border: 1.5px solid transparent;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 9px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: all .2s var(--ease-soft);
}
.quiz-opt:active { transform: scale(0.98); }
.quiz-opt.selected { border-color: var(--wine); background: var(--blush); }
.quiz-opt.correct { border-color: #6b9a5a; background: #e4f0de; }
.quiz-opt.wrong { border-color: #b1584f; background: #f6e2df; }
.quiz-opt[disabled] { cursor: default; }

.quiz-result { text-align: center; padding-top: 8px; }
.quiz-score-ring {
  width: 120px; height: 120px;
  border-radius: 50%;
  border: 6px solid var(--rose);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--wine-deep);
  background: var(--paper);
}
#quizResultText { color: var(--ink-soft); font-size: 14px; margin-bottom: 26px; }

/* =========================================================================
   PHASE 5 — SURPRISE
   ========================================================================= */
.btn-surprise {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 22px;
  color: var(--paper);
  background: linear-gradient(135deg, var(--wine), var(--wine-deep));
  border: none;
  padding: 22px 48px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 16px 32px -14px var(--shadow);
  animation: breathe 2.2s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { transform: scale(1);} 50% { transform: scale(1.045);} }
.btn-surprise:active { transform: scale(0.94); }
.surprise-reveal { margin-top: 34px; animation: qIn .7s var(--ease-soft); }
.surprise-text {
  font-family: var(--font-hand);
  font-size: 26px;
  color: var(--wine);
  max-width: 420px;
  margin: 0 0 26px;
}

/* =========================================================================
   PHASE 6 — GALLERY (polaroid grid, holds 20)
   ========================================================================= */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px 14px;
  margin-bottom: 20px;
}
@media (min-width: 560px) { .gallery-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 860px) { .gallery-grid { grid-template-columns: repeat(4, 1fr); } }

.polaroid {
  background: #fff;
  padding: 8px 8px 26px;
  border-radius: 3px;
  box-shadow: 0 10px 22px -12px var(--shadow);
  cursor: pointer;
  transform: rotate(var(--rot, 0deg));
  transition: transform .3s var(--ease-soft), box-shadow .3s;
  opacity: 0;
  transform-origin: center;
}
.polaroid.is-visible { animation: polaroidIn .6s var(--ease-soft) forwards; }
@keyframes polaroidIn {
  from { opacity: 0; transform: translateY(20px) rotate(var(--rot,0deg)) scale(0.92); }
  to { opacity: 1; transform: translateY(0) rotate(var(--rot,0deg)) scale(1); }
}
.polaroid:active { transform: rotate(var(--rot,0deg)) scale(0.96); }
.polaroid-photo {
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: 1px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--blush), var(--rose));
  display: flex;
  align-items: center;
  justify-content: center;
}
.polaroid-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.polaroid-photo .ph-fallback { font-family: var(--font-hand); font-size: 15px; color: var(--wine); opacity: .6; }
.polaroid-tape {
  position: absolute;
  top: -10px; left: 50%;
  width: 46px; height: 18px;
  margin-left: -23px;
  background: rgba(201,166,107,0.55);
  transform: rotate(-3deg);
}
.polaroid-cap {
  display: block;
  text-align: center;
  font-family: var(--font-hand);
  font-size: 15px;
  color: var(--ink-soft);
  margin-top: 6px;
}

/* lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(58,35,35,0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 30px;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: 85vh; border-radius: 6px; }
.lightbox-close {
  position: absolute;
  top: 20px; right: 20px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

/* =========================================================================
   PHASE 7 — LETTER
   ========================================================================= */
.letter-section { margin-top: 90px; }
.envelope-wrap {
  display: flex;
  justify-content: center;
  perspective: 1200px;
  margin-bottom: 30px;
}
.envelope {
  position: relative;
  width: min(320px, 82vw);
  cursor: pointer;
}
.envelope-back {
  position: relative;
  height: 210px;
  background: linear-gradient(135deg, var(--rose), var(--blush));
  border-radius: 8px;
  box-shadow: 0 18px 36px -18px var(--shadow);
  transition: opacity .5s;
}
.envelope-back::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 49.4%, rgba(107,39,55,0.18) 50%, transparent 50.6%),
    linear-gradient(-135deg, transparent 49.4%, rgba(107,39,55,0.18) 50%, transparent 50.6%);
  border-radius: 8px;
}
.envelope-back::after {
  content: "✉";
  position: absolute;
  bottom: 14px; right: 16px;
  color: var(--wine);
  font-size: 20px;
  opacity: 0.55;
}
/* letter sits in normal flow right below the envelope, so opening it
   pushes content DOWN instead of growing upward over things above it.
   Height is set to the exact content height via JS so the transition
   reads as a smooth continuous unroll, not a snap. */
.letter-paper {
  position: relative;
  width: 88%;
  margin: 0 auto;
  height: 0;
  background: var(--paper);
  border: 1px solid rgba(107,39,55,0.1);
  border-top: none;
  border-radius: 0 0 6px 6px;
  overflow: hidden;
  text-align: left;
  transition: height 1s var(--ease-soft), margin-top .7s var(--ease-soft), box-shadow .6s var(--ease-soft) .1s;
  z-index: 2;
}
.envelope.open .letter-paper {
  margin-top: -18px;
  box-shadow: 0 26px 50px -22px var(--shadow);
}
/* rolling edge — anchored to the paper's bottom, so it visibly travels
   downward as the height animates, like a curl unrolling */
.letter-paper::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 16px;
  background: linear-gradient(180deg, transparent, rgba(107,39,55,0.14));
  box-shadow: 0 8px 14px -6px rgba(107,39,55,0.35);
  opacity: 0;
  pointer-events: none;
}
.envelope.open .letter-paper::after { opacity: 1; }
.letter-paper.settled::after { opacity: 0; transition: opacity .4s var(--ease-soft); }

.letter-content {
  padding: 26px 22px 30px;
  opacity: 0;
  transform: translateY(-14px);
  transition: opacity .7s var(--ease-soft) .25s, transform .7s var(--ease-soft) .25s;
}
.envelope.open .letter-content { opacity: 1; transform: translateY(0); }
.envelope.open { cursor: default; }
.envelope.open .envelope-back { opacity: 0.35; }

.letter-greeting {
  font-family: var(--font-hand);
  font-size: 24px;
  color: var(--wine);
  margin: 0 0 14px;
}
.letter-paper p {
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  margin: 0 0 14px;
}
.letter-closing {
  font-family: var(--font-hand) !important;
  font-size: 22px !important;
  color: var(--wine) !important;
  margin-top: 20px !important;
}

/* =========================================================================
   RESPONSIVE / LOW-END DEVICE SAFETY
   ========================================================================= */
@media (max-width: 380px) {
  .section-title { font-size: 30px; }
  .gift-wrap { width: 160px; height: 160px; }
}
