/* ===== 基础变量与重置 ===== */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --accent: #ec4899;
  --bg: #f7f8fc;
  --bg-soft: #eef1fb;
  --card: #ffffff;
  --text: #1e293b;
  --text-soft: #64748b;
  --text-mute: #94a3b8;
  --border: #e6e9f2;
  --shadow-sm: 0 1px 3px rgba(30, 41, 59, .06), 0 1px 2px rgba(30, 41, 59, .04);
  --shadow-md: 0 4px 16px rgba(99, 102, 241, .08), 0 2px 6px rgba(30, 41, 59, .05);
  --shadow-lg: 0 12px 32px rgba(99, 102, 241, .14), 0 4px 12px rgba(30, 41, 59, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --maxw: 1240px;
  --header-h: 56px;
  --nav-h-real: 56px;  /* 默认值，JS 会根据 navbar 实际高度覆盖 */
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --bg-soft: #161a24;
    --card: #1a1f2b;
    --text: #e8ecf3;
    --text-soft: #a3acc0;
    --text-mute: #6b7488;
    --border: #283040;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .35);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
  }
}

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

html { scroll-behavior: smooth; scroll-padding-top: 160px; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 15px;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

/* ===== 顶部品牌栏（精简：仅品牌标识 + 返回按钮，分类导航由左侧 sidebar 承担） ===== */
.navbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
  transition: box-shadow .25s ease;
}
.navbar.scrolled { box-shadow: var(--shadow-sm); }
@media (prefers-color-scheme: dark) {
  .navbar { background: rgba(15, 17, 23, .82); }
}
.nav-inner {
  padding: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 100%;
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--grad);
  color: #fff; font-weight: 800; font-size: 17px;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(99, 102, 241, .35);
}
.brand-logo.small { width: 34px; height: 34px; font-size: 15px; border-radius: 10px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; font-weight: 700; }
.brand-text em { font-size: 12px; color: var(--text-soft); font-style: normal; }

/* 返回首页按钮（category.php 用） - 已被下拉菜单取代，保留样式以防其他地方引用 */
.back-home-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 14px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-soft);
  background: var(--bg-soft);
  border: 1px solid transparent;
  transition: all .2s ease;
  flex-shrink: 0;
}
.back-home-btn:hover {
  color: var(--primary);
  background: rgba(99, 102, 241, .08);
  border-color: rgba(99, 102, 241, .2);
}

/* ===== 顶部分类筛选组（标签 + 下拉菜单） ===== */
.cat-selector {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.cat-selector-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-soft);
  white-space: nowrap;
  user-select: none;
}

/* 下拉容器 */
.cat-dropdown {
  position: relative;
  flex-shrink: 0;
  width: 260px;  /* 按钮和菜单统一宽度 */
}

