
/* ---------- 设计变量 ---------- */
:root {
  --paper: #fbf9f5;
  --paper-2: #f4f0e8;
  --paper-3: #efeadf;
  --ink: #1b1916;
  --ink-2: #3d3830;
  --muted: #6f675b;
  --line: #e3dccf;
  --line-strong: #d3c9b7;
  --accent: #9c3b2e;
  --accent-2: #c0604f;
  --accent-soft: #f6e9e5;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(27,25,22,.05);
  --shadow: 0 2px 4px rgba(27,25,22,.04), 0 10px 28px rgba(27,25,22,.07);
  --serif: "Songti SC", "Source Han Serif SC", "Noto Serif SC", "Noto Serif CJK SC", "SimSun", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --max: 1080px;
  --read: 760px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15140f;
    --paper-2: #1c1a14;
    --paper-3: #232019;
    --ink: #ece7dc;
    --ink-2: #d3ccbe;
    --muted: #9a9184;
    --line: #2c2820;
    --line-strong: #3b3428;
    --accent: #d0705f;
    --accent-2: #e08a79;
    --accent-soft: #2a1d19;
    --shadow: 0 2px 4px rgba(0,0,0,.3), 0 10px 28px rgba(0,0,0,.35);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  }
}

/* 手动切换（页头 ☾/☀）：data-theme 优先于系统偏好 */
:root[data-theme="dark"] {
  --paper: #15140f;
  --paper-2: #1c1a14;
  --paper-3: #232019;
  --ink: #ece7dc;
  --ink-2: #d3ccbe;
  --muted: #9a9184;
  --line: #2c2820;
  --line-strong: #3b3428;
  --accent: #d0705f;
  --accent-2: #e08a79;
  --accent-soft: #2a1d19;
  --shadow: 0 2px 4px rgba(0,0,0,.3), 0 10px 28px rgba(0,0,0,.35);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.75 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- 骨架 ---------- */
.wrap { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 24px; }
.wrap--read { max-width: var(--read); }
.read { max-width: var(--read); margin: 0 auto; }
.admin-line { margin: 14px 0 0; font-size: 13.5px; }
.admin-line:empty { display: none; }

main.wrap { padding-top: 40px; padding-bottom: 72px; flex: 1 0 auto; }

/* 主题开关 */
.theme-toggle {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--paper-2);
  color: var(--ink-2);
  cursor: pointer;
  flex: none;
  transition: border-color .15s, color .15s, background .15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--paper); }

