:root {
  --bg: #f6f5f1; --card: #fff; --fg: #1f1e1c; --mut: #77736a; --line: #e4e1d8;
  --acc: #c2643c; --acc-fg: #fff; --me: #ece7dc; --code: #f0eee8; --ok: #2e8b57; --bad: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1a18; --card: #262522; --fg: #ebe8e1; --mut: #9b968c; --line: #3a3833;
    --acc: #d9774c; --acc-fg: #fff; --me: #34322d; --code: #2e2c28; --ok: #4fb37d; --bad: #e0675a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.55 -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  display: flex; flex-direction: column; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }
textarea { resize: none; max-height: 40vh; min-height: 38px; }
.note, small { font-size: 11px; color: var(--mut); }
.err { color: var(--bad); font-size: 12px; min-height: 1em; }
.chip { font-size: 12px; border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; background: var(--card); }
.primary { background: var(--acc); color: var(--acc-fg); border-radius: 10px; padding: 8px 14px; font-weight: 600; white-space: nowrap; }
.primary:disabled { opacity: .5; }
.icon { font-size: 22px; width: 36px; height: 36px; line-height: 1; }

#bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
#ttl { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { flex: 1; overflow-y: auto; padding: 10px 12px; -webkit-overflow-scrolling: touch; }
#auth { max-width: 420px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 10px; padding-top: 30px; }
#auth h2 { font-size: 16px; margin: 0; }

#q { margin-bottom: 8px; }
#items { list-style: none; margin: 0; padding: 0; }
#items li { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; }
#items li b { font-size: 13px; font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#items li .meta { display: flex; gap: 6px; align-items: center; font-size: 11px; color: var(--mut); white-space: nowrap; }
#items li .meta span { flex: none; }
#items li .meta span:last-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.dot.busy { background: var(--acc); animation: pulse 1s infinite; }
.dot.idle { background: var(--ok); }
.dot.pc { background: #5b8def; }
.dot.ask { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }

#chat { padding-bottom: 6px; }
#more { display: block; margin: 0 auto 8px; }
.u { background: var(--me); border-radius: 12px 12px 2px 12px; padding: 7px 10px; margin: 10px 0 10px 12%; white-space: pre-wrap; word-break: break-word; }
.a { margin: 6px 0; word-break: break-word; }
.md p { margin: 4px 0; }
.md pre, .tool pre { background: var(--code); border-radius: 8px; padding: 8px; overflow-x: auto; font-size: 12px; line-height: 1.4; margin: 6px 0; white-space: pre-wrap; word-break: break-all; }
.md code { background: var(--code); border-radius: 4px; padding: 0 3px; font-size: 12.5px; }
.md pre code { padding: 0; background: none; }
.md table { border-collapse: collapse; font-size: 12.5px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 3px 6px; }
.md h1, .md h2, .md h3 { font-size: 14px; margin: 10px 0 4px; }
.md ul, .md ol { padding-left: 20px; margin: 4px 0; }
.md a { color: var(--acc); }
.tool { margin: 2px 0; font-size: 12px; color: var(--mut); }
.tool summary { list-style: none; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 2px 0; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: "▸ "; }
.tool[open] summary::before { content: "▾ "; }
.tool summary b { color: var(--fg); font-weight: 600; }
.tool.e summary b { color: var(--bad); }
.tool.wait summary b::after { content: " …"; }
#live { opacity: .9; }

.ask { background: var(--card); border: 1.5px solid var(--acc); border-radius: 12px; padding: 10px; margin: 8px 0; }
.ask h4 { margin: 0 0 4px; font-size: 13px; }
.ask pre { max-height: 30vh; overflow: auto; }
.ask .btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.ask .btns button { flex: 1; min-width: 40%; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg); text-align: left; }
.ask .btns button small { display: block; }
.ask .btns .primary { text-align: center; background: var(--acc); }
.ask > .chip { margin-top: 8px; }

#composer { background: var(--card); border-top: 1px solid var(--line); padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
#composer .row { display: flex; gap: 8px; align-items: flex-end; }
#status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--mut); margin-bottom: 6px; }
#status #stText { flex: 1; }
.spin { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--acc); border-radius: 50%; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
#new { display: flex; flex-direction: column; gap: 6px; }
