:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #646b75;
  --line: #dfe3e8;
  --accent: #d6343a;
  --accent-text: #ffffff;
  --neg: #b4232a;
  --neg-bg: #fdecec;
  --chip: #eef1f4;
  --bar: #4a90d9;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1d2026;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --line: #2f343c;
    --accent: #ef5a5f;
    --accent-text: #14161a;
    --neg: #ff8a8f;
    --neg-bg: #3a1e21;
    --chip: #272b32;
    --bar: #6aa8eb;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
main, .top, .foot { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 24px; }
h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
.sub, .muted { color: var(--muted); }
.sub { margin: 4px 0 16px; }
code { font: 0.9em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--chip); padding: 1px 4px; border-radius: 4px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.label { display: block; font-weight: 600; margin-bottom: 8px; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
input, select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.qrow { display: flex; gap: 8px; }
#q { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; padding: 9px 10px; }
.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 7px; padding: 0 16px; font-weight: 600; }
.error { color: var(--neg); margin: 8px 0 0; }

.help { margin-top: 10px; }
.help summary { cursor: pointer; color: var(--muted); }
.help-body { overflow-x: auto; }
.help table { border-collapse: collapse; margin-top: 6px; }
.help td { padding: 4px 8px 4px 0; vertical-align: top; border-top: 1px solid var(--line); }
.help td:first-child { white-space: nowrap; }

.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: var(--chip); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 0.88rem; }

/* builder */
.group { border: 1px solid var(--line); border-left: 3px solid var(--bar); border-radius: 8px; padding: 8px; background: var(--panel); }
.group.negated { border-left-color: var(--neg); background: var(--neg-bg); }
.group .group { margin: 2px 0; }
.group-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.spacer { flex: 1; }
.children { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.joiner { font-size: 0.72rem; font-weight: 700; color: var(--muted); padding-left: 10px; letter-spacing: 0.05em; }
.empty { margin: 2px 0 0 4px; }
.cond { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 4px; border-radius: 7px; }
.cond.negated { background: var(--neg-bg); }
.cond input[type='text'] { flex: 1 1 160px; }
.cond .num { width: 90px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 4px 10px; font-size: 0.85rem; }
.seg button.on { background: var(--bar); color: #fff; }
.not { background: transparent; border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.not.on { background: var(--neg); border-color: var(--neg); color: var(--panel); }
.ghost { background: transparent; border: 1px dashed var(--line); border-radius: 7px; padding: 4px 10px; font-size: 0.85rem; }
.x { background: transparent; border: 0; font-size: 1.2rem; line-height: 1; padding: 2px 8px; color: var(--muted); }

/* results */
.result-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 6px 0 10px; flex-wrap: wrap; }
#count { font-weight: 600; }
.sort { color: var(--muted); display: flex; gap: 6px; align-items: center; }
.results { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.card { display: flex; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-width: 0; }
.sprite { flex: 0 0 96px; height: 96px; display: grid; place-items: center; background: var(--bg); border-radius: 8px; }
.sprite img { image-rendering: pixelated; }
.info { min-width: 0; flex: 1; }
.title { display: flex; align-items: baseline; gap: 6px; }
.title h2 { font-size: 1.02rem; margin: 0; }
.dex { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.genus { font-size: 0.82rem; }
.types, .abilities { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.type { background: var(--c); color: #fff; border-radius: 5px; padding: 0 7px; font-size: 0.78rem; font-weight: 600; text-shadow: 0 1px 1px rgb(0 0 0 / 0.35); }
.ability { background: var(--chip); border-radius: 5px; padding: 0 7px; font-size: 0.78rem; }
.ability.hidden { font-style: italic; }
.desc { margin: 6px 0; font-size: 0.86rem; }
.stats { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; font-size: 0.7rem; }
.stat { display: flex; flex-direction: column; align-items: center; position: relative; padding-bottom: 4px; }
.stat span { color: var(--muted); }
.stat i { position: absolute; bottom: 0; left: 10%; height: 3px; width: calc(var(--w) * 0.8); background: var(--bar); border-radius: 2px; }
.more { display: block; margin: 16px auto; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 8px 18px; }

.foot { color: var(--muted); font-size: 0.8rem; padding-top: 24px; padding-bottom: 32px; }
.foot a { color: inherit; }

@media (max-width: 520px) {
  .results { grid-template-columns: 1fr; }
  .sprite { flex-basis: 72px; height: 72px; }
  .sprite img { width: 72px; height: 72px; }
  .help td:first-child { white-space: normal; }
}
