/* ═══════════════════════════════════════════════════════
   AJEDREZ — Tablero de madera nórdica + oro
═══════════════════════════════════════════════════════ */

#screen-chess-menu {
  background: radial-gradient(ellipse at 40% 30%, #28180a 0%, #0f0804 75%);
}

#screen-chess-menu .submenu-title {
  color: #e8c361;
  text-shadow: 0 0 24px rgba(230, 180, 60, 0.25), 1px 1px 0 #3a2000;
  letter-spacing: 6px;
}

#screen-chess-menu .submenu-desc { color: #9a7a40; }
#screen-chess-menu .btn-back { border-color: rgba(200, 150, 60, 0.3); color: #c8a050; }
#screen-chess-menu .btn-back:hover { color: #e8c361; }
#screen-chess-menu .submenu-rules-link { color: #c8a050; }
#screen-chess-menu .submenu-rules-link:hover { color: #e8c361; border-color: rgba(200, 150, 60, 0.35); }

#screen-chess-game {
  background:
    radial-gradient(ellipse at 50% 0%,   rgba(80, 50, 10, 0.45) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 90%,  rgba(60, 35, 5,  0.35) 0%, transparent 50%),
    linear-gradient(160deg, #1a1008 0%, #100c05 60%, #0a0804 100%);
  color: #e8d8b0;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  overflow: hidden;
}

#screen-chess-game.screen:not(.active) { display: none; }

/* ── Botón menú in-game ──────────────────────────────── */
#screen-chess-game .btn-back {
  color: #c8a050;
  border-color: rgba(200, 160, 60, 0.35);
  background: rgba(60, 38, 8, 0.75);
}
#screen-chess-game .btn-back:hover {
  background: rgba(80, 52, 12, 1);
  color: #f0d070;
}
#screen-chess-game .game-menu-dropdown {
  background: rgba(16, 10, 3, 0.97);
  border-color: rgba(200, 160, 60, 0.3);
}
#screen-chess-game .game-menu-dropdown button { color: #c8a870; }
#screen-chess-game .game-menu-dropdown button:hover {
  background: rgba(200, 160, 60, 0.1);
  color: #f0d898;
}

/* ── Layout principal ────────────────────────────────── */
#chess-game-section {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 20px;
  width: 100%;
  max-width: 960px;
  padding: 48px 16px 16px;
  box-sizing: border-box;
  height: 100%;
  overflow: hidden;
}

.chess-engine-credit {
  position: fixed;
  right: 18px;
  bottom: 14px;
  z-index: 950;
  padding: 6px 10px;
  border: 1px solid rgba(200, 160, 60, 0.28);
  border-radius: 999px;
  background: rgba(16, 10, 3, 0.66);
  color: rgba(232, 200, 112, 0.78);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  backdrop-filter: blur(6px);
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.chess-engine-credit:hover {
  background: rgba(48, 30, 8, 0.86);
  border-color: rgba(240, 208, 96, 0.45);
  color: #f0d898;
}

/* ── Columna tablero ─────────────────────────────────── */
.chess-board-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Etiquetas de coordenadas */
.chess-coords-row {
  display: flex;
  width: var(--board-px, 480px);
  padding-left: 20px;
}
.chess-coords-row span {
  flex: 1;
  text-align: center;
  font-size: 0.6rem;
  color: rgba(200, 160, 80, 0.55);
  letter-spacing: 1px;
  font-weight: 600;
}
.chess-coords-col {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: var(--board-px, 480px);
  width: 20px;
}
.chess-coords-col span {
  font-size: 0.6rem;
  color: rgba(200, 160, 80, 0.55);
  text-align: center;
  font-weight: 600;
}
.chess-board-with-coords {
  display: flex;
  gap: 0;
}

/* ── Tablero de madera ───────────────────────────────── */
#chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: var(--board-px, 480px);
  height: var(--board-px, 480px);
  border: 12px solid #3a2008;
  border-radius: 6px;
  box-shadow:
    inset 0 0 0 2px rgba(200, 140, 40, 0.3),
    0 0 0 2px rgba(30, 16, 4, 0.9),
    0 16px 40px rgba(0, 0, 0, 0.7),
    0 0 60px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  user-select: none;
  flex-shrink: 0;
}

/* ── Casillas ────────────────────────────────────────── */
.chess-sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s, box-shadow 0.1s;
}

.chess-sq.light {
  background: #f0d9b5;
  background-image: repeating-linear-gradient(45deg, transparent, transparent 20px, rgba(0,0,0,0.015) 20px, rgba(0,0,0,0.015) 40px);
}
.chess-sq.dark {
  background: #b58863;
  background-image: repeating-linear-gradient(45deg, transparent, transparent 20px, rgba(0,0,0,0.03) 20px, rgba(0,0,0,0.03) 40px);
}

