/* ============================================================
   CodeMentor · 编程学习助手
   视觉方向：浅色「程序员工作台」 + 深色代码编辑器卡片
   强调色：琥珀橙  代码字体：JetBrains Mono  标题：Space Grotesk
   ============================================================ */

/* ---------- 本地字体 ---------- */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../assets/fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../assets/fonts/jetbrains-mono-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/jetbrains-mono-latin-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../assets/fonts/space-grotesk-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../assets/fonts/space-grotesk-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/space-grotesk-latin-700-normal.woff2') format('woff2');
}

/* ---------- 设计变量 ---------- */
:root {
  --bg: #f3f5f8;
  --bg-grid: rgba(22, 32, 46, 0.025);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f4f8;

  --ink: #151f2b;
  --ink-2: #3a4757;
  --muted: #6b7787;
  --faint: #97a2b1;

  --line: #e2e8f0;
  --line-2: #eceff4;

  --amber: #e07416;
  --amber-strong: #c25f0a;
  --amber-soft: #fdf0e3;
  --amber-ink: #9a4a0c;

  --teal: #0d9488;
  --teal-soft: #e6f5f3;
  --green: #1a7f4e;
  --red: #d23b3b;
  --red-soft: #fdecec;

  --code-bg: #0c131b;
  --code-bg-2: #111b26;
  --code-line: #1d2835;
  --code-ink: #dbe3ee;
  --code-muted: #8593a5;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 45, 0.05), 0 6px 20px -10px rgba(20, 30, 45, 0.12);
  --shadow-lg: 0 12px 48px -12px rgba(15, 23, 35, 0.28);

  --font-ui: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas,
    'Liberation Mono', monospace;
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 28px 28px;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
::selection { background: var(--amber-soft); color: var(--amber-ink); }

/* 焦点可见 */
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- 顶部导航 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  height: 62px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  flex-shrink: 0;
}
.brand-mark svg { color: var(--amber); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; color: var(--muted); font-family: var(--font-ui); }

.lang-switch {
  display: flex;
  gap: 4px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
}
.lang-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  font-family: var(--font-mono);
  padding: 7px 18px;
  border-radius: 7px;
  transition: all 0.15s ease;
}
.lang-btn:hover { color: var(--ink); }
.lang-btn.active {
  background: var(--surface);
  color: var(--amber-strong);
  box-shadow: 0 1px 3px rgba(20, 30, 45, 0.12);
}

.top-actions { display: flex; gap: 8px; }
.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.ghost-btn:hover { border-color: var(--amber); color: var(--amber-strong); background: var(--amber-soft); }

/* ---------- 模式切换 ---------- */
.mode-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 22px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 18px;
  font-size: 14.5px;
  font-weight: 600;
  border-radius: 10px 10px 0 0;
  position: relative;
  transition: all 0.15s ease;
}
.mode-btn svg { opacity: 0.8; }
.mode-btn:hover { color: var(--ink); }
.mode-btn.active {
  color: var(--amber-strong);
  background: var(--bg);
  border-color: var(--line);
}
.mode-btn.active::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--bg);
}

/* ---------- 对话区 ---------- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.messages {
  max-width: 880px;
  margin: 0 auto;
  padding: 28px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* 欢迎页 */
.welcome {
  text-align: center;
  padding: 46px 12px 10px;
}
.welcome-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--amber);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}
.welcome h1 {
  font-size: 27px;
  font-weight: 700;
  margin: 0 0 10px;
  letter-spacing: 0.2px;
}
.welcome h1 .lang-name { color: var(--amber-strong); font-family: var(--font-mono); }
.welcome p { color: var(--muted); margin: 0 auto 26px; max-width: 560px; font-size: 15px; }
.welcome-feats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 0 auto 28px;
  max-width: 680px;
}
.feat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 14px;
  text-align: left;
}
.feat-ico {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--amber-soft);
  color: var(--amber-strong);
  display: grid;
  place-items: center;
  margin-bottom: 9px;
}
.feat-card h4 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.feat-card p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.welcome-lbl { font-size: 12.5px; color: var(--faint); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 1px; }
.example-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 680px; margin: 0 auto; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 13px;
  transition: all 0.14s ease;
}
.chip:hover { border-color: var(--amber); color: var(--amber-strong); background: var(--amber-soft); }

/* 消息行 */
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg-avatar {
  width: 34px; height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}
.msg-user .msg-avatar { background: var(--amber); color: #fff; }
.msg-ai .msg-avatar { background: var(--ink); color: var(--amber); }
.msg-body { flex: 1; min-width: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.msg-name { font-size: 13.5px; font-weight: 600; }
.msg-time { font-size: 11.5px; color: var(--faint); }

.msg-bubble {
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--line);
}
.msg-user .msg-bubble {
  background: var(--amber-soft);
  border-color: #f3d9bf;
  color: var(--ink);
}
.msg-ai .msg-bubble {
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* 用户代码预览 */
.msg-code-preview {
  margin-top: 10px;
  background: var(--code-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--code-line);
}
.msg-code-preview .cp-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--code-bg-2);
  border-bottom: 1px solid var(--code-line);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--code-muted);
}
.msg-code-preview pre {
  margin: 0;
  padding: 12px 14px;
  max-height: 260px;
  overflow: auto;
}
.msg-code-preview code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--code-ink);
  white-space: pre;
}
.msg-question {
  margin-top: 8px;
  font-size: 14px;
  padding-top: 8px;
  border-top: 1px dashed #ecc79f;
}
.msg-question .q-lbl { color: var(--amber-ink); font-weight: 600; margin-right: 6px; }

