:root {
  --bg: #ffffff;
  --side: #f8f6f3;
  --hover: #efebe5;
  --line: #ebe7e1;
  --text: #2a2622;
  --muted: #8c8379;
  --faint: #b3aaa0;
  --accent: #e47f2c;
  --accent-ink: #ffffff;
  --accent-soft: #fdf0e3;
  --accent-line: #f3c79d;
  --ububble: #f3f0ec;
  --code: #f7f5f2;
  --narr: #8f7c69;
  --danger: #d0533f;
  --shadow: 0 4px 24px rgba(70, 45, 20, 0.08);
  --fs: 16px;
  --app-h: 100dvh;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1b19;
    --side: #242120;
    --hover: #302c29;
    --line: #36312d;
    --text: #ece6df;
    --muted: #a39a90;
    --faint: #7b736b;
    --accent: #f0994d;
    --accent-ink: #2a1806;
    --accent-soft: #3a2a1c;
    --accent-line: #7a5232;
    --ububble: #2e2a27;
    --code: #262321;
    --narr: #b6a38f;
    --danger: #ef7a66;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-size: var(--fs); -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

#app { position: fixed; left: 0; right: 0; top: 0; height: var(--app-h); }
.shell { display: flex; height: 100%; }

/* 侧边栏 */
.side {
  width: 272px; flex: none; background: var(--side); display: flex; flex-direction: column;
  border-right: 1px solid var(--line); padding-top: env(safe-area-inset-top);
}
.side-mask { display: none; }
@media (max-width: 899px) {
  .side { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .22s ease; width: 82vw; max-width: 300px; }
  body.side-open .side { transform: none; box-shadow: var(--shadow); }
  body.side-open .side-mask { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(20, 12, 4, .35); }
}
@media (min-width: 900px) { .only-mobile { display: none !important; } }
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; font-weight: 800; font-size: 1.15em; letter-spacing: 1px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.newchat {
  margin: 4px 12px 10px; display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--accent-line); background: var(--accent-soft); color: var(--accent);
  border-radius: 12px; padding: 9px 12px; font-weight: 700;
}
.side-search { margin: 0 12px 8px; }
.side-search input {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 7px 10px; font-size: max(16px, .88em); outline: none;
}
.convs { flex: 1; overflow-y: auto; padding: 0 8px 8px; overscroll-behavior: contain; }
.group { font-size: .74em; color: var(--muted); padding: 12px 8px 4px; font-weight: 600; }
.conv {
  display: flex; align-items: center; gap: 4px; border-radius: 10px; padding: 8px 6px 8px 10px;
  cursor: pointer; font-size: .9em; min-height: 38px;
}
.conv:hover, .conv.on { background: var(--hover); }
.conv .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }
.conv .more { border: 0; background: none; color: var(--muted); padding: 2px 6px; border-radius: 6px; visibility: hidden; }
.conv:hover .more, .conv.on .more { visibility: visible; }
@media (pointer: coarse) { .conv .more { visibility: visible; } }
.side-foot { border-top: 1px solid var(--line); padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px); }
.side-foot button {
  display: flex; width: 100%; align-items: center; gap: 10px; border: 0; background: none;
  border-radius: 10px; padding: 9px 10px; font-size: .9em; text-align: left;
}
.side-foot button:hover { background: var(--hover); }
.side-foot .lic { color: var(--muted); font-size: .8em; padding: 4px 10px 2px; }
.side-foot .lic b { color: var(--accent); }
.empty-side { color: var(--muted); font-size: .85em; padding: 20px 10px; text-align: center; line-height: 1.7; }

/* 主区域 */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.topbar {
  flex: none; display: flex; align-items: center; gap: 4px; min-height: 50px;
  padding: calc(env(safe-area-inset-top) + 4px) 8px 4px;
}
.top-title { flex: 1; min-width: 0; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; }
.icon-btn {
  border: 0; background: none; border-radius: 10px; min-width: 38px; min-height: 38px;
  font-size: 1.15em; color: var(--text); display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--hover); }
