/* Design tokens. Branding lands later - reskinning should be this block only. */
:root {
  --bg: #fbfbfa;
  --bg-elev: #ffffff;
  --bg-sunk: #f2f2f0;
  --line: #e4e4e0;
  --line-soft: #eeeeea;
  --ink: #16160f;
  --ink-2: #55554c;
  --ink-3: #8a8a80;
  --accent: #1a1a17;
  /* --brand is injected from config.php; everything below derives from it,
     so one hex re-skins every interactive state. */
  --brand: #c2452e;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, transparent);
  --brand-line: color-mix(in srgb, var(--brand) 38%, var(--line));
  --brand-ink: color-mix(in srgb, var(--brand) 82%, var(--ink));
  --focus: var(--brand);

  --air: #e5484d;
  --cabin: #3b82f6;
  --oil: #eab308;
  --fuel: #22c55e;

  --r-sm: 8px;
  --r: 14px;
  --r-lg: 22px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.04);
  --shadow-2: 0 4px 12px rgba(0,0,0,.06), 0 12px 32px rgba(0,0,0,.07);
  --shadow-3: 0 8px 24px rgba(0,0,0,.10), 0 32px 64px rgba(0,0,0,.12);
  --ease: cubic-bezier(.22,.61,.36,1);
  --font: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
/* Dark palette applies when the OS asks for it, unless light is forced,
   or when dark is forced explicitly. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e0d; --bg-elev: #17171a; --bg-sunk: #121214;
    --line: #26262a; --line-soft: #1e1e22;
    --ink: #f2f2ef; --ink-2: #a9a9a3; --ink-3: #6f6f69;
    --accent: #f2f2ef;
    --brand-soft: color-mix(in srgb, var(--brand) 20%, transparent);
    --brand-line: color-mix(in srgb, var(--brand) 46%, var(--line));
    --brand-ink: color-mix(in srgb, var(--brand) 70%, var(--ink));
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 4px 14px rgba(0,0,0,.45);
    --shadow-3: 0 12px 40px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
    --bg: #0e0e0d; --bg-elev: #17171a; --bg-sunk: #121214;
    --line: #26262a; --line-soft: #1e1e22;
    --ink: #f2f2ef; --ink-2: #a9a9a3; --ink-3: #6f6f69;
    --accent: #f2f2ef;
    --brand-soft: color-mix(in srgb, var(--brand) 20%, transparent);
    --brand-line: color-mix(in srgb, var(--brand) 46%, var(--line));
    --brand-ink: color-mix(in srgb, var(--brand) 70%, var(--ink));
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 4px 14px rgba(0,0,0,.45);
    --shadow-3: 0 12px 40px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  /* light-touch deterrence; inputs re-enabled below */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
img { -webkit-user-drag: none; user-drag: none; pointer-events: none; }

/* ---------- shell ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 24px 96px; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 13px 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .25s var(--ease);
}
.topbar.stuck { border-bottom-color: var(--line); }
.bar-side { display: flex; align-items: center; min-width: 0; }
.bar-side.end { justify-content: flex-end; }
.logo-link { display: flex; align-items: center; justify-self: center; color: var(--ink); }
.logo { height: var(--logo-h, 26px); width: auto; display: block; }
/* logo follows the resolved theme, not the OS preference */
.logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .logo-light { display: none; }
  html:not([data-theme="light"]) .logo-dark  { display: block; }
}
html[data-theme="dark"] .logo-light { display: none; }
html[data-theme="dark"] .logo-dark  { display: block; }
html[data-theme="light"] .logo-light { display: block; }
html[data-theme="light"] .logo-dark  { display: none; }
.login-logo { justify-content: center; margin-bottom: 14px; }
@media (max-width: 520px) { .logo { height: calc(var(--logo-h, 26px) * .85); } }
.ghost {
  color: var(--ink-3); text-decoration: none; font-size: 13px;
  padding: 6px 10px; border-radius: var(--r-sm);
}
.ghost:hover { color: var(--brand-ink); background: var(--brand-soft); }

