/* 用同一组颜色变量管理两种配色，保持所有页面的层级一致。 */
:root {
  color-scheme: light;
  --background: #f7f7f2;
  --surface: #eeeee7;
  --text: #29332c;
  --muted: #71766d;
  --line: #dfe2d7;
  --accent: #42664d;
  --selection: #dbe7cc;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #1c231e;
  --surface: #273029;
  --text: #e5e8df;
  --muted: #a1ad9e;
  --line: #384138;
  --accent: #a9c595;
  --selection: #455c3a;
}

/* 基础排版使用系统字体，不依赖外部字体服务或图片请求。 */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 32px; }
body { margin: 0; background: var(--background); color: var(--text); font-family: var(--font-sans); -webkit-font-smoothing: antialiased; }
::selection { background: var(--selection); }
a { color: inherit; text-decoration: none; text-underline-offset: 5px; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; border-radius: 3px; }
h1, h2, h3, p { margin: 0; }
svg { display: block; }
.shell { width: min(940px, calc(100% - 80px)); margin-inline: auto; }
main.shell { min-height: calc(100svh - 190px); padding-block: 70px 100px; }
.skip-link { position: fixed; z-index: 10; inset: 12px auto auto 16px; padding: 12px 18px; background: var(--text); color: var(--background); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }

/* 导航和工具分成两组；窄屏仍保留完整入口，不藏进额外菜单。 */
.site-header { border-bottom: 1px solid var(--line); }
.header-inner { min-height: 91px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.wordmark { font-family: var(--font-mono); font-size: 20px; font-weight: 600; letter-spacing: -1px; white-space: nowrap; }
.wordmark span { color: var(--accent); font-weight: 400; }
.header-actions, .header-tools, .header-actions nav { display: flex; align-items: center; }
.header-actions { gap: 27px; }
.header-actions nav { gap: 28px; }
.header-actions nav a { position: relative; padding-block: 12px; color: var(--muted); font-size: 14px; }
.header-actions nav a:hover, .header-actions nav a[aria-current="page"] { color: var(--text); }
.header-actions nav a[aria-current="page"]::after { position: absolute; content: ""; height: 2px; inset: auto 0 3px; background: var(--accent); }
.header-tools { gap: 5px; border-left: 1px solid var(--line); padding-left: 18px; }
.icon-button { width: 38px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; cursor: pointer; transition: background 150ms ease, color 150ms ease; }
.icon-button svg { width: 20px; height: 20px; }
.icon-button:hover, .icon-button[aria-current="page"] { color: var(--accent); background: var(--surface); }
.sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: block; }

/* 首页直接显示文章列表，标题和归档入口保持同一层级。 */
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.section-heading h1 { font-size: 21px; font-weight: 550; letter-spacing: -.4px; }
.text-link { color: var(--accent); font-size: 14px; line-height: 1.7; }
.text-link:hover { text-decoration: underline; }
.text-link span { margin-left: 5px; }
.post-list { padding: 0; margin: 0; list-style: none; border-top: 1px solid var(--line); }
.post-card { position: relative; display: grid; grid-template-columns: 135px minmax(0, 1fr) 20px; gap: 24px; padding-block: 30px; border-bottom: 1px solid var(--line); }
.post-card time { color: var(--muted); font-size: 12px; line-height: 2.5; font-variant-numeric: tabular-nums; }
.post-card h3 { font-size: 22px; font-weight: 550; line-height: 1.5; }
.post-card h3 a:hover { text-decoration: underline; }
.post-card p { margin-top: 9px; color: var(--muted); font-size: 14px; line-height: 1.8; }
.post-arrow { align-self: start; padding-top: 3px; color: var(--muted); font-size: 22px; transition: transform 150ms ease, color 150ms ease; }
.post-card:has(a:hover) .post-arrow { color: var(--accent); transform: translate(2px, -2px); }
.empty-state { padding-block: 35px; color: var(--muted); font-size: 15px; line-height: 1.8; border-top: 1px solid var(--line); }

