:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1a1a19;
  --muted: #6b6b66;
  --line: #e7e6e2;
  --accent: #2f6f4e;
  --accent-ink: #ffffff;
  --user-bg: #1f2a25;
  --user-ink: #f2f5f3;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 600;
  flex: none;
}

.brand-text h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.sub {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  flex: none;
}

.ghost:hover {
  border-color: #d5d4cf;
  color: var(--ink);
}

/* ---------- 消息区 ---------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.row {
  display: flex;
  gap: 10px;
  max-width: 100%;
}

.row.user {
  justify-content: flex-end;
}

.bubble {
  padding: 11px 14px;
  border-radius: var(--radius);
  max-width: 82%;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.row.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.row.user .bubble {
  background: var(--user-bg);
  color: var(--user-ink);
  border-bottom-right-radius: 4px;
}

.bubble code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 13px;
}

.row.user .bubble code {
  background: rgba(255, 255, 255, 0.16);
}

.note {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin: 0;
}

/* 正在输入 */
.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 20px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #b6b5ae;
  animation: blink 1.2s infinite;
}

.typing i:nth-child(2) {
  animation-delay: 0.2s;
}
.typing i:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* ---------- 输入区 ---------- */

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}

#input {
  flex: 1;
  resize: none;
  overflow-y: auto;
  scrollbar-width: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  line-height: 1.5;
  max-height: 140px;
  background: #fbfbf9;
  color: inherit;
}

#input::-webkit-scrollbar {
  display: none;
}

#input:focus {
  outline: 2px solid rgba(47, 111, 78, 0.25);
  border-color: var(--accent);
  background: #fff;
}

.send {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 12px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  flex: none;
}

.send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status {
  margin: 0;
  padding: 0 18px 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
}

@media (max-width: 520px) {
  .bubble {
    max-width: 88%;
  }
  .messages {
    padding: 16px 12px 6px;
  }
  .composer {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  }
}
