:root {
  --bg: #fbfaf6;
  --paper: #ffffff;
  --ink: #1f2a24;
  --muted: #68746c;
  --line: #dfe4dc;
  --header-bg: rgba(251, 250, 246, 0.94);
  --green: #22634d;
  --green-dark: #174838;
  --gold: #c58b2b;
  --board: #ddb36d;
  --board-line: #7b5528;
  --shadow: 0 18px 42px rgba(35, 45, 39, 0.14);
}

[data-theme="dark"] {
  --bg: #111815;
  --paper: #18231e;
  --ink: #edf3ee;
  --muted: #aab8ae;
  --line: #2d3b34;
  --header-bg: rgba(17, 24, 21, 0.94);
  --green: #68b08e;
  --green-dark: #8bc5a8;
  --gold: #e0b85f;
  --board: #c89652;
  --board-line: #60421f;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #111815;
    --paper: #18231e;
    --ink: #edf3ee;
    --muted: #aab8ae;
    --line: #2d3b34;
    --header-bg: rgba(17, 24, 21, 0.94);
    --green: #68b08e;
    --green-dark: #8bc5a8;
    --gold: #e0b85f;
    --board: #c89652;
    --board-line: #60421f;
    --shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
  }
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

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

a {
  color: inherit;
}

.game-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
}

.nav {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--green);
  color: #fff;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
}

.nav-links a {
  text-decoration: none;
}

.theme-toggle {
  width: 48px;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.theme-toggle-track {
  width: 48px;
  height: 28px;
  display: block;
  position: relative;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2ed;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.theme-toggle-thumb {
  width: 22px;
  height: 22px;
  position: absolute;
  left: 3px;
  top: 2px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ffffff;
  color: #5e6870;
  box-shadow: 0 2px 6px rgba(31, 42, 36, 0.24);
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.theme-toggle-icon,
.theme-toggle-icon svg {
  width: 14px;
  height: 14px;
  display: block;
}

.theme-toggle-icon svg {
  fill: currentColor;
}

.theme-toggle[data-resolved-theme="dark"] .theme-toggle-track {
  border-color: #39463f;
  background: #202622;
}

.theme-toggle[data-resolved-theme="dark"] .theme-toggle-thumb {
  transform: translateX(20px);
  background: #2f3732;
  color: #f3f6f1;
}

.game-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 22px;
  align-items: start;
}

.game-panel,
.side-panel > div,
.actions {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.game-panel {
  padding: 20px;
}

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

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

h1 {
  margin-bottom: 6px;
  font-size: clamp(34px, 4vw, 52px);
  line-height: 1;
}

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

p,
li {
  color: var(--muted);
  line-height: 1.55;
}

.score-strip {
  min-width: 190px;
  display: grid;
  gap: 8px;
}

.score-strip span {
  display: block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.board-wrap {
  width: min(100%, 760px);
  margin: 0 auto;
}

.game-intro {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.game-intro h2 {
  margin-bottom: 8px;
}

.game-intro p {
  max-width: 780px;
  margin-bottom: 10px;
}

.board-row-layout {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
}

.board-labels {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  user-select: none;
}

.board-cols {
  position: relative;
  height: 18px;
  margin-left: 36px;
  margin-bottom: 8px;
}

.board-rows {
  position: relative;
}

.board-cols span,
.board-rows span {
  position: absolute;
  transform: translate(-50%, -50%);
}

.board-cols span {
  top: 50%;
}

.board-rows span {
  right: 0;
  transform: translateY(-50%);
}

.board {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 8px solid #9c6c32;
  border-radius: 8px;
  padding: 0;
  background:
    linear-gradient(to right, transparent calc(50% - 1px), rgba(123, 85, 40, .74) calc(50% - 1px), rgba(123, 85, 40, .74) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to bottom, transparent calc(50% - 1px), rgba(123, 85, 40, .74) calc(50% - 1px), rgba(123, 85, 40, .74) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--board);
  background-size: calc(100% / 14) calc(100% / 14);
  background-position: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
}

.cell {
  position: absolute;
  width: calc(100% / 14);
  height: calc(100% / 14);
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.cell:disabled {
  cursor: default;
}

.cell::before {
  content: "";
  position: absolute;
  width: 64%;
  height: 64%;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.72);
  transition: transform .18s ease, opacity .18s ease, box-shadow .18s ease;
}

.cell.black::before,
.cell.white::before {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.cell.black::before {
  background: radial-gradient(circle at 34% 28%, #686b64, #111 58%, #050505);
  box-shadow: 0 6px 12px rgba(0,0,0,.34);
}

.cell.white::before {
  background: radial-gradient(circle at 32% 24%, #fff, #f1eee2 56%, #c9c3af);
  box-shadow: 0 5px 12px rgba(44,35,20,.28);
}

.cell.last::after,
.cell.win::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  border: 3px solid var(--gold);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.cell.win::after {
  width: 48%;
  height: 48%;
  left: 50%;
  top: 50%;
  border-color: #d33b2f;
  box-shadow: 0 0 0 4px rgba(211,59,47,.16);
}

.side-panel {
  display: grid;
  gap: 14px;
}

.status-card,
.legend {
  padding: 18px;
}

.actions {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.actions button,
.actions a {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
}

.actions button:hover,
.actions a:hover {
  background: var(--green-dark);
}

.actions button:disabled {
  opacity: .45;
  cursor: default;
}

.legend ul {
  margin: 0;
  padding-left: 18px;
}

@media (max-width: 880px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .nav,
  .game-top,
  .side-panel {
    align-items: flex-start;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .score-strip {
    width: 100%;
  }

  .game-panel {
    padding: 14px;
  }

  .board-row-layout {
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 6px;
  }

  .board-cols {
    margin-left: 28px;
  }

  .board {
    border-width: 6px;
  }

  .cell::before {
    width: 72%;
    height: 72%;
  }
}
