/* ==========================================================================
   Design tokens — warm achromatic editorial palette, light & dark
   仅黑白灰，不引入彩色；日间为暖纸白，夜间为暖炭灰
   ========================================================================== */
:root {
  --bg: #faf9f8;
  --bg-card: #ffffff;
  --bg-code: rgba(41, 35, 28, 0.05);
  --bg-header: rgba(250, 249, 248, 0.82);
  --text: #1a1a1a;
  --text-secondary: #6b6b6b;
  --text-tertiary: #8e8e8e;
  --accent: #1a1a1a;
  --accent-strong: #000000;
  --on-accent: #ffffff;
  --border: rgba(60, 50, 40, 0.12);
  --border-strong: rgba(60, 50, 40, 0.22);
  --shadow-card: 0 1px 2px rgba(40, 33, 26, 0.03), 0 6px 20px rgba(40, 33, 26, 0.05);
  --shadow-card-hover: 0 2px 6px rgba(40, 33, 26, 0.06), 0 14px 36px rgba(40, 33, 26, 0.10);
  --shadow-pop: 0 4px 12px rgba(40, 33, 26, 0.08), 0 18px 48px rgba(40, 33, 26, 0.14);
  --selection: rgba(41, 35, 28, 0.12);
  --maxwidth: 1080px;
  --reading: 740px;
  --radius: 12px;
  --radius-sm: 8px;
}

html[data-theme="dark"] {
  --bg: #121211;
  --bg-card: #1c1c1b;
  --bg-code: rgba(255, 255, 255, 0.07);
  --bg-header: rgba(18, 18, 17, 0.82);
  --text: #f2f1ef;
  --text-secondary: #a3a2a0;
  --text-tertiary: #74736f;
  --accent: #f2f1ef;
  --accent-strong: #ffffff;
  --on-accent: #121211;
  --border: rgba(255, 255, 255, 0.14);
  --border-strong: rgba(255, 255, 255, 0.24);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-card-hover: 0 2px 6px rgba(0, 0, 0, 0.5), 0 14px 36px rgba(0, 0, 0, 0.5);
  --shadow-pop: 0 4px 12px rgba(0, 0, 0, 0.5), 0 18px 48px rgba(0, 0, 0, 0.6);
  --selection: rgba(255, 255, 255, 0.16);
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }

/* 确保原生控件不使用系统蓝色强调色 */
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

* { -webkit-tap-highlight-color: transparent; }

input, textarea, select, button, progress { accent-color: var(--text); }

a, button, input, textarea, select { outline-color: var(--text-secondary); }
:focus-visible { outline: 2px solid var(--text-secondary); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.wrap {
  max-width: var(--maxwidth);
  margin: 0 auto;
  padding: 0 1.25rem;
}

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

::selection { background: var(--selection); }

h1, h2, h3, h4 {
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--text);
}

/* ==========================================================================
   Header — sticky, translucent blur
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 1rem;
  min-height: 3.5rem;
}

.site-title {
  font-size: 1.02rem;
  font-weight: 750;
  letter-spacing: -0.015em;
  color: var(--text);
  white-space: nowrap;
  margin-right: auto;
}
.site-title:hover { color: var(--accent); }

.site-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.1rem;
}

.site-nav a {
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.92rem;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.site-nav a:hover { color: var(--text); background: var(--bg-code); }
.site-nav a.active { color: var(--text); font-weight: 600; }

.header-actions { display: flex; align-items: center; gap: 0.35rem; }

.lang-switch {
  padding: 0.28rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}
.lang-switch:hover { color: var(--text); border-color: var(--text); background: var(--bg-code); }

.icon-button {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.icon-button:hover { background: var(--bg-code); color: var(--text); }
.icon-button svg { width: 1.05rem; height: 1.05rem; }

#search-toggle[aria-expanded="true"] { background: var(--bg-code); color: var(--text); }

html[data-theme="dark"] .icon-sun { display: none; }
html:not([data-theme="dark"]) .icon-moon { display: none; }

/* Search — collapsed into an icon, expands within the header surface */
.search-panel {
  border-top: 1px solid var(--border);
  background: transparent;
}

.search-panel[hidden] { display: none; }

