/* ==================== Design Tokens ==================== */
:root[data-theme="dark"] {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #1a1f35;
  --bg-card-hover: #222848;
  --border-color: #2a3050;
  --border-hover: #3d4570;
  --text-primary: #e8ecf4;
  --text-secondary: #8892b0;
  --text-muted: #5a6378;
  --accent: #00d4ff;
  --accent-glow: rgba(0, 212, 255, 0.15);
  --accent-soft: rgba(0, 212, 255, 0.08);
  --gradient-bg: radial-gradient(ellipse at top, rgba(0, 212, 255, 0.06) 0%, transparent 50%);
  --shadow-hover: 0 8px 30px rgba(0, 212, 255, 0.12);
  --ad-bg: #111827;
  --ad-border: #2a3050;
  --ad-text: #5a6378;
}

:root[data-theme="light"] {
  --bg-primary: #f0f4fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f5ff;
  --border-color: #e2e8f0;
  --border-hover: #c8d4f0;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #a0aec0;
  --accent: #0088cc;
  --accent-glow: rgba(0, 136, 204, 0.12);
  --accent-soft: rgba(0, 136, 204, 0.06);
  --gradient-bg: radial-gradient(ellipse at top, rgba(0, 136, 204, 0.05) 0%, transparent 50%);
  --shadow-hover: 0 8px 25px rgba(0, 136, 204, 0.1);
  --ad-bg: #f8fafc;
  --ad-border: #e2e8f0;
  --ad-text: #94a3b8;
}

/* ==================== Reset ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  background-image: var(--gradient-bg);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* ==================== Header ==================== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  transition: background 0.3s ease, border-color 0.3s ease;
}
:root[data-theme="light"] .header { background: rgba(255, 255, 255, 0.88); }

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.back-btn {
  display: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: all 0.25s;
  -webkit-appearance: none;
  text-decoration: none;
}
.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.logo-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #0066ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 0 12px var(--accent-glow);
}

.logo-text {
  background: linear-gradient(135deg, var(--accent), #6c5ce7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  display: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-title.visible { display: block; }

.spacer { flex: 1; }

.theme-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.3s;
  flex-shrink: 0;
  -webkit-appearance: none;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.theme-toggle .sun { display: none; }
:root[data-theme="light"] .theme-toggle .sun { display: block; }
:root[data-theme="light"] .theme-toggle .moon { display: none; }

/* ==================== Main ==================== */
.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 18px 16px 36px;
}

/* ==================== Ad Slots ==================== */
.ad-slot {
  margin: 20px auto;
  min-height: 90px;
  background: var(--ad-bg);
  border: 1px dashed var(--ad-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ad-text);
  font-size: 12px;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
}
.ad-slot::before {
  content: "Google AdSense";
  opacity: 0.5;
}
.ad-slot--top { margin-top: 0; }
.ad-slot--bottom { margin-bottom: 0; max-width: 960px; margin-left: auto; margin-right: auto; width: 100%; }
.ad-slot--inline { min-height: 100px; }

/* ==================== Home View ==================== */
.home-hero {
  text-align: center;
  margin-bottom: 24px;
  padding: 24px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  position: relative;
  overflow: hidden;
}
.home-hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.home-hero h1 { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.home-hero p { color: var(--text-secondary); font-size: 13px; margin-top: 6px; }

/* Category Grid - 6 per row */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}

.cat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-primary);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1 / 1;
}
.cat-card-tint {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.cat-card > *:not(.cat-card-tint) { position: relative; z-index: 1; }
.cat-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent-glow), transparent);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 1;
}
.cat-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}
.cat-card:hover::before { opacity: 1; }
.cat-card:active { transform: translateY(-1px); }

.cat-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cat-card-icon svg { width: 28px; height: 28px; }

.cat-card-name {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
}

/* AdSense grid card base - occupies one grid cell */
.ad-card {
  background: var(--ad-bg);
  border: 1px dashed var(--ad-border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.ad-card::before {
  content: "Ad";
  color: var(--ad-text);
  font-size: 10px;
  opacity: 0.5;
}
.ad-card ins.adsbygoogle {
  width: 100%;
  height: 100%;
  display: block;
}

/* AdSense grid card in cat-grid (home) - single cell, square */
.cat-grid .ad-card {
  aspect-ratio: 1 / 1;
}

/* ==================== Category Detail Page ==================== */
.cat-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}
.cat-detail-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cat-detail-icon svg { width: 24px; height: 24px; }
.cat-detail-title { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.cat-detail-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 3px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

/* Site Grid - 5 per row */
.site-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: minmax(56px, auto);
  gap: 12px;
}

.site-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text-primary);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}
.site-item:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}
.site-item:active { transform: translateY(0); }