/* 下拉按钮 */
.cat-dropdown-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s ease;
}
.cat-dropdown-btn:hover {
  background: rgba(99, 102, 241, .08);
  border-color: rgba(99, 102, 241, .2);
  color: var(--primary);
}
.cat-dropdown-btn.open {
  background: rgba(99, 102, 241, .1);
  border-color: rgba(99, 102, 241, .3);
  color: var(--primary);
}
.cat-dropdown-ico { font-size: 16px; flex-shrink: 0; }
.cat-dropdown-label {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cat-dropdown-count {
  background: var(--card);
  color: var(--text-mute);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.cat-dropdown-btn.open .cat-dropdown-count,
.cat-dropdown-btn:hover .cat-dropdown-count {
  border-color: rgba(99, 102, 241, .3);
}
.cat-dropdown-arrow {
  flex-shrink: 0;
  transition: transform .25s ease;
  color: var(--text-mute);
}
.cat-dropdown-btn.open .cat-dropdown-arrow {
  transform: rotate(180deg);
  color: var(--primary);
}

/* 下拉菜单：与按钮等宽 */
.cat-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;       /* 与按钮等宽 */
  max-height: 60vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.cat-dropdown-menu::-webkit-scrollbar { width: 6px; }
.cat-dropdown-menu::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
.cat-dropdown-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* 下拉菜单顶部提示条 */
.cat-dropdown-tip {
  padding: 8px 12px;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-mute);
  background: linear-gradient(135deg, rgba(99,102,241,.06), rgba(236,72,153,.06));
  border-radius: 8px;
  line-height: 1.4;
}

/* 下拉菜单项 */
.cat-dropdown-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  background: transparent;
  border: 0;
  color: var(--text-soft);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: all .15s ease;
  text-decoration: none;
}
.cat-dropdown-item:hover {
  background: var(--bg-soft);
  color: var(--primary);
}
.cat-dropdown-item.active {
  background: rgba(99, 102, 241, .1);
  color: var(--primary);
  font-weight: 600;
}
.cat-dropdown-item .ico { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.cat-dropdown-item .label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-dropdown-item .count {
  font-size: 12px;
  color: var(--text-mute);
  background: var(--bg-soft);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}
.cat-dropdown-item.active .count {
  background: rgba(99, 102, 241, .15);
  color: var(--primary);
}

/* ===== Hero 区 ===== */
.hero {
  position: relative;
  padding: 64px 0 56px;
  text-align: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.hero-bg {
  position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(60% 50% at 20% 10%, rgba(99,102,241,.18), transparent 70%),
    radial-gradient(50% 50% at 90% 20%, rgba(236,72,153,.15), transparent 70%),
    radial-gradient(40% 40% at 50% 100%, rgba(139,92,246,.12), transparent 70%);
}
.hero-inner { position: relative; }
.hero-title {
  font-size: clamp(28px, 5vw, 46px);
  font-weight: 800; letter-spacing: -.02em;
  margin: 0 0 14px;
}
.hero-title span {
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero-sub { color: var(--text-soft); font-size: clamp(14px, 2vw, 17px); margin: 0 0 30px; }

.search-box {
  position: relative; max-width: 600px; margin: 0 auto;
  display: flex; align-items: center;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 4px 4px 18px;
  box-shadow: var(--shadow-md);
  transition: border-color .2s, box-shadow .2s;
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,.12), var(--shadow-md); }
.search-icon { color: var(--text-mute); flex-shrink: 0; }
.search-box input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-size: 15px; padding: 12px 12px; color: var(--text);
}
.search-box input::placeholder { color: var(--text-mute); }
.search-clear {
  width: 32px; height: 32px; margin-right: 4px;
  border: 0; border-radius: 50%; cursor: pointer;
  background: var(--bg-soft); color: var(--text-soft); font-size: 18px; line-height: 1;
  display: grid; place-items: center; transition: .2s;
}
.search-clear:hover { background: var(--primary); color: #fff; }

.hero-stats { margin-top: 22px; display: flex; gap: 28px; justify-content: center; flex-wrap: wrap; color: var(--text-soft); font-size: 14px; }
.hero-stats b { color: var(--primary); font-size: 18px; font-weight: 700; margin-right: 4px; }

/* ===== 主内容区（单列布局，分类切换由顶部下拉菜单完成） ===== */
.main-content.content { padding: 24px 0 48px; }

/* ===== 顶部水平筛选条（分类详情页 / 移动端首页 fallback） ===== */
.filter-bar {
  position: sticky; top: var(--nav-h-real, var(--header-h)); z-index: 90;
  background: rgba(247, 248, 252, .85);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
@media (prefers-color-scheme: dark) { .filter-bar { background: rgba(15,17,23,.85); } }
.filter-inner { padding: 12px 20px; position: relative; }
.filter-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap; /* 换行显示，不再横向滚动挤压 */
  padding-inline: 4px;
}
.filter-tab {
  padding: 8px 16px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border);
  color: var(--text-soft); font-size: 14px; cursor: pointer;
  transition: all .2s ease; display: inline-flex; align-items: center; gap: 6px;
}
.filter-tab .ico { font-size: 15px; }
.filter-tab:hover { color: var(--primary); border-color: var(--primary-light); }
.filter-tab.active {
  background: var(--grad); color: #fff; border-color: transparent;
  box-shadow: 0 4px 12px rgba(99,102,241,.3);
}
.filter-tab .count { font-size: 12px; opacity: .8; }

/* ===== 内容区 ===== */
.content { padding: 32px 0 64px; }
.catalog { display: flex; flex-direction: column; gap: 48px; }

.cat-section { scroll-margin-top: 200px; }
.cat-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.cat-emoji {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--bg-soft); display: grid; place-items: center; font-size: 22px;
}
.cat-title { display: flex; flex-direction: column; line-height: 1.25; }
.cat-title h2 { margin: 0; font-size: 20px; font-weight: 700; }
.cat-title small { color: var(--text-soft); font-size: 13px; }
.cat-line { flex: 1; height: 1px; background: linear-gradient(90deg, var(--border), transparent); }

/* 工具卡片网格 */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.tool-card {
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
  position: relative; overflow: hidden;
}
.tool-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--grad); transform: scaleX(0); transform-origin: left; transition: transform .3s ease;
}
.tool-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: transparent;
}
.tool-card:hover::before { transform: scaleX(1); }

.tool-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.tool-logo {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  background: var(--bg-soft); object-fit: contain; padding: 6px;
  border: 1px solid var(--border);
}
.tool-logo-fallback {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  background: var(--grad); color: #fff; font-weight: 700; font-size: 17px;
  display: grid; place-items: center;
}
.tool-name { font-size: 15.5px; font-weight: 650; color: var(--text); margin: 0; }
.tool-desc {
  color: var(--text-soft); font-size: 13px; line-height: 1.55;
  margin: 0 0 14px; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tool-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.tag {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: var(--bg-soft); color: var(--text-soft);
}
.tool-arrow {
  position: absolute; top: 18px; right: 18px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--bg-soft); color: var(--text-mute);
  display: grid; place-items: center; font-size: 14px;
  opacity: 0; transform: translateX(-4px); transition: .25s ease;
}
.tool-card:hover .tool-arrow { opacity: 1; transform: translateX(0); color: var(--primary); background: rgba(99,102,241,.12); }

