/* ============================================================
   高中知识讲解库 · 样式
   浅色优雅主题 · 各科配色 · 响应式
   ============================================================ */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --text: #1f2430;
  --muted: #6b7280;
  --faint: #9aa1ad;
  --border: #e7e9ee;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(20, 30, 50, 0.06);
  --shadow-hover: 0 12px 34px rgba(20, 30, 50, 0.14);
  --maxw: 1160px;
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui,
    -apple-system, "Segoe UI", Roboto, sans-serif;
  --accent: #2563eb; /* 默认主题色，按学科覆盖 */
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff; font-size: 18px; font-weight: 800;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.brand-text { font-size: 17px; letter-spacing: 0.5px; }

.search { position: relative; margin-left: auto; flex: 0 1 360px; }
.search input {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.search-results {
  position: absolute;
  top: 46px; left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover);
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
  z-index: 60;
}
.search-results .item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.search-results .item:last-child { border-bottom: none; }
.search-results .item:hover { background: var(--surface-2); }
.search-results .item .t { font-size: 14px; font-weight: 600; }
.search-results .item .p { font-size: 12px; color: var(--muted); }
.search-results .empty { padding: 14px; color: var(--muted); font-size: 13px; }

/* ---------------- 主体 ---------------- */
.app { max-width: var(--maxw); margin: 0 auto; padding: 28px 20px 60px; }

