:root {
  color-scheme: dark;
  --page: #071011;
  --page-soft: #102326;
  --page-glow: #18393a;
  --panel: #f7efd9;
  --panel-strong: #ead9aa;
  --panel-warm: #fff8e7;
  --ink: #12201f;
  --muted: #5b665f;
  --gold: #c9a24d;
  --gold-bright: #f5d98a;
  --ivory: #fff2c9;
  --wine: #7d2632;
  --garnet: #591924;
  --checker-red: #641C28;
  --green: #1f4d43;
  --teal: #12363a;
  --line: rgba(18, 32, 31, 0.18);
  --light-square: #f2e3b8;
  --light-square-deep: #d9bd72;
  --dark-square: #2b403b;
  --dark-square-deep: #172724;
  --danger: #b83b34;
  --ok: #1f795b;
  --shadow: 0 20px 48px rgba(0, 0, 0, 0.38);
  --panel-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
  --panel-label-size: 0.88rem;
  --panel-section-label-size: 0.78rem;
  --control-font-size: 0.95rem;
  --sidebar-width: clamp(430px, 26vw, 540px);
  --layout-gap: 20px;
  --board-size: min(calc(100vh - 44px), calc(100vw - var(--sidebar-width) - 84px));
  --ui: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  --mono: "Consolas", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: var(--ui);
  color: var(--panel);
  background:
    radial-gradient(ellipse at 50% -12%, rgba(201, 162, 77, 0.2), transparent 42%),
    linear-gradient(145deg, #050a0b 0%, var(--page) 34%, var(--page-soft) 68%, #060b0c 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.page-shell {
  width: min(1880px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.app-layout {
  display: grid;
  gap: 22px;
  align-items: start;
}

.top-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: var(--layout-gap);
  align-items: start;
}

.control-sidebar,
.play-column {
  min-width: 0;
}

.control-sidebar {
  display: grid;
  gap: 12px;
}

.play-column {
  display: grid;
  align-self: start;
  gap: 0;
}

.site-header {
  position: relative;
  display: grid;
  grid-template-columns: minmax(88px, 106px) minmax(0, 1fr);
  grid-template-rows: auto auto;
  gap: 12px 14px;
  align-items: stretch;
  margin-bottom: 0;
  padding: 14px;
  overflow: hidden;
  border: 1px solid rgba(245, 217, 138, 0.32);
  border-radius: 8px;
  background:
    radial-gradient(ellipse at 42% 0%, rgba(245, 217, 138, 0.14), transparent 58%),
    linear-gradient(180deg, rgba(20, 48, 50, 0.94), rgba(5, 10, 11, 0.96));
  box-shadow:
    0 16px 36px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 248, 228, 0.12);
}

.site-header::after {
  content: "";
  position: absolute;
  inset: auto 12px 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(245, 217, 138, 0.72), transparent);
  pointer-events: none;
}

.brand-mark {
  position: relative;
  z-index: 1;
  display: inline-flex;
  grid-row: 1 / 3;
  grid-column: 1;
  width: 100%;
  height: 100%;
  min-height: 112px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 248, 228, 0.9), rgba(215, 200, 150, 0.78));
  border: 1px solid rgba(245, 217, 138, 0.58);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 8px 16px rgba(0, 0, 0, 0.18);
}

.brand-mark img {
  width: auto;
  height: 94%;
  max-width: 96%;
  object-fit: contain;
}

.title-block {
  position: relative;
  z-index: 1;
  display: grid;
  align-self: end;
  align-content: end;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--gold-bright);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 4px;
  color: #fff7df;
  font-size: clamp(2rem, 3vw, 2.45rem);
  letter-spacing: 0;
  line-height: 1;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.38);
}

.title-block p:last-child {
  max-width: 520px;
  margin-bottom: 0;
  color: #d8e3d8;
  font-size: 1rem;
  line-height: 1.25;
}

