:root {
  color-scheme: dark;
  --bg: #0e1014;
  --panel: #151820;
  --panel-2: #1b1f29;
  --line: #262b36;
  --text: #e6e8ec;
  --text-2: #a4aab5;
  --muted: #6f7683;
  --accent: #5b8def;
  --up: #1baf7a;
  --down: #e34948;
  --value: #c98500;
  /* categorical slots (dark steps), validated on this surface; fixed order per participant group */
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { border-color: #3a4150; }
button.active, button.toggle.on { background: #24324f; border-color: var(--accent); color: #fff; }
button.primary { background: #24324f; border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
input[type="number"] { width: 100%; }
input[type="checkbox"] { width: auto; }
textarea { width: 100%; resize: vertical; }
a { color: var(--text-2); }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.sec-h { color: var(--text-2); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin: 10px 0 6px; }

#lab { display: grid; grid-template-columns: 300px minmax(0, 1fr) 270px;
  grid-template-rows: 44px minmax(260px, 1fr) minmax(250px, 38vh) 24px;
  grid-template-areas: "top top top" "build main state" "build bottom bottom" "foot foot foot"; height: 100vh; }
.top { grid-area: top; display: flex; align-items: center; gap: 16px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-size: 15px; display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; }
.brand b { font-weight: 650; }
.ring { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--text); display: inline-block; }
.exp { color: var(--text-2); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.persp { display: flex; gap: 3px; }
.status { color: var(--muted); font: 12px var(--mono); min-width: 170px; text-align: right; }

.build { grid-area: build; overflow-y: auto; padding: 10px; border-right: 1px solid var(--line); background: var(--panel); }
.build details { border-top: 1px solid var(--line); padding: 4px 0; }
.build summary { cursor: pointer; color: var(--text-2); font-weight: 600; padding: 4px 0; }
.row { display: grid; grid-template-columns: 1fr 120px; gap: 6px; align-items: center; margin: 4px 0; color: var(--text-2); font-size: 12px; }
.row select, .row input { width: 100%; }
.col { display: flex; flex-direction: column; gap: 4px; color: var(--text-2); font-size: 12px; margin-bottom: 8px; }
.check { display: flex; gap: 6px; align-items: center; color: var(--text-2); font-size: 12px; margin: 4px 0; }
.runbar { display: flex; gap: 6px; margin: 12px 0 4px; position: sticky; bottom: 0; background: var(--panel); padding: 6px 0; }
.runbar .primary { flex: 1; }
.action-row { display: grid; grid-template-columns: 52px 1fr 72px 44px 18px; gap: 4px; margin: 4px 0; align-items: center; }
.action-row.noday { grid-template-columns: minmax(0, 1fr) 84px 48px 18px; }
.action-row select { min-width: 0; width: 100%; }
.action-row input { min-width: 0; }
.action-row button { padding: 0 4px; }
.branch { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 4px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs.small { margin-bottom: 8px; }
.nl-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 8px 0; }
.nl-table td { border-bottom: 1px solid var(--line); padding: 3px 4px; vertical-align: top; }
.warn { color: #fab219; font-size: 12px; }

.main { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chart-head { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--line); min-height: 34px; }
.legend { flex: 1; font: 12px var(--mono); color: var(--text-2); display: flex; gap: 12px; flex-wrap: wrap; }
.legend b { color: var(--text); font-weight: 500; }
.legend .up { color: var(--up); } .legend .down { color: var(--down); }
.legend .val { color: var(--value); }
.chart-tools { display: flex; gap: 6px; }
.chart-wrap { position: relative; flex: 1; min-height: 0; }
.chart { position: absolute; inset: 0; }
.busy { position: absolute; right: 70px; top: 10px; z-index: 3; color: var(--text); font-size: 12px; background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 2px 10px; }
.replay { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.replay .speeds, .replay .jumps { display: flex; gap: 3px; }
.replay button { padding: 2px 8px; }
#scrub { flex: 1; min-width: 120px; padding: 0; }
#dayLabel { min-width: 120px; color: var(--text-2); }

.state { grid-area: state; overflow-y: auto; padding: 8px 12px; border-left: 1px solid var(--line); background: var(--panel); }
.state dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; font-size: 12px; }
.state dt { color: var(--muted); }
.state dd { margin: 0; font-family: var(--mono); text-align: right; }
.state dd small { color: var(--muted); display: block; font-family: inherit; }
.trade { border-top: 1px solid var(--line); margin-top: 10px; }
.row2 { display: flex; gap: 6px; margin: 6px 0; }
.row2 input { flex: 1; }

.bottom { grid-area: bottom; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--line); background: var(--panel); }
.bottom > .tabs { padding: 6px 10px; border-bottom: 1px solid var(--line); }
.tab { flex: 1; overflow: auto; padding: 8px 12px; min-height: 0; }
.split { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 14px; min-height: 100%; }
.branch-view { min-width: 0; }
.mini-chart { height: 190px; position: relative; }
.foot { grid-area: foot; display: flex; justify-content: space-between; gap: 12px; padding: 3px 12px; color: var(--muted); font-size: 11px; border-top: 1px solid var(--line); overflow: hidden; white-space: nowrap; }

.why-controls { color: var(--text-2); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.why h3 { margin: 4px 0 8px; font-size: 14px; }
.chain { display: flex; flex-wrap: wrap; gap: 6px; align-items: stretch; margin: 6px 0 12px; }
.chain .step { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; max-width: 260px; }
.chain .step .st { display: block; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
.chain .arrow { align-self: center; color: var(--muted); }
.why-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar { display: grid; grid-template-columns: 190px 1fr 48px; gap: 8px; align-items: center; font-size: 12px; }
.bar .lbl { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { height: 10px; background: #11141a; border-radius: 3px; position: relative; }
.bar .fill { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.bar .fill.up { background: var(--up); }
.bar .fill.down { background: var(--down); }
.bar .num { font-family: var(--mono); text-align: right; color: var(--text); }
table.t { width: 100%; border-collapse: collapse; font-size: 12px; }
table.t th, table.t td { padding: 3px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t th { color: var(--muted); font-weight: 500; }
table.t td.reasons { white-space: normal; text-align: left; min-width: 160px; color: var(--text-2); }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: baseline; }
.events { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.events li { display: grid; grid-template-columns: 70px 130px 1fr; gap: 8px; padding: 3px 4px; border-bottom: 1px solid #1a1e27; cursor: pointer; }
.events li:hover { background: #171b24; }
.events .k { color: var(--text-2); font-family: var(--mono); }
.events .priv { color: var(--muted); }
.agents { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 14px; }
.agents tr.click { cursor: pointer; }
.agents tr.click:hover td { background: #171b24; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 12px; }
.card h4 { margin: 0 0 4px; font: 600 14px var(--mono); }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; }
.card dt { color: var(--muted); } .card dd { margin: 0; font-family: var(--mono); }
.debrief { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; font-size: 12.5px; }
.debrief h4 { margin: 0 0 6px; }
.debrief ul { margin: 0; padding-left: 18px; }
.nb { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; font-size: 11px; overflow: auto; max-height: 100%; margin: 0; white-space: pre-wrap; }
.err { color: #fab219; }

@media (max-width: 1100px) {
  #lab { grid-template-columns: 260px minmax(0, 1fr); grid-template-rows: 44px 60vh auto auto 24px;
    grid-template-areas: "top top" "build main" "state state" "bottom bottom" "foot foot"; height: auto; }
  .state { border-left: 0; border-top: 1px solid var(--line); }
  .bottom { min-height: 420px; }
}
@media (max-width: 720px) {
  #lab { grid-template-columns: minmax(0, 1fr); grid-template-rows: 44px auto 70vh auto auto 24px;
    grid-template-areas: "top" "build" "main" "state" "bottom" "foot"; }
  .top { overflow-x: auto; }
  .exp, .status { display: none; }
  .build { max-height: 50vh; border-right: 0; }
  .split, .why-grid, .agents, .debrief { grid-template-columns: minmax(0, 1fr); }
  .bar { grid-template-columns: 120px 1fr 44px; }
  .foot { white-space: normal; flex-direction: column; height: auto; }
}
#cfSel { width: 100%; margin-bottom: 6px; }