/* 普通页面使用一致的标题间距；年份和标签只显示有内容的项目。 */
.page-header { margin-bottom: 45px; }
.page-header h1 { font-size: 38px; font-weight: 550; line-height: 1.5; letter-spacing: -1px; }
.page-header p { margin-top: 15px; color: var(--muted); font-size: 15px; line-height: 1.8; }
.back-link { display: inline-block; margin-bottom: 24px; color: var(--muted); font-size: 13px; }
.back-link:hover { color: var(--accent); }
.archive-group + .archive-group { margin-top: 45px; }
.archive-year { margin-bottom: 18px; font-family: var(--font-mono); font-size: 19px; color: var(--muted); font-weight: 400; }
.tag-directory { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 50px; margin: 0; padding: 0; list-style: none; }
.tag-directory a { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 25px; padding: 22px 0; border-block: 1px solid var(--line); }
.tag-directory a:hover { color: var(--accent); }
.tag-count { color: var(--muted); font-size: 13px; font-family: var(--font-mono); }

/* 文章正文控制行宽，目录在桌面侧栏和手机折叠区之间切换。 */
.post-header { max-width: 730px; padding-bottom: 36px; margin-bottom: 36px; border-bottom: 1px solid var(--line); }
.post-meta { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 17px; color: var(--muted); font-size: 13px; }
.post-header h1 { font-size: clamp(30px, 4vw, 43px); font-weight: 550; line-height: 1.45; letter-spacing: -1px; overflow-wrap: anywhere; }
.post-description { margin-top: 20px; color: var(--muted); line-height: 1.8; font-size: 16px; }
.post-tags { display: flex; flex-wrap: wrap; gap: 12px; list-style: none; padding: 0; margin: 20px 0 0; }
.post-tags a { color: var(--accent); font-size: 12px; background: var(--surface); padding: 5px 11px; border-radius: 3px; }
.article-layout { max-width: 730px; }
.article-layout.has-toc { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 58px; max-width: none; align-items: start; }
.article-toc { position: sticky; top: 38px; padding-left: 18px; margin-top: 5px; border-left: 1px solid var(--line); }
.article-toc summary { font-size: 12px; color: var(--muted); cursor: pointer; list-style: none; }
.article-toc summary::-webkit-details-marker { display: none; }
.article-toc ul { margin: 14px 0 0; padding: 0; list-style: none; }
.article-toc li { margin-top: 11px; font-size: 12px; line-height: 1.7; color: var(--muted); }
.article-toc a:hover { color: var(--accent); }
.article-toc .nested { padding-left: 12px; }
.prose { min-width: 0; font-size: 16px; line-height: 2; overflow-wrap: break-word; }
.prose p { margin-block: 0 24px; }
.prose h2 { margin-block: 42px 18px; font-size: 24px; font-weight: 550; line-height: 1.6; letter-spacing: -.5px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { margin-block: 32px 14px; font-size: 20px; font-weight: 550; }
.prose a { color: var(--accent); text-decoration: underline; }
.prose ul, .prose ol { padding-left: 1.5em; margin-block: 0 25px; }
.prose li { padding-left: 4px; margin-bottom: 5px; }
.prose blockquote { margin: 28px 0; padding: 3px 0 3px 22px; color: var(--muted); border-left: 3px solid var(--accent); }
.prose blockquote p:last-child { margin-bottom: 0; }
.prose pre { margin-block: 25px; border-radius: 6px; padding: 22px; overflow-x: auto; font-size: 13px; line-height: 1.8; }
.prose code { font-family: var(--font-mono); }
.prose :not(pre) > code { background: var(--surface); padding: 3px 5px; border-radius: 3px; font-size: .85em; }
.prose img { max-width: 100%; height: auto; border-radius: 5px; }
.prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin-block: 24px; font-size: 14px; }
.prose th, .prose td { padding: 10px 16px; border: 1px solid var(--line); }
.prose th { background: var(--surface); text-align: left; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin-block: 40px; }
.post-end { max-width: 730px; margin-top: 60px; color: var(--muted); }
.next-post { display: grid; gap: 12px; max-width: 730px; margin-top: 40px; padding-top: 25px; border-top: 1px solid var(--line); }
.next-post > span { font-size: 12px; color: var(--muted); }
.next-post strong { font-size: 18px; font-weight: 500; color: var(--accent); }
.about-content { max-width: 650px; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 32px; color: var(--accent); font-size: 14px; }
.pagination span { margin-inline: auto; color: var(--muted); }

