:root {
  --bg-main: #0e141b;
  --bg-surface: #17212b;
  --bg-card: #202b38;
  --border-color: #2a3a4d;
  --accent-gold: #f59e0b;
  --accent-blue: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --square-light: #e2d6b5;
  --square-dark: #b88b4a;
  --square-highlight: rgba(56, 189, 248, 0.45);
  --square-target: rgba(34, 197, 94, 0.4);
  --square-check: rgba(239, 68, 68, 0.6);
  --font-sans: 'Inter', sans-serif;
  --font-serif: 'Cinzel', serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body.steam-theme {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* HEADER */
.game-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-zone {
  display: flex;
  align-items: center;
  gap: 12px;
}

.game-logo {
  font-size: 2rem;
  background: rgba(245, 158, 11, 0.15);
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.game-title {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent-gold);
  letter-spacing: 0.05em;
}

.game-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ai-elo-badge {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: var(--accent-blue);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
}

.badge-dot {
  width: 8px;
  height: 8px;
  background: var(--accent-blue);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-blue);
}

.btn-subtle {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-exit {
  background: transparent;
  border: 1px solid #ef4444;
  color: #ef4444;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

/* BANNER */
.counter-banner {
  background: linear-gradient(90deg, #991b1b, #7f1d1d);
  color: #fef2f2;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  border-bottom: 1px solid #ef4444;
}

/* CONTAINER PRINCIPAL */
.game-container {
  display: flex;
  flex-grow: 1;
  padding: 24px;
  gap: 24px;
  max-width: 1300px;
  margin: 0 auto;
  width: 100%;
}

/* BARRE EVALUATION */
.eval-bar-container {
  width: 28px;
  background: #334155;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column-reverse;
}

.eval-bar-fill {
  background: #f8fafc;
  width: 100%;
  transition: height 0.4s ease;
}

.eval-score {
  position: absolute;
  bottom: 8px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: #0f172a;
  font-family: var(--font-mono);
}

/* BOARD WRAPPER */
.board-wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* CADRE EXTÉRIEUR ET COORDONNÉES DE L'ÉCHIQUIER (A-H & 1-8) */
.board-outer-frame {
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #2b1810 0%, #170e08 100%);
  border: 4px solid #4a301f;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.75), inset 0 0 15px rgba(0, 0, 0, 0.7);
  padding: 6px;
  user-select: none;
}

.coords-row {
  display: flex;
  align-items: center;
  height: 28px;
}

.board-center-row {
  display: flex;
  align-items: center;
}

.coords-col {
  display: flex;
  flex-direction: column;
  width: 28px;
  height: 560px;
}

.coord-corner {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.coord-file {
  flex: 1;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: #f59e0b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 28px;
}

.coord-rank {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: #f59e0b;
}

.chessboard {
  width: 560px;
  height: 560px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 3px solid #1a0f08;
  border-radius: 4px;
  box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.8);
  user-select: none;
}

/* ÉTIQUETTES DANS LES COINS DES CASES (STYLE CHESS.COM) */
.sq-rank-label {
  position: absolute;
  top: 3px;
  left: 4px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
  pointer-events: none;
  opacity: 0.8;
}

.sq-file-label {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
  pointer-events: none;
  opacity: 0.8;
}

.square.light .sq-rank-label,
.square.light .sq-file-label {
  color: #785a3c;
}

.square.dark .sq-rank-label,
.square.dark .sq-file-label {
  color: #d2b48c;
}

.piece-glyph {
  font-size: 42px;
  line-height: 1;
  z-index: 1;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease;
}

.square.light {
  background-color: var(--square-light);
  color: #2b1f14;
}

.square.dark {
  background-color: var(--square-dark);
  color: #1f140a;
}

.square.selected {
  background-color: var(--square-highlight) !important;
}

.square.valid-target::after {
  content: '';
  width: 16px;
  height: 16px;
  background: var(--square-target);
  border-radius: 50%;
  position: absolute;
}

.square.valid-capture {
  background-color: rgba(239, 68, 68, 0.45) !important;
}

.square.valid-castle {
  background-color: rgba(59, 130, 246, 0.45) !important;
  box-shadow: inset 0 0 14px rgba(59, 130, 246, 0.85) !important;
  position: relative;
}

.square.valid-castle::before {
  content: '🏰';
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 16px;
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.square.in-check {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.95) 0%, rgba(185, 28, 28, 0.8) 75%) !important;
  box-shadow: 0 0 25px rgba(239, 68, 68, 0.95), inset 0 0 10px rgba(255, 255, 255, 0.6) !important;
  animation: kingCheckPulse 0.9s infinite alternate ease-in-out;
  border-radius: 4px;
  z-index: 2;
}

@keyframes kingCheckPulse {
  0% { transform: scale(1); filter: drop-shadow(0 0 6px #ef4444); }
  100% { transform: scale(1.05); filter: drop-shadow(0 0 14px #f87171); }
}

.board-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px;
}

.turn-indicator {
  font-weight: 700;
  color: var(--accent-gold);
  font-size: 0.95rem;
}

.btn-subtle-sm {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}

/* COACH SIDEBAR */
.coach-sidebar {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 440px;
}

.coach-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 16px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.coach-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.coach-avatar {
  font-size: 24px;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid var(--accent-gold);
  padding: 6px 10px;
  border-radius: 8px;
}

.coach-name {
  font-weight: 700;
  color: var(--accent-gold);
  font-size: 1rem;
}

.level-badge {
  font-size: 0.75rem;
  color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.1);
  padding: 2px 8px;
  border-radius: 12px;
}

.coach-speech-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #e2e8f0;
}

.analysis-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 14px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.box-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.quality-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  width: fit-content;
}

.quality-badge.excellent { background: rgba(34, 197, 94, 0.2); color: #4ade80; }
.quality-badge.inaccuracy { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.quality-badge.blunder { background: rgba(239, 68, 68, 0.25); color: #f87171; }

.move-detail {
  font-size: 0.85rem;
  color: #cbd5e1;
  line-height: 1.4;
}

.history-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 14px;
  border-radius: 10px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  max-height: 180px;
}

.history-list {
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  color: #94a3b8;
}

.chesscom-promo-card {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 14px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.promo-text {
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.btn-chesscom {
  background: #81b64c;
  color: white;
  text-align: center;
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 700;
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s;
}

.btn-chesscom:hover {
  background: #a3d160;
}

/* MODALS */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 30px;
  border-radius: 16px;
  max-width: 650px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-title {
  font-family: var(--font-serif);
  color: var(--accent-gold);
  font-size: 1.5rem;
  text-align: center;
}

.modal-desc {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.levels-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
}

.level-option {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text-main);
  transition: all 0.2s;
}

.level-option:hover {
  border-color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.05);
}

.level-option.selected {
  border-color: var(--accent-gold);
  background: rgba(245, 158, 11, 0.1);
}

.lvl-icon {
  font-size: 24px;
}

.lvl-info strong {
  display: block;
  font-size: 0.95rem;
}

.lvl-info span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.btn-primary-large {
  background: var(--accent-gold);
  color: #0f172a;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
}

.end-game-card {
  text-align: center;
  align-items: center;
}

.end-icon {
  font-size: 48px;
}

.end-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.advice-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 18px;
  border-radius: 10px;
  font-size: 0.95rem;
  line-height: 1.6;
  text-align: left;
  color: #e2e8f0;
  width: 100%;
}

.end-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.btn-chesscom-large {
  background: #81b64c;
  color: white;
  text-align: center;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
  font-size: 1rem;
}


/* ==========================================================================
   INDICATION DU DERNIER COUP JOUÉ (BLANCS ET NOIRS)
   Case de départ en rouge clair, Case d'arrivée en rouge foncé
   ========================================================================== */
.square.last-move-src {
  background-color: rgba(239, 68, 68, 0.42) !important;
  box-shadow: inset 0 0 10px rgba(239, 68, 68, 0.55) !important;
}

.square.light.last-move-src {
  background-color: rgba(248, 113, 113, 0.48) !important;
  box-shadow: inset 0 0 8px rgba(239, 68, 68, 0.45) !important;
}

.square.dark.last-move-src {
  background-color: rgba(220, 38, 38, 0.40) !important;
  box-shadow: inset 0 0 8px rgba(185, 28, 28, 0.55) !important;
}

.square.last-move-dest {
  background-color: rgba(153, 27, 27, 0.88) !important;
  box-shadow: inset 0 0 14px rgba(69, 10, 10, 0.95), 0 0 8px rgba(185, 28, 28, 0.5) !important;
  position: relative;
}

.square.light.last-move-dest {
  background-color: rgba(160, 25, 25, 0.88) !important;
}

.square.dark.last-move-dest {
  background-color: rgba(125, 15, 15, 0.94) !important;
}

/* Contraste optimal pour les glyphes de pièces noires et blanches sur fond rouge */
.square.last-move-dest .piece-glyph {
  filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.65)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.9)) !important;
}
