/* =========================================================================
   base.css / 重置、排版基线、可访问性基础
   ========================================================================= */

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

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--t-body);
  line-height: var(--lh-body);
  font-weight: 400;
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;

  /* 顶部一层极淡的暖光，给纯色底一点纵深。
     刻意不加“竖向网格线”：那种等分条纹与 4 列封面网格并不对齐，
     看起来像渲染故障而不是结构。 */
  background-image: radial-gradient(120% 70% at 50% -12%, var(--accent-glow), transparent 62%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

/* hidden 属性必须真的隐藏：.state 等组件会写 display，
   作者样式会盖掉浏览器默认的 [hidden]，所以这里显式兜底。 */
[hidden] {
  display: none !important;
}

/* ---------------------------------------------------------------- 排版 */
h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 620;
  line-height: var(--lh-tight);
  letter-spacing: var(--track-tight);
  text-wrap: balance;
}

h1 {
  font-size: var(--t-h1);
}
h2 {
  font-size: var(--t-h2);
}
h3 {
  font-size: var(--t-h3);
}

p {
  text-wrap: pretty;
}

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

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

button,
input,
select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
}

button {
  cursor: pointer;
  text-align: left;
}

ol,
ul {
  list-style: none;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.72em;
  letter-spacing: 0.02em;
  padding: 0.15em 0.42em;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-control);
  color: var(--ink-2);
  background: var(--surface-2);
  white-space: nowrap;
}

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

/* ---------------------------------------------------- 焦点可见性（必做）
   只在键盘操作时出现焦点环，鼠标点击不出现，避免视觉噪音。 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-control);
}

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

/* -------------------------------------------------------------- 滚动条 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 3px solid var(--bg);
  border-radius: var(--r-pill);
}

/* ------------------------------------------------------- 可访问性工具类 */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* 跳转到主内容：键盘用户按 Tab 第一下就能看到 */
.skip-link {
  position: fixed;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: calc(var(--z-overlay) + 1);
  transform: translateY(-160%);
  padding: var(--sp-3) var(--sp-4);
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--r-control);
  font-size: var(--t-small);
  font-weight: 600;
  transition: transform var(--dur-2) var(--ease);
}
.skip-link:focus-visible {
  transform: translateY(0);
}

/* 正文宽度约束，避免大屏上出现超长行 */
.prose {
  max-width: var(--measure);
}

/* ------------------------------------------------------------- 颗粒层
   固定、不接收指针事件，绝不放在滚动容器上，避免移动端持续重绘。 */
.grain {
  position: fixed;
  inset: 0;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --------------------------------------------------------- 动效偏好
   所有进入动画都包裹在 no-preference 下；reduce 时整体降级为静态。 */
@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;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --line: var(--line-strong);
    --ink-2: var(--ink);
    --ink-3: var(--ink-2);
  }
}
