/* ---------- theme tokens ---------- */
:root {
  --bg:            #f7f8fa;
  --bg-panel:      #ffffff;
  --bg-sidebar:    #fafbfc;
  --border:        #e5e7eb;
  --border-strong: #d1d5db;
  --text:          #1f2937;
  --text-muted:    #6b7280;
  --text-dim:      #9ca3af;
  --accent:        #2563eb;
  --accent-soft:   #dbeafe;
  --shadow-sm:     0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:     0 2px 6px rgba(0,0,0,0.06);

  /* tag palette — one hue per facet */
  --tag-category-bg:       #eef2ff;  --tag-category-fg:       #3730a3;
  --tag-benchmark-type-bg: #ffe4e6;  --tag-benchmark-type-fg: #9f1239;
  --tag-storage-bg:        #fef3c7;  --tag-storage-fg:        #92400e;
  --tag-learning-bg:       #ede9fe;  --tag-learning-fg:       #5b21b6;
  --tag-memory-type-bg:    #d1fae5;  --tag-memory-type-fg:    #065f46;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0f1115;
    --bg-panel:      #161a22;
    --bg-sidebar:    #12151b;
    --border:        #262b36;
    --border-strong: #333a47;
    --text:          #e5e7eb;
    --text-muted:    #9ca3af;
    --text-dim:      #6b7280;
    --accent:        #60a5fa;
    --accent-soft:   #1e3a8a;
    --shadow-sm:     0 1px 2px rgba(0,0,0,0.3);
    --shadow-md:     0 2px 6px rgba(0,0,0,0.4);

    --tag-category-bg:       #1e1b4b;  --tag-category-fg:       #c7d2fe;
    --tag-benchmark-type-bg: #4c0519;  --tag-benchmark-type-fg: #fecdd3;
    --tag-storage-bg:        #451a03;  --tag-storage-fg:        #fde68a;
    --tag-learning-bg:       #2e1065;  --tag-learning-fg:       #ddd6fe;
    --tag-memory-type-bg:    #064e3b;  --tag-memory-type-fg:    #a7f3d0;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg-panel);
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand .tag-line {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}
.brand .tag-line a {
  color: var(--text);
  font-weight: 500;
}
.brand .tag-line a:hover { color: var(--accent); }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-right input[type="search"] {
  width: 260px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.topbar-right input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.topbar-right select {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.topbar-right .gh {
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.topbar-right .gh:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 95px);
}

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 16px 14px 24px 20px;
  position: sticky;
  top: 55px;
  height: calc(100vh - 55px);
  overflow-y: auto;
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.sidebar-head strong { font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
.sidebar-head button {
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-panel);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
}
.sidebar-head button:hover { color: var(--accent); border-color: var(--accent); }

.filter-group {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.filter-group:last-of-type { border-bottom: none; }
.filter-group h3 {
  margin: 0 0 8px 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}
.facet-options { display: flex; flex-direction: column; gap: 4px; }

.chk {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text);
}
.chk:hover { background: var(--bg); }
.chk input { margin: 0; accent-color: var(--accent); }
.chk .count {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.chk.is-disabled { color: var(--text-dim); cursor: not-allowed; }
.chk.is-disabled input { opacity: 0.4; }

.sidebar-footer {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 16px;
  line-height: 1.5;
}

/* ---------- main ---------- */
.main {
  padding: 16px 22px 40px 22px;
}
.results-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
#result-count {
  font-size: 13px;
  color: var(--text-muted);
}
#result-count strong { color: var(--text); font-weight: 600; }
.active-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.active-tags .at-chip {
  font-size: 11px;
  padding: 2px 7px 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  border: 1px solid transparent;
}
.active-tags .at-chip:hover { border-color: var(--accent); }
.active-tags .at-chip::after { content: " ×"; opacity: 0.6; }

/* ---------- cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 12px;
}
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 15px 12px 15px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.12s, border-color 0.12s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.card .title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  margin: 0;
}
.card .title a { color: var(--text); }
.card .title a:hover { color: var(--accent); }
.card .meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: baseline;
}
.card .meta .venue { font-weight: 600; color: var(--text); }
.card .meta .date { font-variant-numeric: tabular-nums; }
.card .notes {
  font-size: 12px;
  color: var(--text-muted);
  border-left: 2px solid var(--border);
  padding-left: 8px;
  margin: 2px 0;
}
.card .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.chip {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}
.chip:hover { filter: brightness(0.96); border-color: rgba(0,0,0,0.1); }
.chip.facet-category       { background: var(--tag-category-bg);       color: var(--tag-category-fg); }
.chip.facet-benchmark_type { background: var(--tag-benchmark-type-bg); color: var(--tag-benchmark-type-fg); }
.chip.facet-storage        { background: var(--tag-storage-bg);        color: var(--tag-storage-fg); }
.chip.facet-learning       { background: var(--tag-learning-bg);       color: var(--tag-learning-fg); }
.chip.facet-memory_type    { background: var(--tag-memory-type-bg);    color: var(--tag-memory-type-fg); }

.card .actions {
  display: flex;
  gap: 8px;
  font-size: 12px;
  margin-top: 4px;
}
.card .actions a {
  padding: 3px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text);
}
.card .actions a:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}
.card .actions a.blog-link {
  border-color: var(--accent);
  color: var(--accent);
}
.card .actions a.blog-link:hover {
  background: var(--accent);
  color: #fff;
}

/* ---------- empty state & footer ---------- */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .topbar { flex-wrap: wrap; }
  .topbar-right input[type="search"] { width: 180px; }
}
