:root {
  --bg: #0b0d12;
  --bg-elevated: #12151c;
  --bg-card: #161a24;
  --bg-card-hover: #1c2230;
  --border: #252b3a;
  --border-subtle: #1a1f2c;
  --text: #e8ecf4;
  --text-muted: #8b93a7;
  --text-dim: #5c657a;
  --accent: #6ea8ff;
  --accent-soft: rgba(110, 168, 255, 0.12);
  --accent-strong: #4d8fff;
  --ai: #a78bfa;
  --ai-soft: rgba(167, 139, 250, 0.14);
  --star: #f5c542;
  --lang: #34d399;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --sidebar-w: 300px;
  --header-h: 72px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* —— Header —— */
.header {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--header-h);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 12px 20px;
  background: rgba(11, 13, 18, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, #2a3550, #1a2235);
  color: var(--star);
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px var(--border);
}

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.search-wrap {
  position: relative;
  flex: 1 1 220px;
  max-width: 360px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 40px;
  padding: 0 36px 0 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input::placeholder {
  color: var(--text-dim);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-hint {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  background: var(--bg);
}

.filter-chips {
  display: flex;
  gap: 6px;
}

.chip {
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chip:hover {
  color: var(--text);
  border-color: #3a4358;
}

.chip.active {
  background: var(--accent-soft);
  border-color: rgba(110, 168, 255, 0.45);
  color: var(--accent);
}

.chip[data-scope="ai"].active {
  background: var(--ai-soft);
  border-color: rgba(167, 139, 250, 0.5);
  color: var(--ai);
}

.sort-select {
  height: 34px;
  padding: 0 28px 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b93a7' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.sort-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-icon {
  display: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
}

.btn-text {
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}

.btn-text:hover {
  background: var(--accent-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid rgba(110, 168, 255, 0.4);
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.btn:hover {
  background: rgba(110, 168, 255, 0.2);
}

/* —— Body layout —— */
.body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--header-h));
  position: sticky;
  top: var(--header-h);
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-head h2 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.tree-l1,
.tree-l2,
.tree-l3 {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-l2 {
  padding-left: 10px;
  margin-top: 2px;
  display: none;
}

.tree-l2.open {
  display: block;
}

.tree-l3 {
  padding-left: 12px;
  margin-top: 2px;
  display: none;
}

.tree-l3.open {
  display: block;
}

.tree-item {
  margin: 1px 0;
}

.tree-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: left;
  padding: 7px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.tree-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.tree-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tree-btn.ai-node.active {
  background: var(--ai-soft);
  color: var(--ai);
}

.tree-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.tree-caret {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  transition: transform 0.15s;
}

.tree-caret.open {
  transform: rotate(90deg);
}

.tree-caret.leaf {
  visibility: hidden;
}

.tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-count {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  padding: 1px 7px;
  border-radius: 999px;
}

.tree-btn.active .tree-count {
  color: inherit;
  background: rgba(255, 255, 255, 0.08);
}

.tree-l1 > .tree-item > .tree-btn {
  font-weight: 600;
  color: var(--text);
  font-size: 0.88rem;
}

.tree-l1 > .tree-item > .tree-btn.ai-node {
  color: #c4b5fd;
}

/* —— Main —— */
.main {
  flex: 1;
  min-width: 0;
  padding: 16px 20px 40px;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  min-height: 24px;
}

.crumb {
  color: var(--text-muted);
}

.crumb-sep {
  color: var(--text-dim);
  user-select: none;
}

.crumb-btn {
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: inherit;
  cursor: pointer;
  padding: 0;
}

.crumb-btn:hover {
  text-decoration: underline;
}

.crumb-current {
  color: var(--text);
  font-weight: 500;
}

.list-meta {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  text-decoration: none;
  color: inherit;
  min-height: 160px;
}

.card:hover {
  background: var(--bg-card-hover);
  border-color: #323a4f;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.card-top > div:first-child {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.card-name {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 650;
  color: var(--text);
  word-break: break-word;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-full {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-stars {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--star);
  background: rgba(245, 197, 66, 0.1);
  padding: 3px 8px;
  border-radius: 999px;
}

.card-desc {
  margin: 0;
  flex: 1;
  font-size: 0.86rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge-lang::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lang);
}

.badge-path {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
  border-style: dashed;
}

.topics {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.topic {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
}

.topic.more {
  color: var(--text-muted);
}

/* Empty / loading */
.empty,
.loading {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 1.1rem;
  color: var(--text);
}

.empty-desc {
  margin: 0 0 20px;
  font-size: 0.9rem;
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 14px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.sidebar-backdrop {
  display: none;
}

/* —— Mobile —— */
@media (max-width: 860px) {
  .btn-icon {
    display: grid;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    max-height: none;
    width: min(var(--sidebar-w), 88vw);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, 0.55);
  }

  .sidebar-backdrop[hidden] {
    display: none;
  }

  .header {
    padding: 10px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .header-left {
    width: 100%;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  .brand-title {
    font-size: 0.92rem;
    white-space: normal;
    line-height: 1.25;
  }

  .brand-sub {
    font-size: 0.72rem;
  }

  .header-controls {
    width: 100%;
    justify-content: stretch;
    gap: 8px;
  }

  .search-wrap {
    flex: 1 1 100%;
    max-width: none;
    order: 0;
  }

  .filter-chips {
    flex: 1 1 auto;
  }

  .sort-label {
    flex: 0 0 auto;
    margin-left: auto;
  }

  .sort-select {
    max-width: 42vw;
  }

  .search-hint {
    display: none;
  }

  .main {
    padding: 14px 14px 32px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.tree-node.dimmed {
  opacity: 0.38;
}
.tree-node.dimmed > .tree-row {
  pointer-events: auto;
}
