.tree-search-demo {
  --ts-paper: #f8f8f6;
  --ts-ink: #283b40;
  --ts-muted: #596367;
  --ts-line: #c8d0d0;
  --ts-accent: #547a81;
  --ts-green: #285f50;
  --ts-amber: #795525;
  width: min(1040px, calc(100vw - 48px));
  margin: 28px 0 24px;
  margin-inline-start: calc((100% - min(1040px, 100vw - 48px)) / 2);
  color: var(--ts-ink);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-variant-numeric: tabular-nums;
  container: tree-search / inline-size;
}
.tree-search-demo *, .tree-search-demo *::before, .tree-search-demo *::after { box-sizing: border-box; }
.tree-search-demo p { margin: 0; }
.ts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
  border-top: 1px solid var(--ts-line);
  margin-bottom: 16px;
}
.ts-header strong { font-weight: 600; }
.ts-counter { color: var(--ts-muted); font-size: 12px; }
.ts-next {
  flex: none;
  width: 148px;
  height: 38px;
  border: 1px solid #9eafb2;
  border-radius: 4px;
  background: #eef2f2;
  color: #354e54;
  font: 600 13px/1 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  cursor: pointer;
}
.ts-next:hover { border-color: var(--ts-accent); background: #e5eded; }
.ts-next:focus-visible { outline: 2px solid var(--ts-accent); outline-offset: 4px; }
.ts-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 364px; gap: 24px; }
.ts-visual { min-width: 0; display: flex; flex-direction: column; height: 640px; }
.ts-tree { display: block; width: 100%; height: 580px; flex: none; }
.ts-tree-compact { display: none; }
.ts-edge { fill: none; stroke: #b6c0bf; stroke-width: 1.25; }
.ts-edge-active { stroke: var(--ts-accent); stroke-width: 2.5; }
.ts-edge-new { stroke: #6b9281; stroke-width: 2; }
.ts-edge-backup { stroke: #a08353; }
.ts-node > rect { fill: var(--ts-paper); stroke: #aebcbe; stroke-width: 1.2; }
.ts-node-opponent > rect { fill: #f7f1e7; stroke: #c5b79f; }
.ts-node-active > rect { stroke: var(--ts-accent); stroke-width: 2.5; }
.ts-node-new > rect { fill: #edf4f0; stroke: #6b9281; stroke-width: 2; }
.ts-node-unvisited > rect { stroke-dasharray: 3 3; }
.ts-node-terminal > rect { stroke-dasharray: none; }
.ts-node .ts-terminal-ring { fill: none; stroke-width: 0.8; stroke-dasharray: none; }
.ts-node text { fill: var(--ts-ink); text-anchor: middle; font-size: 13px; }
.ts-node .ts-node-name { font-family: 'Iowan Old Style', 'Charter', Georgia, serif; font-size: 20px; }
.ts-label-index { font-size: 0.72em; font-style: normal; font-weight: 400; vertical-align: baseline; baseline-shift: 0; }
.ts-node .ts-node-prior { fill: var(--ts-muted); font-size: 12px; }
.ts-node-active .ts-node-value { font-weight: 600; }
.ts-legend { display: flex; flex-wrap: wrap; align-content: start; gap: 6px 18px; height: 60px; padding: 10px 0 0 16px; color: var(--ts-muted); font-size: 12px; }
.ts-legend span { display: inline-flex; align-items: center; gap: 6px; }
.ts-legend i { display: inline-block; width: 10px; height: 10px; border: 1px solid #aebcbe; border-radius: 2px; background: var(--ts-paper); }
.ts-legend .ts-opponent-key { background: #f7f1e7; border-color: #c5b79f; }
.ts-panel {
  height: 640px;
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--ts-line);
  border-radius: 4px;
  display: grid;
  grid-template-rows: 30px 34px 1fr;
  background: #f1f4f433;
}
.ts-phases { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: start; gap: 6px; color: var(--ts-muted); font-size: 11px; }
.ts-phases span { padding-bottom: 5px; border-bottom: 2px solid transparent; }
.ts-phases [aria-current="step"] { color: var(--ts-green); border-color: #6b9281; font-weight: 600; }
.ts-panel h3 { margin: 0; color: var(--ts-ink); font: 600 20px/1.25 'Iowan Old Style', 'Charter', Georgia, serif; }
.ts-explanation { min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.ts-explanation > p { font-size: 13px; }
.ts-explanation var, .ts-notation { font-family: 'Iowan Old Style', 'Charter', Georgia, serif; }
.ts-explanation sub { line-height: 0; }
.ts-path { font: 18px/1.4 'Iowan Old Style', 'Charter', Georgia, serif; color: var(--ts-accent); }
.ts-formula { display: flex; align-items: center; justify-content: center; gap: 5px; padding: 8px 0; border-top: 1px solid #dce2df; border-bottom: 1px solid #dce2df; white-space: nowrap; font: 16px/1.4 'Iowan Old Style', 'Charter', Georgia, serif; }
.ts-fraction { display: inline-flex; flex-direction: column; align-items: center; font-size: 14px; }
.ts-fraction > span:first-child { border-bottom: 1px solid #7a8588; padding: 0 4px 2px; }
.ts-fraction > span:last-child { padding-top: 2px; }
.ts-decision-title { margin-bottom: 4px !important; color: var(--ts-muted); font-size: 12px; }
.tree-search-demo .ts-worked { margin-top: 6px; color: var(--ts-muted); font-size: 11px; line-height: 1.5; }
.ts-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
.ts-table th, .ts-table td { text-align: right; height: 27px; padding: 3px 5px; white-space: nowrap; }
.ts-table th { border-bottom: 1px solid var(--ts-line); color: var(--ts-muted); font-weight: 400; }
.ts-table th:first-child, .ts-table td:first-child { text-align: left; }
.ts-table .ts-chosen td { background: #e8efea; }
.ts-table .ts-chosen td:first-child { font-weight: 600; }
.ts-output { padding: 13px 14px; background: #edf4f0; border-left: 2px solid #9db8aa; }
.ts-output.ts-value-output { background: #f7f1e7; border-color: #c5b79f; }
.ts-output-label { color: var(--ts-muted); font-size: 11px; margin-bottom: 7px !important; }
.ts-output-value { color: var(--ts-amber); font: 21px/1.4 'Iowan Old Style', 'Charter', Georgia, serif; }
.ts-policy { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.ts-footnote { margin-top: auto !important; padding-top: 12px; border-top: 1px solid #dce2df; color: var(--ts-muted); }
.ts-result { color: var(--ts-green); }
.tree-search-demo figcaption { margin-top: 16px; padding-top: 12px; border-top: 1px solid #d4d7cf; color: #535952; font: 12px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.ts-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.tree-search-note { font-size: 0.9em; color: #535952; }
.tree-search-equation { font-size: clamp(13px, 3.5vw, 17px); }
@container tree-search (max-width: 800px) {
  .ts-header { position: sticky; top: 0; z-index: 2; background: var(--ts-paper); }
  .ts-workspace { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .ts-visual { height: auto; }
  .ts-tree { height: 580px; }
  .ts-legend { padding-left: 0; height: 44px; }
}
@container tree-search (max-width: 460px) {
  .ts-header { gap: 8px; }
  .ts-header strong { font-size: 13px; }
  .ts-counter { font-size: 11px; }
  .ts-next { width: 124px; }
  .ts-tree-wide { display: none; }
  .ts-tree-compact { display: block; height: 600px; }
  .ts-panel { padding: 16px; height: 720px; }
  .ts-legend { height: 64px; }
}
@media (max-width: 400px) {
  .tree-search-demo { width: calc(100vw - 32px); margin-inline-start: calc((100% - (100vw - 32px)) / 2); }
}
