/* ===========================================================
   个人技术文章存档 · 全站样式
   www.d9dd.cn
   =========================================================== */

:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --surface-soft: #efece5;
  --text: #1e2126;
  --text-soft: #545b66;
  --muted: #8b929e;
  --line: #e2ded5;
  --accent: #2f5de3;
  --accent-soft: #eaeffd;
  --accent-ink: #1c3aa0;
  --code-bg: #f2f4f8;
  --code-text: #23304a;
  --warn-bg: #fdf5e6;
  --warn-line: #e0b877;
  --shadow: 0 1px 2px rgba(20, 24, 33, .05), 0 8px 24px -12px rgba(20, 24, 33, .12);
  --radius: 10px;
  --font-ui: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
  --measure: 44rem;
}

html[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1b1e24;
  --surface-soft: #23262e;
  --text: #e7e9ed;
  --text-soft: #aeb5c0;
  --muted: #7c8492;
  --line: #2c3038;
  --accent: #7c9bff;
  --accent-soft: #1e2536;
  --accent-ink: #b3c6ff;
  --code-bg: #23262e;
  --code-text: #d8dee9;
  --warn-bg: #2a2418;
  --warn-line: #8a6d34;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.85;
  letter-spacing: .01em;
  transition: background-color .2s ease, color .2s ease;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

img { max-width: 100%; height: auto; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 24px; }

/* ---------------- 阅读进度条 ---------------- */
#progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: var(--accent); z-index: 60; transition: width .1s linear;
}

/* ---------------- 顶栏 ---------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap {
  display: flex; align-items: center; gap: 20px;
  height: 62px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: linear-gradient(145deg, #3f6cf5, #2450d2); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 3px 8px -3px rgba(47, 93, 227, .65);
}
.brand-mark svg { width: 16px; height: 16px; display: block; }
.brand-name { font-size: 17px; }
.brand-sub { font-size: 12.5px; color: var(--muted); font-weight: 400; }

.nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.nav a {
  color: var(--text-soft); font-size: 15px; padding: 7px 12px; border-radius: 8px;
}
.nav a:hover { background: var(--surface-soft); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.theme-btn {
  margin-left: 8px; width: 34px; height: 34px; flex: none;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text-soft); border-radius: 9px; cursor: pointer;
  display: grid; place-items: center; font-size: 15px; line-height: 1;
}
.theme-btn:hover { color: var(--text); border-color: var(--muted); }

/* ---------------- 首页 hero ---------------- */
.hero { padding: 68px 0 34px; }
.hero h1 {
  margin: 0 0 18px; font-size: 40px; line-height: 1.28; font-weight: 700;
  letter-spacing: -.01em; max-width: 26em;
}
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { margin: 0 0 10px; max-width: var(--measure); color: var(--text-soft); font-size: 17px; }
.hero-meta {
  display: flex; flex-wrap: wrap; gap: 8px 22px;
  margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 14px;
}
.hero-meta b { color: var(--text); font-weight: 600; }

/* ---------------- 板块 ---------------- */
.part { padding: 40px 0 8px; }
.part-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.part-no {
  font-family: var(--font-mono); font-size: 13px; color: var(--accent);
  background: var(--accent-soft); padding: 3px 9px; border-radius: 6px; flex: none;
}
.part-head h2 { margin: 0; font-size: 23px; font-weight: 660; letter-spacing: -.005em; }
.part-desc { margin: 4px 0 22px; color: var(--text-soft); font-size: 15.5px; max-width: var(--measure); }

.post-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; }
.post-card {
  display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px 18px;
  box-shadow: var(--shadow); color: var(--text);
  transition: transform .16s ease, border-color .16s ease;
}
.post-card:hover { text-decoration: none; transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.post-card .idx {
  font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); letter-spacing: .04em;
}
.post-card h3 { margin: 6px 0 8px; font-size: 17.5px; font-weight: 640; line-height: 1.5; }
.post-card p { margin: 0; color: var(--text-soft); font-size: 14.5px; line-height: 1.7; }
.post-card .tags { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 12px; color: var(--text-soft); background: var(--surface-soft);
  border-radius: 5px; padding: 2px 7px;
}

/* ---------------- 文章页 ---------------- */
.crumb { padding: 26px 0 0; font-size: 14px; color: var(--muted); }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--accent); }

.article-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 210px;
  gap: 52px; align-items: start; padding: 18px 0 60px;
}

.post { min-width: 0; max-width: var(--measure); }
.post-kicker {
  font-family: var(--font-mono); font-size: 13px; color: var(--accent);
  letter-spacing: .03em; margin: 0 0 12px;
}
.post h1 {
  margin: 0 0 16px; font-size: 33px; line-height: 1.34; font-weight: 700; letter-spacing: -.012em;
}
.post-lede {
  margin: 0 0 28px; padding: 0 0 0 16px; border-left: 3px solid var(--accent);
  color: var(--text-soft); font-size: 16.5px; line-height: 1.8;
}
.post-body h2 {
  margin: 46px 0 14px; font-size: 23px; font-weight: 660; letter-spacing: -.005em;
  scroll-margin-top: 80px;
}
.post-body h3 {
  margin: 30px 0 10px; font-size: 18.5px; font-weight: 640; scroll-margin-top: 80px;
}
.post-body h2 + h3 { margin-top: 18px; }
.post-body p { margin: 0 0 18px; }
.post-body ul, .post-body ol { margin: 0 0 18px; padding-left: 1.35em; }
.post-body li { margin-bottom: 8px; }
.post-body li::marker { color: var(--muted); }
.post-body strong { font-weight: 650; }
.post-body code {
  font-family: var(--font-mono); font-size: .875em;
  background: var(--code-bg); color: var(--code-text);
  padding: .12em .4em; border-radius: 5px;
}
.post-body pre {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; overflow-x: auto; margin: 0 0 20px; line-height: 1.65;
}
.post-body pre code { background: none; padding: 0; font-size: 13.5px; }
.post-body blockquote {
  margin: 0 0 20px; padding: 12px 18px; border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-soft); font-size: 16px;
}
.post-body blockquote p:last-child { margin-bottom: 0; }
.post-body hr { border: 0; border-top: 1px solid var(--line); margin: 38px 0; }
.post-body table { width: 100%; border-collapse: collapse; margin: 0 0 22px; font-size: 15px; }
.post-body th, .post-body td { border: 1px solid var(--line); padding: 9px 12px; text-align: left; }
.post-body th { background: var(--surface-soft); font-weight: 620; }