.return-link {
  position: relative;
  z-index: 1;
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border: 1px solid rgba(245, 217, 138, 0.5);
  border-radius: 8px;
  color: #fff8e4;
  font-weight: 800;
  text-decoration: none;
  background:
    linear-gradient(180deg, rgba(31, 77, 67, 0.92), rgba(13, 38, 39, 0.96));
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 228, 0.16),
    0 8px 16px rgba(0, 0, 0, 0.24);
  font-size: var(--control-font-size);
}

.site-header .return-link {
  grid-column: 2;
  grid-row: 2;
  width: 100%;
}

.return-link:hover,
.return-link:focus-visible {
  border-color: rgba(255, 242, 201, 0.8);
  background: linear-gradient(180deg, rgba(125, 38, 50, 0.94), rgba(59, 18, 26, 0.98));
}

.board-section {
  display: flex;
  justify-content: center;
}

.board-frame {
  position: relative;
  display: grid;
  width: min(100%, var(--board-size));
  aspect-ratio: 1;
  padding: clamp(9px, 0.85vw, 13px);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 248, 228, 0.08), rgba(255, 248, 228, 0) 28%),
    linear-gradient(145deg, #081010 0%, #102523 52%, #060a0b 100%);
  border: 1px solid rgba(201, 162, 77, 0.58);
  box-shadow:
    0 22px 42px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 248, 228, 0.18),
    inset 0 0 0 1px rgba(255, 242, 201, 0.12);
}

.board-frame::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255, 242, 201, 0.22);
  border-radius: 7px;
  pointer-events: none;
}

.board-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 1px solid rgba(7, 11, 12, 0.96);
  border-radius: 6px;
  background: #0f1918;
  box-shadow:
    inset 0 0 24px rgba(0, 0, 0, 0.46);
}

.square {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow:
    inset 0 0 0 1px rgba(8, 13, 13, 0.26),
    inset 0 1px 0 rgba(255, 248, 228, 0.12);
}

.square::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent 38%),
    linear-gradient(315deg, rgba(0, 0, 0, 0.1), transparent 44%);
  opacity: 0.62;
  pointer-events: none;
}

.square.light {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.34), transparent 36%),
    linear-gradient(315deg, rgba(148, 104, 34, 0.16), transparent 48%),
    linear-gradient(180deg, #fff4d3 0%, var(--light-square) 58%, var(--light-square-deep) 100%);
}

