:root {
  --bg: #f6f3ec;
  --surface: #fffdf7;
  --surface-2: #f1ece0;
  --ink: #1c2230;
  --muted: #6b7280;
  --line: #d8d2c2;
  --accent: #2f6f73;
  --accent-light: #d8e8e9;
  --warn: #b54708;
  --highlight: #ffe9a8;
  --shadow: 0 8px 24px rgba(20, 24, 30, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Source Han Sans", "PingFang SC", "Microsoft YaHei", "Inter", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.bootstrap {
  display: grid;
  place-items: center;
  min-height: 100vh;
  text-align: center;
  padding: 40px;
  color: var(--muted);
}
.bootstrap.error { color: var(--warn); }

/* ── Three-column shell ─────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 400px;
  height: 100vh;
  overflow: hidden;
}

/* ── Left panel ─────────────────────────────────────────── */
.leftPanel {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
}
.leftBrand {
  padding: 16px 12px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--line);
}
.leftSearch {
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--line);
}
#conceptSearch {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: white;
}
.tabsHeader {
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.tabsEmpty {
  padding: 16px 10px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.tabsList {
  overflow-y: auto;
  flex: 1;
  padding: 4px 8px 8px;
}
.tabCard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background 80ms, border-color 80ms;
}
.tabCard:hover { background: var(--accent-light); border-color: var(--line); }
.tabCard.active {
  background: var(--accent-light);
  border-color: var(--accent);
}
.tabTitle {
  flex: 1;
  font-size: 15px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tabClose {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
}
.tabClose:hover { background: rgba(0,0,0,0.08); color: var(--ink); }

/* ── Entry area (middle) ────────────────────────────────── */
.entryArea {
  padding: 28px 15% 120px;
  overflow-y: auto;
  height: 100vh;
}
.conceptEntry.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--muted);
}
.emptyHint { max-width: 420px; }
.welcomeTitle {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 16px;
  letter-spacing: 0.02em;
}
.welcomeDesc {
  font-size: 14px;
  color: var(--ink);
  line-height: 1.8;
  margin: 0 0 20px;
}
.emptyHint p { margin: 4px 0; }
.emptyMuted { font-size: 12px; color: var(--muted); }

.entryHeader {
  margin-bottom: 24px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--accent);
}
.entryHeaderTop {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}
.entryTitles { flex: 1; min-width: 0; }
.entryHeader h2 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
}
.entryHeader .enName {
  color: var(--muted);
  font-style: italic;
  font-size: 15px;
}
.entryHeader .aliases {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}
.entryActions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  padding-top: 2px;
}
.actionBtn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: white;
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
}
.actionBtn:hover { background: var(--accent-light); }
.actionBtn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.entryMeta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 10px;
  font-size: 12px;
}
.pill {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--muted);
}
.evMeta { color: var(--muted); }
.reviewedBadge {
  padding: 2px 8px;
  border-radius: 4px;
  background: #e6f4ea;
  border: 1px solid #a8d5b0;
  color: #2d6a4f;
  font-size: 11px;
}

/* Code section */
.codeSection { background: var(--surface-2); border-radius: 8px; padding: 12px; }
.entryCode {
  font-family: "Cascadia Code", "Fira Code", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  color: var(--ink);
}

.wikiSection { margin-bottom: 22px; }
.sectionNote {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 6px;
}
.sectionBody p { margin: 0 0 8px; }
.sectionBody p:last-child { margin-bottom: 0; }
.wikiSection h3 {
  font-size: 15px;
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
}
.wikiSection p { margin: 0; color: var(--ink); }
.perspective {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  margin-bottom: 8px;
  border-radius: 0 6px 6px 0;
}
.perspective strong { display: none; }
.perspective p { font-size: 13px; color: var(--muted); }
.relatedChips { display: flex; flex-wrap: wrap; gap: 6px; }
.relatedChip {
  border: 1px solid var(--line);
  background: white;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--accent);
}
.relatedChip:hover { background: var(--accent-light); }
.relatedChip.dim { color: var(--muted); background: var(--surface-2); cursor: default; }
.relatedChip.backlink {
  border-color: #a3b8c0;
  color: #3a6b85;
  background: #eef4f7;
}
.relatedChip.backlink:hover { background: #d4e8f0; }

.evidenceList { display: flex; flex-direction: column; gap: 4px; }
.evidenceItem {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
}
.evidenceItem:hover { border-color: var(--accent); }
.evIdx { color: var(--muted); font-weight: 600; }
.evTitle { color: var(--ink); font-weight: 500; }
.evHeading { color: var(--muted); font-style: italic; }

/* ── Right panel (directory) ────────────────────────────── */
.rightPanel {
  background: var(--surface-2);
  border-left: 1px solid var(--line);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 8px 0 16px;
}
.rightPanel::-webkit-scrollbar { display: none; }
.dirGroup { margin-bottom: 8px; }
.dirLetter {
  padding: 6px 10px 3px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--surface-2);
  z-index: 1;
}
.dirItems {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 4px;
  padding: 2px 8px 4px;
}
.dirItem {
  display: inline-block;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font-size: 12px;
  color: var(--ink);
  transition: background 60ms, border-color 60ms;
  word-break: break-all;
  max-width: 100%;
}
.dirItem:hover { background: var(--accent-light); border-color: var(--line); }
.dirItem.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ── Progress panel ─────────────────────────────────────── */
.progressSlot {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 300px;
  z-index: 50;
}
.progressPanel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-size: 12px;
}
.progressPanel.idle { color: var(--muted); text-align: center; }
.progressTop {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-weight: 600;
}
.progressBar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}
.progressFill { height: 100%; background: var(--accent); transition: width 200ms; }
.progressMeta { display: flex; gap: 10px; color: var(--muted); font-size: 11px; }
.progressMeta .warn { color: var(--warn); }
.progressCurrent {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Source viewer overlay ──────────────────────────────── */
.sourceOverlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 30, 0.4);
  display: grid;
  place-items: center;
  z-index: 100;
}
.sourcePanel {
  background: var(--surface);
  width: min(880px, 92vw);
  max-height: 86vh;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.sourceHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.sourceHeader strong { font-size: 15px; }
.sourceMeta { color: var(--muted); font-size: 12px; margin-left: 8px; }
.sourceHeader button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 6px;
}
.sourceBody { overflow-y: auto; padding: 18px; flex: 1; }
.sourceBody pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Source Han Serif", "Songti SC", "SimSun", serif;
  font-size: 14px;
  line-height: 1.8;
  margin: 0;
}
.sourceBody mark {
  background: var(--highlight);
  padding: 1px 2px;
  border-radius: 2px;
}
.sourceFooter {
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