/* Hover */
.chess-sq.light:hover { background: #f6e8ce; }
.chess-sq.dark:hover  { background: #c99a74; }

/* Casilla seleccionada */
.chess-sq.selected {
  background: #f6f669 !important;
  box-shadow: inset 0 0 0 3px rgba(200, 180, 0, 0.7);
}

/* Último movimiento */
.chess-sq.last-from,
.chess-sq.last-to {
  background: rgba(205, 210, 106, 0.55) !important;
}
.chess-sq.dark.last-from,
.chess-sq.dark.last-to {
  background: rgba(170, 162, 58, 0.7) !important;
}

/* Movimiento legal — punto central */
.chess-sq.legal-move::after {
  content: '';
  position: absolute;
  width: 32%;
  height: 32%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  pointer-events: none;
  z-index: 3;
}

/* Captura legal — anillo */
.chess-sq.legal-capture::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 4px solid rgba(0, 0, 0, 0.25);
  pointer-events: none;
  z-index: 3;
}

/* Rey en jaque */
.chess-sq.in-check {
  background: radial-gradient(circle at 50% 50%, rgba(220, 30, 10, 0.85) 0%, rgba(180, 20, 0, 0.6) 45%, transparent 70%) !important;
  box-shadow: inset 0 0 12px rgba(255, 40, 0, 0.6) !important;
}

/* ── Piezas ──────────────────────────────────────────── */
.chess-piece {
  font-size: calc(var(--board-px, 480px) / 8 * 0.82);
  line-height: 1;
  text-align: center;
  pointer-events: none;
  position: relative;
  z-index: 2;
  transition: transform 0.08s ease;
  will-change: transform;
}
.chess-piece.white {
  color: #f8f4ec;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.7)) drop-shadow(0 0 1px rgba(0,0,0,0.9));
}
.chess-piece.black {
  color: #1a1008;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5)) drop-shadow(0 0 1px rgba(255,255,255,0.1));
}
.chess-sq:hover .chess-piece { transform: scale(1.06); }
.chess-sq.selected .chess-piece { transform: scale(1.1) translateY(-4%); }

/* ── Panel lateral ───────────────────────────────────── */
.chess-side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 200px;
  flex-shrink: 0;
  height: var(--board-px, 480px);
  overflow: hidden;
}

