:root {
  --bg: #0e1013;
  --panel: rgba(21, 25, 32, 0.86);
  --panel-line: rgba(255, 255, 255, 0.07);
  --text: #e8e6e3;
  --text-dim: #9aa3ad;
  --accent: #d98f7f;
  --accent-2: #7fb2d9;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, "Segoe UI", Inter, Roboto, sans-serif;
  overflow: hidden;
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

#vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 42%, transparent 55%, rgba(0,0,0,0.42) 100%);
}
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px 0 20px;
  background: linear-gradient(rgba(10,12,15,0.85), rgba(10,12,15,0));
  pointer-events: none; z-index: 30;
}
#topbar .brand { display: flex; gap: 12px; align-items: center; pointer-events: auto; }
#topbar svg { color: var(--accent); flex: none; }
#topbar h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: 0.2px; }
#topbar h1 .thin { font-weight: 350; color: var(--text-dim); }
#topbar p { margin: 1px 0 0; font-size: 11.5px; color: var(--text-dim); }
#topbar p em { font-style: italic; }
#views { display: flex; gap: 2px; pointer-events: auto; }
#views button {
  background: rgba(255,255,255,0.04); border: 1px solid transparent; color: var(--text-dim);
  font: inherit; font-size: 12px; padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
#views button:hover { color: var(--text); background: rgba(255,255,255,0.08); }
#views button.active { color: #fff; background: rgba(217,143,127,0.18); border-color: rgba(217,143,127,0.35); }

/* ---------- left panel ---------- */
#panel {
  position: fixed; top: 66px; left: 14px; bottom: 14px; width: 294px;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 14px;
  padding: 12px; backdrop-filter: blur(14px); z-index: 20;
}
.modes { display: flex; gap: 3px; background: rgba(0,0,0,0.3); padding: 3px; border-radius: 9px; }
.modes button {
  flex: 1; background: transparent; border: 0; color: var(--text-dim);
  font: inherit; font-size: 12.5px; font-weight: 550; padding: 7px 0; border-radius: 7px; cursor: pointer;
}
.modes button.active { background: rgba(217,143,127,0.22); color: #fff; }
.modes button[data-mode="regions"].active { background: rgba(127,178,217,0.22); }
.modes button[data-mode="ghost"].active { background: rgba(127,201,166,0.2); }

.note { font-size: 11.5px; color: var(--text-dim); min-height: 30px; }

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.legend .chip-row { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text); }
.legend .swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .desc { grid-column: 1 / -1; color: var(--text-dim); font-size: 10.5px; margin-top: 2px; }

#search {
  background: rgba(0,0,0,0.35); border: 1px solid var(--panel-line); color: var(--text);
  font: inherit; font-size: 13px; padding: 8px 11px; border-radius: 9px; outline: none;
}
#search:focus { border-color: rgba(217,143,127,0.5); }
#search::placeholder { color: #6b7480; }

