:root {
  --bg: #05070c;
  --panel: rgba(12, 16, 24, 0.86);
  --panel-solid: #0c1018;
  --line: rgba(148, 170, 200, 0.16);
  --line-strong: rgba(148, 170, 200, 0.32);
  --text: #dfe7f2;
  --muted: #8e9bb0;
  --accent: #6cc4ff;
  --accent-2: #ffc857;
  --ok: #6fe3a1;
  --warn: #ffb454;
  --calc: #b79bff;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; overflow: hidden; }
#app { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#leaders, #labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#leaders line { stroke: rgba(180, 205, 235, 0.55); stroke-width: 1; }
#leaders circle { fill: #dfe7f2; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

/* ---------------------------------------------------------------- top bar */
#topbar { position: absolute; top: 0; left: 0; right: 0; height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: linear-gradient(180deg, rgba(5, 7, 12, 0.92), rgba(5, 7, 12, 0)); pointer-events: none; z-index: 5; }
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark { width: 30px; height: 30px; color: var(--accent); }
.brand h1 { font-size: 16px; font-weight: 650; letter-spacing: 0.01em; }
.brand p { font-size: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }
button.ghost { background: rgba(20, 26, 38, 0.8); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; }
button.ghost:hover { border-color: var(--line-strong); }

/* ------------------------------------------------------------------ tabs */
#tabs { position: absolute; top: 56px; left: 12px; width: 332px; display: flex; gap: 2px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0; padding: 4px; z-index: 4; backdrop-filter: blur(8px); }
#tabs button { flex: 1; background: transparent; border: 0; border-radius: 7px; padding: 7px 2px; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
#tabs button:hover { color: var(--text); }
#tabs button[aria-selected="true"] { background: rgba(108, 196, 255, 0.16); color: var(--accent); }

/* ---------------------------------------------------------------- panels */
.panel { position: absolute; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); overflow-y: auto; z-index: 4;
  scrollbar-width: thin; scrollbar-color: rgba(148, 170, 200, 0.3) transparent; }
#left { top: 100px; left: 12px; width: 332px; bottom: 40px; border-radius: 0 var(--radius) var(--radius) var(--radius); padding: 4px 14px 16px; }
#right { top: 56px; right: 12px; width: 348px; max-height: calc(100% - 100px); border-radius: var(--radius); padding: 12px 14px 14px; }
body.panels-hidden #left, body.panels-hidden #right, body.panels-hidden #tabs { display: none; }
.panel h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin: 16px 0 8px; font-weight: 600; }
.panel h2:first-child { margin-top: 10px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 4px 0 8px; }

