:root {
  --page-bg: #1c2026;
  --panel-bg: #262c34;
  --panel-border: #39424e;
  --ink: #eef1f4;
  --ink-dim: #b9c1cb;
  --accent: #7fa650;
  --accent-dark: #5d7f38;
  --light-sq: #ece0c8;
  --dark-sq: #739552;
  --hl-last: rgba(205, 210, 60, 0.55);
  --hl-check: rgba(220, 60, 50, 0.75);
  --hl-select: rgba(64, 140, 220, 0.55);
  --dot: rgba(30, 40, 30, 0.35);
  --cap-dot: rgba(30, 40, 30, 0.55);
  --radius: 10px;
  --board-size: min(92vw, 62vh, 560px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
}

h1, h2 {
  font-family: Georgia, "Times New Roman", serif;
  margin: 0;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: #14181d;
  border-bottom: 1px solid var(--panel-border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 40px; line-height: 1; color: var(--light-sq); }
.brand h1 { font-size: 26px; letter-spacing: 0.5px; }
.tagline { margin: 2px 0 0; font-size: 12px; color: var(--ink-dim); }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.ctl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-dim); }
select, .btn {
  font: inherit;
  color: var(--ink);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 10px;
}
select:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent-dark); color: #101408; font-weight: 700; }
.btn.primary:hover { background: var(--accent-dark); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: default; }

.layout {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
  padding: 18px;
  max-width: 1020px;
  margin: 0 auto;
}

.board-col { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.status {
  min-height: 28px;
  font-weight: 600;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 14px;
}

.board-wrap { position: relative; width: var(--board-size); height: var(--board-size); }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  border: 3px solid #101408;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--board-size) / 11);
  line-height: 1;
  cursor: pointer;
}
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq .piece { pointer-events: none; }
.sq .piece.w { color: #fafafa; text-shadow: 0 0 2px #000, 1px 1px 1px #000, -1px -1px 1px #000; }
.sq .piece.b { color: #151515; text-shadow: 0 0 2px #888, 1px 1px 1px #555; }
.sq.last { box-shadow: inset 0 0 0 100px var(--hl-last); }
.sq.selected { box-shadow: inset 0 0 0 100px var(--hl-select); }
.sq.in-check { box-shadow: inset 0 0 0 100px var(--hl-check); }
.sq.legal::after {
  content: "";
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--dot);
}
.sq.legal.capture::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: calc(var(--board-size) / 130) solid var(--cap-dot);
}
.sq .coord {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  font-family: inherit;
  pointer-events: none;
  opacity: 0.9;
}
.sq.light .coord { color: var(--dark-sq); }
.sq.dark .coord { color: var(--light-sq); }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 2px; right: 4px; }
.sq.dragging-from { opacity: 0.55; }
.piece-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  font-size: calc(var(--board-size) / 11);
  transform: translate(-50%, -58%);
  display: none;
}

.promo, .thinking {
  position: absolute;
  z-index: 40;
}
.promo {
  display: flex;
  gap: 6px;
  background: #101408;
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 8px;
}
.promo.hidden, .thinking.hidden, .modal.hidden { display: none; }
.promo button {
  font-size: 40px;
  line-height: 1;
  width: 58px;
  height: 58px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: var(--light-sq);
  color: #151515;
  cursor: pointer;
}
.promo button:hover { background: #fff; border-color: var(--accent); }
.thinking {
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  background: rgba(16, 20, 8, 0.9);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
}

.captured {
  width: var(--board-size);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 20px;
  min-height: 86px;
}
.cap-row { display: flex; gap: 8px; align-items: baseline; }
.cap-label { font-size: 12px; color: var(--ink-dim); min-width: 135px; }
.edge { font-size: 12px; color: var(--ink-dim); margin-top: 4px; }

.side-col {
  width: 300px;
  max-width: 92vw;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.side-col h2 { font-size: 20px; margin-bottom: 8px; }
.moves {
  margin: 0;
  padding: 6px 6px 6px 34px;
  height: 320px;
  overflow-y: auto;
  background: #14181d;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 14px;
}
.moves li { padding: 1px 0; }
.hint { font-size: 12px; color: var(--ink-dim); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}
.modal-card {
  background: var(--panel-bg);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 24px 28px;
  text-align: center;
  max-width: 90vw;
}
.modal-card h2 { margin-bottom: 8px; }

@media (max-width: 900px) {
  .layout { flex-direction: column; align-items: center; }
  .side-col { width: var(--board-size); }
  .moves { height: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
