:root {
  --paper: #FBF8F3;
  --paper-2: #F4EFE7;
  --ink: #0E0E0E;
  --ink-2: #2A2725;
  --muted: #77706A;
  --line: #E6DED3;
  --blush: #F2DCD5;
  --gold: #B8924A;
  --good: #1F7A4D;
  --bad: #B23A3A;
  --radius: 22px;
  --shadow: 0 1px 0 rgba(0,0,0,.04), 0 12px 32px -12px rgba(14,14,14,.18);
  --display: 'Fraunces', Georgia, serif;
  --body: 'DM Sans', system-ui, -apple-system, sans-serif;
  --hand: 'Caveat', 'Bradley Hand', cursive;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  background-image:
    radial-gradient(1200px 600px at 110% -10%, var(--blush) 0%, transparent 55%),
    radial-gradient(900px 500px at -20% 110%, var(--paper-2) 0%, transparent 60%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100dvh;
}

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* drifting little black hearts in the background */
.floaties { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.floaties span {
  position: absolute; bottom: -40px; font-size: 18px; opacity: .14;
  animation: drift linear infinite;
}
@keyframes drift {
  from { transform: translateY(0) rotate(0deg); }
  to   { transform: translateY(-115vh) rotate(40deg); }
}

/* ---------- top progress ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: center;
  padding: max(14px, env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(var(--paper) 60%, transparent);
}
.progress { display: flex; gap: 8px; }
.progress .pip {
  width: 22px; height: 22px; display: grid; place-items: center;
  transition: transform .4s cubic-bezier(.3,1.6,.5,1);
}
.progress .pip svg { width: 100%; height: 100%; }
.progress .pip path { fill: transparent; stroke: var(--ink); stroke-width: 2; transition: fill .4s; }
.progress .pip.done path { fill: var(--ink); }
.progress .pip.now { transform: scale(1.25); }
.progress .pip.now path { animation: beat 1.2s ease-in-out infinite; }

/* ---------- stage card ---------- */
.app {
  position: relative; z-index: 1;
  width: 100%; max-width: 560px; margin: 0 auto;
  padding: 8px 16px calc(40px + env(safe-area-inset-bottom));
  min-height: calc(100dvh - 60px);
  display: flex; flex-direction: column; justify-content: center;
}
.stage { animation: enter .6s cubic-bezier(.2,.8,.2,1) both; }
.stage.leaving { animation: leave .35s ease-in both; }
@keyframes enter { from { opacity: 0; transform: translateY(18px) scale(.98); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes leave { to { opacity: 0; transform: translateY(-14px) scale(.98); filter: blur(4px); } }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px;
}
.card.ink { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.eyebrow {
  font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; margin: 0 0 10px;
}
h1, h2 { font-family: var(--display); font-weight: 500; line-height: 1.08; margin: 0 0 12px; letter-spacing: -.01em; }
h1 { font-size: clamp(40px, 11vw, 62px); }
h2 { font-size: clamp(28px, 7.5vw, 38px); }
h1 em, h2 em { font-style: italic; font-weight: 400; }
p.lead { font-size: 19px; color: var(--ink-2); margin: 0 0 22px; }
.hand { font-family: var(--hand); font-size: 26px; line-height: 1.15; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  font: 600 17px/1 var(--body);
  padding: 17px 26px; border-radius: 999px;
  background: var(--ink); color: var(--paper);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 54px;
  transition: transform .15s ease, box-shadow .2s ease, background .2s;
  box-shadow: 0 8px 20px -8px rgba(14,14,14,.55);
  touch-action: manipulation; user-select: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .4; pointer-events: none; }

.input {
  width: 100%; font: 500 19px var(--body); color: var(--ink);
  padding: 16px 18px; border-radius: 16px;
  border: 1.5px solid var(--line); background: var(--paper);
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--ink); box-shadow: 0 0 0 4px rgba(14,14,14,.08); }
.row { display: flex; gap: 10px; }
.stack { display: grid; gap: 12px; }

.hint { min-height: 26px; margin-top: 14px; font-size: 16px; color: var(--ink-2); }
.shake { animation: shake .45s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
@keyframes beat { 0%,100% { transform: scale(1); } 15% { transform: scale(1.18); } 30% { transform: scale(1); } 45% { transform: scale(1.1); } }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }

/* ---------- intro ---------- */
.intro-heart { font-size: 72px; display: inline-block; animation: beat 1.4s ease-in-out infinite; margin-bottom: 6px; }
.intro .sub { font-family: var(--hand); font-size: 24px; color: var(--muted); margin-top: 18px; }

/* ---------- quiz ---------- */
.qmeta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.dots { display: flex; gap: 6px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--ink); }
.options { display: grid; gap: 10px; margin-top: 18px; }
.opt {
  text-align: left; font: 500 17px var(--body); color: var(--ink);
  padding: 16px 18px; border-radius: 16px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--paper);
  transition: border-color .15s, background .15s, transform .1s;
  touch-action: manipulation;
}
.opt:hover { border-color: var(--ink); }
.opt:active { transform: scale(.99); }
.opt.right { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.opt.wrong { border-color: var(--bad); color: var(--bad); }

/* ---------- hearts game ---------- */
.arena {
  position: relative; height: min(58dvh, 460px); margin: 16px 0 14px;
  border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(#fff, var(--paper-2));
  border: 1px solid var(--line);
  touch-action: none; user-select: none;
}
.arena .h {
  position: absolute; top: 0; left: 0; line-height: 1; cursor: pointer;
  will-change: transform; filter: drop-shadow(0 4px 6px rgba(0,0,0,.15));
}
.arena .plus {
  position: absolute; font: 700 20px var(--body); pointer-events: none;
  animation: rise .7s ease-out forwards;
}
@keyframes rise { to { transform: translateY(-40px); opacity: 0; } }
.arena .overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: rgba(251,248,243,.85); backdrop-filter: blur(3px); padding: 20px;
}
.hud { display: flex; justify-content: space-between; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud .big { font-family: var(--display); font-size: 28px; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--ink); width: 0; transition: width .2s; }

/* ---------- memory ---------- */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 18px 0 12px; perspective: 900px; }
.tile {
  aspect-ratio: 3/4; position: relative; cursor: pointer; border: 0; padding: 0; background: none;
  transform-style: preserve-3d; transition: transform .45s cubic-bezier(.3,1.3,.5,1);
  touch-action: manipulation;
}
.tile.flip, .tile.got { transform: rotateY(180deg); }
.tile .face {
  position: absolute; inset: 0; border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: grid; place-items: center; overflow: hidden;
}
.tile .back { background: var(--ink); color: var(--paper); box-shadow: var(--shadow); }
.tile .back svg, .ring-box svg { width: 40%; fill: none; stroke: var(--paper); stroke-width: 1.6; }
.ring-box svg { width: 52%; fill: var(--paper); stroke: none; }
.tile .back::after { content: ''; position: absolute; inset: 6px; border: 1px solid rgba(251,248,243,.25); border-radius: 10px; }
.tile .front { transform: rotateY(180deg); background: var(--paper-2); font-size: 40px; border: 1px solid var(--line); }
.tile .front img { width: 100%; height: 100%; object-fit: cover; }
.tile.got .front { box-shadow: 0 0 0 3px var(--ink); animation: pop .4s; }

/* ---------- memory lane ---------- */
.lane { display: grid; gap: 34px; margin: 22px 0 26px; }
.polaroid {
  background: #fff; padding: 12px 12px 18px; border-radius: 6px;
  box-shadow: 0 2px 2px rgba(0,0,0,.05), 0 18px 34px -16px rgba(0,0,0,.35);
  position: relative; max-width: 380px; margin: 0 auto; width: 100%;
  opacity: 0; transform: translateY(30px) rotate(var(--r, 0deg));
  transition: opacity .7s ease, transform .7s cubic-bezier(.2,.8,.2,1);
}
.polaroid.seen { opacity: 1; transform: rotate(var(--r, 0deg)); }
.polaroid::before {
  content: ''; position: absolute; top: -12px; left: 50%; width: 92px; height: 26px;
  transform: translateX(-50%) rotate(-3deg);
  background: rgba(14,14,14,.82); border-radius: 2px;
}
.polaroid img, .polaroid video { display: block; width: 100%; border-radius: 2px; background: #111; }
.polaroid img { aspect-ratio: 4/5; object-fit: cover; }
.polaroid video { aspect-ratio: 9/16; max-height: 70dvh; object-fit: cover; }
.polaroid figcaption { font-family: var(--hand); font-size: 26px; text-align: center; margin-top: 10px; line-height: 1.1; }

/* ---------- letter ---------- */
.letter { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 30px 24px; box-shadow: var(--shadow); position: relative; }
.letter::before { content: '🖤'; position: absolute; top: -18px; right: 22px; font-size: 32px; transform: rotate(12deg); }
.letter p { font-family: var(--display); font-style: italic; font-size: 20px; line-height: 1.55; margin: 0 0 14px; min-height: 1em; }
.letter p:first-child { font-style: normal; font-weight: 600; }
.caret::after { content: '▍'; animation: blink 1s steps(1) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- finale ---------- */
.finale { text-align: center; }
.ring-box {
  width: 120px; height: 120px; margin: 0 auto 18px; border-radius: 28px;
  background: var(--ink); display: grid; place-items: center; font-size: 56px;
  box-shadow: 0 20px 40px -18px rgba(0,0,0,.7); animation: beat 1.6s ease-in-out infinite;
}
.answers { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 26px; min-height: 120px; flex-wrap: wrap; }
.btn.yes { font-size: 20px; padding: 20px 36px; transition: transform .3s cubic-bezier(.3,1.6,.5,1); }
.btn.no { transition: left .25s ease, top .25s ease, transform .25s ease, opacity .25s; z-index: 20; }

.done-photo { width: 220px; margin: 0 auto 22px; --r: -3deg; }
.done-photo.polaroid { opacity: 1; transform: rotate(-3deg); }

/* ---------- confetti + toast ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 999px;
  font-weight: 600; font-size: 15px; opacity: 0; transition: all .35s cubic-bezier(.2,.8,.2,1);
  z-index: 40; max-width: calc(100% - 32px); text-align: center; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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