/* ---------- 页头 ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .site-header { background: var(--paper); }
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink);
  text-decoration: none;
  flex: none;
}
.brand:hover { color: var(--ink); }

.seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1;
  letter-spacing: 0;
  box-shadow: var(--shadow-sm);
}

.nav {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 14.5px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}
.nav a {
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.nav a:hover { color: var(--ink); border-bottom-color: var(--accent); }

.header-tools { display: flex; align-items: center; gap: 14px; flex: none; }

/* 搜索框（页头紧凑版 / 首页大版共用基础样式） */
.search { display: flex; align-items: center; margin: 0; }
.search input[type="search"], .search input[name="q"] {
  width: 200px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: width .2s, border-color .15s, box-shadow .15s, background .15s;
}
.search input[name="q"]:focus {
  width: 260px;
  background: var(--paper);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search button { display: none; }

.user {
  font-size: 14px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.user a { color: var(--ink); text-decoration: none; }
.user a:hover { color: var(--accent); }

/* ---------- 首页 hero ---------- */
.hero {
  padding: 56px 0 44px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 40px;
}
.eyebrow {
  margin: 0 0 14px;
  font-size: 12.5px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
.hero h1 {
  margin: 0 0 18px;
  font-family: var(--serif);
  font-size: clamp(30px, 4.4vw, 46px);
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: .01em;
  max-width: 20em;
}
.hero .lede {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 16.5px;
  max-width: 34em;
}
.hero-search { display: flex; gap: 10px; max-width: 560px; margin: 0; }
.hero-search input[name="q"] {
  flex: 1 1 auto;
  height: 50px;
  padding: 0 20px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.hero-search input[name="q"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.hero-search button {
  flex: none;
  height: 50px;
  padding: 0 26px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.hero-search button:hover { background: var(--accent); }
.hero-search button:active { transform: translateY(1px); }
.hero-stats {
  margin: 22px 0 0;
  font-size: 13.5px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}
.hero-stats span::before {
  content: "";
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 8px;
  vertical-align: middle;
  opacity: .7;
}

/* ---------- 区块标题 ---------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 18px;
}
.section-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: .02em;
}
.section-head .more { font-size: 13.5px; color: var(--muted); text-decoration: none; }
.section-head .more:hover { color: var(--accent); }

/* ---------- 卡片索引 ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.card {
  position: relative;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--line-strong);
}
.card::before {
  content: "";
  position: absolute;
  left: 0; top: 14px; bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  opacity: 0;
  transition: opacity .16s;
}
.card:hover::before { opacity: 1; }
.card a {
  display: block;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.45;
  font-weight: 600;
}
.card a:hover { color: var(--accent); }
.card .card-sub {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- 阅读页 ---------- */
.entry-head {
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 30px;
}
.entry-head h1 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: clamp(28px, 3.6vw, 40px);
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: .01em;
}
.entry-meta {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: center;
}
.entry-meta a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dashed var(--line-strong);
}
.entry-meta a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.entry-meta span a { margin-right: 8px; }
.entry-meta span + span::before {
  content: "";
  display: inline-block;
  width: 1px; height: 11px;
  background: var(--line-strong);
  margin-right: 12px;
  vertical-align: -1px;
}

.prose { font-size: 16.5px; line-height: 1.9; color: var(--ink-2); }
.prose > *:first-child { margin-top: 0; }
.prose h2 {
  margin: 2.2em 0 .8em;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--ink);
}
.prose h3 {
  margin: 1.8em 0 .6em;
  font-family: var(--serif);
  font-size: 18.5px;
  color: var(--ink);
}
.prose p { margin: 0 0 1.15em; }
.prose a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  transition: border-color .15s, color .15s;
}
.prose a:hover { border-bottom-color: var(--accent); }
.prose ul, .prose ol { margin: 0 0 1.2em; padding-left: 1.4em; }
.prose li { margin: .35em 0; }
.prose blockquote {
  margin: 1.6em 0;
  padding: 14px 20px;
  border-left: 3px solid var(--line-strong);
  background: var(--paper-2);
  border-radius: 0 10px 10px 0;
  color: var(--muted);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code {
  font-family: var(--mono);
  font-size: .9em;
  padding: .15em .42em;
  border-radius: 5px;
  background: var(--paper-3);
  color: var(--accent);
}
.prose pre {
  margin: 1.4em 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-2);
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.7;
}
.prose pre code { background: none; padding: 0; color: var(--ink); }
.prose img { max-width: 100%; height: auto; border-radius: 10px; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.2em 0; }
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
  font-size: 14.5px;
}
.prose th, .prose td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.prose th { color: var(--ink); font-weight: 600; background: var(--paper-2); }

/* 内联双链解析失败（红链）的视觉：由 render 层输出 a 标签，这里不加特殊处理 */

/* ---------- 面板（反链 / 提示） ---------- */
.panel {
  margin: 44px 0 0;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
}
.panel h2 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  border: 0;
  padding: 0;
}
.panel ul { margin: 0; padding-left: 1.2em; }
.panel li { margin: .3em 0; font-size: 14.5px; }
.panel a { color: var(--accent); text-decoration: none; }
.panel a:hover { text-decoration: underline; }

/* ---------- 操作行 ---------- */
.actions {
  margin: 36px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--muted);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.actions a { color: var(--muted); text-decoration: none; }
.actions a:hover { color: var(--accent); }

