:root {
  --tg-blue: #2AABEE;
  --tg-blue-dark: #229ED9;
  --tg-blue-light: rgba(42, 171, 238, 0.12);
  --bg-primary: #f4f7fb;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 8px 32px rgba(42, 171, 238, 0.12);
  --radius: 12px;
  --radius-lg: 16px;
  --header-height: 64px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  --bg-primary: #0f1419;
  --bg-secondary: #1a2332;
  --bg-card: #1e2a3a;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #2d3a4d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --tg-blue-light: rgba(42, 171, 238, 0.18);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  transition: background 0.3s, color 0.3s;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.bg-gradient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(42, 171, 238, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(42, 171, 238, 0.08), transparent);
  pointer-events: none;
  z-index: -1;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 24px);
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

[data-theme="dark"] .header {
  background: rgba(15, 20, 25, 0.9);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  gap: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.15rem;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--tg-blue), var(--tg-blue-dark));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.logo-icon svg {
  width: 22px;
  height: 22px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav,
.desktop-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-secondary);
  cursor: pointer;
}

.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

body.nav-open .menu-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.nav-open .menu-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .menu-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.mobile-nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.4);
}

.mobile-nav {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  z-index: 95;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px clamp(16px, 4vw, 24px);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-lg);
}

.mobile-nav-link {
  padding: 14px 16px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 500;
  font-size: 1rem;
  transition: background 0.2s;
}

.mobile-nav-link:hover,
.mobile-nav-link:active,
.mobile-nav-link.active {
  background: var(--tg-blue-light);
  color: var(--tg-blue);
}

body.nav-open { overflow: hidden; }

