:root {
  --bg: #f6f4ef; --panel: #ffffff; --ink: #1f1d1a; --muted: #6f6a62; --line: #e4e0d8;
  --di: #1f5c4a; --di-ink: #ffffff;
  --claude: #fbefe6; --claude-edge: #d97a4a;
  --grok: #ebeff5; --grok-edge: #5a6f8f;
  --sys: #8a857c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514; --panel: #201f1d; --ink: #ece9e3; --muted: #a29d94; --line: #34322e;
    --di: #2f7d66; --di-ink: #ffffff;
    --claude: #33261e; --claude-edge: #e08a5c;
    --grok: #232a35; --grok-edge: #8ea4c6;
    --sys: #8f8a81;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
}
[hidden] { display: none !important; }

#login { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 16px; }
#login h1 { margin: 0; font-size: 26px; }
#login p { margin: 0 0 12px; color: var(--muted); }
.err { color: #b3261e; min-height: 1.5em; }

#chat { height: 100%; height: 100dvh; display: flex; max-width: 1040px; margin: 0 auto; }
#pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* 话题列表：电脑上在左边，手机上是抽屉 */
#topics { width: 230px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
.topics-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 12px 8px 16px; padding-top: max(12px, env(safe-area-inset-top));
}
#newTopic { padding: 5px 10px; border: 0; border-radius: 999px; background: var(--di); color: var(--di-ink); font: inherit; font-size: 13px; cursor: pointer; }
#topicList { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; }
.topic {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left;
  padding: 9px 10px; border: 0; border-radius: 10px; background: none; color: var(--ink); font: inherit; font-size: 15px; cursor: pointer;
}
.topic span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic:hover { background: var(--bg); }
.topic.on { background: var(--bg); font-weight: 600; box-shadow: inset 3px 0 0 var(--di); }
.dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--claude-edge); }
.icon { flex: none; width: 34px; height: 34px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.icon:hover { background: var(--bg); color: var(--ink); }
#menuBtn { display: none; }
#scrim { display: none; }
@media (max-width: 719px) {
  #menuBtn { display: block; }
  #topics { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(80vw, 300px); transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 24px rgba(0,0,0,.18); }
  #chat.drawer #topics { transform: none; }
  #chat.drawer #scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.3); }
  .switch span { font-size: 13px; }
}

header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topicTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--di); }

#list { flex: 1; overflow-y: auto; margin: 0; padding: 12px 16px; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; display: flex; flex-direction: column; gap: 2px; }
.msg .who { font-size: 12px; color: var(--muted); padding: 0 4px; }
.msg .bubble { padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.di { align-self: flex-end; align-items: flex-end; }
.msg.di .bubble { background: var(--di); color: var(--di-ink); border-bottom-right-radius: 4px; }
.msg.claude .bubble { background: var(--claude); border-left: 3px solid var(--claude-edge); border-bottom-left-radius: 4px; }
.msg.grok .bubble { background: var(--grok); border-left: 3px solid var(--grok-edge); border-bottom-left-radius: 4px; }
.msg .row { display: flex; align-items: flex-end; gap: 8px; }
.msg .avatar { width: 30px; height: 30px; flex: none; border-radius: 8px; box-shadow: 0 0 0 1px var(--line); }
.msg.claude .who, .msg.grok .who { padding-left: 42px; }
.msg.system { align-self: center; max-width: 92%; text-align: center; }
.msg.system .bubble { color: var(--sys); font-size: 13px; padding: 2px 8px; }
.msg.system .who { display: none; }
.bubble a { color: inherit; }

#mentions { display: flex; align-items: center; gap: 8px; padding: 8px 16px 0; background: var(--panel); border-top: 1px solid var(--line); }
#mentions button {
  display: flex; align-items: center; gap: 5px; padding: 4px 10px 4px 5px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
}
#mentions img { width: 20px; height: 20px; border-radius: 6px; }
#mentions span { font-size: 12px; color: var(--muted); }
#mentions + #composer { border-top: 0; }
#composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--panel);
}
#text {
  flex: 1; resize: none; max-height: 40vh; padding: 9px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit;
}
#send { padding: 9px 16px; border: 0; border-radius: 12px; background: var(--di); color: var(--di-ink); font: inherit; cursor: pointer; }
#send:disabled { opacity: .5; }
