:root {
  --bg: #0f1117;
  --bg-elev: #171a23;
  --bg-soft: #1e222e;
  --border: #2a2f3c;
  --text: #e7e9ee;
  --text-dim: #9aa1b1;
  --accent: #c9a86a;
  --accent-soft: #c9a86a22;
  --user-bubble: #2563eb;
  --user-bubble-text: #ffffff;
  --danger: #ef4444;
  --radius: 16px;
  --maxw: 820px;
  font-synthesis: none;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f7f8;
    --bg-elev: #ffffff;
    --bg-soft: #f0f1f4;
    --border: #e3e5ea;
    --text: #1f2330;
    --text-dim: #6b7180;
    --accent: #9a7b3f;
    --accent-soft: #9a7b3f1a;
    --user-bubble: #2563eb;
    --user-bubble-text: #ffffff;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 100%;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elev) 85%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  font-size: 26px;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 12px;
}
.brand-text .title { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.brand-text .subtitle { font-size: 12px; color: var(--text-dim); }
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: all .15s ease;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- 聊天区 ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.messages, .welcome { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* 欢迎屏 */
.welcome {
  text-align: center;
  padding-top: 8vh;
  padding-bottom: 40px;
}
.welcome-logo {
  font-size: 56px;
  color: var(--accent);
  margin-bottom: 12px;
}
.welcome h1 { font-size: 24px; margin: 0 0 12px; font-weight: 700; }
.welcome-desc { color: var(--text-dim); max-width: 560px; margin: 0 auto 28px; }
.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 620px;
  margin: 0 auto;
}
.chip {
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.5;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--accent); background: var(--bg-soft); }

/* 消息 */
.messages { padding-top: 20px; padding-bottom: 24px; }
.msg { display: flex; gap: 14px; margin-bottom: 22px; }
.msg .avatar {
  flex: 0 0 34px;
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 17px;
}
.msg.user .avatar { background: var(--user-bubble); color: #fff; }
.msg.assistant .avatar { background: var(--accent-soft); color: var(--accent); }
.msg .bubble { min-width: 0; flex: 1; padding-top: 4px; }
.msg.user .bubble { color: var(--text); }

/* Markdown 内容样式 */
.bubble p { margin: 0 0 12px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 18px 0 10px; line-height: 1.4; }
.bubble h1 { font-size: 20px; }
.bubble h2 { font-size: 18px; }
.bubble h3 { font-size: 16px; }
.bubble ul, .bubble ol { margin: 0 0 12px; padding-left: 22px; }
.bubble li { margin: 4px 0; }
.bubble strong { color: var(--text); font-weight: 700; }
.bubble code {
  background: var(--bg-soft);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}
.bubble pre {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  overflow-x: auto;
  margin: 0 0 12px;
}
.bubble pre code { background: none; padding: 0; }
.bubble blockquote {
  border-left: 3px solid var(--accent);
  margin: 0 0 12px;
  padding: 2px 0 2px 14px;
  color: var(--text-dim);
}
.bubble table { border-collapse: collapse; width: 100%; margin: 0 0 12px; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.bubble th { background: var(--bg-soft); }

/* 光标闪烁（流式中） */
.cursor-blink::after {
  content: "▋";
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
  margin-left: 2px;
}
@keyframes blink { to { visibility: hidden; } }

.error-text { color: var(--danger); }

/* ---------- 输入区 ---------- */
.composer {
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 12px 16px calc(10px + env(safe-area-inset-bottom));
}
.composer-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 16px;
  transition: border-color .15s ease;
}
.composer-inner:focus-within { border-color: var(--accent); }
.input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.6;
  max-height: 200px;
  padding: 6px 0;
}
.input::placeholder { color: var(--text-dim); }
.send-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: none;
  border-radius: 11px;
  background: var(--accent);
  color: #1a1407;
  display: grid; place-items: center;
  cursor: pointer;
  transition: opacity .15s ease, transform .1s ease;
}
.send-btn:hover { opacity: .9; }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.composer-hint {
  max-width: var(--maxw);
  margin: 8px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
}

@media (max-width: 600px) {
  .suggestions { grid-template-columns: 1fr; }
  .welcome { padding-top: 6vh; }
  .welcome h1 { font-size: 20px; }
}
