.board-wrapper {
  position: relative;
  width: 100%;
  max-width: min(760px, 92vw);
  margin: 0 auto;
}

.board-frame {
  position: relative;
  padding: 12px;
  background: linear-gradient(145deg, #3d3428 0%, #2a231c 50%, #1f1a15 100%);
  border-radius: var(--radius-md);
  box-shadow:
    var(--shadow-lift),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -2px 4px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(196, 163, 90, 0.15);
}

.board-frame::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(196, 163, 90, 0.08);
  border-radius: calc(var(--radius-md) - 4px);
  pointer-events: none;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.board-square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.board-square.light {
  background: var(--board-light, #e8dcc4);
}

.board-square.dark {
  background: var(--board-dark, #8b7355);
}

.board-square.highlight {
  position: relative;
  overflow: hidden;
}

.board-square.highlight::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgb(255, 213, 28);
  border-radius: 50%;
  transform: scale(0);
  animation: select-fill 0.3s ease-out forwards;
}

@keyframes tile-blink-red {
  0%,
  100% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
}

.board-square.check,
.board-square.checkmate {
  position: relative;
}

.board-square.check::after,
.board-square.checkmate::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(220, 50, 50, 0.65);
  pointer-events: none;
  z-index: 1;
}

.board-square.check::after {
  animation: tile-blink-red 0.8s ease-in-out infinite;
}

.board-square.checkmate::after {
  animation: tile-blink-red 0.6s ease-in-out 3;
}

.board-square.selected {
  position: relative;
  overflow: hidden;
}

.board-square.selected::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgb(246, 200, 102);
  border-radius: 50%;
  transform: scale(0);
  animation: select-fill 0.25s ease-out forwards;
}

.board-square.legal-target::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(40, 35, 28, 0.35);
}

.board-square.legal-capture::after {
  content: "";
  position: absolute;
  inset: 8%;
  border: 3px solid rgba(40, 35, 28, 0.35);
  border-radius: 50%;
  background: transparent;
}

.chess-piece {
  width: 88%;
  height: 88%;
  cursor: grab;
  z-index: 2;
  transition: transform 0.1s ease;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.chess-piece:active {
  cursor: grabbing;
}

.chess-piece.dragging {
  opacity: 0.15;
}

.chess-piece {
  display: flex;
  justify-content: center;
  align-items: center;
}

.chess-piece img {
  object-fit: contain;
}

.type-p img {
  width: 65%;
}

.type-n img {
  width: 80%;
}

.type-b img {
  width: 88%;
}

.type-r img {
  width: 72%;
}

.type-q img {
  width: 88%;
}

.type-k img {
  width: 85%;
}

.dragging-piece {
  position: fixed;
  width: 50px;

  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 1000;
  opacity: 0.55;
}

.board-coords {
  position: absolute;
  font-size: 0.6rem;
  font-weight: 600;
  pointer-events: none;
  opacity: 0.55;
}

.board-coords.file {
  bottom: 3px;
  right: 5px;
}

.board-coords.rank {
  top: 3px;
  left: 5px;
}

.board-square.light .board-coords {
  color: var(--board-dark, #8b7355);
}

.board-square.dark .board-coords {
  color: var(--board-light, #e8dcc4);
}

.board-controls {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.move-list {
  font-family: "Source Sans 3", monospace;
  font-size: 0.875rem;
  max-height: 280px;
  overflow-y: auto;
}

.move-list-table {
  width: 100%;
  border-collapse: collapse;
}

.move-list-table td {
  padding: 0.35rem 0.5rem;
  color: var(--text-secondary);
}

.move-list-table td.move-num {
  color: var(--text-muted);
  width: 2rem;
  text-align: right;
  padding-right: 0.75rem;
}

.move-list-table td.move-san {
  cursor: pointer;
  border-radius: 3px;
  transition: background var(--transition);
}

.move-list-table td.move-san:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.move-list-table td.move-san.is-current {
  background: rgba(196, 163, 90, 0.15);
  color: var(--accent-gold-light);
  font-weight: 600;
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 2rem;
  align-items: start;
  max-width: 1200px;
  margin: 0 auto;
}

.game-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.opponent-card {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.opponent-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bg-elevated), var(--bg-hover));
  border: 2px solid var(--border-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.opponent-info h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}

.opponent-info p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.game-status {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
}

.game-status.your-turn {
  background: rgba(196, 163, 90, 0.12);
  color: var(--accent-gold-light);
  border: 1px solid rgba(196, 163, 90, 0.25);
}

.game-status.opponent-turn {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.game-status.game-over {
  background: rgba(180, 60, 60, 0.12);
  color: #d4a0a0;
  border: 1px solid rgba(180, 60, 60, 0.25);
}

.clock-display {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .game-sidebar {
    order: -1;
  }
}

.promotion-overlay {
  position: fixed;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  background: var(--bg-elevated, #2a231c);
  border: 1px solid rgba(196, 163, 90, 0.3);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}

.promotion-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease;
}

.promotion-choice:hover {
  background: rgba(196, 163, 90, 0.15);
}

.promotion-choice img {
  width: 42px;
  height: 42px;
}

.move-quality-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.move-quality-badge img {
  width: 70%;
  height: 70%;
  object-fit: contain;
}

.move-quality-best {
  background: #3d9970;
}
.move-quality-good {
  background: #6aa84f;
}
.move-quality-okay {
  background: #a3b854;
}
.move-quality-inaccuracy {
  background: #f1c40f;
}
.move-quality-mistake {
  background: #e67e22;
}
.move-quality-blunder {
  background: #e74c3c;
}

.game-result-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.game-result-badge img {
  width: 70%;
  height: 70%;
  object-fit: contain;
}

.game-result-lost {
  background: #e74c3c;
}
.game-result-won {
  background: #2e7d4f;
}
.game-result-resign {
  background: #e74c3c;
}

@keyframes king-shiver {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }
  20% {
    transform: translate(-2px, 0) rotate(-4deg);
  }
  40% {
    transform: translate(2px, 0) rotate(4deg);
  }
  60% {
    transform: translate(-1px, 0) rotate(-2deg);
  }
  80% {
    transform: translate(1px, 0) rotate(2deg);
  }
}

.board-square.check .chess-piece.type-k {
  animation: king-shiver 0.2s ease-in-out;
}

@keyframes select-fill {
  from {
    transform: scale(0);
  }
  to {
    transform: scale(1.5);
  }
}

@keyframes tile-flash-red {
  0% {
    opacity: 0;
  }
  40% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.board-square.wrong-move {
  position: relative;
}

.board-square.wrong-move::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(220, 50, 50, 0.65);
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  animation: tile-flash-red 0.6s ease-in-out;
}

@keyframes tile-flash-green {
  0% {
    opacity: 0;
  }
  40% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.board-square.correct-move {
  position: relative;
}

.board-square.correct-move::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(60, 180, 90, 0.65);
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  animation: tile-flash-green 0.6s ease-in-out;
}

.chess-board {
  position: relative;
}

.arrow-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

.move-quality-miss {
  background: #c96b4f;
}
