:root {
  --bg: #0e1217;
  --panel: #151b23;
  --panel-2: #1b232d;
  --line: #263039;
  --text: #dfe7ef;
  --muted: #8a98a6;
  --accent: #e8a13a;
  --accent-soft: #3a2f1c;
  --blue: #4a82c4;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-columns: 320px 1fr;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ---------- sidebar ---------- */
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.brand {
  display: flex; gap: 12px; align-items: center;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 38px; height: 14px; border-radius: 8px;
  background: linear-gradient(90deg, transparent, var(--accent) 25%, var(--accent) 75%, transparent);
  flex: none;
}
.brand h1 { font-size: 15px; margin: 0; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }

#catalog { overflow-y: auto; padding: 10px; flex: 1; min-height: 0; }
.loading-list { color: var(--muted); padding: 16px; }

.group { margin-bottom: 14px; }
.group-head { padding: 8px 10px 6px; }
.group-head h2 { margin: 0; font-size: 13px; color: var(--text); }
.group-head p { margin: 3px 0 0; font-size: 11px; color: var(--muted); }

.item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; margin: 2px 0;
  border-radius: 8px; cursor: pointer;
  color: var(--text); border: 1px solid transparent;
  transition: background .12s, border-color .12s;
}
.item:hover { background: var(--panel-2); }
.item.active { background: var(--accent-soft); border-color: var(--accent); }
.item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); flex: none; }
.item.assembly .dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(232,161,58,.15); }
.item .label { flex: 1; }
.item.assembly .label { font-weight: 600; }
.item .x { font-size: 11px; color: var(--muted); }

.side-foot {
  padding: 10px 18px; font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--line);
}

/* ---------- stage ---------- */
#stage { position: relative; min-width: 0; }
#viewport { position: absolute; inset: 0; }
#viewport canvas { display: block; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 12px;
  background: linear-gradient(180deg, rgba(14,18,23,.85), transparent);
  pointer-events: none;
}
#crumb { font-size: 13px; pointer-events: none; }
#crumb b { color: var(--accent); }
.muted { color: var(--muted); }
.tools { display: flex; gap: 6px; pointer-events: auto; }
.tools button {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); cursor: pointer; font-size: 15px;
  transition: background .12s, border-color .12s, color .12s;
}
.tools button:hover { background: #222c37; }
.tools button.on { border-color: var(--accent); color: var(--accent); }

#hud {
  position: absolute; left: 16px; bottom: 16px;
  background: rgba(21,27,35,.82); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; pointer-events: none;
}
.hud-name { font-weight: 600; font-size: 13px; }
.hud-dims { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

#loader {
  position: absolute; inset: 0; display: flex; gap: 12px;
  align-items: center; justify-content: center;
  color: var(--muted); background: rgba(14,18,23,.4);
}
.spin {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: sp .8s linear infinite;
}
@keyframes sp { to { transform: rotate(360deg); } }

#err {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  background: #2a1b1b; border: 1px solid #6b3a3a; color: #f3c9c9;
  padding: 14px 18px; border-radius: 10px; max-width: 70%;
}
.hidden { display: none !important; }

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; grid-template-rows: 38vh 1fr; }
  #sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
}
