
:root {
  --bg: #141317;
  --panel: #1c1a20;
  --panel-2: #242229;
  --elevated: #2c2930;
  --text: #eae7e1;
  --text-2: #b8b3ab;
  --muted: #7a756f;
  --accent: #d4a373;
  --accent-2: #eacda3;
  --border: #2e2b33;
  --code-bg: #1a181f;
}
[data-theme="light"] {
  --bg: #f7f5f2;
  --panel: #ffffff;
  --panel-2: #f0eeeb;
  --elevated: #ffffff;
  --text: #1a1a1a;
  --text-2: #4a4a4a;
  --muted: #7a7a7a;
  --accent: #b07d4b;
  --accent-2: #8f5e2d;
  --border: #e0ddd8;
  --code-bg: #f5f2ee;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont,
               "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); text-decoration: underline; }

/* ---- 细滚动条（6px） ---- */
* { scrollbar-width: thin; scrollbar-color: var(--panel-2) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--panel-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-2); }

/* ---- 整体布局：侧栏 + 右侧查看区 ---- */
body.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 16px;
  overflow-y: auto;
  transition: width 0.18s ease, padding 0.18s ease, opacity 0.12s ease;
}
body.sidebar-collapsed .sidebar {
  width: 0; padding: 18px 0; opacity: 0; pointer-events: none;
}

.site-title { font-size: 17px; font-weight: 600; margin: 0 0 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.search-box { position: relative; margin-bottom: 16px; }
.search-box input {
  width: 100%; padding: 9px 11px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px;
}
.search-box input:focus { outline: none; border-color: var(--accent); }
.search-results {
  list-style: none; margin: 6px 0 0; padding: 0;
  position: absolute; left: 0; right: 0;
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: 8px; max-height: 320px; overflow-y: auto;
  z-index: 10; display: none;
}
.search-results li a { display: block; padding: 8px 11px; font-size: 13px; color: var(--text); }
.search-results li a:hover { background: var(--panel-2); }
.search-results li a strong { color: var(--accent); font-weight: 600; }
.download-all {
  display: block; margin-bottom: 16px; padding: 9px 11px;
  text-align: center; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; white-space: nowrap;
}
.download-all:hover { background: var(--elevated); border-color: var(--accent); }
.tree { white-space: nowrap; }
.tree details { margin-left: 4px; }
.tree summary {
  cursor: pointer; padding: 5px 7px; border-radius: 5px; font-size: 14px;
  color: var(--text-2); list-style: none;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary:before { content: "▸ "; font-size: 11px; color: var(--muted); }
.tree details[open] > summary:before { content: "▾ "; }
.tree summary:hover { background: var(--panel-2); color: var(--text); }
.tree .tree-children { margin-left: 14px; border-left: 1px dashed var(--border); padding-left: 8px; }
.tree .file-link {
  display: block; padding: 5px 7px; font-size: 13.5px; border-radius: 5px;
  color: var(--text); cursor: pointer;
}
.tree .file-link:hover { background: var(--panel-2); }
.tree .file-link.active {
  background: var(--panel-2);
  color: var(--accent);
  box-shadow: inset 2px 0 0 var(--accent);
  font-weight: 600;
}

/* ---- 右侧查看区 ---- */
.viewer { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.viewer-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#sidebar-toggle {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 14px;
  flex-shrink: 0;
}
#sidebar-toggle:hover { background: var(--panel-2); border-color: var(--accent); }
.viewer-title-wrap { min-width: 0; flex: 1; display: flex; align-items: baseline; gap: 8px; }
.viewer-breadcrumb {
  font-size: 12px; color: var(--muted); white-space: nowrap; flex-shrink: 0;
}
.viewer-breadcrumb:not(:empty)::after { content: "›"; margin-left: 8px; color: var(--muted); }
.viewer-title-wrap h1 {
  font-size: 16px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}

.welcome-hint { padding: 48px; color: var(--muted); font-size: 15px; }
.welcome-hint p { max-width: 520px; line-height: 1.8; }

.columns { flex: 1; display: flex; min-height: 0; }
.column {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  border-right: 1px solid var(--border);
}
.column:last-child { border-right: none; }
.column-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 16px; border-bottom: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-2); flex-shrink: 0;
}
.icon-actions { display: flex; gap: 6px; }
.icon-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  width: 28px; height: 28px; border-radius: 7px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--accent); color: var(--accent); }
.icon-btn svg { width: 15px; height: 15px; }

/* 纯 CSS 悬浮提示 */
.icon-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%);
  background: var(--elevated); color: var(--text); padding: 4px 8px;
  border: 1px solid var(--border); border-radius: 5px;
  font-size: 11px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 0.1s ease; z-index: 20;
}
.icon-btn[data-tooltip]:hover::after { opacity: 0.98; }
/* 顶部栏按钮的提示往下弹，避免被视口顶部裁切 */
.icon-btn.tip-below[data-tooltip]::after { bottom: auto; top: 130%; }

