:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #24292f;
  --muted: #6a737d;
  --accent: #2563eb;
  --accent-weak: #dbeafe;
  --mark: #fde68a;
  --hover: #f0f3f7;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
#book-select {
  max-width: 320px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
}
#search-form { display: flex; gap: 8px; margin-left: auto; }
#search-input {
  width: 320px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }
#search-form button {
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
#search-form button:hover { filter: brightness(1.08); }

#layout { flex: 1; display: flex; min-height: 0; }

#sidebar {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
}
#tabs { display: flex; border-bottom: 1px solid var(--border); flex: none; }
#tabs button {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
#tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-pane { display: none; flex: 1; min-height: 0; }
.tab-pane.active { display: block; }
.pane-body { height: 100%; overflow: auto; padding: 6px 4px 24px; }

/* 目录树 */
.tree ul { list-style: none; margin: 0; padding-left: 16px; }
.tree > ul { padding-left: 4px; }
.tree li { margin: 1px 0; }
.node-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: 5px;
  font-size: 13.5px;
  line-height: 1.4;
}
.node-row:hover { background: var(--hover); }
.node-row.active { background: var(--accent-weak); }
.caret {
  width: 16px;
  flex: none;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  font-size: 10px;
  transition: transform .15s;
}
.caret.open { transform: rotate(90deg); }
.caret.empty { visibility: hidden; }
.node-link {
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  word-break: break-all;
}
.node-link:hover { color: var(--accent); }
.children { display: none; }
.children.open { display: block; }

/* 索引 */
.index-list { list-style: none; margin: 0; padding: 0 8px; }
.index-list li { padding: 3px 6px; font-size: 13.5px; border-radius: 5px; }
.index-list li:hover { background: var(--hover); }
.index-list a { color: var(--text); text-decoration: none; cursor: pointer; }
.index-list a:hover { color: var(--accent); }

/* 搜索结果 */
.result-item { padding: 10px 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.result-item:hover { background: var(--hover); }
.result-title { font-size: 14px; font-weight: 600; color: var(--accent); word-break: break-all; }
.result-path { font-size: 11.5px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.result-snippet { font-size: 12.5px; color: #424a53; margin-top: 4px; line-height: 1.5; }
.result-snippet mark { background: var(--mark); padding: 0 1px; border-radius: 2px; }
.search-meta { padding: 8px 12px; font-size: 12.5px; color: var(--muted); }
.hint { padding: 16px 12px; font-size: 13px; color: var(--muted); line-height: 1.6; }
code {
  background: #eef1f5;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

#content { flex: 1; min-width: 0; background: #fff; }
#viewer { width: 100%; height: 100%; border: none; display: block; }

#empty-state {
  position: fixed;
  inset: 56px 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 10;
}
#empty-state.hidden { display: none; }
.empty-card { text-align: center; color: var(--muted); max-width: 480px; padding: 24px; }
.empty-icon { font-size: 42px; }
.empty-card h2 { margin: 12px 0 8px; color: var(--text); }
.empty-card p { line-height: 1.7; }

@media (max-width: 900px) {
  #sidebar { width: 260px; }
  #search-input { width: 160px; }
}
