/* ==========================================================
   Calm · Typecho theme  v1.1
   ========================================================== */
:root {
  --bg: #F4F3EE; --bg-elev: #FAF9F5;
  --ink: #141413; --ink-2: #4B4A45; --ink-3: #8B8A82;
  --line: #DFDDD4; --line-strong: #B8B6AC;
  --accent: #C96A4B; --code-bg: #EAE8E0; --sel: #E6D9CF;
  --hl-kw: #8A5A3C; --hl-str: #4F6F52; --hl-num: #3F6A8A; --hl-fn: #2F5D8C; --hl-type: #7A4E5E;

  --serif: "Tiempos Text","Source Serif 4","Iowan Old Style",Georgia,"Noto Serif SC","Songti SC","SimSun",serif;
  --sans:  Inter,"Helvetica Neue",-apple-system,BlinkMacSystemFont,"PingFang SC","Hiragino Sans GB","Noto Sans SC","Microsoft YaHei",sans-serif;
  --mono:  "SF Mono","JetBrains Mono",Menlo,Consolas,"Noto Sans Mono",monospace;

  --wrap: 1120px; --measure: 720px; --scale: 1;
  --ease: cubic-bezier(.2,.6,.2,1);
}
html[data-theme="sepia"] {
  --bg: #F1E9DA; --bg-elev: #F7F1E5;
  --ink: #2B2620; --ink-2: #5A5248; --ink-3: #8E8577;
  --line: #DDD2BE; --line-strong: #B9AC94; --code-bg: #E7DDC9; --sel: #E4D2B6;
}
html[data-theme="dark"] {
  --bg: #1B1A17; --bg-elev: #23221E;
  --ink: #E8E6DF; --ink-2: #B5B3A9; --ink-3: #7E7C73;
  --line: #33322D; --line-strong: #4A4841;
  --accent: #D98B6E; --code-bg: #2A2925; --sel: #4A3B32;
  --hl-kw: #D6A27C; --hl-str: #A3C29A; --hl-num: #8FB8D6; --hl-fn: #9BBEE6; --hl-type: #D3A2B4;
  color-scheme: dark;
}
html[data-width="narrow"] { --measure: 620px; }
html[data-width="wide"]   { --measure: 900px; }

/* ---------- Reset ---------- */
*,*::before,*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern","liga","calt";
  transition: background .25s var(--ease), color .25s var(--ease);
}
img,svg,video { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration: none; transition: color .2s var(--ease); }
a:hover { color: var(--accent); }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input,textarea { font: inherit; color: inherit; }
::selection { background: var(--sel); color: var(--ink); }
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 28px; }
.muted { color: var(--ink-3); }
.eyebrow {
  margin: 0 0 12px; font-family: var(--mono); font-size: 11px;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3);
}

/* ---------- Progress ---------- */
.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 60;
  background: var(--accent); transform-origin: left; transform: scaleX(0);
}

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px); -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
@supports not (background: color-mix(in srgb, red, blue)) { .site-header { background: var(--bg); } }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 58px; gap: 32px; }
.brand { font-family: var(--serif); font-size: 19px; font-weight: 500; letter-spacing: -.01em; }
.brand:hover { color: var(--ink); }
.nav { display: flex; gap: 26px; margin-left: auto; }
.nav a { position: relative; padding: 6px 0; font-size: 13.5px; color: var(--ink-2); }
.nav a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--ink);
  transform: scaleX(0); transform-origin: left; transition: transform .3s var(--ease);
}
.nav a:hover, .nav a.is-active { color: var(--ink); }
.nav a:hover::after, .nav a.is-active::after { transform: scaleX(1); }
.header-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: var(--ink-2);
  transition: background .2s var(--ease), color .2s var(--ease);
}
.icon-btn:hover { background: var(--code-bg); color: var(--ink); }
.menu-toggle { display: none; position: relative; }
.menu-toggle span { position: absolute; left: 9px; width: 16px; height: 1.5px; background: currentColor; transition: all .3s var(--ease); }
.menu-toggle span:first-child { top: 13px; } .menu-toggle span:last-child { top: 19px; }
.menu-toggle.is-open span:first-child { top: 16px; transform: rotate(45deg); }
.menu-toggle.is-open span:last-child  { top: 16px; transform: rotate(-45deg); }
.search-bar { border-top: 1px solid var(--line); background: var(--bg-elev); }
.search-bar input { width: 100%; height: 54px; padding: 0 28px; background: transparent; border: 0; outline: 0; font-family: var(--serif); font-size: 18px; }
.search-bar input::placeholder { color: var(--ink-3); }

/* ---------- Hero ---------- */
.hero { padding: 72px 0 56px; max-width: 760px; }
.hero--small { padding: 56px 0 36px; }
.hero--404 { padding: 120px 0; }
.hero-title {
  margin: 0; font-family: var(--serif); font-weight: 400;
  font-size: clamp(26px, 3.4vw, 38px); line-height: 1.2; letter-spacing: -.015em; text-wrap: balance;
}
.hero-sub { margin: 16px 0 28px; font-size: 15px; color: var(--ink-2); }

