:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #23262b;
  --muted: #6b7078;
  --line: #dcd8d0;
  --accent: #1f7a8c;
  --accent-ink: #ffffff;
  --chip: #ebe8e1;
  --stage-a: #eef2f4;
  --stage-b: #cfd8dc;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --panel: #20242a;
    --ink: #e7e9ec;
    --muted: #9aa1ab;
    --line: #333942;
    --accent: #54c2d6;
    --accent-ink: #0b1b20;
    --chip: #2b3038;
    --stage-a: #2c343c;
    --stage-b: #161a1e;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
code { background: var(--chip); padding: 0 .3em; border-radius: 4px; }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.25rem; white-space: nowrap; }
h1 a { color: inherit; text-decoration: none; }
h1 span { color: var(--accent); }
h2 { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: .5rem; }
.muted { color: var(--muted); margin: .15rem 0 .8rem; }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .8rem;
  padding: .6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
#search {
  flex: 1; min-width: 0; max-width: 40rem;
  font: inherit; color: inherit;
  padding: .55rem .8rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg);
}
.gh { margin-left: auto; }
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  font: inherit; color: inherit;
  background: var(--chip);
  border: 1px solid var(--line); border-radius: 8px;
  padding: .45rem .8rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, select:focus-visible, input:focus-visible, .card button:focus-visible, .crumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.small { padding: .25rem .6rem; font-size: .88rem; }
.btn.primary, .btn[aria-pressed="true"].toggle { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* layout: filters | results | viewer */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  align-items: start;
}
.layout.has-viewer { grid-template-columns: 17rem minmax(0, 1fr) minmax(24rem, 36rem); }
#filters {
  position: sticky; top: 3.7rem;
  max-height: calc(100vh - 3.7rem);
  overflow: auto;
  padding: 1rem;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 1.2rem;
}
main { padding: 1rem; min-width: 0; }
.count { display: block; margin: 0 0 .8rem; color: var(--muted); }
.empty { color: var(--muted); }

/* category tree */
#tree ul { list-style: none; margin: 0; padding-left: .9rem; }
#tree > ul { padding-left: 0; }
#tree li { margin: 1px 0; }
#tree .node {
  display: flex; align-items: center; gap: .3rem;
  width: 100%;
  background: none; border: 0; color: inherit; font: inherit; text-align: left;
  padding: .2rem .35rem; border-radius: 6px; cursor: pointer;
}
#tree .node:hover { background: var(--chip); }
#tree .node[aria-current="true"] { background: var(--accent); color: var(--accent-ink); }
#tree .node .n { margin-left: auto; opacity: .65; font-size: .82rem; }
#tree .caret { width: .9rem; display: inline-block; opacity: .6; }

