:root {
  --bg-deep: #0a0a0f;
  --bg-surface: #12121a;
  --bg-card: #1a1a24;
  --bg-card-hover: #22222e;
  --text-primary: #e8e8ed;
  --text-secondary: #8888a0;
  --text-muted: #55556a;
  --border-subtle: #2a2a3a;
  --border-strong: #3a3a4a;
  --accent-cyan: #00f5d4;
  --accent-magenta: #f72585;
  --accent-yellow: #fee440;
  --accent-blue: #4cc9f0;
  --accent-purple: #7b2cbf;
  --accent-orange: #ff9f1c;
  --accent-red: #ff6b6b;
  --accent-green: #06d6a0;
  --glow-cyan: rgb(0 245 212 / 15%);
  --glow-magenta: rgb(247 37 133 / 15%);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

[data-theme='light'] {
  --bg-deep: #fafafa;
  --bg-surface: #fff;
  --bg-card: #fff;
  --bg-card-hover: #f5f5f5;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #999;
  --border-subtle: #e5e5e5;
  --border-strong: #d4d4d4;
  --accent-cyan: #00d4b8;
  --accent-magenta: #e63975;
  --accent-yellow: #f5c518;
  --accent-blue: #0ea5e9;
  --accent-purple: #9333ea;
  --glow-cyan: rgb(0 212 184 / 10%);
  --glow-magenta: rgb(230 57 117 / 10%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgb(0 245 212 / 3%) 1px, transparent 1px),
    linear-gradient(90deg, rgb(0 245 212 / 3%) 1px, transparent 1px);
  background-size: 50px 50px;
  pointer-events: none;
  z-index: 0;
}

.bg-gradient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, var(--glow-cyan), transparent),
    radial-gradient(ellipse 60% 40% at 80% 110%, var(--glow-magenta), transparent);
  pointer-events: none;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 24px 80px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  position: relative;
  gap: 16px;
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.hero-stats {
  display: flex;
  align-items: center;
  gap: 20px;
}

.stat-item {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.stat-number {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-cyan);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.stat-divider {
  width: 1px;
  height: 16px;
  background: var(--border-subtle);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.25s ease;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--accent-cyan);
  color: var(--text-primary);
  box-shadow: 0 0 0 3px rgb(0 245 212 / 12%);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--bg-deep);
  transform: rotate(-3deg);
  box-shadow: 0 2px 10px var(--glow-cyan);
  flex-shrink: 0;
}

header h1 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.tagline {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: none;
}

@media (min-width: 768px) {
  .tagline {
    display: flex;
    align-items: center;
    gap: 8px;
  }
}

.tagline span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tagline .dot {
  width: 3px;
  height: 3px;
  background: var(--accent-cyan);
  border-radius: 50%;
}

.search-wrapper {
  max-width: 560px;
  margin: 0 auto 28px;
  position: relative;
}

.search-box {
  position: relative;
}

.search-box::before {
  content: '>';
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  color: var(--accent-cyan);
  font-weight: 600;
}

.search-box input {
  width: 100%;
  padding: 12px 16px 12px 38px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  color: var(--text-primary);
  outline: none;
  transition: all 0.25s ease;
}

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

.search-box input:focus {
  border-color: var(--accent-cyan);
  box-shadow:
    0 0 0 3px rgb(0 245 212 / 12%),
    0 4px 16px rgb(0 245 212 / 10%);
}

.search-results-count {
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 10px;
  min-height: 18px;
}

.search-hint {
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.search-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-size: 0.65rem;
  margin: 0 2px;
}

/* 桌面端 categories-wrapper */
.categories-wrapper {
  margin-bottom: 32px;
  position: relative;
}

.categories-wrapper::after {
  display: none;
}

.categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-height: 90px; /* 约2行分类按钮 */
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.categories-wrapper.expanded .categories {
  max-height: 2000px;
}

/* 桌面端展开按钮 */
.categories-expand-btn-desktop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 12px auto 0;
  padding: 6px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.25s ease;
}

.categories-expand-btn-desktop:hover {
  border-color: var(--accent-cyan);
  color: var(--text-primary);
}

.categories-expand-btn-desktop .expand-icon {
  transition: transform 0.3s ease;
  font-size: 0.7rem;
}

.categories-wrapper.expanded .categories-expand-btn-desktop .expand-icon {
  transform: rotate(180deg);
}

.category-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.category-btn .cat-icon {
  font-size: 0.9rem;
  transition: transform 0.25s ease;
}

.category-btn .cat-count {
  font-size: 0.65rem;
  padding: 2px 6px;
  background: var(--bg-card);
  border-radius: 10px;
  color: var(--text-muted);
  transition: all 0.25s ease;
  font-weight: 600;
}

