/* =================================================================
   EXPEDIENTE V-01 — styles.css
   Mobile-first. Oscuro, elegante, misterioso. Estilo expediente
   futurista. Paleta: negro / rojo oscuro / blanco roto + acentos rojos.
   ================================================================= */

/* ---------- Variables de tema (edita aqui los colores) ---------- */
:root {
  --black:      #0a0a0a;
  --black-2:    #111110;
  --panel:      rgba(20, 14, 14, 0.55);
  --panel-line: rgba(225, 6, 0, 0.22);
  --red:        #e10600;   /* acento principal */
  --red-deep:   #7a0d0d;   /* rojo oscuro */
  --red-darkbg: #1c0606;   /* fondo final (rojo muy oscuro) */
  --bone:       #ece8e1;   /* blanco roto */
  --bone-dim:   #9a948c;   /* texto secundario */
  --bone-faint: rgba(236, 232, 225, 0.45);

  --font-head: 'Orbitron', 'Exo 2', system-ui, sans-serif;
  --font-body: 'Exo 2', system-ui, -apple-system, sans-serif;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --maxw: 32rem;

  /* Espaciado movil (safe areas + notch) */
  --pad-x: max(1.25rem, env(safe-area-inset-left), env(safe-area-inset-right));
  --pad-top: calc(env(safe-area-inset-top, 0px) + 4.25rem);
  --pad-bottom: calc(env(safe-area-inset-bottom, 0px) + 1.75rem);
  --touch: 52px;   /* altura minima botones en movil */
}

/* ---------- Reset basico ---------- */
*,
*::before,
*::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--black);
  color: var(--bone);
  line-height: 1.55;
  min-height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;          /* menos delay al tocar en movil */
  overscroll-behavior: none;
}

button { font-family: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input  { font-family: inherit; -webkit-tap-highlight-color: transparent; }

/* =================================================================
   Capas de ambiente (ruido, scanlines, viñeta)
   ================================================================= */
.fx-noise,
.fx-scanlines,
.fx-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.fx-noise {
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: screen;
}

.fx-scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.22) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  opacity: 0.35;
}

.fx-vignette {
  background: radial-gradient(120% 110% at 50% 40%, transparent 55%, rgba(0, 0, 0, 0.85) 100%);
  z-index: 3;
}

/* Flash rojo de error (se activa con accesodenegado) */
.fx-flash {
  background: radial-gradient(120% 120% at 50% 50%, rgba(225, 6, 0, 0.55), rgba(120, 0, 0, 0.25));
  opacity: 0;
  z-index: 9;
  mix-blend-mode: screen;
}

/* Lavado rojo del final (negro -> rojo oscuro). Se funde con GSAP. */
.fx-redwash {
  background: radial-gradient(120% 120% at 50% 0%, var(--red-darkbg) 0%, #120303 60%, #0a0202 100%);
  opacity: 0;
  z-index: 1;            /* detras de las pantallas (z-index 4) */
}

/* =================================================================
   HUD superior: barra de progreso de investigacion
   ================================================================= */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 6;
  padding: calc(env(safe-area-inset-top, 0px) + 0.75rem) 1rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}
.hud.is-visible { opacity: 1; transform: none; }

.hud__label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-head);
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  color: var(--bone-dim);
  text-transform: uppercase;
  min-width: 0;
}
#hudText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.hud__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
  animation: pulse 1.6s infinite;
}

.hud__bar {
  height: 2px;
  width: 100%;
  background: rgba(236, 232, 225, 0.12);
  overflow: hidden;
}

.hud__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--red-deep), var(--red));
  box-shadow: 0 0 10px var(--red);
  transition: width 0.8s var(--ease-out);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.35; transform: scale(0.8); }
}

/* =================================================================
   Boton de audio
   ================================================================= */
.sound-toggle {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 0.55rem);
  right: max(0.85rem, env(safe-area-inset-right));
  z-index: 7;
  background: rgba(10, 10, 10, 0.72);
  border: 1px solid var(--panel-line);
  color: var(--bone-dim);
  font-family: var(--font-head);
  font-size: 0.52rem;
  letter-spacing: 0.12em;
  padding: 0.5rem 0.65rem;
  border-radius: 3px;
  min-height: var(--touch);
  min-width: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.sound-toggle:hover,
