:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1b2230;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e4e7ec;
  --line-strong: #cfd4dc;
  --accent: #2557d6;
  --accent-text: #ffffff;
  --accent-weak: #e7eefc;
  --hover: #f6f7f9;
  --mark: #fff0a8;
  --thumb-bg: #ffffff;
  --ok: #157f3d;
  --bad: #c0392b;
  --basic-bg: #dcf5e4; --basic-fg: #146c36;
  --pref-bg: #d5f3f0; --pref-fg: #0f5f5a;
  --ext-bg: #e8eaf0; --ext-fg: #414a5c;
  --eco-bg: #ece6fd; --eco-fg: #5a2fb8;
  --smd-bg: #e0effc; --smd-fg: #0c5a8f;
  --tht-bg: #fde8dd; --tht-fg: #9a3b12;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --card: #1a1f27; --text: #e6e9ef; --muted: #9aa4b5; --faint: #6d7789;
    --line: #2a313c; --line-strong: #3a4250; --accent: #4f7df0; --accent-weak: #22304d; --hover: #20262f;
    --mark: #6b5a12; --thumb-bg: #f4f5f7; --ok: #4cc27a; --bad: #ef6f61;
    --basic-bg: #173a26; --basic-fg: #7fdca2; --pref-bg: #13383a; --pref-fg: #77d8d0;
    --ext-bg: #2a303b; --ext-fg: #b9c1d0; --eco-bg: #2d2350; --eco-fg: #c3b0ff;
    --smd-bg: #142f47; --smd-fg: #8cc8f5; --tht-bg: #44271a; --tht-fg: #f5b48f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
kbd, code { font-family: var(--mono); font-size: .92em; background: var(--hover); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* ------------------------------------------------------------ header */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px 20px 8px;
}
.bar { display: flex; align-items: center; gap: 16px; max-width: 1680px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 650; white-space: nowrap; }
.search { position: relative; flex: 1; max-width: 900px; }
.search input {
  width: 100%; height: 40px; padding: 0 40px 0 38px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--card);
  font-size: 16px; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.search input::-webkit-search-cancel-button { display: none; }
.search-icon { position: absolute; left: 12px; top: 11px; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2.2; stroke-linecap: round; }
.clear { position: absolute; right: 6px; top: 6px; width: 28px; height: 28px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 20px; line-height: 1; }
.clear:hover { background: var(--hover); color: var(--text); }

.toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; max-width: 1680px; margin: 8px auto 0; }
.group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.group.right { margin-left: auto; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--card); color: var(--text); font-size: 13px; white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s;
}
.pill:hover { background: var(--hover); }
.pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.pill.on:hover { filter: brightness(1.08); }
.pill .n { font-size: 12px; opacity: .7; font-variant-numeric: tabular-nums; }
.pill .n:empty { display: none; }
.pill.ghost { border-style: dashed; }
.pill:disabled { opacity: .45; cursor: default; }
.pill-combo { display: inline-flex; align-items: center; }
.pill-combo .pill { border-radius: 999px 0 0 999px; }
.pill-combo select {
  height: 30px; border: 1px solid var(--line-strong); border-left: 0; border-radius: 0 999px 999px 0;
  background: var(--card); font-size: 12.5px; padding: 0 6px 0 8px; color: var(--muted);
}
.pill-combo .pill.on + select { border-color: var(--accent); color: var(--text); }
.sort { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.sort select { height: 30px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); padding: 0 6px; font-size: 13px; color: var(--text); }

.progress { position: absolute; left: 0; bottom: -1px; height: 2px; width: 100%; background: var(--accent); opacity: 0; transform: scaleX(0); transform-origin: left center; transition: transform .4s ease, opacity .3s; }
.progress.busy { transform: scaleX(.7); opacity: 1; transition: transform 2.5s cubic-bezier(.1, .6, .3, 1), opacity .1s; }

