:root {
  --ink: #172033;
  --muted: #687386;
  --light: #eee4d2;
  --dark: #7d8f72;
  --board-edge: #313d33;
  --white-piece: #fff9ef;
  --black-piece: #172033;
  --accent: #0f766e;
  --danger: #b42318;
  --panel: #fbfaf6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(125, 143, 114, 0.18), transparent 38%),
    #f5f1e9;
  font-family: Arial, Helvetica, sans-serif;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: white;
  background: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  background: #9aa4b2;
  cursor: not-allowed;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1;
}

.game {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  min-height: 100vh;
  padding: 20px;
}

.topbar,
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar {
  justify-content: space-between;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

#contextLabel {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.table {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(270px, 340px);
  gap: 18px;
  align-items: stretch;
  min-height: 0;
}

.board-wrap {
  align-self: center;
  justify-self: center;
  width: min(72vh, 72vw, 720px);
  min-width: 300px;
}

.rank-labels {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  color: #56624e;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.rank-labels.top {
  margin-bottom: 6px;
}

.rank-labels.bottom {
  margin-top: 6px;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  border: 4px solid var(--board-edge);
  border-radius: 8px;
  background: var(--board-edge);
  box-shadow: 0 22px 52px rgba(23, 32, 51, 0.22);
  overflow: hidden;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  background: var(--light);
}

.square.dark {
  background: var(--dark);
}

.square.selected {
  outline: 4px solid rgba(15, 118, 110, 0.72);
  outline-offset: -4px;
}

.square.last {
  box-shadow: inset 0 0 0 5px rgba(250, 204, 21, 0.58);
}

.square.in-check {
  background: #eab0a8;
}

.square.legal::before,
.square.capture::before {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
}

.square.legal::before {
  width: 20%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(15, 118, 110, 0.76);
}

.square.capture::before {
  inset: 10%;
  border: 4px solid rgba(15, 118, 110, 0.8);
  border-radius: 50%;
}

.piece {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 78%;
  aspect-ratio: 1;
  border-radius: 50%;
  font-size: clamp(28px, 6.4vmin, 56px);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.32);
}

.piece.white {
  color: var(--white-piece);
  text-shadow:
    0 1px 0 #433826,
    0 3px 8px rgba(23, 32, 51, 0.42);
}

.piece.black {
  color: var(--black-piece);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5),
    0 3px 8px rgba(23, 32, 51, 0.3);
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  min-height: 0;
}

.status-card,
.captured,
.moves,
.rules {
  border: 1px solid rgba(49, 61, 51, 0.18);
  border-radius: 8px;
  background: rgba(251, 250, 246, 0.92);
  box-shadow: 0 10px 24px rgba(23, 32, 51, 0.08);
}

.status-card,
.captured,
.moves {
  padding: 14px;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.25;
}

.player-side {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.captured {
  display: grid;
  gap: 12px;
}

.captured-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 28px;
}

.captured-piece {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e7dfd1;
  font-size: 21px;
  line-height: 1;
}

.captured-piece.white {
  color: #fff9ef;
  background: #536052;
}

.captured-piece.black {
  color: #172033;
  background: #c5baa8;
}

.moves {
  min-height: 140px;
  overflow: auto;
}

.moves ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
  font-size: 13px;
}

.moves li {
  line-height: 1.25;
}

.rules {
  padding: 12px 14px;
  color: #2f3b31;
  font-size: 13px;
  line-height: 1.4;
}

.rules summary {
  cursor: pointer;
  font-weight: 800;
}

.rules p {
  margin-top: 8px;
}

.result-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 20;
  display: grid;
  min-width: min(78vw, 390px);
  padding: 26px 32px;
  border: 2px solid #facc15;
  border-radius: 8px;
  color: #111827;
  background: rgba(251, 250, 246, 0.97);
  box-shadow: 0 24px 60px rgba(23, 32, 51, 0.3);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.result-overlay.hidden {
  display: none;
}

.result-message {
  color: var(--accent);
  font-size: clamp(38px, 9vmin, 76px);
  font-weight: 900;
  line-height: 1;
}

@media (max-width: 900px) {
  .table {
    grid-template-columns: 1fr;
  }

  .board-wrap {
    width: min(88vw, 640px);
  }

  .side-panel {
    grid-template-rows: auto auto auto auto;
  }
}

@media (max-width: 620px) {
  .game {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  button {
    padding: 9px 11px;
  }
}
