/* ==========================================================================
   离散数学学习助手 · 样式�?   无外部依�?/ �?CDN，全部使�?CSS 自定义属性管理颜色，便于换肤�?   断点：桌�?>=1024px，移�?<1024px
   ========================================================================== */

/* ---------- 1. 设计令牌 ---------- */
:root {
  --primary: #4f46e5;
  --primary-strong: #4338ca;
  --primary-soft: #eef2ff;
  --primary-soft-2: #e0e7ff;
  --primary-ring: rgba(79, 70, 229, 0.28);

  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-sunken: #f1f5f9;
  --bg-hover: #f1f5f9;
  --bg-active: #eef2ff;

  --text: #0f172a;
  --text-soft: #334155;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --success: #10b981;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #f59e0b;
  --mark-bg: #fef08a;
  --mark-text: #422006;

  --code-bg: #f6f8fa;
  --code-text: #24292f;
  --code-border: #e2e8f0;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.09), 0 2px 6px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 18px 44px rgba(15, 23, 42, 0.16);

  --header-h: 56px;
  --tabbar-h: 58px;
  --sidebar-w: 300px;
  --chat-w: 400px;

  --font-sans: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC",
    "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans CJK SC", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "Cascadia Mono", "Cascadia Code", Consolas,
    "Liberation Mono", Menlo, "Courier New", monospace;
  --font-math: "KaTeX_Main", "Times New Roman", serif;

  --fs-body: 16px;
  --lh-body: 1.75;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 0.15s;
  --t: 0.2s;
  --t-slow: 0.25s;

  --z-header: 60;
  --z-overlay: 70;
  --z-search: 80;
  --z-drawer: 90;
  --z-toast: 100;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #818cf8;
    --primary-strong: #a5b4fc;
    --primary-soft: #1e1b4b;
    --primary-soft-2: #312e81;
    --primary-ring: rgba(129, 140, 248, 0.35);

    --bg: #0b1120;
    --bg-elevated: #131c31;
    --bg-sunken: #0f172a;
    --bg-hover: #1c2740;
    --bg-active: #1e293b;

    --text: #e6edf7;
    --text-soft: #cbd5e1;
    --text-muted: #94a3b8;
    --text-faint: #64748b;

    --border: #24314c;
    --border-strong: #334155;

    --success: #34d399;
    --danger: #f87171;
    --danger-soft: #3b1414;
    --warning: #fbbf24;
    --mark-bg: #78350f;
    --mark-text: #fef3c7;

    --code-bg: #0d1526;
    --code-text: #d6e2f0;
    --code-border: #24314c;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.6);
  }
}

/* ---------- 2. 基础重置 ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6, p, ul, ol, figure, blockquote, pre {
  margin: 0;
}

ul, ol {
  padding-left: 1.35em;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

input,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code, kbd, samp {
  font-family: var(--font-mono);
}

svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

::selection {
  background: var(--primary-soft-2);
  color: var(--text);
}

.muted { color: var(--text-muted); }
.muted-xs { color: var(--text-faint); font-size: 12px; }
.only-mobile { display: none !important; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 999;
  padding: 8px 14px;
  background: var(--primary);
  color: #fff;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
}

/* 细滚动条 */
.reader-scroll,
.chat-log,
.sidebar-body,
.search-results {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.reader-scroll::-webkit-scrollbar,
.chat-log::-webkit-scrollbar,
.sidebar-body::-webkit-scrollbar,
.search-results::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.reader-scroll::-webkit-scrollbar-thumb,
.chat-log::-webkit-scrollbar-thumb,
.sidebar-body::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--radius-pill);
}
.reader-scroll::-webkit-scrollbar-track,
.chat-log::-webkit-scrollbar-track,
.sidebar-body::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- 3. 通用组件 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
}

.btn.sm {
  padding: 6px 11px;
  font-size: 13px;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-xs);
}
.btn.primary:hover:not(:disabled) {
  background: var(--primary-strong);
  box-shadow: var(--shadow-sm);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn.ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}
.btn.danger:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.icon-btn.sm {
  width: 28px;
  height: 28px;
  padding: 6px;
}

/* ---------- 4. 顶部 header ---------- */
.app-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--header-h);
  padding: 0 14px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .app-header {
    background: var(--bg-elevated);
  }
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.header-center {
  flex: 1 1 auto;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  box-shadow: var(--shadow-xs);
}

