/* ===== 基础重置 ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* —— 暖色纸张风（浅色，默认）—— */
  --bg: #faf8f4;
  --surface: #ffffff;
  --glass: rgba(250, 248, 244, 0.85);
  --ink: #1f1d1a;
  --ink-soft: #514c44;
  --muted: #8a8478;
  --accent: #b6552f;
  --accent-soft: #f3e7df;
  --accent-deep: #8f3f20;
  --line: #e7e0d4;
  --warn: #c0894a;
  --warn-soft: #fbf3e6;

  /* —— 代码配色 —— */
  --code-bg: #f6f1ea;
  --code-ink: #3a342c;
  --kw: #b6552f;
  --typ: #2a6f97;
  --str: #5a7a3a;
  --num: #9c5d22;
  --cmt: #9a9384;
  --ann: #8f3f20;

  --maxw: 720px;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 29, 26, 0.04), 0 8px 24px rgba(31, 29, 26, 0.05);
  --shadow-lg: 0 6px 16px rgba(31, 29, 26, 0.08), 0 18px 40px rgba(31, 29, 26, 0.08);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", sans-serif;
  --font-serif: "Georgia", "Songti SC", "SimSun", "宋体", serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo,
    "Courier New", monospace;
}

/* —— 暖色夜读风（深色，由 app.js 设置 data-theme）—— */
:root[data-theme="dark"] {
  --bg: #1b1815;
  --surface: #242019;
  --glass: rgba(27, 24, 21, 0.82);
  --ink: #ece3d6;
  --ink-soft: #bfb4a1;
  --muted: #8c8474;
  --accent: #e08a5f;
  --accent-soft: #33271e;
  --accent-deep: #f0a47c;
  --line: #38322b;
  --warn: #d6a05f;
  --warn-soft: #2f2417;

  --code-bg: #15120e;
  --code-ink: #e6dfd2;
  --kw: #e89372;
  --typ: #7fb4d6;
  --str: #a7c47c;
  --num: #e0a96d;
  --cmt: #8a8170;
  --ann: #e0a070;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 6px 16px rgba(0, 0, 0, 0.45), 0 18px 40px rgba(0, 0, 0, 0.5);
}

html {
  scroll-behavior: smooth;
}

/* 锚点定位时给粘性导航留出空间 */
[id] {
  scroll-margin-top: 84px;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--accent-deep);
  text-decoration: underline;
  text-underline-offset: 3px;
}

img {
  max-width: 100%;
  display: block;
}

/* ===== 顶部导航 ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.nav {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

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

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

.nav-right {
  display: flex;
  align-items: center;
  gap: 18px;
}

.nav-links {
  display: flex;
  gap: 26px;
  list-style: none;
}

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

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

/* 主题切换按钮 */
.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}

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

.theme-toggle:active {
  transform: scale(0.92);
}

.theme-toggle svg {
  width: 17px;
  height: 17px;
}

.theme-toggle .icon-sun {
  display: none;
}

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

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

/* ===== 阅读进度条 ===== */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-deep));
  z-index: 40;
  transition: width 0.08s linear;
}

/* ===== 返回顶部 ===== */
.to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease;
  z-index: 35;
}

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

.to-top:hover {
  background: var(--accent-deep);
}

.to-top svg {
  width: 20px;
  height: 20px;
}

/* ===== 主体容器 ===== */
.main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 24px;
  width: 100%;
  flex: 1;
}

/* ===== 首页 Hero ===== */
.hero {
  padding: 80px 0 56px;
  text-align: center;
}

.hero h1 {
  font-size: clamp(1.9rem, 5vw, 2.8rem);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.5px;
  margin-bottom: 18px;
}

.hero p {
  font-size: 1.1rem;
  color: var(--ink-soft);
  max-width: 540px;
  margin: 0 auto;
}

.hero .tags {
  margin-top: 26px;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.82rem;
  padding: 5px 14px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 500;
}

/* ===== 板块标题 ===== */
.section-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 16px 0 28px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ===== 首页分类筛选 ===== */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.filter-btn {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-btn:hover {
  border-color: var(--accent-soft);
  color: var(--accent);
}

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ===== 文章列表（卡片） ===== */
.post-list {
  padding-bottom: 64px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.post-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 30px;
  transition: transform 0.18s ease, box-shadow 0.18s ease,
    border-color 0.18s ease;
}

.post-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--accent-soft);
}

.post-card a {
  color: inherit;
}

.post-card a:hover {
  text-decoration: none;
}

.post-card.hidden {
  display: none;
}

