/* Board Container */
.board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  max-width: 740px;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: var(--board-dark);
}

/* Squares */
.square {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
}

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

.square.light .coord { color: #202636; }
.square.dark .coord { color: #f1f5f9; }

/* Piece styling */
.piece {
  width: 82%;
  height: 82%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  cursor: grab;
  transition: transform var(--transition-fast), filter var(--transition-fast);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.35));
}

.piece[data-piece^="b"] {
  filter: drop-shadow(0 1px 2px rgba(255,255,255,0.35));
}

.piece:active {
  cursor: grabbing;
}

.square .piece.dragging {
  opacity: 0.5;
  transform: scale(1.12);
  filter: drop-shadow(0 8px 6px rgba(0, 0, 0, 0.4));
}

/* Lifted piece effect when square is selected */
.square.selected .piece {
  transform: translateY(-10px) scale(1.1);
  filter: drop-shadow(0 14px 10px rgba(0, 0, 0, 0.55)) drop-shadow(0 0 8px rgba(6, 182, 212, 0.2));
  z-index: 10;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.2s ease;
}

/* Hints & Highlights */
.square.legal-move::after {
  content: '';
  position: absolute;
  width: 44%;
  height: 44%;
  background: rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Capture indicator - ring around the piece */
.square.capture-move::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 3px solid rgba(239, 68, 68, 0.5);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.2), inset 0 0 8px rgba(239, 68, 68, 0.15);
}

.square.last-move {
  background: rgba(250, 204, 21, 0.06) !important;
  box-shadow: inset 0 0 0 2px rgba(250, 204, 21, 0.35);
}

.square.check {
  background: rgba(239, 68, 68, 0.06) !important;
  box-shadow: inset 0 0 16px rgba(239, 68, 68, 0.35);
}

.square.selected {
  background: rgba(6, 182, 212, 0.08) !important;
  box-shadow: inset 0 0 0 2px rgba(6, 182, 212, 0.5);
}

/* Coordinates */
.square .coord {
  position: absolute;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  opacity: 0.75;
  pointer-events: none;
}

.square .coord.file { bottom: 2px; right: 4px; }
.square .coord.rank { top: 2px; left: 4px; }

/* Game Info Panel */
.game-info {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  width: 100%;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.game-header h3 {
  font-size: var(--text-xl);
}

.game-players {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--color-elevated);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.player-row.white {
  background: #f8fafc;
  color: #121520;
}

.player-row.black {
  background: #121520;
  color: #f8fafc;
  border: 1px solid #343d4c;
}

.player-row.white .timer {
  color: #121520;
}

.player-row.black .timer {
  color: #f8fafc;
}

.player-row.active {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-glow);
}

.player-row.my-turn {
  animation: pulse-turn 1.5s infinite;
}

@keyframes pulse-turn {
  0% { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(6, 182, 212, 0); }
  100% { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0); }
}

.player-name {
  font-weight: 600;
}

.board-turn-indicator {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-2) var(--space-6);
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #fff;
  opacity: 0;
  transition: opacity var(--transition-fast);
  box-shadow: var(--shadow-glow);
  pointer-events: none;
}

.board-turn-indicator.visible {
  opacity: 1;
}

.timer {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--color-text);
}

/* History Navigation Header */
.history-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: 0 var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease, margin-bottom 0.3s ease;
  pointer-events: none;
}

.history-nav.open {
  max-height: 60px;
  opacity: 1;
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  pointer-events: auto;
}

.history-btn {
  background: var(--color-elevated);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: all var(--transition-fast);
  line-height: 1;
}

.history-btn:hover {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.history-label {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  min-width: 120px;
  text-align: center;
}

.history-close {
  margin-left: var(--space-2);
  font-weight: 700;
}

/* Move List */
.move-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  padding: 0 0 var(--space-1);
}

.move-list-header .btn-sm {
  font-size: 0.6rem;
  padding: 2px 6px;
  line-height: 1;
}