.sound-toggle:active { color: var(--bone); border-color: var(--red); background: rgba(20, 10, 10, 0.9); }
.sound-toggle .sound-toggle__off { display: none; }
.sound-toggle.is-muted .sound-toggle__on  { display: none; }
.sound-toggle.is-muted .sound-toggle__off { display: inline; }

/* Ocultar boton AUDIO ON/OFF en movil */
@media (max-width: 767px) {
  .sound-toggle { display: none !important; }
}

/* =================================================================
   Estructura de pantallas (fases)
   ================================================================= */
.app {
  position: relative;
  height: 100%;
  min-height: 100dvh;
}

/* Pantallas: scroll suave si el contenido no cabe (informes, epilogo, clave) */
.screen {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: none;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: var(--pad-top) var(--pad-x) var(--pad-bottom);
}
.screen.is-active { display: block; }

.screen__inner {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: calc(100dvh - var(--pad-top) - var(--pad-bottom));
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.35rem;
}

/* =================================================================
   Tipografia y elementos comunes
   ================================================================= */
.kicker {
  font-family: var(--font-head);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--red);
  opacity: 0.9;
  max-width: 100%;
}
.kicker--danger { color: var(--red); }
.kicker--ok     { color: var(--bone); }

.title {
  font-family: var(--font-head);
  font-weight: 900;
  font-size: clamp(1.65rem, 8.5vw, 3.4rem);
  letter-spacing: 0.03em;
  line-height: 1.08;
  color: var(--bone);
  text-shadow: 0 0 22px rgba(225, 6, 0, 0.28);
  max-width: 100%;
  word-break: break-word;
  hyphens: auto;
}
.title--denied { color: var(--red); text-shadow: 0 0 26px rgba(225, 6, 0, 0.55); }

.lead {
  font-size: clamp(1rem, 4.2vw, 1.05rem);
  color: var(--bone);
  letter-spacing: 0.02em;
  line-height: 1.45;
  max-width: 22rem;
}

.fineprint,
.hint {
  font-size: 0.82rem;
  color: var(--bone-dim);
  max-width: 24rem;
}
.hint--muted { color: var(--bone-faint); font-style: italic; }
.fineprint   { font-size: 0.7rem; letter-spacing: 0.06em; opacity: 0.7; }

/* =================================================================
   Botones
   ================================================================= */
.btn {
  position: relative;
  font-family: var(--font-head);
  font-weight: 500;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--bone);
  background: transparent;
  border: 1px solid var(--red-deep);
  padding: 1rem 1.4rem;
  border-radius: 4px;
  width: 100%;
  max-width: 20rem;
  min-height: var(--touch);
  transition: background-color 0.2s var(--ease-out),
              border-color 0.2s var(--ease-out),
              color 0.2s var(--ease-out),
              box-shadow 0.2s var(--ease-out),
              transform 0.15s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn--primary {
  border-color: var(--red);
  background: rgba(225, 6, 0, 0.08);
  box-shadow: 0 0 0 rgba(225, 6, 0, 0);
}
.btn--primary:hover,
.btn--primary:focus-visible,
.btn--primary:active {
  background: rgba(225, 6, 0, 0.18);
  box-shadow: 0 0 26px rgba(225, 6, 0, 0.35);
  outline: none;
}

.btn--ghost { border-color: var(--panel-line); color: var(--bone-dim); }
.btn--ghost:hover,
.btn--ghost:focus-visible,
.btn--ghost:active { color: var(--bone); border-color: var(--red); outline: none; }

/* Feedback tactil en movil (sin hover) */
@media (hover: none) {
  .btn--primary:active { transform: scale(0.97); background: rgba(225, 6, 0, 0.22); }
  .btn--ghost:active   { transform: scale(0.97); }
}

.btn:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

/* Boton desactivado (durante la cuenta atras) */
.btn:disabled,
.btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(0.4);
  box-shadow: none;
}
.btn:disabled:hover { background: rgba(225, 6, 0, 0.08); }

/* =================================================================
   Pantalla de cuenta atras (bloqueo temporal)
   ================================================================= */
.lock {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 0.5rem;
}
.lock__msg {
  font-size: 0.92rem;
  color: var(--bone-dim);
  letter-spacing: 0.02em;
  line-height: 1.45;
  max-width: 18rem;
}
.countdown {
  font-family: var(--font-head);
  font-size: clamp(2.2rem, 12vw, 2.8rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--red);
  text-shadow: 0 0 28px rgba(225, 6, 0, 0.45);
  font-variant-numeric: tabular-nums;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  padding: 0.35rem 0;
  line-height: 1.1;
}
/* Solo si el navegador bloquea el audio: el contador se vuelve pulsable */

