:root {
  --purple: #6e49cb;
  --purple-dark: #5a3bb0;
  --orange: #fc6d26;
  --bg: #fafaff;
  --surface: #ffffff;
  --surface-2: #f4f4fb;
  --border: #dcdce6;
  --border-strong: #c3c3d4;
  --text: #1f1e24;
  --text-muted: #5e5e6e;
  --text-subtle: #8c8c9c;
  --shadow: 0 1px 2px rgba(31, 30, 36, .08), 0 2px 8px rgba(31, 30, 36, .06);
  --shadow-lg: 0 8px 32px rgba(31, 30, 36, .18);
  --radius: 10px;
  --radius-sm: 6px;
  --focus: 0 0 0 3px rgba(110, 73, 203, .35);
  --header-h: 132px;
  --badge-cap-bg: rgba(31, 30, 36, .06);
  --beta: #c1510f;
  --beta-bg: rgba(252, 109, 38, .14);
  font-size: 16px;
}

/* Dark theme tokens, shared by system preference and the explicit toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --purple: #9a7ce8;
    --purple-dark: #b29aef;
    --bg: #16151c;
    --surface: #201f29;
    --surface-2: #2a2935;
    --border: #36353f;
    --border-strong: #4a4955;
    --text: #ecebf2;
    --text-muted: #a8a7b6;
    --text-subtle: #7d7c8c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, .5);
    --focus: 0 0 0 3px rgba(154, 124, 232, .4);
    --badge-cap-bg: rgba(255, 255, 255, .07);
    --beta: #ffae7a;
    --beta-bg: rgba(252, 109, 38, .2);
  }
}
:root[data-theme="dark"] {
  --purple: #9a7ce8;
  --purple-dark: #b29aef;
  --bg: #16151c;
  --surface: #201f29;
  --surface-2: #2a2935;
  --border: #36353f;
  --border-strong: #4a4955;
  --text: #ecebf2;
  --text-muted: #a8a7b6;
  --text-subtle: #7d7c8c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, .5);
  --focus: 0 0 0 3px rgba(154, 124, 232, .4);
  --badge-cap-bg: rgba(255, 255, 255, .07);
  --beta: #ffae7a;
  --beta-bg: rgba(252, 109, 38, .2);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "GitLab Sans", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }

a { color: var(--purple); }
a:hover { color: var(--purple-dark); }

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .88em;
  background: var(--surface-2);
  padding: .1em .35em;
  border-radius: 4px;
}

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

.visually-hidden, .skip-link {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed; top: 8px; left: 8px;
  width: auto; height: auto; clip: auto;
  background: var(--purple); color: #fff;
  padding: .5rem .75rem; border-radius: var(--radius-sm); z-index: 100;
}

/* ---------- Header ---------- */
.site-header {
  background: linear-gradient(120deg, var(--purple) 0%, var(--purple-dark) 60%, #41338a 100%);
  color: #fff;
}
.site-header__inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.site-header__title { display: flex; align-items: center; gap: 1rem; }
.site-header__logo {
  width: 80px; height: 80px; flex: none;
  background: #fff; border-radius: 14px; padding: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}
.site-header h1 { font-size: 1.5rem; }
.site-header__subtitle { margin: .35rem 0 0; color: rgba(255, 255, 255, .85); font-size: .95rem; max-width: 52ch; }

.site-header__right { display: flex; align-items: center; gap: 1.1rem; }

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; flex: none;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--radius);
  color: #fff; cursor: pointer;
}
.theme-toggle:hover { background: rgba(255, 255, 255, .24); }
.theme-toggle svg { width: 20px; height: 20px; }

