/* SETTLE. Layout: title with scenario chips, the scenario note and control bar; then the instance network, the gated chamber and the demon/telemetry column; then rules and the event log. Columns stack on narrow screens. */
:root {
  color-scheme: dark;
  --bg: #0a0e17;
  --panel: #0f1522;
  --panel-2: #151d2e;
  --line: #1e2839;
  --line-2: #2b3850;
  --fg: #e3e8f2;
  --muted: #8b97ad;
  --dim: #56627a;
  --cyan: #22d3ee;
  --amber: #f59e0b;
  --crimson: #f43f5e;
  --green: #34d399;
  --violet: #a78bfa;
  --display: "Literata", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.app { display: grid; gap: 12px; padding-block: 12px 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.eyebrow { font: 500 11px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 4px 0 0; font: 600 26px/1.15 var(--mono); letter-spacing: .06em; color: var(--cyan); text-shadow: 0 0 18px rgba(34,211,238,.35); }
h1 span { display: block; margin-top: 4px; font: 400 13px/1.3 var(--sans); letter-spacing: 0; color: var(--muted); text-shadow: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12.5px var(--sans); padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; transition: border-color .15s, color .15s; }
.chip:hover { border-color: var(--cyan); }
.chip.on { border-color: var(--cyan); color: var(--cyan); background: rgba(34,211,238,.08); }
.note { margin: 0; font-size: 13.5px; color: #c4cddc; max-width: 130ch; }
.note b { color: var(--fg); }

select, .btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 5px 9px; min-height: 32px; max-width: 100%; }
.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; transition: border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--cyan); }
.btn svg { width: 14px; height: 14px; flex: none; }
.btn.primary { background: rgba(34,211,238,.12); border-color: rgba(34,211,238,.5); color: var(--cyan); }
.controlbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px; }
.fieldi { display: grid; gap: 0; min-width: 150px; }
.fieldi span { font: 500 10.5px var(--mono); color: var(--muted); letter-spacing: .04em; }
.fieldi output { color: var(--fg); }
.gate-ctl output { color: var(--amber); }
.round { font: 500 13px var(--mono); }
.round b { color: var(--cyan); }
.spacer { flex: 1; }
.badge { display: inline-flex; align-items: center; gap: 8px; font: 700 11.5px/1 var(--mono); letter-spacing: .06em; padding: 7px 11px; border-radius: 4px; border: 1px solid var(--line-2); background: var(--panel-2); }
.badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.run { color: #a5f3fc; } .badge.run i { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.badge.ok { color: #6ee7b7; border-color: rgba(52,211,153,.5); } .badge.ok i { background: var(--green); box-shadow: 0 0 8px var(--green); }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; height: 18px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--cyan); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--cyan); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--cyan); border: 2px solid var(--bg); }
.gate-ctl input::-webkit-slider-thumb { background: var(--amber); box-shadow: 0 0 0 1px var(--amber); }
.gate-ctl input::-moz-range-thumb { background: var(--amber); }

.main { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 0.9fr); gap: 12px; align-items: start; }
.card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px 12px; display: grid; gap: 8px; min-width: 0; align-content: start; position: relative; }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.sec-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sec-h em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--dim); }
canvas { display: block; width: 100%; }
#cvGraph { height: 540px; border-radius: 6px; background: radial-gradient(120% 90% at 50% 30%, #0f1828 0%, #070a12 75%); border: 1px solid var(--line); cursor: pointer; }
#cvGate { height: 150px; border-radius: 6px; background: #070a12; border: 1px solid var(--line); }
#cvTele { height: 90px; border-radius: 6px; background: #070a12; border: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font: 11px var(--mono); color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.ln { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.ln.on { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.ln.mid { background: rgba(34,211,238,.4); }
.ln.off { background: repeating-linear-gradient(90deg, #56627a 0 3px, transparent 3px 6px); }
.ln.bad { background: var(--crimson); box-shadow: 0 0 6px var(--crimson); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.claim { background: #fde68a; }

.popover { position: absolute; z-index: 5; width: 260px; background: #111a2b; border: 1px solid var(--cyan); border-radius: 8px; padding: 10px; display: grid; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.pop-h { display: flex; justify-content: space-between; align-items: center; font: 600 13px var(--mono); }
.pop-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.x { background: none; border: 0; padding: 2px; cursor: pointer; color: var(--muted); }
.x svg { width: 15px; height: 15px; }
.inspector { border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; background: var(--panel-2); display: grid; gap: 7px; font-size: 12.5px; }
.inspector .ih { display: flex; justify-content: space-between; align-items: center; gap: 8px; font: 600 13px var(--mono); }
.inspector ul { margin: 0; padding-left: 16px; color: #c4cddc; font: 11.5px/1.5 var(--mono); }
.inspector .k { color: var(--muted); }

.lanes { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.lane .small { font-size: 12px; color: var(--dim); }
.lane h4 { margin: 0 0 6px; display: flex; align-items: center; gap: 6px; font: 600 11.5px var(--mono); letter-spacing: .04em; text-transform: uppercase; }
.lane h4 b { margin-left: auto; font-weight: 600; }
.lane h4 i { width: 8px; height: 8px; border-radius: 50%; }
.lane.pass h4 { color: #6ee7b7; } .lane.pass h4 i { background: var(--green); box-shadow: 0 0 6px var(--green); }
.lane.hang h4 { color: #fcd34d; } .lane.hang h4 i { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.lane.supp h4 { color: #fda4af; } .lane.supp h4 i { background: var(--crimson); box-shadow: 0 0 6px var(--crimson); }
.lane ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; max-height: 250px; overflow-y: auto; align-content: start; }
.job { border: 1px solid var(--line-2); border-left-width: 3px; border-radius: 5px; padding: 5px 7px; background: var(--panel-2); font: 11px/1.4 var(--mono); display: grid; gap: 3px; }
.lane.pass .job { border-left-color: var(--green); }
.lane.hang .job { border-left-color: var(--amber); }
.lane.supp .job { border-left-color: var(--crimson); opacity: .8; }
.job .jh { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); }
.job .jh b { color: var(--fg); font-weight: 600; }
.job .prem { display: flex; flex-wrap: wrap; gap: 3px; }
.pc { padding: 1px 4px; border-radius: 3px; border: 1px solid; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.pc.hi { color: #a5f3fc; border-color: rgba(34,211,238,.45); }
.pc.lo { color: #fcd34d; border-color: rgba(245,158,11,.55); background: rgba(245,158,11,.08); }
.pc.dead { color: #fda4af; border-color: rgba(244,63,94,.55); }
.job .tg { color: #e2e8f0; }
.job .why { color: #fcd34d; }
.lane.supp .job .why { color: #fda4af; }

.side { display: grid; gap: 12px; min-width: 0; }
.demons { display: grid; gap: 5px; max-height: 300px; overflow-y: auto; }
.drow { display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 8px; align-items: start; font: 11.5px var(--mono); padding: 4px 6px; border-radius: 5px; border: 1px solid transparent; transition: background .3s, border-color .3s; }
.drow .sl { color: var(--fg); }
.drow .ds { display: flex; flex-wrap: wrap; gap: 3px; }
.drow .d { padding: 1px 5px; border-radius: 3px; border: 1px solid var(--line-2); color: var(--muted); }
.drow .d.wait { border-color: rgba(167,139,250,.6); color: #c4b5fd; background: rgba(167,139,250,.08); }
.drow .d.sf { border-style: dashed; }
.drow.woke { background: rgba(34,211,238,.1); border-color: rgba(34,211,238,.5); }
.table-wrap { overflow-x: auto; }
table.stats { width: 100%; border-collapse: collapse; font: 11.5px var(--mono); font-variant-numeric: tabular-nums; }
.stats th, .stats td { padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.stats th { color: var(--muted); font-weight: 500; font-size: 10.5px; }
.stats td:first-child, .stats th:first-child { text-align: left; color: var(--muted); }
.stats .nz { color: var(--fg); font-weight: 600; }
.cons summary { list-style: none; display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.cons summary::-webkit-details-marker { display: none; }
.cons summary svg { width: 15px; height: 15px; color: var(--muted); transition: transform .2s; }
.cons[open] summary svg { transform: rotate(180deg); }
.conlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; max-height: 360px; overflow-y: auto; }
.conlist li { font: 11px/1.45 var(--mono); padding: 5px 7px; border-radius: 5px; background: var(--panel-2); border-left: 3px solid var(--line-2); }
.conlist li.slot { border-left-color: var(--violet); }
.conlist li.infer { border-left-color: var(--cyan); }
.conlist li.soft { border-left-color: var(--amber); }
.conlist li .ex { color: #e2e8f0; }
.conlist li .lb { color: var(--muted); }
.conlist li .v { color: var(--crimson); }

.lower { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rules li { font: 11.5px/1.5 var(--mono); padding: 6px 8px; border-radius: 5px; background: var(--panel-2); }
.rules li b { color: var(--cyan); font-weight: 600; }
.rules li .t { color: var(--muted); font-family: var(--sans); font-size: 12px; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; max-height: 300px; overflow-y: auto; font: 11.5px/1.45 var(--mono); }
.log li { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 8px; color: #c4cddc; }
.log li .r { color: var(--dim); }
.log li.run { color: #a7f3d0; } .log li.rouse { color: #fcd34d; } .log li.wake { color: #c4b5fd; } .log li.claim { color: #fde68a; }

@media (max-width: 1280px) {
  .main { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .side { grid-column: 1 / -1; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
}
@media (max-width: 860px) {
  .main, .lower { grid-template-columns: minmax(0, 1fr); }
  .lanes { grid-template-columns: minmax(0, 1fr); }
  #cvGraph { height: 540px; }
}
.pg-embedded .top > div:first-child { display: none; }
@media (prefers-reduced-motion: reduce) { .btn, .chip, .drow, .cons summary svg { transition: none; } }
