* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #000;
}

canvas {
  display: block;
}

/* 加载遮罩 */
#loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  z-index: 100;
  transition: opacity 0.4s;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#loading-overlay p {
  margin-top: 1.2rem;
  font-size: 1rem;
}

.loader {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* XR 启动按钮 */
#xr-button {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 36px;
  font-size: 1.1rem;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  z-index: 50;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.5);
  transition: opacity 0.3s, transform 0.15s;
}

#xr-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#xr-button:not(:disabled):hover {
  transform: translateX(-50%) scale(1.05);
}

#xr-button:not(:disabled):active {
  transform: translateX(-50%) scale(0.97);
}

/* XR 激活后隐藏按钮 */
#xr-button.hidden {
  display: none;
}

/* 降级提示 */
#fallback-info {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: rgba(239, 68, 68, 0.85);
  color: #fff;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 60;
  display: none;
}

#fallback-info.show {
  display: block;
}

/* 调试输出面板 */
#debug-panel {
  position: fixed;
  left: 10px;
  bottom: 10px;
  max-width: 90vw;
  width: 420px;
  max-height: 45vh;
  background: rgba(0, 0, 0, 0.8);
  color: #7fff7f;
  border: 1px solid #444;
  border-radius: 8px;
  z-index: 200;
  font-family: Consolas, Menlo, monospace;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#debug-panel.collapsed #debug-output {
  display: none;
}

.debug-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #222;
  border-bottom: 1px solid #444;
  font-size: 12px;
  color: #fff;
}

.debug-header span {
  flex: 1;
}

.debug-header button {
  background: #444;
  color: #fff;
  border: 1px solid #666;
  border-radius: 4px;
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
}

.debug-header button:hover {
  background: #555;
}

#debug-output {
  margin: 0;
  padding: 8px 10px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: text;
}

/* 模型控制面板 */
#model-controls {
  position: fixed;
  right: 12px;
  bottom: 90px;
  width: 220px;
  max-width: 78vw;
  background: #0f0f19;          /* 不透明深色背景，避免遮挡画面 */
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  z-index: 150;
  overflow: hidden;
  user-select: none;
  /* 注意：不要用 backdrop-filter 毛玻璃，
     它在 XR dom-overlay 中会模糊整个 3D 画面 */
  touch-action: none;
}

/* 默认隐藏；进入 AR 会话后由 xr-session.js 显示 */
#model-controls.hidden {
  display: none;
}

#model-controls.collapsed .controls-body {
  display: none;
}

.controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
}

.controls-header button {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  border-radius: 6px;
  padding: 2px 10px;
  font-size: 12px;
  cursor: pointer;
}

.controls-body {
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.controls-body label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #ccc;
}

.controls-body label em {
  font-style: normal;
  color: #8b5cf6;
  font-weight: 600;
}

.controls-body label span {
  display: flex;
  justify-content: space-between;
}

.controls-body input[type="range"] {
  width: 100%;
  accent-color: #8b5cf6;
  height: 24px;
  cursor: pointer;
}

#controls-reset {
  margin-top: 4px;
  padding: 8px 0;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
