:root {
  --bg: #070a12;
  --bg-2: #0d1322;
  --fg: #e8edf7;
  --muted: #8b97ad;
  --accent: #5b8cff;
  --accent-2: #7de2d1;
  --danger: #ff6b6b;
  --card: rgba(255, 255, 255, 0.06);
  --stroke: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(91, 140, 255, 0.22), transparent 60%),
    radial-gradient(90% 60% at 50% 110%, rgba(125, 226, 209, 0.12), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 8px;
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: #cfd8ea;
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 12px var(--accent-2);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn, .ghost-btn, .primary-btn, .send-btn {
  font: inherit;
  color: var(--fg);
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: var(--card);
  cursor: pointer;
}

.icon-btn {
  width: 38px;
  height: 38px;
  font-size: 17px;
  display: grid;
  place-items: center;
}

.ghost-btn { padding: 8px 14px; font-size: 13px; color: #cbd5e6; }

.primary-btn {
  padding: 11px 22px;
  background: linear-gradient(135deg, var(--accent), #7f6bff);
  border: none;
  font-weight: 600;
}

/* ---------- 对话区 ---------- */

.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise 0.18s ease-out;
}

.bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.9), rgba(127, 107, 255, 0.9));
  color: #fff;
  border-bottom-right-radius: 6px;
}

.bubble.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--stroke);
  color: #e6ecf9;
  border-bottom-left-radius: 6px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 主舞台 ---------- */

.stage {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 10px 18px calc(env(safe-area-inset-bottom, 0px) + 6px);
}

.hint {
  font-size: 13.5px;
  color: var(--muted);
  min-height: 20px;
  text-align: center;
  transition: color 0.2s;
}

.orb {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: radial-gradient(circle at 32% 28%, #2a3a63, #111a2e 70%);
  color: #cfe0ff;
  display: grid;
  place-items: center;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: transform 0.15s ease, box-shadow 0.25s ease;
}

.orb:active { transform: scale(0.97); }

.orb-icon { position: relative; z-index: 2; opacity: 0.92; }

.orb-glow {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0deg, rgba(91, 140, 255, 0.75) 90deg, transparent 200deg);
  filter: blur(6px);
  opacity: 0;
  transition: opacity 0.3s;
}

body[data-mode="listening"] .orb-glow {
  opacity: 1;
  animation: spin 2.4s linear infinite;
}

body[data-mode="listening"] .orb {
  box-shadow: 0 0 0 13px rgba(91, 140, 255, 0.1), 0 18px 44px rgba(0, 0, 0, 0.45);
}

body[data-mode="thinking"] .orb { color: #9fb4ff; animation: pulse 1.1s ease-in-out infinite; }
body[data-mode="speaking"] .orb { color: #9ff0e2; box-shadow: 0 0 0 13px rgba(125, 226, 209, 0.1), 0 18px 44px rgba(0, 0, 0, 0.45); }
body[data-mode="speaking"] .orb-glow {
  opacity: 0.8;
  background: conic-gradient(from 0deg, transparent 0deg, rgba(125, 226, 209, 0.7) 90deg, transparent 200deg);
  animation: spin 1.5s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { transform: scale(1.035); } }

.meter {
  width: 132px;
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.meter i {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: transform 0.06s linear;
}

/* ---------- 输入框 ---------- */

.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 6px 18px calc(env(safe-area-inset-bottom, 0px) + 14px);
}

.composer input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
  font: inherit;
  font-size: 14.5px;
  outline: none;
}

.composer input:focus { border-color: rgba(91, 140, 255, 0.6); }

.send-btn {
  padding: 0 18px;
  font-size: 14px;
  background: rgba(91, 140, 255, 0.18);
  border-color: rgba(91, 140, 255, 0.35);
  color: #cfe0ff;
}

/* ---------- 设置面板 ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  margin: auto;
  width: min(520px, calc(100% - 16px));
  max-height: 92dvh;
  overflow-y: auto;
  padding: 20px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
  background: #0f1524;
  border: 1px solid var(--stroke);
  border-radius: 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
}

.sheet[hidden] { display: none; }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sheet-head h2 { font-size: 17px; margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-size: 13px; color: var(--muted); }
.field input[type="text"], .field input[type="password"], .field select, .field textarea {
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
  font: inherit;
  font-size: 14.5px;
  outline: none;
}
.field textarea { resize: vertical; line-height: 1.5; }
.field small { color: #6d7a92; font-size: 12px; }

.row { display: flex; gap: 12px; }
.row .field { flex: 1; }

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  font-size: 14px;
  color: #cfd8ea;
}

.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
}

/* ---------- 提示 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
  transform: translate(-50%, 12px);
  max-width: 86vw;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(255, 107, 107, 0.92);
  color: #fff;
  font-size: 13.5px;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