.nav-link {
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-link:hover,
.nav-link.active {
  color: var(--tg-blue);
  background: var(--tg-blue-light);
}

.nav-link-accent {
  color: var(--tg-blue);
  border: 1px solid var(--tg-blue);
  background: transparent;
}

.nav-link-accent:hover {
  background: var(--tg-blue);
  color: white;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-toggle:hover {
  border-color: var(--tg-blue);
  color: var(--tg-blue);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* Hero */
.hero {
  padding: 64px 0 48px;
  text-align: center;
}

.hero-title {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  color: var(--text-primary);
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--tg-blue) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 520px;
  margin: 0 auto 36px;
}

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

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 16px 48px 16px 50px;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.search-input:focus {
  border-color: var(--tg-blue);
  box-shadow: var(--shadow-lg);
}

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

.search-hint {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 8px;
  font-size: 0.75rem;
  font-family: inherit;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
}

.stats {
  display: flex;
  justify-content: center;
  gap: 48px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--tg-blue);
}

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

/* Filters */
.filters-section {
  padding-bottom: 24px;
}

.filters {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.filter-group + .filter-group {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.filter-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.filter-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-block;
}

.filter-tab:hover {
  border-color: var(--tg-blue);
  color: var(--tg-blue);
}

.filter-tab.active {
  background: var(--tg-blue);
  border-color: var(--tg-blue);
  color: white;
}

.filter-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-tag {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-tag:hover {
  border-color: var(--tg-blue);
  color: var(--tg-blue);
}

.filter-tag.active {
  background: var(--tg-blue-light);
  border-color: var(--tg-blue);
  color: var(--tg-blue);
  font-weight: 500;
}

/* Content */
.content-section {
  padding: 24px 0 64px;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
}

.section-title {
  font-size: 1.35rem;
  font-weight: 600;
}

.result-count {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: clamp(12px, 3vw, 20px);
}

/* Loading */
.loading-state,
.load-more,
.end-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

.load-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.end-state p {
  font-size: 0.875rem;
  padding: 16px;
  border-top: 1px dashed var(--border);
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 12px;
  border: 3px solid var(--border);
  border-top-color: var(--tg-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 20px;
  height: 20px;
  margin: 0;
  border-width: 2px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all 0.25s;
  box-shadow: var(--shadow);
}

.card:hover {
  border-color: var(--tg-blue);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-featured-tag {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--tg-blue);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  pointer-events: none;
}

.card.is-featured .card-link-body {
  padding-top: 4px;
}

.featured-section {
  padding: 8px 0 16px;
}

.featured-section.hidden {
  display: none;
}

.featured-header {
  margin-bottom: 16px;
}

.featured-header .section-title {
  font-size: 1.15rem;
}

.card-link-body {
  text-decoration: none;
  color: inherit;
  display: block;
  flex: 1;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.card-footer .btn-secondary {
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.card-footer .btn-secondary:hover {
  border-color: var(--tg-blue);
  color: var(--tg-blue);
}

.card-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.card-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-avatar-letter {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
}

.card-avatar.avatar-fallback .card-avatar-letter {
  display: flex;
}

.card-info {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-channel { background: #dbeafe; color: #1d4ed8; }
.badge-group { background: #dcfce7; color: #15803d; }
.badge-bot { background: #fef3c7; color: #b45309; }
.badge-default { background: var(--tg-blue-light); color: var(--tg-blue); }

[data-theme="dark"] .badge-channel { background: rgba(29, 78, 216, 0.2); color: #93c5fd; }
[data-theme="dark"] .badge-group { background: rgba(21, 128, 61, 0.2); color: #86efac; }
[data-theme="dark"] .badge-bot { background: rgba(180, 83, 9, 0.2); color: #fcd34d; }

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

.card-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.card-members {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-members svg {
  width: 14px;
  height: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--tg-blue);
  color: white;
}

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

.btn-secondary {
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--tg-blue);
  color: var(--tg-blue);
}

.btn-join {
  padding: 6px 14px;
  font-size: 0.8rem;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  margin-bottom: 16px;
}

.hidden {
  display: none !important;
}

/* Submit section */
.stats-section {
  padding: 8px 0 32px;
}

.stats-section .stats {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.submit-section {
  padding-bottom: 64px;
}

.submit-card {
  background: linear-gradient(135deg, var(--tg-blue), var(--tg-blue-dark));
  border-radius: var(--radius-lg);
  padding: 40px 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: white;
}

.submit-content h2 {
  font-size: 1.35rem;
  margin-bottom: 8px;
}

.submit-content p {
  opacity: 0.9;
  font-size: 0.95rem;
}

.submit-card .btn-primary {
  background: white;
  color: var(--tg-blue);
  flex-shrink: 0;
}

.submit-card .btn-primary:hover {
  background: rgba(255, 255, 255, 0.9);
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  background: var(--bg-secondary);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  gap: 20px;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--tg-blue);
}

.desktop-only { display: inline; }

/* Responsive — 大屏 */
@media (min-width: 1400px) {
  .container { max-width: 1320px; }
  .cards-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Responsive — 平板 */
@media (max-width: 1024px) {
  .hero { padding: 48px 0 36px; }
  .stats { gap: 32px; }
}

/* Responsive — 手机 */
@media (max-width: 768px) {
  :root { --header-height: 56px; }

  .desktop-nav { display: none; }
  .menu-toggle { display: flex; }
  .desktop-only { display: none; }

  .logo-text { font-size: 1rem; }
  .logo-icon { width: 32px; height: 32px; border-radius: 8px; }
  .logo-icon svg { width: 18px; height: 18px; }

  .hero { padding: 32px 0 24px; }
  .hero-title {
    -webkit-text-fill-color: unset;
    background: none;
    color: var(--text-primary);
  }
  .hero-subtitle { font-size: 0.95rem; margin-bottom: 24px; }

  .search-input {
    padding: 14px 16px 14px 44px;
    font-size: 16px; /* 防止 iOS 缩放 */
  }

  .search-icon { left: 14px; width: 18px; height: 18px; }

  .stats-section { padding: 4px 0 24px; }
  .stats-section .stats { padding: 20px 16px; max-width: none; }

  .stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    max-width: 320px;
    margin: 0 auto;
  }

  .stat-value { font-size: 1.4rem; }

  .filters { padding: 16px; }
  .filter-tab { padding: 10px 16px; min-height: 44px; }
  .filter-tag { padding: 8px 14px; min-height: 40px; }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .cards-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .card { padding: 12px; gap: 8px; }
  .card-header { gap: 8px; }
  .card-avatar { width: 36px; height: 36px; font-size: 0.95rem; border-radius: 8px; }
  .card-title { font-size: 0.85rem; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .card-meta { gap: 4px; }
  .card-badge { font-size: 0.6rem; padding: 1px 6px; }
  .card-category { font-size: 0.65rem; }
  .card-desc { font-size: 0.75rem; -webkit-line-clamp: 2; }

  .card-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding-top: 4px;
  }

  .card-members { justify-content: center; font-size: 0.7rem; }
  .card-actions { gap: 6px; }
  .card-actions .btn { flex: 1; min-width: 0; }

  .btn-join {
    padding: 6px 8px;
    font-size: 0.7rem;
    min-height: 32px;
  }

  .submit-card {
    flex-direction: column;
    text-align: center;
    padding: 28px 20px;
  }

  .submit-card .btn-primary { width: 100%; min-height: 48px; }

  .footer {
    padding: 20px 0;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .footer-inner {
    flex-direction: column;
    text-align: center;
  }

  .footer-links { flex-wrap: wrap; justify-content: center; }
}

/* Responsive — 小屏手机 */
@media (max-width: 380px) {
  .stats { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat-value { font-size: 1.2rem; }
  .stat-label { font-size: 0.75rem; }
  .filter-tabs { gap: 6px; }
  .filter-tab { padding: 8px 12px; font-size: 0.8rem; }
  .cards-grid { gap: 8px; }
  .card { padding: 10px; }
  .card-title { font-size: 0.8rem; }
  .btn-join { font-size: 0.65rem; min-height: 30px; }
}

/* 触摸设备优化 */
@media (hover: none) {
  .card:hover { transform: none; }
  .card:active { border-color: var(--tg-blue); }
}

/* 横屏手机 */
@media (max-height: 500px) and (orientation: landscape) {
  .hero { padding: 20px 0 16px; }
  .stats { flex-direction: row; display: flex; max-width: none; }
}
