/* Board, squares and square states. Colours only via tokens. */

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  border: var(--line-strong) solid var(--ink);
  background: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.sq {
  --sq-fg: var(--ink);
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.sq--light { background: var(--square-light); }
.sq--dark { background: var(--square-dark); --sq-fg: var(--paper); }
.sq.is-selected { background: var(--yellow); --sq-fg: var(--ink); }

.board.is-locked .sq { cursor: default; }
.board:not(.is-locked) .sq.has-own { cursor: grab; }

.sq:focus-visible {
  z-index: 4;
  outline: 4px solid var(--ink);
  outline-offset: -4px;
  box-shadow: inset 0 0 0 8px var(--yellow);
}

/* Check: red disc behind the king */
.sq.is-check::before {
  content: '';
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  background: var(--red);
  z-index: 0;
  pointer-events: none;
}

/* Last move: red triangle in the top right corner */
.sq.is-last::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 30%;
  height: 30%;
  background: var(--red);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
  z-index: 2;
  pointer-events: none;
}

.sq__piece {
  position: absolute;
  inset: 7%;
  z-index: 1;
  pointer-events: none;
  will-change: transform;
}
.sq__piece svg { width: 100%; height: 100%; }
.sq__piece.is-dragging { opacity: 0.35; }

/* Target dot and capture ring */
.sq__mark {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  display: none;
}
.sq.has-target .sq__mark {
  display: block;
  left: 37%;
  top: 37%;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--sq-fg);
}
.sq.has-capture .sq__mark {
  display: block;
  inset: 4%;
  border-radius: 50%;
  border: 5px solid var(--sq-fg);
}

/* Coordinates inside the corner */
.sq__rank,
.sq__file {
  position: absolute;
  z-index: 3;
  font-size: var(--fs-coord);
  font-weight: 700;
  line-height: 1;
  color: var(--sq-fg);
  pointer-events: none;
}
.sq__rank { top: 3px; left: 4px; }
.sq__file { right: 4px; bottom: 3px; }

/* Piece following the pointer while dragging */
.board-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  pointer-events: none;
}
.board-ghost svg { width: 100%; height: 100%; }
