:root {
  --bg: #0b0d12;
  --fg: #e9edf5;
  --dim: #8b93a7;
  --accent: #6ea8fe;
  --panel: rgba(20, 24, 34, 0.72);
  --border: rgba(255, 255, 255, 0.10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
}

/* 背景主题：四种深色调，保证浅色文字始终清晰 */
body {
  background:
    radial-gradient(120% 90% at 50% 8%, #1b2340 0%, #0d1120 45%, #06080e 100%),
    var(--bg);
  transition: background .6s ease;
}
body.bg-slate {
  background:
    radial-gradient(120% 90% at 50% 8%, #2b3138 0%, #171b21 48%, #090b0e 100%),
    var(--bg);
}
body.bg-warm {
  background:
    radial-gradient(120% 90% at 50% 8%, #3a2a26 0%, #241816 48%, #0d0807 100%),
    var(--bg);
}
body.bg-mint {
  background:
    radial-gradient(120% 90% at 50% 8%, #16352f 0%, #0e211e 48%, #050d0b 100%),
    var(--bg);
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;   /* 交给 OrbitControls 处理手势 */
  cursor: grab;
}
#scene:active { cursor: grabbing; }

/* ---------- 顶部标题 ---------- */
.hud-top {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: max(18px, env(safe-area-inset-top)) 20px 0;
  pointer-events: none;
  text-align: center;
}
.hud-top h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .06em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .6);
}
.hud-top p {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--dim);
  letter-spacing: .04em;
}

/* ---------- 底部控制栏 ---------- */
.hud-bottom {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .45);
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  scrollbar-width: none;
}
.hud-bottom::-webkit-scrollbar { display: none; }

.hud-bottom button {
  flex: 0 0 auto;
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  color: var(--fg);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .16s, color .16s;
}
.hud-bottom button:hover { background: rgba(255, 255, 255, .08); }
.hud-bottom button.on {
  background: var(--accent);
  color: #07101f;
  font-weight: 600;
}

/* ---------- 樱花页面 ---------- */
/* 场景自带天空穹顶，画布不透明，所以去掉暗色渐变背景 */
body.sakura {
  background: #f6dfe6;
}
body.sakura .hud-top h1 {
  font-size: 20px;
  letter-spacing: .22em;
  color: #6b3a4e;
  text-shadow: 0 2px 14px rgba(255, 255, 255, .8);
}
body.sakura .hud-top p {
  color: #8a5a6c;
  text-shadow: 0 1px 10px rgba(255, 255, 255, .85);
}
body.sakura .hud-bottom {
  background: rgba(255, 255, 255, .62);
  border-color: rgba(190, 120, 150, .28);
  box-shadow: 0 8px 28px rgba(150, 90, 120, .22);
}
body.sakura .hud-bottom button { color: #7a4457; }
body.sakura .hud-bottom button:hover { background: rgba(255, 180, 205, .35); }
body.sakura .hud-bottom button.on {
  background: #f78bb0;
  color: #fff;
  font-weight: 600;
}

/* 夜樱模式下把界面文字调亮，保证可读 */
body.sakura.night {
  background: #0c1226;
}
body.sakura.night .hud-top h1 {
  color: #ffd6e6;
  text-shadow: 0 2px 16px rgba(0, 0, 0, .7);
}
body.sakura.night .hud-top p {
  color: #e0b6c8;
  text-shadow: 0 1px 10px rgba(0, 0, 0, .8);
}
body.sakura.night .hud-bottom {
  background: rgba(18, 22, 42, .72);
  border-color: rgba(255, 180, 210, .22);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
}
body.sakura.night .hud-bottom button { color: #f0cfe0; }
body.sakura.night .hud-bottom button:hover { background: rgba(255, 180, 205, .18); }
body.sakura.night .hud-bottom button.on {
  background: #f78bb0;
  color: #22101c;
}

/* ---------- 模型选择器（有多个候选模型时出现）---------- */
.hud-picker {
  position: fixed;
  left: 50%;
  bottom: max(74px, calc(env(safe-area-inset-bottom) + 74px));
  transform: translateX(-50%);
  display: none;
  gap: 5px;
  padding: 5px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .4);
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  scrollbar-width: none;
}
.hud-picker::-webkit-scrollbar { display: none; }
.hud-picker.show { display: flex; }

.hud-picker button {
  flex: 0 0 auto;
  padding: 7px 11px;
  font-size: 12px;
  font-family: inherit;
  color: var(--dim);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .16s, color .16s;
}
.hud-picker button:hover { background: rgba(255, 255, 255, .08); }
.hud-picker button.on {
  background: #a78bfa;
  color: #07101f;
  font-weight: 600;
}

/* ---------- 右下角统计信息 ---------- */
.hud-stats {
  position: fixed;
  right: 12px;
  bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px));
  font-size: 11px;
  line-height: 1.6;
  color: var(--dim);
  text-align: right;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .8);
}

/* ---------- 遮罩层（加载 / 报错）---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 10;
  transition: opacity .5s ease;
}
.overlay.hidden { display: none; }
.overlay.fade { opacity: 0; pointer-events: none; }

.loader-box { width: min(320px, 78vw); text-align: center; }
.loader-title {
  font-size: 14px;
  letter-spacing: .08em;
  color: var(--dim);
  margin-bottom: 14px;
}
.bar {
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .10);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  transition: width .25s ease;
}
.loader-pct {
  margin-top: 10px;
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

#errorMsg {
  text-align: left;
  font-size: 11px;
  color: #ff9d9d;
  background: rgba(255, 80, 80, .08);
  border: 1px solid rgba(255, 80, 80, .22);
  border-radius: 8px;
  padding: 10px;
  margin: 0 0 14px;
  max-height: 34vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.retry {
  padding: 9px 18px;
  font-size: 13px;
  font-family: inherit;
  color: #07101f;
  background: var(--accent);
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
}

@media (max-width: 420px) {
  .hud-top h1 { font-size: 15px; }
  .hud-bottom button { padding: 8px 11px; font-size: 12px; }
}