.move-list {
  max-height: 120px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--color-bg);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  margin-bottom: var(--space-3);
  border: 1px solid var(--color-border);
}

.move-row {
  display: flex;
  gap: var(--space-4);
  padding: 2px 0;
  align-items: center;
}

.move-number {
  color: var(--color-text-secondary);
  width: 2rem;
  text-align: right;
  flex-shrink: 0;
}

.move-san {
  color: var(--color-text);
  font-weight: 500;
  cursor: pointer;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast), color var(--transition-fast);
  min-width: 3rem;
}

.move-san:hover {
  background: var(--color-primary);
  color: #fff;
}

.move-san.active {
  background: var(--color-primary);
  color: #fff;
}

/* Game Actions */
.game-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.game-actions .action-row {
  display: flex;
  gap: var(--space-3);
}

.game-actions .action-row .btn {
  flex: 1;
}

/* Game Layout */
.game-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--space-8);
  align-items: start;
}

.info-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: 320px;
  min-height: 0;
  max-height: calc(100vh - 180px);
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
  .info-section {
    width: 100%;
    min-height: auto;
  }
  .game-info {
    max-width: 100%;
  }
  .game-chat {
    flex: none;
    height: 320px;
  }
}

/* CVC Spectator Controls */
.cvc-controls {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  width: 100%;
}

.cvc-controls-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-3);
  text-align: center;
}

.cvc-controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}

.cvc-controls-row .btn {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  min-width: 44px;
}

.cvc-controls-row .btn.active {
  box-shadow: 0 0 0 2px var(--color-primary-hover);
}

.cvc-delay-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.cvc-delay-wrap label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

.cvc-delay-wrap .form-select {
  background: var(--color-elevated);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  min-width: 60px;
}

.cvc-delay-wrap .form-select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Chat inside game */
.game-chat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 180px;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  align-items: flex-start;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-width: 85%;
  font-size: var(--text-sm);
  line-height: 1.4;
  word-break: break-word;
  overflow-wrap: break-word;
}

.chat-message.self {
  align-self: flex-end;
  text-align: right;
}

.chat-message .author {
  font-weight: 600;
  font-size: var(--text-xs);
  padding: 0 var(--space-1);
}

.chat-message .content {
  color: var(--color-text);
  background: var(--color-elevated);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-align: left;
}

.chat-message.self .content {
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid rgba(6, 182, 212, 0.25);
}

/* White player messages */
.chat-message.white .author {
  color: #facc15;
}

/* Black player messages */
.chat-message.black .author {
  color: #a78bfa;
}

/* Spectator messages */
.chat-message.spectator .author {
  color: var(--color-primary);
}

/* Own messages */
.chat-message.self .author {
  color: var(--color-success);
}

.chat-input-row {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.chat-input-row input {
  flex: 1;
}

/* Captured Pieces Bars */
.captured-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: 100%;
  max-width: 740px;
  border-radius: var(--radius-md);
  min-height: 0;
  padding: 0 10px;
  overflow: hidden;
  transition: min-height 0.2s ease, padding 0.2s ease, margin 0.2s ease;
}

.captured-bar.has-pieces {
  min-height: 32px;
  padding: 6px 10px;
  margin: 4px 0;
}

.captured-bar.has-result {
  min-height: 32px;
  padding: 6px 10px;
  margin: 4px 0;
}

.captured-bar.white-bar {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.captured-bar.black-bar {
  background: #121520;
  border: 1px solid #343d4c;
}

.captured-piece {
  width: 24px;
  height: 24px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  flex-shrink: 0;
}

.captured-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 700;
  align-self: center;
  padding-left: var(--space-2);
}

.captured-bar.white-bar .captured-count {
  color: #121520;
}

.captured-bar.black-bar .captured-count {
  color: #f8fafc;
}

.captured-result {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 700;
  align-self: center;
  padding-left: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.captured-bar.white-bar .captured-result {
  color: #121520;
}

.captured-bar.black-bar .captured-result {
  color: #f8fafc;
}
