:root {
  --bg: #0f172a; /* slate-900 */
  --panel: #111827; /* gray-900 */
  --panel-2: #0b1220; /* deep */
  --text: #e5e7eb; /* gray-200 */
  --muted: #94a3b8; /* slate-400 */
  --accent: #22d3ee; /* cyan-400 */
  --accent-2: #06b6d4; /* cyan-500 */
  --danger: #ef4444; /* red-500 */
  --good: #22c55e; /* green-500 */
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(
    1200px 800px at 20% 0%,
    #0b1020,
    #0a0f1d 35%,
    var(--bg)
  );
  user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
    "Poppins", Arial, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  font-weight: 700;
}

.app-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(16px, 4vw, 40px);
}

.turn-indicator {
  font-weight: 600;
  color: var(--accent);
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 clamp(16px, 4vw, 40px) 18px;
}

#score-board .scores {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.score {
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 12px;
  border-radius: 10px;
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}
.dot.white {
  background: #fff;
  border: 1px solid #000;
}
.dot.black {
  background: #111;
  border: 1px solid #444;
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  padding: 6px 8px;
}
.link-btn:hover {
  color: var(--text);
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #04111f;
  border: none;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.2s ease;
}
.btn:hover {
  filter: brightness(1.1);
}
.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: linear-gradient(180deg, #a1a1aa, #71717a);
  color: #0b0b0d;
}
.btn-danger {
  background: linear-gradient(180deg, var(--danger), #c02626);
  color: #fff;
}

.layout {
  display: grid;
  grid-template-columns: 1fr minmax(320px, 640px) 1fr;
  gap: 18px;
  align-items: start;
  padding: 0 clamp(16px, 4vw, 40px) 40px;
}

.board-wrapper {
  padding: 14px;
}
.chess-board {
  width: min(86vw, 640px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.square {
  display: grid;
  place-items: center;
  position: relative;
  user-select: none;
  -webkit-user-drag: none;
  transition: background-color 0.12s ease;
}
.square.light {
  background: var(--board-light);
}
.square.dark {
  background: var(--board-dark);
}

.square.highlight {
  box-shadow: inset 0 0 0 3px rgba(34, 211, 238, 0.8);
}
.square.valid::after {
  content: "";
  position: absolute;
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: rgba(34, 211, 238, 0.7);
}
.square.capture::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 4px solid rgba(239, 68, 68, 0.9);
  border-radius: 12px;
}

.piece {
  width: 72%;
  height: 72%;
  pointer-events: none; /* click squares not image */
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.25));
  transition: transform 0.12s ease;
}

.tray h3 {
  margin-bottom: 10px;
}
.captured {
  min-height: 84px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 10px;
}
.captured img {
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2));
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
}
.modal.hidden {
  display: none;
}
.modal-card {
  width: min(90vw, 420px);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .tray {
    order: 3;
  }
  .board-wrapper {
    order: 2;
  }
  #score-board,
  #controls {
    margin: 0 16px 16px;
  }
  .app-header {
    flex-direction: column;
  }
}
