:root {
  --blush: #FFF0F3;
  --blush-2: #FBD9E2;
  --petal: #F9C6D3;
  --rose: #E0457B;
  --rose-deep: #A8174E;
  --wine: #5C1030;
  --gold: #D9A441;
  --gold-soft: #F3D58E;
  --leaf: #5E8C5A;
  --cream: #FFFAF7;

  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --hand: "Caveat", "Segoe Print", cursive;

  --radius-lg: 28px;
  --radius-sm: 14px;
  --shadow: 0 18px 40px -18px rgba(92, 16, 48, .35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.5;
  color: var(--wine);
  background:
    radial-gradient(120% 70% at 50% 0%, var(--cream) 0%, var(--blush) 45%, var(--blush-2) 100%) fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

#petals {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
}

main {
  position: relative; z-index: 1;
  max-width: 460px;
  margin: 0 auto;
  min-height: 100svh;
  padding: max(24px, env(safe-area-inset-top)) 22px max(28px, env(safe-area-inset-bottom));
}

.screen {
  min-height: calc(100svh - 52px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  gap: 14px;
  animation: screen-in .7s ease both;
}
.screen-game { justify-content: flex-start; padding-top: 58px; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Type ─────────────────────────────────────────────── */
.display {
  font-weight: 600;
  font-size: clamp(34px, 9vw, 46px);
  line-height: 1.04;
  letter-spacing: -.01em;
  margin: 0;
  max-width: 13ch;
  text-wrap: balance;
}
.lede { margin: 0; font-size: 20px; max-width: 30ch; opacity: .85; text-wrap: pretty; }
.note, .letter p { font-family: var(--hand); font-size: 25px; line-height: 1.3; font-weight: 500; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  font: 600 20px/1 var(--serif);
  color: var(--cream);
  background: linear-gradient(180deg, var(--rose) 0%, var(--rose-deep) 100%);
  border: 0;
  border-radius: 999px;
  padding: 16px 30px;
  min-height: 52px;
  cursor: pointer;
  box-shadow: 0 10px 22px -10px rgba(168, 23, 78, .7), inset 0 1px 0 rgba(255,255,255,.3);
  transition: transform .15s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:hover { filter: brightness(1.06); }
.btn:focus-visible, select:focus-visible, button:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 3px;
}
.btn-quiet {
  background: transparent; color: var(--rose-deep);
  box-shadow: inset 0 0 0 1.5px var(--rose);
}

/* ── Roses ────────────────────────────────────────────── */
.hero-rose svg { width: 132px; height: 132px; display: block; filter: drop-shadow(0 14px 18px rgba(168,23,78,.28)); }
.hero-rose { animation: sway 6s ease-in-out infinite; }
@keyframes sway { 0%,100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.bloom-in svg { animation: bloom 1.4s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes bloom { from { transform: scale(.2) rotate(-90deg); opacity: 0; } to { transform: none; opacity: 1; } }

.rose-gold { --r-out: #F3D58E; --r-mid: #E2B04F; --r-in: #B07D1E; --r-line: #FFF1C9; }
.rose-white { --r-out: #FFF7F2; --r-mid: #F6DCD8; --r-in: #E5B3B8; --r-line: #fff; }
.rose-blush { --r-out: #FBD3DE; --r-mid: #F49BB6; --r-in: #E0457B; --r-line: #FFE6EE; }
.rose-red { --r-out: #E8506F; --r-mid: #C21F48; --r-in: #7E0E2E; --r-line: #F59AAE; }

/* ── Letter bar ───────────────────────────────────────── */
.letterbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: linear-gradient(180deg, rgba(255,240,243,.96) 60%, rgba(255,240,243,0));
}
.buds {
  list-style: none; margin: 0 auto; padding: 0;
  display: flex; justify-content: center; gap: 6px;
  max-width: 420px;
}
.bud {
  position: relative;
  width: 36px; height: 36px;
  display: grid; place-items: center;
}
.bud svg { position: absolute; inset: 0; width: 100%; height: 100%; transition: transform .6s cubic-bezier(.2,.9,.3,1.3), opacity .4s; }
.bud .bud-empty { transform: scale(.55); opacity: .35; }
.bud .bud-full { transform: scale(0); }
.bud b { position: relative; font: 700 17px/1 var(--serif); color: var(--wine); opacity: 0; transition: opacity .4s .3s; }
.bud.filled .bud-empty { transform: scale(0); }
.bud.filled .bud-full { transform: scale(1); }
.bud.filled b { opacity: 1; }
.bud.just { animation: pop .8s ease; }
@keyframes pop { 40% { transform: scale(1.35); } }

/* ── Gate ─────────────────────────────────────────────── */
.gate-form { display: flex; flex-direction: column; align-items: center; gap: 18px; margin-top: 10px; width: 100%; }
.date-pickers { display: grid; grid-template-columns: 1fr 1.5fr 1.2fr; gap: 10px; width: 100%; }
.date-pickers label { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: 15px; opacity: .9; }
select {
  font: 600 19px var(--serif); color: var(--wine);
  background: rgba(255,255,255,.75);
  border: 1.5px solid var(--petal);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  min-height: 50px;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--rose) 50%), linear-gradient(135deg, var(--rose) 50%, transparent 50%);
  background-position: calc(100% - 16px) 22px, calc(100% - 11px) 22px;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.gate-error { margin: 0; color: var(--rose-deep); font-size: 18px; }
.shake { animation: shake .45s ease; }
@keyframes shake { 20%,60% { transform: translateX(-7px); } 40%,80% { transform: translateX(7px); } }

/* ── Countdown ────────────────────────────────────────── */
.anniversary {
  margin: 0; font-family: var(--hand); font-size: 26px; color: var(--rose-deep);
}
.bouquet {
  position: relative; width: 230px; height: 200px;
}
.bouquet svg { position: absolute; transition: transform 1.2s ease; filter: drop-shadow(0 8px 10px rgba(168,23,78,.2)); }
.clock { display: flex; gap: 10px; justify-content: center; }
.clock div {
  min-width: 70px; padding: 12px 6px 8px;
  background: rgba(255,255,255,.6);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1.5px var(--petal);
}
.clock b { display: block; font-size: 34px; line-height: 1; font-weight: 600; font-variant-numeric: tabular-nums; }
.clock span { font-size: 14px; opacity: .75; }

/* ── Chapter heading ──────────────────────────────────── */
.chapter-head { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.chapter-dates { margin: 0; font-style: italic; font-size: 17px; color: var(--rose-deep); }
.chapter-title { margin: 0; font-size: 34px; line-height: 1.05; font-weight: 600; }
.chapter-goal { margin: 4px 0 6px; font-size: 17px; max-width: 32ch; opacity: .8; }

/* ── Level 1: catch ───────────────────────────────────── */
.catch-stage {
  position: relative; width: 100%;
  height: min(56svh, 500px);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255,255,255,.55), rgba(249,198,211,.45));
  box-shadow: inset 0 0 0 1.5px rgba(224,69,123,.25), var(--shadow);
  overflow: hidden;
  touch-action: none;
}
#catch-canvas { width: 100%; height: 100%; display: block; }
.catch-hud {
  position: absolute; top: 12px; left: 14px;
  font-size: 16px; padding: 4px 12px; border-radius: 999px;
  background: rgba(255,255,255,.75);
}
.catch-hud span { font-weight: 700; }
.btn-overlay { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.btn-overlay:active { transform: translate(-50%, -50%) scale(.97); }

/* ── Level 2: memory ──────────────────────────────────── */
.memory-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px;
  width: 100%; perspective: 900px;
}
.card {
  position: relative; aspect-ratio: 3 / 4;
  border: 0; padding: 0; background: none; cursor: pointer;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.3,.8,.3,1);
}
.card.flipped, .card.matched { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0;
  border-radius: var(--radius-sm);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  overflow: hidden;
  display: grid; place-items: center;
}
.card-back {
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.25) 0 18%, transparent 19%),
    linear-gradient(160deg, var(--rose) 0%, var(--rose-deep) 100%);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.35), 0 8px 16px -10px rgba(92,16,48,.6);
}
.card-back svg { width: 46%; opacity: .5; --r-out: #fff; --r-mid: #FBD3DE; --r-in: #F49BB6; --r-line: #fff; }
.card-front {
  transform: rotateY(180deg);
  background: var(--cream);
  box-shadow: inset 0 0 0 2px var(--petal);
}
.card-front svg { width: 70%; }
.card-front img { width: 100%; height: 100%; object-fit: cover; }
.card.matched .card-front { box-shadow: inset 0 0 0 3px var(--gold); }
.card-letter {
  position: absolute; right: 6px; bottom: 6px;
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; color: var(--wine);
  background: var(--gold-soft);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  animation: pop .7s ease;
}

/* ── Level 3: quiz ────────────────────────────────────── */
.quiz { width: 100%; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.quiz-progress { margin: 0; display: flex; gap: 8px; justify-content: center; }
.quiz-progress svg { width: 34px; height: 34px; transition: transform .6s cubic-bezier(.2,.9,.3,1.3), opacity .4s; }
.quiz-progress .waiting { transform: scale(.55); opacity: .35; }
.quiz-q { margin: 6px 0 4px; font-size: 26px; line-height: 1.15; font-weight: 600; text-wrap: balance; }
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.option {
  font: 500 19px/1.3 var(--serif); color: var(--wine); text-align: left;
  background: rgba(255,255,255,.7);
  border: 1.5px solid var(--petal);
  border-radius: var(--radius-sm);
  padding: 14px 16px; min-height: 54px;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.option:hover { border-color: var(--rose); }
.option.wrong { opacity: .45; }
.option.right { background: var(--gold-soft); border-color: var(--gold); }
.quiz-hint { margin: 0; min-height: 1.5em; font-family: var(--hand); font-size: 23px; color: var(--rose-deep); }
.quiz-bloom { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 20px 0; }
.quiz-bloom .bloom-rose { position: relative; width: 140px; height: 140px; }
.quiz-bloom .bloom-rose svg { width: 100%; height: 100%; animation: bloom 1.2s cubic-bezier(.2,.9,.3,1.2) both; }
.quiz-bloom .bloom-rose b {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 40px; color: var(--wine); animation: screen-in .6s .7s both;
}

/* ── Memory card overlay ──────────────────────────────── */
.memory-card-wrap {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(92,16,48,.35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: screen-in .4s ease both;
}
.memory-card {
  width: min(380px, 100%);
  max-height: calc(100svh - 40px); overflow-y: auto;
  background: var(--cream);
  border-radius: var(--radius-lg);
  padding: 14px 14px 22px;
  text-align: center;
  box-shadow: 0 30px 60px -20px rgba(92,16,48,.6);
  transform: rotate(-1.2deg);
  animation: card-in .6s cubic-bezier(.2,.9,.3,1.2) both;
}
@keyframes card-in { from { transform: translateY(40px) rotate(4deg); opacity: 0; } }
.memory-card img { display: block; max-width: 100%; max-height: 38svh; width: auto; height: auto; margin: 0 auto 12px; border-radius: 18px; }
.memory-card .note { margin: 6px 4px 16px; font-size: 22px; }

/* ── Puzzle ───────────────────────────────────────────── */
.puzzle-slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; row-gap: 12px; margin-top: 8px; }
.word { display: flex; gap: 5px; }
.word + .word { margin-left: 18px; }
.slot {
  width: 40px; height: 50px;
  border: 0; padding: 0;
  border-radius: 10px;
  background: rgba(255,255,255,.55);
  box-shadow: inset 0 -3px 0 var(--petal);
  font: 700 26px var(--serif); color: var(--wine);
  cursor: pointer;
}
.slot.filled { background: var(--gold-soft); box-shadow: inset 0 -3px 0 var(--gold); }
.puzzle-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 320px; margin-top: 10px; min-height: 120px; }
.tile {
  position: relative; width: 54px; height: 54px;
  border: 0; padding: 0; background: none; cursor: pointer;
  animation: float 3.5s ease-in-out infinite;
}
.tile:nth-child(2n) { animation-delay: -1.2s; }
.tile:nth-child(3n) { animation-delay: -2.1s; }
.tile svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.tile b, .drag-ghost b {
  position: relative; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 250, 240, .92); box-shadow: 0 1px 4px rgba(92,16,48,.25);
  font: 700 21px/1 var(--serif); color: var(--wine);
}
.tile, .slot { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tile { display: grid; place-items: center; }
.tile.dragging, .slot.dragging { opacity: .3; }
.slot.over { box-shadow: inset 0 0 0 2.5px var(--rose); background: #fff; }
.drag-ghost {
  position: fixed; z-index: 30; width: 62px; height: 62px; pointer-events: none;
  display: grid; place-items: center;
  transform: translate(-50%, -60%) scale(1.1);
  filter: drop-shadow(0 8px 10px rgba(92,16,48,.35));
}
.drag-ghost svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.tile.used { visibility: hidden; }
@keyframes float { 50% { transform: translateY(-6px) rotate(3deg); } }
.puzzle-hint { margin: 0; min-height: 1.5em; font-family: var(--hand); font-size: 23px; color: var(--rose-deep); }
.puzzle-solved { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.solved-words {
  margin: 0;
  font-size: clamp(54px, 16vw, 76px); line-height: .95; font-weight: 700; font-style: italic;
  color: var(--rose-deep);
}
.solved-words span { display: inline-block; animation: letter-in .7s cubic-bezier(.2,.9,.3,1.3) both; }
@keyframes letter-in { from { transform: translateY(20px) scale(.4); opacity: 0; } }
.solved-line { margin: 0 0 8px; font-family: var(--hand); font-size: 27px; max-width: 24ch; }

/* ── Finale ───────────────────────────────────────────── */
.finale-before { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.finale-teaser { font-size: 26px; font-style: italic; max-width: 22ch; }
.gift {
  position: relative; width: 190px; height: 200px;
  border: 0; background: none; padding: 0; cursor: pointer;
  animation: wobble 2.6s ease-in-out infinite;
}
@keyframes wobble { 0%, 70%, 100% { transform: rotate(0); } 76% { transform: rotate(-4deg); } 84% { transform: rotate(4deg); } 92% { transform: rotate(-2deg); } }
.gift-box {
  position: absolute; left: 12px; right: 12px; bottom: 0; height: 130px;
  border-radius: 10px;
  background:
    linear-gradient(90deg, transparent 43%, var(--gold) 43% 57%, transparent 57%),
    linear-gradient(160deg, var(--rose) 0%, var(--rose-deep) 100%);
  box-shadow: var(--shadow);
}
.gift-lid {
  position: absolute; left: 0; right: 0; top: 50px; height: 34px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 43%, var(--gold) 43% 57%, transparent 57%),
    linear-gradient(180deg, #EC6A95 0%, var(--rose) 100%);
  z-index: 2;
  transition: transform .9s cubic-bezier(.3,1.4,.5,1), opacity .9s;
}
.gift-bow {
  position: absolute; left: 50%; top: -38px; width: 0; height: 0;
}
.gift-bow::before, .gift-bow::after {
  content: ""; position: absolute; top: 0;
  width: 46px; height: 38px;
  border: 9px solid var(--gold); border-radius: 50% 50% 10% 50%;
}
.gift-bow::before { right: 0; transform: rotate(-12deg); }
.gift-bow::after { left: 0; transform: scaleX(-1) rotate(-12deg); }
.gift.open { animation: none; }
.gift.open .gift-lid { transform: translateY(-160px) rotate(-25deg); opacity: 0; }
.tap-note { margin: 0; font-family: var(--hand); font-size: 24px; opacity: .8; }

.burst { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
.burst svg {
  position: absolute; left: 50%; top: 50%;
  width: 40px; height: 40px; margin: -20px 0 0 -20px;
  animation: fly 1.8s cubic-bezier(.15,.7,.3,1) forwards;
}
@keyframes fly {
  0% { transform: translate(0,0) scale(.2) rotate(0); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) scale(var(--s)) rotate(var(--r)); opacity: 0; }
}

.finale-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-position: center; background-size: cover;
  opacity: 0; transition: opacity 1.6s ease;
}
.finale-bg::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(255,240,243,.62) 0%, rgba(251,217,226,.5) 45%, rgba(255,240,243,.8) 100%);
}
.finale-bg.show { opacity: 1; }
#screen-finale .finale-teaser, #screen-finale .tap-note, .finale-title, .finale-sub {
  text-shadow: 0 0 14px var(--blush), 0 0 6px var(--blush), 0 0 2px var(--blush);
  background: radial-gradient(closest-side, rgba(255,240,243,.92) 60%, rgba(255,240,243,0));
  padding: 14px 34px;
}
.finale-after { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px 0 30px; animation: screen-in 1s ease both; }
.portrait { position: relative; width: 230px; height: 290px; margin-bottom: 10px; }
.portrait img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 50% / 45%;
  box-shadow: 0 0 0 6px var(--cream), 0 0 0 8px var(--gold), var(--shadow);
  animation: bloom 1.4s cubic-bezier(.2,.9,.3,1.1) both;
}
.portrait-roses svg { position: absolute; width: 58px; height: 58px; animation: bloom 1s cubic-bezier(.2,.9,.3,1.3) both; }
.finale-title { max-width: 17ch; }
.finale-sub { margin: 0; font-size: 24px; font-style: italic; color: var(--rose-deep); }
.letter {
  margin-top: 14px;
  background: rgba(255, 250, 247, .88);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  border-radius: var(--radius-lg);
  padding: 22px 22px 24px;
  text-align: left;
  box-shadow: var(--shadow);
  transform: rotate(.8deg);
}
.letter p { margin: 0 0 14px; }
.letter .sig { text-align: right; margin: 6px 0 0; color: var(--rose-deep); font-weight: 700; }

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