:root {
  --rose: #ff5c8a;
  --rose-deep: #d81b55;
  --blush: #ffd3de;
  --ink: #fff7f4;
  --glass: rgba(26, 14, 22, 0.52);
  --line: rgba(255, 255, 255, 0.16);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --script: 'Great Vibes', cursive;
  --sans: 'Jost', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #1a1020;
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body.touch .desktop-only { display: none !important; }
body:not(.touch) .touch-only { display: none !important; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(10, 4, 10, 0.55) 100%);
}
.grain {
  position: fixed;
  inset: -50%;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-3%, 2%); }
  50% { transform: translate(2%, -3%); }
  75% { transform: translate(3%, 3%); }
  100% { transform: translate(0, 0); }
}

#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
body.touch #crosshair { display: none; }

/* ---------- loader ---------- */
#loader {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: #1a1020;
  transition: opacity 1.4s ease, visibility 1.4s;
}
#loader.gone { opacity: 0; visibility: hidden; }
#loader p { font-style: italic; font-size: 19px; opacity: 0.75; }
.loader-heart {
  font-size: 44px;
  color: var(--rose);
  animation: beat 1.1s ease-in-out infinite;
}
@keyframes beat {
  0%, 100% { transform: scale(1); }
  12% { transform: scale(1.2); }
  24% { transform: scale(1.02); }
  36% { transform: scale(1.14); }
}

/* ---------- start ---------- */
#start {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(20, 8, 18, 0.25), rgba(20, 8, 18, 0.7));
  opacity: 0;
  visibility: hidden;
  transition: opacity 1.2s ease, visibility 1.2s;
}
#start.show { opacity: 1; visibility: visible; }
.start-inner { text-align: center; max-width: 560px; }
#start h1 {
  font-weight: 500;
  font-size: clamp(42px, 7vw, 72px);
  line-height: 1.02;
  letter-spacing: -0.01em;
  margin: 10px 0 16px;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.35);
}
.lede {
  font-style: italic;
  font-size: clamp(18px, 2.4vw, 22px);
  line-height: 1.45;
  opacity: 0.92;
  margin-bottom: 26px;
  text-wrap: balance;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 22px;
  margin-bottom: 30px;
  font-family: var(--sans);
  font-size: 13px;
  color: rgba(255, 247, 244, 0.85);
}
.ctl { display: flex; align-items: center; gap: 4px; }
.ctl span { margin-left: 6px; }
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.08);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}
.tiny {
  margin-top: 16px;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: lowercase;
  opacity: 0.6;
}

