:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #23262b;
  --muted: #6b7078;
  --line: #c9d3e0;
  --paper: #fbfcfe;
  --x: #d23c3c;
  --o: #2f62c9;
  --accent: #2f62c9;
  --last: #ffe9a8;
  --win: #1f9d55;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 20px;
}
header h1 { margin: 0; font-size: 22px; display: flex; align-items: center; gap: 8px; }
header .logo { width: 28px; height: 28px; }
.rules { color: var(--muted); }

main {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 16px;
  padding: 0 20px 20px;
}

.panel {
  width: 280px;
  flex: none;
  background: var(--panel);
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel section { display: flex; flex-direction: column; gap: 4px; }
.panel label { font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
select, input, button {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid #d0d4da;
  border-radius: 6px;
  background: #fff;
  color: inherit;
}
.inline { display: flex; align-items: center; gap: 6px; }
.inline input { width: 100px; }

.buttons { display: flex; flex-wrap: wrap; gap: 6px; }
button { cursor: pointer; }
button:hover { background: #f1f3f6; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; }

.zoom { display: flex; align-items: center; gap: 6px; }
.zoom span { color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 600; margin-right: auto; }
.zoom button { width: 34px; padding: 4px 0; }

.status #status { font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); font-size: 12px; }

.hint-box h2 { margin: 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.hint-box ol { list-style: none; margin: 4px 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.hint-box li { padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.hint-box li:hover, .hint-box li.active { background: #eef3fc; }
.hint-box .hl-head { display: flex; align-items: baseline; gap: 6px; }
.hint-box .hl-rank { color: #1f9d55; font-weight: 700; width: 1.2em; }
.hint-box .hl-move { font-weight: 700; }
.hint-box .hl-score { margin-left: auto; font-variant-numeric: tabular-nums; }
.hint-box .hl-score.win { color: #1f9d55; font-weight: 600; }
.hint-box .hl-score.loss { color: #d23c3c; font-weight: 600; }
.hint-box .hl-pv { font-size: 11px; color: var(--muted); padding-left: 1.7em; word-break: break-word; }
.hint-forced { background: #e7f6ee; color: #146c3b; border-radius: 6px; padding: 4px 8px; font-weight: 600; font-size: 13px; }
button.on { background: #e7f6ee; border-color: #1f9d55; color: #146c3b; }
button.icon { padding: 4px 8px; line-height: 0; }
button.icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#pause .i-play, #pause.paused .i-pause { display: none; }
#pause.paused .i-play { display: inline; fill: currentColor; }
#hint { color: #8a919c; }
#hint .rays { opacity: .45; }
#hint.on { background: #fff4cc; border-color: #e0a800; color: #9a6a00; }
#hint.on .bulb { fill: #ffd43b; }
#hint.on .rays { opacity: 1; }

.ai-info h2 { margin: 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.ai-info dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 4px 0; }
.ai-info dt { color: var(--muted); }
.ai-info dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.board-wrap {
  flex: 1;
  min-width: 0;
  overflow: auto;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  position: relative;
  display: grid;
  place-items: safe center;
}
.board-grid {
  display: grid;
  grid-template-columns: auto auto;
  padding: 0 14px 14px 0;
}
.ruler-top, .ruler-left, .ruler-corner { position: sticky; background: var(--panel); z-index: 1; }
.ruler-top { top: 0; }
.ruler-left { left: 0; }
.ruler-corner { top: 0; left: 0; z-index: 2; }
.ruler-top, .ruler-left { cursor: default; }
.cursor { font-size: 13px; color: var(--muted); margin-top: 2px; }
.cursor b { color: var(--ink); font-variant-numeric: tabular-nums; }
canvas { display: block; cursor: pointer; }
canvas.busy { cursor: progress; }

.thinking::after {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  margin-left: 8px;
  border: 2px solid var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  body { height: auto; }
  main { flex-direction: column; padding: 0 12px 12px; }
  .panel { width: auto; }
  .board-wrap { height: 75vh; }
}