/* Markdown 内容 */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 {
  font-weight: 600;
  line-height: 1.35;
  margin: 20px 0 9px;
}
.md h1 { font-size: 20px; }
.md h2 { font-size: 17.5px; }
.md h3 { font-size: 15.5px; }
.md h4 { font-size: 14.5px; }
.md p { margin: 9px 0; }
.md ul, .md ol { margin: 9px 0; padding-left: 22px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--amber); }
.md strong { color: var(--ink); font-weight: 600; }
.md blockquote {
  margin: 12px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--amber);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  color: var(--ink-2);
}
.md a { color: var(--amber-strong); text-decoration: underline; text-underline-offset: 2px; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.md table { border-collapse: collapse; margin: 12px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 12px; text-align: left; }
.md th { background: var(--surface-3); font-weight: 600; }

/* 行内代码 */
.md :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface-3);
  color: var(--amber-ink);
  border: 1px solid var(--line-2);
  border-radius: 5px;
  padding: 0.12em 0.42em;
  word-break: break-word;
}

/* 代码块（编辑器卡片） */
.code-block {
  margin: 13px 0;
  background: var(--code-bg);
  border: 1px solid var(--code-line);
  border-radius: var(--radius);
  overflow: hidden;
}
.code-block-head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 10px 0 13px;
  background: var(--code-bg-2);
  border-bottom: 1px solid var(--code-line);
}
.cb-dots { display: flex; gap: 5px; flex-shrink: 0; }
.cb-dots i { width: 9px; height: 9px; border-radius: 50%; display: block; }
.cb-dots i:nth-child(1) { background: #ff5f57; }
.cb-dots i:nth-child(2) { background: #febc2e; }
.cb-dots i:nth-child(3) { background: #28c840; }
.cb-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--code-ink);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cb-file svg { color: var(--code-muted); flex-shrink: 0; }
.cb-lang {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--amber);
  background: rgba(224, 116, 22, 0.14);
  border: 1px solid rgba(224, 116, 22, 0.28);
  padding: 1px 7px;
  border-radius: 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  flex-shrink: 0;
}
.cb-actions { margin-left: auto; display: flex; gap: 4px; flex-shrink: 0; }
.cb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--code-muted);
  font-size: 11.5px;
  padding: 5px 8px;
  border-radius: 6px;
  transition: all 0.13s ease;
}
.cb-btn:hover { color: var(--code-ink); background: var(--code-line); }
.code-block-body { margin: 0; overflow-x: auto; }
.code-block-body pre { margin: 0; padding: 14px 16px; }
.code-block-body code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  color: var(--code-ink);
  background: transparent;
  padding: 0;
  border: none;
  white-space: pre;
}