/* ---------- hero search ---------- */
.hero {
  padding: clamp(48px, 12vh, 130px) 0 34px;
  text-align: center;
  transition: padding .45s var(--ease);
}
.hero.compact { padding: 22px 0 18px; }
.hero h1 {
  font-size: clamp(28px, 4.4vw, 46px);
  letter-spacing: -.035em; font-weight: 640;
  margin: 0 0 10px; line-height: 1.05;
}
.hero p { color: var(--ink-2); margin: 0 0 30px; font-size: 15px; }
.hero.compact h1, .hero.compact p { display: none; }

.searchbox {
  position: relative; max-width: 660px; margin: 0 auto;
}
.searchbox input {
  width: 100%; font: inherit; font-size: 17px;
  padding: 17px 52px 17px 50px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  box-shadow: var(--shadow-2);
  transition: box-shadow .25s var(--ease), border-color .2s var(--ease);
}
.searchbox input::placeholder { color: var(--ink-3); }
.searchbox input:focus {
  outline: none; border-color: var(--brand-line);
  box-shadow: var(--shadow-3), 0 0 0 4px var(--brand-soft);
}
.searchbox input:focus + .kbd { border-color: var(--brand-line); color: var(--brand-ink); }
.searchbox .icon {
  position: absolute; left: 18px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); pointer-events: none; display: flex;
}
.box-actions {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; gap: 2px;
}
.icon-btn {
  position: relative; width: 32px; height: 32px; border-radius: 9px;
  border: 0; background: transparent; color: var(--ink-3);
  cursor: pointer; display: grid; place-items: center;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--bg-sunk); color: var(--ink); }
.icon-btn.on { color: var(--brand); background: var(--brand-soft); }
.icon-btn .badge {
  position: absolute; top: 1px; right: 1px; min-width: 15px; height: 15px;
  border-radius: 999px; background: var(--brand); color: #fff;
  font: 600 9.5px/15px var(--font); text-align: center; padding: 0 3px;
}
.searchbox.busy .box-actions { opacity: 0; transition: opacity .2s; }
.spinner {
  position: absolute; right: 18px; top: 50%; margin-top: -8px;
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--ink-3);
  animation: spin .7s linear infinite; opacity: 0;
  transition: opacity .2s;
}
.searchbox.busy .spinner { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- filters ---------- */
.filters {
  position: relative; z-index: 30;   /* above the results grid below it */
  max-width: 660px; margin: 10px auto 0; text-align: left;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-2);
  padding: 14px 16px 12px;
  /* no overflow:hidden - it clipped the typeahead dropdown. The drop animation
     works without clipping. */
  animation: drop .28s var(--ease) both;
}
.filters[hidden] { display: none; }
@keyframes drop {
  from { opacity: 0; transform: translateY(-8px) scaleY(.97); transform-origin: top; }
}
.filter-row { display: flex; gap: 12px; padding: 7px 0; align-items: flex-start; }
.filter-label {
  flex: none; width: 54px; padding-top: 5px;
  font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-3);
}
.chip-set { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }

/* token input: chips for what is chosen, typeahead for adding more */
.tokens {
  position: relative; flex: 1; min-width: 0;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); padding: 5px 7px;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.tokens:focus-within {
  border-color: var(--brand-line);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.token {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 520; padding: 4px 5px 4px 9px;
  border-radius: 999px; background: var(--brand); color: #fff;
}
.token button {
  border: 0; background: none; color: #fff; cursor: pointer;
  width: 15px; height: 15px; border-radius: 50%; line-height: 1;
  display: grid; place-items: center; font-size: 13px; opacity: .75;
}
.token button:hover { opacity: 1; background: rgba(255,255,255,.22); }
.token-input {
  flex: 1; min-width: 110px; border: 0; outline: none; background: none;
  font: inherit; font-size: 13px; color: var(--ink); padding: 4px 2px;
}
.token-input::placeholder { color: var(--ink-3); }

.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 5px); z-index: 40;
  margin: 0; padding: 4px; list-style: none; max-height: 224px; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 11px; box-shadow: var(--shadow-2);
  animation: drop .16s var(--ease) both;
}
.suggest[hidden] { display: none; }
.suggest li {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 13px;
  color: var(--ink-2);
}
.suggest li[aria-selected="true"], .suggest li:hover {
  background: var(--brand-soft); color: var(--brand-ink);
}
.suggest li .n { font-size: 11px; opacity: .6; }
.suggest .none { color: var(--ink-3); cursor: default; }
.suggest .none:hover { background: none; color: var(--ink-3); }
.opt {
  font: inherit; font-size: 12.5px; cursor: pointer;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg);
  color: var(--ink-2); white-space: nowrap;
  transition: background .16s var(--ease), border-color .16s var(--ease),
              color .16s var(--ease);
}
.opt:hover { border-color: var(--brand-line); color: var(--ink); }
.opt.on {
  background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 520;
}
.opt .n { opacity: .55; margin-left: 5px; font-size: 11px; }
.opt.on .n { opacity: .75; }
.filter-foot { display: flex; justify-content: flex-end; padding-top: 6px; }
.link-btn {
  border: 0; background: none; cursor: pointer; font: inherit; font-size: 12.5px;
  color: var(--ink-3); padding: 4px 2px;
}
.link-btn:hover { color: var(--brand-ink); }