/* ---- 渲染后的 Markdown 内容区 ---- */
.pane-content {
  flex: 1; overflow-x: hidden; overflow-y: auto; min-height: 0; margin: 0; padding: 32px 36px;
  background: var(--bg);
  font-size: 15px; line-height: 1.8;
}
.pane-content.placeholder { color: var(--muted); }
.pane-content.loading { color: var(--muted); }
.pane-content.error { color: #e57373; }

.prose { color: var(--text); overflow-wrap: anywhere; word-break: break-word; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  color: var(--text); font-weight: 600; line-height: 1.35; margin-top: 1.8em; margin-bottom: 0.7em;
}
.prose h1 { font-size: 28px; padding-bottom: 0.4em; border-bottom: 1px solid var(--border); }
.prose h2 { font-size: 22px; padding-bottom: 0.3em; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 19px; }
.prose h4 { font-size: 16px; color: var(--text-2); }
.prose p { margin: 0.9em 0; }
.prose ul, .prose ol { margin: 0.8em 0; padding-left: 1.6em; }
.prose li { margin: 0.35em 0; }
.prose li > p { margin: 0.3em 0; }
.prose blockquote {
  margin: 1.2em 0; padding: 0.6em 1em;
  border-left: 3px solid var(--accent);
  background: var(--panel); border-radius: 0 6px 6px 0;
  color: var(--text-2);
}
.prose blockquote p:first-child { margin-top: 0; }
.prose blockquote p:last-child { margin-bottom: 0; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.prose code {
  background: var(--panel-2); color: var(--accent-2);
  padding: 2px 6px; border-radius: 4px; font-size: 0.9em;
  font-family: SF Mono, Menlo, Consolas, "PingFang SC", monospace;
}
.prose pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; overflow-x: auto; white-space: pre;
  margin: 1.1em 0;
}
.prose pre code {
  background: transparent; color: var(--text);
  padding: 0; font-size: 13px; line-height: 1.7;
  white-space: pre; overflow-wrap: normal; word-break: normal;
}
.prose table {
  width: 100%; border-collapse: collapse; margin: 1.2em 0;
  font-size: 14px;
}
.prose th, .prose td {
  border: 1px solid var(--border); padding: 8px 12px; text-align: left;
  overflow-wrap: anywhere; word-break: break-word;
}
.prose th { background: var(--panel); font-weight: 600; }
.prose tr:nth-child(even) { background: rgba(255,255,255,0.02); }
.prose strong { color: var(--text); font-weight: 600; }
.prose em { color: var(--text-2); }
.prose a { color: var(--accent); }
.prose a:hover { color: var(--accent-2); }
.prose img { max-width: 100%; border-radius: 6px; }
.prose .table-wrap { overflow-x: auto; margin: 1.2em 0; }
.prose .table-wrap > table { margin: 0; }

/* 空状态与提示 */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 16px; font-size: 13px;
  opacity: 0; transform: translateY(10px); transition: all 0.2s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: #e57373; color: #e57373; }

/* ---- 主题切换 / 联动滚动：统一为图标按钮，状态用图标切换 ---- */
.theme-toggle { margin-left: auto; font-size: 16px; }
.sync-toggle { font-size: 15px; }
.sync-toggle .ic-off { display: none; }
.sync-toggle.is-off .ic-on { display: none; }
.sync-toggle.is-off .ic-off { display: inline; }

/* ---- 每栏底部目录 + 返回顶部 ---- */
.column { position: relative; }
.column-fabs {
  position: absolute;
  right: 16px; bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
}
.fab {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.28);
  font-size: 12px;
  line-height: 1;
  transition: transform 0.12s ease, border-color 0.15s ease, color 0.15s ease;
}
.fab svg {
  width: 16px; height: 16px;
}
.fab:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
}
.fab.top-fab { font-size: 14px; }

.column-toc {
  position: absolute;
  right: 16px; bottom: 102px;
  width: 220px;
  max-height: 44vh;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.32);
  z-index: 25;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.column-toc.open { display: flex; }
.column-toc-header {
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--text);
}
.column-toc .toc-list {
  list-style: none; margin: 0; padding: 5px 0;
  overflow-y: auto;
  max-height: calc(44vh - 38px);
}
.column-toc .toc-empty { padding: 9px 13px; color: var(--muted); font-size: 12px; }
.column-toc .toc-item { line-height: 1.45; }
.column-toc .toc-item a {
  display: block;
  padding: 4px 13px;
  color: var(--text-2);
  text-decoration: none;
  border-left: 2px solid transparent;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px;
}
.column-toc .toc-item a:hover { color: var(--accent); background: var(--panel-2); }
.column-toc .toc-h1 a { font-weight: 600; color: var(--text); }
.column-toc .toc-h2 a { padding-left: 21px; }
.column-toc .toc-h3 a { padding-left: 29px; font-size: 11.5px; }

@media (max-width: 900px) {
  .columns { flex-direction: column; }
  .column { border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar { position: fixed; z-index: 30; height: 100vh; }
  .pane-content { padding: 20px; }
  .column-fabs { right: 12px; bottom: 12px; }
  .column-toc { right: 12px; bottom: 108px; width: 180px; }
}
