:root {
  --bg: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --teal: #0d9488;
  --teal-soft: #f0fdfa;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --inline-code-bg: #f1f5f9;
  --inline-code-text: #334155;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 12px;
}

[data-theme="dark"] {
  --bg: #0b0f19;
  --bg-subtle: #111827;
  --bg-card: #131b2e;
  --border: #1e293b;
  --border-strong: #334155;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.14);
  --teal: #2dd4bf;
  --teal-soft: rgba(45, 212, 191, 0.12);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.12);
  --code-bg: #060911;
  --code-text: #e2e8f0;
  --inline-code-bg: #1e293b;
  --inline-code-text: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Inter", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.78;
  font-size: 15.5px;
  -webkit-font-smoothing: antialiased;
}

/* Unified Sticky Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 56px;
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.06em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  border: none;
}
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.nav-group {
  display: flex;
  align-items: center;
  gap: 20px;
}
.nav-link {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border: none;
  transition: color 0.15s ease;
}
.nav-link:hover,
.nav-link.active {
  color: var(--text);
}
.nav-link.active {
  font-weight: 650;
}
.theme-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 5px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.theme-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

/* Page Containers */
.container-narrow {
  max-width: 860px;
  margin: 0 auto;
  padding: 48px 24px 88px;
}
.layout {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 88px;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 52px;
}
.layout.no-toc {
  grid-template-columns: minmax(0, 800px);
  justify-content: center;
}

/* Sidebar TOC */
.toc {
  position: sticky;
  top: 76px;
  align-self: start;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  font-size: 13px;
}
.toc-title {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.toc a {
  display: block;
  padding: 5px 10px;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-bottom: none;
  border-radius: 0 6px 6px 0;
  line-height: 1.45;
}
.toc a.toc-sub { padding-left: 20px; font-size: 12.5px; }
.toc a:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

/* Typography & Hero */
article { min-width: 0; }
.hero {
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 11px;
  border-radius: 999px;
  margin-bottom: 14px;
}
h1 {
  font-size: 30px;
  line-height: 1.28;
  letter-spacing: -0.025em;
  font-weight: 800;
  margin-bottom: 14px;
  color: var(--text);
}
.lead {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.75;
}
.meta-row {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.tag {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 9px;
  border-radius: 999px;
}
.tag.teal { color: var(--teal); background: var(--teal-soft); }

article h2 {
  font-size: 21px;
  font-weight: 750;
  letter-spacing: -0.02em;
  margin: 42px 0 14px;
  padding-top: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.sec-num {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
article h3 { font-size: 17.5px; font-weight: 700; margin: 28px 0 10px; color: var(--text); }
article h4 { font-size: 16px; font-weight: 700; margin: 24px 0 8px; color: var(--text); }
article h5 { font-size: 15px; font-weight: 650; margin: 18px 0 6px; color: var(--text); }
p { margin-bottom: 14px; color: var(--text-secondary); }
strong { color: var(--text); font-weight: 650; }
a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
a:hover { border-bottom-color: var(--accent); }
ul, ol { padding-left: 22px; margin-bottom: 16px; color: var(--text-secondary); }
li { margin-bottom: 7px; }
blockquote {
  border-left: 3px solid var(--accent);
  background: var(--bg-subtle);
  padding: 12px 18px;
  border-radius: 0 10px 10px 0;
  margin: 16px 0 20px;
  color: var(--text-secondary);
}
blockquote p:last-child { margin-bottom: 0; }
hr { border: none; border-top: 1px solid var(--border); margin: 32px 0; }
article img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 18px auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* Inline & Block Code */
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.87em;
  background: var(--inline-code-bg);
  color: var(--inline-code-text);
  padding: 2px 6px;
  border-radius: 5px;
}
.code-wrap {
  position: relative;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 16px 0 22px;
  overflow-x: auto;
}
.code-wrap pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13.2px;
  line-height: 1.62;
  white-space: pre;
}
.code-wrap code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}
.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.copy-btn:hover { background: rgba(255, 255, 255, 0.22); color: #fff; }

/* Callouts, Tables, Cards, Diagrams */
.callout {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 20px 0 24px;
}
.callout.warn, .callout.amber { border-left-color: var(--amber); background: var(--amber-soft); }
.callout.teal { border-left-color: var(--teal); background: var(--teal-soft); }
.callout-title { font-size: 13.5px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.callout p:last-child { margin-bottom: 0; }

.table-wrap {
  overflow-x: auto;
  margin: 18px 0 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 16px 0 22px; }
.table-wrap table { margin: 0; }
th {
  text-align: left;
  background: var(--bg-subtle);
  color: var(--text);
  font-weight: 650;
  padding: 11px 15px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 11px 15px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }

.steps-grid, .grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 20px 0 26px;
}
.step-card, .pill-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.step-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.step-badge {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 6px;
}
.step-cmd { font-family: ui-monospace, monospace; font-size: 13.5px; font-weight: 700; color: var(--text); }
.step-card p, .pill-card p { font-size: 13.8px; margin-bottom: 0; }
.pill-card h4 { font-size: 15px; font-weight: 700; color: var(--text); margin: 0 0 6px; }

.diagram-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 22px 0 26px;
}
.diagram-caption { text-align: center; font-size: 12.5px; color: var(--text-muted); margin-top: 10px; }

.timeline {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0 26px;
}
.tl-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--teal);
  border-radius: 10px;
  padding: 14px;
}
.tl-day { font-size: 12px; font-weight: 700; color: var(--teal); font-family: ui-monospace, monospace; margin-bottom: 6px; }
.tl-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.tl-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.55; }

/* Index & Archive Lists */
.search-bar { margin: 24px 0 28px; }
.search-input {
  width: 100%;
  padding: 11px 16px;
  font-size: 14.5px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text);
  outline: none;
}
.search-input:focus { border-color: var(--accent); }

.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 34px 0 14px;
}
.card-list { display: grid; gap: 14px; }
.card {
  display: block;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 14px;
  padding: 20px 24px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.card-title {
  font-size: 18px;
  font-weight: 750;
  color: var(--text);
  line-height: 1.38;
  margin-bottom: 6px;
}
.card-desc { font-size: 14px; color: var(--text-secondary); line-height: 1.65; }

.year-group { margin-bottom: 32px; }
.year-heading {
  font-size: 19px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.archive-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  border-bottom: none;
  transition: background 0.15s ease;
}
.archive-row:hover { background: var(--bg-subtle); }
.archive-title { font-size: 15px; font-weight: 600; color: var(--text); }
.archive-row:hover .archive-title { color: var(--accent); }
.archive-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.post-nav {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 14px;
}
.refs {
  margin-top: 44px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
}
.empty { display: none; text-align: center; padding: 44px 0; color: var(--text-muted); }

/* About Card */
.about-card {
  display: flex;
  align-items: center;
  gap: 24px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 28px;
}
.about-avatar {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
}
.about-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.link-pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  text-decoration: none;
}
.link-pill:hover { border-color: var(--accent); color: var(--accent); }

/* Footer */
.site-footer {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; gap: 20px; }
  .toc { display: none; }
  .steps-grid, .grid-2, .timeline { grid-template-columns: 1fr; }
  .about-card { flex-direction: column; text-align: center; }
  .about-links { justify-content: center; }
  .archive-row { flex-direction: column; gap: 4px; }
}
