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

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #2a2f3e 0%, #14161d 60%, #0b0c10 100%);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #e8eaf0;
  user-select: none;
}

#stage { position: relative; width: 100%; height: 100%; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- 气泡 ---------- */
.bubble {
  position: absolute; left: 50%; top: max(14px, env(safe-area-inset-top));
  transform: translateX(-50%) scale(1);
  max-width: min(86vw, 520px);
  max-height: 26vh; overflow-y: auto;
  padding: 14px 18px;
  background: rgba(255,255,255,0.94);
  color: #1a1c22;
  border-radius: 16px;
  font-size: 15px; line-height: 1.6;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
  transition: opacity .22s ease, transform .22s cubic-bezier(.2,.9,.3,1.2);
  transform-origin: 50% 100%;
  z-index: 20;
  word-break: break-word;
}
.bubble.hidden { opacity: 0; transform: translateX(-50%) scale(0.9) translateY(6px); pointer-events: none; }
.bubble-tail {
  position: absolute; bottom: -8px; left: 50%; margin-left: -8px;
  width: 0; height: 0;
  border-left: 9px solid transparent; border-right: 9px solid transparent;
  border-top: 9px solid rgba(255,255,255,0.94);
}
.bubble.thinking #bubble-text::after {
  content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 4px;
  border-radius: 50%; background: #8a8f9e; animation: blink 1s infinite;
}
@keyframes blink { 0%,100%{opacity:.2} 50%{opacity:1} }

/* ---------- 加载 ---------- */
#loading {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  font-size: 14px; color: #9aa0b0; z-index: 30;
  background: rgba(11,12,16,0.92); transition: opacity .4s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: #7aa2ff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 顶部 ---------- */
#topbar {
  position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px;
  display: flex; gap: 8px; z-index: 25;
}
#model-select, #btn-mute {
  appearance: none; border: 1px solid rgba(255,255,255,0.14);
  background: rgba(20,22,28,0.72); color: #dfe3ec;
  padding: 8px 12px; border-radius: 10px; font-size: 13px;
  backdrop-filter: blur(10px); cursor: pointer;
}
#btn-mute, #btn-look { width: 40px; padding: 8px 0; text-align: center; }
#btn-look { background: rgba(122,162,255,0.28); border-color: rgba(122,162,255,0.5); }
#btn-look.hidden { display: none; }
#btn-look:active { transform: scale(0.94); }
#model-select:focus { outline: none; border-color: #7aa2ff; }

/* ---------- 输入 ---------- */
#inputbar {
  position: absolute; left: 0; right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; gap: 10px; padding: 0 16px; z-index: 25;
}
#input {
  flex: 1; min-width: 0;
  padding: 14px 16px; font-size: 15px;
  border-radius: 14px; border: 1px solid rgba(255,255,255,0.12);
  background: rgba(20,22,28,0.82); color: #eef1f7;
  backdrop-filter: blur(12px);
}
#input::placeholder { color: #6d7382; }
#input:focus { outline: none; border-color: #7aa2ff; background: rgba(26,29,38,0.92); }
#send {
  padding: 0 22px; font-size: 15px; font-weight: 600;
  border: none; border-radius: 14px; cursor: pointer;
  background: linear-gradient(135deg, #5b8cff, #7aa2ff);
  color: #fff; transition: transform .12s ease, opacity .2s;
}
#send:active { transform: scale(0.96); }
#send:disabled { opacity: .45; cursor: default; }

/* 窄屏（手机竖屏）微调 */
@media (max-width: 520px) {
  .bubble { font-size: 14px; padding: 12px 15px; line-height: 1.55; }
  #inputbar { gap: 8px; padding: 0 12px; }
  #input { padding: 12px 14px; font-size: 15px; }
  #send { padding: 0 18px; }
}
/* 横屏：顶部空间紧张，气泡缩小 */
@media (max-height: 480px) {
  .bubble { max-height: 34vh; top: 8px; }
}

/* ============ 悬浮窗模式：透明背景，只留角色 ============ */
html.overlay-mode,
html.overlay-mode body,
body.overlay-mode {
  background: transparent !important;
  background-image: none !important;
}
body.overlay-mode #stage {
  background: transparent !important;
}
body.overlay-mode #loading {
  background: transparent !important;
  color: rgba(255,255,255,.7);
}
body.overlay-mode #topbar {
  top: 0; right: 0; gap: 4px;
}
body.overlay-mode #model-select { display: none !important; }
body.overlay-mode #btn-mute { display: none !important; }
body.overlay-mode #btn-look {
  width: 26px; font-size: 12px; padding: 3px 0;
  background: rgba(20,22,28,0.45); border-color: rgba(255,255,255,0.10);
}
body.overlay-mode .bubble {
  top: 2px; max-width: 94%; max-height: 42vh;
  font-size: 12.5px; line-height: 1.5; padding: 8px 11px;
  border-radius: 12px;
  opacity: 0.97;
}
body.overlay-mode #inputbar { display: none !important; }
body.overlay-mode #btn-close {
  width: 26px; font-size: 12px; padding: 3px 0;
  background: rgba(255,80,80,0.30); border-color: rgba(255,120,120,0.45);
  color: #fff;
}
body.overlay-mode #btn-close.hidden { display: none; }