/* ------------------------------------------------------------- controls */
.views { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.views button, .row button, .modal button { background: rgba(30, 38, 54, 0.9); border: 1px solid var(--line); border-radius: 8px; padding: 7px 6px; font-size: 12px; }
.views button:hover, .row button:hover, .modal button:hover { border-color: var(--line-strong); }
.views button.on, .row button.on, .toggle.on { background: rgba(108, 196, 255, 0.18); border-color: rgba(108, 196, 255, 0.55); color: var(--accent); }
.row { display: flex; gap: 6px; margin: 8px 0; }
.row button { flex: 1; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 12.5px; }
.checks label { display: flex; align-items: center; gap: 7px; padding: 3px 0; cursor: pointer; }
.checks input { accent-color: var(--accent); }
.slider { display: block; margin: 8px 0 2px; font-size: 12.5px; }
.slider > span { display: flex; justify-content: space-between; color: var(--text); }
.slider output { color: var(--accent); font-family: var(--mono); font-size: 12px; }
.slider input { width: 100%; accent-color: var(--accent); margin: 5px 0 0; }
input[type="range"]:disabled { opacity: 0.4; }

/* ------------------------------------------------------------------ lists */
.list { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.item { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: rgba(22, 28, 40, 0.7);
  cursor: pointer; font-size: 12.5px; text-align: left; width: 100%; }
.item:hover { border-color: var(--line-strong); }
.item.on { border-color: rgba(108, 196, 255, 0.6); background: rgba(108, 196, 255, 0.12); }
.item .name { flex: 1; min-width: 0; }
.item .name b { display: block; font-weight: 600; }
.item .name small { color: var(--muted); display: block; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .state { font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 44px; text-align: right; }
.item.on .state { color: var(--accent); }
.swatch-dot { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(255, 255, 255, 0.25); flex: none; }

/* -------------------------------------------------------------- bay map */
#bay-map { margin: 4px 0 2px; }
#bay-map svg { width: 100%; max-width: 300px; display: block; margin: 0 auto; }
#bay-map svg path:hover, #bay-map svg rect:hover { stroke: #6cc4ff; }

/* ------------------------------------------------------------- inspector */
#inspector .eyebrow { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
#inspector h2 { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 2px 0 6px; font-weight: 650; }
#inspector .summary { font-size: 13px; line-height: 1.5; color: #c9d4e3; }
#inspector ul { margin: 6px 0; padding-left: 18px; font-size: 12.5px; line-height: 1.5; color: #c9d4e3; }
#inspector li { margin: 3px 0; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 12.5px; padding: 6px 0; border-top: 1px solid var(--line); }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); font-size: 12px; text-align: right; }
.dim { border-top: 1px solid var(--line); padding: 7px 0; font-size: 12.5px; }
.dim .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.dim .top b { font-weight: 600; }
.dim .top .val { font-family: var(--mono); font-size: 12px; }
.dim .note { color: var(--muted); font-size: 11.5px; line-height: 1.45; margin-top: 3px; }
.badge { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; padding: 1px 6px; border-radius: 999px; border: 1px solid currentColor; vertical-align: middle; }
.badge.documented { color: var(--ok); }
.badge.approximation { color: var(--warn); }
.badge.computed { color: var(--calc); }
a { color: var(--accent); }
.src { font-size: 12px; line-height: 1.5; padding: 6px 0; border-top: 1px solid var(--line); }
.src b { display: block; font-weight: 600; }
.src small { color: var(--muted); display: block; }
.empty { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.facts { font-size: 12px; color: var(--muted); line-height: 1.5; }
.facts b { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------- materials */
.mat { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.mat img { width: 64px; height: 64px; border-radius: 8px; border: 1px solid var(--line); background: #000; }
.mat .name { font-weight: 600; font-size: 12.5px; }
.mat .where { color: var(--muted); font-size: 11.5px; }
.mat .params { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 3px; }
.mat .cmp { display: flex; gap: 8px; align-items: center; margin-top: 5px; font-size: 11px; color: var(--muted); }
.mat .cmp i { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(255, 255, 255, 0.25); vertical-align: middle; margin-right: 4px; }
.mat .cmp img { width: 96px; height: 64px; border-radius: 6px; object-fit: cover; }
.mat .note { font-size: 11.5px; color: var(--muted); margin-top: 4px; line-height: 1.45; }

/* -------------------------------------------------------------- labels */
.lbl { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer; font-size: 11.5px; line-height: 1.2; color: #eaf1fb;
  background: rgba(8, 12, 20, 0.78); border: 1px solid rgba(160, 190, 230, 0.35); border-radius: 6px; padding: 3px 7px; white-space: nowrap; user-select: none;
  transition: opacity 0.15s, border-color 0.15s; }
.lbl:hover, .lbl.on { border-color: var(--accent); color: var(--accent); }
.lbl.station { font-family: var(--mono); font-size: 10.5px; color: var(--accent-2); border-color: rgba(255, 200, 87, 0.4); }
.lbl.dim { font-family: var(--mono); font-size: 11px; color: var(--ok); border-color: rgba(111, 227, 161, 0.45); }
#tooltip { position: absolute; z-index: 9; pointer-events: none; background: rgba(8, 12, 20, 0.92); border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 4px 8px; font-size: 12px; white-space: nowrap; }

/* ------------------------------------------------------------ status bar */
#statusbar { position: absolute; left: 0; right: 0; bottom: 0; height: 30px; display: flex; align-items: center; gap: 14px; padding: 0 14px; font-size: 11.5px;
  color: var(--muted); background: rgba(5, 7, 12, 0.82); border-top: 1px solid var(--line); z-index: 5; }
#statusbar .grow { flex: 1; }
#statusbar .sep { width: 1px; height: 14px; background: var(--line); }
.legend { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.documented { background: var(--ok); }
.dot.approximation { background: var(--warn); }
.dot.computed { background: var(--calc); }
#perf { font-family: var(--mono); }

/* ----------------------------------------------------------------- modal */
.modal { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal[hidden] { display: none; }
.modal-card { width: min(560px, 92vw); background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 12px; padding: 20px 22px; }
.modal-card h2 { font-size: 16px; margin-bottom: 10px; }
.modal-card ul { margin: 0 0 14px; padding-left: 18px; line-height: 1.6; font-size: 13px; color: #c9d4e3; }
kbd { font-family: var(--mono); font-size: 11px; background: #1a2231; border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 5px; }

/* --------------------------------------------------------------- loading */
#loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: var(--bg); z-index: 30; color: var(--muted); }
#loading[hidden] { display: none; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(108, 196, 255, 0.2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loading.error .spinner { display: none; }
#loading.error p { color: #ff8f8f; max-width: 520px; text-align: center; line-height: 1.5; }

.files { margin: 4px 0; padding-left: 18px; font-size: 12px; line-height: 1.6; color: #c9d4e3; }
code { font-family: var(--mono); font-size: 11.5px; color: var(--accent-2); }

@media (max-width: 1100px) {
  #right { width: 300px; }
  #left, #tabs { width: 300px; }
}
@media (max-width: 820px) {
  #right { display: none; }
  #left { bottom: 30px; max-height: 46vh; }
  #statusbar #hint { display: none; }
  .brand p { display: none; }
}

.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 10px; }
.gallery a { display: block; text-decoration: none; color: var(--muted); font-size: 10.5px; line-height: 1.35; }
.gallery img { width: 100%; border-radius: 6px; border: 1px solid var(--line); display: block; margin-bottom: 3px; background: #000; }
.gallery a:hover img { border-color: var(--accent); }
#bay-figure { margin: 8px 0 4px; }
#bay-figure .note, #inspector .note { color: var(--muted); font-size: 11px; line-height: 1.4; margin-top: 3px; }