/* highlight.js 配色（GitHub Dark 风格） */
.hljs-comment, .hljs-quote { color: #8b949e; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-tag { color: #ff7b72; }
.hljs-string, .hljs-regexp, .hljs-addition { color: #a5d6ff; }
.hljs-number, .hljs-literal, .hljs-built_in { color: #79c0ff; }
.hljs-title, .hljs-title.function_, .hljs-section { color: #d2a8ff; }
.hljs-title.class_, .hljs-type, .hljs-class .hljs-title { color: #ffa657; }
.hljs-name, .hljs-selector-id, .hljs-selector-class, .hljs-attr, .hljs-attribute { color: #7ee787; }
.hljs-variable, .hljs-template-variable, .hljs-symbol { color: #ffa657; }
.hljs-meta, .hljs-deletion { color: #8b949e; }
.hljs-bullet, .hljs-link { color: #79c0ff; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* AI 消息底部操作 */
.msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--line-2);
}
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.14s ease;
}
.action-btn:hover { border-color: var(--amber); color: var(--amber-strong); }
.action-btn.primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}
.action-btn.primary:hover { background: var(--amber-strong); border-color: var(--amber-strong); color: #fff; }

/* 流式光标 */
.stream-cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--amber);
  vertical-align: text-bottom;
  margin-left: 2px;
  border-radius: 1px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
.msg-error {
  margin-top: 10px;
  background: var(--red-soft);
  border: 1px solid #f3c5c5;
  color: #a32626;
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 13px;
}
.msg-error .err-title { font-weight: 600; display: block; margin-bottom: 3px; }
.typing-dots { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: bounce 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---------- 输入区 ---------- */
.composer {
  flex-shrink: 0;
  padding: 14px 22px 18px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer-inner {
  max-width: 880px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  transition: border-color 0.15s ease;
}
.composer-inner:focus-within { border-color: var(--amber); }

.file-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 9px; }
.file-chips:empty { display: none; }
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--ink);
  color: #e8edf4;
  border-radius: 7px;
  padding: 5px 9px 5px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.file-chip svg { color: var(--amber); }
.file-chip button {
  border: none;
  background: transparent;
  color: var(--code-muted);
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 4px;
  line-height: 0;
}
.file-chip button:hover { color: #fff; }

.main-input-wrap { position: relative; }
.main-input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--ink);
  resize: none;
  line-height: 1.6;
  min-height: 78px;
  max-height: 260px;
}
.main-input.code-font {
  font-family: var(--font-mono);
  font-size: 13px;
  tab-size: 4;
}
.main-input:focus { outline: none; border-color: var(--amber); background: var(--surface); }

.question-row {
  display: none;
  align-items: center;
  gap: 9px;
  margin-top: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: var(--surface-2);
}
.question-row svg { color: var(--faint); flex-shrink: 0; }
.question-row input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 0;
  font-size: 13.5px;
  color: var(--ink);
}
.question-row input:focus { outline: none; }
body.mode-explain .question-row { display: flex; }

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 11px;
}
.composer-left { display: flex; align-items: center; gap: 10px; }
.composer-tip { font-size: 11.5px; color: var(--faint); }
.composer-right { display: flex; gap: 8px; }
.send-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: var(--amber);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 9px 20px;
  border-radius: 9px;
  transition: all 0.15s ease;
}
.send-btn:hover { background: var(--amber-strong); }
.send-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.stop-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--red);
  background: var(--red-soft);
  color: var(--red);
  font-weight: 600;
  font-size: 14px;
  padding: 9px 18px;
  border-radius: 9px;
}
.stop-dot { width: 9px; height: 9px; background: var(--red); border-radius: 50%; }
.stop-btn:hover { background: var(--red); color: #fff; }
.stop-btn:hover .stop-dot { background: #fff; }

/* ---------- 抽屉 ---------- */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 360px;
  max-width: 88vw;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.drawer-head-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: 7px;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.text-btn { border: none; background: transparent; color: var(--amber-strong); font-size: 13px; font-weight: 500; padding: 6px 8px; border-radius: 6px; }
.text-btn:hover { background: var(--amber-soft); }
.drawer-body { flex: 1; overflow-y: auto; padding: 10px; }
.drawer-empty { text-align: center; color: var(--faint); font-size: 13.5px; padding: 46px 20px; }
.history-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 11px 12px;
  margin-bottom: 8px;
  transition: all 0.13s ease;
}
.history-item:hover { border-color: var(--amber); background: var(--amber-soft); }
.hi-top { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.hi-mode { font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 4px; }
.hi-mode.explain { background: var(--teal-soft); color: var(--teal); }
.hi-mode.generate { background: var(--amber-soft); color: var(--amber-ink); }
.hi-lang { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }
.hi-title { font-size: 13.5px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hi-time { font-size: 11px; color: var(--faint); margin-top: 3px; }

/* ---------- 模态 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 35, 0.45);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--surface);
  border-radius: 14px;
  width: 560px;
  max-width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: pop 0.18s ease;
}
@keyframes pop { from { transform: scale(0.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 15px 20px;
  border-top: 1px solid var(--line);
}
.field { margin-bottom: 15px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
.field input[type=text], .field input[type=password], .field input[type=number], .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface-2);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--amber); background: var(--surface); }
.field-hint { display: block; font-size: 11.5px; color: var(--faint); margin-top: 5px; line-height: 1.5; }
.input-with-action { display: flex; gap: 8px; }
.input-with-action input { flex: 1; }
.field-check { margin-top: 4px; }
.check-label { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.check-label input { margin-top: 3px; accent-color: var(--amber); }
.test-result { margin-top: 6px; font-size: 13px; border-radius: var(--radius-sm); padding: 0; max-height: 0; overflow: hidden; transition: all 0.2s ease; }
.test-result.show { padding: 10px 13px; margin-top: 8px; }
.test-result.ok { background: var(--teal-soft); color: var(--teal); }
.test-result.fail { background: var(--red-soft); color: #a32626; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  padding: 11px 20px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  .topbar { padding: 0 13px; height: 56px; }
  .brand-sub { display: none; }
  .ghost-btn span { display: none; }
  .ghost-btn { padding: 8px; }
  .lang-btn { padding: 7px 12px; }
  .mode-tabs { padding: 10px 13px 0; }
  .mode-btn { padding: 10px 12px; font-size: 13.5px; }
  .mode-btn span { display: none; }
  .messages { padding: 18px 13px; }
  .composer { padding: 10px 13px 14px; }
  .welcome-feats { grid-template-columns: 1fr; }
  .composer-tip { display: none; }
  .send-btn { padding: 9px 15px; }
  .field-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
