/* ============================================================
   Ajedrez STA — hoja de estilos
   Temas claro/oscuro con variables CSS, mobile-first.
   ============================================================ */

:root {
  --bg: #f3f0e9;
  --panel: #ffffff;
  --panel-2: #f7f4ee;
  --texto: #27241e;
  --texto-suave: #6d675c;
  --borde: #e2ddd2;
  --acento: #2f7d6d;
  --acento-hover: #276657;
  --acento-texto: #ffffff;
  --peligro: #b9433c;
  --casilla-clara: #eeeed2;
  --casilla-oscura: #769656;
  --resalte-ultima: rgba(247, 236, 116, 0.55);
  --resalte-seleccion: rgba(32, 90, 70, 0.35);
  --resalte-jaque: rgba(214, 60, 50, 0.75);
  --sombra: 0 2px 12px rgba(30, 25, 15, 0.08);
}

[data-theme="dark"] {
  --bg: #1d1f24;
  --panel: #272a31;
  --panel-2: #2e323b;
  --texto: #e8e6e1;
  --texto-suave: #a3a09a;
  --borde: #3a3e48;
  --acento: #4da58f;
  --acento-hover: #5cb8a1;
  --acento-texto: #10231e;
  --peligro: #d2645d;
  --casilla-clara: #a3a88b;
  --casilla-oscura: #5a7048;
  --resalte-ultima: rgba(240, 225, 100, 0.42);
  --sombra: 0 2px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--texto);
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

a { color: var(--acento); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Cabecera ---------- */
.cabecera {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--borde);
  box-shadow: var(--sombra);
}
.logo {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--texto);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.logo:hover { text-decoration: none; }
.logo i { color: var(--acento); }
.cabecera nav { display: flex; gap: 0.9rem; margin-left: 0.5rem; }
.cabecera nav a { color: var(--texto-suave); font-weight: 600; font-size: 0.95rem; }
.cabecera nav a:hover { color: var(--acento); text-decoration: none; }
.cabecera .espacio { flex: 1; }
#zonaUsuario { display: flex; align-items: center; gap: 0.5rem; }
.usuario-nombre { font-weight: 700; font-size: 0.92rem; }
.usuario-nombre small { color: var(--texto-suave); }

.btn-icono {
  background: none;
  border: none;
  color: var(--texto-suave);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0.45rem;
  border-radius: 8px;
}
.btn-icono:hover { background: var(--panel-2); color: var(--acento); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.5rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primario { background: var(--acento); color: var(--acento-texto); }
.btn-primario:hover { background: var(--acento-hover); text-decoration: none; }
.btn-suave { background: var(--panel-2); color: var(--texto); border-color: var(--borde); }
.btn-suave:hover { border-color: var(--acento); text-decoration: none; }
.btn-peligro { background: transparent; color: var(--peligro); border-color: var(--peligro); }
.btn-peligro:hover { background: var(--peligro); color: #fff; }
.btn-bloque { width: 100%; }

/* ---------- Portada ---------- */
.portada {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2.5rem 1.2rem 4rem;
  text-align: center;
}
.portada h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.portada h1 span { color: var(--acento); }
.portada .subtitulo {
  color: var(--texto-suave);
  font-size: 1.1rem;
  margin: 0.8rem auto 2.5rem;
  max-width: 34rem;
}
.modos {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.2rem;
  text-align: left;
}
.tarjeta-modo {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: var(--sombra);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  transition: transform 0.15s, border-color 0.15s;
}
.tarjeta-modo:hover { transform: translateY(-4px); border-color: var(--acento); }
.tarjeta-modo .icono {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--acento) 14%, transparent);
  color: var(--acento);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.tarjeta-modo h2 { font-size: 1.2rem; }
.tarjeta-modo p { color: var(--texto-suave); font-size: 0.94rem; flex: 1; }
.opciones-modo { display: flex; flex-wrap: wrap; gap: 0.45rem; }

/* ---------- Página de juego ---------- */
.partida-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}
@media (min-width: 900px) {
  .partida-layout { grid-template-columns: minmax(0, 1fr) 330px; align-items: start; }
}

