:root {
  --bg: #f6f6f3; --surface: #ffffff; --ink: #1b1d21; --ink-soft: #4a4f57; --muted: #7a808a; --line: #e2e2dc;
  --accent: #2f5bd3; --accent-ink: #ffffff; --bad: #b3261e;
  --arena: #fbfbf9; --grid: #ecece6; --hz: #d23c35; --hz-fill: rgba(210, 60, 53, .18); --goal: #1f8a5b; --goal-fill: rgba(31, 138, 91, .18);
  --wall: #2c2f36; --trail: rgba(47, 91, 211, .55); --agent: #2f5bd3; --cell: #efefea;
  --pos-rgb: 47, 91, 211; --neg-rgb: 214, 120, 30;
  --radius: 12px; --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --surface: #191c21; --ink: #e9eaec; --ink-soft: #b9bdc4; --muted: #8a909a; --line: #2a2e35;
    --accent: #7c9cff; --accent-ink: #0d1020; --bad: #ff8a80;
    --arena: #15181c; --grid: #20242a; --hz: #ff6b62; --hz-fill: rgba(255, 107, 98, .2); --goal: #4cc38a; --goal-fill: rgba(76, 195, 138, .18);
    --wall: #d9dbe0; --trail: rgba(124, 156, 255, .6); --agent: #9db4ff; --cell: #22262c;
    --pos-rgb: 124, 156, 255; --neg-rgb: 255, 170, 90;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); letter-spacing: -.01em; }
h2 { font-size: 1rem; font-weight: 650; }
code { font: 12.5px/1.4 var(--mono); }

