/* ============================================================================
 * base.css —— 基础层
 * 只做四件事：重置、盒模型、系统字体栈、页面容器；外加 [hidden] 处理与
 * prefers-reduced-motion / prefers-contrast 兜底。
 * ⛔ 不放任何组件样式（组件在 components.css，页面布局在 pages.css）。
 * 所有色值/字号一律引用 tokens.css 的变量（设计规范 §7.1）。
 * ========================================================================== */

/* ------------------------------------------------------------------ 重置 + 盒模型 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* 禁止 iOS 横屏时自动放大字号（会打乱既定字号阶梯） */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--color-bg);
}

body,
h1,
h2,
h3,
p,
ul,
ol,
figure,
blockquote {
  margin: 0;
}

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

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

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

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

/* ------------------------------------------------------------------ 字体与正文
   只用系统字体栈（tokens.css 的 --font-sans），不加载 Web 字体。 */
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  font-weight: var(--weight-regular);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ 页面容器
   手机竖屏：左右边距固定 16px；平板：内容最大 640px 居中，不拉满。 */
.page {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--max-content);
  min-height: 100vh;
  min-height: 100dvh;
  margin-inline: auto;
  padding-inline: var(--space-md);
  padding-bottom: calc(var(--space-md) + var(--safe-bottom));
  background: var(--color-bg);
}

/* ------------------------------------------------------------------ [hidden]
   flex/grid 子元素的 display 会盖掉 hidden 属性，这里强制生效。 */
[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------------ 只给屏幕朗读器的文字
   视觉上不可见，但屏幕朗读器会读（用于补齐页面标题这类结构信息）。 */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------------ 焦点可见（无障碍硬要求）
   禁止用 outline: none 了事（设计规范 §6.1）。 */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ 无障碍兜底
   1) prefers-reduced-motion：系统开了"减弱动态效果"（有些孩子前庭敏感）时，
      所有动效时长归零、循环动画只跑一次（设计规范 §4.3，硬要求不是可选项）。
   2) prefers-contrast：系统要求更高对比度时，把边框与提示文字各加深一档
      （规范 §6.1 要求尊重该设置）。这两个覆盖只改令牌取值，不写死色值。 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --color-border: var(--gray-600);
    --color-text-hint: var(--gray-600);
  }
}
