* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.app-container {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.scene-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.three-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}

.controls-container {
  position: absolute;
  left: 30px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 15px;
  z-index: 1000;
  background-color: rgba(0, 0, 0, 0.5);
  padding: 20px 15px;
  border-radius: 10px;
  backdrop-filter: blur(5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  max-height: 90vh;
  width: auto;

  /* 移动端：禁止双击缩放（只影响控制面板，不影响画布） */
  touch-action: manipulation;
}

/* 面板内：禁止出现光标/全选/长按选择菜单（不影响按钮点击） */
.controls-container,
.controls-container * {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none; /* iOS 长按菜单 */
}

.top-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.bottom-controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: stretch;
  justify-content: center;
}

.control-group, .control-group-single {
  position: relative;
  flex: 1;
  max-width: 160px;
}

.main-btn {
  width: 100%;
  background-color: #2196F3;
  text-align: center;
  margin: 0;
  padding: 12px 20px;
}

.sub-controls {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 15px;
  display: none;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 12px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 9999;
}

/* 特殊布局的子控件面板 */
.frame-sub-controls, .segment-sub-controls {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  max-height: 300px;
  overflow-y: auto;
  position: relative;
  left: 0;
  top: 0;
  transform: none;
  margin-left: 0;
  width: auto;
}

.sub-controls::after {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 8px solid rgba(0, 0, 0, 0.9);
}

.sub-controls.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}

.sub-btn {
  padding: 12px 14px;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: bold;
  width: 80px;
  height: 46px;
  cursor: pointer;
  transition: all 0.3s ease;
  background: linear-gradient(135deg, #4a90e2, #357abd);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25),
              inset 0 1px 2px rgba(255, 255, 255, 0.3),
              inset 0 -2px 2px rgba(0, 0, 0, 0.15);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.sub-btn:hover {
  background: linear-gradient(135deg, #5a9ee8, #4a90e2);
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.35),
              inset 0 1px 2px rgba(255, 255, 255, 0.4);
}

/*
  PNG 重新着色（把白色图标“染”成指定颜色）
  说明：纯 PNG 不能直接用 CSS 改像素颜色，这里用 filter 近似实现。
  目标色：#941755
*/
.sub-btn,
.sub-btn:hover,
.sub-btn:active,
.axis-sub-controls .sub-btn:hover {
  filter: none !important;
}

.sub-btn img {
  /* 将接近白色的图标染成 #941755（近似值，不同浏览器可能略有差异） */
  filter: brightness(0) saturate(100%) invert(14%) sepia(37%) saturate(4928%) hue-rotate(315deg) brightness(91%) contrast(97%) !important;
  mix-blend-mode: normal !important;
  opacity: 1 !important;
}

.sub-btn:active {
  background: linear-gradient(135deg, #357abd, #2c5aa0);
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3),
              inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.sub-btn.active {
  background: linear-gradient(to bottom, #357abd, #4a90e2);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.control-btn, .control-single-btn {
  padding: 10px 15px;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  margin: 0;
  width: 120px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  text-align: center;
}

.reset-btn {
  background-color: #4CAF50;
}

.play-btn {
  background-color: #2196F3;
}

#speedUpAnimation {
  background-color: #FF9800;
}

#slowDownAnimation {
  background-color: #9C27B0;
}

/* 控制组按钮颜色 */
#toggleAxisControls {
  background-color: #3F51B5;
}

#toggleLinearControls {
  background-color: #009688;
}

#toggleRotationControls {
  background-color: #673AB7;
}

/* 单轴运动按钮特殊样式 */
.axis-sub-controls .sub-btn {
  border: 2px solid rgba(255, 255, 255, 0.2);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
  position: relative;
  overflow: hidden;
}

.axis-sub-controls .sub-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
}

.axis-sub-controls .sub-btn:hover::before {
  left: 100%;
}