/* header */
header.site { max-width: 1320px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); text-decoration: none; font-weight: 650; }
.brand svg { fill: var(--accent); stroke: var(--accent); stroke-width: 1.4; }
nav.inline { display: flex; gap: 4px; margin-left: auto; }
nav.inline a, .menu-panel a { color: var(--ink-soft); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; padding: 0 12px; border-radius: 8px; }
nav.inline a:hover, .menu-panel a:hover { background: var(--surface); color: var(--ink); }
nav.inline a[aria-current], .menu-panel a[aria-current] { color: var(--ink); font-weight: 600; }
details.menu { position: relative; }
details.menu summary { list-style: none; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 10px; color: var(--ink); }
details.menu summary::-webkit-details-marker { display: none; }
details.menu summary svg { stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; fill: none; }
details.menu .close { display: none; }
details.menu[open] .open { display: none; }
details.menu[open] .close { display: block; }
.menu-panel { position: absolute; right: 0; top: 50px; width: min(16rem, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; box-shadow: 0 12px 30px rgba(0, 0, 0, .15); display: flex; flex-direction: column; }
.menu-panel a { display: flex; }
@media (max-width: 899px) { nav.inline { display: none; } }

/* layout */
main { max-width: 1320px; margin: 0 auto; padding: 0 16px 32px; }
main.prose { max-width: 760px; }
main.prose h1 { margin-top: 1.2rem; }
main.prose h2 { font-size: 1.15rem; margin-top: 1.8rem; }
main.prose p, main.prose li { color: var(--ink-soft); }
main.prose table { border-collapse: collapse; width: 100%; font-size: 14px; display: block; overflow-x: auto; }
main.prose th, main.prose td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; white-space: nowrap; }
main.prose pre { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; }
.intro { padding: 8px 0 14px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: 12px; color: var(--muted); margin: 0 0 4px; }
.lede { color: var(--ink-soft); max-width: 62ch; margin: 0; }
.grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.col-main, .col-side { display: grid; gap: 16px; min-width: 0; }
@media (max-width: 1099px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card .head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.card .head h2 { margin: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.row.tight { margin-top: 0; gap: 6px; }
.fine { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.status { margin: 10px 0 0; min-height: 1.5em; color: var(--ink-soft); }
.status.bad { color: var(--bad); }
.empty { color: var(--muted); margin: 4px 0 0; }

/* controls */
textarea { width: 100%; font: 16px/1.45 var(--font); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; resize: vertical; min-height: 64px; }
textarea:focus, select:focus, .btn:focus-visible, .chip:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn, .chip, .seg button, select { font: 500 14px/1 var(--font); min-height: 44px; border-radius: 10px; cursor: pointer; }
.btn { padding: 0 16px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); margin-left: auto; padding: 0 26px; font-weight: 650; }
.btn.icon { width: 44px; padding: 0; font-size: 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { background: transparent; color: var(--ink-soft); border: 1px dashed var(--line); padding: 0 12px; }
.chip:hover { color: var(--ink); border-color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 2px; background: var(--bg); }
.seg button { background: transparent; border: 0; color: var(--ink-soft); padding: 0 14px; min-height: 44px; border-radius: 8px; }
.seg button[aria-checked="true"], .seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.seg.small button { min-height: 44px; font-size: 13px; }
.sel { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
select { background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 0 10px; max-width: 15rem; }

/* arenas */
.arenas { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.arena { margin: 0; min-width: 0; }
.arena figcaption { font-size: 13px; font-weight: 600; margin-bottom: 6px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.arena canvas { display: block; width: 100%; aspect-ratio: 1 / 1; height: auto; border-radius: 10px; border: 1px solid var(--line); }
.tag { font-weight: 400; color: var(--muted); font-size: 12px; }
.only-narrow { display: none; }
.controls .seed { color: var(--ink-soft); font-size: 14px; min-width: 9.5em; text-align: center; }
.controls #play { margin-left: auto; min-width: 84px; }
.legend { font-size: 12px; color: var(--muted); margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.legend .k { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 4px; vertical-align: -2px; }
.legend .goal { background: var(--goal-fill); border: 1.5px solid var(--goal); }
.legend .hz { background: var(--hz-fill); border: 1.5px solid var(--hz); }
.legend .wall { background: var(--wall); border-radius: 2px; width: 4px; }
.legend .ag { background: var(--agent); }
@media (max-width: 599px) {
  .only-narrow { display: inline-flex; }
  .arenas { grid-template-columns: 1fr; }
  .arenas[data-view="orig"] .arena[data-which="edit"], .arenas[data-view="edit"] .arena[data-which="orig"] { display: none; }
  .btn.primary { width: 100%; margin-left: 0; }
  .row .seg { width: 100%; }
  .row .seg button { flex: 1; }
}

/* metrics */
.table-wrap { overflow-x: auto; }
table.metrics { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.metrics td { white-space: nowrap; }
table.metrics th, table.metrics td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
table.metrics thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.metrics tbody th { text-align: left; font-weight: 500; }
table.metrics tbody th small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }
table.metrics td.chg { color: var(--accent); font-weight: 650; }
table.metrics td.good { color: var(--goal); }
table.metrics td.worse { color: var(--bad); }
table.metrics.noft .ftcol { color: var(--muted); }
table.metrics .ftcol { border-left: 1px dashed var(--line); }

/* heatmaps */
.heatmaps { overflow-x: auto; padding-bottom: 4px; }
.hm { margin-top: 12px; min-width: max-content; }
.hm-h { margin: 0 0 4px; font-size: 13px; color: var(--ink-soft); }
.hm-h span { color: var(--muted); }
.hm-h .cnt { margin-left: 6px; }
.hm-h .cnt.on { color: var(--accent); font-weight: 600; }
.hm-row { display: flex; gap: 2px; margin-bottom: 2px; align-items: center; }
.hm-l { width: 88px; flex: none; font: 11px/1 var(--mono); color: var(--muted); }
.hm-c { width: 16px; height: 16px; border-radius: 3px; flex: none; cursor: pointer; }
.hm-c:focus { outline: 2px solid var(--ink); }
.hm-ix span:not(.hm-l) { width: 16px; flex: none; text-align: center; font: 9px/1 var(--mono); color: var(--muted); }
#hm-sum { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#hm-tip { font-family: var(--mono); font-size: 12px; min-height: 1.5em; }

/* log */
ol.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.entry { border-top: 1px solid var(--line); padding-top: 10px; }
.entry:first-child { border-top: 0; padding-top: 0; }
.e-h { margin: 0; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.e-sum { margin: 4px 0 0; color: var(--ink-soft); }
.entry details { margin-top: 6px; }
.entry summary { cursor: pointer; color: var(--accent); min-height: 32px; display: flex; align-items: center; font-size: 14px; }
ol.ops { margin: 4px 0 0; padding-left: 1.4em; display: grid; gap: 8px; font-size: 13.5px; }
ol.ops code { overflow-wrap: anywhere; }
.ba { color: var(--muted); font: 12px var(--mono); }
.why { color: var(--ink-soft); overflow-wrap: anywhere; }
ol.trace .note { color: var(--muted); font-style: italic; }

/* footer */
footer.site { max-width: 1320px; margin: 0 auto; padding: 18px 16px 28px; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line); }
footer.site p { margin: 0 0 6px; }
footer.site .links { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
footer.site a { color: var(--muted); min-height: 32px; display: inline-flex; align-items: center; }
footer.site .ver { margin-left: auto; opacity: .75; }
@media (min-width: 900px) { details.menu { display: none; } }
@media (max-width: 1099px) {
  .grid { display: flex; flex-direction: column; }
  .col-main, .col-side { display: contents; }
  .grid .card { width: 100%; }
  .o1 { order: 1; } .o2 { order: 2; } .o3 { order: 3; } .o4 { order: 4; } .o5 { order: 5; } .o6 { order: 6; }
}
.entry.na { border-left: 3px solid var(--muted); padding-left: 10px; }

/* ready-made instructions */
.preset { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.preset select { max-width: none; width: 100%; font-size: 15px; }

/* weights view */
.wv { overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 4px; }
.wv-grid { display: flex; flex-wrap: wrap; gap: 18px 24px; align-items: flex-start; }
table.wt { border-collapse: separate; border-spacing: 1px; font: 11px/1.2 var(--mono); font-variant-numeric: tabular-nums; }
table.wt caption { text-align: left; font: 600 13px/1.4 var(--font); color: var(--ink-soft); padding-bottom: 4px; white-space: nowrap; }
table.wt caption span { font-weight: 400; color: var(--muted); margin-left: 6px; }
table.wt th { font-weight: 500; color: var(--muted); padding: 2px 3px; white-space: nowrap; }
table.wt thead th { text-align: center; }
table.wt tbody th { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.wt td { text-align: right; padding: 3px 3px; min-width: 34px; border-radius: 3px; background: var(--cell); color: var(--muted); cursor: pointer; }
table.wt td.chg { color: var(--ink); font-weight: 650; }
table.wt td.hl, table.wl tr.hl th, table.wl tr.hl td { outline: 2px solid var(--ink); outline-offset: -2px; }
table.wt td:focus { outline: 2px solid var(--accent); }
table.wt tr.bias th, table.wt tr.bias td { border-top: 1px solid var(--line); }
table.wt tr.bias td { box-shadow: inset 0 1px 0 var(--line); }
table.wl { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; min-width: 100%; }
table.wl th, table.wl td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.wl th[scope=row], table.wl thead th:first-child { text-align: left; }
table.wl thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.wl .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; color: var(--ink-soft); cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.mono { font-family: var(--mono); }
.hlnote { color: var(--ink); }
.linkbtn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0 4px; min-height: 44px; text-decoration: underline; }
.btn.small { min-height: 40px; font-size: 13px; padding: 0 12px; margin-top: 6px; }
.entry.active { box-shadow: inset 3px 0 0 var(--accent); padding-left: 10px; }
#wv-cmp[hidden] { display: none; }
#wv-sum { margin: 0 0 10px; }
@media (max-width: 599px) { table.wl { font-size: 12px; } table.wl th, table.wl td { padding: 5px 4px; } table.wl code { font-size: 11px; } }
