/* ==========================================================================
 * reader.css —— 学习页样式（浅色主题 / 手机优先 / 零外部引用）
 * 配色：底 #f5f7fa、卡片 #ffffff、正文 #1f2937、主色 #2563eb
 * ========================================================================== */

:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.08);
  --border: #e5e7eb;
  --code-bg: #f6f8fa;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 26px -20px rgba(15, 23, 42, 0.35);
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
    "MiSans", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
    "Noto Sans CJK SC", "WenQuanYi Micro Hei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    "Courier New", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

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

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.85;
  overflow-wrap: break-word;
  -webkit-tap-highlight-color: rgba(37, 99, 235, 0.12);
}

@media (min-width: 420px) {
  body { font-size: 18px; }
}

/* 正文容器：最大宽度 35em 居中，两边留白，320px 也不横向滚动 */
.wrap {
  width: 100%;
  max-width: 35em;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

/* ---------------- 顶部阅读进度条 ---------------- */

.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border);
  z-index: 50;
}

.progress > span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
  transition: width 0.12s linear;
}

/* ---------------- 页头 ---------------- */

.site-head {
  padding-top: calc(20px + env(safe-area-inset-top));
  padding-bottom: 2px;
}

.back-link {
  display: inline-block;
  padding: 4px 0;
  color: var(--primary);
  font-size: 15px;
  text-decoration: none;
}

.back-link:active { opacity: 0.6; }

.day-card {
  margin-top: 8px;
  padding: 18px 18px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.day-badge {
  display: inline-block;
  padding: 3px 10px;
  background: var(--primary-soft);
  border-radius: 999px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.day-title {
  margin: 10px 0 6px;
  font-size: 22px;
  line-height: 1.45;
  letter-spacing: 0.01em;
}

.day-meta {
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.exam-hint {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

/* ---------------- 主体卡片 ---------------- */

main { padding-bottom: calc(30px + env(safe-area-inset-bottom)); }

.card {
  margin-top: 14px;
  padding: 16px 18px 18px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------------- Markdown 正文排版 ---------------- */

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }

.md p {
  margin: 0 0 1.15em;
  text-align: justify;
  text-justify: inter-ideograph;
}

.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 1.8em 0 0.7em;
  line-height: 1.45;
  font-weight: 700;
}

.md h1 { font-size: 1.3em; }
.md h2 {
  padding-left: 10px;
  border-left: 4px solid var(--primary);
  font-size: 1.16em;
}
.md h3 { font-size: 1.06em; }
.md h4, .md h5, .md h6 { font-size: 1em; color: var(--muted); }

/* 和页头标题重复的那一级标题（由 reader.js 标记） */
.md-dup-title { display: none; }

.md strong { font-weight: 700; }
.md em { font-style: italic; }

.md a {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.md ul, .md ol { margin: 0 0 1.15em; padding-left: 1.4em; }
.md li { margin: 0.35em 0; }
.md li > ul, .md li > ol { margin: 0.35em 0 0.1em; }

.md blockquote {
  margin: 0 0 1.15em;
  padding: 0.7em 1em;
  background: #f8fafc;
  border-left: 3px solid #cbd5e1;
  border-radius: 0 10px 10px 0;
  color: #374151;
}

.md blockquote > :last-child { margin-bottom: 0; }

.md hr {
  margin: 1.8em 0;
  border: 0;
  border-top: 1px solid var(--border);
}

/* 行内代码 */
.md code {
  padding: 0.12em 0.38em;
  background: var(--primary-soft);
  border-radius: 5px;
  color: #1d4ed8;
  font-family: var(--font-mono);
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

/* 代码块：块内横向滚动，绝不撑破页面 */
.md .md-pre {
  margin: 0 0 1.15em;
  padding: 12px 14px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.md .md-pre code {
  display: block;
  padding: 0;
  background: none;
  border-radius: 0;
  color: #111827;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre;
  overflow-wrap: normal;
}

/* 表格：外层容器负责横向滚动，页面本身永远不会被撑宽 */
.md-table-wrap {
  margin: 0 0 1.15em;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.md table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.65;
}

.md th, .md td {
  min-width: 4.2em;               /* 列不会被挤成一条线；放不下时容器横向滚动 */
  padding: 8px 10px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: break-word;
}

.md th { background: #f9fafb; font-weight: 700; }
.md th:last-child, .md td:last-child { border-right: 0; }
.md tbody tr:last-child td { border-bottom: 0; }
.md .ta-center { text-align: center; }
.md .ta-right { text-align: right; }

/* 复选框列表 */
.md .md-task-item {
  display: flex;
  gap: 0.5em;
  align-items: flex-start;
  margin-left: -1.4em;
  list-style: none;
}

.md .md-task {
  flex: 0 0 auto;
  width: 1em;
  height: 1em;
  margin: 0.45em 0 0;
  accent-color: var(--primary);
}

/* 降级 / 空态 / 加载中 */
.loading, .md-empty, .toc-empty {
  margin: 0;
  padding: 6px 0;
  color: var(--muted);
  font-size: 15px;
}

.md-error {
  margin: 0 0 12px;
  padding: 12px 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  color: #991b1b;
  font-size: 15px;
  line-height: 1.7;
}

.md-raw { font-size: 13.5px; }

/* ---------------- 底部：上下页导航 + 原文链接 ---------------- */

.day-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.day-nav[hidden] { display: none; }

.day-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  background: var(--card);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.day-link:active { background: #f9fafb; }
.day-link-label { color: var(--primary); font-size: 14px; font-weight: 700; }
.day-link-sub { color: var(--muted); font-size: 13px; }

.foot-card {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}

.foot-card .raw-link,
.foot-card .back-link { padding: 0; font-size: 15px; }

.raw-link {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px solid var(--primary-soft);
}

/* ---------------- 总目录页 ---------------- */

.toc-head {
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: 0;
}

.toc-title {
  margin: 0 0 6px;
  font-size: 23px;
  line-height: 1.4;
}

.toc-sub {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.toc-count {
  display: inline-block;
  margin-top: 10px;
  padding: 3px 10px;
  background: var(--primary-soft);
  border-radius: 999px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

.toc-list {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.toc-link {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 13px 15px;
  background: var(--card);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.toc-link:active { background: #f9fafb; }

.toc-day {
  padding: 3px 9px;
  background: var(--primary-soft);
  border-radius: 999px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.toc-body { display: block; min-width: 0; }

.toc-item-title {
  display: block;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.5;
}

.toc-summary {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.65;
}

.toc-date {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------------- 动效：用户在系统里关了动画就一个都不跑 ---------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