/* Icon-led ruleset summary pills. */
.stats { display: flex; gap: .75rem; margin: 0; }
.stat-pill {
  display: inline-flex; align-items: center; gap: .5rem;
  background: rgba(255, 255, 255, .1);
  border-radius: 999px;
  padding: .4rem .9rem;
  color: rgba(255, 255, 255, .85);
}
.stat-pill svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.stat-pill__num { font-size: 1.3rem; font-weight: 700; color: #fff; }
.stat-pill__label { font-size: .88rem; }

/* ---------- Layout ---------- */
.layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 264px 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* ---------- Filters ---------- */
.filters-toggle { display: none; }

.filters {
  position: sticky;
  top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* legacy Edge/IE */
}
.filters::-webkit-scrollbar { display: none; } /* Chrome, Safari */
.filters__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.filters__head h2 { font-size: 1rem; }

.filter-group { border-bottom: 1px solid var(--border); }
.filter-group:last-child { border-bottom: 0; }
.filter-group > summary {
  cursor: pointer; list-style: none;
  padding: .7rem 1rem;
  font-weight: 600; font-size: .9rem;
  display: flex; align-items: center; justify-content: space-between;
  user-select: none;
}
.filter-group > summary::-webkit-details-marker { display: none; }
.filter-group > summary::after {
  content: ""; flex: none;
  width: 7px; height: 7px; margin-right: 3px;
  border-top: 2px solid var(--text-subtle);
  border-right: 2px solid var(--text-subtle);
  transform: rotate(45deg);
  transition: transform .15s ease;
}
.filter-group[open] > summary::after { transform: rotate(135deg); }
.filter-group__options { padding: 0 1rem .7rem; display: flex; flex-direction: column; gap: .1rem; }

.facet {
  display: flex; align-items: center; gap: .55rem;
  padding: .3rem .35rem; border-radius: var(--radius-sm);
  cursor: pointer; font-size: .88rem;
}
.facet:hover { background: var(--surface-2); }
.facet input { accent-color: var(--purple); width: 15px; height: 15px; flex: none; }
.facet__label { flex: 1; }
.facet__count { color: var(--text-subtle); font-size: .78rem; font-variant-numeric: tabular-nums; }
.facet--disabled { opacity: .45; cursor: default; }

.link-btn {
  background: none; border: 0; color: var(--purple);
  font: inherit; font-size: .85rem; cursor: pointer; padding: 0;
}
.link-btn:hover { color: var(--purple-dark); text-decoration: underline; }

/* ---------- Content / search ---------- */
.content { min-width: 0; }

.searchbar { margin-bottom: 1rem; }
.searchbar__field {
  display: flex; align-items: center; gap: .5rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0 .85rem;
  box-shadow: var(--shadow);
}
.searchbar__field:focus-within { box-shadow: var(--focus); border-color: var(--purple); }
.searchbar__icon { width: 18px; height: 18px; color: var(--text-subtle); flex: none; }
.searchbar input {
  border: 0; background: none; outline: none;
  font: inherit; color: var(--text);
  padding: .7rem 0; flex: 1; min-width: 0;
}

.active-filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  margin-bottom: 1rem;
}
.filter-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: .25rem .35rem .25rem .7rem;
  font-size: .82rem; color: var(--text); box-shadow: var(--shadow);
}
.filter-chip__group { color: var(--text-subtle); font-weight: 600; }
.filter-chip__remove {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; flex: none; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--text-muted);
  font-size: 1rem; line-height: 1; cursor: pointer;
}
.filter-chip__remove:hover { background: var(--purple); color: #fff; }
.active-filters__clear { margin-left: .25rem; }

.results-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .85rem; gap: 1rem; flex-wrap: wrap;
}
.result-count { margin: 0; color: var(--text-muted); font-size: .9rem; }
.sort { display: flex; align-items: center; gap: .45rem; font-size: .85rem; color: var(--text-muted); }
.sort select {
  font: inherit; font-size: .85rem; padding: .35rem 1.6rem .35rem .6rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); cursor: pointer;
}

/* ---------- Results ---------- */
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }

.rule-card {
  width: 100%; text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color .12s ease, transform .12s ease;
  font: inherit; color: inherit;
  display: block;
}
.rule-card:hover { border-color: var(--purple); transform: translateY(-1px); }
.rule-card__top { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.rule-card__title { font-size: 1.02rem; font-weight: 600; }
.rule-card__vendor { color: var(--text-muted); font-size: .85rem; white-space: nowrap; }
.rule-card__desc {
  margin: .4rem 0 .6rem; color: var(--text-muted); font-size: .88rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.rule-card__badges { display: flex; flex-wrap: wrap; gap: .35rem; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .72rem; font-weight: 600;
  padding: .18rem .5rem; border-radius: 999px;
  border: 1px solid var(--border-strong); color: var(--text-muted);
  background: var(--surface-2); white-space: nowrap;
}
.badge--type { border-color: transparent; background: rgba(110, 73, 203, .12); color: var(--purple); }
.badge--cap { border-color: transparent; background: var(--badge-cap-bg); }
.badge--count {
  background: #fff; color: var(--purple); border: 0;
  min-width: 1.2rem; justify-content: center; padding: .1rem .4rem;
}

/* Beta indication — distinct from chips: an accented dot + label. */
.beta-flag {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .7rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--beta); white-space: nowrap;
}
.beta-flag::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--beta); flex: none;
}
.rule-card--beta { border-left: 3px solid var(--beta); }
.detail__beta { margin: .5rem 0 0; }

