:root {
  --ink: #1f2933;
  --muted: #6b7280;
  --paper: #f8e1b5;
  --paper-deep: #d69b5b;
  --line: #6f3f1d;
  --cho: #1463ad;
  --han: #b42318;
  --accent: #0f766e;
  --panel: #fffaf0;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

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(180, 35, 24, 0.1), transparent 30%),
    #f6efe2;
  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(28px, 4vw, 44px);
  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(70vh, 72vw, 720px);
  min-width: 300px;
}

.file-labels {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  padding: 0 5.1%;
  color: #80512c;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

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

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

.board {
  --point-w: min(13.4%, 72px);
  --point-h: min(12%, 72px);
  position: relative;
  aspect-ratio: 9 / 10;
  padding: 5.1%;
  border: 3px solid #5a3218;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 22px 52px rgba(31, 41, 51, 0.22);
  overflow: hidden;
}

.board-line {
  position: absolute;
  z-index: 0;
  display: block;
  background: rgba(111, 63, 29, 0.86);
  pointer-events: none;
}

.board-line.vertical {
  top: 5.1%;
  width: 2px;
  height: 89.8%;
  transform: translateX(-50%);
}

.board-line.horizontal {
  left: 5.1%;
  width: 89.8%;
  height: 2px;
  transform: translateY(-50%);
}

.board-line.palace {
  height: 2px;
  transform-origin: 0 50%;
}

.point {
  position: absolute;
  z-index: 1;
  display: grid;
  place-items: center;
  width: var(--point-w);
  height: var(--point-h);
  padding: 0;
  border-radius: 0;
  background: transparent;
  transform: translate(-50%, -50%);
}

.point::before {
  content: "";
  position: absolute;
  z-index: 1;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(111, 63, 29, 0.2);
  opacity: 0;
}

.point.legal::before {
  opacity: 1;
  background: var(--accent);
}

.point.capture::before {
  z-index: 3;
  width: 96%;
  height: 96%;
  border: 3px solid var(--accent);
  background: transparent;
  opacity: 1;
  pointer-events: none;
}

.point.capture .piece {
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.8),
    inset 0 -4px 8px rgba(89, 51, 24, 0.24),
    0 0 0 4px rgba(15, 118, 110, 0.18),
    0 8px 16px rgba(31, 41, 51, 0.28);
}

.point.selected {
  background: radial-gradient(circle, rgba(15, 118, 110, 0.22), transparent 58%);
}

.point.screen {
  background: radial-gradient(circle, rgba(245, 158, 11, 0.2), transparent 58%);
}

.point.screen .piece {
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.8),
    inset 0 -4px 8px rgba(89, 51, 24, 0.24),
    0 0 0 4px rgba(245, 158, 11, 0.22),
    0 8px 16px rgba(31, 41, 51, 0.24);
}

.point.last {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.8), transparent 58%);
}

.piece {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: min(88%, 60px);
  aspect-ratio: 1;
  border: 2px solid #7c4d22;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, #fffdf6, #f7dfb2 58%, #c78948);
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.8),
    inset 0 -4px 8px rgba(89, 51, 24, 0.24),
    0 5px 10px rgba(31, 41, 51, 0.24);
  font-size: clamp(18px, 4.4vmin, 32px);
  font-weight: 900;
  line-height: 1;
}

.piece.cho {
  color: var(--cho);
}

.piece.han {
  color: var(--han);
}

.piece.general {
  width: min(98%, 68px);
}

.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(111, 63, 29, 0.22);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.88);
  box-shadow: 0 10px 24px rgba(31, 41, 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: 1px solid rgba(111, 63, 29, 0.5);
  border-radius: 50%;
  background: #f4d7a3;
  font-weight: 900;
}

.captured-piece.cho {
  color: var(--cho);
}

.captured-piece.han {
  color: var(--han);
}

.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: #3f2b1b;
  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, 380px);
  padding: 26px 32px;
  border: 2px solid #facc15;
  border-radius: 8px;
  color: #111827;
  background: rgba(255, 250, 240, 0.96);
  box-shadow: 0 24px 60px rgba(31, 41, 51, 0.3);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

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

.result-message {
  color: #0f766e;
  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, 620px);
  }

  .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;
  }
}