.category-btn:hover {
  border-color: var(--accent-cyan);
  color: var(--text-primary);
  background: var(--bg-card);
}

.category-btn:hover .cat-icon {
  transform: scale(1.1);
}

.category-btn:hover .cat-count {
  background: rgb(0 245 212 / 15%);
  color: var(--accent-cyan);
}

.category-btn.active {
  background: var(--bg-card);
  border-color: var(--accent-cyan);
  color: var(--text-primary);
  box-shadow:
    0 0 0 1px var(--accent-cyan),
    0 2px 12px rgb(0 245 212 / 20%);
}

.category-btn.active .cat-count {
  background: var(--accent-cyan);
  color: var(--bg-deep);
}

.category-btn.active .cat-icon {
  transform: scale(1.1);
}

/* Light theme adjustments */
[data-theme='light'] .category-btn.active {
  background: rgb(0 212 184 / 8%);
  box-shadow:
    0 0 0 1px var(--accent-cyan),
    0 2px 12px rgb(0 212 184 / 15%);
}

[data-theme='light'] .category-btn:hover .cat-count {
  background: rgb(0 212 184 / 12%);
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;

  /* 性能优化 */
  will-change: contents;
  contain: layout style;
}

.tool-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  animation: fade-in-up 0.5s ease backwards;

  /* 性能优化 */
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: transform;
  contain: layout paint;
}

.tool-card::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  height: 3px;
  background: linear-gradient(90deg, var(--card-accent, var(--accent-cyan)), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.tool-card:hover {
  border-color: var(--card-accent, var(--accent-cyan));
  background: var(--bg-card-hover);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px -8px rgb(0 0 0 / 40%);
}

.tool-card:hover::before {
  opacity: 1;
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
}
.tool-title-group {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex: 1;
}

.tool-icon {
  width: 44px;
  height: 44px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  color: var(--card-accent, var(--accent-cyan));
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.tool-card:hover .tool-icon {
  background: var(--card-accent, var(--accent-cyan));
  border-color: var(--card-accent, var(--accent-cyan));
  color: var(--bg-deep);
  transform: scale(1.05);
}

.tool-card h3 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.3;
}

.tool-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
  flex-grow: 1;
}

.tool-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.tool-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 4px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tool-arrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.2rem;
  color: var(--text-muted);
  transition: all 0.3s ease;
}

.tool-card:hover .tool-arrow {
  color: var(--card-accent, var(--accent-cyan));
  transform: translateX(4px);
}

.tool-card.hidden {
  display: none;
}

/* 分类颜色 */
.tool-card[data-category='dev'] {
  --card-accent: var(--accent-cyan);
}
.tool-card[data-category='text'] {
  --card-accent: var(--accent-blue);
}
.tool-card[data-category='time'] {
  --card-accent: var(--accent-yellow);
}
.tool-card[data-category='generator'] {
  --card-accent: var(--accent-magenta);
}
.tool-card[data-category='privacy'] {
  --card-accent: var(--accent-purple);
}
.tool-card[data-category='media'] {
  --card-accent: var(--accent-red);
}
.tool-card[data-category='security'] {
  --card-accent: var(--accent-orange);
}
.tool-card[data-category='network'] {
  --card-accent: var(--accent-green);
}
.tool-card[data-category='calculator'] {
  --card-accent: #f97316;
}
.tool-card[data-category='converter'] {
  --card-accent: #a855f7;
}
.tool-card[data-category='extractor'] {
  --card-accent: #ec4899;
}
.tool-card[data-category='ai'] {
  --card-accent: #6366f1;
}

.favorite-btn {
  width: 36px;
  height: 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.25s ease;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: auto;
}

.favorite-btn:hover {
  border-color: var(--accent-yellow);
  background: var(--bg-card-hover);
  color: var(--accent-yellow);
  box-shadow: 0 0 0 3px rgb(254 228 64 / 15%);
}

.favorite-btn.active {
  background: var(--accent-yellow);
  border-color: var(--accent-yellow);
  color: var(--bg-deep);
}

.favorite-btn.active:hover {
  box-shadow: 0 0 0 3px rgb(254 228 64 / 25%);
}

.favorite-btn:focus-visible {
  outline: none;
  border-color: var(--accent-yellow);
  box-shadow: 0 0 0 3px rgb(254 228 64 / 20%);
}

.tool-card:focus-visible {
  outline: none;
  border-color: var(--card-accent, var(--accent-cyan));
  box-shadow:
    0 0 0 3px rgb(0 245 212 / 15%),
    0 8px 24px -8px rgb(0 0 0 / 40%);
  transform: translateY(-3px);
}

.no-results {
  text-align: center;
  padding: 60px 20px;
  display: none;
}