.post-meta {
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.post-meta .cat {
  color: var(--accent);
  font-weight: 600;
}

.post-card h2 {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 10px;
  letter-spacing: -0.2px;
}

.post-card p {
  color: var(--ink-soft);
  font-size: 0.97rem;
}

.read-more {
  display: inline-block;
  margin-top: 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
}

/* ===== 文章正文页 ===== */
.article {
  padding: 56px 0 72px;
}

.article-header {
  margin-bottom: 32px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 28px;
}

.article-header .cat {
  display: inline-block;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
}

.article-header h1 {
  font-size: clamp(1.7rem, 4vw, 2.3rem);
  font-weight: 800;
  line-height: 1.3;
  margin: 12px 0 16px;
  letter-spacing: -0.3px;
}

.article-header .meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.article-body {
  font-family: var(--font-serif);
  font-size: 1.08rem;
  color: var(--ink);
}

.article-body p {
  margin-bottom: 1.5em;
}

.article-body h2 {
  font-family: var(--font-sans);
  font-size: 1.3rem;
  font-weight: 700;
  margin: 2em 0 0.7em;
  scroll-margin-top: 84px;
}

.article-body h3 {
  font-family: var(--font-sans);
  font-size: 1.1rem;
  font-weight: 700;
  margin: 1.6em 0 0.6em;
}

.article-body strong {
  color: var(--ink);
  font-weight: 700;
}

.article-body blockquote {
  margin: 1.6em 0;
  padding: 6px 0 6px 22px;
  border-left: 3px solid var(--accent);
  color: var(--ink-soft);
  font-style: italic;
}

/* 行内代码 */
.article-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 5px;
  color: var(--accent-deep);
}

/* 代码块 */
.article-body pre {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  margin: 1.6em 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.65;
  -webkit-overflow-scrolling: touch;
}

.article-body pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: var(--code-ink);
  font-size: inherit;
  line-height: inherit;
}

/* 代码块右上角的语言标签 */
.article-body pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  right: 12px;
  font-family: var(--font-sans);
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--cmt);
  pointer-events: none;
}

/* —— Java 语法高亮 token —— */
.t-c {
  color: var(--cmt);
  font-style: italic;
}
.t-s {
  color: var(--str);
}
.t-k {
  color: var(--kw);
  font-weight: 600;
}
.t-t {
  color: var(--typ);
}
.t-n {
  color: var(--num);
}
.t-a {
  color: var(--ann);
}

/* —— 表格 —— */
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.6em 0;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  display: block;
  overflow-x: auto;
}

.article-body th,
.article-body td {
  border: 1px solid var(--line);
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}

.article-body th {
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 700;
}

.article-body tbody tr:nth-child(even) td {
  background: var(--accent-soft);
  background: color-mix(in srgb, var(--accent-soft) 40%, transparent);
}

/* —— 提示框 —— */
.callout {
  margin: 1.6em 0;
  padding: 14px 18px;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  font-family: var(--font-sans);
  font-size: 0.97rem;
}

.callout.warn {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.callout .callout-title {
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--ink);
}

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

.article-body ul,
.article-body ol {
  margin: 0 0 1.5em 1.4em;
}

.article-body li {
  margin-bottom: 0.5em;
}

/* —— 文章目录 —— */
.toc {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 22px 20px;
  margin: 0 0 40px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
}

.toc .toc-title {
  font-weight: 700;
  font-size: 0.76rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.toc ol {
  list-style: none;
  counter-reset: toc;
  margin: 0;
}

.toc li {
  counter-increment: toc;
  margin-bottom: 7px;
}

.toc li::before {
  content: counter(toc, decimal-leading-zero);
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  margin-right: 10px;
}

.toc a {
  color: var(--ink-soft);
}

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

.back-link {
  display: inline-block;
  margin-bottom: 24px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-soft);
}

.back-link::before {
  content: "← ";
}

/* ===== 上一篇 / 下一篇 ===== */
.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 56px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  font-family: var(--font-sans);
}

.post-nav a {
  flex: 1;
  min-width: 0;
  padding: 12px 4px;
  border-radius: 8px;
  transition: color 0.15s ease;
}

.post-nav a:hover {
  text-decoration: none;
}

.post-nav .nav-label {
  display: block;
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.post-nav .nav-title {
  font-weight: 600;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.4;
}

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

.post-nav .next {
  text-align: right;
}

.post-nav .placeholder {
  visibility: hidden;
}

/* ===== 关于卡片 ===== */
.about {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 36px;
  margin-bottom: 64px;
}

.about h2 {
  font-size: 1.3rem;
  margin-bottom: 12px;
}

.about p {
  color: var(--ink-soft);
  margin-bottom: 12px;
}

/* ===== 底部 + 备案 ===== */
.site-footer {
  margin-top: 40px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.footer-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 36px 24px;
  text-align: center;
}

.footer-links {
  display: flex;
  gap: 22px;
  justify-content: center;
  list-style: none;
  margin-bottom: 18px;
}

.footer-links a {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

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

.footer-meta {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 2;
}

.footer-meta a {
  color: var(--muted);
}

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

.icp {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.icp .sep {
  color: var(--line);
}

.gov-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.gov-badge .police {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  display: inline-block;
  background: var(--accent);
  border-radius: 3px;
  position: relative;
}

/* ===== 响应式 ===== */
@media (max-width: 600px) {
  .nav {
    padding: 14px 18px;
  }
  .nav-links {
    gap: 16px;
  }
  .hero {
    padding: 52px 0 40px;
  }
  .post-card {
    padding: 22px;
  }
  .about {
    padding: 24px;
  }
  .article-body pre {
    padding: 14px 16px;
    font-size: 0.84rem;
  }
  .post-nav {
    flex-direction: column;
    gap: 4px;
  }
  .post-nav .next {
    text-align: left;
  }
}

/* ===== 尊重「减少动态效果」偏好 ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
