/* Puerta de entrada: video de fondo, titulo con glitch rojo y cian, y formulario en el tercio de abajo. */
:root {
  --glitch-rojo: #ff4b55;
  --glitch-cian: #22d3d3;
  --negro: #000;
  --texto: #eee;
  --tenue: rgb(238 238 238 / 0.6);
  --borde-campo: rgb(238 238 238 / 0.5);
  --toque: 48px;
  --radio: 12px;
  --margen-seguro: env(safe-area-inset-bottom, 0px);
  --desfase: 0.06em;
  /* Centro de la capucha en el cuadro: hacia ahi entra la camara. */
  --centro-capucha: 50% 37%;
  --duracion-entrada: 1.2s;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--negro); color: var(--texto); font-family: system-ui, sans-serif; }
button, input { font: inherit; color: inherit; }

/* Fondo: el poster se ve al instante y el video entra encima cuando empieza a correr. */
.fondo { position: fixed; inset: 0; overflow: hidden; transform-origin: var(--centro-capucha); }
.fondo img, .fondo video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 50%; }
.fondo video { opacity: 0; transition: opacity 0.8s ease; }
.fondo video.listo { opacity: 1; }
.fondo::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgb(0 0 0 / 0.85) 0%, rgb(0 0 0 / 0.45) 28%, transparent 48%); }

.puerta {
  position: relative; z-index: 1; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 24px 24px calc(28px + var(--margen-seguro));
  transition: opacity 0.35s ease;
}

/* Titulo con capas roja y cian desfasadas. */
.titulo {
  position: relative; isolation: isolate; margin: 0 0 24px; white-space: nowrap; text-align: center;
  font: 900 clamp(38px, 10.5vw, 116px) / 1 "Arial Black", "Segoe UI Black", system-ui, sans-serif;
  letter-spacing: 0.04em; color: var(--texto);
}
.titulo::before, .titulo::after {
  content: attr(data-texto); position: absolute; inset: 0; z-index: -1; text-align: left;
  animation: temblor 5s steps(1, end) infinite;
}
.titulo::before { color: var(--glitch-rojo); transform: translate(var(--desfase), 0.02em); }
.titulo::after { color: var(--glitch-cian); transform: translate(calc(var(--desfase) * -1), -0.01em); animation-delay: -2.3s; }

@keyframes temblor {
  0%, 88%, 100% { clip-path: inset(0); }
  89% { clip-path: inset(18% 0 52% 0); translate: 0.08em 0; }
  91% { clip-path: inset(60% 0 8% 0); translate: -0.06em 0; }
  93% { clip-path: inset(0); translate: 0.03em 0; }
  95% { clip-path: inset(0); translate: 0 0; }
}

/* Error: glitch fuerte, mas ancho y sin pausa, por menos de un segundo. */
.titulo.error { --desfase: 0.14em; animation: sacudida 0.6s steps(1, end); }
.titulo.error::before, .titulo.error::after { animation: temblor-fuerte 0.6s steps(1, end) 1; }
@keyframes sacudida {
  0%, 100% { translate: 0 0; }
  15% { translate: 0.05em 0; }
  35% { translate: -0.07em 0.01em; }
  55% { translate: 0.06em -0.01em; }
  75% { translate: -0.03em 0; }
}
@keyframes temblor-fuerte {
  0% { clip-path: inset(10% 0 60% 0); translate: 0.12em 0; }
  16% { clip-path: inset(55% 0 12% 0); translate: -0.14em 0; }
  33% { clip-path: inset(0 0 70% 0); translate: 0.1em 0; }
  50% { clip-path: inset(40% 0 30% 0); translate: -0.1em 0; }
  66% { clip-path: inset(70% 0 0 0); translate: 0.14em 0; }
  83% { clip-path: inset(20% 0 45% 0); translate: -0.08em 0; }
  100% { clip-path: inset(0); translate: 0 0; }
}

/* Formulario. */
.formulario { width: 100%; max-width: 360px; display: grid; gap: 10px; }
.formulario label { font-size: 14px; color: var(--tenue); }
.campo { position: relative; }
.campo input {
  width: 100%; height: var(--toque); padding: 0 88px 0 14px;
  border: 1px solid var(--borde-campo); border-radius: var(--radio);
  background: rgb(17 17 17 / 0.85); font-size: 16px; letter-spacing: 0.02em;
}
.campo input:focus-visible { outline: 2px solid var(--glitch-cian); outline-offset: 2px; }
.campo input[aria-invalid="true"] { border-color: var(--glitch-rojo); }
.mostrar {
  position: absolute; right: 4px; top: 4px; bottom: 4px; padding: 0 12px;
  border: 0; border-radius: 8px; background: none; font-size: 14px; color: var(--tenue); cursor: pointer;
}
.mostrar:focus-visible, .entrar:focus-visible { outline: 2px solid var(--glitch-cian); outline-offset: 2px; }
.mensaje { min-height: 20px; margin: 0; font-size: 14px; color: var(--glitch-rojo); }
.entrar {
  height: var(--toque); border: 0; border-radius: var(--radio);
  background: var(--texto); color: var(--negro); font-size: 16px; font-weight: 700; letter-spacing: 0.04em; cursor: pointer;
}
.entrar:disabled, .passkey:disabled { opacity: 0.6; cursor: progress; }
.passkey {
  height: var(--toque); border: 1px solid var(--borde-campo); border-radius: var(--radio);
  background: rgb(17 17 17 / 0.85); color: var(--texto); font-size: 15px; cursor: pointer;
}
.passkey:focus-visible { outline: 2px solid var(--glitch-cian); outline-offset: 2px; }
.passkey[hidden] { display: none; }

/* Acierto: la camara entra en la capucha y todo se funde a negro. */
.negro { position: fixed; inset: 0; z-index: 2; background: var(--negro); opacity: 0; pointer-events: none; }
body.entrando .fondo { transform: scale(7); transition: transform var(--duracion-entrada) cubic-bezier(0.55, 0, 0.9, 0.4); }
body.entrando .puerta { opacity: 0; }
body.entrando .negro { opacity: 1; transition: opacity 0.45s ease-in calc(var(--duracion-entrada) - 0.5s); }

@media (prefers-reduced-motion: reduce) {
  .titulo::before, .titulo::after { animation: none; }
  .fondo video { display: none; }
  body.entrando .fondo { transform: none; transition: none; }
  body.entrando .negro { transition: opacity 0.3s ease; }
  .titulo.error, .titulo.error::before, .titulo.error::after { animation: none; }
}

/* Poca altura (horizontal con el teclado abierto): sin titulo, y solo el campo y los botones, compactos. */
@media (max-height: 300px) {
  :root { --toque: 40px; }
  .puerta { justify-content: center; padding-top: 8px; padding-bottom: 8px; overflow-y: auto; }
  .titulo { display: none; }
  .formulario { gap: 6px; }
  .formulario label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .mensaje { min-height: 0; }
}
