:root {
  --ink: #12071f;
  --violet: #2a1250;
  --violet-2: #3b1d6e;
  --purple: #9d5cff;
  --lilac: #d9c7ff;
  --paper: #f6efff;
  --tangerine: #ff8a1f;
  --tangerine-deep: #d96a00;
  --mint: #8ff0d0;
  --display: "Unbounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  --body: "Onest", system-ui, sans-serif;
  --hand: "Caveat", "Segoe Script", cursive;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--tangerine);
}
::selection { background: var(--tangerine); color: var(--ink); }
[hidden] { display: none !important; }

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

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 3px solid var(--mint); outline-offset: 3px; }

/* ---------- controls ---------- */
.cta {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1rem;
  padding: 1.05rem 1.8rem;
  border-radius: 999px;
  background: var(--tangerine);
  color: var(--ink);
  box-shadow: 0 12px 24px -10px rgba(0, 0, 0, 0.75), 0 2px 0 var(--tangerine-deep);
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease), background 0.2s;
}
.cta:hover:not(:disabled) { transform: translateY(-3px); background: #ffa04a; box-shadow: 0 20px 30px -12px rgba(0, 0, 0, 0.8), 0 2px 0 var(--tangerine-deep); }
.cta:active:not(:disabled) { transform: translateY(1px); }
.cta:disabled { background: var(--violet-2); color: var(--lilac); box-shadow: none; cursor: progress; }
.cta.small { font-size: 0.8rem; padding: 0.8rem 1.2rem; }

.ghost {
  font-family: var(--display);
  font-weight: 500;
  font-size: 0.8rem;
  padding: 0.8rem 1.2rem;
  border-radius: 999px;
  color: var(--paper);
  background: rgba(42, 18, 80, 0.82);
  box-shadow: inset 0 0 0 1.5px var(--purple);
  transition: background 0.25s, transform 0.35s var(--ease);
}
.ghost:hover { background: var(--violet-2); transform: translateY(-2px); }

.icon-btn {
  width: 2.9rem; height: 2.9rem;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(42, 18, 80, 0.82);
  box-shadow: inset 0 0 0 1.5px var(--purple);
  transition: background 0.25s, transform 0.35s var(--ease);
}
.icon-btn:hover { background: var(--violet-2); transform: translateY(-2px); }
svg { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#sound .mute { display: none; }
#sound[aria-pressed="true"] .waves { display: none; }
#sound[aria-pressed="true"] .mute { display: inline; }

#dock { position: fixed; top: 1.25rem; right: 1.25rem; display: flex; gap: 0.6rem; align-items: center; z-index: 30; }

/* ---------- intro ---------- */
#intro {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-start;
  padding: clamp(1.5rem, 5vw, 4.5rem);
  padding-bottom: clamp(2rem, 7vh, 5rem);
  background: linear-gradient(to top, rgba(18, 7, 31, 0.92) 0%, rgba(18, 7, 31, 0.35) 45%, rgba(18, 7, 31, 0) 70%);
  z-index: 20;
  transition: opacity 0.9s var(--ease), transform 0.9s var(--ease), filter 0.9s var(--ease);
}
#intro.leaving { opacity: 0; transform: translateY(2rem); filter: blur(10px); pointer-events: none; }
#intro h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.6rem, 9.2vw, 6rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
  color: var(--paper);
}
.h1-name { display: block; }
.intro-line {
  margin: 1.4rem 0 2rem;
  font-size: clamp(1.1rem, 1.7vw, 1.45rem);
  line-height: 1.4;
  color: var(--lilac);
  max-width: 28ch;
}
.intro-note { margin: 1.1rem 0 0; font-size: 0.9rem; color: #b9a5e6; }

/* ---------- speech bubble ---------- */
#bubble {
  position: fixed; left: 0; top: 0;
  max-width: min(19rem, 70vw);
  padding: 0.75rem 1.05rem;
  background: var(--paper);
  color: var(--ink);
  font-weight: 500;
  font-size: 1rem;
  line-height: 1.35;
  border-radius: 1.1rem 1.1rem 1.1rem 0.25rem;
  box-shadow: 0 14px 30px -12px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transform-origin: 0 100%;
  scale: 0.6;
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.3s, scale 0.45s var(--ease);
}
#bubble.on { opacity: 1; scale: 1; }

/* etiqueta que acompaña al cursor sobre lo que se puede tocar */
#tip {
  position: fixed; left: 0; top: 0;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--paper); color: var(--ink);
  font-size: 0.82rem; font-weight: 500; white-space: nowrap;
  box-shadow: 0 8px 18px -8px rgba(0, 0, 0, 0.7);
  opacity: 0; pointer-events: none; z-index: 16;
  transition: opacity 0.15s;
}
#tip.on { opacity: 1; }

