:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e5e4e0;
  --text: #1f2328;
  --text-secondary: #59636e;
  --text-muted: #8a939c;
  --accent: #d66b3f;
  --accent-soft: #f7ede7;
  --sidebar-bg: #26282b;
  --sidebar-text: #c9cdd2;
  --sidebar-muted: #8a8f96;
  --sidebar-active: #ffffff;
  --sidebar-hover: #33363a;
  --code-bg: #f6f8fa;
  --shadow: 0 2px 12px rgba(31, 35, 40, 0.08);
  --radius: 8px;
  --sidebar-w: 300px;
  --header-h: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  overflow-y: auto;
  z-index: 40;
  display: flex;
  flex-direction: column;
  transition: transform 0.28s ease;
}

.sidebar-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  position: sticky;
  top: 0;
  background: var(--sidebar-bg);
  z-index: 2;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--sidebar-text);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 17px; color: #fff; letter-spacing: 0.5px; }
.brand-text small { font-size: 12px; color: var(--sidebar-muted); margin-top: 2px; }

.doc-list { padding: 10px 0 14px; border-bottom: 1px solid rgba(255,255,255,0.08); }

.doc-group-label {
  padding: 12px 22px 5px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}

.doc-link {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 22px 7px 22px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.45;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.doc-link:hover { background: var(--sidebar-hover); color: #fff; }

.doc-link.active {
  background: rgba(214,107,63,0.16);
  color: var(--sidebar-active);
  border-left-color: var(--accent);
}

.doc-num {
  font-size: 11px;
  color: var(--sidebar-muted);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  flex-shrink: 0;
  min-width: 22px;
}

.doc-link.active .doc-num { color: var(--accent); }
.doc-name { flex: 1; }

.toc-title {
  padding: 16px 22px 6px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}

.toc { padding: 0 0 30px; }

.toc-link {
  display: block;
  padding: 4px 22px;
  color: var(--sidebar-muted);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.5;
  border-left: 2px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
}

.toc-link:hover { color: #fff; }
.toc-link.lv2 { padding-left: 22px; }
.toc-link.lv3 { padding-left: 34px; font-size: 12.5px; }
.toc-link.lv4 { padding-left: 46px; font-size: 12px; }
.toc-link.active { color: var(--accent); border-left-color: var(--accent); }

/* ===== Main ===== */
.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  height: var(--header-h);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  z-index: 30;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right { margin-left: auto; }
.progress-text { font-size: 12px; color: var(--text-muted); }

.menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
}

.menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.content {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 36px 24px 60px;
}

.content-inner {
  width: 100%;
  max-width: 860px;
}

/* ===== Markdown Body ===== */
.markdown-body { animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.markdown-body > h1:first-child {
  font-size: 2em;
  line-height: 1.3;
  margin: 0 0 6px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.markdown-body h1 { font-size: 1.9em; margin: 2.2em 0 0.6em; line-height: 1.35; }
.markdown-body h2 {
  font-size: 1.5em;
  margin: 2em 0 0.6em;
  line-height: 1.4;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.markdown-body h3 { font-size: 1.22em; margin: 1.7em 0 0.5em; line-height: 1.45; }
.markdown-body h4 { font-size: 1.06em; margin: 1.5em 0 0.4em; line-height: 1.5; }
.markdown-body h5, .markdown-body h6 { font-size: 0.95em; margin: 1.3em 0 0.4em; }

.markdown-body p { margin: 0.8em 0; }

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}

.markdown-body a:hover { border-bottom-color: var(--accent); }

.markdown-body strong { font-weight: 650; }

.markdown-body blockquote {
  margin: 1.2em 0;
  padding: 12px 18px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #59473c;
}

.markdown-body blockquote p { margin: 0.3em 0; }

.markdown-body ul, .markdown-body ol { margin: 0.8em 0; padding-left: 1.8em; }
.markdown-body li { margin: 0.35em 0; }
.markdown-body li > ul, .markdown-body li > ol { margin: 0.2em 0; }

.markdown-body code {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
  background: #eef0f2;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: #b94a2e;
}

.markdown-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 1.1em 0;
  position: relative;
  line-height: 1.55;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 0.86em;
  color: var(--text);
}

.markdown-body .code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f1f3f4;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1.1em;
}

.markdown-body .code-header + pre {
  margin-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}

.code-lang { font-family: "SF Mono", Menlo, Consolas, monospace; text-transform: uppercase; letter-spacing: 0.5px; font-size: 11px; }

.copy-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 5px;
  padding: 2px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.copy-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.copy-btn.copied { background: #2da44e; color: #fff; border-color: #2da44e; }

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.2em 0;
  font-size: 0.94em;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.markdown-body thead th {
  background: #f1f3f4;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 9px 14px;
  vertical-align: top;
}

.markdown-body tbody tr:nth-child(even) { background: #fafaf8; }
.markdown-body tbody tr:hover { background: #f4f5f2; }

.markdown-body img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.2em auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: zoom-in;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

/* 图片占位 */
.img-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 1.2em 0;
  padding: 36px 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #fafaf8;
  color: var(--text-muted);
  text-align: center;
}

.img-placeholder .ph-icon {
  font-size: 26px;
  color: #c4c9cd;
  line-height: 1;
}

.img-placeholder .ph-text { font-size: 14px; color: var(--text-secondary); }
.img-placeholder .ph-name {
  font-size: 12px;
  color: var(--text-muted);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  word-break: break-all;
  max-width: 100%;
}

/* mermaid */
.mermaid {
  margin: 1.4em 0;
  text-align: center;
  overflow-x: auto;
}

.mermaid svg { max-width: 100%; height: auto; }

/* ===== Lightbox ===== */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,17,20,0.92);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 30px;
}

.lightbox.open { display: flex; }

.lightbox img {
  max-width: 94vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 30px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
}

.lightbox-close:hover { background: rgba(255,255,255,0.2); }

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 22px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ===== Scrollbar ===== */
.sidebar::-webkit-scrollbar, .content::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: #4a4d52; border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: #d2d5d8; border-radius: 4px; }

/* ===== Responsive ===== */
@media (max-width: 1080px) {
  :root { --sidebar-w: 280px; }
  .content { padding: 28px 20px 50px; }
}

@media (max-width: 860px) {
  .menu-btn { display: flex; }
  .sidebar { transform: translateX(-100%); width: 300px; }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.3); }
  .main-wrap { margin-left: 0; }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,17,20,0.5);
    z-index: 35;
    display: none;
  }
  .sidebar-overlay.open { display: block; }
  .content { padding: 22px 16px 46px; }
  .markdown-body { font-size: 15.5px; }
}

@media (max-width: 480px) {
  body { font-size: 15px; }
  .topbar { padding: 0 14px; }
  .markdown-body h1 { font-size: 1.6em; }
  .markdown-body h2 { font-size: 1.3em; }
  .markdown-body blockquote { padding: 10px 14px; }
  .markdown-body th, .markdown-body td { padding: 7px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .markdown-body, .sidebar { animation: none; transition: none; }
}
