:root {
  --teal: #2a9689;
  --teal-claro: #3ddc97;
  --fondo: #0b1216;
  --panel: #121d22;
  --tecla: #1b2a31;
  --tecla-borde: #26383f;
  --texto: #eaf4f2;
  --apagado: #7e969b;
  --error: #e2574c;
  --radio: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--fondo);
  color: var(--texto);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100dvh;
}

.tarjeta {
  width: 100%;
  max-width: 440px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--fondo);
}

.pantalla { display: none; flex-direction: column; gap: 14px; flex: 1; min-height: 0; }
.pantalla.activa { display: flex; }
.oculto { display: none !important; }

/* ---------- marca ---------- */
.marca { text-align: center; margin-top: 8px; }
.marca h1 {
  margin: 0;
  font-size: clamp(2.4rem, 13vw, 3.4rem);
  letter-spacing: -0.03em;
  font-weight: 800;
  color: var(--texto);
}
.marca h1 span { color: var(--teal); }
.marca p { margin: 6px 0 0; color: var(--apagado); font-size: 0.95rem; line-height: 1.35; }

/* ---------- botones ---------- */
.boton {
  appearance: none;
  border: 1px solid var(--tecla-borde);
  background: var(--tecla);
  color: var(--texto);
  font: inherit;
  font-weight: 600;
  padding: 14px 16px;
  border-radius: var(--radio);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.boton:active { transform: scale(0.985); background: #22343c; }
.boton.principal { background: var(--teal); border-color: var(--teal); color: #04211d; font-size: 1.1rem; }
.boton.principal:active { background: #34ab9c; }
.boton:disabled { opacity: 0.45; cursor: not-allowed; }

.fila { display: flex; gap: 10px; }
.fila > * { flex: 1; }

.enlace {
  appearance: none;
  background: none;
  border: none;
  color: var(--apagado);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 8px;
}

/* ---------- campos ---------- */
.campo {
  width: 100%;
  padding: 14px;
  border-radius: var(--radio);
  border: 1px solid var(--tecla-borde);
  background: var(--panel);
  color: var(--texto);
  font: inherit;
  text-align: center;
  letter-spacing: 0.06em;
}
.campo::placeholder { color: #55707a; }
.campo:focus { outline: 2px solid var(--teal); outline-offset: 1px; }
.campo.codigo { text-transform: uppercase; letter-spacing: 0.35em; font-size: 1.4rem; font-weight: 700; }

.record { text-align: center; color: var(--apagado); margin: 0; font-size: 0.95rem; }
.record b { color: var(--teal-claro); }
.ayuda { text-align: center; color: var(--apagado); font-size: 0.82rem; margin: 0; line-height: 1.4; }

/* ---------- barra del juego ---------- */
.barra {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
}
.barra .nivel { font-weight: 700; color: var(--apagado); font-size: 0.95rem; letter-spacing: 0.02em; }
.icono {
  appearance: none;
  border: 1px solid var(--tecla-borde);
  background: var(--tecla);
  color: var(--texto);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}

/* ---------- jugadores (sala) ---------- */
.jugadores { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.ficha {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--tecla-borde);
  color: var(--apagado);
  max-width: 44%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ficha.turno { border-color: var(--teal); color: var(--teal-claro); }
.ficha.yo { color: var(--texto); }
.ficha.fuera { text-decoration: line-through; opacity: 0.5; }

/* ---------- display ---------- */
.display {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 24px;
  background: radial-gradient(circle at 50% 30%, #16262c 0%, #0e181d 70%);
  border: 1px solid #1b2a31;
  position: relative;
  overflow: hidden;
}
.digito {
  font-size: clamp(4.5rem, 30vw, 8rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--texto);
  transition: color 0.1s ease, transform 0.1s ease;
}
.digito.apagado { color: #2c4149; }
.digito.acierto { color: var(--teal-claro); }
.digito.error { color: var(--error); }
.leyenda {
  font-size: 0.95rem;
  color: var(--apagado);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  text-align: center;
  padding: 0 12px;
}
.leyenda.destacada { color: var(--teal-claro); }
.leyenda.error { color: var(--error); }
.progreso { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; padding: 0 12px; min-height: 10px; }
.punto { width: 8px; height: 8px; border-radius: 50%; background: #2c4149; }
.punto.hecho { background: var(--teal-claro); }
.punto.fallo { background: var(--error); }

/* ---------- teclado ---------- */
.teclado {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.tecla {
  appearance: none;
  border: 1px solid var(--tecla-borde);
  background: var(--tecla);
  color: var(--texto);
  font: inherit;
  font-size: clamp(1.4rem, 7vw, 1.9rem);
  font-weight: 700;
  min-height: clamp(58px, 9.5vh, 78px);
  border-radius: var(--radio);
  cursor: pointer;
  transition: background 0.1s ease, transform 0.06s ease, color 0.1s ease;
  display: grid;
  place-items: center;
}
.tecla:active { transform: scale(0.97); }
.tecla.activa { background: var(--teal); border-color: var(--teal); color: #04211d; transform: scale(0.96); }
.tecla.bien { background: rgba(61, 220, 151, 0.25); border-color: var(--teal-claro); color: var(--teal-claro); }
.tecla.mal { background: var(--error); border-color: var(--error); color: #2b0906; }
.tecla.vacia { background: transparent; border-color: transparent; cursor: default; }
.teclado.bloqueado .tecla:not(.vacia) { opacity: 0.4; }

/* ---------- listas y fin ---------- */
.titulo-seccion { margin: 0; font-size: 1.5rem; text-align: center; }
.lista { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; min-height: 0; padding: 0; margin: 0; list-style: none; }
.fila-puntaje {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--tecla-borde);
  border-radius: 12px;
}
.fila-puntaje .pos { width: 26px; color: var(--apagado); font-weight: 700; }
.fila-puntaje .nombre { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fila-puntaje .nivel-num { color: var(--teal-claro); font-weight: 800; font-variant-numeric: tabular-nums; }
.fila-puntaje .fecha { color: #55707a; font-size: 0.78rem; }

.aviso {
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(226, 87, 76, 0.12);
  border: 1px solid rgba(226, 87, 76, 0.5);
  color: #ffb4ad;
  font-size: 0.85rem;
  text-align: center;
}

.codigo-sala {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: var(--teal-claro);
  margin: 0;
}

/* escritorio: la tarjeta se centra y no se estira */
@media (min-width: 700px) and (min-height: 560px) {
  body { align-items: center; }
  .tarjeta {
    min-height: auto;
    height: min(92vh, 900px);
    border-radius: 28px;
    border: 1px solid #1b2a31;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
    background: linear-gradient(180deg, #0e181d 0%, #0b1216 100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* display en reposo: sin dígito, un pulso suave para que no quede muerto */
.digito:empty::after {
  content: "";
  display: block;
  width: clamp(70px, 22vw, 120px);
  height: clamp(70px, 22vw, 120px);
  border-radius: 50%;
  border: 3px solid #22353d;
  animation: latido 2.4s ease-in-out infinite;
}
.digito.apagado:empty::after { border-color: #1d2d34; }
@keyframes latido {
  0%, 100% { transform: scale(0.92); opacity: 0.55; }
  50% { transform: scale(1); opacity: 0.9; }
}