.square.dark {
  background:
    linear-gradient(145deg, rgba(255, 242, 201, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(0, 0, 0, 0.24), transparent 48%),
    linear-gradient(180deg, #36514a 0%, var(--dark-square) 48%, var(--dark-square-deep) 100%);
}

.square:disabled {
  cursor: default;
}

.square:not(:disabled):hover {
  filter: brightness(1.06);
}

.square.legal-start {
  box-shadow:
    inset 0 0 0 3px rgba(245, 217, 138, 0.72),
    inset 0 0 22px rgba(255, 248, 228, 0.26);
}

.square.selected {
  box-shadow:
    inset 0 0 0 5px rgba(245, 185, 66, 0.98),
    inset 0 0 0 8px rgba(64, 36, 9, 0.5),
    inset 0 0 30px rgba(255, 235, 156, 0.42);
}

.square.legal-end {
  box-shadow:
    inset 0 0 0 4px rgba(24, 177, 146, 0.9),
    inset 0 0 26px rgba(134, 255, 220, 0.24);
}

.square.legal-end::after {
  content: "";
  position: absolute;
  z-index: 3;
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #d8fff2 0 18%, #2ed5b1 19% 58%, #0b6a58 59% 100%);
  border: 2px solid rgba(255, 248, 228, 0.72);
  box-shadow:
    0 0 0 2px rgba(5, 18, 17, 0.28),
    0 0 16px rgba(46, 213, 177, 0.72);
  pointer-events: none;
}

.square.ai-from,
.square.ai-to {
  animation: aiPulse 2600ms ease-out forwards;
}

.square.ai-from {
  box-shadow:
    inset 0 0 0 4px rgba(255, 242, 201, 0.7),
    inset 0 0 0 7px rgba(18, 54, 58, 0.85),
    inset 0 0 30px rgba(245, 217, 138, 0.46);
}

.square.ai-to {
  box-shadow:
    inset 0 0 0 5px rgba(245, 217, 138, 0.98),
    inset 0 0 0 8px rgba(125, 38, 50, 0.55),
    inset 0 0 34px rgba(255, 248, 228, 0.46);
}

.square.check {
  box-shadow:
    inset 0 0 0 5px rgba(184, 59, 52, 0.98),
    inset 0 0 0 8px rgba(255, 216, 194, 0.36),
    inset 0 0 34px rgba(184, 59, 52, 0.48);
}

.coord {
  position: absolute;
  top: 5px;
  left: 6px;
  z-index: 2;
  color: rgba(46, 38, 24, 0.52);
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 1px 0 rgba(255, 248, 228, 0.28);
}

.square.dark .coord {
  color: rgba(255, 232, 169, 0.56);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.44);
}

.piece {
  position: relative;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  pointer-events: none;
}

.piece.chess {
  width: 98%;
  height: 98%;
  filter:
    drop-shadow(0 7px 6px rgba(0, 0, 0, 0.38))
    drop-shadow(0 1px 0 rgba(255, 248, 228, 0.22));
}

.piece.chess::before {
  content: "";
  position: absolute;
  right: 18%;
  bottom: 5%;
  left: 18%;
  height: 13%;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  filter: blur(2px);
}

.piece.chess img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.piece.checker {
  width: 94%;
  height: 94%;
  filter:
    drop-shadow(0 7px 6px rgba(0, 0, 0, 0.34))
    drop-shadow(0 1px 0 rgba(255, 248, 228, 0.16));
}

.piece.checker.lane-light {
  filter:
    drop-shadow(0 7px 6px rgba(0, 0, 0, 0.36))
    drop-shadow(0 1px 0 rgba(255, 248, 228, 0.18));
}

.piece.checker.lane-dark {
  filter:
    drop-shadow(0 8px 7px rgba(0, 0, 0, 0.42))
    drop-shadow(0 0 8px rgba(100, 28, 40, 0.46))
    drop-shadow(0 1px 0 rgba(255, 230, 202, 0.16));
}

.piece.checker img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.panel {
  position: relative;
  padding: 14px;
  overflow: hidden;
  border-radius: 8px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 253, 244, 0.92), rgba(247, 239, 217, 0.96) 38%, rgba(234, 217, 170, 0.96)),
    var(--panel);
  border: 1px solid rgba(201, 162, 77, 0.44);
  box-shadow:
    var(--panel-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    inset 0 -1px 0 rgba(128, 85, 24, 0.12);
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, rgba(89, 25, 36, 0.72), rgba(201, 162, 77, 0.86), rgba(31, 77, 67, 0.7));
  pointer-events: none;
}

.panel h2 {
  position: relative;
  margin-bottom: 10px;
  color: #15211f;
  font-size: var(--panel-label-size);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel > h2::after,
.panel-heading h2::after {
  content: "";
  display: block;
  width: 34px;
  height: 2px;
  margin-top: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), rgba(201, 162, 77, 0));
}

.mode-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  border: 0;
}

