:root {
  --bg: #08080d;
  --surface: #12121a;
  --surface2: #1a1a26;
  --border: rgba(255,255,255,0.06);
  --text: #e8e8ed;
  --text2: #8b8b9e;
  --accent: #EE4D2D;
  --accent2: #FF6B35;
  --accent-glow: rgba(238,77,45,0.15);
  --radius: 16px;
  --radius-sm: 10px;
  --header-bg: rgba(8,8,13,0.85);
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --card-hover-shadow: 0 12px 40px -8px rgba(238,77,45,0.15), 0 4px 16px rgba(0,0,0,0.3);
  --like-btn-bg: rgba(255, 255, 255, 0.04);
}

:root.light {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface2: #f1f3f7;
  --border: rgba(0,0,0,0.08);
  --text: #1a1a24;
  --text2: #6c757d;
  --accent-glow: rgba(238,77,45,0.08);
  --header-bg: rgba(255,255,255,0.85);
  --shadow: 0 4px 20px rgba(0,0,0,0.03);
  --card-hover-shadow: 0 12px 30px rgba(238,77,45,0.08), 0 4px 16px rgba(0,0,0,0.04);
  --like-btn-bg: rgba(0, 0, 0, 0.03);
}

* { margin:0; padding:0; box-sizing:border-box; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}
/* ===== HEADER ===== */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s ease;
}
.header-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(238,77,45,0.08) 0%, transparent 50%);
  pointer-events: none;
}
.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: relative;
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}
.logo-icon {
  font-size: 32px;
  filter: drop-shadow(0 2px 8px rgba(238,77,45,0.4));
}
.logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(238,77,45,0.4));
}
.logo h1 {
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}
.tagline {
  font-size: 11px;
  color: var(--text2);
  font-weight: 500;
  letter-spacing: 0.3px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 1 520px; /* Increased to fit search, telegram, and theme toggle */
  justify-content: flex-end;
}
.search-box {
  position: relative;
  flex: 1;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text2);
  pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 10px 16px 10px 42px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.3s ease;
}
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--surface);
}
#search-input::placeholder {
  color: var(--text2);
}

/* ===== TELEGRAM JOIN BUTTON ===== */
.telegram-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #229ED9, #0088cc);
  color: white;
  text-decoration: none;
  border-radius: 50px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(34, 158, 217, 0.25);
  transition: all 0.3s ease;
  flex-shrink: 0;
  height: 40px;
}
.telegram-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(34, 158, 217, 0.4);
  filter: brightness(1.08);
}
.telegram-icon {
  fill: currentColor;
  flex-shrink: 0;
}

/* ===== THEME TOGGLE BUTTON ===== */
.theme-toggle-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  position: relative;
}
.theme-toggle-btn:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.05);
  box-shadow: 0 0 12px var(--accent-glow);
}
.theme-toggle-btn svg {
  position: absolute;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.5s ease;
}
.theme-toggle-btn .sun-icon {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}
.theme-toggle-btn .moon-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}
:root.light .theme-toggle-btn .sun-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}
:root.light .theme-toggle-btn .moon-icon {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

/* ===== MAIN ===== */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  min-height: 60vh;
}
.stats-bar {
  margin-bottom: 24px;
  font-size: 13px;
  color: var(--text2);
  font-weight: 500;
}
.stats-bar span {
  background: var(--surface);
  padding: 8px 16px;
  border-radius: 50px;
  border: 1px solid var(--border);
  display: inline-block;
}
/* ===== PRODUCT GRID ===== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.product-card:hover {
  transform: translateY(-4px);
  border-color: rgba(238,77,45,0.3);
  box-shadow: var(--card-hover-shadow);
}
.product-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface2);
  display: block;
}
.product-image-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: linear-gradient(135deg, var(--surface2) 0%, #1e1e2e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  opacity: 0.5;
}
.product-info {
  padding: 14px 16px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.product-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text);
}
.product-id {
  font-size: 11px;
  color: var(--text2);
  font-weight: 500;
}
.product-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  margin-top: auto;
}
.product-btn:hover {
  filter: brightness(1.1);
  transform: scale(1.02);
}
/* ===== LOADING ===== */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}
.spinner {
  width: 36px;
  height: 36px;
  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); } }
