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

/* ---------- 主题变量:默认深色,body.light 覆盖 ---------- */
:root {
  --bg: #1b1424;
  --bg2: #251b31;
  --card: rgba(255, 255, 255, .06);
  --card-border: rgba(255, 255, 255, .09);
  --text: #f3ece4;
  --dim: #a495b2;
  --accent: #e8927c;
  --accent-soft: rgba(232, 146, 124, .14);
  --accent-grad: linear-gradient(135deg, #f2b8a2, #e8927c 55%, #d97b62);
  --on-accent: #3a2027;
  --user-bubble: linear-gradient(135deg, #54406b, #463156);
  --user-text: #f3ece4;
  --ai-bubble: rgba(255, 255, 255, .06);
  --ai-shadow: none;
  --sheet: #281e36;
  --field: rgba(255, 255, 255, .06);
  --hangup: #c14e63;
  --radius: 22px;
  --serif: "Noto Serif SC", "Songti SC", "STSong", serif;
}
body.light {
  --bg: #fdf9f4;
  --bg2: #f6ece4;
  --card: #ffffff;
  --card-border: transparent;
  --text: #3a2f38;
  --dim: #a08e9a;
  --accent: #d97b62;
  --accent-soft: rgba(217, 123, 98, .14);
  --accent-grad: linear-gradient(135deg, #e8927c, #d97b62);
  --on-accent: #ffffff;
  --user-bubble: linear-gradient(135deg, #e8927c, #d97b62);
  --user-text: #ffffff;
  --ai-bubble: #ffffff;
  --ai-shadow: 0 2px 12px rgba(90, 55, 65, .07);
  --sheet: #fffdfb;
  --field: #f6efe9;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Noto Sans SC", sans-serif;
  background: linear-gradient(170deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--text);
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ---------- 品牌光球 ---------- */
.avatar-orb, .login-orb, .orb {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f6c9b5, #e8927c 58%, #b45f4d);
}
.avatar-orb { width: 34px; height: 34px; box-shadow: 0 0 16px rgba(232, 146, 124, .4); flex-shrink: 0; }
.login-orb { width: 88px; height: 88px; margin: 0 auto 18px; box-shadow: 0 0 70px rgba(232, 146, 124, .45); }

/* ---------- 布局 ---------- */
#app { display: flex; flex-direction: column; height: 100dvh; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 18px 12px;
  backdrop-filter: blur(8px);
}
.title { font-size: 20px; font-weight: 600; font-family: var(--serif); display: flex; align-items: center; gap: 12px; }
.badge {
  font-size: 11px; font-weight: 400; color: var(--dim); font-family: -apple-system, "PingFang SC", sans-serif;
  border: 1px solid var(--dim); border-radius: 99px; padding: 1px 8px;
}

main {
  flex: 1; overflow-y: auto; padding: 8px 16px 16px;
  display: flex; flex-direction: column; gap: 10px;
}

footer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 10px);
}
#input {
  flex: 1; resize: none; border: 1px solid var(--card-border); outline: none;
  background: var(--card); color: var(--text); box-shadow: var(--ai-shadow);
  border-radius: 22px; padding: 12px 16px; font-size: 16px; line-height: 1.4;
  max-height: 120px; font-family: inherit;
}
#input::placeholder { color: var(--dim); }

.icon-btn {
  border: none; background: none; color: var(--text);
  font-size: 20px; cursor: pointer; flex-shrink: 0;
}
.icon-btn.round {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--card); box-shadow: var(--ai-shadow); color: var(--dim);
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.icon-btn.big {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
#sendBtn {
  background: var(--accent-grad); color: var(--on-accent); font-weight: 700; font-size: 20px;
  box-shadow: 0 4px 14px rgba(232, 146, 124, .35);
}

/* ---------- 气泡 ---------- */
.msg { max-width: 82%; padding: 12px 16px; border-radius: var(--radius); font-size: 16px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; animation: pop .18s ease; }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: var(--user-text); border-bottom-right-radius: 8px; }
.msg.ai { align-self: flex-start; background: var(--ai-bubble); border: 1px solid var(--card-border); box-shadow: var(--ai-shadow); border-bottom-left-radius: 8px; }
.msg.sys { align-self: center; background: none; color: var(--dim); font-size: 13px; text-align: center; }
.msg .mode-tag { font-size: 11px; opacity: .75; display: block; margin-top: 5px; }
@keyframes pop { from { transform: translateY(4px); opacity: 0; } }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- 覆盖层 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: linear-gradient(170deg, var(--bg) 0%, var(--bg2) 100%);
  display: flex; align-items: center; justify-content: center;
}