.outside-note {
  margin: 34px 2px 12px; font-size: 12.5px; color: var(--ink-3);
  display: flex; align-items: center; gap: 9px;
}
.outside-note::before, .outside-note::after {
  content: ''; height: 1px; background: var(--line-soft); flex: 1;
}

/* ---------- results ---------- */
.meta-row {
  display: flex; align-items: baseline; gap: 10px;
  margin: 26px 2px 14px; font-size: 13px; color: var(--ink-3);
}
.meta-row h2 {
  font-size: 13px; font-weight: 560; letter-spacing: .01em;
  color: var(--ink-2); margin: 0; text-transform: none;
}

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
}
.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  overflow: hidden; cursor: pointer;
  transition: transform .22s var(--ease), box-shadow .22s var(--ease),
              border-color .22s var(--ease);
  animation: rise .34s var(--ease) both;
}
.card:hover, .card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--brand-line);
  box-shadow: var(--shadow-2);
  outline: none;
}
.card:focus-visible { box-shadow: var(--shadow-2), 0 0 0 3px var(--brand-soft); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
  * { transition-duration: .01ms !important; }
}

.thumb {
  aspect-ratio: 4/3; background: var(--bg-sunk);
  display: grid; place-items: center; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; padding: 12px; }
.thumb.empty::after {
  content: ''; width: 34px; height: 34px; border-radius: 8px;
  border: 2px dashed var(--line);
}
.card-body { padding: 12px 13px 14px; display: flex; flex-direction: column; gap: 7px; }
.card-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.brand-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 5px;
  background: var(--bg-sunk); color: var(--ink-2); white-space: nowrap;
}
.code { font: 600 14px/1 var(--mono); letter-spacing: -.01em; }
.desc {
  font-size: 12.5px; color: var(--ink-2); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.chip {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--bg-sunk); color: var(--ink-2); white-space: nowrap;
}
.chip.type { display: inline-flex; align-items: center; gap: 5px; font-weight: 520; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.t-air { background: var(--air); } .t-cabin { background: var(--cabin); }
.t-oil { background: var(--oil); } .t-fuel { background: var(--fuel); }

/* infinite-scroll sentinel */
.sentinel {
  display: flex; justify-content: center; gap: 6px; padding: 30px 0 6px;
}
/* an author display rule beats the UA stylesheet for [hidden] - be explicit */
.sentinel[hidden] { display: none; }
.sentinel span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3);
  opacity: .25; animation: bob 1.1s var(--ease) infinite;
}
.sentinel span:nth-child(2) { animation-delay: .13s; }
.sentinel span:nth-child(3) { animation-delay: .26s; }
@keyframes bob { 0%,100% { transform: translateY(0); opacity: .25; }
                 50% { transform: translateY(-5px); opacity: .7; } }
@media (prefers-reduced-motion: reduce) { .sentinel span { animation: none; } }

.empty-state { text-align: center; padding: 70px 20px; color: var(--ink-3); }
.empty-state strong { display: block; color: var(--ink-2); font-weight: 560; margin-bottom: 6px; }

.skeleton { pointer-events: none; }
.skeleton .thumb, .skeleton .code, .skeleton .desc {
  background: linear-gradient(90deg, var(--bg-sunk) 25%, var(--line-soft) 50%, var(--bg-sunk) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; color: transparent;
  border-radius: 6px;
}
.skeleton .code { height: 14px; width: 60%; } .skeleton .desc { height: 30px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- detail panel ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10,10,10,.32); backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity .3s var(--ease);
}
.scrim.open { opacity: 1; pointer-events: auto; }