/* chips */
.chip-group { margin-bottom: .9rem; }
.chips, .pills { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  font: inherit; font-size: .85rem; color: inherit;
  background: var(--chip); border: 1px solid var(--line); border-radius: 999px;
  padding: .15rem .6rem; cursor: pointer;
}
.chip .n { opacity: .6; margin-left: .25em; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.zero { opacity: .45; }
.chip.small-chip { font-size: .8rem; }
details.more > summary { cursor: pointer; color: var(--muted); font-size: .85rem; margin-bottom: .4rem; }

/* grid of cards */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .8rem;
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.card button {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; color: inherit; font: inherit; padding: 0; cursor: pointer;
}
.card:hover { border-color: var(--accent); }
.card.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card .img {
  aspect-ratio: 1; width: 100%;
  background: radial-gradient(circle at 50% 35%, var(--stage-a), var(--stage-b));
  display: grid; place-items: center;
}
.card img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card .meta { padding: .5rem .6rem .6rem; }
.card .name { font-weight: 600; font-size: .92rem; line-height: 1.25; }
.card .sub { color: var(--muted); font-size: .8rem; margin-top: .1rem; }
.badges { display: flex; gap: .25rem; margin-top: .3rem; flex-wrap: wrap; }
.badge { font-size: .72rem; padding: 0 .4rem; border-radius: 4px; background: var(--chip); border: 1px solid var(--line); color: var(--muted); }

/* viewer */
.viewer { position: sticky; top: 3.7rem; max-height: calc(100vh - 3.7rem); overflow: auto; border-left: 1px solid var(--line); background: var(--panel); }
.viewer[hidden] { display: none; }
.stage {
  position: relative;
  aspect-ratio: 4 / 3; width: 100%;
  background: radial-gradient(circle at 50% 40%, var(--stage-a), var(--stage-b));
  touch-action: none;
}
#canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.stage-bar { position: absolute; top: .5rem; left: .5rem; right: .5rem; display: flex; gap: .4rem; pointer-events: none; }
.stage-bar .btn { pointer-events: auto; background: color-mix(in srgb, var(--panel) 85%, transparent); }
.spacer { flex: 1; }
.hint, .status {
  position: absolute; left: .5rem; bottom: .5rem; margin: 0;
  font-size: .82rem; padding: .2rem .6rem; border-radius: 6px;
  background: color-mix(in srgb, var(--panel) 85%, transparent); color: var(--muted);
}
.status:empty { display: none; }
.panel { padding: 1rem; }
/* maximised: the viewer covers the page under the header, the stage takes all the room and the details sit in a column beside it (below it on a phone) */
.viewer.max { position: fixed; z-index: 35; top: 3.7rem; left: 0; right: 0; bottom: 0; max-height: none; border: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(20rem, 26rem); overflow: hidden; }
.viewer.max .stage { aspect-ratio: auto; height: 100%; }
.viewer.max .panel { overflow: auto; border-left: 1px solid var(--line); }
.panel h2#v-name { font-size: 1.3rem; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .8rem; }
.row[hidden] { display: none; }
.label { color: var(--muted); font-size: .85rem; min-width: 5.5rem; }
select { font: inherit; color: inherit; background: var(--chip); border: 1px solid var(--line); border-radius: 8px; padding: .3rem .5rem; }
input[type=range] { flex: 1; min-width: 7rem; accent-color: var(--accent); }
.pill {
  font: inherit; font-size: .85rem; color: inherit;
  background: var(--chip); border: 1px solid var(--line); border-radius: 999px;
  padding: .15rem .65rem; cursor: pointer;
}
.pill[aria-pressed="true"], .pill[aria-current="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; margin: 1rem 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.credit { margin: .25rem 0 0; color: var(--muted); font-size: .8rem; }
footer { padding: 1rem; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); }

.only-narrow { display: none; }

/* phones and narrow windows: filters become a drawer, the viewer a full-screen sheet */
@media (max-width: 62rem) {
  .layout, .layout.has-viewer { grid-template-columns: minmax(0, 1fr); }
  .only-narrow { display: inline-block; }
  #filters {
    position: fixed; z-index: 30; top: 3.7rem; left: 0; bottom: 0; width: min(20rem, 88vw);
    max-height: none;
    background: var(--panel);
    transform: translateX(-102%); transition: transform .2s;
    border-right: 1px solid var(--line);
  }
  #filters.open { transform: none; box-shadow: 0 0 30px rgba(0, 0, 0, .35); }
  .viewer {
    position: fixed; z-index: 40; inset: 0; max-height: none; border: 0;
  }
  .stage { aspect-ratio: auto; height: min(62vh, 30rem); }
  .viewer.max { top: 0; display: block; overflow: auto; }
  .viewer.max .stage { height: 80vh; }
  .viewer.max .panel { border-left: 0; }
  .top { gap: .5rem; padding: .5rem .7rem; }
  .gh { display: none; }   /* no room next to the search box; the footer links to GitHub */
  h1 { font-size: 1.05rem; }
  main { padding: .7rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr)); gap: .6rem; }
}
@media (prefers-reduced-motion: reduce) { #filters { transition: none; } }

.paint { display: inline-flex; align-items: center; gap: .4rem; }
.paint i { width: .9rem; height: .9rem; border-radius: 50%; border: 1px solid var(--line, rgba(128, 128, 128, .6)); display: inline-block; }
.paint-part { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; }
.paint-part input[type="color"] { width: 2rem; height: 1.6rem; padding: 0; border: 1px solid var(--line, rgba(128, 128, 128, .6)); border-radius: .3rem; background: none; cursor: pointer; }

/* the breadcrumbs above a model's details: each level is a link back to that category */
#v-type .crumb { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
#v-type .crumb:hover, #v-type .crumb:focus-visible { color: var(--ink); text-decoration-style: solid; }

/* very narrow phones: the longer name leaves no room for the search box next to it, so the box drops to its own row */
@media (max-width: 26rem) {
  .top { flex-wrap: wrap; }
  #search { order: 3; flex: 1 1 100%; max-width: none; }
  #filters { top: 6.5rem; }   /* the header is two rows tall here (about 104 px), so the Filters drawer starts below both */
}
.paint[hidden] { display: none; }
