.board-wrapper {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--c-board-frame);
  border-radius: var(--r-sm);
  padding: 8px;
  box-shadow: var(--sh-board);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: none;
  transition: box-shadow var(--t-med);
}

.board-wrapper::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: var(--r-sm);
  padding: 2px;
  background: linear-gradient(135deg, #6b4c3a, var(--c-board-frame), #6b4c3a);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

#chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--c-board-light);
  box-shadow: inset 0 0 20px rgba(0,0,0,0.2);
  position: relative;
  touch-action: none;
}

/* ===== Клетки ===== */
.square {
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  aspect-ratio: 1 / 1;
  position: relative;
  font-size: clamp(24px, 6vw, 50px);
  transition: background var(--t-fast);
}

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

.square .coord {
  position: absolute;
  font-size: clamp(10px, 1.2vw, 14px);
  font-weight: 500;
  pointer-events: none;
  opacity: 0.6;
}
.square .coord-file { bottom: 2px; right: 4px; }
.square .coord-rank { top: 2px; left: 4px; }
.square.light .coord { color: #5a4a3a; }
.square.dark  .coord { color: var(--c-board-light); opacity: 0.5; }

/* ===== Курсоры ===== */
.square.has-piece { cursor: grab; }
.square.has-piece:active { cursor: grabbing; }
.board-wrapper.dragging,
.board-wrapper.dragging .square.has-piece { cursor: grabbing; }

/* ===== Подсветки ===== */
.square.last-move {
  background: var(--c-last-move) !important;
  transition: background var(--t-med);
}

.square.selected {
  background: var(--c-selected) !important;
}

.square.valid-move::before {
  content: '';
  position: absolute;
  width: 24%;
  height: 24%;
  background: var(--c-valid);
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
  animation: dotIn var(--t-med);
}
.square.dark.valid-move::before { background: var(--c-valid-dark); }

@keyframes dotIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.square.valid-capture {
  background: var(--c-capture) !important;
  box-shadow: inset 0 0 0 3px rgba(200, 50, 50, 0.4);
}

/* ===== Фигуры ===== */
.square .piece {
  pointer-events: none;
  line-height: 1;
  filter: var(--sh-piece);
  position: relative;
  z-index: 1;
  font-size: inherit;
  transition: transform var(--t-fast);
  animation: pieceIn var(--t-med);
}

@keyframes pieceIn {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.square .piece.white {
  color: #ffffff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.5);
}
.square .piece.black {
  color: #1a1a1a;
  text-shadow: 0 2px 6px rgba(255,255,255,0.15);
}
.square.dragging .piece {
  transform: translateY(-8px) scale(1.1);
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.5));
}

/* ===== Drag ghost ===== */
#drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  font-size: clamp(28px, 6vw, 50px);
  line-height: 1;
  filter: var(--sh-ghost);
  transform: translate(-50%, -50%) scale(1.1);
  transition: none;
  opacity: 0;
  will-change: transform, left, top;
}
#drag-ghost.visible { opacity: 1; }
#drag-ghost .piece.white { color: #ffffff; text-shadow: 0 2px 12px rgba(0,0,0,0.7); }
#drag-ghost .piece.black { color: #1a1a1a; text-shadow: 0 2px 12px rgba(255,255,255,0.2); }