:root {
  --gold: #e7c477;
  --gold-soft: rgba(231, 196, 119, 0.22);
  --ink: #030706;
  --text: #eaf1e7;
  --muted: #9fb3a6;
  --panel: rgba(6, 16, 13, 0.72);
  --panel-border: rgba(231, 196, 119, 0.26);
  --radius: 14px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #010404;
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#scene-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene-canvas.is-dragging { cursor: grabbing; }

/* ---------- 加载 ---------- */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 42%, #0b2019 0%, #010404 70%);
  transition: opacity 0.45s ease, visibility 0.45s;
}
#loading-screen.is-hidden { opacity: 0; visibility: hidden; }
.loading-inner { text-align: center; padding: 24px; }
.loading-star {
  font-size: 46px;
  color: var(--gold);
  animation: pulse 1.8s ease-in-out infinite;
  text-shadow: 0 0 28px rgba(231, 196, 119, 0.8);
}
.loading-inner h1 {
  margin: 6px 0 10px;
  font-size: 26px;
  letter-spacing: 0.16em;
  font-weight: 500;
  color: var(--gold);
}
.loading-inner p { margin: 0; color: var(--muted); font-size: 14px; }
@keyframes pulse { 0%, 100% { opacity: 0.55; transform: scale(0.94); } 50% { opacity: 1; transform: scale(1.06); } }

/* ---------- 状态胶囊 ---------- */
#scene-state-pill {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.22em;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

/* ---------- 祝福文字 ---------- */
#greeting {
  position: fixed;
  left: 50%;
  bottom: 46px;
  transform: translateX(-50%);
  z-index: 10;
  text-align: center;
  padding: 12px 22px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
#greeting:active { cursor: grabbing; }
#greeting-line-one {
  font-family: Cinzel, "Palatino Linotype", Georgia, serif;
  color: var(--gold);
  font-size: 64px;
  line-height: 1.05;
  letter-spacing: 0.04em;
  text-shadow: 0 0 26px rgba(231, 196, 119, 0.55), 0 6px 30px rgba(0, 0, 0, 0.6);
}
#greeting-line-two {
  margin-top: 6px;
  font-size: 16px;
  letter-spacing: 0.3em;
  color: rgba(234, 241, 231, 0.78);
}

/* ---------- 摄像头面板 ---------- */
#camera-panel {
  position: fixed;
  left: calc(16px + env(safe-area-inset-left, 0px));
  bottom: calc(16px + var(--safe-bottom));
  z-index: 14;
  width: 232px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  overflow: hidden;
}
#camera-panel header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}
#camera-panel header strong { color: var(--text); font-size: 12px; font-weight: 600; }
#camera-status { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#camera-toggle {
  width: 22px; height: 22px; line-height: 1;
  border-radius: 6px; border: 1px solid var(--panel-border);
  background: transparent; color: var(--gold); cursor: pointer;
}
#camera-dot { width: 8px; height: 8px; border-radius: 50%; background: #43d68a; box-shadow: 0 0 8px #43d68a; }
#camera-dot.is-off { background: #6b7d72; box-shadow: none; }
#camera-panel .camera-body {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #020807;
}
#camera-panel.is-collapsed .camera-body { display: none; }
#camera-video, #camera-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
#camera-video { opacity: 0.55; }
#gesture-name {
  position: absolute;
  left: 8px; bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--gold);
  text-shadow: 0 1px 6px #000;
}

/* ---------- 授权弹窗 ---------- */
#camera-permission {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(1, 4, 4, 0.72);
  backdrop-filter: blur(6px);
}
#camera-permission[hidden] { display: none; }
.permission-card {
  width: min(460px, 100%);
  padding: 24px 22px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(12, 28, 22, 0.96), rgba(4, 10, 8, 0.98));
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}
.permission-card h2 { margin: 0 0 10px; font-size: 19px; color: var(--gold); font-weight: 600; }
.permission-card p { margin: 0 0 10px; font-size: 14px; line-height: 1.7; color: var(--text); }
.permission-card .hint { color: var(--muted); font-size: 13px; }
.permission-actions { display: flex; gap: 10px; margin-top: 16px; }
.permission-actions button {
  flex: 1;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid rgba(231, 196, 119, 0.5);
  background: linear-gradient(180deg, #e9c879, #c69a45);
  color: #23180a;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.permission-actions .ghost {
  background: transparent;
  color: var(--muted);
  border-color: rgba(159, 179, 166, 0.3);
  font-weight: 500;
}
kbd {
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(231, 196, 119, 0.35);
  background: rgba(231, 196, 119, 0.1);
  color: var(--gold);
  font-size: 12px;
}

/* ---------- 控制面板 ---------- */
#control-panel {
  position: fixed;
  top: calc(14px + var(--safe-top));
  right: calc(16px + env(safe-area-inset-right, 0px));
  z-index: 16;
  width: 288px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  overflow: hidden;
}
#control-panel .panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(231, 196, 119, 0.14);
}
#control-panel .panel-head strong { font-size: 13px; letter-spacing: 0.2em; color: var(--gold); }
#panel-collapse {
  width: 24px; height: 24px; border-radius: 6px;
  border: 1px solid var(--panel-border); background: transparent;
  color: var(--gold); cursor: pointer; line-height: 1;
}
#control-panel .panel-body {
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 12px;
}
#control-panel.is-collapsed .panel-body { display: none; }

