/* base.css — 基础样式（变量、重置、字体、通用排版）
 * 用途: 定义整个站点的 CSS 变量和基础排版规范
 */

/* 引入 Google Fonts（IBM Plex 套件 + JetBrains Mono） */
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=IBM+Plex+Serif:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap");

/* CSS 变量定义 —— 整个站点的设计 token */
:root {
  /* 颜色 */
  --color-bg: #FAFAF7;
  --color-bg-elevated: #FFFFFF;
  --color-ink: #0F172A;
  --color-ink-muted: #475569;
  --color-ink-soft: #94A3B8;
  --color-line: #E2E8F0;
  --color-accent: #F59E0B;
  --color-accent-soft: #FCD34D;
  --color-accent-deep: #B45309;
  --color-success: #10B981;
  --color-danger: #EF4444;
  --color-info: #3B82F6;

  /* 字体 */
  --font-display: "IBM Plex Serif", "Source Han Serif SC", "Songti SC", serif;
  --font-body: "IBM Plex Sans", "Source Han Sans SC", "PingFang SC", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Menlo", Consolas, monospace;

  /* 字号（clamp 实现响应式） */
  --fs-h1: clamp(2.5rem, 5vw, 4.5rem);
  --fs-h2: clamp(1.875rem, 3vw, 2.75rem);
  --fs-h3: 1.5rem;
  --fs-h4: 1.25rem;
  --fs-body: 1rem;
  --fs-body-lg: 1.125rem;
  --fs-small: 0.875rem;
  --fs-tiny: 0.75rem;

  /* 字重 */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* 行高 */
  --lh-tight: 1.15;
  --lh-snug: 1.35;
  --lh-normal: 1.6;
  --lh-relaxed: 1.75;

  /* 间距 */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
  --space-32: 128px;

  /* 圆角 */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 12px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.08);
  --shadow-xl: 0 24px 60px rgba(15, 23, 42, 0.12);
  --shadow-glow: 0 0 60px rgba(245, 158, 11, 0.25);

  /* 动效 */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 150ms;
  --duration-base: 300ms;
  --duration-slow: 600ms;

  /* 布局 */
  --max-width: 1200px;
  --max-width-prose: 720px;
  --nav-height: 56px;
}

/* CSS 重置（精简版） */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + 16px);
}

body {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--lh-normal);
  color: var(--color-ink);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* 噪点纹理背景（覆盖全站，1% 不透明度） */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: 0.025;
  mix-blend-mode: multiply;
}

/* 排版基础 */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  color: var(--color-ink);
  letter-spacing: -0.02em;
}

h1 { font-size: var(--fs-h1); font-weight: var(--fw-bold); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
h4 { font-size: var(--fs-h4); }

p {
  line-height: var(--lh-relaxed);
  color: var(--color-ink-muted);
}

a {
  color: var(--color-ink);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--color-accent-deep);
}

a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* 代码块：横向溢出内部滚动，不撑破容器（移动端必备） */
pre {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* 防止代码块整体宽度受 content 撑爆 grid/flex 父容器 */
  min-width: 0;
}
pre > code {
  white-space: pre;        /* 保持代码原本格式 */
  display: block;
  word-break: normal;
}

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

ul, ol {
  list-style: none;
}

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

button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* 选中文本颜色 */
::selection {
  background-color: var(--color-accent-soft);
  color: var(--color-ink);
}

/* 通用容器 */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-6);
  position: relative;
  z-index: 2;
}

/* 文本工具类 */
.text-accent { color: var(--color-accent-deep); }
.text-muted { color: var(--color-ink-muted); }
.text-mono { font-family: var(--font-mono); }

/* 数字装饰（关键数字用等宽 + 琥珀色） */
.num {
  font-family: var(--font-mono);
  color: var(--color-accent-deep);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
}

/* 通用 section 间距 */
section {
  padding: var(--space-24) 0;
  position: relative;
  z-index: 2;
}

section + section {
  padding-top: var(--space-16);
}

/* 入场动画基础类 */
.fade-in {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.7s var(--ease-out), transform 0.7s var(--ease-out);
}

.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* 减弱动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .fade-in { opacity: 1; transform: none; }
}

/* 通用工具类：视觉隐藏但保留给屏幕阅读器 */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
