/* ============================================================
   Word-Weaver · 设计系统 (SaaS-grade, restrained)
   ============================================================ */

:root {
  /* 中性色板 */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e7e9ed;
  --border-strong: #d8dce1;

  /* 文本 */
  --text: #16181d;
  --text-soft: #5c6470;
  --text-faint: #8a9099;

  /* 主色（单一） */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0fe;
  --primary-tint: #e2e5fd;

  /* 状态辅助色（克制使用） */
  --success: #0f9d6b;
  --success-soft: #e7f6ef;
  --danger: #e5484d;
  --danger-soft: #fdeced;

  /* 高亮（复习词） */
  --hl: #fde68a;
  --hl-text: #7c5a00;

  /* 形状 / 阴影（统一、轻） */
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-hover: 0 4px 12px rgba(16, 24, 40, .08);

  --font-size: 16px;
  --content-w: 960px;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #161a20;
  --surface-2: #1c212a;
  --border: #272c34;
  --border-strong: #343b45;
  --text: #e8eaed;
  --text-soft: #9aa1ac;
  --text-faint: #6b7280;
  --primary: #818cf8;
  --primary-hover: #a5aef9;
  --primary-soft: #20243f;
  --primary-tint: #2a2f52;
  --success: #34d399;
  --success-soft: #11271f;
  --danger: #f87171;
  --danger-soft: #2a1718;
  --hl: #4a3f12;
  --hl-text: #fde9a8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 强制 hidden 生效，避免被 .modal 等 display 规则覆盖 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-size);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 线性图标统一尺寸 */
.ico { width: 18px; height: 18px; flex: 0 0 auto; vertical-align: middle; }
.btn .ico, .icon-btn .ico { width: 17px; height: 17px; }
.ico-sm { width: 15px; height: 15px; }

/* ===== 引导信息条（克制的提示卡片，非渐变招牌） ===== */
.guide-banner {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text-soft);
}
.guide-inner {
  max-width: var(--content-w); margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: flex-start; gap: 12px;
}
.guide-icon { color: var(--primary); flex: 0 0 auto; font-size: 16px; line-height: 1.5; }
.guide-text { flex: 1; font-size: 13.5px; line-height: 1.6; }
.guide-text b { color: var(--text); font-weight: 600; }
.guide-close {
  background: transparent; border: none; font-size: 20px; cursor: pointer;
  color: var(--text-faint); line-height: 1; padding: 2px 4px; border-radius: 6px;
}
.guide-close:hover { background: var(--surface-2); color: var(--text); }
.guide-opts { display: inline-flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.guide-opt {
  background: var(--primary-soft); color: var(--primary); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 12px; font-size: 13px; cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.guide-opt:hover { background: var(--primary-tint); border-color: var(--primary); }
.guide-opt:active { transform: translateY(1px); }
.guide-opt b { font-weight: 700; }
.guide-opt.is-flash { box-shadow: 0 0 0 3px var(--primary-soft); border-color: var(--primary); }
.flash-target { animation: flashPulse 1.2s ease; }
@keyframes flashPulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  30% { box-shadow: 0 0 0 4px var(--primary-soft); border-color: var(--primary); }
}

/* ===== Header（实色 sticky，非玻璃拟态） ===== */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header .header-inner {
  max-width: var(--content-w); margin: 0 auto; padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center;
}
.brand-mark { width: 22px; height: 22px; }
.brand-text { display: flex; flex-direction: column; gap: 3px; }
.brand-name {
  margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05;
  background: linear-gradient(120deg, var(--primary) 0%, #8b5cf6 52%, #ec4899 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
.brand-accent { font-style: italic; font-weight: 800; }
.brand-tag {
  margin: 0; font-size: 12px; color: var(--text-faint); font-weight: 500;
  font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  letter-spacing: .22em; padding-left: .22em;
}
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stat-pills { display: flex; gap: 6px; }
.pill {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 5px 11px; border-radius: var(--radius-pill);
  font-size: 12px; color: var(--text-soft);
}
.pill b { color: var(--text); font-weight: 700; }
.icon-btn {
  width: 38px; height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-soft); cursor: pointer;
  display: grid; place-items: center; transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.settings-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--primary); background: var(--primary-soft); color: var(--primary);
  cursor: pointer; font-size: 14px; font-weight: 600; font-family: inherit;
  transition: background .15s, color .15s, border-color .15s, box-shadow .2s, transform .15s;
}
.settings-pill .ico { width: 17px; height: 17px; }
.settings-pill:hover { background: var(--primary); color: #fff; }
.settings-pill.attention { animation: pillPulse 1.1s ease-in-out 3; }
@keyframes pillPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79,70,229,0); }
  50% { box-shadow: 0 0 0 6px rgba(79,70,229,.20); }
}

