/* ===== Design tokens ===== */
:root {
  --bg: #f6f7f9;
  --bg-soft: #eef0f4;
  --surface: #ffffff;
  --surface-2: #f4f5f8;
  --border: #e4e6ec;
  --border-strong: #d3d6df;
  --text: #12141c;
  --text-dim: #5a6072;
  --text-faint: #8b91a1;

  --accent: #5b57e0;
  --accent-2: #8b5cf6;
  --accent-ink: #ffffff;
  --accent-soft: #ecebfb;
  --accent-ring: rgba(91, 87, 224, 0.35);

  --ok: #0e9f6e;
  --warn: #b45309;
  --warn-soft: #fdf3e6;

  --shadow-sm: 0 1px 2px rgba(18, 20, 28, 0.05), 0 1px 3px rgba(18, 20, 28, 0.06);
  --shadow-md: 0 4px 12px rgba(18, 20, 28, 0.08), 0 2px 4px rgba(18, 20, 28, 0.05);
  --shadow-lg: 0 12px 32px rgba(18, 20, 28, 0.12);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
  --maxw: 1160px;
}

:root[data-theme="dark"], :root.dark {
  --bg: #0c0d12;
  --bg-soft: #111319;
  --surface: #16181f;
  --surface-2: #1c1f28;
  --border: #262a34;
  --border-strong: #363b48;
  --text: #e9eaef;
  --text-dim: #9aa0ae;
  --text-faint: #6b7180;

  --accent: #8b8bf5;
  --accent-2: #a78bfa;
  --accent-ink: #0c0d12;
  --accent-soft: #1e2035;
  --accent-ring: rgba(139, 139, 245, 0.4);

  --warn: #f0a952;
  --warn-soft: #2a2113;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0d12; --bg-soft: #111319; --surface: #16181f; --surface-2: #1c1f28;
    --border: #262a34; --border-strong: #363b48; --text: #e9eaef; --text-dim: #9aa0ae; --text-faint: #6b7180;
    --accent: #8b8bf5; --accent-2: #a78bfa; --accent-ink: #0c0d12; --accent-soft: #1e2035; --accent-ring: rgba(139,139,245,0.4);
    --warn: #f0a952; --warn-soft: #2a2113;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow-md: 0 4px 14px rgba(0,0,0,.4); --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.86em; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.02em; }
[hidden] { display: none !important; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  font: inherit; font-weight: 600; font-size: 14px; padding: 10px 18px;
  border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer;
  transition: transform .06s ease, background .15s ease, border-color .15s ease; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--text-faint); }
.linkbtn { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-faint); }
.icon-btn svg { width: 18px; height: 18px; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun, :root.dark .i-sun { display: none; }
:root[data-theme="dark"] .i-moon, :root.dark .i-moon { display: block; }

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 14px;
}
.topbar-search { position: relative; flex: 1; max-width: 520px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; fill: var(--text-faint); pointer-events: none; }
#q {
  width: 100%; font: inherit; font-size: 14px; padding: 10px 14px 10px 38px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  background: var(--surface); color: var(--text);
}
#q:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.topbar-links { display: flex; align-items: center; gap: 18px; }
.topbar-links a { color: var(--text-dim); font-weight: 500; font-size: 14px; }
.topbar-links a:hover { color: var(--text); text-decoration: none; }

/* ===== Hero ===== */
.hero { border-bottom: 1px solid var(--border); background:
    radial-gradient(1000px 400px at 80% -50%, color-mix(in srgb, var(--accent) 12%, transparent), transparent); }
.hero-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 56px 24px 44px;
  display: grid; grid-template-columns: 1fr auto; gap: 40px; align-items: center;
}
.hero-copy h1 { margin: 0 0 14px; font-size: clamp(28px, 4.2vw, 46px); font-weight: 700; max-width: 16ch; }
.grad { background: linear-gradient(120deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-copy p { margin: 0 0 24px; color: var(--text-dim); font-size: 16px; max-width: 54ch; }
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; }
.hero-stats { display: flex; gap: 12px; margin: 0; }
.hero-stats div {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 22px; text-align: center; box-shadow: var(--shadow-sm); margin: 0; min-width: 92px;
}
.hero-stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); margin-bottom: 6px; }
.hero-stats dd { margin: 0; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ===== Ad slots ===== */
.ad-wrap { max-width: var(--maxw); margin: 0 auto; padding: 22px 24px 0; display: flex; justify-content: center; }
.ad { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ad-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-faint);
}
.ad-fill {
  display: grid; place-items: center; background: var(--surface-2);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); color: var(--text-faint);
  font-size: 12px; font-family: var(--mono); overflow: hidden;
}
.ad-fill::after { content: attr(data-size); }
.ad-fill.filled { border-style: solid; background: transparent; }
.ad-fill.filled::after { content: none; }
/* Reserved sizes prevent layout shift (good for Core Web Vitals). */
.ad-leaderboard .ad-fill { width: 728px; max-width: 100%; height: 90px; }
.ad-rectangle .ad-fill { width: 300px; height: 250px; }
@media (max-width: 767px) {
  .ad-leaderboard .ad-fill { width: 320px; height: 100px; }
  .ad-leaderboard .ad-fill::after { content: "320×100"; }
}

/* ===== Catalog layout ===== */
.layout {
  max-width: var(--maxw); margin: 0 auto; padding: 32px 24px 8px;
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start;
}
.rail { position: sticky; top: 78px; display: flex; flex-direction: column; gap: 18px; }
.rail-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm);
}
.rail-card h3 { margin: 0 0 8px; font-size: 15px; }
.rail-card p { margin: 0; font-size: 13.5px; color: var(--text-dim); }

