/* =========================================================
   RatoLibre — Ahorcado: estilos propios del juego
   Depende de los tokens de ../../assets/css/base.css
   Cada tecla usada lleva color y símbolo: ✓ está (verde),
   ✕ no está (gris y tachada).
   ========================================================= */

:root {
  --ah-bien: #2f6f4e;
  --ah-bien-texto: #ffffff;
  --ah-no: #d6d1c7;
  --ah-no-texto: #4b5563;
  --ah-madera: #8b5e3c;
  --ah-falta: #b3261e;
  --ah-casilla: 44px;
  --ah-hueco: 4px;
}

/* Los botones del sitio usan display: inline-flex; sin esto, hidden no los ocultaría. */
[hidden] {
  display: none !important;
}

/* ---------- Zona de juego ---------- */

.ah-area {
  padding: 12px;
}

.ah-area > * {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

/* La palabra usa todo el ancho, para que una frase quepa en una sola línea. */
.ah-area > .ah-palabra {
  max-width: none;
}

/* ---------- Nivel y tema ---------- */

.ah-opciones {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 20px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.ah-etiqueta {
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.ah-niveles {
  flex: 1 1 260px;
}

.ah-niveles-botones {
  display: flex;
  gap: 6px;
}

.ah-nivel {
  flex: 1 1 0;
  min-height: 48px;
  padding: 0 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.ah-nivel:hover {
  border-color: var(--accent);
}

.ah-nivel[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.ah-temas {
  flex: 1 1 220px;
}

.ah-select {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.ah-select:hover {
  border-color: var(--accent);
}

/* ---------- Dibujo e información ---------- */

.ah-tablero {
  display: flex;
  align-items: center;
  gap: 16px;
}

.ah-dibujo {
  flex: 0 0 auto;
  width: 150px;
  height: auto;
  aspect-ratio: 200 / 220;
  border-radius: var(--radius);
  background: var(--bg);
}

.ah-pieza,
.ah-brazo-arriba {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

.ah-madera .ah-pieza {
  stroke: var(--ah-madera);
  stroke-width: 9;
}

.ah-madera .ah-hilo {
  stroke-width: 3;
}

.ah-munieco .ah-pieza,
.ah-brazo-arriba,
.ah-cabeza {
  stroke: var(--text);
  stroke-width: 6;
}

.ah-cabeza {
  fill: var(--surface);
}

.ah-ojo {
  fill: var(--text);
}

.ah-boca {
  fill: none;
  stroke: var(--text);
  stroke-width: 3;
  stroke-linecap: round;
  display: none;
}

.ah-boca-feliz {
  fill: var(--surface);
}

.ah-pieza.es-visible {
  opacity: 1;
}

/* Cada fallo dibuja la pieza nueva, trazo a trazo. */
path.ah-pieza.es-nueva,
.ah-pieza.es-nueva > .ah-cabeza {
  stroke-dasharray: 1;
  animation: ah-trazo 0.45s ease-out both;
}

g.ah-pieza.es-nueva .ah-cara {
  animation: ah-aparece 0.3s ease-out 0.3s both;
}

@keyframes ah-trazo {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}

@keyframes ah-aparece {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Cara: tranquila mientras se juega, contenta si adivinas y triste si no. */
.ah-dibujo .ah-boca-normal { display: inline; }
.ah-dibujo.es-ganada .ah-boca-normal,
.ah-dibujo.es-perdida .ah-boca-normal { display: none; }
.ah-dibujo.es-ganada .ah-boca-feliz { display: inline; }
.ah-dibujo.es-perdida .ah-boca-triste { display: inline; }

/* Al adivinar, el muñeco levanta los brazos que ya tenga. */
.ah-dibujo.es-ganada .ah-munieco .ah-pieza,
.ah-dibujo.es-ganada .ah-cabeza,
.ah-dibujo.es-ganada .ah-brazo-arriba {
  stroke: var(--accent-2);
}

.ah-dibujo.es-ganada .ah-brazo.es-visible {
  opacity: 0;
}

.ah-brazo-arriba.es-visible {
  opacity: 1;
}

.ah-info {
  flex: 1 1 auto;
  min-width: 0;
}

.ah-info p {
  margin: 0;
}

.ah-tema {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  margin-bottom: 4px;
  font-size: 1.05rem;
  line-height: 1.3;
}

.ah-tema-etiqueta {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.ah-tema strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--accent);
}

.ah-largo {
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.ah-fallos {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ah-marcas {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.ah-marca {
  width: 16px;
  height: 16px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  background: var(--surface);
}

.ah-marca.es-usada {
  border-color: var(--accent);
  background: var(--accent);
}

/* ---------- Palabra ---------- */

.ah-palabra {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px calc(var(--ah-casilla) * 0.7);
  margin-top: 16px;
  margin-bottom: 6px;
  user-select: none;
  -webkit-user-select: none;
}

.ah-grupo {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--ah-hueco);
}

/* Cada letra lleva su rayita debajo, como en el papel. */
.ah-casilla {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--ah-casilla);
  height: calc(var(--ah-casilla) * 1.25);
  font-size: calc(var(--ah-casilla) * 0.62);
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

.ah-casilla::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 2px;
  height: 4px;
  border-radius: 2px;
  background: var(--text);
}

.ah-casilla.es-nueva {
  animation: ah-sube 0.35s ease-out both;
}

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

/* Letras que no se adivinaron: se muestran al final en rojo. */
.ah-casilla.es-faltante {
  color: var(--ah-falta);
}

.ah-palabra.es-ganada .ah-casilla {
  color: var(--accent-2);
}

/* ---------- Mensajes ---------- */

.ah-mensaje {
  min-height: 1.4em;
  margin: 4px auto 8px;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  color: var(--muted);
}

.ah-mensaje.es-aviso { color: #b3261e; }
.ah-mensaje.es-exito { color: var(--accent-2); }

/* ---------- Teclado en pantalla ---------- */

.ah-teclado {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ah-teclado-fila {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.ah-tecla {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1 1 0;
  max-width: 64px;
  min-width: 0;
  min-height: 52px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--border);
  touch-action: manipulation;
}

.ah-tecla:hover {
  border-color: var(--accent);
}

.ah-tecla:active {
  transform: translateY(2px);
  box-shadow: none;
}

.ah-tecla:focus-visible {
  outline: var(--focus);
  outline-offset: 1px;
}

.ah-tecla:disabled {
  cursor: default;
  transform: none;
}

.ah-tecla-letra {
  line-height: 1;
}

.ah-tecla-simbolo {
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1;
}

.ah-tecla-simbolo:empty {
  display: none;
}

.ah-tecla.es-bien {
  background: var(--ah-bien);
  border-color: var(--ah-bien);
  color: var(--ah-bien-texto);
  box-shadow: 0 2px 0 #1f4d36;
}

.ah-tecla.es-no {
  background: var(--ah-no);
  border-color: var(--ah-no);
  color: var(--ah-no-texto);
  box-shadow: none;
}

.ah-tecla.es-no .ah-tecla-letra {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

/* ---------- Paneles (fin de partida y confirmación) ---------- */

.ah-panel {
  margin-top: 8px;
  margin-bottom: 4px;
  padding: 18px 16px;
  border: 2px solid var(--accent-2);
  border-radius: var(--radius);
  background: var(--accent-2-soft);
  text-align: center;
}

/* El panel recibe el foco solo para que el lector de pantalla lo lea; no lleva contorno. */
.ah-panel:focus,
.ah-panel:focus-visible {
  outline: none;
}

.ah-panel .titulo {
  margin: 0 0 0.4rem;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--accent-2);
}

.ah-panel p {
  margin-bottom: 0.5rem;
}

.ah-fin-era {
  margin-bottom: 0.1rem;
  font-weight: 600;
  color: var(--muted);
}

.ah-fin-palabra {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
  color: var(--text);
}

.ah-panel .botones {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

.ah-panel .botones .btn {
  flex: 1 1 200px;
  max-width: 320px;
}

.ah-fin.es-perdida,
.ah-confirmar {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ah-fin.es-perdida .titulo,
.ah-confirmar .titulo {
  color: var(--accent-dark);
}

/* ---------- Estadísticas ---------- */

.ah-estado {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 16px 0 32px;
}

.ah-estado .dato {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.ah-estado .etiqueta {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.ah-estado strong {
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

.ah-ayuda li {
  margin-bottom: 0.5rem;
}

/* ---------- Celular ---------- */

@media (max-width: 719px) {
  :root {
    --ah-casilla: 40px;
    --ah-hueco: 0px;
  }

  /* Margen chico para que una palabra de 10 letras quepa con casillas de 32 px;
     la palabra usa también ese margen (32 px desde 360 px de ancho). */
  .ah-area {
    padding: 10px 8px;
  }

  .ah-area > .ah-palabra {
    margin-left: -8px;
    margin-right: -8px;
  }

  /* Nivel y tema con la etiqueta al lado, para que el dibujo, la palabra
     y el teclado quepan juntos en la pantalla. */
  .ah-opciones {
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 12px;
  }

  .ah-niveles,
  .ah-temas {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 100%;
  }

  .ah-opciones .ah-etiqueta {
    flex: 0 0 2.9em;
    margin: 0;
  }

  .ah-niveles-botones,
  .ah-select {
    flex: 1 1 auto;
    min-width: 0;
  }

  .ah-nivel {
    padding: 0 4px;
  }

  .ah-dibujo {
    width: 128px;
  }

  .ah-tablero {
    gap: 12px;
  }

  .ah-tecla {
    min-height: 50px;
  }
}

/* Celulares muy angostos: dibujo algo más chico para que quepa el tema. */
@media (max-width: 359px) {
  .ah-dibujo {
    width: 104px;
  }
}

/* ---------- Escritorio ---------- */

@media (min-width: 720px) {
  .ah-area {
    padding: 20px;
  }

  .ah-dibujo {
    width: 190px;
  }

  .ah-tablero {
    justify-content: center;
    gap: 28px;
  }

  .ah-info {
    flex: 0 1 300px;
  }

  .ah-tema {
    font-size: 1.2rem;
  }

  .ah-estado {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  path.ah-pieza.es-nueva,
  .ah-pieza.es-nueva > .ah-cabeza,
  g.ah-pieza.es-nueva .ah-cara,
  .ah-casilla.es-nueva {
    animation: none;
  }

  .ah-tecla:active {
    transform: none;
  }
}
