:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f4f6f8;
  --line: #e4e8ee;
  --text: #161b22;
  --text-2: #424b57;
  --muted: #6b7480;

  /* Funnel layer — selection / interaction */
  --brand: #2f6df0;
  --brand-soft: #e9effe;
  --brand-line: #c7d8fb;

  /* Preview layer — explanatory annotations */
  --note: #6d4ed6;
  --note-2: #533aa8;
  --note-soft: #f2edfd;
  --note-line: #ddd0f7;
  --note-mark: #e6dcfb;

  /* Mechanic semantics (used inside the preview layer) */
  --hard: #b5651d;          /* hard step / facetFilter (narrows) */
  --hard-soft: #fbeede;
  --hard-line: #f0d8bd;
  --soft: #0c8a8a;          /* soft step / optionalFilter (boosts) */
  --soft-soft: #ddf4f3;
  --soft-line: #b3e3e0;

  --good: #128a5b;
  --good-soft: #e3f5ec;
  --good-line: #bfe6d2;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 22px rgba(20,30,50,.07);
  --shadow-sm: 0 2px 8px rgba(20,30,50,.05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
code { font-family: var(--mono); font-size: .9em; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap;
  padding: 12px 22px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); z-index: 10;
}
.brand { font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--note); margin-left: 4px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.badge { font-size: 12px; color: var(--muted); border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px; background: var(--panel); white-space: nowrap; }
.badge.live { color: var(--good); border-color: var(--good-line); background: var(--good-soft); }
.badge.local { color: var(--hard); border-color: var(--hard-line); background: var(--hard-soft); }

/* annotation toggle */
.annot-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 12.5px; color: var(--text-2); }
.annot-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.annot-switch { width: 34px; height: 20px; border-radius: 999px; background: #cdd3db; position: relative; transition: .15s; flex: none; }
.annot-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.annot-toggle input:checked + .annot-switch { background: var(--note); }
.annot-toggle input:checked + .annot-switch::after { transform: translateX(14px); }
.annot-toggle input:focus-visible + .annot-switch { outline: 2px solid var(--note); outline-offset: 2px; }
.annot-label { white-space: nowrap; }

main { max-width: 1180px; margin: 0 auto; padding: 26px 22px 60px; }
.hidden { display: none !important; }

/* ---------- The preview layer: a tagged "note" ---------- */
.note {
  position: relative;
  background: var(--note-soft);
  border: 1px solid var(--note-line);
  border-left: 3px solid var(--note);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  color: var(--note-2);
  font-size: 12.5px; line-height: 1.5;
}
.note p { margin: 0; }
.note code { background: #fff; border: 1px solid var(--note-line); border-radius: 4px; padding: 0 4px; color: var(--note-2); }
.note-tag {
  display: inline-block; font: 700 10px/1 var(--mono); text-transform: uppercase; letter-spacing: .8px;
  color: #fff; background: var(--note); padding: 3px 6px; border-radius: 5px; margin-right: 7px; vertical-align: 1px;
}
.note-mark { background: var(--note-mark); border-radius: 4px; padding: 0 4px; font-weight: 600; }
/* the toggle hides every preview-layer element */
body.hide-annotations .preview-only { display: none !important; }

/* ---------- Chooser ---------- */
.chooser h1 { font-size: 30px; margin: 6px 0 6px; letter-spacing: -.3px; }
.sub { color: var(--muted); margin: 0 0 18px; max-width: 60ch; }
.note-intro { margin: 0 0 24px; max-width: 80ch; }
.chooser-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.choose-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; cursor: pointer; transition: .15s; text-align: left; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
}
.choose-card:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow); }
.choose-card .ct { font-size: 18px; font-weight: 650; }
.choose-card .cs { color: var(--muted); font-size: 13px; }
.card-note { font-size: 11.5px; padding: 7px 9px; margin-top: 2px; }
.card-note code { font-size: 11px; }

