/* ==========================================================================
   base.css — 设计系统层（Design Tokens）
   本文件只做三件事：① 定义设计令牌 ② 元素级基础重置 ③ 通用原子类
   页面与组件样式分别放在 home.css / work.css / skills.css / guestbook.css
   --------------------------------------------------------------------------
   Apple 官网风格的可迁移要点：
   1) 色彩：近黑 #1d1d1f 做正文，中性灰做次级信息，彩色只用于「强调点缀」
   2) 字体：系统字体栈（-apple-system / SF Pro），标题紧字距（负 letter-spacing）
   3) 布局：窄内容栏（980px）+ 宽栅格（1240px），大留白，圆角卡片承载模块
   4) 交互：以「位移 + 透明度 + 毛玻璃」表达状态，动效时长 200~700ms
   ========================================================================== */

/* ---------- 1. 设计令牌 ---------- */
:root {
  /* 色彩：Apple 强调色 + 中性灰阶 */
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --blue-light: #2997ff;          /* 暗色背景上可读的蓝 */
  --purple: #bf5af2;
  --pink: #ff375f;
  --green: #30d158;
  --orange: #ff9f0a;
  --teal: #40c8e0;

  /* 彩色渐变（用于标题与卡片封面，克制使用） */
  --grad-brand: linear-gradient(120deg, #0071e3 0%, #5e5ce6 42%, #bf5af2 72%, #ff375f 100%);
  --grad-blue: linear-gradient(135deg, #0071e3, #40c8e0);
  --grad-purple: linear-gradient(135deg, #5e5ce6, #bf5af2);
  --grad-pink: linear-gradient(135deg, #ff375f, #ff9f0a);
  --grad-green: linear-gradient(135deg, #30d158, #40c8e0);
  --grad-surface: linear-gradient(180deg, #ffffff 0%, #f5f5f7 100%);

  /* 中性色（亮色主题） */
  --bg: #ffffff;
  --bg-alt: #f5f5f7;
  --bg-elevated: #ffffff;
  --bg-dark: #000000;
  --bg-dark-2: #1d1d1f;
  --text: #1d1d1f;              /* 页面主文字色（深色分区会覆盖它） */
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --text-inverse: #f5f5f7;
  --text-inverse-secondary: #a1a1a6;
  --line: #d2d2d7;
  --line-soft: rgba(0, 0, 0, 0.08);
  --glass: rgba(251, 251, 253, 0.72);
  --fill-hover: rgba(0, 0, 0, 0.05);

  /* 圆角 */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 30px;
  --r-pill: 980px;

  /* 阴影（Apple 的阴影很轻，靠层级与留白表达） */
  --sh-1: 0 1px 3px rgba(0, 0, 0, 0.04), 0 6px 18px rgba(0, 0, 0, 0.05);
  --sh-2: 0 4px 12px rgba(0, 0, 0, 0.06), 0 18px 40px rgba(0, 0, 0, 0.10);
  --sh-3: 0 24px 70px rgba(0, 0, 0, 0.18);
  --ring: 0 0 0 4px rgba(0, 113, 227, 0.28);

  /* 字体：系统字体栈，macOS 即 SF Pro；中文回落到苹方 */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* 字阶：Apple 的层次拉得很开——叙事标题巨大，正文保持 17px 不动 */
  --fs-display: clamp(48px, 7.4vw, 104px);   /* 章节主张句 */
  --fs-hero: clamp(46px, 8.2vw, 96px);
  --fs-h1: clamp(34px, 5vw, 56px);
  --fs-h2: clamp(28px, 3.6vw, 44px);
  --fs-h3: clamp(20px, 2.2vw, 26px);
  --fs-lead: clamp(17px, 1.6vw, 22px);
  --fs-body: 17px;
  --fs-sm: 14px;
  --fs-xs: 12px;

  /* 节奏 */
  --maxw: 980px;       /* 叙事内容栏 */
  --maxw-wide: 1240px; /* 全宽展示 */
  --nav-h: 48px;
  --sec-y: clamp(64px, 9vw, 130px);
  --gap: clamp(16px, 2vw, 24px);

  /* 动效曲线（Apple 常用平滑进出） */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 0.42s;
}

/* 暗色主题：同一套语义变量换一套取值，页面无需改一行结构 */
:root[data-theme="dark"] {
  --bg: #000000;
  --bg-alt: #0b0b0d;
  --bg-elevated: #16161a;
  --bg-dark: #f5f5f7;
  --bg-dark-2: #ffffff;
  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-tertiary: #8e8e93;
  --text-inverse: #1d1d1f;
  --text-inverse-secondary: #424245;
  --line: #2a2a2e;
  --line-soft: rgba(255, 255, 255, 0.12);
  --glass: rgba(18, 18, 20, 0.72);
  --fill-hover: rgba(255, 255, 255, 0.08);
  --blue: #2997ff;
  --grad-surface: linear-gradient(180deg, #141418 0%, #0b0b0d 100%);
  --sh-1: 0 1px 3px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.45);
  --sh-2: 0 6px 18px rgba(0, 0, 0, 0.55), 0 22px 50px rgba(0, 0, 0, 0.5);
}

/* ---------- 2. 基础重置 ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + 20px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.55;
  letter-spacing: -0.01em;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.35s var(--ease), color 0.35s var(--ease);
}

img { max-width: 100%; display: block; height: auto; }
a { color: var(--blue); text-decoration: none; transition: opacity 0.2s var(--ease); }
a:hover { opacity: 0.75; }
button { font: inherit; color: inherit; }

h1, h2, h3, h4 {
  margin: 0 0 0.4em;
  font-weight: 600;
  letter-spacing: -0.022em;
  line-height: 1.08;
}
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }
strong { font-weight: 600; }

::selection { background: rgba(0, 113, 227, 0.22); }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
  border-radius: 6px;
}

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 3px solid var(--bg);
  border-radius: 8px;
}
::-webkit-scrollbar-track { background: var(--bg); }

/* ---------- 3. 通用工具类 ---------- */
.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 22px;
}
.wrap--wide { max-width: var(--maxw-wide); }

.section { padding: var(--sec-y) 0; }
.section--alt { background: var(--bg-alt); }
.section--dark {
  background: #000000;
  color: #f5f5f7;
  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --line: rgba(255, 255, 255, 0.16);
  --glass: rgba(255, 255, 255, 0.08);
  --fill-hover: rgba(255, 255, 255, 0.1);
}
:root[data-theme="dark"] .section--dark {
  background: #f5f5f7;
  color: #1d1d1f;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --line: rgba(0, 0, 0, 0.12);
  --glass: rgba(255, 255, 255, 0.72);
  --fill-hover: rgba(0, 0, 0, 0.05);
}

.section-head {
  max-width: 760px;
  margin: 0 auto clamp(36px, 5vw, 64px);
  text-align: center;
}
.section-head--left { margin-left: 0; text-align: left; }
.section-head h2 { margin-bottom: 14px; }
.section-head p {
  font-size: var(--fs-lead);
  color: var(--text-secondary);
  line-height: 1.5;
}

/* 代码风格的“小标签”，Apple 开发者页面上常见的等宽眉标 */
.eyebrow {
  display: inline-block;
  margin-bottom: 14px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
}
.eyebrow--muted { color: var(--text-tertiary); }

/* 苹果式渐变文字 */
.grad-text {
  background: var(--grad-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.lead {
  font-size: var(--fs-lead);
  color: var(--text-secondary);
  line-height: 1.5;
}
.muted { color: var(--text-secondary); }
.small { font-size: var(--fs-sm); }
.center { text-align: center; }
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 999;
  padding: 12px 18px;
  background: var(--blue);
  color: #fff;
  border-radius: 0 0 var(--r-sm) 0;
}
.skip-link:focus { left: 0; }

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

/* hidden 属性必须能压过组件自己的 display（例如 .chip / .badge 的 inline-flex） */
[hidden] { display: none !important; }

/* ---------- 4. 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: 16px;
  font-weight: 400;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background-color 0.22s var(--ease), color 0.22s var(--ease),
    transform 0.22s var(--ease), box-shadow 0.22s var(--ease), border-color 0.22s var(--ease);
}
.btn:hover { opacity: 1; }
.btn:active { transform: scale(0.97); }

.btn--primary { background: var(--blue); color: #fff; }
.btn--primary:hover { background: var(--blue-hover); }

.btn--ghost {
  background: transparent;
  color: var(--blue);
  border-color: var(--blue);
}
.btn--ghost:hover { background: rgba(0, 113, 227, 0.08); }

.btn--soft { background: var(--fill-hover); color: var(--text); }
.btn--soft:hover { background: var(--line-soft); }

.btn--light { background: #fff; color: #1d1d1f; }
:root[data-theme="dark"] .btn--light { background: #f5f5f7; color: #1d1d1f; }

.btn--block { width: 100%; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }

/* “了解更多 ›” 文字链接 */
.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-body);
  color: var(--blue);
}
.link-arrow::after {
  content: "›";
  font-size: 1.15em;
  line-height: 1;
  transition: transform 0.22s var(--ease);
}
.link-arrow:hover::after { transform: translateX(4px); }

/* ---------- 5. 卡片 / 徽章 / 标签 ---------- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out),
    border-color 0.3s var(--ease);
}
.card--hover:hover {
  transform: translateY(-6px) scale(1.012);
  box-shadow: var(--sh-2);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 10px; }
.chip-row--center { justify-content: center; }
.chip {
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: all 0.22s var(--ease);
}
.chip:hover { background: var(--fill-hover); color: var(--text); }
.chip[aria-pressed="true"], .chip.is-active {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: var(--fill-hover);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  letter-spacing: 0;
}
.tag--blue { background: rgba(0, 113, 227, 0.12); color: var(--blue); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  background: var(--fill-hover);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  backdrop-filter: blur(12px);
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(48, 209, 88, 0.22);
}

/* ---------- 6. 滚动揭示动画（人机交互：滚动的“叙事感”） ---------- */
[data-reveal] {
  opacity: 0;
  transform: translateY(26px);
  transition: opacity 0.8s var(--ease-out), transform 0.8s var(--ease-out);
  will-change: opacity, transform;
}
[data-reveal].is-visible { opacity: 1; transform: none; }
[data-reveal="fade"] { transform: none; }
[data-reveal="left"] { transform: translateX(-30px); }
[data-reveal="scale"] { transform: scale(0.94); }

/* 尊重系统「减弱动态效果」设置 */
@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;
  }
  [data-reveal] { opacity: 1; transform: none; }
}

/* ---------- 7. 打印：直接在浏览器里导出 PDF ---------- */
@media print {
  .nav, .to-top, .scroll-hint, .fab { display: none !important; }
  .section { padding: 22px 0; break-inside: avoid; }
  body { font-size: 12pt; }
  [data-reveal] { opacity: 1 !important; transform: none !important; }
}
