/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* === Variables === */
:root {
  --c-bg: #fafafa;
  --c-text: #1a1a1a;
  --c-text-light: #666;
  --c-border: #e5e5e5;
  --c-accent: #2563eb;
  --c-code-bg: #f4f4f5;
  --c-card-bg: #fff;
  --width-main: 720px;
}

/* === Base === */
html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.8;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Header === */
header {
  position: sticky; top: 0; z-index: 10;
  background: rgba(250,250,250,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--c-border);
}
header .inner {
  max-width: var(--width-main);
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header .logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--c-text);
}
header nav a {
  margin-left: 28px;
  font-size: 14px;
  color: var(--c-text-light);
}
header nav a:hover { color: var(--c-text); text-decoration: none; }

/* === Responsive === */
@media (max-width: 640px) {
  header nav a { margin-left: 16px; font-size: 13px; }
}

/* === TOC Sidebar === */
.toc-sidebar {
  position: fixed;
  left: 0;
  top: 56px;
  height: calc(100vh - 56px);
  width: 40px;
  background: var(--c-card-bg);
  border-right: 1px solid var(--c-border);
  z-index: 20;
  transition: width .25s ease;
  overflow: hidden;
}
.toc-sidebar.open {
  width: 220px;
}

/* Toggle bar */
.toc-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 12px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
.toc-bar-icon {
  font-size: 16px;
  color: var(--c-text-light);
  flex-shrink: 0;
}
.toc-bar-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
  opacity: 0;
  transition: opacity .2s;
}
.toc-sidebar.open .toc-bar-label {
  opacity: 1;
}

/* Nav list */
.toc-nav {
  overflow-y: auto;
  height: calc(100% - 48px);
  scrollbar-width: thin;
}
.toc-list {
  list-style: none;
  padding: 10px 14px;
  opacity: 0;
  transition: opacity .2s;
}
.toc-sidebar.open .toc-list {
  opacity: 1;
}
.toc-list li {
  margin-bottom: 4px;
}
.toc-list li a {
  display: block;
  font-size: 13px;
  color: var(--c-text-light);
  text-decoration: none;
  line-height: 1.5;
  padding: 3px 6px;
  border-radius: 4px;
  transition: background .15s, color .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-list li a:hover {
  background: var(--c-code-bg);
  color: var(--c-text);
  text-decoration: none;
}
.toc-list li a.active {
  color: var(--c-accent);
  background: #eff6ff;
  font-weight: 500;
}

/* H3 indent */
.toc-list .toc-h3 a {
  padding-left: 18px;
  font-size: 12px;
  color: #999;
}
.toc-list .toc-h3 a::before {
  content: "\25E6 ";
  color: #ccc;
}

/* Responsive: hide sidebar on small screens */
@media (max-width: 1024px) {
  .toc-sidebar {
    display: none;
  }
}
