* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(94vw, 70vh, 720px);
  aspect-ratio: 1;
  overflow: hidden;
  border: 12px solid rgba(247, 239, 225, 0.16);
  border-radius: clamp(1.2rem, 3vw, 2.25rem);
  background: #1b1510;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.board.my-turn {
  border-color: rgba(247, 200, 115, 0.9);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 0 0 2px rgba(247, 200, 115, 0.28),
    0 0 34px rgba(247, 200, 115, 0.42),
    0 24px 80px rgba(185, 137, 73, 0.26);
  animation: board-turn-glow 1.35s ease-in-out infinite alternate;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: none;
  cursor: pointer;
  touch-action: manipulation;
}

.square.light {
  background: linear-gradient(135deg, #eadcc8, #d7bd94);
}

.square.dark {
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.12), transparent 28%),
    linear-gradient(135deg, #5a3926, #2c1f18);
}

.square.selected {
  box-shadow: inset 0 0 0 5px #b7ff3c;
}

.square.movable .piece {
  cursor: grab;
  filter: drop-shadow(0 0 14px rgba(183, 255, 60, 0.62));
}

.square.movable::before {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 999px;
  border: 2px solid rgba(183, 255, 60, 0.72);
  pointer-events: none;
}

.square.legal::after {
  content: "";
  position: absolute;
  width: 32%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(247, 200, 115, 0.86);
  box-shadow: 0 0 28px rgba(247, 200, 115, 0.8);
}

.square.capture::after {
  width: 58%;
  background: transparent;
  border: 4px solid rgba(247, 200, 115, 0.95);
}

.piece {
  position: relative;
  z-index: 2;
  width: 72%;
  aspect-ratio: 1;
  border-radius: 999px;
  transform: translateY(-2%);
  transition: transform 180ms ease, filter 180ms ease;
}

.piece:hover {
  transform: translateY(-7%) scale(1.03);
}

.piece:active {
  cursor: grabbing;
}

.piece.black {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.18), transparent 18%),
    linear-gradient(145deg, #33271f, #090706);
  border: 2px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 -10px 18px rgba(0, 0, 0, 0.45), 0 10px 18px rgba(0, 0, 0, 0.38);
}

.piece.white {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.95), transparent 22%),
    linear-gradient(145deg, #fff6df, #c79b61);
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 -10px 18px rgba(120, 70, 24, 0.26), 0 10px 18px rgba(0, 0, 0, 0.28);
}

.piece.king::before {
  content: "D";
  position: absolute;
  inset: 18%;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 2px solid currentColor;
  color: rgba(247, 200, 115, 0.95);
  font-size: clamp(0.75rem, 2.4vw, 1.35rem);
  font-weight: 900;
  font-family: Manrope, sans-serif;
}

.piece.white.king::before {
  color: #5d3a1e;
}

.player-panel {
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.player-panel.active {
  border-color: rgba(185, 137, 73, 0.8);
  background: rgba(185, 137, 73, 0.14);
  box-shadow:
    inset 0 0 0 1px rgba(247, 200, 115, 0.2),
    0 0 0 2px rgba(247, 200, 115, 0.14),
    0 0 26px rgba(247, 200, 115, 0.34);
  transform: translateY(-2px);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(circle at top, rgba(185, 137, 73, 0.18), transparent 32%),
    rgba(11, 9, 7, 0.78);
  backdrop-filter: blur(16px);
}

.modal-card {
  width: min(100%, 34rem);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1.75rem;
  padding: 1.5rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03)),
    #17120d;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 24px 80px rgba(0, 0, 0, 0.45);
  animation: pop-in 220ms ease both;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes board-turn-glow {
  from {
    border-color: rgba(247, 200, 115, 0.72);
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.12),
      0 0 0 2px rgba(247, 200, 115, 0.18),
      0 0 22px rgba(247, 200, 115, 0.3),
      0 24px 80px rgba(185, 137, 73, 0.22);
  }
  to {
    border-color: rgba(255, 219, 143, 1);
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.2),
      0 0 0 3px rgba(247, 200, 115, 0.34),
      0 0 42px rgba(247, 200, 115, 0.58),
      0 24px 90px rgba(185, 137, 73, 0.34);
  }
}

.piece {
  animation: pop-in 220ms ease both;
}

@media (max-width: 640px) {
  .board {
    width: min(94vw, 58vh);
    border-width: 7px;
    border-radius: 1.25rem;
  }

  .square.selected {
    box-shadow: inset 0 0 0 3px #b7ff3c;
  }

  .square.capture::after {
    border-width: 3px;
  }

  .piece {
    width: 74%;
  }

  .modal-card {
    border-radius: 1.35rem;
    padding: 1.25rem;
  }
}

@media (max-width: 380px) {
  .board {
    width: min(94vw, 54vh);
    border-width: 5px;
  }

  .piece.king::before {
    border-width: 1px;
  }
}
