/* 单文件主题：零图片、系统字体栈；四套配色 + auto 跟随系统。
   data-theme 由 <head> 极小的内联脚本在 CSS 之前写入，避免闪烁。 */
:root,
:root[data-theme="light"],
:root[data-theme="auto"] {
  --bg: #fbfbfa;
  --bg-elevated: #ffffff;
  --text: #383d42;
  --text-muted: #5b6673;
  --text-disabled: #6b7581;
  --border: #e3e6ea;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --link: #1d4ed8;
  --code-bg: #f4f6f8;
  --code-text: #1f2328;
  --danger: #d1242f;
  --warning: #b45309;
  --success: #1a7f37;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #12161c;
  --bg-elevated: #1a2029;
  --text: #c3c9d2;
  --text-muted: #a3adbb;
  --text-disabled: #616c7a;
  --border: #5e6d82;
  --accent: #8ab4ff;
  --accent-soft: rgba(138, 180, 255, 0.16);
  --link: #a7c5ff;
  --code-bg: #171d25;
  --code-text: #e5e9f0;
  --danger: #ff8f8f;
  --warning: #e5b567;
  --success: #7ee2a8;
  --shadow: none;
  color-scheme: dark;
}

:root[data-theme="eye"] {
  --bg: #f7f0e1;
  --bg-elevated: #fdf8ee;
  --text: #3b342a;
  --text-muted: #6b5f4e;
  --text-disabled: #726757;
  --border: #e2d6bf;
  --accent: #8a4b0f;
  --accent-soft: rgba(138, 75, 15, 0.12);
  --link: #8a4b0f;
  --code-bg: #efe5d2;
  --code-text: #3b342a;
  --danger: #a83232;
  --warning: #8a5a00;
  --success: #3f6b2f;
  --shadow: 0 1px 2px rgba(93, 74, 40, 0.06);
  color-scheme: light;
}

:root[data-theme="vivid"] {
  --bg: #f7f3ff;
  --bg-elevated: #ffffff;
  --text: #3a3054;
  --text-muted: #5f5578;
  --text-disabled: #756b8e;
  --border: #ded4f0;
  --accent: #a21caf;
  --accent-soft: linear-gradient(120deg, rgba(236, 72, 153, 0.14), rgba(59, 130, 246, 0.14));
  --link: #86198f;
  --code-bg: #f0eaff;
  --code-text: #241b3a;
  --danger: #c0243d;
  --warning: #8a5306;
  --success: #0f6b33;
  --shadow: 0 2px 10px rgba(120, 60, 200, 0.08);
  color-scheme: light;
}

:root[data-theme="green"] {
  --bg: #eef5ec;
  --bg-elevated: #f7fbf5;
  --text: #2f3a2f;
  --text-muted: #55645a;
  --text-disabled: #7a897e;
  --border: #7b927f;
  --accent: #1f5f4a;
  --accent-soft: rgba(31, 95, 74, 0.12);
  --link: #1f5f4a;
  --code-bg: #dfe9db;
  --code-text: #263126;
  --danger: #a83232;
  --warning: #8a5306;
  --success: #1f6b3a;
  --shadow: 0 1px 2px rgba(47, 58, 47, 0.06);
  color-scheme: light;
}