/* ===== 「更多」按钮（首页） ===== */
.cat-head { position: relative; }
.cat-more-btn {
  position: relative; z-index: 1;
  flex-shrink: 0;
  padding: 6px 14px; border-radius: 999px;
  background: var(--bg-soft); color: var(--primary);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  transition: all .2s ease;
}
.cat-more-btn:hover { background: var(--grad); color: #fff; box-shadow: 0 4px 12px rgba(99,102,241,.3); }

.cat-more-row { margin-top: 14px; text-align: center; }
.btn-more {
  display: inline-block;
  padding: 10px 22px; border-radius: 999px;
  background: var(--card); color: var(--primary);
  border: 1px solid var(--primary-light);
  font-size: 14px; font-weight: 600;
  transition: all .25s ease;
}
.btn-more:hover {
  background: var(--grad); color: #fff; border-color: transparent;
  transform: translateY(-2px); box-shadow: var(--shadow-md);
}

/* ===== 分类详情页专属 ===== */
.cat-hero { padding: 48px 0 40px; }
.crumb { color: var(--text-soft); font-size: 14px; margin-bottom: 14px; display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; }
.crumb a { color: var(--text-soft); transition: color .2s; }
.crumb a:hover { color: var(--primary); }
.crumb .sep { color: var(--text-mute); }
.cat-hero .hero-title { font-size: clamp(26px, 4.5vw, 38px); }
.cat-hero .hero-sub { margin-bottom: 22px; }
.cat-hero .hero-sub b { color: var(--primary); }

/* ===== 空状态 ===== */
.empty-tip { text-align: center; padding: 60px 20px; color: var(--text-soft); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== 高亮搜索 ===== */
mark { background: rgba(236, 132, 71, .25); color: inherit; padding: 0 2px; border-radius: 3px; }

/* ===== 页脚 ===== */
.footer { background: var(--bg-soft); border-top: 1px solid var(--border); padding: 36px 0 24px; }
.footer-inner { display: flex; flex-direction: column; gap: 18px; align-items: center; text-align: center; }
.footer-brand { display: flex; align-items: center; gap: 12px; }
.footer-brand strong { font-size: 16px; display: block; }
.footer-brand p { margin: 2px 0 0; font-size: 13px; color: var(--text-soft); }
.footer-links { display: flex; gap: 20px; }
.footer-links a { color: var(--text-soft); font-size: 14px; transition: color .2s; }
.footer-links a:hover { color: var(--primary); }
.footer-copy { font-size: 12.5px; color: var(--text-mute); margin: 0; }

/* ===== 返回顶部 ===== */
.back-top {
  position: fixed; right: 24px; bottom: 24px; z-index: 80;
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--grad); color: #fff; font-size: 20px; font-weight: 700;
  box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(10px); transition: opacity .25s, transform .25s;
}
.back-top.show { opacity: 1; transform: translateY(0); }
.back-top:hover { transform: translateY(-2px) scale(1.05); }

/* ===== 响应式 ===== */

/* --- 中等屏幕 --- */
@media (max-width: 1100px) {
  .cat-dropdown { width: 220px; }
}

/* --- 平板/小屏 --- */
@media (max-width: 880px) {
  .cat-selector-label { display: none; }
  .cat-dropdown { width: 200px; }
  .cat-dropdown-btn { padding: 7px 12px; font-size: 13px; }
  .hero { padding: 44px 0 40px; }
  .hero-stats { gap: 18px; font-size: 13px; }
  .main-content.content { padding: 16px 0 40px; }
  .tools-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
  .cat-section + .cat-section { gap: 36px; }
}

@media (max-width: 560px) {
  .container { padding: 0 16px; }
  .hero { padding: 32px 0 32px; }
  .hero-stats { gap: 14px; }
  .cat-dropdown { width: 170px; }
  .cat-dropdown-btn .cat-dropdown-label { font-size: 13px; }
  .cat-dropdown-count { display: none; }
  .main-content.content { padding: 12px 0 32px; }
  .tools-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tool-card { padding: 14px; }
  .tool-logo, .tool-logo-fallback { width: 36px; height: 36px; }
  .tool-name { font-size: 14.5px; }
  .tool-desc { font-size: 12.5px; -webkit-line-clamp: 2; }
  .catalog { gap: 36px; }
  .back-top { right: 16px; bottom: 16px; width: 40px; height: 40px; }
}

@media (max-width: 380px) {
  .tools-grid { grid-template-columns: 1fr; }
}

/* 入场动画 */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.cat-section { animation: fadeUp .5s ease both; }
.cat-section:nth-child(2) { animation-delay: .05s; }
.cat-section:nth-child(3) { animation-delay: .1s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