.results {
  max-height: 40%; overflow-y: auto; border: 1px solid var(--panel-line);
  border-radius: 9px; background: rgba(0,0,0,0.25);
}
.results .hit {
  display: flex; align-items: baseline; gap: 8px; padding: 6px 10px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.results .hit:hover { background: rgba(217,143,127,0.12); }
.results .hit .a { font-family: var(--mono); font-size: 11px; color: var(--accent); min-width: 52px; }
.results .hit .n { font-size: 12.5px; }
.results .hit .c { margin-left: auto; font-size: 10px; color: var(--text-dim); }

.tree { flex: 1 1 0; min-height: 130px; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.tree.small { font-size: 12px; }
.tree details { margin: 1px 0; }
.tree summary {
  cursor: pointer; padding: 5px 8px; border-radius: 7px; font-size: 12.5px; font-weight: 600;
  color: var(--text-dim); list-style: none; display: flex; align-items: center; gap: 7px;
  user-select: none;
}
.tree summary::before { content: "▸"; font-size: 10px; transition: transform 0.15s; color: #6b7480; }
.tree details[open] > summary::before { transform: rotate(90deg); }
.tree summary:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.tree .items { display: flex; flex-direction: column; padding: 1px 0 4px; }
.tree .item {
  display: flex; align-items: center; gap: 8px; padding: 3.5px 8px 3.5px 22px;
  border-radius: 6px; cursor: pointer; font-size: 12.5px; color: var(--text);
}
.tree .item:hover { background: rgba(255,255,255,0.06); }
.tree .item.selected { background: rgba(217,143,127,0.2); }
.tree .item .a { font-family: var(--mono); font-size: 10.5px; color: var(--accent); min-width: 46px; }
.tree.small .item { padding: 2.5px 8px 2.5px 22px; font-size: 12px; }
.tree .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

#fullIndex { flex: 1 1 0; min-height: 130px; display: flex; flex-direction: column; }
#fullIndex summary {
  cursor: pointer; padding: 7px 8px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  color: var(--text-dim); background: rgba(255,255,255,0.03); user-select: none;
}
#fullIndex[open] summary { color: var(--text); }
#fullIndex .count { color: #6b7480; font-weight: 400; margin-left: 4px; }
#fullIndex .tree { display: none; }
#fullIndex[open] .tree { display: block; }

/* ---------- right controls ---------- */
#controls {
  position: fixed; right: 14px; top: 66px; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 14px;
  padding: 12px; backdrop-filter: blur(14px); z-index: 20; width: 190px;
}
.ctl label { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-dim); margin-bottom: 5px; }
.ctl label .hint { text-transform: none; letter-spacing: 0; }
.ctl { position: relative; }
.seg { display: flex; gap: 2px; background: rgba(0,0,0,0.3); padding: 2px; border-radius: 7px; }
.seg button {
  flex: 1; background: transparent; border: 0; color: var(--text-dim); font: inherit; font-size: 11px;
  padding: 4px 0; border-radius: 5px; cursor: pointer;
}
.seg button.active { background: rgba(217,143,127,0.25); color: #fff; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin-top: 7px; }
.toggle {
  background: rgba(0,0,0,0.3); border: 1px solid var(--panel-line); color: var(--text-dim);
  font-size: 13px; border-radius: 7px; padding: 4px 10px; cursor: pointer;
}
.toggle.on { color: var(--accent); border-color: rgba(217,143,127,0.4); }
.hidden { display: none !important; }

/* ---------- info card ---------- */
#info {
  position: fixed; left: 322px; bottom: 16px; width: 330px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 14px;
  padding: 14px 16px; backdrop-filter: blur(14px); z-index: 25;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}
#info h2 { margin: 6px 0 2px; font-size: 16.5px; font-weight: 650; }
#infoClose {
  position: absolute; top: 9px; right: 9px; background: transparent; border: 0;
  color: var(--text-dim); font-size: 13px; cursor: pointer;
}
#infoClose:hover { color: #fff; }
.tagrow { display: flex; gap: 6px; align-items: center; }
.abbr {
  font-family: var(--mono); font-size: 12px; color: var(--accent);
  background: rgba(217,143,127,0.14); border: 1px solid rgba(217,143,127,0.3);
  padding: 2px 7px; border-radius: 6px;
}
.chip {
  font-size: 10.5px; color: var(--text-dim); background: rgba(255,255,255,0.06);
  padding: 2.5px 8px; border-radius: 6px;
}
.chip.lobe { color: #fff; }
.cat { font-size: 11.5px; color: var(--text-dim); margin-bottom: 7px; }
#info p { margin: 4px 0 8px; font-size: 12.8px; color: #cfd4da; }
.pages { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
#infoFly {
  margin-top: 10px; width: 100%; background: rgba(217,143,127,0.16);
  border: 1px solid rgba(217,143,127,0.35); color: #fff; font: inherit; font-size: 12.5px;
  padding: 7px 0; border-radius: 8px; cursor: pointer;
}
#infoFly:hover { background: rgba(217,143,127,0.28); }

/* ---------- markers & labels ---------- */
.lbl {
  pointer-events: none; white-space: nowrap; font-size: 11px; letter-spacing: 0.2px;
  color: #f2efe9; text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.6);
  padding-left: 10px; position: relative; transform: translateY(-1px);
}
.lbl::before {
  content: ""; position: absolute; left: 0; top: 50%; width: 7px; height: 7px;
  margin-top: -3.5px; border-radius: 50%; background: currentColor;
  box-shadow: 0 0 0 1.5px rgba(0,0,0,0.55);
}
.lbl.sel { font-weight: 700; font-size: 12.5px; color: #fff; }

#tooltip {
  position: fixed; z-index: 40; pointer-events: none;
  background: rgba(15,18,23,0.95); border: 1px solid var(--panel-line); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; max-width: 260px;
}
#tooltip .t { font-weight: 650; }
#tooltip .s { color: var(--text-dim); font-size: 11px; }

#hint {
  position: fixed; bottom: 14px; right: 16px; z-index: 15;
  color: #5f6873; font-size: 11px; letter-spacing: 0.4px;
}

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; flex-direction: column; gap: 18px; align-items: center; justify-content: center;
}
#loading .spin {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid rgba(217,143,127,0.2); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadMsg { color: var(--text-dim); font-size: 13px; letter-spacing: 0.3px; }

::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }
