/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', sans-serif;
  background: #1a1a2e;
  background-image: radial-gradient(circle at 30% 70%, #16213e 0%, #1a1a2e 60%);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: #fff;
  user-select: none;
  touch-action: none;
}

/* ===== TOP BAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(4px);
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-back {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.15);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn-back:hover { background: rgba(255,255,255,0.3); }

.game-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 0.8rem;
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0.9;
  white-space: nowrap;
}

/* ===== GAME WRAPPER ===== */
.game-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  min-height: 0;
  gap: 0.5rem;
}

.turn-indicator {
  font-size: 1rem;
  font-weight: 700;
  padding: 0.3rem 1.2rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  transition: background 0.3s, color 0.3s;
}
.turn-indicator.player-turn {
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.turn-indicator.cpu-turn {
  background: rgba(255,107,53,0.3);
  color: #ff6b35;
}

/* ===== BOARD ===== */
.board-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  border: 3px solid rgba(255,255,255,0.2);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  aspect-ratio: 1;
  max-width: min(90vw, 70vh, 520px);
  max-height: min(90vw, 70vh, 520px);
  width: 100%;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
}

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

/* Highlight valid moves */
.cell.valid-move {
  cursor: pointer;
}
.cell.valid-move::after {
  content: '';
  position: absolute;
  width: 35%;
  height: 35%;
  border-radius: 50%;
  background: rgba(76, 175, 80, 0.5);
  pointer-events: none;
  animation: pulse 1.2s infinite;
}

.cell.valid-capture::after {
  width: 80%;
  height: 80%;
  background: transparent;
  border: 3px solid rgba(244, 67, 54, 0.7);
  border-radius: 50%;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.05); }
}

/* Last move highlight */
.cell.last-from {
  box-shadow: inset 0 0 0 3px rgba(255, 235, 59, 0.4);
}
.cell.last-to {
  box-shadow: inset 0 0 0 3px rgba(255, 235, 59, 0.6);
}

/* ===== PIECES ===== */
.piece {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  position: absolute;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  z-index: 2;
}
.piece:hover {
  transform: scale(1.08);
}

/* Player piece (dark) */
.piece.player {
  background: radial-gradient(circle at 35% 35%, #555, #222);
  border: 2.5px solid #111;
  box-shadow: 0 3px 8px rgba(0,0,0,0.5), inset 0 1px 2px rgba(255,255,255,0.15);
}

/* CPU piece (orange) */
.piece.cpu {
  background: radial-gradient(circle at 35% 35%, #ff8f5e, #e05520);
  border: 2.5px solid #c44a1a;
  box-shadow: 0 3px 8px rgba(0,0,0,0.4), inset 0 1px 2px rgba(255,255,255,0.25);
}

/* Selected piece */
.piece.selected {
  transform: scale(1.12);
  box-shadow: 0 0 0 3px #4caf50, 0 4px 12px rgba(76,175,80,0.5);
  z-index: 3;
}

/* King indicator */
.piece.king::after {
  content: '';
  position: absolute;
  width: 50%;
  height: 50%;
  border-radius: 50%;
  border: 2.5px solid #ffd700;
  background: radial-gradient(circle, rgba(255,215,0,0.35), transparent);
  box-shadow: 0 0 6px rgba(255,215,0,0.5);
}

/* Moving animation */
.piece.moving {
  transition: top 0.3s ease, left 0.3s ease;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 0.5rem 1.5rem;
  border: none;
  border-radius: 999px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.btn:active { transform: scale(0.96); }
.btn-orange { background: #ff6b35; color: #fff; }
.btn-orange:hover { opacity: 0.88; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal-content {
  text-align: center;
  background: #1e2a3a;
  border-radius: 20px;
  padding: 2rem 2.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: popIn 0.3s ease;
  max-width: 90vw;
}

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.modal-icon { font-size: 3.5rem; margin-bottom: 0.5rem; }
.modal-content h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 0.3rem;
}
.modal-content p {
  font-size: 1rem;
  color: rgba(255,255,255,0.7);
  margin-bottom: 0.5rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .game-title { font-size: 0.95rem; }
  .board {
    max-width: min(95vw, 65vh, 400px);
    max-height: min(95vw, 65vh, 400px);
  }
  .turn-indicator { font-size: 0.85rem; }
  .btn { font-size: 0.8rem; padding: 0.4rem 1.2rem; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .topbar { padding: 0.25rem 0.5rem; }
  .game-title { display: none; }
  .board {
    max-width: min(50vw, 80vh);
    max-height: min(50vw, 80vh);
  }
  .turn-indicator { font-size: 0.8rem; padding: 0.2rem 0.8rem; }
  .btn { font-size: 0.75rem; padding: 0.3rem 1rem; }
  .game-wrapper { gap: 0.2rem; padding: 0.2rem; }
}

/* ===== SEO GAME INFO SECTION ===== */
body:has(.game-info) { overflow-y: auto; height: auto; min-height: 100dvh; }
.game-info {
  max-width: 780px;
  margin: 1rem auto;
  padding: 1rem 1.2rem;
  background: rgba(0,0,0,0.15);
  border-radius: 12px;
  color: rgba(255,255,255,0.85);
  font-size: 0.88rem;
  line-height: 1.6;
}
.game-info h2 { font-size: 1.1rem; font-weight: 800; margin-bottom: 0.5rem; }
.game-info h3 { font-size: 0.95rem; font-weight: 700; margin: 0.8rem 0 0.3rem; }
.game-info ul { padding-left: 1.2rem; }
.game-info li { margin-bottom: 0.2rem; }
