:root {
  --bg: #f4ece0;
  --bg-accent: #eadfcc;
  --text: #3b2f26;
  --text-muted: #7a6a5b;
  --light-square: #f0dfc0;
  --dark-square: #b58863;
  --frame: #6f4e37;
  --button: #8a5a3c;
  --button-hover: #724830;
  --button-text: #fffaf2;
  --board-size: min(92vw, 60vh, 560px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background: radial-gradient(circle at top, var(--bg) 0%, var(--bg-accent) 100%);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
}

.game {
  width: 100%;
  max-width: 640px;
  padding: 24px 16px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.title {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: normal;
  letter-spacing: 0.04em;
}

.status-bar {
  width: calc(var(--board-size) + 1.6rem);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}

.buttons {
  display: flex;
  gap: 8px;
}

.status {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-muted);
  font-style: italic;
}

.btn {
  font: inherit;
  font-size: 0.95rem;
  padding: 8px 18px;
  border: none;
  border-radius: 6px;
  background: var(--button);
  color: var(--button-text);
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover {
  background: var(--button-hover);
}

.btn:focus-visible {
  outline: 3px solid #d9a066;
  outline-offset: 2px;
}

/* Board with rank/file labels */
.board-frame {
  display: grid;
  grid-template-columns: 1.6rem var(--board-size);
  grid-template-rows: var(--board-size) 1.6rem;
}

.ranks,
.files {
  display: grid;
  color: var(--text-muted);
  font-size: clamp(0.7rem, 2.6vw, 0.9rem);
  user-select: none;
}

.ranks {
  grid-template-rows: repeat(8, 1fr);
}

.files {
  grid-template-columns: repeat(8, 1fr);
}

.ranks span,
.files span {
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 4px solid var(--frame);
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(59, 47, 38, 0.25);
  /* border sits inside the fixed grid cell */
  box-sizing: border-box;
}

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

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

/* Pieces */
.square {
  display: flex;
  align-items: center;
  justify-content: center;
}

.piece {
  /* each square is board-size / 8 wide; the symbol fills most of it */
  font-size: calc(var(--board-size) / 8 * 0.8);
  line-height: 1;
  user-select: none;
  font-family: "Segoe UI Symbol", "DejaVu Sans", "Noto Sans Symbols 2", "Arial Unicode MS", sans-serif;
}

.piece.white {
  color: #fffdf7;
  text-shadow:
    -1px -1px 0 #2b2018,
    1px -1px 0 #2b2018,
    -1px 1px 0 #2b2018,
    1px 1px 0 #2b2018,
    0 2px 3px rgba(0, 0, 0, 0.35);
}

.piece.black {
  color: #2b2018;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.35);
}

/* Interaction */
.square {
  cursor: pointer;
}

.square.selected {
  background: #e8c35a;
  box-shadow: inset 0 0 0 3px #b8860b;
}

/* Squares the selected piece can move to */
.square.move-target,
.square.capture-target {
  position: relative;
}

.square.move-target::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(59, 47, 38, 0.28);
  pointer-events: none;
}

.square.capture-target {
  box-shadow: inset 0 0 0 4px rgba(160, 60, 40, 0.55);
}

/* King in check, and status alerts */
.square.in-check {
  background: radial-gradient(circle, #e0604a 0%, #c0392b 45%, transparent 85%), var(--dark-square);
}

.square.in-check.light {
  background: radial-gradient(circle, #e0604a 0%, #c0392b 45%, transparent 85%), var(--light-square);
}

.status.alert {
  color: #9b2c1f;
  font-style: normal;
  font-weight: bold;
}

/* Pawn promotion chooser */
.promotion-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(59, 47, 38, 0.5);
  z-index: 10;
}

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

.promotion-dialog {
  width: min(100%, 400px);
  padding: 20px 16px 16px;
  background: var(--bg);
  border: 4px solid var(--frame);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.promotion-title {
  margin: 0 0 14px;
  font-size: 1.2rem;
  font-weight: normal;
}

.promotion-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.promotion-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 2px;
  font: inherit;
  color: var(--text);
  background: var(--light-square);
  border: 2px solid var(--dark-square);
  border-radius: 6px;
  cursor: pointer;
}

.promotion-choice:hover,
.promotion-choice:focus-visible {
  background: #e8c35a;
  border-color: #b8860b;
  outline: none;
}

.promotion-choice .choice-glyph {
  font-size: clamp(2.2rem, 11vw, 3.2rem);
  line-height: 1;
}

.choice-name {
  font-size: 0.8rem;
}

.promotion-cancel {
  margin-top: 14px;
  padding: 4px 14px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text-muted);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn:disabled:hover {
  background: var(--button);
}

/* Captured pieces and move list */
.info-panel {
  width: calc(var(--board-size) + 1.6rem);
  padding: 12px 14px;
  background: rgba(255, 250, 242, 0.6);
  border: 1px solid #d8c7ab;
  border-radius: 8px;
}

.captured-row {
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 1.8rem;
}

.captured-label {
  flex: 0 0 5.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.captured-pieces {
  display: flex;
  flex-wrap: wrap;
}

.captured-pieces .piece {
  font-size: 1.4rem;
}

.panel-title {
  margin: 10px 0 6px;
  font-size: 1rem;
  font-weight: normal;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-top: 1px solid #d8c7ab;
  padding-top: 10px;
}

.move-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 9rem;
  overflow-y: auto;
  font-size: 0.95rem;
}

.move-row {
  display: grid;
  grid-template-columns: 2.4rem 1fr 1fr;
  padding: 2px 4px;
}

.move-row:nth-child(even) {
  background: rgba(181, 136, 99, 0.12);
}

.move-number {
  color: var(--text-muted);
}

.move-empty {
  color: var(--text-muted);
  font-style: italic;
}