.content { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.thread { max-width: 780px; margin: 0 auto; padding: 8px 16px 16px; }
.bottom { flex: none; max-width: 812px; width: 100%; margin: 0 auto; padding: 0 16px calc(env(safe-area-inset-bottom) + 6px); }
.disclaimer { text-align: center; font-size: .7em; color: var(--faint); padding: 6px 0 2px; }
.status { text-align: center; font-size: .78em; color: var(--muted); padding: 4px 0; }

/* 欢迎页 */
.welcome { text-align: center; padding: 9vh 8px 20px; }
.welcome img { width: 64px; height: 64px; border-radius: 16px; }
.welcome h2 { margin: 14px 0 8px; font-size: 1.35em; }
.welcome p { color: var(--muted); line-height: 1.7; margin: 0 auto; max-width: 30em; font-size: .92em; }
.setup { text-align: left; margin: 22px auto 0; max-width: 460px; }

/* 消息 */
.day { text-align: center; font-size: .72em; color: var(--faint); margin: 18px 0 6px; }
.msg { margin: 18px 0; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.ububble {
  background: var(--ububble); border-radius: 18px; padding: 10px 14px; max-width: 86%;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; line-height: 1.65; cursor: pointer;
}
.msg.ai { display: flex; gap: 12px; align-items: flex-start; }
.msg.ai .logo { width: 30px; height: 30px; border-radius: 9px; flex: none; margin-top: 2px; }
.abody { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 240px; border: 1px solid var(--line);
  background: var(--bg); border-radius: 10px; padding: 6px 10px; font-size: .8em;
}
.chip .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .s { color: var(--muted); flex: none; }
.chip .x { border: 0; background: none; color: var(--muted); padding: 0 2px; }
.chip.err { border-color: var(--danger); color: var(--danger); }
.think {
  color: var(--muted); font-size: .88em; margin-bottom: 10px;
}
.think summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; background: var(--side); border-radius: 8px; padding: 5px 10px; }
.think summary::-webkit-details-marker { display: none; }
.think .tx { border-left: 2px solid var(--line); padding: 2px 0 2px 12px; margin-top: 8px; white-space: pre-wrap; line-height: 1.7; }
.searchline { display: inline-flex; align-items: center; gap: 6px; font-size: .84em; color: var(--muted); background: var(--side); border: 0; border-radius: 8px; padding: 5px 10px; margin-bottom: 10px; }
.md { line-height: 1.75; word-break: break-word; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .55em 0; }
.md h2, .md h3, .md h4, .md h5 { margin: 1em 0 .45em; line-height: 1.4; }
.md h2 { font-size: 1.25em; } .md h3 { font-size: 1.12em; } .md h4, .md h5 { font-size: 1em; }
.md ul, .md ol { padding-left: 1.5em; margin: .5em 0; }
.md li { margin: .25em 0; }
.md blockquote { margin: .6em 0; padding: 2px 0 2px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md code { background: var(--code); border-radius: 5px; padding: 1px 5px; font-size: .88em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.codeblock { background: var(--code); border: 1px solid var(--line); border-radius: 12px; margin: .7em 0; overflow: hidden; }
.codehead { display: flex; justify-content: space-between; align-items: center; padding: 5px 8px 5px 12px; font-size: .75em; color: var(--muted); border-bottom: 1px solid var(--line); }
.codehead button { border: 0; background: none; color: var(--muted); font-size: 1em; padding: 2px 6px; border-radius: 6px; }
.codehead button:hover { background: var(--hover); }
.codeblock pre { margin: 0; padding: 10px 12px; overflow-x: auto; font-size: .85em; line-height: 1.6; }
.codeblock pre code { background: none; padding: 0; font-size: 1em; }
.tablewrap { overflow-x: auto; margin: .7em 0; }
.md table { border-collapse: collapse; font-size: .9em; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--side); }
.md .narr { color: var(--narr); }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.dots { display: inline-flex; gap: 4px; padding: 8px 0; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: hop 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
.tools { display: flex; align-items: center; gap: 2px; margin-top: 8px; color: var(--muted); font-size: .82em; flex-wrap: wrap; }
.tools button { border: 0; background: none; color: var(--muted); border-radius: 8px; padding: 4px 8px; font-size: 1em; }
.tools button:hover { background: var(--hover); color: var(--text); }
.tools button:disabled { opacity: .35; }
.tools .warn { color: var(--danger); padding: 0 6px; }
.tools .ver { padding: 0 2px; }
.uacts { display: flex; gap: 2px; margin-top: 4px; }
.uacts button { border: 0; background: none; color: var(--muted); border-radius: 8px; padding: 4px 8px; font-size: .82em; }
.uacts button:hover { background: var(--hover); }
.sysline { text-align: center; font-size: .76em; color: var(--muted); margin: 14px 20px; line-height: 1.5; }
.errline { margin: 14px 0 14px 42px; padding: 10px 12px; border-radius: 12px; font-size: .86em; line-height: 1.6; border: 1px solid var(--danger); color: var(--danger); }
.errline .detail { color: var(--muted); font-size: .9em; word-break: break-all; }
.errline .row { margin-top: 8px; }
.loadmore { display: block; margin: 8px auto; }

/* 输入框 */
.composer {
  border: 1px solid var(--line); border-radius: 22px; background: var(--bg); box-shadow: var(--shadow);
  padding: 10px 10px 8px 14px;
}
.composer:focus-within { border-color: var(--accent-line); }
.composer .chips { justify-content: flex-start; }
.composer textarea {
  width: 100%; border: 0; outline: none; resize: none; background: transparent; line-height: 1.55;
  max-height: 180px; min-height: 26px; padding: 2px 0; font-size: max(16px, 1em);
}
.crow { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.pill {
  border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 999px;
  padding: 5px 12px; font-size: .8em; display: inline-flex; align-items: center; gap: 4px;
}
.pill.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); font-weight: 600; }
.attach { border: 0; background: none; font-size: 1.15em; padding: 4px 6px; border-radius: 8px; color: var(--muted); }
.attach:hover { background: var(--hover); }
.send {
  width: 34px; height: 34px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 1em;
}
.send:disabled { background: var(--line); color: var(--faint); }
.send.stop { background: var(--text); color: var(--bg); }
.spacer { flex: 1; }

/* 页面、卡片、表单 */
.page { max-width: 680px; margin: 0 auto; padding: 8px 16px calc(env(safe-area-inset-bottom) + 30px); }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 1em; }
.card p { margin: 6px 0; line-height: 1.65; }
.card.notice { background: var(--accent-soft); border-color: var(--accent-line); }
.hint { color: var(--muted); font-size: .85em; line-height: 1.65; }
.btn { border: 0; border-radius: 12px; padding: 9px 16px; font-weight: 600; background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--side); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { padding: 6px 12px; font-size: .86em; border-radius: 10px; }
.btn.block { display: block; width: 100%; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .92em; }
.field .hint { margin-top: 4px; }
.field input[type=text], .field input[type=password], .field input[type=url], .field input[type=search], .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; background: var(--bg);
  outline: none; font-size: max(16px, 1em);
}
.field textarea { resize: vertical; line-height: 1.65; min-height: 90px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent-line); }
.seg { display: flex; background: var(--side); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 7px 4px; font-size: .86em; }
.seg button.on { background: var(--bg); box-shadow: 0 1px 4px rgba(0,0,0,.08); font-weight: 700; }
.switch { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 6px 0; }
.switch .txt { flex: 1; }
.switch input { width: 44px; height: 26px; appearance: none; -webkit-appearance: none; background: var(--line); border-radius: 13px; position: relative; flex: none; transition: background .2s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: .9em; }
.kv span:first-child { color: var(--muted); }
ol.steps { padding-left: 1.3em; margin: 6px 0; line-height: 1.85; }
.memitem { display: flex; gap: 8px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); line-height: 1.6; }
.memitem .t { flex: 1; white-space: pre-wrap; word-break: break-word; }
.memitem .src { font-size: .7em; color: var(--muted); flex: none; margin-top: 4px; }
.memitem button { border: 0; background: none; color: var(--muted); padding: 2px 6px; }
.stat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat div { background: var(--side); border-radius: 12px; padding: 8px 4px; }
.stat b { display: block; font-size: 1.1em; }
.stat span { font-size: .74em; color: var(--muted); }
.progress { height: 6px; background: var(--side); border-radius: 3px; overflow: hidden; margin: 8px 0; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.convpick { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.convpick input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.convpick .info { flex: 1; min-width: 0; }
.convpick b { display: block; font-weight: 600; }
.convpick .hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.codebox { font-family: ui-monospace, Menlo, monospace; letter-spacing: 1px; text-transform: uppercase; }

/* 弹层 */
.mask { position: fixed; inset: 0; background: rgba(20, 12, 4, .45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 900px) { .mask { align-items: center; } .sheet { border-radius: 20px !important; } }
.sheet {
  background: var(--bg); width: 100%; max-width: 520px; border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); max-height: 86vh; overflow: auto; animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h3 { margin: 0 0 12px; font-size: 1.05em; line-height: 1.5; }
.sheet textarea { width: 100%; min-height: 160px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); line-height: 1.6; font-size: max(16px, 1em); outline: none; resize: vertical; }
.sheet .row { margin-top: 12px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 6px; border-bottom: 1px solid var(--line); font-size: .95em; }
.menu button:last-child { border-bottom: 0; }
.menu button.danger { color: var(--danger); }
.src { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); }
.src b { display: block; font-weight: 600; font-size: .92em; }
.src span { color: var(--muted); font-size: .78em; }
#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 60px); transform: translateX(-50%);
  background: rgba(40, 30, 20, .92); color: #fff; padding: 9px 16px; border-radius: 20px; font-size: .88em;
  z-index: 100; opacity: 0; pointer-events: none; transition: opacity .25s; max-width: 86vw; text-align: center; line-height: 1.5;
}
#toast.show { opacity: 1; }
