/* ==========================================================================
   魔法窝瓜的博客 — 样式表
   风格参考 Eleventy 官方站点（www.11ty.dev）：单栏窄版心、细线分隔、
   等宽字体的元信息、克制的一个强调色，不用阴影、不用圆角卡片。
   针对中文正文调整了字号、行高与字距。
   ========================================================================== */

/* --- 设计变量 ----------------------------------------------------------- */

:root {
  color-scheme: light dark;

  /* 版面：正文单栏窄版心，便于长文阅读 */
  --measure: 46rem;
  --gutter: 1.5rem;

  /* 字体：正文用系统字体栈（中文优先），元信息与代码用等宽 */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
    "Noto Sans CJK SC", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", "Courier New", monospace;

  --text-lg: 1.1875rem;
  --text-base: 1.0625rem;
  --text-sm: 0.9375rem;
  --text-xs: 0.8125rem;

  --leading: 1.85;
  --leading-tight: 1.4;

  /* 明度层级：正文最重，注释最轻 */
  --text: #1a1d21;
  --text-soft: #52585f;
  --text-faint: #828991;
  --bg: #ffffff;
  --bg-code: #f6f7f8;
  --rule: #e6e8ea;
  --rule-strong: #cdd1d5;
  --accent: #0f6f7a;
  --mark: #fff3c4;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: #e4e6e8;
    --text-soft: #a6adb5;
    --text-faint: #767d85;
    --bg: #16181b;
    --bg-code: #1d2023;
    --rule: #2a2e33;
    --rule-strong: #3b4046;
    --accent: #4cc7d4;
    --mark: #453a17;
  }
}

:root[data-theme="dark"] {
  --text: #e4e6e8;
  --text-soft: #a6adb5;
  --text-faint: #767d85;
  --bg: #16181b;
  --bg-code: #1d2023;
  --rule: #2a2e33;
  --rule-strong: #3b4046;
  --accent: #4cc7d4;
  --mark: #453a17;
}

/* --- 基础 --------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
  background: var(--bg);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0 0 0.5em;
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: 0.01em;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

p {
  margin: 0 0 1.25em;
}

ul,
ol {
  margin: 0 0 1.25em;
  padding-left: 1.5em;
}

li {
  margin: 0.35em 0;
}

li > ul,
li > ol {
  margin: 0.35em 0 0.5em;
}

/* 链接默认不画下划线，仅靠颜色区分；悬停/聚焦时才出现细下划线 */
a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}

