:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #6b7686;
  --line: #e6eaf0;
  --brand: #4f6ef7;
  --brand-soft: #eef1fe;
  --user: #e8f0ff;
  --coach: #ffffff;
  --good: #1f9d55;
  --good-soft: #e7f6ee;
  --bad: #d9434e;
  --bad-soft: #fdecee;
  --shadow: 0 6px 24px rgba(31, 39, 51, 0.08);
  --radius: 16px;
}

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

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

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo, .welcome-avatar {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, #4f6ef7, #7b5cf0);
  color: #fff; font-weight: 700; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.brand-text h1 { font-size: 18px; margin: 0; font-weight: 700; }
.brand-text .sub { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.mode-badge {
  display: inline-block; margin-top: 3px;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.mode-badge.real { background: var(--good-soft); color: var(--good); }

.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: .15s;
}
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); }

/* 聊天区 */
.chat {
  flex: 1; overflow-y: auto; padding: 20px 16px 8px;
  display: flex; flex-direction: column; gap: 16px;
}
.welcome {
  text-align: center; padding: 28px 20px; color: var(--muted);
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  margin: auto 0;
}
.welcome-avatar { margin: 0 auto 12px; width: 56px; height: 56px; font-size: 28px; border-radius: 16px; }
.welcome h2 { color: var(--ink); margin: 4px 0 10px; font-size: 20px; }
.welcome p { margin: 6px 0; font-size: 14px; line-height: 1.6; }
.welcome-hint { font-size: 12px; opacity: .8; }

.msg { display: flex; gap: 10px; max-width: 100%; }
.msg .ava {
  flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
  background: linear-gradient(135deg, #4f6ef7, #7b5cf0);
}
.msg.user { flex-direction: row-reverse; }
.msg.user .ava { background: #2b3340; }
.bubble {
  max-width: 78%; padding: 11px 14px; border-radius: 14px; font-size: 15px;
  line-height: 1.55; box-shadow: var(--shadow); word-break: break-word;
}
.msg.coach .bubble { background: var(--coach); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg.user .bubble { background: var(--user); border-top-right-radius: 4px; }

.bubble .speak {
  margin-top: 8px; font-size: 12px; color: var(--brand); cursor: pointer;
  border: none; background: none; padding: 0; font-weight: 600;
}
.bubble .speak:hover { text-decoration: underline; }

/* 纠错卡片 */
.corrections {
  max-width: 78%; margin: -6px 0 0 44px;
}
.msg.user + .corrections { margin-right: 0; }
.correction-card {
  background: #fffdf6; border: 1px solid #f3e6c4; border-radius: 12px;
  padding: 10px 12px; margin-top: 8px; font-size: 13px; box-shadow: var(--shadow);
}
.correction-card .natural {
  font-size: 12px; color: var(--muted); margin-bottom: 6px;
}
.correction-card .natural b { color: var(--good); }
.fix-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 3px 0; }
.fix-old { color: var(--bad); text-decoration: line-through; }
.fix-arrow { color: var(--muted); }
.fix-new { color: var(--good); font-weight: 600; }
.fix-exp { color: var(--ink); margin-top: 4px; line-height: 1.5; }
.fix-exp::before { content: "讲解："; color: var(--muted); font-weight: 600; }

/* 输入区 */
.composer { padding: 12px 16px 18px; background: var(--panel); border-top: 1px solid var(--line); }
.live-text {
  min-height: 18px; font-size: 13px; color: var(--brand); padding: 0 4px 6px;
  font-style: italic;
}
.composer-row { display: flex; align-items: center; gap: 10px; }
.mic-btn {
  flex: 0 0 auto; display: flex; align-items: center; gap: 6px;
  padding: 10px 14px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 14px;
  transition: .15s;
}
.mic-btn:hover { filter: brightness(1.05); }
.mic-btn.listening { background: var(--bad); animation: pulse 1.2s infinite; }
.mic-btn:disabled { background: #c4cad6; cursor: not-allowed; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .65; } }
.mic-icon { font-size: 16px; }

#textInput {
  flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  font-size: 15px; outline: none; background: #fbfcfe; color: var(--ink);
}
#textInput:focus { border-color: var(--brand); background: #fff; }
.send-btn {
  flex: 0 0 auto; padding: 12px 20px; border-radius: 12px; border: none; cursor: pointer;
  background: #2b3340; color: #fff; font-weight: 600; font-size: 14px;
}
.send-btn:hover { background: #1f2733; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 26, 36, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-mask[hidden] { display: none; }
.modal {
  width: 100%; max-width: 460px; background: var(--panel); border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25); max-height: 88vh; overflow: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 18px 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input[type=text], .field input[type=password], .field select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  font-size: 14px; outline: none; background: #fbfcfe;
}
.field input:focus, .field select:focus { border-color: var(--brand); background: #fff; }
.field input[type=range] { width: 100%; }
.mode-note { font-size: 12px; color: var(--muted); line-height: 1.5; background: var(--brand-soft); padding: 8px 10px; border-radius: 8px; }
hr { border: none; border-top: 1px solid var(--line); margin: 6px 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.btn-ghost, .btn-primary {
  padding: 10px 18px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid var(--line);
}
.btn-ghost { background: #fff; color: var(--muted); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { filter: brightness(1.05); }
.save-hint { font-size: 12px; color: var(--good); min-height: 16px; margin: 8px 0 0; }
.help-body ul { padding-left: 18px; margin: 6px 0 14px; }
.help-body li { font-size: 14px; line-height: 1.7; color: var(--ink); }
.help-body p { font-size: 14px; line-height: 1.6; margin: 10px 0 4px; }
.help-body .muted { color: var(--muted); font-size: 12px; }

/* 设置项提示 */
.field-hint { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 6px; }
.field-hint.warn { color: #b06a00; background: #fff6e6; padding: 6px 8px; border-radius: 8px; }
.field-inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-inline label { margin-bottom: 0; }
.field-inline input[type=checkbox] { width: 20px; height: 20px; }

/* 思考中动画 */
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; } 40% { opacity: 1; } }

/* 轻提示 toast */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: rgba(31,39,51,.92); color: #fff; font-size: 13px; padding: 10px 16px;
  border-radius: 999px; z-index: 80; opacity: 0; transition: .3s; max-width: 86%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 滚动条 */
.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb { background: #d4dae4; border-radius: 8px; }
