:root {
  --bg: #f5f6fb;
  --bg-elevated: #ffffff;
  --text: #1a1d29;
  --text-muted: #6b7280;
  --border: #e6e8f0;
  --primary: #6366f1;
  --primary-2: #22d3ee;
  --primary-soft: #eef0ff;
  --shadow: 0 2px 10px rgba(20, 20, 43, 0.06);
  --shadow-hover: 0 10px 24px rgba(20, 20, 43, 0.10);
  --radius: 14px;
  --header-h: 64px;
  --rail-w: 64px;
}

:root[data-theme="dark"] {
  --bg: #0f1117;
  --bg-elevated: #171a24;
  --text: #e8e9f0;
  --text-muted: #9098ac;
  --border: #262a38;
  --primary-soft: #1c1f3a;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 10px 28px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 12px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  transition: background .2s ease, color .2s ease;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 0 0 8px 0; z-index: 200;
}
.skip-link:focus { left: 0; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1240px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none;
  flex-shrink: 0;
}
.brand-logo { width: 28px; height: 28px; border-radius: 8px; }

.cat-nav {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  flex: 1;
}
.cat-nav::-webkit-scrollbar { display: none; }
.cat-nav a {
  white-space: nowrap;
  padding: 8px 12px; border-radius: 8px;
  color: var(--text-muted); text-decoration: none; font-size: 14px;
  transition: background .15s, color .15s;
}
.cat-nav a:hover, .cat-nav a.active { background: var(--primary-soft); color: var(--primary); }

.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text);
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn .icon-moon { display: none; }
:root[data-theme="dark"] .icon-btn .icon-sun { display: none; }
:root[data-theme="dark"] .icon-btn .icon-moon { display: block; }

/* ---------- Side rail ---------- */
.side-rail {
  position: fixed; left: 16px; top: 50%; transform: translateY(-50%);
  z-index: 90;
  display: none;
  flex-direction: column; gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px;
  box-shadow: var(--shadow);
}
@media (min-width: 1280px) { .side-rail { display: flex; } }
.side-rail a {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); text-decoration: none;
  font-size: 12px; text-align: center;
  transition: background .15s, color .15s;
}
.side-rail a:hover, .side-rail a.active { background: var(--primary-soft); color: var(--primary); }

/* ---------- Hero ---------- */
.hero {
  max-width: 760px; margin: 0 auto; padding: 56px 20px 28px; text-align: center;
}
.hero h1 {
  font-size: 36px; margin: 0 0 8px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--text-muted); margin: 0 0 28px; font-size: 15px; }

.search-box {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 18px; padding: 14px; box-shadow: var(--shadow);
}
.engine-tabs { display: flex; gap: 4px; margin-bottom: 10px; justify-content: center; flex-wrap: wrap; }
.engine-tab {
  border: none; background: transparent; color: var(--text-muted);
  padding: 6px 14px; border-radius: 999px; cursor: pointer; font-size: 13px;
}
.engine-tab:hover { background: var(--primary-soft); }
.engine-tab.active { background: var(--primary); color: #fff; }

.search-form { display: flex; gap: 8px; }
.search-form input {
  flex: 1; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); border-radius: 12px; padding: 12px 16px; font-size: 15px; outline: none;
}
.search-form input:focus { border-color: var(--primary); }
.search-btn {
  width: 46px; border: none; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.search-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.chip {
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text-muted);
  padding: 6px 14px; border-radius: 999px; font-size: 13px; cursor: pointer; text-decoration: none;
}
.chip:hover { color: var(--primary); border-color: var(--primary); }

.search-status { text-align: center; color: var(--text-muted); font-size: 14px; margin: 0 0 8px; }

/* ---------- Sections & cards ---------- */
#categories, .category-section { max-width: 1240px; margin: 0 auto; padding: 0 20px; }
.category-section { margin-bottom: 36px; scroll-margin-top: calc(var(--header-h) + 12px); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2 { font-size: 19px; margin: 0; display: flex; align-items: center; gap: 8px; }
.section-icon {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.add-btn {
  border: 1px dashed var(--border); background: transparent; color: var(--text-muted);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.add-btn:hover { color: var(--primary); border-color: var(--primary); }

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

.card {
  position: relative;
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--text);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: transparent; }

.card-icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px; overflow: hidden;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.card-icon img { width: 100%; height: 100%; object-fit: cover; }

.card-body { min-width: 0; flex: 1; padding-right: 24px; }
.card-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 600; font-size: 14.5px; }
.card-title > span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 100%;
}
.card-title .hot-badge {
  font-size: 10px; background: #fef2f2; color: #ef4444; padding: 1px 6px; border-radius: 999px; flex-shrink: 0;
}
:root[data-theme="dark"] .card-title .hot-badge { background: #3a1c1c; }
.card-desc {
  margin: 4px 0 0; font-size: 12.5px; color: var(--text-muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.4;
}
.card-tag {
  display: inline-block; margin-top: 8px; font-size: 11px; color: var(--primary);
  background: var(--primary-soft); padding: 2px 8px; border-radius: 999px;
}

.fav-btn {
  position: absolute; top: 10px; right: 10px;
  width: 26px; height: 26px; border-radius: 50%;
  border: none; background: transparent; color: var(--text-muted);
  cursor: pointer; font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.fav-btn:hover { color: #f59e0b; background: var(--primary-soft); }
.fav-btn.active { color: #f59e0b; }

.card-remove {
  position: absolute; top: 10px; right: 10px;
  width: 22px; height: 22px; border-radius: 50%;
  border: none; background: var(--border); color: var(--text-muted);
  cursor: pointer; font-size: 13px; line-height: 1; display: none;
  align-items: center; justify-content: center;
}
.card.custom-card .card-remove { display: flex; }
.card.custom-card .fav-btn { display: none; }

.empty-fav-hint { color: var(--text-muted); font-size: 13px; padding: 10px 2px; }

/* ---------- Footer ---------- */
.site-footer {
  max-width: 1240px; margin: 48px auto 24px; padding: 24px 20px 0;
  border-top: 1px solid var(--border);
  text-align: center; color: var(--text-muted); font-size: 13px;
}
.site-footer p { margin: 4px 0; }
.site-footer .muted { font-size: 12px; opacity: .8; }

/* ---------- Back to top ---------- */
.back-top {
  position: fixed; right: 20px; bottom: 24px; z-index: 90;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  box-shadow: var(--shadow); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.back-top svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .cat-nav { display: none; }
  .hero { padding: 40px 16px 20px; }
  .hero h1 { font-size: 28px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