/* ---------------- 首页 Hero ---------------- */
.hero {
  background: linear-gradient(135deg, #eef2ff 0%, #faf5ff 55%, #fff7ed 100%);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 40px 36px;
  margin-bottom: 30px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute; right: -60px; top: -60px;
  width: 240px; height: 240px;
  background: radial-gradient(circle, rgba(124,58,237,0.12), transparent 70%);
}
.hero h1 { margin: 0 0 8px; font-size: 30px; letter-spacing: 1px; }
.hero p { margin: 0; color: var(--muted); font-size: 15px; max-width: 640px; }

.stats { display: flex; flex-wrap: wrap; gap: 26px; margin-top: 22px; }
.stats .stat .n { font-size: 26px; font-weight: 800; color: var(--text); }
.stats .stat .l { font-size: 13px; color: var(--muted); }

/* ---------------- 学科卡片 ---------------- */
.section-title { font-size: 18px; font-weight: 700; margin: 6px 0 18px; }
.grid { display: grid; gap: 18px; }
.grid.subjects { grid-template-columns: repeat(3, 1fr); }
.grid.books { grid-template-columns: repeat(3, 1fr); }
.grid.units { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s;
  cursor: pointer;
  position: relative;
  display: block;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: transparent;
}
.card .topbar-accent {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 5px; border-radius: var(--radius) 0 0 var(--radius);
  background: var(--accent);
}
.subject-card { display: flex; align-items: center; gap: 16px; }
.subject-card .badge {
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 14px;
  display: grid; place-items: center;
  color: #fff; font-size: 22px; font-weight: 800;
  background: var(--accent);
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}
.subject-card .meta .name { font-size: 19px; font-weight: 700; }
.subject-card .meta .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.subject-card .meta .count { font-size: 12px; color: var(--faint); margin-top: 4px; }

/* ---------------- 页头 ---------------- */
.page-head {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 22px;
}
.page-head .badge {
  width: 56px; height: 56px; flex: 0 0 56px;
  border-radius: 16px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 24px; background: var(--accent);
  box-shadow: 0 8px 20px rgba(0,0,0,0.14);
}
.page-head .title { font-size: 24px; font-weight: 800; margin: 0; }
.page-head .desc { color: var(--muted); font-size: 14px; margin: 2px 0 0; }
.note {
  background: #fffbeb; border: 1px solid #fde68a;
  color: #92400e; border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 13px; margin-bottom: 20px;
}

/* ---------------- 面包屑 ---------------- */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { margin: 0 8px; color: var(--faint); }
.crumbs .cur { color: var(--text); font-weight: 600; }

/* ---------------- 书/专题/单元 卡片 ---------------- */
.book-card .name { font-size: 16px; font-weight: 700; }
.book-card .sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

.topic-card { padding: 16px 18px; }
.topic-card .name { font-size: 16px; font-weight: 700; }
.topic-card .sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

.unit-card { padding: 18px 20px; }
.unit-card .name { font-size: 15px; font-weight: 600; }
.unit-card .go { font-size: 12px; color: var(--accent); margin-top: 8px; font-weight: 600; }

/* 示例占位标记 */
.tag-example {
  display: inline-block; font-size: 11px; font-weight: 700;
  color: #b45309; background: #fef3c7;
  border-radius: 6px; padding: 1px 7px; margin-left: 8px;
  vertical-align: middle;
}

/* ---------------- 单元内容页 ---------------- */
.content-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 34px;
  margin-top: 8px;
}
.content-wrap h1 { font-size: 24px; border-left: 5px solid var(--accent); padding-left: 12px; }
.content-wrap h2 { font-size: 20px; margin-top: 28px; }
.content-wrap h3 { font-size: 17px; margin-top: 22px; color: #374151; }
.content-wrap img { max-width: 100%; border-radius: 10px; border: 1px solid var(--border); margin: 12px 0; }
.content-wrap pre {
  background: #0f172a; color: #e2e8f0; padding: 14px 16px;
  border-radius: 10px; overflow-x: auto; font-size: 13px;
}
.content-wrap code { font-family: "SFMono-Regular", Consolas, monospace; }
.content-wrap :not(pre) > code { background: #eef2ff; color: #3730a3; padding: 1px 6px; border-radius: 5px; }
.content-wrap blockquote {
  border-left: 4px solid var(--accent); background: var(--surface-2);
  margin: 14px 0; padding: 8px 16px; color: var(--muted);
}
.content-wrap table { border-collapse: collapse; width: 100%; margin: 14px 0; }
.content-wrap th, .content-wrap td { border: 1px solid var(--border); padding: 8px 12px; font-size: 14px; }
.content-wrap th { background: var(--surface-2); }

.placeholder {
  text-align: center; padding: 48px 20px; color: var(--muted);
}
.placeholder .big { font-size: 40px; margin-bottom: 12px; }
.placeholder .hint {
  display: inline-block; text-align: left; max-width: 560px;
  background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: var(--radius-sm); padding: 16px 20px; margin-top: 14px;
  font-size: 14px; color: var(--text);
}
.placeholder .hint code { background: #eef2ff; color: #3730a3; padding: 1px 6px; border-radius: 5px; }

/* ---------------- 单元内容页：讲义美化 ---------------- */
/* 标题层级（覆盖通用规则，优先级更高） */
.content-wrap .sec-h1 {
  font-size: 23px; font-weight: 800; border-left: 5px solid var(--accent);
  padding-left: 12px; margin: 32px 0 14px;
}
.content-wrap .divider {
  font-size: 20px; font-weight: 800; color: var(--text);
  margin: 30px 0 12px; padding-left: 14px; border-left: 5px solid var(--accent);
}
.content-wrap .sec-h3 { font-size: 16px; color: #475569; margin-top: 18px; }

/* 「讲」区块：每个知识点一张卡 */
.lecture {
  border: 1px solid var(--border); border-radius: 14px;
  padding: 6px 24px 20px; margin: 22px 0;
  background: linear-gradient(180deg, #ffffff, #fcfdff);
}
.content-wrap .lec-title {
  font-size: 19px; font-weight: 800; color: var(--accent);
  margin: 20px 0 8px; padding-bottom: 10px;
  border-bottom: 2px solid color-mix(in srgb, var(--accent) 28%, transparent);
}

/* 「练习」区块：课后习题一张卡 */
.exercise {
  border: 1px solid #fde68a; background: #fffdf5;
  border-radius: 14px; padding: 4px 24px 18px; margin: 22px 0;
}
.content-wrap .ex-title {
  font-size: 18px; font-weight: 800; color: #b45309; margin: 18px 0 8px;
}

/* 五段字段卡片：左色条 + 标签胶囊 + 正文 */
.seg {
  border-left: 4px solid var(--seg-c, #94a3b8);
  background: var(--seg-bg, #f8fafc);
  border-radius: 0 12px 12px 0;
  padding: 12px 16px; margin: 12px 0;
}
.seg-label {
  display: inline-block; font-size: 12px; font-weight: 800; color: #fff;
  background: var(--seg-c, #94a3b8); padding: 2px 10px; border-radius: 999px;
  margin-bottom: 6px; letter-spacing: 0.5px;
}
.seg-body { font-size: 14.5px; color: #334155; }
.seg-body p { margin: 6px 0; }
.seg-body ul, .seg-body ol { margin: 6px 0; padding-left: 22px; }
.seg-body table { margin: 8px 0; }

.seg-textbook { --seg-c: #2563eb; --seg-bg: #eff6ff; }
.seg-plain   { --seg-c: #16a34a; --seg-bg: #f0fdf4; }
.seg-think   { --seg-c: #7c3aed; --seg-bg: #f5f3ff; }
.seg-exam    { --seg-c: #ea580c; --seg-bg: #fff7ed; }
.seg-warn    { --seg-c: #dc2626; --seg-bg: #fef2f2; }
.seg-core    { --seg-c: #d97706; --seg-bg: #fffbeb; }
.seg-core .seg-body { font-weight: 700; color: #92400e; }
.seg-orig    { --seg-c: #475569; --seg-bg: #f8fafc; }
.seg-point   { --seg-c: #4f46e5; --seg-bg: #eef2ff; }
.seg-rel     { --seg-c: #0d9488; --seg-bg: #f0fdfa; }
.seg-entry   { --seg-c: #db2777; --seg-bg: #fdf2f8; }
.seg-route   { --seg-c: #0891b2; --seg-bg: #ecfeff; }
.seg-why     { --seg-c: #6d28d9; --seg-bg: #f5f3ff; }
.seg-ans     { --seg-c: #059669; --seg-bg: #ecfdf5; }
.seg-ans .seg-body { font-weight: 600; color: #065f46; }
.seg-detail  { --seg-c: #64748b; --seg-bg: #f8fafc; }
.warn-ico { font-size: 13px; vertical-align: -1px; }

/* 引用块（讲义导语 / 说明） */
.content-wrap blockquote.callout {
  border-left: 4px solid var(--accent); background: #f8fafc;
  border-radius: 0 10px 10px 0; padding: 10px 16px; margin: 14px 0;
  color: #475569; font-size: 14px;
}

/* 课本页图：图 + 图注 */
.content-wrap figure.fig { margin: 14px 0; text-align: center; }
.content-wrap figure.fig img {
  max-width: 100%; border-radius: 10px; border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(20, 30, 50, 0.08);
}
.content-wrap figcaption { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.content-wrap .inline-img { max-width: 100%; vertical-align: middle; }

/* 表格：横向滚动 + 斑马纹 */
.table-wrap {
  overflow-x: auto; margin: 14px 0; border-radius: 10px;
  border: 1px solid var(--border);
}
.content-wrap table { border-collapse: collapse; width: 100%; margin: 0; font-size: 13.5px; }
.content-wrap th {
  background: #f1f5f9; color: #334155; font-weight: 700; text-align: left;
  padding: 9px 12px; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.content-wrap td { padding: 8px 12px; border-bottom: 1px solid var(--border); color: #334155; }
.content-wrap tbody tr:nth-child(even) { background: #fafbfc; }
.content-wrap tbody tr:hover { background: #f0f7ff; }

/* 方程式 code 块 */
.content-wrap pre.eq {
  background: #0f172a; color: #e2e8f0; padding: 14px 18px;
  border-radius: 10px; overflow-x: auto; font-size: 13.5px; line-height: 1.65;
}
.content-wrap pre.eq code { font-family: "SFMono-Regular", Consolas, monospace; }

/* 化学 LaTeX 箭头与条件 */
.content-wrap .chem-cond,
.content-wrap pre.eq sup.chem-cond {
  color: #f59e0b; font-weight: 600; font-size: 0.82em;
}
.content-wrap pre.eq sub { color: #94a3b8; }
.content-wrap pre.eq sup { color: #f59e0b; }

/* 单元页布局：内容全宽，目录为悬浮按钮+侧滑面板 */
.unit-layout {
  display: block;
  position: relative;
}
.content-wrap {
  max-width: 960px;
  margin: 0 auto;
}

/* ---- 目录悬浮按钮（右下角）---- */
.toc-toggle {
  position: fixed; right: 24px; bottom: 32px;
  z-index: 200; cursor: pointer;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: #fff;
  border: none; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  font-size: 20px; display: flex; align-items: center; justify-content: center;
  transition: transform .2s, box-shadow .2s;
}
.toc-toggle:hover { transform: scale(1.08); box-shadow: 0 6px 22px rgba(0,0,0,.22); }

/* ---- 目录侧滑面板 ---- */
.toc-overlay {
  display: none; position: fixed; inset: 0; z-index: 298;
  background: rgba(15,23,42,.35);
}
.toc-overlay.show { display: block; }
.toc-drawer {
  position: fixed; top: 0; right: -320px; bottom: 0; z-index: 299;
  width: 300px; background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(0,0,0,.10);
  transition: right .28s ease; overflow-y: auto;
  padding: 20px 14px 40px;
}
.toc-drawer.open { right: 0; }
.toc-drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.toc-drawer-close {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--muted); padding: 2px 6px; border-radius: 8px;
}
.toc-drawer-close:hover { background: var(--surface-2); color: var(--text); }
.toc { position: static; max-height: none; }
.toc-box {
  background: transparent; border: none; border-radius: 0; padding: 0;
}
.toc-title {
  font-size: 12px; font-weight: 800; color: var(--muted); letter-spacing: 1px;
  margin: 2px 8px 10px; text-transform: uppercase;
}
.toc-link {
  display: block; padding: 5px 10px; border-radius: 8px; font-size: 13px;
  color: #475569; cursor: pointer; border-left: 3px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toc-link:hover { background: var(--surface-2); color: var(--accent); }
.toc-link.active {
  background: #eff6ff; color: var(--accent); border-left-color: var(--accent); font-weight: 700;
}
.toc-link.l2 { padding-left: 20px; }
.toc-link.l3 { padding-left: 32px; font-size: 12.5px; color: var(--muted); }

/* ---------------- 页脚 ---------------- */
.footer { border-top: 1px solid var(--border); margin-top: 40px; }
.footer-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 18px 20px;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  font-size: 13px; color: var(--muted);
}
.muted { color: var(--muted); }

/* ---------------- 响应式 ---------------- */
@media (max-width: 880px) {
  .grid.subjects, .grid.books { grid-template-columns: repeat(2, 1fr); }
  .grid.units { grid-template-columns: 1fr; }
  .hero { padding: 30px 22px; }
  .hero h1 { font-size: 24px; }
  .content-wrap { max-width: 100%; }
  .toc-drawer { width: 260px; }
}
@media (max-width: 560px) {
  .grid.subjects, .grid.books { grid-template-columns: 1fr; }
  .topbar-inner { flex-wrap: wrap; }
  .search { flex-basis: 100%; order: 3; }
  .app { padding: 20px 14px 48px; }
}
