:root {
  --bg: #0f0d12;
  --bg-soft: #17131c;
  --card: #1e1826;
  --card-2: #251d30;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3edf8;
  --muted: #a99bb8;
  --accent: #e8a0b8;
  --accent-2: #9b7cff;
  --think: #c7b8d8;
  --danger: #ff8999;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60% 40% at 15% 0%, rgba(155, 124, 255, 0.16), transparent 70%),
    radial-gradient(50% 35% at 90% 8%, rgba(232, 160, 184, 0.14), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.6; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; z-index: 1; }

/* ---------- 登录 ---------- */
.login-screen { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; text-align: center;
  background: linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0.015));
  border: 1px solid var(--line); border-radius: 26px; padding: 32px 24px 26px;
  backdrop-filter: blur(14px);
}
.avatar {
  width: 54px; height: 54px; border-radius: 50%; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: #2a1a22;
  background: linear-gradient(145deg, #f4c3d4, #c9a6ff);
  box-shadow: 0 10px 30px rgba(201, 166, 255, 0.25);
}
.avatar.big { width: 72px; height: 72px; font-size: 32px; }
.login-card h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: 2px; font-weight: 600; }
.login-card p { margin: 0 0 20px; }
input[type="password"] {
  width: 100%; padding: 14px 16px; border-radius: 14px; font-size: 16px;
  border: 1px solid var(--line); background: rgba(0,0,0,0.28); color: var(--text);
  outline: none; margin-bottom: 12px;
}
input[type="password"]:focus { border-color: rgba(232,160,184,0.5); }
button { font-family: inherit; cursor: pointer; border: none; }
.primary {
  width: 100%; padding: 14px; border-radius: 14px; font-size: 16px; font-weight: 600;
  color: #251522; background: linear-gradient(120deg, #f2b8cb, #c4a6ff);
}
.primary:active { transform: scale(0.98); }

/* ---------- 顶栏 ---------- */
.app-screen { background: transparent; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 13, 18, 0.72);
  backdrop-filter: blur(16px);
  z-index: 3;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; font-size: 17px;
  color: var(--text); background: rgba(255,255,255,0.05);
}
.title-wrap { flex: 1; display: flex; align-items: baseline; gap: 8px; }
.title { font-size: 17px; font-weight: 600; letter-spacing: 1px; }
.status { font-size: 11px; color: var(--muted); }
.status.busy { color: var(--accent); }