.zona-tablero { display: flex; flex-direction: column; gap: 0.55rem; }

.jugador {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: 0.45rem 0.8rem;
}
.jug-color { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--borde); flex: none; }
.color-w { background: #f5f5f0; }
.color-b { background: #3a373f; }
.jug-nombre { font-weight: 700; font-size: 0.95rem; }
.jug-capturadas {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 22px;
  overflow: hidden;
}
.jug-capturadas .pieza { width: 20px; height: 20px; margin-right: -6px; }
.jug-capturadas .ventaja {
  margin-left: 12px;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--texto-suave);
}
.jug-reloj {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.1rem;
  background: var(--panel-2);
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 0.2rem 0.6rem;
}
.jug-reloj.activo { border-color: var(--acento); color: var(--acento); }
.jug-reloj.apuro { border-color: var(--peligro); color: var(--peligro); }

.marco-tablero {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--sombra);
}
#tablero {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}
.casilla { position: relative; display: flex; align-items: center; justify-content: center; }
.casilla.clara { background: var(--casilla-clara); }
.casilla.oscura { background: var(--casilla-oscura); }
.casilla.ultima::before {
  content: ""; position: absolute; inset: 0; background: var(--resalte-ultima);
}
.casilla.seleccionada::before {
  content: ""; position: absolute; inset: 0; background: var(--resalte-seleccion);
}
.casilla.jaque::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, var(--resalte-jaque) 20%, transparent 72%);
}
.casilla.destino::after {
  content: ""; position: absolute;
  width: 30%; height: 30%; border-radius: 50%;
  background: rgba(20, 40, 30, 0.28);
}
[data-theme="dark"] .casilla.destino::after { background: rgba(230, 240, 230, 0.3); }
.casilla.destino-captura::after {
  width: 92%; height: 92%;
  background: transparent;
  border: 4px solid rgba(20, 40, 30, 0.32);
}
[data-theme="dark"] .casilla.destino-captura::after { border-color: rgba(230, 240, 230, 0.35); }

.coord {
  position: absolute;
  font-size: clamp(8px, 1.4vw, 11px);
  font-weight: 800;
  opacity: 0.75;
  pointer-events: none;
}
.coord-fila { top: 2px; left: 3px; }
.coord-col { bottom: 1px; right: 4px; }
.clara .coord { color: var(--casilla-oscura); }
.oscura .coord { color: var(--casilla-clara); }

