:root {
  --bg: #f6f7fb;
  --bg-soft: #eef1f8;
  --card: #ffffff;
  --line: #e6eaf2;
  --line-strong: #d3dae7;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #7c8aa3;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --hot: #f97316;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .05);
  --shadow-hi: 0 2px 6px rgba(15, 23, 42, .06), 0 16px 36px rgba(15, 23, 42, .1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(900px 420px at 8% -10%, #e8ecff 0%, rgba(232, 236, 255, 0) 62%),
    radial-gradient(760px 380px at 92% 0%, #e6fbff 0%, rgba(230, 251, 255, 0) 60%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
  flex: none;
}
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  font-size: 18px;
  border-radius: 10px;
  background: linear-gradient(135deg, #eef0ff, #e2f6ff);
  border: 1px solid #dfe5f6;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 15px; letter-spacing: .2px; }
.brand-text i { font-style: normal; font-size: 11px; color: var(--muted); }

.search-wrap {
  position: relative;
  flex: 1 1 auto;
  max-width: 560px;
  margin-left: auto;
}
.search-wrap .search-icon {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round;
  pointer-events: none;
}
#q {
  width: 100%;
  height: 40px;
  padding: 0 42px 0 38px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
#q::placeholder { color: #9aa7bd; }
#q:focus {
  border-color: #b9bfff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.search-kbd {
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 6px;
}
.home-link {
  flex: none;
  font-size: 13px;
  color: var(--text-2);
  text-decoration: none;
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid transparent;
  transition: all .18s;
}
.home-link:hover { background: var(--bg-soft); border-color: var(--line); color: var(--text); }

/* ---------- layout ---------- */
.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 20px 48px;
}

.hero h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.2px;
}
.hero p {
  margin-top: 6px;
  font-size: 13.5px;
  color: var(--text-2);
}
.stat { color: var(--muted); margin-left: 6px; }
.hero-note {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- filters ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px 0 16px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  font-size: 13px;
  color: var(--text-2);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .16s;
}
.chip:hover { border-color: var(--line-strong); background: #fdfdff; }
.chip .num {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 1px 6px;
  min-width: 20px;
  text-align: center;
}
.chip[aria-selected="true"] {
  color: #fff;
  background: linear-gradient(135deg, #5b54ea, #4f46e5);
  border-color: #4f46e5;
  box-shadow: 0 4px 14px rgba(79, 70, 229, .28);
}
.chip[aria-selected="true"] .num { color: #fff; background: rgba(255, 255, 255, .22); }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.result-info { font-size: 12.5px; color: var(--muted); }
.toolbar-right { display: flex; align-items: center; gap: 14px; }
.fav-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.fav-toggle input { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }
#sort {
  height: 32px;
  padding: 0 8px;
  font-size: 13px;
  color: var(--text-2);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  cursor: pointer;
}
#sort:focus { border-color: #b9bfff; }

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

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 16px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hi);
  border-color: #cfd6ea;
}
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card-head { display: flex; align-items: flex-start; gap: 11px; }
.card-icon {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 19px;
  border-radius: 11px;
  background: var(--bg-soft);
  border: 1px solid #e9edf6;
}
.card-title { min-width: 0; flex: 1; }
.card-title h3 {
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: -.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-title .badge {
  display: inline-block;
  margin-top: 3px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.5;
  padding: 1px 7px;
  border-radius: 5px;
  color: #475569;
  background: #f1f4f9;
}
.badge.b-free { color: #067647; background: #e7f8ef; }
.badge.b-freemium { color: #1d4ed8; background: #e8efff; }
.badge.b-paid { color: #b45309; background: #fdf1e2; }
.badge.b-oss { color: #7c3aed; background: #f1eaff; }

.card-hot {
  position: absolute;
  top: 12px; right: 12px;
  font-size: 12px;
  color: var(--hot);
  opacity: .9;
}

.card-desc {
  font-size: 12.8px;
  color: var(--text-2);
  line-height: 1.62;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 41px;
}

.card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: auto; }
.card-tags span {
  font-size: 11px;
  color: var(--muted);
  background: #f6f8fc;
  border: 1px solid #edf1f8;
  border-radius: 5px;
  padding: 1px 6px;
}

.card-fav {
  position: absolute;
  bottom: 10px; right: 12px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  font-size: 14px;
  color: #c3cddd;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .16s, color .16s, background .16s;
}
.card:hover .card-fav, .card-fav.on { opacity: 1; }
.card-fav:hover { background: #f2f5fb; color: #f59e0b; }
.card-fav.on { color: #f59e0b; }

/* category accent on icon */
.card[data-cat="chat"] .card-icon { background: linear-gradient(135deg, #eef1ff, #e6ecff); }
.card[data-cat="search"] .card-icon { background: linear-gradient(135deg, #e8f7ff, #e0f2fe); }
.card[data-cat="writing"] .card-icon { background: linear-gradient(135deg, #fff4e8, #ffe9d6); }
.card[data-cat="image"] .card-icon { background: linear-gradient(135deg, #ffeef5, #ffe4ef); }
.card[data-cat="video"] .card-icon { background: linear-gradient(135deg, #f1eeff, #e9e3ff); }
.card[data-cat="audio"] .card-icon { background: linear-gradient(135deg, #eafaf1, #ddf6e7); }
.card[data-cat="coding"] .card-icon { background: linear-gradient(135deg, #eef4ff, #e3ecff); }
.card[data-cat="office"] .card-icon { background: linear-gradient(135deg, #fff8e6, #fdf0cf); }
.card[data-cat="agent"] .card-icon { background: linear-gradient(135deg, #eefbf7, #e2f7ef); }
.card[data-cat="study"] .card-icon { background: linear-gradient(135deg, #f3f0ff, #eeeaff); }

/* ---------- misc ---------- */
.empty {
  padding: 60px 0;
  text-align: center;
  font-size: 13.5px;
  color: var(--muted);
}
.foot {
  margin-top: 34px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.foot b { color: var(--text-2); font-weight: 600; }

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .brand-text i { display: none; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; margin-left: 0; }
  .home-link { margin-left: auto; }
  .wrap { padding: 20px 14px 40px; }
  .hero h1 { font-size: 21px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .filters::-webkit-scrollbar { display: none; }
  .toolbar { flex-wrap: wrap; }
  .card-fav { opacity: 1; }
}
