:root {
  --bg: #f4f2ee;
  --bg-top: linear-gradient(135deg, #2f3a56 0%, #4a5a7a 55%, #c98a5b 130%);
  --bubble-user: linear-gradient(135deg, #3f4f74 0%, #5a6c96 100%);
  --bubble-assistant: #ffffff;
  --text-user: #ffffff;
  --text-assistant: #2b2f38;
  --accent: #c98a5b;
  --muted: #8a8f99;
  --line: #e7e4de;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text-assistant);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-top);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
  position: relative;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.bird { font-size: 26px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.3)); }
.brand-text h1 { margin: 0; font-size: 18px; letter-spacing: 1px; }
.brand-text p { margin: 2px 0 0; font-size: 11px; opacity: .85; }
.status {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.16);
  backdrop-filter: blur(4px);
}

/* ---------- 聊天区 ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.msg { display: flex; flex-direction: column; margin-bottom: 14px; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }
.msg .bubble {
  max-width: 86%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.65;
  word-break: break-word;
  white-space: normal;
}
.msg.user .bubble {
  background: var(--bubble-user);
  color: var(--text-user);
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: var(--bubble-assistant);
  color: var(--text-assistant);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* 引用来源徽章 */
.sources {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 86%;
}
.sources .src {
  padding: 2px 8px;
  border-radius: 999px;
  background: #efe9e0;
  color: #8a6a4b;
}

/* 打字指示 */
.typing { display: inline-flex; gap: 4px; padding: 6px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #b9bec7; display: inline-block;
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* 提示词 chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; max-width: 92%; }
.chip {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: #4a5a7a;
  cursor: pointer;
}
.chip:active { background: #eef1f7; }

/* ---------- 输入区 ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid var(--line);
  position: relative;
  z-index: 5;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 11px 16px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  background: #f7f6f3;
}
.composer textarea:focus { border-color: #b9c2d8; background: #fff; }
.composer button {
  flex: none;
  width: 42px; height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--bubble-user);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.composer button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Markdown 渲染 ---------- */
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 14px 0 6px; line-height: 1.35;
}
.bubble h1 { font-size: 18px; }
.bubble h2 { font-size: 16px; }
.bubble h3 { font-size: 15px; }
.bubble p { margin: 6px 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble li { margin: 3px 0; }
.bubble code {
  background: #f0efe9; padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}
.bubble pre {
  background: #2b2f38; color: #e8e8e8; padding: 10px 12px; border-radius: 8px;
  overflow-x: auto; font-size: 13px;
}
.bubble pre code { background: transparent; color: inherit; padding: 0; }
.bubble blockquote {
  margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--accent);
  color: #6b6f78; background: #faf7f2; border-radius: 0 6px 6px 0;
}
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 13px; max-width: 100%; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid #ddd8cf; padding: 5px 8px; text-align: left; }
.bubble th { background: #f1eee7; }
.bubble hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.bubble a { color: #4a6aa8; }

/* Wiki 链接徽章 */
.bubble .wikilink {
  display: inline-block;
  padding: 0 7px;
  margin: 0 1px;
  border-radius: 5px;
  background: #eef1f7;
  color: #4a5a7a;
  font-size: 13px;
  border: 1px solid #d9dfee;
}

@media (max-width: 480px) {
  .msg .bubble { max-width: 90%; }
}
