/* ============================================================
   个人博客 · 全局样式
   设计：极简中文排版 · 响应式 · 支持暗色模式
   ============================================================ */

:root {
  /* 配色（浅色） */
  --bg: #faf9f7;
  --bg-soft: #f1efeb;
  --card: #ffffff;
  --text: #1f2328;
  --text-soft: #5c6470;
  --text-faint: #8a919c;
  --accent: #c2410c;
  --accent-soft: #fdeae0;
  --border: #e5e1da;
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.05);

  /* 字体栈：中文系统字体，无外部加载 */
  --font-serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC",
    "STSong", SimSun, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Segoe UI",
    sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas,
    "Courier New", monospace;

  --maxw: 720px;
  --radius: 10px;
  --gap: 1.5rem;
}

/* 暗色模式（跟随系统 + 手动切换按钮） */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --bg-soft: #1d2026;
    --card: #20242b;
    --text: #e7e9ec;
    --text-soft: #a8b0ba;
    --text-faint: #6d7683;
    --accent: #fb923c;
    --accent-soft: #3a2417;
    --border: #2c313a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

/* 手动暗色模式覆盖 */
html[data-theme="dark"] {
  --bg: #16181d;
  --bg-soft: #1d2026;
  --card: #20242b;
  --text: #e7e9ec;
  --text-soft: #a8b0ba;
  --text-faint: #6d7683;
  --accent: #fb923c;
  --accent-soft: #3a2417;
  --border: #2c313a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

html[data-theme="light"] {
  --bg: #faf9f7;
  --bg-soft: #f1efeb;
  --card: #ffffff;
  --text: #1f2328;
  --text-soft: #5c6470;
  --text-faint: #8a919c;
  --accent: #c2410c;
  --accent-soft: #fdeae0;
  --border: #e5e1da;
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.8;
  transition: background 0.25s ease, color 0.25s ease;
}

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

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

::selection {
  background: var(--accent-soft);
}

/* ---------------- 布局 ---------------- */

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1.25rem;
}

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

.site-header {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.brand {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.brand:hover {
  text-decoration: none;
  color: var(--accent);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  list-style: none;
}

.nav-links a {
  color: var(--text-soft);
  font-size: 0.95rem;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--accent);
  text-decoration: none;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.15rem 0.65rem;
  line-height: 1.6;
  transition: border-color 0.2s, color 0.2s;
}

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

/* 移动端菜单按钮 */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.25rem;
}

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

.site-footer {
  margin-top: 4rem;
  padding: 2rem 0 2.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 0.875rem;
  text-align: center;
}

.site-footer .container {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* ---------------- 首页 ---------------- */

.hero {
  padding: 3.5rem 0 2rem;
}

.hero h1 {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  line-height: 1.35;
  margin-bottom: 0.8rem;
}

.hero .subtitle {
  color: var(--text-soft);
  font-size: 1.05rem;
  max-width: 34em;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  margin: 2.5rem 0 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* 文章卡片列表 */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.post-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
}

.post-card:hover {
  transform: translateY(-5px) scale(1.01);
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.12);
  background: var(--bg-soft);
  text-decoration: none;
}

.post-card h3 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: var(--text);
  margin-bottom: 0.35rem;
  line-height: 1.5;
}

.post-card:hover h3 {
  color: var(--accent);
}

.post-card .excerpt {
  color: var(--text-soft);
  font-size: 0.95rem;
  line-height: 1.7;
}

.post-meta {
  color: var(--text-faint);
  font-size: 0.85rem;
  margin-top: 0.6rem;
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

/* ---------------- 文章页 ---------------- */

.post-header {
  padding: 3rem 0 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.post-header h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  line-height: 1.4;
  margin-bottom: 0.9rem;
}

.post-body {
  font-size: 1.02rem;
}

.post-body h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin: 2.2rem 0 0.9rem;
  line-height: 1.45;
}

.post-body h3 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  margin: 1.8rem 0 0.7rem;
}

.post-body p {
  margin-bottom: 1.15rem;
}

.post-body ul,
.post-body ol {
  margin: 0 0 1.15rem 1.4rem;
}

.post-body li {
  margin-bottom: 0.35rem;
}