/* Q casi escondida (detalle sutil, sin explicacion) */
.q-mark {
  position: fixed;
  right: max(1.1rem, env(safe-area-inset-right));
  bottom: max(1.1rem, env(safe-area-inset-bottom));
  z-index: 4;
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--bone);
  opacity: 0.06;
  letter-spacing: 0.1em;
  pointer-events: none;
  user-select: none;
}

/* Boton huidizo: se mueve y nunca se deja pulsar */
.btn--runaway {
  border-color: var(--bone-faint);
  color: var(--bone-dim);
  will-change: transform, left, top;
  touch-action: none;
}
/* Cuando "escapa" se posiciona en coordenadas absolutas */
.btn--runaway.is-loose {
  position: fixed;
  z-index: 8;
  margin: 0;
  width: auto;
  max-width: calc(100vw - 24px);
  min-width: 10rem;
  min-height: var(--touch);
  font-size: 0.72rem;
  padding: 0.85rem 1.1rem;
}

/* =================================================================
   FASE 2 — tarjeta de informe
   ================================================================= */
.report-card {
  width: 100%;
  border: 1px solid var(--panel-line);
  border-left: 3px solid var(--red);
  background: var(--panel);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: 1.25rem 1.1rem;
  border-radius: 6px;
  text-align: left;
}
.report-meta {
  font-family: var(--font-head);
  font-size: 0.55rem;
  letter-spacing: 0.14em;
  color: var(--red);
  margin-bottom: 0.85rem;
}
.report-text {
  font-size: 1.18rem;
  color: var(--bone);
  min-height: 3.2em;
  line-height: 1.5;
}

/* =================================================================
   FASE 4 — procesamiento automatico + bloque de clave
   ================================================================= */
.proc {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  text-align: left;
}
.proc-bar {
  height: 3px;
  width: 100%;
  background: rgba(236, 232, 225, 0.12);
  border-radius: 2px;
  overflow: hidden;
}
.proc-bar__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--red-deep), var(--red));
  box-shadow: 0 0 10px var(--red);
}
.proc-result { color: var(--red); font-weight: 600; }

/* Fase 4: historia arriba, login debajo (sin centrar vertical en movil) */
.screen[data-screen="4"] .screen__inner {
  justify-content: flex-start;
  min-height: auto;
  padding-top: 0.5rem;
}

.keyblock {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.keyblock__story {
  width: 100%;
  max-width: 22rem;
  text-align: center;
}
.keyblock__story .kicker {
  margin-bottom: 1rem;
}

/* Historia centrada; primera linea = titulo ACCESO DENEGADO */
#keyStory {
  align-items: center;
  text-align: center;
}
#keyStory .ending__line {
  text-align: center;
}
#keyStory .ending__line:first-child {
  font-family: var(--font-head);
  font-size: clamp(1.35rem, 6.5vw, 1.9rem);
  font-weight: 900;
  color: var(--red);
  letter-spacing: 0.04em;
  line-height: 1.15;
  text-shadow: 0 0 22px rgba(225, 6, 0, 0.35);
  margin-bottom: 0.35rem;
}

.keyblock__login {
  width: 100%;
  max-width: 22rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--panel-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.keyblock__login[hidden] { display: none !important; }

/* =================================================================
   FASE 3 — teoria
   ================================================================= */
.theory-line { font-size: 1.05rem; color: var(--bone); }
.theory-line--big {
  font-family: var(--font-head);
  font-size: clamp(1.2rem, 6vw, 1.7rem);
  color: var(--bone);
  line-height: 1.25;
}
.theory-line--ask { color: var(--red); font-weight: 600; }

.choice {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  align-items: center;
  margin-top: 0.5rem;
}
.choice[hidden] { display: none !important; }
.choice--final { margin-top: 2.5rem; }

/* Fase 6 movil: solo botones, sin narrativa visible */
@media (max-width: 767px) {
  .screen[data-screen="6"].is-mobile-epilogue .kicker,
  .screen[data-screen="6"].is-mobile-epilogue #epilogueText {
    display: none !important;
  }
  .screen[data-screen="6"].is-mobile-epilogue .screen__inner {
    justify-content: center;
    gap: 1rem;
  }
  .screen[data-screen="6"] #epNo.btn--runaway:not(.is-loose) {
    font-size: 0.58rem;
    min-height: 38px;
    padding: 0.5rem 0.75rem;
    max-width: 11.5rem;
    width: auto;
    letter-spacing: 0.05em;
  }
  .screen[data-screen="6"].is-mobile-epilogue .choice {
    margin-top: 0;
  }
}

