/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #a1a1a6;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --border: rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 8px 30px rgba(0,0,0,0.10);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.14);
  --radius: 18px;
  --radius-sm: 12px;
  --nav-h: 52px;

  /* Category colors */
  --c1: #ff6b6b; --c1-bg: #fff0f0;
  --c2: #ff9f43; --c2-bg: #fff7ed;
  --c3: #48dbfb; --c3-bg: #edfbff;
  --c4: #1dd1a1; --c4-bg: #edfff8;
  --c5: #a29bfe; --c5-bg: #f5f3ff;
  --c6: #ffd32a; --c6-bg: #fffceb;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== Nav ===== */
nav {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(245,245,247,0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
}

.nav-inner {
  max-width: 1200px; margin: 0 auto; width: 100%;
  padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
}

.nav-logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text-primary);
}

.nav-logo-icon {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, #0071e3, #00c7ff);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: white;
}

.nav-logo-text { font-size: 15px; font-weight: 600; letter-spacing: -0.3px; }
.nav-logo-sub { font-size: 11px; color: var(--text-secondary); margin-top: -2px; }

.nav-lang {
  display: flex; gap: 4px;
}

.lang-btn {
  padding: 4px 12px; border-radius: 20px; border: none;
  font-size: 13px; cursor: pointer; transition: all 0.2s;
  background: transparent; color: var(--text-secondary);
}
.lang-btn.active {
  background: var(--accent); color: white;
}
.lang-btn:hover:not(.active) { background: var(--border); color: var(--text-primary); }

/* ===== Hero ===== */
.hero {
  text-align: center;
  padding: 80px 24px 56px;
  max-width: 800px; margin: 0 auto;
}

.hero-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, rgba(0,113,227,0.1), rgba(0,199,255,0.1));
  border: 1px solid rgba(0,113,227,0.2);
  color: var(--accent);
  padding: 6px 16px; border-radius: 20px;
  font-size: 13px; font-weight: 500;
  margin-bottom: 20px;
}

.hero h1 {
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1.1;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #1d1d1f 0%, #434343 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero h1 span {
  background: linear-gradient(135deg, #0071e3, #00c7ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  font-size: clamp(16px, 2vw, 20px);
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.hero-en {
  font-size: 14px; color: var(--text-tertiary); margin-bottom: 40px;
}

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

.stat { text-align: center; }
.stat-num { font-size: 28px; font-weight: 700; color: var(--accent); letter-spacing: -1px; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ===== Category Tabs ===== */
.categories {
  max-width: 1200px; margin: 0 auto;
  padding: 0 24px 32px;
}

.cat-scroll {
  display: flex; gap: 8px;
  overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: none;
}
.cat-scroll::-webkit-scrollbar { display: none; }

.cat-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 30px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 14px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: all 0.2s;
  color: var(--text-primary);
}

.cat-btn:hover { border-color: var(--accent); color: var(--accent); }

.cat-btn.active {
  background: var(--accent); color: white;
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(0,113,227,0.3);
}

.cat-dot {
  width: 8px; height: 8px; border-radius: 50%;
}

.cat-count {
  font-size: 12px; opacity: 0.7;
  background: rgba(255,255,255,0.2);
  padding: 2px 7px; border-radius: 10px;
}
.cat-btn:not(.active) .cat-count {
  background: var(--bg); color: var(--text-secondary);
}

/* ===== Cards Grid ===== */
.grid-section {
  max-width: 1200px; margin: 0 auto;
  padding: 0 24px 80px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.3s;
  display: flex; flex-direction: column;
}

.card:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: var(--shadow-lg);
}

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

.card-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}

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

.card-name {
  font-size: 15px; font-weight: 600;
  letter-spacing: -0.3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.card-name-en {
  font-size: 12px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}

.card-body { padding: 0 20px 16px; flex: 1; }

.card-desc {
  font-size: 13px; color: var(--text-secondary);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-desc-en {
  font-size: 12px; color: var(--text-tertiary);
  line-height: 1.5;
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

.card-category {
  font-size: 11px; font-weight: 500;
  padding: 3px 10px; border-radius: 10px;
}

.card-arrow {
  color: var(--accent); font-size: 14px;
  opacity: 0; transition: opacity 0.2s, transform 0.2s;
  transform: translateX(-4px);
}
.card:hover .card-arrow { opacity: 1; transform: translateX(0); }

/* ===== Expanded Card ===== */
.card.expanded { cursor: default; }
.card.expanded:hover { transform: none; }

.card-expand-body {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: none;
}
.card.expanded .card-expand-body { display: block; }

.expand-section { margin-bottom: 14px; }
.expand-label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-tertiary); margin-bottom: 6px;
}
.expand-text { font-size: 13px; color: var(--text-primary); line-height: 1.6; }
.expand-text-en { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag {
  font-size: 11px; padding: 3px 10px; border-radius: 8px;
  background: var(--border); color: var(--text-secondary);
}

.btn-detail {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px;
  padding: 10px 18px; border-radius: 10px;
  background: var(--accent); color: white;
  text-decoration: none; font-size: 13px; font-weight: 500;
  transition: background 0.2s, transform 0.15s;
}
.btn-detail:hover { background: var(--accent-hover); transform: scale(1.02); }

.btn-github {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px; margin-left: 8px;
  padding: 10px 18px; border-radius: 10px;
  background: var(--surface); color: var(--text-primary);
  text-decoration: none; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border);
  transition: background 0.2s;
}
.btn-github:hover { background: var(--bg); }

.collapse-btn {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-secondary);
  cursor: pointer; background: none; border: none;
  margin-top: 8px; padding: 0;
}
.collapse-btn:hover { color: var(--text-primary); }