/* ---------- List ---------- */
.post-list { border-top: 1px solid var(--line-strong); }
.entry { display: grid; grid-template-columns: 180px minmax(0,1fr); gap: 36px; padding: 34px 0; border-bottom: 1px solid var(--line); }
.entry--compact { padding: 26px 0; }
.entry-meta { display: flex; flex-direction: column; gap: 5px; font-family: var(--mono); font-size: 11.5px; letter-spacing: .04em; color: var(--ink-3); padding-top: 4px; }
.entry-cat { color: var(--ink-2); text-transform: uppercase; letter-spacing: .1em; }
.entry-body { max-width: 680px; }
.entry-title { margin: 0 0 10px; font-family: var(--serif); font-weight: 400; font-size: 20px; line-height: 1.35; letter-spacing: -.01em; text-wrap: balance; }
.entry--featured .entry-title { font-size: clamp(22px, 2.6vw, 28px); line-height: 1.25; }
.entry--compact .entry-title { font-size: 18px; }
.entry-excerpt { margin: 0 0 14px; font-size: 14.5px; line-height: 1.7; color: var(--ink-2); }
.entry--compact .entry-excerpt { margin-bottom: 0; }
.entry-more { display: inline-block; font-size: 13px; color: var(--ink); border-bottom: 1px solid var(--line-strong); padding-bottom: 1px; transition: all .2s var(--ease); }
.entry-more:hover { border-color: var(--accent); }
.empty { padding: 72px 0; color: var(--ink-2); }
.empty a { border-bottom: 1px solid var(--line-strong); }
.pager { display: flex; justify-content: space-between; padding: 30px 0 80px; font-size: 13px; }
.pager a { border-bottom: 1px solid var(--line-strong); padding-bottom: 1px; }
.pager a:hover { border-color: var(--accent); }

/* ---------- Post layout + TOC ---------- */
.post-layout { position: relative; }
.post { max-width: var(--measure); margin: 0 auto; padding-top: 64px; transition: max-width .3s var(--ease); }
.toc {
  position: fixed; top: 96px; right: max(20px, calc((100vw - var(--wrap)) / 2 + 28px));
  width: 200px; max-height: calc(100vh - 140px); overflow: auto;
  font-size: 12.5px; line-height: 1.5; opacity: 0; visibility: hidden; transform: translateX(8px);
  transition: opacity .25s var(--ease), transform .25s var(--ease), visibility .25s;
  scrollbar-width: thin;
}
html.toc-open .toc { opacity: 1; visibility: visible; transform: none; }
.toc nav { border-left: 1px solid var(--line); }
.toc a { display: block; padding: 5px 0 5px 14px; margin-left: -1px; color: var(--ink-3); border-left: 1px solid transparent; transition: all .2s var(--ease); }
.toc a.toc-h3 { padding-left: 26px; font-size: 12px; }
.toc a:hover { color: var(--ink); }
.toc a.is-active { color: var(--ink); border-left-color: var(--ink); }
@media (max-width: 1199px) {
  .toc {
    right: 20px; left: 20px; top: auto; bottom: 76px; width: auto; max-height: 50vh;
    padding: 18px 20px; background: var(--bg-elev); border: 1px solid var(--line);
    border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.12); transform: translateY(8px);
  }
  html.toc-open .toc { transform: none; }
}
@media (max-width: 1360px) and (min-width: 1200px) {
  html.toc-open { --wrap: 1360px; }
  .toc { right: 24px; width: 180px; }
}

