.search-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 8px 0 24px;
}
.search-wrap {
  position: relative;
  flex: 1;
  max-width: 720px;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 14px;
  color: var(--text-faint);
  font-size: 18px;
  pointer-events: none;
}
.search-input {
  flex: 1;
  background: var(--surface-0);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 42px 12px 40px;
  font: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}
.search-input::placeholder { color: var(--text-faint); }
.search-input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface-1);
}
.search-kbd {
  position: absolute;
  right: 10px;
  color: var(--text-faint);
  font-family: ui-monospace, "JetBrains Mono", monospace;
  font-size: 11px;
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 3px;
  pointer-events: none;
}
.count {
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.count-label { color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.14em; font-size: 10px; }

.tag-toggle {
  margin: 0 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tag-toggle-count { color: var(--text-faint); font-size: 10px; }
.tag-toggle[aria-expanded="true"] {
  color: var(--text);
  border-color: var(--border-strong);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 18px;
  padding: 0;
}
.tag-row.collapsed { display: none; }
.tag-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-0);
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background-color 140ms ease;
}
.tag-chip:hover { border-color: var(--accent-1); color: var(--text); }
.tag-chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-1);
  color: var(--text);
}
.tag-chip .tag-count {
  color: var(--text-faint);
  font-size: 10px;
}
.tag-chip[aria-pressed="true"] .tag-count { color: var(--accent-2); }
.tag-clear { color: var(--text-faint); border-style: dashed; }

.grid {
  display: grid;
  gap: 14px;
}
.grid[data-size="s"] { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid[data-size="m"] { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid[data-size="l"] { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

/* CSS toggle: hide the inactive set entirely. Server renders both. */
body[data-mode="sfw"]  .tile[data-set="nsfw"] { display: none; }
body[data-mode="nsfw"] .tile[data-set="sfw"]  { display: none; }

.tile {
  appearance: none;
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  cursor: pointer;
  color: inherit;
  box-shadow: var(--shadow-tile);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 220ms ease, background-color 320ms ease;
}
.tile:hover, .tile:focus-visible {
  border-color: var(--accent-1);
  box-shadow: 0 1px 0 rgba(0,0,0,0.5), 0 0 0 1px var(--accent-1), 0 12px 32px -14px var(--accent-glow);
  transform: translateY(-1px);
  outline: none;
}
.tile img, .tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}
.tile-name {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 18px 10px 6px;
  font-size: 10px;
  color: var(--text);
  background: linear-gradient(to top, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.6) 55%, rgba(0,0,0,0) 100%);
  text-shadow: 0 1px 2px rgba(0,0,0,0.85);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile:hover .tile-name, .tile:focus-visible .tile-name { opacity: 1; }

/* Secondary affordance — hover-revealed icon that opens the embed page in a
   new tab (handled in list.js, since nesting an <a> inside the tile <button>
   is invalid HTML and would also double-trigger the copy gesture). The
   primary click→copy gesture is unaffected: the grid handler routes clicks
   landing on .tile-embed to window.open and skips the copy. */
.tile-embed {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, background-color 120ms ease, color 120ms ease;
  z-index: 2;
}
.tile:hover .tile-embed,
.tile:focus-visible .tile-embed { opacity: 1; pointer-events: auto; }
.tile-embed:hover { background: var(--accent-1); color: var(--bg); }

/* Click-to-copy confirmation: accent pulse + ring, image stays visible.
   Was a white-stomp that hid the meme for 240 ms — that was rough. */
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent-1);
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  transition: opacity 220ms ease;
}
.tile.flash::after { opacity: 0.32; transition-duration: 60ms; }
.tile.flash {
  box-shadow: 0 0 0 2px var(--accent-1), 0 12px 32px -10px var(--accent-glow);
}

.empty {
  text-align: center;
  padding: 80px 24px;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.size-toggle { display: inline-flex; gap: 2px; margin-right: 6px; }
.size-toggle .btn { font-size: 10px; }

@media (max-width: 640px) {
  .search-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .search-kbd { display: none; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; }
  main { padding: 16px; }
  .grid[data-size="m"] { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .grid[data-size="l"] { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