/* 搜索 */
.search-wrap {
  position: relative;
  max-width: 460px;
  margin: 0 auto;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 8px 34px 8px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  font-size: 14px;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease);
}
.search-input::placeholder {
  color: var(--text-faint);
}
.search-input:focus {
  outline: none;
  background: var(--bg-elevated);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.search-input::-webkit-search-cancel-button {
  display: none;
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  transition: background var(--t-fast) var(--ease);
}
.search-clear:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* 后端状�?*/
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  transition: border-color var(--t) var(--ease);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: 0 0 auto;
  transition: background var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.status-dot.is-ok {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 22%, transparent);
}
.status-dot.is-bad {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent);
}
.status-dot.is-warn {
  background: var(--warning);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 22%, transparent);
}
.status-dot.is-unknown {
  background: var(--text-faint);
  animation: pulse 1.6s var(--ease) infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- 5. 搜索结果浮层 ---------- */
.search-overlay {
  position: fixed;
  inset: var(--header-h) 0 0 0;
  z-index: var(--z-overlay);
  background: rgba(15, 23, 42, 0.28);
  animation: fade-in var(--t) var(--ease);
}

.search-results {
  position: fixed;
  top: calc(var(--header-h) + 6px);
  left: 50%;
  z-index: var(--z-search);
  width: min(680px, calc(100vw - 24px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--t) var(--ease);
  transform: translateX(-50%);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.sr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 6px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.sr-item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  transition: background var(--t-fast) var(--ease);
}
.sr-item:hover,
.sr-item:focus-visible {
  background: var(--bg-hover);
}

.sr-path {
  font-size: 12px;
  color: var(--primary);
  margin-bottom: 2px;
}
.sr-path .sr-sep {
  color: var(--text-faint);
  margin: 0 4px;
}

.sr-snippet {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-soft);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

mark {
  padding: 0 2px;
  border-radius: 3px;
  background: var(--mark-bg);
  color: var(--mark-text);
}

.sr-empty {
  padding: 26px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.sr-loading {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- 6. 主体布局 ---------- */
.app-body {
  position: fixed;
  inset: var(--header-h) 0 0 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--chat-w);
  transition: grid-template-columns var(--t-slow) var(--ease);
}

body.sidebar-collapsed .app-body {
  grid-template-columns: 0 minmax(0, 1fr) var(--chat-w);
}

body.chat-collapsed .app-body {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 0;
}

body.sidebar-collapsed.chat-collapsed .app-body {
  grid-template-columns: 0 minmax(0, 1fr) 0;
}

/* ---------- 7. 左：目录�?---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  transition: opacity var(--t) var(--ease);
}

body.sidebar-collapsed .sidebar {
  opacity: 0;
  pointer-events: none;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 8px;
  flex: 0 0 auto;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.sidebar-head-actions {
  display: flex;
  gap: 2px;
}

.sidebar-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 8px 12px;
}

.sidebar-foot {
  flex: 0 0 auto;
  padding: 8px 14px 12px;
  border-top: 1px solid var(--border);
}

.chapter {
  margin-bottom: 2px;
}

.chapter-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
  text-align: left;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.chapter-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.chapter-caret {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  color: var(--text-faint);
  transition: transform var(--t) var(--ease);
}
.chapter.is-open .chapter-caret {
  transform: rotate(90deg);
}

.chapter-code {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary);
}

.chapter-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-count {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.chapter-docs {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--t-slow) var(--ease);
}
.chapter.is-open .chapter-docs {
  grid-template-rows: 1fr;
}
.chapter-docs > .chapter-docs-inner {
  overflow: hidden;
  min-height: 0;
}

.doc-link {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 7px 10px 7px 26px;
  border: none;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: transparent;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: left;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease);
}
.doc-link:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.doc-link.is-active {
  background: var(--bg-active);
  border-left-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.doc-badge {
  flex: 0 0 auto;
  margin-top: 2px;
  font-size: 10px;
  color: var(--warning);
  letter-spacing: -1px;
}

.doc-link-text {
  min-width: 0;
}

/* 文档内小节列表（阅读时展开�?*/
.sec-list {
  padding: 2px 0 6px;
  animation: fade-in var(--t) var(--ease);
}

.sec-link {
  display: block;
  width: 100%;
  padding: 4px 10px 4px 40px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.6;
  text-align: left;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.sec-link:hover {
  background: var(--bg-hover);
  color: var(--text-soft);
}
.sec-link.is-active {
  color: var(--primary);
  font-weight: 600;
}
.sec-link.lv3 {
  padding-left: 54px;
  font-size: 12px;
}
.sec-link.lv4 {
  padding-left: 66px;
  font-size: 12px;
}

.sidebar-scrim {
  position: fixed;
  inset: var(--header-h) 0 0 0;
  z-index: var(--z-drawer);
  background: rgba(15, 23, 42, 0.4);
  animation: fade-in var(--t) var(--ease);
}

/* ---------- 8. 中：阅读�?---------- */
.reader {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  overflow: hidden;
}

.reader-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
}

.breadcrumb .crumb {
  padding: 2px 6px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.breadcrumb .crumb:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.breadcrumb .crumb-current {
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crumb-sep {
  color: var(--text-faint);
  flex: 0 0 auto;
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.reader-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 20px 120px;
  scroll-behavior: smooth;
}

.doc {
  max-width: 780px;
  margin: 0 auto;
}

.doc:empty {
  display: none;
}

/* 文档信息�?*/
.doc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  margin-bottom: 22px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}

.doc-meta-label {
  font-size: 12px;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.7;
}

.badge.plain {
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-weight: 500;
}

.badge.diff {
  background: color-mix(in srgb, var(--warning) 16%, transparent);
  color: var(--warning);
  letter-spacing: 1px;
}

.badge.tag {
  background: var(--bg-sunken);
  color: var(--text-soft);
  font-weight: 500;
}

/* 阅读区正文排�?*/
.doc-body {
  color: var(--text-soft);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  overflow-wrap: break-word;
}

.doc-body > * + * {
  margin-top: 14px;
}

.doc-body h1,
.doc-body h2,
.doc-body h3,
.doc-body h4,
.doc-body h5,
.doc-body h6 {
  color: var(--text);
  line-height: 1.4;
  font-weight: 680;
  scroll-margin-top: 20px;
}

.doc-body h1 {
  font-size: 26px;
  margin-top: 10px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
}

.doc-body h2 {
  font-size: 21px;
  margin-top: 34px;
  padding-left: 12px;
  border-left: 4px solid var(--primary);
}

.doc-body h3 {
  font-size: 17.5px;
  margin-top: 26px;
  color: var(--text);
}

.doc-body h4 {
  font-size: 16px;
  margin-top: 20px;
  color: var(--text-soft);
}

.doc-body h5,
.doc-body h6 {
  font-size: 15px;
  margin-top: 16px;
  color: var(--text-muted);
}

.doc-body strong {
  color: var(--text);
  font-weight: 650;
}

.doc-body ul,
.doc-body ol {
  padding-left: 1.5em;
}

.doc-body li + li {
  margin-top: 5px;
}

.doc-body li > ul,
.doc-body li > ol {
  margin-top: 5px;
}

.doc-body blockquote {
  padding: 10px 16px;
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--bg-sunken);
  color: var(--text-muted);
}

.doc-body hr {
  height: 1px;
  margin: 26px 0;
  border: none;
  background: var(--border);
}

.doc-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

.doc-body a {
  border-bottom: 1px solid color-mix(in srgb, var(--primary) 40%, transparent);
}
.doc-body a:hover {
  border-bottom-color: var(--primary);
}

/* 表格 */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.doc-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
}

.doc-body th,
.doc-body td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.doc-body thead th {
  background: var(--bg-sunken);
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
}

.doc-body tbody tr:last-child td {
  border-bottom: none;
}

.doc-body tbody tr:hover {
  background: var(--bg-hover);
}

/* 行内代码 */
.doc-body :not(pre) > code {
  padding: 0.15em 0.4em;
  border: 1px solid var(--code-border);
  border-radius: 5px;
  background: var(--code-bg);
  color: var(--code-text);
  font-size: 0.88em;
  word-break: break-word;
}

/* 代码�?*/
.code-block {
  margin: 16px 0;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 6px 14px;
  border-bottom: 1px solid var(--code-border);
  background: color-mix(in srgb, var(--code-bg) 80%, var(--bg-sunken));
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: lowercase;
  letter-spacing: 0.04em;
}

.code-copy {
  padding: 2px 8px;
  border: 1px solid var(--code-border);
  border-radius: 5px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 11px;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.code-copy:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
}

.code-block code {
  display: block;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--code-text);
  white-space: pre;
  tab-size: 4;
  -webkit-overflow-scrolling: touch;
}

/* 公式 */
.katex {
  font-size: 1.06em;
}

.katex-display {
  margin: 18px 0;
  padding: 4px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.math-fallback {
  display: inline-block;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--danger-soft);
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.math-fallback.display {
  display: block;
  padding: 8px 12px;
  margin: 14px 0;
  white-space: pre-wrap;
  text-align: left;
}

/* 空状�?/ 加载 / 错误 */

/**
 * 关键修复：必须显式声�?[hidden]�? *
 * 浏览器对 hidden 属性的默认样式�?display:none，但�?*优先级极�?*—�? * 下面 .empty-state{display:grid}�?loading{display:flex} 这类显式 display
 * 会直接盖掉它，导�?app.js �?node.hidden = true 完全失效�? * 四张状态卡片（欢迎/资料库空/正在加载/加载失败）会同时显示在页面上�? */
[hidden] {
  display: none !important;
}

.empty-state {
  display: grid;
  place-items: center;
  padding: 6vh 8px;
  animation: fade-in var(--t-slow) var(--ease);
}

.empty-card {
  max-width: 560px;
  padding: 28px 26px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.empty-emoji {
  font-size: 30px;
  line-height: 1;
  margin-bottom: 10px;
}

.empty-card h2 {
  font-size: 19px;
  margin-bottom: 8px;
}

.empty-card p {
  font-size: 14.5px;
  color: var(--text-muted);
  line-height: 1.7;
}

.empty-tips,
.empty-steps {
  margin: 14px 0 0;
  padding-left: 1.4em;
  font-size: 14px;
  color: var(--text-muted);
}

.empty-tips li,
.empty-steps li {
  margin-bottom: 6px;
}

.empty-card code {
  padding: 0.12em 0.4em;
  border: 1px solid var(--code-border);
  border-radius: 5px;
  background: var(--code-bg);
  color: var(--code-text);
  font-size: 0.9em;
}

.empty-card .btn {
  margin-top: 18px;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.to-top {
  position: absolute;
  right: 18px;
  bottom: 22px;
  width: 38px;
  height: 38px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-muted);
  box-shadow: var(--shadow-md);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease),
    color var(--t-fast) var(--ease);
}
.to-top:hover {
  color: var(--primary);
  transform: translateY(-2px);
}

/* 锚点高亮 */
@keyframes flash-target {
  0% { background: color-mix(in srgb, var(--primary) 20%, transparent); }
  100% { background: transparent; }
}

.flash-target {
  animation: flash-target 1.6s var(--ease);
  border-radius: 4px;
}

/* 阅读区小节提问浮动按钮（移动端） */
.ask-float {
  position: absolute;
  right: 16px;
  bottom: 74px;
  z-index: 5;
  padding: 9px 14px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.ask-float:hover {
  background: var(--primary-strong);
  transform: translateY(-2px);
}

/* ---------- 9. 右：问答面板 ---------- */
.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  overflow: hidden;
  transition: opacity var(--t) var(--ease);
}

body.chat-collapsed .chat {
  opacity: 0;
  pointer-events: none;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 650;
}

.chat-title-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-banner {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex: 0 0 auto;
  margin: 10px 12px 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--warning) 35%, var(--border));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warning) 10%, var(--bg-elevated));
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.6;
  animation: pop-in-plain var(--t) var(--ease);
}