/* ---------- Drawer ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(20, 19, 28, .45);
  z-index: 40; opacity: 0; animation: fade .15s ease forwards;
}
@keyframes fade { to { opacity: 1; } }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.22, .61, .36, 1);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.drawer.is-open { transform: translateX(0); }
.drawer__head {
  display: flex; justify-content: flex-end;
  padding: .6rem .75rem; border-bottom: 1px solid var(--border); flex: none;
}
.drawer__body { padding: 0 1.6rem 2rem; overflow-y: auto; }

.icon-btn {
  background: none; border: 0; cursor: pointer; color: var(--text-muted);
  font-size: 1.1rem; width: 2rem; height: 2rem; border-radius: var(--radius-sm);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.detail__title { font-size: 1.45rem; margin-top: .5rem; }
.detail__id { font-family: ui-monospace, monospace; font-size: .82rem; color: var(--text-subtle); margin: .3rem 0 0; }
.detail__badges { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0 1.5rem; }

.detail__section { margin-bottom: 1.6rem; }
.detail__section h3 {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-subtle); margin-bottom: .5rem;
}
.section-head h3 { margin-bottom: 0; }
.detail__caps { display: grid; gap: .4rem; }
.cap-row { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.cap-row__mark { font-size: .9rem; }
.cap-row--on { color: var(--text); }
.cap-row--off { color: var(--text-subtle); }

.prose { font-size: .92rem; color: var(--text); }
.prose p { margin: 0 0 .7rem; }
.prose ul, .prose ol { margin: 0 0 .7rem; padding-left: 1.3rem; }
.prose li { margin-bottom: .25rem; }
.prose code { font-size: .85em; }
.prose a { word-break: break-word; }

.code-block {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .7rem .85rem;
  font-family: ui-monospace, monospace; font-size: .82rem;
  overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; margin-bottom: .5rem;
}
.copy-btn {
  display: inline-flex; align-items: center; gap: .3rem; flex: none;
  font: inherit; font-size: .72rem; font-weight: 600;
  padding: .25rem .5rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-muted); cursor: pointer;
}
.copy-btn:hover { color: var(--text); border-color: var(--purple); }
.copy-btn svg { width: 12px; height: 12px; }
.copy-btn.is-copied { color: #1a7a30; border-color: #1a7a30; }
@media (prefers-color-scheme: dark) { .copy-btn.is-copied { color: #6ee7a0; border-color: #6ee7a0; } }
:root[data-theme="dark"] .copy-btn.is-copied { color: #6ee7a0; border-color: #6ee7a0; }
.example-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.example-list code {
  display: block; background: var(--surface-2); border: 1px solid var(--border);
  padding: .45rem .6rem; border-radius: var(--radius-sm);
  word-break: break-all; font-size: .8rem;
}
.synthetic-note { font-size: .78rem; color: var(--text-subtle); margin: 0 0 .5rem; }

details.tech { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: .4rem; }
details.tech > summary {
  cursor: pointer; padding: .6rem .85rem; font-weight: 600; font-size: .85rem;
  list-style: none; display: flex; align-items: center; gap: .5rem;
}
details.tech > summary::-webkit-details-marker { display: none; }
details.tech > summary::before {
  content: ""; flex: none;
  width: 6px; height: 6px;
  border-top: 2px solid var(--text-subtle);
  border-right: 2px solid var(--text-subtle);
  transform: rotate(45deg);
  transition: transform .15s ease;
}
details.tech[open] > summary::before { transform: rotate(135deg); }
details.tech > div { padding: 0 .85rem .85rem; }

/* ---------- States / footer ---------- */
.empty, .error {
  text-align: center; padding: 3rem 1rem; color: var(--text-muted);
  background: var(--surface); border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.error { border-color: var(--orange); }

.site-footer {
  max-width: 1240px; margin: 0 auto; padding: 2rem 1.5rem 3rem;
  color: var(--text-subtle); font-size: .82rem; text-align: center;
}
.site-footer p { margin: .25rem 0; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .filters-toggle {
    display: inline-flex; align-items: center; gap: .5rem;
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius); padding: .6rem 1rem; font: inherit; font-weight: 600;
    cursor: pointer; color: var(--text); box-shadow: var(--shadow);
  }
  .filters { display: none; position: static; max-height: none; margin-top: .25rem; }
  .filters.is-open { display: block; }
  .stats { width: 100%; }
}
