* {
  box-sizing: border-box;
}

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --subtext: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --primary-border: #c7d2fe;
  --star: #f59e0b;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
  --shadow-hover: 0 14px 32px rgba(79, 70, 229, 0.14);
  --radius: 18px;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;min-height: 100dvh;
}

a, button, input {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.page {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

/* ========== 轻量头部（无大横幅） ========== */
.site-header {
  padding: 8px 0 20px;
}

.eyebrow {
  display: inline-block;
  margin: 0 0 10px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  border: 1px solid #e0e7ff;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
}

.site-header h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.3;
  letter-spacing: 0.2px;
}

.subtitle {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
  color: var(--subtext);
  max-width: 760px;
}

/* ========== 统计行（全部动态） ========== */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--primary);
}

.stat-label {
  font-size: 13px;
  color: var(--subtext);
}

/* ========== 工具栏：搜索 + 视图 + 筛选 ========== */
.toolbar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 14px;
}

.search-box {
  flex: 1 1 320px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 0 14px;
  min-height: 52px;
  box-shadow: var(--shadow-sm);
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.search-box img {
  width: 22px;
  height: 22px;
  object-fit: cover;
  flex-shrink: 0;
}

.search-box input {
  border: none;
  outline: none;
  flex: 1;
  min-width: 0;
  font-size: 16px;
  color: var(--text);
  background: transparent;
}

.clear-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--subtext);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.clear-btn:hover {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.view-toggle {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  flex-shrink: 0;
}

.view-btn {
  border: none;
  background: #fff;
  color: var(--subtext);
  padding: 0 18px;
  min-height: 52px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.view-btn.active {
  background: var(--primary);
  color: #fff;
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: #475467;
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  font-size: 14px;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--primary-border);
  color: var(--primary-dark);
}

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.chip-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.12);
  font-size: 12px;
  font-weight: 700;
}

.chip.active .chip-count {
  background: rgba(255, 255, 255, 0.22);
}

.result-count {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--subtext);
}

/* ========== 工具卡片网格（自适应，不写死列数） ========== */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.tool-grid.list-view {
  grid-template-columns: 1fr;
}

.tool-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.tool-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  border-color: var(--primary-border);
}

.tool-card-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.tool-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background: var(--primary-soft);
  border: 1px solid #e0e7ff;
  flex-shrink: 0;
}

.tool-icon img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 8px;
}

.fav-btn {
  margin-left: auto;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
  color: #94a3b8;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.fav-btn[aria-pressed="true"] {
  color: var(--star);
  border-color: #fde68a;
  background: #fffbeb;
}

.tool-card-body {
  flex: 1 1 auto;
  min-width: 0;
}

.tool-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.5;
  margin: 0 0 8px;
}

.tool-desc {
  font-size: 14px;
  line-height: 1.7;
  color: var(--subtext);
  margin-bottom: 14px;
}

.tool-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tool-meta-item {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f8fafc;
  border: 1px solid #e6eaf0;
  color: #475467;
  font-size: 12px;
  line-height: 1;
}

.tool-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  min-height: 44px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
  flex: 1 1 auto;
}

.btn-primary {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.22);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  color: var(--primary-dark);
  background: #fff;
  border: 1.5px solid var(--primary-border);
}

.btn-secondary:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

/* ========== 紧凑列表视图 ========== */
.tool-card-row {
  flex-direction: row;
  align-items: center;
  gap: 16px;
}

.tool-card-row .tool-card-head {
  margin-bottom: 0;
  flex: 0 0 auto;
}

.tool-card-row .tool-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 10px;
}

.tool-card-row .tool-meta {
  margin-bottom: 0;
}

.tool-card-row .tool-actions {
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

.tool-card-row .tool-actions .btn {
  flex: 0 0 auto;
}

.empty-state {
  text-align: center;
}

.empty-state .tool-actions {
  justify-content: center;
}

.empty-state .tool-actions .btn {
  flex: 0 0 auto;
}

/* ========== 统计悬浮按钮（链接不变，仅按新风格重排样式） ========== */
.stats-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.35);
  z-index: 9999;
}

.stats-fab img {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 6px;
}

/* ========== 底部 ========== */
.footer {
  margin-top: 30px;
  text-align: center;
  color: var(--subtext);
  font-size: 12px;
  line-height: 1.8;
  padding: 12px 8px 0;
}

/* ========== 移动端 ========== */
@media (max-width: 760px) {
  .page {
    padding: 20px 14px 36px;
  }

  .site-header h1 {
    font-size: 26px;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
    padding: 16px 18px;
  }

  .search-box {
    flex: 1 1 100%;
  }

  .view-toggle {
    width: 100%;
  }

  .view-btn {
    flex: 1 1 50%;
  }

  .tool-card-row {
    flex-direction: column;
    align-items: stretch;
  }

  .tool-card-row .tool-actions {
    width: 100%;
  }

  .tool-card-row .tool-actions .btn {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tool-card,
  .btn,
  .chip {
    transition: none;
  }

  .tool-card:hover {
    transform: none;
  }
}

/* ========== 主题切换按钮 ========== */
.theme-btn {
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  padding: 0 16px;
  min-height: 52px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.theme-btn:hover {
  border-color: var(--primary-border);
  color: var(--primary-dark);
}

/* ========== 深色主题（data-theme="dark"，由 JS 按日出日落或手动切换） ========== */
[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --subtext: #94a3b8;
  --border: #334155;
  --primary: #6366f1;
  --primary-dark: #818cf8;
  --primary-soft: #1e1b4b;
  --primary-border: #4338ca;
  --star: #fbbf24;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 14px 32px rgba(99, 102, 241, 0.28);
  color-scheme: dark;
}

/* 以下选择器在浅色样式里写死了颜色，深色下逐个覆盖。 */
[data-theme="dark"] .search-box,
[data-theme="dark"] .view-btn,
[data-theme="dark"] .chip,
[data-theme="dark"] .fav-btn,
[data-theme="dark"] .btn-secondary,
[data-theme="dark"] .theme-btn {
  background: var(--card);
}

[data-theme="dark"] .chip {
  color: #cbd5e1;
}

[data-theme="dark"] .chip-count {
  background: rgba(148, 163, 184, 0.18);
}

[data-theme="dark"] .tool-meta-item {
  background: #0f172a;
  border-color: #334155;
  color: #cbd5e1;
}

[data-theme="dark"] .tool-icon {
  border-color: #3730a3;
}

[data-theme="dark"] .eyebrow {
  border-color: #3730a3;
}

[data-theme="dark"] .fav-btn {
  color: #64748b;
}

[data-theme="dark"] .fav-btn[aria-pressed="true"] {
  color: var(--star);
  border-color: #78350f;
  background: #451a03;
}

[data-theme="dark"] .search-box input::placeholder {
  color: var(--subtext);
}

[data-theme="dark"] .search-box input {
  color-scheme: dark;
}

@media (max-width: 760px) {
  .theme-btn {
    flex: 1 1 100%;
  }
}
