/* ─── Theme tokens ─────────────────────────────────────────────────────────── */
:root {
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 0 rgba(255,255,255,0.02) inset, 0 8px 24px -12px rgba(0,0,0,0.4);
  --transition: 180ms cubic-bezier(.4,.0,.2,1);

  --accent: #ff7a00;
  --accent-soft: rgba(255, 122, 0, 0.12);
  --accent-ring: rgba(255, 122, 0, 0.4);
}

html[data-theme="dark"] {
  --bg: #0d0d0f;
  --bg-elev: #131316;
  --card: #16161a;
  --card-hover: #1c1c22;
  --border: #26262c;
  --border-strong: #34343c;
  --text: #ededed;
  --text-dim: #b8b8c0;
  --muted: #7a7a83;
  --grain-opacity: 0.04;
}

html[data-theme="light"] {
  --bg: #fafaf7;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-hover: #fbfbf8;
  --border: #e8e8e1;
  --border-strong: #d6d6cd;
  --text: #16161a;
  --text-dim: #45454d;
  --muted: #87878f;
  --accent: #e85d00;
  --accent-soft: rgba(232, 93, 0, 0.10);
  --accent-ring: rgba(232, 93, 0, 0.35);
  --grain-opacity: 0.025;
  --shadow-card: 0 1px 0 rgba(255,255,255,0.6) inset, 0 4px 12px -8px rgba(0,0,0,0.12);
}

/* ─── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* HTML's `hidden` attribute must always win over class-based display rules.
   Without this, `.modal { display: flex }` overrides `[hidden]` from UA stylesheet. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

/* Subtle grain texture for depth */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: var(--grain-opacity);
  mix-blend-mode: overlay;
}

/* Ambient accent glow in top-right */
body::after {
  content: '';
  position: fixed;
  top: -300px; right: -200px;
  width: 700px; height: 700px;
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 65%);
  pointer-events: none;
  z-index: 0;
  filter: blur(20px);
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font: inherit; color: inherit; }

.mono  { font-family: var(--font-mono); font-size: 0.85em; letter-spacing: 0.01em; }
.muted { color: var(--muted); }

/* ─── Header ──────────────────────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in oklab, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header__inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: inline-flex; align-items: baseline; gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.01em;
}
.brand__mark   { color: var(--accent); font-size: 14px; transform: translateY(-2px); }
.brand__accent { color: var(--accent); }

.header__actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-dim);
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--card-hover); color: var(--text); }
.icon { width: 18px; height: 18px; }

html[data-theme="dark"]  .icon-sun  { display: block; }
html[data-theme="dark"]  .icon-moon { display: none; }
html[data-theme="light"] .icon-sun  { display: none; }
html[data-theme="light"] .icon-moon { display: block; }

.btn {
  display: inline-flex; align-items: center;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.btn--ghost {
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.btn--ghost:hover { background: var(--card-hover); color: var(--text); border-color: var(--border-strong); }

/* ─── Main ───────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 32px 64px;
  position: relative;
  z-index: 2;
}

/* ─── Hero ───────────────────────────────────────────────────────────────── */
.hero { margin-bottom: 40px; }
.hero__eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 12px;
}
.hero__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(40px, 6vw, 64px);
  line-height: 1;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}
.hero__sub { color: var(--text-dim); font-size: 16px; }

/* ─── Controls (search + tags) ───────────────────────────────────────────── */
.controls { margin-bottom: 28px; }

.search {
  position: relative;
  margin-bottom: 16px;
  display: flex; align-items: center;
}
.search__icon {
  position: absolute; left: 16px;
  width: 18px; height: 18px;
  color: var(--muted);
  pointer-events: none;
}
.search__input {
  width: 100%;
  padding: 14px 60px 14px 46px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.search__input::placeholder { color: var(--muted); }
.search__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}
.search__kbd {
  position: absolute; right: 14px;
  font-family: var(--font-mono); font-size: 11px;
  padding: 3px 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  pointer-events: none;
}

.tags {
  display: flex; flex-wrap: wrap; gap: 8px;
  min-height: 32px;
}
.tag-chip {
  display: inline-flex; align-items: center;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-dim);
  background: transparent;
  transition: all var(--transition);
  user-select: none;
}
.tag-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.tag-chip[data-active="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Results meta ───────────────────────────────────────────────────────── */
.results__meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
  padding: 0 4px;
}
.link-btn {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--accent);
  transition: opacity var(--transition);
}
.link-btn:hover { opacity: 0.75; }

/* ─── Grid ───────────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform var(--transition), border-color var(--transition), background var(--transition);
  box-shadow: var(--shadow-card);
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: var(--card-hover);
}
.card:hover .card__arrow { opacity: 1; transform: translate(0, 0); color: var(--accent); }

.card__preview {
  position: relative;
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, var(--bg-elev), var(--card));
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.card__img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.card__placeholder {
  color: var(--muted);
  opacity: 0.35;
}
.card__placeholder svg { width: 64px; height: 64px; }
.card__img:not([hidden]) ~ .card__placeholder { display: none; }

.card__body {
  padding: 16px 18px 18px;
  display: flex; flex-direction: column; gap: 8px;
  flex: 1;
}
.card__title {
  font-family: var(--font-display);
  font-size: 18px; font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.card__desc {
  font-size: 13.5px;
  color: var(--text-dim);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__tags {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 6px;
}
.card-tag {
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

.card__arrow {
  position: absolute; top: 14px; right: 14px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  background: color-mix(in oklab, var(--bg) 70%, transparent);
  backdrop-filter: blur(4px);
  font-size: 16px;
  color: var(--text-dim);
  opacity: 0;
  transform: translate(4px, -4px);
  transition: all var(--transition);
}

/* ─── Empty state ────────────────────────────────────────────────────────── */
.empty {
  padding: 80px 24px;
  text-align: center;
  color: var(--muted);
}
.empty__mark {
  font-family: var(--font-display);
  font-size: 64px;
  color: var(--border-strong);
  margin-bottom: 8px;
}
.empty__title { font-size: 16px; color: var(--text); margin-bottom: 4px; }
.empty__sub   { font-size: 13px; }

/* ─── Footer ─────────────────────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border);
  padding: 20px 32px;
  text-align: center;
  position: relative; z-index: 2;
}

/* ─── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .header__inner { padding: 12px 18px; }
  .main { padding: 32px 18px 48px; }
  .footer { padding: 16px 18px; }
  .hero__title { font-size: 40px; }
  .grid { grid-template-columns: 1fr; }
  .search__kbd { display: none; }
}

/* ─── Subtle entrance animation ──────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card { animation: fadeUp 360ms cubic-bezier(.4,.0,.2,1) both; }
.card:nth-child(1)  { animation-delay: 0ms; }
.card:nth-child(2)  { animation-delay: 30ms; }
.card:nth-child(3)  { animation-delay: 60ms; }
.card:nth-child(4)  { animation-delay: 90ms; }
.card:nth-child(5)  { animation-delay: 120ms; }
.card:nth-child(6)  { animation-delay: 150ms; }
.card:nth-child(7)  { animation-delay: 180ms; }
.card:nth-child(8)  { animation-delay: 210ms; }
.card:nth-child(n+9){ animation-delay: 240ms; }