.mode-option {
  position: relative;
  min-width: 0;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-option span {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border: 1px solid rgba(18, 32, 31, 0.18);
  border-radius: 8px;
  color: #21423b;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(232, 218, 179, 0.64));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.86),
    0 1px 0 rgba(0, 0, 0, 0.05);
  font-weight: 900;
  font-size: var(--control-font-size);
  letter-spacing: 0;
  text-align: center;
}

.mode-option input:checked + span {
  color: #fff8e4;
  border-color: rgba(245, 217, 138, 0.86);
  background:
    linear-gradient(180deg, rgba(35, 86, 76, 0.98), rgba(11, 33, 35, 0.98));
  box-shadow:
    inset 0 0 0 2px rgba(245, 217, 138, 0.22),
    inset 0 1px 0 rgba(255, 248, 228, 0.18),
    0 8px 14px rgba(18, 32, 31, 0.18);
}

.mode-option input:focus-visible + span,
.start-button:focus-visible,
.sound-toggle input:focus-visible + span,
.move-button:focus-visible,
.return-link:focus-visible,
.square:focus-visible {
  outline: 3px solid rgba(245, 217, 138, 0.95);
  outline-offset: 2px;
}

.setup-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.start-button {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(74, 21, 30, 0.72);
  border-radius: 8px;
  color: #fff8e4;
  background:
    linear-gradient(180deg, #a34144 0%, var(--wine) 54%, #4f141f 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 228, 0.18),
    0 10px 18px rgba(75, 20, 28, 0.22);
  font-weight: 900;
  font-size: var(--control-font-size);
  letter-spacing: 0;
}

.start-button:hover {
  filter: brightness(1.06);
}

.sound-toggle {
  position: relative;
  display: inline-flex;
  min-width: 98px;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid rgba(18, 32, 31, 0.18);
  border-radius: 8px;
  color: #21423b;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(232, 218, 179, 0.64));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.86),
    0 1px 0 rgba(0, 0, 0, 0.05);
  font-size: var(--control-font-size);
  font-weight: 900;
}

.sound-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.sound-toggle span {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding-left: 24px;
}

.sound-toggle span::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(18, 32, 31, 0.36);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.52);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transform: translateY(-50%);
}

.sound-toggle span::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 6px;
  width: 5px;
  height: 9px;
  border: solid #fff8e4;
  border-width: 0 2px 2px 0;
  opacity: 0;
  transform: translateY(-62%) rotate(45deg);
}

.sound-toggle input:checked + span::before {
  border-color: rgba(245, 217, 138, 0.9);
  background: linear-gradient(180deg, #2d6b5e, #143e39);
}

.sound-toggle input:checked + span {
  color: var(--green);
}

.sound-toggle input:checked + span::after {
  opacity: 1;
}

.status-heading {
  margin-bottom: 8px;
}

.turn-title {
  margin-bottom: 8px;
  color: #14211f;
  font-size: clamp(1.08rem, 2.5vw, 1.25rem);
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: 0;
  text-transform: none;
  overflow-wrap: anywhere;
}

#modeReadout {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.35;
}

.status-message {
  margin-bottom: 8px;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.35;
}

.status-message:empty {
  display: none;
}

.detail-line {
  margin-bottom: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.detail-line:empty {
  display: none;
}

.result-banner {
  display: none;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 900;
  text-transform: uppercase;
}

.result-banner.visible {
  display: block;
}

.result-banner.win {
  color: #5a250e;
  background: rgba(201, 162, 77, 0.34);
  border: 1px solid rgba(201, 162, 77, 0.58);
}

.result-banner.draw {
  color: var(--green);
  background: rgba(31, 77, 67, 0.14);
  border: 1px solid rgba(31, 77, 67, 0.28);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.metrics-grid div {
  display: grid;
  min-height: 62px;
  min-width: 0;
  align-content: center;
  padding: 9px 7px;
  border-radius: 8px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.56), rgba(31, 77, 67, 0.1));
  border: 1px solid rgba(18, 32, 31, 0.08);
}

.metrics-grid strong {
  display: block;
  color: var(--green);
  font-size: 1.16rem;
  line-height: 1;
}

.metrics-grid span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

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

#legalMoveCount {
  display: inline-flex;
  min-width: 34px;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: #fff8e4;
  background:
    linear-gradient(180deg, #2d6b5e, #143e39);
  box-shadow: inset 0 1px 0 rgba(255, 248, 228, 0.18);
  font-family: var(--mono);
  font-weight: 900;
}