/* 登录 */
.login-card { text-align: center; width: min(320px, 86vw); }
.login-brand { font-family: var(--serif); font-size: 40px; font-weight: 600; letter-spacing: 2px; color: var(--accent); margin-bottom: 8px; }
.login-card h1 { font-family: var(--serif); font-size: 28px; margin-bottom: 8px; }
.login-card p { color: var(--dim); margin-bottom: 30px; font-size: 15px; }
.login-card input {
  width: 100%; border: 1px solid var(--card-border); outline: none; text-align: center;
  background: var(--card); color: var(--text); box-shadow: var(--ai-shadow);
  border-radius: 16px; padding: 15px; font-size: 17px; margin-bottom: 14px;
}
.login-card input::placeholder { color: var(--dim); }
.login-card button {
  width: 100%; border: none; border-radius: 16px; padding: 15px;
  background: var(--accent-grad); color: var(--on-accent); font-size: 16px; font-weight: 700; cursor: pointer;
  box-shadow: 0 8px 24px rgba(232, 146, 124, .3);
}
.err { color: #f38ba8; font-size: 14px; margin-top: 12px; min-height: 20px; }

/* 语音 */
.voice-wrap { text-align: center; width: min(340px, 88vw); display: flex; flex-direction: column; align-items: center; gap: 22px; }
.voice-label { color: var(--dim); font-size: 13px; letter-spacing: 3px; }
.voice-name { font-family: var(--serif); font-size: 26px; font-weight: 600; margin-top: -10px; }
.orb-wrap { position: relative; width: 170px; height: 170px; margin: 10px 0; }
.orb-wrap .ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid rgba(232, 146, 124, .35); animation: ripple 2.6s ease-out infinite;
}
.orb-wrap .ring.r2 { animation-delay: 1.3s; border-color: rgba(232, 146, 124, .25); }
@keyframes ripple { from { transform: scale(1); opacity: .45; } to { transform: scale(1.6); opacity: 0; } }
.orb {
  position: absolute; inset: 0;
  box-shadow: 0 0 80px rgba(232, 146, 124, .45);
  transition: transform .15s ease;
}
.orb.listening { animation: breathe 2.6s ease-in-out infinite; }
.orb.speaking { animation: pulse .9s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes pulse { 0%, 100% { transform: scale(1); box-shadow: 0 0 80px rgba(232,146,124,.45); } 50% { transform: scale(1.12); box-shadow: 0 0 100px rgba(232,146,124,.6); } }
.voice-status { color: var(--dim); font-size: 15px; }
.voice-caption { min-height: 72px; font-size: 17px; line-height: 1.7; padding: 0 12px; }
#hangupBtn {
  border: none; border-radius: 99px; padding: 14px 46px;
  background: var(--hangup); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
  box-shadow: 0 8px 24px rgba(193, 78, 99, .35);
}

/* 设置 */
#settings { align-items: flex-end; }
.sheet {
  width: 100%; background: var(--sheet);
  border-top: 1px solid var(--card-border);
  border-radius: 28px 28px 0 0; padding: 14px 24px calc(env(safe-area-inset-bottom) + 22px);
  display: flex; flex-direction: column; gap: 10px;
  animation: rise .22s ease;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .18);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 40px; height: 4px; border-radius: 99px; background: var(--dim); opacity: .4; align-self: center; margin-bottom: 8px; }
.sheet h2 { font-family: var(--serif); font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.sheet label { color: var(--dim); font-size: 13px; margin-top: 6px; }
.sheet input {
  border: 1px solid var(--card-border); outline: none; background: var(--field); color: var(--text);
  border-radius: 14px; padding: 13px 15px; font-size: 16px;
}
.persona-list { display: flex; flex-direction: column; gap: 8px; }
.persona-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1.5px solid transparent; background: var(--field);
  border-radius: 16px; padding: 13px 15px; cursor: pointer;
}
.persona-item::after {
  content: ""; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--dim); opacity: .5; flex-shrink: 0;
}
.persona-item.active { border-color: var(--accent); background: var(--accent-soft); }
.persona-item.active::after { border: 6px solid var(--accent); opacity: 1; }
.persona-item .p-name { font-size: 16px; font-weight: 600; }
.persona-item .p-desc { font-size: 13px; color: var(--dim); margin-top: 3px; }
.theme-list { display: flex; gap: 8px; }
.theme-list button {
  flex: 1; border: 1.5px solid transparent; background: var(--field); color: var(--text);
  border-radius: 14px; padding: 12px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.theme-list button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.sheet-btns { display: flex; gap: 10px; margin-top: 14px; }
.sheet-btns button {
  flex: 1; border: none; border-radius: 16px; padding: 14px;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
#cfgSave { background: var(--accent-grad); color: var(--on-accent); font-weight: 700; box-shadow: 0 8px 24px rgba(232, 146, 124, .25); }
.ghost { background: var(--field); color: var(--dim); }
