:root {
  --bg: #fbf7f4;
  --surface: #ffffff;
  --surface-2: #f3ede9;
  --text: #2a2224;
  --text-2: #7a6d70;
  --line: #ebe2dd;
  --accent: #c8566b;
  --accent-soft: #f6e3e6;
  --accent-text: #ffffff;
  --warn: #b7791f;
  --warn-soft: #fbf0dc;
  --danger: #c0392b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1718;
    --surface: #262022;
    --surface-2: #2f282a;
    --text: #f1e9ea;
    --text-2: #a8999c;
    --line: #3a3134;
    --accent: #e07a8e;
    --accent-soft: #3d2a2f;
    --accent-text: #1b1718;
    --warn: #e0a84a;
    --warn-soft: #3a2f1e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); }

#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
.bar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title-btn { flex: 1; min-width: 0; text-align: left; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; color: var(--text-2); }
.icon-btn:active { background: var(--surface-2); }
.chip {
  font-size: 13px; padding: 5px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.chip.low { background: var(--warn-soft); color: var(--warn); }

/* ---------- 通用 ---------- */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.btn:active { opacity: .85; }
.btn[disabled] { opacity: .5; }
.btn.ghost { background: var(--surface-2); color: var(--text); font-weight: 500; }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.field {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); outline: none;
}
.field:focus { border-color: var(--accent); }
textarea.field { resize: vertical; min-height: 120px; }
.muted { color: var(--text-2); font-size: 14px; }
.err { color: var(--danger); font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row > .grow { flex: 1; min-width: 0; }
.banner {
  margin: 12px 16px 0; padding: 12px 14px; border-radius: 12px;
  background: var(--warn-soft); color: var(--warn); font-size: 14px;
}
.banner b { color: inherit; }
.banner button { color: inherit; text-decoration: underline; font-size: 14px; }

/* ---------- 欢迎页 ---------- */
.hero { padding: calc(var(--safe-top) + 40px) 24px 16px; }
.hero h1 { font-size: 30px; margin: 0 0 8px; letter-spacing: .5px; }
.hero p { margin: 0; color: var(--text-2); }
.points { margin: 20px 0 0; padding: 0; list-style: none; }
.points li { padding: 10px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.points li span:first-child { flex: none; }
.steps { counter-reset: s; padding: 0; margin: 0; list-style: none; }
.steps li { counter-increment: s; position: relative; padding: 0 0 14px 34px; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 1px;
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  font-size: 13px; font-weight: 700; display: grid; place-items: center;
}

/* ---------- 对话列表 ---------- */
.conv {
  display: block; width: 100%; text-align: left;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.conv:active { background: var(--surface-2); }
.conv .t { font-weight: 600; display: flex; gap: 8px; }
.conv .t span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .t time { flex: none; font-weight: 400; font-size: 12px; color: var(--text-2); }
.conv .p { font-size: 14px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.empty { padding: 48px 24px; text-align: center; }
.empty .big { font-size: 40px; }
.fab-row {
  flex: none; display: flex; gap: 10px;
  padding: 10px 16px calc(var(--safe-bottom) + 10px); border-top: 1px solid var(--line); background: var(--bg);
}
.fab-row .btn { flex: 1; }

/* ---------- 聊天 ---------- */
.msgs { padding: 12px 12px 4px; }
.msg { display: flex; margin: 6px 0; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 84%; padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; word-break: break-word;
  background: var(--surface); border: 1px solid var(--line);
}
.msg.user .bubble { background: var(--accent); color: var(--accent-text); border-color: transparent; border-bottom-right-radius: 6px; }
.msg.assistant .bubble { border-bottom-left-radius: 6px; }
.bubble i { color: var(--text-2); font-style: normal; }
.msg.user .bubble i { color: inherit; opacity: .85; }
.bubble.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.meta { font-size: 11px; color: var(--text-2); margin: -2px 6px 6px; }
.msg-wrap.user .meta { text-align: right; }
.actions { display: flex; gap: 6px; margin: 0 6px 8px; flex-wrap: wrap; }
.msg-wrap.user .actions { justify-content: flex-end; }
.actions button { font-size: 13px; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); color: var(--text-2); }
.divider { text-align: center; font-size: 12px; color: var(--text-2); margin: 14px 0; display: flex; gap: 8px; align-items: center; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px dashed var(--line); }
.more { display: block; margin: 8px auto; font-size: 13px; color: var(--accent); }
.status { text-align: center; font-size: 13px; color: var(--text-2); padding: 6px 12px; }
.fail { margin: 0 6px 8px; display: flex; justify-content: flex-end; align-items: center; gap: 8px; font-size: 13px; color: var(--danger); flex-wrap: wrap; }
.composer {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(var(--safe-bottom) + 8px); border-top: 1px solid var(--line); background: var(--bg);
}
.composer textarea {
  flex: 1; resize: none; max-height: 40vh; min-height: 42px; padding: 9px 14px; border-radius: 21px;
  border: 1px solid var(--line); background: var(--surface); outline: none; line-height: 1.45;
}
.composer textarea:focus { border-color: var(--accent); }
.send { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 18px; flex: none; }
.send.stop { background: var(--surface-2); color: var(--text); }
.trial { text-align: center; font-size: 12px; color: var(--text-2); padding: 4px 0 0; }

/* ---------- 设置 ---------- */
.group { margin: 16px; }
.group h3 { font-size: 13px; color: var(--text-2); font-weight: 500; margin: 0 4px 6px; }
.group .card { padding: 4px 16px; }
.item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); min-height: 50px; }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .v { color: var(--text-2); font-size: 14px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.item select { border: 0; background: transparent; color: var(--text-2); text-align: right; max-width: 60%; font-size: 15px; }
button.item { width: 100%; text-align: left; }
a.item { color: inherit; text-decoration: none; }
.file-btn { position: relative; overflow: hidden; cursor: pointer; }
.file-btn.busy { opacity: .5; pointer-events: none; }
.file-hit { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 0; }

/* ---------- 底部弹层 ---------- */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 88dvh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 8px 18px calc(var(--safe-bottom) + 18px);
  animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 19px; margin: 0 0 6px; }
.menu button { display: block; width: 100%; text-align: left; padding: 14px 4px; border-bottom: 1px solid var(--line); font-size: 16px; }
.menu button:last-child { border-bottom: 0; }
.menu button.danger { color: var(--danger); }
.pick { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.pick input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); }
.tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin: 10px 0 14px; }
.tabs button { flex: 1; padding: 8px; border-radius: 9px; font-size: 14px; color: var(--text-2); }
.tabs button.on { background: var(--surface); color: var(--text); font-weight: 600; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 90px); transform: translateX(-50%);
  background: rgba(30,24,26,.92); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; }