a:hover,
a:focus-visible {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

img,
video,
iframe {
  max-width: 100%;
  height: auto;
}

hr {
  height: 1px;
  border: 0;
  background: var(--rule);
  margin: 2.5rem 0;
}

mark {
  background: var(--mark);
  color: inherit;
}

abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

/* 跳到正文：默认隐藏，聚焦时浮出 */
.skip-link {
  position: absolute;
  left: 0;
  top: -3rem;
  z-index: 10;
  padding: 0.5rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  color: var(--text);
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0;
}

/* --- 版心 --------------------------------------------------------------- */

.wrap {
  width: 100%;
  max-width: calc(var(--measure) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

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

.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  flex-wrap: wrap;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.site-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

.site-title:hover {
  color: var(--accent);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
}

.site-nav a {
  color: var(--text-soft);
  padding-bottom: 0.15rem;
  border-bottom: 2px solid transparent;
}

.site-nav a:hover {
  color: var(--text);
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  border: 1px solid var(--rule);
  background: none;
  color: var(--text-faint);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--rule-strong);
  color: var(--text);
}

.theme-toggle svg {
  width: 1rem;
  height: 1rem;
}

/* --- 主体 --------------------------------------------------------------- */

.site-main {
  padding: 3rem 0 4rem;
  min-height: 55vh;
}

.site-main > .wrap > :first-child {
  margin-top: 0;
}

/* 小节标题：等宽、大写、细线，作为版面的「标签」 */
.section-label {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--rule);
  margin: 0 0 1.25rem;
}

section + section {
  margin-top: 3.5rem;
}

/* --- 首页 --------------------------------------------------------------- */

.home-intro {
  margin-bottom: 3rem;
}

.home-title {
  font-size: clamp(1.6rem, 1.2rem + 1.8vw, 2rem);
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.home-lede {
  margin: 0 0 1rem;
  color: var(--text-soft);
}

.home-meta {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.home-meta a {
  color: var(--text-soft);
}

/* --- 文章列表 ----------------------------------------------------------- */

/* 序号用计数器生成，形式参考 Eleventy 官方 starter 的 postlist */
.post-list {
  counter-reset: post;
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-item {
  counter-increment: post;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.75rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--rule);
}

.post-item:last-child {
  border-bottom: 0;
}

.post-item::before {
  content: counter(post, decimal-leading-zero);
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.post-item-body {
  flex: 1 1 20rem;
  min-width: 0;
}

.post-item-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.005em;
}

.post-item-title:hover {
  color: var(--accent);
}

.post-item-desc {
  margin: 0.2rem 0 0;
  font-size: var(--text-sm);
  color: var(--text-soft);
  line-height: 1.7;
}

.post-item-meta {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 34rem) {
  .post-item-meta {
    order: -1;
    flex-basis: 100%;
    margin-left: 2.1rem;
  }
}

/* --- 归档 --------------------------------------------------------------- */

.archive-year + .archive-year {
  margin-top: 2.5rem;
}

.year-label {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding-bottom: 0.5rem;
  margin: 0 0 0.5rem;
  border-bottom: 1px solid var(--rule);
}

/* --- 标签 --------------------------------------------------------------- */

.tag-index {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  padding: 0;
  margin: 0;
}

.tag-index a {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--rule);
  font-size: var(--text-sm);
  color: var(--text-soft);
}

.tag-index a:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.tag-count {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* 文章里的标签：等宽小字，不要胶囊 */
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.tag-row a {
  color: var(--text-soft);
}

/* --- 页面标题区 --------------------------------------------------------- */

.page-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--rule);
}

.page-title {
  font-size: clamp(1.5rem, 1.2rem + 1.4vw, 1.85rem);
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.page-lede {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-soft);
}

/* --- 文章页 ------------------------------------------------------------- */

.post-header {
  margin-bottom: 2.5rem;
}

.post-title {
  font-size: clamp(1.55rem, 1.2rem + 1.8vw, 2rem);
  margin-bottom: 0.6rem;
}

.post-desc {
  margin: 0 0 1rem;
  color: var(--text-soft);
  font-size: var(--text-sm);
  line-height: 1.75;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 1rem;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.post-source {
  margin: 0.75rem 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
}

/* 目录：等宽小字，用左侧细线成组 */
.post-toc {
  margin: 0 0 3rem;
  border-left: 2px solid var(--rule);
  padding-left: 1rem;
}

.post-toc > summary {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  cursor: pointer;
  list-style: none;
}

.post-toc > summary::-webkit-details-marker {
  display: none;
}

.post-toc > summary::after {
  content: " ▾";
}

.post-toc[open] > summary::after {
  content: " ▴";
}

.post-toc ol {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  font-size: var(--text-sm);
}

.post-toc li {
  margin: 0.2rem 0;
}

.post-toc a {
  color: var(--text-soft);
}

.post-toc a:hover {
  color: var(--accent);
}

.toc-l3 { padding-left: 1rem; }
.toc-l4 { padding-left: 2rem; }

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

.post-content h2 {
  margin: 3rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: 4.5rem;
}

.post-content h3 {
  margin: 2.25rem 0 0.75rem;
  scroll-margin-top: 4.5rem;
}

.post-content h4 {
  margin: 1.75rem 0 0.6rem;
  color: var(--text-soft);
  scroll-margin-top: 4.5rem;
}

.post-content > :first-child {
  margin-top: 0;
}

.post-content p {
  margin: 0 0 1.4em;
}

.post-content blockquote {
  margin: 1.75rem 0;
  padding: 0.25rem 0 0.25rem 1.15rem;
  border-left: 2px solid var(--rule-strong);
  color: var(--text-soft);
}

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

.post-content strong {
  font-weight: 700;
}

/* 代码：等宽 + 浅底，不画重边框 */
code,
kbd,
samp {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

:not(pre) > code {
  background: var(--bg-code);
  padding: 0.12em 0.35em;
  word-break: break-word;
}

pre {
  margin: 1.75rem 0;
  padding: 1rem 1.15rem;
  background: var(--bg-code);
  border-left: 2px solid var(--rule-strong);
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: 1.7;
  tab-size: 2;
}

pre code {
  background: none;
  padding: 0;
  font-size: 1em;
}

table {
  width: 100%;
  margin: 1.75rem 0;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

th,
td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--rule);
  text-align: left;
}

th {
  border-bottom-color: var(--rule-strong);
  font-weight: 600;
}

/* --- 脚注 --------------------------------------------------------------- */

.footnote-ref a {
  font-family: var(--font-mono);
  font-size: 0.75em;
  padding: 0 0.1em;
}

.footnotes-sep {
  margin: 3rem 0 1.5rem;
}

.footnotes {
  font-size: var(--text-sm);
  color: var(--text-soft);
}

.footnotes-title {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}

.footnotes ol {
  padding-left: 1.4em;
  margin: 0;
}

.footnotes li {
  margin: 0.5rem 0;
}

.footnotes li p {
  margin: 0;
}

.footnote-backref {
  text-decoration: none;
}

/* --- 文章底部的上下篇 --------------------------------------------------- */

.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-top: 3.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-size: var(--text-sm);
}

.post-nav-next {
  text-align: right;
}

.post-nav-label {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.2rem;
}

/* --- 关于页等普通正文 --------------------------------------------------- */

.prose h2 {
  margin: 2.5rem 0 1rem;
  font-size: 1.25rem;
}

.prose blockquote {
  margin: 1.75rem 0;
  padding-left: 1.15rem;
  border-left: 2px solid var(--rule-strong);
  color: var(--text-soft);
}

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

/* --- 页脚 --------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--rule);
  padding: 1.5rem 0 2.5rem;
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.site-footer .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  justify-content: space-between;
}

.footer-motto {
  margin: 0;
  color: var(--text-soft);
}

.footer-meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.footer-meta a {
  color: var(--text-soft);
}

/* --- 打印 --------------------------------------------------------------- */

@media print {
  .site-header,
  .site-footer,
  .post-toc,
  .post-nav,
  .skip-link,
  .theme-toggle {
    display: none;
  }

  body {
    font-size: 11pt;
    background: #fff;
    color: #000;
  }

  a {
    color: inherit;
  }

  .post-content a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #444;
  }
}
