/* =========================================================
   English Reader · Base Layout & Components
   ========================================================= */
:root {
  --font-sans: "Inter", "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
  --font-serif: "Source Serif Pro", "Songti SC", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ---- 整体布局 ---- */
.app {
  display: grid;
  grid-template-columns: 200px 1fr 240px;
  grid-template-rows: 44px 1fr;
  height: 100vh;
  overflow: hidden;
}
.app.no-drawer { grid-template-columns: 200px 1fr; }
.app.no-sidebar { grid-template-columns: 1fr 240px; }
.app.full { grid-template-columns: 1fr; }

/* ---- 顶栏 ---- */
.titlebar {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.brand:hover { color: var(--accent); }
.brand svg { color: var(--accent); }
.brand svg.icon { width: 16px; height: 16px; }

.nav { display: flex; gap: 2px; margin-left: 16px; }
.nav a {
  padding: 5px 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
  cursor: pointer;
}
.nav a svg { width: 14px; height: 14px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

.titlebar .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--warning);
  font-size: 12px;
  font-weight: 500;
  padding: 3px 8px;
  background: var(--surface-2);
  border-radius: 12px;
}

.icon-btn {
  width: 28px; height: 28px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---- 侧边栏 ---- */
.sidebar {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  overflow-y: auto;
}
.sidebar-section { padding: 0 10px; margin-bottom: 14px; }
.sidebar-section h4 {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 6px;
  letter-spacing: 0.6px;
  font-weight: 600;
  padding: 0 8px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.sidebar-item svg { width: 14px; height: 14px; color: var(--text-3); flex-shrink: 0; }
.sidebar-item:hover { background: var(--surface); }
.sidebar-item:hover svg { color: var(--text-2); }
.sidebar-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.sidebar-item.active svg { color: var(--accent); }
.sidebar-item .count { margin-left: auto; color: var(--text-3); font-size: 11px; }
.sidebar-item .progress-bar { width: 100%; }

.progress-bar {
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  margin-top: 4px;
  overflow: hidden;
}
.progress-bar .fill { height: 100%; background: var(--accent); }

/* ---- 主区 ---- */
.main {
  padding: 28px 40px;
  overflow-y: auto;
  background: var(--bg);
  min-height: 0;
}
.app.full > .settings-wrap,
.app.full > .stats-wrap {
  min-height: 0;
  overflow-y: auto;
  background: var(--bg);
  width: 100%;
}
.main h1 { font-size: 20px; margin-bottom: 4px; font-weight: 600; letter-spacing: -0.01em; }
.main .meta { color: var(--text-3); font-size: 11px; margin-bottom: 20px; }
.main .meta span { color: var(--text-2); }

/* Reader: keep font / 中英 controls fixed while content scrolls */
.reader-sticky {
  position: sticky;
  top: -28px;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px 16px;
  margin: -28px -40px 16px;
  padding: 16px 40px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--bg) 55%, transparent);
}
.reader-sticky-info {
  min-width: 0;
  flex: 1 1 200px;
}
.reader-sticky h1 {
  font-size: 16px;
  margin: 0 0 2px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-sticky .meta {
  margin-bottom: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-controls {
  margin-bottom: 0;
  flex: 0 0 auto;
}
.reader-ctrl-hint {
  color: var(--text-3);
  font-size: 11px;
  margin-right: 4px;
}
@supports not (background: color-mix(in srgb, white 50%, transparent)) {
  .reader-sticky {
    background: var(--bg);
    box-shadow: none;
  }
}

/* ---- 工具栏 ---- */
.toolbar {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: fit-content;
  align-items: center;
}
.toolbar .divider { width: 1px; height: 16px; background: var(--border); margin: 0 3px; }

.kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 1.5px;
  border-radius: 3px;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-2);
}

/* ---- 通用按钮 ---- */
.btn {
  padding: 5px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.12s;
  cursor: pointer;
}
.btn svg { width: 12px; height: 12px; }
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }

/* ---- 抽屉 ---- */
.drawer {
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  padding: 14px 12px;
  overflow-y: auto;
}
.drawer h3 {
  font-size: 10px;
  margin-bottom: 8px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
  padding: 0 4px;
}
.word-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 12px;
}
.word-card .head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 2px; }
.word-card .w { font-weight: 600; font-size: 13px; }
.word-card .pos { color: var(--text-3); font-size: 10px; margin-left: 4px; }
.word-card .src { color: var(--text-3); font-size: 10px; }
.word-card .ctx { color: var(--text-2); font-size: 11px; font-style: italic; }
.word-card .meaning-text { color: var(--text); font-size: 12px; margin-top: 2px; }
.word-card .actions { margin-top: 4px; display: flex; gap: 2px; }
.word-card .icon-btn-mini {
  background: transparent;
  border: none;
  color: var(--text-3);
  padding: 2px;
  border-radius: 3px;
  display: inline-flex;
  cursor: pointer;
}
.word-card .icon-btn-mini svg { width: 12px; height: 12px; }
.word-card .icon-btn-mini:hover { background: var(--surface-2); color: var(--text); }

/* ---- 阅读器 ---- */
.reader { max-width: 720px; margin: 0 auto; }
.paragraph {
  margin-bottom: 18px;
  font-family: var(--font-serif);
  font-size: 1em;
  line-height: 1.85;
  color: var(--text);
  position: relative;
  padding-right: 36px;
}
.paragraph.tts-active {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 4px;
  background: var(--accent-soft);
}
.paragraph .en .word {
  cursor: pointer;
  border-radius: 2px;
  padding: 0 1px;
}
.paragraph .en .word:hover { background: var(--accent-soft); }
.paragraph .en .word.highlight { background: var(--highlight); }
.paragraph .en .word.selected { background: var(--accent); color: #fff; }
.paragraph .en .word.in-vocab {
  border-bottom: 1.5px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 2px;
}

.page-word-item {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.page-word-item:hover { background: var(--accent-soft); }
.page-word-item .pw-word {
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
}
.page-word-item .pw-gloss {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
  line-height: 1.4;
}
.paragraph .en .sentence { border-radius: 2px; }
.paragraph .zh {
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 0.82em;
  margin-top: 4px;
  padding: 6px 10px;
  background: var(--accent-soft);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  display: none;
  cursor: pointer;
}
.reader.show-all-zh .paragraph .zh,
.paragraph.show-line-zh .zh { display: block; }

/* Per-sentence translation peek */
.paragraph .line-zh-btn {
  position: absolute;
  top: 2px;
  right: 0;
  min-width: 28px;
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-3);
  font-size: 11px;
  font-family: var(--font-sans);
  line-height: 1;
  opacity: 0.55;
  transition: opacity 0.12s, color 0.12s, border-color 0.12s, background 0.12s;
}
.paragraph:hover .line-zh-btn,
.paragraph.show-line-zh .line-zh-btn {
  opacity: 1;
}
.paragraph .line-zh-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.paragraph.show-line-zh .line-zh-btn,
.reader.show-all-zh .paragraph .line-zh-btn {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
  opacity: 1;
}

/* ---- 词典弹窗 ---- */
.dict-popover {
  position: absolute;
  top: 320px; left: 560px;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 14px 16px;
  z-index: 100;
}
.dict-popover .word-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.dict-popover .word-head h2 { font-size: 18px; font-weight: 600; }
.dict-popover .phonetic { color: var(--text-3); font-family: var(--font-mono); font-size: 12px; }
.dict-popover .pos-tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
}
.dict-popover .meaning { margin-bottom: 8px; }
.dict-popover .meaning .zh { color: var(--text); font-weight: 500; font-size: 13px; }
.dict-popover .example { color: var(--text-3); font-size: 11px; font-style: italic; margin-top: 2px; line-height: 1.5; }
.dict-popover .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.dict-popover .tag { background: var(--surface-2); color: var(--text-2); padding: 2px 7px; border-radius: 8px; font-size: 10px; }
.dict-popover .actions { display: flex; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

/* ---- 复习中心 ---- */
.review { max-width: 640px; margin: 0 auto; padding: 32px 0; }
.review-locked-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 16px;
  margin: 0 auto 16px;
}
.review-locked-title { flex: 1; min-width: 180px; }
.review-locked-title h2 {
  font-size: 18px;
  margin: 0 0 4px;
  font-weight: 600;
}
.review-queue-hint {
  margin: 0 auto 12px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.5;
}
.practice-section {
  margin: 18px 0 8px;
  padding: 14px 14px 16px;
  border-radius: calc(var(--radius) + 2px);
  border: 1px solid var(--border);
}
.practice-section-word {
  background: var(--practice-word-bg);
}
.practice-section-ai {
  background: var(--practice-ai-bg);
  border-color: var(--practice-ai-border);
}
.practice-section-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.practice-section-title .hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-3);
}
.practice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.practice-card-ai {
  border-color: var(--practice-ai-card-border, var(--practice-ai));
  background: var(--practice-ai-card-bg, var(--practice-ai-soft));
}
.practice-card-word .badge-due {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--accent);
}
.review .stats-bar { display: flex; justify-content: space-around; margin-bottom: 20px; color: var(--text-3); font-size: 11px; }
.review .stats-bar .num { font-size: 18px; color: var(--text); font-weight: 600; }
.review .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  box-shadow: var(--shadow);
  text-align: center;
}
.review .card .word { font-size: 32px; font-weight: 600; margin-bottom: 6px; }
.review .card .phonetic { color: var(--text-3); font-family: var(--font-mono); font-size: 13px; margin-bottom: 24px; }
.review .card .question { color: var(--text-2); font-size: 12px; margin-bottom: 16px; }
.review .options { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.review .option {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.12s;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.review .option .key {
  width: 18px; height: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-3);
  font-weight: 600;
  font-family: var(--font-mono);
}
.review .option:hover { border-color: var(--accent); background: var(--accent-soft); }
.review .option.correct { border-color: var(--success); background: rgba(22,163,74,.08); }
.review .option.correct .key { border-color: var(--success); background: var(--success); color: #fff; }
.review .option.wrong { border-color: var(--danger); background: rgba(220,38,38,.08); }
.review .rating-bar { display: flex; gap: 6px; margin-top: 20px; justify-content: center; }
.review .rating-bar .btn { padding: 8px 14px; font-size: 12px; flex-direction: column; gap: 1px; min-width: 80px; }
.review .rating-bar .btn small { font-size: 10px; color: var(--text-3); font-weight: 400; }
.review .rating-bar .btn.easy { color: var(--success); border-color: rgba(22,163,74,.3); }
.review .rating-bar .btn.hard { color: var(--warning); border-color: rgba(234,138,31,.3); }
.review .rating-bar .btn.again { color: var(--danger); border-color: rgba(220,38,38,.3); }
.review .meta-row { margin-top: 14px; font-size: 10px; color: var(--text-3); text-align: center; }

/* ---- 设置 ---- */
.settings-wrap { max-width: 760px; margin: 0 auto; padding: 28px 40px; }
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 12px;
}
.settings-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.settings-section .section-desc { font-size: 11px; color: var(--text-3); margin-bottom: 12px; }
.form-row { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); gap: 16px; }
.form-row:last-child { border-bottom: none; }
.form-row .label { flex: 1; min-width: 0; }
.form-row .label .title { font-size: 12px; font-weight: 500; }
.form-row .label .hint { font-size: 10px; color: var(--text-3); margin-top: 1px; }
.form-row .control { flex-shrink: 1; min-width: 0; max-width: 100%; }
.form-row .control select {
  max-width: min(360px, 100%);
  box-sizing: border-box;
}
.form-row input[type="text"], .form-row input[type="password"] {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  width: 240px;
}
.form-row input:focus { outline: none; border-color: var(--accent); }
.switch { position: relative; display: inline-block; width: 32px; height: 18px; }
.switch input { display: none; }
.slider { position: absolute; cursor: pointer; inset: 0; background: var(--border-strong); border-radius: 18px; }
.slider::before { content: ""; position: absolute; width: 14px; height: 14px; left: 2px; bottom: 2px; background: #fff; border-radius: 50%; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(14px); }
.radio-group { display: flex; gap: 4px; }
.radio-group label { padding: 3px 10px; border: 1px solid var(--border); border-radius: 12px; font-size: 11px; cursor: pointer; color: var(--text-2); }
.radio-group label.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
select { padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 11px; font-family: inherit; }

/* ---- 统计 ---- */
.stats-wrap { max-width: 1100px; margin: 0 auto; padding: 28px 40px; }
.stats-overview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; }
.stat-card .label { font-size: 11px; color: var(--text-3); margin-bottom: 4px; display: flex; align-items: center; gap: 4px; }
.stat-card .label svg { width: 12px; height: 12px; }
.stat-card .num { font-size: 22px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.stat-card .delta { font-size: 10px; margin-top: 2px; color: var(--text-3); }
.stat-card .delta.up { color: var(--success); }
.card-block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 20px; margin-bottom: 12px; }
.card-block h3 { font-size: 13px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.card-block h3 svg { width: 14px; height: 14px; color: var(--text-3); }
.calendar .grid { display: grid; grid-template-columns: repeat(26, 1fr); gap: 2px; }
.calendar .day { aspect-ratio: 1; background: var(--surface-2); border-radius: 2px; }
.calendar .day.l1 { background: #c8d8f5; } .calendar .day.l2 { background: #82a7e8; }
.calendar .day.l3 { background: #4674d4; } .calendar .day.l4 { background: #1e4fc2; }
[data-theme="dark"] .calendar .day.l1 { background: #1e2c4a; }
[data-theme="dark"] .calendar .day.l2 { background: #2e4880; }
[data-theme="dark"] .calendar .day.l3 { background: #4674d4; }
[data-theme="dark"] .calendar .day.l4 { background: #82a7e8; }
.calendar .legend { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 10px; color: var(--text-3); }
.calendar .legend .scale { display: flex; gap: 2px; }
.calendar .legend .scale span { width: 10px; height: 10px; border-radius: 2px; background: var(--surface-2); }
.freq-bar { display: flex; align-items: center; margin-bottom: 6px; font-size: 11px; gap: 8px; }
.freq-bar .label { width: 64px; color: var(--text-2); }
.freq-bar .bar { flex: 1; height: 14px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.freq-bar .fill { height: 100%; background: var(--accent); }
.freq-bar .count { width: 50px; text-align: right; color: var(--text-3); font-family: var(--font-mono); }
.badges-grid { display: flex; gap: 6px; flex-wrap: wrap; }
.badge-card { background: var(--accent-soft); color: var(--accent); padding: 5px 10px; border-radius: 12px; font-size: 11px; display: inline-flex; align-items: center; gap: 4px; }
.badge-card svg { width: 11px; height: 11px; }
.badge-card.locked { opacity: 0.45; background: var(--surface-2); color: var(--text-3); }

/* ---- AI 练习（独立入口） ---- */
.ai-shell-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.ai-shell-head h1 { margin: 0 0 4px; }
.ai-chat-log {
  max-height: 360px;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
}
.ai-bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  animation: er-bubble-in 0.28s ease-out both;
}
.ai-bubble.bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.ai-bubble.user {
  align-self: flex-end;
  background: var(--accent-soft);
  color: var(--accent);
}
.ai-bubble strong {
  font-weight: 700;
  color: inherit;
}
.ai-bubble em {
  font-style: italic;
}

/* WeChat-style voice bubbles */
.ai-voice-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 85%;
  animation: er-bubble-in 0.28s ease-out both;
}
.ai-voice-wrap.bot { align-self: flex-start; align-items: flex-start; }
.ai-voice-wrap.user { align-self: flex-end; align-items: flex-end; }
.ai-voice-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  min-height: 40px;
  box-sizing: border-box;
}
.ai-voice-bubble.bot {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.ai-voice-bubble.user {
  background: var(--accent-soft);
  color: var(--accent);
  border-bottom-right-radius: 4px;
  flex-direction: row-reverse;
}
.ai-voice-bubble.playing .ai-voice-bars i {
  animation: er-dot-bounce 0.7s ease-in-out infinite;
}
.ai-voice-icon {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent currentColor;
  opacity: 0.85;
  flex-shrink: 0;
}
.ai-voice-bubble.user .ai-voice-icon {
  border-width: 6px 10px 6px 0;
  border-color: transparent currentColor transparent transparent;
}
.ai-voice-bars {
  display: inline-flex;
  gap: 3px;
  align-items: flex-end;
  height: 14px;
  flex: 1;
}
.ai-voice-bars i {
  width: 3px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.55;
  display: block;
}
.ai-voice-bars i:nth-child(1) { height: 6px; }
.ai-voice-bars i:nth-child(2) { height: 12px; }
.ai-voice-bars i:nth-child(3) { height: 8px; }
.ai-voice-dur {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
  flex-shrink: 0;
}
.ai-voice-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 0 2px;
}
.ai-voice-text {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-2);
  padding: 6px 8px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  max-width: 100%;
  white-space: pre-wrap;
}
.voice-hold-btn {
  width: 100%;
  max-width: 320px;
  height: 48px;
  font-size: 15px;
  touch-action: none;
}
.voice-hold-btn.recording {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
#aiPanel .card-block .section-desc { font-size: 11px; color: var(--text-3); }
#aiPanel .badge-card { margin: 0 4px 4px 0; }

/* ---- 等待 / 过渡 ---- */
@keyframes er-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes er-bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes er-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-4px); opacity: 1; }
}
@keyframes er-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.er-route-enter,
.er-panel-enter {
  animation: er-fade-up 0.32s ease-out both;
}
.er-wait {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  color: var(--text-2);
  font-size: 13px;
  animation: er-fade-up 0.25s ease-out both;
}
.er-wait-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.er-wait-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  display: block;
  animation: er-dot-bounce 1.1s ease-in-out infinite;
}
.er-wait-dots i:nth-child(2) { animation-delay: 0.15s; }
.er-wait-dots i:nth-child(3) { animation-delay: 0.3s; }
.er-wait-bar {
  height: 3px;
  border-radius: 2px;
  margin-top: 10px;
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--accent-soft) 40%,
    var(--accent) 50%,
    var(--accent-soft) 60%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: er-shimmer 1.4s linear infinite;
}
.ai-typing {
  align-self: flex-start;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  animation: er-fade-up 0.2s ease-out both;
}

