:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #1d232b;
  --ink-2: #4a5360;
  --muted: #7a8390;
  --line: #e2ded6;
  --accent: #1d232b;
  --board: #23344d;
  --hole: #f4f2ee;
  --p1: #d9620f;
  --p2: #3f8fd2;
  --win: #f2c230;
  --bar: #5b6b80;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --surface: #1b2129;
    --ink: #e8ebef;
    --ink-2: #b4bcc7;
    --muted: #8590a0;
    --line: #2b333e;
    --accent: #e8ebef;
    --board: #2b4466;
    --hole: #12161c;
    --p1: #f07a2a;
    --p2: #5aa6e6;
    --bar: #8a9bb2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --surface: #1b2129; --ink: #e8ebef; --ink-2: #b4bcc7; --muted: #8590a0;
  --line: #2b333e; --accent: #e8ebef; --board: #2b4466; --hole: #12161c;
  --p1: #f07a2a; --p2: #5aa6e6; --bar: #8a9bb2; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 16px 24px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand .sub { color: var(--muted); font-size: 13px; margin-left: 6px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; }
.dot.p1 { background: var(--p1); }
.dot.p2 { background: var(--p2); }

.tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.tabs button {
  border: 0; background: transparent; color: var(--ink-2); padding: 7px 14px; border-radius: 8px;
  font: inherit; font-weight: 500; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

.layout {
  display: grid; grid-template-columns: 290px minmax(0, 1fr) 300px; gap: 20px;
  padding: 20px 24px; max-width: 1400px; margin: 0 auto; align-items: start;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 290px minmax(0, 1fr); }
  .analysis { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .center { order: -1; }
  .top { padding: 12px 16px; }
  .brand .sub { display: none; }
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 4px; margin: 0 0 14px; }
legend { padding: 0 6px; font-weight: 600; font-size: 14px; }
label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
label output { float: right; color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 500; }
select, input[type=range] { display: block; width: 100%; margin-top: 4px; }
select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px;
}
input[type=range] { accent-color: var(--ink); }

.buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.buttons button {
  flex: 1; font: inherit; font-weight: 500; padding: 8px 10px; white-space: nowrap; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.buttons button.primary { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.buttons button:disabled { opacity: .45; cursor: default; }

.rules { margin-top: 18px; font-size: 13px; color: var(--ink-2); }
.rules summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.rules p { margin: 8px 0; }

/* Board */
.center { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.status { font-size: 18px; font-weight: 600; min-height: 27px; text-align: center; }
.status .dot { margin-right: 6px; }
.thinking { width: min(520px, 100%); height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.thinking .bar { height: 100%; width: 0; background: var(--ink-2); }
.board-wrap { width: min(560px, 100%); }
.arrows, .board { display: grid; grid-template-columns: repeat(7, 1fr); }
.arrows { gap: 0; padding: 0 12px; height: 28px; }
.arrows span { display: flex; justify-content: center; align-items: center; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.board {
  background: var(--board); border-radius: 18px; padding: 12px; gap: 8px; position: relative;
  box-shadow: 0 10px 30px rgb(0 0 0 / .18); overflow: hidden;
}
.cell {
  aspect-ratio: 1; border-radius: 50%; background: var(--hole); position: relative;
  box-shadow: inset 0 3px 6px rgb(0 0 0 / .25);
}
.piece {
  position: absolute; inset: 0; border-radius: 50%;
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / .18), inset 0 3px 0 rgb(255 255 255 / .18);
}
.piece.p1 { background: var(--p1); }
.piece.p2 { background: var(--p2); }
.piece.drop { animation: drop var(--dur, 350ms) cubic-bezier(.45, 0, .9, .55); }
@keyframes drop { from { transform: translateY(var(--from)); } to { transform: translateY(0); } }
.cell.last .piece::after {
  content: ""; position: absolute; inset: 36%; border-radius: 50%; background: rgb(255 255 255 / .55);
}
.cell.enclosed { box-shadow: 0 0 0 4px var(--win); z-index: 1; }
.cell.enclosed .piece { animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: .45; } }

.board.clickable .cell { cursor: pointer; }
.ghost { opacity: .35; pointer-events: none; }

.legend { display: flex; gap: 20px; font-size: 14px; color: var(--ink-2); flex-wrap: wrap; justify-content: center; }

/* Analysis */
.decision { font-size: 14px; margin-bottom: 14px; min-height: 42px; }
.decision strong { color: var(--ink); }
.chart {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; align-items: end;
  height: 150px; border-bottom: 1px solid var(--line); position: relative;
}
.chart .col { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.chart .b { width: 70%; background: var(--bar); border-radius: 4px 4px 0 0; min-height: 0; transition: height .3s; }
.chart .col.best .b { background: var(--ink); }
.chart .col:hover .b { opacity: .8; }
.chart-x { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; font-size: 12px; text-align: center; font-variant-numeric: tabular-nums; margin-top: 4px; }
.chart-x .c { color: var(--muted); }
.chart-x .w { color: var(--ink-2); font-weight: 500; }
.chart-note { font-size: 12px; margin: 8px 0 18px; }
.chart-empty { grid-column: 1 / -1; align-self: center; text-align: center; font-size: 13px; }

.movelog {
  margin: 0; padding: 0; max-height: 240px; overflow: auto; font-size: 13px; list-style-position: inside;
  display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; font-variant-numeric: tabular-nums;
}
.movelog li { color: var(--ink-2); }
.movelog li .dot { width: 9px; height: 9px; margin-right: 4px; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 10; background: var(--ink); color: var(--surface);
  font-size: 12px; padding: 6px 9px; border-radius: 7px; line-height: 1.4; white-space: nowrap;
}
