/* ==========================================================================
   ANALIZADOR DE CRIPTOGRAMAS — descifrador.css
   "Fluid Glass" en Dark Mode: fondo casi negro con resplandores de color,
   paneles de cristal translúcidos y transiciones suaves entre fases.
   Mobile-first (pensado para proporciones tipo iPhone 16), escala a escritorio.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. RESET BÁSICO
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body, h1, h2, h3, p, ul { margin: 0; padding: 0; }

html { font-size: 100%; -webkit-text-size-adjust: 100%; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

a { color: inherit; }

textarea, select, input { font: inherit; color: inherit; }

ul { list-style: none; }

/* --------------------------------------------------------------------------
   2. TOKENS DE DISEÑO
   -------------------------------------------------------------------------- */
:root {
  /* Tipografía */
  --font-display: "Poppins", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  /* Texto */
  --text-primary: #f2f3fb;
  --text-secondary: #a6acce;
  --text-faint: rgba(242, 243, 251, .55);

  /* Fondo */
  --bg-deep: #060613;
  --bg-deep-2: #0c0a1f;

  /* Cristal */
  --glass: rgba(255, 255, 255, .055);
  --glass-strong: rgba(255, 255, 255, .09);
  --glass-border: rgba(255, 255, 255, .14);

  /* Acentos vibrantes (resplandor sobre fondo oscuro) */
  --accent: #8b7dff;   /* violeta — acciones primarias */
  --accent-2: #35e7c6; /* teal — zona polialfabética / éxito */
  --accent-3: #ff5da8; /* rosa — zona monoalfabética / énfasis */
  --focus-ring: #a99dff;

  /* Sombras */
  --shadow-1: 0 10px 34px rgba(0, 0, 0, .45);
  --shadow-2: 0 22px 55px rgba(0, 0, 0, .55);

  /* Radios */
  --radius-sm: .75rem;
  --radius-md: 1.25rem;
  --radius-lg: 1.75rem;
  --radius-pill: 999px;

  /* Espaciado */
  --space-1: .5rem;
  --space-2: .75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
}

/* --------------------------------------------------------------------------
   3. BASE DE PÁGINA Y RESPLANDORES DE FONDO
   -------------------------------------------------------------------------- */
body {
  min-height: 100svh;
  font-family: var(--font-body);
  color: var(--text-primary);
  line-height: 1.5;
  background:
    radial-gradient(circle at 50% -10%, var(--bg-deep-2), var(--bg-deep) 60%);
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.bg-glow span {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(90px);
  opacity: .3;
}

.bg-glow span:nth-child(1) { width: 46vw; height: 46vw; top: -14%; left: -12%; background: var(--accent); }
.bg-glow span:nth-child(2) { width: 40vw; height: 40vw; bottom: -16%; right: -10%; background: var(--accent-2); }
.bg-glow span:nth-child(3) { width: 30vw; height: 30vw; top: 42%; right: 18%; background: var(--accent-3); opacity: .2; }

/* --------------------------------------------------------------------------
   4. LAYOUT
   -------------------------------------------------------------------------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.page {
  min-height: 100svh;
  max-width: 880px;
  margin-inline: auto;
  padding: var(--space-5) var(--space-3);
  padding-bottom: max(var(--space-5), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.app-header {
  text-align: center;
  padding: 0 var(--space-2);
}

.app-header__back {
  display: inline-block;
  margin-bottom: var(--space-3);
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
}

.app-header__back:hover { color: var(--text-primary); }

.app-header__subtitle {
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

.phases {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

/* --------------------------------------------------------------------------
   5. TIPOGRAFÍA
   -------------------------------------------------------------------------- */
h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

h1 { font-size: clamp(1.6rem, 1.2rem + 2vw, 2.2rem); }
h2 { font-size: clamp(1.05rem, 1rem + .4vw, 1.25rem); margin-bottom: var(--space-4); }
h3 {
  font-size: .95rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-secondary);
  margin: var(--space-4) 0 var(--space-2);
}

/* --------------------------------------------------------------------------
   6. FASES (contenedor de animación) + TARJETA DE CRISTAL
   -------------------------------------------------------------------------- */
.phase {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  overflow: hidden;
  transition: grid-template-rows .5s ease, opacity .4s ease;
}

.phase.is-active {
  grid-template-rows: 1fr;
  opacity: 1;
}

.glass-card {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  padding: var(--space-5);
}

.glass-card::before {
  content: "";
  position: absolute;
  top: 0; left: 12%; right: 12%;
  height: 3px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3));
}

