/* ==========================================================================
   base.css —— 设计令牌、主题三态、排版与无障碍基础
   主题：light / dark / system（system 通过 prefers-color-scheme 生效）
   字号一律用 rem（跟随系统字体缩放），正文不写死 px 字号。
   ========================================================================== */

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

html {
  font-size: 100%; /* 跟随系统字体缩放设置 */
  -webkit-text-size-adjust: 100%;
}

:root {
  color-scheme: light;

  /* ---- 浅色主题（默认） ---- */
  --bg: #f4f6f8;
  --bg-elev: #ffffff;
  --bg-sunken: #e9edf2;
  --text: #16191d;          /* 对比度 ≈ 15:1 */
  --text-muted: #565f6b;    /* 对比度 ≈ 5.6:1（AA 正文） */
  --text-faint: #6b7480;    /* ≈ 4.6:1 */
  --border: #d5dbe3;
  --border-strong: #b7c0cc;
  --primary: #1a56c7;       /* 白底 5.9:1 */
  --primary-strong: #14449f;
  --primary-fg: #ffffff;
  --primary-soft: #dce9ff;
  --accent: #8a4b00;
  --accent-soft: #fff0dc;
  --danger: #b3261e;        /* 白底 6.2:1 */
  --danger-soft: #fdeceb;
  --success: #146c43;       /* ≈ 5.2:1 */
  --success-soft: #dff3e8;
  --warn: #8a5300;
  --warn-soft: #fff3d6;
  --focus: #0b4fd1;
  --shadow: 0 6px 24px rgba(16, 24, 40, 0.12);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.12);
  --overlay: rgba(15, 18, 22, 0.45);
  --active-bg: #dce9ff;
  --active-fg: #0f2f6b;
  --track: #cbd3dd;
  --radius: 10px;
  --radius-lg: 16px;
  --tap: 44px;              /* 最小可点区域 */
  --font: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC",
          "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --header-h: 3.25rem;
  --tabbar-h: 3.5rem;
  --mini-h: 3.75rem;
}

/* 深色主题（显式选择） */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1216;
  --bg-elev: #171b21;
  --bg-sunken: #1e232b;
  --text: #e9edf3;          /* ≈ 13:1 */
  --text-muted: #a7b1be;    /* ≈ 7.6:1 */
  --text-faint: #8d97a5;    /* ≈ 5.4:1 */
  --border: #2b323c;
  --border-strong: #3c4551;
  --primary: #7fb0ff;       /* 深底 ≈ 8:1 */
  --primary-strong: #a6c9ff;
  --primary-fg: #0d1524;
  --primary-soft: #1c2c47;
  --accent: #ffb765;
  --accent-soft: #35260f;
  --danger: #ff8b83;
  --danger-soft: #3a1a18;
  --success: #67d6a0;
  --success-soft: #12301f;
  --warn: #ffc46b;
  --warn-soft: #33270f;
  --focus: #8ab4ff;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --overlay: rgba(0, 0, 0, 0.6);
  --active-bg: #1f3355;
  --active-fg: #d6e6ff;
  --track: #333b46;
}

/* 跟随系统：未显式指定 light/dark 时按系统偏好 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1216;
    --bg-elev: #171b21;
    --bg-sunken: #1e232b;
    --text: #e9edf3;
    --text-muted: #a7b1be;
    --text-faint: #8d97a5;
    --border: #2b323c;
    --border-strong: #3c4551;
    --primary: #7fb0ff;
    --primary-strong: #a6c9ff;
    --primary-fg: #0d1524;
    --primary-soft: #1c2c47;
    --accent: #ffb765;
    --accent-soft: #35260f;
    --danger: #ff8b83;
    --danger-soft: #3a1a18;
    --success: #67d6a0;
    --success-soft: #12301f;
    --warn: #ffc46b;
    --warn-soft: #33270f;
    --focus: #8ab4ff;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --overlay: rgba(0, 0, 0, 0.6);
    --active-bg: #1f3355;
    --active-fg: #d6e6ff;
    --track: #333b46;
  }
}

/* 显式浅色时压过系统深色 */
:root[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure {
  margin: 0;
}

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

b, strong {
  font-weight: 650;
}

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

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

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

/* ---------- 无障碍 ---------- */

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute !important;
  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: -3rem;
  left: 0.5rem;
  z-index: 120;
  min-height: var(--tap);
  padding: 0.6rem 1rem;
  background: var(--primary);
  color: var(--primary-fg);
  border: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  cursor: pointer;
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 0;
}

/* 通用图标尺寸 */
.ic {
  width: 1.375rem;
  height: 1.375rem;
  flex: none;
  display: block;
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
