/**
 * 基础重置与全局排版
 */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + var(--space-4));
  /* 更柔和的滚动条（支持的浏览器） */
  scrollbar-gutter: stable;
}

@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;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* iOS 底部安全区 */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* 页面进入淡入 */
body.page-ready {
  animation: page-fade-in var(--duration-slow) var(--ease-out);
}

@keyframes page-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

img {
  border: 0;
}

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

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

a {
  color: var(--color-primary);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--color-primary-hover);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

/* 触控设备：去掉 sticky hover 残留感 */
@media (hover: none) {
  a:hover {
    color: var(--color-primary);
  }
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0 0 var(--space-4);
  font-weight: 650;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  color: var(--color-text);
  text-wrap: balance;
}

h1 {
  font-size: clamp(var(--text-3xl), 4.2vw, var(--text-5xl));
}

h2 {
  font-size: clamp(var(--text-2xl), 2.8vw, var(--text-3xl));
}

h3 {
  font-size: var(--text-xl);
}

p {
  margin: 0 0 var(--space-4);
  text-wrap: pretty;
}

p:last-child {
  margin-bottom: 0;
}

ul,
ol {
  margin: 0 0 var(--space-4);
  padding-left: 1.25em;
}

li {
  margin-bottom: var(--space-2);
}

li:last-child {
  margin-bottom: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: var(--space-8) 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-primary-soft);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* 屏幕阅读器专用 */
.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: absolute;
  top: -100%;
  left: max(var(--space-4), env(safe-area-inset-left, 0));
  z-index: calc(var(--z-top) + 1);
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: max(var(--space-4), env(safe-area-inset-top, 0));
  color: #fff;
}

/* 选中文字 */
::selection {
  background: var(--color-primary-soft);
  color: var(--color-text);
}

/* 细滚动条（WebKit / Chromium） */
@media (pointer: fine) {
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--color-border-strong) 80%, transparent);
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    background-clip: content-box;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--color-text-faint) 70%, transparent);
    background-clip: content-box;
    border: 2px solid transparent;
  }
}