/* ===== Footer ===== */
footer {
  background: #1d1d1f; color: #a1a1a6;
  text-align: center; padding: 48px 24px;
}
footer .footer-logo { font-size: 24px; margin-bottom: 8px; }
footer p { font-size: 13px; line-height: 1.8; }
footer a { color: #a1a1a6; text-decoration: none; }
footer a:hover { color: white; }

/* ===== Detail Page ===== */
.detail-nav {
  display: flex; align-items: center; gap: 8px;
  padding: 16px 24px;
  max-width: 900px; margin: 0 auto;
}

.back-btn {
  display: flex; align-items: center; gap: 6px;
  color: var(--accent); font-size: 14px; font-weight: 500;
  cursor: pointer; background: none; border: none;
  text-decoration: none;
}
.back-btn:hover { text-decoration: underline; }

.detail-container {
  max-width: 900px; margin: 0 auto;
  padding: 0 24px 80px;
}

.detail-hero {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

.detail-icon { font-size: 48px; margin-bottom: 16px; }

.detail-title { font-size: 32px; font-weight: 700; letter-spacing: -1px; margin-bottom: 4px; }
.detail-title-en { font-size: 18px; color: var(--text-secondary); margin-bottom: 16px; }
.detail-cat-badge {
  display: inline-block;
  font-size: 12px; font-weight: 600;
  padding: 4px 12px; border-radius: 10px;
  margin-bottom: 20px;
}
.detail-desc { font-size: 17px; color: var(--text-secondary); line-height: 1.7; }

.detail-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px;
  border: 1px solid var(--border);
}

.detail-content h2 { font-size: 22px; font-weight: 600; margin: 28px 0 12px; }
.detail-content h3 { font-size: 18px; font-weight: 600; margin: 20px 0 8px; }
.detail-content p { font-size: 15px; color: var(--text-secondary); line-height: 1.8; margin-bottom: 12px; }
.detail-content ul, .detail-content ol { padding-left: 20px; margin-bottom: 12px; }
.detail-content li { font-size: 15px; color: var(--text-secondary); line-height: 1.8; margin-bottom: 4px; }
.detail-content code {
  background: var(--bg); padding: 2px 6px; border-radius: 4px;
  font-size: 13px; font-family: "SF Mono", monospace;
}
.detail-content pre {
  background: #1d1d1f; color: #f5f5f7;
  padding: 20px; border-radius: var(--radius-sm);
  overflow-x: auto; margin-bottom: 16px;
}
.detail-content pre code { background: none; color: inherit; padding: 0; }

.loading { text-align: center; padding: 60px; color: var(--text-secondary); }
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .hero { padding: 48px 20px 40px; }
  .hero h1 { font-size: 28px; }
  .detail-hero { padding: 24px; }
  .detail-content { padding: 24px; }
  .detail-title { font-size: 24px; }
}

/* ===== Animations ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.card { animation: fadeUp 0.4s ease both; }

.card:nth-child(1) { animation-delay: 0.05s; }
.card:nth-child(2) { animation-delay: 0.10s; }
.card:nth-child(3) { animation-delay: 0.15s; }
.card:nth-child(4) { animation-delay: 0.20s; }
.card:nth-child(5) { animation-delay: 0.25s; }
.card:nth-child(6) { animation-delay: 0.30s; }
.card:nth-child(7) { animation-delay: 0.35s; }
.card:nth-child(8) { animation-delay: 0.40s; }

/* ===== Hide/Show lang ===== */
.lang-zh, .lang-en { transition: opacity 0.2s; }
body.lang-en .lang-zh { display: none; }
body.lang-zh .lang-en { display: none; }
