:root {
  --bg: #f7f8fa; --card: #ffffff; --text: #1a1d23; --muted: #6b7280;
  --border: #e5e7eb; --accent: #2563eb; --shadow: 0 1px 2px rgba(0,0,0,.05);
  --tile-num: #111827;
}
[data-theme="dark"] {
  --bg: #0f1115; --card: #171a21; --text: #e5e7eb; --muted: #9ca3af;
  --border: #262b35; --accent: #60a5fa; --shadow: none; --tile-num: #f3f4f6;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Hub */
.hub { max-width: 880px; margin: 0 auto; padding: 48px 24px; }
.eyebrow { font-size: 12px; letter-spacing: .12em; color: var(--muted); text-transform: uppercase; }
.hub h1 { font-size: 40px; margin: 8px 0 12px; letter-spacing: -0.02em; }
.hub .lede { color: var(--muted); max-width: 560px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; margin-top: 36px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.card .emoji { font-size: 28px; }
.card h2 { margin: 0; font-size: 21px; }
.card p { margin: 0; color: var(--muted); font-size: 14.5px; }
.card .head { display: flex; justify-content: space-between; align-items: flex-start; }
.card .open { margin-top: auto; font-weight: 600; font-size: 14px; }
.stat-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Badges and chips */
.badge {
  font-size: 11px; font-weight: 700; letter-spacing: .04em; border-radius: 999px;
  padding: 3px 10px; background: #ecfdf5; color: #047857; white-space: nowrap;
}
.badge.gray { background: #f3f4f6; color: #4b5563; }
[data-theme="dark"] .badge { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge.gray { background: #262b35; color: #9ca3af; }
.chip {
  display: inline-block; font-size: 13px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card); cursor: pointer; user-select: none;
}
.chip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Cluster palette (assigned by cluster order per category) and type colors */
.cl-blue { background: #eff6ff; color: #1d4ed8; }
.cl-purple { background: #f5f3ff; color: #6d28d9; }
.cl-red { background: #fef2f2; color: #b91c1c; }
.cl-green { background: #ecfdf5; color: #047857; }
.cl-orange { background: #fff7ed; color: #c2410c; }
.ty-empirical { background: #ecfdf5; color: #047857; }
.ty-theoretical { background: #f5f3ff; color: #6d28d9; }
.ty-both { background: #eff6ff; color: #1d4ed8; }
.ty-conceptual { background: #fff7ed; color: #c2410c; }
[data-theme="dark"] .cl-blue, [data-theme="dark"] .ty-both { background: #172554; color: #93c5fd; }
[data-theme="dark"] .cl-purple, [data-theme="dark"] .ty-theoretical { background: #2e1065; color: #c4b5fd; }
[data-theme="dark"] .cl-red { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .cl-green, [data-theme="dark"] .ty-empirical { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .cl-orange, [data-theme="dark"] .ty-conceptual { background: #431407; color: #fdba74; }

/* Category layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 264px; flex-shrink: 0; border-right: 1px solid var(--border);
  padding: 24px 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--card); display: flex; flex-direction: column;
}
.sidebar h1 { font-size: 17px; margin: 0; }
.sidebar .sub { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.sidebar .backlink { font-size: 13.5px; display: block; margin-bottom: 16px; }
.sidebar .navlabel {
  font-size: 10.5px; letter-spacing: .1em; color: var(--muted);
  text-transform: uppercase; margin: 14px 0 4px; font-weight: 700;
}
.sidebar nav a {
  display: block; font-size: 14px; color: var(--text); padding: 5px 8px; border-radius: 6px;
}
.sidebar nav a:hover { background: var(--bg); text-decoration: none; }
.sidebar nav a.active { background: var(--bg); font-weight: 600; }
.sidebar .paperlink { font-size: 12.5px; color: var(--muted); }
.sidebar .theme-toggle {
  margin-top: auto; font-size: 13px; cursor: pointer; color: var(--muted);
  background: none; border: none; text-align: left; padding: 8px;
}
.content { flex: 1; padding: 48px 56px; max-width: 1060px; }
.content h1 { font-size: 36px; letter-spacing: -0.02em; margin: 8px 0 14px; }
.content .lede { color: var(--muted); font-size: 17px; max-width: 640px; }
.content h2 { font-size: 23px; margin-top: 40px; }
.content h3 { font-size: 16.5px; margin-bottom: 4px; }
.section-desc { color: var(--muted); margin-top: 0; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 14px; margin: 28px 0; }
.tile {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.tile .num { font-size: 26px; font-weight: 700; color: var(--tile-num); }
.tile .lbl { font-size: 12.5px; color: var(--muted); }

/* Table */
.searchbox {
  width: 100%; padding: 12px 16px; font-size: 15px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--card); color: var(--text); margin: 18px 0 12px;
}
.filterrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filterrow .grouplabel { font-size: 11px; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin-left: 8px; }
.count { margin-left: auto; font-size: 13px; color: var(--muted); }
table.papers { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table.papers th {
  text-align: left; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
}
table.papers td { padding: 14px; border-bottom: 1px solid var(--border); font-size: 14.5px; vertical-align: top; }
table.papers tr.row:hover { background: var(--bg); cursor: pointer; }
table.papers .pid { font-size: 12px; color: var(--muted); }
tr.expand td { background: var(--bg); font-size: 14px; }

/* Paper page */
.paper-head {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 26px 30px; box-shadow: var(--shadow); margin-bottom: 30px;
}
.paper-head .meta { font-size: 13.5px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.paper-head h1 { font-size: 27px; margin: 10px 0 8px; }
.notes h2 { font-size: 20px; margin: 34px 0 10px; }
.notes p { margin: 0 0 14px; }
.autonote {
  border: 1px dashed var(--border); border-radius: 10px; padding: 6px 14px;
  color: var(--muted); font-size: 13.5px; margin-bottom: 22px;
}

/* New papers list */
.newlist .card { margin-bottom: 14px; }
.score { font-size: 22px; font-weight: 800; color: #047857; }
[data-theme="dark"] .score { color: #6ee7b7; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .content { padding: 28px 18px; }
}
