:root {
  --bg: #0d0d0f;
  --bg-soft: #141417;
  --card: #17171b;
  --card-hover: #1d1d22;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #ededf0;
  --muted: #9a9aa3;
  --faint: #6a6a73;
  --gold: #f4c04a;
  --gold-dim: rgba(244, 192, 74, 0.14);
  --purple: #a78bfa;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
/* `hidden` must always win over component display rules (lightbox/toast). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(244, 192, 74, 0.08), transparent 60%),
    radial-gradient(700px 500px at 0% 0%, rgba(167, 139, 250, 0.06), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 13, 15, 0.75);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  font-size: 30px;
  filter: drop-shadow(0 2px 8px rgba(244, 192, 74, 0.4));
}
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: -0.02em; }
.sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

.settings { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; }
.field select {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13px;
  min-width: 130px;
  cursor: pointer;
}
.field select:focus { outline: 2px solid var(--gold-dim); border-color: var(--gold); }

.pill {
  font-size: 12.5px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  white-space: nowrap;
}
.pill--ok { color: #6ee7a8; border-color: rgba(110, 231, 168, 0.35); background: rgba(110, 231, 168, 0.08); }
.pill--bad { color: #ff9a8b; border-color: rgba(255, 154, 139, 0.35); background: rgba(255, 154, 139, 0.08); }
.pill--idle { color: var(--muted); }

/* ---------- filters ---------- */
.filters {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 28px 8px;
  max-width: 1320px;
  margin: 0 auto;
}
#search {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
}
#search:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-dim); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { color: var(--text); border-color: var(--gold); }
.chip.active { background: var(--gold); color: #2a1f00; border-color: var(--gold); font-weight: 600; }

/* ---------- grid ---------- */
.grid {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px 28px 60px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.card:hover { transform: translateY(-3px); border-color: var(--line-strong); box-shadow: var(--shadow); }

.thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  background:
    linear-gradient(135deg, #1c1c22, #121216);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.thumb__glyph { font-size: 44px; opacity: 0.35; }
.thumb__badge {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.55);
  color: var(--gold);
  border: 1px solid var(--gold-dim);
  padding: 4px 9px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}
.thumb__spin {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: rgba(10, 10, 12, 0.78);
  color: var(--gold);
  font-size: 13px;
}
.card.busy .thumb__spin { display: flex; }
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--gold-dim);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.body { padding: 14px 15px 16px; display: flex; flex-direction: column; gap: 9px; flex: 1; }
.card h3 { margin: 0; font-size: 15px; letter-spacing: -0.01em; }
.ptext {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.ptext.expanded { -webkit-line-clamp: unset; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 10.5px; color: var(--faint); background: var(--bg-soft); border: 1px solid var(--line); padding: 2px 8px; border-radius: 6px; }

.actions { display: flex; gap: 8px; align-items: center; margin-top: auto; padding-top: 4px; }
.btn {
  border: 1px solid var(--gold);
  background: var(--gold);
  color: #2a1f00;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { background: transparent; color: var(--faint); border-color: var(--line-strong); cursor: not-allowed; font-weight: 500; }
.btn--ghost { background: transparent; border-color: var(--line-strong); color: var(--muted); font-weight: 500; }
.btn--ghost:hover { color: var(--text); border-color: var(--gold); }
.meta { margin-left: auto; font-size: 11px; color: var(--faint); }
.needs { font-size: 11px; color: var(--purple); }

/* ---------- footer ---------- */
.foot {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 28px 40px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--faint);
  border-top: 1px solid var(--line);
}

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 32px;
}
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 10px; box-shadow: var(--shadow); }
.lightbox__close {
  position: absolute; top: 18px; right: 22px;
  background: transparent; border: none; color: #fff; font-size: 26px; cursor: pointer;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #222; color: var(--text);
  border: 1px solid var(--line-strong);
  padding: 11px 18px; border-radius: 10px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 60; max-width: 80vw;
}
.toast.err { border-color: rgba(255, 154, 139, 0.5); color: #ff9a8b; }

@media (max-width: 640px) {
  .topbar { padding: 14px 16px; }
  .filters, .grid, .foot { padding-left: 16px; padding-right: 16px; }
}
