/* ============================================================
   Foliate v2 — 现代编辑排版
   ============================================================ */

/* ---------- 设计变量 ---------- */
:root {
  --bg: #faf9f6;
  --bg-card: #ffffff;
  --bg-code: #f5f3ee;
  --text: #1a1814;
  --text-2: #5c5850;
  --text-3: #9a958a;
  --border: #e8e4db;
  --accent: #9a3412;
  --accent-hover: #7c2d12;
  --selection: #9a3412;
  --shadow: 0 1px 3px rgba(26,24,20,.05), 0 1px 2px rgba(26,24,20,.03);
  --shadow-lg: 0 10px 30px rgba(26,24,20,.08), 0 3px 8px rgba(26,24,20,.04);
  --radius: 10px;
  --radius-sm: 6px;
  --measure: 65ch;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --font-serif: "Source Han Serif SC", "Noto Serif CJK SC", "Songti SC", "Noto Serif SC", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --transition: 180ms cubic-bezier(.4, 0, .2, 1);
}

[data-theme="dark"] {
  --bg: #131210;
  --bg-card: #1c1b18;
  --bg-code: #222019;
  --text: #e8e4dc;
  --text-2: #a8a39a;
  --text-3: #6e6a62;
  --border: #2e2c26;
  --accent: #c2693a;
  --accent-hover: #d97706;
  --selection: #c2693a;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.4);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }

::selection { background: var(--selection); color: #fff; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ---------- 容器 ---------- */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- 进度条 ---------- */
.progress-bar {
  position: fixed; top: 0; left: 0; height: 2px;
  width: 0; background: var(--accent);
  z-index: 100; transition: width 80ms linear;
}

/* ---------- 顶栏 ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; gap: 24px;
}
.brand {
  display: flex; flex-direction: column; line-height: 1.2;
  color: var(--text); text-decoration: none;
  flex-shrink: 0;
}
.brand-name {
  font-family: var(--font-serif);
  font-weight: 700; font-size: 1.25rem; letter-spacing: -.01em;
}
.brand-sub { font-size: .75rem; color: var(--text-3); margin-top: 3px; font-weight: 400; }
.header-right {
  display: flex; align-items: center; gap: 20px;
  margin-left: auto;
}
.nav { display: flex; gap: 24px; }
.nav a {
  color: var(--text-2); font-size: .9rem; font-weight: 450;
  position: relative; padding: 4px 0;
}
.nav a:hover { color: var(--text); }
.nav a::after {
  content: ''; position: absolute; bottom: 0; left: 0;
  width: 0; height: 1.5px; background: var(--accent);
  transition: width var(--transition);
}
.nav a:hover::after { width: 100%; }
.actions { display: flex; gap: 2px; align-items: center; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--bg-code); color: var(--text); }
#menu-toggle { display: none; }

/* 暗色切换图标 */
.icon-sun, .icon-moon { display: none; }
[data-theme="light"] .icon-moon { display: inline-flex; }
[data-theme="dark"] .icon-sun { display: inline-flex; }

/* ---------- 搜索 overlay ---------- */
.search-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 16vh 24px 0;
}
.search-overlay[hidden] { display: none; }
.search-overlay form { position: relative; width: 100%; max-width: 640px; }
.search-overlay input {
  width: 100%; padding: 20px 56px 20px 24px;
  font-size: 1.15rem; font-family: var(--font-serif);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  box-shadow: var(--shadow-lg);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-overlay input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent); }
.search-close {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-size: 1.6rem; color: var(--text-3); width: 36px; height: 36px;
}

/* ---------- 首页 Hero / 列表头 ---------- */
.list-layout { padding-top: 72px; padding-bottom: 96px; }
.list-header { margin-bottom: 56px; }
.list-title {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 1.5rem + 2vw, 2.75rem);
  margin: 0 0 12px; font-weight: 700; letter-spacing: -.02em;
  line-height: 1.15;
}
.list-desc { color: var(--text-3); margin: 0; font-size: 1rem; max-width: 50ch; }

