/* ============================================
   base.css — 重置、变量、字体、基础排版
   ============================================ */

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

/* ---------- 主题变量 ---------- */
:root {
  /* 浅色：纸张感 */
  --bg: #f4efe4;
  --bg-paper: #fbf7ed;
  --bg-elevated: #ffffff;
  --text: #2a2622;
  --text-muted: #6b6660;
  --text-subtle: #9a9388;
  --border: #d9d3c4;
  --border-strong: #b8b0a0;
  --accent: #a83232;
  --accent-soft: #f0d9d9;
  --code-bg: #efe9dc;
  --code-border: #d9d3c4;
  --selection: #f0d9d9;
  --shadow: 0 1px 2px rgba(60, 50, 40, 0.04), 0 4px 12px rgba(60, 50, 40, 0.05);
  --shadow-lg: 0 4px 20px rgba(60, 50, 40, 0.08);
  --noise-opacity: 0.03;

  /* 字体 */
  --font-serif: "Source Han Serif SC", "Noto Serif CJK SC", "Songti SC",
    "STSong", Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", "Source Code Pro",
    Consolas, "Courier New", monospace;

  /* 尺寸 */
  --content-width: 720px;
  --wide-width: 1080px;
  --radius: 2px;
  --radius-md: 4px;
  --radius-lg: 8px;
}

[data-theme="dark"] {
  --bg: #1a1814;
  --bg-paper: #23201a;
  --bg-elevated: #2a2620;
  --text: #e8e3d6;
  --text-muted: #a8a094;
  --text-subtle: #6b6660;
  --border: #3a352d;
  --border-strong: #4a4438;
  --accent: #d46565;
  --accent-soft: #3a2525;
  --code-bg: #1f1d18;
  --code-border: #2e2a23;
  --selection: #3a2525;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.4);
  --noise-opacity: 0.04;
}

/* ---------- 基础 ---------- */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-serif);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
  /* 微微的纸张纹理 */
  background-image:
    radial-gradient(at 20% 30%, rgba(168, 50, 50, 0.015) 0px, transparent 50%),
    radial-gradient(at 80% 70%, rgba(80, 60, 40, 0.02) 0px, transparent 50%);
}

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

a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  transition: color 0.2s, border-color 0.2s;
}
a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

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

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input,
textarea {
  font-family: inherit;
  color: inherit;
}

/* ---------- 工具类 ---------- */
.container {
  max-width: var(--wide-width);
  margin: 0 auto;
  padding: 0 24px;
}

.container-narrow {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 24px;
}

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

.divider-double {
  height: 5px;
  border: 0;
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
  margin: 64px 0;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.875rem;
}

.tiny {
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-sans);
}

/* 焦点 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