.pieza {
  width: 88%;
  height: 88%;
  position: relative;
  z-index: 2;
  cursor: grab;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.25));
}
.pieza-w { fill: #f8f7f2; stroke: #3a352f; }
.pieza-b { fill: #403c46; stroke: #17151b; }
.pieza-w .detalle { fill: #3a352f; stroke: #3a352f; }
.pieza-b .detalle { fill: #e9e7e2; stroke: #e9e7e2; }
.pieza-flotante {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  cursor: grabbing;
}

.barra-estado {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
#estadoPartida { font-weight: 700; color: var(--texto-suave); flex: 1; min-width: 150px; }

/* ---------- Panel lateral ---------- */
.panel-lateral {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 14px;
  box-shadow: var(--sombra);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-lateral h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--texto-suave);
  padding: 0.8rem 1rem 0.4rem;
}
#listaJugadas {
  max-height: 320px;
  overflow-y: auto;
  padding: 0.3rem 1rem 0.8rem;
  font-variant-numeric: tabular-nums;
}
.par-jugadas {
  display: grid;
  grid-template-columns: 2.2rem 1fr 1fr;
  gap: 0.3rem;
  padding: 0.12rem 0;
  font-size: 0.95rem;
}
.par-jugadas .num { color: var(--texto-suave); font-weight: 700; }
.media { cursor: pointer; padding: 0.05rem 0.4rem; border-radius: 6px; font-weight: 600; }
.media:hover { background: var(--panel-2); }
.media.actual { background: var(--acento); color: var(--acento-texto); }
.lista-vacia { color: var(--texto-suave); font-size: 0.9rem; }
.controles-nav {
  display: flex;
  gap: 0.4rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--borde);
}
.controles-nav .btn { flex: 1; padding: 0.4rem; }
.acciones-partida {
  display: flex;
  gap: 0.5rem;
  padding: 0 1rem 1rem;
  flex-wrap: wrap;
}
.acciones-partida .btn { flex: 1; }

/* ---------- Modales ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 10, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
  padding: 1rem;
}
.modal.abierto { opacity: 1; pointer-events: auto; }
.modal-caja {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 18px;
  padding: 1.8rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  transform: translateY(12px);
  transition: transform 0.2s;
}
.modal.abierto .modal-caja { transform: translateY(0); }
.fin-titulo { font-size: 1.5rem; font-weight: 800; }
.fin-detalle { color: var(--texto-suave); margin: 0.5rem 0 1.3rem; }
.fin-acciones { display: flex; flex-direction: column; gap: 0.6rem; }
.promo-piezas { display: flex; gap: 0.6rem; justify-content: center; margin-top: 1rem; }
.promo-btn {
  width: 64px; height: 64px;
  background: var(--panel-2);
  border: 2px solid var(--borde);
  border-radius: 12px;
  cursor: pointer;
  padding: 6px;
}
.promo-btn:hover { border-color: var(--acento); }

/* ---------- Formularios ---------- */
.form-caja {
  max-width: 400px;
  margin: 3rem auto;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 18px;
  padding: 2rem;
  box-shadow: var(--sombra);
}
.form-caja h1 { font-size: 1.5rem; margin-bottom: 0.4rem; }
.form-caja .nota { color: var(--texto-suave); font-size: 0.92rem; margin-bottom: 1.4rem; }
.campo { margin-bottom: 1rem; text-align: left; }
.campo label { display: block; font-weight: 700; font-size: 0.9rem; margin-bottom: 0.3rem; }
.campo input, .campo select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--borde);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--texto);
  font: inherit;
}
.campo input:focus, .campo select:focus { outline: 2px solid var(--acento); border-color: transparent; }
.form-pie { margin-top: 1.2rem; text-align: center; color: var(--texto-suave); font-size: 0.92rem; }

/* ---------- Lobby y tablas ---------- */
.contenido {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}
.contenido h1 { font-size: 1.6rem; margin-bottom: 1.2rem; }
.seccion {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 14px;
  box-shadow: var(--sombra);
  padding: 1.2rem;
  margin-bottom: 1.3rem;
}
.seccion h2 { font-size: 1.05rem; margin-bottom: 0.9rem; display: flex; align-items: center; gap: 0.5rem; }
.seccion h2 i { color: var(--acento); }
.fila-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 0.4rem;
  border-top: 1px solid var(--borde);
  flex-wrap: wrap;
}
.fila-item:first-of-type { border-top: none; }
.fila-item .detalle-item { flex: 1; min-width: 160px; }
.fila-item .detalle-item strong { display: block; }
.fila-item .detalle-item small { color: var(--texto-suave); }
.vacio { color: var(--texto-suave); font-size: 0.94rem; padding: 0.4rem; }

.etiqueta {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  background: color-mix(in srgb, var(--acento) 15%, transparent);
  color: var(--acento);
}
.etiqueta.turno { background: color-mix(in srgb, #d99f28 22%, transparent); color: #a8791a; }
[data-theme="dark"] .etiqueta.turno { color: #e6b84f; }

table.tabla {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.tabla th {
  text-align: left;
  color: var(--texto-suave);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.6rem;
  border-bottom: 2px solid var(--borde);
}
.tabla td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--borde); }
.tabla tr:last-child td { border-bottom: none; }
.tabla .pos { font-weight: 800; color: var(--texto-suave); width: 2.5rem; }
.tabla .elo { font-weight: 800; color: var(--acento); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--texto);
  color: var(--bg);
  padding: 0.65rem 1.2rem;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.93rem;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 200;
  max-width: min(92vw, 420px);
  text-align: center;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--peligro); color: #fff; }

/* ---------- Utilidades ---------- */
.oculto { display: none !important; }
.centrado { text-align: center; }
.pie {
  text-align: center;
  color: var(--texto-suave);
  font-size: 0.85rem;
  padding: 2rem 1rem;
}
