:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eceee9;
  --line: #d9dcd4;
  --text: #15181a;
  --muted: #5f6763;
  --accent: #0f9b6c;
  --accent-ink: #ffffff;
  --warn: #b7791f;
  --bad: #c2410c;
  --k1: #2563eb;
  --k2: #0f9b6c;
  --k3: #c2410c;
  --grid: rgba(0, 0, 0, 0.07);
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0f0e; --surface: #141917; --surface-2: #1b2220; --line: #27302d;
    --text: #e6ebe8; --muted: #8b9792; --accent: #34d399; --accent-ink: #052016;
    --warn: #f6c35b; --bad: #fb8a5c; --k1: #7aa7ff; --k2: #34d399; --k3: #fb8a5c;
    --grid: rgba(255, 255, 255, 0.06); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0f0e; --surface: #141917; --surface-2: #1b2220; --line: #27302d;
  --text: #e6ebe8; --muted: #8b9792; --accent: #34d399; --accent-ink: #052016;
  --warn: #f6c35b; --bad: #fb8a5c; --k1: #7aa7ff; --k2: #34d399; --k3: #fb8a5c;
  --grid: rgba(255, 255, 255, 0.06); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--sans);
  max-width: 1240px; margin: 0 auto; padding: 0 16px;
  overflow-x: hidden;
}
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 22px 0 14px; flex-wrap: wrap; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand svg { width: 36px; height: 36px; color: var(--accent); flex: none; }
.brand h1 { font: 600 20px/1.1 var(--mono); margin: 0; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge { font: 600 11px/1 var(--mono); letter-spacing: 0.08em; padding: 6px 8px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.badge.live { color: var(--accent); border-color: var(--accent); }
.badge.sim { color: var(--warn); border-color: var(--warn); }
.pill { display: inline-flex; align-items: center; gap: 7px; font: 500 13px var(--mono); padding: 5px 11px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.on i { background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.pill.wait i { background: var(--warn); animation: blink 1s infinite; }
.pill.err i { background: var(--bad); }
@keyframes blink { 50% { opacity: 0.3; } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { font: 500 14px var(--sans); background: none; border: 0; color: var(--muted); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--text); border-color: var(--accent); }
.panel { display: none; padding: 18px 0 8px; }
.panel.active { display: block; }

.conn { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.grow { flex: 1 1 260px; }
.field span { font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
input, select { font: 14px var(--mono); color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { font: 600 14px var(--sans); border-radius: 6px; padding: 9px 18px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: none; }
.btn.sm { padding: 3px 10px; font-size: 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 2px 14px; min-height: 1.5em; }
.hint.err { color: var(--bad); }

.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.tile h3 { margin: 0; font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.tile .big { font: 600 clamp(20px, 2.2vw, 28px)/1.2 var(--mono); margin: 6px 0 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .big small { font-size: 12px; color: var(--muted); margin-left: 4px; font-weight: 500; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile.present { border-color: var(--accent); }
.tile.present .big { color: var(--accent); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card > header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card h2 { font: 600 13px var(--mono); margin: 0; }
.muted { color: var(--muted); font-size: 12px; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.legend i { width: 10px; height: 3px; display: inline-block; border-radius: 2px; margin-left: 6px; }
.legend .k1 { background: var(--k1); } .legend .k2 { background: var(--k2); } .legend .k3 { background: var(--k3); }
canvas { display: block; width: 100%; }
#cHistory { height: 220px; }
canvas.square { aspect-ratio: 1 / 1; max-height: 360px; border-radius: 6px; background: var(--surface-2); }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font: 13px var(--mono); }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.log { list-style: none; margin: 0; padding: 0; font: 12px/1.6 var(--mono); max-height: 220px; overflow: auto; }
.log li { border-bottom: 1px dashed var(--line); padding: 2px 0; overflow-wrap: anywhere; }
.log time { color: var(--muted); margin-right: 8px; }
.log .err { color: var(--bad); } .log .ok { color: var(--accent); }
.raw summary { cursor: pointer; font: 600 13px var(--mono); }
.raw pre { font: 12px/1.5 var(--mono); max-height: 320px; overflow: auto; margin: 10px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.prose { max-width: 820px; }
.prose h2 { font: 600 20px var(--mono); margin: 4px 0 10px; }
.prose h3 { font: 600 15px var(--mono); margin: 26px 0 6px; }
.prose p, .prose li { color: var(--text); }
.code { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.code pre { margin: 0; padding: 12px 70px 12px 14px; font: 13px/1.55 var(--mono); overflow-x: auto; }
.copy { position: absolute; top: 8px; right: 8px; font: 500 11px var(--mono); padding: 4px 8px; border-radius: 4px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer; }
.flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.flow .node { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; min-width: 130px; }
.flow .node b { font: 600 13px var(--mono); }
.flow .node span { font-size: 12px; color: var(--muted); }
.flow .node.accent { border-color: var(--accent); }
.flow .arrow { font: 11px var(--mono); color: var(--muted); }
.flow .arrow::after { content: " →"; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.box h3 { margin-top: 0; }
.foot { color: var(--muted); font-size: 12px; padding: 24px 0 32px; border-top: 1px solid var(--line); margin-top: 20px; }

/* 3D observatory */
.stage { position: relative; height: min(72vh, 760px); min-height: 420px; border-radius: 12px; overflow: hidden; background: #05060c; border: 1px solid #1b2140; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.stage canvas:active { cursor: grabbing; }
.hud { position: absolute; z-index: 2; color: #dfe6ff; font-family: var(--mono); pointer-events: none; }
.hud-tl { top: 14px; left: 16px; }
.hud-k { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: #8d97c7; }
.hud-v { font-size: 34px; font-weight: 600; color: #57ff86; line-height: 1.1; text-shadow: 0 0 14px rgba(56, 255, 106, 0.55); }
.hud-br { position: absolute; z-index: 2; right: 12px; bottom: 12px; color: #c9d2ff; border-color: #2a3366; background: rgba(8, 10, 22, 0.6); }
.vitals { position: absolute; z-index: 2; top: 14px; right: 14px; width: 240px; padding: 14px 16px 10px; border-radius: 14px;
  background: linear-gradient(160deg, rgba(34, 46, 66, 0.82), rgba(16, 22, 34, 0.86)); border: 1px solid rgba(150, 175, 220, 0.35);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); color: #e8eefc; font-family: var(--mono); backdrop-filter: blur(6px); }
.vitals h3 { margin: 0 0 10px; font: 700 12px var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: #c9d4ee; border-bottom: 1px solid rgba(150, 175, 220, 0.25); padding-bottom: 8px; }
.vrow { margin-bottom: 12px; }
.vlabel { display: flex; align-items: center; gap: 8px; font: 700 12px var(--mono); text-transform: uppercase; letter-spacing: 0.04em; }
.ic { width: 18px; height: 18px; flex: none; }
.ic.heart { color: #ff6b9a; } .ic.lung { color: #8dff6a; } .ic.conf { color: #ffc93c; }
.vnum b { font: 700 32px/1.15 var(--mono); color: #5dff8f; text-shadow: 0 0 12px rgba(56, 255, 106, 0.45); }
.vnum small { font: 700 11px var(--mono); margin-left: 6px; color: #c9d4ee; }
.vbar { height: 4px; border-radius: 3px; background: rgba(160, 180, 220, 0.25); overflow: hidden; }
.vbar i { display: block; height: 100%; width: 0; background: #5dff8f; box-shadow: 0 0 8px #38ff6a; transition: width 0.6s ease; }
.vnote { margin: 4px 0 2px; font: 11px/1.4 var(--sans); color: #aab6d6; }
.waiting { position: absolute; z-index: 2; left: 50%; bottom: 22px; transform: translateX(-50%); margin: 0; padding: 8px 14px; border-radius: 999px;
  font: 13px var(--mono); color: #c9d2ff; background: rgba(8, 10, 22, 0.7); border: 1px solid #2a3366; white-space: nowrap; }
.obs-foot { margin: 8px 2px 0; }
.conn { margin-bottom: 0; }

@media (max-width: 1000px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px) {
  .grid2, .two { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile .big { font-size: 24px; }
  .conn .btn { width: 100%; }
  .stage { height: 78vh; min-height: 480px; }
  .vitals { top: auto; bottom: 52px; right: 10px; left: 10px; width: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px 12px 6px; }
  .vitals h3, .vnote { grid-column: 1 / -1; }
  .vnum b { font-size: 22px; }
  .vlabel { font-size: 10px; gap: 4px; }
  .ic { width: 14px; height: 14px; }
  .waiting { white-space: normal; text-align: center; width: max-content; max-width: 90%; top: 50%; bottom: auto; }
}
