/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;       /* 关键：禁止任何横向滚动 */
  max-width: 100vw;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue",
               Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  background: #f8fafc;
  color: #1e293b;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.2s ease, color 0.2s ease;
  width: 100%;
  max-width: 100vw;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Theme Variables ===== */
:root {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-bg: #eff6ff;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --success-border: #86efac;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --danger-border: #fca5a5;
  --warn: #f59e0b;
  --warn-bg: #fef3c7;
  --code-bg: #f1f5f9;
  --code-text: #334155;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px rgba(15, 23, 42, 0.07), 0 2px 4px rgba(15, 23, 42, 0.05);
  --radius: 12px;
  --radius-sm: 6px;
  --radius-md: 8px;
}

/* ========== 关键修复：body.dark 必须显式修改根级颜色与背景 ========== */
html { background: var(--bg); }
body.dark {
  --bg: #0b1220;
  --bg-card: #111827;
  --bg-elevated: #0f172a;
  --bg-input: #0b1220;
  --bg-hover: #1f2937;
  --text: #f1f5f9;
  --text-muted: #cbd5e1;
  --text-faint: #94a3b8;
  --border: #1f2937;
  --border-strong: #334155;
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --primary-bg: #172554;
  --success: #4ade80;
  --success-bg: #14532d;
  --success-border: #166534;
  --danger: #f87171;
  --danger-bg: #450a0a;          /* 加深，使白文字可读 */
  --danger-border: #7f1d1d;
  --warn: #fbbf24;
  --warn-bg: #78350f;
  --code-bg: #0b1220;
  --code-text: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.7);

  background-color: var(--bg) !important;
  background: var(--bg) !important;
  color: var(--text) !important;
}
body.dark * {
  border-color: var(--border);
}
body.dark .question-card,
body.dark .sidebar,
body.dark .topbar,
body.dark .option,
body.dark input,
body.dark textarea {
  background-color: var(--bg-card);
  color: var(--text);
}
body.dark .option:hover { background-color: var(--bg-hover); }
body.dark .option.selected { background-color: var(--primary-bg); color: var(--primary); }
body.dark .option.correct,
body.dark .option.correct .opt-text { background-color: #14532d !important; color: #dcfce7 !important; border-color: #22c55e !important; }
body.dark .option.wrong,
body.dark .option.wrong .opt-text { background-color: #450a0a !important; color: #fee2e2 !important; border-color: #ef4444 !important; }
body.dark .option .opt-key { background: #0f172a; color: var(--text); }
body.dark .option.correct .opt-key { background: #166534; color: #dcfce7; }
body.dark .option.wrong .opt-key { background: #991b1b; color: #fee2e2; }
body.dark input,
body.dark textarea {
  border-color: var(--border);
}
body.dark .explanation { background: #0f172a; color: var(--text); border-left-color: var(--primary); }
body.dark .chapter-divider { background: var(--bg-card); color: var(--text); border-color: var(--border); }
body.dark .q-type { color: #fff; }
body.dark .essay-ref { background: #0b1220; color: #cbd5e1; border-color: var(--border); }

/* ===== Essay / pre 代码块（关键：必须换行不撑开容器） ===== */
.essay-area {
  max-width: 100%;
  overflow-x: hidden;
}
.essay-ref {
  max-width: 100%;
  width: 100%;
  overflow-x: auto;          /* 自己横向滚，不影响父级 */
  white-space: pre-wrap;     /* 关键：允许换行 */
  word-break: break-word;
  word-wrap: break-word;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  margin: 0 0 12px 0;
  box-sizing: border-box;
}

/* 全局：任何元素溢出都不可撑开 body 横向滚动 */
img, table, pre, code, .question-card, .q-stem, .options, .blanks-area,
.essay-area, .essay-ref, .explanation, .chapter-divider {
  max-width: 100%;
  box-sizing: border-box;
}
pre { white-space: pre-wrap; word-break: break-word; overflow-x: auto; }
code { white-space: pre-wrap; word-break: break-word; }
table { table-layout: fixed; }
body.dark .sidebar-backdrop { background: rgba(0,0,0,0.7); }
body.dark .btn-ghost { background: var(--bg-card); color: var(--text); border-color: var(--border); }
body.dark .btn-ghost:hover { background: var(--bg-hover); }
body.dark .qdot.unanswered,
body.dark .qdot.dim { background: var(--bg-hover); color: var(--text-muted); }
body.dark .qdot.correct { background: #14532d; color: #86efac; }
body.dark .qdot.wrong { background: #7f1d1d; color: #fca5a5; }
body.dark .qdot.answered { background: var(--primary-bg); color: var(--primary); }
body.dark .legend-swatch.unanswered { background: var(--bg-hover); }
body.dark .legend-swatch.answered { background: var(--primary-bg); }
body.dark .blank-input,
body.dark .essay-input {
  background: #0b1220; color: var(--text); border-color: var(--border);
}
body.dark .back-top-fab { box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
body.dark .blank-label { color: var(--text-muted); }
body.dark .essay-label { color: var(--text-muted); }
body.dark .explanation-toggle { color: var(--primary); background: transparent; }
body.dark .empty { color: var(--text-muted); }

/* ===== Top Bar ===== */
.topbar {
  position: fixed;            /* 完全固定顶部，不随滚动 */
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  max-width: 1400px;
  margin: 0 auto;
  flex-wrap: wrap;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-right: 8px;
}

.topbar-progress {
  flex: 1;
  min-width: 180px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-hover);
  border-radius: 999px;
  overflow: hidden;
  max-width: 320px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #16a34a);
  transition: width 0.3s ease;
  width: 0%;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger-border);
}

.btn-danger:hover {
  background: var(--danger-bg);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--bg-hover);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

.btn-icon {
  padding: 8px;
  width: 36px;
  height: 36px;
}

/* ===== Layout ===== */
.app {
  max-width: 100vw;
  margin: 0 auto;
  width: 100%;
  position: relative;
  overflow-x: hidden;
}

.sidebar {
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  padding: 16px;
  position: fixed;
  top: 60px;
  right: max(16px, calc((100vw - 1400px) / 2 + 16px));
  bottom: 16px;
  width: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 30;
  /* flex 容器里这个 fixed 元素仍占位，需用 absolute 替代或脱离 flex */
  flex-shrink: 0;
}

/* ===== 题号导航分组（按题型分段） ===== */
.qnav-section {
  margin-bottom: 14px;
}
.qnav-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.3px;
  padding: 6px 4px 6px 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.qnav-section-title .qnav-range {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}
body.dark .qnav-section-title { color: var(--text); border-bottom-color: var(--border); }
body.dark .qnav-section-title .qnav-range { color: var(--text-muted); }
.qnav-container {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.qgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 6px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.qdot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: 13px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.qdot:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.qdot.current {
  border-color: var(--primary);
  font-weight: 600;
}

.qdot.answered {
  background: var(--primary-bg);
  color: var(--primary);
}

.qdot.correct {
  background: var(--success-bg);
  color: var(--success);
}

.qdot.wrong {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ===== Main ===== */
.main {
  padding: var(--topbar-h, 60px) 296px 80px 16px;   /* top 给 topbar 留位 */
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.question-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  max-width: 100%;
  overflow: hidden;           /* 关键：截断内部溢出内容 */
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.q-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.q-id {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.q-type-inline {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: none;
  letter-spacing: 0;
  display: inline-block;
}

.q-type {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.q-type.single, .q-type-inline.single { color: #2563eb; background: #dbeafe; }
.q-type.multi,  .q-type-inline.multi  { color: #7c3aed; background: #ede9fe; }
.q-type.judge,  .q-type-inline.judge  { color: #ea580c; background: #ffedd5; }
.q-type.blank,  .q-type-inline.blank  { color: #0891b2; background: #cffafe; }
.q-type.material, .q-type-inline.material { color: #db2777; background: #fce7f3; }
.q-type.essay, .q-type-inline.essay { color: #16a34a; background: #dcfce7; }

body.dark .q-type.single,   body.dark .q-type-inline.single { background: #1e3a8a; color: #fff; }
body.dark .q-type.multi,    body.dark .q-type-inline.multi { background: #4c1d95; color: #fff; }
body.dark .q-type.judge,    body.dark .q-type-inline.judge { background: #7c2d12; color: #fff; }
body.dark .q-type.blank,    body.dark .q-type-inline.blank { background: #155e75; color: #fff; }
body.dark .q-type.material, body.dark .q-type-inline.material { background: #831843; color: #fff; }
body.dark .q-type.essay,    body.dark .q-type-inline.essay { background: #14532d; color: #fff; }

.q-status {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-muted);
}

.q-status.correct { color: var(--success); }
.q-status.wrong { color: var(--danger); }

.q-stem {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  margin-bottom: 20px;
}

.q-stem code, .q-stem pre {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13.5px;
}

.q-stem pre {
  padding: 12px 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  word-wrap: break-word;
  max-width: 100%;
  line-height: 1.55;
}

/* ===== Options ===== */
.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.option:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.option.selected {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.option.correct {
  border-color: var(--success-border);
  background: var(--success-bg);
  color: var(--text);
}
.option.correct .opt-text { color: #166534; font-weight: 600; }
.option.correct .opt-key { background: var(--success); color: #fff; }
.option.correct .opt-mark { color: var(--success); }

.option.wrong {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--text);
}
.option.wrong .opt-text { color: #991b1b; font-weight: 600; }
.option.wrong .opt-key { background: var(--danger); color: #fff; }
.option.wrong .opt-mark { color: var(--danger); }

.option.dim-correct { opacity: 0.7; }

.option .opt-key {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.option.selected .opt-key {
  background: var(--primary);
  color: #fff;
}

.option.correct .opt-key {
  background: var(--success);
  color: #fff;
}

.option.wrong .opt-key {
  background: var(--danger);
  color: #fff;
}

/* Browse page: faded non-correct options */
.option.wrong-faded {
  border-color: var(--border);
  background: var(--bg-card);
  color: var(--text-faint);
}
.option.wrong-faded .opt-key {
  background: var(--bg-hover);
  color: var(--text-faint);
}

.option .opt-text {
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

.option .opt-mark {
  flex-shrink: 0;
  font-weight: 600;
}

/* ===== Blank / Text inputs ===== */
.blanks-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.blank-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.blank-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 64px;
}

.blank-input,
.essay-input {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  outline: none;
  transition: all 0.2s ease;
}

.blank-input:focus,
.essay-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.essay-input {
  width: 100%;
  resize: vertical;
  min-height: 140px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.6;
}

.blank-status {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 50px;
}

.blank-status.correct { color: var(--success); }
.blank-status.wrong { color: var(--danger); }

/* ===== Explanation ===== */
.explanation {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--primary-bg);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.explanation .exp-label {
  font-weight: 600;
  color: var(--primary);
  margin-right: 8px;
}

body.dark .explanation { color: var(--text); }

.explanation-toggle {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.explanation-toggle:hover {
  background: var(--bg-hover);
  color: var(--primary);
}

.explanation-toggle .chev {
  display: inline-block;
  transition: transform 0.2s ease;
}

.explanation-toggle.open .chev {
  transform: rotate(90deg);
}

/* ===== Navigation ===== */
.qnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  gap: 10px;
}

.qnav .btn {
  min-width: 100px;
}

/* ===== Legend ===== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.legend-swatch.answered { background: var(--primary-bg); border: 1px solid var(--primary); }
.legend-swatch.correct { background: var(--success-bg); border: 1px solid var(--success); }
.legend-swatch.wrong { background: var(--danger-bg); border: 1px solid var(--danger); }
.legend-swatch.unanswered { background: var(--bg-hover); border: 1px solid var(--border-strong); }

/* ===== Browse page ===== */
.browse-toolbar {
  position: sticky;
  top: var(--topbar-h, 60px);
  z-index: 40;
  background: var(--bg-card);
  padding: 0;          /* 搜索框与菜单栏无缝衔接 */
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

/* 搜索框 + 上下按钮一体（无间距） */
.search-box {
  display: flex;
  flex: 1;
  min-width: 0;
  border-right: 1px solid transparent;
}
.search-input {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  font-size: 14px;
  border: none;
  border-radius: 0;
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  transition: all 0.2s ease;
}
.search-input:focus {
  background: var(--bg-card);
  box-shadow: inset 0 0 0 2px var(--primary);
}
.match-nav {
  display: flex;
  align-items: stretch;
}
.btn-icon-mini {
  width: 40px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}
.btn-icon-mini:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--primary);
}
.btn-icon-mini:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.match-nav .btn-icon-mini + .btn-icon-mini { border-left: 1px solid var(--border); }

.search-hint {
  font-size: 13px;
  color: var(--text-muted);
  padding-right: 20px;
  white-space: nowrap;
}

/* ===== 结果检索按钮（顶栏左侧） ===== */
.results-toggle-btn {
  position: relative;
  padding: 0 12px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: not-allowed;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.results-toggle-btn:not(:disabled) {
  background: var(--primary-bg);
  color: var(--primary);
  border-color: var(--primary);
  cursor: pointer;
}
.results-toggle-btn:not(:disabled):hover {
  background: var(--primary);
  color: #fff;
}
.results-toggle-btn .rt-text {
  letter-spacing: 0.5px;
}

/* ===== 结果侧栏（桌面左 / 移动左抽屉） ===== */
.results-sidebar {
  position: fixed;
  top: var(--topbar-h, 60px);
  bottom: 0;
  left: 0;
  width: 320px;
  max-width: 86vw;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.results-sidebar.open { transform: translateX(0) !important; }
.results-sidebar .sidebar-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.match-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.match-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: left;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.match-row:hover { background: var(--bg-hover); }
.match-row.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}
.match-row .match-id {
  font-weight: 600;
  color: var(--primary);
  flex-shrink: 0;
  min-width: 30px;
}
.match-row .match-stem {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.match-empty {
  text-align: center;
  padding: 30px 12px;
  font-size: 13px;
  color: var(--text-muted);
}
body.dark .match-row { border-bottom-color: var(--border); }
body.dark .results-toggle-btn:not(:disabled) { background: var(--primary-bg); color: var(--primary); }
body.dark .btn-icon-mini { color: var(--text-muted); }
body.dark .btn-icon-mini:hover:not(:disabled) { background: var(--bg-hover); }

.browse-list {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.browse-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: all 0.2s ease;
  scroll-margin-top: 140px;
}

.browse-card.highlight {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18), var(--shadow-md);
}

.browse-card.match {
  border-color: var(--warn);
}

/* ===== Mobile drawer ===== */
.mobile-drawer-trigger {
  display: none;
}

/* 移动端：章节 tab 固定在顶栏下方，不随内容滚动 */
/* ========== 响应式断点 ========== */

/* 大屏桌面（>1280px） */
@media (min-width: 1281px) {
  .sidebar { width: 300px; }
  .main { padding: var(--topbar-h, 60px) 316px 80px 32px; }
}

/* 平板 / 小桌面（769px ~ 1024px） */
@media (max-width: 1024px) and (min-width: 769px) {
  .sidebar { width: 240px; }
  .main { padding: var(--topbar-h, 60px) 256px 80px 16px; }
  .question-card { padding: 20px; }
}

/* 平板竖屏 / 大屏手机（481px ~ 768px） */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; }
  .topbar-inner {
    padding: 8px 12px;
    gap: 8px;
  }
  .topbar-title {
    font-size: 14px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-progress {
    order: 99;
    flex-basis: 100%;
    margin-top: 4px;
  }
  .progress-bar { max-width: none; }

  /* 移动端 main 恢复单边距 */
  .main { padding: var(--topbar-h, 60px) 14px 80px; }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h, 60px);
    bottom: 0;
    width: 86vw;
    max-width: 320px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-md);
    border-left: none;
    border-right: 1px solid var(--border);
  }
  .sidebar.open { transform: translateX(0) !important; }
  .mobile-drawer-trigger { display: inline-flex; }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: var(--topbar-h, 60px);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 99;
  }
  .sidebar-backdrop.open { display: block; }

  .question-card { padding: 16px; }
  .q-stem { font-size: 14.5px; }
  .q-id { font-size: 14px; flex-wrap: wrap; }
  .q-type-inline { font-size: 11px; }

  .btn { min-height: 44px; }
  .btn-icon { min-width: 44px; }
  .blank-input, .essay-input, .search-input { font-size: 16px; }
  .essay-input { min-height: 120px; }
  .essay-ref { font-size: 12px; padding: 10px 12px; }

  .browse-list { padding: 14px 12px 40px; }
  .browse-card { padding: 16px; }
  .browse-toolbar {
    top: var(--topbar-h, 60px);
    flex-wrap: nowrap;
    padding: 0;
    gap: 0;
  }
  .search-box { flex: 1 1 auto; min-width: 0; }
  .search-input { padding: 12px 14px; font-size: 16px; }
  .btn-icon-mini { width: 36px; height: 44px; font-size: 12px; }
  .search-hint { padding-right: 12px; font-size: 12px; min-width: 60px; }

  .results-toggle-btn { padding: 0 10px; }
  .results-toggle-btn .rt-text { display: inline; font-size: 12px; }
  body { padding-bottom: env(safe-area-inset-bottom); }
}

/* 小屏手机（≤480px）—— 最窄适配 */
@media (max-width: 480px) {
  .topbar-inner {
    padding: 6px 10px;
    gap: 6px;
  }
  .topbar-title { font-size: 13px; }
  .topbar-actions .btn { font-size: 12px; padding: 6px 10px; }
  .results-toggle-btn { padding: 0 8px; }
  .results-toggle-btn .rt-text { font-size: 11px; }
  .progress-bar { max-width: 100%; }

  .question-card { padding: 12px; border-radius: 8px; }
  .q-stem { font-size: 14px; line-height: 1.65; }
  .q-id { font-size: 13px; }
  .q-type-inline { font-size: 11px; padding: 1px 6px; }

  .options { gap: 8px; }
  .option { padding: 10px 12px; font-size: 14px; }
  .option .opt-key { width: 24px; height: 24px; font-size: 12px; }
  .option .opt-text { font-size: 14px; }

  .blanks-area .blank-row { flex-direction: column; align-items: stretch; gap: 4px; }
  .blank-row .blank-label { margin-right: 0; }

  .essay-area { padding: 10px; }
  .essay-input { min-height: 100px; font-size: 14px; }

  .chapter-divider { padding: 8px 12px; flex-direction: column; align-items: flex-start; gap: 2px; }
  .chapter-divider .chap-name { font-size: 14px; }
  .chapter-divider .chap-range { margin-left: 0; font-size: 11px; }

  .browse-list { padding: 10px 8px 40px; }
  .browse-card { padding: 12px; }
  .q-id { font-size: 13px; }
  .option { padding: 10px; font-size: 13.5px; }

  .results-sidebar { width: 90vw; max-width: none; }
  .match-row { padding: 7px 8px; font-size: 12px; }
  .match-id { min-width: 24px; }

  .back-top-fab {
    right: 12px;
    bottom: 12px;
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}

/* 极窄屏（≤360px）—— iPhone SE / 旧机型适配 */
@media (max-width: 360px) {
  .topbar-title { font-size: 12px; }
  .topbar-actions { gap: 4px; }
  .topbar-actions .btn { font-size: 11px; padding: 4px 8px; }
  .results-toggle-btn .rt-text { font-size: 10px; }
  .main { padding: var(--topbar-h, 60px) 6px 80px; }
  .question-card { padding: 10px; }
  .option { padding: 8px 10px; font-size: 13px; }
  .option .opt-key { width: 22px; height: 22px; font-size: 11px; }
  .q-stem { font-size: 13px; }

  /* 极窄屏下隐藏 match 提示（文字太长会挤压搜索框） */
  .search-hint { display: none; }
  .results-toggle-btn { padding: 0 6px; }
}
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-backdrop.open .modal {
  transform: translateY(0);
}

.modal h3 {
  margin: 0 0 12px;
  font-size: 17px;
  color: var(--text);
}

.modal p {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  font-size: 14px;
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 300;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Utilities ===== */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.fade-in { animation: fadeIn 0.2s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Highlight search matches */
mark {
  background: #fef08a;
  color: #1e293b;
  padding: 1px 3px;
  border-radius: 3px;
}
body.dark mark {
  background: #713f12;
  color: #fef08a;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ===== Feed (滚动模式题卡容器) ===== */
.qfeed {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 6px 0 40px 0;
}

.question-card.scroll-target {
  scroll-margin-top: 80px;
}

/* 章节分隔 */
.chapter-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 4px 0;
  padding: 10px 14px;
  border-left: 4px solid var(--primary);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.chapter-divider .chap-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.chapter-divider .chap-range {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== 空态 ===== */
.empty {
  text-align: center;
  padding: 60px 20px;
  font-size: 14px;
  color: var(--text-muted);
}

/* ===== 章节列表（侧栏里） ===== */
.sidebar-section { margin-bottom: 18px; }
.sidebar-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 10px;
}

/* ===== 圆点 dim（不在章节筛选时） ===== */
.qdot.dim { opacity: 0.28; }

/* ===== 顶栏 extraLeft 区域 ===== */
.topbar-extra { display: flex; align-items: center; gap: 8px; }

/* ===== 回到顶部 FAB ===== */
.back-top-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-top-fab:hover { background: var(--primary-hover); transform: translateY(0); }
.back-top-fab.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
@media (max-width: 768px) {
  .back-top-fab {
    right: 16px;
    bottom: 16px;
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
}
body.dark .back-top-fab { box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
