/* chess.wrst.click — estilos móvil-first, tema oscuro */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
/* Mata el font-boosting de Chrome Android: sin esto, el navegador re-escala
   texto "chico" con heuristicas y los glifos cambian de tamano al mover piezas. */
html { -webkit-text-size-adjust: none; text-size-adjust: none; overscroll-behavior-y: contain; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
}
/* Centrado con margin:auto (NO align-items:center): cuando el contenido crece
   (cartel de resultado, etc.) la página se scrollea bien y el layout no "respira"
   al ocultarse la barra de URL de Android. */
.inicio, .juego { margin: auto; }

.oculto { display: none !important; }

/* ===== PANTALLA INICIAL ===== */
.inicio {
  width: 100%;
  max-width: 420px;
  padding: 24px;
  text-align: center;
}
.logo { font-size: 56px; margin: 8px 0; }
h1 { margin: 0; font-size: 32px; letter-spacing: 1px; color: #fff; }
.sub { color: #b8b8d0; margin: 6px 0 24px; }

.panel {
  background: #232341;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

/* Selector de juego (Ajedrez / Damas) */
.selector { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 4px; }
.selector .sel {
  padding: 12px; border-radius: 10px; border: 2px solid #3a3a5c; background: #14142a;
  color: #999; font-size: 15px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.selector .sel.active {
  background: linear-gradient(135deg, #7c6cff, #5a4bd6);
  color: #fff; border-color: transparent;
}
.selector .sel:active { transform: scale(.98); }

.barra.junt { justify-content: center; gap: 8px; }
.tp { display: flex; align-items: center; gap: 6px; font-weight: 600; color: #ddd; }
.tp .mini { font-size: 16px; }
.panel label { font-size: 13px; color: #a9a9c8; margin-top: 4px; }
input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #3a3a5c;
  background: #14142a;
  color: #fff;
  font-size: 16px;
  outline: none;
}
input:focus { border-color: #7c6cff; }
.codigo { text-transform: uppercase; letter-spacing: 3px; font-weight: bold; }

.btn {
  padding: 14px;
  border-radius: 10px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  background: #3a3a5c;
  color: #fff;
  transition: transform .05s;
}
.btn:active { transform: scale(.98); }
.btn.principal { background: linear-gradient(135deg, #7c6cff, #5a4bd6); }
.btn.peligro { background: #b3403a; }
.btn.secundario { background: #2c2c4a; }
.fila { display: flex; gap: 8px; }
.fila .codigo { flex: 1; }
.divisor { display: flex; align-items: center; gap: 10px; color: #666; font-size: 13px; margin: 6px 0; }
.divisor::before, .divisor::after { content: ""; flex: 1; height: 1px; background: #333; }
.pie { color: #777; margin-top: 18px; }

/* ===== PANTALLA DE JUEGO ===== */
.juego {
  width: 100%;
  max-width: 480px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.barra {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #232341;
  border-radius: 12px;
  padding: 10px 14px;
}
.jugador { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.punto { width: 12px; height: 12px; border-radius: 50%; background: #666; flex-shrink: 0; }
.punto.activo { background: #4caf50; box-shadow: 0 0 8px #4caf50; }
.crono {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: #14142a;
  padding: 4px 14px;
  border-radius: 8px;
}
.turno { text-align: center; color: #b8b8d0; font-size: 14px; padding: 4px; }

/* ===== TABLERO ===== */
.tablero {
  display: grid;
  /* minmax(0,1fr) en AMBOS ejes: filas/columnas EXACTAMENTE iguales pase lo que
     pase con el contenido. Antes las filas eran implicitas (auto) y se estiraban
     por el contenido -> cuadrados desiguales. */
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #3a3a5c;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  container-type: inline-size;
}
.celda { position: relative; overflow: hidden; }
.celda.clara { background: #edeed1; }
.celda.oscura { background: #779556; }
.celda.seleccion { outline: 3px solid #ffd75e; outline-offset: -3px; z-index: 2; }
.celda.movimiento::after,
.celda.captura::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.celda.movimiento::after { background: radial-gradient(circle, rgba(255,215,94,.85) 22%, transparent 30%); }
.celda.captura::after { background: radial-gradient(circle, transparent 58%, rgba(255,80,80,.75) 62%); }
.celda.last-from { box-shadow: inset 0 0 0 100px rgba(255, 215, 94, .18); }
.celda.last-to { box-shadow: inset 0 0 0 100px rgba(255, 215, 94, .32); }
.celda.jaque-rey { box-shadow: inset 0 0 0 3px #ff5252, inset 0 0 24px rgba(255,82,82,.6); }

.pieza {
  position: absolute; /* FUERA del flujo: el glifo no puede estirar la fila */
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 9vw, 42px); /* fallback navegadores sin container queries */
  font-size: 11cqw; /* anclado al ancho REAL del tablero (container query) */
  font-family: "Noto Sans Symbols 2", "Segoe UI Symbol", "DejaVu Sans", sans-serif;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
  pointer-events: none; /* el click va a la celda (listener), no al glifo */
}
/* Mismo glifo solido para ambos: color + contorno marcan la diferencia */
.pieza.blanca {
  color: #fafafa;
  text-shadow:
    0 0 2px #000, 0 0 3px #000, 0 1px 0 #000,
    1px 0 0 #000, -1px 0 0 #000, 0 -1px 0 #000;
}
.pieza.negra {
  color: #17171c;
  text-shadow: 0 0 2px rgba(255,255,255,.55), 0 1px 1px rgba(0,0,0,.65);
}

/* ===== Fichas de DAMAS (discos CSS) ===== */
.pieza.dama {
  position: absolute;
  border-radius: 50%;
  width: 78%;
  height: 78%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 55%;
  pointer-events: none;
  box-sizing: border-box;
}
.pieza.dama.blanca {
  background: radial-gradient(circle at 32% 28%, #ffffff 0%, #e6e2d4 45%, #b8b2a0 100%);
  border: 2px solid #6f6a58;
  box-shadow: 0 3px 5px rgba(0,0,0,.4), inset 0 -2px 3px rgba(0,0,0,.25);
  color: #3a2f14;
}
.pieza.dama.negra {
  background: radial-gradient(circle at 32% 28%, #4a4a52 0%, #2a2a30 45%, #141419 100%);
  border: 2px solid #000;
  box-shadow: 0 3px 5px rgba(0,0,0,.5), inset 0 2px 2px rgba(255,255,255,.18);
  color: #f2d057;
}
.pieza.dama.reina { font-size: 62%; font-weight: 700; }
.coord { position: absolute; font-size: 8px; color: rgba(0,0,0,.4); }
.coord.a { top: 2px; left: 3px; }
.coord.h { bottom: 1px; right: 3px; color: rgba(255,255,255,.5); }

/* ===== ACCIONES ===== */
.acciones { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.acciones2 { display: grid; grid-template-columns: 1fr; gap: 8px; }
.acciones .btn, .acciones2 .btn { padding: 10px; font-size: 13px; }

.estado {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  padding: 18px;
  background: #232341;
  border-radius: 12px;
  border: 2px solid #ffd75e;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.85);
  color: #fff;
  padding: 12px 20px;
  border-radius: 30px;
  font-size: 14px;
  z-index: 50;
  max-width: 90%;
  pointer-events: none;
}