.post-body blockquote {
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  padding: 0.7rem 1.1rem;
  margin: 1.2rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-soft);
}

.post-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.12em 0.4em;
}

.post-body pre {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  overflow-x: auto;
  margin: 1.2rem 0;
  line-height: 1.6;
}

.post-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.88rem;
}

.post-body img {
  display: block;
  margin: 1.5rem auto;
}

.post-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2rem 0;
  font-size: 0.95rem;
}

.post-body th,
.post-body td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.8rem;
  text-align: left;
}

.post-body th {
  background: var(--bg-soft);
}

.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.95rem;
}

.post-nav a {
  color: var(--text-soft);
  max-width: 46%;
}

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

/* ---------------- 关于页 / 通用内容 ---------------- */

.page-header {
  padding: 3rem 0 1.25rem;
}

.page-header h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  margin-bottom: 0.6rem;
}

.prose {
  font-size: 1.02rem;
}

.prose h2 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  margin: 2rem 0 0.8rem;
}

.prose p {
  margin-bottom: 1.1rem;
}

.prose ul,
.prose ol {
  margin: 0 0 1.1rem 1.4rem;
}

.prose li {
  margin-bottom: 0.35rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.2rem 0;
  box-shadow: var(--shadow);
}

.avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  border-radius: 999px;
  padding: 0.1rem 0.75rem;
  margin-right: 0.4rem;
  margin-bottom: 0.4rem;
}

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

@media (max-width: 640px) {
  body {
    font-size: 16px;
  }

  .hero h1 {
    font-size: 1.9rem;
  }

  .post-header h1 {
    font-size: 1.6rem;
  }

  .page-header h1 {
    font-size: 1.7rem;
  }

  .nav-toggle {
    display: block;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    padding: 0.5rem 1.25rem 1rem;
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links li {
    width: 100%;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--border);
  }

  .nav-links li:last-child {
    border-bottom: none;
  }

  .post-nav {
    flex-direction: column;
  }

  .post-nav a {
    max-width: 100%;
  }
}

/* ============================================================
   动效增强（滚动渐入 / 悬停微光 / 背景氛围 / 回到顶部）
   仅在 JS 可用时应用隐藏态，无 JS 时内容始终完整可见
   ============================================================ */

/* 滚动渐入：元素进入视口时淡入上移 */
html.js .reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.65s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.65s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}

html.js .reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* 首页标题：逐字浮现 */
html.js .hero h1 .char {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.55em);
  animation: char-up 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes char-up {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 打字机光标 */
.typing::after {
  content: "|";
  margin-left: 2px;
  color: var(--accent);
  font-weight: 300;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* 背景氛围光斑：缓慢漂浮的柔和色块 */
body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  pointer-events: none;
  will-change: transform;
}

body::before {
  width: 480px;
  height: 480px;
  top: -160px;
  right: -120px;
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  filter: blur(90px);
  animation: drift-a 20s ease-in-out infinite alternate;
}

body::after {
  width: 420px;
  height: 420px;
  bottom: -150px;
  left: -130px;
  background: color-mix(in srgb, #3b82f6 20%, transparent);
  filter: blur(90px);
  animation: drift-b 26s ease-in-out infinite alternate;
}

@keyframes drift-a {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(-70px, 50px) scale(1.18);
  }
}

@keyframes drift-b {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(60px, -60px) scale(1.12);
  }
}

/* 导航链接：下划线从左滑入 */
.nav-links a {
  position: relative;
}

.nav-links a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -3px;
  width: 100%;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.28s ease;
}

.nav-links a:hover::after,
.nav-links a.active::after {
  transform: scaleX(1);
  transform-origin: left;
}

/* 文章卡片：悬停上浮（基础 hover 效果定义在文章卡片列表一节） */

/* 回到顶部按钮 */
#back-to-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-soft);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease, color 0.2s,
    border-color 0.2s;
  z-index: 90;
}

#back-to-top.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#back-to-top:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* 无障碍：用户偏好减少动效时，全部动画降级为无 */
@media (prefers-reduced-motion: reduce) {
  html.js .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }

  html.js .hero h1 .char {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .typing::after,
  body::before,
  body::after {
    animation: none;
  }

  #back-to-top {
    transition: none;
  }
}
