.chessboard {
  width: 100%;
  min-width: 0;
  position: relative;
  aspect-ratio: 1;
  background: #2b2023;
  padding: clamp(4px, 0.6vw, 8px);
  box-sizing: border-box;
}

.chessboard-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  height: 100%;
  border: 1px solid #271d20;
  box-sizing: border-box;
}

.chess-square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-sizing: border-box;
  color: #432a26;
  cursor: default;
  isolation: isolate;
  touch-action: manipulation;
}

.chess-square-light { background: #e6cbab; }
.chess-square-dark { background: #a76c57; color: #fff1db; }
.chessboard-active .chess-square-playable { cursor: pointer; }

.chess-square::before,
.chess-square::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.chess-square::before { inset: 0; z-index: -1; }
.chess-square-last::before { background: #eedf5875; }
.chess-square-check::before { background: #cc3848b8; }
.chess-square-selected::before { background: #70253675; box-shadow: inset 0 0 0 2px #ffefd2; }

.chess-square-legal::after {
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #2a191c59;
}

.chess-square-capture::after {
  inset: 8%;
  width: auto;
  background: transparent;
  border: clamp(2px, 0.35vw, 5px) solid #321921a6;
}

.chess-square:focus-visible {
  outline: 2px solid #fffbf1;
  outline-offset: -3px;
  z-index: 1;
}

@media (hover: hover) {
  .chessboard-active .chess-square-playable:hover { box-shadow: inset 0 0 0 1px #fff4dd; }
}

.chess-coordinate {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  font: 700 clamp(8px, 1.05vw, 11px)/1 ui-monospace, monospace;
}

.chess-coordinate-rank { left: 6%; top: 6%; }
.chess-coordinate-file { right: 7%; bottom: 6%; }

.chess-square-piece {
  width: 83%;
  height: 83%;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.chess-piece {
  width: 100%;
  height: 100%;
  fill: var(--piece-fill);
  stroke: var(--piece-stroke);
  stroke-width: 2.4px;
  overflow: visible;
  filter: drop-shadow(0 1px 0 #241b2050);
}

.chess-piece.piece-white {
  --piece-fill: #fff2d9;
  --piece-stroke: #392729;
  --piece-detail: #76564f;
}

.chess-piece.piece-black {
  --piece-fill: #281e24;
  --piece-stroke: #171015;
  --piece-detail: #cfa58c;
}

.chess-piece .piece-detail {
  fill: none;
  stroke: var(--piece-detail);
  stroke-width: 1.7px;
}

.chess-piece .piece-cross { stroke-width: 3px; }

@media (max-width: 500px) and (orientation: portrait) {
  .chess-square-piece { width: 89%; height: 89%; }
  .chess-square-legal:not(.chess-square-capture)::after { width: 28%; }
}

.chess-promotion[hidden] { display: none; }

.chess-promotion {
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 12px;
  position: absolute;
  z-index: 5;
  inset: 0;
  text-align: center;
  background: #241b20ce;
}

.chess-promotion-label {
  margin: 0;
  color: #fff2d9;
  font-weight: 700;
}

.chess-promotion-choices {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.chess-promotion-option {
  display: grid;
  place-items: center;
  width: clamp(39px, 9vw, 55px);
  aspect-ratio: 1;
  padding: 3px;
  border: 1px solid #a76c57;
  border-radius: 0;
  background: #e6cbab;
  cursor: pointer;
}

.chess-promotion-option:hover,
.chess-promotion-option:focus-visible {
  background: #fff2d9;
  outline: 2px solid #fff2d9;
  outline-offset: 1px;
}
