/* ============================================================
 * Timedecimal 基础样式（reset + 排版）
 * 文件：assets/css/base.css
 * 说明：现代 reset + Mobile-first 排版基线。
 *       任何页面都依赖此文件作为基础。
 * ============================================================ */

/* ====== 现代 reset ====== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;       /* 防止 iOS 自动放大字体 */
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 80px;             /* 锚点偏移补偿（顶部 sticky 导航） */
}

body {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text-primary);
  background: var(--bg-primary);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  max-width: 100vw;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 主内容容器在 footer 上方推开 */
main {
  flex: 1 0 auto;
}

/* ====== 媒体元素自适应（防 CLS） ====== */
img, video, iframe, svg, embed, picture {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ====== 链接 ====== */
a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.18em;
  transition: color var(--dur-fast) var(--ease-out);
}
a:hover { color: var(--accent-hover); text-decoration: underline; }
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ====== 标题层级（视觉权重 + 行距 + 字距） ====== */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--text-primary);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.018em;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.5rem);
  line-height: 1.05;
  letter-spacing: -0.025em;
  margin-bottom: var(--space-5);
}
h2 {
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  line-height: 1.15;
  margin: var(--space-7) 0 var(--space-4);
}
h3 {
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  line-height: 1.25;
  margin: var(--space-6) 0 var(--space-3);
}
h4 {
  font-size: 1.125rem;
  margin: var(--space-5) 0 var(--space-3);
}

/* 段落基础（v3.2 强制-M02：每段 ≤ 5 行） */
p {
  margin-bottom: var(--space-4);
  max-width: 70ch;                       /* 最佳阅读行宽 */
}

/* ====== 列表 ====== */
ul, ol {
  margin-bottom: var(--space-4);
  padding-left: 1.4em;
}
li { margin-bottom: var(--space-2); }
li > ul, li > ol { margin-top: var(--space-2); }

/* ====== 强调与代码 ====== */
strong, b { font-weight: 700; color: var(--text-primary); }
em, i     { font-style: italic; }

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
code {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 0.1em 0.4em;
  word-break: break-word;
}
pre {
  background: var(--bg-inverse);
  color: var(--text-on-dark);
  padding: var(--space-4);
  border-radius: var(--r-md);
  overflow-x: auto;
  margin-bottom: var(--space-5);
}
pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
}

/* ====== 引用 ====== */
blockquote {
  border-left: 4px solid var(--accent);
  background: var(--bg-soft);
  padding: var(--space-4) var(--space-5);
  margin: var(--space-5) 0;
  border-radius: 0 var(--r-md) var(--r-md) 0;
  color: var(--text-secondary);
  font-style: italic;
}
blockquote cite { font-style: normal; color: var(--text-tertiary); }

/* ====== 表格基础（响应式横滚 wrapper） ====== */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: var(--space-5) 0;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-small);
}
caption {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: var(--fs-tiny);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
th, td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background: var(--bg-soft);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) { background: rgba(244,244,245,.5); }

/* ====== 水平线 ====== */
hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-6) 0;
}

/* ====== 表单基础 ====== */
input, select, textarea, button {
  font: inherit;
  color: inherit;
}
input, select, textarea {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 0 var(--space-4);
  min-height: var(--touch-min);
  width: 100%;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
textarea { padding: var(--space-3) var(--space-4); min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--sh-focus);
}
label { font-weight: 600; font-size: var(--fs-small); display: block; margin-bottom: var(--space-2); color: var(--text-secondary); }

/* 隐藏 spinner（数字输入更整洁） */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* ====== 跳过导航（无障碍 + SEO 信号） ====== */
.skip-nav {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--text-primary);
  color: var(--text-on-dark);
  padding: var(--space-3) var(--space-4);
  z-index: var(--z-skip);
  border-radius: 0 0 var(--r-md) 0;
}
.skip-nav:focus { top: 0; outline: 0; color: var(--text-on-dark); }

/* ====== 通用容器 ====== */
.container         { width: 100%; max-width: var(--container-default); margin: 0 auto; padding: 0 var(--space-5); }
.container-narrow  { max-width: var(--container-narrow); }
.container-wide    { max-width: var(--container-wide); }

/* ====== 实用类 ====== */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
.text-secondary { color: var(--text-secondary); }
.text-tertiary  { color: var(--text-tertiary); }
.text-mono      { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.text-center    { text-align: center; }

/* ====== 动效尊重用户偏好 ====== */
@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;
  }
}

/* ====== 图片懒加载占位（防 CLS） ====== */
img[loading="lazy"] { background: var(--bg-soft); }

/* ====== 选中文字色 ====== */
::selection { background: var(--accent); color: var(--text-on-dark); }
