:root {
  --bg: #f4f6fb; --panel: #ffffff; --text: #1c2333; --muted: #667085; --line: #e4e8f0;
  --accent: #2f6bff; --accent2: #16b8a6; --on-accent: #ffffff; --soft: #eef3ff;
  --code: #f3f5f9; --codebar: #e8ecf3; --danger: #c0362c; --danger-soft: #fdf0ee;
  --key-bg: #eef4ff; --key-line: #2f6bff; --warn-bg: #fff8e8; --warn-line: #f0a020;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --glow: rgba(47, 107, 255, .10);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --panel: #1b1f27; --text: #e7eaf0; --muted: #98a2b3; --line: #2b313c;
    --accent: #5b8cff; --accent2: #2fd0bd; --on-accent: #ffffff; --soft: #1f2a44;
    --code: #232833; --codebar: #2b3140; --danger: #ff8f85; --danger-soft: #3a2422;
    --key-bg: #1c2740; --key-line: #5b8cff; --warn-bg: #33290f; --warn-line: #e0a030;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --glow: rgba(91, 140, 255, .14);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; color: var(--text);
  background: radial-gradient(1100px 380px at 50% -140px, var(--glow), transparent 70%), var(--bg);
  font: 16px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 顶栏 ---------- */
header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 36px; height: 36px; flex: none; border-radius: 10px; }
.names { min-width: 0; }
header h1 { margin: 0; font-size: 17px; font-weight: 650; line-height: 1.25; letter-spacing: .2px; }
#subtitle { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle:empty { display: none; }
.actions { display: flex; align-items: center; gap: 8px; flex: none; }
.ghost, .chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel); font-size: 14px;
  transition: background .15s, border-color .15s;
}
.ghost:hover, .chip:hover { background: var(--soft); border-color: var(--accent); }
.chip { padding-left: 4px; max-width: 46vw; }
.chip #mename { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.face {
  width: 26px; height: 26px; flex: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-size: 13px; font-weight: 600;
}

/* ---------- 消息区 ---------- */
main { flex: 1; overflow-y: auto; padding: 22px 16px 8px; scroll-behavior: smooth; }
main > * { max-width: 860px; margin-left: auto; margin-right: auto; }

#welcome { text-align: center; padding: 6vh 0 12px; }
.hero { width: 64px; height: 64px; border-radius: 18px; box-shadow: var(--shadow); }
#welcome h2 { margin: 16px 0 6px; font-size: 24px; font-weight: 650; }
#intro { margin: 0 auto; max-width: 560px; color: var(--muted); }
#examples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 26px 0 18px; text-align: left; }
#examples button {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left;
  padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); line-height: 1.5; transition: transform .15s, border-color .15s;
}
#examples button::after { content: "→"; color: var(--accent); flex: none; opacity: .65; transition: transform .15s, opacity .15s; }
#examples button:hover { border-color: var(--accent); transform: translateY(-1px); }
#examples button:hover::after { transform: translateX(3px); opacity: 1; }
.tip {
  max-width: 620px; margin: 0 auto 18px; padding: 10px 14px; text-align: left; font-size: 14px; line-height: 1.6;
  color: var(--text); background: var(--key-bg); border-radius: 12px; border-left: 3px solid var(--key-line);
}
.tip:empty { display: none; }
.tip kbd, .hint kbd {
  font: 12px/1 Consolas, Menlo, monospace; padding: 2px 6px; margin: 0 1px; border-radius: 5px;
  background: var(--panel); border: 1px solid var(--line); border-bottom-width: 2px;
}
.hint {
  max-width: 860px; margin: 0 auto 8px; padding: 8px 14px; font-size: 14px; line-height: 1.6; border-radius: 12px;
  color: var(--text); background: var(--warn-bg); border-left: 3px solid var(--warn-line); animation: rise .2s ease-out;
}
#topics { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 4px; }
#topics span { font-size: 12px; color: var(--muted); padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
#topics:not(:empty)::before { content: "已覆盖"; font-size: 12px; color: var(--muted); padding: 2px 4px; }

.msg { display: flex; gap: 10px; margin-bottom: 20px; animation: rise .22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: 82%; padding: 9px 14px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; word-break: break-word;
  color: var(--on-accent); background: linear-gradient(135deg, var(--accent), #4a7dff); box-shadow: var(--shadow);
}
.avatar { width: 32px; height: 32px; flex: none; border-radius: 10px; margin-top: 2px; }
.msg.bot .body { min-width: 0; flex: 1; }
.msg.bot .bubble {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px 16px 16px 16px;
  padding: 6px 16px; box-shadow: var(--shadow); word-break: break-word;
}
.bubble p { margin: 10px 0; }
.bubble h4 { margin: 16px 0 6px; font-size: 16px; font-weight: 650; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 1.5em; }
.bubble .ind1 { margin-left: 1.1em; }
.bubble .ind2 { margin-left: 2.2em; }
.bubble li { margin: 4px 0; }
.bubble li::marker { color: var(--accent); font-weight: 600; }
.bubble strong { font-weight: 650; }
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.bubble code { background: var(--code); border-radius: 5px; padding: 1px 6px; font: 14px/1.55 Consolas, "SFMono-Regular", Menlo, monospace; }

/* 回答里的 【结论】【原因/规则】… 小节 */
.sec { margin: 12px 0; }
.sec h5 {
  display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 0; padding: 1px 10px 1px 8px;
  font-size: 13px; font-weight: 650; color: var(--accent); background: var(--soft); border-radius: 999px; letter-spacing: .5px;
}
.sec h5::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.sec.key, .sec.warn { margin: 12px -6px; padding: 8px 12px 4px; border-radius: 10px; border-left: 3px solid var(--key-line); background: var(--key-bg); }
.sec.key h5 { background: none; padding-left: 0; }
.sec.warn { border-left-color: var(--warn-line); background: var(--warn-bg); }
.sec.warn h5 { background: none; padding-left: 0; color: var(--warn-line); }
.sec > p:first-of-type { margin-top: 6px; }

/* 代码块 */
.code { margin: 10px 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--code); }
.codebar { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 12px; background: var(--codebar); font-size: 12px; color: var(--muted); letter-spacing: .5px; }
.codebar button { font-size: 12px; padding: 2px 10px; border-radius: 6px; color: var(--muted); }
.codebar button:hover { background: var(--panel); color: var(--accent); }
.code pre { margin: 0; padding: 10px 12px; overflow-x: auto; }
.code pre code { background: none; padding: 0; white-space: pre; }

