/* 从零开始学 - 阅读优先的极简样式 */

:root {
  --bg: #faf9f7;
  --fg: #1f2328;
  --muted: #6b7280;
  --accent: #0b6bcb;
  --border: #e5e2dc;
  --code-bg: #f0eeea;
  --quote-bg: #f3f1ec;
  --pop-border: #b9b2a6;   /* 弹窗外框：比 --border 深，浮层要压得住底下的正文 */
  --pop-line: #ddd8ce;    /* 弹窗内分隔线 */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --fg: #e6e4df;
    --muted: #9aa0a6;
    --accent: #6cb2ff;
    --border: #2c2f36;
    --code-bg: #22252c;
    --quote-bg: #1d2026;
    --pop-border: #565c66;
    --pop-line: #383d45;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 17px;
  line-height: 1.85;
}

main { max-width: 760px; margin: 0 auto; padding: 24px 20px 64px; }

.site-header {
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
}
.site-header a {
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.4; }
.site-title { text-align: center; margin: 40px 0 32px; }

/* 课程卡片 */
.course-list { display: grid; gap: 16px; }
.course-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  color: var(--fg);
  background: transparent;
}
.course-card:hover { border-color: var(--accent); text-decoration: none; }
.course-card h2 { margin: 0 0 8px; }
.course-card p { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.course-card .meta { color: var(--muted); font-size: 13px; }

/* 目录 */
.toc { padding-left: 2em; }
.toc li { margin: 8px 0; }
.note { color: var(--muted); font-size: 15px; }

/* 章节导航条 */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.chapter-nav:last-of-type { border-bottom: none; border-top: 1px solid var(--border); }
.chapter-nav .dim { color: var(--muted); opacity: 0.5; }

/* 正文排版 */
.chapter h1 { font-size: 1.55em; margin-top: 12px; }
.chapter h2 {
  font-size: 1.25em;
  margin-top: 2em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.chapter hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

.chapter blockquote {
  margin: 1.2em 0;
  padding: 10px 18px;
  background: var(--quote-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
}
.chapter blockquote p { margin: 0.4em 0; }

.chapter table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.2em 0;
  font-size: 15px;
  display: block;
  overflow-x: auto;
}
.chapter th, .chapter td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.chapter th { background: var(--code-bg); }

.chapter code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.chapter pre {
  background: var(--code-bg);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.6;
}
.chapter pre code { background: none; padding: 0; }

/* 插图。SVG 自带深色模式媒体查询，这里只管尺寸与留白 */
.chapter img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.8em auto;
}
@media (max-width: 480px) {
  body { font-size: 16px; }
  .chapter-nav { font-size: 14px; }
}

/* ============================================================
   交叉引用：正文里的「“X”这一章」可点，弹窗预览目标章
   ============================================================ */

/* 引用链接。用虚下划线而不是蓝色——正文里有 300 多处，
   全染成链接色会把页面搞得像维基百科，反而干扰阅读。 */
.chapter a.xref {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed var(--accent);
  cursor: pointer;
}
.chapter a.xref:hover { background: var(--quote-bg); border-bottom-style: solid; }

/* 小节标题旁的 ¶，悬停才显形 */
.chapter h2 .anchor-link {
  margin-left: .4em; font-size: .7em; font-weight: normal;
  color: var(--muted); text-decoration: none;
  opacity: 0; transition: opacity .15s;
}
.chapter h2:hover .anchor-link { opacity: .6; }
.chapter h2 .anchor-link:hover { opacity: 1; }
.chapter h2 .anchor-link[data-copied]::after {
  content: " 已复制"; font-size: .85em; color: var(--accent);
}

/* 落点高亮：从引用跳过来时，闪一下告诉读者该看哪 */
.xref-hit {
  animation: xref-flash 2s ease-out;
  scroll-margin-top: 1em;
}
@keyframes xref-flash {
  0%, 40% { background: color-mix(in srgb, var(--accent) 18%, transparent); }
  100% { background: transparent; }
}

/* ---- 弹窗 ---- */
.xref-pop {
  position: fixed; z-index: 50; display: none;
  flex-direction: column;
  background: var(--bg);
  border: 2px solid var(--pop-border);
  border-radius: 10px;
  box-shadow: 0 12px 44px rgba(0,0,0,.28);
  overflow: hidden;
}
.xref-pop.is-open { display: flex; }

.xref-head {
  display: flex; align-items: center; gap: .6em;
  padding: .7em 1.1em;
  border-bottom: 2px solid var(--pop-line);
  background: var(--quote-bg);
  font-size: .9rem;
}
.xref-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xref-open { color: var(--accent); text-decoration: none; white-space: nowrap; font-size: .85em; }
.xref-back, .xref-close {
  border: 0; background: none; cursor: pointer;
  color: var(--muted); font-size: 1.1em; line-height: 1; padding: .1em .3em;
}
.xref-back:hover, .xref-close:hover { color: var(--fg); }

/* 小节目录。定位猜错时全靠这一排兜底，所以默认就展开。 */
.xref-outline {
  display: flex; gap: .35em; overflow-x: auto;
  padding: .55em 1.1em; border-bottom: 2px solid var(--pop-line);
  scrollbar-width: thin;
}
.xref-outline:empty { display: none; }
.xref-outline button {
  flex: 0 0 auto; cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg); color: var(--muted);
  font-size: .75rem; padding: .2em .7em; white-space: nowrap;
}
.xref-outline button:hover { color: var(--fg); border-color: var(--accent); }

.xref-body { flex: 1; overflow-y: auto; padding: .4em 1.6em 1.5em; font-size: .92rem; line-height: 1.75; }
.xref-body h1 { font-size: 1.15rem; }
.xref-body h2 { font-size: 1rem; }
.xref-body img { max-width: 100%; height: auto; }
.xref-body .anchor-link { display: none; }
/* 弹窗里的引用不再加边框，避免一层套一层看着乱 */
.xref-body a.xref { border-bottom-color: var(--border); }

.xref-hint {
  padding: .4em 1.1em; border-top: 2px solid var(--pop-line);
  font-size: .72rem; color: var(--muted); text-align: center;
}
.xref-pop.is-loading .xref-body::before { content: "载入中…"; color: var(--muted); }

/* 窄屏改成底部抽屉，指头够得着 */
@media (max-width: 720px) {
  .xref-pop.is-open {
    left: 0; right: 0; bottom: 0; top: auto;
    width: auto; height: 70vh;
    border-radius: 12px 12px 0 0;
  }
}
