:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8a91a2;
  --accent: #8b5cf6;
  --accent2: #a78bfa;
  --ok: #22c55e;
  --null: #3b82f6;
  --warn: #f59e0b;
  --err: #ef4444;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 10px; cursor: pointer;
}
button:hover { border-color: var(--accent2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
button.small { padding: 0 7px; font-size: 12px; }
select, input[type=text], input[type=search], input[type=number] {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px;
}
input[type=number] { width: 64px; }
kbd {
  font-family: ui-monospace, monospace; font-size: 10px; padding: 0 4px;
  border: 1px solid var(--line); border-radius: 3px; color: var(--muted); background: var(--bg);
}
button.active kbd { color: #e9e2ff; border-color: #c4b5fd; background: transparent; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, monospace; font-size: 12px; white-space: pre; }
.hidden { display: none !important; }
.small-text { font-size: 11px; margin-top: 6px; line-height: 1.4; }

header {
  height: 46px; display: flex; align-items: center; gap: 16px; padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; font-size: 15px; white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 6px; }
.stats { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--muted); }
.progress { flex: 1; max-width: 320px; height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--ok); transition: width .3s; }
.actions { display: flex; gap: 6px; align-items: center; }
.save-state { color: var(--muted); min-width: 70px; text-align: right; }
.save-state.err { color: var(--err); }

#layout { display: flex; height: calc(100% - 46px); }
#left, #right { background: var(--panel); overflow: auto; }
#left { width: 270px; border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 8px; gap: 6px; }
#right { width: 330px; border-left: 1px solid var(--line); padding: 4px 10px; }
#search { width: 100%; }
.filters { display: flex; gap: 6px; }
.filters select { flex: 1; }
#list { list-style: none; margin: 0; padding: 0; overflow-y: auto; overflow-x: hidden; flex: 1; }
#list li {
  display: flex; align-items: center; gap: 7px; padding: 4px 6px; border-radius: 5px;
  cursor: pointer; font-family: ui-monospace, monospace; font-size: 11.5px; white-space: nowrap;
}
#list li:hover { background: var(--panel2); }
#list li.cur { background: #2b2346; outline: 1px solid var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: #4b5263; }
.dot.labeled { background: var(--ok); }
.dot.null { background: var(--null); }
.badge { margin-left: auto; font-size: 10px; color: var(--muted); flex: none; }

#center { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 6px 8px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.group { display: flex; gap: 4px; align-items: center; }
.group label { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.group input[type=range] { width: 80px; }
label.check { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.frame-title { margin-left: auto; font-family: ui-monospace, monospace; color: var(--accent2); }
.hint { font-size: 11px; margin-left: auto; }
#view2d { position: relative; height: 38%; min-height: 80px; background: #08090c; }
#c2d { width: 100%; height: 100%; display: block; }
#splitter { height: 6px; cursor: row-resize; background: var(--line); }
#splitter:hover { background: var(--accent); }
#view3d { position: relative; flex: 1; min-height: 80px; background: #050608; }
#view3d canvas { display: block; }
.hud {
  position: absolute; left: 8px; bottom: 6px; pointer-events: none;
  font-family: ui-monospace, monospace; font-size: 11px; color: #cfd3dc;
  background: rgba(0,0,0,.55); padding: 2px 6px; border-radius: 4px; white-space: pre;
}
.hud:empty { display: none; }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); }

section { border-bottom: 1px solid var(--line); padding: 8px 0; }
section h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.kv { display: flex; justify-content: space-between; align-items: center; margin: 3px 0; }
#i-status { font-weight: 600; }
#inst-list { list-style: none; margin: 0; padding: 0; }
#inst-list li {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 5px; cursor: pointer;
}
#inst-list li.sel { background: #2b2346; outline: 1px solid var(--accent); }
#inst-list li .grow { flex: 1; }
#inst-list li select { padding: 1px 4px; }
#kp-table { width: 100%; border-collapse: collapse; font-size: 12px; }
#kp-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 2px; }
#kp-table td { padding: 3px 2px; border-top: 1px solid var(--line); font-family: ui-monospace, monospace; font-size: 11px; }
#kp-table tr { cursor: pointer; }
#kp-table tr.active td { background: #2b2346; }
#kp-table td.name { font-family: inherit; font-size: 12px; }
#kp-table select { padding: 0 2px; font-size: 11px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.na { color: var(--muted); }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 20px; min-width: 460px; max-width: 720px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 10px; font-size: 16px; }
dialog label { display: flex; flex-direction: column; gap: 3px; margin: 8px 0; color: var(--muted); }
dialog label.check { flex-direction: row; }
dialog label input[type=text] { color: var(--text); }
dialog .row { display: flex; gap: 10px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 14px 0 0; }
.result { background: var(--bg); border-radius: 6px; padding: 6px 8px; max-height: 200px; overflow: auto; font-size: 12px; white-space: pre-wrap; }
.result:empty { display: none; }
table.keys td { padding: 3px 10px 3px 0; }
code { font-size: 12px; color: var(--accent2); }

.who { color: var(--accent2); font-weight: 600; }
.who:empty { display: none; }
#list li .stem { overflow: hidden; text-overflow: ellipsis; }
.badge .by { color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 3px; margin-right: 4px; }
.badge .by.mine { color: var(--ok); border-color: #1f5f3a; }
.badge .lock { color: var(--warn); margin-right: 4px; }

#ctxmenu {
  position: fixed; z-index: 50; min-width: 220px; padding: 4px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
#ctxmenu .title { padding: 4px 8px 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
#ctxmenu .sep { height: 1px; background: var(--line); margin: 4px 2px; }
#ctxmenu button {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  background: none; border: 0; border-radius: 5px; padding: 5px 8px;
}
#ctxmenu button:hover:not(:disabled) { background: #2b2346; }
#ctxmenu button:disabled { color: var(--muted); cursor: default; opacity: .6; }
#ctxmenu button.danger { color: #fca5a5; }
#ctxmenu .ck { width: 12px; color: var(--accent2); }
#ctxmenu .lbl { flex: 1; }
#ctxmenu kbd:empty { display: none; }

.badge .rev { margin-right: 4px; font-weight: 700; }
.badge .rev.ok { color: var(--ok); }
.badge .rev.stale { color: var(--warn); }
