:root {
  --bg: #faf8f3;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --border: #e5e7eb;
  --warn: #f59e0b;
  --danger: #ef4444;
  --site-header-height: 40px;
  --serif: Georgia, "Times New Roman", "Songti SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.nav {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
header.nav .brand { font-weight: 700; font-size: 18px; }
header.nav a { color: var(--ink); }
header.nav a.active { color: var(--accent); font-weight: 600; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}

/* --- Library layout: sidebar + main content --- */
/* 试题库页外壳: body 取满视口高并禁止自身滚动, header 取自然高度,
   .layout 填充剩余空间 => 页面级永不出现滚动条, 滚动只发生在内容列 */
body.app-shell { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  width: 56px;
  border-right: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.22s ease;
}
.sidebar.expanded { width: 280px; }
.sidebar:not(.expanded) .sidebar-body { display: none; }

/* 折叠按钮: 图标 + 数值(居中) + 标签 */
.sidebar-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  padding: 14px 0 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: #f3f4f6; }
.toggle-icon { font-size: 20px; line-height: 1; }
.toggle-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.toggle-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: opacity 0.2s ease, max-height 0.2s ease;
}
.sidebar.expanded .toggle-label { max-height: 20px; opacity: 1; }
.sidebar-body { flex: 1; overflow-y: auto; }
.sidebar-title {
  padding: 14px 16px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
}
.nav-list { list-style: none; margin: 0; padding: 6px 0; }
.nav-list > li { margin: 0; }
.nav-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
  user-select: none;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
}
.nav-group-header:hover { background: #f3f4f6; }
.nav-group-header .chev {
  font-size: 10px;
  transition: transform 0.2s;
  color: var(--muted);
  width: 12px;
  display: inline-block;
}
.nav-group.collapsed > ul { display: none; }
.nav-group.collapsed > .nav-group-header .chev { transform: rotate(-90deg); }

.nav-subgroup-header {
  padding: 6px 16px 6px 30px;
  font-weight: 600;
  font-size: 13px;
  color: #374151;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-subgroup-header:hover { background: #f3f4f6; }
.nav-subgroup-header .chev {
  font-size: 10px;
  transition: transform 0.2s;
  color: var(--muted);
  width: 12px;
  display: inline-block;
}
.nav-subgroup.collapsed > ul { display: none; }
.nav-subgroup.collapsed > .nav-subgroup-header .chev { transform: rotate(-90deg); }

.nav-item {
  display: block;
  padding: 7px 16px 7px 48px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  border-left: 3px solid transparent;
  text-decoration: none;
}
.nav-item:hover { background: #eef2ff; }
.nav-item.active {
  background: #dbeafe;
  color: var(--accent-dark);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* 导航里“已做过”的 ✅ 标记 */
.nav-done {
  margin-left: 6px;
  font-size: 11px;
  vertical-align: middle;
}

/* 导航内的阅读/写作分类小标签 */
.nav-cat-label {
  padding: 6px 16px 2px 40px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: uppercase;
}

.sidebar-empty {
  padding: 24px 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.content-area {
  flex: 1;
  overflow: hidden;
  display: flex;
  justify-content: center;
}
.content-area .content-inner {
  max-width: 880px;
  width: 100%;
  overflow-y: auto;
  padding: 28px 40px;
}
.content-empty {
  text-align: center;
  padding: 100px 20px;
  color: var(--muted);
}
.content-empty .big { font-size: 48px; margin-bottom: 16px; }
.content-empty h2 { color: var(--ink); margin-bottom: 8px; }

/* Top right actions */
.top-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.llm-status { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 10px; font-size: 12px; }
.llm-status.ok { background: #d1fae5; color: #065f46; }
.llm-status.missing { background: #fee2e2; color: #b91c1c; }

/* Modal */
.modal-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1000;
  justify-content: center;
  align-items: flex-start;
  padding-top: 80px;
}
.modal-mask.show { display: flex; }
.modal {
  width: 560px;
  max-width: 94vw;
  max-height: calc(100vh - 120px);
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: #f3f4f6; color: var(--ink); }
.modal-body { padding: 20px; overflow-y: auto; }

.tabbar-inline { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tabbar-inline .tab { padding: 8px 16px; cursor: pointer; border-radius: 6px 6px 0 0; font-weight: 600; color: var(--muted); font-size: 14px; }
.tabbar-inline .tab.active { background: var(--card); color: var(--ink); border: 2px solid var(--border); border-bottom-color: transparent; margin-bottom: -2px; }
.tabbar-inline .tab:hover:not(.active) { background: #f3f4f6; }

.progress-box { margin-top: 14px; padding: 16px; background: #f9fafb; border-radius: 8px; border: 1px solid var(--border); display: none; }
.progress-box.active { display: block; }
.progress-bar-wrap { background: #e5e7eb; border-radius: 10px; height: 22px; overflow: hidden; margin-top: 8px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 10px; transition: width 0.4s ease; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #fff; font-weight: 600; min-width: 30px; }
.progress-msg { font-size: 14px; margin-top: 8px; }
.stage-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.stage-badge.ocr { background: #dbeafe; color: #1e40af; }
.stage-badge.splitting { background: #fef3c7; color: #92400e; }
.stage-badge.formatting { background: #e9d5ff; color: #6b21a8; }
.stage-badge.done { background: #d1fae5; color: #065f46; }
.stage-badge.partial { background: #fef3c7; color: #b45309; }
.stage-badge.blocked { background: #fee2e2; color: #b91c1c; }
.stage-badge.error { background: #fee2e2; color: #b91c1c; }
.stage-badge.queued { background: #f3f4f6; color: #6b7280; }
.stage-badge.init { background: #e0f2fe; color: #075985; }
.stage-badge.toc { background: #fce7f3; color: #9d174d; }
.stage-badge.extracting { background: #cffafe; color: #155e75; }
.stage-badge.fallback_ocr { background: #dbeafe; color: #1e40af; }
.stage-badge.processing { background: #e0f2fe; color: #075985; }
.stage-badge.cancelled { background: #f3f4f6; color: #6b7280; text-decoration: line-through; }
.stage-badge.lost { background: #f3f4f6; color: #9ca3af; }

/* Reader */
.reader-meta {
  font-size: 13px;
  color: var(--muted);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.reader-meta a { color: var(--accent); }
.reader-meta .actions { display: inline-flex; gap: 8px; margin-left: 12px; }
.reader-meta .actions button { font-size: 12px; padding: 3px 10px; }

.tabbar { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabbar .tab { padding: 8px 16px; cursor: pointer; border-radius: 6px 6px 0 0; font-weight: 600; color: var(--muted); }
.tabbar .tab.active { background: var(--card); color: var(--ink); border: 2px solid var(--border); border-bottom-color: transparent; margin-bottom: -2px; }
.tabbar .tab:hover:not(.active) { background: #f3f4f6; }
.panel { display: none; }
.panel.active { display: block; }

.p-section { padding: 14px 0; border-bottom: 1px dashed var(--border); }
.p-section:last-child { border-bottom: none; }
.p-section .stitle { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.p-section .sbody { font-family: var(--serif); font-size: 17px; line-height: 1.85; }

.q-card { border-left: 4px solid var(--accent); padding: 10px 14px; background: #f9fafb; border-radius: 0 8px 8px 0; margin-bottom: 14px; }
.q-num { display: inline-block; background: var(--accent); color: #fff; padding: 2px 8px; border-radius: 10px; font-weight: 700; margin-right: 8px; }
.q-type { color: var(--muted); font-size: 12px; }
.q-opts { margin-top: 6px; }
/* 题组(忠实复刻原书): 每组一个块, 组标题突出 */
.q-set { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px dashed var(--border); }
.q-set:last-child { border-bottom: none; }
.q-set h3 { font-size: 15px; color: var(--accent); margin: 14px 0 8px; }
.q-set h3:first-child { margin-top: 0; }
.q-set table { margin: 10px 0; }
/* 题组内的图(流程图/示意图题图): 加更明显的边框+浅色底, 与正文插图区分 */
.q-set .md-img img { border: 2px solid var(--accent); background: #f6f8fb; padding: 4px; }
.q-opts .opt { padding: 2px 0; }
.q-opts .opt .opt-key { font-weight: 700; display: inline-block; min-width: 24px; }
details.answerbox { margin-top: 10px; }
details.answerbox > summary { cursor: pointer; color: var(--accent); font-size: 13px; list-style: none; }
details.answerbox > summary::before { content: "▶ "; font-size: 11px; }
details.answerbox[open] > summary::before { content: "▼ "; }
.q-answer { margin-top: 6px; padding: 8px 12px; background: #ecfdf5; border-radius: 6px; color: #065f46; font-size: 14px; }
.q-answer b { color: var(--accent-dark); }
.a-section .abody { white-space: pre-wrap; font-family: var(--serif); font-size: 16px; line-height: 1.9; }

/* Popup word lookup (for library page reader) */
#reader-popup {
  position: absolute;
  z-index: 50;
  max-width: 360px;
  min-width: 240px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 14px 16px;
  display: none;
  font-size: 14px;
}
#reader-popup .pw { font-size: 18px; font-weight: 700; }
#reader-popup .pp { color: var(--muted); margin-left: 8px; font-style: italic; }
#reader-popup .pcount { margin-top: 4px; font-size: 12px; }
#reader-popup .pdef { margin-top: 8px; }
#reader-popup .pdef .pos { color: var(--accent); font-style: italic; font-size: 12px; }
#reader-popup .pdef .ex { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
#reader-popup .ploading { color: var(--muted); }
#reader-popup .pnone { color: var(--danger); font-size: 13px; }
#reader-popup .pclose { position: absolute; top: 6px; right: 10px; cursor: pointer; color: var(--muted); }

/* --- 左文右题分栏 --- */
/* 桌面端: content-inner 不滚动, 原文/题目两栏各自独立滚动, 页面最右侧不出现滚动条 */
.content-area .content-inner:has(.split-view) {
  max-width: 1440px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.content-area .content-inner:has(.split-view) #rdContainer {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.split-view {
  display: flex;
  gap: 32px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}
.split-article {
  flex: 1.25;
  min-width: 0;
  overflow-y: auto;
  padding-right: 8px;
}
.split-questions {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding-right: 4px;
}
.sq-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 14px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}
@media (max-width: 980px) {
  /* 窄屏: 上下堆叠, 恢复整页单滚动条 */
  .content-area .content-inner:has(.split-view) { display: block; overflow-y: auto; }
  .content-area .content-inner:has(.split-view) #rdContainer { display: block; flex: none; }
  .split-view { flex-direction: column; flex: none; }
  .split-article, .split-questions { overflow: visible; padding-right: 0; }
}

/* --- 阅读答题框 + 批改结果 --- */
input.ans-input {
  display: inline-block;
  width: 110px !important;
  margin: 0 4px;
  padding: 3px 8px !important;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  border: none !important;
  border-bottom: 1.5px solid var(--accent);
  background: rgba(59,130,246,.06);
  border-radius: 4px 4px 0 0;
  box-sizing: border-box;
  vertical-align: baseline;
}
.ans-input:focus { outline: none; background: rgba(59,130,246,.12); }
input.ans-input.blank { width: 96px !important; }
.ans-row-h { margin: 2px 0 10px; }
.diagram-answer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px 14px;
  margin: 14px 0 22px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}
.diagram-answer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.diagram-answer-item .ans-input { flex: 1; width: auto !important; min-width: 80px; }
.ans-input.correct { border-bottom-color: #16a34a; background: rgba(22,163,74,.10); color: #15803d; font-weight: 600; }
.ans-input.wrong { border-bottom-color: #dc2626; background: rgba(220,38,38,.08); color: #b91c1c; }
.ans-input:disabled { cursor: default; }
.ans-tag {
  display: inline-block;
  margin: 0 4px;
  padding: 1px 7px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  vertical-align: baseline;
  white-space: nowrap;
}
.ans-tag.ok { color: #15803d; background: rgba(22,163,74,.12); }
.ans-tag.no { color: #b91c1c; background: rgba(220,38,38,.10); }
.grade-summary {
  margin: 0 0 14px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
}
.grade-summary b { color: #0369a1; font-size: 16px; }

/* --- 写作题目排版: 一般性描述弱化 + 选项清单列表化 --- */
.writing-body p { margin-bottom: 10px; }
.w-instruction { color: var(--muted); font-size: 13.5px; margin-bottom: 6px; }
.writing-body ul { margin: 4px 0 12px; padding-left: 26px; }
.writing-body li { margin-bottom: 3px; }

/* --- 口语练习模块 --- */
.speak-nav-actions { display: flex; gap: 6px; padding: 10px 12px 4px; }
.speak-part-title { font-size: 13px; font-weight: 700; color: var(--accent-dark); padding: 10px 16px 4px; }
.nav-topic-title { font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 16px 2px 28px; }
.speak-nav-item { padding-left: 40px; }
.q-phase-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  font-size: 10px; font-weight: 700; color: #fff;
  margin-right: 6px; vertical-align: 1px; background: #94a3b8;
}
.q-phase-badge.p1 { background: #3b82f6; }
.q-phase-badge.p2 { background: #f59e0b; }
.q-phase-badge.p3 { background: #10b981; }

.speak-practice { max-width: 860px; margin: 0 auto; padding: 24px 8px 80px; }
.q-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.part-badge {
  font-size: 12px; font-weight: 700; color: #fff;
  padding: 4px 12px; border-radius: 999px; white-space: nowrap;
}
.part-badge.part-1 { background: #3b82f6; }
.part-badge.part-2 { background: #8b5cf6; }
.part-badge.part-3 { background: #f59e0b; }
.topic-tag {
  font-size: 12px; font-weight: 600; color: var(--accent-dark);
  background: #eef2ff; border: 1px solid #c7d2fe;
  padding: 3px 10px; border-radius: 999px;
}
.q-text {
  font-family: var(--serif); font-size: 19px; line-height: 1.7;
  background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 0 10px 10px 0; padding: 16px 20px; margin-bottom: 14px;
}
.cue-card {
  background: #fefce8; border: 1px solid #fde68a; border-radius: 10px;
  padding: 12px 16px; margin-bottom: 16px;
}
.cue-title { font-size: 13px; font-weight: 700; color: #92400e; margin-bottom: 6px; }
.cue-body { font-size: 14px; line-height: 1.7; color: #78350f; }

.phase-selector { display: flex; gap: 10px; margin: 18px 0; }
.phase-btn {
  flex: 1; padding: 10px 8px; border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--card);
  font-size: 14px; font-weight: 700; color: var(--ink);
  cursor: pointer; line-height: 1.4; transition: all .15s;
}
.phase-btn .phase-sub { display: block; font-size: 11px; font-weight: 500; color: var(--muted); margin-top: 3px; }
.phase-btn:hover { border-color: var(--accent); }
.phase-btn.active { border-color: var(--accent); background: #eff6ff; color: var(--accent-dark); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.phase-btn.active .phase-sub { color: var(--accent); }

.answer-label { font-size: 14px; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
.retell-hint {
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: 10px;
  padding: 14px 16px; font-size: 14px; line-height: 1.7; color: #9a3412; margin: 16px 0;
}
.record-area {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin: 16px 0;
}
.rec-time { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); min-width: 52px; }
#btnRecord.recording { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; }
.speak-actions { display: flex; gap: 10px; margin: 16px 0; }
.transcript-area { margin: 4px 0 8px; }
.transcript-box { min-height: 96px; font-size: 14px; background: #f0fdf4; border-color: #bbf7d0; }

/* --- 写作答题框 + AI 批改结果 --- */
.essay-box {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.7;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-sizing: border-box;
}
.essay-box:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.essay-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0 16px;
}
.fb-error { color: var(--danger); padding: 10px 0; font-size: 14px; }
.fb-scores {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
}
.score-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
  padding: 6px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 11px;
  color: var(--muted);
}
.score-chip b { font-size: 17px; color: var(--ink); margin-top: 2px; }
.score-chip.overall { background: var(--accent); border-color: var(--accent); color: rgba(255,255,255,.85); }
.score-chip.overall b { color: #fff; }
.fb-block { margin-bottom: 14px; }
.fb-block-title { font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.fb-list { list-style: none; margin: 0; padding: 0; }
.fb-list li {
  padding: 8px 10px;
  font-size: 13.5px;
  line-height: 1.6;
  border-left: 3px solid var(--border);
  background: #fafafa;
  border-radius: 0 8px 8px 0;
  margin-bottom: 6px;
}
.fb-list s { color: var(--danger); text-decoration-color: rgba(220,38,38,.5); }
.fb-list b.good { color: #16a34a; }
.fb-note {
  font-size: 13.5px;
  line-height: 1.8;
  padding: 10px 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  white-space: pre-wrap;
}
/* --- 口语 8 分提升版答案 --- */
.b8-block {
  padding: 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
}
.b8-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.b8-title button { flex: 0 0 auto; }
.fb-b8 {
  font-size: 14px;
  line-height: 1.95;
  color: var(--ink);
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
}
.b8-meta { font-size: 11.5px; margin-top: 4px; text-align: right; }
.b8-sub { margin-top: 10px; }
.b8-note {
  margin-top: 8px;
  background: #ecfdf5;
  border-color: #a7f3d0;
}
details.essay-history { margin-top: 8px; }
details.essay-history > summary { cursor: pointer; color: var(--accent); font-size: 13px; list-style: none; }
details.essay-history > summary::before { content: "▶ "; font-size: 11px; }
details.essay-history[open] > summary::before { content: "▼ "; }
.eh-item { padding: 10px 0; border-bottom: 1px dashed var(--border); }
.eh-item:last-child { border-bottom: none; }
.eh-head { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 4px; }
.eh-essay { font-size: 12.5px; color: var(--muted); line-height: 1.6; }

/* --- 高亮 / 划线 --- */
.hl {
  background: #fef08a;
  border-radius: 2px;
  padding: 0 1px;
  box-shadow: 0 0 0 1px #fde047 inset;
}
.ul {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

/* 选中文字后的高亮/划线工具栏 */
#selToolbar {
  position: absolute;
  z-index: 60;
  display: none;
  gap: 4px;
  background: #1f2328;
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.28);
}
#selToolbar button {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
#selToolbar button:hover { background: #374151; }


.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
}

h1, h2, h3 { line-height: 1.3; }
h1 { font-size: 24px; margin-top: 0; }
h2 { font-size: 20px; }

input[type=text], input[type=file], select {
  font: inherit;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  width: 100%;
}
button, .btn {
  font: inherit;
  padding: 8px 18px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button.ghost { background: transparent; color: var(--accent); }
button.danger { border-color: var(--danger); background: var(--danger); }
button.small { padding: 4px 10px; font-size: 13px; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.muted { color: var(--muted); }
.spacer { height: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}
.tag.hot { background: #fee2e2; color: #b91c1c; }
.tag.warm { background: #fef3c7; color: #92400e; }
.tag.cool { background: #dbeafe; color: #1e40af; }
.tag.known { background: #d1fae5; color: #065f46; }

/* Reading view */
.passage-title { font-size: 26px; margin-bottom: 4px; }
.passage-meta { color: var(--muted); font-size: 13px; margin-bottom: 24px; }

.article {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.85;
}
.article p { margin: 0 0 1.1em; }
.article h1, .article h2, .article h3 { font-family: var(--sans); margin: 1.4em 0 0.6em; }
.article hr { border: none; border-top: 1px dashed var(--border); margin: 2em 0; }
.article ul, .article ol { margin: 0 0 1.1em 1.5em; }

/* Inline word markers */
.kw {
  border-bottom: 2px solid var(--warn);
  cursor: help;
}
.kw.hot {
  background: #fef3c7;
  border-bottom-color: var(--danger);
  font-weight: 600;
}
.kw.known { color: var(--muted); border-bottom: 1px dotted var(--muted); }

/* Lookup popup */
#popup {
  position: absolute;
  z-index: 50;
  max-width: 360px;
  min-width: 240px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 14px 16px;
  display: none;
  font-size: 14px;
}
#popup .pw { font-size: 18px; font-weight: 700; }
#popup .pp { color: var(--muted); margin-left: 8px; font-style: italic; }
#popup .pcount { margin-top: 4px; font-size: 12px; }
#popup .pdef { margin-top: 8px; }
#popup .pdef .pos { color: var(--accent); font-style: italic; font-size: 12px; }
#popup .pdef .ex { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
#popup .ploading { color: var(--muted); }
#popup .pnone { color: var(--danger); font-size: 13px; }
#popup .pclose { position: absolute; top: 6px; right: 10px; cursor: pointer; color: var(--muted); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2328;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 100;
}
.toast.show { opacity: 1; }

/* --- 右下角后台任务浮岛 --- */
.task-dock {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 320px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.14);
  z-index: 200;
  overflow: hidden;
  animation: dock-in 0.25s ease;
}
@keyframes dock-in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.task-dock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #f3f4f6;
  border-bottom: 1px solid var(--border);
}
.task-dock-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}
.task-dock-close {
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
}
.task-dock-close:hover { background: #e5e7eb; }
.task-dock-body {
  max-height: 0;              /* 默认折叠, 仅显示标题栏 */
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
  padding: 0 14px;
}
.task-dock:hover .task-dock-body {
  max-height: 340px;          /* 鼠标悬停展开文件列表 */
  overflow-y: auto;
  padding: 10px 14px;
}
.dock-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 2px;
}
.dock-item {
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.dock-item:last-child { border-bottom: none; }
.dock-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.dock-item-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.dock-item-bar { margin-top: 6px; height: 16px; }
.dock-item-bar .progress-bar { font-size: 10px; min-width: 26px; }
.dock-item-msg {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dock-item-err { color: #b91c1c; }
/* 任务行操作按钮(取消/删除) */
.dock-item-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--muted);
  flex-shrink: 0;
  white-space: nowrap;
}
.dock-item-btn:hover { background: #e5e7eb; color: #374151; }
.dock-item-btn.cancel:hover { background: #fef3c7; color: #b45309; }
.dock-item-btn.delete:hover { background: #fee2e2; color: #b91c1c; }

/* ============= 知识库页面 (words.html) ============= */
main.kb-page { max-width: 1080px; padding: 16px 24px 40px; }
.kb-control-card { padding: 16px 18px; }
.kb-overview { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.kb-heading h1 { margin: 0; font-size: 21px; }
.kb-stats { margin-top: 3px; font-size: 13px; color: var(--muted); }
.kb-tabs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.kb-tab { border: 0; background: transparent; padding: 7px 10px; cursor: pointer; border-radius: 7px; font-weight: 600; color: var(--muted); font-size: 13px; }
.kb-tab.active { color: var(--accent); background: #eff6ff; }
.kb-tab:hover:not(.active) { background: #f3f4f6; color: var(--ink); }
.kb-tab-count { font-size: 12px; color: var(--muted); font-weight: 400; }
.kb-toolbar { display: flex; gap: 8px; align-items: center; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.kb-toolbar input { flex: 1; min-width: 180px; height: 36px; padding: 6px 10px; }
.kb-toolbar select { width: 142px; height: 36px; padding: 6px 28px 6px 10px; }
.kb-actions { display: flex; gap: 6px; }
.kb-actions button { height: 36px; padding: 5px 10px; white-space: nowrap; }
.kb-empty { min-height: 132px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; }
.kb-empty-icon { font-size: 24px; margin-bottom: 4px; }
.kb-empty p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
@media (max-width: 760px) {
  main.kb-page { padding: 12px 12px 32px; }
  .kb-control-card { padding: 14px; }
  .kb-overview { align-items: flex-start; flex-direction: column; gap: 10px; }
  .kb-toolbar { flex-wrap: wrap; }
  .kb-toolbar input { flex: 1 1 100%; }
  .kb-toolbar select { flex: 1; }
  .kb-actions { width: 100%; }
  .kb-actions button { flex: 1; padding: 5px 6px; font-size: 12px; }
}

/* 词根分组卡片 */
.w-group { padding: 16px 20px; }
.w-group.by-root { border-left: 4px solid #10b981; }
.w-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 10px;
}
.root-meaning { color: #059669; font-size: 13px; font-weight: 400; }
.w-group-count { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 400; }

.w-row { display: flex; align-items: flex-start; gap: 12px; padding: 8px 0; border-bottom: 1px solid #f3f4f6; }
.w-row:last-child { border-bottom: none; }
.w-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 210px; }
.w-word { font-size: 16px; }
.w-def { flex: 1; font-size: 14px; color: #374151; }
.w-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* 词形徽章 (-ing 现在分词/动名词 等) */
.form-badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  background: #ede9fe;
  color: #6d28d9;
  font-weight: 600;
}

/* 遗忘曲线复习阶段徽章 */
.stage-badge-new {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  background: #e0f2fe;
  color: #075985;
  font-weight: 600;
}
.stage-badge-lv {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  background: #fef3c7;
  color: #92400e;
  font-weight: 600;
}

/* 记忆故事 */
.w-mnemonic {
  margin-top: 4px;
  font-size: 13px;
  color: #b45309;
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  padding: 5px 9px;
  border-radius: 0 6px 6px 0;
}
.review-mnemonic {
  margin: 8px auto 0;
  max-width: 480px;
  text-align: left;
  font-size: 14px;
  color: #b45309;
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
}
.review-next { margin-top: 12px; font-size: 12px; }

/* 短语 / 句子卡片 */
.ph-card { padding: 14px 18px; }
.ph-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.ph-kind { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 10px; }
.ph-kind.k-hl { background: #fef9c3; color: #854d0e; }
.ph-kind.k-ul { background: #dbeafe; color: #1e40af; }
.ph-src { font-size: 12px; flex: 1; min-width: 120px; }
.ph-actions { display: flex; gap: 6px; }
.ph-text { font-family: var(--serif); font-size: 16px; line-height: 1.7; padding: 6px 10px; border-radius: 6px; }
.ph-text.is-hl { background: #fef9c3; }
.ph-text.is-ul { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.ph-note { font-size: 13px; margin-top: 8px; padding: 8px 10px; background: #f9fafb; border-radius: 6px; border-left: 3px solid var(--warn); }
.ph-note-empty { border-left-color: var(--border); }

/* 复习闪卡 */
.review-card { text-align: center; padding: 44px 24px; }
.review-progress { font-size: 13px; margin-bottom: 22px; }
.review-word { font-size: 40px; font-weight: 700; font-family: var(--serif); margin-bottom: 6px; }
.review-hint { margin: 22px 0 4px; font-size: 14px; }
.review-answer { margin-top: 22px; }
.review-def { font-size: 18px; color: #374151; margin-bottom: 10px; }
.review-root { font-size: 14px; color: #059669; margin-bottom: 4px; }
.review-btns { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
.review-empty { text-align: center; padding: 36px 0; }
.review-empty .big { font-size: 48px; margin-bottom: 12px; }

/* --- 编辑 Markdown 弹窗 --- */
.md-editor {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.md-panel {
  width: min(1200px, 96vw);
  height: min(860px, 92vh);
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.md-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  flex-shrink: 0;
}
.md-editor-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md-editor-body {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 14px 18px;
  min-height: 0;
}
.md-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.md-pane label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}

/* ============================================================
 * 全站统一固定页眉（header.nav.site-header-fixed）
 * - 跨 6 个页面：index/writing/read/words/word-stats/speak/agent-chat
 * - 所有页面 header.nav 追加 class="site-header-fixed"
 * - 所有页面 <body> 追加 class="with-fixed-header"
 * - position:fixed 相对 viewport，不随父容器 transform 变化
 * ============================================================ */
header.nav.site-header-fixed {
  position: fixed !important;
  top: 0; left: 0; right: 0;
  z-index: 9999 !important;
  height: var(--site-header-height); /* 全站统一紧凑高度 */
  box-sizing: border-box;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
}
header.nav.site-header-fixed .brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
header.nav.site-header-fixed a { color: var(--ink); font-size: 13px; white-space: nowrap; }
header.nav.site-header-fixed a.active { color: var(--accent); font-weight: 600; }
header.nav.site-header-fixed .top-actions { margin-left: auto; }
/* 响应式：小屏幕缩小间距，防止换行 */
@media (max-width: 900px) {
  header.nav.site-header-fixed { padding: 0 12px; gap: 10px; }
  header.nav.site-header-fixed .brand { font-size: 14px; }
  header.nav.site-header-fixed a { font-size: 12px; }
  header.nav.site-header-fixed .top-actions button { font-size: 12px; padding: 3px 8px; }
}

/* ------- 让位规则：根据页面 3 种布局分别调整（页眉高由变量统一控制） ------- */

/* 布局 A：简单 main 布局（read/words/word-stats → body > main{max-width:900px}） */
body.with-fixed-header > main { padding-top: calc(var(--site-header-height) + 16px); box-sizing: border-box; }

/* 布局 B：app-shell flex column 布局（index/speak → body.app-shell > header.nav + div.layout > aside+content）
   header 从 flex 文档流脱离后，给 .layout 整体加 padding-top 让位 */
body.with-fixed-header.app-shell > .layout {
  padding-top: calc(var(--site-header-height) + 4px);
  box-sizing: border-box;
}

/* 布局 C：agent-chat 独立 flex row 布局（body > aside.sidebar + main.main，并排 100vh）
   本页在自己的内联样式中处理让位（sidebar top:44px + main margin-top:44px），
   这里只兜底移动端之外极端情况 */
body.with-fixed-header > aside.sidebar {
  height: calc(100vh - var(--site-header-height)) !important;
  padding-top: var(--site-header-height);
  box-sizing: border-box;
}
body.with-fixed-header > main.main {
  height: calc(100vh - var(--site-header-height)) !important;
  padding-top: var(--site-header-height);
  box-sizing: border-box;
}
@media (max-width: 900px) {
  body.with-fixed-header > aside.sidebar { padding-top: var(--site-header-height); }
  body.with-fixed-header > main.main { padding-top: var(--site-header-height); }
}
.md-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.md-pane textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
  background: #fbfaf7;
  outline: none;
}
.md-pane textarea:focus { border-color: var(--accent); background: var(--card); }
.md-editor-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.md-editor-foot .muted { flex: 1; font-size: 13px; }
@media (max-width: 860px) {
  .md-editor { padding: 10px; }
  .md-editor-body { flex-direction: column; }
}

/* Markdown 图片渲染 */
.md-img { text-align: center; margin: 16px 0; }
.md-img img { max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); }
/* 连续多张图片并排(如 Q30-32 的三个轮子示意图) */
.md-img-row { display: flex; gap: 18px; justify-content: center; align-items: flex-start; flex-wrap: wrap; margin: 16px 0; }
.md-img-row .md-img { margin: 0; }
.md-img-row .md-img img { max-width: 100%; }
.md-inline-img { max-width: 100%; height: auto; vertical-align: middle; border-radius: 4px; }

/* Markdown 表格渲染 */
.md-table-wrap { margin: 16px 0; overflow-x: auto; }
.md-table { border-collapse: collapse; width: 100%; font-size: 14px; background: var(--card); }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; vertical-align: top; }
.md-table th { background: #f3f4f6; font-weight: 700; }
.md-table tbody tr:nth-child(even) { background: #fafaf8; }

/* ============================================================
 * PWA: install banner & app display adjustments
 * ============================================================ */
.pwa-install-banner {
  position: fixed;
  z-index: 9998; /* just below fixed header (9999) so header remains on top */
  left: 12px;
  right: 12px;
  bottom: -140px;
  transform: translateY(100%);
  opacity: 0;
  transition: transform .28s cubic-bezier(.2,.8,.2,1), opacity .2s ease, bottom .2s ease;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.12), 0 2px 8px rgba(17, 24, 39, 0.06);
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  -webkit-tap-highlight-color: transparent;
}
.pwa-install-banner.is-visible {
  bottom: 14px;
  transform: translateY(0);
  opacity: 1;
}
.pwa-install-banner__body {
  flex: 1 1 260px;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.pwa-install-banner__icon {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
}
.pwa-install-banner__title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 2px;
}
.pwa-install-banner__desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}
.pwa-install-banner__actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pwa-install-banner__btn {
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .05s ease;
}
.pwa-install-banner__btn:active { transform: scale(.97); }
.pwa-install-banner__btn--primary {
  background: var(--accent);
  color: #ffffff;
}
.pwa-install-banner__btn--primary:hover { background: var(--accent-dark); }
.pwa-install-banner__btn--ghost {
  color: var(--muted);
  background: transparent;
}
.pwa-install-banner__btn--ghost:hover { background: #f3f4f6; color: var(--ink); }

/* Reserve space so banner never covers page content (body or main bottom padding) */
@media (max-width: 768px) {
  body.pwa-banner-spacer,
  body.pwa-banner-spacer > main,
  body.with-fixed-header > main { padding-bottom: 130px; }
}

/* =====================================================================
   用户体系 UI: 顶栏用户入口 / 登录页 / 用户管理页 / 修改密码弹窗
   ===================================================================== */

/* --- 顶栏「当前用户」入口 --- */
.user-chip { position: relative; }
.user-chip-right { margin-left: auto; }
.user-chip-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent; border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px 3px 4px; cursor: pointer; color: var(--ink);
  font-size: 13px; font-family: inherit; line-height: 1.4;
}
.user-chip-btn:hover { background: #f3f4f6; border-color: #d1d5db; }
.user-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.user-name { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  min-width: 190px; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; text-align: left;
}
.user-menu-head {
  display: flex; flex-direction: column; gap: 1px;
  padding: 7px 10px 9px; border-bottom: 1px solid var(--border); margin-bottom: 5px;
}
.user-menu-head b { font-size: 13.5px; }
.user-menu-head span { font-size: 11.5px; color: var(--muted); }
.user-menu a, .user-menu button {
  display: block; width: 100%; text-align: left; box-sizing: border-box;
  padding: 8px 10px; border: 0; background: transparent; border-radius: 7px;
  font-size: 13.5px; color: var(--ink); cursor: pointer;
  font-family: inherit; text-decoration: none;
}
.user-menu a:hover, .user-menu button:hover { background: #f3f4f6; text-decoration: none; }

/* --- 修改密码弹窗 --- */
.pwd-mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(17,24,39,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.pwd-box {
  background: var(--card); border-radius: 14px; padding: 22px;
  width: 100%; max-width: 380px; box-shadow: 0 18px 48px rgba(0,0,0,.22);
}
.pwd-box h3 { margin: 0 0 6px; font-size: 17px; }
.pwd-hint { margin: 0 0 14px; font-size: 12.5px; color: var(--muted); }
.pwd-box label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 11px; }
.pwd-box input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; box-sizing: border-box;
}
.pwd-box input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.pwd-msg { min-height: 18px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.pwd-msg.err { color: var(--danger); }
.pwd-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* --- 登录页 --- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(160deg, #faf8f3 0%, #eef2ff 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card);
  border: 1px solid var(--border); border-radius: 16px; padding: 30px 28px;
  box-shadow: 0 10px 32px rgba(31,35,40,.08);
}
.login-card h1 { margin: 0 0 4px; font-size: 21px; }
.login-sub { margin: 0 0 22px; font-size: 13px; color: var(--muted); }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 13px; }
.login-card input {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 9px;
  font-size: 15px; font-family: inherit; box-sizing: border-box;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.login-btn {
  width: 100%; padding: 11px; border: 0; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit; margin-top: 4px;
}
.login-btn:hover { background: var(--accent-dark); }
.login-btn:disabled { opacity: .6; cursor: default; }
.login-msg { min-height: 20px; font-size: 13px; margin: 10px 0 0; color: var(--danger); }
.login-foot { margin: 20px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

/* --- 用户管理页 --- */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 24px; }
.admin-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.admin-head h1 { margin: 0; font-size: 21px; }
.admin-sub { margin: 0 0 20px; font-size: 13px; color: var(--muted); }
.admin-grid { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: 18px; align-items: start; }
@media (max-width: 820px) { .admin-grid { grid-template-columns: 1fr; } }
.admin-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; overflow: hidden;
}
.admin-card h2 { margin: 0 0 12px; font-size: 15px; }
.admin-card label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.admin-card input, .admin-card select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; box-sizing: border-box; background: #fff;
}
.admin-msg { min-height: 18px; font-size: 12.5px; margin: 6px 0; }
.admin-msg.err { color: var(--danger); }
.admin-msg.ok { color: #065f46; }
table.users { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.users th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px;
  border-bottom: 1px solid var(--border); padding: 7px 8px; white-space: nowrap;
}
table.users td { border-bottom: 1px solid #f3f4f6; padding: 9px 8px; vertical-align: middle; }
table.users tr:last-child td { border-bottom: 0; }
.u-badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.u-badge.admin { background: #dbeafe; color: #1d4ed8; }
.u-badge.user { background: #f3f4f6; color: #4b5563; }
.u-badge.off { background: #fee2e2; color: #b91c1c; }
.u-badge.self { background: #d1fae5; color: #065f46; }
.u-stats { color: var(--muted); font-size: 12px; white-space: nowrap; }
.u-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.u-actions button {
  font-size: 12px; padding: 3px 9px; border-radius: 7px;
  border: 1px solid var(--border); background: #fff; color: var(--ink);
  cursor: pointer; font-family: inherit; white-space: nowrap;
}
.u-actions button:hover { background: #f3f4f6; }
.u-actions button.danger { color: var(--danger); border-color: #fecaca; }
.u-actions button.danger:hover { background: #fef2f2; }
.u-actions button:disabled { opacity: .45; cursor: default; }

/* --- 无权限页 --- */
.forbidden-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
.forbidden-card { max-width: 380px; }
.forbidden-card .big { font-size: 44px; }
.forbidden-card h1 { font-size: 20px; margin: 10px 0 6px; }
.forbidden-card p { color: var(--muted); font-size: 14px; }
