/* ==========================================================================
   base.css — 基础重置与排版基线 / Reset + typographic baseline
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box; /* 让 padding/border 不撑破宽度，是所有布局计算的前提 */
}

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* 锚点跳转时给 sticky 顶栏留出空间，避免标题被顶栏盖住 */
  scroll-padding-top: calc(var(--header-h) + var(--s-5));
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* 防止演示区里超宽的内容把整页顶出横向滚动条 */
  overflow-x: hidden;
}

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

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

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

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

/* 键盘可达性：只在键盘聚焦时显示焦点环，鼠标点击不显示 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

::selection {
  background: var(--mark);
  color: var(--ink);
}

/* ---------- 标题层级 / Headings ---------- */
h1,
h2,
h3,
h4,
h5 {
  font-weight: 650;
  line-height: var(--leading-tight);
  text-wrap: balance; /* 标题自动均衡断行，避免末行孤字 */
  letter-spacing: -0.011em;
}

h1 { font-size: var(--step-5); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }

p,
li {
  text-wrap: pretty; /* 正文避免孤字与难看的断行 */
}

/* ==========================================================================
   行内元素 / Inline elements
   ========================================================================== */
mark {
  background: var(--mark);
  color: inherit;
  padding: 0.05em 0.25em;
  border-radius: 3px;
}

/* 术语首次出现：加下划线点标记 */
.term {
  font-weight: 600;
  border-bottom: 1px dashed var(--line-2);
}

/* 行内代码：与周围文字形成温和对比，但不过度抢眼 */
:not(pre) > code {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.35em;
  color: var(--ink-2);
  /* 不用 nowrap：grid-template-columns: repeat(12, minmax(0, 1fr)) 这类长 token
     不换行会被顶到行外，把段落右边缘顶得参差不齐。允许在空格处折行即可。 */
  overflow-wrap: break-word;
}

kbd {
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  padding: 0.1em 0.4em;
}

/* ==========================================================================
   通用工具类 / Utilities
   ========================================================================== */
.wrap {
  /* 左右至少 1rem 内边距，同时不超过内容最大宽度 —— 一行代码搞定容器 */
  width: min(100% - 2 * var(--s-4), var(--content));
  margin-inline: auto;
}

.wrap--narrow {
  width: min(100% - 2 * var(--s-4), 900px);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  top: var(--s-2);
  left: var(--s-2);
  z-index: 100;
  padding: var(--s-2) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  transform: translateY(-200%);
  transition: transform var(--t-fast) var(--ease);
}

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

/* 尊重系统的「减少动态效果」设置 —— 无障碍是布局质量的一部分 */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
