/* ============================================================
   博客文章公共样式
   路径：style/blog-common.css
   引用：<link rel="stylesheet" href="../../style/blog-common.css">
   ============================================================ */

/* --- CSS 变量：亮色模式 --- */
:root {
  --color-bg: #fafaf9;
  --color-surface: #ffffff;
  --color-text: #1c1917;
  --color-text-secondary: #57534e;
  --color-text-muted: #a8a29e;
  --color-accent: #2563eb;
  --color-accent-light: #dbeafe;
  --color-border: #e7e5e4;
  --color-code-bg: #1e1e2e;
  --color-code-text: #cdd6f4;
  --color-highlight: #fef3c7;
  --color-red-bg: #fef2f2;
  --color-green-bg: #f0fdf4;
  --color-yellow-bg: #fefce8;
  --color-blue-bg: #eff6ff;
  --font-body: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
  --font-code: 'JetBrains Mono', 'Fira Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --max-width: 780px;
}

/* --- CSS 变量：暗色模式 --- */
[data-theme="dark"] {
  --color-bg: #0f0f11;
  --color-surface: #1a1a1f;
  --color-text: #e4e4e7;
  --color-text-secondary: #a1a1aa;
  --color-text-muted: #71717a;
  --color-accent: #60a5fa;
  --color-accent-light: #1e3a5f;
  --color-border: #2e2e35;
  --color-code-bg: #11111b;
  --color-code-text: #cdd6f4;
  --color-highlight: #422006;
  --color-red-bg: #1c1111;
  --color-green-bg: #0d1f12;
  --color-yellow-bg: #1c1a0e;
  --color-blue-bg: #0f1a2e;
}

/* --- Reset & Base --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* --- Fixed Action Buttons --- */
.fixed-btn {
  position: fixed;
  z-index: 100;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  transition: background 0.2s, border-color 0.2s, transform 0.15s, opacity 0.3s, visibility 0.3s;
  text-decoration: none;
  line-height: 1;
}
.fixed-btn:hover { transform: scale(1.08); border-color: var(--color-accent); background: var(--color-accent-light); }
.btn-home { top: 20px; left: 20px; }
.theme-toggle { top: 20px; right: 20px; }
.btn-backtop { bottom: 28px; right: 20px; opacity: 0; visibility: hidden; }
.btn-backtop.visible { opacity: 1; visibility: visible; }

/* --- Article Container --- */
.article {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 60px 24px 120px;
}

/* --- Hero Section --- */
.hero {
  text-align: center;
  padding: 80px 0 60px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 60px;
}
.hero h1 {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.4;
  color: var(--color-text);
  margin-bottom: 16px;
}
.hero .subtitle {
  font-size: 1rem;
  color: var(--color-text-muted);
  font-family: var(--font-sans);
}

/* --- Headings --- */
h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 72px;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--color-accent);
  color: var(--color-text);
  letter-spacing: 0.01em;
}
h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 48px;
  margin-bottom: 16px;
  color: var(--color-text);
}
h4 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--color-text);
}

/* --- Paragraphs --- */
p {
  margin-bottom: 20px;
}

