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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* ---- 摄像头 ---- */
#camera-video {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 1;
}

/* ---- Three.js 渲染层 ---- */
#three-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* ---- 隐藏的合成 canvas ---- */
#capture-canvas {
  display: none;
}

/* ---- 加载遮罩 ---- */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  gap: 16px;
  transition: opacity 0.4s ease;
}

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

.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#loading-text {
  font-size: 15px;
  color: rgba(255,255,255,0.7);
}

/* ---- 权限提示 ---- */
#permission-overlay {
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}

#permission-overlay.hidden {
  display: none;
}

.permission-card {
  background: #1c1c1e;
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  max-width: 300px;
  color: #fff;
}

.permission-card h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.permission-card p {
  font-size: 14px;
  color: rgba(255,255,255,0.6);
  margin-bottom: 24px;
  line-height: 1.5;
}

#permission-btn {
  background: #007aff;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 32px;
  font-size: 16px;
  cursor: pointer;
}

/* ---- AR UI ---- */
#ar-ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#ar-ui.hidden {
  display: none;
}

#ar-ui > * {
  pointer-events: auto;
}

#hint-bar {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  color: #fff;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 20px;
  transition: opacity 2s ease;
}

#hint-bar.fade {
  opacity: 0;
}

/* ---- 底部工具栏 ---- */
#toolbar {
  position: absolute;
  bottom: 40px;
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 0 24px;
}

.tool-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.tool-btn:active {
  background: rgba(255,255,255,0.3);
}

/* ---- 拍照按钮 ---- */
#photo-btn {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-ring {
  width: 68px; height: 68px;
  border-radius: 50%;
  border: 4px solid #fff;
  display: block;
  transition: transform 0.15s ease;
}

#photo-btn:active .photo-ring {
  transform: scale(0.9);
}

/* ---- 角色选择面板 ---- */
#character-panel {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  z-index: 50;
  background: rgba(28,28,30,0.95);
  backdrop-filter: blur(20px);
  border-radius: 20px 20px 0 0;
  padding: 16px 0 32px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

#character-panel.visible {
  transform: translateY(0);
}

#character-panel.hidden {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 12px;
  color: #fff;
}

.panel-header h3 {
  font-size: 17px;
  font-weight: 600;
}

#panel-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#character-list {
  display: flex;
  gap: 12px;
  padding: 0 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.character-card {
  flex-shrink: 0;
  width: 80px;
  text-align: center;
  cursor: pointer;
}

.character-card .thumb {
  width: 80px; height: 80px;
  border-radius: 12px;
  background: rgba(255,255,255,0.1);
  border: 2px solid transparent;
  object-fit: cover;
  transition: border-color 0.2s;
}

.character-card.active .thumb {
  border-color: #007aff;
}

.character-card .name {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.character-card .placeholder-thumb {
  width: 80px; height: 80px;
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.3);
  font-size: 28px;
}

/* ---- 预览弹窗 ---- */
#preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0,0,0,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

#preview-overlay.hidden {
  display: none;
}

#preview-image {
  max-width: 90vw;
  max-height: 65vh;
  border-radius: 8px;
  object-fit: contain;
}

.preview-actions {
  display: flex;
  gap: 16px;
}

.preview-actions button {
  padding: 12px 28px;
  border-radius: 24px;
  font-size: 16px;
  border: none;
  cursor: pointer;
}

#retake-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

#save-btn {
  background: #007aff;
  color: #fff;
}

/* ---- 倒计时 ---- */
#countdown-display {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 120px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 40px rgba(0,0,0,0.5);
  pointer-events: none;
}

#countdown-display.hidden {
  display: none;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  animation: toastIn 0.3s ease;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