/* ------------------------------------------------------------ facet columns */
.facets {
  display: flex; gap: 12px; align-items: flex-start;
  max-width: 1680px; margin: 12px auto 0; padding: 0 20px;
  overflow-x: auto;
}
.facet { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 10px; min-width: 0; box-shadow: var(--shadow); }
/* Category and the value columns get the room; package is capped and scrolls sideways. */
.facet-cat { flex: 0 0 420px; }
.facet-pkg { flex: 0 1 460px; min-width: 220px; }
.facet-nums { display: contents; }
.facet-num { flex: 1 1 0; min-width: 170px; }
.facet-body.grid { overflow-x: auto; }
.facet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12px; text-transform: none; letter-spacing: 0; font-weight: 500; }
.link:disabled { visibility: hidden; }
.facet-body { max-height: 252px; overflow: auto; overscroll-behavior: contain; }
.facet-body.grid { display: grid; grid-auto-flow: column; grid-auto-columns: max-content; grid-template-rows: repeat(var(--rows, 8), auto); gap: 4px 6px; justify-content: start; }
.facet-body.grid .fp { width: 100%; }
.facet-empty { color: var(--faint); font-size: 12.5px; padding: 4px 0; }

.fp {
  display: inline-flex; align-items: center; justify-content: space-between; gap: 6px;
  height: 25px; padding: 0 9px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--card); font-size: 12.5px; white-space: nowrap; text-align: left; min-width: 0;
}
.fp:hover { background: var(--hover); }
.fp .n { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.fp.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.fp.on .n { color: inherit; opacity: .8; }
.fp.zero:not(.on) { opacity: .45; }
.cat-group { margin-bottom: 4px; }
.cat-group > .fp { font-weight: 600; }
.subs { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; margin: 3px 0 6px 14px; padding-left: 8px; border-left: 1px solid var(--line); }
/* Long subcategory names wrap instead of being cut off. */
.subs .fp { max-width: 100%; height: auto; min-height: 25px; padding: 3px 9px; border-radius: 13px; white-space: normal; line-height: 1.25; }
.fp.in { background: var(--accent-weak); border-color: var(--accent); }
.head-tools { display: inline-flex; align-items: center; gap: 10px; }
.modes { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.mode { border: 0; background: var(--card); color: var(--muted); width: 26px; height: 20px; padding: 0; font-size: 13px; line-height: 1; text-transform: none; }
.mode + .mode { border-left: 1px solid var(--line-strong); }
.mode:hover { background: var(--hover); color: var(--text); }
.mode.on { background: var(--accent); color: var(--accent-text); }

/* ------------------------------------------------------------ results */
.results { max-width: 1680px; margin: 0 auto; padding: 10px 20px 60px; }
.status { color: var(--muted); font-size: 13px; padding: 4px 2px 10px; min-height: 30px; }
.status b { color: var(--text); }
.status .err { color: var(--bad); }

.card {
  display: grid;
  grid-template-columns: 128px 128px 72px minmax(0, 1fr) 210px;
  grid-template-areas: "photo fp sch info buy";
  gap: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow);
  min-height: 154px;
}
.card.dim { opacity: .75; }
.thumb {
  position: relative; margin: 0;
  width: 128px; height: 128px;
  display: grid; place-items: center;
  background: var(--thumb-bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; cursor: zoom-in; }
.thumb.photo { grid-area: photo; }
.thumb.fp-img { grid-area: fp; }
.thumb.sch { grid-area: sch; width: 72px; height: 72px; }
.thumb figcaption {
  position: absolute; left: 4px; bottom: 3px; font-size: 10px; color: #8a93a3; letter-spacing: .03em; pointer-events: none;
}
.thumb.empty img { display: none; }
.thumb.empty::before {
  content: ""; width: 34px; height: 34px; opacity: .35;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='1.6'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='9' cy='9' r='2'/%3E%3Cpath d='m21 15-5-5L5 21'/%3E%3C/svg%3E");
}
.thumb.sch.empty::before { width: 24px; height: 24px; }

.info { grid-area: info; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.line1 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.mpn { font-family: var(--mono); font-size: 15.5px; font-weight: 650; word-break: break-all; }
.lcsc {
  font-family: var(--mono); font-size: 13px; color: var(--accent);
  background: var(--accent-weak); border: 1px solid transparent; border-radius: 6px; padding: 1px 7px;
}
.lcsc:hover { border-color: var(--accent); }
.lcsc::after { content: ""; display: inline-block; width: 11px; height: 11px; margin-left: 5px; vertical-align: -1px; opacity: .55;
  background: currentColor; -webkit-mask: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4'%3E%3Crect x='9' y='9' width='12' height='12' rx='2'/%3E%3Cpath d='M5 15V5a2 2 0 0 1 2-2h10'/%3E%3C/svg%3E"); mask: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4'%3E%3Crect x='9' y='9' width='12' height='12' rx='2'/%3E%3Cpath d='M5 15V5a2 2 0 0 1 2-2h10'/%3E%3C/svg%3E"); }
.badge { font-size: 11px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; border-radius: 5px; padding: 2px 7px; }
.b-basic { background: var(--basic-bg); color: var(--basic-fg); }
.b-preferred { background: var(--pref-bg); color: var(--pref-fg); }
.b-extended { background: var(--ext-bg); color: var(--ext-fg); }
.b-eco { background: var(--eco-bg); color: var(--eco-fg); }
.b-smd { background: var(--smd-bg); color: var(--smd-fg); }
.b-tht { background: var(--tht-bg); color: var(--tht-fg); }
.pkg { font-size: 12.5px; border: 1px solid var(--line-strong); border-radius: 5px; padding: 0 7px; color: var(--text); }
.desc { font-size: 14px; }
.desc mark, .mpn mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.meta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 14px; }
.meta b { color: var(--text); font-weight: 550; }
.links { margin-top: auto; display: flex; gap: 14px; font-size: 12.5px; }
.links a { color: var(--muted); text-decoration: none; }
.links a:hover { color: var(--accent); text-decoration: underline; }
.links a::after { content: " ↗"; font-size: 11px; }

.buy { grid-area: buy; display: flex; flex-direction: column; gap: 6px; font-variant-numeric: tabular-nums; border-left: 1px solid var(--line); padding-left: 14px; }
.stock { display: grid; grid-template-columns: auto 1fr; gap: 0 10px; font-size: 12.5px; }
.stock span { color: var(--muted); }
.stock b { text-align: right; font-weight: 600; color: var(--ok); }
.stock b.none { color: var(--bad); }
.prices { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.prices td { padding: 1px 0; border-top: 1px solid var(--line); }
.prices td:first-child { color: var(--muted); }
.prices td:last-child { text-align: right; font-weight: 550; }
.prices tr.cur td { color: var(--text); }
.noprice { font-size: 12.5px; color: var(--faint); }

.sentinel { height: 1px; }
.loadmore { text-align: center; color: var(--muted); padding: 14px; font-size: 13px; }

.intro { max-width: 760px; margin: 40px auto; color: var(--muted); }
.intro h1 { color: var(--text); font-size: 22px; margin: 0 0 8px; }
.intro ul { padding-left: 18px; }
.intro li { margin: 6px 0; }
.intro .credit { font-size: 12.5px; margin-top: 28px; }

/* ------------------------------------------------------------ hover preview + toast */
.preview {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--thumb-bg); border: 1px solid var(--line-strong); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(16, 24, 40, .22); padding: 8px;
}
.preview img { display: block; width: 420px; height: 420px; object-fit: contain; }
.preview.small img { width: 340px; height: 340px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #1b2230; color: #fff; border-radius: 8px; padding: 8px 14px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------ small screens */
@media (max-width: 1100px) {
  .card { grid-template-columns: 104px 104px 60px minmax(0, 1fr) 190px; }
  .thumb { width: 104px; height: 104px; }
  .thumb.sch { width: 60px; height: 60px; }
}
@media (max-width: 860px) {
  .top { padding: 8px 12px; }
  .brand span { display: none; }
  .facets, .results { padding-left: 12px; padding-right: 12px; }
  .card {
    grid-template-columns: 96px 96px minmax(0, 1fr);
    grid-template-areas: "photo fp sch" "info info info" "buy buy buy";
    min-height: 0;
  }
  .thumb { width: 96px; height: 96px; }
  .thumb.sch { width: 60px; height: 60px; }
  .buy { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 8px; }
  .group.right { margin-left: 0; }
  .facet-cat, .facet-pkg, .facet-num { flex: 0 0 85vw; }
}
@media (hover: none) { .preview { display: none !important; } }
.thumb:not(.empty) figcaption { display: none; }
.caret { width: 14px; display: inline-block; text-align: center; color: var(--muted); }
.cat-group > .fp { vertical-align: middle; }
.thumb.wait img { visibility: hidden; }
