:root, [data-theme="light"] {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-subtle: #f4f1ea;
  --text: #1c1917;
  --text-secondary: #44403c;
  --muted: #78716c;
  --border: #e7e5e4;
  --accent: #1d4ed8;
  --accent-soft: #eff6ff;
  --code-bg: #f5f5f4;
  --shadow: 0 2px 14px rgba(28, 25, 23, 0.04);
}
[data-theme="sepia"] {
  --bg: #f4ecd8;
  --surface: #fbf6ea;
  --surface-subtle: #efe4ca;
  --text: #2c221e;
  --text-secondary: #4a3b32;
  --muted: #7c6a5a;
  --border: #e2d5b8;
  --accent: #9a3412;
  --accent-soft: #f5e6d3;
  --code-bg: #efe5cf;
  --shadow: 0 2px 14px rgba(44, 34, 30, 0.05);
}
[data-theme="dark"] {
  --bg: #0c0e12;
  --surface: #14171f;
  --surface-subtle: #1c202b;
  --text: #e5e7eb;
  --text-secondary: #cbd5e1;
  --muted: #94a3b8;
  --border: #262b38;
  --accent: #60a5fa;
  --accent-soft: #1e293b;
  --code-bg: #1a1e29;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.28);
}
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --article-font: var(--font-sans);
  --article-size: 17px;
  --article-lh: 1.85;
}
[data-font="serif"] {
  --article-font: var(--font-serif);
}
[data-size="sm"] { --article-size: 15.5px; --article-lh: 1.8; }
[data-size="md"] { --article-size: 17px; --article-lh: 1.85; }
[data-size="lg"] { --article-size: 19px; --article-lh: 1.92; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Progress Bar */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent);
  z-index: 1000;
  transition: width 0.08s linear;
}

/* Sticky Top Nav */
.topbar {
  position: sticky;
  top: 0;
  z-index: 90;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.brand-link {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.brand-link:hover { text-decoration: none; color: var(--accent); }
.reader-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.ctrl-group {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.ctrl-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.24rem 0.55rem;
  font-size: 0.78rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all 0.12s ease;
}
.ctrl-btn:hover { color: var(--text); }
.ctrl-btn.active {
  background: var(--surface-subtle);
  color: var(--text);
  font-weight: 600;
}

/* Containers */
.container { max-width: 860px; margin: 0 auto; padding: 2.2rem 1.25rem 4.5rem; }
.reader-layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem 1.25rem 5rem;
  display: grid;
  grid-template-columns: minmax(0, 760px) 240px;
  gap: 2.5rem;
  justify-content: center;
  align-items: start;
}
.reader-layout.no-toc {
  grid-template-columns: minmax(0, 760px);
}
@media (max-width: 1024px) {
  .reader-layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 1.25rem 1rem 4rem;
  }
  .toc-sidebar { display: none; }
}

/* Homepage Header & Filter */
.site-header {
  padding-bottom: 1.5rem;
  margin-bottom: 1.6rem;
  border-bottom: 1px solid var(--border);
}
.site-title {
  font-size: 1.85rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  margin: 0 0 0.45rem;
}
.site-subtitle { color: var(--muted); margin: 0; font-size: 0.94rem; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.tabs { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.tab-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  padding: 0.38rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.86rem;
  transition: all 0.15s ease;
}
.tab-btn:hover { border-color: var(--accent); color: var(--accent); }
.tab-btn.active {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
  font-weight: 600;
}
.search-input {
  flex: 1;
  min-width: 210px;
  max-width: 300px;
  padding: 0.46rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }

/* Post Cards */
.post-list { display: grid; gap: 1rem; }
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.35rem 1.6rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.post-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  font-size: 0.81rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.badge {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.14rem 0.55rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.76rem;
}
.tag {
  background: var(--surface-subtle);
  color: var(--text-secondary);
  padding: 0.1rem 0.48rem;
  border-radius: 5px;
  font-size: 0.75rem;
}
.post-card h2 {
  margin: 0 0 0.45rem;
  font-size: 1.24rem;
  line-height: 1.4;
}
.post-card h2 a { color: var(--text); }
.post-card h2 a:hover { color: var(--accent); text-decoration: none; }
.post-card p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.93rem;
  line-height: 1.68;
}