/* ---------- 文章列表（网格：日期 | 内容） ---------- */
.post-list { display: flex; flex-direction: column; }
.post-item {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 32px;
  padding: 28px 0;
  border-bottom: 1px solid var(--border);
}
.post-item:first-child { padding-top: 0; }
.post-item-date {
  font-size: .82rem; color: var(--text-3);
  padding-top: 5px; line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.post-item-date .dot-sep { display: none; }
.post-item-body { min-width: 0; }
.post-item-title {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 1.35rem; font-weight: 600; line-height: 1.35;
  letter-spacing: -.005em;
}
.post-item-title a {
  color: var(--text);
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: 0% 1.5px; background-repeat: no-repeat; background-position: 0 100%;
  transition: background-size var(--transition), color var(--transition);
}
.post-item-title a:hover { color: var(--accent); background-size: 100% 1.5px; }
.post-item-excerpt { margin: 0; color: var(--text-2); font-size: .93rem; line-height: 1.7; }
.post-item-meta {
  font-size: .8rem; color: var(--text-3);
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.post-item-meta a { color: var(--text-3); }
.post-item-meta a:hover { color: var(--accent); }

/* ---------- 分页 ---------- */
.pagination, .page-navigator {
  margin-top: 56px; display: flex; justify-content: center;
  gap: 4px; list-style: none; padding: 0;
}
.pagination a, .pagination span,
.page-navigator a, .page-navigator span,
.page-navigator li {
  list-style: none;
  padding: 7px 14px; border-radius: var(--radius-sm);
  font-size: .88rem; color: var(--text-2);
  transition: background var(--transition);
  white-space: nowrap;
}
.pagination a:hover, .page-navigator a:hover { background: var(--bg-code); color: var(--text); }
.page-navigator .current, .pagination .current {
  background: var(--text); color: var(--bg); font-weight: 500;
}
.page-navigator .current span { background: var(--text); color: var(--bg); }
.page-navigator .next, .page-navigator .prev { color: var(--text-2); }

/* ---------- 文章页 ---------- */
.post-layout {
  padding-top: 64px;
  padding-bottom: 80px;
}
.post { min-width: 0; }
.post-header { margin-bottom: 40px; }
.breadcrumb {
  font-size: .8rem; color: var(--text-3); margin-bottom: 20px;
  display: flex; align-items: center; gap: 4px;
}
.breadcrumb .sep { margin: 0 6px; color: var(--border); }
.breadcrumb a { color: var(--text-3); }
.breadcrumb a:hover { color: var(--text); }
.post-title {
  font-family: var(--font-serif);
  font-size: clamp(1.9rem, 1.4rem + 1.8vw, 2.6rem);
  line-height: 1.2; margin: 0 0 20px;
  letter-spacing: -.015em; font-weight: 700;
}
.post-meta {
  font-size: .85rem; color: var(--text-3);
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}
.post-meta .dot { color: var(--border); }
.post-meta a { color: var(--text-3); }
.post-meta a:hover { color: var(--accent); }

/* 正文排版 */
.post-content {
  font-size: 1.0625rem;
  line-height: 1.85;
  color: var(--text);
  word-break: break-all;
}
.post-content > * + * { margin-top: 1.2em; }
.post-content h2, .post-content h3 {
  font-family: var(--font-serif);
  line-height: 1.35; margin-top: 2em; letter-spacing: -.01em;
}
.post-content h2 {
  font-size: 1.5rem; padding-bottom: .4em;
  border-bottom: 1px solid var(--border);
}
.post-content h3 { font-size: 1.2rem; }
.post-content p { margin: 0 0 0.5rem; }
.post-content a {
  color: var(--accent);
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: 100% 1px; background-repeat: no-repeat; background-position: 0 100%;
  transition: background-size var(--transition);
  padding-bottom: 1px;
}
.post-content a:hover { background-size: 100% 2px; }

/* 锚点 # */
.post-content .sec-anchor {
  display: inline-block; width: 1em; margin-left: -1em;
  opacity: 0; color: var(--text-3); font-weight: 400;
  transition: opacity var(--transition); background: none !important;
}
.post-content h2:hover .sec-anchor, .post-content h3:hover .sec-anchor { opacity: 1; }

/* 引用 */
.post-content blockquote {
  margin: 2em 0; padding: 8px 0 8px 24px;
  border-left: 3px solid var(--accent);
  color: var(--text-2); font-style: normal;
}
.post-content blockquote p { margin: .5em 0; }

/* 列表 */
.post-content ul, .post-content ol { padding-left: 1.5em; }
.post-content li { margin: .4em 0; }

/* 图片 */
.post-content img {
  border-radius: var(--radius); margin: 2em auto;
  cursor: zoom-in;
  box-shadow: var(--shadow);
}

/* 行内代码 */
.post-content code {
  font-family: var(--font-mono); font-size: .86em;
  background: var(--bg-code); padding: 2px 7px; border-radius: 4px;
}

/* 代码块 */
.post-content pre {
  background: var(--bg-code);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: .85rem;
  line-height: 1.7;
  position: relative;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-all;
  overflow-wrap: break-word;
}
.post-content pre code { background: none; padding: 0; font-size: inherit; color: inherit; }
.code-block { position: relative; }
.code-toolbar {
  position: absolute; top: 10px; right: 10px;
  display: flex; gap: 6px; opacity: 0;
  transition: opacity var(--transition);
}
.code-block:hover .code-toolbar { opacity: 1; }
.code-copy {
  font-size: .75rem; padding: 4px 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-2);
  box-shadow: var(--shadow);
}
.code-copy:hover { color: var(--text); }

/* 标签 */
.post-tags {
  margin-top: 48px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}
.post-tags a {
  font-size: .85rem; color: var(--text-3);
  transition: color var(--transition);
}
.post-tags a::before {
  content: '#'; color: var(--text-3); margin-right: 2px;
}
.post-tags a:hover { color: var(--accent); }

/* 上/下一篇 */
.post-nav {
  margin-top: 56px; padding-top: 28px; padding-bottom: 32px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 16px;
  font-size: .9rem;
}
.post-nav .prev, .post-nav .next { max-width: 48%; }
.post-nav .next { text-align: right; }
.post-nav a { color: var(--text-2); font-weight: 500; }
.post-nav a:hover { color: var(--accent); }
.post-nav .none { color: var(--text-3); }

/* ---------- TOC（窄容器，不显示侧边目录） ---------- */
.post-toc { display: none; }
.toc-title {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--text-3); margin-bottom: 14px; font-weight: 600;
}
.post-toc ul { list-style: none; padding: 0; margin: 0; border-left: 1px solid var(--border); }
.post-toc li { margin: 0; }
.post-toc a {
  display: block; padding: 5px 0 5px 16px;
  color: var(--text-3); border-left: 2px solid transparent;
  margin-left: -1px;
  transition: color var(--transition), border-color var(--transition);
}
.post-toc a:hover { color: var(--text); }
.post-toc a.active { color: var(--accent); border-left-color: var(--accent); }
.post-toc .toc-l3 a { padding-left: 28px; font-size: .8rem; }

