/* ============================================================================
   SHELL — lo que rodea siempre al contenido: telón de entrada, puerta del PIN,
   cabecera, navegación y las hojas que se abren encima.
   ========================================================================== */

#app {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100svh;
  max-width: var(--shell);
  margin-inline: auto;
  padding-top: var(--safe-t);
}
@media (min-width: 900px) { :root { --shell: 720px; } }

/* ── Telón de entrada ────────────────────────────────────────────────────── */

#telon {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: radial-gradient(70% 50% at 50% 50%, #0B0917, #05040B);
  transition: opacity 900ms var(--ease-out), visibility 900ms;
}
#telon.fuera { opacity: 0; visibility: hidden; }

.telon-luz {
  position: absolute;
  width: 2px; height: 42vh;
  background: linear-gradient(180deg, transparent, var(--gold), transparent);
  filter: blur(1px);
  animation: hilo 2.4s var(--ease-out) infinite;
}
@keyframes hilo {
  0%   { transform: scaleY(0); opacity: 0; }
  35%  { transform: scaleY(1); opacity: 1; }
  100% { transform: scaleY(1) translateY(6%); opacity: 0; }
}
.telon-firma {
  font-family: var(--display);
  font-style: italic;
  font-size: var(--t-xl);
  letter-spacing: .16em;
  color: var(--gold-soft);
  opacity: .0;
  animation: firmar 2.6s var(--ease-out) forwards;
}
@keyframes firmar {
  0% { opacity: 0; letter-spacing: .5em; filter: blur(10px); }
  60% { opacity: .95; }
  100% { opacity: .85; letter-spacing: .16em; filter: blur(0); }
}

/* ── La puerta: PIN ──────────────────────────────────────────────────────── */

#puerta {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background: radial-gradient(80% 60% at 50% 40%, rgba(11,9,23,.82), rgba(5,4,11,.96));
  backdrop-filter: blur(6px);
}
.puerta-caja { width: min(360px, 92vw); text-align: center; }

.cerradura {
  width: 96px; height: 96px;
  margin: 0 auto var(--sp-5);
  border-radius: 50%;
  border: 1px solid rgba(233,199,132,.35);
  display: grid;
  place-items: center;
  position: relative;
  box-shadow: inset 0 0 40px rgba(233,199,132,.10), 0 0 40px rgba(233,199,132,.12);
}
.cerradura::before {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 1px dashed rgba(233,199,132,.18);
  animation: gira 28s linear infinite;
}
@keyframes gira { to { transform: rotate(360deg); } }
.cerradura svg { width: 34px; height: 34px; stroke: var(--gold); fill: none; stroke-width: 1.4; }

.puerta-titulo {
  font-family: var(--display);
  font-style: italic;
  font-size: var(--t-xl);
  color: var(--gold-soft);
  margin-bottom: var(--sp-2);
}
.puerta-pista { font-family: var(--util); font-size: var(--t-sm); color: var(--mist-dim); margin-bottom: var(--sp-5); }

.puntos { display: flex; justify-content: center; gap: 14px; margin-bottom: var(--sp-6); }
.puntos i {
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 1px solid rgba(233,199,132,.45);
  transition: all var(--d-sm) var(--ease-back);
}
.puntos i.lleno { background: var(--gold); box-shadow: var(--halo-oro); transform: scale(1.18); }
.puerta.error .puntos { animation: temblar 420ms var(--ease-soft); }
@keyframes temblar {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.teclado { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tecla {
  height: 62px;
  border-radius: var(--r-m);
  border: 1px solid rgba(214,207,228,.14);
  background: linear-gradient(180deg, rgba(34,29,60,.75), rgba(18,16,31,.75));
  color: var(--mist);
  font-family: var(--display);
  font-size: var(--t-lg);
  cursor: pointer;
  transition: transform var(--d-xs) var(--ease-back), border-color var(--d-sm), box-shadow var(--d-sm);
}
.tecla:active { transform: scale(.93); border-color: rgba(233,199,132,.6); box-shadow: var(--halo-oro); }
.tecla.entrar {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold-deep));
  color: #1A1206;
  border-color: transparent;
  display: grid;
  place-items: center;
}
.tecla.entrar[hidden] { display: none; }
.tecla.entrar .ico { width: 24px; height: 24px; stroke-width: 2; }
.puntos i { flex: none; }

/* ── Cabecera ────────────────────────────────────────────────────────────── */

#cabecera {
  position: relative;
  padding: var(--sp-5) var(--sp-5) var(--sp-3);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: var(--sp-3);
}
.cab-eyebrow {
  grid-column: 1;
  margin: 0 0 2px;
  font-family: var(--util);
  font-size: var(--t-xs);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--mist-faint);
}
.cab-titulo {
  grid-column: 1;
  font-family: var(--display);
  font-style: italic;
  font-size: var(--t-xl);
  color: var(--gold-soft);
}