/* auto：系统暗色时切换；显式主题块 specificity 更高，不受影响 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="eye"]):not([data-theme="vivid"]):not([data-theme="green"]) {
    --bg: #12161c;
    --bg-elevated: #1a2029;
    --text: #c3c9d2;
    --text-muted: #a3adbb;
    --text-disabled: #616c7a;
    --border: #5e6d82;
    --accent: #8ab4ff;
    --accent-soft: rgba(138, 180, 255, 0.16);
    --link: #a7c5ff;
    --code-bg: #171d25;
    --code-text: #e5e9f0;
    --danger: #ff8f8f;
    --warning: #e5b567;
    --success: #7ee2a8;
    --shadow: none;
    color-scheme: dark;
  }
}

:root {
  --radius: 12px;
  --wrap: 1080px;
  --measure: 70ch;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", "Helvetica Neue",
    Arial, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  text-rendering: optimizeLegibility;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { width: min(var(--wrap), 92vw); margin: 0 auto; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--bg-elevated);
  padding: 8px 12px;
  z-index: 20;
}
.skip-link:focus { left: 12px; top: 12px; }

/* ---------------------------------------------------------------- header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); flex: 0 0 auto; }

.nav {
  display: flex;
  gap: 16px;
  font-size: 14px;
  margin-right: auto;
}
.nav a { color: var(--text-muted); }
.nav a:hover { color: var(--text); text-decoration: none; }

.header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  row-gap: 6px;
  gap: 10px;
  font-size: 14px;
}
.ghost-link {
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font: inherit;
  cursor: pointer;
}
.ghost-link:hover { color: var(--text); border-color: var(--text-muted); text-decoration: none; }
.inline-form { margin: 0; }

/* 切换控件：无 JS 时整块隐藏（.js 由内联脚本在 CSS 之前加上） */
.theme-control { display: none; }
.js .theme-control { display: inline-block; }
.theme-select {
  font: inherit;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  max-width: 7.5em;
  cursor: pointer;
}

/* --------------------------------------------------------------- messages */
.messages {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.message {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--bg-elevated);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
}
.message.warning { border-left-color: var(--warning); }
.message.error { border-left-color: var(--danger); }
.message.success { border-left-color: var(--success); }

/* ---------------------------------------------------------------- sections */
.section { margin: 40px 0; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.section-title {
  font-size: 15px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin: 0;
}
.count { color: var(--text-muted); font-size: 13px; }

/* ------------------------------------------------------------------ cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(272px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }

.card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}
.pin { color: var(--warning); }

.card-title { font-size: 18px; line-height: 1.45; margin: 0; }
.card-title a { color: var(--text); }
.card-title a:hover { text-decoration: none; color: var(--accent); }
.card-summary { margin: 0; color: var(--text-muted); font-size: 14px; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.empty {
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 22px;
  color: var(--text-muted);
}

/* ----------------------------------------------------------------- paging */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 26px;
  font-size: 14px;
}
.pager .disabled { color: var(--text-disabled); }
.page-info { color: var(--text-muted); font-size: 13px; }

/* ---------------------------------------------------------------- article */
.article { padding: 28px 0 8px; }
.article-head {
  max-width: var(--measure);
  margin: 0 auto;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.breadcrumb .current { color: var(--text); }
.breadcrumb .sep { color: var(--border); }

.article-title {
  font-size: clamp(26px, 4vw, 34px);
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: 14px 0 10px;
}
.article-summary { color: var(--text-muted); font-size: 16px; margin: 0 0 14px; }

.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.article-meta time { font-variant-numeric: tabular-nums; }
.badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 12px;
}
.raw-link { font-size: 13px; }

.article-body {
  max-width: var(--measure);
  margin: 0 auto;
  padding-top: 8px;
  overflow-wrap: break-word;
}

/* 目录（渲染时拼进 body_html） */
.article-toc {
  margin: 22px 0 30px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  font-size: 14px;
}
.toc-title {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.article-toc ul { list-style: none; margin: 0; padding: 0; }
.article-toc li { margin: 3px 0; }
.article-toc li ul { padding-left: 1.1rem; }
.article-toc a { color: var(--text); }
.article-toc a:hover { color: var(--accent); }

/* ---------------------------------------------------------- prose styles */
.article-body h2,
.article-body h3,
.article-body h4 {
  line-height: 1.35;
  margin: 2em 0 0.6em;
  scroll-margin-top: 84px;
}
.article-body h2 { font-size: 1.4em; }
.article-body h3 { font-size: 1.2em; }
.article-body h4 { font-size: 1.05em; }

.article-body p { margin: 0 0 1.1em; }
.article-body ul,
.article-body ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.article-body li { margin: 0.3em 0; }

.article-body blockquote {
  margin: 1.4em 0;
  padding: 0.2em 1em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  color: var(--text);
}

.article-body code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  font-size: 0.9em;
  color: var(--code-text);
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
}

