/* board.css: how the chess board of src/ui/board.ts looks. Sizes inside
 * the board are in percentages and cqw (hundredths of the board's width),
 * so it looks the same at 120 px and at 1200. The squares' colours are
 * custom properties; dark mode follows the system unless the page's root
 * says data-theme="light" or "dark". */

.board {
  --board-light: #e9ecdf;
  --board-dark: #7d9b80;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  container-type: inline-size;
  border-radius: max(3px, 0.833%);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.14),
    0 10px 30px rgba(0, 0, 0, 0.12);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .board {
    --board-light: #c9d1bf;
    --board-dark: #5f7d63;
  }
}
:root[data-theme='dark'] .board {
  --board-light: #c9d1bf;
  --board-dark: #5f7d63;
}

/* A board people play on keeps every touch to itself: no scrolling, no zoom. */
.board.interactive {
  touch-action: none;
}

/* The squares: 8 rows of 8. Only this layer is clipped to the rounded
 * corners, so a dragged piece may leave the board. */
.board .grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: repeat(8, minmax(0, 1fr));
  border-radius: inherit;
  overflow: hidden;
  outline: none;
}
.board .row {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
}
.board .sq {
  position: relative;
}
.board .l {
  background: var(--board-light);
  color: var(--board-dark);
}
.board .d {
  background: var(--board-dark);
  color: var(--board-light);
}
/* A marked square (a diagram's): its translucent colour, --mark, over the square's own. */
.board .sq {
  background-image: linear-gradient(var(--mark, transparent), var(--mark, transparent));
}

/* Highlights: a tint below (last move, selected piece, a square to go to)
 * and a mark above it (check, a move's dot, a capture's ring). */
.board .sq::before,
.board .sq::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.board .last::before {
  background: rgba(250, 204, 21, 0.45);
}
.board .selected::before {
  background: rgba(21, 128, 61, 0.42);
}
.board .over::before {
  background: rgba(21, 128, 61, 0.3);
}
.board .check::after {
  background: radial-gradient(
    circle,
    rgba(220, 38, 38, 0.95) 0%,
    rgba(220, 38, 38, 0.55) 35%,
    rgba(220, 38, 38, 0) 72%
  );
}
.board .move::after {
  background: radial-gradient(circle, rgba(17, 40, 28, 0.28) 0 16%, transparent 17%);
}
.board .take::after {
  background: radial-gradient(circle, transparent 0 79%, rgba(17, 40, 28, 0.28) 80%);
}
.board .over::after {
  background: none;
}
@media (hover: hover) {
  .board .move:hover::before,
  .board .take:hover::before {
    background: rgba(21, 128, 61, 0.3);
  }
  .board .move:hover::after,
  .board .take:hover::after {
    background: none;
  }
}

/* The keyboard's square, shown only while the keyboard is in use. */
.board .grid:focus-visible .cursor {
  outline: max(2px, 0.6cqw) solid #14281c;
  outline-offset: min(-2px, -0.6cqw);
}

/* Coordinates: the rank at the top left of the left column, the file at
 * the bottom right of the bottom row, in the other square colour. */
.board .rank,
.board .file {
  position: absolute;
  z-index: 1;
  font:
    600 max(8px, 2.6cqw) / 1 Inter,
    system-ui,
    sans-serif;
  pointer-events: none;
}
.board .rank {
  top: 4%;
  left: 5%;
}
.board .file {
  bottom: 4%;
  right: 6%;
}

.board.interactive .own {
  cursor: grab;
}
.board.dragging,
.board.dragging .sq {
  cursor: grabbing;
}

/* Pieces: a square each, placed by percentage. A lifted piece rises above
 * the others and the arrows, with a deeper shadow. */
.board .pieces {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.board .pieces img {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  display: block;
  filter: drop-shadow(0 0.25cqw 0.2cqw rgba(0, 0, 0, 0.22));
}
.board .pieces img.lifted {
  z-index: 1;
  filter: drop-shadow(0 1cqw 0.8cqw rgba(0, 0, 0, 0.3));
}

.board .arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* The promotion picker: the board dimmed, and the pieces on round tiles. */
.board .promo {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  background: rgba(20, 32, 24, 0.5);
}
.board .promo[hidden] {
  display: none;
}
.board .promo button {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #f4f5ee;
  box-shadow: 0 0.3cqw 1cqw rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition:
    border-radius 0.12s,
    background 0.12s;
}
.board .promo button:hover,
.board .promo button:focus-visible {
  border-radius: 12%;
  background: #ffffff;
}
.board .promo button:focus-visible {
  outline: max(2px, 0.6cqw) solid #15803d;
  outline-offset: min(-2px, -0.6cqw);
}
.board .promo img {
  display: block;
  width: 100%;
  height: 100%;
}

/* The live region: read out, never seen. */
.board .said {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
