:root {
  color-scheme: light dark;
  --paper: #f5f1e8;
  --surface: #fffdf8;
  --surface-soft: #f0eadf;
  --ink: #171512;
  --muted: #756f65;
  --line: #d8d0c1;
  --green: #245f3d;
  --green-bright: #55b989;
  --south: #14110e;
  --south-bright: #4a4138;
  --south-text: #3c332d;
  --stone-rim: rgb(255 250 238 / 44%);
  --shadow: 0 18px 42px rgb(57 47 32 / 10%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #18130f;
    --surface: #211a15;
    --surface-soft: #2b231d;
    --ink: #f4ecdf;
    --muted: #b7aa99;
    --line: #463b31;
    --green: #72c18c;
    --green-bright: #9bdbad;
    --south: #070605;
    --south-bright: #38312b;
    --south-text: #e8d9c7;
    --stone-rim: rgb(255 246 232 / 58%);
    --shadow: 0 18px 42px rgb(0 0 0 / 26%);
  }
}

* {
  box-sizing: border-box;
}

html {
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 22%), transparent 28rem),
    var(--paper);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 18px;
  margin-bottom: 14px;
}

.eyebrow,
.label {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.button {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.button:hover {
  border-color: color-mix(in srgb, var(--green), var(--line) 42%);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible,
.point:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--green), transparent 65%);
  outline-offset: 3px;
}

.button.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fffdf8;
}

.button[data-ai],
.button[data-copy] {
  border-color: color-mix(in srgb, var(--green), var(--line) 46%);
  background: color-mix(in srgb, var(--green), var(--surface) 86%);
  color: var(--green);
}

.button[data-undo],
.button[data-reset] {
  min-height: 38px;
  padding-inline: 14px;
  color: var(--muted);
}

.button.secondary:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.55;
}

.table {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 22px;
  align-items: start;
}

.board-zone,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface), transparent 4%);
  box-shadow: var(--shadow);
}

.board-zone {
  padding: clamp(14px, 3vw, 24px);
}

.turnline {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  margin-bottom: 14px;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 750;
}

.board {
  --inset: 10%;
  position: relative;
  width: min(100%, 650px);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 1px solid color-mix(in srgb, var(--line), var(--ink) 7%);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, rgb(36 95 61 / 7%), transparent 38%),
    var(--surface-soft);
  overflow: hidden;
}

.line {
  position: absolute;
  z-index: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted), transparent 22%);
}

.line.horizontal {
  left: var(--inset);
  right: var(--inset);
  top: var(--position);
  height: 2px;
  transform: translateY(-50%);
}

.line.vertical {
  top: var(--inset);
  bottom: var(--inset);
  left: var(--position);
  width: 2px;
  transform: translateX(-50%);
}

.point {
  position: absolute;
  z-index: 1;
  left: var(--x);
  top: var(--y);
  width: clamp(44px, 8.7vw, 74px);
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.point::before {
  content: "";
  position: absolute;
  inset: 43%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--muted), transparent 35%);
  transition: inset 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.point.legal::before {
  inset: 31%;
  background: color-mix(in srgb, var(--green), transparent 36%);
  box-shadow: 0 0 0 9px color-mix(in srgb, var(--green), transparent 86%);
}

.stone {
  position: absolute;
  inset: 8%;
  border: 1px solid var(--stone-rim);
  border-radius: 50%;
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 28%),
    inset 0 -9px 18px rgb(0 0 0 / 20%),
    0 9px 18px rgb(30 22 12 / 22%);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.point[data-player="north"] .stone {
  background:
    radial-gradient(circle at 35% 28%, rgb(255 255 255 / 52%), transparent 0 25%, transparent 42%),
    linear-gradient(145deg, var(--green-bright), var(--green));
}

.point[data-player="south"] .stone {
  background:
    radial-gradient(circle at 35% 28%, rgb(255 255 255 / 22%), transparent 0 20%, transparent 42%),
    linear-gradient(145deg, var(--south-bright), var(--south));
}

.point.selected .stone {
  transform: scale(1.08);
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 34%),
    inset 0 -9px 18px rgb(0 0 0 / 20%),
    0 0 0 5px color-mix(in srgb, var(--green), transparent 55%),
    0 13px 24px rgb(30 22 12 / 26%);
}

.point:disabled {
  cursor: default;
}

.point.moving .stone {
  opacity: 0;
}

.motion-stone {
  position: absolute;
  z-index: 4;
  border: 1px solid var(--stone-rim);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: left 180ms cubic-bezier(0.2, 0.8, 0.2, 1), top 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 28%),
    inset 0 -9px 18px rgb(0 0 0 / 20%),
    0 12px 22px rgb(30 22 12 / 28%);
}

.motion-stone.north {
  background:
    radial-gradient(circle at 35% 28%, rgb(255 255 255 / 52%), transparent 0 25%, transparent 42%),
    linear-gradient(145deg, var(--green-bright), var(--green));
}

.motion-stone.south {
  background:
    radial-gradient(circle at 35% 28%, rgb(255 255 255 / 22%), transparent 0 20%, transparent 42%),
    linear-gradient(145deg, var(--south-bright), var(--south));
}

.panel {
  padding: 14px;
  background: color-mix(in srgb, var(--surface), transparent 12%);
  box-shadow: 0 10px 28px rgb(57 47 32 / 7%);
}

.score {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.metric {
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  font-size: 1.55rem;
  line-height: 1;
}

.metric.north strong {
  color: var(--green);
}

.metric.south strong {
  color: var(--south-text);
}

.section {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.section + .section {
  margin-top: 12px;
}

.state {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.42;
}

.rules {
  display: grid;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.rules dt {
  color: var(--muted);
}

.rules dd {
  margin: 0;
}

.history {
  display: grid;
  gap: 6px;
  max-height: 150px;
  margin: 0;
  padding-left: 1.25rem;
  overflow: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.history li::marker {
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 860px) {
  .shell {
    width: min(100% - 22px, 620px);
    padding-top: 18px;
  }

  .masthead,
  .table {
    display: grid;
    grid-template-columns: 1fr;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    gap: 8px;
  }

  .button[data-room] {
    grid-column: 1 / -1;
  }

  .button {
    width: 100%;
    padding-inline: 12px;
  }

  .panel {
    order: 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