/* ---------- song HUD ---------- */
#hud {
  position: fixed; left: 50%; bottom: 1.4rem; translate: -50% 0;
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
  padding: 0.9rem 1.5rem 0.85rem;
  border-radius: 1.5rem;
  background: rgba(18, 7, 31, 0.84);
  box-shadow: 0 18px 36px -18px rgba(0, 0, 0, 0.8);
  z-index: 10; pointer-events: none;
  text-align: center;
  max-width: calc(100vw - 1.5rem);
}
#progress { display: flex; gap: 1.5rem; align-items: flex-end; }
#progress .phrase { display: flex; flex-direction: column; align-items: center; gap: 0.45rem; }
#progress .phrase b {
  font-family: var(--display); font-weight: 500; font-size: 0.7rem; letter-spacing: 0.01em;
  color: #a48fd6;
  transition: color 0.4s;
}
#progress .phrase.now b { color: var(--paper); }
#progress .phrase.done b { color: var(--mint); }
#progress .dots { display: flex; gap: 0.32rem; align-items: center; }
#progress i {
  width: 0.62rem; height: 0.62rem; border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 1.5px #7d62b8;
  transition: background 0.25s, box-shadow 0.25s, scale 0.4s var(--ease);
}
#progress i.done { background: var(--purple); box-shadow: none; }
#progress i.next { background: var(--tangerine); box-shadow: none; scale: 1.45; }
#hint {
  margin: 0;
  color: var(--lilac);
  font-size: 1rem;
  line-height: 1.7;
  text-wrap: balance;
}
#hint:empty { display: none; }
#hud:has(#hint:empty):has(#progress[hidden]) { visibility: hidden; }
#hint.nudge { animation: nudge 0.45s var(--ease); }
@keyframes nudge { 25% { transform: translateX(-7px); } 60% { transform: translateX(5px); } }
#hint kbd {
  font-family: var(--display); font-size: 0.82rem; font-weight: 500;
  padding: 0.2rem 0.55rem; margin: 0 0.2rem;
  border-radius: 0.4rem;
  background: var(--tangerine); color: var(--ink);
}

/* ---------- gallery controls ---------- */
#gallery-ui {
  position: fixed; left: 50%; bottom: 1.6rem; translate: -50% 0;
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.5rem 0.6rem;
  border-radius: 999px;
  background: rgba(18, 7, 31, 0.8);
  z-index: 12;
}
#gallery-ui button:not(.cta) {
  width: 2.75rem; height: 2.75rem; border-radius: 50%;
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 1.5px var(--purple);
  transition: background 0.2s, transform 0.3s var(--ease);
}
#gallery-ui button:not(.cta):hover { background: var(--violet-2); transform: scale(1.08); }
#g-count { font-family: var(--display); font-size: 0.8rem; color: var(--lilac); min-width: 3.2rem; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- blow meter ---------- */
#blow {
  position: fixed; left: 50%; bottom: 2rem; translate: -50% 0;
  width: min(31rem, 90vw);
  text-align: center; z-index: 12; pointer-events: none;
}
#blow { padding: 1rem 1.4rem 1.1rem; border-radius: 1.4rem; background: rgba(18, 7, 31, 0.86); }
#blow p { margin: 0 0 0.8rem; font-size: 1.1rem; color: var(--paper); text-wrap: balance; }
#blow strong { color: var(--tangerine); font-weight: 700; }
.meter { height: 0.7rem; border-radius: 999px; background: rgba(42, 18, 80, 0.9); box-shadow: inset 0 0 0 1.5px var(--purple); overflow: hidden; }
#blow-bar { display: block; height: 100%; width: 100%; transform: scaleX(0); transform-origin: 0 50%; background: var(--mint); border-radius: inherit; }

/* ---------- finale ---------- */
#finale {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: clamp(1.5rem, 5vh, 3.5rem) 1.5rem clamp(1.5rem, 4vh, 2.5rem);
  text-align: center; z-index: 11; pointer-events: none;
}
#finale h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(1.5rem, 3.4vw, 2.6rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  color: var(--paper);
  text-shadow: 0 4px 30px rgba(18, 7, 31, 0.9);
  animation: rise 1.2s var(--ease) both;
}
#finale h2 span { display: block; font-size: clamp(2.6rem, 6.4vw, 5rem); color: var(--tangerine); margin-top: 0.15em; }
.finale-actions { display: flex; gap: 0.8rem; flex-wrap: wrap; justify-content: center; pointer-events: auto; animation: rise 1.2s 0.5s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(1.5rem); filter: blur(8px); } }

/* ---------- letter ---------- */
#letter {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(30rem, 100vw);
  padding: 4.5rem clamp(1.4rem, 3vw, 2.4rem) 2.5rem;
  background: var(--violet);
  box-shadow: -30px 0 60px -20px rgba(0, 0, 0, 0.7);
  overflow-y: auto;
  z-index: 40;
  animation: slide 0.8s var(--ease) both;
  scrollbar-width: thin; scrollbar-color: var(--purple) var(--violet);
}
@keyframes slide { from { transform: translateX(100%); } }
#close-letter { position: absolute; top: 1.25rem; right: 1.25rem; }
.polaroid {
  margin: 0 auto 2rem; width: min(15rem, 70%);
  padding: 0.6rem 0.6rem 0.4rem;
  background: var(--paper);
  rotate: -3deg;
  box-shadow: 0 18px 30px -14px rgba(0, 0, 0, 0.75);
}
.polaroid img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
.polaroid figcaption { font-family: var(--hand); font-size: 1.5rem; color: var(--violet); text-align: center; line-height: 1.4; }
#letter-body p { margin: 0 0 1.05rem; color: #ece2ff; font-size: 1.06rem; line-height: 1.62; max-width: 62ch; text-wrap: pretty; }
#letter-body p:first-child { font-family: var(--display); font-weight: 500; font-size: 1.25rem; color: var(--tangerine); line-height: 1.25; }
#letter-body .sign { font-family: var(--hand); font-size: 1.9rem; color: var(--mint); margin-top: 1.6rem; line-height: 1.2; }

.fallback { position: fixed; inset: 0; display: grid; place-items: center; padding: 2rem; text-align: center; }

@media (max-width: 640px) {
  #hint { font-size: 0.85rem; }
  #progress { gap: 0.7rem; }
  #hud { padding: 0.7rem 0.9rem; }
  #progress i { width: 0.45rem; height: 0.45rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