.tablewrap { overflow-x: auto; margin: 10px 0; border: 1px solid var(--line); border-radius: 10px; }
.bubble table { border-collapse: collapse; width: 100%; font-size: 15px; }
.bubble th { background: var(--code); font-weight: 650; }
.bubble th, .bubble td { padding: 7px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.bubble tr:last-child td { border-bottom: 0; }

/* 等待、出错、提示 */
.waiting { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 10px 0; font-size: 15px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .45; } 40% { transform: scale(1); opacity: 1; } }
.error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 15px; }
.sysline { text-align: center; color: var(--muted); font-size: 13px; margin: 6px auto 18px; }

.tools { display: flex; gap: 4px; margin: 6px 0 0 4px; }
.tools button {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px; border-radius: 8px;
  font-size: 13px; color: var(--muted); transition: background .15s, color .15s;
}
.tools button:hover { background: var(--soft); color: var(--accent); }
.tools button.on { color: var(--accent); background: var(--soft); }
.tools button.on.down { color: var(--danger); background: var(--danger-soft); }

#tobottom {
  position: fixed; left: 50%; bottom: 118px; transform: translateX(-50%); width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow); color: var(--muted);
}

/* ---------- 输入区 ---------- */
footer { padding: 6px 16px calc(10px + env(safe-area-inset-bottom)); }
#form {
  display: flex; gap: 8px; align-items: flex-end; max-width: 860px; margin: 0 auto; padding: 8px 8px 8px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
#form:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow), var(--shadow); }
#input { flex: 1; resize: none; max-height: 40vh; overflow-y: hidden; border: 0; outline: 0; background: none; color: var(--text); font: inherit; padding: 6px 0; }
#input::placeholder { color: var(--muted); opacity: .8; }
#send {
  width: 38px; height: 38px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); transition: transform .15s, opacity .15s;
}
#send:hover { transform: translateY(-1px); }
#send:disabled { opacity: .45; cursor: default; transform: none; }
.note { max-width: 860px; margin: 8px auto 0; font-size: 12px; color: var(--muted); text-align: center; }
.msgline { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--danger); text-align: center; }
/* 备案号（配置里填了才有） */
.beian { margin: 4px auto 0; font-size: 11px; text-align: center; }
.beian a { margin: 0 6px; color: var(--muted); text-decoration: none; }
.beian a:hover { text-decoration: underline; }
body.login .beian { position: fixed; left: 0; right: 0; bottom: calc(10px + env(safe-area-inset-bottom)); margin: 0; }

/* ---------- 历史对话抽屉 ---------- */
#history { position: fixed; inset: 0; background: rgba(15, 20, 30, .4); display: flex; justify-content: flex-end; }
#history aside {
  width: 100%; max-width: 400px; height: 100%; display: flex; flex-direction: column; background: var(--panel);
  border-left: 1px solid var(--line); box-shadow: var(--shadow); animation: slidein .2s ease-out;
}
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.hishead { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 12px 18px; border-bottom: 1px solid var(--line); }
.hishead h2 { margin: 0; font-size: 17px; font-weight: 650; }
.hishead .ghost { width: 34px; padding: 0; justify-content: center; }
#hislist { flex: 1; overflow-y: auto; padding: 10px; }
#hislist button {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px;
  transition: background .15s;
}
#hislist button:hover { background: var(--soft); }
.histitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hismeta { font-size: 12px; color: var(--muted); }
#history .note { margin: 0; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }

/* ---------- 弹窗：姓名、口令 ---------- */
#who { position: fixed; inset: 0; background: rgba(15, 20, 30, .5); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; }
body.login { align-items: center; justify-content: center; padding: 16px; }
#whoform, #login {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px 22px; box-shadow: var(--shadow);
  animation: rise .25s ease-out;
}
#whoform h2, #login h2 { margin: 4px 0 0; font-size: 20px; font-weight: 650; }
#whoform .note, #login .note { margin: 0; font-size: 13px; }
#whoform input, #login input {
  width: 100%; font: inherit; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text);
}
#whoform input:focus, #login input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
#whoform button, #login button {
  width: 100%; padding: 11px; border-radius: 12px; color: #fff; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}

@media (max-width: 640px) {
  header { padding: 8px 12px; }
  #newchat span, #hisbtn span { display: none; }
  #newchat, #hisbtn { width: 34px; padding: 0; justify-content: center; }
  .chip { max-width: 30vw; }
  #history aside { max-width: none; }
  main { padding: 16px 12px 4px; }
  #examples { grid-template-columns: 1fr; gap: 10px; }
  #welcome { padding-top: 3vh; }
  #welcome h2 { font-size: 21px; }
  .avatar { width: 26px; height: 26px; border-radius: 8px; }
  .msg { gap: 8px; }
  .msg.bot .bubble { padding: 4px 12px; }
  .msg.user .bubble { max-width: 90%; }
  footer { padding-left: 10px; padding-right: 10px; }
  .note { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  main { scroll-behavior: auto; }
}
