:root {
  --bg: #0c0c14;
  --bg-subtle: #12121c;
  --surface: #16162a;
  --surface-hover: #1c1c36;
  --surface-2: #1e1e3a;
  --border: #2a2a4a;
  --border-subtle: #222244;
  --text: #e8e8f0;
  --text-muted: #8888a8;
  --text-dim: #5a5a7a;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-soft: rgba(139, 92, 246, 0.15);
  --accent-glow: rgba(139, 92, 246, 0.25);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.12);
  --yellow: #fbbf24;
  --yellow-soft: rgba(251, 191, 36, 0.12);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  width: 260px;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border-subtle);
  padding: 20px 0;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  display: flex;
  flex-direction: column;
}

.sidebar::-webkit-scrollbar {
  width: 5px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.sidebar-header {
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 12px;
}

.sidebar-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.tag-list {
  padding: 0 8px;
  flex: 1;
  overflow-y: auto;
}

.tag-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-muted);
  transition: all 0.15s;
  border: 1px solid transparent;
}

.tag-item:hover {
  background: var(--surface);
  color: var(--text);
}

.tag-item.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: rgba(139, 92, 246, 0.2);
}

.tag-count {
  font-size: 0.72rem;
  color: var(--text-dim);
  min-width: 24px;
  text-align: right;
}

.tag-item.active .tag-count {
  color: var(--accent);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
  flex-shrink: 0;
}

.sidebar-footer-link {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 8px;
  border-radius: var(--radius-xs);
  transition: all 0.15s;
}

.sidebar-footer-link:hover {
  color: var(--text-muted);
  background: var(--surface);
}

/* ---- Main content ---- */

.main {
  flex: 1;
  min-width: 0;
  padding: 24px 28px;
}

.header {
  margin-bottom: 24px;
}

.title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #e8e8f0, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.stats {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}

.stat-value {
  font-weight: 600;
  color: var(--accent-hover);
}

.stat-label {
  color: var(--text-muted);
}

/* ---- Controls ---- */

.controls {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
  display: flex;
  align-items: center;
}

.search {
  width: 100%;
  padding: 10px 12px 10px 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s;
}

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

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

.select {
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238888a8' d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-btn {
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.filter-btn.active {
  background: var(--accent-soft);
  border-color: rgba(139, 92, 246, 0.3);
  color: var(--accent-hover);
}

/* ---- Active filters bar ---- */

.active-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--accent-hover);
  cursor: pointer;
  transition: all 0.15s;
}

.active-filter-chip:hover {
  background: rgba(139, 92, 246, 0.25);
}

.clear-filters {
  font-size: 0.78rem;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 999px;
  transition: color 0.15s;
}

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

/* ---- Card grid ---- */

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

.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
}

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

/* ---- Preview ---- */

.preview-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg);
  overflow: hidden;
}

.preview-media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.preview-placeholder svg {
  width: 40px;
  height: 40px;
  opacity: 0.3;
}

.preview-wrap[draggable="true"] {
  cursor: grab;
}

.preview-wrap[draggable="true"]:active {
  cursor: grabbing;
}

.drag-indicator {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  color: white;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.preview-wrap:hover .drag-indicator {
  opacity: 0.7;
}

.preview-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-badge.video {
  background: rgba(139, 92, 246, 0.85);
  color: white;
}

/* ---- Card body ---- */

.card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

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

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}

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

.card-author {
  color: var(--accent-hover);
  cursor: pointer;
  transition: color 0.15s;
}

.card-author:hover {
  color: var(--accent);
  text-decoration: underline;
}

.card-desc {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Card tags ---- */

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.card-tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.15s;
}

.card-tag:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: rgba(139, 92, 246, 0.2);
}

/* ---- Card actions ---- */

.card-actions {
  display: flex;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.card-btn {
  flex: 1;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  font-size: 0.78rem;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text-muted);
}

.card-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.card-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.card-btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ---- Empty state ---- */

.empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-text {
  font-size: 0.95rem;
}

.empty-sub {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 6px;
}

/* ---- Loading ---- */

.loading {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  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); }
}

/* ---- Mobile tags (horizontal scroll) ---- */

.mobile-tags {
  display: none;
  gap: 6px;
  overflow-x: auto;
  padding: 0 0 10px;
  margin-bottom: 16px;
  scrollbar-width: none;
}

.mobile-tags::-webkit-scrollbar {
  display: none;
}

.mobile-tag {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.mobile-tag.active {
  background: var(--accent-soft);
  border-color: rgba(139, 92, 246, 0.3);
  color: var(--accent-hover);
}

/* ---- Source modal ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 820px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.15s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 12px;
  flex-shrink: 0;
}

.modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.modal-copy-btn,
.modal-close-btn {
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  transition: all 0.15s;
  white-space: nowrap;
}

.modal-copy-btn:hover,
.modal-close-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.modal-copy-btn.copied {
  background: var(--green-soft);
  border-color: rgba(52, 211, 153, 0.3);
  color: var(--green);
}

/* ---- Modal preview ---- */

.modal-preview {
  width: 100%;
  max-height: 300px;
  overflow: hidden;
  background: var(--bg);
  flex-shrink: 0;
}

.modal-preview-media {
  width: 100%;
  height: 100%;
  max-height: 300px;
  object-fit: cover;
  display: block;
}

/* ---- Modal info section ---- */

.modal-info {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.modal-desc {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.modal-info-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.modal-info-author {
  color: var(--accent-hover);
}

.modal-info-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.modal-info-tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.modal-info-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.modal-download-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: var(--radius-xs);
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  cursor: pointer;
  transition: all 0.15s;
}

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

.modal-tabs {
  display: flex;
  gap: 0;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 20px;
  flex-shrink: 0;
}

.modal-tabs .modal-copy-btn {
  margin-left: auto;
}

.modal-tab {
  padding: 10px 16px;
  font-size: 0.82rem;
  color: var(--text-dim);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
}

.modal-tab:hover {
  color: var(--text-muted);
}

.modal-tab.active {
  color: var(--accent-hover);
  border-bottom-color: var(--accent);
}

.modal-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-body pre {
  margin: 0;
  padding: 20px;
  font-size: 0.82rem;
  line-height: 1.6;
  overflow-x: auto;
}

.modal-body pre code {
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", Menlo, monospace;
  font-size: 0.8rem;
}

/* Override Prism theme to match dark UI */
.modal-body pre[class*="language-"] {
  background: var(--bg) !important;
  margin: 0;
  border-radius: 0;
}

.modal-body code[class*="language-"] {
  text-shadow: none !important;
}

.modal-meta {
  padding: 16px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.modal-meta-item {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.modal-meta-item strong {
  color: var(--text-muted);
}

.modal-loading {
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
}

.modal-error {
  padding: 40px;
  text-align: center;
  color: var(--yellow);
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
  .sidebar {
    display: none;
  }

  .mobile-tags {
    display: flex;
  }

  .main {
    padding: 16px;
  }

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

@media (max-width: 560px) {
  .controls {
    flex-direction: column;
  }

  .search-wrap {
    min-width: unset;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .title {
    font-size: 1.3rem;
  }
}