/* ---------- Post ---------- */
.post-header { padding-bottom: 32px; border-bottom: 1px solid var(--line); margin-bottom: 40px; }
.post-title { margin: 0 0 16px; font-family: var(--serif); font-weight: 400; font-size: clamp(24px, 3.2vw, 34px); line-height: 1.2; letter-spacing: -.015em; text-wrap: balance; }
.post-summary { margin: 0 0 22px; font-family: var(--serif); font-size: 16.5px; line-height: 1.55; color: var(--ink-2); }
.post-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; font-family: var(--mono); font-size: 11.5px; letter-spacing: .04em; color: var(--ink-3); }
.post-meta > * + *::before { content: "·"; margin-right: 16px; color: var(--line-strong); }
.post-meta a:hover { color: var(--accent); }
.difficulty { padding: 2px 8px; border-radius: 100px; border: 1px solid var(--line-strong); font-size: 10.5px; letter-spacing: .08em; }
.difficulty--easy   { color: #4F7F55; border-color: #4F7F55; }
.difficulty--medium { color: #B07A2A; border-color: #B07A2A; }
.difficulty--hard   { color: var(--accent); border-color: var(--accent); }
.difficulty::before { display: none !important; }

/* 正文 */
.post-content { font-family: var(--serif); font-size: calc(16px * var(--scale)); line-height: 1.75; color: var(--ink); transition: font-size .2s var(--ease); }
html[data-font="sans"] .post-content { font-family: var(--sans); line-height: 1.7; }
.post-content > * + * { margin-top: 1.3em; }
.post-content h2, .post-content h3, .post-content h4 { font-weight: 500; line-height: 1.3; letter-spacing: -.01em; margin-top: 2em; scroll-margin-top: 80px; }
.post-content h2 { font-size: 1.4em; padding-bottom: .4em; border-bottom: 1px solid var(--line); }
.post-content h3 { font-size: 1.15em; }
.post-content h4 { font-size: 1em; font-family: var(--sans); }
.post-content p { margin-bottom: 0; }
.post-content a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.post-content a:hover { color: var(--accent); text-decoration-color: var(--accent); }
.post-content blockquote { margin: 1.6em 0; padding: 0 0 0 20px; border-left: 1px solid var(--ink); color: var(--ink-2); }
.post-content ul, .post-content ol { padding-left: 1.4em; }
.post-content li + li { margin-top: .3em; }
.post-content li::marker { color: var(--ink-3); }
.post-content hr { border: 0; height: 1px; background: var(--line); margin: 2.6em 0; }
.post-content img { margin: 2em auto; border-radius: 4px; }
.post-content figcaption { margin-top: 8px; text-align: center; font-family: var(--sans); font-size: 12.5px; color: var(--ink-3); }
.post-content code { font-family: var(--mono); font-size: .86em; background: var(--code-bg); padding: .12em .35em; border-radius: 3px; }
.post-content strong { font-weight: 600; }
.post-content table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: .9em; display: block; overflow-x: auto; }
.post-content th, .post-content td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.post-content th { font-weight: 500; border-bottom-color: var(--ink); }
.post-content .katex-display { margin: 1.4em 0; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.post-content .katex { font-size: 1.05em; }

/* 折叠块：答案 / 提示 */
.post-content details { border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 18px; font-size: .95em; }
.post-content details + details { margin-top: .8em; }
.post-content summary {
  list-style: none; cursor: pointer; padding: 12px 0; margin: 0 -18px; padding-left: 18px; padding-right: 18px;
  display: flex; align-items: center; gap: 10px; font-family: var(--sans); font-size: 13.5px; color: var(--ink-2); user-select: none;
}
.post-content summary::-webkit-details-marker { display: none; }
.post-content summary::before { content: ""; width: 6px; height: 6px; border-right: 1px solid currentColor; border-bottom: 1px solid currentColor; transform: rotate(-45deg); transition: transform .2s var(--ease); }
.post-content details[open] summary::before { transform: rotate(45deg); }
.post-content details[open] summary { border-bottom: 1px solid var(--line); color: var(--ink); }
.post-content details > :not(summary) { margin-top: 1em; }
.post-content details > :last-child { margin-bottom: 1.1em; }

/* 代码块 */
.code-block { margin: 1.6em 0; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-elev); overflow: hidden; position: relative; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px 6px 16px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 11px; letter-spacing: .06em; color: var(--ink-3); }
.code-lang { text-transform: uppercase; }
.code-copy { padding: 3px 8px; border-radius: 4px; color: var(--ink-3); transition: all .2s var(--ease); }
.code-copy:hover { color: var(--ink); background: var(--code-bg); }
.post-content pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-family: var(--mono); font-size: 13px; line-height: 1.65; tab-size: 4; display: flex; }
.post-content pre code { background: none; padding: 0; font-size: inherit; flex: 1; min-width: 0; display: block; }
.code-gutter { flex: none; text-align: right; padding-right: 16px; margin-right: 16px; border-right: 1px solid var(--line); color: var(--ink-3); user-select: none; white-space: pre; opacity: .7; }
html[data-wrap="on"] .post-content pre code { white-space: pre-wrap; word-break: break-word; }
html[data-wrap="on"] .code-gutter { display: none; }
.code-block.is-collapsed pre { max-height: 400px; }
.code-block.is-collapsed::after { content: ""; position: absolute; left: 0; right: 0; bottom: 36px; height: 70px; background: linear-gradient(to bottom, transparent, var(--bg-elev)); pointer-events: none; }
.code-expand { display: block; width: 100%; padding: 9px; border-top: 1px solid var(--line); font-family: var(--sans); font-size: 12.5px; color: var(--ink-2); background: var(--bg-elev); }
.code-expand:hover { color: var(--accent); }
/* highlight.js 中性配色 */
.hljs { color: var(--ink); background: transparent; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-meta { color: var(--hl-kw); }
.hljs-string, .hljs-attr, .hljs-template-tag, .hljs-regexp { color: var(--hl-str); }
.hljs-number, .hljs-literal, .hljs-symbol { color: var(--hl-num); }
.hljs-title, .hljs-section, .hljs-name { color: var(--hl-fn); }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_ { color: var(--hl-type); }
.hljs-comment, .hljs-quote { color: var(--ink-3); font-style: italic; }
.hljs-emphasis { font-style: italic; } .hljs-strong { font-weight: 600; }

.post-footer { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--line); }
.post-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.post-tags a { font-family: var(--mono); font-size: 11px; letter-spacing: .04em; padding: 4px 11px; border: 1px solid var(--line-strong); border-radius: 100px; color: var(--ink-2); transition: all .2s var(--ease); }
.post-tags a:hover { border-color: var(--ink); color: var(--ink); }

