/* ==========================================================================
   Gimnasio Táctico Diario de Ajedrez - Fijate.com
   Estándar Canónico Midnight Slate, Tablero Torneo y Feedback Táctico
   ========================================================================== */

:root {
  --bg-primary: #0b0f17;
  --bg-surface: #121826;
  --bg-surface-elevated: #1a2336;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-hover: rgba(255, 255, 255, 0.16);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-gold: #f59e0b;
  --accent-gold-glow: rgba(245, 158, 11, 0.25);
  --accent-blue: #3b82f6;
  --accent-emerald: #10b981;
  --accent-rose: #ef4444;

  /* Tablero estilo torneo oficial */
  --square-light: #eeeed2;
  --square-dark: #769656;
  --square-highlight: rgba(245, 158, 11, 0.55);
  --square-selected: rgba(59, 130, 246, 0.6);
  --square-hint: rgba(16, 185, 129, 0.6);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
  --shadow-board: 0 12px 36px -4px rgba(0, 0, 0, 0.7);
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --border-color: #e2e8f0;
  --border-color-hover: #cbd5e1;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --shadow-card: 0 4px 16px -2px rgba(15, 23, 42, 0.06);
  --shadow-board: 0 12px 32px -4px rgba(15, 23, 42, 0.15);
}

/* Base */
body {
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: 0;
}

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3.5rem;
  padding: 0 1rem;
  width: 100%;
  box-sizing: border-box;
}

.tool-with-sidebar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 1536px) {
  .tool-with-sidebar {
    grid-template-columns: 1fr 300px;
  }
}

.tool-main-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

/* Layout del gimnasio (Tablero + Panel de telemetría) */
.chess-gym-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.75rem;
  align-items: start;
}

@media (min-width: 900px) {
  .chess-gym-layout {
    grid-template-columns: minmax(360px, 540px) 1fr;
  }
}

/* Tablero de ajedrez */
.board-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.board-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 0.75rem;
  box-shadow: var(--shadow-board);
  display: flex;
  justify-content: center;
}

.board-frame {
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1 / 1;
  position: relative;
  background: #1e293b;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.4);
}

.chess-board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  user-select: none;
  -webkit-user-select: none;
}

/* Casillas */
.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.square.light {
  background-color: var(--square-light);
  color: var(--square-dark);
}

.square.dark {
  background-color: var(--square-dark);
  color: var(--square-light);
}

.square.selected {
  background-color: var(--square-selected) !important;
}

.square.last-move {
  background-color: var(--square-highlight) !important;
}

.square.hint-target {
  background-color: var(--square-hint) !important;
}

/* Coordenadas alfanuméricas */
.square-coord {
  position: absolute;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  font-weight: 700;
  pointer-events: none;
  line-height: 1;
  opacity: 0.8;
}

.square-coord-rank {
  top: 3px;
  left: 3px;
}

.square-coord-file {
  bottom: 3px;
  right: 3px;
}

/* Piezas de ajedrez SVG */
.piece {
  width: 90%;
  height: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: transform 0.15s ease;
}

.piece svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.square:hover .piece {
  transform: scale(1.06);
}

/* Barra inferior del tablero */
.board-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.25rem;
}

.turn-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.turn-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-color-hover);
}

.turn-dot.white {
  background: #ffffff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
}

.turn-dot.black {
  background: #111827;
  border-color: #64748b;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}

.board-quick-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-subtle {
  height: 38px;
  padding: 0 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-subtle:hover {
  border-color: var(--accent-gold);
  color: var(--text-primary);
}

/* Columna del entrenador táctico */
.trainer-column {
  min-width: 0;
}

.card-trainer {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
}

.puzzle-header {
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.puzzle-tags {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.badge-source {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--accent-emerald);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  text-transform: uppercase;
}

.badge-mode {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--accent-gold);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
}

.puzzle-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.35rem;
  line-height: 1.3;
}

.puzzle-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Feedback banner reactivo */
.feedback-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 1rem 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.feedback-banner.status-waiting {
  background: var(--bg-surface-elevated);
  border-color: var(--border-color);
}

.feedback-banner.status-waiting .feedback-icon {
  color: var(--accent-blue);
}

.feedback-banner.status-correct {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.3);
}

.feedback-banner.status-correct .feedback-icon {
  color: var(--accent-emerald);
}

.feedback-banner.status-error {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
}

.feedback-banner.status-error .feedback-icon {
  color: var(--accent-rose);
}

.feedback-banner.status-complete {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
}

.feedback-banner.status-complete .feedback-icon {
  color: var(--accent-gold);
}

.feedback-headline {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
}

.feedback-message {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* Pista táctica */
.hint-card {
  background: var(--bg-surface-elevated);
  border: 1px dashed var(--accent-gold);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
}

.hint-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent-gold);
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
}

.hint-body {
  color: var(--text-primary);
  font-size: 0.88rem;
  line-height: 1.5;
}

/* Explicación táctica profunda */
.tactics-explanation {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
}

.tactics-title {
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-blue);
  margin: 0 0 0.4rem;
}

.tactics-text {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.5;
}

/* Botones de acción del entrenador */
.trainer-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.btn-action-primary {
  height: 46px;
  min-height: 40px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--accent-gold);
  border: none;
  border-radius: var(--radius-sm);
  color: #0b0f17;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: filter 0.2s;
}

.btn-action-primary:hover {
  filter: brightness(1.1);
}

.btn-action-secondary {
  height: 44px;
  min-height: 40px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-action-secondary:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.btn-split-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.btn-action-outline {
  height: 42px;
  min-height: 40px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-action-outline:hover {
  border-color: var(--border-color-hover);
  color: var(--text-primary);
}

/* Tarjeta de clasificaciones mundiales */
.card-main {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
}

.card-header-leaderboard {
  margin-bottom: 1.25rem;
}

.section-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.4rem;
}

.section-desc {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0;
}

.leaderboard-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.btn-tab-leader {
  height: 40px;
  min-height: 40px;
  padding: 0 1.25rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.btn-tab-leader:hover {
  border-color: var(--accent-gold);
  color: var(--text-primary);
}

.btn-tab-leader.active {
  background: var(--accent-gold);
  border-color: var(--accent-gold);
  color: #0b0f17;
  font-weight: 700;
}

.leaderboard-table-container {
  width: 100%;
  overflow-x: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.leaderboard-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
}

.leaderboard-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.leaderboard-table tr:hover td {
  background: var(--bg-surface-elevated);
}

.player-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.player-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  background: #1e293b;
}

.player-name-wrap {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
}

.player-username {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.player-title-badge {
  background: #dc2626;
  color: #ffffff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  display: inline-block;
}

.score-cell {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--accent-gold);
  font-size: 0.95rem;
}

/* Modales */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 1rem;
}

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: var(--shadow-board);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}

.btn-close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.modal-body {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.55;
  margin-bottom: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
}

.btn-primary {
  height: 42px;
  min-height: 40px;
  padding: 0 1.5rem;
  background: var(--accent-gold);
  border: none;
  border-radius: var(--radius-sm);
  color: #0b0f17;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Responsive móvil */
@media (max-width: 768px) {
  .board-wrapper {
    padding: 0.35rem;
  }

  .card-trainer, .card-main {
    padding: 1.25rem;
  }

  .btn-split-row {
    grid-template-columns: 1fr;
  }
}