.search-panel-inner {
  position: relative;
  display: flex;
  align-items: center;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  animation: search-panel-in 0.18s ease-out;
}

@keyframes search-panel-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

#search-input {
  width: 100%;
  max-width: 420px;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#search-input::placeholder { color: var(--text-tertiary); }
#search-input:focus {
  border-color: var(--text-secondary);
  box-shadow: 0 0 0 3px var(--selection);
}

#search-results {
  position: absolute;
  top: calc(100% - 0.5rem);
  left: 1.25rem;
  right: 1.25rem;
  max-width: 460px;
  z-index: 90;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
#search-results:empty { display: none; }

.search-item { padding: 0.7rem 0.95rem; border-bottom: 1px solid var(--border); }
.search-item:last-child { border-bottom: none; }
.search-item a { color: var(--text); }
.search-item a:hover h4 { color: var(--accent); }
.search-item h4 { margin: 0 0 0.15rem; font-size: 0.95rem; }
.search-item p { margin: 0; font-size: 0.85rem; color: var(--text-secondary); }

/* ==========================================================================
   Main / reading column
   ========================================================================== */
.main-content {
  max-width: var(--reading);
  padding: 2.5rem 1.25rem 3.5rem;
}

/* 首页版面更宽（两栏资料块 + 日期列表），文章页保持窄栏阅读宽度 */
.main-content-wide { max-width: 920px; }

/* ---------- Hero (homepage) ---------- */
.hero { padding: 2.5rem 0 1rem; }

.hero-eyebrow {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2.2rem, 5.5vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.hero-tagline {
  margin: 0 0 1.75rem;
  max-width: 34em;
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.hero-links { display: flex; flex-wrap: wrap; gap: 0.75rem; }

/* ---------- Quote rotator (footer epigraph) ---------- */
/* 单句显示 + 淡入，不再多句 grid 叠加交叉淡化，避免切换 0.65s 内两句重影 */
.quote-rotator {
  display: block;
  text-align: left;
  margin: 0 0 0.65rem;
  min-height: 1.65em;
}

.quote-item {
  display: none;
  margin: 0;
}
.quote-item.is-active {
  display: block;
  animation: quote-in 0.4s ease;
}

@keyframes quote-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.quote-text {
  margin: 0;
  font-size: 0.88rem;
  font-style: italic;
  line-height: 1.6;
  color: var(--text-tertiary);
  /* 页脚只占一行，超长用省略号，完整内容悬停可见 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.quote-author {
  font-style: normal;
  white-space: nowrap;
  color: var(--text-tertiary);
}

@media (prefers-reduced-motion: reduce) {
  .quote-item.is-active { animation: none; }
}

/* ---------- Ink divider ---------- */
.ink-divider { margin: 1.9rem 0 0.4rem; opacity: 0.55; }
.ink-divider svg { display: block; width: 100%; height: 12px; }
.ink-divider path {
  fill: none;
  stroke: var(--border-strong);
  stroke-width: 1.2;
  stroke-linecap: round;
}

/* ---------- Buttons ---------- */
.button {
  display: inline-block;
  padding: 0.55rem 1.15rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.92rem;
  font-weight: 600;
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.button:hover { background: var(--accent-strong); color: var(--on-accent); transform: translateY(-1px); }

.button-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border-strong);
}
.button-ghost:hover { background: var(--bg-code); border-color: var(--accent); }

/* ---------- Sections on homepage ---------- */
.section { margin: 2.1rem 0; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.4rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
}
.section-head h2, .page-head h1 { font-size: 1.45rem; margin: 0; }

.see-all { font-size: 0.9rem; font-weight: 500; white-space: nowrap; }

/* ---------- Cards ---------- */
.card-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
  padding: 0;
  margin: 0;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 1.05rem 1.15rem;
  box-shadow: var(--shadow-card);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--border-strong);
}

.card a { color: inherit; display: block; height: 100%; }
.card h4 { margin: 0 0 0.35rem; font-size: 1rem; }
.card:hover h4 { color: var(--accent); }
.card p { margin: 0; font-size: 0.88rem; color: var(--text-secondary); }

/* ---------- Entry list (section index pages) ---------- */
.page-head { margin: 0 0 2rem; }
.page-head p { margin: 0.4rem 0 0; color: var(--text-secondary); }

