:root {
  color-scheme: light dark;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #666f7a;
  --line: #deded8;
  --accent: #0f766e;
  --accent-soft: #d7f1ee;
  --bg-secondary: #f0f3f2;
  --border-color: var(--line);
  --text-muted: var(--muted);
  --bg-hover: #f1f6f5;
  --badge-bg: #dfe6e3;
  --badge-text: #3f514d;
  --scrollbar-thumb: #b9c5c1;
  --scrollbar-track: transparent;
  --cat-header-bg: #e7f0ef;
  --accent-color: var(--accent);
  --bg-primary: var(--panel);
  --text-primary: var(--ink);
  --tag-bg: #e5e7eb;
  --tag-text: #374151;
  --tag-bg-hover: #d1d5db;
  --popover-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181a1b;
    --panel: #202324;
    --ink: #ecefed;
    --muted: #aab4b0;
    --line: #363c3a;
    --accent: #5ee0cf;
    --accent-soft: #183d39;
    --bg-secondary: #242928;
    --bg-hover: #232d2b;
    --badge-bg: #313937;
    --badge-text: #d7e3df;
    --scrollbar-thumb: #4b5652;
    --scrollbar-track: transparent;
    --cat-header-bg: #263331;
    --bg-primary: #202324;
    --text-primary: #ecefed;
    --tag-bg: #333b39;
    --tag-text: #d7e3df;
    --tag-bg-hover: #46514e;
    --popover-bg: #202324;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: var(--accent); text-decoration-thickness: .08em; text-underline-offset: .2em; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 22px 18px;
}
.brand {
  font-weight: 760;
  font-size: 18px;
  margin-bottom: 16px;
}
#search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--panel);
  color: var(--ink);
}
#search-results {
  display: grid;
  gap: 6px;
  margin: 10px 0 18px;
}
.search-hit {
  display: block;
  padding: 7px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
}
nav h2 {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}
.nav-category {
  margin-bottom: 4px;
}
.nav-category summary {
  cursor: pointer;
  padding: 6px 8px;
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 4px;
  color: var(--ink);
  list-style: none;
}
.nav-category summary::-webkit-details-marker { display: none; }
.nav-category summary:hover {
  background: var(--bg-hover, rgba(255,255,255,0.05));
}
.nav-badge {
  background: var(--badge-bg, #e0e0e0);
  color: var(--badge-text, #555);
  font-size: 0.75rem;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.nav-link {
  display: block;
  padding: 7px 8px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
}
.nav-link:hover, .nav-link.active {
  background: var(--accent-soft);
}
main {
  min-width: 0;
  padding: 42px clamp(24px, 6vw, 72px);
}
article {
  max-width: 920px;
}
article.index-page {
  max-width: 1280px;
}
h1, h2, h3 {
  line-height: 1.25;
}
h1 {
  margin: 0 0 20px;
  font-size: clamp(30px, 5vw, 48px);
}
h2 {
  margin-top: 38px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
h3 { margin-top: 26px; }
p, li { max-width: 78ch; }
code {
  background: #ecece7;
  border-radius: 4px;
  padding: .12em .32em;
}
pre {
  overflow: auto;
  padding: 16px;
  border-radius: 8px;
  background: #202124;
  color: #f8f8f2;
}
pre code {
  background: transparent;
  padding: 0;
}
.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 20px 0 28px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.meta dt {
  color: var(--muted);
  font-weight: 700;
}
.meta dd {
  margin: 0;
}
.wiki-stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 22px 0 0.75rem; }
.stat-item { padding: 8px 16px; border: 1px solid var(--border-color, #dee2e6); border-radius: 8px; background: var(--panel); text-align: center; cursor: pointer; transition: background 0.15s; }
.stat-item:hover { background: var(--bg-hover, #f5f7fa); }
.stat-total { font-weight: 700; border-color: var(--accent-color, #3b82f6); }
.stat-number { display: block; font-size: 1.4rem; line-height: 1.1; font-weight: 700; }
.stat-label { display: block; margin-top: 4px; color: var(--text-muted, #6c757d); font-size: 0.75rem; }
.index-intro { color: var(--muted); }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 14px; background: var(--bg-secondary, #f8f9fa); border: 1px solid var(--border-color, #dee2e6); border-radius: 8px; margin-top: 0.75rem; }
.filter-group { display: flex; align-items: center; gap: 4px; }
.filter-search-group { flex: 1 1 220px; }
.filter-group label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted, #6c757d); white-space: nowrap; }
.filter-search { padding: 6px 10px; border: 1px solid var(--border-color, #dee2e6); border-radius: 6px; font-size: 0.8rem; width: 220px; outline: none; background: var(--bg-primary, #fff); color: var(--text-primary, #333); }
.filter-search:focus { border-color: var(--accent-color, #3b82f6); box-shadow: 0 0 0 2px rgba(59,130,246,0.15); }
.filter-select { padding: 5px 8px; border: 1px solid var(--border-color, #dee2e6); border-radius: 6px; font-size: 0.8rem; background: var(--bg-primary, #fff); color: var(--text-primary, #333); cursor: pointer; }
.filter-reset-btn { padding: 5px 12px; border: 1px solid var(--border-color, #dee2e6); border-radius: 6px; font-size: 0.75rem; background: transparent; cursor: pointer; color: var(--text-muted, #6c757d); }
.filter-reset-btn:hover { background: var(--bg-hover, #eee); }
.active-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.unified-table-container { max-height: 75vh; overflow-y: auto; overflow-x: auto; border: 1px solid var(--border-color, #dee2e6); border-radius: 8px; margin-top: 0.5rem; background: var(--panel); scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb, #c1c1c1) var(--scrollbar-track, transparent); }
.unified-table-container::-webkit-scrollbar { width: 8px; height: 8px; }
.unified-table-container::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb, #c1c1c1); border-radius: 4px; }
.unified-table-container::-webkit-scrollbar-track { background: var(--scrollbar-track, transparent); }
.wiki-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; line-height: 1.5; table-layout: fixed; }
.wiki-table thead { background: var(--bg-secondary, #f8f9fa); position: sticky; top: 0; z-index: 3; }
.wiki-table th { text-align: left; padding: 10px 12px; font-weight: 600; border-bottom: 2px solid var(--border-color, #dee2e6); white-space: nowrap; cursor: pointer; user-select: none; }
.wiki-table th:hover { background: var(--bg-hover, #e9ecef); }
.wiki-table th .sort-arrow { margin-left: 4px; opacity: 0.4; font-size: 0.7em; }
.wiki-table th.sorted-asc .sort-arrow, .wiki-table th.sorted-desc .sort-arrow { opacity: 1; }
.wiki-table td { padding: 8px 12px; border-bottom: 1px solid var(--border-color, #eee); vertical-align: top; overflow: hidden; text-overflow: ellipsis; }
.wiki-table tbody tr.paper-row:hover { background: var(--bg-hover, #f5f7fa); }
.col-star     { width: 36px; text-align: center; }
.col-num      { width: 36px; text-align: center; }
.col-status   { width: 52px; text-align: center; }
.col-category { width: 85px; }
.col-author   { width: 85px; }
.col-year     { width: 76px; text-align: center; }
.col-journal  { width: 100px; }
.col-title    { width: 22%; }
.col-tags     { width: 15%; }
.col-summary  { width: auto; }
.category-header-row td { background: var(--cat-header-bg, #edf2f7); padding: 10px 12px; font-weight: 700; font-size: 0.95rem; border-bottom: 2px solid var(--border-color, #cbd5e0); position: sticky; top: 42px; z-index: 2; }
.category-label { margin-right: 8px; }
.paper-count { font-size: 0.8rem; font-weight: 400; color: var(--text-muted, #6c757d); margin-right: 8px; }
.collapse-btn { background: none; border: none; cursor: pointer; font-size: 0.9rem; color: var(--text-muted, #6c757d); padding: 2px 6px; border-radius: 4px; }
.collapse-btn:hover { background: var(--bg-hover, rgba(0,0,0,0.05)); }
.paper-row.collapsed, .paper-row.filter-hidden, .category-header-row.filter-hidden { display: none; }
.category-pill { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.7rem; font-weight: 500; white-space: nowrap; }
.cat-oncology    { background: #dbeafe; color: #1e40af; }
.cat-imaging     { background: #fce7f3; color: #9d174d; }
.cat-pulmonology { background: #d1fae5; color: #065f46; }
.cat-generic     { background: var(--bg-secondary, #f0f0f0); color: var(--muted); }
.tag-pill { display: inline-block; padding: 1px 6px; border: 0; border-radius: 8px; font-size: 0.65rem; font-weight: 500; background: var(--tag-bg, #e5e7eb); color: var(--tag-text, #374151); margin: 1px 2px; cursor: pointer; transition: background 0.15s; }
.tag-pill:hover { background: var(--tag-bg-hover, #d1d5db); }
.tag-pill.active { background: var(--accent-color, #3b82f6); color: #fff; }
.star-btn, .status-btn { background: none; border: none; cursor: pointer; font-size: 1rem; padding: 2px; line-height: 1; transition: transform 0.15s; color: var(--text-muted, #999); }
.star-btn:hover, .status-btn:hover { transform: scale(1.2); }
.star-btn.active { color: #f59e0b; }
.status-btn[data-status="unread"]    { color: var(--text-muted, #999); }
.status-btn[data-status="reading"]   { color: #3b82f6; }
.status-btn[data-status="read"]      { color: #22c55e; }
.status-btn[data-status="important"] { color: #ef4444; }
.year-badge { display: inline-block; padding: 1px 6px; border-radius: 8px; font-size: 0.65rem; font-weight: 600; vertical-align: middle; margin-left: 4px; }
.year-badge.new { background: #22c55e; color: #fff; }
.year-old { color: var(--text-muted, #999); }
.title-cell { position: relative; overflow: visible; }
.title-popover { display: none; position: absolute; bottom: 100%; left: 0; width: 350px; max-width: 90vw; padding: 12px 16px; background: var(--popover-bg, #fff); border: 1px solid var(--border-color, #dee2e6); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.12); font-size: 0.8rem; line-height: 1.6; color: var(--text-primary, #333); z-index: 10; pointer-events: none; white-space: normal; }
.title-cell.popover-active .title-popover { display: block; }
.empty-categories { margin-top: 1.5rem; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.empty-label { font-size: 0.85rem; color: var(--text-muted, #999); margin: 0; font-style: italic; }
.empty-cat-pill { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 0.75rem; background: var(--bg-secondary, #f0f0f0); color: var(--text-muted, #888); }
.relationship-map { margin: 24px 0 22px; padding: 16px; border: 1px solid var(--border-color, #dee2e6); border-radius: 8px; background: var(--panel); }
.relationship-heading { display: flex; justify-content: space-between; gap: 18px; align-items: baseline; margin-bottom: 12px; }
.relationship-heading h2 { margin: 0; padding: 0; border: 0; font-size: 1.05rem; }
.relationship-heading p { margin: 0; color: var(--text-muted, #6c757d); font-size: 0.82rem; max-width: 64ch; }
.relationship-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.relationship-card { border: 1px solid var(--border-color, #dee2e6); border-radius: 8px; padding: 12px; background: var(--bg-secondary, #f8f9fa); }
.relationship-card h3 { margin: 0 0 6px; font-size: 0.92rem; }
.relationship-card p { margin: 0 0 10px; color: var(--text-muted, #6c757d); font-size: 0.82rem; line-height: 1.45; }
.relationship-links { display: flex; flex-wrap: wrap; gap: 6px; }
.relationship-chip, .relationship-more { display: inline-block; padding: 3px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); font-size: 0.75rem; text-decoration: none; }
.relationship-chip:hover { background: var(--bg-hover, #f5f7fa); }
@media (prefers-color-scheme: dark) {
  .cat-oncology    { background: #1e3a5f; color: #bfdbfe; }
  .cat-imaging     { background: #55223d; color: #fbcfe8; }
  .cat-pulmonology { background: #174536; color: #bbf7d0; }
  .title-popover { box-shadow: 0 4px 18px rgba(0,0,0,0.45); }
}
@media (max-width: 768px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-group { align-items: stretch; }
  .filter-search { width: 100%; }
  .col-summary, .col-journal, .col-tags, .col-category { display: none; }
  .wiki-table th.col-summary, .wiki-table td:nth-child(10),
  .wiki-table th.col-journal, .wiki-table td:nth-child(7),
  .wiki-table th.col-tags, .wiki-table td:nth-child(9),
  .wiki-table th.col-category, .wiki-table td:nth-child(4) { display: none; }
}
@media (max-width: 820px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  main { padding: 28px 20px; }
}