@font-face {
  font-family: "Shantell";
  src: url("fonts/shantell-latin.woff2") format("woff2");
  font-weight: 300 800;
  font-display: swap;
}

:root {
  --ink: #3B2A3D;
  --paper: #FFFDF9;
  --letter: #FFF7F3;
  --rose: #E04E78;
  --rose-soft: #FFB3C7;
  --hud-ink: var(--ink);
  --hud-track: rgba(59, 42, 61, .16);
  --hud-pill: rgba(255, 255, 255, .6);
  --dock-h: 200px; /* JS la ajusta a la altura real del conejito + burbuja */
  --top-h: 70px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  background: #0E1236;
}

body {
  font-family: "Shantell", ui-rounded, system-ui, sans-serif;
  font-variation-settings: "INFM" 40, "BNCE" 0;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--rose); outline-offset: 3px; }

/* ---------- Cielo: una capa por momento del día, se cruzan con opacidad ---------- */
#sky { position: fixed; inset: 0; overflow: hidden; }
#sky .layer { position: absolute; inset: 0; opacity: 0; transition: opacity 1.6s ease; }
#sky .layer.on { opacity: 1; }
[data-phase="dawn"]     { background: linear-gradient(180deg, #F6D3E3 0%, #FBE0DA 55%, #FFEBD2 100%); }
[data-phase="morning"]  { background: linear-gradient(180deg, #BFE0FF 0%, #E6EFFA 50%, #FFE6CF 100%); }
[data-phase="day"]      { background: linear-gradient(180deg, #8CCBFF 0%, #CDE9FF 60%, #EEF8FF 100%); }
[data-phase="noon"]     { background: linear-gradient(180deg, #6DBBFF 0%, #B5DEFF 55%, #F2FAFF 100%); }
[data-phase="golden"]   { background: linear-gradient(180deg, #9CC9EE 0%, #FBD9A6 60%, #FFC98B 100%); }
[data-phase="dusk"]     { background: linear-gradient(180deg, #4E4790 0%, #B66A9E 52%, #FFAE8A 100%); }
[data-phase="night"]    { background: linear-gradient(180deg, #1F2559 0%, #362F6B 60%, #574585 100%); }
[data-phase="midnight"] { background: linear-gradient(180deg, #0E1236 0%, #1F1E4E 60%, #35296A 100%); }

#stars { position: absolute; inset: 0; opacity: 0; transition: opacity 2s ease; }
body.is-night #stars { opacity: 1; }
#stars i {
  position: absolute;
  width: 2px; height: 2px;
  border-radius: 50%;
  background: #FFF6E0;
  animation: twinkle 3s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .25; } to { opacity: 1; } }

#sun, #moon {
  position: absolute;
  transform: translate(-50%, -50%);
  transition: left 1.8s cubic-bezier(.4, 0, .2, 1), top 1.8s cubic-bezier(.4, 0, .2, 1), opacity 1.4s ease;
}
#sun {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle, #FFF9DC 0 30%, #FFE28A 46%, rgba(255, 214, 110, .35) 58%, rgba(255, 214, 110, 0) 70%);
}
#sun.setting { background: radial-gradient(circle, #FFE7C2 0 28%, #FF9F6B 46%, rgba(255, 120, 90, .35) 58%, rgba(255, 120, 90, 0) 70%); }
#moon {
  width: 44px; height: 44px;
  border-radius: 50%;
  box-shadow: 10px -5px 0 0 #FFF2CF;
  filter: drop-shadow(0 0 14px rgba(255, 240, 200, .45));
  opacity: 0;
}

/* ---------- Barra superior: progreso tipo historia + reloj ---------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  padding: calc(var(--safe-t) + 10px) 14px 0;
  color: var(--hud-ink);
  opacity: 0;
  transition: opacity .6s ease;
}
body.mode-story #hud { opacity: 1; }
body.is-night { --hud-ink: #FFF3F6; --hud-track: rgba(255, 255, 255, .22); --hud-pill: rgba(255, 255, 255, .13); }

#progress { display: flex; gap: 4px; }
#progress span { flex: 1; height: 3px; border-radius: 3px; background: var(--hud-track); overflow: hidden; }
#progress span::after {
  content: "";
  display: block;
  height: 100%;
  background: var(--hud-ink);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .5s ease;
}
#progress span.done::after { transform: scaleX(1); }

#clock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 4px 11px 4px 7px;
  border-radius: 999px;
  background: var(--hud-pill);
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  transition: background .8s ease, color .8s ease;
}
#clock svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
#time { display: inline-block; }

/* ---------- Escenario: la foto del momento ---------- */
#stage {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-t) + var(--top-h)) 0 var(--dock-h);
  pointer-events: none;
}
.card {
  grid-area: 1 / 1;
  position: relative;
  width: min(82vw, calc((100vh - var(--top-h) - var(--dock-h) - 40px) * var(--ar)));
  width: min(82vw, calc((100dvh - var(--top-h) - var(--dock-h) - var(--safe-t) - 40px) * var(--ar)));
  aspect-ratio: var(--ar);
  padding: 8px;
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(40, 20, 40, .2), 0 18px 36px -12px rgba(30, 15, 40, .45);
  transform: rotate(var(--tilt));
}
.card img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 3px; }
.card::before {
  content: "";
  position: absolute;
  top: -13px; left: 50%;
  width: 88px; height: 26px;
  transform: translateX(-50%) rotate(var(--tape-r, -4deg));
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, .25) 0 6px, transparent 6px 12px), var(--tape, #FFB3C7);
  opacity: .88;
  border-radius: 2px;
  z-index: 1;
}

/* ---------- Collage final ---------- */
#collage { position: fixed; inset: 0; z-index: 6; pointer-events: none; transition: opacity .9s ease, filter .9s ease, transform .9s ease; }
body.mode-letter #collage { opacity: .4; filter: blur(1.5px); transform: scale(.96); }
body.mode-letter.peek #collage { opacity: 1; filter: none; transform: none; }
.tile {
  position: absolute;
  left: 0; top: 0;
  padding: 5px;
  border-radius: 4px;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(20, 10, 30, .25), 0 12px 26px -10px rgba(10, 5, 30, .6);
}
.tile img { display: block; width: 100%; aspect-ratio: var(--ar); object-fit: cover; border-radius: 2px; }

/* ---------- Conejito + burbuja ---------- */
#dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 0 14px calc(var(--safe-b) + 14px);
  pointer-events: none;
}
#bunny-wrap { flex: none; width: 92px; transform-origin: 50% 100%; }
#bunny { display: block; width: 100%; overflow: visible; }
#bunny .fur { fill: #FFFDFB; stroke: var(--ink); stroke-width: 2.4; stroke-linejoin: round; }
#bunny .inner { fill: #FFC4D3; }
#bunny .cheek { fill: #FFB3C7; opacity: .75; }
#bunny .eyes ellipse { fill: var(--ink); }
#bunny .glint { fill: #fff; }
#bunny .nose { fill: #FF8FAB; }
#bunny .mouth { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; }
#bunny .held-heart { fill: #FF5C86; transform-box: fill-box; transform-origin: center; transform: scale(0); transition: transform .5s cubic-bezier(.3, 1.6, .5, 1); }
body.holding #bunny .held-heart { transform: scale(1); }

.ear, .eyes { transform-box: fill-box; }
.ear { transform-origin: 50% 100%; }
.eyes { transform-origin: center; animation: blink 4.6s infinite; }
.ear-r { animation: twitch 5.2s infinite; }
.ear-l { animation: twitch 7.4s 1.3s infinite; }
#bunny-body { transform-box: fill-box; transform-origin: 50% 100%; animation: breathe 3.2s ease-in-out infinite; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes twitch { 0%, 86%, 100% { transform: rotate(0); } 89% { transform: rotate(-9deg); } 93% { transform: rotate(5deg); } }
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.015, .985); } }

#bubble {
  position: relative;
  flex: 1;
  min-height: 96px;
  margin-bottom: 46px;
  padding: 14px 16px 20px;
  border-radius: 22px 22px 22px 6px;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(40, 20, 40, .15), 0 14px 30px -14px rgba(30, 15, 40, .5);
  font-size: 17px;
  line-height: 1.42;
  transition: opacity .35s ease, transform .35s ease;
}
#bubble::before {
  content: "";
  position: absolute;
  left: -6px; bottom: 24px;
  width: 14px; height: 14px;
  background: var(--paper);
  border-radius: 2px;
  transform: rotate(45deg);
}
#bubble.hidden { opacity: 0; transform: translateY(8px) scale(.97); }
#say { margin: 0; }
#say .w { white-space: nowrap; }
#say .c { opacity: 0; transition: opacity .14s ease; }
#say .c.on { opacity: 1; }
#more {
  position: absolute;
  right: 14px; bottom: 9px;
  width: 0; height: 0;
  border: 6px solid transparent;
  border-top: 7px solid var(--rose);
  border-bottom: 0;
  opacity: 0;
  transition: opacity .3s ease;
}
#bubble.ready #more { opacity: 1; animation: nudge 1.1s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(3px); } }

/* Intro: conejito grande y centrado, la burbuja arriba */
body.mode-intro #dock { top: 0; flex-direction: column-reverse; align-items: center; justify-content: center; padding-bottom: calc(var(--safe-b) + 60px); }
body.mode-intro #bunny-wrap { width: 156px; }
body.mode-intro #bubble { flex: none; width: min(320px, 86vw); margin: 0 0 18px; text-align: center; border-radius: 24px; padding: 18px 20px 24px; }
body.mode-intro #bubble::before { left: 50%; bottom: -6px; transform: translateX(-50%) rotate(45deg); border-radius: 0 0 4px 0; }

/* Carta: el conejito se sienta en el borde, con la burbuja a su izquierda */
body.mode-letter #dock { flex-direction: row-reverse; bottom: calc(var(--letter-h, 420px) - 22px); padding-bottom: 0; }
body.mode-letter #bunny-wrap { width: 84px; }
body.mode-letter #bubble { flex: none; max-width: 230px; min-height: 0; margin-bottom: 52px; padding: 11px 14px 13px; font-size: 16px; border-radius: 20px 20px 6px 20px; }
body.mode-letter #bubble::before { left: auto; right: -6px; bottom: 16px; }
body.mode-letter #more { display: none; }
body.mode-letter.peek #dock { opacity: 0; }

#start {
  position: fixed;
  left: 50%; bottom: calc(var(--safe-b) + 34px);
  z-index: 40;
  padding: 15px 30px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #FFF6F8;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 12px 26px -10px rgba(59, 42, 61, .7);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity .4s ease, transform .5s cubic-bezier(.3, 1.5, .5, 1);
}
#start.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }

/* ---------- Carta ---------- */
#letter {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 25;
  max-width: 460px;
  max-height: calc(100dvh - var(--safe-t) - 150px);
  margin: 0 auto;
  overflow-y: auto;
  padding: 26px 24px calc(var(--safe-b) + 20px);
  border-radius: 28px 28px 0 0;
  background: var(--letter);
  box-shadow: 0 -18px 44px -12px rgba(8, 6, 30, .6);
  transform: translateY(110%);
  transition: transform .9s cubic-bezier(.2, .9, .2, 1);
  -webkit-user-select: text;
  user-select: text;
}
body.mode-letter #letter { transform: none; }
body.mode-letter.peek #letter { transform: translateY(calc(100% - var(--safe-b) - 64px)); }
#letter p { margin: 0 0 12px; font-size: 16.5px; line-height: 1.52; }
#letter p:first-child { font-weight: 700; font-size: 18px; }
#letter .line { opacity: 0; transform: translateY(8px); transition: opacity .8s ease, transform .8s ease; }
#letter .line.on { opacity: 1; transform: none; }
#letter .sign { text-align: right; font-weight: 700; margin-top: 2px; }

#love {
  margin: 14px 0 8px;
  color: var(--rose);
  font-size: clamp(32px, 10.5vw, 46px);
  font-weight: 800;
  white-space: nowrap;
  line-height: 1.05;
  letter-spacing: -.01em;
}
#love .l { display: inline-block; opacity: 0; transform: translateY(18px) scale(.6); }
#love.pop .l { animation: pop .7s cubic-bezier(.3, 1.6, .5, 1) forwards, wobble 2.6s ease-in-out infinite alternate; }
@keyframes pop { to { opacity: 1; transform: none; } }
@keyframes wobble {
  from { font-variation-settings: "INFM" 70, "BNCE" -70; }
  to   { font-variation-settings: "INFM" 70, "BNCE" 70; }
}

.actions { display: flex; gap: 10px; margin-top: 10px; opacity: 0; transition: opacity .8s ease; }
.actions.on { opacity: 1; }
#letter button {
  padding: 10px 18px;
  border: 2px solid rgba(59, 42, 61, .2);
  border-radius: 999px;
  background: transparent;
  font-size: 15px;
  font-weight: 650;
}
#peek-hint {
  position: fixed;
  left: 0; right: 0; bottom: calc(var(--safe-b) + 78px);
  z-index: 26;
  text-align: center;
  color: #FFF3F6;
  font-size: 15px;
  opacity: 0;
  transition: opacity .5s ease;
  pointer-events: none;
}
body.peek #peek-hint { opacity: .85; }

/* ---------- Corazones flotantes ---------- */
#hearts { position: fixed; inset: 0; z-index: 35; pointer-events: none; overflow: hidden; }
#hearts svg { position: absolute; fill: #FF6F91; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01s !important; }
  #love .l { opacity: 1; transform: none; }
}
