:root {
  color-scheme: light;
  --bg: #f6f6f4; --surface: #fcfcfb; --surface-2: #f0f0ed; --line: #e2e1dc; --line-2: #cfcec8;
  --text: #0b0b0b; --text-2: #52514e; --muted: #7a7974;
  --accent: #2a78d6; --accent-fg: #fff;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100; --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --good: #0a7d3b; --good-bg: #e5f4ea; --bad: #b42318; --bad-bg: #fdecec;
  --warn: #8a5a00; --warn-bg: #fff4dc; --info-bg: #e8f0fb;
  --code-bg: #f3f3f0; --shadow: 0 1px 2px rgba(0,0,0,.05);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2b; --line-2: #3d3d39;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --good: #5cc98a; --good-bg: #16301f; --bad: #f28b82; --bad-bg: #3a1a18;
    --warn: #e8b85a; --warn-bg: #33270f; --info-bg: #182638;
    --code-bg: #161615; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2b; --line-2: #3d3d39;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --good: #5cc98a; --good-bg: #16301f; --bad: #f28b82; --bad-bg: #3a1a18;
  --warn: #e8b85a; --warn-bg: #33270f; --info-bg: #182638;
  --code-bg: #161615; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
a { color: var(--accent); }
code, pre, textarea.code { font-family: var(--mono); font-size: 12.5px; }

header { display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header h1 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: .01em; white-space: nowrap; }
header h1 span { color: var(--muted); font-weight: 450; }
nav { display: flex; gap: 2px; height: 100%; overflow-x: auto; }
nav button { border: 0; background: none; color: var(--text-2); font: inherit; padding: 0 14px; cursor: pointer;
  border-bottom: 2px solid transparent; height: 100%; white-space: nowrap; }
nav button:hover { color: var(--text); }
nav button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
header .right { margin-left: auto; display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 12.5px; white-space: nowrap; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
section.tab { display: none; }
section.tab.on { display: block; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
@media (max-width: 960px) { .grid.two { grid-template-columns: minmax(0, 1fr); } main { padding: 16px; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 16px; min-width: 0; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin: 0 0 12px; font-weight: 600; }
.card h3 { font-size: 14px; margin: 16px 0 8px; }
.sub { color: var(--muted); font-size: 12.5px; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row + .row { margin-top: 10px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
input[type=text], input[type=number], input[type=password], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 6px; padding: 6px 8px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.code { width: 100%; background: var(--code-bg); resize: vertical; tab-size: 4; white-space: pre;
  overflow: auto; line-height: 1.5; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; padding: 6px 0; }
.checks label { display: flex; gap: 6px; align-items: center; cursor: pointer; }

button.b { font: inherit; border: 1px solid var(--line-2); background: var(--surface); color: var(--text);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
button.b:hover { background: var(--surface-2); }
button.b.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.b.primary:hover { filter: brightness(1.07); }
button.b:disabled { opacity: .5; cursor: default; }
button.b.small { padding: 2px 8px; font-size: 12.5px; }

table.t { border-collapse: collapse; width: 100%; font-size: 13px; }
table.t th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; border-bottom: 1px solid var(--line-2); padding: 6px 8px; white-space: nowrap; }
table.t td { border-bottom: 1px solid var(--line); padding: 7px 8px; vertical-align: middle; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
table.t tr.sel td { background: var(--info-bg); }
.scroll-x { overflow-x: auto; }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.done, .badge.pass { color: var(--good); background: var(--good-bg); }
.badge.failed, .badge.fail, .badge.lost { color: var(--bad); background: var(--bad-bg); }
.badge.timeout, .badge.error { color: var(--text-2); background: var(--surface-2); border: 1px dashed var(--line-2); }
.badge.running, .badge.cancelling { color: var(--accent); background: var(--info-bg); }
.badge.paused, .badge.pausing, .badge.interrupted { color: var(--text-2); background: var(--surface-2); border: 1px solid var(--line-2); }
.badge.queued, .badge.cancelled { color: var(--warn); background: var(--warn-bg); }
.badge.online, .badge.lic-ok { color: var(--good); background: var(--good-bg); }
.badge.offline, .badge.lic-bad { color: var(--bad); background: var(--bad-bg); }
.badge.lic-unknown { color: var(--text-2); background: var(--surface-2); border: 1px dashed var(--line-2); }
#runners-card { margin-bottom: 16px; }

.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

pre.out { background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px;
  margin: 0; overflow: auto; max-height: 420px; white-space: pre; }
pre.out.err { border-color: var(--bad); }
pre.out.empty { color: var(--muted); font-style: italic; }
details summary { cursor: pointer; color: var(--text-2); font-size: 13px; margin: 10px 0 6px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.tile { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface); }
.tile .k { font-size: 12px; color: var(--text-2); }
.tile .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .d { font-size: 12px; color: var(--muted); }

.msg { padding: 8px 12px; border-radius: 6px; margin: 10px 0 0; font-size: 13px; }
.msg.err { background: var(--bad-bg); color: var(--bad); }
.msg.ok { background: var(--good-bg); color: var(--good); }
.empty-state { color: var(--muted); padding: 24px; text-align: center; }

/* chart */
.chart-wrap { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis .title { fill: var(--text-2); font-size: 12px; }
.chart .label { font-size: 12px; fill: var(--text); font-weight: 600; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin: 4px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.band { height: 10px; opacity: .25; width: 14px; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 6px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 14px rgba(0,0,0,.12); min-width: 170px; display: none; z-index: 3; }
.tip .h { font-weight: 600; margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.tip .r i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* non-passing simulations */
.np-reason { font-family: ui-monospace, monospace; font-size: 12px; word-break: break-word; }
.np-knobs { font-size: 11.5px; color: var(--text-2); }
pre.np-src { max-height: 420px; overflow: auto; font-size: 12px; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }

/* genes / chromosomes */
.grp summary { cursor: pointer; padding: 6px 0; font-weight: 600; }
.grp summary .sub { font-weight: 400; margin-left: 8px; }
.grp .tools { display: inline-flex; gap: 6px; margin-left: 10px; }
table.genes td { padding: 3px 6px; vertical-align: middle; }
table.genes input[type=number], table.genes input[type=text] { width: 76px; }
table.genes tr.off td.enc input { visibility: hidden; }
table.genes tr.on td.fix input { visibility: hidden; }
table.genes td.nm { font-family: ui-monospace, monospace; font-size: 12px; white-space: nowrap; }
table.genes td.doc { color: var(--text-2); font-size: 12px; }

/* chart options: scale and series selection */
.chart-opts { gap: 8px; margin: 2px 0 6px; }
.chart-opts input[type=number] { width: 84px; }
.legend span.tog { cursor: pointer; user-select: none; }
.legend span.tog.off { opacity: .4; text-decoration: line-through; }

/* hardware switches */
.badge.test { color: var(--accent); background: var(--info-bg); font-size: 11px; padding: 0 6px; border-radius: 4px; }

/* fitness functions */
.formula { min-height: 2.6em; padding: 8px 10px; margin-top: 8px; border-radius: 8px; background: var(--surface-2); overflow-x: auto; }
.formula.err { color: var(--bad); font-size: 13px; }
.fn { border-top: 1px solid var(--line); padding: 12px 0; }
.fn:first-child { border-top: 0; }
.fn .head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.fn .head b { font-family: ui-monospace, monospace; }
.fn .head .tools { margin-left: auto; display: flex; gap: 6px; }
.fn code.expr { display: block; margin-top: 4px; font-size: 12px; color: var(--text-2); white-space: pre-wrap; word-break: break-word; }
.ins { cursor: pointer; text-decoration: underline dotted; font-family: ui-monospace, monospace; }

/* roles: controls a role cannot use are hidden (the server checks every request anyway) */
body[data-role="viewer"] .needs-user, body[data-role="viewer"] .needs-admin,
body[data-role="none"] .needs-user, body[data-role="none"] .needs-admin,
body[data-role="user"] .needs-admin { display: none !important; }
body:not([data-user]) .needs-login { display: none !important; }
body[data-user] .needs-guest { display: none !important; }

/* results page */
details.opts, details.manage { display: inline-block; }
details.opts > summary, details.manage > summary { cursor: pointer; color: var(--text-2); font-size: 13px; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 6px; list-style: none; }
details.opts[open] > summary, details.manage[open] > summary { margin-bottom: 6px; }
details.help { margin-top: 10px; } details.help > summary { cursor: pointer; color: var(--text-2); }
details.help p { margin: 6px 0; max-width: 900px; }
.headline { font-size: 17px; margin: 12px 0 6px; line-height: 1.4; }
.ov-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 8px 0; }
.ov-tiles .tile .v { font-size: 20px; }
.point-card h2 small { font-weight: 400; color: var(--text-2); text-transform: none; letter-spacing: 0; }
.cm { border-top: 1px solid var(--line); padding: 10px 0; }
.cm:first-child { border-top: 0; }
.cm .meta { font-size: 12px; color: var(--text-2); }
.cm .text { white-space: pre-wrap; margin-top: 4px; }

/* ---------------------------------------------------------------- notes */
.notes { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; }
@media (max-width: 800px) { .notes { grid-template-columns: minmax(0, 1fr); } }
.notes-main { display: grid; gap: 16px; align-content: start; min-width: 0; }
.notes-list a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--text); text-decoration: none; }
.notes-list a:hover { background: var(--surface-2); }
.notes-list a.on { background: var(--surface-2); font-weight: 600; }
.notes-list a .sub { display: block; font-size: 12px; font-weight: 400; }
.notes-bar { align-items: center; gap: 8px; flex-wrap: wrap; }
.note-name { margin-right: auto; }
.seg { display: inline-flex; }
.seg .b { border-radius: 0; margin: 0; }
.seg .b:first-child { border-radius: 6px 0 0 6px; }
.seg .b:last-child { border-radius: 0 6px 6px 0; }
.seg .b.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.note-body { display: grid; gap: 16px; margin-top: 10px; }
.note-body[data-mode="split"] { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 1000px) { .note-body[data-mode="split"] { grid-template-columns: minmax(0, 1fr); } }
.note-body[data-mode="preview"] #note-src, .note-body[data-mode="edit"] #note-view { display: none; }
#note-src { min-height: 70vh; resize: vertical; white-space: pre-wrap; }
.note-body[data-mode="split"] #note-view { max-height: 80vh; overflow: auto; }
.md { line-height: 1.55; overflow-wrap: anywhere; }
.md h1 { font-size: 22px; margin: 0 0 12px; }
.md h2 { font-size: 18px; margin: 24px 0 8px; text-transform: none; letter-spacing: 0; color: var(--text); }
.md h3 { font-size: 15px; margin: 18px 0 6px; }
.md code { background: var(--code-bg); padding: 1px 4px; border-radius: 4px; font-size: 12.5px; }
.md pre { background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md blockquote { border-left: 3px solid var(--line-2); margin: 8px 0; padding: 2px 12px; color: var(--text-2); }
.md .mermaid { display: flex; justify-content: center; margin: 12px 0; overflow-x: auto; }
.md .mermaid svg { max-width: 100%; max-height: 640px; height: auto; }
.nc-quote, .cm .quote { border-left: 3px solid var(--accent); padding: 2px 10px; margin: 6px 0; color: var(--text-2);
  white-space: pre-wrap; font-size: 13px; }

/* header with many tabs: the tabs keep their width, the server line shortens first */
nav { flex-shrink: 0; }
header .right { min-width: 0; }
#host { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@media (max-width: 1500px) { header h1 span { display: none; } }
@media (max-width: 1200px) { #host { display: none; } nav { flex-shrink: 1; } }
