/* ==========================================================================
   base.css — 设计变量 / 重置 / 排版 / 通用工具
   ========================================================================== */

:root {
  /* 色彩 */
  --ink-900: #060607;
  --ink-850: #0a0a0c;
  --ink-800: #0e0e11;
  --ink-700: #141418;
  --ink-600: #1b1b21;
  --ink-500: #24242c;
  --paper: #f2efe9;
  --paper-dim: #b6b0a6;
  --paper-faint: #7d786f;
  --blood: #c1121f;
  --blood-deep: #7d0512;
  --ember: #ff4d1a;
  --line: rgba(242, 239, 233, 0.1);
  --line-strong: rgba(242, 239, 233, 0.2);

  /* 字体 */
  --font-display: "Barlow Condensed", "Arial Narrow", "Bahnschrift", sans-serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "Yu Mincho", "SimSun", serif;
  --font-sans: "Inter", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", Consolas, "Courier New", monospace;

  /* 字号 */
  --step--1: 0.78rem;
  --step-0: 0.95rem;
  --step-1: 1.12rem;
  --step-2: clamp(1.35rem, 1.1rem + 0.9vw, 1.75rem);
  --step-3: clamp(1.75rem, 1.3rem + 1.9vw, 2.75rem);
  --step-4: clamp(2.4rem, 1.6rem + 3.4vw, 4.1rem);
  --step-5: clamp(2.9rem, 1.7rem + 5.2vw, 6.2rem);

  /* 间距与尺寸 */
  --space-1: 0.35rem;
  --space-2: 0.65rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.25rem;
  --space-6: 3.25rem;
  --space-7: 5rem;
  --shell: 1180px;
  --gutter: clamp(1.15rem, 4vw, 2.75rem);
  --nav-h: 62px;
  --radius: 2px;
  --ease: cubic-bezier(0.22, 0.68, 0.18, 1);

  color-scheme: dark;
}

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

* {
  margin: 0;
}

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

body {
  min-height: 100vh;
  background-color: var(--ink-900);
  background-image:
    radial-gradient(circle at 78% -10%, rgba(193, 18, 31, 0.22), transparent 46%),
    radial-gradient(circle at 8% 22%, rgba(255, 77, 26, 0.07), transparent 38%),
    linear-gradient(180deg, var(--ink-850), var(--ink-900) 46%);
  background-attachment: fixed;
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.75;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

img {
  height: auto;
}

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

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

/* ---------- 选中与滚动条 ---------- */
::selection {
  background: var(--blood);
  color: #fff;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--ink-500) var(--ink-900);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--ink-900);
}

::-webkit-scrollbar-thumb {
  background: var(--ink-500);
  border: 2px solid var(--ink-900);
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--blood);
}

/* ---------- 排版 ---------- */
h1,
h2,
h3,
h4 {
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

strong {
  color: var(--paper);
  font-weight: 700;
}

small {
  font-size: var(--step--1);
}

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

/* ---------- 焦点可见性 ---------- */
:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 3px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ---------- 布局工具 ---------- */
.shell {
  width: min(100% - var(--gutter) * 2, var(--shell));
  margin-inline: auto;
}

.section {
  position: relative;
  padding-block: clamp(3.25rem, 7vw, 6rem);
}

.section + .section {
  border-top: 1px solid var(--line);
}

/* 章节标题：编号 + 标题 + 细线 */
.section-head {
  margin-bottom: var(--space-5);
}

.section-head__index {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.7rem;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.28em;
  color: var(--blood);
}

.section-head__index::after {
  content: "";
  width: 42px;
  height: 1px;
  background: currentColor;
  opacity: 0.6;
}

.section-head__title {
  font-family: var(--font-serif);
  font-size: var(--step-3);
  letter-spacing: 0.04em;
}

.section-head__title small {
  display: block;
  margin-top: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 400;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--paper-faint);
}

.section-head__rule {
  display: block;
  height: 1px;
  margin-top: 1.15rem;
  background: linear-gradient(90deg, var(--line-strong), transparent);
}

/* 等宽小标签 */
.mono-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--paper-faint);
}

/* 引用 / 注释 */
.note {
  font-size: var(--step--1);
  color: var(--paper-faint);
}

/* 屏幕阅读器专用 */
.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;
}

.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 200;
  padding: 0.6rem 1rem;
  background: var(--paper);
  color: var(--ink-900);
  font-weight: 700;
  transform: translateY(-160%);
  transition: transform 0.25s var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

/* ---------- 全局颗粒 / 扫描线质感 ---------- */
/* 用轻量渐变模拟胶片颗粒，避免全屏 feTurbulence 带来的渲染开销 */
.grain {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0.6;
  background-image:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.018) 0 1px,
      transparent 1px 3px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(0, 0, 0, 0.05) 0 1px,
      transparent 1px 4px
    );
}

/* ---------- 入场动画 ---------- */
.js [data-reveal] {
  opacity: 0;
  transform: translateY(22px);
  transition:
    opacity 0.7s var(--ease),
    transform 0.7s var(--ease);
  transition-delay: var(--reveal-delay, 0ms);
}

.js [data-reveal].is-visible {
  opacity: 1;
  transform: none;
}

/* ---------- 减少动态效果 ---------- */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .js [data-reveal] {
    opacity: 1;
    transform: none;
  }
}