@keyframes pop-in-plain {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.banner-icon {
  flex: 0 0 auto;
  line-height: 1.5;
}

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-empty {
  margin: auto;
  padding: 24px 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.8;
}

.chat-empty strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 6px;
}

.chat-empty-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 14px;
}

.chip {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  color: var(--text-soft);
  font-size: 12.5px;
  text-align: left;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease);
}
.chip:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 100%;
  animation: msg-in var(--t-slow) var(--ease);
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-user {
  align-items: flex-end;
}

.msg-ai {
  align-items: flex-start;
}

.bubble {
  max-width: 92%;
  padding: 10px 13px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.7;
  overflow-wrap: break-word;
}

.msg-user .bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.msg-ai .bubble {
  background: var(--bg-sunken);
  color: var(--text-soft);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.is-error {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
  color: var(--text-soft);
}

.bubble-body > * + * {
  margin-top: 10px;
}

.bubble-body h1,
.bubble-body h2,
.bubble-body h3,
.bubble-body h4 {
  font-size: 15.5px;
  color: var(--text);
  line-height: 1.5;
  margin-top: 16px;
}

.bubble-body h2 {
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--border-strong);
}

.bubble-body ul,
.bubble-body ol {
  padding-left: 1.4em;
}

.bubble-body li + li {
  margin-top: 3px;
}

.bubble-body strong {
  color: var(--text);
}

.bubble-body .code-block {
  margin: 10px 0;
}

.bubble-body .code-block code {
  font-size: 12.5px;
}

.bubble-body .katex {
  font-size: 1em;
}

.bubble-body .katex-display {
  margin: 10px 0;
}

.bubble-body blockquote {
  padding: 6px 12px;
  border-left: 3px solid var(--border-strong);
  background: var(--bg-elevated);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

.bubble-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.bubble-body th,
.bubble-body td {
  padding: 5px 8px;
  border: 1px solid var(--border);
  text-align: left;
}

.bubble-body th {
  background: var(--bg-elevated);
}

/* 打字机光�?*/
.typing-cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -0.15em;
  border-radius: 1px;
  background: var(--primary);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* 思考动�?*/
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 13.5px;
}

.thinking-dots {
  display: inline-flex;
  gap: 3px;
}

