:root {
  --bg: #f4f4f1;
  --panel: rgba(255, 255, 255, 0.88);
  --line: rgba(17, 24, 39, 0.08);
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #4f6df5;
  --working: #3b82f6;
  --thinking: #8b5cf6;
  --idle: #9ca3af;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 8px 24px rgba(17, 24, 39, 0.06);
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; -webkit-text-size-adjust: 100%; }
body { position: fixed; inset: 0; touch-action: none; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; cursor: default; }
#world.hover { cursor: pointer; }

#chrome { position: absolute; inset: 0; pointer-events: none; transition: opacity 0.35s ease; }
#chrome > * { pointer-events: auto; }
body.ui-hidden #chrome { opacity: 0; }
body.ui-hidden #chrome > * { pointer-events: none; }

.hud {
  position: absolute; top: max(10px, env(safe-area-inset-top)); display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px);
}
#brandpill { left: max(12px, env(safe-area-inset-left)); padding: 8px 14px; }
#brandpill h1 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -0.01em; white-space: nowrap; }
#actions { right: max(12px, env(safe-area-inset-right)); gap: 8px; }
.count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #d1d5db; box-shadow: 0 0 0 3px rgba(209, 213, 219, 0.25); flex: none; }
.dot.live { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }
.btn, .seg button {
  min-height: 36px; min-width: 40px; padding: 0 12px; font: inherit; font-size: 13px; font-weight: 500; color: var(--text);
  background: #fff; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: rgba(17, 24, 39, 0.18); }
.btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg { display: flex; background: #fff; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 0 12px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { color: var(--text); background: #eef0f4; }

#roster {
  position: absolute; left: max(12px, env(safe-area-inset-left)); top: 64px; width: 250px; max-height: calc(100% - 280px);
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(10px); overflow: hidden;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 8px 14px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.icon { min-width: 40px; min-height: 40px; border: 0; background: transparent; font-size: 16px; color: var(--muted); cursor: pointer; border-radius: 8px; }
.icon:hover { background: #eef0f4; }
#roster.collapsed #rosterList, #roster.collapsed #rosterEmpty { display: none; }
#roster.collapsed .icon { transform: rotate(180deg); }
#rosterList { list-style: none; margin: 0; padding: 0 6px 6px; overflow: auto; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 8px; min-height: 44px; border-radius: 8px; cursor: pointer; }
.row:hover { background: rgba(17, 24, 39, 0.04); }
.row.sel { background: rgba(79, 109, 245, 0.1); }
.row.gone { opacity: 0.45; }
.sw { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.rt { min-width: 0; flex: 1; }
.nm { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nm .sub { font-weight: 400; color: var(--muted); font-size: 11px; }
.pj { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 999px; color: #fff; white-space: nowrap; max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
.pill.working { background: var(--working); }
.pill.thinking { background: var(--thinking); }
.pill.idle { background: var(--idle); }
.pill.gone { background: #d1d5db; color: #4b5563; }
.empty { padding: 8px 14px 16px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.empty code { background: #eef0f4; padding: 1px 5px; border-radius: 4px; }

#details {
  position: absolute; right: max(12px, env(safe-area-inset-right)); top: 64px; width: 320px; max-height: calc(100% - 96px);
  overflow: auto; padding: 14px 16px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(10px); font-size: 13px;
}
#details .head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
#details .head .sw { width: 16px; height: 16px; border-radius: 5px; }
#details .head h2 { font-size: 16px; margin: 0; flex: 1; }
#details .close { margin-left: auto; }
#details .title { color: var(--muted); margin: 0 0 12px; line-height: 1.4; }
#details dl { display: grid; grid-template-columns: 84px 1fr; gap: 6px 10px; margin: 0; }
#details dt { color: var(--muted); }
#details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
#details .quote { margin: 10px 0 0; padding: 8px 10px; background: #f6f7f9; border-radius: 8px; color: #374151; line-height: 1.45; font-size: 12px; }
#details .quote b { display: block; color: var(--muted); font-weight: 500; font-size: 11px; margin-bottom: 2px; }
#details .bars { margin-top: 12px; display: grid; grid-template-columns: 64px 1fr 28px; gap: 5px 8px; align-items: center; font-size: 11px; }
#details .bars .lbl { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#details .bars .bar { height: 8px; background: #e5e7eb; border-radius: 4px; overflow: hidden; }
#details .bars .bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
#details .bars .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
#details code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; background: #eef0f4; padding: 1px 5px; border-radius: 4px; }

#legend {
  position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); width: 250px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px);
  padding: 10px 12px 8px; font-size: 12px;
}
#stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.st { display: flex; flex-direction: column; line-height: 1.2; }
.st.wide { grid-column: 1 / -1; }
.st b { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.st span { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; }
.st .dim { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); font-size: 12px; }
#ticker { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; line-height: 1.45; min-height: 14px; }
#ticker:empty { display: none; }
#addr { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#addr a { color: var(--muted); text-decoration: none; }
#addr a:hover { color: var(--text); }
#addr .sep { margin: 0 6px; opacity: 0.6; }
.ev { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev .t { font-variant-numeric: tabular-nums; margin-right: 6px; opacity: 0.7; }
.bar.ctx { display: block; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar.ctx i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

@media (max-width: 820px) {
  #brandpill h1 { display: none; }
  #btnHide, #btnLabels { display: none; }
  #roster { width: 200px; }
  #legend { width: 200px; }
  #details { width: min(320px, calc(100% - 24px)); top: auto; bottom: max(12px, env(safe-area-inset-bottom)); max-height: 50%; }
}
@media (max-width: 560px) { #roster, #legend { display: none; } }
