* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #1a1a1a;
  color: #e0e0e0;
  padding: 20px;
  min-height: 100vh;
}
h1 { text-align: center; margin-bottom: 16px; color: #4ade80; font-size: 1.5rem; }

.container {
  max-width: 1350px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr 460px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1100px) { 
  .container { grid-template-columns: 1fr; } 
}

/* --- ZONA DEL TABLERO (Ancho fijo de 520px para que no se encoja) --- */
.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 520px;
  max-width: 520px;
  margin: 0 auto;
  grid-column: 2;
}

@media (max-width: 1100px) {
  .board-area { grid-column: auto; width: 100%; }
}

/* --- BARRA DE EVALUACIÓN HORIZONTAL --- */
.eval-bar-wrapper {
  display: flex;
  flex-direction: row;
  width: 100%;
  max-width: 520px;
  justify-content: space-between;
  align-items: center;
  margin: 0 auto 4px auto;
  gap: 8px;
}

.eval-bar {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 20px;
  background: #212121;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #374151;
  position: relative;
}

.eval-fill-black {
  width: 50%;
  height: 100%;
  background: #262626;
  transition: width 0.2s ease;
}

.eval-fill-white {
  width: 50%;
  height: 100%;
  background: #f0f0f0;
  flex-grow: 1;
  transition: width 0.2s ease;
}

.eval-number {
  font-size: 11px;
  font-family: monospace;
  color: #9ca3af;
  min-width: 36px;
  text-align: center;
}