/* ---------- 搜索结果 ---------- */
.result-list { list-style: none; margin: 26px 0 0; padding: 0; }
.result-list li {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.result-list li:first-child { border-top: 1px solid var(--line); }
.result-list .result-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}
.result-list .result-title:hover { color: var(--accent); }
.result-list .snippet {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}
.result-list .snippet u { text-decoration: none; background: var(--accent-soft); color: var(--accent); border-radius: 3px; padding: 0 2px; }

/* ---------- 时间轴 ---------- */
.tl-shell {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  padding: 10px;
  overflow: hidden;
}
.tl-shell canvas { display: block; width: 100%; height: 440px; touch-action: none; border-radius: 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 12px 0 0; }

/* ---------- 表单一族 ---------- */
input[type="text"], input:not([type]), input[type="password"], input[type="search"], textarea, select {
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus, input:not([type]):focus, input[type="password"]:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { width: 100%; line-height: 1.7; resize: vertical; }
button, .btn {
  font: inherit;
  font-size: 14.5px;
  padding: 9px 18px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
button:hover { background: var(--accent); border-color: var(--accent); }
button:active { transform: translateY(1px); }
.md-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; }
.md-toolbar button {
  background: var(--paper-2);
  color: var(--ink-2);
  border: 1px solid var(--line-strong);
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 8px;
}
.md-toolbar button:hover { background: var(--paper-3); border-color: var(--accent); color: var(--accent); }

/* ---------- 通用排版 ---------- */
h1 {
  font-family: var(--serif);
  font-size: clamp(26px, 3.2vw, 34px);
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: .01em;
  margin: 0 0 18px;
}
h2 {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  margin: 40px 0 14px;
}
p { margin: 0 0 1em; }
ul, ol { padding-left: 1.35em; }
li { margin: .3em 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-2); }
small { font-size: 13px; color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--paper-3);
  padding: .12em .4em;
  border-radius: 5px;
}
pre {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  overflow-x: auto;
}
pre code { background: none; padding: 0; }
table { width: 100%; border-collapse: collapse; margin: 1.2em 0; font-size: 14.5px; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--paper-2); font-weight: 600; }

/* diff 视图（审核页） */
.diff-add { background: color-mix(in srgb, #2e7d32 12%, transparent); }
.diff-del { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ---------- 登录卡片 ---------- */
.auth {
  max-width: 380px;
  margin: 56px auto 0;
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
}
.auth h1 { margin: 0 0 8px; font-size: 26px; }
.auth-sub { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-form input { width: 100%; }
.auth-form button { width: 100%; margin-top: 4px; }

/* ---------- 页脚 ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--paper-2);
  padding: 30px 0 40px;
  font-size: 13px;
  color: var(--muted);
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  align-items: center;
  justify-content: space-between;
}
.site-footer a { color: var(--muted); text-decoration: none; border-bottom: 1px solid transparent; }
.site-footer a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.footer-links { display: flex; flex-wrap: wrap; gap: 18px; }

/* ---------- 空态 ---------- */
.empty {
  padding: 48px 0;
  text-align: center;
  color: var(--muted);
}
.empty strong { display: block; font-family: var(--serif); font-size: 18px; color: var(--ink); margin-bottom: 6px; }

/* ---------- 焦点可见性 ---------- */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .nav { display: none; }
  .search input[name="q"] { width: 150px; }
  .search input[name="q"]:focus { width: 180px; }
}
@media (max-width: 640px) {
  .wrap { padding: 0 18px; }
  .header-inner { height: 58px; gap: 12px; }
  .brand { font-size: 18px; }
  .seal { width: 26px; height: 26px; font-size: 15px; }
  .search input[name="q"] { width: 120px; }
  .hero { padding: 34px 0 30px; }
  .hero-search { flex-direction: column; }
  .hero-search button { width: 100%; }
  .card-grid { grid-template-columns: 1fr; }
  .tl-shell canvas { height: 320px; }
}

@media print {
  .site-header, .site-footer, .actions, .hero-search { display: none; }
  body { background: #fff; }
}
