/* ==========================================================================
   沈志清的个人网站 · 全局样式
   - 支持明亮 / 暗黑两套主题（由 <html data-theme="light|dark"> 控制）
   - 所有颜色对均满足 WCAG 2.1 AAA：
     正文文字 ≥ 7:1，大号文字 ≥ 4.5:1，UI 边界等非文本 ≥ 3:1
   ========================================================================== */

/* ---------- 设计令牌 ---------- */

:root {
  /* 明亮模式 */
  --bg: #f7f8fa;              /* 页面背景 */
  --surface: #ffffff;         /* 卡片 / 头部背景 */
  --text: #101418;            /* 正文，与背景 17.7:1 */
  --text-secondary: #404752;  /* 次要文字，与背景 8.8:1 */
  --border: #7a828e;          /* 边框，与表面 3.9:1 */
  --accent: #0b3d91;          /* 链接 / 强调，与背景 9.5:1 */
  --accent-hover: #082c69;    /* 悬停，与背景 12.6:1 */
  --accent-contrast: #ffffff; /* 强调色上的文字，10.1:1 */
  --shadow: 0 1px 3px rgba(16, 20, 24, 0.12), 0 6px 18px rgba(16, 20, 24, 0.08);
  --glow: 0 10px 24px rgba(11, 61, 145, 0.16), 0 3px 8px rgba(11, 61, 145, 0.12);
  --sheen: rgba(11, 61, 145, 0.12);
  --radius: 12px;
  --header-h: 64px;
}

[data-theme="dark"] {
  /* 暗黑模式 */
  --bg: #0e1116;              /* 页面背景 */
  --surface: #171b22;         /* 卡片 / 头部背景 */
  --text: #f2f4f7;            /* 正文，与背景 17.3:1 */
  --text-secondary: #a9b4c0;  /* 次要文字，与背景 9.1:1 */
  --border: #606b79;          /* 边框，与表面 3.3:1 */
  --accent: #7fb2ff;          /* 链接 / 强调，与背景 8.8:1 */
  --accent-hover: #9cc4ff;    /* 悬停，与表面 10.1:1 */
  --accent-contrast: #0b1220; /* 强调色上的文字，8.8:1 */
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 6px 18px rgba(0, 0, 0, 0.45);
  --glow: 0 0 0 1px rgba(127, 178, 255, 0.35), 0 0 20px rgba(127, 178, 255, 0.18),
    0 10px 28px rgba(0, 0, 0, 0.55);
  --sheen: rgba(127, 178, 255, 0.16);
}

/* ---------- 基础 ---------- */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 12px);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, p, ul {
  margin: 0;
}

ul {
  padding: 0;
}

h1 {
  font-size: clamp(2rem, 4.5vw + 1rem, 3rem);
  line-height: 1.25;
  margin-bottom: 20px;
}

h2 {
  font-size: clamp(1.4rem, 2.5vw + 0.8rem, 1.9rem);
  line-height: 1.3;
  margin-bottom: 24px;
  padding-bottom: 12px;
  position: relative;
}

/* 标题下的强调短横线（装饰性） */
h2::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 44px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
}

p {
  margin-bottom: 12px;
}

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

/* ---------- 文字辅助 ---------- */

.accent {
  color: var(--accent);
}

.lead {
  font-size: 1.25rem;
}

.muted {
  color: var(--text-secondary);
}

/* ---------- 链接 ---------- */

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

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

