:root {
  --bg: #0b0d12;
  --panel: rgba(22, 26, 34, 0.62);
  --panel-solid: #161a22;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #e8ebf2;
  --muted: #9aa3b2;
  --accent: #6ea8fe;
  --accent-2: #b98cff;
  --radius: 16px;
  --wrap: 1080px;
  --rail-lane: 260px;
  font-synthesis-weight: none;
}

:root[data-theme="light"] {
  --bg: #f5f6f9;
  --panel: rgba(255, 255, 255, 0.75);
  --panel-solid: #ffffff;
  --border: rgba(15, 18, 25, 0.09);
  --border-strong: rgba(15, 18, 25, 0.18);
  --text: #14161c;
  --muted: #565e6e;
}

.theme-toggle {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

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

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

html {
  background: var(--bg);
}

body {
  background: transparent;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  /* Pills dock/undock above the viewport as you scroll. Scroll anchoring reacts
     to that mutation by yanking scrollTop back up = stutter/refuses to scroll
     down. Opt out. */
  overflow-anchor: none;
}

#bg-plexus {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  width: 100vw;
  height: 100vh;
  display: block;
}

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 24px;
}

.site-header {
  position: relative;
  padding: 72px 0 28px;
}

h1 {
  font-size: clamp(2.1rem, 4vw, 3rem);
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  color: var(--text);
}

.tagline {
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 60ch;
  margin: 0 0 28px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

#search {
  flex: 1 1 240px;
  min-width: 200px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  padding: 11px 18px;
  font-size: 0.95rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  outline: none;
  transition: border-color 0.15s ease;
}
#search:focus { border-color: var(--accent); }

.sort-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.sort-btn:hover { color: var(--text); border-color: var(--border-strong); }
.sort-btn.active {
  color: #0b0d12;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.tag-filters { display: flex; flex-wrap: wrap; gap: 8px; }

.tag-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tag-btn:hover { color: var(--text); border-color: var(--border-strong); }
.tag-btn[aria-pressed="true"] {
  color: #0b0d12;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.tag-rail {
  position: fixed;
  top: 50%;
  left: 16px;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(2, max-content);
  align-items: start;
  justify-items: start;
  gap: 8px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 4px;
  transform: translate(-140%, -50%);
  transition: transform 0.25s ease;
}
.tag-rail.docked { transform: translate(0, -50%); }
@media (max-width: 640px) { .tag-rail { display: none; } }

/* Rail floats in the left gutter. When the window narrows the gutter vanishes
   and the rail overlaps the cards. Reserve a left lane so the grid squeezes
   instead — only while pills are docked, and only above the mobile breakpoint
   where the rail is hidden. Above ~1580px the natural gutter clears the rail,
   so no reserve needed. --rail-lane: tune if the widest pill pair overflows. */
@media (min-width: 641px) and (max-width: 1580px) {
  body:has(.tag-rail.docked) main.wrap { padding-left: var(--rail-lane, 260px); }
}
@media (max-width: 640px) {
  .tag-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    margin-inline: -24px;
    padding-inline: 24px;
    -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
  }
  .tag-filters::-webkit-scrollbar { display: none; }
  .tag-filters .tag-btn { flex: none; scroll-snap-align: start; }
}
.tag-slot { display: inline-flex; }
.tag-rail .tag-btn { animation: pill-in 0.25s ease; }
@keyframes pill-in {
  from { opacity: 0; transform: translateX(-24px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tag-rail .tag-btn { animation: none; }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
  padding: 12px 0 64px;
}

.card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  text-decoration: none;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  /* No backdrop-filter: the plexus canvas behind redraws every frame, so a
     blur per card re-rasterizes ~60 layers per frame and makes scroll drag. */
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  background: var(--panel-solid);
}
.card[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
}

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.card-tags span {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
}

.card-title { font-size: 1.18rem; margin: 0 0 6px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.card-arrow { color: var(--accent); opacity: 0.6; font-weight: 700; transition: opacity 0.16s ease; }
.card:hover .card-arrow { opacity: 1; }
.card-summary { color: var(--muted); font-size: 0.92rem; margin: 0; }

.empty { color: var(--muted); text-align: center; padding: 40px 0 80px; }
.site-header code { color: var(--text); }
code {
  background: rgba(255,255,255,0.06);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.85em;
}

.footer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 5;
}

.footer.visible {
  opacity: 1;
  pointer-events: auto;
}

.footer a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--muted);
  transition: color 0.2s ease;
}

.footer a:hover {
  color: var(--accent);
}

@media (max-width: 640px) {
  .footer {
    position: static;
    width: fit-content;
    margin: 24px auto;
    opacity: 1;
    pointer-events: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover { transform: none; }
  .footer { transition: none; }
}