/* ---------- 评论 ---------- */
.comments-layout { padding-top: 64px; padding-bottom: 96px; border-top: 1px solid var(--border); }
.comments-title {
  font-family: var(--font-serif);
  font-size: 1.3rem; margin: 0 0 28px; font-weight: 600;
}
.comment-list { list-style: none; padding: 0; margin: 0 0 36px; }
.comment-item { padding: 20px 0; border-bottom: 1px solid var(--border); }
.comment-head { display: flex; gap: 12px; align-items: baseline; margin-bottom: 6px; }
.comment-author { font-weight: 600; font-size: .92rem; }
.comment-head time { font-size: .78rem; color: var(--text-3); }
.comment-content { color: var(--text-2); font-size: .95rem; }
.comment-actions { margin-top: 8px; }
.comment-actions a { font-size: .8rem; color: var(--text-3); }
.comment-actions a:hover { color: var(--accent); }
.comment-children {
  list-style: none; padding-left: 24px; margin-top: 12px;
  border-left: 1px solid var(--border);
}

.respond { margin-top: 36px; }
.respond-title { font-family: var(--font-serif); font-size: 1.1rem; margin: 0 0 18px; }
.login-tip { font-size: .85rem; color: var(--text-3); }
.comment-form .form-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 12px; margin-bottom: 12px;
}
.comment-form input, .comment-form textarea {
  width: 100%; padding: 11px 15px;
  background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: none; transition: border-color var(--transition), box-shadow var(--transition);
}
.comment-form input:focus, .comment-form textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}
.comment-form textarea { resize: vertical; min-height: 120px; }
.form-foot { display: flex; align-items: center; gap: 16px; margin-top: 14px; }
.comments-closed { color: var(--text-3); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block; padding: 10px 22px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius-sm); font-size: .9rem; font-weight: 500;
  transition: opacity var(--transition);
}
.btn:hover { opacity: .85; color: var(--bg); }

