:root {
  --bg: #0a1420;
  --glass: rgba(16, 28, 42, 0.82);
  --glass-border: rgba(140, 180, 220, 0.18);
  --text: #dce8f5;
  --muted: #8ba3ba;
  --accent: #4fc3f7;
  --accent-2: #81d4a8;
  --panel-w: 264px;
}

* { box-sizing: border-box; }

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

#app { position: relative; width: 100vw; height: 100vh; }

#scene { display: block; width: 100%; height: 100%; outline: none; }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28);
}

/* 标题 */
#titlebar {
  position: absolute;
  top: 18px;
  left: 22px;
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
.title-main { font-size: 21px; font-weight: 650; letter-spacing: 0.5px; }
.title-sub { margin-top: 3px; font-size: 11px; color: var(--muted); letter-spacing: 0.4px; }

/* 控制面板 */
#panel {
  position: absolute;
  top: 74px;
  left: 22px;
  width: var(--panel-w);
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--glass-border);
  flex: 0 0 auto;
}
.panel-title { font-weight: 600; letter-spacing: 1px; }
.icon-btn {
  width: 24px; height: 24px;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }
.panel-body { padding: 6px 14px 14px; overflow-y: auto; }
#panel.collapsed { width: 150px; }
#panel.collapsed .panel-body { display: none; }

.group { padding: 10px 0; border-bottom: 1px solid rgba(140, 180, 220, 0.1); }
.group:last-child { border-bottom: none; }
.group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--accent);
  margin-bottom: 8px;
}

.row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; cursor: pointer; }
.toggle input { display: none; }
.switch {
  position: relative;
  width: 34px; height: 18px;
  border-radius: 10px;
  background: #33465a;
  transition: background 0.2s;
  flex: 0 0 auto;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #cfe0ef;
  transition: transform 0.2s;
}
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { transform: translateX(16px); background: #fff; }

.slider-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; }
.slider-row label { color: var(--muted); }
.slider-row .value { font-variant-numeric: tabular-nums; color: var(--accent-2); font-weight: 600; }
input[type="range"] {
  width: 100%;
  margin: 8px 0 2px;
  accent-color: var(--accent);
  cursor: pointer;
}

.btn-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.btn {
  padding: 7px 4px;
  border: 1px solid var(--glass-border);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: rgba(79, 195, 247, 0.16); border-color: var(--accent); }
.hint { color: var(--muted); font-size: 10.5px; line-height: 1.6; margin: 9px 0 0; }

.stats .stat { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 11.5px; }
.stats .stat span { color: var(--muted); }
.stats .stat b { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

/* 图例 */
#legend {
  position: absolute;
  left: 22px;
  bottom: 56px;
  width: 180px;
  padding: 10px 12px;
}
.legend-title { font-size: 11px; color: var(--muted); margin-bottom: 7px; }
.legend-bar { height: 12px; border-radius: 3px; border: 1px solid rgba(255,255,255,0.15); }
.legend-scale { display: flex; justify-content: space-between; margin-top: 5px; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* 读数 */
#readout {
  position: absolute;
  right: 22px;
  bottom: 56px;
  padding: 10px 14px;
  min-width: 150px;
}
.readout-row { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; font-size: 11.5px; }
.readout-row span { color: var(--muted); }
.readout-row b { font-variant-numeric: tabular-nums; font-weight: 600; }

/* 署名 */
#attribution {
  position: absolute;
  left: 22px;
  bottom: 18px;
  font-size: 10px;
  color: var(--muted);
  text-shadow: 0 1px 6px #000;
}
#attribution a { color: #8fc7ea; text-decoration: none; }
#attribution a:hover { text-decoration: underline; }

/* 加载 / 错误 */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(8, 16, 26, 0.92);
  z-index: 20;
  transition: opacity 0.5s;
}
#loading.done { opacity: 0; pointer-events: none; }
.spinner {
  width: 42px; height: 42px;
  border: 3px solid rgba(79, 195, 247, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--muted); letter-spacing: 1px; }

#error {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  max-width: 520px;
  padding: 20px 24px;
  background: rgba(60, 20, 24, 0.94);
  border: 1px solid #d0676f;
  border-radius: 10px;
  color: #ffd9dc;
  z-index: 30;
  line-height: 1.6;
  white-space: pre-wrap;
}
.hidden { display: none !important; }

@media (max-width: 760px) {
  :root { --panel-w: 210px; }
  #titlebar .title-main { font-size: 16px; }
  #panel { top: 64px; left: 12px; }
  #legend { left: 12px; bottom: 48px; width: 150px; }
  #readout { right: 12px; bottom: 48px; }
  #attribution { left: 12px; bottom: 12px; font-size: 9px; }
}
