/* ==========================================================================
   《学渣自救手册》HTML 版 · 样式表 —— 书卷学术风
   浅色米纸主题，面向高三学生阅读（长文 + 数学公式 + 表格密集）
   ========================================================================== */

:root {
  --paper: #f6f2e9;
  --surface: #fffdf7;
  --surface-2: #faf6ec;

  --ink: #26241f;
  --ink-2: #3f3d37;
  --muted: #7a746a;

  --line: #ddd6c6;
  --line-2: #eae4d6;

  --accent: #5b4632;
  --accent-soft: #f1ece2;
  --accent-ink: #5b4632;

  --cinnabar: #a63d2f;
  --cinnabar-soft: #f3e4df;

  --ochre: #8a5a2b;
  --ochre-soft: #f0e7da;
  --ochre-line: #d4c4a8;

  --green: #3d6b52;
  --green-soft: #e5efe9;

  --red: #a63d2f;
  --red-soft: #f3e4df;

  --violet: #5b4a7a;
  --violet-soft: #ece8f2;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(38, 36, 31, .06);
  --shadow-md: 0 2px 8px rgba(38, 36, 31, .08);
  --sidebar-w: 276px;
  --maxw: 880px;

  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC",
                "STSong", "SimSun", serif;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
          "Noto Sans CJK SC", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo,
          "Courier New", "Microsoft YaHei", monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16.5px;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, .brand-title, .chapter-head h1, .card .c-title {
  font-family: var(--font-serif);
  font-weight: 700;
}

/* ---------- 顶部阅读进度条 ---------- */
#progress-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--accent);
  z-index: 60;
  transition: width .08s linear;
}

/* ---------- 布局 ---------- */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky; top: 0;
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  padding: 22px 16px 40px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 40;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.brand { display: block; text-decoration: none; color: inherit; margin-bottom: 18px; }
.brand-title { font-size: 17px; font-weight: 800; letter-spacing: .02em; color: var(--ink); display: block; line-height: 1.4; }
.brand-sub { font-size: 12.5px; color: var(--muted); display: block; margin-top: 3px; }

.nav-section-label {
  font-size: 11.5px; font-weight: 700; letter-spacing: .14em;
  color: var(--muted); text-transform: uppercase;
  margin: 20px 0 8px 10px;
}
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list li { margin: 2px 0; }
.nav-link {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink-2);
  font-size: 14.5px; line-height: 1.5;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: var(--surface-2); color: var(--accent-ink); }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }
.nav-num { flex: 0 0 auto; font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 700; color: var(--muted); min-width: 30px; }
.nav-link.is-active .nav-num { color: var(--accent); }

.pill { flex: 0 0 auto; margin-left: auto; font-size: 11px; font-weight: 700; line-height: 1.6; padding: 0 7px; border-radius: 20px; background: var(--green-soft); color: var(--green); white-space: nowrap; }
.pill.todo { background: var(--surface-2); color: var(--muted); }
.pill.base { background: var(--violet-soft); color: var(--violet); }

.toc { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 1px 0; }
.toc a { display: block; padding: 5px 10px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; font-size: 13.5px; line-height: 1.5; transition: color .12s, border-color .12s, background .12s; }
.toc a:hover { color: var(--accent-ink); background: var(--surface-2); }
.toc a.is-active { color: var(--accent-ink); font-weight: 700; border-left-color: var(--accent); background: var(--accent-soft); }
.toc .lvl-3 a { padding-left: 24px; font-size: 13px; }

/* ---------- 主内容 ---------- */
.main { flex: 1 1 auto; min-width: 0; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 34px 32px 96px; }

.topbar {
  display: none; position: sticky; top: 0; z-index: 45;
  align-items: center; gap: 12px; padding: 10px 16px;
  background: rgba(255, 253, 247, .92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 15px; font-weight: 700; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); padding: 6px 11px; font-size: 14px; cursor: pointer; color: var(--ink-2); font-family: inherit; }
.menu-btn:hover { background: var(--surface-2); }
.scrim { display: none; position: fixed; inset: 0; z-index: 39; background: rgba(38, 36, 31, .38); }
.scrim.show { display: block; }

