/* ==========================================================================
   Chessboard Grid, Pieces, Animations & Visual Overlays
   ========================================================================== */

.board-wrapper {
  position: relative;
  width: 100%;
  max-width: min(82vh, 860px);
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg);
  padding: 12px;
  background: var(--bg-tertiary);
  box-shadow: var(--shadow-board);
  border: 1px solid var(--surface-glass-border);
  user-select: none;
  touch-action: none;
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.4);
}

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

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

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

/* Coordinate notations along ranks and files */
.coord {
  position: absolute;
  font-family: var(--font-mono);
  font-size: clamp(11px, 1.4vw, 14px);
  font-weight: 700;
  pointer-events: none;
  opacity: 0.7;
}

.coord-rank {
  top: 5px;
  left: 7px;
}

.coord-file {
  bottom: 5px;
  right: 7px;
}

.board-square.light .coord {
  color: var(--tile-dark);
}

.board-square.dark .coord {
  color: var(--tile-light);
}

/* Highlights */
.board-square.highlight-last {
  background-color: var(--tile-last-move) !important;
}

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

.board-square.highlight-check {
  background: radial-gradient(circle, var(--accent-crimson-glow) 0%, var(--accent-crimson) 90%) !important;
  animation: pulse-check 1.4s infinite ease-in-out;
}

/* Checkmate Intense Crimson Red Square */
.board-square.highlight-checkmate {
  background: radial-gradient(circle, #ef4444 15%, #b91c1c 65%, #450a0a 100%) !important;
  box-shadow: inset 0 0 28px rgba(255, 0, 0, 0.95), 0 0 32px rgba(239, 68, 68, 0.9) !important;
  z-index: 15 !important;
  animation: checkmate-pulse 0.9s infinite alternate ease-in-out;
}

@keyframes checkmate-pulse {
  0% {
    filter: brightness(1);
    box-shadow: inset 0 0 20px rgba(255, 0, 0, 0.85), 0 0 18px rgba(239, 68, 68, 0.7);
  }
  100% {
    filter: brightness(1.35);
    box-shadow: inset 0 0 36px rgba(255, 0, 0, 1), 0 0 35px rgba(239, 68, 68, 1);
  }
}

@keyframes pulse-check {
  0%, 100% {
    box-shadow: inset 0 0 16px var(--accent-crimson);
  }
  50% {
    box-shadow: inset 0 0 32px var(--accent-crimson);
  }
}

/* Legal Move Dots & Capture Rings */
.legal-indicator {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  animation: pop-in 0.18s var(--ease-spring);
}

.legal-indicator.move-dot {
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(2px);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

.legal-indicator.capture-ring {
  width: 88%;
  height: 88%;
  border-radius: 50%;
  border: 4px solid rgba(0, 0, 0, 0.35);
  box-sizing: border-box;
}

@keyframes pop-in {
  from {
    transform: scale(0.3);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* Pieces */
.chess-piece {
  position: absolute;
  width: 96%;
  height: 96%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  cursor: grab;
  transition: transform 0.18s var(--ease-spring);
  will-change: transform;
}

.chess-piece img.chess-piece-img,
.chess-piece svg.chess-svg {
  width: 90%;
  height: 90%;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
  transition: transform 0.15s ease, filter 0.15s ease;
}

.chess-piece:hover img.chess-piece-img,
.chess-piece:hover svg.chess-svg {
  transform: translateY(-2px) scale(1.04);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.45));
}

.chess-piece.dragging {
  z-index: 1000 !important;
  cursor: grabbing !important;
  pointer-events: none !important;
  filter: drop-shadow(0 24px 38px rgba(0, 0, 0, 0.75)) !important;
}

/* King Fall Dramatic Animation */
.chess-piece.king-toppled {
  transform-origin: 50% 90% !important;
  animation: king-topple 0.85s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards !important;
  z-index: 60 !important;
  pointer-events: none !important;
}

@keyframes king-topple {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }
  20% {
    transform: translate(3px, -5px) rotate(16deg);
  }
  48% {
    transform: translate(9px, 4px) rotate(52deg);
  }
  72% {
    transform: translate(16px, 14px) rotate(84deg);
  }
  86% {
    transform: translate(20px, 18px) rotate(93deg);
  }
  100% {
    transform: translate(22px, 20px) rotate(88deg);
    filter: drop-shadow(0 5px 12px rgba(0, 0, 0, 0.85)) !important;
  }
}

.board-square.highlight-hover {
  background-color: var(--tile-selected) !important;
  box-shadow: inset 0 0 0 3px var(--accent-gold) !important;
}

/* SVG Arrow Layer */
.board-arrow-layer {
  position: absolute;
  top: 10px;
  left: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  pointer-events: none;
  z-index: 20;
}

/* Floating Promotion Modal */
.promotion-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 11, 16, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  border-radius: var(--radius-lg);
  transition: opacity 0.2s ease;
}

.promotion-modal.hidden {
  display: none;
}

.promotion-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--surface-glass-border);
  box-shadow: var(--shadow-board);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  text-align: center;
  animation: pop-in 0.25s var(--ease-spring);
}

.promotion-title {
  font-family: var(--font-title);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 16px;
  letter-spacing: 0.05em;
}

.promotion-pieces {
  display: flex;
  gap: 12px;
}

.promotion-btn {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  background: var(--surface-glass);
  border: 1px solid var(--surface-glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.promotion-btn:hover {
  background: var(--surface-glass-hover);
  transform: translateY(-4px) scale(1.08);
  border-color: var(--accent-gold);
}

.promotion-btn img {
  width: 48px;
  height: 48px;
}
