/* Frikile — terminal CRT de recreativa. Móvil primero. */
:root {
  --fondo: #050a07;
  --fondo-2: #0b140f;
  --panel: #0e1a13;
  --linea: #1f3a2a;
  --texto: #c8f5d6;
  --tenue: #7fa98d;
  --fosforo: #3dff8a;
  --fosforo-osc: #04140a;
  --ambar: #ffb627;
  --ambar-osc: #1c1203;
  --gris: #1d2a22;
  --gris-texto: #8da596;
  --peligro: #ff5d73;
  --brillo: 0 0 6px rgb(61 255 138 / 0.55), 0 0 18px rgb(61 255 138 / 0.25);
  --f-logo: "Press Start 2P", ui-monospace, monospace;
  --f-pixel: "VT323", ui-monospace, monospace;
  --f-texto: "IBM Plex Mono", ui-monospace, monospace;
  --cols: 5;
  --hueco: 6px;
  --casilla: min(3.6rem, calc((min(100vw, 30rem) - 2rem - (var(--cols) - 1) * var(--hueco)) / var(--cols)), 7.4dvh);
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 120% 70% at 50% 0%, #0f2a1b 0%, transparent 60%),
    radial-gradient(ellipse 80% 50% at 50% 110%, #1a1405 0%, transparent 70%),
    var(--fondo);
  color: var(--texto);
  font-family: var(--f-texto);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--fosforo); }
:focus-visible { outline: 2px dashed var(--ambar); outline-offset: 3px; }

/* ───── Capa CRT: scanlines + viñeta + parpadeo sutil ───── */
.crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background:
    repeating-linear-gradient(to bottom, rgb(0 0 0 / 0) 0 2px, rgb(0 0 0 / 0.22) 2px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgb(0 0 0 / 0.6) 100%);
  animation: parpadeo 6s infinite steps(1);
}
@keyframes parpadeo {
  0%, 100% { opacity: 1; }
  47% { opacity: 0.92; }
  48% { opacity: 1; }
}

.app {
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 1rem 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  animation: encendido 0.7s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes encendido {
  0% { opacity: 0; transform: scaleY(0.02); filter: brightness(3); }
  60% { opacity: 1; transform: scaleY(1.02); filter: brightness(1.6); }
  100% { transform: none; filter: none; }
}

/* ───── Cabecera ───── */
.barra {
  display: grid;
  grid-template-columns: 2.6rem 1fr 2.6rem;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.6rem;
  border-bottom: 2px solid var(--linea);
}
.marca { text-align: center; }
.logo {
  margin: 0;
  font-family: var(--f-logo);
  font-size: clamp(1.15rem, 6vw, 1.6rem);
  letter-spacing: 0.08em;
  color: var(--fosforo);
  text-shadow: var(--brillo), 2px 0 0 rgb(255 182 39 / 0.35), -2px 0 0 rgb(61 160 255 / 0.25);
}
.logo span { color: var(--ambar); text-shadow: 0 0 8px rgb(255 182 39 / 0.6); }
.numero {
  margin: 0.35rem 0 0;
  font-family: var(--f-pixel);
  font-size: 1.6rem;
  line-height: 1;
  color: var(--tenue);
}
.cursor { animation: cursor 1s steps(1) infinite; color: var(--fosforo); }
@keyframes cursor { 50% { opacity: 0; } }

.icono {
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 2px solid var(--linea);
  border-radius: 4px;
  font-family: var(--f-logo);
  font-size: 0.9rem;
  color: var(--fosforo);
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 0.5);
  transition: border-color .15s, transform .08s;
}
.icono svg { width: 1.1rem; height: 1.1rem; }
.icono:hover { border-color: var(--fosforo); }
.icono:active { transform: translateY(2px); }

.categoria {
  margin: 0.7rem auto 0;
  padding: 0.2rem 0.7rem;
  font-family: var(--f-pixel);
  font-size: 1.35rem;
  line-height: 1.2;
  text-align: center;
  color: var(--ambar);
  border: 1px dashed rgb(255 182 39 / 0.45);
  border-radius: 3px;
  background: rgb(255 182 39 / 0.06);
  max-width: 100%;
}

