/* GIF Hub — contact-sheet layout.
   The content is the design: chrome collapses to a single sticky row, cards
   sit in a dense near-gapless grid, and colour is spent only on the active
   filter. Everything else stays out of the way of the images. */

:root {
  --bg: #0A0A0D;
  --surface: #131318;
  --surface-2: #1C1C23;
  --line: #26262F;
  --text: #ECECF1;
  --muted: #7E7E8C;
  --accent: #FFB454;
  --danger: #FF5C7A;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --body: system-ui, "Segoe UI", sans-serif;
  --bar-h: 3.25rem;
}

* { box-sizing: border-box; }

/* Author display rules must not beat the browser default for [hidden]. */
[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

button, input, select { font: inherit; }

/* ---------- top bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  height: var(--bar-h);
  padding: 0 0.75rem;
  background: rgb(10 10 13 / 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.mark {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  flex: none;
}

.mark span { color: var(--accent); }

.search {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 30rem;
  display: flex;
  align-items: center;
}

.search svg {
  position: absolute;
  left: 0.7rem;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.search input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  padding: 0.45rem 2rem 0.45rem 2.1rem;
}

.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--accent); outline: none; }
.search input::-webkit-search-cancel-button { display: none; }

.clear {
  position: absolute;
  right: 0.35rem;
  width: 1.5rem;
  height: 1.5rem;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.7rem;
  cursor: pointer;
}

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

.count {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
  flex: none;
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.icon-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.icon-btn.on {
  color: #0A0A0D;
  background: var(--accent);
  border-color: var(--accent);
}

#shuffleBtn svg { fill: none; }

/* brief spin so a re-shuffle is visibly acknowledged */
#shuffleBtn.spin svg { animation: spin 0.4s ease; }

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(180deg); }
}

@media (prefers-reduced-motion: reduce) {
  #shuffleBtn.spin svg { animation: none; }
}

/* ---------- quick categories ---------- */

.quick {
  position: sticky;
  top: var(--bar-h);
  z-index: 29;
  display: flex;
  gap: 0.3rem;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0.45rem 0.75rem;
  background: rgb(10 10 13 / 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.quick::-webkit-scrollbar { display: none; }

.qchip {
  flex: none;
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

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

.qchip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #0A0A0D;
  font-weight: 600;
}

.qchip .n {
  font-family: var(--mono);
  font-size: 0.68rem;
  opacity: 0.65;
}

.qchip.more { color: var(--accent); background: transparent; border-color: var(--line); }

/* ---------- active filter ---------- */

.active-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.6rem 0.75rem 0;
  padding: 0.4rem 0.75rem;
  border-left: 2px solid var(--accent);
  background: var(--surface);
  border-radius: 0 8px 8px 0;
  font-size: 0.85rem;
}

.active-filter button {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.active-filter button:hover { color: var(--text); }

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

main { padding: 0.5rem 0.5rem 3rem; }

/* Real columns, not CSS multi-column: multi-column re-balances every card
   across all columns whenever new ones arrive, which makes the whole page
   jump mid-scroll. Appending to the shortest column never moves what is
   already on screen. */
.grid {
  display: flex;
  align-items: flex-start;
  gap: 5px;
}

.col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.card {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  border-radius: 5px;
  overflow: hidden;
  background: var(--surface);
  cursor: zoom-in;
}

.card img, .card video {
  display: block;
  width: 100%;
  height: auto;
  background: var(--surface-2);
}

/* Cards with a known aspect ratio hold their box from the start; fading the
   image in is gentler than having it pop, and nothing around it moves. */
.card.pending img, .card.pending video { opacity: 0; }

/* A card whose media never arrives keeps its space rather than collapsing
   and dragging the rest of the column up. */
.card.dead { pointer-events: none; opacity: 0.25; }
.card.dead img, .card.dead video { visibility: hidden; }

.card img, .card video { opacity: 1; transition: opacity 0.18s ease; }

.card.pending::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg,
    var(--surface-2) 30%, #23232C 50%, var(--surface-2) 70%);
  background-size: 220% 100%;
  animation: sweep 1.1s linear infinite;
}

@keyframes sweep {
  from { background-position: 180% 0; }
  to { background-position: -40% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .card.pending::after { animation: none; }
  .card img, .card video { transition: none; }
}

.card-meta {
  position: absolute;
  inset: auto 0 0 0;
  padding: 1.6rem 0.5rem 0.4rem;
  font-size: 0.7rem;
  line-height: 1.3;
  color: #fff;
  background: linear-gradient(transparent, rgb(0 0 0 / 0.8));
  opacity: 0;
  transition: opacity 0.12s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card:hover .card-meta,
.card:focus-visible .card-meta { opacity: 1; }

@media (hover: none) { .card-meta { display: none; } }

.card-kill {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 1.6rem;
  height: 1.6rem;
  border: none;
  border-radius: 6px;
  background: rgb(0 0 0 / 0.55);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease;
}

.card:hover .card-kill,
.card:focus-within .card-kill { opacity: 1; }

.card-kill:hover { background: var(--danger); }
.card-kill:disabled { opacity: 1; background: var(--danger); }

/* always reachable where there is no hover */
@media (hover: none) { .card-kill { opacity: 0.75; } }

.card.removed { opacity: 0; transform: scale(0.96); transition: all 0.18s ease; }

/* ---------- empty / more ---------- */

.empty {
  max-width: 24rem;
  margin: 4rem auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty strong { color: var(--accent); font-weight: 500; }

/* Reserved height so the sentinel does not resize as batches land. */
.more-wrap { text-align: center; padding: 1.25rem 0; min-height: 4.5rem; }

.more {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  padding: 0.5rem 1.4rem;
  cursor: pointer;
}

.more:hover { border-color: var(--accent); color: var(--accent); }

/* Fixed to the corner: appearing mid-browse must not push the grid down. */
.broken-notice {
  position: fixed;
  left: 0.75rem;
  bottom: 0.75rem;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--line);
  border-left: 2px solid var(--danger);
  background: rgb(19 19 24 / 0.95);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.4);
}

.broken-notice button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.76rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}

.broken-notice button:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- category sheet ---------- */

.sheet { position: fixed; inset: 0; z-index: 60; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(5 5 8 / 0.75);
  backdrop-filter: blur(3px);
}

.sheet-body {
  position: relative;
  margin: 0 auto;
  max-width: 60rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1rem 1rem 2rem;
  background: var(--bg);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.sheet-head h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.1rem;
  margin: 0;
}

.sheet-close {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  width: 2rem;
  height: 2rem;
  cursor: pointer;
}

#catFilter {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 0.5rem 0.8rem;
  margin-bottom: 0.9rem;
}

