:root {
  --light: #f0d9b5;
  --dark: #b58863;
  --accent: #2e7d32;
  --sel: rgba(20, 85, 30, 0.55);
  --move-dot: rgba(20, 85, 30, 0.35);
  --capture-ring: rgba(180, 30, 30, 0.55);
  --check: rgba(220, 20, 20, 0.75);
  --bg: #20242b;
  --panel: #2b303a;
  --text: #e8e6e3;
  --muted: #9aa0a9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.layout {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.header { text-align: center; margin-bottom: 18px; }
.header h1 { margin: 0 0 4px; font-size: 1.9rem; letter-spacing: 0.5px; }
.subtitle { margin: 0; color: var(--muted); font-size: 0.95rem; }

.main {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- Board ---------- */
.board-wrap {
  position: relative;
  flex: 0 1 560px;
  width: 100%;
  max-width: 560px;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 6px solid #5c4a3a;
  border-radius: 4px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  user-select: none;
  background: var(--dark);
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 2%;
}

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

.square .piece {
  width: 88%;
  height: 88%;
  pointer-events: none;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.25));
}

.square.selected { background: var(--sel); }

.square .dot {
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--move-dot);
  pointer-events: none;
}

.square .capture-ring {
  position: absolute;
  inset: 4%;
  border-radius: 12%;
  border: 3px solid var(--capture-ring);
  pointer-events: none;
}

.square .last-move {
  position: absolute;
  inset: 0;
  background: rgba(255, 213, 96, 0.35);
  pointer-events: none;
}

.square.in-check {
  background: radial-gradient(circle, var(--check) 0%, transparent 70%);
}

/* file / rank coordinates */
.square .coord {
  position: absolute;
  font-size: clamp(8px, 1.4vw, 12px);
  font-weight: 600;
  color: rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
.square.light .coord { color: rgba(181, 136, 99, 0.9); }
.square.dark .coord  { color: rgba(240, 217, 181, 0.9); }
.coord.file { bottom: 3px; right: 5px; }
.coord.rank { top: 3px; left: 5px; }

/* ---------- Promotion overlay ---------- */
.promotion-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  z-index: 5;
}

.promotion-box {
  background: var(--panel);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.promotion-title { display: block; margin-bottom: 10px; color: var(--muted); }

.promotion-choices { display: flex; gap: 8px; }

.promotion-choices button {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--light);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.promotion-choices button:hover { transform: scale(1.08); }

.promotion-choices img { width: 80%; height: 80%; }

.hidden { display: none !important; }

/* ---------- Side panel ---------- */
.side {
  flex: 0 1 300px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 260px;
}

.status {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--panel);
  border-left: 4px solid var(--accent);
  font-size: 1.05rem;
  font-weight: 600;
}

.status.win   { border-left-color: #43a047; }
.status.loss  { border-left-color: #e53935; }
.status.warn  { border-left-color: #f9a825; }

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

.btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn:hover { background: #38404d; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.difficulty .label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.segmented {
  display: flex;
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
}

.seg-btn {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.history-wrap {
  background: var(--panel);
  border-radius: 8px;
  padding: 10px 12px;
  max-height: 260px;
  display: flex;
  flex-direction: column;
}

.history-title {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
}

.history {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 2px 10px;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

.history li {
  padding: 2px 4px;
  border-radius: 4px;
  white-space: nowrap;
}

.history .num { color: var(--muted); }
.history .last { background: rgba(255, 213, 96, 0.18); }

.footer {
  margin-top: 26px;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.footer a { color: #8ab4f8; text-decoration: none; }

@media (max-width: 640px) {
  .main { gap: 16px; }
  .side { flex-basis: 100%; }
  .history-wrap { max-height: 180px; }
}