.no-results.show {
  display: block;
}
.no-results-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.no-results p {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  font-size: 1rem;
}

footer {
  text-align: center;
  margin-top: 80px;
  padding: 32px 0;
  border-top: 1px solid var(--border-subtle);
}

footer p {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

footer a {
  color: var(--accent-cyan);
  text-decoration: none;
  transition: color 0.2s ease;
}

footer a:hover {
  color: var(--text-primary);
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 加载指示器（隐藏但用于触发懒加载） */
#load-trigger {
  height: 1px;
  margin: 0;
  visibility: hidden;
}

@media (width <= 640px) {
  .container {
    padding: 16px 12px 60px;
  }

  /* 隐藏桌面端展开按钮 */
  .categories-expand-btn-desktop {
    display: none !important;
  }

  /* Header 移动端布局 - 单行紧凑 */
  header {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
  }

  .header-left {
    flex: 1;
    min-width: 0;
  }

  .header-right {
    flex-shrink: 0;
    gap: 10px;
  }

  .hero-stats {
    gap: 8px;
  }

  .stat-item {
    gap: 2px;
  }

  .stat-number {
    font-size: 0.9rem;
  }

  .stat-label {
    font-size: 0.65rem;
  }

  .stat-divider {
    height: 12px;
  }

  .logo {
    gap: 8px;
  }

  .logo-icon {
    width: 28px;
    height: 28px;
    font-size: 11px;
    border-radius: 6px;
  }
  header h1 {
    font-size: 1rem;
  }
  .theme-toggle {
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
    border-radius: 6px;
  }

  /* 搜索框 - 减少空白 */
  .search-wrapper {
    position: sticky;
    top: 0;
    z-index: 100;
    margin: 0 -12px 10px;
    padding: 8px 12px 6px;
    background: var(--bg-deep);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-subtle);
  }

  .search-box input {
    padding: 10px 14px 10px 36px;
    font-size: 16px; /* 防止 iOS 自动缩放 */
    border-radius: 16px;
    -webkit-appearance: none;
  }

  .search-box::before {
    left: 12px;
    font-size: 0.9rem;
  }
  .search-hint {
    display: none;
  }
  .search-results-count {
    display: none;
  } /* Hide on mobile */

  /* 分类区域 - 限制3行 + 展开按钮 */
  .categories-wrapper {
    margin: 0 0 12px;
    position: relative;
  }

  .categories-wrapper::after {
    display: none;
  }

  .categories {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
    margin: 0;
    padding: 0;
    max-height: 102px; /* 约3行 */
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  .categories-wrapper.expanded .categories {
    max-height: 500px;
  }

  .categories-expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    margin-top: 8px;
    padding: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-muted);
    background: transparent;
    border: 1px dashed var(--border-subtle);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .categories-expand-btn:hover {
    color: var(--text-secondary);
    border-color: var(--border-strong);
  }

  .categories-expand-btn:focus-visible {
    color: var(--text-secondary);
    border-color: var(--accent-cyan);
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-cyan);
  }

  .categories-expand-btn .expand-icon {
    transition: transform 0.3s ease;
  }

  .categories-wrapper.expanded .categories-expand-btn .expand-icon {
    transform: rotate(180deg);
  }

  .category-btn {
    padding: 5px 8px;
    font-size: 0.65rem;
    white-space: nowrap;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    border-radius: 12px;
    box-shadow: none;
    border-width: 1px;
    gap: 4px;
  }

  .category-btn .cat-icon {
    font-size: 0.8rem;
  }

  .category-btn .cat-count {
    display: none;
  }

  .category-btn.active {
    box-shadow: 0 0 0 1.5px var(--accent-cyan);
    transform: none;
  }

  /* 工具卡片紧凑 - 优化 */
  .tools-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 20px;
  }

  .tool-card {
    padding: 18px;
    gap: 10px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .tool-icon {
    width: 38px;
    height: 38px;
    font-size: 17px;
  }
  .tool-title-group {
    gap: 12px;
  }
  .tool-card h3 {
    font-size: 1rem;
    font-weight: 600;
  }
  .tool-card p {
    font-size: 0.85rem;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tool-tag {
    font-size: 0.7rem;
    padding: 4px 10px;
  }
  .tool-arrow {
    font-size: 1.1rem;
  }

  /* 收藏按钮 - 更大触摸区域 */
  .favorite-btn {
    width: 40px;
    height: 40px;
    font-size: 16px;
    position: relative;
  }

  .favorite-btn::before {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
  }

  /* Footer */
  footer {
    margin-top: 40px;
    padding: 20px 0;
  }
  footer p {
    font-size: 0.75rem;
    gap: 6px;
  }
}