/* ---------- 消息区 ---------- */
.messages {
  flex: 1; overflow-y: auto; padding: 18px 14px 8px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth; z-index: 1;
}
.msg { display: flex; gap: 10px; max-width: 100%; animation: rise .22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg .bubble {
  max-width: 84%; padding: 11px 14px; border-radius: var(--radius);
  font-size: 15.5px; line-height: 1.62; word-break: break-word;
}
.msg .bubble .text { white-space: pre-wrap; }
.msg.me { justify-content: flex-end; }
.msg.me .bubble {
  background: linear-gradient(135deg, #3d2a3f, #2b2338);
  border: 1px solid rgba(232, 160, 184, 0.22);
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}
.msg.her { justify-content: flex-start; }
.msg.her .bubble {
  background: var(--card); border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.msg .who {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #2a1a22; margin-top: 2px;
  background: linear-gradient(145deg, #f4c3d4, #c9a6ff);
}
.msg.me .who { display: none; }

/* 思考块 */
.think {
  margin: 0 0 9px; border-radius: 12px; overflow: hidden;
  border: 1px dashed rgba(201, 166, 255, 0.28);
  background: rgba(155, 124, 255, 0.06);
}
.think-head {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; font-size: 12px; color: var(--think);
  cursor: pointer; user-select: none;
}
.think-head .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent-2);
  animation: pulse 1.1s infinite ease-in-out;
}
@keyframes pulse { 0%,100% { opacity: .35; transform: scale(.8);} 50% { opacity: 1; transform: scale(1.15);} }
.think-body {
  display: none; padding: 0 12px 10px; font-size: 13px; line-height: 1.6;
  color: var(--think); white-space: pre-wrap; max-height: 40vh; overflow-y: auto;
  border-top: 1px solid rgba(201, 166, 255, 0.14); padding-top: 8px;
}
.think.open .think-body { display: block; }
.think.done .think-head .dot { animation: none; background: rgba(201,166,255,.45); }

.tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.tool-chip {
  font-size: 11.5px; color: #cfc0e2; padding: 4px 9px; border-radius: 999px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--line);
}

.typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,80%,100% { opacity: .25; } 40% { opacity: 1; } }

.elapsed { font-size: 11px; color: var(--muted); margin-left: 6px; }

/* ---------- 输入区 ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: rgba(15, 13, 18, 0.85);
  backdrop-filter: blur(14px);
  z-index: 3;
}
.composer textarea {
  flex: 1; resize: none; max-height: 132px; min-height: 44px;
  padding: 12px 14px; border-radius: 16px; font-size: 16px; line-height: 1.45;
  color: var(--text); background: var(--card); border: 1px solid var(--line);
  outline: none; font-family: inherit;
}
.composer textarea:focus { border-color: rgba(232,160,184,0.35); }
.send-btn {
  width: 44px; height: 44px; border-radius: 15px; flex: 0 0 44px;
  display: flex; align-items: center; justify-content: center;
  color: #2a1a22; background: linear-gradient(135deg, #f2b8cb, #c4a6ff);
}
.send-btn:disabled { opacity: .35; }
.send-btn.stop { background: rgba(255,255,255,0.1); color: var(--text); }

/* ---------- 抽屉 / 设置 ---------- */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 8; backdrop-filter: blur(2px); }
.drawer, .settings {
  position: fixed; top: 0; bottom: 0; width: min(86vw, 360px); z-index: 9;
  background: var(--bg-soft); border-right: 1px solid var(--line);
  transform: translateX(-102%); transition: transform .26s ease;
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
}
.drawer.open { transform: none; }
.settings { left: auto; right: 0; border-right: none; border-left: 1px solid var(--line); transform: translateX(102%); }
.settings.open { transform: none; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; font-size: 15px; font-weight: 600; border-bottom: 1px solid var(--line);
}
.small-btn {
  font-size: 12.5px; padding: 7px 12px; border-radius: 10px;
  color: var(--accent); background: rgba(232,160,184,.12);
}
.session-list { overflow-y: auto; padding: 8px; flex: 1; }
.session-item {
  padding: 12px; border-radius: 12px; display: flex; gap: 8px; align-items: center;
  color: var(--text); font-size: 14px;
}
.session-item:active, .session-item.active { background: rgba(255,255,255,0.06); }
.session-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .d { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.session-item .x { color: var(--muted); padding: 4px 6px; font-size: 15px; }

.setting-block { padding: 16px; border-bottom: 1px solid var(--line); }
.setting-title { font-size: 12px; color: var(--muted); margin-bottom: 10px; letter-spacing: 1px; }
.option {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); margin-bottom: 8px; background: rgba(255,255,255,0.02);
}
.option input { margin-top: 3px; accent-color: #e8a0b8; }
.option b { font-size: 14px; font-weight: 600; display: block; }
.option small { color: var(--muted); font-size: 11.5px; line-height: 1.5; display: block; margin-top: 2px; }
.ghost-btn {
  width: 100%; padding: 12px; border-radius: 12px; font-size: 14px;
  color: var(--danger); background: rgba(255,137,153,.08); border: 1px solid rgba(255,137,153,.18);
}
.foot { padding: 16px; margin: 0; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(40, 30, 48, 0.96); color: var(--text); font-size: 13px;
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line); z-index: 20;
  max-width: 80vw; text-align: center;
}
