:root {
  --paper: #f5dfb4;
  --paper-dark: #d9aa64;
  --ink: #201915;
  --grid: #3b2415;
  --red: #a52118;
  --black: #1b1a18;
  --accent: #1f6f78;
  --panel: #fff7e7;
  --shadow: 0 28px 70px rgba(32, 25, 21, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Songti TC", "Noto Serif TC", "PMingLiU", serif;
  background:
    radial-gradient(circle at top left, rgba(31, 111, 120, 0.2), transparent 34rem),
    linear-gradient(135deg, #281b14, #7b3e21 48%, #192f31);
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 22px;
  align-items: center;
}

.game-surface,
.side-panel {
  border: 1px solid rgba(255, 247, 231, 0.22);
  background: rgba(255, 247, 231, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.game-surface {
  padding: 22px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4.25rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.05rem;
}

.status-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.turn-label {
  min-width: 96px;
  padding: 9px 12px;
  border: 1px solid rgba(32, 25, 21, 0.28);
  text-align: center;
  font-weight: 800;
  color: var(--ink);
}

.turn-label.red {
  color: var(--red);
}

.turn-label.black {
  color: var(--black);
}

#resetButton {
  padding: 10px 14px;
  color: #fff7e7;
  background: var(--ink);
}

.preview-victory-button {
  padding: 10px 14px;
  border: 1px solid rgba(165, 33, 24, 0.38);
  background: rgba(165, 33, 24, 0.12);
  color: var(--red);
  font-weight: 900;
}

.preview-victory-button.black-preview {
  border-color: rgba(32, 25, 21, 0.34);
  background: rgba(32, 25, 21, 0.9);
  color: #fff7e7;
}

.vault-button,
.history-button,
.coordinate-toggle-button {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(32, 25, 21, 0.28);
  background: var(--ink);
  color: #fff7e7;
  font-weight: 900;
}

.coordinate-toggle-button[aria-pressed="false"] {
  border-color: rgba(31, 111, 120, 0.58);
  background: rgba(31, 111, 120, 0.12);
  color: var(--accent);
}

.mode-badge {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid rgba(32, 25, 21, 0.16);
  border-left: 5px solid rgba(32, 25, 21, 0.38);
  background: rgba(255, 247, 231, 0.52);
  color: rgba(32, 25, 21, 0.76);
  font-size: 0.98rem;
  font-weight: 900;
}

.mode-badge.active {
  border-left-color: var(--accent);
  background: rgba(31, 111, 120, 0.08);
  color: var(--accent);
}

.mode-button {
  width: 100%;
  min-height: 42px;
  margin-top: 8px;
  border: 1px solid rgba(32, 25, 21, 0.28);
  background: var(--ink);
  color: #fff7e7;
  font-size: 1rem;
  font-weight: 900;
}

.mode-button.active {
  background: var(--accent);
  color: #fff7e7;
}

.mode-control-group {
  margin-top: 10px;
  padding: 8px;
  border: 1px solid rgba(59, 36, 21, 0.16);
  background: rgba(245, 223, 180, 0.28);
}

.mode-control-label {
  margin-bottom: 6px;
  color: rgba(32, 25, 21, 0.58);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.first-controls {
  display: grid;
  gap: 4px;
}

.first-controls {
  grid-template-columns: repeat(2, 1fr);
}

.strength-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.first-button,
.strength-button {
  min-height: 34px;
  padding: 7px 6px;
  border: 1px solid rgba(32, 25, 21, 0.16);
  background: rgba(255, 247, 231, 0.64);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 900;
}

.first-button.active,
.strength-button.active {
  border-color: rgba(165, 33, 24, 0.64);
  background: var(--red);
  color: #fff7e7;
  box-shadow: 0 6px 12px rgba(165, 33, 24, 0.16);
}

.first-button[data-player-side="black"].active {
  border-color: rgba(32, 25, 21, 0.72);
  background: var(--black);
  box-shadow: 0 6px 12px rgba(32, 25, 21, 0.18);
}

.mode-status {
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(59, 36, 21, 0.12);
  background: rgba(255, 247, 231, 0.38);
  color: rgba(32, 25, 21, 0.62);
  font-size: 0.92rem;
  line-height: 1.45;
}

.save-status,
.history-status,
.coordinate-status {
  margin: 10px 0 0;
  color: rgba(32, 25, 21, 0.62);
  font-size: 0.92rem;
  line-height: 1.45;
}

.storage-dialog,
.game-history-dialog,
.replay-dialog {
  width: min(920px, calc(100vw - 24px));
  max-height: min(760px, calc(100vh - 24px));
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.storage-dialog::backdrop,
.game-history-dialog::backdrop,
.replay-dialog::backdrop {
  background: rgba(32, 25, 21, 0.62);
  backdrop-filter: blur(4px);
}

.dialog-panel {
  padding: 20px;
  border: 1px solid rgba(59, 36, 21, 0.24);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dialog-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.dialog-header h2 {
  margin-bottom: 0;
  font-size: 1.7rem;
}

.dialog-close {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(32, 25, 21, 0.24);
  background: rgba(245, 223, 180, 0.58);
  color: var(--ink);
  font-size: 1.45rem;
  line-height: 1;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-switch button {
  min-height: 42px;
  border: 1px solid rgba(32, 25, 21, 0.28);
  background: rgba(245, 223, 180, 0.6);
  color: var(--ink);
  font-weight: 900;
}

.mode-switch button.active {
  background: var(--ink);
  color: #fff7e7;
}

.storage-hint {
  margin-bottom: 14px;
  color: rgba(32, 25, 21, 0.64);
  line-height: 1.5;
}

.history-hint {
  margin-bottom: 14px;
  color: rgba(32, 25, 21, 0.64);
  line-height: 1.5;
}

.slot-list,
.game-history-list {
  max-height: min(500px, calc(100vh - 250px));
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
}

.game-history-card {
  min-height: 228px;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  padding: 18px;
  border: 1px solid rgba(59, 36, 21, 0.18);
  background: rgba(255, 247, 231, 0.72);
  overflow: hidden;
}

.history-thumbnail {
  width: 180px;
  height: 212px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(59, 36, 21, 0.28);
  background: var(--paper);
  overflow: hidden;
}

.history-game-body {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.history-game-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.history-winner {
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1;
}

.history-winner.red {
  color: var(--red);
}

.history-winner.black {
  color: var(--black);
}

.history-game-header span,
.history-game-time {
  color: rgba(32, 25, 21, 0.58);
  font-size: 0.94rem;
  line-height: 1.45;
}

.history-game-time {
  margin: 0;
}

.history-game-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-game-stats span {
  padding: 6px 10px;
  border: 1px solid rgba(32, 25, 21, 0.16);
  background: rgba(245, 223, 180, 0.52);
  color: rgba(32, 25, 21, 0.72);
  font-size: 0.88rem;
  font-weight: 900;
}

.history-game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-replay-button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid rgba(31, 111, 120, 0.58);
  background: var(--accent);
  color: #fff7e7;
  font-weight: 900;
}

.history-move-details {
  border-top: 1px solid rgba(59, 36, 21, 0.16);
  padding-top: 10px;
}

.history-move-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 900;
}

.history-move-list {
  max-height: 220px;
  margin: 10px 0 0;
  padding: 0 0 0 1.35rem;
  overflow: auto;
  color: rgba(32, 25, 21, 0.72);
  line-height: 1.65;
}

.game-history-empty {
  padding: 28px;
  border: 1px solid rgba(59, 36, 21, 0.18);
  background: rgba(255, 247, 231, 0.72);
  color: rgba(32, 25, 21, 0.56);
  text-align: center;
  font-weight: 900;
}

.slot-card {
  width: 100%;
  min-height: 228px;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 24px;
  align-items: center;
  padding: 18px;
  border: 1px solid rgba(59, 36, 21, 0.18);
  background: rgba(255, 247, 231, 0.72);
  color: var(--ink);
  text-align: left;
  overflow: hidden;
}

.slot-card:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.slot-thumbnail {
  width: 180px;
  height: 212px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(59, 36, 21, 0.28);
  background: var(--paper);
  overflow: hidden;
}

.empty-thumbnail {
  color: rgba(32, 25, 21, 0.42);
  font-weight: 900;
}

.mini-board {
  position: relative;
  width: 152px;
  aspect-ratio: 8 / 9;
}

.mini-line,
.mini-palace-line {
  position: absolute;
  display: block;
  background: rgba(59, 36, 21, 0.36);
  pointer-events: none;
}

.mini-horizontal {
  left: 0;
  width: 100%;
  height: 1px;
}

.mini-vertical {
  top: 0;
  width: 1px;
  height: 100%;
}

.mini-top-half {
  height: calc(4 / 9 * 100%);
}

.mini-bottom-half {
  top: calc(5 / 9 * 100%);
  height: calc(4 / 9 * 100%);
}

.mini-palace-line {
  width: 1px;
  height: calc(2.828 / 9 * 100%);
  transform-origin: top center;
}

.mini-marker {
  --mark-gap: 3px;
  --mark-len: 5px;
  --mark-thick: 1px;
  position: absolute;
  display: block;
  width: 13px;
  height: 13px;
  transform: translate(-50%, -50%);
  background: transparent;
  color: rgba(59, 36, 21, 0.55);
  pointer-events: none;
}

.marker-corner {
  position: absolute;
  width: var(--mark-len);
  height: var(--mark-len);
}

.marker-corner::before,
.marker-corner::after {
  content: "";
  position: absolute;
  display: block;
  background: currentColor;
}

.marker-corner::before {
  width: var(--mark-len);
  height: var(--mark-thick);
}

.marker-corner::after {
  width: var(--mark-thick);
  height: var(--mark-len);
}

.marker-corner.tl {
  right: calc(50% + var(--mark-gap));
  bottom: calc(50% + var(--mark-gap));
}

.marker-corner.tl::before {
  bottom: 0;
  left: 0;
}

.marker-corner.tl::after {
  right: 0;
  top: 0;
}

.marker-corner.tr {
  left: calc(50% + var(--mark-gap));
  bottom: calc(50% + var(--mark-gap));
}

.marker-corner.tr::before {
  bottom: 0;
  left: 0;
}

.marker-corner.tr::after {
  left: 0;
  top: 0;
}

.marker-corner.bl {
  right: calc(50% + var(--mark-gap));
  top: calc(50% + var(--mark-gap));
}

.marker-corner.bl::before {
  top: 0;
  left: 0;
}

.marker-corner.bl::after {
  right: 0;
  top: 0;
}

.marker-corner.br {
  left: calc(50% + var(--mark-gap));
  top: calc(50% + var(--mark-gap));
}

.marker-corner.br::before {
  top: 0;
  left: 0;
}

.marker-corner.br::after {
  left: 0;
  top: 0;
}

.mini-piece {
  position: absolute;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(109, 57, 31, 0.88);
  border-radius: 999px;
  background: #f4d39a;
  color: var(--black);
  font-size: 0.62rem;
  font-weight: 900;
  line-height: 1;
}

.mini-piece.red {
  color: var(--red);
}

.mini-coordinate {
  position: absolute;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(59, 36, 21, 0.22);
  border-radius: 999px;
  background: rgba(255, 247, 231, 0.72);
  color: rgba(59, 36, 21, 0.72);
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  z-index: 5;
}

.mini-coordinate.red {
  color: rgba(165, 33, 24, 0.86);
}

.mini-coordinate.black {
  color: rgba(27, 26, 24, 0.78);
}

.mini-coordinate.top {
  top: -8%;
}

.mini-coordinate.bottom {
  top: 108%;
}

.mini-last-move {
  position: absolute;
  width: 21px;
  height: 21px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  pointer-events: none;
  z-index: 2;
}

.mini-last-move-from {
  border: 2px dashed rgba(31, 111, 120, 0.62);
}

.mini-last-move-to {
  border: 2px solid rgba(31, 111, 120, 0.88);
  background: rgba(31, 111, 120, 0.12);
  box-shadow: 0 0 0 3px rgba(245, 223, 180, 0.44);
}

.replay-layout {
  display: grid;
  grid-template-columns: minmax(260px, 440px) minmax(240px, 1fr);
  gap: 22px;
  align-items: center;
}

.replay-board-shell {
  display: grid;
  place-items: center;
  padding: 42px 18px;
  border: 10px solid #6d391f;
  background:
    linear-gradient(90deg, rgba(59, 36, 21, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(59, 36, 21, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 16px 16px;
  box-shadow: inset 0 0 0 2px rgba(255, 247, 231, 0.35);
}

.replay-board-shell .mini-board {
  width: min(392px, calc(100vw - 92px));
}

.replay-board-shell .mini-line,
.replay-board-shell .mini-palace-line {
  background: rgba(59, 36, 21, 0.62);
}

.replay-board-shell .mini-piece {
  width: 34px;
  height: 34px;
  border-width: 2px;
  font-size: 1.15rem;
  z-index: 3;
}

.replay-board-shell .mini-marker {
  --mark-gap: 5px;
  --mark-len: 8px;
  --mark-thick: 2px;
  width: 22px;
  height: 22px;
}

.replay-board-shell .mini-coordinate {
  min-width: 24px;
  height: 24px;
  font-size: 0.92rem;
}

.replay-board-shell .mini-last-move {
  width: 48px;
  height: 48px;
}

.replay-panel {
  min-width: 0;
  display: grid;
  gap: 16px;
}

.replay-status {
  min-height: 78px;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid rgba(59, 36, 21, 0.16);
  background: rgba(245, 223, 180, 0.34);
  color: rgba(32, 25, 21, 0.76);
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1.55;
}

.replay-progress-row {
  display: grid;
  gap: 8px;
}

.replay-progress-row span {
  color: rgba(32, 25, 21, 0.62);
  font-size: 0.92rem;
  font-weight: 900;
}

.replay-range {
  width: 100%;
  accent-color: var(--accent);
}

.replay-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.replay-controls button {
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid rgba(32, 25, 21, 0.28);
  background: var(--ink);
  color: #fff7e7;
  font-weight: 900;
}

.replay-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.slot-meta {
  min-width: 0;
  display: grid;
  gap: 6px;
  align-content: center;
}

.slot-meta strong {
  display: block;
  font-size: 1.48rem;
  line-height: 1.25;
  white-space: normal;
}

.slot-meta span {
  display: block;
  color: rgba(32, 25, 21, 0.62);
  font-size: 1.05rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.board-wrap {
  display: grid;
  place-items: center;
  padding: clamp(34px, 9vw, 72px) 18px;
  background:
    linear-gradient(90deg, rgba(59, 36, 21, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(59, 36, 21, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 18px 18px;
  border: 12px solid #6d391f;
  box-shadow: inset 0 0 0 2px rgba(255, 247, 231, 0.35);
}

.board {
  position: relative;
  width: min(720px, calc(100vw - 92px));
  aspect-ratio: 8 / 9;
  background: var(--paper);
}

.board-coordinate {
  position: absolute;
  min-width: 1.35rem;
  height: 1.35rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(59, 36, 21, 0.2);
  border-radius: 999px;
  background: rgba(255, 247, 231, 0.58);
  color: rgba(59, 36, 21, 0.68);
  font-size: clamp(0.68rem, 1.8vw, 0.88rem);
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  z-index: 6;
}

.board-coordinate.red {
  color: rgba(165, 33, 24, 0.82);
}

.board-coordinate.black {
  color: rgba(27, 26, 24, 0.76);
}

.board-coordinate.file {
  transform: translate(-50%, -50%);
}

.board-coordinate.file.top {
  top: calc(var(--cell) * -0.72);
}

.board-coordinate.file.bottom {
  top: calc(9 * var(--cell) + var(--cell) * 0.72);
}

.grid-line {
  position: absolute;
  background: var(--grid);
  opacity: 0.82;
  pointer-events: none;
}

.grid-line.horizontal {
  left: 0;
  width: 100%;
  height: 2px;
}

.grid-line.vertical {
  top: 0;
  width: 2px;
  height: 100%;
}

.grid-line.vertical.top-half {
  height: calc(4 * var(--cell));
}

.grid-line.vertical.bottom-half {
  top: calc(5 * var(--cell));
  height: calc(4 * var(--cell));
}

.palace-line {
  position: absolute;
  width: 2px;
  height: calc(2.828 * var(--cell));
  background: var(--grid);
  transform-origin: top center;
  opacity: 0.82;
  pointer-events: none;
}

.river {
  position: absolute;
  left: 0;
  top: calc(4 * var(--cell));
  width: 100%;
  height: var(--cell);
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  text-align: center;
  color: rgba(59, 36, 21, 0.7);
  font-size: clamp(1.1rem, 3vw, 2.1rem);
  font-weight: 900;
  letter-spacing: 0.34em;
  pointer-events: none;
}

.board-marker {
  --mark-gap: 6px;
  --mark-len: 9px;
  --mark-thick: 2px;
  position: absolute;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%);
  color: rgba(59, 36, 21, 0.62);
  pointer-events: none;
}

.cell {
  position: absolute;
  width: var(--piece);
  height: var(--piece);
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border-radius: 999px;
  z-index: 2;
}

.cell.capture-hint {
  z-index: 4;
}

.cell.hint::after,
.cell.capture-hint::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: rgba(31, 111, 120, 0.32);
  pointer-events: none;
}

.cell.capture-hint::after {
  inset: calc(var(--piece) * -0.12);
  width: auto;
  height: auto;
  border: 4px solid rgba(31, 111, 120, 0.82);
  background: transparent;
  box-shadow: 0 0 0 4px rgba(245, 223, 180, 0.24);
  z-index: 2;
}

.cell.last-move-from::before,
.cell.last-move-to::before {
  content: "";
  position: absolute;
  inset: calc(var(--piece) * -0.16);
  border-radius: 999px;
  pointer-events: none;
  z-index: 0;
}

.cell.last-move-from::before {
  border: 3px dashed rgba(31, 111, 120, 0.52);
}

.cell.last-move-to::before {
  border: 3px solid rgba(31, 111, 120, 0.82);
  background: rgba(31, 111, 120, 0.12);
  box-shadow: 0 0 0 6px rgba(245, 223, 180, 0.34);
}

.piece {
  width: var(--piece);
  height: var(--piece);
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 3px solid #6d391f;
  background:
    radial-gradient(circle at 35% 28%, #fff6dd 0 18%, transparent 19%),
    radial-gradient(circle, #f9db9c, #c6883f);
  color: var(--black);
  font-size: clamp(1.25rem, 3.4vw, 2.15rem);
  font-weight: 900;
  box-shadow:
    inset 0 -5px 0 rgba(80, 43, 20, 0.18),
    0 8px 14px rgba(32, 25, 21, 0.24);
  transition: transform 140ms ease, box-shadow 140ms ease;
  position: relative;
  z-index: 1;
}

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

.piece.selected {
  transform: translateY(-5px);
  box-shadow:
    inset 0 -5px 0 rgba(80, 43, 20, 0.18),
    0 0 0 5px rgba(31, 111, 120, 0.28),
    0 14px 24px rgba(32, 25, 21, 0.28);
}

.piece.moving-source {
  opacity: 0.18;
  transform: scale(0.92);
}

.move-ghost {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 9;
  pointer-events: none;
  border-color: #1f6f78;
  box-shadow:
    inset 0 -5px 0 rgba(80, 43, 20, 0.18),
    0 0 0 6px rgba(31, 111, 120, 0.22),
    0 18px 28px rgba(32, 25, 21, 0.34);
  will-change: transform, filter;
}

.side-panel {
  min-height: 610px;
  padding: 22px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.side-panel p {
  line-height: 1.65;
}

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

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h2 {
  margin-bottom: 0;
}

#captureCount {
  min-width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(32, 25, 21, 0.24);
  border-radius: 999px;
  background: rgba(245, 223, 180, 0.68);
  font-weight: 900;
}

.capture-log {
  display: grid;
  gap: 12px;
}

.capture-group {
  padding: 12px;
  border: 1px solid rgba(59, 36, 21, 0.18);
  background:
    linear-gradient(90deg, rgba(59, 36, 21, 0.07) 1px, transparent 1px),
    linear-gradient(rgba(59, 36, 21, 0.07) 1px, transparent 1px),
    rgba(245, 223, 180, 0.36);
  background-size: 13px 13px;
}

.capture-group-title {
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  color: rgba(32, 25, 21, 0.72);
  font-size: 0.88rem;
  font-weight: 900;
}

.capture-pieces {
  min-height: 54px;
  display: flex;
  align-items: center;
  align-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}

.captured-piece {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 2px solid #6d391f;
  background:
    radial-gradient(circle at 35% 28%, #fff6dd 0 18%, transparent 19%),
    radial-gradient(circle, #f9db9c, #bd7b35);
  color: var(--black);
  font-size: 1.32rem;
  font-weight: 900;
  box-shadow:
    inset 0 -4px 0 rgba(80, 43, 20, 0.2),
    0 5px 10px rgba(32, 25, 21, 0.16);
}

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

.capture-empty {
  color: rgba(32, 25, 21, 0.48);
  font-size: 0.92rem;
}

.history-section {
  display: grid;
  gap: 10px;
}

.capture-history {
  max-height: 210px;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  overflow: auto;
  list-style: none;
}

.capture-history li {
  display: grid;
  grid-template-columns: 30px 48px 28px 48px;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid rgba(59, 36, 21, 0.14);
  background: rgba(255, 247, 231, 0.48);
}

.capture-history span {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(32, 25, 21, 0.1);
  font-size: 0.78rem;
  font-weight: 900;
}

.history-piece {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 2px solid #6d391f;
  border-radius: 999px;
  background:
    radial-gradient(circle at 35% 28%, #fff6dd 0 18%, transparent 19%),
    radial-gradient(circle, #f9db9c, #bd7b35);
  color: var(--black);
  font-size: 1.25rem;
  font-weight: 900;
  box-shadow: inset 0 -3px 0 rgba(80, 43, 20, 0.18);
}

.history-piece.red {
  color: var(--red);
}

.capture-history em {
  color: rgba(32, 25, 21, 0.54);
  font-style: normal;
  font-weight: 900;
  text-align: center;
}

.capture-history .history-empty {
  display: block;
  color: rgba(32, 25, 21, 0.48);
  font-size: 0.92rem;
}

.victory-overlay {
  --victory-color: var(--red);
  --victory-muted: rgba(165, 33, 24, 0.68);
  --victory-soft: rgba(165, 33, 24, 0.12);
  --victory-ring: rgba(165, 33, 24, 0.12);
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at center, rgba(255, 247, 231, 0.2), transparent 18rem),
    rgba(32, 25, 21, 0.74);
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transition: opacity 220ms ease;
}

.victory-overlay.black-win {
  --victory-color: var(--black);
  --victory-muted: rgba(27, 26, 24, 0.66);
  --victory-soft: rgba(27, 26, 24, 0.1);
  --victory-ring: rgba(27, 26, 24, 0.16);
}

.victory-overlay::before,
.victory-overlay::after {
  content: "";
  position: absolute;
  width: 160vw;
  height: 160px;
  background: linear-gradient(90deg, transparent, rgba(255, 247, 231, 0.34), transparent);
  transform-origin: center;
  animation: victory-beam 3.2s linear infinite;
}

.victory-overlay::before {
  transform: rotate(24deg);
}

.victory-overlay::after {
  transform: rotate(-24deg);
  animation-delay: -1.4s;
}

.victory-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.victory-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  padding: 34px 26px 28px;
  display: grid;
  justify-items: center;
  text-align: center;
  border: 2px solid rgba(255, 247, 231, 0.38);
  background:
    linear-gradient(135deg, rgba(255, 247, 231, 0.96), rgba(245, 223, 180, 0.9)),
    var(--panel);
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.4),
    inset 0 0 0 8px rgba(109, 57, 31, 0.08);
  animation: victory-panel-in 520ms cubic-bezier(0.18, 0.92, 0.24, 1.2) both;
}

.victory-logo {
  width: 150px;
  height: 150px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 8px double currentColor;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.68) 0 14%, transparent 15%),
    radial-gradient(circle, #f8d891, #b46a2f);
  color: var(--victory-color);
  box-shadow:
    0 0 0 10px var(--victory-ring),
    0 20px 42px rgba(32, 25, 21, 0.32);
  animation: victory-stamp 760ms cubic-bezier(0.16, 1, 0.3, 1) 120ms both;
}

.victory-logo.black {
  color: var(--black);
  box-shadow:
    0 0 0 10px var(--victory-ring),
    0 20px 42px rgba(32, 25, 21, 0.32);
}

.victory-logo span {
  font-size: 5.4rem;
  font-weight: 900;
  line-height: 1;
  transform: translateY(-3px);
}

.victory-kicker {
  margin: 22px 0 8px;
  color: var(--victory-color);
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0.28em;
}

.victory-panel h2 {
  margin: 0;
  color: var(--victory-color);
  font-size: clamp(2.4rem, 8vw, 5rem);
  line-height: 1;
}

#victoryText {
  max-width: 26rem;
  margin: 14px 0 22px;
  color: var(--victory-muted);
  font-size: 1.15rem;
  line-height: 1.55;
}

.victory-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.victory-actions button {
  min-width: 118px;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid var(--victory-color);
  background: var(--victory-color);
  color: #fff7e7;
  font-weight: 900;
}

.victory-actions button + button {
  background: var(--victory-soft);
  color: var(--victory-color);
}

@keyframes victory-panel-in {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes victory-stamp {
  0% {
    opacity: 0;
    transform: translateY(-34px) rotate(-12deg) scale(1.38);
  }
  58% {
    opacity: 1;
    transform: translateY(4px) rotate(4deg) scale(0.94);
  }
  100% {
    opacity: 1;
    transform: translateY(0) rotate(-2deg) scale(1);
  }
}

@keyframes victory-beam {
  from {
    translate: -38vw -26vh;
  }
  to {
    translate: 38vw 26vh;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .side-panel {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 16px, 1180px);
    padding: 8px 0;
  }

  .game-surface,
  .side-panel {
    padding: 14px;
  }

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

  .status-panel {
    width: 100%;
    justify-content: space-between;
  }

  .board-wrap {
    padding: 34px 10px;
    border-width: 7px;
  }

  .board {
    width: calc(100vw - 58px);
  }

  .slot-card,
  .game-history-card,
  .replay-layout {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 12px;
  }

  .slot-meta {
    width: 100%;
    text-align: center;
  }

  .replay-panel {
    width: 100%;
  }

  .replay-board-shell {
    width: 100%;
    padding: 34px 10px;
    border-width: 7px;
  }

  .replay-controls {
    grid-template-columns: 1fr;
  }
}