/* Placa de jugador */
.chess-player-card {
  background: linear-gradient(135deg, rgba(50, 30, 8, 0.85), rgba(28, 16, 4, 0.9));
  border: 1px solid rgba(200, 150, 50, 0.25);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.25s, background 0.25s;
}
.chess-player-card.active {
  border-color: rgba(240, 192, 64, 0.55);
  background: linear-gradient(135deg, rgba(80, 50, 12, 0.9), rgba(48, 28, 6, 0.95));
  box-shadow: 0 0 12px rgba(240, 192, 64, 0.12);
}
.chess-player-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: #e8c870;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chess-player-color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.chess-player-color-dot.white { background: #f8f4ec; border: 1px solid #ccc; }
.chess-player-color-dot.black { background: #1a1008; border: 1px solid #555; }
.chess-captured {
  font-size: 0.72rem;
  color: rgba(220, 190, 120, 0.65);
  line-height: 1.3;
  min-height: 1em;
  letter-spacing: 1px;
}

/* Indicador de turno/estado */
.chess-status-line {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(200, 150, 50, 0.2);
  color: #c8a040;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.chess-status-line.my-turn {
  color: #f0d040;
  border-color: rgba(240, 200, 60, 0.45);
  background: rgba(80, 55, 8, 0.5);
  animation: chess-turn-pulse 1.4s ease-in-out infinite alternate;
}
.chess-status-line.in-check-status {
  color: #ff6040;
  border-color: rgba(255, 80, 40, 0.5);
  background: rgba(80, 20, 8, 0.6);
  animation: chess-check-flash 0.7s ease-in-out infinite alternate;
}
.chess-status-line.thinking {
  color: #7fc7ff;
  border-color: rgba(127, 199, 255, 0.45);
  background: rgba(20, 45, 70, 0.55);
  animation: chess-thinking-pulse 1s ease-in-out infinite alternate;
}
.chess-status-line.finished { color: #80a870; border-color: rgba(120, 180, 90, 0.35); }
@keyframes chess-turn-pulse {
  from { box-shadow: 0 0 0 rgba(240, 200, 60, 0); }
  to   { box-shadow: 0 0 12px rgba(240, 200, 60, 0.35); }
}
@keyframes chess-check-flash {
  from { box-shadow: 0 0 0 rgba(255, 80, 40, 0); }
  to   { box-shadow: 0 0 14px rgba(255, 80, 40, 0.5); }
}
@keyframes chess-thinking-pulse {
  from { box-shadow: 0 0 0 rgba(127, 199, 255, 0); }
  to   { box-shadow: 0 0 12px rgba(127, 199, 255, 0.35); }
}

#chess-board.bot-thinking {
  cursor: progress;
  filter: saturate(0.9);
}

/* ── Historial de movimientos ────────────────────────── */
.chess-moves-box {
  flex: 1;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(200, 150, 50, 0.15);
  border-radius: 6px;
  padding: 5px 0;
  min-height: 0;
}
.chess-moves-box::-webkit-scrollbar { width: 4px; }
.chess-moves-box::-webkit-scrollbar-track { background: transparent; }
.chess-moves-box::-webkit-scrollbar-thumb { background: rgba(200, 150, 50, 0.3); border-radius: 2px; }

/* Un par de movimientos (blancas + negras) por turno */
.cmove-pair {
  padding: 0 4px;
  margin-bottom: 1px;
}
.cmove-pair + .cmove-pair {
  border-top: 1px solid rgba(200, 150, 50, 0.06);
  padding-top: 1px;
}

/* Cada semimovimiento (blancas o negras) */
.cmove-half {
  display: flex;
  align-items: flex-start;
  gap: 3px;
  padding: 2px 3px;
  border-radius: 3px;
  transition: background 0.1s;
}
.cmove-half.cmove-w { background: rgba(250, 230, 190, 0.04); }
.cmove-half.cmove-b { background: rgba(50,  30,  10,  0.18); }

/* Último movimiento resaltado */
.cmove-half.is-latest {
  background: rgba(240, 210, 60, 0.13) !important;
  border-left: 2px solid rgba(240, 200, 55, 0.45);
}

/* Modificadores de tipo de movimiento */
.cmove-half.is-capture  .cmove-text { color: #d4894a; }
.cmove-half.is-check    .cmove-text { color: #e05840; }
.cmove-half.is-checkmate .cmove-text { color: #ff4433; font-weight: 700; }
.cmove-half.is-castle   .cmove-text { color: #c8b060; }
.cmove-half.is-promotion .cmove-text { color: #b090e0; }

/* Número de turno */
.cmove-turn {
  font-size: 0.52rem;
  color: rgba(200, 160, 80, 0.38);
  width: 15px;
  flex-shrink: 0;
  text-align: right;
  padding-top: 2px;
  letter-spacing: 0.5px;
}
/* Sangría alineada para el semimovimiento negro */
.cmove-indent {
  width: 15px;
  flex-shrink: 0;
}

/* Icono de la pieza */
.cmove-icon {
  font-size: 0.82rem;
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  line-height: 1.2;
}
.cmove-icon.wpiece {
  color: #f0e8d4;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.85));
}
.cmove-icon.bpiece {
  color: #c8a060;
  background: rgba(20, 10, 4, 0.55);
  border-radius: 3px;
  padding: 0 1px;
}

/* Descripción del movimiento */
.cmove-text {
  font-size: 0.61rem;
  color: #b09870;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}
.cmove-half.cmove-w .cmove-text { color: #c8aa78; }
.cmove-half.cmove-b .cmove-text { color: #9a8260; }
.cmove-half.is-latest .cmove-text { color: #e8c860 !important; }

/* Badges de jaque / jaque mate */
.cmove-badge {
  flex-shrink: 0;
  font-size: 0.55rem;
  font-weight: 900;
  padding: 0px 3px;
  border-radius: 2px;
  line-height: 1.5;
  margin-top: 1px;
}
.cmove-badge.badge-check {
  color: #e05840;
  background: rgba(220, 80, 50, 0.15);
  border: 1px solid rgba(220, 80, 50, 0.3);
}
.cmove-badge.badge-mate {
  color: #ff4433;
  background: rgba(255, 60, 40, 0.2);
  border: 1px solid rgba(255, 60, 40, 0.4);
  font-weight: 900;
}

/* ── Dialog de promoción ─────────────────────────────── */
#chess-promo-overlay {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  z-index: 20000;
}
#chess-promo-overlay.visible { display: flex; }
.chess-promo-panel {
  background: linear-gradient(145deg, rgba(60, 38, 10, 0.98), rgba(24, 14, 4, 0.98));
  border: 2px solid rgba(200, 160, 50, 0.6);
  border-radius: 12px;
  padding: 24px 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.7), inset 0 0 20px rgba(0,0,0,0.5);
  text-align: center;
}
.chess-promo-title {
  font-size: 0.75rem;
  letter-spacing: 4px;
  color: #c8a040;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.chess-promo-choices {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.chess-promo-choice {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(200,160,50,0.35);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
}
.chess-promo-choice:hover {
  background: rgba(200,160,50,0.18);
  border-color: rgba(240,200,70,0.6);
  transform: scale(1.1);
}

/* ── Overlay de resultado ────────────────────────────── */
#chess-result-overlay {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 20000;
}
#chess-result-overlay.visible { display: flex; }
.chess-result-panel {
  width: min(380px, calc(100vw - 32px));
  padding: 28px;
  background: linear-gradient(145deg, rgba(55, 34, 8, 0.98), rgba(20, 12, 3, 0.98));
  border: 2px solid rgba(200,160,50,0.55);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.7), inset 0 0 20px rgba(0,0,0,0.5);
  text-align: center;
}
.chess-result-title {
  font-size: 1.8rem;
  font-weight: 900;
  color: #f0d060;
  margin-bottom: 6px;
  letter-spacing: 2px;
}
.chess-result-sub {
  font-size: 0.88rem;
  color: #c8a050;
  margin-bottom: 22px;
}
.chess-result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}
.chess-result-btn {
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid rgba(240, 210, 140, 0.25);
  cursor: pointer;
  font-weight: 800;
  font-size: 0.85rem;
  transition: filter 0.15s;
}
.chess-result-btn:hover { filter: brightness(1.18); }
.chess-result-btn.primary {
  background: linear-gradient(135deg, #b8882a, #7a4f16);
  color: #1a0e04;
}
.chess-result-btn.secondary {
  background: rgba(0, 0, 0, 0.28);
  color: #f0d898;
}

/* ── Responsive ──────────────────────────────────────── */
/* Dev Tools de Ajedrez */
.chess-dev-tools {
  width: min(360px, calc(100vw - 32px));
  max-height: min(72vh, 520px);
  overflow-y: auto;
  background: rgba(12, 8, 4, 0.94);
  border-color: rgba(200, 160, 60, 0.34);
  color: #d8c08a;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
}
.chess-dev-tools .dev-tools-header {
  color: #c8a040;
}
.chess-dev-tools .dev-tools-header:hover {
  color: #f0d070;
}
.chess-dev-fen-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}
.chess-dev-fen-input {
  min-width: 0;
  background: #0a0804;
  border: 1px solid rgba(200, 160, 60, 0.32);
  border-radius: 4px;
  color: #ead8a8;
  font: 11px 'Courier New', monospace;
  padding: 6px 7px;
  outline: none;
}
.chess-dev-fen-input:focus {
  border-color: rgba(240, 208, 96, 0.65);
}
.chess-dev-load {
  width: auto;
  white-space: nowrap;
}
.chess-dev-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}
.chess-dev-tools .dev-btn {
  background: rgba(32, 20, 6, 0.95);
  border-color: rgba(200, 160, 60, 0.28);
  color: #e0bd66;
}
.chess-dev-tools .dev-btn:hover {
  background: rgba(68, 43, 10, 0.98);
}
.chess-dev-section-label {
  margin-top: 3px;
  color: rgba(214, 180, 98, 0.72);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.chess-dev-msg {
  min-height: 14px;
  color: rgba(216, 192, 138, 0.72);
  font-size: 10px;
  line-height: 1.35;
}
.chess-dev-msg.ok { color: #9ad47e; }
.chess-dev-msg.error { color: #ff8c76; }

@media (max-width: 760px) {
  #chess-game-section {
    flex-direction: column;
    align-items: center;
    padding-top: 44px;
    gap: 12px;
    overflow-y: auto;
  }

  .chess-side-panel {
    width: min(var(--board-px, 340px), 90vw);
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .chess-player-card { flex: 1; min-width: 140px; }
  .chess-status-line { width: 100%; }
  .chess-moves-box { width: 100%; max-height: 100px; }
}

@media (max-width: 520px) {
  :root { --board-px: calc(min(92vw, 380px)); }
  .chess-board-col { width: calc(var(--board-px) + 20px + 6px); }
  .chess-coords-row { width: var(--board-px); }
  #chess-board {
    width: var(--board-px);
    height: var(--board-px);
    border-width: 8px;
  }
  .chess-piece { font-size: calc(var(--board-px) / 8 * 0.82); }
}
