:root {
  --bg: #0b0b12;
  --bg-elevada: #17161f;
  --bg-elevada-2: #1f1e29;
  --borde: #2a2836;
  --texto: #f5f5f7;
  --texto-suave: #a5a3b3;
  --tabu: #ff5a36;
  --mimicas: #7c5cff;
  --impostor: #e11d48;
  --trivial: #eab308;
  --timesup: #38bdf8;
  --verde: #22c55e;
  --ambar: #f5a524;
  --rojo: #ef4444;
  --oro: #ffcc4d;
  --radius-l: 28px;
  --radius-m: 18px;
  --radius-s: 12px;
  --fuente-display: "Bricolage Grotesque", system-ui, sans-serif;
  --fuente-cuerpo: "Hanken Grotesk", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--texto);
  font-family: var(--fuente-cuerpo);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  background-image:
    radial-gradient(circle at 15% 0%, rgba(255, 90, 54, 0.12), transparent 45%),
    radial-gradient(circle at 90% 10%, rgba(124, 92, 255, 0.14), transparent 45%);
}

h1, h2, h3 {
  font-family: var(--fuente-display);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

button { font-family: var(--fuente-cuerpo); }
input { font-family: var(--fuente-cuerpo); }

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  gap: 16px;
  animation: aparecer 0.22s ease both;
}
.screen.activa { display: flex; }

@keyframes aparecer {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.pantalla-centrada {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
}

/* --- Marca / entrada --- */
.marca { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.marca-emoji {
  font-size: 52px;
  line-height: 1;
  filter: drop-shadow(0 8px 20px rgba(124, 92, 255, 0.35));
  animation: flotar 3.2s ease-in-out infinite;
}
.marca h1 {
  font-size: 34px;
  background: linear-gradient(120deg, #fff 30%, var(--mimicas) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitulo { color: var(--texto-suave); margin: 0 0 8px; font-size: 15px; }

@keyframes flotar {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-6px) rotate(2deg); }
}

.tarjeta-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-elevada);
  border: 1px solid var(--borde);
  border-radius: var(--radius-l);
  padding: 20px;
  box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.6);
}
.tarjeta-form label { font-size: 14px; color: var(--texto-suave); text-align: left; }
.tarjeta-form input {
  background: var(--bg-elevada-2);
  border: 1px solid var(--borde);
  border-radius: var(--radius-s);
  padding: 14px 16px;
  color: var(--texto);
  font-size: 17px;
  outline: none;
}
.tarjeta-form input:focus { border-color: var(--mimicas); }

.nota-pie { color: var(--texto-suave); font-size: 13px; max-width: 340px; line-height: 1.5; }