/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text2);
}
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state h3 {
  font-size: 18px;
  color: var(--text);
  margin-bottom: 8px;
}
/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 40px;
}
.page-num-btn {
  background: transparent;
  border: none;
  color: var(--text2);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 12px;
  min-width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-family: inherit;
}
.page-num-btn:hover:not(:disabled) {
  color: var(--accent);
  background: var(--surface2);
}
.page-num-btn.active {
  background: var(--accent);
  color: white;
  font-weight: 700;
}
.page-num-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.page-dots {
  color: var(--text2);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
}
/* ===== FOOTER ===== */
footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
  text-align: center;
}
footer p {
  font-size: 13px;
  color: var(--text2);
}
.footer-sub {
  margin-top: 6px;
  font-size: 11px;
}
.footer-sub a {
  color: var(--accent);
  text-decoration: none;
}
.footer-sub a:hover { text-decoration: underline; }
/* ===== ANIMATIONS ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.product-card {
  animation: fadeUp 0.4s ease backwards;
}
.product-card:nth-child(1) { animation-delay: 0.02s; }
.product-card:nth-child(2) { animation-delay: 0.04s; }
.product-card:nth-child(3) { animation-delay: 0.06s; }
.product-card:nth-child(4) { animation-delay: 0.08s; }
.product-card:nth-child(5) { animation-delay: 0.10s; }
.product-card:nth-child(6) { animation-delay: 0.12s; }
.product-card:nth-child(7) { animation-delay: 0.14s; }
.product-card:nth-child(8) { animation-delay: 0.16s; }
.product-card:nth-child(9) { animation-delay: 0.18s; }
.product-card:nth-child(10) { animation-delay: 0.20s; }
.product-card:nth-child(11) { animation-delay: 0.22s; }
.product-card:nth-child(12) { animation-delay: 0.24s; }

/* ===== CATEGORIES ===== */
.category-container {
  margin-bottom: 20px;
  overflow: hidden;
}
.category-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none; /* Firefox */
}
.category-scroll::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}
.category-btn {
  padding: 10px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 50px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.25s ease;
  font-family: inherit;
}
.category-btn:hover {
  border-color: rgba(238,77,45,0.4);
  color: var(--text);
  background: var(--surface2);
}
.category-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(238,77,45,0.3);
}

/* ===== SORTING ===== */
.sort-container {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  background: var(--surface);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.sort-label {
  font-size: 13px;
  color: var(--text2);
  font-weight: 600;
}
.sort-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.sort-btn {
  padding: 8px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}
.sort-btn:hover {
  color: var(--text);
  border-color: rgba(255,255,255,0.15);
}
.sort-btn.active {
  background: rgba(238,77,45,0.1);
  color: var(--accent);
  border-color: var(--accent);
}

/* ===== PRODUCT PRICE ===== */
.product-price {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}
.product-price-placeholder {
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  font-style: italic;
}

/* ===== PRODUCT LIKE FEATURE ===== */
.product-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  gap: 8px;
}
.like-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--like-btn-bg);
  border: 1px solid var(--border);
  color: var(--text2);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 50px;
  transition: all 0.25s ease;
}
.like-btn:hover {
  background: rgba(238,77,45,0.08);
  border-color: rgba(238,77,45,0.2);
  color: var(--accent);
}
.like-btn.liked {
  background: rgba(238,77,45,0.1);
  border-color: var(--accent);
  color: var(--accent);
}
.like-icon {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2px;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.like-btn.liked .like-icon {
  fill: currentColor;
}
.like-btn:active .like-icon {
  transform: scale(1.3);
}
.like-count {
  font-size: 12px;
  font-weight: 600;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  header {
    position: relative; /* Non-sticky on mobile to prevent the search bar from covering/blocking products when scrolling */
  }
  .header-content {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    padding: 12px 16px;
  }
  .header-actions {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
  }
  .search-box {
    flex: 1;
    width: 100%;
  }
  .logo h1 { font-size: 16px; }
  .logo-icon { font-size: 28px; }
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .product-name { font-size: 12px; }
  .product-info { padding: 10px 12px 12px; }
  .product-btn { font-size: 11px; padding: 8px 12px; }
  .sort-container {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .product-grid {
    grid-template-columns: 1fr;
  }
  /* On very small screens, make the Telegram button a circular icon button to save space */
  .telegram-btn span {
    display: none;
  }
  .telegram-btn {
    padding: 10px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    justify-content: center;
  }
}