/* 隐藏的表单标签仍可被屏幕阅读器读取。 */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* 页脚和空页面保持安静，不添加与阅读无关的装饰和统计。 */
.site-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-block: 26px 32px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.site-footer a:hover { color: var(--accent); }
.site-footer a span { margin-left: 5px; }
.not-found { padding-block: 35px 80px; }
.error-code { color: var(--accent); font-family: var(--font-mono); margin-bottom: 20px; }
.not-found h1 { font-size: 36px; font-weight: 550; }
.not-found > p:not(.error-code) { margin-block: 20px 30px; color: var(--muted); line-height: 1.8; }

/* 手机布局保留舒适字号和点击尺寸，长标题、代码和表格各自处理溢出。 */
@media (max-width: 700px) {
  .shell { width: calc(100% - 40px); }
  .header-inner { min-height: 78px; gap: 12px; }
  .wordmark { font-size: 17px; letter-spacing: -1px; }
  .header-actions { gap: 13px; }
  .header-actions nav { gap: 17px; }
  .header-actions nav a { font-size: 13px; }
  .header-tools { gap: 0; padding-left: 8px; }
  .icon-button { width: 33px; min-height: 42px; }
  .icon-button svg { width: 18px; height: 18px; }
  main.shell { padding-block: 45px 75px; min-height: calc(100svh - 177px); }
  .section-heading { margin-bottom: 20px; }
  .section-heading h1 { font-size: 19px; }
  .text-link { font-size: 13px; }
  .post-card { grid-template-columns: minmax(0, 1fr) 20px; gap: 10px 15px; padding-block: 24px; }
  .post-card time { grid-column: 1; line-height: 1.8; }
  .post-card-content { grid-column: 1; }
  .post-arrow { grid-column: 2; grid-row: 2; }
  .post-card h3 { font-size: 20px; }
  .post-card p { font-size: 13px; margin-top: 8px; }
  .page-header { margin-bottom: 35px; }
  .page-header h1 { font-size: 30px; }
  .tag-directory { grid-template-columns: 1fr; }
  .article-layout.has-toc { display: flex; flex-direction: column; gap: 32px; }
  .article-toc { order: -1; position: static; width: 100%; padding: 15px 18px; margin: 0; border: 1px solid var(--line); border-radius: 5px; }
  .article-toc summary { font-size: 13px; }
  .article-toc summary::after { content: "−"; float: right; }
  .article-toc details:not([open]) summary::after { content: "+"; }
  .article-toc li { font-size: 13px; }
  .post-header { padding-bottom: 27px; margin-bottom: 28px; }
  .post-header h1 { font-size: 31px; }
  .post-description { font-size: 15px; margin-top: 16px; }
  .post-meta { font-size: 12px; }
  .prose { font-size: 15px; line-height: 2; }
  .prose h2 { font-size: 22px; margin-top: 34px; }
  .prose pre { margin-inline: -5px; padding: 18px; }
  .site-footer { font-size: 11px; padding-block: 24px 30px; }
}

/* 更窄的手机减少导航间距，保持入口与品牌都在可见区域内。 */
@media (max-width: 380px) {
  .header-inner { gap: 8px; }
  .wordmark { font-size: 15px; }
  .header-actions { gap: 8px; }
  .header-actions nav { gap: 12px; }
  .header-tools { padding-left: 4px; }
  .icon-button { width: 30px; }
}

/* 系统要求减少动画时关闭滚动和交互过渡。 */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
