:root {
  --night: #14060c;
  --wine: #3a0a1a;
  --rose: #c41c3b;
  --rose-2: #e8435f;
  --blush: #f7c6d0;
  --cream: #fff6ef;
  --gold: #e8c27a;
  --gold-2: #f6dfa8;
  --ink: #2c1a1f;
  --serif: "Fraunces", Georgia, serif;
  --hand: "Caveat", "Bradley Hand", cursive;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--night);
  color: var(--cream);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }

#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; z-index: 0; touch-action: none; }
#dim {
  position: fixed; inset: 0; z-index: 1; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at 50% 40%, rgba(58,10,26,.35), rgba(20,6,12,.85) 70%);
}
#flash {
  position: fixed; inset: 0; z-index: 50; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 50%, #fff 0%, #ffd7df 35%, #e8435f 100%);
}

.scene {
  position: fixed; inset: 0; z-index: 5;
  display: none;
  align-items: center; justify-content: center;
  padding: 24px 16px;
}
.scene.is-active { display: flex; }

/* Buttons – paper-like, no glow */
.btn {
  position: relative;
  cursor: pointer;
  padding: 16px 30px;
  border-radius: 12px;
  border: 1px solid #d9bf8f;
  font-family: var(--serif); font-weight: 600; font-size: 19px; letter-spacing: .1px; white-space: nowrap;
  color: var(--wine);
  background: #f7ede1;
  box-shadow: 0 3px 0 #b8996a, 0 10px 24px rgba(0,0,0,.28);
  transition: transform .15s ease, box-shadow .15s ease, background .2s;
}
.btn:hover { transform: translateY(-1px); background: #fff6ec; box-shadow: 0 4px 0 #b8996a, 0 14px 28px rgba(0,0,0,.3); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b8996a, 0 6px 14px rgba(0,0,0,.25); }
.btn:disabled { opacity: .6; cursor: progress; transform: none; }
.btn-ghost {
  color: var(--cream);
  background: transparent;
  border: 1px solid rgba(246,223,168,.55);
  box-shadow: none;
}
.btn-ghost:hover { background: rgba(255,246,239,.08); box-shadow: none; }
.btn-danger { background: #b3122f; color: #fff6ef; border-color: #ff6b82; box-shadow: 0 3px 0 #5e0616, 0 10px 30px rgba(179,18,47,.45); }
.btn-danger:hover { background: #c8173a; box-shadow: 0 4px 0 #5e0616, 0 14px 34px rgba(179,18,47,.55); }
.icon-btn {
  position: fixed; top: max(14px, env(safe-area-inset-top)); right: 14px; z-index: 60;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid rgba(246,223,168,.35); background: rgba(20,6,12,.45);
  backdrop-filter: blur(8px); cursor: pointer; font-size: 18px;
}
.hint { font-size: 15px; opacity: .7; margin: 14px 0 0; letter-spacing: .2px; }

/* Intro */
#intro { align-items: flex-end; padding-bottom: max(7vh, 32px); pointer-events: none; }
.intro-text { text-align: center; width: min(960px, 100%); pointer-events: auto; position: relative; }
.intro-text::before {
  content: ""; position: absolute; inset: -40px -80px -30px; z-index: -1; pointer-events: none;
  background: radial-gradient(closest-side, rgba(20,6,12,.75), rgba(20,6,12,0));
}
.sub { text-shadow: 0 1px 12px rgba(20,6,12,.9); }
.kicker {
  font-family: var(--hand); font-size: clamp(30px, 6vw, 44px); color: var(--gold-2);
  margin: 0; line-height: 1;
}
#intro .kicker {
  font-family: var(--serif); font-style: normal; font-weight: 500;
  font-size: clamp(15px, 2.4vw, 19px); letter-spacing: .32em; text-transform: uppercase;
  font-variation-settings: "opsz" 14;
}
.headline {
  font-family: var(--serif); font-style: italic; font-weight: 600;
  font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1;
  font-size: clamp(46px, 8.2vw, 92px); line-height: .98; margin: 12px 0 18px; letter-spacing: -.01em;
  color: #fbe9e4;
  text-shadow: 0 2px 0 rgba(120,10,35,.55), 0 10px 40px rgba(20,6,12,.9);
}
.word { display: inline-block; white-space: nowrap; }
.headline .ch, .kicker .ch { display: inline-block; will-change: transform, opacity; }
.sub { font-weight: 400; font-size: clamp(17px, 2.5vw, 21px); line-height: 1.55; opacity: .92; margin: 0 auto 28px; max-width: 32em; }

/* Journey */
#journey { pointer-events: none; }
#yearHud {
  position: fixed; left: max(18px, 3vw); bottom: max(18px, 4vh);
  font-family: var(--serif); font-style: italic; font-size: clamp(44px, 8vw, 96px);
  line-height: 1; color: transparent;
  -webkit-text-stroke: 1px rgba(246,223,168,.7);
  text-shadow: 0 0 30px rgba(232,194,122,.25);
}
.journey-hint {
  position: fixed; top: max(20px, 4vh); left: 50%; transform: translateX(-50%);
  font-size: 15px; letter-spacing: .3px; opacity: .75; white-space: nowrap;
  padding: 8px 14px; border-radius: 999px; background: rgba(20,6,12,.4); backdrop-filter: blur(6px);
}
.progress { position: fixed; right: max(18px, 3vw); bottom: max(28px, 5vh); width: min(28vw, 180px); height: 3px; border-radius: 3px; background: rgba(255,255,255,.12); overflow: hidden; }
#progressBar { width: 0%; height: 100%; background: linear-gradient(90deg, var(--gold), var(--rose-2)); }
.btn-float { position: fixed; left: 50%; bottom: max(28px, 7vh); transform: translateX(-50%); pointer-events: auto; opacity: 0; visibility: hidden; }
.btn-float:hover { transform: translateX(-50%) translateY(-2px) scale(1.02); }

/* Cake */
#cake { overflow: hidden; }
.cake-wrap { position: relative; z-index: 2; text-align: center; width: min(520px, 100%); }
.cake-title { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: clamp(32px, 6.4vw, 52px); margin: 0 0 6px; line-height: 1.08; }
.cake-title span { font-family: var(--hand); font-style: normal; color: var(--gold-2); font-size: .85em; }
#cakeSvg { width: min(480px, 92vw, 62vh); height: auto; display: block; margin: 0 auto; overflow: visible; filter: drop-shadow(0 30px 40px rgba(0,0,0,.45)); }
.candle { cursor: pointer; }
.flame { transform-box: fill-box; transform-origin: 50% 100%; animation: flicker .18s ease-in-out infinite alternate; }
.flame-glow { animation: glow 1.4s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes flicker { from { transform: scale(1, 1) skewX(-2deg); } to { transform: scale(.92, 1.08) skewX(3deg); } }
@keyframes glow { from { opacity: .7; transform: scale(.95); } to { opacity: 1; transform: scale(1.08); } }
.candle.out .flame, .candle.out .flame-glow { animation: none; }
.smoke { fill: #ddd; opacity: 0; }
.cake-actions { margin-top: 6px; }
.bday-shout {
  font-family: var(--serif); font-style: italic; font-weight: 700;
  font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1;
  font-size: clamp(38px, 8vw, 72px); line-height: 1.02; margin: 8px 0 18px; min-height: 0;
  color: var(--gold-2);
  text-shadow: 0 2px 0 rgba(120,70,10,.6), 0 10px 34px rgba(20,6,12,.85);
}
.bday-shout .ch { display: inline-block; }
#toLetterBtn { opacity: 0; visibility: hidden; }
.party-hat {
  display: inline-block; width: .9em; height: 1.1em; vertical-align: top;
  margin: -0.62em -0.62em 0 -0.12em; position: relative; z-index: 2;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.35));
}
.party-hat svg { width: 100%; height: 100%; display: block; }
#balloons { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.balloon { position: absolute; bottom: -180px; width: 70px; }

/* Letter */
#letter { overflow-y: auto; align-items: center; }
.envelope-wrap { text-align: center; padding-top: 120px; }
.envelope { transform-style: preserve-3d; }
.envelope {
  position: relative; display: block; width: min(340px, 82vw); aspect-ratio: 3 / 2;
  border: 0; padding: 0; background: none; cursor: pointer; perspective: 900px;
}
.envelope > span { position: absolute; inset: 0; display: block; }
.env-back { z-index: 1; background: linear-gradient(160deg, #e9aab8, #c96a82); border-radius: 10px; box-shadow: 0 30px 60px rgba(0,0,0,.45); }
.env-paper {
  inset: 8px 14px auto 14px !important; height: 88%; z-index: 2;
  background: var(--cream); border-radius: 6px; box-shadow: 0 -2px 8px rgba(0,0,0,.08);
  display: flex !important; align-items: flex-start; justify-content: center; padding-top: 18%;
  font-family: var(--hand); font-size: 30px; color: var(--rose);
}
.env-front {
  background:
    linear-gradient(to top right, #f2bfcb 49.6%, transparent 50%) left / 50.5% 100% no-repeat,
    linear-gradient(to top left, #f2bfcb 49.6%, transparent 50%) right / 50.5% 100% no-repeat;
  border-radius: 0 0 10px 10px; z-index: 3; pointer-events: none;
}
.env-front::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 58%;
  background: linear-gradient(180deg, #f5c9d3, #eab0be);
  clip-path: polygon(0 100%, 50% 0, 100% 100%); border-radius: 0 0 10px 10px;
}
.env-flap {
  height: 62%; bottom: auto !important;
  background: linear-gradient(180deg, #dd8ea2, #e9a7b6);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: 50% 0; z-index: 4; backface-visibility: visible;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.15));
}
.env-seal {
  inset: auto !important; left: 50% !important; top: 52% !important; transform: translate(-50%, -50%);
  width: 56px; height: 56px; border-radius: 50%; z-index: 5;
  display: grid !important; place-items: center; font-size: 26px;
  background: radial-gradient(circle at 35% 30%, #e8435f, #8e0f28);
  box-shadow: 0 4px 12px rgba(0,0,0,.35), inset 0 -3px 6px rgba(0,0,0,.25);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: translate(-50%, -50%) scale(1.08); } }

.letter-card {
  display: none;
  position: relative; width: min(680px, 100%); margin: auto;
  max-height: calc(100vh - 48px); overflow-y: auto;
  padding: clamp(24px, 5vw, 48px);
  border-radius: 22px;
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 0% 0%, rgba(247,198,208,.35), transparent),
    linear-gradient(180deg, #fffaf4, #fbefe6);
  box-shadow: 0 40px 100px rgba(0,0,0,.55), inset 0 0 0 1px rgba(232,194,122,.35);
}
.letter-card h2 { font-family: var(--hand); font-weight: 700; font-size: clamp(38px, 7vw, 52px); color: var(--rose); margin: 0 0 10px; }
.letter-card p { font-family: var(--serif); font-size: clamp(18px, 2.6vw, 21px); line-height: 1.65; margin: 0 0 16px; font-variation-settings: "opsz" 18; }
.letter-card .sig { font-family: var(--hand); font-size: 32px; line-height: 1.2; margin-top: 20px; }
.letter-card .sig span { font-size: 46px; color: var(--rose); }
.gift { margin-top: 26px; padding-top: 22px; border-top: 1px dashed rgba(196,28,59,.35); text-align: center; }
.gift .gift-intro { font-family: var(--serif); font-style: italic; font-size: 20px; line-height: 1.5; margin-bottom: 18px; }
#toGiftBtn { opacity: 0; visibility: hidden; }
#toHeartBtn { display: block; margin: 22px auto 0; opacity: 0; visibility: hidden; }

/* Gift quiz */
#quiz { flex-direction: column; overflow-y: auto; justify-content: safe center; }
#letter { justify-content: safe center; }
#alarm {
  position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 0;
  background: radial-gradient(ellipse at center, rgba(255,40,60,.15), rgba(200,0,30,.75));
}
body.alarm-mode #dim { background: radial-gradient(ellipse at 50% 40%, rgba(60,0,10,.6), rgba(10,0,3,.95) 70%); opacity: 1; }
body.alarm-mode #alarm { animation: alarmPulse 1.3s ease-in-out infinite; }
@keyframes alarmPulse { 0%, 100% { opacity: .15; } 50% { opacity: .5; } }
.quiz-rules, .quiz-card, .quiz-result { display: none; position: relative; z-index: 2; width: min(640px, 100%); }
.quiz-rules {
  padding: clamp(24px, 5vw, 40px); border-radius: 18px;
  background: #160307; border: 2px solid #ff3b55;
  box-shadow: 0 0 0 6px rgba(255,59,85,.12), 0 30px 80px rgba(0,0,0,.7);
}
.rules-warn {
  margin: 0; font-weight: 700; font-size: clamp(15px, 2.6vw, 18px); letter-spacing: .25em; text-transform: uppercase; color: #ff5a70;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
.rules-title { font-family: var(--serif); font-weight: 700; font-size: clamp(30px, 6.4vw, 50px); line-height: 1.05; margin: 10px 0 12px; color: #fff; }
.rules-lead { font-size: clamp(17px, 2.5vw, 20px); line-height: 1.5; margin: 0 0 18px; opacity: .9; }
.rules-list { list-style: none; padding: 0; margin: 0 0 24px; display: grid; gap: 10px; }
.rules-list li {
  font-size: clamp(17px, 2.5vw, 20px); line-height: 1.45; padding: 12px 16px; border-radius: 10px;
  background: rgba(255,255,255,.05); border-left: 4px solid rgba(255,255,255,.3);
}
.rules-list li.win { border-left-color: #3ecf7a; }
.rules-list li.win b { color: #6ff0a2; }
.rules-list li.lose { border-left-color: #ff3b55; }
.rules-list li.lose b { color: #ff7a8c; }
.countdown {
  display: none; place-items: center; position: relative; z-index: 3;
  font-family: var(--serif); font-weight: 700; font-size: clamp(110px, 26vw, 220px); color: #fff;
  text-shadow: 0 0 40px rgba(255,59,85,.8);
}
.quiz-card {
  padding: clamp(20px, 4.5vw, 34px); border-radius: 18px;
  background: #fbf3ea; color: var(--ink);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.q-top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 17px; }
#qMoney { font-family: var(--serif); font-size: 26px; transition: color .2s; }
#qMoney.pos { color: #1b9a52; } #qMoney.neg { color: #c41c3b; }
.timer { display: flex; align-items: center; gap: 12px; margin: 14px 0 18px; }
.timer-track { flex: 1; height: 12px; border-radius: 6px; background: #ead9c8; overflow: hidden; }
#timerBar { height: 100%; width: 100%; transform-origin: left; background: #2a7d4f; border-radius: 6px; transition: background .3s; }
#timerNum { font-family: var(--serif); font-weight: 700; font-size: 28px; min-width: 2ch; text-align: right; }
.quiz-card.hurry #timerBar { background: #e0263f; }
.quiz-card.hurry #timerNum { color: #e0263f; animation: throb .5s ease-in-out infinite; }
@keyframes throb { 50% { transform: scale(1.25); } }
#qText { font-family: var(--serif); font-weight: 600; font-size: clamp(22px, 4.2vw, 30px); line-height: 1.25; margin: 0 0 18px; }
.q-choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 14px; text-align: left; cursor: pointer;
  padding: 14px 16px; border-radius: 12px; border: 2px solid #e2cfbb; background: #fff;
  font-size: clamp(17px, 2.6vw, 20px); color: var(--ink);
  transition: border-color .15s, background .15s, transform .1s;
}
.choice:hover { border-color: var(--wine); }
.choice:active { transform: scale(.98); }
.choice-letter {
  flex: none; width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  font-weight: 700; background: #f2e4d4; color: var(--wine);
}
.q-choices.answered .choice { pointer-events: none; }
.choice.right { background: #e3f8ea; border-color: #2a9d5c; }
.choice.right .choice-letter { background: #2a9d5c; color: #fff; }
.choice.wrong { background: #fde6e9; border-color: #e0263f; }
.choice.wrong .choice-letter { background: #e0263f; color: #fff; }
.money-pop {
  position: absolute; right: 24px; top: 16px; pointer-events: none;
  font-family: var(--serif); font-weight: 700; font-size: 34px;
}
.money-pop.plus { color: #1b9a52; } .money-pop.minus { color: #e0263f; }
.quiz-result { text-align: center; }
.quiz-result .kicker { font-family: var(--serif); font-size: clamp(16px, 2.6vw, 20px); letter-spacing: .25em; text-transform: uppercase; }
#resultHead { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: clamp(34px, 7vw, 60px); line-height: 1.08; margin: 12px 0 10px; color: #fbe9e4; }
#resultHead .pos { color: #7ef0ac; font-style: normal; } #resultHead .neg { color: #ff7a8c; font-style: normal; }
#resultNote { font-size: clamp(18px, 2.6vw, 21px); opacity: .9; margin: 0; }
.result-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 22px; }
.result-actions .btn { margin: 0 !important; }
#retryBtn { opacity: 0; visibility: hidden; }
.abort-note {
  display: none; margin: 0 0 16px; padding: 12px 16px; border-radius: 10px;
  background: rgba(255,59,85,.18); border: 1px solid #ff3b55; color: #ffd0d6;
  font-size: clamp(16px, 2.4vw, 18px); line-height: 1.45; font-weight: 600;
}

/* Heart finale */
#heart { flex-direction: column; gap: 6px; }
.heart-kicker { font-size: clamp(18px, 3.4vw, 26px); opacity: .9; text-align: center; }
.heart-box { position: relative; width: min(96vw, 72vh, 720px); aspect-ratio: 1 / .95; }
.heart-photo {
  position: absolute; width: 14%; aspect-ratio: 1; border-radius: 14%;
  background-size: cover; background-position: center;
  border: 2px solid rgba(255,246,239,.9);
  box-shadow: 0 8px 22px rgba(0,0,0,.45);
  transform: translate(-50%, -50%);
}
.heart-center { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); text-align: center; width: 50%; }
.heart-center h2 {
  font-family: var(--serif); font-style: italic; font-weight: 600; margin: 6px 0;
  font-size: clamp(21px, 4.8vw, 48px); line-height: 1.06; color: #fbe9e4;
}
.sig-sm { font-family: var(--hand); font-size: clamp(20px, 3.6vw, 30px); color: var(--gold-2); margin: 0; }
#replayBtn { padding: 12px 22px; font-size: 17px; }

@media (max-width: 520px) {
  .journey-hint { font-size: 13px; }
  .heart-photo { border-width: 1.5px; }
  #replayBtn { padding: 10px 16px; font-size: 15px; }
  .btn { font-size: 17px; padding: 14px 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .flame, .flame-glow, .env-seal { animation: none; }
}