/* --- Links --- */
a {
  color: var(--color-accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
a:hover {
  border-bottom-color: var(--color-accent);
}

/* --- Lists --- */
ul,
ol {
  margin-bottom: 20px;
  padding-left: 1.8em;
}
li {
  margin-bottom: 8px;
}
li::marker {
  color: var(--color-text-muted);
}

/* --- Blockquote --- */
blockquote {
  border-left: 3px solid var(--color-accent);
  padding: 12px 20px;
  margin: 24px 0;
  background: var(--color-blue-bg);
  border-radius: 0 6px 6px 0;
  font-style: normal;
  color: var(--color-text-secondary);
}

/* --- Inline Code --- */
code {
  font-family: var(--font-code);
  font-size: 0.88em;
  background: var(--color-accent-light);
  color: var(--color-accent);
  padding: 2px 6px;
  border-radius: 4px;
  word-break: break-word;
}

/* --- Code Blocks --- */
pre {
  margin: 24px 0;
  padding: 20px 24px;
  background: var(--color-code-bg);
  color: var(--color-code-text);
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.65;
  font-family: var(--font-code);
  position: relative;
}
pre code {
  background: none;
  color: inherit;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

/* --- Prism.js Syntax Highlighting (Catppuccin Mocha) --- */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata { color: #a6adc8; font-style: italic; }
.token.punctuation { color: #bac2de; }
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted { color: #fab387; }
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted { color: #a6e3a1; }
.token.operator,
.token.entity,
.token.url { color: #89dceb; }
.token.atrule,
.token.attr-value,
.token.keyword { color: #cba6f7; }
.token.function,
.token.class-name { color: #89b4fa; }
.token.regex,
.token.important,
.token.variable { color: #f9e2af; }
.token.type { color: #f9e2af; }
.token.decorator,
.token.annotation { color: #89dceb; font-style: italic; }
.token.string { color: #a6e3a1; }
.token.parameter { color: #fab387; }
.token.macro { color: #89dceb; }
.token.namespace { color: #f5c2e7; }
.token.plain-text { color: #cdd6f4; }

/* Prism line-highlight / line-numbers 插件兼容 */
pre[class*="language-"] { position: relative; }
code[class*="language-"] { text-shadow: none; }

/* 代码块语言标签 */
.code-lang-label {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 0.72rem;
  font-family: var(--font-sans);
  color: #585b70;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  pointer-events: none;
  user-select: none;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 0.92rem;
  font-family: var(--font-sans);
}
thead {
  background: var(--color-surface);
}
th {
  font-weight: 600;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 2px solid var(--color-border);
  color: var(--color-text);
}
td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-secondary);
}
tbody tr:hover {
  background: var(--color-blue-bg);
}

/* --- Mermaid Diagrams --- */
.mermaid-container {
  margin: 32px 0;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 24px 16px;
  overflow-x: auto;
}
.mermaid {
  font-family: var(--font-sans);
}
.mermaid-container .mermaid-label {
  display: block;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: 12px;
  font-family: var(--font-sans);
}

/* --- Strong / Emphasis --- */
strong {
  font-weight: 700;
  color: var(--color-text);
}

/* --- Flow Arrow Block --- */
.flow-arrow {
  text-align: center;
  font-family: var(--font-code);
  font-size: 0.95rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 16px 24px;
  margin: 24px 0;
  letter-spacing: 0.02em;
}

/* --- Callout --- */
.callout {
  padding: 16px 20px;
  border-radius: 8px;
  margin: 24px 0;
  font-family: var(--font-sans);
  font-size: 0.95rem;
}
.callout-red {
  background: var(--color-red-bg);
  border-left: 3px solid #ef4444;
}
.callout-green {
  background: var(--color-green-bg);
  border-left: 3px solid #22c55e;
}
.callout-yellow {
  background: var(--color-yellow-bg);
  border-left: 3px solid #eab308;
}
.callout-blue {
  background: var(--color-blue-bg);
  border-left: 3px solid #2563eb;
}

/* --- Section Divider --- */
.section-divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 60px 0;
}

/* --- Header TOC（文章顶部目录，1级 h2） --- */
.header-toc {
  margin: 0 0 48px;
  padding: 20px 24px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
}
.header-toc-title {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 12px;
  font-family: var(--font-sans);
}
.header-toc ol {
  list-style: none;
  counter-reset: header-toc-counter;
  padding-left: 0;
  margin: 0;
}
.header-toc ol li {
  counter-increment: header-toc-counter;
  margin-bottom: 0;
}
.header-toc ol li::before {
  content: counter(header-toc-counter) ".";
  color: var(--color-text-muted);
  font-weight: 500;
  margin-right: 4px;
  font-size: 0.82rem;
  font-family: var(--font-sans);
}
.header-toc a {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  line-height: 1.6;
  border-bottom: none;
  transition: color 0.2s;
}
.header-toc a:hover {
  color: var(--color-accent);
}

/* --- Sidebar TOC（浮动目录，2级 h2 + h3） --- */
.sidebar-toc {
  position: fixed;
  top: 80px;
  left: max(16px, calc((100vw - 780px) / 2 - 260px));
  width: 230px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 20px 18px;
  font-family: var(--font-sans);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-8px);
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
.sidebar-toc.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}
.sidebar-toc-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--color-border);
}
.sidebar-toc .toc-group {
  margin-bottom: 6px;
}
.sidebar-toc .toc-group-h2 {
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.sidebar-toc .toc-group-h2 .toc-num {
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 0.78rem;
  flex-shrink: 0;
}
.sidebar-toc .toc-group-h2 a {
  color: var(--color-text);
  font-size: 0.84rem;
  font-weight: 400;
  line-height: 1.5;
  border-bottom: none;
  transition: color 0.2s;
}
.sidebar-toc .toc-group-h2 a:hover {
  color: var(--color-accent);
}
.sidebar-toc .toc-group-h2 a.active {
  color: var(--color-accent);
  font-weight: 700;
}
.sidebar-toc .toc-h3-list {
  list-style: none;
  padding-left: 18px;
  margin: 2px 0 4px;
}
.sidebar-toc .toc-h3-list li {
  margin-bottom: 1px;
}
.sidebar-toc .toc-h3-list li::before {
  content: "";
}
.sidebar-toc .toc-h3-list a {
  color: var(--color-text-muted);
  font-size: 0.78rem;
  line-height: 1.5;
  border-bottom: none;
  display: inline;
  transition: color 0.2s;
}
.sidebar-toc .toc-h3-list a:hover {
  color: var(--color-accent);
}
.sidebar-toc .toc-h3-list a.active {
  color: var(--color-accent);
  font-weight: 600;
}

/* 移动端隐藏浮动目录 */
@media (max-width: 1100px) {
  .sidebar-toc {
    display: none;
  }
  .header-toc ol {
    flex-direction: column;
    gap: 4px 0;
  }
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .article {
    padding: 32px 16px 80px;
  }
  .hero {
    padding: 48px 0 40px;
  }
  .hero h1 {
    font-size: 1.6rem;
  }
  h2 {
    font-size: 1.3rem;
    margin-top: 48px;
  }
  h3 {
    font-size: 1.1rem;
  }
  pre {
    padding: 16px;
    font-size: 0.8rem;
  }
  table {
    font-size: 0.82rem;
  }
  th,
  td {
    padding: 8px 10px;
  }
  .theme-toggle {
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
}

/* --- Print --- */
@media print {
  body {
    background: white;
  }
  .article {
    max-width: 100%;
    padding: 0;
  }
  .hero {
    padding: 20px 0;
  }
  h2 {
    page-break-before: auto;
  }
  .mermaid-container {
    border: 1px solid #ddd;
  }
  .theme-toggle {
    display: none;
  }
}
