:root {
  --bg: #faf9f7;
  --card: #ffffff;
  --border: #e8e4df;
  --text: #2c2c2c;
  --text2: #8a8580;
  /* 强调色家族：默认「墨蓝 Ink Navy」，可被 [data-palette] 覆盖 */
  --accent: #2f4a6b;
  --accent-light: #eef1f6;
  --accent-rgb: 47,74,107;
  --accent-sb: #7fa0c9;        /* 深色侧边栏上用的提亮强调色 */
  --sel-bg: #e7dcc4;           /* 选中底：暖砂，和强调色明显区分 */
  --sel-fg: #2c2c2c;
  --green: #059669;
  --green-light: #d1fae5;
  --yellow: #d97706;
  --yellow-light: #fef3c7;
  --red: #e11d48;
  --red-light: #ffe4e6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.03);
  --sidebar-bg: #efede9;
  --sidebar-text: #2c2c2c;
  --sidebar-text2: #8a8580;
  --sidebar-hover: rgba(0,0,0,.04);
  --sidebar-active: rgba(0,0,0,.05);
  --sidebar-divider: rgba(0,0,0,.07);
  --font-serif: 'Playfair Display', Georgia, 'Noto Serif SC', serif;
  --font-sans: 'Inter', 'PingFang SC', -apple-system, BlinkMacSystemFont, 'Noto Sans SC', sans-serif;
}
[data-theme="dark"] {
  --bg: #161620;
  --card: #1e1e2e;
  --border: #2e2e3e;
  --text: #c4c0b8;
  --text2: #8a8780;
  /* 强调色家族：默认「墨蓝」深色版（提亮以保证深底对比） */
  --accent: #7fa0c9;
  --accent-light: #1a2230;
  --accent-rgb: 127,160,201;
  --accent-sb: #7fa0c9;
  --sel-bg: #3a4257;
  --sel-fg: #f0ede8;
  --green: #34d399;
  --green-light: #064e3b;
  --yellow: #fbbf24;
  --yellow-light: #422006;
  --red: #fb7185;
  --red-light: #4c0519;
  --shadow: 0 1px 3px rgba(0,0,0,.2), 0 1px 2px rgba(0,0,0,.15);
  --sidebar-bg: #141a24;
  --sidebar-text: rgba(255,255,255,.85);
  --sidebar-text2: rgba(255,255,255,.45);
  --sidebar-hover: rgba(255,255,255,.04);
  --sidebar-active: rgba(255,255,255,.07);
  --sidebar-divider: rgba(255,255,255,.08);
}

