/* =========================================================
   RatoLibre — Ajedrez (estilos propios del juego)
   ========================================================= */

/* ---------- Barra de herramientas ---------- */

.ajedrez-opcion {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  flex: 1 1 auto;
  font-weight: 700;
}

.ajedrez-opcion select {
  flex: 1 1 auto;
  min-height: 48px;
  min-width: 150px;
  padding: 0 40px 0 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%231f2a37' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' d='M4 7l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

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

@media (min-width: 720px) {
  .ajedrez-opcion {
    flex: 0 1 auto;
  }
}

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

.ajedrez-area {
  padding: 8px;
}

@media (min-width: 600px) {
  .ajedrez-area {
    padding: 12px;
  }
}

.ajedrez-cuerpo {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 900px) {
  .ajedrez-cuerpo {
    flex-direction: row;
    align-items: flex-start;
    gap: 24px;
  }

  .ajedrez-marco {
    flex: 0 0 auto;
    width: 580px;
  }

  .ajedrez-lateral {
    flex: 1 1 auto;
    min-width: 0;
  }
}

/* ---------- Tablero ---------- */

.ajedrez-marco {
  position: relative;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  grid-template-rows: auto 24px;
  width: 100%;
  max-width: 580px;
  margin: 0 auto;
  padding: 6px 8px 0 2px;
  border-radius: 10px;
  background: #5b3a22;
  box-shadow: var(--shadow);
}

.ajedrez-filas,
.ajedrez-columnas {
  display: grid;
  color: #f6ead2;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}

.ajedrez-filas {
  grid-column: 1;
  grid-row: 1;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
}

.ajedrez-columnas {
  grid-column: 2;
  grid-row: 2;
  grid-template-columns: repeat(8, 1fr);
  align-items: center;
}

.ajedrez-tablero {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 2px solid #3f2816;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.ajedrez-casilla {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #f1dfbd;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ajedrez-casilla.es-oscura {
  background: #a26f48;
}

.ajedrez-casilla:focus-visible {
  outline: 4px solid #1f5fbf;
  outline-offset: -4px;
  border-radius: 0;
  z-index: 2;
}

/* Última jugada */
.ajedrez-casilla.es-ultima {
  background: #f2dc78;
}

.ajedrez-casilla.es-oscura.es-ultima {
  background: #c49a3c;
}

/* Pista */
.ajedrez-casilla.es-pista,
.ajedrez-casilla.es-oscura.es-pista {
  background: #6dbb8d;
}

/* Rey en jaque */
.ajedrez-casilla.es-jaque {
  background: radial-gradient(circle, #ff4d3a 0%, #e53925 40%, rgba(198, 40, 40, 0.65) 70%, rgba(198, 40, 40, 0.15) 100%);
}

/* Pieza elegida */
.ajedrez-casilla.es-elegida {
  box-shadow: inset 0 0 0 5px #1f7a4d;
}

/* Piezas propias en peligro */
.ajedrez-casilla.en-peligro {
  box-shadow: inset 0 0 0 4px #e65100;
}

.ajedrez-casilla.en-peligro.es-elegida {
  box-shadow: inset 0 0 0 5px #1f7a4d;
}

/* Casillas a las que puede ir la pieza elegida */
.ajedrez-casilla.es-meta::before {
  content: "";
  position: absolute;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: #1f7a4d;
  border: 3px solid #ffffff;
  box-shadow: 0 0 0 2px #1f2a37;
  pointer-events: none;
  z-index: 1;
}

.ajedrez-casilla.es-meta.es-captura::before {
  width: 86%;
  height: 86%;
  background: transparent;
  border: 5px solid #1f7a4d;
  box-shadow: 0 0 0 2px #ffffff, inset 0 0 0 2px #ffffff;
}

.ajedrez-casilla.es-meta:hover {
  background: #8fc9a7;
}

/* ---------- Piezas ---------- */

.ajedrez-pieza {
  display: block;
  width: 90%;
  height: 90%;
  pointer-events: none;
  transition: transform 0.25s ease;
}

.ajedrez-pieza svg,
.ajedrez-icono svg {
  display: block;
  width: 100%;
  height: 100%;
}

.ajedrez-casilla.es-elegida .ajedrez-pieza {
  transform: scale(1.08);
}

.ajedrez-casilla.es-arrastrada .ajedrez-pieza {
  opacity: 0.3;
}

.ajedrez-fantasma {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
}

.ajedrez-tablero.arrastrando,
.ajedrez-tablero.arrastrando .ajedrez-casilla {
  cursor: grabbing;
}

/* ---------- Coronación ---------- */

.ajedrez-coronar {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border-radius: 10px;
  background: rgba(31, 42, 55, 0.72);
}

.ajedrez-coronar[hidden] {
  display: none;
}

.ajedrez-coronar .caja {
  width: 100%;
  max-width: 400px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.ajedrez-coronar .titulo {
  margin: 0 0 12px;
  font-weight: 800;
  line-height: 1.3;
}

.ajedrez-coronar .opciones {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.ajedrez-coronar .opciones .btn {
  flex-direction: column;
  gap: 2px;
  min-height: 88px;
  padding: 6px;
}

.ajedrez-coronar .opciones .ajedrez-icono {
  width: 48px;
  height: 48px;
}

/* ---------- Panel lateral ---------- */

.ajedrez-mensaje {
  min-height: 3em;
  margin: 0 0 12px;
  padding: 8px 12px;
  border-left: 5px solid var(--accent);
  background: var(--bg);
  border-radius: 0 8px 8px 0;
  font-weight: 600;
}

.ajedrez-mensaje.es-pensando {
  border-left-color: var(--accent-2);
}

.ajedrez-mensaje.es-alerta {
  border-left-color: #c62828;
  background: #fdecea;
  color: #8e1b1b;
}

.ajedrez-acciones {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.ajedrez-acciones .btn {
  flex: 1 1 140px;
}

.ajedrez-comidas {
  margin: 16px 0 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.ajedrez-comidas .fila {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-height: 40px;
}

.ajedrez-comidas .etiqueta,
.ajedrez-estado .etiqueta {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.ajedrez-comidas .etiqueta {
  min-width: 6.5em;
}

.ajedrez-comidas .piezas {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  min-height: 32px;
}

.ajedrez-comidas .ajedrez-icono {
  width: 30px;
  height: 30px;
  margin-right: -6px;
}

.ajedrez-comidas .ventaja {
  margin-left: 8px;
  color: var(--accent-2);
}

.ajedrez-casilla-ayuda {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-top: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ajedrez-casilla-ayuda input {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  margin: 0;
  accent-color: var(--accent-2);
  cursor: pointer;
}

/* ---------- Marcador ---------- */

.ajedrez-estado {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  margin: 16px 0;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.ajedrez-estado .dato {
  display: flex;
  flex-direction: column;
  min-width: 6ch;
}

.ajedrez-estado strong {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Paneles (final y confirmación) ---------- */

.ajedrez-panel {
  margin: 0 0 16px;
  padding: 20px 16px;
  border: 2px solid var(--accent-2);
  border-radius: var(--radius);
  background: var(--accent-2-soft);
  text-align: center;
  animation: ajedrez-entrar 0.35s ease-out;
}

.ajedrez-panel[hidden] {
  display: none;
}

.ajedrez-panel:focus {
  outline: none;
}

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

.ajedrez-panel.es-derrota,
.ajedrez-confirmar {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ajedrez-panel.es-derrota .titulo,
.ajedrez-confirmar .titulo {
  color: var(--accent-dark);
}

.ajedrez-panel p {
  margin: 0 0 0.6rem;
}

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

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

/* ---------- Animaciones ---------- */

@keyframes ajedrez-entrar {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ajedrez-panel {
    animation: none;
  }

  .ajedrez-pieza {
    transition: none;
  }
}
