/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-card: #1e1e1e;
  --bg-card-hover: #252525;
  --bg-input: #252525;
  --text-primary: #e8e8e8;
  --text-secondary: #999;
  --text-muted: #666;
  --accent: #6c5ce7;
  --accent-hover: #7f70ed;
  --accent-glow: rgba(108, 92, 231, 0.25);
  --border: #2a2a2a;
  --tag-bg: rgba(108, 92, 231, 0.12);
  --tag-text: #a89cf4;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.25s ease;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ===== Layout ===== */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 15, 15, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
}

.header-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.site-logo {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.site-logo .dot {
  color: var(--accent);
}

.site-slogan {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ===== Search ===== */
.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  display: none;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--transition);
}

.search-clear:hover {
  color: var(--text-secondary);
}

.search-clear.visible {
  display: block;
}

/* ===== Category Nav ===== */
.category-nav {
  padding: 18px 0 6px;
  position: sticky;
  top: 0;
  z-index: 90;
  background: rgba(15, 15, 15, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.cat-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cat-tab:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.cat-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.cat-tab .cat-icon {
  font-size: 1rem;
}

.cat-tab .cat-count {
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 2px;
}

.cat-tab.active .cat-count {
  background: rgba(255, 255, 255, 0.25);
}

/* ===== Resource Cards ===== */
.resource-section {
  padding: 8px 0 20px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .sec-icon {
  font-size: 1.2rem;
}

.cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 960px) {
  .cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.resource-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.resource-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  opacity: 0;
  transition: opacity var(--transition);
}

.resource-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 1px var(--accent-glow);
  transform: translateY(-2px);
}

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

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  flex: 1;
}

.card-desc {
  font-size: 0.82rem;
  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;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  gap: 8px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--tag-bg);
  color: var(--tag-text);
  white-space: nowrap;
}

.card-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.card-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.card-btn .btn-arrow {
  font-size: 0.85rem;
  transition: transform var(--transition);
}

.card-btn:hover .btn-arrow {
  transform: translateX(2px);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.9rem;
}

/* ===== Result Count ===== */
.result-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 6px 0;
  display: none;
}

.result-info.visible {
  display: block;
}

.result-info span {
  color: var(--accent);
  font-weight: 600;
}

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

.site-footer a {
  color: var(--text-secondary);
  transition: color var(--transition);
}

.site-footer a:hover {
  color: var(--accent);
}

/* ===== Loading ===== */
.loading {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.loading .spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 14px;
}

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

/* ===== Back to Top ===== */
.back-top {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition);
  z-index: 80;
  box-shadow: var(--shadow);
}

.back-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.back-top:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ===== Responsive ===== */
@media (min-width: 640px) {
  .site-header {
    padding: 18px 0;
  }

  .header-inner {
    flex-direction: row;
    align-items: center;
    gap: 20px;
  }

  .search-box {
    flex: 1;
    max-width: 420px;
  }

  .category-nav {
    padding: 14px 0 2px;
  }

  .resource-card {
    padding: 20px;
  }
}

@media (min-width: 960px) {
  .site-slogan {
    display: inline;
  }
}

/* ===== Smooth card appear animation ===== */
@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.resource-card {
  animation: cardIn 0.3s ease forwards;
}