/* --------------------------------------------------------------------------
   7. FASE 1 — ENTRADA
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }

.input-mono {
  font-family: var(--font-mono);
  font-size: 1rem;
  letter-spacing: .03em;
  resize: vertical;
  min-height: 9rem;
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  color: var(--text-primary);
}

.input-mono::placeholder { color: var(--text-faint); font-family: var(--font-body); }

.input-mono:focus-visible {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px rgba(169, 157, 255, .3);
}

.hint {
  font-size: .85rem;
  color: var(--text-faint);
  margin: var(--space-2) 0 var(--space-4);
}

/* --------------------------------------------------------------------------
   8. FASE 2 — DIAGNÓSTICO (medidor de IC + frecuencias)
   -------------------------------------------------------------------------- */
.ic-readout {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.ic-value {
  font-family: var(--font-mono);
  font-size: clamp(2rem, 1.6rem + 1.5vw, 2.6rem);
  font-weight: 700;
  color: var(--accent-2);
}

.ic-label {
  color: var(--text-secondary);
  font-size: .9rem;
}

.ic-gauge__track {
  position: relative;
  height: .55rem;
  border-radius: var(--radius-pill);
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
}

.ic-gauge__zone {
  position: absolute;
  top: -1px; bottom: -1px;
  border-radius: var(--radius-pill);
}

.ic-gauge__zone--poly { left: 35%; width: 15%; background: rgba(53, 231, 198, .35); }
.ic-gauge__zone--mono { left: 60%; width: 25%; background: rgba(255, 93, 168, .35); }

.ic-gauge__marker {
  position: absolute;
  top: 50%;
  left: 0;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: var(--text-primary);
  box-shadow: 0 0 0 4px rgba(242, 243, 251, .18), var(--shadow-1);
  transform: translate(-50%, -50%);
  transition: left .6s ease;
}

.ic-gauge__scale {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: .75rem;
  color: var(--text-faint);
  margin-top: var(--space-1);
}

.freq-list { display: flex; flex-direction: column; gap: var(--space-2); }

.freq-item {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto;
  align-items: center;
  gap: var(--space-2);
}

.freq-item__letter {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-primary);
}

.freq-item__bar {
  display: block;
  height: .45rem;
  border-radius: var(--radius-pill);
  background: var(--glass-strong);
  overflow: hidden;
}

.freq-item__bar span {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.freq-item__count {
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   9. FASE 3 — ENRUTAMIENTO
   -------------------------------------------------------------------------- */
.suggestion {
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

.manual-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--glass-border);
}

.field label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.field select {
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: .7rem .9rem;
  color: var(--text-primary);
}

.field select:focus-visible {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px rgba(169, 157, 255, .3);
}

/* --------------------------------------------------------------------------
   10. FASE 4 — RESULTADO
   -------------------------------------------------------------------------- */
.result-method {
  font-weight: 600;
  color: var(--accent-2);
  margin-bottom: var(--space-3);
}

.result-key,
.result-text {
  font-family: var(--font-mono);
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  white-space: pre-wrap;
  word-break: break-word;
}

.result-key {
  color: var(--accent-3);
  font-weight: 700;
  margin-bottom: var(--space-3);
}

.result-text {
  color: var(--text-primary);
  max-height: 16rem;
  overflow-y: auto;
  margin-bottom: var(--space-5);
}

/* --------------------------------------------------------------------------
   11. BOTONES
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  min-height: 3rem;
  padding: .85rem 1.75rem;
  border-radius: var(--radius-pill);
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }

.btn:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

.btn--block { width: 100%; }
.btn--lg { min-height: 3.25rem; font-size: 1.05rem; }

.btn--primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-3));
  color: #ffffff;
  box-shadow: var(--shadow-1);
}

.btn--primary:hover { box-shadow: var(--shadow-2); }

.btn--primary:disabled {
  opacity: .4;
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

.btn--outline {
  background: var(--glass-strong);
  border: 1.5px solid var(--glass-border);
  color: var(--text-primary);
}

.btn--outline:hover { border-color: var(--text-primary); }

/* --------------------------------------------------------------------------
   12. RESPONSIVE — escala a escritorio (mobile-first)
   -------------------------------------------------------------------------- */
@media (min-width: 900px) {
  .page { max-width: 1040px; }

  .phases {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    grid-auto-flow: column;
    align-items: start;
  }

  .glass-card { padding: var(--space-6); }

  .manual-controls { grid-template-columns: 1fr 1fr; }
}

/* --------------------------------------------------------------------------
   13. PREFERENCIAS DE ACCESIBILIDAD
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .phase, .btn, .ic-gauge__marker {
    transition: none;
  }
}