.thinking-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary);
  animation: bounce 1.1s var(--ease) infinite;
}
.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* 参考来�?*/
.msg-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  max-width: 92%;
  font-size: 11.5px;
  color: var(--text-muted);
}

.source-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: 11.5px;
  transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.source-tag:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* 错误重试 */
.msg-foot {
  display: flex;
  gap: 8px;
  align-items: center;
}

.retry-btn {
  padding: 4px 11px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  color: var(--danger);
  font-size: 12px;
  transition: background var(--t-fast) var(--ease);
}
.retry-btn:hover {
  background: var(--danger-soft);
}

/* 输入�?*/
.chat-compose {
  flex: 0 0 auto;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.compose-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease);
}

.compose-box:focus-within {
  background: var(--bg-elevated);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.chat-input {
  width: 100%;
  max-height: 168px;
  padding: 2px 2px 0 0;
  border: none;
  background: transparent;
  font-size: 14.5px;
  line-height: 1.65;
  resize: none;
  overflow-y: auto;
}
.chat-input:focus {
  outline: none;
}
.chat-input::placeholder {
  color: var(--text-faint);
}
.chat-input:disabled {
  cursor: not-allowed;
}

.compose-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.compose-hint {
  flex: 1 1 auto;
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 10. 移动�?tabbar ---------- */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-drawer);
  display: none;
  align-items: stretch;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  transition: color var(--t-fast) var(--ease);
}

.tab svg {
  width: 20px;
  height: 20px;
}

.tab.is-active {
  color: var(--primary);
  font-weight: 600;
}

/* ---------- 11. toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  z-index: var(--z-toast);
  transform: translateX(-50%);
  max-width: min(90vw, 460px);
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: pop-in-plain var(--t) var(--ease);
  pointer-events: none;
}

/* ---------- 12. 响应式：<1024px ---------- */
@media (max-width: 1023px) {
  :root {
    --fs-body: 15.5px;
  }

  .only-mobile {
    display: inline-flex !important;
  }

  .brand-text {
    display: none;
  }

  .header-center {
    flex: 1 1 auto;
  }

  .status-text {
    display: none;
  }

  .status {
    padding: 5px;
    border-radius: 50%;
  }

  .app-body {
    inset: var(--header-h) 0 calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)) 0;
    display: block;
    position: fixed;
  }

  body.sidebar-collapsed .app-body,
  body.chat-collapsed .app-body,
  body.sidebar-collapsed.chat-collapsed .app-body {
    display: block;
  }

  .tabbar {
    display: flex;
  }

  /* 阅读区占�?*/
  .reader {
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  /* 目录抽屉 */
  .sidebar {
    position: fixed;
    top: var(--header-h);
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    left: 0;
    z-index: calc(var(--z-drawer) + 1);
    width: min(84vw, 340px);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    opacity: 1;
    transition: transform var(--t-slow) var(--ease);
    pointer-events: auto;
  }

  body.sidebar-collapsed .sidebar {
    opacity: 1;
    pointer-events: auto;
  }

  body.drawer-open .sidebar {
    transform: translateX(0);
  }

  body.drawer-open .sidebar-scrim {
    display: block;
  }

  /* 问答面板 */
  .chat {
    position: absolute;
    inset: 0;
    z-index: 2;
    border-left: none;
    transform: translateY(100%);
    opacity: 1;
    transition: transform var(--t-slow) var(--ease);
    pointer-events: auto;
  }

  body.chat-collapsed .chat {
    opacity: 1;
    pointer-events: auto;
  }

  body[data-view="chat"] .chat {
    transform: translateY(0);
  }

  body[data-view="toc"] .reader,
  body[data-view="reader"] .reader {
    z-index: 1;
  }

  .reader-scroll {
    padding: 18px 14px 140px;
  }

  .doc-body {
    font-size: 15.5px;
  }

  .doc-body h1 { font-size: 22px; }
  .doc-body h2 { font-size: 19px; margin-top: 28px; }
  .doc-body h3 { font-size: 16.5px; }

  .reader-top {
    padding: 8px 12px;
  }

  .breadcrumb .crumb {
    max-width: 30vw;
  }

  .bubble {
    max-width: 96%;
    font-size: 14px;
  }

  .toast {
    bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom, 0px));
  }

  .search-results {
    top: calc(var(--header-h) + 4px);
    width: calc(100vw - 16px);
    max-height: 66vh;
  }

  .sidebar-scrim {
    display: none;
    z-index: var(--z-drawer);
  }
}

/* 中等屏幕：问答面板稍�?*/
@media (min-width: 1024px) and (max-width: 1280px) {
  :root {
    --sidebar-w: 264px;
    --chat-w: 340px;
  }
}

/* 超宽屏：给阅读区留出更多呼吸空间 */
@media (min-width: 1600px) {
  :root {
    --sidebar-w: 320px;
    --chat-w: 440px;
  }
}

/* ---------- 13. 可访问性偏�?---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .app-header,
  .sidebar,
  .chat,
  .tabbar,
  .reader-top,
  .to-top,
  .search-results,
  .search-overlay {
    display: none !important;
  }
  .app-body {
    position: static;
    display: block;
  }
  .reader-scroll {
    overflow: visible;
    padding: 0;
  }
  body {
    overflow: visible;
  }
}

/* ==========================================================
   多教材：顶部教材选择器
   用原生 <select>：手机上会弹出系统选择器，比自绘下拉可靠。
   ========================================================== */
.subject-host {
  display: flex;
  align-items: center;
  margin-right: 14px;
}

.subject-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 9px;
  background: var(--card, #fff);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.subject-picker:hover {
  border-color: var(--brand, #4f46e5);
}

.subject-picker:focus-within {
  border-color: var(--brand, #4f46e5);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.subject-picker-icon {
  font-size: 14px;
  line-height: 1;
}

/* 原生 select：去掉默认外观，铺满整个胶囊 */
.subject-picker select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px; /* 防 iOS 聚焦放大 */
  border: 0;
  background: transparent;
  appearance: none;
}

.subject-picker-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text, #0f172a);
  white-space: nowrap;
  pointer-events: none;
}