.post-nav { max-width: var(--measure); margin: 56px auto 0; display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.post-nav-item { padding: 22px 24px 22px 0; font-family: var(--serif); font-size: 16px; line-height: 1.4; }
.post-nav-item--next { padding: 22px 0 22px 24px; border-left: 1px solid var(--line); text-align: right; }
.post-nav-item .eyebrow { display: block; margin-bottom: 8px; }

/* ---------- Reader bar ---------- */
.reader-bar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 55;
  display: flex; align-items: center; gap: 2px; padding: 5px;
  background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: 100px;
  box-shadow: 0 8px 30px rgba(0,0,0,.10); max-width: calc(100vw - 32px); overflow-x: auto; scrollbar-width: none;
}
.reader-bar::-webkit-scrollbar { display: none; }
.reader-bar button {
  flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%;
  color: var(--ink-2); transition: all .2s var(--ease); position: relative;
}
.reader-bar button:hover { background: var(--code-bg); color: var(--ink); }
.reader-bar button:disabled { opacity: .3; cursor: default; background: none; }
.reader-bar button.is-on { color: var(--accent); }
.reader-bar button.is-on::after { content: ""; position: absolute; bottom: 4px; left: 50%; width: 3px; height: 3px; margin-left: -1.5px; border-radius: 50%; background: var(--accent); }
.reader-bar svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.reader-bar .txt { font-family: var(--sans); font-size: 14px; line-height: 1; }
.reader-bar .txt sup { font-size: 9px; margin-left: 1px; }
.reader-bar .txt--serif { font-family: var(--serif); }
html[data-font="sans"] .reader-bar .txt--serif { font-family: var(--sans); }
.reader-bar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; flex: none; }
.reader-bar [data-action="top"] { opacity: .3; pointer-events: none; transition: opacity .2s; }
.reader-bar [data-action="top"].is-show { opacity: 1; pointer-events: auto; }
.toast {
  position: fixed; left: 50%; bottom: 72px; transform: translate(-50%, 6px); z-index: 56;
  padding: 6px 14px; border-radius: 100px; background: var(--ink); color: var(--bg);
  font-size: 12.5px; opacity: 0; pointer-events: none; transition: all .2s var(--ease);
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* 专注模式 */
html.is-focus .site-header, html.is-focus .site-footer, html.is-focus .post-nav,
html.is-focus .comments, html.is-focus .toc, html.is-focus .post-footer { display: none !important; }
html.is-focus .post { padding-top: 72px; padding-bottom: 120px; }
html.is-focus .reader-bar { opacity: .35; }
html.is-focus .reader-bar:hover { opacity: 1; }

/* ---------- Comments ---------- */
.comments { max-width: var(--measure); margin: 0 auto; padding: 56px 0 120px; }
.section-title { margin: 0 0 24px; font-family: var(--serif); font-weight: 400; font-size: 20px; letter-spacing: -.01em; }
.comment-list, .comment-list ol { list-style: none; margin: 0; padding: 0; }
.comment { padding: 20px 0; border-top: 1px solid var(--line); }
.comment--child { border-top: 1px dashed var(--line); }
.comment-children { margin-left: 28px; padding-left: 18px; border-left: 1px solid var(--line); }
.comment-children .comment:first-child { border-top: 0; }
.comment-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 6px; font-size: 13.5px; }
.comment-author { font-weight: 500; }
.comment--owner .comment-author::after { content: "作者"; margin-left: 8px; font-family: var(--mono); font-size: 10px; letter-spacing: .1em; color: var(--accent); }
.comment-time { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.comment-reply { margin-left: auto; font-size: 12.5px; }
.comment-reply a { color: var(--ink-3); }
.comment-content { font-size: 14.5px; line-height: 1.7; color: var(--ink-2); }
.comment-content p { margin: 0; } .comment-content p + p { margin-top: .6em; }
.comment-pager { margin: 20px 0; font-size: 13px; }
.comment-pager .page-navigator { display: flex; gap: 14px; list-style: none; padding: 0; margin: 0; }
.comment-pager .current a { color: var(--accent); }
.respond { margin-top: 48px; padding-top: 32px; border-top: 1px solid var(--line-strong); }
.respond-head { display: flex; align-items: baseline; justify-content: space-between; }
.cancel-reply a { font-size: 12.5px; color: var(--ink-3); border-bottom: 1px solid var(--line-strong); }
.logged-in { font-size: 13.5px; color: var(--ink-2); margin: 0 0 18px; }
.form-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 24px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field--full { margin-top: 24px; }
.field span { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.field input, .field textarea { width: 100%; padding: 9px 0; background: transparent; border: 0; border-bottom: 1px solid var(--line-strong); border-radius: 0; outline: 0; resize: vertical; transition: border-color .2s var(--ease); }
.field textarea { font-family: var(--serif); font-size: 15.5px; line-height: 1.6; }
.field input:focus, .field textarea:focus { border-bottom-color: var(--ink); }
.form-actions { display: flex; align-items: center; gap: 18px; margin-top: 28px; font-size: 12.5px; }
.comments-closed { padding-top: 20px; border-top: 1px solid var(--line); }
.btn { display: inline-flex; align-items: center; padding: 10px 20px; border-radius: 100px; background: var(--ink); color: var(--bg); font-size: 13.5px; transition: background .2s var(--ease), transform .2s var(--ease); }
.btn:hover { background: var(--accent); color: #fff; }
.btn:active { transform: translateY(1px); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line-strong); margin-top: 40px; padding-bottom: 72px; }
.footer-inner { display: grid; grid-template-columns: 1.4fr 1fr; gap: 36px; padding: 48px 28px 32px; }
.footer-brand p { margin: 8px 0 0; color: var(--ink-2); font-size: 14px; max-width: 420px; }
.footer-links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 24px; align-content: start; }
.footer-links a { font-size: 13.5px; color: var(--ink-2); border-bottom: 1px solid transparent; }
.footer-links a:hover { border-color: var(--accent); }
.footer-copy { grid-column: 1 / -1; margin: 20px 0 0; padding-top: 20px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 11.5px; letter-spacing: .03em; color: var(--ink-3); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) { .entry { grid-template-columns: 140px 1fr; gap: 24px; } }
@media (max-width: 720px) {
  .wrap { padding: 0 20px; }
  .header-inner { height: 54px; }
  .menu-toggle { display: grid; }
  .nav { position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; gap: 0; margin: 0; background: var(--bg); border-bottom: 1px solid var(--line); max-height: 0; overflow: hidden; transition: max-height .35s var(--ease); }
  .nav.is-open { max-height: 480px; }
  .nav a { padding: 14px 20px; border-top: 1px solid var(--line); font-size: 15px; }
  .nav a::after { display: none; }
  .search-bar input { height: 50px; padding: 0 20px; font-size: 16px; }
  .hero { padding: 48px 0 36px; }
  .entry, .entry--compact { grid-template-columns: 1fr; gap: 10px; padding: 26px 0; }
  .entry-meta { flex-direction: row; gap: 14px; padding-top: 0; }
  .entry-title { font-size: 18px; } .entry--featured .entry-title { font-size: 22px; }
  .post { padding-top: 44px; }
  .post-content { font-size: calc(15.5px * var(--scale)); }
  .post-nav { grid-template-columns: 1fr; }
  .post-nav-item, .post-nav-item--next { padding: 20px 0; border-left: 0; text-align: left; }
  .post-nav-item--next { border-top: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; gap: 18px; }
  .comment-children { margin-left: 10px; padding-left: 12px; }
  .footer-inner { grid-template-columns: 1fr; gap: 24px; padding: 36px 20px 28px; }
  .reader-bar { bottom: max(14px, env(safe-area-inset-bottom)); justify-content: flex-start; }
}
@media print {
  .site-header, .site-footer, .post-nav, .comments, .pager, .reader-bar, .toc, .progress, .code-copy { display: none !important; }
  body { background: #fff; color: #000; }
  .post-content details { border: 0; padding: 0; } .post-content details:not([open]) > :not(summary) { display: block; }
  .code-block.is-collapsed pre { max-height: none; } .code-block.is-collapsed::after, .code-expand { display: none; }
}
/* ==========================================================
   v1.2 additions · 交互 / 首页 / 归档 / 友链
   ========================================================== */

/* 页面进入 */
@keyframes calm-in { from { opacity: 0; } to { opacity: 1; } }
html.js body { animation: calm-in .35s var(--ease) both; }

/* 滚动淡入 */
html.js [data-reveal] {
  opacity: 0; transform: translateY(14px);
  transition: opacity .6s var(--ease), transform .6s var(--ease);
  transition-delay: calc(var(--i, 0) * 60ms);
}
html.js [data-reveal].is-in { opacity: 1; transform: none; }

/* 顶栏隐藏 */
.site-header { transition: transform .3s var(--ease), background .25s var(--ease); }
.site-header.is-hidden { transform: translateY(-100%); }
@keyframes drop { from { opacity: 0; transform: translateY(-4px); } }
.search-bar:not([hidden]) { animation: drop .25s var(--ease); }

/* 首页统计 */
.hero-sub { margin: 14px 0 0; font-size: 14.5px; color: var(--ink-2); max-width: 560px; }
.hero-sub.post-content { font-family: var(--sans); font-size: 14.5px; line-height: 1.65; }
.hero-stats {
  list-style: none; margin: 28px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 28px;
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .06em; color: var(--ink-3);
}
.hero-stats b { font-family: var(--serif); font-weight: 400; font-size: 17px; color: var(--ink); margin: 0 4px 0 0; letter-spacing: 0; }
.hero-stats li:last-child b { margin-left: 4px; }

/* 分类胶囊 */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 0 0 22px; margin-top: -8px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 5px 12px; border: 1px solid var(--line-strong); border-radius: 100px;
  font-size: 12.5px; color: var(--ink-2); white-space: nowrap;
  transition: border-color .2s var(--ease), color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease);
}
.chip small { margin-left: 5px; font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }
.chip:hover { border-color: var(--ink); color: var(--ink); transform: translateY(-1px); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip.is-active small { color: var(--bg); opacity: .6; }

/* 列表悬停：细线画出 + 箭头位移 */
.entry-title a {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat; background-position: 0 100%; background-size: 0 1px;
  transition: background-size .45s var(--ease), color .2s var(--ease);
}
.entry:hover .entry-title a { background-size: 100% 1px; }
.entry-more span { display: inline-block; margin-left: 4px; transition: transform .3s var(--ease); }
.entry:hover .entry-more span { transform: translateX(4px); }
.entry-meta .difficulty { align-self: flex-start; margin-top: 2px; }
.inline-search { margin: 0 0 28px; max-width: 360px; }
.inline-search input {
  width: 100%; padding: 10px 0; background: transparent; border: 0; outline: 0;
  border-bottom: 1px solid var(--line-strong); font-family: var(--serif); font-size: 17px;
  transition: border-color .2s var(--ease);
}
.inline-search input:focus { border-bottom-color: var(--ink); }
.hero--404 .btn { margin-top: 8px; }

/* 文章：锚点 / 更新 / 复制链接 */
.post-content h2, .post-content h3 { position: relative; }
.anchor {
  position: absolute; left: -1.1em; top: 0; width: 1em; text-align: center;
  font-family: var(--sans); font-weight: 400; color: var(--ink-3);
  opacity: 0; text-decoration: none !important; transition: opacity .2s var(--ease), color .2s var(--ease);
}
.anchor::before { content: "#"; }
.post-content h2:hover .anchor, .post-content h3:hover .anchor { opacity: 1; }
.anchor:hover { color: var(--accent); }
.post-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.copy-link {
  flex: none; font-family: var(--mono); font-size: 11.5px; letter-spacing: .04em; color: var(--ink-3);
  border-bottom: 1px solid transparent; transition: color .2s var(--ease), border-color .2s var(--ease);
}
.copy-link:hover { color: var(--ink); border-color: var(--ink); }
.post-content img { cursor: zoom-in; }

/* 学习专题导航 */
.series-nav { max-width: var(--measure); margin: 48px auto 0; padding: 22px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.series-heading { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.series-heading .eyebrow { margin: 0; }
.series-heading strong { font: 17px var(--serif); font-weight: 500; }
.series-heading span { color: var(--ink-3); font: 11px var(--mono); }
.series-nav ol { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 20px; margin: 0; padding: 0; list-style: none; }
.series-nav li { display: flex; align-items: baseline; gap: 8px; min-width: 0; padding: 10px 0; border-top: 1px dashed var(--line); font: 14px/1.4 var(--serif); }
.series-nav li > span { flex: none; color: var(--ink-3); font: 11px var(--mono); }
.series-nav li a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.series-nav li b { flex: none; color: var(--accent); font: 10px var(--sans); font-weight: 400; }
.series-nav li.is-current a { color: var(--accent); }
@media (max-width: 720px) { .series-nav { margin-top: 32px; } .series-nav ol { grid-template-columns: 1fr; } .series-nav li a { white-space: normal; } }


.related { max-width: var(--measure); margin: 48px auto 0; }
.related-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; border-top: 1px solid var(--line); }
.related-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
  transition: padding-left .25s var(--ease);
}
.related-item:hover { padding-left: 6px; }
.related-title { font-family: var(--serif); font-size: 15.5px; line-height: 1.4; }
.related-item time { flex: none; font-family: var(--mono); font-size: 11px; color: var(--ink-3); }

/* 灯箱 */
.lightbox {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 24px;
  background: rgba(20,20,19,.9); cursor: zoom-out;
  opacity: 0; visibility: hidden; transition: opacity .25s var(--ease), visibility .25s;
}
.lightbox img {
  max-width: 100%; max-height: 100%; width: auto; height: auto; border-radius: 4px;
  transform: scale(.96); transition: transform .3s var(--ease);
}
.lightbox figure { position: relative; max-width: min(92vw, 1400px); max-height: 90vh; margin: 0; text-align: center; }
.lightbox figure img { display: block; max-width: 100%; max-height: calc(90vh - 28px); }
.lightbox figcaption { margin-top: 8px; color: rgba(255,255,255,.72); font: 12px/1.4 var(--sans); }
.lightbox-nav, .lightbox-close { position: absolute; z-index: 2; display: grid; place-items: center; color: #fff; background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.35); border-radius: 50%; }
.lightbox-nav { top: 50%; width: 42px; height: 42px; margin-top: -21px; font: 32px/1 var(--sans); }
.lightbox-prev { left: 22px; } .lightbox-next { right: 22px; }
.lightbox-close { top: 18px; right: 20px; width: 34px; height: 34px; font: 24px/1 var(--sans); }
.lightbox-nav:hover, .lightbox-close:hover { background: rgba(255,255,255,.18); }


/* 回到顶部（非文章页） */
.back-top {
  position: fixed; right: 20px; bottom: 20px; z-index: 55; width: 38px; height: 38px;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--bg-elev); border: 1px solid var(--line-strong); color: var(--ink-2);
  opacity: 0; visibility: hidden; transform: translateY(8px);
  transition: opacity .25s var(--ease), transform .25s var(--ease), visibility .25s, color .2s, border-color .2s;
}
.back-top.is-show { opacity: 1; visibility: visible; transform: none; }
.back-top:hover { color: var(--ink); border-color: var(--ink); }

/* 归档页 */
.archive-filter { margin: -8px 0 8px; max-width: 420px; }
.archive-filter input {
  width: 100%; padding: 10px 0; background: transparent; border: 0; outline: 0;
  border-bottom: 1px solid var(--line-strong); font-family: var(--serif); font-size: 17px;
  transition: border-color .2s var(--ease);
}
.archive-filter input:focus { border-bottom-color: var(--ink); }
.archive { border-top: 1px solid var(--line-strong); margin-bottom: 96px; }
.archive-year { display: grid; grid-template-columns: 140px 1fr; gap: 32px; padding: 28px 0; border-bottom: 1px solid var(--line); }
.archive-year-label { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 28px; line-height: 1; letter-spacing: -.02em; }
.archive-year-label small { display: block; margin-top: 8px; font-family: var(--mono); font-size: 11px; letter-spacing: .08em; color: var(--ink-3); }
.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  padding: 9px 0; border-bottom: 1px dashed var(--line); font-family: var(--serif); font-size: 15.5px;
  transition: padding-left .25s var(--ease);
}
.archive-item:last-child { border-bottom: 0; }
.archive-item:hover { padding-left: 6px; }
.archive-item time { flex: none; font-family: var(--mono); font-size: 11px; color: var(--ink-3); }

