/* Agent Universe. The scene is always dark; panels follow the system setting (dark by default), with the
   dashboard's palette. */
:root {
  --bg: #05060b;
  --glass: rgba(22, 26, 33, 0.78);
  --surface-2: rgba(255, 255, 255, 0.06);
  --border: rgba(130, 140, 255, 0.22);
  --text: #e6e8ec;
  --muted: #8b93a1;
  --accent: #818cf8;
  --accent-soft: rgba(129, 140, 248, 0.22);
  --err: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --core: #ffd27a;
  --tool: #6bffd8;
  --llm: #c4b5fd;
  --chain: #a77bff;
  --store: #4de8ff;
  --evidence: #ffc861;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --glass: rgba(255, 255, 255, 0.9);
    --surface-2: #f1f3f6;
    --border: #e3e6eb;
    --text: #1b1f27;
    --muted: #6b7280;
    --accent: #4f46e5;
    --accent-soft: #eef0ff;
    --err: #dc2626;
    --ok: #059669;
    --warn: #b45309;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.err { color: var(--err); font-weight: 600; }
.ok { color: var(--ok); font-weight: 600; }
.warn { color: var(--warn); }

#stage, #labels { position: fixed; inset: 0; }
#stage canvas { display: block; cursor: grab; }
#stage canvas.pointing { cursor: pointer; }
#labels { pointer-events: none; }

/* labels over the scene: always light text on the dark scene */
.lbl { color: #e9ecff; text-align: center; white-space: nowrap; font-size: 12px; letter-spacing: 0.04em;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.95), 0 0 2px rgba(0, 0, 0, 0.9); }
.lbl .name { display: block; font-weight: 600; }
.lbl .sub { display: block; font-family: var(--mono); font-size: 10px; color: #a3abc4; }
.lbl.err .sub { color: #ff8b8b; }
.lbl.core .name { color: #ffe2a8; }
.lbl.store .name { color: #b5f5ff; }
.lbl.be .name { color: #bae6fd; }
.lbl.be.off .sub { color: #ff8b8b; }
.lbl.be-db .name { color: #a7f3d0; }
.lbl.be-ext .name { color: #d1d5db; }
.lbl.ghost { font-size: 10px; }
.lbl.ghost .name { color: #fca5a5; }
.lbl.ghost.untraced .name { color: #fcd34d; }
/* screen-space de-confliction (declutter() in universe.js): a crowded label drops its stats line, then moves */
.lbl.compact .sub { display: none; }
.lbl.nudge-up { margin-top: -20px; }
.lbl.nudge-down { margin-top: 20px; }

.glass { background: var(--glass); border: 1px solid var(--border); border-radius: 12px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }

select, button, .button {
  font: inherit; font-size: 12.5px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px; cursor: pointer;
}
button:hover, .button:hover { background: var(--accent-soft); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: default; }
button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
select option { color: #1b1f27; }

/* HUD */
#hud { position: fixed; top: 14px; left: 14px; z-index: 3; width: min(340px, calc(100vw - 28px)); padding: 14px 16px; }
.hud-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
#hud-collapse { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; font: inherit; font-weight: 700;
  font-size: 15px; }
#hud-collapse .arrow { width: 12px; font-size: 12px; color: var(--muted); }
#hud.collapsed { width: auto; padding: 10px 14px; }
#hud.collapsed #hud-body { display: none; }
.logo { width: 18px; height: 18px; border-radius: 5px; background: linear-gradient(135deg, #6366f1, #0ea5e9); }
.hud-row { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.hud-row label, .replay { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.hud-row select { max-width: 150px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; margin-top: 12px; }
.stat .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.stat .k, .k { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
#status { margin: 10px 0 0; min-height: 1em; }

/* control bar */
#bar { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; gap: 6px;
  width: max-content;
  align-items: center; padding: 7px; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 28px); }
#bar .sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 2px; }
#session { max-width: 220px; }
.speed { display: inline-flex; gap: 2px; }

/* the turn being animated */
#now { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 3; padding: 8px 14px;
  max-width: min(640px, calc(100vw - 740px)); min-width: 220px; text-align: center; }
#now .path { font-size: 13px; overflow-wrap: anywhere; }

/* side panel */
#panel { position: fixed; top: 14px; right: 14px; bottom: 14px; z-index: 4; width: min(380px, calc(100vw - 28px));
  overflow-y: auto; padding: 0 16px 14px; }
.panel-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 0 10px; background: var(--glass); border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.panel-head button { font-size: 18px; line-height: 1; padding: 2px 10px; }
.panel-section { padding: 10px 0; border-bottom: 1px solid var(--border); }
.panel-section:last-child { border-bottom: none; }
.panel-section h3 { font-size: 11px; font-weight: 600; margin: 0 0 6px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); }
.row { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; padding: 3px 0; }
.row > span:first-child { color: var(--muted); flex: none; }
.row > span:last-child { text-align: right; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { font-size: 12.5px; padding: 4px 0; border-bottom: 1px solid var(--surface-2); overflow-wrap: anywhere; }
.list li:last-child { border-bottom: none; }
.list li.clickable { cursor: pointer; }
.list li.clickable:hover { color: var(--accent); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
/* with the event stream open, the side panel opens to its left */
body.stream-on.stream-open #panel { right: calc(var(--stream-w) + 24px); }

/* event stream: newest at the top */
:root { --stream-w: min(340px, 34vw); }
#stream { position: fixed; top: 14px; right: 14px; bottom: 70px; z-index: 3; width: var(--stream-w); display: flex;
  flex-direction: column; padding: 0 0 6px; overflow: hidden; }
#stream.collapsed { bottom: auto; padding-bottom: 0; }
#stream.collapsed .stream-body { display: none; }
.stream-head { display: flex; align-items: center; gap: 8px; padding: 9px 10px 8px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; }
#stream.collapsed .stream-head { border-bottom: none; }
.stream-head h2 { margin: 0; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); flex: none; }
.stream-count { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.stream-head button { padding: 1px 8px; line-height: 1.3; flex: none; }
.stream-mode { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; padding: 1px 6px; border-radius: 6px;
  border: 1px solid var(--border); color: var(--muted); flex: none; }
.stream-mode.live { color: var(--ok); border-color: var(--ok); }
.stream-mode.replay { color: var(--accent); border-color: var(--accent); }
.stream-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.stream-filter { display: flex; gap: 3px; padding: 7px 10px; flex-wrap: wrap; }
.stream-filter button { font-size: 11.5px; padding: 2px 8px; }
#stream-empty { margin: 4px 12px; }
.stream-list { list-style: none; margin: 0; padding: 0 6px; overflow-y: auto; flex: 1; min-height: 0; }
.ev { display: grid; gap: 1px; padding: 5px 6px; border-bottom: 1px solid var(--surface-2); border-radius: 6px;
  font-size: 12px; cursor: pointer; }
.ev:hover, .ev:focus-visible { background: var(--accent-soft); outline: none; }
.ev-top, .ev-meta { display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; }
.ev-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 11.5px; }
.ev-dur { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.ev-meta { font-size: 10.5px; color: var(--muted); padding-left: 22px; }
.ev-meta .ok, .ev-meta .err { font-weight: 600; }
.ev-time { font-family: var(--mono); font-variant-numeric: tabular-nums; flex: none; }
.ev-agent { overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 120px; }
.ev-icon { width: 16px; height: 16px; flex: none; border-radius: 4px; display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 700; color: #05060b; background: var(--ev, var(--muted)); }
/* kinds: agent step, LLM call, tool call, handoff, http/db, proof.coverage heartbeat, other step, failure */
.k-agent { --ev: #6fb8ff; }
.k-llm { --ev: var(--llm); }
.k-tool { --ev: var(--tool); }
.k-handoff { --ev: #8f9bff; }
.k-io { --ev: #ff9d6b; }
.k-proof { --ev: var(--chain); }
.k-step { --ev: #6b7280; }
.k-fail { --ev: #ff5d73; }
.k-fail .ev-name { color: var(--err); }
.ev-tag { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.06em; padding: 0 5px; border-radius: 5px;
  border: 1px solid var(--border); flex: none; }
.proof-batched { color: var(--warn); border-color: var(--warn); }
.proof-anchored, .proof-verified { color: var(--ok); border-color: var(--ok); }
.ev-signed { color: var(--ok); border-color: transparent; padding: 0; }
.ev-replay { color: var(--accent); border-color: var(--accent); }
.ev-more { cursor: default; text-align: center; font-size: 11.5px; }
.ev-more:hover { background: none; }
.ev.fresh { animation: ev-in 1.6s ease-out; }
@keyframes ev-in {
  from { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--ev, var(--accent)); }
  to { background: transparent; box-shadow: inset 3px 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .ev.fresh { animation: none; }
}

/* legend */
#legend { position: fixed; left: 14px; bottom: 14px; z-index: 3; padding: 10px 12px; font-size: 11.5px;
  display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; align-items: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.dot-core { color: var(--core); }
.dot-agent { color: #6fb8ff; }
.dot-tool { color: var(--tool); }
.dot-llm { color: var(--llm); }
.dot-err { color: #ff5d73; }
.dot-chain { color: var(--chain); }
.dot-storage { color: var(--store); border-radius: 2px; }
/* links: a handoff is a solid arc; evidence, storage and anchoring are thin dashed lines */
#legend .dot, .swatch { justify-self: center; }
.swatch { width: 16px; height: 0; border-top: 2px solid currentColor; }
.swatch-handoff { color: #8f9bff; }
.swatch-evidence { color: var(--evidence); border-top-style: dashed; }
.swatch-anchor { color: var(--chain); border-top-style: dashed; }
.dot-svc { color: #7dd3fc; border-radius: 2px; }
.dot-db { color: #34d399; border-radius: 3px; }
.dot-ext { color: #9ca3af; transform: rotate(45deg); border-radius: 1px; }
.dot-ghost { color: #ff5d73; background: transparent; border: 1px dashed currentColor; box-shadow: none; }
.swatch-backend { color: #93c5fd; }

#tip { position: fixed; z-index: 5; pointer-events: none; padding: 7px 10px; font-size: 12px; max-width: 280px; }
#tip .name { font-weight: 600; display: block; }

/* sign-in, errors and the WebGL fallback */
.message { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 10; padding: 22px 26px;
  width: min(440px, calc(100vw - 28px)); text-align: center; }
.message h1 { margin: 0 0 8px; font-size: 18px; }
.message p { margin: 6px 0; }

@media (max-width: 900px) {
  #legend, #now { display: none !important; }
  .stat .v { font-size: 15px; }
  /* the event stream becomes a bottom drawer; the control bar sits on top of it */
  #stream { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 40vh; border-radius: 12px 12px 0 0; }
  #stream.collapsed { height: auto; bottom: 0; }
  body.stream-on #bar { bottom: 52px; }
  body.stream-on.stream-open #bar { bottom: calc(40vh + 8px); }
  body.stream-on.stream-open #panel { right: 14px; }
}
