:root {
  --bg: #0c0e10;
  --bg-elev: #121418;
  --text: #e6e6e6;
  --muted: #a0a0a0;
  --accent: #6ea8fe;
  --accent-2: #b388ff;
  --border: #22252b;
  --hover: #1a1f24;
  --shadow: 0 8px 24px rgba(0, 0, 0, .4);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.sidebar-header h1 {
  margin: 0 0 8px 0;
  font-size: 20px;
  letter-spacing: .5px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0a0a;
  border: none;
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.btn:active {
  transform: translateY(1px);
}

.search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1216;
  color: var(--text);
  outline: none;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

/* TOC */
.toc {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section {
  background: #0f1216;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
}

.section-header:hover {
  background: var(--hover);
}

.section-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.section-count {
  color: var(--muted);
  font-size: 12px;
  margin-left: auto;
}

.section-list {
  max-height: 0;
  overflow: hidden;
  transition: max-height .24s ease;
  border-top: 1px solid var(--border);
}

.section.open .section-list {
  max-height: 600px;
}

.section-list .item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  border-top: 1px solid rgba(255, 255, 255, .02);
}

.section-list .item:hover {
  background: #12161b;
}

.section-list .item.active {
  background: #18202a;
  border-left: 3px solid var(--accent);
}

/* Content */
.content {
  padding: 24px clamp(16px, 3vw, 48px);
}

.doc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: linear-gradient(0deg, rgba(12, 14, 16, 0), var(--bg) 60%);
  padding: 8px 0 12px 0;
  backdrop-filter: blur(4px);
  z-index: 5;
}

.breadcrumb {
  color: var(--muted);
  font-size: 14px;
}

.icon-btn {
  background: #11151a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.article {
  background: #0f1216;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 2.5vw, 28px);
  min-height: 60vh;
  line-height: 1.65;
}

/* Markdown body tweaks */
.markdown-body h1,
h2,
h3 {
  border-bottom: 1px dashed rgba(255, 255, 255, .06);
  padding-bottom: .3em;
}

.markdown-body pre {
  background: #0b0e12 !important;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
}

.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: #0d1014;
}

.empty {
  color: var(--muted);
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid #2a2f36;
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
  display: inline-block;
  margin-right: 8px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Footer */
.sidebar-footer {
  margin-top: auto;
  color: var(--muted);
}

/* Responsive */
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }
}

.katex {
  color: #f0f0f0;
}

.katex-display {
  margin: 1em 0;
}

/* 代码块容器：定位工具按钮与徽标 */
.markdown-body pre.code-block {
  position: relative;
  /* 用于定位右上角按钮/徽标 */
  padding-top: 40px;
  /* 预留顶部空间放按钮与语言徽标 */
}

/* 复制按钮 */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid var(--border);
  background: #11151a;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  opacity: .0;
  /* 初始隐藏，悬浮时出现 */
  transition: opacity .18s ease, transform .1s ease;
  box-shadow: var(--shadow);
}

.markdown-body pre.code-block:hover .copy-btn {
  opacity: 1;
}

.copy-btn:active {
  transform: translateY(1px);
}

.copy-btn.copied {
  border-color: #2e7d32;
  background: #0f2a14;
}

/* 语言徽标 */
.code-lang {
  position: absolute;
  top: 8px;
  left: 12px;
  font-size: 12px;
  color: var(--muted);
  background: #0b0e12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  text-transform: lowercase;
  pointer-events: none;
}

/* 让 highlight.js 主题在你当前配色下更清晰 */
.hljs {
  color: var(--text);
  background: transparent;
  /* 我们用 pre 的背景 */
}
