:root {
  --bg: #0c0c0e;
  --bg-elev: #15151a;
  --bg-card: #1a1a20;
  --border: #2a2a32;
  --text: #f1f1f3;
  --muted: #8b8b96;
  --accent: #ff4d8d;
  --accent-2: #b06bff;
  --acid: #c4ff3a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, "Inter Tight", "Inter", BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { color: var(--accent); }
code, pre { font-family: "JetBrains Mono", "SF Mono", Menlo, ui-monospace, monospace; }

/* ----- top bar ----- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--text);
}
.topbar #search {
  flex: 1;
  max-width: 520px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font: inherit;
}
.topbar #search:focus { outline: 1px solid var(--accent-2); border-color: var(--accent-2); }
.meta { color: var(--muted); font-size: 13px; margin-left: auto; }
.meta button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font: inherit;
  cursor: pointer;
}
.meta button:hover { color: var(--text); border-color: var(--accent-2); }

/* ----- layout ----- */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 49px);
}
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 49px);
  position: sticky; top: 49px;
}
.sidebar h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 18px 0 6px;
}
.sidebar h3:first-child { margin-top: 0; }
.facet-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
}
.facet-item:hover { background: var(--bg-card); }
.facet-item.active {
  background: var(--accent);
  color: #fff;
}
.facet-item.active .count { color: rgba(255,255,255,0.8); }
.facet-item .count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ----- grid ----- */
.grid-wrap { padding: 16px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  position: relative;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-2);
}
.card .thumb-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #0a0a0c;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card .thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card .badge {
  position: absolute;
  top: 6px; left: 6px;
  background: rgba(0,0,0,0.75);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.card .badge.video { background: rgba(176,107,255,0.9); color:#fff; }
.card .badge.audio { background: rgba(196,255,58,0.9); color:#0c0c0e; }
.card .meta-row {
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  gap: 6px;
}
.card .meta-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.load-more {
  display: block;
  margin: 24px auto;
  padding: 10px 24px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.load-more:hover { border-color: var(--accent-2); }

/* ----- detail ----- */
.detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 0;
  min-height: calc(100vh - 49px);
}
.detail-media {
  background: #050507;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.detail-media img,
.detail-media video {
  max-width: 100%;
  max-height: calc(100vh - 100px);
  object-fit: contain;
}
.detail-media audio { width: 100%; max-width: 600px; }
.dl-link {
  padding: 14px 28px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
}
.detail-meta {
  padding: 20px 24px;
  border-left: 1px solid var(--border);
  background: var(--bg-elev);
  overflow-y: auto;
  max-height: calc(100vh - 49px);
}
.detail-meta h1 { font-size: 16px; margin: 0 0 16px; word-break: break-all; }
.detail-meta h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 0 6px; }
.detail-meta dl {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 4px 12px;
  font-size: 13px;
  margin: 0;
}
.detail-meta dt { color: var(--muted); }
.detail-meta dd { margin: 0; word-break: break-word; }
.detail-meta dd.path { font-family: "JetBrains Mono", monospace; font-size: 11px; color: var(--muted); }
.detail-meta .muted { color: var(--muted); }
.prompt {
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 6px;
  font-size: 12px;
  max-height: 240px;
  overflow-y: auto;
}
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.tag {
  background: var(--bg-card);
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  border: 1px solid var(--border);
}
.actions { display: flex; gap: 8px; margin-top: 16px; }
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: var(--accent-2); color: #fff; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .detail { grid-template-columns: 1fr; }
  .detail-meta { border-left: none; border-top: 1px solid var(--border); max-height: none; }
}

/* ----- compare ----- */
.compare-grid {
  display: grid;
  gap: 12px;
  padding: 12px;
  min-height: calc(100vh - 49px);
}
.compare-cols-1 { grid-template-columns: 1fr; }
.compare-cols-2 { grid-template-columns: 1fr 1fr; }
.compare-cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.compare-cols-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.compare-cols-5,
.compare-cols-6 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.compare-cell {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-height: 0;
}
.compare-media {
  flex: 1;
  background: #050507;
  display: flex; align-items: center; justify-content: center;
  min-height: 0;
  padding: 8px;
}
.compare-media img,
.compare-media video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.compare-cell figcaption {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.cell-name {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-name a { color: var(--text); }
.cell-letter {
  display: inline-flex;
  width: 22px; height: 22px;
  align-items: center; justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 4px;
  font-size: 12px;
  flex-shrink: 0;
}
.cell-meta { color: var(--muted); font-size: 11px; display: flex; gap: 4px; flex-wrap: wrap; }
.cell-prompt summary {
  cursor: pointer; color: var(--muted); margin-top: 6px;
  font-size: 11px;
}
.cell-prompt pre {
  background: var(--bg);
  padding: 8px;
  border-radius: 4px;
  margin: 4px 0 0;
  font-size: 11px;
  max-height: 100px;
  overflow-y: auto;
  white-space: pre-wrap;
}

@media (max-width: 900px) {
  .compare-grid,
  .compare-cols-2,
  .compare-cols-3,
  .compare-cols-4,
  .compare-cols-5,
  .compare-cols-6 {
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }
}

/* ----- gallery multi-select ----- */
.card.selected {
  outline: 3px solid var(--acid);
  outline-offset: -3px;
}
.card .select-marker {
  position: absolute;
  top: 6px; right: 6px;
  width: 22px; height: 22px;
  background: rgba(0,0,0,0.6);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: none;
  align-items: center; justify-content: center;
  color: var(--acid);
  font-weight: 700;
  font-size: 12px;
}
.card.selected .select-marker {
  display: flex;
  background: var(--acid);
  color: #0c0c0e;
  border-color: var(--acid);
}
.compare-bar {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--accent-2);
  border-radius: 32px;
  padding: 10px 18px;
  display: none;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 100;
}
.compare-bar.show { display: flex; }
.compare-bar .count {
  background: var(--accent);
  color: #fff;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.compare-bar button {
  background: var(--accent-2);
  border: none;
  color: #fff;
  padding: 6px 14px;
  border-radius: 16px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.compare-bar button:hover { background: var(--accent); }
.compare-bar button.ghost {
  background: transparent;
  color: var(--muted);
  font-weight: 400;
}
.compare-bar button.ghost:hover { color: var(--text); }