.player-card {
  width: 100%;
  max-width: 520px;
  background: #262626;
  border-radius: 8px;
  padding: 10px 14px;
  display: none;
  align-items: center;
  gap: 12px;
  border: 1px solid #374151;
}
.player-card.active { display: flex; }
.player-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #404040;
  object-fit: cover;
}
.player-info { display: flex; flex-direction: column; gap: 2px; }
.player-name { font-weight: 600; font-size: 14px; color: #f3f4f6; }
.player-role { font-size: 11px; color: #9ca3af; }

#board-container {
  position: relative;
  width: 100%;
  max-width: 520px;
}
#board { width: 100%; }

/* Insignia flotante sobre la casilla en el tablero */
.board-move-badge {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  border: 2px solid #fff;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 100;
  pointer-events: none;
}
.board-move-badge.show {
  transform: translate(-50%, -50%) scale(1);
}
.badge-bg-brilliant { background: #2dd4bf; }
.badge-bg-great { background: #818cf8; }
.badge-bg-best { background: #4ade80; }
.badge-bg-excellent { background: #22c55e; }
.badge-bg-good { background: #4ade80; }
.badge-bg-book { background: #3b82f6; }
.badge-bg-inaccuracy { background: #eab308; }
.badge-bg-mistake { background: #f97316; }
.badge-bg-blunder { background: #ef4444; }

/* Gráfica de Evaluación Histórica */
.eval-graph-container {
  width: 100%;
  max-width: 520px;
  background: #262626;
  border-radius: 8px;
  padding: 10px;
  position: relative;
  border: 1px solid #374151;
  display: none;
}
.eval-graph-container.active { display: block; }
.eval-graph-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 6px;
}
#evalCanvas {
  width: 100%;
  height: 100px;
  display: block;
  border-radius: 4px;
  cursor: pointer;
  background: #1a1a1a;
}

.move-quality-badge {
  font-size: 16px;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 10px;
  background: #1f2937;
  min-width: 240px;
  text-align: center;
  border: 2px solid #374151;
  display: none;
}
.move-quality-badge.active { display: block; }
.badge-brilliant { border-color: #2dd4bf; color: #5eead4; }
.badge-great { border-color: #818cf8; color: #a5b4fc; }
.badge-best { border-color: #22c55e; color: #86efac; }
.badge-excellent { border-color: #16a34a; color: #4ade80; }
.badge-good { border-color: #4ade80; color: #bbf7d0; }
.badge-book { border-color: #3b82f6; color: #93c5fd; }
.badge-inaccuracy { border-color: #eab308; color: #fde047; }
.badge-mistake { border-color: #f97316; color: #fdba74; }
.badge-blunder { border-color: #ef4444; color: #fca5a5; }

.panel {
  background: #262626;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 93vh;
  overflow-y: auto;
  grid-column: 3;
}

@media (max-width: 1100px) {
  .panel { grid-column: auto; }
}

input[type="text"] {
  width: 100%;
  background: #1a1a1a;
  border: 1px solid #404040;
  color: #e0e0e0;
  border-radius: 8px;
  padding: 11px;
  font-size: 15px;
}
button {
  background: #4ade80;
  color: #000;
  border: none;
  padding: 11px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
button:hover { background: #22c55e; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.controls { display: flex; gap: 6px; }
.controls button { flex: 1; }
#status, #eval, #loading {
  font-size: 13px;
  padding: 8px;
  background: #1a1a1a;
  border-radius: 6px;
}
#eval { font-weight: bold; color: #4ade80; }
#loading { color: #fbbf24; display: none; }

#openingInfo {
  font-size: 13px;
  padding: 9px;
  background: #1a1a1a;
  border-radius: 6px;
  color: #60a5fa;
  font-weight: 500;
  border-left: 3px solid #3b82f6;
}

.analysis-progress-container {
  background: #1a1a1a;
  border-radius: 8px;
  padding: 10px;
  display: none;
  flex-direction: column;
  gap: 6px;
}
.progress-bar-bg { width: 100%; height: 8px; background: #333; border-radius: 4px; overflow: hidden; }
.progress-bar-fill { width: 0%; height: 100%; background: #4ade80; transition: width 0.2s ease; }
.progress-text { font-size: 12px; color: #a0a0a0; text-align: right; }

.lines-box {
  background: #0f0f0f;
  border: 2px solid #333;
  border-radius: 10px;
  padding: 12px;
}
.lines-title { font-size: 13px; font-weight: 600; color: #4ade80; margin-bottom: 10px; }
.line-row {
  display: flex; gap: 12px; padding: 8px; border-radius: 6px; margin-bottom: 6px;
  background: #1a1a1a; font-family: monospace; font-size: 13.5px; align-items: flex-start;
}
.line-score { min-width: 54px; font-weight: 700; color: #f87171; padding-top: 3px; }
.line-score.pos { color: #4ade80; }
.line-moves { display: flex; flex-wrap: wrap; gap: 4px; line-height: 1.5; }
.move-white { background: #e5e5e5; color: #111; padding: 2px 6px; border-radius: 4px; font-weight: 500; }
.move-black { background: #333; color: #f0f0f0; padding: 2px 6px; border-radius: 4px; font-weight: 500; }
.move-number { color: #888; padding: 2px 2px; }

.moves-table {
  width: 100%; border-collapse: collapse; font-family: monospace; font-size: 13px;
  background: #1a1a1a; border-radius: 8px; overflow: hidden;
}
.moves-table th { background: #111; padding: 8px 6px; text-align: center; font-size: 12px; color: #a0a0a0; }
.moves-table td { padding: 6px 8px; border-bottom: 1px solid #333; }
.moves-table .num { width: 32px; text-align: center; color: #888; }
.moves-table .san { cursor: pointer; padding: 4px 6px; border-radius: 4px; display: inline-flex; align-items: center; gap: 5px; }
.moves-table .san:hover { background: #333; }
.moves-table .san.selected { outline: 2px solid #4ade80; background: #14532d; }
.icon { font-size: 14px; }

.games-list { max-height: 140px; overflow-y: auto; background: #1a1a1a; border-radius: 8px; padding: 4px; }
.game-item { padding: 9px; border-bottom: 1px solid #333; cursor: pointer; font-size: 13px; }
.game-item:hover { background: #333; }
.game-item.selected { background: #4ade80; color: #000; }
.info { font-size: 12px; color: #a0a0a0; }
.error { color: #f87171; font-size: 13px; }
.best-move {
  font-size: 14px; padding: 10px 12px; background: #1e3a2f; border-radius: 8px; color: #86efac; line-height: 1.4;
}

.stats-summary {
  background: #1f1f1f;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 12px;
  margin-top: 10px;
}
.stats-header {
  font-size: 13px;
  font-weight: 600;
  color: #4ade80;
  margin-bottom: 8px;
  text-align: center;
}
.stats-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 6px 12px;
  font-size: 13px;
  align-items: center;
}
.stats-label {
  text-align: center;
  color: #9ca3af;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.stats-val-w { text-align: right; font-weight: 700; color: #f3f4f6; font-family: monospace; }
.stats-val-b { text-align: left; font-weight: 700; color: #f3f4f6; font-family: monospace; }