/* Botón de latido: late de verdad, y más fuerte cuando llega uno de ella. */
.latir {
  grid-column: 2;
  grid-row: 1 / span 2;
  position: relative;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 1px solid rgba(222,139,132,.35);
  background: radial-gradient(circle at 50% 35%, rgba(222,139,132,.22), rgba(18,16,31,.9));
  color: var(--rose);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform var(--d-sm) var(--ease-back), box-shadow var(--d-sm);
}
.latir-ico { width: 24px; height: 24px; fill: currentColor; animation: latido 2.6s var(--ease-soft) infinite; }
@keyframes latido {
  0%, 100% { transform: scale(1); }
  12% { transform: scale(1.16); }
  24% { transform: scale(1); }
  36% { transform: scale(1.1); }
  48% { transform: scale(1); }
}
.latir:active { transform: scale(.9); }
.latir.suena { box-shadow: 0 0 0 0 rgba(222,139,132,.45); animation: onda 900ms var(--ease-out); }
@keyframes onda {
  from { box-shadow: 0 0 0 0 rgba(222,139,132,.5); }
  to   { box-shadow: 0 0 0 26px rgba(222,139,132,0); }
}
.latir-n {
  position: absolute;
  bottom: -4px; right: -4px;
  min-width: 22px;
  padding: 1px 5px;
  border-radius: var(--r-full);
  background: var(--card-hi);
  border: 1px solid rgba(233,199,132,.28);
  font-family: var(--util);
  font-size: 10px;
  color: var(--gold-soft);
}

/* ── Lienzo ──────────────────────────────────────────────────────────────── */

#lienzo {
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  /* Abajo se reserva sitio para la barra, la hierba y el gato, que pasea
     por esa franja: si no, se planta encima de los botones. */
  padding: 0 var(--sp-5) calc(var(--nav-h) + var(--safe-b) + 92px);
  scrollbar-width: none;
}
#lienzo::-webkit-scrollbar { display: none; }
.vista { display: block; }

/* ── Navegación ──────────────────────────────────────────────────────────── */

#nav {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 16px);
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  border-radius: var(--r-full);
  background: rgba(12,10,22,.92);
  border: 1px solid rgba(233,199,132,.16);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--sombra-alta);
  width: max-content;
  max-width: calc(100vw - 24px);
}
.nav-luz {
  position: absolute;
  top: 6px;
  height: calc(100% - 12px);
  border-radius: var(--r-full);
  background: linear-gradient(180deg, rgba(233,199,132,.22), rgba(233,199,132,.08));
  border: 1px solid rgba(233,199,132,.3);
  box-shadow: var(--halo-oro);
  transition: left 520ms var(--ease-back), width 520ms var(--ease-back);
  pointer-events: none;
}
.nav-btn {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  gap: 2px;
  min-width: 0;
  padding: 8px 7px 6px;
  border: 0;
  background: none;
  color: var(--mist-faint);
  cursor: pointer;
  border-radius: var(--r-full);
  transition: color var(--d-sm) var(--ease-out), transform var(--d-sm) var(--ease-back);
}
.nav-btn .ico { width: 20px; height: 20px; }
.nav-btn span {
  font-family: var(--util);
  font-size: 9px;
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.nav-btn[aria-current="page"] { color: var(--gold-soft); }
.nav-btn:active { transform: scale(.92); }

/* ── Hojas ───────────────────────────────────────────────────────────────── */

.velo {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  align-items: end;
  justify-items: center;
  background: rgba(5,4,11,.7);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
}
@media (min-width: 720px) { .velo { align-items: center; } }

.hoja {
  position: relative;
  width: min(var(--shell), 100%);
  max-height: 88svh;
  overflow-y: auto;
  padding: var(--sp-6) var(--sp-5) calc(var(--sp-6) + var(--safe-b));
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: linear-gradient(170deg, rgba(38,32,66,.96), rgba(14,12,26,.98));
  border: 1px solid rgba(233,199,132,.18);
  border-bottom: 0;
  box-shadow: var(--sombra-alta);
  scrollbar-width: none;
}
.hoja::-webkit-scrollbar { display: none; }
@media (min-width: 720px) {
  .hoja { border-radius: var(--r-xl); border-bottom: 1px solid rgba(233,199,132,.18); }
}
.hoja.completa { max-height: 100svh; height: 100svh; border-radius: 0; padding-top: calc(var(--safe-t) + var(--sp-6)); }

/* Asa: se arrastra para cerrar. */
.hoja::before {
  content: "";
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  width: 46px; height: 4px;
  border-radius: 2px;
  background: rgba(214,207,228,.22);
}
.hoja-cerrar {
  position: absolute;
  top: 14px; right: 14px;
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(214,207,228,.14);
  background: rgba(18,16,31,.7);
  color: var(--mist-dim);
  cursor: pointer;
  transition: color var(--d-sm), border-color var(--d-sm), transform var(--d-sm) var(--ease-back);
}
.hoja-cerrar:hover { color: var(--gold); border-color: rgba(233,199,132,.4); transform: rotate(90deg); }
.hoja-titulo {
  font-family: var(--display);
  font-style: italic;
  font-size: var(--t-lg);
  color: var(--gold-soft);
  margin-bottom: var(--sp-4);
  padding-right: 44px;
}

/* ── Transición entre vistas (View Transitions) ──────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root) {
    animation: salir-vista 280ms var(--ease-in) both;
  }
  ::view-transition-new(root) {
    animation: entrar-vista 520ms var(--ease-out) both;
  }
}
@keyframes salir-vista {
  to { opacity: 0; transform: translateY(-10px) scale(.985); filter: blur(6px); }
}
@keyframes entrar-vista {
  from { opacity: 0; transform: translateY(16px) scale(.99); filter: blur(8px); }
}