.move-list,
.history-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.move-button {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid rgba(18, 32, 31, 0.16);
  border-radius: 8px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(238, 223, 184, 0.62));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  text-align: left;
}

.move-button:hover:not(:disabled) {
  border-color: rgba(201, 162, 77, 0.72);
  background:
    linear-gradient(180deg, rgba(255, 250, 232, 0.92), rgba(232, 205, 139, 0.46));
}

.move-button:disabled {
  cursor: default;
  opacity: 0.58;
}

.move-button strong {
  display: block;
  font-family: var(--mono);
  font-size: 0.95rem;
}

.move-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
}

.empty-list,
.history-item {
  margin: 0;
  padding: 10px 11px;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(31, 77, 67, 0.08);
  border: 1px solid rgba(18, 32, 31, 0.08);
  line-height: 1.35;
}

.history-item {
  color: var(--ink);
}

.history-item strong {
  display: inline-block;
  min-width: 78px;
  color: var(--green);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.history-item span {
  font-family: var(--mono);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.lower-info {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(16px, 1.3vw, 24px);
  align-items: start;
  margin-top: 0;
}

.lower-info > .panel {
  min-height: 160px;
}

.rules-panel h2 {
  margin-bottom: 10px;
}

.rules-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

@media (min-width: 1500px) {
  .rules-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.rules-grid article {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(31, 77, 67, 0.08);
  border: 1px solid rgba(18, 32, 31, 0.12);
}

.rules-grid h3 {
  margin: 0 0 6px;
  color: var(--green);
  font-size: var(--panel-section-label-size);
  line-height: 1.15;
  letter-spacing: 0;
  text-transform: uppercase;
}

.rules-grid ul {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  line-height: 1.34;
}

.rules-grid li + li {
  margin-top: 4px;
}

.stats-panel {
  width: 100%;
  margin-top: clamp(18px, 1.4vw, 26px);
}

.stats-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, auto);
  gap: 14px;
  align-items: start;
  margin-bottom: 12px;
}

.stats-header h2 {
  margin-bottom: 8px;
}

.stats-header h2::after {
  content: "";
  display: block;
  width: 34px;
  height: 2px;
  margin-top: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), rgba(201, 162, 77, 0));
}

.stats-header p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.35;
}

.stats-latest {
  justify-self: end;
  max-width: 420px;
  padding: 9px 11px;
  border: 1px solid rgba(18, 32, 31, 0.1);
  border-radius: 8px;
  background: rgba(31, 77, 67, 0.08);
  color: var(--green);
  font-weight: 800;
}

.stats-grid,
.stats-type-list {
  display: grid;
  gap: 8px;
}

.stats-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.stats-grid div,
.stats-type-item,
.stats-empty {
  min-width: 0;
  padding: 10px 9px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.56), rgba(31, 77, 67, 0.1));
  border: 1px solid rgba(18, 32, 31, 0.08);
}

.stats-grid div,
.stats-type-item {
  text-align: center;
}

.stats-grid strong,
.stats-type-item strong {
  display: block;
  color: var(--green);
  font-size: 1.16rem;
  line-height: 1;
}

.stats-grid span,
.stats-type-item span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stats-breakdown {
  margin-top: 14px;
}