.subject-picker-caret {
  position: absolute;
  right: 9px;
  font-size: 10px;
  color: var(--text-3, #94a3b8);
  pointer-events: none;
}

/* 窄屏：图标不显示，只留下拉 */
@media (max-width: 720px) {
  .subject-picker-icon {
    display: none;
  }
  .subject-host {
    margin-right: 8px;
  }
}

/* ==========================================================
   问答模式切换（电脑版）：问 AI / 问老师
   ========================================================== */
.chat-compose .ask-mode {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 0 8px;
}

.chat-compose .mode-btn {
  height: 30px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.chat-compose .mode-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.chat-compose .mode-btn.is-on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}

.chat-compose .mode-wall {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--brand);
  text-decoration: none;
  white-space: nowrap;
}

.chat-compose .mode-wall:hover {
  text-decoration: underline;
}

/* ==========================================================
   华丽升级：主题色随教材变 + 回答四段卡片化
   ========================================================== */
/* 顶栏渐变跟随科目主色（--brand 由 app.js 的 applyTheme 设置） */
.app-header {
  background: linear-gradient(135deg, var(--brand), var(--brand-2, #6366f1)) !important;
}

/* 回答里的四段标题做成「色条卡片头」，一眼能分清结构 */
.msg .bubble h2 {
  margin: 14px 0 8px;
  padding: 6px 10px;
  font-size: 0.98em;
  border-left: 3px solid var(--brand);
  border-radius: 6px;
  background: var(--brand-soft, #eef2ff);
  color: var(--brand);
}

.msg .bubble h2:first-child {
  margin-top: 2px;
}

/* 第一段（知识框架）前面的小图标 */
.msg .bubble h3 {
  margin: 12px 0 6px;
  padding-left: 2px;
}

/* ==========================================================
   华丽升级 · 质感层（纯样式，不动逻辑）
   ========================================================== */

/* ① 背景：极淡的双色光晕，跟随教材主题色，缓慢漂移 */
body {
  background-image:
    radial-gradient(900px 520px at 12% -8%, var(--brand-soft, #eef2ff) 0%, transparent 62%),
    radial-gradient(720px 480px at 92% 4%, color-mix(in srgb, var(--brand, #4f46e5) 12%, transparent) 0%, transparent 58%);
  background-attachment: fixed;
}

/* ② 玻璃拟态：顶栏、面板、卡片半透明 + 背景模糊 */
.app-header,
.chat-panel,
.sidebar,
.chapter,
.qitem,
.doc {
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
}

/* ③ 卡片：悬浮时轻微抬起 + 阴影加深（不要位移太大，避免抖动） */
.chapter,
.qitem,
.chat-empty-answer,
.doc-card {
  transition: transform .18s cubic-bezier(.4,0,.2,1),
              box-shadow .18s cubic-bezier(.4,0,.2,1),
              border-color .18s;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.chapter:hover,
.qitem:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(15, 23, 42, .08);
  border-color: color-mix(in srgb, var(--brand, #4f46e5) 35%, var(--border, #e2e8f0));
}

/* ④ 按钮：按下有反馈，主按钮带一点色晕 */
button,
.chip,
.mode-btn,
.tab {
  transition: transform .12s ease, background-color .15s ease, color .15s ease, box-shadow .15s;
}

button:active,
.chip:active,
.mode-btn:active {
  transform: scale(.97);
}

.btn.primary,
button.go,
.send-btn,
.action-btn {
  box-shadow: 0 2px 10px color-mix(in srgb, var(--brand, #4f46e5) 30%, transparent);
}

.btn.primary:hover,
button.go:hover {
  box-shadow: 0 4px 16px color-mix(in srgb, var(--brand, #4f46e5) 42%, transparent);
}

/* ⑤ 键盘可达性：焦点环用主题色 */
:focus-visible {
  outline: 2px solid var(--brand, #4f46e5);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ⑥ 选中文字用主题浅色 */
::selection {
  background: color-mix(in srgb, var(--brand, #4f46e5) 22%, transparent);
}

/* ⑦ 细滚动条（Windows 上观感提升明显） */
* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--brand, #4f46e5) 40%, transparent) transparent;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--brand, #4f46e5) 34%, transparent);
  border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--brand, #4f46e5) 55%, transparent);
}
*::-webkit-scrollbar-track {
  background: transparent;
}

/* ⑧ 内容淡入：切换文档时正文轻微上浮，避免"啪"地闪出来 */
@keyframes content-rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
#doc:not(:empty),
.chat-log > *:last-child {
  animation: content-rise .26s cubic-bezier(.4,0,.2,1) both;
}

@media (prefers-reduced-motion: reduce) {
  body, #doc, .chat-log > * {
    animation: none !important;
  }
  .chapter:hover, .qitem:hover { transform: none; }
}

/* ==========================================================
   欢迎页：教材大卡片
   ========================================================== */
.welcome-subjects {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 18px 0 6px;
  width: 100%;
}

.subject-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 14px 14px 13px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 14px;
  background: var(--card, #fff);
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  transition: transform .18s cubic-bezier(.4,0,.2,1), box-shadow .18s, border-color .18s;
}

/* 左侧一条主题色竖条，一眼区分科目 */
.subject-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--sc, var(--brand));
  opacity: .85;
}

.subject-card:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--sc, var(--brand));
  box-shadow: 0 8px 22px color-mix(in srgb, var(--sc, #4f46e5) 20%, transparent);
}

.subject-card:active:not(:disabled) {
  transform: translateY(0) scale(.99);
}

.subject-card-icon {
  font-size: 22px;
  line-height: 1.1;
  color: var(--sc, var(--brand));
  font-weight: 700;
}

.subject-card-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text, #0f172a);
}

.subject-card-meta {
  font-size: 12px;
  color: var(--text-3, #94a3b8);
  line-height: 1.5;
}

/* 完善中的科目：置灰不可点 */
.subject-card.is-coming {
  cursor: not-allowed;
  opacity: .55;
  filter: grayscale(.5);
}

.subject-card.is-coming::before {
  background: var(--text-3, #94a3b8);
}

@media (max-width: 560px) {
  .welcome-subjects {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================
   闯关式启动页
   ========================================================== */
.landing {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  overflow: hidden;
  background:
    radial-gradient(1100px 640px at 15% -10%, #eef2ff 0%, transparent 60%),
    radial-gradient(900px 600px at 88% 8%, #f5f3ff 0%, transparent 58%),
    linear-gradient(160deg, #fbfbff 0%, #f4f4fb 100%);
}

.landing[hidden] { display: none !important; }

/* 背景漂浮数学符号 */
.landing-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.landing-bg span {
  position: absolute;
  font-family: ui-monospace, monospace;
  font-size: 46px;
  color: color-mix(in srgb, var(--brand, #4f46e5) 12%, transparent);
  animation: drift 18s ease-in-out infinite;
}
.landing-bg span:nth-child(1) { left: 6%;  top: 12%; animation-delay: 0s;   font-size: 60px; }
.landing-bg span:nth-child(2) { left: 22%; top: 72%; animation-delay: -2s;  font-size: 40px; }
.landing-bg span:nth-child(3) { left: 44%; top: 8%;  animation-delay: -4s;  font-size: 54px; }
.landing-bg span:nth-child(4) { left: 68%; top: 66%; animation-delay: -6s;  font-size: 48px; }
.landing-bg span:nth-child(5) { left: 86%; top: 22%; animation-delay: -8s;  font-size: 62px; }
.landing-bg span:nth-child(6) { left: 12%; top: 46%; animation-delay: -10s; font-size: 36px; }
.landing-bg span:nth-child(7) { left: 58%; top: 34%; animation-delay: -12s; font-size: 34px; }
.landing-bg span:nth-child(8) { left: 78%; top: 82%; animation-delay: -14s; font-size: 38px; }
.landing-bg span:nth-child(9) { left: 32%; top: 88%; animation-delay: -16s; font-size: 44px; }
.landing-bg span:nth-child(10){ left: 92%; top: 52%; animation-delay: -9s;  font-size: 40px; }

@keyframes drift {
  0%, 100% { transform: translateY(0) rotate(0deg); opacity: .8; }
  50%      { transform: translateY(-22px) rotate(6deg); opacity: 1; }
}

.landing-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 760px;
  text-align: center;
}

.landing-kicker {
  margin: 0 0 10px;
  font-family: ui-monospace, monospace;
  font-size: 11.5px;
  letter-spacing: .22em;
  color: var(--text-3, #94a3b8);
}

.landing-title {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: .01em;
  color: var(--text, #0f172a);
}

.landing-sub {
  margin: 12px auto 26px;
  max-width: 520px;
  font-size: 14px;
  line-height: 1.85;
  color: var(--text-2, #475569);
}

.landing-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  text-align: left;
}

.landing-foot {
  margin: 22px 0 0;
  font-size: 12.5px;
  color: var(--text-3, #94a3b8);
}

/* 关卡卡片：比欢迎页的更大更醒目 */
.landing-cards .subject-card {
  padding: 18px 18px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 2px 10px rgba(15, 23, 42, .05);
}

.landing-cards .subject-card-name { font-size: 17px; }
.landing-cards .subject-card-icon { font-size: 26px; }

@media (max-width: 620px) {
  .landing-title { font-size: 26px; }
  .landing-cards { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .landing-bg span { animation: none; }
}

/* ==========================================================
   启动页 · 校园照片层
   把照片放到 public/assets/cuc/bg.jpg 就会自动生效；
   没有照片时这一层不绘制，退回到渐变 + 数学符号。
   ========================================================== */
.landing::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url('/assets/cuc/bg.jpg');
  background-size: cover;
  background-position: center 38%;
  background-repeat: no-repeat;
  opacity: 0.20;
  /* 轻微模糊，避免照片细节和文字抢注意力 */
  filter: saturate(105%) blur(0.3px);
  /* 上下两端压暗一点，保证标题和卡片可读 */
  mask-image: linear-gradient(180deg, rgba(0,0,0,.55), rgba(0,0,0,1) 35%, rgba(0,0,0,1) 65%, rgba(0,0,0,.55));
  -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,.55), rgba(0,0,0,1) 35%, rgba(0,0,0,1) 65%, rgba(0,0,0,.55));
}

/* 校名标签 */
.landing-school {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 14px;
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--brand, #4f46e5);
  background: color-mix(in srgb, var(--brand, #4f46e5) 10%, #fff);
  border: 1px solid color-mix(in srgb, var(--brand, #4f46e5) 22%, transparent);
}

@media (prefers-reduced-motion: reduce) {
  .landing::before { filter: none; }
}

/* 照片实装后微调：透明度与取景再压一点，保证文字可读 */
.landing::before {
  opacity: 0.30;
  background-position: center 42%;
  filter: saturate(112%) contrast(102%) blur(0.2px);
}

/* ==========================================================
   启动页视差：照片随鼠标轻微位移，产生纵深
   由 JS 在 .landing 上设置 --land-px / --land-py（-1 ~ 1）
   ========================================================== */
.landing::before {
  transform: translate3d(calc(var(--land-px, 0) * 12px), calc(var(--land-py, 0) * 9px), 0) scale(1.05);
  transition: transform .35s cubic-bezier(.4, 0, .2, 1);
  will-change: transform;
}

/* 背景数学符号反向位移，形成第二层视差 */
.landing-bg {
  transform: translate3d(calc(var(--land-px, 0) * -18px), calc(var(--land-py, 0) * -14px), 0);
  transition: transform .45s cubic-bezier(.4, 0, .2, 1);
  will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
  .landing::before, .landing-bg { transform: none !important; transition: none; }
}

/* ==========================================================
   ④ 侧边栏高亮条：当前讲义左侧一条主题色竖条
   ========================================================== */
.doc-link {
  position: relative;
  transition: background-color .18s, color .18s, padding-left .18s;
}

.doc-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 0;
  border-radius: 0 3px 3px 0;
  background: var(--brand, #4f46e5);
  transform: translateY(-50%);
  transition: height .2s cubic-bezier(.4, 0, .2, 1);
}

.doc-link.is-active::before {
  height: 62%;
}

.doc-link.is-active {
  padding-left: 10px;
}

/* ==========================================================
   ⑤ 搜索框：聚焦时展开 + 主题色光晕
   ========================================================== */
.search-wrap {
  transition: max-width .26s cubic-bezier(.4, 0, .2, 1),
              box-shadow .26s cubic-bezier(.4, 0, .2, 1),
              border-color .2s;
  border-radius: 999px;
}

.search-wrap:focus-within {
  max-width: 560px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand, #4f46e5) 18%, transparent);
  border-color: color-mix(in srgb, var(--brand, #4f46e5) 55%, transparent);
}

.search-wrap:focus-within .search-icon {
  color: var(--brand, #4f46e5);
}

@media (prefers-reduced-motion: reduce) {
  .doc-link, .doc-link::before, .search-wrap { transition: none; }
}

/* ==========================================================
   ② 流式打字光标：AI 回答时末尾闪烁的方块
   只在 [data-streaming="1"] 时出现，回答结束自动消失
   ========================================================== */
@keyframes caret-blink {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.msg-ai[data-streaming="1"] .bubble::after {
  content: '▍';
  display: inline;
  margin-left: 1px;
  color: var(--brand, #4f46e5);
  animation: caret-blink 1s steps(1, end) infinite;
}

/* 光标不该被当成正文复制走：加在伪元素上，天然不会被选中 */
@media (prefers-reduced-motion: reduce) {
  .msg-ai[data-streaming="1"] .bubble::after {
    animation: none;
    opacity: .55;
  }
}

/* ==========================================================
   ① 电脑端正文切换：重放淡入（配合 app.js 的 replayDocEnter）
   ========================================================== */
#doc.doc-enter {
  animation: doc-enter .28s cubic-bezier(.4, 0, .2, 1) both;
}

@keyframes doc-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  #doc.doc-enter { animation: none; }
}

/* ==========================================================
   电脑端「互动实验室」主按钮：从图标改成显眼的胶囊按钮
   ========================================================== */
.icon-btn.lab-btn {
  width: auto;
  min-width: 0;
  padding: 0 14px 0 11px;
  height: 34px;
  gap: 7px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand, #4f46e5), var(--brand-2, #6366f1));
  border: none;
  box-shadow: 0 3px 14px color-mix(in srgb, var(--brand, #4f46e5) 38%, transparent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .01em;
  position: relative;
  overflow: visible;
  transition: transform .16s cubic-bezier(.4, 0, .2, 1),
              box-shadow .2s,
              filter .2s;
}

.icon-btn.lab-btn svg {
  width: 17px;
  height: 17px;
  stroke: #fff;
  flex: none;
}

.icon-btn.lab-btn .lab-label {
  white-space: nowrap;
  line-height: 1;
}

/* 悬浮：抬起 + 光晕加强 */
.icon-btn.lab-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--brand, #4f46e5) 52%, transparent);
  filter: brightness(1.06);
}

.icon-btn.lab-btn:active {
  transform: translateY(0) scale(.98);
}

/* 呼吸光晕：每隔几秒轻微扩散一次，吸引视线但不刺眼 */
@keyframes lab-halo {
  0%, 72%, 100% {
    box-shadow: 0 3px 14px color-mix(in srgb, var(--brand, #4f46e5) 38%, transparent);
  }
  80% {
    box-shadow: 0 3px 14px color-mix(in srgb, var(--brand, #4f46e5) 38%, transparent),
                0 0 0 6px color-mix(in srgb, var(--brand, #4f46e5) 16%, transparent);
  }
  88% {
    box-shadow: 0 3px 14px color-mix(in srgb, var(--brand, #4f46e5) 38%, transparent);
  }
}

.icon-btn.lab-btn {
  animation: lab-halo 6s ease-in-out infinite;
}

/* 窄屏只留图标，避免顶栏挤爆 */
@media (max-width: 1180px) {
  .icon-btn.lab-btn {
    padding: 0 11px;
  }
  .icon-btn.lab-btn .lab-label {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn.lab-btn {
    animation: none;
  }
}

/* ==========================================================
   修正：实验室按钮改用白底紫字
   原因：顶栏本身是主题色渐变，用同色按钮会糊在一起看不清
   ========================================================== */
.icon-btn.lab-btn {
  background: #ffffff;
  color: var(--brand, #4f46e5);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18);
}

.icon-btn.lab-btn svg {
  stroke: var(--brand, #4f46e5);
}

.icon-btn.lab-btn .lab-label {
  color: var(--brand, #4f46e5);
  font-weight: 700;
}

.icon-btn.lab-btn:hover {
  background: #ffffff;
  color: var(--brand-dark, #4338ca);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.28);
  filter: none;
}

.icon-btn.lab-btn:hover svg {
  stroke: var(--brand-dark, #4338ca);
}

.icon-btn.lab-btn:hover .lab-label {
  color: var(--brand-dark, #4338ca);
}

/* 呼吸光晕也改成白色扩散，在白底按钮上更自然 */
@keyframes lab-halo {
  0%, 72%, 100% {
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18);
  }
  80% {
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18),
                0 0 0 7px rgba(255, 255, 255, 0.28);
  }
  88% {
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18);
  }
}

.icon-btn.lab-btn {
  animation: lab-halo 6s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn.lab-btn { animation: none; }
}

/* ==========================================================
   右上角一整套按钮：统一成白底胶囊（与「互动实验室」同一视觉体系）
   ========================================================== */
.header-right {
  gap: 8px;
}

/* 除实验室按钮外的三个图标按钮：白底 + 主题色图标 */
.header-right .icon-btn:not(.lab-btn) {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.9);
  color: var(--brand, #4f46e5);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16);
  transition: transform .16s cubic-bezier(.4, 0, .2, 1),
              box-shadow .2s,
              background-color .2s,
              color .2s;
}

.header-right .icon-btn:not(.lab-btn) svg {
  width: 17px;
  height: 17px;
  stroke: var(--brand, #4f46e5);
}

.header-right .icon-btn:not(.lab-btn):hover {
  background: #ffffff;
  color: var(--brand-dark, #4338ca);
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(15, 23, 42, 0.26);
}

.header-right .icon-btn:not(.lab-btn):hover svg {
  stroke: var(--brand-dark, #4338ca);
}

.header-right .icon-btn:not(.lab-btn):active {
  transform: translateY(0) scale(.97);
}

/* 状态徽章也统一：白底 + 主题色文字，避免顶栏上出现第三种杂色 */
.header-right .status {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16);
  border-radius: 999px;
  padding: 0 11px;
  height: 30px;
}

.header-right .status .status-text {
  color: var(--brand, #4f46e5);
  font-weight: 600;
}

/* 状态点的颜色保留语义：绿灯还是绿、红灯还是红 */
.header-right .status .status-dot {
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  .header-right .icon-btn:not(.lab-btn) { transition: none; }
}

/* ==========================================================
   启动页：标出"上次用的教材"
   ========================================================== */
.subject-card.is-current {
  border-color: var(--sc, var(--brand));
  box-shadow: 0 2px 12px color-mix(in srgb, var(--sc, #4f46e5) 22%, transparent);
}

.sc-recent {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 600;
  vertical-align: middle;
  color: #fff;
  background: var(--sc, var(--brand));
}

/* ==========================================================
   ① 加载骨架屏：用灰块占位代替转圈，专业感更强
   ========================================================== */
.skeleton-wrap {
  display: block;
  width: 100%;
  max-width: 720px;
  padding: 6px 2px;
}

.skeleton-wrap .skeleton-line,
.skeleton-wrap .skeleton-block {
  position: relative;
  overflow: hidden;
  border-radius: 7px;
  background: color-mix(in srgb, var(--text-3, #94a3b8) 12%, transparent);
  margin: 0 0 12px;
}

.skeleton-wrap .skeleton-line {
  height: 13px;
}

.skeleton-wrap .skeleton-line.tall {
  height: 24px;
  margin-bottom: 20px;
}

.skeleton-wrap .skeleton-block {
  height: 150px;
  margin: 18px 0;
  border-radius: 10px;
}

.skeleton-wrap .w-40 { width: 40%; }
.skeleton-wrap .w-60 { width: 60%; }
.skeleton-wrap .w-75 { width: 75%; }
.skeleton-wrap .w-80 { width: 80%; }
.skeleton-wrap .w-85 { width: 85%; }
.skeleton-wrap .w-90 { width: 90%; }

/* 扫光动画 */
@keyframes skeleton-shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.skeleton-wrap .skeleton-line::after,
.skeleton-wrap .skeleton-block::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    color-mix(in srgb, #ffffff 55%, transparent) 50%,
    transparent 100%
  );
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

/* 屏幕阅读器专用文字 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-wrap .skeleton-line::after,
  .skeleton-wrap .skeleton-block::after {
    animation: none;
  }
}

/* ==========================================================
   ③ 空状态统一：图标做成柔和圆形底、标题分级、整体淡入
   影响：搜索无结果 / 资料库为空 / 文档加载失败 / 欢迎页
   ========================================================== */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  animation: empty-in .28s cubic-bezier(.4, 0, .2, 1) both;
}

@keyframes empty-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.empty-card {
  max-width: 560px;
  width: 100%;
  text-align: center;
  padding: 34px 28px 30px;
  border-radius: 20px;
  border: 1px solid var(--border, #e2e8f0);
  background: color-mix(in srgb, var(--card, #fff) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 10px 34px rgba(15, 23, 42, .06);
}

/* 图标：柔和圆形底 + 主题色 */
.empty-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
  background: color-mix(in srgb, var(--brand, #4f46e5) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand, #4f46e5) 16%, transparent);
}

.empty-card h2 {
  margin: 0 0 10px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.01em;
}

.empty-card > p {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.85;
  color: var(--text-2, #475569);
}

/* 提示列表：左侧不再用 • 挂在外边，改成带小点的卡片行 */
.empty-tips {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
  display: grid;
  gap: 8px;
}

.empty-tips li {
  position: relative;
  padding: 9px 12px 9px 30px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--brand, #4f46e5) 5%, transparent);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-2, #475569);
}

.empty-tips li::before {
  content: '';
  position: absolute;
  left: 13px;
  top: 16px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand, #4f46e5);
  opacity: .75;
}

@media (prefers-reduced-motion: reduce) {
  .empty-state { animation: none; }
}

/* ==========================================================
   ④ 目录滚动进度条（CSS 滚动驱动动画，无需 JS）
   浏览器不支持 scroll() 时只是不显示，不影响任何功能
   ========================================================== */
.sidebar {
  position: relative;
}

@supports (animation-timeline: scroll()) {
  .sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 3px;
    height: 100%;
    transform-origin: top;
    transform: scaleY(0);
    background: linear-gradient(
      180deg,
      var(--brand, #4f46e5),
      color-mix(in srgb, var(--brand, #4f46e5) 35%, transparent)
    );
    border-radius: 0 3px 3px 0;
    animation: sidebar-progress linear;
    animation-timeline: scroll(nearest block);
    pointer-events: none;
  }
}

@keyframes sidebar-progress {
  from { transform: scaleY(0); }
  to   { transform: scaleY(1); }
}

/* ==========================================================
   ⑤ 搜索结果：键盘选中态
   ========================================================== */
.sr-item.is-kb-focus {
  background: color-mix(in srgb, var(--brand, #4f46e5) 12%, transparent);
  border-color: color-mix(in srgb, var(--brand, #4f46e5) 55%, transparent);
  box-shadow: inset 3px 0 0 var(--brand, #4f46e5);
}

/* ==========================================================
   顶栏汉字按钮：练习 / 错题本（与「互动实验室」同一体系，但不做呼吸光晕）
   ========================================================== */
.header-right .icon-btn.text-btn {
  width: auto;
  min-width: 0;
  padding: 0 13px 0 10px;
  height: 34px;
  gap: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.9);
  color: var(--brand, #4f46e5);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16);
  font-size: 13px;
  font-weight: 600;
  transition: transform .16s cubic-bezier(.4, 0, .2, 1), box-shadow .2s, background-color .2s;
}

.header-right .icon-btn.text-btn svg {
  width: 16px;
  height: 16px;
  stroke: var(--brand, #4f46e5);
  flex: none;
}

.header-right .icon-btn.text-btn .lab-label {
  color: var(--brand, #4f46e5);
  white-space: nowrap;
  line-height: 1;
}

.header-right .icon-btn.text-btn:hover {
  background: #fff;
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(15, 23, 42, 0.26);
}

.header-right .icon-btn.text-btn:active {
  transform: translateY(0) scale(.98);
}

/* 窄屏只留图标 */
@media (max-width: 1320px) {
  .header-right .icon-btn.text-btn {
    padding: 0 10px;
  }
  .header-right .icon-btn.text-btn .lab-label {
    display: none;
  }
}
