:root {
  --bg: #0f1115;
  --panel: #171a21;
  --card: #1d212b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a5;
  --accent: #4da3ff;
  --accent-dim: #25304a;

  /* Silhouette plates carry a baked-in background per ticket 10 — these are
     each mod's actual plate margin colour, sampled from the PNGs, so a tile
     blends into the image instead of showing a hard dark seam around it.
     Set per-mod on <body data-mod>. */
  --sil-bg: #7c7570;
}
body[data-mod="oae152"] { --sil-bg: #9d9c88; }

* { box-sizing: border-box; }

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

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.subtitle {
  color: var(--muted);
  font-weight: 400;
  margin-left: 6px;
}

.toggles {
  display: flex;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
}

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
}

.segmented button {
  background: var(--panel);
  color: var(--muted);
  border: none;
  border-right: 1px solid var(--border);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.segmented button:last-child { border-right: none; }
.segmented button:hover { color: var(--text); }

.segmented button[aria-pressed="true"] {
  background: var(--accent-dim);
  color: #cfe4ff;
}

/* ---------- Filter pills + popovers ---------- */

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

/* This is #controls. It exists only to give renderControls() a container it can
   safely empty, so display:contents keeps its pills as flex items of .controls
   itself — laid out alongside the search box and result count, which outlive it
   and therefore sit outside it. */
.facet-row { display: contents; }

.facet { position: relative; }

/* ---------- Search ---------- */

.search { position: relative; display: flex; }

.search-input {
  width: 220px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 30px 6px 14px;
  font-size: 13px;
  font-family: inherit;
}

.search-input::placeholder { color: var(--muted); }
.search-input:hover { border-color: var(--accent); }

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel);
}

/* Ours is the only clear affordance — suppress the one Chrome adds. */
.search-input::-webkit-search-cancel-button { display: none; }

.search-clear {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 28px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

.search-clear:hover { color: var(--text); }

.facet-pill {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.facet-pill:hover { border-color: var(--accent); }
.facet-pill[aria-expanded="true"] { background: var(--accent-dim); }
.facet-pill .caret { color: var(--muted); margin-left: 4px; }

.popover {
  position: absolute;
  top: 38px;
  left: 0;
  z-index: 20;
  width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}

.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.checklist li { border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: none; }

.checklist label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

.checklist label:hover { background: #202531; }
.checklist input { accent-color: var(--accent); flex-shrink: 0; }

.count-pill {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  background: #12141a;
  padding: 1px 6px;
  border-radius: 10px;
}

.count-pill.is-zero { opacity: .4; }

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 4px;
}

.link-button:hover { text-decoration: underline; }

.result-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Results grid ---------- */

.results-wrap { padding: 16px; }

.status {
  color: var(--muted);
  font-size: 13px;
  padding: 24px 0;
  text-align: center;
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.unit-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: left;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

.unit-card:hover { border-color: var(--accent); }
.unit-card.is-hidden { display: none; }

/* The card face is the silhouette recognition plate — the thing a player is
   actually matching against. The _shp map icon is a narrow top-down sliver and
   reads as nothing at this size, so it lives in the detail panel instead. */
.unit-card .thumb {
  width: 100%;
  height: 132px;
  object-fit: contain;
  background: var(--sil-bg);
  border-radius: 4px;
}

.unit-card .name { font-weight: 600; font-size: 13px; }

.unit-card .meta {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: auto;
}

.badge {
  display: inline-block;
  font-size: 10px;
  background: var(--accent-dim);
  color: #8fbfff;
  padding: 1px 6px;
  border-radius: 4px;
  margin: 0 4px 3px 0;
}

/* ---------- Detail panel ---------- */

.detail-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, .65);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px;
  overflow-y: auto;
}

.detail-backdrop[hidden] { display: none; }

.detail {
  position: relative;
  width: min(760px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.detail-close:hover { color: var(--text); }

.detail h2 { margin: 0 0 2px; font-size: 20px; }

.detail .classname {
  color: var(--muted);
  font-size: 12px;
  font-family: ui-monospace, Consolas, monospace;
  margin-bottom: 12px;
}

.detail .sil {
  display: block;
  width: 100%;
  background: var(--sil-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 12px;
}

/* The in-game map icon: a top-down sprite, tall and narrow. Shown at its own
   aspect on a small tile rather than stretched across the panel. */
.detail .shp {
  display: block;
  max-width: 100%;
  max-height: 120px;
  width: auto;
  object-fit: contain;
  background: #12141a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
}

.detail-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.detail h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 0 0 8px;
}

.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.spec-table th {
  text-align: left;
  font-weight: 400;
  color: var(--muted);
  padding: 4px 12px 4px 0;
  white-space: nowrap;
  vertical-align: top;
}

.spec-table td { padding: 4px 0; }

.text-lines { margin: 0; font-size: 13px; line-height: 1.7; }

.notice {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  margin: 0 0 8px;
}

.nation-list {
  font-size: 13px;
  line-height: 1.7;
  margin: 0;
}