/* 友链 */
.links-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-bottom: 72px; }
.link-card {
  display: flex; flex-direction: column; gap: 6px; padding: 18px 20px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg-elev);
  transition: border-color .25s var(--ease), transform .25s var(--ease), box-shadow .25s var(--ease);
}
.link-card:hover { color: inherit; border-color: var(--ink); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.05); }
.link-name { font-family: var(--serif); font-size: 17px; }
.link-desc { font-size: 13px; color: var(--ink-2); line-height: 1.55; }
.link-host { margin-top: auto; padding-top: 6px; font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; color: var(--ink-3); }
.link-card:hover .link-host { color: var(--accent); }

/* 响应式 & 无障碍 */
@media (max-width: 720px) {
  .hero-stats { gap: 6px 20px; }
  .related-grid { grid-template-columns: 1fr; }
  .archive-year { grid-template-columns: 1fr; gap: 12px; padding: 22px 0; }
  .archive-year-label { font-size: 22px; }
  .archive-year-label small { display: inline; margin: 0 0 0 10px; }
  .anchor { display: none; }
  .back-top { right: 14px; bottom: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  html.js body, .search-bar:not([hidden]) { animation: none; }
  html.js [data-reveal] { transition: none; opacity: 1; transform: none; }
  .site-header, .chip, .entry-title a, .entry-more span, .related-item, .archive-item, .link-card, .lightbox img { transition: none; }
}

/* iOS Safari 稳定性：取消可能卡在 opacity:0 的整页动画，保留元素级 reveal */
html.js body { opacity: 1; animation: none; }

/* 所有设备默认可见：避免 reveal 时序或缓存导致内容透明 */
html.js [data-reveal], html.js [data-reveal].is-in { opacity: 1 !important; }
html.js [data-reveal].is-in { transform: none; }

.reader-bar button.is-on { color: var(--accent); }
.reader-bar button.is-on svg { fill: currentColor; }
.post-content mjx-container[display="true"] { cursor: copy; }

.post-content { min-width: 0; overflow-x: hidden; }
.table-scroll { position: relative; max-width: 100%; margin: 1.3em 0; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.table-scroll > table { margin: 0; display: table; width: max-content; min-width: 100%; }
.table-hint { position: absolute; right: 8px; top: 8px; padding: 3px 7px; border-radius: 99px; background: var(--ink); color: var(--bg); font: 10px/1.2 var(--sans); opacity: .72; pointer-events: none; transition: opacity .25s; }
.table-scroll.has-scrolled .table-hint { opacity: 0; }
.reader-progress { flex: none; min-width: 28px; text-align: center; color: var(--ink-3); font: 10px/1 var(--mono); }
.reader-bar { transition: opacity .25s var(--ease), transform .25s var(--ease); }
.reader-bar.is-idle { opacity: .18; }
.reader-bar.is-idle:hover, .reader-bar.is-idle:focus-within { opacity: 1; }
.resume-prompt { position: fixed; left: 50%; bottom: 82px; z-index: 57; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px); padding: 9px 11px 9px 15px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--bg-elev); box-shadow: 0 8px 30px rgba(0,0,0,.12); color: var(--ink-2); font: 12px/1.3 var(--sans); }
.resume-prompt button { padding: 5px 9px; border-radius: 999px; color: var(--ink); font: inherit; white-space: nowrap; }
.resume-prompt button:first-of-type { background: var(--ink); color: var(--bg); }
@media (max-width: 720px) {
  .post { padding-bottom: 92px; }
  .table-scroll { margin-left: -2px; margin-right: -2px; padding-bottom: 5px; }
  .reader-bar.is-idle { transform: translate(-50%, calc(100% + 10px)); opacity: 0; pointer-events: none; }
  .resume-prompt { bottom: 132px; flex-wrap: wrap; justify-content: center; border-radius: 14px; }
}