/* ---------- 章节头部 ---------- */
.chapter-head { margin-bottom: 26px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.chapter-kicker { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .14em; color: var(--cinnabar); margin-bottom: 12px; }
.chapter-head h1 { font-size: 30px; line-height: 1.35; margin: 0 0 6px; letter-spacing: .01em; }
.chapter-head .sub { color: var(--muted); font-size: 14.5px; }

.chapter-meta {
  background: var(--ochre-soft); border: 1px solid var(--ochre-line);
  border-radius: var(--radius); padding: 16px 20px; margin: 0 0 30px;
  font-size: 15px; line-height: 1.8; color: var(--ochre);
}
.chapter-meta strong { color: var(--ink); }
.chapter-meta p { margin: 0 !important; }
.chapter-meta .meta-row { display: flex; gap: 8px; align-items: flex-start; }
.chapter-meta .meta-icon { flex: 0 0 auto; }

.score-card {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--green); border-radius: var(--radius);
  padding: 16px 20px; margin: 0 0 26px; box-shadow: var(--shadow-sm);
}
.score-card .sc-line { display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 15px; }
.score-card .sc-line b { color: var(--green); font-size: 18px; }

/* ---------- 正文排版 ---------- */
.main h2 { font-size: 23px; line-height: 1.4; margin: 46px 0 18px; padding-left: 14px; border-left: 3px solid var(--accent); letter-spacing: -.005em; }
.main h3 { font-size: 19px; line-height: 1.5; margin: 32px 0 12px; color: var(--ink); }
.main h4 { font-size: 16.5px; margin: 24px 0 10px; color: var(--ink-2); }
.main p { margin: 0 0 14px; }
.main strong { color: var(--ink); font-weight: 700; }
.main a { color: var(--accent-ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.main a:hover { border-bottom-color: var(--accent); }
.main ul, .main ol { margin: 0 0 16px; padding-left: 26px; }
.main li { margin: 5px 0; }
.main li > ul, .main li > ol { margin: 5px 0 5px; }
.main hr { border: 0; border-top: 1px dashed var(--line); margin: 34px 0; }

.main blockquote {
  margin: 18px 0; padding: 14px 18px;
  background: var(--ochre-soft); border: 1px solid var(--ochre-line);
  border-left: 3px solid var(--ochre); border-radius: var(--radius-sm);
  color: var(--ochre); font-size: 15.5px;
}
.main blockquote p { margin: 0 0 8px; }
.main blockquote p:last-child { margin-bottom: 0; }
.main blockquote strong { color: var(--ink); }
.main blockquote code { background: var(--surface-2); border-color: var(--line); color: var(--cinnabar); }

.main pre { margin: 18px 0; padding: 16px 18px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow-x: auto; line-height: 1.6; }
.main pre code { font-family: var(--mono); font-size: 14px; color: var(--ink-2); background: none; border: 0; padding: 0; white-space: pre; }
.main code { font-family: var(--mono); font-size: 14.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; color: var(--cinnabar); }

.main table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  margin: 20px 0; font-size: 15px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  overflow: hidden; box-shadow: var(--shadow-sm); display: block; overflow-x: auto;
}
.main thead th { background: var(--surface-2); font-weight: 700; color: var(--ink); white-space: nowrap; }
.main th, .main td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; line-height: 1.7; }
.main tbody tr:last-child td { border-bottom: 0; }
.main tbody tr:nth-child(even) td { background: var(--surface-2); }
.main td code, .main th code { font-size: 13.5px; }

.math-block, mjx-container[display="true"] { margin: 16px 0 !important; overflow-x: auto; overflow-y: hidden; }
.math-block { text-align: center; padding: 4px 0; }
.main h3 + p, .main h2 + p { margin-top: 0; }

/* ---------- 答案折叠 ---------- */
details.answer-box { margin: 22px 0 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
details.answer-box > summary {
  cursor: pointer; list-style: none; padding: 14px 20px;
  background: var(--green-soft); color: var(--green);
  font-weight: 700; font-size: 15.5px;
  display: flex; align-items: center; gap: 10px; user-select: none;
}
details.answer-box > summary::-webkit-details-marker { display: none; }
details.answer-box > summary::before { content: "▸"; display: inline-block; transition: transform .18s; font-size: 13px; }
details.answer-box[open] > summary::before { transform: rotate(90deg); }
details.answer-box > summary:hover { background: var(--surface-2); }
.answer-body { padding: 4px 22px 22px; }
.answer-body > h2:first-child { display: none; }
.answer-hint { padding: 10px 20px; font-size: 14px; color: var(--muted); background: var(--surface-2); border-top: 1px solid var(--line-2); }

/* ---------- 章节底部导航 ---------- */
.footer-nav { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 48px; padding-top: 26px; border-top: 1px solid var(--line); }
.footer-nav a { flex: 1 1 240px; display: block; padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s, border-color .12s; }
.footer-nav a:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--muted); }
.footer-nav .fn-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.footer-nav .fn-title { display: block; font-size: 15.5px; font-weight: 700; color: var(--accent-ink); }
.footer-nav a.next { text-align: right; }
.page-foot { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- 首页 Hero（米纸扉页式） ---------- */
.hero {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 36px 34px 32px; margin: 0 0 30px; box-shadow: var(--shadow-sm);
}
.hero h1 { margin: 0 0 10px; font-family: var(--font-serif); font-size: 30px; line-height: 1.3; letter-spacing: .01em; color: var(--accent); }
.hero p { margin: 0; font-size: 15.5px; color: var(--ink-2); line-height: 1.8; }
.hero .hero-tags { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.hero .hero-tags span { display: inline-block; font-size: 13px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px; padding: 4px 12px; color: var(--ink-2); }

/* 章节卡片网格 */
.card-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(228px, 1fr)); margin: 18px 0 8px; }
.card { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s, border-color .12s; position: relative; overflow: hidden; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--muted); }
.card .c-no { font-size: 12px; font-weight: 700; letter-spacing: .1em; color: var(--accent); margin-bottom: 6px; display: block; }
.card .c-title { font-size: 16px; font-weight: 700; line-height: 1.5; display: block; }
.card .c-desc { font-size: 13px; color: var(--muted); margin-top: 6px; display: block; line-height: 1.6; }
.card .c-score { display: inline-block; margin-top: 10px; font-size: 12px; font-weight: 700; background: var(--green-soft); color: var(--green); border-radius: 20px; padding: 2px 10px; }
.card .c-score.todo { background: var(--surface-2); color: var(--muted); }
.card .c-score.base { background: var(--violet-soft); color: var(--violet); }
.card.is-todo { opacity: .72; }
.card.is-todo .c-no { color: var(--muted); }

