:root {
  --bg: #15131a;
  --panel: #221f29;
  --text: #ece6da;
  --muted: #9a93a6;
  --gold: #d9b45a;
  --light-sq: #cfc6b4;
  --dark-sq: #5a5560;
  --board: min(92vw, 76vh, 640px);
  --sq: calc(var(--board) / 8);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #2a2433, var(--bg) 70%);
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
}

header { text-align: center; padding: 16px 16px 4px; }
h1 { margin: 0; color: var(--gold); letter-spacing: 0.08em; font-size: 2rem; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-style: italic; }

main {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  padding: 16px;
}

/* Board */
.board-wrap { display: flex; flex-direction: column; gap: 6px; }

.board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq));
  grid-template-rows: repeat(8, var(--sq));
  border: 6px solid #3b3442;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  user-select: none;
}

.board3d {
  width: min(92vw, 760px);
  height: min(92vw * 0.85, 76vh, 640px);
  cursor: pointer;
  touch-action: none;
}
.board3d canvas { display: block; }

.square { position: relative; cursor: pointer; }
.square.light { background: var(--light-sq); }
.square.dark { background: var(--dark-sq); }
.square.last::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(217, 180, 90, 0.35);
}
.square.selected::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(120, 200, 140, 0.5);
}
.square.check::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(230, 40, 40, 0.9), rgba(230, 40, 40, 0) 70%);
}
.square.target::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28%;
  height: 28%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(30, 30, 30, 0.35);
  pointer-events: none;
}
.square.target.capture::after {
  width: 92%;
  height: 92%;
  background: none;
  border: 4px solid rgba(200, 40, 40, 0.6);
}

.coord {
  position: absolute;
  font-size: calc(var(--sq) * 0.18);
  font-family: system-ui, sans-serif;
  opacity: 0.7;
  pointer-events: none;
}
.coord.rank { top: 3px; left: 4px; }
.coord.file { bottom: 2px; right: 5px; }
.light .coord { color: var(--dark-sq); }
.dark .coord { color: var(--light-sq); }

.piece {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: calc(var(--sq) * 0.78);
  line-height: 1;
  pointer-events: none;
}
.piece.white {
  color: #f7f1e3;
  text-shadow: 0 0 2px #000, 0 2px 4px rgba(0, 0, 0, 0.7);
}
.piece.black {
  color: #1c1a20;
  text-shadow: 0 0 2px #bbb, 0 2px 4px rgba(0, 0, 0, 0.6);
}
.piece.moving { z-index: 10; transition: transform 380ms cubic-bezier(0.3, 0.7, 0.4, 1); }

/* Captured pieces get smashed, wizard-chess style. */
.piece.smashed {
  position: absolute;
  inset: 0;
  z-index: 3;
  animation: smash 700ms ease-in 250ms forwards;
}
@keyframes smash {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; filter: none; }
  20% { transform: translate(-6%, 0) rotate(-8deg); }
  40% { transform: translate(6%, 0) rotate(8deg); filter: brightness(2); }
  100% { transform: translate(0, 30%) rotate(40deg) scale(1.6); opacity: 0; filter: blur(4px); }
}

.graveyard {
  min-height: calc(var(--sq) * 0.5);
  font-size: calc(var(--sq) * 0.42);
  line-height: 1;
  display: flex;
  flex-wrap: wrap;
}
.graveyard .piece { width: auto; height: auto; }

/* Side panel */
.panel {
  width: min(92vw, 300px);
  background: var(--panel);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.panel h2 {
  font-size: 1rem;
  color: var(--gold);
  margin: 16px 0 6px;
  border-bottom: 1px solid #3b3442;
  padding-bottom: 4px;
}

.status { font-size: 1.15rem; min-height: 1.5em; margin-bottom: 12px; }
.status.over { color: var(--gold); font-weight: bold; }

.controls { display: flex; flex-direction: column; gap: 8px; }
.controls label { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
select, button {
  font: inherit;
  background: #302b38;
  color: var(--text);
  border: 1px solid #4a4354;
  border-radius: 6px;
  padding: 6px 10px;
}
button { cursor: pointer; flex: 1; }
button:hover:not(:disabled) { border-color: var(--gold); }
button:disabled { opacity: 0.5; cursor: default; }
.buttons { display: flex; gap: 8px; }
.hint { margin: 0; font-size: 0.85rem; color: var(--muted); font-style: italic; }

.moves {
  margin: 0;
  padding-left: 2.2em;
  max-height: 180px;
  overflow-y: auto;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.9rem;
}
.moves li span { display: inline-block; min-width: 4.5em; }

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.9rem;
  color: var(--muted);
}
.log li { padding: 3px 0; }
.log li:first-child { color: var(--text); }

/* Promotion dialog */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay[hidden] { display: none; }
.dialog {
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 16px 20px;
  text-align: center;
}
.promo-choices { display: flex; gap: 8px; }
.promo-choices button {
  width: var(--sq);
  height: var(--sq);
  padding: 0;
  background: var(--light-sq);
}