/* ── 配色方案（叠加在浅/深色模式之上，data-palette 控制） ── */
[data-palette="navy"] { --accent:#2f4a6b; --accent-light:#eef1f6; --accent-rgb:47,74,107; --accent-sb:#2f4a6b; --sidebar-bg:#eef1f6; --sel-bg:#e7dcc4; --sel-fg:#2c2c2c; }
[data-theme="dark"][data-palette="navy"] { --accent:#7fa0c9; --accent-light:#1a2230; --accent-rgb:127,160,201; --sidebar-bg:#141a24; --sidebar-text:rgba(255,255,255,.85); --sidebar-text2:rgba(255,255,255,.45); --sidebar-hover:rgba(255,255,255,.04); --sidebar-active:rgba(255,255,255,.07); --sidebar-divider:rgba(255,255,255,.08); --accent-sb:#7fa0c9; --sel-bg:#3a4257; --sel-fg:#f0ede8; }

[data-palette="bordeaux"] { --accent:#8c3b4a; --accent-light:#f7ecee; --accent-rgb:140,59,74; --accent-sb:#8c3b4a; --sidebar-bg:#f7ecee; --sel-bg:#ecdcc0; --sel-fg:#2c2c2c; }
[data-theme="dark"][data-palette="bordeaux"] { --accent:#cf8893; --accent-light:#2a1a1d; --accent-rgb:207,136,147; --sidebar-bg:#1c1416; --sidebar-text:rgba(255,255,255,.85); --sidebar-text2:rgba(255,255,255,.45); --sidebar-hover:rgba(255,255,255,.04); --sidebar-active:rgba(255,255,255,.07); --sidebar-divider:rgba(255,255,255,.08); --accent-sb:#cf8893; --sel-bg:#4a2f34; --sel-fg:#f0ede8; }

[data-palette="bronze"] { --accent:#94703a; --accent-light:#f5efe2; --accent-rgb:148,112,58; --accent-sb:#94703a; --sidebar-bg:#f5efe2; --sel-bg:#e4e0d4; --sel-fg:#2c2c2c; }
[data-theme="dark"][data-palette="bronze"] { --accent:#c8a468; --accent-light:#272016; --accent-rgb:200,164,104; --sidebar-bg:#1b1c17; --sidebar-text:rgba(255,255,255,.85); --sidebar-text2:rgba(255,255,255,.45); --sidebar-hover:rgba(255,255,255,.04); --sidebar-active:rgba(255,255,255,.07); --sidebar-divider:rgba(255,255,255,.08); --accent-sb:#c8a468; --sel-bg:#463c28; --sel-fg:#f0ede8; }

/* ── 东方配色（宁学苑 / 贡院，data-palette-east 控制）── */
/* 深色模式下恢复全局 dark 底色，各朝仅覆盖 accent 系 */
[data-theme="dark"][data-palette-east] {
  --bg: #161620; --card: #1e1e2e; --border: #2e2e3e;
  --text: #c4c0b8; --text2: #8a8780;
}
/* 秦 · 大秦黑金 — 厚重朴拙 */
[data-palette-east="qin"] {
  --bg:#fbf7ee; --card:#fffaf0; --border:#eadbc3;
  --text:#1f2328; --text2:#6b6560;
  --accent:#1f2328; --accent-light:#f0ebe2; --accent-rgb:31,35,40;
}
[data-theme="dark"][data-palette-east="qin"] { --accent:#b98b2e; --accent-light:#2a2418; --accent-rgb:185,139,46; }
/* 汉 · 汉家赤胆 — 热烈沉雄 */
[data-palette-east="han"] {
  --bg:#fff8ef; --card:#fff3e8; --border:#efd5bf;
  --text:#3a1a16; --text2:#8a6a5c;
  --accent:#b23a2f; --accent-light:#fae8df; --accent-rgb:178,58,47;
}
[data-theme="dark"][data-palette-east="han"] { --accent:#c69332; --accent-light:#2a2218; --accent-rgb:198,147,50; }
/* 唐 · 盛唐华彩 — 雍容开阔 */
[data-palette-east="tang"] {
  --bg:#fff9e8; --card:#fff5d9; --border:#ecd393;
  --text:#1a3a3f; --text2:#5a8a80;
  --accent:#2f7f8f; --accent-light:#e4f2f1; --accent-rgb:47,127,143;
}
[data-theme="dark"][data-palette-east="tang"] { --accent:#d4a635; --accent-light:#2a2418; --accent-rgb:212,166,53; }
/* 宋 · 雅宋青绿 — 清逸文雅 */
[data-palette-east="song"] {
  --bg:#fbfaf5; --card:#fffdf7; --border:#e7dfcb;
  --text:#2a3a32; --text2:#7a8a78;
  --accent:#4f8b82; --accent-light:#e8f2ee; --accent-rgb:79,139,130;
}
[data-theme="dark"][data-palette-east="song"] { --accent:#b9913a; --accent-light:#2a2218; --accent-rgb:185,145,58; }
/* 明 · 大明风骨 — 刚健炽烈 */
[data-palette-east="ming"] {
  --bg:#fff8f1; --card:#fff2e8; --border:#eac8b7;
  --text:#2a1216; --text2:#8a5a58;
  --accent:#b9312d; --accent-light:#fae4dc; --accent-rgb:185,49,45;
}
[data-theme="dark"][data-palette-east="ming"] { --accent:#c9a13f; --accent-light:#2a2218; --accent-rgb:201,161,63; }
/* 现代 · 现代海蓝 — 理性明快 */
[data-palette-east="modern"] {
  --bg:#f8fbff; --card:#f1f7ff; --border:#d8e6f5;
  --text:#1a2a3f; --text2:#5a7a9a;
  --accent:#1f63a6; --accent-light:#e3f0fb; --accent-rgb:31,99,166;
}
[data-theme="dark"][data-palette-east="modern"] { --accent:#d6a832; --accent-light:#2a2418; --accent-rgb:214,168,50; }

::selection { background: var(--sel-bg); color: var(--sel-fg); }
::-moz-selection { background: var(--sel-bg); color: var(--sel-fg); }

/* 主题色选择器 */
.palette-grid { display: flex; gap: 12px; flex-wrap: wrap; }
.palette-swatch {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 18px; min-width: 96px; cursor: pointer;
  background: var(--card); border: 1.5px solid var(--border); border-radius: 10px;
  transition: border-color .18s, box-shadow .18s; color: var(--text); font-family: inherit;
}
.palette-swatch:hover { border-color: var(--text2); }
.palette-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.14); }
.palette-dot { width: 30px; height: 30px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.10); }
.palette-name { font-size: 14px; font-weight: 600; }
.palette-en { font-size: 11px; color: var(--text2); letter-spacing: .3px; }
* { margin: 0; padding: 0; box-sizing: border-box; }
*, *::before, *::after { box-sizing: border-box; }
html { overflow-x: hidden; width: 100%; }
input, button, select, textarea { font-family: inherit; }
body {
  font-family: var(--font-sans);
  background: var(--bg); color: var(--text); line-height: 1.6;
  overflow-x: hidden; width: 100%; max-width: 100%;
}

/* ── Layout ── */
.shell { display: flex; min-height: 100vh; overflow: hidden; width: 100%; }
.sidebar {
  width: 240px; background: var(--sidebar-bg); color: var(--sidebar-text);
  padding: 28px 0; flex-shrink: 0; position: fixed; top: 0; bottom: 0; z-index: 10;
  display: flex; flex-direction: column;
}
.sidebar h1 { font-family: var(--font-serif); font-size: 20px; font-weight: 700; padding: 0 24px 24px; border-bottom: 1px solid var(--sidebar-divider); letter-spacing: .3px; }
.sidebar nav { flex: 1; padding: 16px 0; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 24px; color: var(--sidebar-text2); text-decoration: none;
  font-size: 13px; font-weight: 500; transition: all .2s; border-left: 3px solid transparent;
}
.sidebar nav a:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }
.sidebar nav a.active { color: var(--sidebar-text); background: var(--sidebar-active); border-left-color: var(--accent-sb); }
.sidebar nav a .icon { width: 18px; text-align: center; font-size: 15px; }
.sidebar .api-status { padding: 18px 24px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: rgba(255,255,255,.5); }
.sidebar .api-status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.sidebar .api-status .dot.ok { background: #34d399; }
.sidebar .api-status .dot.no { background: #fb7185; }

.main { margin-left: 240px; flex: 1; padding: 36px 40px; max-width: 1000px; }
.main.main-full { margin-left: 0; max-width: 100%; padding: 20px 24px; }

/* ── Components ── */
.page { display: none; }
.page.active { display: block; }
#page-vocab.active, #page-sage.active, #page-writing.active, #page-exercises.active { display: flex; flex-direction: column; height: calc(100vh - 72px); height: calc(100dvh - 72px); overflow: hidden; }
#page-articles.active, #page-lessons.active, #page-review.active, #page-generate.active {
  display: flex; flex-direction: column; max-height: calc(100vh - 72px); overflow-y: auto;
}
@media (max-width: 768px) {
  #page-vocab.active, #page-writing.active, #page-exercises.active { height: calc(100vh - 76px); height: calc(100dvh - 76px); }
  #page-articles.active, #page-lessons.active, #page-review.active, #page-generate.active { max-height: calc(100vh - 76px); }
}
.page-title { font-family: var(--font-serif); font-size: 24px; font-weight: 700; margin-bottom: 28px; color: var(--text); letter-spacing: -.2px; text-align: left; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center; box-shadow: var(--shadow);
}
.stat-card .num { font-family: var(--font-serif); font-size: 30px; font-weight: 700; color: var(--accent); }
.stat-card .label { font-size: 11px; color: var(--text2); margin-top: 6px; text-transform: uppercase; letter-spacing: .8px; font-weight: 500; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600;
}
.badge.unknown { background: var(--red-light); color: var(--red); }
.badge.learning { background: var(--yellow-light); color: var(--yellow); }
.badge.mastered { background: var(--green-light); color: var(--green); }
.badge.unread { background: #f3f4f6; color: #9ca3af; cursor: pointer; }
.badge.reading { background: #dbeafe; color: #3b82f6; cursor: pointer; }
.badge.finished { background: var(--green-light); color: var(--green); cursor: pointer; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

@media (max-width: 1024px) {
  #page-articles .card, #page-review .card, #page-lessons .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); color: var(--text2); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; font-weight: 600; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:hover td { background: rgba(var(--accent-rgb),.04); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border: none; border-radius: 8px;
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .2s; letter-spacing: .1px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(0.85); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(var(--accent-rgb),.3); }
.btn-secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); border-color: var(--text2); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #047857; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text2); }
.form-group input, .form-group select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px; background: var(--bg);
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.12); }

/* 全局 input/textarea/select 适配深浅模式 */
input, textarea, select {
  background: var(--card); color: var(--text);
  border: 1px solid var(--border);
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.12);
}
[data-theme="dark"] input::placeholder, [data-theme="dark"] textarea::placeholder { color: var(--text2); opacity: .6; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.empty { text-align: center; padding: 48px; color: var(--text2); }

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

/* Article reader */
.article-reader { max-width: 680px; margin: 0 auto; }
.article-reader h2 { font-family: var(--font-serif); font-size: 26px; margin-bottom: 10px; font-weight: 700; line-height: 1.3; color: var(--text); }
.article-reader .meta { color: var(--text2); font-size: 13px; margin-bottom: 24px; letter-spacing: .3px; }
.article-reader .content { font-family: var(--font-serif); font-size: 16.5px; line-height: 1.85; color: var(--text); }
.article-reader .content p { margin-bottom: 18px; text-indent: 2em; text-align: justify; }
.article-reader .vocab-word { color: var(--accent); font-weight: 600; cursor: help; border-bottom: 1px dashed rgba(var(--accent-rgb),.4); }
.article-reader .vocab-word:hover { background: var(--accent-light); border-bottom-color: var(--accent); }

/* Review cards */
.review-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 12px; background: var(--card);
  transition: all .15s; cursor: pointer;
}
.review-card:hover { border-color: var(--accent); box-shadow: 0 2px 12px rgba(var(--accent-rgb),.1); }
.review-card .title { font-family: var(--font-serif); font-weight: 600; font-size: 16px; }
.review-card .info { color: var(--text2); font-size: 13px; margin-top: 4px; }

/* Flashcard */
.flashcard-container { max-width: 500px; margin: 0 auto; text-align: center; }
.flashcard {
  background: var(--card); border: 2px solid var(--border); border-radius: 16px;
  padding: 48px 32px; margin: 24px 0; min-height: 220px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; transition: all .2s; user-select: none;
}
.flashcard:hover { border-color: var(--accent); box-shadow: 0 4px 20px rgba(var(--accent-rgb),.08); }
.flashcard .word { font-size: 32px; font-weight: 700; font-family: var(--font-serif); }
.flashcard .phonetic { color: var(--text2); font-size: 16px; margin-top: 8px; }
.flashcard .meaning { font-size: 18px; margin-top: 16px; color: var(--accent); display: none; }
.flashcard.flipped .meaning { display: block; }
.flashcard .example-sentence { display: none; margin-top: 12px; font-size: 13px; color: var(--text2); font-style: italic; }
.flashcard .example-translation { display: none; margin-top: 8px; font-size: 13px; color: var(--accent); }
.flashcard.flipped .example-sentence { display: block; }
.flashcard.flipped .example-translation { display: block; }
.flashcard-actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.flashcard-progress { color: var(--text2); font-size: 14px; margin-bottom: 8px; }
.flashcard-speaker {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border: none; border-radius: 50%;
  background: var(--accent-light); color: var(--accent); cursor: pointer;
  font-size: 13px; margin-left: 6px; vertical-align: middle;
  transition: all .15s; flex-shrink: 0;
}
.flashcard-speaker:hover { background: var(--accent); color: #fff; }
.flashcard-speaker:disabled { opacity: 0.4; cursor: not-allowed; }
.flashcard-speaker.playing { background: var(--green); color: #fff; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 100; align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--card); border-radius: 12px; padding: 32px;
  max-width: 480px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal h3 { margin-bottom: 16px; }

/* Generate status */
.gen-status { padding: 16px; border-radius: 8px; background: var(--accent-light); margin-top: 16px; display: none; }
.gen-status .spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; margin-right: 8px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--border); }
.tab {
  padding: 8px 16px; font-size: 14px; font-weight: 600; color: var(--text2);
  border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all .15s; font-family: inherit;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Analysis Popup */
.analysis-popup {
  display: none; position: fixed; z-index: 200;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.15);
  width: 400px; max-height: 500px; overflow-y: auto;
}
.analysis-popup.show { display: block; }
.analysis-popup .popup-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--accent-light); border-radius: 12px 12px 0 0;
  position: sticky; top: 0; z-index: 1;
}
.analysis-popup .popup-selected {
  font-weight: 700; font-size: 16px; color: var(--accent);
  font-family: Georgia, serif; flex: 1; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; margin-right: 8px;
}
.analysis-popup .popup-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.analysis-popup .popup-body { padding: 16px; }
.analysis-popup .popup-row { margin-bottom: 12px; }
.analysis-popup .popup-label {
  font-size: 11px; color: var(--text2); text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 3px; font-weight: 600;
}
.analysis-popup .popup-value { font-size: 14px; line-height: 1.6; }
.analysis-popup .popup-examples li { margin-bottom: 4px; list-style: decimal; margin-left: 18px; font-size: 13px; line-height: 1.5; }
.analysis-popup .popup-loading {
  display: flex; align-items: center; gap: 8px; padding: 24px;
  color: var(--text2); font-size: 14px; justify-content: center;
}
.analysis-popup .popup-loading .spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; }
.voice-mini-popup { position: fixed; display: none; z-index: 1001; }
.voice-mini-popup.show { display: block; }
.voice-mini-popup .btn-icon { width: 36px; height: 36px; font-size: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.btn-icon {
  width: 30px; height: 30px; border: none; border-radius: 50%;
  background: var(--accent); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; transition: all .15s; flex-shrink: 0;
}
.btn-icon:hover { background: #094a8a; }
.btn-icon:disabled { background: var(--border); cursor: not-allowed; }
.btn-icon.playing { background: var(--green); }
.btn-close {
  width: 24px; height: 24px; border: none; background: none;
  color: var(--text2); cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.btn-close:hover { color: var(--text); }

/* Login overlay */
.login-overlay {
  display: none; position: fixed; inset: 0;
  background: linear-gradient(145deg, #1e1b2e 0%, #2d2a3e 50%, #1e1b2e 100%);
  z-index: 9999; align-items: center; justify-content: center;
}
.login-overlay.show { display: flex; }
.login-card {
  background: var(--card); border: none;
  border-radius: 20px; padding: 48px 40px; width: 380px; max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); text-align: center;
}
.login-card h2 { font-family: var(--font-serif); font-size: 36px; margin-bottom: 28px; font-weight: 700; color: var(--text); letter-spacing: 2px; }
.login-card p { color: var(--text2); font-size: 14px; margin-bottom: 28px; }

/* Sidebar toggle arrow — positioned at middle-left edge */
.sidebar-arrow {
  display: none; position: fixed; left: 0; top: 50%; transform: translateY(-50%); z-index: 1065;
  width: 22px; height: 48px; background: rgba(30, 27, 46, 0.18); border: none; border-radius: 0 8px 8px 0;
  cursor: pointer; color: rgba(255,255,255,.55); font-size: 18px; line-height: 48px; text-align: center;
  padding: 0; transition: left 0.3s ease, transform 0.3s ease, border-radius 0.3s ease;
}
.sidebar-arrow.open {
  left: 240px;
  border-radius: 8px 0 0 8px;
  transform: translateY(-50%) rotate(180deg);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1055;
}
.sidebar-overlay.show { display: block; }
.sidebar-overlay.show ~ .mobile-fab-container { display: none !important; }

/* Mobile floating buttons */
.mobile-fab-container {
  display: none; position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 0; right: 0;
  z-index: 1050; pointer-events: none;
}
.mobile-fab-container .fab {
  pointer-events: auto; position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  height: 40px; border-radius: 20px; padding: 0 14px;
  border: none; font-size: 13px; color: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
  display: flex; align-items: center; gap: 4px;
  cursor: pointer; opacity: 0.85;
}
.mobile-fab-container .fab:active { opacity: 1; transform: scale(0.95); }
.mobile-fab-container .fab-voice { right: 16px; background: var(--accent); }
.mobile-fab-container .fab-analysis { left: 16px; background: #1e1b2e; }
.mobile-fab-container .fab .fab-icon { font-size: 16px; }
.mobile-fab-toast {
  display: none; position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.78); color: #fff; padding: 8px 20px;
  border-radius: 20px; font-size: 14px; z-index: 1060;
  animation: fabToastFade 2s ease forwards;
}
@keyframes fabToastFade { 0%,60% { opacity: 1; } 100% { opacity: 0; } }

/* Mobile bottom sheet — floating panel with pointer-events passthrough */
.mobile-bottom-sheet {
  display: flex; position: fixed; left: 8px; right: 8px; bottom: 8px;
  max-height: 40vh; z-index: 1100;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 -4px 24px rgba(0,0,0,.2);
  flex-direction: column;
  box-sizing: border-box; overflow: hidden;
  visibility: hidden;
  pointer-events: none;  /* let touches pass through to article */
}
.mobile-bottom-sheet.show {
  visibility: visible;
}
.mobile-bottom-sheet .sheet-header,
.mobile-bottom-sheet .sheet-body {
  pointer-events: auto;  /* these ARE interactive */
}
.mobile-bottom-sheet .sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mobile-bottom-sheet .sheet-selected {
  font-weight: 700; font-size: 15px; color: var(--accent);
  font-family: Georgia, serif; flex: 1; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; margin-right: 8px;
}
.mobile-bottom-sheet .sheet-actions {
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}
.mobile-bottom-sheet .sheet-actions .btn {
  padding: 6px 14px; font-size: 13px; min-width: 0;
}
.mobile-bottom-sheet .sheet-body {
  flex: 1; overflow-y: auto; padding: 16px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ── Lesson Detail ── */
.lesson-reader { max-width: 680px; margin: 0 auto; }
.lesson-reader h2 { font-family: var(--font-serif); font-size: 22px; margin-bottom: 8px; }
.lesson-reader .meta { color: var(--text2); font-size: 13px; margin-bottom: 24px; }
.lesson-entry {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.lesson-entry .word-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.lesson-entry .word-num { color: var(--text2); font-size: 13px; font-weight: 600; min-width: 28px; }
.lesson-entry .word-name { font-size: 16px; font-weight: 700; color: var(--accent); }
.lesson-entry .word-pos { font-size: 12px; color: var(--text2); background: var(--accent-light); padding: 1px 6px; border-radius: 4px; }
.lesson-entry .word-cn { font-size: 13px; color: var(--text2); margin-bottom: 8px; }
.lesson-meaning { padding-left: 12px; border-left: 2px solid var(--border); margin: 8px 0; }
.lesson-meaning .meaning-label { font-size: 13px; color: var(--text); margin-bottom: 4px; }
.lesson-meaning .example { font-size: 13px; color: var(--text); line-height: 1.6; margin: 4px 0; }
.lesson-meaning .example-cn { font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.lesson-speaker {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--border);
  background: transparent; color: var(--text2); cursor: pointer; font-size: 11px;
  margin-left: 6px; vertical-align: middle; transition: all .15s; flex-shrink: 0;
}
.lesson-speaker:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.lesson-speaker.playing { background: var(--green); color: #fff; border-color: var(--green); }
.lesson-speaker:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Gate Page ── */
.gate-container { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80vh; text-align: center; padding: 40px 20px; }
.gate-header { font-family: var(--font-serif); font-size: 48px; font-weight: 700; color: var(--text); margin-bottom: 8px; letter-spacing: 4px; }
.gate-sub { font-family: var(--font-serif); font-size: 13px; color: var(--text2); font-style: italic; margin-bottom: 48px; opacity: .7; }
.gate-cards { display: flex; gap: 24px; flex-wrap: wrap; justify-content: center; max-width: 900px; width: 100%; }
.gate-card { flex: 1; min-width: 220px; max-width: 280px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 24px; cursor: pointer; transition: all .2s; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.gate-card:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,.08); border-color: var(--accent); }
.gate-icon { font-size: 48px; margin-bottom: 4px; }
.gate-title { font-family: var(--font-serif); font-size: 20px; font-weight: 700; color: var(--text); }
.gate-desc { font-size: 13px; color: var(--text2); }
.gate-card .btn { margin-top: 8px; width: 100%; }

/* ── 宁学苑（Sage）样式已提取至 sage.css，按需加载 ── */

/* ── Soul Chat ── */
.soul-chat-container { max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; }
.soul-profile {
  background: linear-gradient(135deg, var(--accent-light) 0%, #f0f4ff 100%);
  border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px;
}
.soul-profile .soul-name { font-family: var(--font-serif); font-size: 20px; font-weight: 700; }
.soul-profile .soul-meta { font-size: 13px; color: var(--text2); margin-top: 4px; }
.soul-profile .soul-bio { font-size: 13px; color: var(--text); margin-top: 10px; line-height: 1.6; font-style: italic; }
.soul-profile .soul-expiry { font-size: 12px; color: var(--text2); margin-top: 8px; }
.soul-chat-messages {
  flex: 1; overflow-y: auto; padding: 4px 0;
  min-height: 120px; max-height: calc(100vh - 320px);
}
.soul-chat-messages .msg { margin-bottom: 14px; }
.soul-chat-messages .msg > div { max-width: 80%; width: fit-content; }
.soul-chat-messages .msg.soul > div { margin-right: auto; }
.soul-chat-messages .msg.user > div { margin-left: auto; }
.soul-chat-messages .msg .bubble {
  padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.6;
  word-break: break-word;
}
.soul-chat-messages .msg.soul .bubble { background: var(--card); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }
.soul-chat-messages .msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.soul-chat-messages .msg .time { font-size: 10px; color: var(--text2); margin-top: 2px; }
.soul-chat-input {
  display: flex; gap: 8px; padding: 12px 0 4px;
  border-top: 1px solid var(--border); background: var(--bg); z-index: 10;
}
.soul-chat-input input {
  flex: 1; padding: 12px 16px; border: 1px solid var(--border); border-radius: 24px;
  font-size: 16px; background: var(--card); font-family: var(--font-sans);
}
.soul-chat-input input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.1); }
.soul-chat-input input:disabled { opacity: 0.5; }
.soul-chat-input .btn { border-radius: 24px; padding: 10px 20px; font-size: 14px; }
.soul-history-item {
  padding: 14px 18px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px;
  cursor: pointer; transition: all .15s; background: var(--card);
}
.soul-history-item:hover { border-color: var(--accent); }
.soul-history-item .soul-name { font-weight: 600; font-size: 15px; }
.soul-history-item .soul-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.soul-history-detail { margin-top: 16px; }
.soul-generate-area { text-align: center; padding: 32px 0; }
.soul-typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.soul-typing span { width: 6px; height: 6px; background: var(--text2); border-radius: 50%; animation: soulBounce 1.2s infinite; }
.soul-typing span:nth-child(2) { animation-delay: .2s; }
.soul-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes soulBounce { 0%,60%,100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }
.soul-farewell { text-align: center; padding: 32px; animation: fadeOutUp .8s ease forwards; animation-delay: 2s; }
@keyframes fadeOutUp { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-20px); } }
.soul-new-invite { text-align: center; padding: 24px; animation: fadeIn .6s ease; }
@keyframes fadeIn { 0% { opacity: 0; } 100% { opacity: 1; } }
body.in-soulchat .scroll-top { display: none !important; }
/* Soul profile modal for mobile */
.soul-profile-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.4); backdrop-filter: blur(2px);
}
.soul-profile-overlay.show { display: block; }
.soul-profile-modal {
  position: fixed; top: 8px; right: 8px; left: 8px; max-height: 80vh; overflow-y: auto;
  background: var(--bg); border-radius: 14px; padding: 20px; z-index: 201;
  box-shadow: 0 8px 40px rgba(0,0,0,.25); display: none;
}
.soul-profile-overlay.show + .soul-profile-modal,
.soul-profile-modal.show { display: block; }
.soul-profile-btn {
  position: fixed; top: 12px; right: 16px; z-index: 100;
  background: var(--accent); color: #fff; border: none; border-radius: 50%;
  width: 36px; height: 36px; font-size: 16px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(var(--accent-rgb),.3); display: none;
  align-items: center; justify-content: center;
}
@media (max-width: 768px) {
  .soul-profile-btn { display: flex; }
  .soul-profile-desktop { display: none; }
  body.in-soulchat #page-soulchat { padding-top: 0; }
  body.in-soulchat #page-soulchat .page-title { display: none; }
  body.in-soulchat .soul-chat-container { height: calc(100vh - 60px); height: calc(100dvh - 60px); }
  .soul-chat-messages { max-height: none !important; flex: 1; -webkit-overflow-scrolling: touch; }
  .soul-chat-input {
    position: sticky; bottom: 0;
    padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  }
  .soul-chat-input input { font-size: 16px; }
}
@media (min-width: 769px) {
  .soul-profile-btn { display: none !important; }
  .soul-profile-modal, .soul-profile-overlay { display: none !important; }
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar-arrow { display: block; }
  .sidebar {
    transform: translateX(-240px); transition: transform .3s ease; z-index: 1060;
  }
  .sidebar.open { transform: translateX(0); }
  .shell { overflow-y: auto; }
  .main { margin-left: 0; padding: 16px; padding-top: 60px; width: 100%; max-width: 100%; overflow-x: auto; overflow-y: auto; }
  .page { overflow-x: auto; width: 100%; }
  .page-title { font-size: 18px; margin-bottom: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat-card { padding: 10px; }
  .stat-card .num { font-size: 22px; }
  .stat-card .label { font-size: 11px; }
  .card { padding: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  table { min-width: 0; width: 100%; font-size: 12px; }
  table th, table td { padding: 6px 4px; word-wrap: break-word; overflow-wrap: break-word; white-space: nowrap; }
  #articlesList table { min-width: 700px; }
  #articlesList table th:first-child, #articlesList table td:first-child { width: 28px; }
  #lessonsList table { min-width: 0; }
  .flashcard-container { max-width: 100%; }
  .flashcard { padding: 32px 16px; min-height: 180px; }
  .flashcard .word { font-size: 24px; }
  .flashcard .meaning { font-size: 15px; }
  .flashcard-actions { flex-wrap: wrap; gap: 8px; }
  .flashcard-actions .btn { min-width: 0 !important; flex: 1; font-size: 12px; padding: 8px 6px; }
  .analysis-popup { width: calc(100vw - 16px) !important; left: 8px !important; max-width: none; }
  .modal { width: 95%; padding: 24px; }
  .article-reader { max-width: 100%; width: 100%; overflow: hidden; word-wrap: break-word; }
  .article-reader h2 { font-size: 20px; word-break: break-word; }
  .article-reader .content { font-size: 15px; overflow-wrap: break-word; width: 100%; padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  .article-reader .content p { text-indent: 0; }
  .article-reader table { table-layout: fixed; width: 100%; min-width: 0; font-size: 11px; }
  .article-reader table th, .article-reader table td { padding: 4px 3px; word-break: break-word; overflow: hidden; }
  table td[style*="nowrap"] { white-space: normal !important; }
  table td button { font-size: 11px; padding: 4px 6px; }
  #page-articles > div:first-child { flex-direction: column; gap: 12px; }
  #page-articles > div:first-child > div:last-child { width: 100%; }
  #page-articles > div:first-child > div:last-child .btn { flex: 1; text-align: center; }
  #page-article-detail > div:first-child { flex-wrap: wrap; gap: 6px; }
  #page-article-detail > div:first-child .btn { font-size: 12px; padding: 6px 10px; }
  .review-card { padding: 14px; }
  .tabs { overflow-x: auto; overflow-y: hidden; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; padding: 8px 12px; font-size: 13px; }
  .progress-bar { max-width: 60px; }
  pre, code { white-space: pre-wrap; word-break: break-all; max-width: 100%; overflow-x: hidden; }
  .popup-mode-card { display: none; }
  .theme-toggle { display: none; }
}

/* ── Page transitions ── */
.page { opacity: 0; transition: opacity .2s ease; }
.page.active { opacity: 1; }

/* ── Toast notifications ── */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 10000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; padding: 12px 20px; border-radius: 10px;
  font-size: 13px; font-weight: 500; box-shadow: 0 4px 20px rgba(0,0,0,.15);
  transform: translateX(120%); transition: transform .3s cubic-bezier(.4,0,.2,1), opacity .3s;
  opacity: 0; max-width: 360px; line-height: 1.5;
  display: flex; align-items: center; gap: 8px;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.hide { transform: translateX(120%); opacity: 0; }
.toast-success { background: var(--green); color: #fff; }
.toast-error { background: var(--red); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }

/* ── Search bar ── */
.search-bar {
  width: 100%; padding: 9px 14px 9px 36px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; background: var(--bg); color: var(--text);
  transition: border-color .2s, box-shadow .2s; font-family: var(--font-sans);
}
.search-bar:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.12); }
.search-bar::placeholder { color: var(--text2); }
.search-wrapper {
  position: relative; margin-bottom: 16px;
}
.search-wrapper::before {
  content: '🔍'; position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 14px; pointer-events: none; opacity: .5;
}

/* ── Sortable table headers ── */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable::after { content: '⇅'; opacity: .3; margin-left: 4px; font-size: 12px; }
th.sortable.asc::after { content: '↑'; opacity: .8; }
th.sortable.desc::after { content: '↓'; opacity: .8; }

/* ── Loading skeleton ── */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, transparent 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Dark mode toggle ── */
.theme-toggle {
  padding: 8px 24px; border: none; background: none;
  color: rgba(255,255,255,.5); cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 8px; width: 100%;
  transition: color .2s;
}
.theme-toggle:hover { color: rgba(255,255,255,.9); }

/* ── Scroll to top ── */
.scroll-top {
  position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%); width: 40px; height: 40px;
  border-radius: 50%; background: var(--accent); color: #fff; border: none;
  cursor: pointer; font-size: 18px; box-shadow: 0 2px 12px rgba(var(--accent-rgb),.3);
  opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s;
  z-index: 90; display: flex; align-items: center; justify-content: center;
}
.scroll-top.show { opacity: 1; pointer-events: auto; }
.scroll-top:hover { transform: translateX(-50%) translateY(-2px); }

/* ── Dark mode overrides ── */
[data-theme="dark"] .login-overlay { background: linear-gradient(145deg, #0a0a12 0%, #161620 50%, #0a0a12 100%); }
[data-theme="dark"] .login-card { box-shadow: 0 20px 60px rgba(0,0,0,.6); }
[data-theme="dark"] .soul-chat-input input { color: var(--text); background: var(--card); }
[data-theme="dark"] .soul-profile { background: linear-gradient(135deg, rgba(var(--accent-rgb),.1) 0%, var(--card) 100%); }
[data-theme="dark"] .modal { box-shadow: 0 20px 60px rgba(0,0,0,.5); }
[data-theme="dark"] .analysis-popup { box-shadow: 0 8px 30px rgba(0,0,0,.4); }
[data-theme="dark"] img { opacity: .9; }

/* ── Better hover on table rows ── */
[data-theme="dark"] tr:hover td { background: rgba(var(--accent-rgb),.06); }

/* ── Empty state polish ── */
.empty { user-select: none; }

/* ── Collection selection bar ── */
.collection-bar {
  display: none; position: sticky; top: 0; z-index: 50;
  background: var(--accent); color: #fff; padding: 10px 20px;
  border-radius: 10px; margin-bottom: 12px;
  align-items: center; gap: 12px; box-shadow: 0 4px 16px rgba(var(--accent-rgb),.3);
  font-size: 14px; font-weight: 500;
  animation: slideDown .2s ease;
}
.collection-bar.show { display: flex; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.collection-bar .bar-actions { margin-left: auto; display: flex; gap: 8px; }
.collection-bar .bar-actions .btn { background: rgba(255,255,255,.2); color: #fff; border: 1px solid rgba(255,255,255,.3); }
.collection-bar .bar-actions .btn:hover { background: rgba(255,255,255,.35); }
.collection-bar .bar-actions .btn-gen { background: #fff; color: var(--accent); font-weight: 700; border: none; }
.collection-bar .bar-actions .btn-gen:hover { background: #eef2ff; }
.article-checkbox {
  width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer;
  flex-shrink: 0; margin: 0;
}
/* ── Agent Page ── */
#page-agent.active {
  display: flex; flex-direction: column;
  height: calc(100vh - 72px); height: calc(100dvh - 72px);
}
.agent-page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-shrink: 0;
}
.agent-container {
  flex: 1; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; min-height: 0;
}

.agent-header-actions { display: flex; gap: 6px; }
.agent-header-actions button {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  width: 32px; height: 32px; cursor: pointer; color: var(--text2);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.agent-header-actions button:hover { background: var(--card); color: var(--text); }

.agent-messages {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.agent-welcome {
  text-align: center; color: var(--text2); font-size: 14px;
  padding: 60px 20px; line-height: 1.8;
}

.agent-msg { display: flex; flex-direction: column; }
.agent-msg.user { align-items: flex-end; }
.agent-msg.assistant { align-items: flex-start; }

.agent-bubble {
  max-width: 90%; padding: 10px 14px; border-radius: 12px;
  font-size: 14px; line-height: 1.7; word-break: break-word;
}
.agent-bubble.user-bubble { white-space: pre-wrap; }
.agent-bubble.user-bubble {
  background: var(--accent); color: #fff;
  border-bottom-right-radius: 4px;
}
.agent-bubble.assistant-bubble {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-bottom-left-radius: 4px;
}
.agent-bubble.assistant-bubble pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; overflow-x: auto; font-size: 13px; margin: 8px 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.agent-bubble.assistant-bubble code {
  background: var(--bg); padding: 1px 5px; border-radius: 3px;
  font-size: 13px; font-family: 'SF Mono', 'Fira Code', monospace;
}
.agent-bubble.assistant-bubble a { color: var(--accent); text-decoration: underline; }
.agent-bubble.assistant-bubble table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.agent-tool-indicator {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 8px;
  background: rgba(var(--accent-rgb),.08); color: var(--accent);
  font-size: 12px; max-width: 90%;
}
.agent-tool-indicator .spinner-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }

.agent-tool-result {
  max-width: 90%; padding: 6px 12px; border-radius: 8px;
  background: var(--card); border: 1px solid var(--border);
  font-size: 12px; color: var(--text2); cursor: pointer;
}
.agent-tool-result .tool-detail {
  display: none; margin-top: 6px; white-space: pre-wrap;
  max-height: 400px; overflow-y: auto; font-size: 12px; color: var(--text);
}
.agent-tool-result.expanded .tool-detail { display: block; }

.agent-file-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 6px; margin-top: 6px;
  background: rgba(16,185,129,.1); color: var(--green);
  font-size: 13px; text-decoration: none; border: 1px solid rgba(16,185,129,.2);
}
.agent-file-link:hover { background: rgba(16,185,129,.18); }

.agent-error {
  padding: 8px 12px; border-radius: 8px;
  background: rgba(239,68,68,.08); color: var(--red);
  font-size: 13px; max-width: 90%;
}

.agent-input-area {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-end;
  flex-shrink: 0;
}
.agent-attach-btn {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text2); font-size: 18px; flex-shrink: 0;
}
.agent-attach-btn:hover { background: var(--bg); color: var(--accent); }

.agent-input-wrapper { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.agent-attach-preview {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 6px;
  background: var(--card); border: 1px solid var(--border);
  font-size: 12px; color: var(--text2);
}
.agent-attach-preview img { width: 32px; height: 32px; border-radius: 4px; object-fit: cover; }
.agent-attach-preview .remove-attach {
  margin-left: auto; cursor: pointer; color: var(--text2); font-size: 14px;
}

#agentInput {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; resize: none;
  background: var(--bg); color: var(--text);
  font-family: inherit; line-height: 1.5;
  min-height: 36px; max-height: 120px;
}
#agentInput:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.1); }

#agentSendBtn {
  border-radius: 8px; padding: 8px 16px; font-size: 14px;
  flex-shrink: 0; height: 36px;
}

.agent-history-list { padding: 8px 0; }
.agent-history-item {
  padding: 10px 20px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.agent-history-item:hover { background: var(--card); }
.agent-history-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-history-item .meta { font-size: 11px; color: var(--text2); margin-left: 8px; white-space: nowrap; }
.agent-history-item .del-btn {
  margin-left: 8px; color: var(--red); cursor: pointer; font-size: 14px;
  opacity: 0; transition: opacity .2s;
}
.agent-history-item:hover .del-btn { opacity: 1; }

.agent-settings {
  padding: 16px 20px; font-size: 13px;
}
.agent-settings label { display: block; margin-bottom: 4px; color: var(--text2); font-size: 12px; }
.agent-settings select {
  width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font-size: 13px;
}

@media (max-width: 768px) {
  #page-agent.active, #page-sage.active { height: calc(100vh - 60px) !important; height: calc(100dvh - 60px) !important; }
}

/* ── Writing Practice ── */
.writing-editor { max-width: 720px; }

.writing-correction { margin-top: 20px; max-width: 720px; }
.correction-score {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 20px; border-radius: 10px;
  font-size: 24px; font-weight: 700; font-family: var(--font-serif);
}
.correction-score.good { background: #e6ffed; color: #1a7f3f; border: 1px solid #1a7f3f; }
[data-theme="dark"] .correction-score.good { background: rgba(26,127,63,.15); color: #3fb950; border-color: #3fb950; }
.correction-score.medium { background: #fff8e1; color: #b8860b; border: 1px solid #b8860b; }
[data-theme="dark"] .correction-score.medium { background: rgba(184,134,11,.15); color: #d4a017; border-color: #d4a017; }
.correction-score.bad { background: #ffeef0; color: #c53030; border: 1px solid #c53030; }
[data-theme="dark"] .correction-score.bad { background: rgba(197,48,48,.15); color: #f85149; border-color: #f85149; }

.correction-section { margin-top: 24px; }
.correction-section h3 {
  font-size: 15px; font-weight: 700; margin-bottom: 10px;
  color: var(--text); border-left: 3px solid var(--accent); padding-left: 10px;
}
.correction-item {
  padding: 10px 14px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; border-left: 3px solid var(--red);
}
.correction-item .ci-original { color: var(--red); text-decoration: line-through; font-size: 14px; }
.correction-item .ci-arrow { color: var(--text2); margin: 0 6px; }
.correction-item .ci-corrected { color: var(--green); font-weight: 600; font-size: 14px; }
.correction-item .ci-explanation { font-size: 12px; color: var(--text2); margin-top: 4px; }

.suggestion-item {
  padding: 10px 14px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; border-left: 3px solid var(--accent);
}
.suggestion-item .si-original { color: var(--text2); text-decoration: line-through; }
.suggestion-item .si-arrow { color: var(--text2); margin: 0 6px; }
.suggestion-item .si-new { color: var(--accent); font-weight: 600; }
.suggestion-item .si-reason { font-size: 12px; color: var(--text2); margin-top: 4px; }

.improved-version {
  padding: 16px; border-radius: 8px; margin-top: 8px;
  background: var(--accent-light); border: 1px solid var(--accent);
  line-height: 1.8; font-size: 14px; white-space: pre-wrap;
  color: var(--text);
}

.writing-history-item {
  padding: 14px 18px; border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 10px; cursor: pointer;
  transition: all .15s; background: var(--card);
}
.writing-history-item:hover { border-color: var(--accent); }
.writing-history-item .wh-title { font-weight: 600; font-size: 15px; }
.writing-history-item .wh-meta { font-size: 12px; color: var(--text2); margin-top: 4px; }
.writing-history-item .wh-score {
  font-size: 13px; font-weight: 700; font-family: var(--font-serif);
  padding: 2px 10px; border-radius: 12px; display: inline-block; margin-top: 6px;
}
.wh-score.high { background: #e6ffed; color: #1a7f3f; }
.wh-score.mid { background: #fff8e1; color: #b8860b; }
.wh-score.low { background: #ffeef0; color: #c53030; }
[data-theme="dark"] .wh-score.high { background: rgba(26,127,63,.2); color: #3fb950; }
[data-theme="dark"] .wh-score.mid { background: rgba(184,134,11,.2); color: #d4a017; }
[data-theme="dark"] .wh-score.low { background: rgba(197,48,48,.2); color: #f85149; }

/* ── Exercise UI ── */
.exercise-card { max-width: 680px; margin: 0 auto; }
.exercise-prompt {
  font-size: 16px; line-height: 1.8; margin-bottom: 16px;
  padding: 16px; background: var(--accent-light); border-radius: 8px;
  color: var(--text);
}
.exercise-hints {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px;
}
.exercise-hint {
  padding: 2px 10px; background: var(--bg); border-radius: 12px;
  font-size: 12px; color: var(--text2); font-family: monospace;
}
.exercise-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.exercise-option {
  padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; cursor: pointer; transition: all .15s;
  display: flex; align-items: center; gap: 8px; font-size: 14px;
}
.exercise-option:hover { border-color: var(--accent); }
.exercise-option.selected { border-color: var(--accent); background: var(--accent-light); }
.exercise-option input[type="radio"] { accent-color: var(--accent); }

.exercise-textarea {
  width: 100%; min-height: 120px; padding: 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; resize: vertical; font-family: var(--font-sans); line-height: 1.6;
  background: var(--card); color: var(--text);
}

.exercise-result { margin-top: 20px; max-width: 680px; }
.exercise-result .result-card {
  padding: 16px; border-radius: 10px; margin-bottom: 12px;
}
.exercise-result .result-card.correct {
  border: 1px solid #1a7f3f; background: #e6ffed;
}
.exercise-result .result-card.incorrect {
  border: 1px solid #c53030; background: #ffeef0;
}
[data-theme="dark"] .exercise-result .result-card.correct { background: rgba(26,127,63,.15); border-color: #3fb950; }
[data-theme="dark"] .exercise-result .result-card.incorrect { background: rgba(197,48,48,.15); border-color: #f85149; }
.exercise-result .result-score {
  font-size: 20px; font-weight: 700; font-family: var(--font-serif); margin-bottom: 8px;
}
.exercise-result .result-comment { font-size: 14px; line-height: 1.7; white-space: pre-wrap; color: var(--text); }
.exercise-result .result-suggested {
  margin-top: 12px; padding: 12px; border-radius: 6px;
  background: var(--accent-light); font-size: 14px; line-height: 1.6;
  white-space: pre-wrap; color: var(--text);
}

.gen-status { display: flex; align-items: center; gap: 10px; margin-top: 10px; }

/* ── Error Notebook ── */
.weak-stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.weak-stats-grid .stat-card {
  padding: 16px; border-radius: 10px; background: var(--card);
  border: 1px solid var(--border);
}
.weak-stats-grid .stat-card h4 {
  font-size: 14px; font-weight: 700; margin-bottom: 10px; color: var(--text);
}
.weak-category-item {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px;
}
.weak-category-item .wc-label { flex: 1; color: var(--text); }
.weak-category-item .wc-weight {
  font-size: 14px; font-weight: 700; color: var(--accent); min-width: 28px; text-align: right;
}
.weak-category-bar {
  height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; flex: 0 0 60px;
}
.weak-category-bar .wc-fill {
  height: 100%; border-radius: 3px; background: var(--accent); transition: width .3s;
}
.weak-word-tag {
  display: inline-block; padding: 2px 10px; margin: 2px 4px 2px 0;
  border-radius: 12px; font-size: 12px;
  background: var(--accent-light); color: var(--accent); font-family: monospace;
}
.resolved-item {
  font-size: 13px; color: var(--text2); padding: 4px 0;
  display: flex; align-items: center; gap: 6px;
}
.resolved-item .resolved-icon { color: var(--green); }

.error-record-item {
  padding: 14px 16px; border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 10px; background: var(--card);
  border-left: 3px solid var(--red); transition: all .15s;
}
.error-record-item.record-correct { border-left-color: var(--green); }
.error-record-item .er-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap;
}
.error-record-item .er-type {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: var(--accent-light); color: var(--accent); font-weight: 600;
}
.error-record-item .er-correct-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600;
  background: #e6ffed; color: #1a7f3f;
}
[data-theme="dark"] .error-record-item .er-correct-badge { background: rgba(26,127,63,.2); color: #3fb950; }
.error-record-item .er-meta { font-size: 11px; color: var(--text2); margin-left: auto; }
.error-record-item .er-exercise { font-size: 13px; color: var(--text); margin-bottom: 6px; line-height: 1.6; }
.error-record-item .er-answers {
  font-size: 12px; display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 6px;
}
.error-record-item .er-answer-label { color: var(--text2); }
.error-record-item .er-answer-user { color: var(--red); }
.error-record-item .er-answer-correct { color: var(--green); }
.error-record-item .er-error-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.er-error-tag {
  font-size: 11px; padding: 1px 8px; border-radius: 10px;
  background: var(--red); color: #fff;
}
[data-theme="dark"] .er-error-tag { background: rgba(248,81,73,.3); color: #f85149; }
.error-record-item .er-delete {
  float: right; background: none; border: none; color: var(--text2);
  cursor: pointer; font-size: 16px; padding: 0 4px; opacity: .5; transition: opacity .15s;
}
.error-record-item .er-delete:hover { opacity: 1; color: var(--red); }

.targeted-toggle { display: flex; align-items: center; gap: 8px; }

/* ── Mobile: Writing & Exercise ── */
@media (max-width: 768px) {
  .writing-editor, .writing-correction, .exercise-card, .exercise-result { max-width: 100%; }
  .writing-editor textarea { height: 200px; }
  .exercise-card .exercise-prompt { font-size: 15px; padding: 12px; }
  .weak-stats-grid { grid-template-columns: 1fr; }
  .error-record-item .er-header { flex-direction: column; align-items: flex-start; }
  .error-record-item .er-meta { margin-left: 0; }
  .exercise-result .result-card { padding: 12px; }
  /* flex pages on mobile: slightly less height to account for smaller viewport */
}

/* ── Warden / 羽林卫 ── */
#page-warden.active { display: block; }
.warden-shell {
  max-width: 1180px; margin: 0 auto; padding: 4px 0 40px;
}
.warden-topbar {
  display: flex; align-items: center; gap: 14px; margin-bottom: 18px;
}
.warden-brand { flex: 1; min-width: 0; }
.warden-title {
  font-family: var(--font-serif); font-size: 26px; font-weight: 700;
  line-height: 1.2; color: var(--text);
}
.warden-subtitle { color: var(--text2); font-size: 13px; margin-top: 3px; }
.warden-stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px; margin-bottom: 16px;
}
.warden-stats .stat-card { padding: 18px 14px; }
.warden-stats .stat-card .num {
  font-size: 24px; min-height: 36px; display: flex; align-items: center; justify-content: center;
}
.warden-layout {
  display: grid; grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr);
  gap: 16px; align-items: start;
}
.warden-column { min-width: 0; }
.warden-column .card h3 { margin-bottom: 12px; font-size: 16px; }
.warden-status {
  padding: 10px 12px; margin-bottom: 14px; border-radius: 8px;
  background: var(--accent-light); color: var(--accent);
  font-size: 13px; font-weight: 600;
}
.warden-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.warden-actions .btn { min-height: 38px; }
.warden-reveal {
  margin-top: 12px; padding: 12px; border-radius: 8px;
  background: var(--yellow-light); color: var(--yellow);
  border: 1px solid rgba(217,119,6,.25); font-size: 13px; line-height: 1.6;
}
.warden-form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.warden-form-grid .form-group { margin-bottom: 0; }
.warden-compliance { display: flex; flex-direction: column; gap: 10px; }
.warden-compliance-item {
  display: grid; grid-template-columns: 12px minmax(0, 1fr);
  gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border);
}
.warden-compliance-item:last-child { border-bottom: none; }
.warden-dot {
  width: 10px; height: 10px; border-radius: 50%; margin-top: 6px;
  background: var(--text2);
}
.warden-dot.required { background: var(--red); }
.warden-dot.ready { background: var(--green); }
.warden-item-title { font-weight: 700; font-size: 14px; color: var(--text); }
.warden-item-detail { color: var(--text2); font-size: 12px; line-height: 1.7; margin-top: 2px; }
.warden-chart {
  height: 190px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px; align-items: end; padding: 8px 0 2px;
}
.warden-bar-wrap {
  height: 100%; min-width: 0; display: flex; flex-direction: column; align-items: center;
}
.warden-bar-value { height: 22px; font-size: 12px; color: var(--text2); }
.warden-bar-track {
  flex: 1; width: 100%; max-width: 34px; display: flex; align-items: flex-end;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.warden-bar {
  width: 100%; min-height: 6px; background: var(--accent);
  border-radius: 7px 7px 0 0; transition: height .2s ease;
}
.warden-bar-label { margin-top: 6px; font-size: 11px; color: var(--text2); white-space: nowrap; }
.warden-device-breakdown { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.warden-chip {
  display: inline-flex; align-items: center; min-height: 24px; padding: 2px 10px;
  border-radius: 12px; background: var(--accent-light); color: var(--accent);
  font-size: 12px; font-weight: 600;
}
.warden-muted { color: var(--text2); font-size: 13px; }
.warden-list { display: flex; flex-direction: column; gap: 8px; }
.warden-list .empty { padding: 24px; }
.warden-list-item {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card);
}
.warden-list-main {
  color: var(--text); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere;
}
.warden-list-meta { color: var(--text2); font-size: 11px; margin-top: 3px; }

/* DNS dual-bar chart */
.warden-bar-dual { position: relative; }
.warden-bar-dual .warden-bar { position: absolute; bottom: 0; left: 0; right: 0; border-radius: 0; }
.warden-bar-q { background: var(--accent); opacity: .45; }
.warden-bar-b { background: var(--red); opacity: .7; min-height: 2px !important; }

/* DNS section */
.warden-section-title { font-size: 12px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.warden-dns-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.warden-chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.warden-instant-card { border-left: 3px solid var(--red); }
/* category tags */
.warden-tag { display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 8px; margin-left: 6px; vertical-align: middle; font-weight: 600; }
.warden-tag-短视频 { background: #fde8e8; color: #c62828; }
.warden-tag-视频号 { background: #fde8e8; color: #c62828; }
.warden-tag-视频 { background: #fff3e0; color: #e65100; }
.warden-tag-社媒 { background: #e8f5e9; color: #2e7d32; }
.warden-tag-游戏 { background: #e3f2fd; color: #1565c0; }
.warden-tag-占卜 { background: #f3e5f5; color: #6a1b9a; }
.warden-tag-色情 { background: #fce4ec; color: #880e4f; }
.warden-tag-其他 { background: #eceff1; color: #546e7a; }
@media (prefers-color-scheme: dark) {
  .warden-tag-短视频, .warden-tag-视频号 { background: #4a1a1a; color: #ef9a9a; }
  .warden-tag-视频 { background: #4a2a10; color: #ffcc80; }
  .warden-tag-社媒 { background: #1a3a1a; color: #a5d6a7; }
  .warden-tag-游戏 { background: #1a2a3a; color: #90caf9; }
  .warden-tag-占卜 { background: #2a1a3a; color: #ce93d8; }
  .warden-tag-色情 { background: #3a1a2a; color: #f48fb1; }
  .warden-tag-其他 { background: #263238; color: #90a4ae; }
}
@media (max-width: 600px) { .warden-dns-grid { grid-template-columns: 1fr; } }

@media (max-width: 900px) {
  .warden-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .warden-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  body.in-warden .main.main-full { padding: 16px; padding-top: 50px; }
  .warden-topbar { align-items: flex-start; }
  .warden-title { font-size: 22px; }
  .warden-subtitle { font-size: 12px; line-height: 1.5; }
  .warden-stats { gap: 8px; }
  .warden-stats .stat-card { padding: 12px 8px; }
  .warden-stats .stat-card .num { font-size: 20px; }
  .warden-form-grid { grid-template-columns: 1fr; }
  .warden-actions .btn { flex: 1; justify-content: center; padding-left: 10px; padding-right: 10px; }
  .warden-chart { gap: 6px; height: 170px; }
  .warden-bar-track { max-width: 28px; }
}

/* ── 备考驾驶舱条 ── */
.kaoyan-dashboard-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 10px 16px;
  margin-bottom: 24px;
  background: var(--card);
  border-radius: 12px;
  font-size: 13px;
  color: var(--text2);
  line-height: 1.6;
}
.kaoyan-db-countdown {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  white-space: nowrap;
}
.kaoyan-db-sep {
  color: var(--border);
  font-size: 13px;
}
.kaoyan-db-item {
  white-space: nowrap;
}
.kaoyan-db-item strong {
  color: var(--text);
  font-weight: 700;
}
@media (max-width: 600px) {
  .kaoyan-dashboard-bar {
    font-size: 12px;
    padding: 8px 12px;
    margin-bottom: 16px;
    gap: 2px 6px;
  }
  .kaoyan-db-countdown { font-size: 14px; }
}