/* ---------- buttons ---------- */
.btn {
  --lift: 0px;
  --grow: 1;
  font-family: var(--sans);
  font-weight: 400;
  font-size: 14px;
  letter-spacing: 0.04em;
  padding: 13px 26px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  cursor: pointer;
  transform: translateY(var(--lift)) scale(var(--grow));
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.25s, border-color 0.25s;
}
.btn:hover { --lift: -2px; background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.45); }
.btn:focus-visible { outline: 2px solid var(--blush); outline-offset: 3px; }
.btn.primary {
  background: linear-gradient(135deg, #ff6f98, var(--rose-deep));
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.btn.primary:hover { background: linear-gradient(135deg, #ff80a5, #e2265f); }
.btn.big { font-size: 16px; padding: 16px 34px; }
.btn.ghost { background: rgba(20, 10, 18, 0.35); }
.btn.fleeing {
  position: fixed;
  z-index: 45;
  margin: 0;
  background: rgba(30, 16, 26, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: left 0.38s cubic-bezier(0.2, 0.9, 0.2, 1.2), top 0.38s cubic-bezier(0.2, 0.9, 0.2, 1.2), transform 0.3s;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  z-index: 20;
  opacity: 0;
  transition: opacity 1s ease;
  pointer-events: none;
}
#hud.show { opacity: 1; }
.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-family: var(--sans);
  font-size: 12px;
}
.progress .label { letter-spacing: 0.14em; text-transform: uppercase; font-size: 10px; opacity: 0.8; }
#hearts { display: flex; gap: 3px; font-size: 13px; }
#hearts span { color: rgba(255, 255, 255, 0.28); transition: color 0.6s, transform 0.6s; }
#hearts span.on { color: var(--rose); transform: scale(1.15); }
#count { opacity: 0.85; font-variant-numeric: tabular-nums; }

#compass {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 12px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
}
#compass.show { opacity: 1; }
#arrow { color: var(--rose); flex: none; }
#next-name { font-size: 16px; font-weight: 500; line-height: 1.1; white-space: nowrap; }
#next-dist { font-family: var(--sans); font-size: 11px; opacity: 0.75; letter-spacing: 0.06em; }

#prompt {
  position: fixed;
  left: 50%;
  bottom: max(34px, env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 10px 10px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-family: var(--sans);
  font-size: 14px;
  transform: translate(-50%, 12px);
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}
#prompt.show { opacity: 1; transform: translate(-50%, 0); }
#prompt-text { white-space: nowrap; }
@media (max-width: 420px) { #prompt { font-size: 12.5px; } }
body.touch #prompt { bottom: 120px; padding-left: 18px; }

#act {
  position: fixed;
  right: 26px;
  bottom: max(40px, env(safe-area-inset-bottom));
  z-index: 25;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: linear-gradient(135deg, #ff6f98, var(--rose-deep));
  color: #fff;
  font-size: 26px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
body.touch #prompt.show ~ #act { opacity: 1; pointer-events: auto; }

#joy {
  position: fixed;
  z-index: 15;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#joy.show { opacity: 1; }
#joy .knob { width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, 0.55); }

#toast {
  position: fixed;
  left: 50%;
  top: 22%;
  z-index: 20;
  max-width: min(560px, 90vw);
  text-align: center;
  font-style: italic;
  font-size: clamp(20px, 3vw, 28px);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
  transform: translate(-50%, 10px);
  opacity: 0;
  transition: opacity 1s ease, transform 1s ease;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.icon-btn {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  z-index: 30;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink);
  cursor: pointer;
}
.icon-btn[hidden] { display: none; }
.icon-btn .off { display: none; }
.icon-btn.muted .on { display: none; }
.icon-btn.muted .off { display: block; }

#paused {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  background: rgba(16, 8, 16, 0.35);
  font-style: italic;
  font-size: 24px;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s, visibility 0.4s;
}
#paused.show { opacity: 1; visibility: visible; }

/* ---------- message card ---------- */
#ui {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  padding: 0 18px max(26px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.card {
  pointer-events: auto;
  width: min(560px, 100%);
  text-align: center;
  padding: 28px 30px 26px;
  border-radius: 26px;
  background: linear-gradient(170deg, rgba(40, 20, 32, 0.72), rgba(20, 10, 18, 0.78));
  border: 1px solid var(--line);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: opacity 0.5s ease, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.5s ease;
}
.card.out { opacity: 0; transform: translateY(24px) scale(0.98); filter: blur(8px); pointer-events: none; }
.eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--blush);
  margin-bottom: 10px;
}
.card h2 {
  font-weight: 500;
  font-size: clamp(28px, 4.4vw, 38px);
  line-height: 1.1;
  margin-bottom: 12px;
  text-wrap: balance;
}
.sub {
  font-style: italic;
  font-size: clamp(18px, 2.3vw, 21px);
  line-height: 1.45;
  color: rgba(255, 247, 244, 0.9);
  margin-bottom: 22px;
  text-wrap: pretty;
}
.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- finale ---------- */
#finale {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 42;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 20px max(34px, env(safe-area-inset-bottom));
  pointer-events: none;
  opacity: 0;
  transition: opacity 1s ease;
}
#finale.show { opacity: 1; }
#finale.show #keep { pointer-events: auto; }
.f-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--blush);
  opacity: 0;
  transition: opacity 1s ease 0.2s;
}
.f-love {
  font-family: var(--script);
  font-weight: 400;
  font-size: clamp(70px, 13vw, 150px);
  line-height: 1.05;
  padding: 0 0.2em;
  color: #fff1f4;
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.45);
}
.f-love span { display: inline-block; opacity: 0; transform: translateY(26px) scale(0.9); filter: blur(10px); }
#finale.show .f-love span {
  animation: rise 1.1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: calc(0.5s + var(--i) * 0.09s);
}
@keyframes rise { to { opacity: 1; transform: none; filter: blur(0); } }
.f-sub {
  font-style: italic;
  font-size: clamp(19px, 2.6vw, 24px);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  opacity: 0;
  margin: 2px 0 20px;
  transition: opacity 1.2s ease 1.8s;
}
#finale.show .f-eyebrow, #finale.show .f-sub { opacity: 0.95; }
#keep { opacity: 0; transition: opacity 1.2s ease 3s, background 0.25s, transform 0.35s; }
#finale.show #keep { opacity: 1; }

@media (max-width: 560px) {
  .card { padding: 22px 20px 20px; border-radius: 22px; }
  .progress .label { display: none; }
  #compass { top: 64px; }
}
@media (prefers-reduced-motion: reduce) { .grain { animation: none; } }