.entry-list { list-style: none; padding: 0; margin: 0; }

.entry {
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--border);
}
.entry:last-child { border-bottom: none; }

.entry-title {
  display: inline-block;
  font-size: 1.08rem;
  font-weight: 650;
  color: var(--text);
}
.entry-title:hover { color: var(--accent); }

.entry-summary { margin: 0.35rem 0 0.4rem; color: var(--text-secondary); font-size: 0.94rem; }

.entry-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }

.entry-date { font-size: 0.82rem; color: var(--text-tertiary); }

.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag {
  padding: 0.1rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.empty { color: var(--text-tertiary); font-style: italic; }

/* ---------- Journal-style list (thoughts on home) ---------- */
.journal-list { list-style: none; padding: 0; margin: 0; }
.journal-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px dashed var(--border);
}
.journal-list li:last-child { border-bottom: none; }
.journal-list a { color: var(--text); }
.journal-list a:hover { color: var(--accent); }
.journal-list time { color: var(--text-tertiary); font-size: 0.85rem; white-space: nowrap; }

/* ==========================================================================
   Prose — article typography
   ========================================================================== */
.prose h1 { font-size: 1.9rem; margin: 0 0 1rem; }
.prose h2 { font-size: 1.35rem; margin: 2rem 0 0.6rem; }
.prose h3 { font-size: 1.12rem; margin: 1.6rem 0 0.5rem; }
.prose a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
}
.prose a:hover { color: var(--accent-strong); text-decoration-color: currentColor; }

/* 正文链接样式不得泄漏到界面组件上
   （.prose a 的 color:inherit / 下划线优先级高于组件类，会盖掉按钮等自身配色） */
.prose .button,
.prose .button:hover { color: var(--on-accent); }

.prose .button-ghost,
.prose .button-ghost:hover { color: var(--accent); }

.prose .entry-title { color: var(--text); }
.prose .entry-title:hover { color: var(--accent); }

.prose .see-all { color: var(--accent); }
.prose .see-all:hover { color: var(--accent-strong); }

.prose .journal-list a { color: var(--text); }
.prose .journal-list a:hover { color: var(--accent); }

.prose .button,
.prose .entry-title,
.prose .see-all,
.prose .card a,
.prose .journal-list a,
.prose .subtitle-return {
  text-decoration: none;
}
.prose p { margin: 0 0 1rem; }
.prose li { margin-bottom: 0.35rem; }
.prose blockquote {
  margin: 1.4rem 0;
  padding: 0.35rem 1.1rem;
  border-left: 3px solid var(--text);
  color: var(--text-secondary);
  background: var(--bg-code);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.prose blockquote p { margin: 0.4rem 0; }
.prose code {
  padding: 0.15em 0.4em;
  border-radius: 5px;
  background: var(--bg-code);
  font-size: 0.88em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.prose pre {
  padding: 1rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-code);
  overflow-x: auto;
  line-height: 1.5;
}
.prose pre code { padding: 0; background: transparent; font-size: 0.86rem; }
.prose img { max-width: 100%; border-radius: var(--radius); }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 2.2rem 0; }
.prose table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.prose th, .prose td { padding: 0.5rem 0.75rem; border: 1px solid var(--border); text-align: left; }
.prose th { background: var(--bg-code); font-weight: 600; }

.article-meta { margin: 0 0 1.5rem; color: var(--text-tertiary); font-size: 0.88rem; }

/* ---------- Post header / footer ---------- */
.post-head { margin-bottom: 2rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.post-title { font-size: clamp(1.7rem, 4vw, 2.3rem); font-weight: 750; margin: 0 0 0.7rem; }
.post-meta { margin: 0; }
.article-back { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 0.92rem; }

/* ==========================================================================
   Reading progress bar
   ========================================================================== */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--text);
  z-index: 200;
  transition: width 0.1s linear;
}

/* ==========================================================================
   Profile header (al-folio style: name, meta line, photo + bio)
   ========================================================================== */
.profile { padding: 1.6rem 0 0; }

.profile-name {
  margin: 0 0 1.1rem;
  font-size: clamp(1.9rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.12;
}

.profile-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 236px;
  gap: 2rem;
  align-items: center;
}

