:root {
  --bg: #f4f6fb;
  --bg-grad: linear-gradient(135deg, #4f6ef7 0%, #7a5cf0 100%);
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --text: #1f2330;
  --text-soft: #5b6275;
  --text-faint: #9aa1b4;
  --border: #e6e9f2;
  --accent: #4f6ef7;
  --accent-soft: #eef1fe;
  --shadow: 0 6px 22px rgba(31, 35, 48, 0.08);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #14161d;
  --bg-grad: linear-gradient(135deg, #2a2f45 0%, #3a2f55 100%);
  --surface: #1d2029;
  --surface-2: #242834;
  --text: #e8eaf0;
  --text-soft: #aab0c2;
  --text-faint: #6b7283;
  --border: #2c3040;
  --accent: #7a8cff;
  --accent-soft: #262b44;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 14px 26px;
  background: var(--bg-grad);
  color: #fff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
}
.brand-logo {
  justify-self: start;
  width: 48px; height: 48px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.18);
  display: grid; place-items: center;
  font-size: 24px; font-weight: 700;
  backdrop-filter: blur(4px);
}
.brand-text { justify-self: center; text-align: center; }
.brand-text h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: 2px; }
.brand-text p { margin: 4px 0 0; font-size: 13px; opacity: 0.85; }
.theme-toggle { justify-self: end; }

.search-bar {
  display: flex;
  justify-content: center;
  padding: 16px 26px 4px;
}
.search-wrap {
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 18px;
  box-shadow: var(--shadow);
  color: var(--text-soft);
}
.search-icon { color: var(--text-faint); flex: 0 0 auto; }
#search {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#search::placeholder { color: var(--text-faint); }
.search-count { font-size: 12px; color: var(--text-faint); white-space: nowrap; flex: 0 0 auto; }

.theme-toggle {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.2s;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.3); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 70px;
  align-self: start;
  height: calc(100vh - 70px);
  overflow-y: auto;
  padding: 20px 12px 40px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin: 2px 0;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-soft);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-size: 14.5px;
}
.sidebar-item:hover { background: var(--surface-2); color: var(--text); }
.sidebar-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-item .count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-faint);
  background: var(--surface-2);
  padding: 1px 8px;
  border-radius: 999px;
}
.sidebar-item.active .count { background: #fff; color: var(--accent); }

.content {
  padding: 24px 30px 60px;
  min-height: calc(100vh - 70px);
}

/* Sections */
.section { margin-bottom: 38px; scroll-margin-top: 80px; }
.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.section-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.section-head .badge {
  font-size: 12px;
  color: var(--text-faint);
}

.subsection { margin: 18px 0 6px; }
.subsection-head {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-soft);
  padding: 6px 0;
}
.subsection-head .arrow { transition: transform 0.2s; font-size: 12px; }
.subsection.collapsed .arrow { transform: rotate(-90deg); }
.subsection.collapsed > .subsection-body { display: none; }

/* Cards grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  overflow: hidden;
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 10px 26px rgba(79, 110, 247, 0.18);
}
.card-icon {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--surface-2);
}
.card-letter {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}
.card-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-host {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--text-faint);
  padding: 60px 0;
  font-size: 15px;
}

.footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  padding: 20px;
  border-top: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px 16px;
    top: 0;
  }
  .sidebar-item { width: auto; margin: 0; }
  .sidebar-item .count { display: none; }
  .content { padding: 16px; }
  .topbar { gap: 10px; padding: 12px 16px; }
}