/* Attachments */
.attach-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
  font-size: 0.82rem;
  color: var(--muted);
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.79rem;
  padding: 0.24rem 0.65rem;
  border-radius: 6px;
  background: var(--surface-subtle);
  color: var(--text);
  border: 1px solid var(--border);
  transition: border-color 0.12s ease;
}
.attach-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

/* Article Reader Surface */
.article-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.6rem 3rem;
  box-shadow: var(--shadow);
}
@media (max-width: 640px) {
  .article-box {
    padding: 1.5rem 1.2rem;
    border-radius: 12px;
  }
}
.article-title {
  margin: 0.55rem 0 0.85rem;
  font-size: 1.95rem;
  line-height: 1.35;
  letter-spacing: -0.015em;
  color: var(--text);
}
@media (max-width: 640px) {
  .article-title { font-size: 1.52rem; }
}
.article-summary-box {
  margin: 1.1rem 0 1.4rem;
  padding: 0.95rem 1.15rem;
  background: var(--surface-subtle);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  color: var(--text-secondary);
  font-size: 0.94rem;
  line-height: 1.7;
}
.article-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.4rem 0 1.8rem;
}

/* Mobile TOC */
.toc-mobile {
  display: none;
  margin: 0 0 1.5rem;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
}
.toc-mobile summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}
.toc-mobile ul {
  margin: 0.6rem 0 0;
  padding-left: 1.1rem;
}
.toc-mobile li { margin: 0.3rem 0; }
@media (max-width: 1024px) {
  .toc-mobile { display: block; }
}

/* Desktop Sticky TOC Sidebar */
.toc-sidebar {
  position: sticky;
  top: 4.5rem;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.83rem;
}
.toc-title {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 0.65rem;
}
.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.toc-list li { margin: 0.35rem 0; line-height: 1.45; }
.toc-list li.toc-h3 { padding-left: 0.85rem; font-size: 0.8rem; }
.toc-list a {
  color: var(--muted);
  display: block;
  padding: 0.12rem 0;
  transition: color 0.12s ease;
}
.toc-list a:hover, .toc-list a.active {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

/* Article Body Typography */
.article-content {
  font-family: var(--article-font);
  font-size: var(--article-size);
  line-height: var(--article-lh);
  color: var(--text);
  overflow-wrap: break-word;
}
.article-content p {
  margin: 0 0 1.25em;
  text-align: justify;
}
.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4 {
  font-family: var(--font-sans);
  color: var(--text);
  scroll-margin-top: 4.5rem;
  line-height: 1.4;
}
.article-content h2 {
  font-size: 1.36em;
  margin: 2.1em 0 0.75em;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border);
}
.article-content h3 {
  font-size: 1.15em;
  margin: 1.65em 0 0.55em;
}
.article-content ul, .article-content ol {
  margin: 0 0 1.25em;
  padding-left: 1.5em;
}
.article-content li { margin: 0.35em 0; }
.article-content blockquote {
  margin: 1.35em 0;
  padding: 0.75em 1.15em;
  border-left: 4px solid var(--accent);
  background: var(--surface-subtle);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}
.article-content blockquote p:last-child { margin-bottom: 0; }
.article-content pre {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1rem 1.1rem;
  border-radius: 10px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.86em;
  line-height: 1.65;
  margin: 1.3em 0;
}
.article-content code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  padding: 0.16em 0.4em;
  border-radius: 5px;
  font-size: 0.87em;
}
.article-content pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}
.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.55rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0.18rem 0.5rem;
  border-radius: 5px;
  cursor: pointer;
}
.copy-btn:hover { color: var(--text); border-color: var(--accent); }

/* Responsive Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 1.4em 0;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.article-content table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.6;
}
.article-content th, .article-content td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0.6rem 0.85rem;
  text-align: left;
  vertical-align: top;
}
.article-content th:last-child, .article-content td:last-child { border-right: none; }
.article-content tr:last-child td { border-bottom: none; }
.article-content th {
  background: var(--surface-subtle);
  font-weight: 600;
  color: var(--text);
}

/* Timestamp pill for video transcripts */
.ts-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.78em;
  padding: 0.08em 0.45em;
  margin-right: 0.35em;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  vertical-align: baseline;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 3.2rem 1.5rem;
  text-align: center;
  color: var(--muted);
}
.footer {
  margin-top: 3.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}
