/* Chess Game Styles */

/* === Setup Panel === */
.chess-setup {
  max-width: 400px;
  margin: 40px auto;
  background-color: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 32px;
  text-align: center;
}

.chess-setup h2 {
  font-size: 1.6rem;
  color: #ffffff;
  margin: 0 0 24px 0;
}

.setup-row {
  margin-bottom: 20px;
}

.setup-label {
  display: block;
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.setup-options {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.setup-btn {
  padding: 8px 16px;
  background-color: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  color: #ccc;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.setup-btn:hover {
  border-color: #64b5f6;
  color: #fff;
}

.setup-btn.active {
  background-color: #1e88e5;
  border-color: #1e88e5;
  color: #fff;
}

.btn-start-game {
  margin-top: 12px;
  width: 100%;
  padding: 12px;
  font-size: 1rem;
}

/* === Game Layout === */
.chess-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 10px;
  flex-wrap: wrap;
}

/* === Left Panel === */
.chess-left-panel,
.chess-right-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 140px;
}

.panel-box {
  background-color: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 10px;
}

.panel-box h3 {
  font-size: 0.72rem;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 6px 0;
  text-align: center;
}

/* Captured pieces */
.captured-list {
  min-height: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 4px;
  justify-content: center;
}

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

/* Move history */
.history-box {
  max-height: 300px;
  overflow: hidden;
}

.move-history {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 250px;
  overflow-y: auto;
  font-size: 0.8rem;
  font-family: 'Courier New', monospace;
  color: #bbb;
}

.move-history li {
  padding: 2px 4px;
  border-bottom: 1px solid #1a1a1a;
}

.move-num {
  color: #666;
}

/* === Controls === */
.chess-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chess-controls .btn {
  font-size: 0.82rem;
  padding: 8px 12px;
}

.btn-sm {
  font-size: 0.82rem;
  padding: 8px 12px;
}

.btn-danger {
  background-color: #c62828;
}

.btn-danger:hover {
  background-color: #e53935;
  box-shadow: 0 4px 12px rgba(229, 57, 53, 0.35);
}

/* === Game Info === */
.game-info {
  text-align: left;
  font-size: 0.82rem;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}

.info-label {
  color: #888;
}

.info-value {
  color: #ddd;
  font-weight: 600;
}

/* === Board === */
.chess-board-wrapper {
  position: relative;
  flex-shrink: 0;
}

.turn-indicator {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: #ccc;
  padding: 6px 0;
  margin-bottom: 4px;
  background-color: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
}

/* The board */
.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(480px, 70vw);
  aspect-ratio: 1;
  border: 2px solid #444;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.chess-square {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  user-select: none;
}

.chess-square.light {
  background-color: #b58863; /* warm brown */
}

.chess-square.dark {
  background-color: #6d4c3d; /* dark brown */
}

/* Coordinate labels: using pseudo-elements on edge squares would be nice
   but for simplicity we use the existing pattern */

/* Piece styling */
.chess-piece {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  line-height: 1;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  transition: transform 0.1s ease;
}

.chess-piece[data-color="w"] {
  color: #ffffff;
  text-shadow: 0 0 3px rgba(0,0,0,0.8), 0 1px 2px rgba(0,0,0,0.9);
}

.chess-piece[data-color="b"] {
  color: #111111;
  text-shadow: 0 0 2px rgba(255,255,255,0.15);
}

.chess-square:hover .chess-piece {
  transform: scale(1.08);
}

/* Selection highlights */
.chess-square.selected {
  background-color: rgba(255, 235, 59, 0.5) !important;
}

.chess-square.valid-move::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  background-color: rgba(0, 200, 83, 0.45);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.chess-square.valid-capture {
  box-shadow: inset 0 0 0 4px rgba(244, 67, 54, 0.5);
}

.chess-square.in-check {
  background-color: rgba(244, 67, 54, 0.55) !important;
  animation: checkPulse 1s ease-in-out infinite;
}

@keyframes checkPulse {
  0%, 100% { box-shadow: inset 0 0 0 3px rgba(244, 67, 54, 0.7); }
  50% { box-shadow: inset 0 0 0 6px rgba(244, 67, 54, 0.9); }
}

.chess-square.last-move {
  background-color: rgba(255, 193, 7, 0.3) !important;
}

/* Check alert */
.check-alert {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(244, 67, 54, 0.92);
  color: #fff;
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 700;
  z-index: 20;
  pointer-events: none;
  animation: fadeInOut 1.5s ease-in-out forwards;
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* === Modals === */
.chess-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.chess-modal-overlay[hidden] {
  display: none !important;
}

.chess-modal {
  background-color: #1a1a1a;
  border: 1px solid #3a3a3a;
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  min-width: 280px;
}

.chess-modal h2 {
  font-size: 1.4rem;
  color: #ffffff;
  margin: 0 0 8px 0;
}

.go-message {
  font-size: 1.1rem;
  color: #aaa;
  margin: 0 0 20px 0;
}

/* Promotion modal */
.promo-options {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 16px 0;
}

.promo-btn {
  width: 60px;
  height: 60px;
  background-color: #2a2a2a;
  border: 2px solid #444;
  border-radius: 8px;
  font-size: 2rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.promo-btn:hover {
  border-color: #64b5f6;
  background-color: #333;
  transform: scale(1.1);
}

#promotion-modal .chess-modal {
  padding: 24px;
}

#promotion-modal h2 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

/* === Responsive === */

/* Tablet */
@media screen and (max-width: 768px) {
  .chess-layout {
    gap: 10px;
    padding: 10px 6px;
  }

  .chess-left-panel,
  .chess-right-panel {
    min-width: 100px;
  }

  .chess-board {
    width: min(400px, 80vw);
  }

  .panel-box {
    padding: 8px;
  }

  .history-box {
    max-height: 200px;
  }

  .move-history {
    max-height: 160px;
  }

  .chess-setup {
    margin: 20px auto;
    padding: 24px;
  }
}

/* Mobile */
@media screen and (max-width: 480px) {
  .chess-layout {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 8px 4px;
  }

  .chess-left-panel,
  .chess-right-panel {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    min-width: 0;
    width: 100%;
  }

  .panel-box {
    flex: 1;
    min-width: 80px;
    max-width: 160px;
  }

  .history-box {
    order: 3;
    width: 100%;
    max-width: none;
  }

  .chess-board {
    width: min(340px, 90vw);
  }

  .turn-indicator {
    font-size: 0.8rem;
  }

  .chess-setup {
    margin: 12px auto;
    padding: 20px 16px;
  }

  .chess-setup h2 {
    font-size: 1.3rem;
  }

  .setup-btn {
    padding: 6px 12px;
    font-size: 0.82rem;
  }

  .promo-btn {
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
  }
}

/* Desktop wide */
@media screen and (min-width: 1200px) {
  .chess-board {
    width: 540px;
  }

  .chess-left-panel,
  .chess-right-panel {
    min-width: 160px;
  }
}
