:root {
  color-scheme: light;
  --ink: #17213a;
  --muted: #647089;
  --line: #dce2ec;
  --panel: #ffffff;
  --page: #f5f7fb;
  --blue: #2d64d8;
  --blue-soft: #e9f0ff;
  --select: #3478f6;
  --expand: #f59e0b;
  --evaluate: #8b5cf6;
  --backup: #16a36a;
  --danger: #c53d4d;
  --shadow: 0 10px 28px rgba(35, 48, 75, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  padding: 18px;
}

.has-site-nav .app-shell {
  min-height: calc(100vh - 52px);
  padding-top: 10px;
}

.has-site-nav .workspace {
  height: calc(100vh - 138px);
  min-height: 610px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  max-width: 1800px;
  margin: 0 auto 14px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 3px;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2.2vw, 2rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.12rem;
}

h3 {
  margin-bottom: 0;
  font-size: 0.98rem;
}

.phase-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.phase-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}

.legend-dot.select {
  color: var(--select);
}

.legend-dot.expand {
  color: var(--expand);
}

.legend-dot.evaluate {
  color: var(--evaluate);
}

.legend-dot.backup {
  color: var(--backup);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 330px) minmax(0, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 1800px;
  height: calc(100vh - 86px);
  min-height: 650px;
  margin: 0 auto;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.game-panel {
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
}

.panel-heading,
.search-heading,
.summary-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.turn-badge {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 800;
}

.edit-tools,
.board-actions,
.search-controls,
.view-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.edit-tools {
  margin: 15px 0 11px;
}

.tool-button,
.secondary-button,
.icon-button,
.primary-button,
.move-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #fff;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 750;
}

.tool-button.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.primary-button {
  flex: 1 1 130px;
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.move-button {
  width: 100%;
  margin-top: 8px;
  border-color: #117b52;
  background: #117b52;
  color: #fff;
}

.icon-button {
  min-width: 32px;
  padding: 6px 8px;
  font-size: 1rem;
  line-height: 1;
}

.main-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 246px;
  min-width: 246px;
  max-width: 246px;
  height: 246px;
  min-height: 246px;
  max-height: 246px;
  flex: 0 0 246px;
  margin: 0 auto;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  gap: 3px;
}

.board-cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  font-size: 3.6rem;
  font-weight: 620;
  line-height: 1;
}

.board-cell.x {
  color: #b85117;
}

.board-cell.o {
  color: #154fb3;
}

.board-cell.recommended {
  background: #dcf7e9;
  box-shadow: inset 0 0 0 4px var(--backup);
}

.board-actions {
  justify-content: center;
  margin: 10px 0 14px;
}

.field-label {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 0.8rem;
}

.status-box {
  min-height: 48px;
  margin: 11px 0;
  border-radius: 9px;
  padding: 9px 10px;
  background: #f2f5fa;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.status-box.error {
  background: #fff0f2;
  color: var(--danger);
}

.status-box.success {
  background: #eaf8f1;
  color: #11734e;
}

.search-controls {
  margin-top: auto;
}

.small-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.4;
}

.search-panel {
  display: grid;
  grid-template-rows: auto minmax(350px, 1fr) auto;
}

.search-heading {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.search-readout {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  color: var(--muted);
  font-size: 0.75rem;
}

.search-readout strong {
  max-width: 480px;
  color: var(--ink);
  font-size: 0.83rem;
  line-height: 1.25;
  text-align: right;
}

.tree-viewport {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background-color: #fbfcfe;
  background-image: radial-gradient(#dce2ec 0.8px, transparent 0.8px);
  background-size: 18px 18px;
  touch-action: none;
  user-select: none;
}

#treeSvg {
  display: block;
  width: 100%;
  height: 100%;
}

.tree-help {
  position: absolute;
  right: 10px;
  bottom: 8px;
  padding: 5px 8px;
  border: 1px solid rgba(220, 226, 236, 0.85);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted);
  font-size: 0.67rem;
  pointer-events: none;
}

.tree-edge {
  fill: none;
  stroke: #bcc6d6;
  stroke-width: 2;
}

.tree-edge.selected {
  stroke: var(--select);
  stroke-width: 4;
}

.tree-edge.rollout {
  stroke: var(--evaluate);
  stroke-width: 3;
  stroke-dasharray: 7 5;
}

.tree-node {
  cursor: pointer;
}

.node-card {
  fill: #fff;
  stroke: #aeb9ca;
  stroke-width: 2;
  rx: 8;
}

.tree-node.root .node-card {
  stroke: var(--ink);
  stroke-width: 3;
}

.tree-node.path .node-card {
  stroke: var(--select);
  stroke-width: 4;
}

.tree-node.expanded .node-card {
  stroke: var(--expand);
  stroke-width: 4;
}

.mini-grid {
  stroke: #718096;
  stroke-width: 1.4;
}

.mini-mark {
  font-size: 15px;
  font-weight: 750;
  text-anchor: middle;
  dominant-baseline: central;
}

.mini-mark.x {
  fill: #b85117;
}

.mini-mark.o {
  fill: #154fb3;
}

.mini-cell.agent-move {
  fill: #dff7ea;
}

.mini-cell.opponent-move {
  fill: #fff1dc;
}

.node-stat {
  fill: var(--ink);
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
}

.terminal-badge.win {
  fill: #d8f4e6;
}

.terminal-badge.loss {
  fill: #ffe2e6;
}

.terminal-badge.draw {
  fill: #e8ecf3;
}

.terminal-label {
  fill: var(--ink);
  font-size: 6.7px;
  font-weight: 850;
  letter-spacing: 0.03em;
  text-anchor: middle;
}

.far-zoom .mini-detail,
.far-zoom .node-stat {
  opacity: 0;
}

.far-zoom .node-card {
  fill: var(--blue-soft);
}

.root-summary {
  max-height: 190px;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding: 10px 14px 12px;
}

.summary-heading {
  margin-bottom: 7px;
}

.summary-heading > p {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.root-bars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 6px;
}

.action-bar {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
}

.action-bar.best {
  border-color: var(--backup);
  background: #f0fbf5;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 7px;
  margin-bottom: 4px;
  font-size: 0.68rem;
  font-weight: 750;
}

.bar-track {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ecf3;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.action-bar.best .bar-fill {
  background: var(--backup);
}

@media (max-width: 900px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .game-panel {
    overflow: visible;
  }

  .search-panel {
    min-height: 720px;
  }
}