/* =================================================================
   FASE 4 — formulario de clave
   ================================================================= */
.key-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  max-width: 22rem;
  margin-top: 0;
}
.key-input {
  height: var(--touch);
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-line);
  border-radius: 4px;
  color: var(--bone);
  font-size: 16px;              /* evita zoom automatico en iOS al enfocar */
  letter-spacing: 0.06em;
  text-align: center;
  padding: 0 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
}
.key-input::placeholder { color: var(--bone-faint); letter-spacing: 0.04em; }
.key-input:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 18px rgba(225, 6, 0, 0.25);
}
.key-input.is-wrong,
.btn.is-wrong { animation: shake 0.4s; border-color: var(--red); }

.key-error {
  color: var(--red);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  line-height: 1.45;
  max-width: 20rem;
  text-align: center;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(5px); }
}

/* =================================================================
   FASE 5 — revelacion final
   ================================================================= */
.screen--final .kicker--ok { color: var(--bone); }

.ending {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  text-align: left;
  width: 100%;
}
/* Excepcion: fase seguridad centrada */
#keyStory.ending {
  text-align: center;
  align-items: center;
}
.ending__line {
  font-size: clamp(1rem, 4.1vw, 1.08rem);
  color: var(--bone);
  opacity: 0;                 /* GSAP las revela una a una */
  line-height: 1.55;
  word-break: break-word;
}
.ending__line--ps {
  margin-top: 0.8rem;
  font-size: 0.92rem;
  color: var(--bone-dim);
  font-style: italic;
  border-top: 1px solid var(--panel-line);
  padding-top: 1rem;
}
/* Cursor de "maquina de escribir" */
.caret {
  display: inline-block;
  width: 0.6ch;
  color: var(--red);
  animation: blink 0.9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* =================================================================
   Glitch del titulo (controlado, sutil)
   ================================================================= */
.glitch { position: relative; }
.glitch.is-glitching::before,
.glitch.is-glitching::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.glitch.is-glitching::before {
  color: var(--red);
  transform: translate(-2px, 0);
  clip-path: inset(0 0 55% 0);
  opacity: 0.8;
}
.glitch.is-glitching::after {
  color: #00e0d6;
  transform: translate(2px, 0);
  clip-path: inset(55% 0 0 0);
  opacity: 0.6;
}

/* =================================================================
   Movil pequeño (iPhone SE, etc.)
   ================================================================= */
@media (max-width: 380px) {
  :root {
    --pad-top: calc(env(safe-area-inset-top, 0px) + 3.75rem);
  }
  .title { font-size: 1.55rem; }
  .kicker { letter-spacing: 0.12em; }
  .countdown { font-size: 2rem; letter-spacing: 0.04em; }
  .btn { font-size: 0.72rem; letter-spacing: 0.08em; }
}

/* =================================================================
   Pantallas mas grandes (tablet / desktop)
   ================================================================= */
@media (min-width: 768px) {
  :root {
    --pad-x: 2rem;
    --pad-top: 5rem;
    --pad-bottom: 3rem;
    --touch: 48px;
  }
  .screen__inner { gap: 1.25rem; }
  .btn {
    width: auto;
    min-width: 12rem;
    letter-spacing: 0.14em;
  }
  .kicker { letter-spacing: 0.28em; font-size: 0.66rem; }
  .hud__label { font-size: 0.62rem; letter-spacing: 0.22em; }
  .report-card { padding: 1.5rem 1.25rem; }
  .report-text { font-size: 1.3rem; }
  .ending__line { font-size: 1.18rem; }
  .choice {
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
  }
  .choice .btn { width: auto; max-width: none; }
}

/* =================================================================
   Accesibilidad: respetar prefers-reduced-motion
   ================================================================= */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .fx-scanlines, .fx-noise { display: none; }
}