/* AdSense grid card in site-grid - variant 1: spans 2 rows (vertical) */
.site-grid .ad-card--span2 {
  grid-row: span 2;
  aspect-ratio: auto;
  min-height: 100%;
}

/* AdSense grid card in site-grid - variant 2: spans 2x2 (4 cells) */
.site-grid .ad-card--span2x2 {
  grid-row: span 2;
  grid-column: span 2;
  aspect-ratio: auto;
  min-height: 100%;
}

/* AdSense grid card in cat-grid (home) - single cell, square */
.cat-grid .ad-card {
  aspect-ratio: 1 / 1;
}

.site-favicon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg-secondary);
  position: relative;
}
.site-favicon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.site-favicon-fallback {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

.site-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-arrow {
  color: var(--text-muted);
  font-size: 14px;
  opacity: 0;
  transform: translateX(-4px);
  transition: all 0.2s;
  flex-shrink: 0;
}
.site-item:hover .site-arrow {
  opacity: 1;
  transform: translateX(0);
  color: var(--accent);
}

/* ==================== Footer ==================== */
.footer {
  text-align: center;
  padding: 24px 24px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 12px;
}

/* ==================== Responsive ==================== */
@media (max-width: 1200px) {
  .site-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (max-width: 1024px) {
  .cat-grid { grid-template-columns: repeat(5, 1fr); }
  .site-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 768px) {
  .header-inner { padding: 0 14px; height: 44px; gap: 8px; }
  .logo { font-size: 14px; gap: 6px; }
  .logo-icon { width: 22px; height: 22px; font-size: 12px; }
  .back-btn, .theme-toggle { width: 30px; height: 30px; font-size: 13px; }
  .header-title { font-size: 13px; }
  .main { padding: 14px 12px 32px; }
  .home-hero { padding: 20px 14px; margin-bottom: 20px; }
  .home-hero h1 { font-size: 17px; }
  .home-hero p { font-size: 12px; }
  .cat-grid { grid-template-columns: repeat(5, 1fr); gap: 10px; }
  .cat-card { padding: 10px 5px; gap: 6px; border-radius: 8px; }
  .cat-card-icon { width: 36px; height: 36px; border-radius: 8px; }
  .cat-card-icon svg { width: 20px; height: 20px; }
  .cat-card-name { font-size: 18px; }
  .cat-detail-title { font-size: 16px; }
  .site-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .site-item { padding: 10px 12px; gap: 8px; border-radius: 10px; }
  .site-favicon { width: 24px; height: 24px; border-radius: 6px; }
  .site-name { font-size: 13px; }
}

@media (max-width: 480px) {
  .logo-text { display: none; }
  .main { padding: 14px 12px 36px; }
  .home-hero { padding: 18px 12px; margin-bottom: 16px; }
  .home-hero h1 { font-size: 15px; }
  .home-hero p { font-size: 11px; }
  .cat-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .cat-card { padding: 8px 4px; gap: 5px; }
  .cat-card-icon { width: 32px; height: 32px; border-radius: 6px; }
  .cat-card-icon svg { width: 18px; height: 18px; }
  .cat-card-name { font-size: 16px; }
  .site-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .site-item { padding: 9px 10px; gap: 8px; }
  .site-favicon { width: 22px; height: 22px; border-radius: 5px; }
  .site-name { font-size: 12px; }
  .site-arrow { display: none; }
  .footer { font-size: 11px; padding: 20px 16px; }
  .ad-slot { min-height: 80px; }
}

@media (max-width: 360px) {
  .cat-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .cat-card { padding: 6px 3px; }
  .cat-card-icon { width: 28px; height: 28px; }
  .cat-card-icon svg { width: 16px; height: 16px; }
  .cat-card-name { font-size: 14px; }
  .site-grid { grid-template-columns: 1fr; gap: 6px; }
  .site-item { padding: 8px 10px; }
  .site-favicon { width: 20px; height: 20px; }
  .site-name { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .cat-card:hover, .site-item:hover { transform: none; }
}

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