/* ---- 翻译入口 & 独立翻译页（PC 优先，mobile.css 再收窄） ---- */
.translate-entry {
  position: relative;
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px !important;
  font-size: 12px;
  font-weight: 500;
  width: auto !important;
  min-width: 0;
}
.translate-entry svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.translate-entry-label { line-height: 1; }
.translate-entry-badge {
  position: absolute;
  top: -5px;
  right: -6px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
  pointer-events: none;
}

.translate-page {
  max-width: 880px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}
.translate-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.translate-page-titles { flex: 1; min-width: 0; }
.translate-page-head h1 {
  font-size: 22px;
  margin: 0 0 6px;
  font-weight: 600;
}
.translate-page-head .meta {
  font-size: 12px;
  color: var(--text-3);
  margin: 0;
  line-height: 1.5;
}
.translate-page-head #translateBackLib {
  flex-shrink: 0;
  margin-top: 2px;
}

.tq-section {
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px 14px;
}
.tq-section-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.tq-section-head h2 { font-size: 14px; font-weight: 600; margin: 0; }
.tq-count {
  font-size: 11px;
  color: var(--text-3);
  background: var(--surface-2);
  padding: 1px 8px;
  border-radius: 10px;
}
.tq-cards { display: flex; flex-direction: column; gap: 8px; }
.tq-card {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tq-card:hover { border-color: var(--border-strong); }
.tq-card-main { flex: 1; min-width: 0; }
.tq-line1 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  min-width: 0;
}
.tq-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.tq-pct {
  flex-shrink: 0;
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.tq-msg {
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tq-bar {
  margin-top: 8px;
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}
.tq-bar .fill { height: 100%; background: var(--accent); }
.tq-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  justify-content: flex-end;
}
.tq-act {
  font-size: 12px;
  padding: 5px 12px;
  min-width: 64px;
  min-height: 32px;
  white-space: nowrap;
}
.tq-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.tq-toggle { width: 100%; margin-top: 10px; min-height: 36px; }
.tq-history-tools {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 10px;
}
.tq-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
}
.tq-run { background: var(--accent-soft); color: var(--accent); }
.tq-wait { background: var(--surface-2); color: var(--text-2); }
.tq-pause { background: var(--warning-soft); color: var(--warning); }
.tq-cancel { background: var(--danger-soft); color: var(--danger); }
.tq-err { background: var(--danger-soft); color: var(--danger); }
.tq-done { background: var(--success-soft); color: var(--success); }