/* ---------- 页脚 ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 40px 0; margin-top: 60px;
  font-size: .82rem; color: var(--text-3);
}
.footer-inner { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.footer-links { display: flex; gap: 20px; align-items: center; }
.footer-links a { color: var(--text-3); display: inline-flex; align-items: center; gap: 5px; }
.footer-links a:hover { color: var(--text); }

/* ---------- 灯箱 ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  padding: 40px; cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 4px; }
.lightbox-close {
  position: absolute; top: 20px; right: 24px;
  color: #fff; font-size: 2rem; line-height: 1;
}

/* ---------- 空态 / 404 ---------- */
.empty, .error-layout {
  text-align: center; padding: 100px 0; color: var(--text-3);
}
.error-code {
  font-family: var(--font-serif);
  font-size: 7rem; font-weight: 700; color: var(--text);
  line-height: 1; letter-spacing: -.04em;
}
.error-text { font-family: var(--font-serif); font-size: 1.2rem; color: var(--text); margin: 20px 0 6px; }
.error-sub { margin: 0 0 28px; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .post-layout { grid-template-columns: 1fr; gap: 0; }
  .post-toc { display: none; }
  .header-inner { gap: 12px; }
  .brand-sub { display: none; }
  .header-right { gap: 8px; }
  #menu-toggle { display: inline-flex; }
  .nav {
    display: none;
    position: absolute; top: 64px; left: 0; right: 0;
    flex-direction: column; gap: 0; flex: none;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
    box-shadow: var(--shadow-lg);
  }
  .nav.open { display: flex; }
  .nav a { padding: 12px 24px; font-size: .95rem; }
  .nav a::after { display: none; }
}
@media (max-width: 640px) {
  .container { padding: 0 20px; }
  .post-layout { padding-top: 32px; }
  .list-layout { padding-top: 48px; }
  .post-item { grid-template-columns: 1fr; gap: 6px; padding: 24px 0; }
  .post-item-date { padding-top: 0; }
  .post-nav { flex-direction: column; gap: 14px; }
  .post-nav .prev, .post-nav .next { max-width: 100%; text-align: left; }
  .comment-form .form-row { grid-template-columns: 1fr; }
  .footer-inner { flex-direction: column; gap: 10px; }
  .footer-links { flex-wrap: wrap; gap: 8px 16px; }
  .pagination, .page-navigator { flex-wrap: wrap; gap: 2px; }
  .pagination a, .pagination span,
  .page-navigator a, .page-navigator span,
  .page-navigator li { padding: 6px 10px; font-size: .82rem; }
}

/* ---------- 语法高亮：统一颜色，不区分 token ---------- */
.tok-comment, .tok-string, .tok-number, .tok-keyword, .tok-fn {
  color: inherit; font-weight: normal; font-style: normal;
}

/* ---------- 打印 ---------- */
@media print {
  .site-header, .site-footer, .post-toc, .post-nav, .code-toolbar,
  .progress-bar, .lightbox, .line-gutter, .search-overlay { display: none !important; }
  body { background: #fff; color: #000; }
  a { color: #000; text-decoration: underline; }
  .post-content { max-width: 100%; }
}