/* ===== Filters ===== */
.filters { margin-bottom: 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 500; padding: 7px 13px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  background: var(--surface); color: var(--text-dim); white-space: nowrap; transition: all .12s ease;
}
.chip:hover { border-color: var(--text-faint); color: var(--text); }
.chip[aria-selected="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.chip .chip-count {
  font-size: 11px; font-variant-numeric: tabular-nums; padding: 1px 7px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text-faint);
}
.chip[aria-selected="true"] .chip-count { background: rgba(255,255,255,.22); color: #fff; }
.chip .chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--chip-color, var(--accent)); }
.chip[aria-selected="true"] .chip-dot { background: currentColor; }

.filter-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.select-wrap { position: relative; display: inline-flex; flex-direction: column; }
.select-wrap > span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); margin: 0 0 3px 2px; }
.select-wrap select, .field input {
  font: inherit; font-size: 14px; padding: 8px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text); min-width: 130px;
}
select:focus-visible, input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.result-count { margin-left: auto; font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.active-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.active-filters .af {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 4px 6px 4px 11px;
  background: var(--accent-soft); color: var(--accent); border-radius: var(--radius-pill); font-weight: 500;
}
.active-filters .af button { background: none; border: none; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; opacity: .7; }
.active-filters .af button:hover { opacity: 1; }

/* ===== Card grid ===== */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.group-heading {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; margin: 18px 0 2px;
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim);
}
.group-heading:first-child { margin-top: 0; }
.group-heading .gh-line { flex: 1; height: 1px; background: var(--border); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden; transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease;
  display: flex; flex-direction: column;
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.card.open { box-shadow: var(--shadow-lg); }
.card-head { padding: 15px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 10px; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-name { font-family: var(--mono); font-size: 13px; font-weight: 500; word-break: break-all; line-height: 1.45; }
.card-name .dir { color: var(--text-faint); }
.card-name .ctrl {
  display: inline-block; font-family: var(--sans); font-size: 9px; font-weight: 700;
  vertical-align: middle; padding: 1px 4px; margin: 0 1px; border-radius: 4px;
  background: var(--warn-soft); color: var(--warn); letter-spacing: 0.03em; cursor: help;
}
.fmt-badge {
  flex: none; font-size: 10.5px; font-weight: 600; padding: 3px 9px; border-radius: var(--radius-pill);
  background: var(--cat-soft, var(--surface-2)); color: var(--cat-color, var(--text-dim));
  border: 1px solid color-mix(in srgb, var(--cat-color, var(--border-strong)) 25%, transparent);
  white-space: nowrap; text-transform: none;
}
.card-desc { font-size: 13px; color: var(--text-dim); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.size-pill { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; background: var(--surface-2); padding: 2px 8px; border-radius: var(--radius-pill); }
.mini-tag { font-size: 11px; color: var(--text-faint); }
.flag-badge { font-size: 10.5px; font-weight: 600; color: var(--warn); background: var(--warn-soft); padding: 2px 8px; border-radius: var(--radius-pill); }

.card-body { border-top: 1px solid var(--border); padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.catches { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 11px 13px; font-size: 13px; color: var(--text); }
.catches b { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--accent); margin-bottom: 4px; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-list .t { font-size: 11.5px; color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--border); padding: 2px 9px; border-radius: var(--radius-pill); cursor: pointer; }
.tag-list .t:hover { border-color: var(--accent); color: var(--accent); }
.actions { display: flex; gap: 7px; flex-wrap: wrap; }
.actions .btn { padding: 7px 13px; font-size: 12.5px; }
.actions .mini { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); }
.actions .mini:hover { border-color: var(--text-faint); }
.snippet { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 13px; white-space: pre-wrap; word-break: break-all; }
.digest { font-family: var(--mono); font-size: 11px; color: var(--text-faint); word-break: break-all; }

.empty { text-align: center; color: var(--text-dim); padding: 60px 0; grid-column: 1 / -1; }

/* ===== Generator + endpoints ===== */
.section { border-top: 1px solid var(--border); margin-top: 40px; background: var(--bg-soft); }
.section-inner { max-width: var(--maxw); margin: 0 auto; padding: 48px 24px; }
.section-inner h2 { font-size: 24px; margin: 0 0 8px; }
.section-lead { color: var(--text-dim); max-width: 68ch; margin: 0 0 24px; }
.generator { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); margin-bottom: 28px; }
.gen-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; }
.field > span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); margin: 0 0 3px 2px; }
.gen-out { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.gen-out code { flex: 1 1 240px; font-size: 12px; color: var(--text-dim); word-break: break-all; }
.endpoint-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.endpoint-grid > div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.endpoint-grid code { display: block; color: var(--accent); margin-bottom: 4px; }
.endpoint-grid a { color: var(--accent); }
.endpoint-grid span { font-size: 12.5px; color: var(--text-dim); }

/* ===== Footer ===== */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); }
.footer-inner { max-width: var(--maxw); margin: 0 auto; padding: 36px 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.footer-inner p { margin: 6px 0 0; font-size: 13.5px; color: var(--text-dim); }
.footer-inner .warn { background: var(--warn-soft); border-radius: var(--radius-sm); padding: 12px 14px; }
.footer-inner .warn strong { color: var(--warn); }

/* ===== Responsive ===== */
@media (max-width: 940px) {
  .layout { grid-template-columns: 1fr; }
  .rail { position: static; flex-direction: row; flex-wrap: wrap; }
  .rail .ad-rectangle { margin: 0 auto; }
  .rail-card { flex: 1; min-width: 260px; }
}
@media (max-width: 720px) {
  .hero-inner { grid-template-columns: 1fr; }
  .hero-stats { flex-wrap: wrap; }
  .topbar-links a { display: none; }
  .footer-inner { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: 1fr; }
}