/* AI reading assistant */
#ai-reader-toggle { font-family: var(--mono); font-size: 10px; font-weight: 600; }
.ai-selection-menu { position: fixed; z-index: 80; display: none; gap: 2px; padding: 4px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--bg-elev); box-shadow: 0 8px 28px rgba(0,0,0,.16); }
.ai-selection-menu.is-open { display: flex; }
.ai-selection-menu button { padding: 6px 8px; color: var(--ink-2); font: 11px var(--sans); white-space: nowrap; }
.ai-selection-menu button:hover { color: var(--accent); background: var(--bg-soft); border-radius: 5px; }
.ai-panel { position: fixed; z-index: 70; top: 68px; right: 18px; bottom: 18px; display: flex; flex-direction: column; width: min(390px, calc(100vw - 36px)); border: 1px solid var(--line-strong); border-radius: 14px; background: var(--bg-elev); box-shadow: 0 18px 60px rgba(0,0,0,.18); opacity: 0; visibility: hidden; transform: translateX(18px); transition: .25s ease; }
.ai-panel.is-open { opacity: 1; visibility: visible; transform: none; }
.ai-panel > header { display: flex; align-items: center; justify-content: space-between; padding: 15px 17px; border-bottom: 1px solid var(--line); }
.ai-panel header b { display: block; font: 15px var(--serif); font-weight: 500; }
.ai-panel header small, .ai-panel small { color: var(--ink-3); font: 10px/1.4 var(--sans); }
.ai-close { color: var(--ink-2); font-size: 22px; }
.ai-context { padding: 11px 15px; border-bottom: 1px solid var(--line); }
.ai-section-title { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--ink-2); font: 11px var(--sans); }
.ai-section-title button { color: var(--accent); font: inherit; }
.ai-context-list { max-height: 108px; overflow: auto; }
.ai-context-list label { display: flex; gap: 7px; align-items: center; padding: 3px 0; color: var(--ink-2); font: 12px var(--serif); }
.ai-context-list span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-messages { flex: 1; overflow: auto; padding: 15px; }
.ai-msg { margin-bottom: 14px; padding: 10px 12px; border-radius: 10px; font: 13px/1.7 var(--serif); }
.ai-msg p { margin: 4px 0 0; white-space: pre-wrap; }
.ai-msg.user { margin-left: 30px; background: var(--bg-soft); }
.ai-msg.assistant { margin-right: 12px; border-left: 2px solid var(--accent); background: var(--bg-soft); }
.ai-msg pre { max-width: 100%; overflow: auto; padding: 8px; font-size: 11px; }
.ai-login { margin: auto 15px; padding: 15px; border: 1px solid var(--line); border-radius: 10px; }
.ai-login p { margin: 0 0 10px; font: 12px var(--serif); }
.ai-login input, .ai-input textarea { box-sizing: border-box; width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px; background: var(--bg); color: var(--ink); font: 13px var(--sans); }
.ai-login button, .ai-input button { margin-top: 8px; padding: 7px 13px; border-radius: 7px; background: var(--ink); color: var(--bg); font: 12px var(--sans); }
.ai-login em { display: block; margin-top: 6px; color: #a33; font: 11px var(--sans); }
.ai-input { display: flex; gap: 7px; align-items: flex-end; padding: 12px 15px 15px; border-top: 1px solid var(--line); }
.ai-input textarea { resize: vertical; min-height: 42px; }
.ai-input button { flex: none; margin: 0; }
@media (max-width:720px) { .ai-panel { top: auto; right: 8px; bottom: 8px; left: 8px; width: auto; height: min(78vh, 620px); transform: translateY(16px); } .ai-selection-menu { max-width: calc(100vw - 16px); overflow-x: auto; } .ai-selection-menu button { padding: 7px 8px; } }
