:root {
  --bg: #0d1017;
  --panel: rgba(22, 26, 36, 0.86);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e7ecf5;
  --muted: #8b94a7;
  --accent: #4f8cff;
  --accent-2: #7c5cff;
  --radius: 12px;
  --toolbar-h: 56px;
  --sidebar-w: 320px;
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-rows: var(--toolbar-h) 1fr;
  grid-template-columns: 1fr var(--sidebar-w);
  grid-template-areas: "toolbar toolbar" "viewport sidebar";
  height: 100vh;
  height: 100dvh;
}

body.no-panel #app { grid-template-columns: 1fr; }
body.no-panel #sidebar { display: none; }

/* ---------- 工具栏 ---------- */
#toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 20;
}
#toolbar::-webkit-scrollbar { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding-right: 6px;
}
.logo { font-size: 24px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 14px; letter-spacing: 0.2px; }
#model-name {
  font-size: 11.5px;
  color: var(--muted);
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 14px;
  border-left: 1px solid var(--panel-border);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: rgba(255, 255, 255, 0.1); }
.btn:active { transform: translateY(1px); }
.btn .ico { font-size: 15px; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}
.btn.primary:hover { filter: brightness(1.1); }
.btn.toggle.active {
  background: rgba(79, 140, 255, 0.22);
  border-color: rgba(79, 140, 255, 0.55);
  color: #cfe0ff;
}
.btn.mini { padding: 5px 9px; font-size: 12px; }

/* ---------- 视口 ---------- */
#viewport {
  grid-area: viewport;
  position: relative;
  min-width: 0;
  min-height: 0;
}
#gl { display: block; width: 100%; height: 100%; outline: none; }

#hud {
  position: absolute;
  left: 14px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  max-width: calc(100% - 28px);
}
#hud-stats {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: #cfe0ff;
  background: rgba(10, 13, 20, 0.6);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 10px;
  width: fit-content;
  white-space: pre;
  display: none;
}
#hud-hint {
  font-size: 11.5px;
  color: var(--muted);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

/* ---------- 加载 / 拖拽 ---------- */
#loader, #dropzone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 16, 0.72);
  backdrop-filter: blur(4px);
  z-index: 15;
  transition: opacity 0.25s;
}
.hidden { opacity: 0; pointer-events: none !important; }

.loader-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(320px, 80%);
}
.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loader-text { font-size: 14px; }
.progress {
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s;
}

#dropzone {
  background: rgba(13, 18, 30, 0.82);
  border: 2px dashed rgba(79, 140, 255, 0.6);
}
.dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 18px;
}
.dropzone-ico { font-size: 44px; }
.dropzone-inner small { color: var(--muted); font-size: 12px; }

/* ---------- 侧边栏 ---------- */
#sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  overflow: hidden;
}

.panel {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.panel.grow { flex: 1 1 auto; min-height: 120px; overflow: hidden; }

.panel h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 20px;
  background: rgba(79, 140, 255, 0.18);
  color: #a8c4ff;
}
.badge:empty { display: none; }

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.row label { flex: 0 0 88px; color: var(--muted); }
.row label span { color: var(--text); font-variant-numeric: tabular-nums; }
.row input[type="range"] { flex: 1; accent-color: var(--accent); }
.row input[type="color"] {
  width: 42px; height: 28px; padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 6px; background: none; cursor: pointer;
}
.row input[type="search"], #tree-filter {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 12.5px;
}
.row select {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #1b2130;
  color: var(--text);
  font-size: 13px;
}
.check { display: flex; align-items: center; gap: 5px; flex: 0 0 auto; font-size: 12px; }
.check input { accent-color: var(--accent); }

.kv { font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }
.kv .line { display: flex; justify-content: space-between; gap: 10px; }
.kv .line b { font-weight: 500; font-variant-numeric: tabular-nums; }
.kv .line span { color: var(--muted); }
.muted { color: var(--muted); margin: 0; }

/* 场景树 */
#tree {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  font-size: 12.5px;
  scrollbar-width: thin;
}
#tree li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  border-radius: 6px;
  cursor: default;
}
#tree li:hover { background: rgba(255, 255, 255, 0.06); }
#tree li .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
#tree li .name:hover { color: var(--accent); }
#tree li.off .name { color: var(--muted); text-decoration: line-through; }
#tree .eye {
  border: none; background: none; cursor: pointer;
  font-size: 12px; padding: 0 2px; opacity: 0.85;
}
#tree .tag {
  font-size: 10px; color: var(--muted);
  border: 1px solid var(--panel-border);
  border-radius: 4px; padding: 0 4px;
}

/* 动画 */
#anim-panel .btn { justify-content: center; }

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: rgba(20, 25, 36, 0.95);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  :root { --toolbar-h: 52px; }
  #app { grid-template-columns: 1fr; grid-template-areas: "toolbar" "viewport"; }
  #sidebar {
    position: fixed;
    top: var(--toolbar-h);
    right: 0;
    bottom: 0;
    width: min(var(--sidebar-w), 88vw);
    z-index: 30;
    transform: translateX(0);
    transition: transform 0.25s;
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.4);
  }
  body.no-panel #sidebar { display: flex; transform: translateX(105%); }
  .btn { padding: 8px 10px; }
  .btn span:not(.ico) { display: none; }
  #hud-hint { display: none; }
}