.mode-row { display: flex; gap: 8px; }
.mode-button {
  flex: 1; padding: 9px 0; border-radius: 9px;
  border: 1px solid rgba(231, 196, 119, 0.35);
  background: rgba(231, 196, 119, 0.08);
  color: var(--gold); font-size: 13px; cursor: pointer;
}
.mode-button:hover { background: rgba(231, 196, 119, 0.18); }

.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.field > span { color: var(--gold); }
.field input[type="text"], .field select {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid rgba(231, 196, 119, 0.22);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text); font-size: 13px;
}
.field input[type="range"] { width: 100%; accent-color: var(--gold); }
.field input[type="color"] {
  width: 100%; height: 30px; border: 1px solid rgba(231, 196, 119, 0.22);
  border-radius: 8px; background: transparent; padding: 2px;
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.photo-actions, .music-row { display: flex; gap: 8px; flex-wrap: wrap; }
.file-button, .ghost, #music-play, #music-replay {
  padding: 8px 12px; border-radius: 9px; font-size: 12px; cursor: pointer;
  border: 1px solid rgba(231, 196, 119, 0.35);
  background: rgba(231, 196, 119, 0.1); color: var(--gold);
}
.ghost { background: transparent; color: var(--muted); border-color: rgba(159, 179, 166, 0.28); }
.wide { width: 100%; }
.photo-meta { color: var(--muted); font-size: 11px; line-height: 1.5; }

/* ---------- 照片槽位（手指提示） ---------- */
#photo-slots {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}
#photo-slots[hidden] { display: none; }
.photo-slot {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(2, 8, 6, 0.66);
  border: 1px solid rgba(231, 196, 119, 0.3);
  color: var(--text);
  font-size: 11px;
  backdrop-filter: blur(4px);
}
.photo-slot b { color: var(--gold); font-size: 13px; }
.photo-slot.index b { color: #ffd75e; }
.photo-slot.middle b { color: #7fe3b0; }
.photo-slot.ring b { color: #ff9a8a; }
.photo-slot.pinky b { color: #9fd8ff; }

/* ---------- 聚焦照片 ---------- */
#photo-focus-ui {
  position: fixed;
  left: 50%; bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
}
#photo-focus-ui[hidden] { display: none; }
.focus-caption { font-size: 13px; color: var(--gold); }
#photo-focus-close {
  padding: 6px 14px; border-radius: 999px;
  border: 1px solid rgba(231, 196, 119, 0.45);
  background: rgba(231, 196, 119, 0.14); color: var(--gold); cursor: pointer;
}

/* ---------- 顶部按钮 / Toast ---------- */
#hide-ui-button, #show-ui-button {
  position: fixed;
  top: calc(14px + var(--safe-top));
  right: calc(16px + env(safe-area-inset-right, 0px));
  z-index: 18;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
#show-ui-button { display: none; }
body.ui-hidden #show-ui-button { display: block; }
#ui-restore { display: none; }
body.ui-hidden #control-panel,
body.ui-hidden #camera-panel,
body.ui-hidden #greeting,
body.ui-hidden #hide-ui-button,
body.ui-hidden #scene-state-pill { display: none; }

#toast {
  position: fixed;
  left: 50%;
  top: calc(64px + var(--safe-top));
  transform: translate(-50%, -10px);
  z-index: 40;
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(6, 18, 14, 0.9);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 86vw;
  text-align: center;
}
#toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 手机适配 ---------- */
@media (max-width: 820px) {
  #greeting-line-one { font-size: clamp(30px, 9vw, 46px); }
  #greeting-line-two { font-size: 12px; letter-spacing: 0.2em; }
  #control-panel {
    top: auto;
    bottom: calc(10px + var(--safe-bottom));
    right: 8px;
    left: 8px;
    width: auto;
    max-height: 46vh;
  }
  #control-panel.is-collapsed .panel-body { display: none; }
  #camera-panel {
    width: 132px;
    left: 8px;
    bottom: calc(10px + var(--safe-bottom));
  }
  #camera-panel header { font-size: 10px; padding: 6px 8px; }
  #scene-state-pill { top: calc(10px + var(--safe-top)); font-size: 11px; }
  #hide-ui-button { top: auto; bottom: calc(10px + var(--safe-bottom)); right: 8px; }
  body.ui-hidden #hide-ui-button { display: none; }
  .photo-slot { font-size: 10px; padding: 4px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .loading-star { animation: none; }
}
