: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 {
  min-height: 100vh;
}

.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 32px;
}

/* ---- Header ---- */

.header {
  margin-bottom: 24px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.header-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.title-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 38px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.menu-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.menu-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.menu-toggle span + span {
  margin-top: 4px;
}

.menu-toggle.open {
  color: var(--accent-hover);
  border-color: rgba(139, 92, 246, 0.35);
  background: var(--accent-soft);
}

.menu-toggle.open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.menu-toggle.open span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.title {
  margin: 0;
  font-size: 1.5rem;
  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;
  flex-shrink: 0;
}

.title-meta {
  font-size: 0.72rem;
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", Menlo, monospace;
  color: var(--text-dim);
  white-space: nowrap;
}

.title-meta a {
  color: var(--accent-hover);
  text-decoration: none;
  border-bottom: 1px solid rgba(167, 139, 250, 0.3);
}

.title-meta a:hover {
  border-bottom-color: var(--accent-hover);
}

.header-utils {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.top-nav {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.top-nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", Menlo, monospace;
  text-decoration: none;
  transition: color 0.15s;
}

.top-nav-link:hover {
  color: var(--text);
}

.top-nav-link::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -6px;
  width: 100%;
  height: 2px;
  border-radius: 999px;
  background: transparent;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.top-nav-link.active {
  color: var(--accent-hover);
}

.top-nav-link.active::after {
  opacity: 1;
  background: linear-gradient(90deg, var(--accent-hover), #22d3ee);
}

.top-nav-link.icon {
  padding: 0;
}

.top-nav-link.icon::after {
  display: none;
}

.top-nav-link.icon svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.header-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  padding: 4px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: var(--surface);
  white-space: nowrap;
}

.drag-callout {
  margin: 10px 0 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.drag-callout code {
  background: rgba(139, 92, 246, 0.15);
  color: var(--accent-hover);
  border: 1px solid rgba(139, 92, 246, 0.28);
}

/* ---- 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);
}

/* ---- Tag Dropdown ---- */

.tag-dropdown {
  position: relative;
}

.tag-dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  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;
}

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

.tag-dropdown-btn.open {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.tag-dropdown-btn svg {
  flex-shrink: 0;
}

.tag-dropdown-caret {
  transition: transform 0.15s ease;
}

.tag-dropdown-caret.open {
  transform: rotate(180deg);
}

.tag-dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 100;
  min-width: 220px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  animation: tagDropIn 0.12s ease-out;
}

@keyframes tagDropIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.tag-dropdown-list {
  max-height: 340px;
  overflow-y: auto;
  padding: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.tag-dropdown-list::-webkit-scrollbar {
  width: 5px;
}

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

.tag-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.1s;
  text-align: left;
}

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

.tag-dropdown-item.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.tag-dropdown-check {
  width: 16px;
  font-size: 0.72rem;
  color: var(--accent);
  text-align: center;
  flex-shrink: 0;
}

.tag-dropdown-name {
  flex: 1;
}

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

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

/* ---- 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-source-size {
  font-weight: 600;
}

.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); }
}

/* ---- 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 {
  flex: 0 0 auto;
}

.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%;
  background: var(--bg);
  flex-shrink: 0;
}

.modal-preview-media {
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  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-download-btn-sm {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.modal-download-btn-sm: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;
}

.modal-files {
  padding: 14px 20px 20px;
}

.modal-file-summary {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.modal-source-stats {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: fit-content;
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  border: 1px solid rgba(139, 92, 246, 0.25);
  background: rgba(139, 92, 246, 0.12);
}

.modal-source-size {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-hover);
  letter-spacing: 0.01em;
}

.modal-source-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.file-tree {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: var(--bg);
  overflow: auto;
  max-height: 360px;
}

.file-tree-node {
  display: block;
}

.file-tree-row {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 30px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.76rem;
}

.file-tree-dir {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
}

.file-tree-dir:hover {
  background: var(--surface);
}

.file-tree-file {
  color: var(--text-dim);
}

.file-tree-row:last-child {
  border-bottom: none;
}

.file-tree-caret {
  font-size: 0.68rem;
  color: var(--text-dim);
  width: 10px;
  text-align: center;
  transition: transform 0.15s ease;
}

.file-tree-caret.open {
  transform: rotate(90deg);
}

.file-tree-name {
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", Menlo, monospace;
  font-size: 0.74rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.file-tree-file-dot {
  color: var(--text-dim);
  width: 8px;
  text-align: center;
}

.file-tree-size {
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-left: auto;
  flex-shrink: 0;
}

/* 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-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) {
  .main {
    padding: 16px;
  }

  .header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .header-brand-row {
    width: 100%;
  }

  .header-utils {
    flex-wrap: wrap;
  }

  .title-wrap {
    flex: 1;
    min-width: 0;
  }

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

  .modal-overlay {
    padding: 14px;
  }

  .modal {
    max-height: 90vh;
  }
}

@media (max-width: 760px) {
  .title-meta {
    display: none;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .header-utils {
    width: 100%;
  }

  .top-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--surface);
  }

  .top-nav.open {
    display: flex;
  }

  .top-nav-link {
    font-size: 0.82rem;
    display: flex;
    width: 100%;
    min-height: 40px;
    align-items: center;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-xs);
  }

  .top-nav-link::after {
    display: none;
  }

  .top-nav-link:hover {
    background: var(--bg-subtle);
    border-color: var(--border);
  }

  .top-nav-link.active {
    background: rgba(139, 92, 246, 0.12);
    border-color: rgba(139, 92, 246, 0.28);
  }

  .top-nav-link.icon {
    justify-content: flex-start;
  }

  .controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 122px;
    gap: 8px;
    align-items: stretch;
  }

  .search-wrap {
    min-width: 0;
    grid-column: 1 / -1;
  }

  .tag-dropdown {
    width: auto;
  }

  .select {
    width: 100%;
  }

  .tag-dropdown-panel {
    min-width: 220px;
    max-width: calc(100vw - 22px);
  }

  .controls {
    margin-bottom: 16px;
  }

  .drag-callout {
    font-size: 0.88rem;
  }

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

@media (max-width: 560px) {
  .main {
    padding: 12px 10px;
  }

  .header {
    margin-bottom: 18px;
  }

  .title-wrap {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .drag-callout {
    margin-top: 8px;
  }

  .controls {
    grid-template-columns: minmax(0, 1fr) 106px;
    gap: 8px;
  }

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

  .search,
  .select {
    font-size: 0.88rem;
  }

  .tag-dropdown-btn {
    width: 100%;
    justify-content: space-between;
  }

  .tag-dropdown-panel {
    min-width: 200px;
    max-width: calc(100vw - 20px);
  }

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

  .title {
    font-size: 1.22rem;
    line-height: 1.2;
  }

  .card-body {
    padding: 12px;
  }

  .card-desc {
    font-size: 0.88rem;
  }

  .modal-overlay {
    padding: 8px;
  }

  .modal {
    max-height: calc(100dvh - 16px);
    border-radius: 10px;
  }

  .modal-header {
    padding: 12px;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .modal-title {
    white-space: normal;
    overflow: visible;
    text-overflow: initial;
  }

  .modal-header-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .modal-download-btn-sm,
  .modal-close-btn {
    padding: 6px 10px;
  }

  .modal-preview-media {
    max-height: 220px;
  }

  .modal-info {
    padding: 12px;
  }

  .modal-info-meta {
    flex-wrap: wrap;
    gap: 6px;
  }

  .modal-tabs {
    padding: 0 12px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .modal-tab {
    white-space: nowrap;
    flex: 0 0 auto;
    padding: 10px 12px;
  }

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

  .modal-files {
    padding: 12px;
  }

  .modal-body pre {
    padding: 12px;
    font-size: 0.78rem;
  }

  .file-tree {
    max-height: 300px;
  }
}

@media (max-width: 420px) {
  .card-actions {
    flex-direction: column;
  }

  .modal-header-actions {
    justify-content: stretch;
  }

  .modal-download-btn-sm,
  .modal-close-btn {
    flex: 1;
    text-align: center;
    justify-content: center;
  }

  .modal-tab {
    font-size: 0.78rem;
  }
}