/* ---------- Legend ---------- */
.legend { margin-bottom: 20px; padding: 13px 15px; }
.legend h2 { font-size: 13.5px; margin: 8px 0 9px; color: var(--note-2); }
.legend ul { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 9px; }
.legend li { font-size: 12.5px; color: var(--text-2); display: flex; gap: 10px; align-items: flex-start; line-height: 1.5; }
.legend li b { color: var(--text); }
.swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; margin-top: 2px; }
.swatch-funnel { background: #fff; border: 2px solid var(--brand); }
.swatch-preview { background: var(--note); }

/* kind pills (preview layer) */
.pill { font: 700 10.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .4px; padding: 3px 7px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.pill.hard { color: var(--hard); background: var(--hard-soft); border-color: var(--hard-line); }
.pill.soft { color: var(--soft); background: var(--soft-soft); border-color: var(--soft-line); }

/* ---------- Finder layout ---------- */
.finder { display: grid; grid-template-columns: 1fr 380px; gap: 26px; align-items: start; }
@media (max-width: 900px) { .finder { grid-template-columns: 1fr; } }

.restart { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 13px; }
.restart:hover { color: var(--brand); }
#funnel-title { font-size: 26px; margin: 10px 0 18px; letter-spacing: -.3px; }

/* ---------- Steps (funnel) ---------- */
.step { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px 18px; margin-bottom: 14px; box-shadow: var(--shadow-sm); }
.step-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.step-num { width: 22px; height: 22px; flex: none; border-radius: 999px; background: var(--text); color: #fff; font: 600 12px/22px -apple-system, sans-serif; text-align: center; }
.step-q { font-size: 16.5px; font-weight: 650; }
.step-hint { color: var(--text-2); font-size: 13px; margin: 9px 0 0; line-height: 1.5; }
.mechanic { margin: 10px 0 0; }
.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(235px, 1fr)); gap: 10px; align-items: start; margin-top: 13px; }

.opt { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-sm); padding: 12px 13px; cursor: pointer; transition: .12s; }
.opt:hover { border-color: var(--brand); box-shadow: var(--shadow-sm); }
.opt.on { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.opt-label { font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.4; }
.opt-hint { font-size: 12px; color: var(--muted); margin-top: 5px; line-height: 1.45; }

/* mapped Algolia clauses (preview layer) */
.opt-clauses { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--note-line); }
.clause { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; font: 11px/1.3 var(--mono); border-radius: 6px; padding: 2px 5px; border: 1px solid; }
.clause-code { overflow-wrap: anywhere; min-width: 0; }
.clause-facetFilter { color: var(--hard); background: var(--hard-soft); border-color: var(--hard-line); }
.clause-optionalFilter { color: var(--soft); background: var(--soft-soft); border-color: var(--soft-line); }
.clause-numericFilter { color: var(--text-2); background: var(--panel-2); border-color: var(--line); }
.clause-matches { font-weight: 700; opacity: .85; }
.clause-none { color: var(--muted); background: var(--panel-2); border: 1px dashed var(--line); font-family: inherit; font-size: 11.5px; padding: 2px 8px; }

/* ---------- Results ---------- */
.results { position: sticky; top: 74px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.results-head { display: flex; align-items: baseline; gap: 8px; padding-bottom: 12px; }
.count { font-size: 28px; font-weight: 750; color: var(--brand); }
.count-label { color: var(--muted); font-size: 13px; }
.results-explain { margin-bottom: 14px; }
.result-list { display: flex; flex-direction: column; gap: 10px; max-height: 66vh; overflow: auto; }
.rcard { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; background: var(--panel); display: grid; grid-template-columns: 56px 1fr; gap: 11px; align-items: start; }
.rcard img { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--line); }
.rbody { min-width: 0; }
.rhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.rn { font-size: 13px; font-weight: 600; line-height: 1.35; }
.rscore { flex: none; font: 700 11px/1 var(--mono); color: var(--note-2); background: var(--note-soft); border: 1px solid var(--note-line); border-radius: 999px; padding: 3px 8px; }
.rmeta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.rneeds { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--panel-2); }
.tag.good { color: var(--good); border-color: var(--good-line); background: var(--good-soft); }
.tag.need { color: var(--soft); border-color: var(--soft-line); background: var(--soft-soft); }
.empty-note { color: var(--muted); font-size: 13px; padding: 8px 2px; }

/* query inspector (preview layer) */
.debug { margin-top: 14px; padding: 0; background: var(--note-soft); }
.debug summary { cursor: pointer; font-size: 12px; color: var(--note-2); padding: 10px 13px; list-style: none; }
.debug summary::-webkit-details-marker { display: none; }
.debug[open] summary { border-bottom: 1px dashed var(--note-line); }
.debug pre { font: 11px/1.5 var(--mono); color: #38465a; background: #fff; border: 0; border-radius: 0 0 var(--radius-sm) var(--radius-sm); margin: 0; padding: 12px 13px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