.stats-breakdown h3 {
  margin: 0 0 8px;
  color: var(--green);
  font-size: var(--panel-section-label-size);
  line-height: 1.15;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stats-type-list {
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}

.stats-empty {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.site-footer {
  margin: 24px -22px -22px;
  padding: 18px 22px 20px;
  color: #fff8e4;
  background:
    linear-gradient(180deg, #111616, #090b0c);
  border-top: 1px solid rgba(201, 162, 77, 0.36);
  text-align: center;
}

.site-footer a {
  color: #fff8e4;
  font-weight: 700;
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--gold-bright);
  text-decoration: underline;
}

.footer-credit {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.35;
}

.footer-credit span {
  display: inline-block;
  margin: 0 8px;
}

.footer-version {
  margin: 12px 0 0;
  color: rgba(255, 248, 228, 0.64);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.victory-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
}

.victory-overlay.visible {
  visibility: visible;
  animation: victoryFade 6400ms ease both;
}

.victory-overlay::before {
  content: "";
  position: absolute;
  inset: -12%;
  opacity: 0;
  background:
    linear-gradient(115deg, transparent 0 23%, rgba(255, 248, 228, 0.18) 24% 28%, transparent 29% 100%),
    linear-gradient(65deg, transparent 0 34%, rgba(245, 217, 138, 0.22) 35% 39%, transparent 40% 100%);
}

.victory-overlay.visible::before {
  animation: victorySweep 4400ms ease-out both;
}

.victory-card {
  position: relative;
  z-index: 2;
  display: grid;
  min-width: min(460px, calc(100vw - 42px));
  gap: 6px;
  padding: 22px 28px;
  border-radius: 8px;
  text-align: center;
  box-shadow:
    0 26px 72px rgba(0, 0, 0, 0.46),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

.victory-kicker {
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.victory-title {
  font-size: 2.15rem;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
}

.victory-spark {
  position: absolute;
  z-index: 1;
  width: 12px;
  height: 12px;
  opacity: 0;
  transform: rotate(45deg);
}

.victory-overlay.visible .victory-spark {
  animation: sparkBurst 3600ms ease-out both;
}

.spark-a {
  top: 22%;
  left: 18%;
}

.spark-b {
  top: 20%;
  right: 18%;
  animation-delay: 120ms;
}

.spark-c {
  right: 24%;
  bottom: 23%;
  animation-delay: 240ms;
}

.spark-d {
  bottom: 20%;
  left: 23%;
  animation-delay: 360ms;
}

.victory-overlay.chess-win {
  background: rgba(5, 10, 11, 0.5);
}

.victory-overlay.chess-win .victory-card {
  color: #162522;
  border: 1px solid rgba(245, 217, 138, 0.84);
  background:
    linear-gradient(180deg, rgba(255, 253, 244, 0.98), rgba(239, 223, 179, 0.98));
  animation: chessVictory 4200ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
}

.victory-overlay.chess-win .victory-kicker {
  color: var(--green);
}

.victory-overlay.chess-win .victory-title {
  color: #102326;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.68);
}

.victory-overlay.chess-win .victory-spark {
  background: var(--gold-bright);
  box-shadow: 0 0 18px rgba(245, 217, 138, 0.84);
}

.victory-overlay.checkers-win {
  background: rgba(5, 10, 11, 0.58);
}

.victory-overlay.checkers-win .victory-card {
  color: #fff8e4;
  border: 1px solid rgba(245, 217, 138, 0.74);
  background:
    linear-gradient(180deg, rgba(125, 38, 50, 0.98), rgba(72, 20, 30, 0.98));
  animation: checkersVictory 4200ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.victory-overlay.checkers-win .victory-kicker {
  color: var(--gold-bright);
}

.victory-overlay.checkers-win .victory-title {
  color: #fff8e4;
  text-shadow: 0 2px 0 rgba(47, 9, 16, 0.72);
}

.victory-overlay.checkers-win .victory-spark {
  background: var(--checker-red);
  box-shadow:
    0 0 0 2px rgba(245, 217, 138, 0.42),
    0 0 18px rgba(100, 28, 40, 0.9);
}

@keyframes aiPulse {
  0% {
    filter: brightness(1.42);
  }
  48% {
    filter: brightness(1.18);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes victoryFade {
  0% {
    opacity: 0;
  }
  10%,
  84% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes victorySweep {
  0% {
    opacity: 0;
    transform: translateX(-14%) rotate(-4deg);
  }
  24%,
  72% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(14%) rotate(4deg);
  }
}

@keyframes chessVictory {
  0% {
    opacity: 0;
    transform: translateY(22px) scale(0.92);
  }
  18% {
    opacity: 1;
    transform: translateY(0) scale(1.04);
  }
  36%,
  78% {
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 1;
    transform: translateY(-8px) scale(1);
  }
}

@keyframes checkersVictory {
  0% {
    opacity: 0;
    transform: translateY(-18px) rotate(-2deg) scale(0.92);
  }
  18% {
    opacity: 1;
    transform: translateY(0) rotate(1deg) scale(1.05);
  }
  36%,
  78% {
    transform: translateY(0) rotate(0deg) scale(1);
  }
  100% {
    opacity: 1;
    transform: translateY(8px) rotate(0deg) scale(1);
  }
}

@keyframes sparkBurst {
  0% {
    opacity: 0;
    transform: translateY(36px) rotate(45deg) scale(0.4);
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-56px) rotate(315deg) scale(1.15);
  }
}

@media (max-width: 1180px) {
  :root {
    --sidebar-width: 420px;
    --layout-gap: 16px;
    --board-size: min(calc(100vh - 44px), calc(100vw - var(--sidebar-width) - 64px));
  }

  .page-shell {
    padding-right: 16px;
    padding-left: 16px;
  }

  .site-footer {
    margin-right: -16px;
    margin-left: -16px;
  }

  h1 {
    font-size: 2rem;
  }
}

@media (max-width: 980px) {
  :root {
    --board-size: min(820px, calc(100vw - 42px));
  }

  .app-layout {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
  }

  .top-layout,
  .control-sidebar,
  .play-column {
    display: contents;
  }

  .site-header {
    order: 1;
  }

  .board-section {
    order: 2;
  }

  .setup-panel {
    order: 3;
    width: 100%;
  }

  .status-panel {
    order: 4;
    width: 100%;
  }

  .lower-info {
    order: 5;
    grid-template-columns: 1fr;
  }

  .stats-header {
    grid-template-columns: 1fr;
  }

  .stats-latest {
    justify-self: stretch;
    max-width: none;
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  :root {
    --board-size: min(640px, calc(100vw - 28px));
  }

  .page-shell {
    padding: 12px;
  }

  .site-header {
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 10px 12px;
    padding: 10px;
  }

  .return-link {
    min-height: 36px;
  }

  .brand-mark {
    min-height: 96px;
  }

  .brand-mark img {
    width: auto;
    height: 94%;
    max-width: 96%;
  }

  h1 {
    font-size: 1.78rem;
  }

  .title-block p:last-child {
    font-size: 0.93rem;
  }

  .board-frame {
    width: 100%;
    padding: 8px;
    border-radius: 10px;
  }

  .board-frame::before {
    inset: 5px;
    border-radius: 8px;
  }

  .board-grid {
    width: 100%;
    border-radius: 5px;
  }

  .coord {
    top: 3px;
    left: 4px;
    font-size: 0.52rem;
  }

  .piece.chess {
    width: 98%;
    height: 98%;
  }

  .piece.checker {
    width: 94%;
    height: 94%;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .victory-card {
    min-width: min(360px, calc(100vw - 28px));
    padding: 20px 22px;
  }

  .victory-title {
    font-size: 1.78rem;
  }

  .rules-panel {
    padding: 16px;
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .site-footer {
    margin-right: -12px;
    margin-left: -12px;
    margin-bottom: -12px;
    padding: 16px 14px 18px;
  }
}

@media (max-width: 520px) {
  .coord {
    display: none;
  }
}

@media (max-width: 420px) {
  .mode-group {
    grid-template-columns: 1fr;
  }

  .setup-actions {
    grid-template-columns: 1fr;
  }

  .sound-toggle {
    width: 100%;
  }

  h1 {
    font-size: 1.42rem;
  }

  .site-header {
    grid-template-columns: 70px minmax(0, 1fr);
  }

  .brand-mark {
    min-height: 86px;
  }

  .title-block p:last-child,
  .return-link {
    font-size: 0.86rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }

  .square.ai-from,
  .square.ai-to {
    animation: none;
  }
}