/* 打卡复选框 */
.chk { display: inline-block; width: 19px; height: 19px; border: 2px solid var(--line); border-radius: 5px; cursor: pointer; vertical-align: -4px; transition: background .12s, border-color .12s; position: relative; }
.chk:hover { border-color: var(--accent); }
.chk.on { background: var(--green); border-color: var(--green); }
.chk.on::after { content: "✓"; color: #fff; font-size: 13px; font-weight: 900; position: absolute; left: 2.5px; top: -3px; }
.progress-note { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 16px; margin: 18px 0; font-size: 14px; color: var(--accent-ink); }
.progress-note .reset { margin-left: auto; font-size: 13px; cursor: pointer; background: var(--surface); border: 1px solid var(--line); color: var(--accent-ink); border-radius: 4px; padding: 3px 10px; font-family: inherit; }

/* ---------- 提示条 ---------- */
.notice { display: flex; gap: 10px; background: var(--red-soft); border: 1px solid var(--line); color: var(--red); border-radius: var(--radius-sm); padding: 12px 16px; margin: 18px 0; font-size: 14.5px; }
.notice.hide { display: none; }

/* ---------- 侧边栏底部工具 ---------- */
.side-tools { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.side-tools button { width: 100%; font-family: inherit; font-size: 13.5px; cursor: pointer; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); transition: background .12s, border-color .12s, color .12s; }
.side-tools button:hover { background: var(--accent-soft); border-color: var(--line); color: var(--accent-ink); }

/* ---------- 返回顶部 ---------- */
#to-top { position: fixed; right: 24px; bottom: 26px; z-index: 50; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: 17px; cursor: pointer; box-shadow: var(--shadow-md); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-family: inherit; }
#to-top.show { opacity: 1; pointer-events: auto; }
#to-top:hover { transform: translateY(-2px); color: var(--accent); }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-md); }
  .sidebar.open { transform: translateX(0); }
  .topbar { display: flex; }
  .wrap { padding: 24px 20px 90px; }
  .hero { padding: 26px 22px; }
  .hero h1 { font-size: 25px; }
  .chapter-head h1 { font-size: 25px; }
  .main h2 { font-size: 20px; }
}
@media (max-width: 560px) {
  body { font-size: 16px; }
  .wrap { padding: 18px 15px 80px; }
  .main table { font-size: 14px; }
  .main th, .main td { padding: 8px 10px; }
}

/* ---------- 打印 / 导出 PDF ---------- */
@media print {
  #progress-bar, #to-top, .sidebar, .topbar, .scrim, .footer-nav { display: none !important; }
  body { background: #fff; font-size: 12pt; }
  .layout { display: block; }
  .wrap { max-width: none; padding: 0; }
  details.answer-box { border: 1px solid #ccc; }
  details.answer-box > summary { background: #f2f2f2; color: #000; }
  details.answer-box > summary::before { content: ""; }
  .hero { background: #fff !important; color: #000 !important; box-shadow: none; border: none; }
  .hero p { opacity: 1; }
  .main h2, .main h3 { break-after: avoid; page-break-after: avoid; }
  .main table, .main pre, details.answer-box { break-inside: avoid; page-break-inside: avoid; }
  a { color: #000 !important; border-bottom: 0 !important; }
}