/* --- Botones --- */
.btn {
  border: none;
  border-radius: 999px;
  padding: 16px 24px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn-ancho { width: 100%; }
.btn-primario {
  background: linear-gradient(135deg, var(--tabu), var(--mimicas));
  color: #fff;
  box-shadow: 0 14px 28px -12px rgba(124, 92, 255, 0.55);
}
.btn-secundario { background: var(--bg-elevada); color: var(--texto); border: 1px solid var(--borde); }
.btn-icono {
  background: var(--bg-elevada);
  border: 1px solid var(--borde);
  color: var(--texto);
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.btn-icono:active { transform: scale(0.92); }
.btn-enlace {
  background: none; border: none; color: var(--texto-suave);
  font-size: 14px; text-decoration: underline; cursor: pointer; padding: 8px;
}

/* --- Hub --- */
.cabecera-hub { display: flex; align-items: flex-start; justify-content: space-between; padding-top: 6px; }
.saludo { margin: 0; color: var(--texto-suave); font-size: 14px; }
.cabecera-hub h1 { font-size: 26px; }

.grid-juegos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}

.tarjeta-juego {
  --acento: var(--mimicas);
  position: relative;
  aspect-ratio: 1 / 1.05;
  border-radius: var(--radius-m);
  border: 1px solid var(--borde);
  background: linear-gradient(160deg, color-mix(in srgb, var(--acento) 28%, var(--bg-elevada)), var(--bg-elevada));
  box-shadow: 0 16px 30px -18px color-mix(in srgb, var(--acento) 60%, transparent);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  color: var(--texto);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.tarjeta-juego:active { transform: scale(0.97); }
.tarjeta-juego .emoji {
  font-size: 34px;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}
.tarjeta-juego .nombre { font-family: var(--fuente-display); font-weight: 700; font-size: 18px; }
.tarjeta-juego .desc { font-size: 12px; color: var(--texto-suave); line-height: 1.35; }

.tarjeta-juego--proximamente {
  opacity: 0.55;
  background: var(--bg-elevada);
  cursor: default;
}
.tarjeta-juego--proximamente:active { transform: none; }
.badge-proximamente {
  position: absolute; top: 12px; right: 12px;
  background: var(--bg-elevada-2);
  border: 1px solid var(--borde);
  color: var(--texto-suave);
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- Cabeceras simples --- */
.cabecera-simple { display: flex; align-items: center; gap: 12px; }
.cabecera-simple h2 { font-size: 20px; }

/* --- Config --- */
.config-bloque { display: flex; flex-direction: column; gap: 10px; }
.config-bloque h3 { font-size: 14px; color: var(--texto-suave); text-transform: uppercase; letter-spacing: 0.04em; }

.stepper { display: flex; align-items: center; gap: 18px; }
.btn-stepper {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--borde); background: var(--bg-elevada);
  color: var(--texto); font-size: 20px; cursor: pointer;
}
.stepper span { font-size: 20px; font-weight: 700; min-width: 20px; text-align: center; }

.lista-equipos { display: flex; flex-direction: column; gap: 8px; }
.equipo-input {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elevada);
  border: 1px solid var(--borde);
  border-radius: var(--radius-s);
  padding: 10px 14px;
}
.equipo-input .punto-color { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.equipo-input input {
  flex: 1; background: none; border: none; color: var(--texto);
  font-size: 15px; outline: none;
}

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--bg-elevada);
  border: 1px solid var(--borde);
  color: var(--texto-suave);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: color-mix(in srgb, var(--mimicas) 30%, var(--bg-elevada));
  border-color: var(--mimicas);
  color: var(--texto);
  font-weight: 700;
}

/* --- Transición de turno --- */
.turno-label { color: var(--texto-suave); font-size: 15px; margin: 0; }
.turno-equipo {
  font-size: 40px;
  margin: 0;
  animation: aparecer-rebote 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}
.turno-puntos { color: var(--texto-suave); margin: 0 0 10px; }

@keyframes aparecer-rebote {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

/* --- Juego --- */
.screen-juego { padding-top: max(14px, env(safe-area-inset-top)); }
.cabecera-juego {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--fuente-display); font-weight: 700;
}
#juego-equipo-actual { font-size: 15px; color: var(--texto-suave); }
.juego-tiempo { font-size: 26px; }
.juego-tiempo.tiempo-urgente { color: var(--rojo); }
#juego-puntos-turno { font-size: 20px; }

.barra-tiempo { height: 6px; border-radius: 999px; background: var(--bg-elevada); overflow: hidden; }
.barra-tiempo-relleno {
  height: 100%; width: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--mimicas), var(--tabu));
  transition: width 1s linear;
}
.barra-tiempo-relleno.tiempo-urgente { background: var(--rojo); }