.note {
  background: var(--warn-bg); border: 1px solid var(--warn-line);
  border-radius: var(--radius); padding: 14px 18px; margin: 0 0 20px; font-size: 15.5px;
}
.note p:last-child { margin-bottom: 0; }
.note b { color: var(--text); }

.formula {
  display: block; text-align: center; font-family: var(--font-mono); font-size: 15px;
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 14px; margin: 0 0 20px; color: var(--text); overflow-x: auto;
}

/* 侧边目录 */
.side-toc { position: sticky; top: 84px; font-size: 14px; }
.side-toc h4 {
  margin: 0 0 10px; font-size: 12.5px; letter-spacing: .08em; color: var(--muted);
  font-weight: 600; text-transform: uppercase;
}
.side-toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.side-toc a {
  display: block; padding: 4px 12px; color: var(--text-soft); line-height: 1.55;
  border-left: 2px solid transparent; margin-left: -2px;
}
.side-toc a:hover { color: var(--text); text-decoration: none; }
.side-toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 550; }
.side-toc .toc-back { margin-top: 14px; }

/* 参考资料 */
.refs {
  margin-top: 52px; padding-top: 26px; border-top: 1px solid var(--line);
}
.refs h2 { margin-top: 0; font-size: 19px; }
.refs ol { padding-left: 1.3em; font-size: 15px; color: var(--text-soft); }
.refs li { margin-bottom: 10px; line-height: 1.7; }
.refs a { word-break: break-all; }

/* 上下篇 */
.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin-top: 44px; padding-top: 26px; border-top: 1px solid var(--line);
}
.pager a {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px;
  background: var(--surface); color: var(--text); font-size: 15px;
}
.pager a:hover { text-decoration: none; border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.pager .dir { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.pager .next { text-align: right; }
.pager .empty { border: 0; }   /* 首尾篇留白占位，不画框 */

/* ---------------- 页脚 ---------------- */
.site-footer {
  margin-top: 60px; border-top: 1px solid var(--line);
  padding: 30px 0 40px; color: var(--muted); font-size: 14px;
}
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 8px 26px; align-items: center; }
.site-footer a { color: var(--text-soft); }
.site-footer .spacer { margin-left: auto; }
.site-footer .beian { display: inline-flex; align-items: center; gap: 6px; }
.site-footer .beian img { width: 16px; height: 16px; }

/* ---------------- 关于页 ---------------- */
.page { max-width: var(--measure); padding: 18px 0 60px; }
.page h1 { font-size: 32px; margin: 0 0 20px; letter-spacing: -.01em; }
.page h2 { font-size: 22px; margin: 42px 0 14px; }
.page p { margin: 0 0 18px; }
.page ul { padding-left: 1.3em; }

/* ---------------- 404 ---------------- */
.notfound { text-align: center; padding: 110px 0 90px; }
.notfound .code { font-family: var(--font-mono); font-size: 76px; color: var(--accent); line-height: 1; }
.notfound p { color: var(--text-soft); }

/* ---------------- 返回顶部 ---------------- */
#to-top {
  position: fixed; right: 26px; bottom: 26px; z-index: 55;
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-soft);
  box-shadow: var(--shadow); display: none; place-items: center; font-size: 16px;
}
#to-top.show { display: grid; }
#to-top:hover { color: var(--accent); }

/* ---------------- 响应式 ---------------- */
@media (max-width: 900px) {
  .article-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .side-toc { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 16.5px; }
  .wrap { padding: 0 18px; }
  .hero { padding: 44px 0 22px; }
  .hero h1 { font-size: 29px; }
  .brand-sub { display: none; }
  .nav a { padding: 7px 9px; font-size: 14.5px; }
  .post h1 { font-size: 26px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { text-align: left; }
  .post-list { grid-template-columns: 1fr; }
  .site-footer .wrap { gap: 6px 18px; }
  .site-footer .spacer { display: none; }

  /* 对比表格列多，窄屏上让它自己横向滚动，别把整页撑宽 */
  .post-body table {
    display: block; width: 100%; overflow-x: auto;
    font-size: 14px; -webkit-overflow-scrolling: touch;
  }
  .post-body th, .post-body td { padding: 8px 10px; }
}

/* 小屏手机（320~420px），顶栏和标题再收一档 */
@media (max-width: 420px) {
  .brand-name { font-size: 15px; }
  .nav { gap: 0; }
  .nav a { padding: 6px 7px; font-size: 14px; }
  .theme-btn { width: 32px; height: 32px; }
  .hero h1 { font-size: 25px; }
  .hero p { font-size: 16px; }
  .post h1 { font-size: 23px; }
  .post-body h2 { font-size: 20px; }
  .post-body h3 { font-size: 17.5px; }
  .post-lede { font-size: 16px; }
}

@media print {
  .site-header, .side-toc, #to-top, .pager, #progress { display: none; }
  body { background: #fff; }
}
