/* ============================================================
   Chess — Game Styles
   ============================================================ */

/* ── Layout ── */
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding-bottom: 2rem;
}

/* Header → see .game-header in global.css */

/* ── Mode Tabs ── */
.mode-tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: 99px;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.mode-tab {
  padding: 0.28em 0.75em;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 200ms ease;
  white-space: nowrap;
}

.mode-tab:hover:not(.active) {
  color: var(--text);
}

.mode-tab.active[data-mode="2p"] {
  background: rgba(129, 140, 248, 0.18);
  color: var(--accent);
}

.mode-tab.active[data-mode="ai-easy"] {
  background: rgba(74, 222, 128, 0.18);
  color: var(--easy);
}

.mode-tab.active[data-mode="ai-hard"] {
  background: rgba(248, 113, 113, 0.18);
  color: var(--hard);
}

/* ── Stats Bar ── */
.stats-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
  max-width: 1100px;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.stat-divider {
  width: 1px;
  height: 2.5rem;
  background: var(--border);
  flex-shrink: 0;
}

/* Turn indicator dot */
.turn-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  border: 2px solid var(--border-strong);
}

.turn-dot.white { background: #f0f0f0; border-color: #aaa; }
.turn-dot.black { background: #1a1a1a; border-color: #666; }

/* Status message */
#status-msg {
  font-size: 0.88rem;
  font-weight: 600;
}

.status-check   { color: var(--warning); }
.status-mate    { color: var(--error); }
.status-draw    { color: var(--text-muted); }
.status-normal  { color: var(--text); }

/* ── Game Layout ── */
.game-container {
  width: 100%;
  max-width: 1100px;
  padding: 0 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-layout {
  display: flex;
  gap: 1rem;
  width: 100%;
  align-items: flex-start;
  justify-content: center;
}

/* ── Board Area ── */
.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.board-with-coords {
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

/* Rank labels (1–8) on left */
.rank-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding: 0 4px 0 0;
  width: 18px;
}

.rank-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-dim);
  text-align: right;
  line-height: 1;
  user-select: none;
}

/* File labels (a–h) on bottom */
.file-labels {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  padding: 4px 0 0 18px;
  width: 100%;
}

.file-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
  flex: 1;
  user-select: none;
}

/* ── Chess Board ── */
.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 2px solid var(--border-strong);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  user-select: none;
  -webkit-user-select: none;
}

/* ── Squares ── */
.square {
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: background 80ms ease;
  -webkit-tap-highlight-color: transparent;
}

.square.light { background: #f0d9b5; }
.square.dark  { background: #b58863; }

/* Selected piece */
.square.selected {
  background: #7fc97f !important;
  box-shadow: inset 0 0 0 3px rgba(74, 222, 128, 0.8);
}

/* Last move highlight */
.square.last-move-from,
.square.last-move-to {
  background: rgba(255, 210, 50, 0.35) !important;
}

/* King in check */
.square.in-check {
  background: rgba(248, 113, 113, 0.55) !important;
  box-shadow: inset 0 0 12px rgba(248, 113, 113, 0.6);
}

/* Legal move indicator — empty square */
.square.legal-move::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

/* Legal move indicator — capturable square (has a piece) */
.square.legal-capture::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 0;
  background: transparent;
  border: 4px solid rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

/* ── Pieces ── */
.piece {
  font-size: 2.6rem;
  line-height: 1;
  pointer-events: none;
  position: relative;
  z-index: 1;
  user-select: none;
}

.piece.white {
  color: #f0f0f0;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8), 0 0 6px rgba(0,0,0,0.5);
}

.piece.black {
  color: #1a1a1a;
  text-shadow: 0 1px 2px rgba(255,255,255,0.3), 0 0 4px rgba(255,255,255,0.2);
}

/* ── Side Panel ── */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 200px;
  min-width: 160px;
}

/* ── Captured Pieces ── */
.captured-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
}

.captured-section h3 {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}

.captured-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.captured-row:last-child { margin-bottom: 0; }

.captured-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 45px;
}

.captured-pieces {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  flex: 1;
  line-height: 1;
}

.captured-piece {
  font-size: 1rem;
  line-height: 1;
}

.captured-piece.white {
  color: #f0f0f0;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

.captured-piece.black {
  color: #1a1a1a;
  text-shadow: 0 1px 1px rgba(255,255,255,0.2);
}

.score-diff {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 24px;
  text-align: right;
}

/* ── Move History ── */
.history-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  max-height: 440px;
}

.history-section h3 {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.history-list {
  overflow-y: auto;
  flex: 1;
  font-variant-numeric: tabular-nums;
}

.history-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 0.2rem;
  padding: 0.2rem 0.3rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
}

.history-row:nth-child(even) {
  background: var(--surface-2);
}

.history-num {
  color: var(--text-dim);
  font-weight: 500;
}

.history-move {
  color: var(--text);
  font-weight: 600;
  font-family: 'Courier New', monospace;
}

.history-move.current {
  color: var(--accent);
}

/* ── Action Buttons ── */
.action-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.action-buttons .btn {
  flex: 1;
  font-size: 0.8rem;
  padding: 0.4em 0.6em;
}

/* ── Promotion Modal ── */
.promotion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 27, 75, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.promotion-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.promotion-card {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: scale(0.9);
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.promotion-overlay.active .promotion-card {
  transform: scale(1);
}

.promotion-card h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}

.promotion-choices {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.promo-choice {
  width: 70px;
  height: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  gap: 0.25rem;
}

.promo-choice:hover {
  border-color: var(--accent);
  background: var(--surface-3);
  box-shadow: 0 0 12px var(--accent-glow);
  transform: translateY(-2px);
}

.promo-piece {
  font-size: 2.2rem;
  line-height: 1;
}

.promo-piece.white {
  color: #f0f0f0;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.promo-piece.black {
  color: #1a1a1a;
  text-shadow: 0 1px 2px rgba(255,255,255,0.3);
}

.promo-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ── Game Over Modal ── */
.modal-emoji {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  display: block;
}

.modal-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.modal-msg {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

/* ── AI Thinking Indicator ── */
.ai-thinking {
  display: none;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.3rem 0.6rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.ai-thinking.visible { display: flex; }

.thinking-dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  margin: 0 1px;
  animation: dot-pulse 1.2s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%            { transform: scale(1);   opacity: 1; }
}

/* ── Below Board ── */
.below-board {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 0.5rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ── Responsive ── */
@media (max-width: 860px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
  }

  .side-panel {
    width: 100%;
    max-width: 560px;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .captured-section {
    flex: 1;
    min-width: 200px;
  }

  .history-section {
    flex: 2;
    min-width: 280px;
    max-height: 180px;
  }
}

@media (max-width: 640px) {
  .mode-tab {
    padding: 0.25em 0.55em;
    font-size: 0.72rem;
  }

  .square {
    width: calc((100vw - 1.5rem - 18px - 4px) / 8);
    height: calc((100vw - 1.5rem - 18px - 4px) / 8);
  }

  .piece {
    font-size: calc((100vw - 1.5rem - 18px - 4px) / 8 * 0.72);
  }

  .side-panel {
    flex-direction: column;
  }

  .history-section {
    max-height: 150px;
  }
}

@media (max-width: 400px) {
  .square {
    width: calc((100vw - 1rem - 18px - 4px) / 8);
    height: calc((100vw - 1rem - 18px - 4px) / 8);
  }

  .piece {
    font-size: calc((100vw - 1rem - 18px - 4px) / 8 * 0.68);
  }
}
