html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d1117;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: #e6edf3;
  -webkit-font-smoothing: antialiased;
}

#scene-container {
  position: absolute;
  inset: 0;
  touch-action: none; /* 触摸手势交给 OrbitControls，避免移动端拖拽触发默认滚动 */
}

#scene-container canvas {
  display: block;
  touch-action: none;
}

/* 标签层：零件名称跟随 3D 位置 */
#labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.part-label {
  position: absolute;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 14px;
  background: rgba(12, 18, 28, 0.88);
  border: 1px solid rgba(80, 180, 255, 0.45);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 10px rgba(35, 140, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #d8eeff;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.3px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.18s ease-out, border-color 0.2s, background 0.2s, color 0.2s;
  user-select: none;
  pointer-events: auto; /* 标签可被点击选中 */
  cursor: pointer;
}

.part-label::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4db2ff;
  box-shadow: 0 0 6px #4db2ff;
  flex-shrink: 0;
}

.part-label:hover {
  border-color: #7eceff;
  color: #ffffff;
  background: rgba(16, 26, 42, 0.95);
}

.part-label.selected {
  border-color: #ffbf37;
  color: #fff3cb;
  background: rgba(48, 36, 10, 0.92);
  box-shadow: 0 0 16px rgba(255, 191, 55, 0.5), 0 4px 14px rgba(0, 0, 0, 0.6);
}

.part-label.selected::before {
  background: #ffbf37;
  box-shadow: 0 0 8px #ffbf37;
}

/* 顶部浮动控制面板 */
#ui-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 410px;
  max-width: calc(100vw - 32px);
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(13, 20, 32, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55), 0 0 1px rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #eaf2fb;
  z-index: 10;
  box-sizing: border-box;
  transition: box-shadow 0.2s ease;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

#ui-panel h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #f2f7fc;
}

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(45, 125, 220, 0.2);
  border: 1px solid rgba(80, 160, 255, 0.35);
  color: #8fd0ff;
  font-weight: normal;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #cfe4fa;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  font-size: 10px;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
}

/* 折叠逻辑 */
#ui-panel.collapsed .panel-content {
  display: none;
}

.panel-content {
  margin-top: 10px;
}

#ui-panel .desc {
  margin: 0 0 12px;
  font-size: 12px;
  color: #8fa5be;
  line-height: 1.45;
}

/* 控制行布局 */
.controls-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slider-row {
  margin-bottom: 10px;
}

.slider-row label {
  font-size: 12px;
  font-weight: 500;
  color: #b7cde3;
  white-space: nowrap;
}

#explode-slider {
  flex: 1;
  min-width: 140px;
  height: 6px;
  border-radius: 3px;
  outline: none;
  background: rgba(255, 255, 255, 0.15);
  accent-color: #3b9eff;
  cursor: pointer;
  margin: 0;
}

#slider-value {
  font-size: 13px;
  font-weight: 600;
  min-width: 38px;
  text-align: right;
  color: #7accff;
  font-variant-numeric: tabular-nums;
}

/* 按钮组 */
.actions-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.btn-action,
.btn-tool {
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 4px;
  text-align: center;
  white-space: nowrap;
  outline: none;
  transition: all 0.15s ease;
  user-select: none;
}

.btn-action {
  background: linear-gradient(135deg, rgba(35, 115, 215, 0.85), rgba(18, 75, 155, 0.85));
  border: 1px solid rgba(80, 160, 255, 0.45);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.btn-action:hover {
  background: linear-gradient(135deg, rgba(48, 134, 240, 0.95), rgba(24, 88, 175, 0.95));
  box-shadow: 0 0 10px rgba(50, 140, 255, 0.4);
}

.btn-action:active {
  transform: scale(0.97);
}

.btn-tool {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #dce7f5;
}

.btn-tool:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
}

.btn-tool:active {
  transform: scale(0.97);
}

.btn-tool.active {
  background: rgba(30, 130, 230, 0.28);
  border-color: rgba(70, 175, 255, 0.7);
  color: #72ccff;
  box-shadow: 0 0 10px rgba(45, 150, 255, 0.3);
}

/* 选中部件信息卡片 */
.selected-card {
  background: rgba(18, 25, 37, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 9px;
  padding: 10px 12px;
  transition: all 0.2s ease;
}

.selected-card.has-selection {
  background: rgba(32, 28, 16, 0.65);
  border-color: rgba(255, 184, 34, 0.35);
}

.selected-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.selected-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: #9bb1c7;
  font-weight: 500;
}

.selected-card.has-selection .selected-badge {
  background: rgba(255, 184, 34, 0.25);
  color: #ffb822;
}

#selected-title {
  font-size: 13px;
  font-weight: 600;
  color: #f0f6fc;
}

.selected-card.has-selection #selected-title {
  color: #ffca48;
}

#selected-desc {
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
  color: #a4b8cc;
}

.selected-card.has-selection #selected-desc {
  color: #e2ecf7;
}

/* 小屏设备（手机/平板竖屏）优化，不遮挡画面 */
@media (max-width: 640px) {
  #ui-panel {
    top: 8px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    padding: 8px 10px;
    border-radius: 10px;
  }
  #ui-panel h1 {
    font-size: 15px;
  }
  #ui-panel .desc {
    display: none; /* 小屏隐藏冗余提示行 */
  }
  .actions-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 8px;
  }
  .btn-action,
  .btn-tool {
    padding: 7px 6px;
    font-size: 12px;
    min-height: 36px;
  }
  .slider-row {
    margin-bottom: 8px;
  }
  .selected-card {
    padding: 8px 10px;
  }
  #selected-title {
    font-size: 13px;
  }
  #selected-desc {
    font-size: 11px;
    line-height: 1.45;
  }
  .part-label {
    font-size: 11px;
    padding: 2px 8px;
  }
}
