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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3348;
  --text: #e8eaf0;
  --muted: #8b92a8;
  --accent: #6c5ce7;
  --accent-hover: #7f71ef;
  --radius: 12px;
  --sidebar-w: 240px;
  --header-h: 110px;
}

html { scroll-behavior: smooth; }

body {
  font-family: "Space Grotesk", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  background-color: var(--bg);
  background-image: url("memesite/f32e7677-ae50-465d-8843-60de71bb19e7.jpg");
  background-position: center center;
  background-size: 50% auto;
  background-repeat: no-repeat;
  min-height: var(--header-h);
}

.header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 23, 0.6);
  pointer-events: none;
}

.header-inner {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: var(--header-h);
  padding: 16px 24px;
}

.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: 100%;
  max-width: 900px;
}

.home-link {
  color: inherit;
  text-decoration: none;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.home-link:hover { opacity: 0.85; }

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

.brand-count {
  font-size: 0.75rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.45);
  padding: 2px 8px;
  border-radius: 20px;
}

.search-wrap {
  flex: 1;
  min-width: 180px;
  max-width: 420px;
  position: relative;
}

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

#search {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: rgba(26, 29, 39, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--muted); }

/* Layout */
.layout {
  display: flex;
  max-width: 1600px;
  margin: 0 auto;
  min-height: calc(100vh - var(--header-h));
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 20px 12px;
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.sidebar-footer {
  flex-shrink: 0;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-footer a {
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-footer a:hover {
  color: var(--text);
  background: var(--surface2);
}

.cat-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  margin-bottom: 2px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.cat-btn:hover { background: var(--surface2); color: var(--text); }

.cat-btn.active {
  background: var(--accent);
  color: #fff;
}

.cat-count {
  font-size: 0.72rem;
  opacity: 0.7;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 4px;
}

/* Main */
.main {
  flex: 1;
  padding: 20px 24px 40px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-h));
}

body.is-landing .toolbar,
body.is-landing .brand-title {
  display: none;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

#view-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.btn-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-refresh svg { width: 14px; height: 14px; }
.btn-refresh:hover { background: var(--surface2); color: var(--text); }

/* Landing */
.landing {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
}

.landing img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  aspect-ratio: 1;
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(108, 92, 231, 0.15);
}

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

.card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(transparent 50%, rgba(0,0,0,0.75));
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px;
}

.card:hover .card-overlay { opacity: 1; }

.card-name {
  font-size: 0.72rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.card-dl {
  font-size: 0.68rem;
  padding: 3px 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  text-decoration: none;
  font-family: inherit;
  cursor: pointer;
}

.video-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

/* States */
.loading, .empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

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

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

.hidden { display: none !important; }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
  z-index: 10;
}

.lightbox-close:hover { opacity: 1; }

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 2.5rem;
  width: 48px;
  height: 64px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
  z-index: 10;
}

.lightbox-nav:hover { background: rgba(255,255,255,0.2); }
.lightbox-nav.prev { left: 16px; }
.lightbox-nav.next { right: 16px; }

.lightbox-content {
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-content img,
.lightbox-content video {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-footer {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 0.85rem;
}

.btn-download {
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.85rem;
  transition: background 0.15s;
}

.btn-download:hover { background: var(--accent-hover); }

/* Mobile */
@media (max-width: 768px) {
  .layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    position: static;
    height: auto;
    display: flex;
    flex-direction: column;
    overflow: visible;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    overflow: visible;
  }

  .sidebar-divider { display: none; }

  .cat-btn {
    width: auto;
    padding: 6px 12px;
    margin: 0;
    border-radius: 20px;
    background: var(--surface2);
  }

  .cat-btn.active { background: var(--accent); }

  #category-list { display: contents; }

  .main { padding: 16px; }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }

  .lightbox-nav { display: none; }
}