/* ───── Tablero ───── */
.juego {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 0.9rem 0;
}
.tablero {
  display: grid;
  grid-template-rows: repeat(6, var(--casilla));
  gap: var(--hueco);
}
.fila {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--casilla));
  gap: var(--hueco);
}
.fila.tiembla { animation: tiembla 0.45s linear; }
@keyframes tiembla {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.casilla {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--casilla);
  height: var(--casilla);
  font-family: var(--f-pixel);
  font-size: calc(var(--casilla) * 0.78);
  line-height: 1;
  text-transform: uppercase;
  color: var(--texto);
  background: var(--fondo-2);
  border: 2px solid var(--linea);
  border-radius: 3px;
  user-select: none;
}
.casilla[data-estado="lleno"] {
  border-color: var(--tenue);
  color: var(--fosforo);
  text-shadow: var(--brillo);
  animation: pop 0.1s ease-out;
}
.fila.activa .casilla:not([data-estado]) { border-color: #2c5a3f; }
@keyframes pop { 50% { transform: scale(1.1); } }

/* Colores + patrón alternativo para daltonismo:
   verde = relleno sólido con muesca; ámbar = rayado diagonal; gris = apagado sin brillo */
.casilla[data-color="verde"] {
  background: var(--fosforo);
  border-color: var(--fosforo);
  color: var(--fosforo-osc);
  text-shadow: none;
  box-shadow: 0 0 14px rgb(61 255 138 / 0.45);
}
.casilla[data-color="verde"]::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18%;
  height: 18%;
  background: var(--fosforo-osc);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}
.casilla[data-color="amarillo"] {
  background:
    repeating-linear-gradient(135deg, rgb(255 182 39 / 0.28) 0 4px, transparent 4px 9px),
    var(--ambar-osc);
  border: 2px dashed var(--ambar);
  color: var(--ambar);
  text-shadow: 0 0 6px rgb(255 182 39 / 0.6);
}
.casilla[data-color="gris"] {
  background: var(--gris);
  border-color: var(--gris);
  color: var(--gris-texto);
  text-shadow: none;
}
.casilla.gira { animation: gira 0.5s ease-in-out both; }
@keyframes gira {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); filter: brightness(2); }
  100% { transform: rotateX(0); }
}
.casilla.salta { animation: salta 0.5s ease both; }
@keyframes salta {
  40% { transform: translateY(-30%); }
  60% { transform: translateY(5%); }
}

/* ───── Oráculo ───── */
.oraculo {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: linear-gradient(180deg, rgb(255 182 39 / 0.08), rgb(255 182 39 / 0.02));
  border: 1px solid rgb(255 182 39 / 0.4);
  border-left: 4px solid var(--ambar);
  border-radius: 3px;
  animation: aparece 0.4s ease both;
}
.oraculo h2 {
  margin: 0 0 0.3rem;
  font-family: var(--f-pixel);
  font-size: 1.3rem;
  font-weight: 400;
  color: var(--ambar);
}
.oraculo ol { margin: 0; padding-left: 1.3rem; font-size: 0.9rem; }
.oraculo li + li { margin-top: 0.25rem; }
.oraculo li::marker { color: var(--ambar); font-family: var(--f-pixel); }
@keyframes aparece { from { opacity: 0; transform: translateY(6px); } }