.panel {
  position: fixed; z-index: 70; top: 0; right: 0; height: 100dvh;
  width: min(660px, 100vw);
  background: var(--bg-elev); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  transform: translateX(101%);
  transition: transform .38s var(--ease);
  display: flex; flex-direction: column;
}
.panel.open { transform: none; }
@media (max-width: 640px) {
  .panel { width: 100vw; top: auto; bottom: 0; height: 92dvh;
           border-left: 0; border-top-left-radius: 18px; border-top-right-radius: 18px;
           transform: translateY(101%); }
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line-soft); flex: none;
}
.panel-head .code { font-size: 17px; }
.close {
  margin-left: auto; border: 1px solid var(--line); background: var(--bg);
  color: var(--ink-2); width: 32px; height: 32px; border-radius: 9px;
  cursor: pointer; display: grid; place-items: center; font-size: 15px;
}
.close:hover { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand-line); }
.panel-body {
  overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 24px;
  /* keep wheel/touch scrolling inside the panel instead of chaining to the page */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* Lock the page while the panel is open. overflow:hidden alone resets scrollTop
   to 0, so the reader loses their place; pinning the body preserves it and the
   saved offset is restored on close. */
body.locked { position: fixed; width: 100%; overflow: hidden; }

.gallery { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.gallery img {
  height: 190px; width: auto; border-radius: var(--r-sm);
  background: var(--bg-sunk); border: 1px solid var(--line-soft); padding: 8px;
  flex: none;
}
.section h3::before {
  content: ''; display: inline-block; width: 3px; height: 11px; margin-right: 8px;
  border-radius: 2px; background: var(--brand); vertical-align: -1px;
}
.section h3 {
  font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 10px;
}
.prose { font-size: 14px; line-height: 1.6; color: var(--ink-2); }
.prose p { margin: 0 0 8px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-weight: 560; color: var(--ink-3); font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 0 10px 7px 0; border-bottom: 1px solid var(--line-soft);
}
table.data td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line-soft); color: var(--ink-2); }
table.data td:first-child { color: var(--ink); font-weight: 520; }
table.data tr:last-child td { border-bottom: 0; }

.xref-brand { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.xref-brand:last-child { border-bottom: 0; }
.xref-brand .b { min-width: 130px; font-size: 12.5px; font-weight: 560; color: var(--brand-ink); }
.xref-brand .r { display: flex; flex-wrap: wrap; gap: 6px; }
.xref-brand .r span {
  font: 12px/1 var(--mono); padding: 4px 8px; border-radius: 6px;
  background: var(--bg-sunk); color: var(--ink-2);
}
.count { color: var(--ink-3); font-weight: 400; font-size: 11px; margin-left: 6px; }

.footnote { text-align: center; color: var(--ink-3); font-size: 12px; padding: 40px 0 0; }

/* theme toggle */
.theme-btn {
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--ink-2);
  width: 30px; height: 30px; border-radius: 9px; cursor: pointer;
  display: grid; place-items: center; margin-right: 4px;
}
.theme-btn:hover { color: var(--brand-ink); border-color: var(--brand-line);
                   background: var(--brand-soft); }
.theme-btn svg { width: 15px; height: 15px; }
/* The icon shows the ACTION, not the current state: moon while light (click to
   go dark), sun while dark. Same resolution order as the palette and the logo. */
.theme-btn .sun  { display: none; }
.theme-btn .moon { display: block; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .theme-btn .sun  { display: block; }
  html:not([data-theme="light"]) .theme-btn .moon { display: none; }
}
html[data-theme="dark"]  .theme-btn .sun  { display: block; }
html[data-theme="dark"]  .theme-btn .moon { display: none; }
html[data-theme="light"] .theme-btn .sun  { display: none; }
html[data-theme="light"] .theme-btn .moon { display: block; }

/* Theme change wipes out from the toggle. Progressive enhancement: browsers
   without the View Transitions API just switch instantly. */
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 9999; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(root),
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none !important; }
}
.end-note {
  text-align: center; color: var(--ink-3); font-size: 12px;
  padding: 26px 0 2px; letter-spacing: .01em;
}
