:root {
  --paper: #d9cab3;
  --raised: #e5dac7;
  --ink: #5e0b15;
  --muted: #90323d;
  --line: #8c7a6b;
  --slot: #cbbaa4;
  --accent: #bc8034;
  --shadow: rgba(94, 11, 21, 0.18);
}

::selection {
  background: var(--accent);
  color: var(--ink);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, sans-serif;
  line-height: 1.45;
}

a {
  color: var(--muted);
  text-decoration-color: var(--accent);
  text-underline-offset: 2px;
}

a:hover {
  color: var(--ink);
}

.masthead-inner,
.controls,
.grid {
  width: min(1120px, calc(100% - 2rem));
  margin-inline: auto;
}

.masthead {
  background: var(--ink);
  padding: 2.25rem 0 1.75rem;
}

.masthead h1 {
  margin: 0 0 0.4rem;
  color: var(--paper);
  font-size: 2rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.masthead h1 img {
  display: block;
  /* The single-line lockup is a mark, not a headline: 30rem wide leaves the
     cover short and lets the specimens own the first screen. */
  width: min(100%, 30rem);
  height: auto;
}

.masthead p {
  margin: 0;
  max-width: 40rem;
  color: var(--paper);
  opacity: 0.85;
}

.controls {
  display: grid;
  gap: 0.9rem;
  padding: 1.5rem 0 1.25rem;
}

/* Search and its result status share one bar; the count's right edge lines up
   with the family counts that run down the chapters below. */
.search-row {
  display: grid;
  grid-template-columns: minmax(0, 34rem) minmax(0, 1fr);
  align-items: center;
  gap: 0.35rem 1.25rem;
}

.search input {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
}

.search input::placeholder {
  color: var(--muted);
  opacity: 0.9;
}

.search input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.result-count {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  justify-self: end;
  text-align: right;
}

#chips button,
.card,
.panel-close {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#chips button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.75rem;
}

#chips button:hover {
  background: var(--raised);
  border-color: var(--ink);
}

#chips button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.9rem;
  padding-bottom: 3rem;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
  margin: 0;
  padding: 0.35rem;
  text-align: left;
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
}

.card:hover {
  border-color: var(--accent);
}

.card[aria-current="true"] {
  border-color: var(--ink);
  background: var(--raised);
}

/* Family chapters run edge to edge above their cards, so the grid reads as a
   catalogue with landmarks instead of one undifferentiated wall. */
.chapter {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.25rem 0 0;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
  font-size: 1.05rem;
  font-weight: 650;
  scroll-margin-top: 1rem;
}

.grid > .chapter:first-child {
  margin-top: 0;
}

.chapter-count {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

.card-name {
  font-size: 0.92rem;
  font-weight: 600;
}

.image-slot {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  width: 100%;
  overflow: hidden;
  background: var(--slot);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  text-align: center;
  padding: 0.75rem;
  font-size: 0.85rem;
}

.image-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Card thumbnails show only the top-left quarter of the full image, scaled to
   fill the slot. The panel preview and style pages keep the whole image. */
.card .image-slot {
  position: relative;
}

.card .image-slot img {
  /* Nudge the crop window down and right from the top-left corner.
     15% of the slot is 7.5% of the image. */
  --thumb-offset: 15%;
  position: absolute;
  top: calc(-1 * var(--thumb-offset));
  left: calc(-1 * var(--thumb-offset));
  width: 200%;
  height: 200%;
  max-width: none;
  object-position: left top;
}

.panel-close {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  margin-bottom: 0.8rem;
}

.panel-close:hover {
  background: var(--raised);
  border-color: var(--ink);
}

#panel-body .era,
#panel-body .family {
  margin: 0.15rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

#panel-body h2 {
  margin: 0.6rem 0 0.2rem;
  font-size: 1.6rem;
  font-weight: 650;
}

/* Opening the panel focuses this heading to orient the reader. It is not a
   control, so the browser's input ring would read as a form field. */
#panel-body h2:focus {
  outline: none;
}

#panel-body .desc {
  max-width: 42rem;
}

.traits {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.8rem 0;
  padding: 0;
  list-style: none;
}

.traits li {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.78rem;
}

.traits--interactive li {
  border: 0;
  padding: 0;
}

.traits--interactive button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.78rem;
}

.traits--interactive button:hover {
  background: var(--raised);
  border-color: var(--ink);
}

.traits--interactive button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.traits--interactive button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.swatch-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin: 0.8rem 0;
  padding: 0;
  list-style: none;
}

.swatch-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.swatch {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 4px;
  border: 1px solid var(--shadow);
}

.swatch-hex {
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
}

/* The zero-result plate: a mounted sheet that names the miss and offers the
   two ways out of it. */
.empty {
  grid-column: 1 / -1;
  max-width: 42rem;
  padding: 1.4rem 1.25rem;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.empty-title {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  font-weight: 650;
}

.empty-copy {
  margin: 0 0 1rem;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.empty-action {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.75rem;
}

.empty-action:hover {
  background: var(--paper);
  border-color: var(--ink);
}

.empty-action:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.empty-suggest {
  margin: 1rem 0 0;
  font-size: 0.92rem;
}

.used-for {
  font-size: 0.92rem;
}

.panel-image-link {
  display: block;
}

.panel-link {
  display: inline-block;
  margin-top: 1rem;
  font-size: 0.9rem;
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (min-width: 840px) {
  #panel:not([hidden]) {
    position: fixed;
    z-index: 2;
    top: 0;
    right: 0;
    width: min(26rem, 38vw);
    height: 100%;
    overflow: auto;
    background: var(--paper);
    border-left: 1px solid var(--line);
  }

  .panel-backdrop {
    display: none;
  }

  .panel-sheet {
    padding: 1.1rem 1.25rem 2rem;
  }

  body:has(#panel:not([hidden])) {
    padding-right: min(26rem, 38vw);
  }
}

/* Tablets keep the compact cover padding; the wordmark keeps filling the
   measure, so there is no step at the 1120px breakpoint. */
@media (min-width: 840px) and (max-width: 1119px) {
  .masthead {
    padding: 1.5rem 0 1.25rem;
  }

  .masthead p {
    font-size: 0.95rem;
  }
}

@media (max-width: 839px) {
  /* Phones meet the catalogue sooner: a capped cover, one snapping filter rail,
     and a locked page behind the sheet. */
  .masthead {
    padding: 1.15rem 0 1rem;
  }

  .masthead p {
    font-size: 0.92rem;
  }

  .controls {
    padding: 1rem 0 1rem;
  }

  .search-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .result-count {
    justify-self: start;
    text-align: left;
  }

  #chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    padding-bottom: 0.35rem;
  }

  #chips button {
    flex: 0 0 auto;
    scroll-snap-align: start;
    min-height: 2.5rem;
    padding-inline: 0.9rem;
  }

  .empty-action {
    min-height: 2.5rem;
    padding-inline: 0.9rem;
  }

  body.panel-locked {
    overflow: hidden;
  }

  #panel:not([hidden]) {
    position: fixed;
    z-index: 2;
    inset: 0;
  }

  .panel-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(94, 11, 21, 0.45);
  }

  .panel-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 72vh;
    overflow: auto;
    background: var(--paper);
    border-top: 1px solid var(--line);
    padding: 0.9rem 1rem 1.4rem;
  }
}
