/* ════════════════════════════════════════════════════════════
   CHESS GAME  ·  style.css
   Professional chess game styling
   ════════════════════════════════════════════════════════════ */

/* ── ROOT VARIABLES ──────────────────────────────────────────── */
:root {
  /* Colors */
  --clr-primary: #6366f1;
  --clr-light-square: #f0d9b5;
  --clr-dark-square: #b58863;
  --clr-highlight: #baca44;
  --clr-valid: #7fc97f;
  --clr-check: #e94560;
  --clr-last-move: #a8c471;

  /* Dark theme */
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --glass: rgba(255, 255, 255, 0.045);
  --glass-border: rgba(255, 255, 255, 0.09);
  --txt: #f1f5f9;
  --txt-dim: rgba(241, 245, 249, 0.6);

  /* Light theme */
  --bg-light: #f8fafc;
  --bg-light-secondary: #e2e8f0;
  --txt-dark: #1e293b;
  --txt-dark-dim: rgba(30, 41, 59, 0.7);

  /* Spacing */
  --radius: 16px;
  --gap: 14px;
}

[data-theme="light"] {
  --bg: var(--bg-light);
  --bg-secondary: var(--bg-light-secondary);
  --txt: var(--txt-dark);
  --txt-dim: var(--txt-dark-dim);
  --glass: rgba(0, 0, 0, 0.03);
  --glass-border: rgba(0, 0, 0, 0.08);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ── LAYOUT ──────────────────────────────────────────────────── */
.chess-layout-wrapper {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 12px;
  min-height: 100vh;
  align-items: flex-start;
}

.chess-container {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.ad-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 300px;
  flex-shrink: 0;
}

.ad-container {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(24px);
  padding: 8px;
  min-height: 600px;
}

.adsbygoogle {
  display: block;
  min-height: 600px;
}

/* ── HEADER ──────────────────────────────────────────────────– */
.chess-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--txt);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: var(--glass-border);
  transform: translateX(-2px);
}

.back-btn svg {
  width: 16px;
  height: 16px;
}

.chess-title {
  flex: 1;
  font-size: 24px;
  font-weight: 900;
  text-align: center;
}

.header-controls {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--txt);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.icon-btn:hover {
  background: var(--glass-border);
  transform: scale(1.05);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ── GLASS CARD ──────────────────────────────────────────────– */
.glass-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 18px 20px;
  transition: all 0.3s ease;
}

/* ── SETTINGS PANEL ──────────────────────────────────────────– */
.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-group label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--txt-dim);
}

.settings-group select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--txt);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.settings-group select:hover,
.settings-group select:focus {
  border-color: var(--clr-primary);
  outline: none;
}

/* ── BUTTONS ─────────────────────────────────────────────────– */
.primary-btn {
  padding: 12px 20px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, var(--clr-primary) 0%, #8b5cf6 100%);
  color: white;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.primary-btn:active {
  transform: scale(0.98);
}

.secondary-btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--txt);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.secondary-btn:hover {
  background: var(--glass-border);
}

/* ── STATUS BAR ──────────────────────────────────────────────– */
.status-bar {
  text-align: center;
  padding: 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--txt);
}

/* ── CHESSBOARD ──────────────────────────────────────────────– */
.chess-board-wrapper {
  display: flex;
  justify-content: center;
  padding: 12px;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  gap: 0;
  background: var(--clr-dark-square);
  border: 3px solid var(--txt);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  user-select: none;
  max-width: 100%;
}

.chess-square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  cursor: pointer;
  overflow: hidden;
  transition: background-color 0.2s ease;
}

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

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

.chess-square:hover {
  filter: brightness(1.1);
}

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

.chess-square.valid-move {
  background: radial-gradient(circle, rgba(127, 201, 127, 0.6) 30%, transparent 70%) !important;
}

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

.chess-square.check {
  background-color: var(--clr-check) !important;
}

/* Coordinates */
.rank-label,
.file-label {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.3);
}

.rank-label {
  top: 3px;
  left: 3px;
}

.file-label {
  bottom: 3px;
  right: 3px;
}

/* Pieces */
.piece {
  width: 85%;
  height: 85%;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  pointer-events: none;
}

/* ── GAME PANEL ──────────────────────────────────────────────– */
.game-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.moves-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.moves-section h3 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--txt-dim);
}

.move-list {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  max-height: 100px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  line-height: 1.5;
}

.controls-section {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.controls-section .secondary-btn {
  flex: 1;
}

/* ── CAPTURED PIECES ─────────────────────────────────────────– */
.captured-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 12px;
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.05) 0%, rgba(0, 0, 0, 0.1) 100%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
}

.captured-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.captured-section h4 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--txt-dim);
  margin: 0;
}

.captured-pieces {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 40px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  align-content: flex-start;
}

.captured-piece {
  width: 32px;
  height: 32px;
  transition: all 0.2s ease;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
  cursor: pointer;
}

.captured-piece:hover {
  transform: scale(1.15);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

/* ── PROMOTION DIALOG ────────────────────────────────────────– */
.promotion-dialog {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.promotion-content {
  background: var(--bg-secondary);
  border: 2px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  backdrop-filter: blur(24px);
}

.promotion-content p {
  font-weight: 700;
  color: var(--txt);
}

.promo-btn {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--txt);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.promo-btn:hover {
  background: var(--clr-primary);
  color: white;
  border-color: var(--clr-primary);
}

/* ── UTILITIES ───────────────────────────────────────────────– */
.hidden {
  display: none !important;
}

/* ── RESPONSIVE ──────────────────────────────────────────────– */
@media (max-width: 1024px) {
  .chess-layout-wrapper {
    flex-direction: column;
    gap: 16px;
    align-items: center;
  }

  .ad-sidebar {
    width: 100%;
    max-width: 500px;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .ad-container {
    min-height: auto;
    max-height: 120px;
  }
}

@media (max-width: 768px) {
  .ad-sidebar {
    display: none;
  }

  .chess-board {
    max-width: 90vw;
  }

  .game-panel {
    grid-template-columns: 1fr;
  }

  .captured-panel {
    grid-template-columns: 1fr;
  }

  .back-btn span {
    display: none;
  }
}

@media (max-width: 480px) {
  .chess-container {
    gap: 10px;
  }

  .settings-panel {
    gap: 10px;
  }

  .chess-board {
    border: 2px solid var(--txt);
  }

  .rank-label,
  .file-label {
    font-size: 9px;
  }
}