#catFilter:focus { border-color: var(--accent); outline: none; }

.cat-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.4rem;
  align-content: start;
}

.cat-tile {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.cat-tile:hover { border-color: var(--accent); }

.cat-tile.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #0A0A0D;
  font-weight: 600;
}

.cat-tile .n {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
}

.cat-tile.on .n { color: rgb(10 10 13 / 0.7); }

/* ---------- lightbox ---------- */

.lightbox { position: fixed; inset: 0; z-index: 70; }

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(5 5 8 / 0.9);
}

.lightbox-body {
  position: relative;
  margin: 3vh auto 0;
  max-width: min(760px, 94vw);
  max-height: 94vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
}

.lightbox-body .lb-media img,
.lightbox-body .lb-media video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  background: #000;
}

.lightbox-body figcaption { padding: 0.8rem 1rem 1rem; }

.lightbox-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.65);
  color: #fff;
  cursor: pointer;
}

#lbTitle {
  font-size: 0.92rem;
  margin: 0 0 0.5rem;
  color: var(--text);
}

.mono { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); }

.lb-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.7rem; }

.lb-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.lb-actions a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.82rem;
}

.lb-actions a:hover { text-decoration: underline; }

.lb-actions button {
  font-size: 0.82rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
}

button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }

/* ---------- admin ---------- */

.admin {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  width: min(380px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 1.1rem 1.1rem 2rem;
  overflow-y: auto;
  box-shadow: -18px 0 40px rgb(0 0 0 / 0.5);
}

.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.9rem;
}

.admin-head h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  margin: 0;
}

.admin-head button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
}

.field { display: block; margin-bottom: 0.75rem; }

.field > span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.field em { font-style: normal; }

.field input, .field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 0.5rem 0.65rem;
}

.field input:focus, .field select:focus { border-color: var(--accent); outline: none; }

.field.check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.field.check input { width: auto; accent-color: var(--accent); }
.field.check span { margin: 0; color: var(--text); font-size: 0.83rem; }

.crawl-opts {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding-bottom: 0.3rem;
}

.crawl-opts input { max-width: 6rem; }

button.primary {
  width: 100%;
  font-weight: 600;
  color: #0A0A0D;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 0.6rem;
  cursor: pointer;
}

button.primary:disabled { opacity: 0.5; cursor: wait; }

.admin-log {
  min-height: 1.1rem;
  margin: 0.6rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.admin-log.ok { color: #6FD08C; }
.admin-log.err { color: var(--danger); }

.admin hr { border: none; border-top: 1px solid var(--line); margin: 1.1rem 0; }

.admin-tools { display: grid; gap: 0.45rem; }

.admin-tools button {
  font-size: 0.83rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
  cursor: pointer;
}

.admin-tools button:hover { border-color: var(--accent); }

.admin-note { font-size: 0.72rem; color: var(--muted); margin-top: 0.8rem; }

.admin-sources { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.8rem; }

.chip {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active { color: var(--accent); border-color: var(--accent); }

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .mark { display: none; }
  .count { display: none; }
  main { padding: 0.4rem 0.35rem 3rem; }
  .sheet-body { padding: 0.9rem 0.75rem 1.5rem; }
  .cat-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
