:root {
  --bg: #050b24;
  --bg2: #0a1640;
  --line: rgba(110, 170, 255, .28);
  --glow: #5ab0ff;
  --cyan: #8fd3ff;
  --text: #cfe3ff;
  --muted: #6e86b8;
  --warn: #ffb547;
  --bad: #ff5c7a;
  --ok: #5cffb0;
  --panel: rgba(12, 28, 78, .45);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 40%, var(--bg2) 0%, var(--bg) 70%);
  color: var(--text);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  overflow: hidden;
  display: flex; flex-direction: column;
}
#bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.mono { font-family: "JetBrains Mono", monospace; }
.small { font-size: 11px; }
.muted { color: var(--muted); }

.topbar {
  position: relative; z-index: 1;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  font-family: Orbitron, sans-serif; letter-spacing: .15em; font-size: 13px;
}
.brand .hex { color: var(--glow); text-shadow: 0 0 8px var(--glow); }
.brand .sub { color: var(--muted); font-size: 10px; margin-left: 10px; }
.link-status { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 8px currentColor; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }

.hud {
  position: relative; z-index: 1; flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(240px, 1fr) minmax(360px, 2fr) minmax(260px, 1fr);
  gap: 16px; padding: 16px 20px;
}
.col { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.panel {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  padding: 12px 14px; backdrop-filter: blur(4px);
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
}
.panel::before {
  content: ""; position: absolute; top: 0; left: 0; width: 40px; height: 2px;
  background: var(--glow); box-shadow: 0 0 10px var(--glow);
}
.panel.grow { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
h3 { font-family: Orbitron, sans-serif; font-size: 10px; letter-spacing: .2em; color: var(--cyan); margin-bottom: 10px; font-weight: 500; }

.meter { display: grid; grid-template-columns: 40px 1fr 48px; align-items: center; gap: 8px; font-size: 11px; margin: 6px 0; }
.meter label { color: var(--muted); }
.meter b { text-align: right; font-weight: 600; }
.bar { height: 6px; background: rgba(255,255,255,.06); position: relative; }
.bar i, .progress i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #2d6cff, var(--cyan)); box-shadow: 0 0 8px var(--glow); transition: width .8s; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin-top: 10px; font-size: 11px; }
.kv dt { color: var(--muted); } .kv dd { text-align: right; }

.list { list-style: none; font-size: 12px; overflow-y: auto; }
.list li { padding: 4px 0; border-bottom: 1px dashed rgba(110,170,255,.12); display: flex; justify-content: space-between; gap: 8px; }
.list.small li { font-size: 10.5px; color: var(--muted); }
.nodes-panel .list { max-height: 312px; }
.nodes-panel .list li { padding: 3px 0; font-size: 11.5px; }
.list li .role { font-style: normal; font-size: 9px; color: var(--muted); border: 1px solid var(--line); padding: 0 4px; margin-right: 6px; }
h3 .scope { float: right; color: var(--muted); letter-spacing: .1em; font-family: "JetBrains Mono", monospace; font-size: 9px; }
.list li .ok { color: var(--ok); } .list li .bad { color: var(--bad); }

.center { align-items: center; }
.core-wrap { position: relative; flex: 1; width: 100%; min-height: 0; }
#core { width: 100%; height: 100%; display: block; }
.state {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  font-family: Orbitron, sans-serif; letter-spacing: .4em; font-size: 12px; color: var(--cyan);
  text-shadow: 0 0 10px var(--glow);
}
.readout {
  width: min(560px, 100%); display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  border-color: rgba(143, 211, 255, .6);
}
.stat { text-align: center; }
.stat span { font-family: Orbitron, sans-serif; font-size: 26px; font-weight: 700; color: #fff; text-shadow: 0 0 12px var(--glow); }
.stat.warn span { color: var(--warn); }
.stat small { display: block; font-size: 9px; letter-spacing: .2em; color: var(--muted); }
.progress { grid-column: 1 / -1; height: 4px; background: rgba(255,255,255,.06); position: relative; margin-top: 8px; }
.readout-foot { grid-column: 1 / -1; display: flex; justify-content: space-between; color: var(--muted); }

.clock { text-align: right; }
#clock { font-family: Orbitron, sans-serif; font-size: 34px; font-weight: 700; color: #fff; text-shadow: 0 0 14px var(--glow); letter-spacing: .05em; }
.radar-wrap { display: grid; grid-template-columns: 1fr; gap: 8px; }
#radar { width: 100%; height: 150px; }
#wave { width: 100%; height: 50px; }

#transcript { overflow-y: auto; flex: 1; font-size: 12.5px; line-height: 1.5; padding-right: 4px; }
.msg { margin-bottom: 10px; }
.msg .who { font-size: 9px; letter-spacing: .2em; color: var(--muted); }
.msg.user .body { color: var(--cyan); }
.msg.bot .body { color: #fff; white-space: pre-wrap; }
.msg .tool { font-size: 10px; color: var(--warn); }
.msg.err .body { color: var(--bad); }
.msg .status { font-size: 10px; letter-spacing: .08em; color: var(--warn); animation: blink 1.4s ease-in-out infinite; }
.msg .status:empty { display: none; }
@keyframes blink { 50% { opacity: .45; } }

.command {
  position: relative; z-index: 1; display: flex; gap: 10px; align-items: center;
  padding: 12px 20px; border-top: 1px solid var(--line);
}
#form { flex: 1; }
#input {
  width: 100%; background: rgba(5, 15, 50, .7); border: 1px solid var(--line); color: var(--text);
  padding: 12px 14px; font: inherit; font-size: 14px; outline: none;
}
#input:focus { border-color: var(--glow); box-shadow: 0 0 12px rgba(90,176,255,.35); }
button { font: inherit; cursor: pointer; }
#mic {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--glow); background: rgba(45,108,255,.15);
  display: grid; place-items: center; transition: .2s;
}
#mic svg { width: 22px; fill: var(--cyan); }
#mic.live { background: var(--glow); box-shadow: 0 0 22px var(--glow); }
#mic.live svg { fill: #021; }
.toggle { font-size: 10px; letter-spacing: .15em; color: var(--muted); display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.ghost { background: none; border: 1px solid var(--line); color: var(--muted); padding: 10px 14px; font-size: 10px; letter-spacing: .2em; }
.ghost:hover { color: var(--text); border-color: var(--glow); }

dialog { margin: auto; background: var(--bg2); color: var(--text); border: 1px solid var(--glow); padding: 24px; }
dialog::backdrop { background: rgba(0,0,0,.7); }
dialog input { display: block; width: 260px; margin: 12px 0; padding: 10px; background: var(--bg); color: var(--text); border: 1px solid var(--line); font: inherit; }
dialog button { background: var(--glow); border: 0; padding: 10px 16px; color: #021; font-weight: 600; }

@media (max-width: 1000px) {
  body { overflow: auto; }
  .hud { grid-template-columns: 1fr; }
  .core-wrap { height: 360px; flex: none; }
  .left { order: 2; } .right { order: 3; }
  .panel.grow { max-height: 320px; }
  .toggle { display: none; }
}