/* ===== 顶部标签导航（清晰分区） ===== */
.tabs {
  max-width: var(--content-w); margin: 0 auto; padding: 0 24px;
  display: flex; gap: 4px; border-bottom: 1px solid var(--border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { height: 0; }
.tab {
  appearance: none; background: none; border: none; cursor: pointer;
  padding: 14px 16px; font-size: 14px; font-weight: 500; color: var(--text-soft);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s;
  white-space: nowrap; flex: 0 0 auto;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ===== 布局容器（有限宽度，避免跨屏） ===== */
.container { max-width: var(--content-w); margin: 0 auto; padding: 24px; }
.panel { display: none; animation: fade .2s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== 卡片（统一圆角/边框/轻阴影） ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.card-title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
.hint { color: var(--text-soft); font-size: 13.5px; margin: 0 0 14px; line-height: 1.6; }
.format-tip { color: var(--text-faint); font-size: 12px; margin-top: 10px; }
code {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 6px; font-size: 12px; color: var(--text-soft);
}

/* ===== 按钮（层级分明） ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 15px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 14px; font-weight: 500; font-family: inherit;
  transition: background .15s, border-color .15s, filter .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn.danger:hover { filter: brightness(.97); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }

/* ===== 导入区 ===== */
.import-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.import-col { display: flex; flex-direction: column; }
.field-label { font-size: 13px; color: var(--text-soft); margin-bottom: 8px; font-weight: 600; }
.textarea {
  width: 100%; min-height: 150px; resize: vertical; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: 14px;
  font-family: inherit; line-height: 1.6;
}
.textarea:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.drop-zone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm);
  padding: 26px; text-align: center; cursor: pointer; color: var(--text-soft);
  background: var(--surface-2); transition: .18s;
}
.drop-zone:hover { border-color: var(--primary); }
.drop-zone.drag { border-color: var(--primary); background: var(--primary-soft); }
.drop-icon { font-size: 30px; }
.drop-inner p { margin: 8px 0 2px; font-weight: 600; color: var(--text); }
.drop-inner small { font-size: 12px; }
.ocr-status { font-size: 13px; margin-top: 10px; color: var(--primary); min-height: 18px; }

/* ===== 单词预览列表 ===== */
.wordlist-meta { font-size: 13px; color: var(--text-soft); margin-bottom: 12px; }
.word-list { display: flex; flex-wrap: wrap; gap: 8px; }
.word-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  font-size: 14px; cursor: pointer; user-select: none; transition: .15s;
}
.word-chip:hover { border-color: var(--border-strong); }
.word-chip.checked { background: var(--primary-soft); border-color: var(--primary); }
.word-chip .wc-text { font-weight: 600; }
.word-chip .wc-meta { font-size: 12px; color: var(--text-soft); }
.word-chip .wc-del { color: var(--danger); font-weight: 700; margin-left: 2px; opacity: .7; }
.word-chip .wc-del:hover { opacity: 1; }
.word-chip .wc-check { font-size: 13px; color: var(--primary); }

/* ===== 短文生成 ===== */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.seg-btn {
  border: none; background: transparent; color: var(--text-soft);
  padding: 8px 14px; cursor: pointer; font-size: 14px; font-family: inherit; font-weight: 500;
  transition: .15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--primary); color: #fff; }
.seg-hint { font-size: 12px; color: var(--text-faint); align-self: center; }
.passage {
  margin-top: 16px; padding: 24px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border); font-size: var(--font-size);
}
.passage-text { line-height: 2.1; }
.passage-text .word { cursor: pointer; border-radius: 4px; padding: 0 1px; transition: background .15s; }
.passage-text .word:hover { background: var(--primary-soft); }
.passage-text .word.hl {
  background: var(--hl); color: var(--hl-text); font-weight: 600; padding: 1px 3px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .05);
}

/* 整段译文（显示在英文原文下方） */
.passage-zh {
  margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--border);
}
.zh-label {
  font-size: 12px; font-weight: 600; color: var(--text-faint);
  letter-spacing: .12em; margin-bottom: 8px;
}
.zh-block { line-height: 2.0; color: var(--text-soft); font-size: var(--font-size); }
.zh-block mark.zh-hl {
  background: var(--hl); color: var(--hl-text); padding: 0 4px; border-radius: 4px; font-weight: 600;
}

/* ===== 生词本：生词本切换栏 ===== */
.book-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.book-tabs { display: flex; gap: 8px; overflow-x: auto; flex: 1; padding-bottom: 2px; }
.book-tab {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-soft); padding: 7px 14px; border-radius: var(--radius-pill);
  cursor: pointer; font-size: 13.5px; font-family: inherit; font-weight: 500;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; transition: .15s;
}
.book-tab:hover { border-color: var(--border-strong); color: var(--text); }
.book-tab.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.book-tab .bt-count {
  font-size: 11px; background: rgba(0, 0, 0, .06); color: inherit;
  padding: 1px 7px; border-radius: 999px; font-weight: 600;
}
[data-theme="dark"] .book-tab .bt-count { background: rgba(255, 255, 255, .1); }
.book-actions { display: flex; gap: 8px; }

