/* ==========================================================================
   tokens.css —— 设计变量 + 基础重置 + 公共组件（站点与后台共用）
   仅由 Lead 维护；前台样式写在 assets/css/style.css，后台样式写在 admin/admin.css
   ========================================================================== */

:root {
  color-scheme: light;

  /* 颜色 · 浅色 */
  --bg: #f7f5f1;
  --bg-soft: #efece5;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --border: #e3ded4;
  --border-strong: #cfc7b8;
  --text: #24211c;
  --text-muted: #6b6459;
  --text-faint: #9b9285;
  --brand: #2f6f5e;
  --brand-hover: #245749;
  --brand-soft: rgba(47, 111, 94, 0.12);
  --on-brand: #ffffff;
  --accent: #b4762b;
  --danger: #b3402e;
  --danger-soft: rgba(179, 64, 46, 0.12);
  --ok: #2f7d3f;
  --ok-soft: rgba(47, 125, 63, 0.12);

  /* 字体 */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --font-serif: Georgia, "Songti SC", "SimSun", "Noto Serif SC", serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Cascadia Mono",
    "Liberation Mono", Menlo, monospace;

  /* 尺寸 */
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-md: 1.0625rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 2rem;
  --fs-3xl: 2.5rem;
  --lh: 1.75;
  --lh-tight: 1.3;

  --maxw: 1120px;
  --maxw-narrow: 720px;
  --maxw-prose: 760px;
  --header-h: 64px;

  /* 间距 / 圆角 / 阴影 */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4rem;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-full: 999px;

  --shadow-sm: 0 1px 2px rgba(20, 18, 14, 0.06), 0 1px 3px rgba(20, 18, 14, 0.05);
  --shadow-md: 0 6px 24px -8px rgba(20, 18, 14, 0.18);
  --shadow-lg: 0 18px 48px -20px rgba(20, 18, 14, 0.3);

  --ring: 0 0 0 3px var(--brand-soft);
  --transition: 160ms ease;
}

/* 深色：手动切换（data-theme="dark"）优先，未指定时跟随系统 */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16181a;
  --bg-soft: #1d2023;
  --surface: #1f2326;
  --surface-2: #24282c;
  --border: #31373c;
  --border-strong: #454d54;
  --text: #e8e6e3;
  --text-muted: #a5a29c;
  --text-faint: #7b7873;
  --brand: #6fc3a8;
  --brand-hover: #8ed3bc;
  --brand-soft: rgba(111, 195, 168, 0.16);
  --on-brand: #10221c;
  --accent: #e0aa6a;
  --danger: #f07a68;
  --danger-soft: rgba(240, 122, 104, 0.16);
  --ok: #6fcf87;
  --ok-soft: rgba(111, 207, 135, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 28px -10px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 20px 52px -22px rgba(0, 0, 0, 0.75);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16181a;
    --bg-soft: #1d2023;
    --surface: #1f2326;
    --surface-2: #24282c;
    --border: #31373c;
    --border-strong: #454d54;
    --text: #e8e6e3;
    --text-muted: #a5a29c;
    --text-faint: #7b7873;
    --brand: #6fc3a8;
    --brand-hover: #8ed3bc;
    --brand-soft: rgba(111, 195, 168, 0.16);
    --on-brand: #10221c;
    --accent: #e0aa6a;
    --danger: #f07a68;
    --danger-soft: rgba(240, 122, 104, 0.16);
    --ok: #6fcf87;
    --ok-soft: rgba(111, 207, 135, 0.16);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 28px -10px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 20px 52px -22px rgba(0, 0, 0, 0.75);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 1rem);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 650;
  line-height: var(--lh-tight);
  letter-spacing: -0.01em;
}

p { margin: 0; }

a {
  color: var(--brand);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--brand-hover); text-decoration: underline; }

img, svg, video { max-width: 100%; height: auto; display: block; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

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

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--s-6) 0;
}

/* ---------------------------------------------------------------- 布局工具 */
.container {
  width: min(100% - 2rem, var(--maxw));
  margin-inline: auto;
}
.container-narrow {
  width: min(100% - 2rem, var(--maxw-prose));
  margin-inline: auto;
}
.stack > * + * { margin-top: var(--s-4); }
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
}
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: var(--fs-sm); }
.mono { font-family: var(--font-mono); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- 组件 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 550;
  line-height: 1.4;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition),
    color var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}
.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: var(--on-brand);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); border-color: transparent; }

.btn-danger {
  color: var(--danger);
  border-color: var(--danger-soft);
  background: var(--danger-soft);
}
.btn-danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

.btn-sm { padding: 0.3rem 0.7rem; font-size: var(--fs-xs); }
.btn-icon {
  padding: 0.45rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--r-full);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.6rem;
  border-radius: var(--r-full);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: var(--fs-xs);
  font-weight: 550;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
}
a.tag:hover { background: transparent; border-color: var(--brand); color: var(--brand); text-decoration: none; }
.tag-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
a.tag-ghost:hover { border-color: var(--brand); color: var(--brand); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.5rem;
  border-radius: var(--r-sm);
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-draft { background: var(--danger-soft); color: var(--danger); }

.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: var(--s-5) 0;
}

.empty-state {
  padding: var(--s-7) var(--s-4);
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
}

/* ---------------------------------------------------------------- 代码 */
code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
:not(pre) > code {
  padding: 0.12em 0.38em;
  border-radius: var(--r-sm);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  word-break: break-word;
}
pre {
  margin: 0;
  padding: var(--s-4);
  overflow-x: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  line-height: 1.65;
  tab-size: 2;
}
pre code { font-size: var(--fs-sm); color: var(--text); background: none; border: 0; }

/* ---------------------------------------------------------------- 正文排版 .prose
   前台文章详情与后台预览共用，保证「预览所见 = 线上所发」 */
.prose {
  font-size: var(--fs-md);
  line-height: 1.85;
  color: var(--text);
  word-wrap: break-word;
}
.prose > * + * { margin-top: 1.1em; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  margin-top: 1.9em;
  margin-bottom: 0.6em;
  scroll-margin-top: calc(var(--header-h) + 1rem);
}
.prose h1 { font-size: 1.7em; }
.prose h2 {
  font-size: 1.4em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}
.prose h3 { font-size: 1.18em; }
.prose h4 { font-size: 1.04em; }
.prose h5, .prose h6 { font-size: 1em; color: var(--text-muted); }
.prose a { text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.prose ul, .prose ol { padding-left: 1.5em; margin-block: 0.8em; }
.prose li + li { margin-top: 0.35em; }
.prose li > ul, .prose li > ol { margin-block: 0.35em; }
.prose blockquote {
  margin: 1.2em 0;
  padding: 0.2em 1.1em;
  border-left: 3px solid var(--brand);
  background: var(--brand-soft);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  color: var(--text-muted);
}
.prose blockquote > * + * { margin-top: 0.6em; }
.prose img { border-radius: var(--r-md); border: 1px solid var(--border); }
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  display: block;
  overflow-x: auto;
}
.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 0.5em 0.75em;
  text-align: left;
}
.prose th { background: var(--surface-2); font-weight: 650; }
.prose hr { margin: 2em 0; }
.prose .code-block { position: relative; }
.prose .code-block[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.15em 0.6em;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 0 var(--r-md) 0 var(--r-sm);
}
.prose .code-block code { display: block; }