.article-body pre {
  overflow-x: auto;
  padding: 14px 16px;
  margin: 1.4em 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
  color: var(--code-text);
  font-size: 14px;
  line-height: 1.6;
}
.article-body pre code { background: none; padding: 0; font-size: inherit; }

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
  font-size: 14px;
  display: block;
  overflow-x: auto;
}
.article-body th,
.article-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.article-body th { background: var(--code-bg); font-weight: 600; }

.article-body hr {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: 2.2em 0;
}

.article-body .footnote-ref { font-size: 0.75em; vertical-align: super; }
.article-body .footnote {
  margin-top: 2.6em;
  border-top: 1px solid var(--border);
  padding-top: 1em;
  font-size: 0.9em;
  color: var(--text-muted);
}
.article-body .footnote ol { padding-left: 1.2em; }

/* ------------------------------------------------------------- auth/forms */
.page-title { font-size: 24px; margin: 32px 0 6px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

.auth,
.upload { max-width: 560px; }

.form { display: grid; gap: 14px; margin: 22px 0 10px; }
.field { display: grid; gap: 6px; margin: 0; font-size: 14px; }
.field label { color: var(--text-muted); }
.hint { color: var(--text-muted); font-size: 12px; }

.form input[type="text"],
.form input[type="password"],
.form input[type="file"] {
  font: inherit;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  width: 100%;
}
.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
}

.button {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-elevated);
  cursor: pointer;
}
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-elevated);
  justify-self: start;
}
.button:hover { text-decoration: none; opacity: 0.92; }

/* manage 落地页入口 */
.manage-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 18px 0;
}
.form .hint ul { margin: 4px 0 0; padding-left: 18px; }

.frontmatter-help {
  margin: 20px 0;
  font-size: 14px;
  color: var(--text-muted);
}
.frontmatter-help summary { cursor: pointer; }
.frontmatter-help pre {
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 13px;
  color: var(--code-text);
}

/* ------------------------------------------------------------ 404/footer */
.error-page { text-align: center; padding: 56px 0; }
.error-page h1 { font-size: 64px; margin: 0; color: var(--border); }
.error-page p { color: var(--text-muted); }

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 64px;
  padding: 22px 0;
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 680px) {
  .header-inner { flex-wrap: wrap; gap: 10px 16px; }
  .nav { order: 3; width: 100%; margin-right: 0; gap: 14px; }
  .header-actions { margin-left: auto; }
  .cards { grid-template-columns: 1fr; }
  .article { padding-top: 16px; }
  .article-title { margin-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover { transform: none; }
}

/* ------------------------------------------- pygments token（全部走主题变量） */
.codehilite .c,
.codehilite .cm,
.codehilite .c1 { color: var(--text-muted); font-style: italic; }
.codehilite .k,
.codehilite .kn,
.codehilite .ow { color: var(--accent); font-weight: bold; }
.codehilite .o,
.codehilite .p { color: var(--text-muted); }
.codehilite .kt { color: var(--warning); }
.codehilite .m,
.codehilite .mf,
.codehilite .mi { color: var(--success); }
.codehilite .s,
.codehilite .sb,
.codehilite .sc,
.codehilite .s2,
.codehilite .s1,
.codehilite .si,
.codehilite .sr { color: var(--link); }
.codehilite .na,
.codehilite .nb,
.codehilite .nf,
.codehilite .nc,
.codehilite .nn,
.codehilite .nt,
.codehilite .no,
.codehilite .nd { color: var(--text); }
.codehilite .gd { color: var(--danger); }
.codehilite .gi { color: var(--success); }