.profile-photo { margin: 0; max-width: 236px; }
.profile-photo img {
  display: block;
  width: 100%;
  /* 竖版人像比例，与原图一致，避免裁切；换图后如需方形改回 1 / 1 并调 object-position */
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: center 20%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  background: var(--bg-card);
}

.profile-bio { max-width: 36em; }
.profile-bio > p {
  margin: 0 0 1.1rem;
  font-size: 1.02rem;
  line-height: 1.68;
  color: var(--text-secondary);
}
.profile-bio > p strong, .profile-bio > p b { color: var(--text); font-weight: 650; }

.profile-links { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1rem 0 0; }
.profile-links .button { padding: 0.5rem 1rem; font-size: 0.88rem; }

/* ==========================================================================
   Date-aligned entry table
   ========================================================================== */
.entry-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.entry-table tr { border-bottom: 1px solid var(--border); }
.entry-table tbody tr:last-child { border-bottom: none; }

.entry-table-date {
  width: 8.2rem;
  padding: 0.62rem 1rem 0.62rem 0;
  vertical-align: baseline;
  text-align: left;
  font-size: 0.83rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.entry-table-body { padding: 0.62rem 0; vertical-align: baseline; line-height: 1.55; }

.prose a.entry-table-title {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.prose a.entry-table-title:hover { color: var(--accent); }

.entry-table-summary {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

/* ---------- Link icon buttons ----------
   类名刻意不含 social/share/icon，避免被广告拦截规则误隐藏 */
.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 1.25rem 0 0;
}

.prose a.link-btn {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}
.prose a.link-btn:hover {
  color: var(--text);
  border-color: var(--text);
  background: var(--bg-code);
  transform: translateY(-1px);
}
.link-btn svg { width: 1.15rem; height: 1.15rem; }
.link-btn-text { font-size: 0.85rem; padding: 0 0.5rem; }

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.4rem 0 1.5rem;
  font-size: 0.83rem;
  color: var(--text-tertiary);
}
.site-footer a { color: var(--text-secondary); }
.site-footer a:hover { color: var(--text); }

/* 页脚与正文同宽（正文 740px / 首页 920px），左右缘完全对齐 */
.footer-inner { max-width: var(--reading); }
.footer-inner.main-content-wide { max-width: 920px; }

/* 底部两栏：左 © + 关于，右技术信息；窄屏自动换行 */
/* 短线代替通栏分割线，与左对齐的短文字呼应，避免长线割裂 */
.footer-rule {
  width: 2.75rem;
  border-top: 1px solid var(--border-strong);
  margin: 0 0 0.7rem;
}
.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.15rem 1rem;
}
.footer-copy { margin: 0; text-align: left; }
.footer-tech { margin: 0; font-size: 0.78rem; color: var(--text-tertiary); }

/* 回到顶部按钮（滚动后出现） */
.back-to-top {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 150;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s, color 0.15s ease, border-color 0.15s ease;
}
.back-to-top.is-visible { opacity: 1; visibility: visible; transform: none; }
.back-to-top:hover { color: var(--text); border-color: var(--text); background: var(--bg-code); }
.back-to-top svg { width: 1.05rem; height: 1.05rem; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 700px) {
  .header-inner { padding-top: 0.6rem; padding-bottom: 0.45rem; row-gap: 0.5rem; }
  .site-nav { order: 3; flex-basis: 100%; justify-content: flex-start; margin-left: -0.65rem; }
  .main-content { padding-top: 1.8rem; }
  .hero { padding-top: 1.5rem; }
  .journal-list li { flex-direction: column; gap: 0.1rem; }

  /* 资料块与日期列表在窄屏改为堆叠 */
  .profile { padding-top: 1.25rem; }
  .profile-body { grid-template-columns: 1fr; gap: 1.35rem; }
  .profile-photo { order: -1; max-width: 190px; }

  .entry-table tr { display: block; padding: 0.7rem 0; }
  .entry-table-date { display: block; width: auto; padding: 0 0 0.15rem; }
  .entry-table-body { display: block; padding: 0; }

  /* 回到顶部按钮在小屏收紧 */
  .back-to-top { right: 1rem; bottom: 1rem; width: 2.4rem; height: 2.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}