.subtabs { display: flex; gap: 8px; margin-bottom: 14px; }
.subtab {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  padding: 6px 14px; border-radius: var(--radius-pill); cursor: pointer; font-size: 13px; font-weight: 500;
}
.subtab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.vocab-list { display: flex; flex-direction: column; gap: 8px; }
.vocab-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); transition: border-color .15s;
}
.vocab-item:hover { border-color: var(--border-strong); }
.vocab-item .vi-check { transform: scale(1.15); accent-color: var(--primary); }
.vocab-item .vi-main { flex: 1; min-width: 0; }
.vocab-item .vi-word { font-weight: 700; font-size: 15px; }
.vocab-item .vi-phon { color: var(--text-soft); font-size: 13px; margin-left: 10px; }
.vocab-item .vi-mean { font-size: 13.5px; color: var(--text-soft); margin-top: 2px; }
.vocab-item .vi-time { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
.vocab-item .vi-ex { font-size: 12.5px; color: var(--text-faint); font-style: italic; margin-top: 3px; }
.vi-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ===== 历史记录 ===== */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px;
  background: var(--surface-2); cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.history-item:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.hi-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; gap: 12px; }
.hi-title { font-weight: 600; color: var(--text); }
.hi-snippet { font-size: 13px; color: var(--text-soft); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.6; }

/* ===== 单词悬浮卡片 ===== */
.word-popup {
  position: fixed; z-index: 100; width: 290px; max-width: 86vw;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-hover); padding: 16px; animation: pop .15s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }
.wp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.wp-word { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.wp-phon { color: var(--text-soft); font-size: 13px; margin-left: 8px; }
.wp-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-faint); line-height: 1; padding: 2px 4px; border-radius: 6px; }
.wp-close:hover { background: var(--surface-2); color: var(--text); }
.wp-mean { margin: 10px 0; font-size: 14px; line-height: 1.6; }
.wp-example { font-size: 13px; color: var(--text-soft); font-style: italic; margin-bottom: 12px; line-height: 1.6; }
.wp-foot { display: flex; gap: 8px; }

/* ===== 设置弹窗 ===== */
.modal {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: 420px; max-width: 100%; padding: 22px; box-shadow: var(--shadow-hover);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-body { margin-top: 18px; display: flex; flex-direction: column; gap: 18px; }
.setting-row { display: flex; flex-direction: column; gap: 9px; }
.setting-row > label { font-size: 13px; color: var(--text-soft); font-weight: 600; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; transition: transform .1s; }
.swatch:hover { transform: scale(1.08); }
.swatch.active { border-color: var(--text); }
input[type="range"] { width: 100%; accent-color: var(--primary); }

/* ===== 轻提示 ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: var(--radius-pill);
  font-size: 14px; z-index: 300; box-shadow: var(--shadow-hover); animation: pop .2s ease;
}

.empty { text-align: center; color: var(--text-faint); padding: 32px 16px; font-size: 14px; line-height: 1.6; }

/* —— AI 模型设置项 —— */
.setting-row.col { align-items: stretch; }
.setting-row.col .input { width: 100%; }
.input {
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; font: inherit; font-size: 14px;
  background: var(--surface-2); color: var(--text);
}
.input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.setting-tip { color: var(--text-faint); font-size: 12px; line-height: 1.6; }

/* ===== 开屏提醒弹窗 ===== */
.onboard-box { max-width: 440px; }
.onboard-lead { margin: 0; font-size: 14px; line-height: 1.7; color: var(--text); }
.onboard-lead b { color: var(--primary); }
.onboard-sub { margin: 0; font-size: 13.5px; line-height: 1.7; color: var(--text-soft); }
.onboard-sub b { color: var(--text); }
.onboard-set {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px;
  border-radius: var(--radius-pill); background: var(--primary-soft);
  color: var(--primary); font-weight: 600; font-size: 12.5px; white-space: nowrap;
}
.onboard-actions { display: flex; gap: 10px; margin: 0; }
.onboard-actions .btn { flex: 1; justify-content: center; }

/* —— 多篇章短文 —— */
.passage-block { margin-bottom: 1.2rem; }
.passage-block:last-child { margin-bottom: 0; }
.passage-cap {
  font-size: 12px; font-weight: 600; letter-spacing: .04em;
  color: var(--text-faint); margin-bottom: .5rem;
}

/* ===== 响应式 ===== */
@media (max-width: 720px) {
  .app-header .header-inner, .tabs, .container, .guide-inner { padding-left: 16px; padding-right: 16px; }
  .import-grid { grid-template-columns: 1fr; }
  .stat-pills { order: 3; width: 100%; justify-content: space-between; }
  .brand-name { font-size: 18px; }
  .card { padding: 16px; }
  .passage { padding: 18px; }
  .tab { padding: 12px 12px; font-size: 13px; }
  .vocab-item { flex-wrap: wrap; }
  .vi-actions { width: 100%; justify-content: flex-end; }
}

/* —— AI 失败原因提示（无需 F12，直接显示在文章区上方）—— */
.ai-warn { display: block; margin-top: 6px; color: #d64545; font-size: 12px; line-height: 1.5; }