.carta {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  background: var(--bg-elevada);
  border: 1px solid var(--borde);
  border-radius: var(--radius-l);
  padding: 28px 20px;
  text-align: center;
  box-shadow: 0 24px 48px -24px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
}
.carta-categoria {
  color: var(--texto-suave);
  font-size: 13px;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.carta-palabra {
  font-family: var(--fuente-display);
  font-size: clamp(32px, 9vw, 46px);
  font-weight: 800;
  margin: 0;
  line-height: 1.1;
  animation: carta-entra 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
.carta-prohibidas {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.carta-prohibidas li {
  color: var(--rojo);
  font-size: 16px;
  font-weight: 600;
  padding-top: 8px;
  border-top: 1px dashed var(--borde);
}
.carta-prohibidas li:first-child { border-top: none; padding-top: 0; }

@keyframes carta-entra {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.botonera-juego { display: flex; gap: 12px; }
.botonera-juego .btn { flex: 1; font-size: 17px; padding: 18px; }
.btn-pasar { background: var(--bg-elevada-2); color: var(--texto); border: 1px solid var(--borde); }
.btn-acierto { background: var(--verde); color: #06210f; box-shadow: 0 14px 26px -14px rgba(34, 197, 94, 0.6); }
.btn-peligro { background: var(--impostor, var(--rojo)); color: #fff; box-shadow: 0 14px 26px -14px rgba(225, 29, 72, 0.55); }

.carta-pregunta {
  font-family: var(--fuente-display);
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 700;
  line-height: 1.35;
  margin: 0;
}
.trivial-respuesta-label {
  color: var(--texto-suave);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 18px 0 6px;
}

.carta-impostor {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  gap: 14px;
}

/* --- Resultado --- */
.tabla-resultado {
  width: 100%;
  display: flex; flex-direction: column; gap: 8px;
  margin: 8px 0;
}
.fila-resultado {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-elevada);
  border: 1px solid var(--borde);
  border-radius: var(--radius-s);
  padding: 12px 16px;
  font-size: 15px;
}
.fila-resultado.ganador {
  border-color: var(--oro);
  background: color-mix(in srgb, var(--oro) 14%, var(--bg-elevada));
  box-shadow: 0 12px 24px -16px rgba(255, 204, 77, 0.5);
}
.fila-resultado .nombre { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.fila-resultado .puntos { font-family: var(--fuente-display); font-weight: 800; font-size: 18px; }

/* --- Modal de confirmación --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 6, 10, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  padding: 20px;
  animation: modal-fondo 0.18s ease both;
}
.modal-overlay[hidden] { display: none; }
@keyframes modal-fondo { from { opacity: 0; } to { opacity: 1; } }

.modal-caja {
  width: 100%;
  max-width: 460px;
  background: var(--bg-elevada);
  border: 1px solid var(--borde);
  border-radius: var(--radius-l);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  box-shadow: 0 -20px 50px -20px rgba(0, 0, 0, 0.7);
  animation: modal-sube 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
  margin-bottom: env(safe-area-inset-bottom);
}
@keyframes modal-sube {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-caja p { font-size: 16px; font-weight: 600; margin: 0; }
.modal-botones { display: flex; flex-direction: column; gap: 10px; }

/* --- Histórico --- */
.titulo-seccion { font-size: 15px; color: var(--texto-suave); margin: 10px 0 0; }
.bloque-historico { display: flex; flex-direction: column; gap: 8px; }
.historico-vacio { color: var(--texto-suave); font-size: 14px; padding: 12px 0; }
.ranking-item, .partida-item {
  background: var(--bg-elevada);
  border: 1px solid var(--borde);
  border-radius: var(--radius-s);
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px;
}
.partida-item .meta { color: var(--texto-suave); font-size: 12px; }

/* --- Flash de feedback --- */
.flash {
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 50;
}
.flash.activo { animation: flash-fade 0.4s ease; }
.flash.verde { background: var(--verde); }
.flash.ambar { background: var(--ambar); }
.flash.rojo { background: var(--rojo); }
@keyframes flash-fade {
  0% { opacity: 0.55; }
  100% { opacity: 0; }
}

@media (min-width: 560px) {
  #app { border-left: 1px solid var(--borde); border-right: 1px solid var(--borde); }
}