.book-card-add {
  border-style: dashed;
  border-color: var(--border-strong);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 100%;
  cursor: pointer;
}
.book-card-add:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.book-card-add.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.book-card-add .add-cover {
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  background: var(--surface-2);
}
.book-card-add:hover .add-cover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 70%, var(--surface-2));
}
.book-card-add .title { text-align: center; }
.book-card-add .author { text-align: center; }

.translate-queue-panel { display: none !important; }

/* ---- 书库首页 ---- */
.library-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.library-header .filters {
  display: flex; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}
.library-header .filter-chip {
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-2);
  border-radius: 3px;
  cursor: pointer;
  font-weight: 500;
}
.library-header .filter-chip.active { background: var(--accent-soft); color: var(--accent); }
.filter-chip {
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-2);
  border-radius: 3px;
  cursor: pointer;
  font-weight: 500;
  user-select: none;
}
.filter-chip:hover { color: var(--text); }
.filter-chip.active { background: var(--accent-soft); color: var(--accent); }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
}
.book-card:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.book-card .cover-art {
  height: 110px;
  background: linear-gradient(135deg, #2563eb 0%, #4f7fe0 100%);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.book-card .cover-art svg { width: 32px; height: 32px; opacity: 0.9; }
.book-card:nth-child(2) .cover-art { background: linear-gradient(135deg, #16a34a 0%, #5cba7a 100%); }
.book-card:nth-child(3) .cover-art { background: linear-gradient(135deg, #ea8a1f 0%, #f0a657 100%); }
.book-card:nth-child(4) .cover-art { background: linear-gradient(135deg, #7c3aed 0%, #a78bfa 100%); }
.book-card:nth-child(5) .cover-art { background: linear-gradient(135deg, #db2777 0%, #ec6ca5 100%); }
.book-card .body { padding: 10px 12px; }
.book-card .title { font-size: 13px; font-weight: 600; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-card .author { font-size: 11px; color: var(--text-3); margin-bottom: 8px; }
.book-card .stats { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-3); margin-bottom: 4px; }
.book-card .stats .pct { color: var(--accent); font-weight: 500; }
.book-card .stats .pct.done { color: var(--success); }
.book-card.locked { opacity: 0.92; }
.book-card.locked .cover-art { filter: grayscale(0.35); }
.book-card .card-actions .btn[disabled] { cursor: not-allowed; }
.book-card .progress-bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.book-card .progress-bar .fill { height: 100%; background: var(--accent); transition: width 0.3s; }


.drop-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 32px 20px;
  text-align: center;
  margin-top: 20px;
  background: var(--surface);
  transition: all 0.15s;
  cursor: pointer;
}
.drop-zone:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop-zone svg { width: 24px; height: 24px; color: var(--text-3); margin-bottom: 6px; }
.drop-zone .dz-title { font-size: 13px; color: var(--text); margin-bottom: 2px; font-weight: 500; }
.drop-zone .dz-hint { font-size: 11px; color: var(--text-3); }