/* ───── Teclado ───── */
.teclado {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0.4rem 0 max(0.8rem, env(safe-area-inset-bottom));
  user-select: none;
  touch-action: manipulation;
}
.teclado.bloqueado { opacity: 0.45; pointer-events: none; }
.teclado-fila { display: flex; gap: 5px; }
.tecla {
  flex: 1 1 0;
  min-width: 0;
  height: 3.3rem;
  padding: 0;
  font-family: var(--f-pixel);
  font-size: 1.55rem;
  line-height: 1;
  color: var(--texto);
  background: var(--panel);
  border: 1px solid var(--linea);
  border-radius: 4px;
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / 0.45);
  transition: background .2s, transform .06s;
}
.tecla.ancha { flex-grow: 1.55; font-size: clamp(0.85rem, 3.6vw, 1.1rem); letter-spacing: 0.02em; }
.tecla[data-accion="borrar"] { font-size: 1.4rem; }
.tecla:active, .tecla.pulsada { transform: translateY(2px); box-shadow: inset 0 -1px 0 rgb(0 0 0 / 0.45); }
.tecla[data-color="verde"] { background: var(--fosforo); color: var(--fosforo-osc); border-color: var(--fosforo); }
.tecla[data-color="amarillo"] {
  background: repeating-linear-gradient(135deg, rgb(255 182 39 / 0.3) 0 4px, transparent 4px 9px), var(--ambar-osc);
  color: var(--ambar);
  border: 1px dashed var(--ambar);
}
.tecla[data-color="gris"] { background: #0a100c; color: #4f6858; border-color: #121c16; text-decoration: line-through; text-decoration-thickness: 1px; }

/* ───── Botones ───── */
.boton {
  display: block;
  width: 100%;
  padding: 0.85rem 1rem;
  font-family: var(--f-logo);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--fosforo-osc);
  background: var(--fosforo);
  border: none;
  border-radius: 3px;
  box-shadow: 0 4px 0 #17803f, var(--brillo);
  transition: transform .06s, box-shadow .06s;
}
.boton:active { transform: translateY(3px); box-shadow: 0 1px 0 #17803f; }
.boton.mini { width: auto; padding: 0.6rem 0.8rem; font-size: 0.6rem; }

/* ───── Toasts ───── */
.toasts {
  position: fixed;
  top: 5.2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  pointer-events: none;
}
.toast {
  padding: 0.55rem 0.9rem;
  font-family: var(--f-pixel);
  font-size: 1.3rem;
  line-height: 1.15;
  text-align: center;
  color: var(--fosforo-osc);
  background: var(--texto);
  border-radius: 3px;
  box-shadow: 4px 4px 0 rgb(0 0 0 / 0.6);
  animation: aparece 0.18s ease both;
}
.toast.error { background: var(--peligro); color: #1a0306; }
.toast.aviso { background: var(--ambar); color: var(--ambar-osc); }
.toast.fuera { opacity: 0; transition: opacity .3s; }

/* ───── Modales ───── */
.modal {
  width: min(28rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 1.4rem 1.1rem 1.2rem;
  overflow-y: auto;
  color: var(--texto);
  background:
    repeating-linear-gradient(to bottom, transparent 0 3px, rgb(61 255 138 / 0.02) 3px 4px),
    var(--fondo-2);
  border: 2px solid var(--fosforo);
  border-radius: 4px;
  box-shadow: 0 0 0 4px var(--fondo), 0 0 0 6px var(--linea), 0 0 40px rgb(61 255 138 / 0.2);
}
.modal:focus, .modal h2:focus { outline: none; }
.modal[open] { animation: modal 0.25s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes modal { from { opacity: 0; transform: translateY(12px) scale(0.97); } }
.modal::backdrop { background: rgb(2 6 4 / 0.82); backdrop-filter: blur(2px); }
.modal h2 {
  margin: 0 0 0.9rem;
  font-family: var(--f-logo);
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--fosforo);
  text-shadow: var(--brillo);
}
.modal p { margin: 0.6rem 0; font-size: 0.9rem; }
.modal strong { color: var(--fosforo); font-weight: 600; }
.cerrar {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  width: 2.2rem;
  height: 2.2rem;
  background: none;
  border: none;
  font-family: var(--f-pixel);
  font-size: 2rem;
  line-height: 1;
  color: var(--tenue);
}
.cerrar:hover { color: var(--fosforo); }

.ejemplo { display: flex; gap: 5px; margin: 0.8rem 0; --casilla: 2.6rem; }
.leyenda { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.leyenda li { display: flex; align-items: center; gap: 0.6rem; margin: 0.4rem 0; }
.casilla.mini { --casilla: 1.9rem; flex: none; }
.nota { color: var(--tenue); font-size: 0.8rem !important; }

/* Final */
.final-titulo { text-align: center; font-size: 1.2rem !important; }
.final-titulo.ganada { color: var(--fosforo); }
.final-titulo.perdida { color: var(--peligro); text-shadow: 0 0 8px rgb(255 93 115 / 0.5); }
.final-sub { text-align: center; color: var(--tenue); margin-top: -0.4rem !important; }
.palabra-final {
  margin: 0.8rem 0 0.4rem !important;
  text-align: center;
  font-family: var(--f-pixel);
  font-size: 3rem !important;
  line-height: 1;
  letter-spacing: 0.2em;
  color: var(--ambar);
  text-shadow: 0 0 12px rgb(255 182 39 / 0.55);
}
.definicion { text-align: center; font-style: italic; color: var(--texto); }
.compartir-preview {
  margin: 1rem auto 0.7rem;
  padding: 0.6rem 0.8rem;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  font-family: var(--f-texto);
  font-size: 0.85rem;
  line-height: 1.35;
  background: var(--fondo);
  border: 1px dashed var(--linea);
  border-radius: 3px;
}
.proxima {
  text-align: center;
  font-family: var(--f-pixel);
  font-size: 1.3rem !important;
  color: var(--tenue);
}
#cuenta-atras { color: var(--fosforo); text-shadow: var(--brillo); }

.alias {
  margin: 1rem 0;
  padding-top: 0.8rem;
  border-top: 2px dotted var(--linea);
}
.alias label { display: block; font-size: 0.8rem; color: var(--tenue); margin-bottom: 0.3rem; }
.alias-fila { display: flex; gap: 0.5rem; }
.alias input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  font-family: var(--f-pixel);
  font-size: 1.4rem;
  color: var(--fosforo);
  background: var(--fondo);
  border: 2px solid var(--linea);
  border-radius: 3px;
}
.alias input:focus { border-color: var(--fosforo); outline: none; }
.alias input[aria-invalid="true"] { border-color: var(--peligro); }
.alias small { display: block; margin-top: 0.25rem; font-size: 0.7rem; color: var(--tenue); }

/* Ranking */
.pestanas { display: flex; gap: 0; margin-bottom: 0.6rem; border-bottom: 2px solid var(--linea); }
.pestanas button {
  flex: 1;
  padding: 0.55rem 0;
  font-family: var(--f-logo);
  font-size: 0.65rem;
  color: var(--tenue);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.pestanas button[aria-selected="true"] { color: var(--ambar); border-bottom-color: var(--ambar); }
.tabla { width: 100%; border-collapse: collapse; font-family: var(--f-pixel); font-size: 1.3rem; line-height: 1.15; }
.tabla th { font-weight: 400; text-align: left; color: var(--tenue); font-size: 1rem; padding: 0.2rem 0.3rem; }
.tabla td { padding: 0.2rem 0.3rem; border-top: 1px solid rgb(31 58 42 / 0.6); }
.tabla td:first-child, .tabla th:first-child { width: 2.2rem; color: var(--ambar); }
.tabla td:nth-child(2) { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabla td:nth-child(n+3), .tabla th:nth-child(n+3) { text-align: right; white-space: nowrap; }
.tabla tr.yo td { color: var(--fosforo); text-shadow: var(--brillo); }
.tabla tbody tr:nth-child(1) td:first-child { color: var(--fosforo); }
.vacio { text-align: center; color: var(--tenue); font-size: 0.85rem; }

/* ───── Mantenimiento ───── */
.mantenimiento {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.5rem;
  text-align: center;
  background: var(--fondo);
}
.mantenimiento[hidden] { display: none; }
.mantenimiento pre { margin: 0; font-family: var(--f-texto); color: var(--peligro); font-size: 0.85rem; line-height: 1.15; text-shadow: 0 0 8px rgb(255 93 115 / 0.5); }
.mantenimiento h2 { margin: 0.5rem 0 0; font-family: var(--f-logo); font-size: 0.9rem; line-height: 1.6; color: var(--peligro); }
.mantenimiento p { margin: 0 0 0.8rem; color: var(--tenue); max-width: 22rem; }
.mantenimiento .boton { width: auto; }

.pie { padding: 0.4rem 1rem 1rem; text-align: center; font-size: 0.7rem; color: #4f6858; }
.pie p { margin: 0; }

@media (min-width: 640px) {
  .app { padding-top: 1.4rem; }
  .tecla { height: 3.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