.axis-sub-controls .sub-btn:hover {
  background: linear-gradient(135deg, #4a5bc4, #3f51b5);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 16px rgba(63, 81, 181, 0.4),
              0 4px 8px rgba(0, 0, 0, 0.3);
}

.axis-sub-controls .sub-btn:active {
  background: linear-gradient(135deg, #303f9f, #283593);
  transform: translateY(0) scale(1.02);
}

/* 禁用状态样式 */
.axis-sub-controls .sub-btn:disabled {
  background: linear-gradient(135deg, #666, #555);
  border-color: rgba(255, 255, 255, 0.1);
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.axis-sub-controls .sub-btn:disabled::before {
  display: none;
}

.linear-sub-controls .sub-btn {
  background-color: rgba(0, 150, 136, 0.3);
}

.rotation-sub-controls .sub-btn {
  background-color: rgba(103, 58, 183, 0.3);
}

.control-btn:hover {
  transform: scale(1.05) translateY(-2px);
  filter: brightness(1.2);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.import-btn {
  background-color: #E91E63;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.remove-btn {
  background-color: #F44336;
}

.import-btn:hover, .remove-btn:hover {
  transform: scale(1.05) translateY(-2px);
  filter: brightness(1.2);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.loading-indicator {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.spinner {
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-text {
  margin-top: 10px;
  color: #fff;
  font-size: 16px;
  font-weight: bold;
}

.format-tooltip {
  position: absolute;
  top: 30px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  padding: 5px 10px;
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 5px;
  z-index: 1002;
}

/* 模型尺寸控制面板样式 */
.model-controls {
  position: absolute;
  top: 70px;
  right: 20px;
  padding: 15px;
  background-color: rgba(0, 0, 0, 0.7);
  border-radius: 8px;
  color: white;
  width: 280px;
  z-index: 1002;
  backdrop-filter: blur(5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
}

.model-control-title {
  font-weight: bold;
  text-align: center;
  margin-bottom: 10px;
  margin-top: 15px;
  font-size: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  padding-bottom: 5px;
}

.model-control-title:first-child {
  margin-top: 0;
}

.model-control-group {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.model-control-group label {
  width: 80px;
  margin-right: 10px;
  font-size: 14px;
}

.model-control-group input[type="range"] {
  flex: 1;
  margin-right: 10px;
}

.model-control-group span {
  width: 40px;
  text-align: right;
}

.model-control-group select {
  flex: 1;
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  border: 1px solid rgba(255, 255,  255, 0.3);
  padding: 5px;
  border-radius: 4px;
}

.model-info {
  margin-top: 15px;
  font-size: 12px;
  background-color: rgba(0, 0, 0, 0.4);
  padding: 8px;
  border-radius: 4px;
}

.model-info p {
  margin: 3px 0;
}

.reset-pos-btn {
  background-color: #FF9800;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: bold;
  display: block;
  margin: 5px auto;
  width: 80%;
}

.reset-pos-btn:hover {
  background-color: #F57C00;
}

/* 伺服电机状态显示（PC 默认） */
#servo-status {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 2000;

  background-color: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 14px 22px;
  border-radius: 12px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);

  max-width: 60vw;
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
}

@media (max-width: 768px) {
    /* 移动端适中大小（之前太小） */
    #servo-status {
        top: 10px;
        right: 10px;
        font-size: 15px;
        padding: 8px 14px;
        border-radius: 10px;
        max-width: 80vw;
    }

    /* 菜单整体下移，避免遮挡机械臂 */
    .controls-container {
        padding: 10px;
        gap: 8px;
        left: 10px;
        top: auto;
        bottom: 20px;
        transform: translateY(0);
        max-height: 70vh; /* 限制高度，减少遮挡 */
        width: auto;
    }

    #enable-key-group {
        padding: 8px;
        gap: 8px;
    }

    #enable-key-group .enable-key-label {
        font-size: 13px;
    }

    #enable-key-group .radio-label {
        font-size: 13px;
    }

    #enable-key-group .radio-custom {
        width: 14px;
        height: 14px;
        margin-right: 6px;
    }

    #enable-key-group input[type="radio"]:checked + .radio-custom::after {
        width: 7px;
        height: 7px;
    }

    /* 统一按钮宽度（解决“重置”与下面三个按钮不对齐） */
    .top-controls,
    .control-group {
        align-items: stretch;
        width: 100px;
    }

    .control-btn,
    .main-btn {
        padding: 8px 10px;
        font-size: 13px;
        width: 100px;
        display: block;
    }

    .control-group,
    #enable-key-group {
        max-width: 100px;
        width: 100px;
    }

    /* 移动端：子面板固定，不随按钮位置变化（固定在左侧菜单右边） */
    .sub-controls {
        position: fixed;
        left: 120px; /* 10(left) + 100(menu) + ~10 gap */
        bottom: 20px; /* 与菜单底部对齐 */
        top: auto;
        transform: none;
        margin-left: 0;

        /* 关键：保证可点击，且不被浏览器手势/OrbitControls吞事件 */
        pointer-events: auto;
        touch-action: none;

        gap: 6px;
        padding: 8px;
        width: auto;

        border-radius: 12px;
        background: rgba(0, 0, 0, 0.9);
        backdrop-filter: blur(10px);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
        z-index: 9999;
    }

    /* 固定弹窗时，不需要箭头 */
    .sub-controls::after {
        display: none;
    }

    .sub-btn {
        padding: 6px;
        font-size: 11px;
        width: 60px;
        height: 36px;
        /* 关键：防止移动端点击出现高亮/缩放 */
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    .sub-btn img {
        width: 18px !important;
        height: 18px !important;
        margin-right: 4px !important;
    }

    .model-controls {
        width: calc(100% - 20px);
        max-width: 280px;
        right: 10px;
        top: 60px;
        padding: 10px;
    }

    .model-control-group label {
        width: 70px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    #servo-status {
        font-size: 14px;
        padding: 7px 12px;
        top: 8px;
        right: 8px;
        border-radius: 10px;
        max-width: 86vw;
    }

    .controls-container {
        left: 5px;
        bottom: 10px;
        padding: 8px;
    }

    /* 进一步确保对齐 */
    .top-controls,
    .control-group {
        width: 90px;
        align-items: stretch;
    }

    .control-btn,
    .main-btn {
        width: 90px;
        font-size: 12px;
        display: block;
    }

    /* 超小屏：子面板也固定在左侧菜单右边 */
    .sub-controls {
        position: fixed;
        left: 105px; /* 5(left) + 90(menu) + 10 gap */
        bottom: 10px;
        top: auto;
        transform: none;
        margin-left: 0;

        pointer-events: auto;
        touch-action: none;

        gap: 4px;
        padding: 6px;
    }

    .sub-btn {
        width: 55px;
        height: 34px;
        font-size: 10px;
    }

    .sub-btn img {
        width: 16px !important;
        height: 16px !important;
    }

    .model-controls {
        width: auto;
        left: 5px;
        right: 5px;
        top: 55px;
    }
} 

/* 隐藏但可被 programmatic click 唤起的文件输入 */
.hidden-file-input {
  position: absolute;
  left: -9999px;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* 动画控制相关样式 */
.animation-sub-controls {
  gap: 8px;
}

.animation-sub-controls .sub-btn {
  min-width: 80px;
  padding: 8px 12px;
  font-size: 12px;
}

.animation-sub-controls .sub-btn[data-animation="play"] {
  background: linear-gradient(135deg, #4CAF50, #45a049);
  color: white;
}

.animation-sub-controls .sub-btn[data-animation="pause"] {
  background: linear-gradient(135deg, #FF9800, #f57c00);
  color: white;
}

.animation-sub-controls .sub-btn[data-animation="resume"] {
  background: linear-gradient(135deg, #2196F3, #1976d2);
  color: white;
}

.animation-sub-controls .sub-btn[data-animation="stop"] {
  background: linear-gradient(135deg, #f44336, #d32f2f);
  color: white;
}

.animation-sub-controls .sub-btn[data-animation="status"] {
  background: linear-gradient(135deg, #9C27B0, #7b1fa2);
  color: white;
}

/* 动画控制按钮悬停效果 */
.animation-sub-controls .sub-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* 帧输入组样式 */
.frame-input-group {
  display: flex;
  gap: 5px;
  align-items: center;
}

.frame-input {
  width: 80px;
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f9f9f9;
  font-size: 12px;
}

/* 分段类别样式 */
.segment-category {
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.segment-category:last-child {
  border-bottom: none;
}

.segment-category h4 {
  margin: 0 0 8px 0;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
}

.segment-category .sub-btn {
  margin: 2px;
  font-size: 11px;
  padding: 6px 10px;
}

/* 帧和分段控件按钮样式 */
.frame-sub-controls .sub-btn,
.segment-sub-controls .sub-btn {
  background-color: #2196F3;
  color: white;
  transition: all 0.2s ease;
}

.frame-sub-controls .sub-btn:hover,
.segment-sub-controls .sub-btn:hover {
  background-color: #1976D2;
  transform: translateY(-1px);
}

/* 使能键样式 */
#enable-key-group {
  display: flex;
  flex-direction: column; /* 改为垂直布局 */
  align-items: start;
  gap: 8px; /* 减小间距 */
  background-color: rgba(255, 255, 255, 0.1);
  padding: 10px;
  border-radius: 8px;
}

#enable-key-group .enable-key-label {
  font-weight: bold;
  font-size: 14px;
  color: #fff;
  text-transform: lowercase;
}

#enable-key-group .radio-group {
  display: flex;
  flex-direction: column;
  gap: 10px; /* 减小选项间距 */
  align-items: flex-start;
  justify-content: flex-start;
}

#enable-key-group .radio-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
  color: #eee;
  transition: color 0.3s ease;
}

#enable-key-group .radio-label:hover {
  color: #fff;
}

#enable-key-group input[type="radio"] {
  display: none; /* 隐藏原生radio */
}

#enable-key-group .radio-custom {
  width: 16px;
  height: 16px;
  border: 2px solid #aaa;
  border-radius: 50%;
  margin-right: 8px;
  display: inline-block;
  position: relative;
  transition: border-color 0.3s ease;
}

#enable-key-group .radio-label:hover .radio-custom {
  border-color: #fff;
}

#enable-key-group input[type="radio"]:checked + .radio-custom {
  border-color: #4CAF50;
}

#enable-key-group input[type="radio"]:checked + .radio-custom::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background-color: #4CAF50;
  border-radius: 50%;
}