/* JS 驱动的动态下划线：悬停 / 键盘聚焦时从左向右“长出来” */
.dynamic-underline {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0% 100%;
  background-size: 0% 1px;
  transition: background-size 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.dynamic-underline.link-hover {
  background-size: 100% 1px;
}

/* ---------- 键盘焦点（清晰可见，≥ 3:1） ---------- */

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- 文本选中 ---------- */

::selection {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* ---------- 跳转链接（辅助技术友好） ---------- */

.skip-link {
  position: fixed;
  top: -64px;
  left: 16px;
  z-index: 300;
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus-visible {
  top: 12px;
}

/* ---------- 顶部导航 ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(16px, 4vw, 32px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-decoration: none;
}

.top nav {
  position: relative;
}

.top nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  list-style: none;
}

.top nav a {
  display: inline-block;
  padding: 8px 4px;
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}

.top nav a:hover {
  color: var(--accent);
}

.top nav a.active {
  color: var(--accent);
}

/* 菜单滑动指示条：在菜单项之间平滑移动 */
.nav-indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: left 0.3s ease, width 0.3s ease, opacity 0.3s ease,
    background-color 0.25s ease;
}

/* ---------- 主题切换按钮 ---------- */

.theme-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.theme-toggle .icon {
  width: 20px;
  height: 20px;
}

/* 明亮模式显示月亮（点击进入暗黑），暗黑模式显示太阳 */
.theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* ---------- 主体与分区 ---------- */

main {
  padding-top: 0;
}

section {
  padding: clamp(48px, 9vw, 96px) clamp(20px, 6vw, 32px);
}

/* 原生锚点跳转（无 JS / 前进后退）时避让吸顶栏 */
section[id] {
  scroll-margin-top: calc(var(--header-h) + 12px);
}

section:nth-of-type(even) {
  background: var(--surface);
  border-block: 1px solid var(--border);
}

.container {
  max-width: 760px;
  margin-inline: auto;
}

/* ---------- 卡片 ---------- */

.card-list {
  list-style: none;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
}

/* 代码仓库链接卡片 */

.link-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--text);
  text-decoration: none;
}

.link-card .name {
  font-weight: 600;
  color: var(--accent);
}

.link-card .hint {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.link-card .arrow {
  flex: none;
  color: var(--accent);
}

.link-card .arrow .icon {
  width: 20px;
  height: 20px;
  display: block;
}

.link-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

/* ---------- 爱好卡片：悬停抬升 + 未来感光效 ---------- */

#hobby .card {
  position: relative;
  overflow: hidden;
  cursor: default;
  transition: background-color 0.25s ease, color 0.25s ease,
    border-color 0.25s ease;
}

/* 顶部强调光带（悬停时淡入） */
#hobby .card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* 光痕扫描：一道斜向光带从卡片上掠过 */
#hobby .card::after {
  content: "";
  position: absolute;
  top: -60%;
  left: -75%;
  width: 50%;
  height: 220%;
  background: linear-gradient(
    105deg,
    transparent,
    var(--sheen) 45%,
    var(--sheen) 55%,
    transparent
  );
  transform: translateX(-150%) rotate(12deg);
  pointer-events: none;
  transition: transform 0.7s ease;
}

/* 仅在支持悬停且未开启“减少动态效果”的设备上启用抬升动画 */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  #hobby .card {
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
      box-shadow 0.3s ease, border-color 0.3s ease,
      background-color 0.25s ease, color 0.25s ease;
  }

  #hobby .card:hover {
    transform: translateY(-8px);
    border-color: var(--accent);
    box-shadow: var(--glow);
  }

  #hobby .card:hover::before {
    opacity: 1;
  }

  #hobby .card:hover::after {
    transform: translateX(350%) rotate(12deg);
  }
}

/* ---------- 页脚 ---------- */

footer {
  padding: 32px 20px;
  text-align: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.95rem;
}

footer p {
  margin-bottom: 6px;
}

footer a {
  color: var(--accent);
}

/* ---------- 响应式 ---------- */

@media (max-width: 640px) {
  :root {
    --header-h: 100px;
  }

  .top {
    height: auto;
    min-height: 64px;
    flex-wrap: wrap;
    padding-block: 8px 0;
  }

  .top nav {
    order: 3;
    flex-basis: 100%;
    padding-bottom: 8px;
  }

  /* 移动端导航有 8px 底部内边距，指示条同步上移对齐菜单项 */
  .nav-indicator {
    bottom: 8px;
  }

  .top nav ul {
    justify-content: center;
    gap: 4px 14px;
  }

  .top nav a {
    padding: 6px 4px;
  }
}

/* ---------- 动画与无障碍 ---------- */

@media (prefers-reduced-motion: no-preference) {
  body,
  .top,
  section,
  .card,
  footer {
    transition: background-color 0.25s ease, color 0.25s ease,
      border-color 0.25s ease;
  }

  .link-card {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
