:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #5f6368;
  --border: #dedcd7;
  --accent: #c8102e;        /* GameStop red */
  --accent-text: #ffffff;
  --tag-bg: #ecebe7;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --surface: #1e1e21;
    --text: #ececee;
    --muted: #a0a0a8;
    --border: #333338;
    --accent: #e0334f;
    --tag-bg: #2b2b30;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

.page-head {
  padding: 32px 0 8px;
}
.page-head h1 {
  margin: 0 0 4px;
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  line-height: 1.2;
}
.lede {
  margin: 0;
  color: var(--muted);
}

/* Two tiers: the filters (what's shown), then a quieter results bar with the
   count and the presentation controls (how it's shown). */
.toolbar {
  margin: 20px 0;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.filter {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.filter button {
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.filter button + button { border-left: 1px solid var(--border); }
.filter button:hover { background: var(--tag-bg); }
.filter button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}
.filter button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -4px;
}

.results-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.results-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 0;
}
/* A thin divider between Sort by and View. */
.results-controls .control + .control {
  margin-left: 16px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}
/* Phones: everything stacks left-aligned, count last, and the divider goes. */
@media (max-width: 520px) {
  .results-bar {
    flex-direction: column;
    align-items: flex-start;
  }
  .results-bar .count {
    order: 1;
  }
  .results-controls {
    flex-direction: column;
    align-items: flex-start;
  }
  .results-controls .control + .control {
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }
}

/* View and sort use neutral pills, not the red segmented filters, so they read
   as "presentation" rather than "narrowing". */
.control {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.control-label {
  color: var(--muted);
  font-size: 0.9rem;
}
.pills {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}
.pills button {
  font: inherit;
  font-size: 0.85rem;
  padding: 4px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.pills button:hover {
  color: var(--text);
  border-color: var(--border);
}
.pills button[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
  font-weight: 600;
}
.select {
  font: inherit;
  font-size: 0.85rem;
  padding: 4px 8px 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.select:hover {
  border-color: var(--muted);
}
.select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.pills button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.count {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.grid {
  list-style: none;
  margin: 0 0 48px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-link {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: inherit;
  text-decoration: none;
  border-radius: inherit;
}
.card:hover {
  border-color: var(--muted);
}
.card-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.card-img {
  display: block;
  padding: 12px 12px 0;
}
.card-img img {
  display: block;
  width: 100%;
  aspect-ratio: 63 / 88;   /* standard TCG card proportions */
  object-fit: contain;
  border-radius: 8px;
}

.card-body {
  padding: 12px 14px 16px;
}
.card-body h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.3;
}
.meta {
  margin: 2px 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-block;
  margin: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--tag-bg);
  font-size: 0.8rem;
}
.tag-stamp {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.tag-other {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
}

/* .grid and .list-wrap set display, which would otherwise beat [hidden]. */
[hidden] { display: none !important; }

/* ---- List view ---- */

.list-wrap {
  margin: 0 0 48px;
  overflow-x: auto;   /* in-between widths: scroll the table, not the page */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.list {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.list th,
.list td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.list thead th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  vertical-align: bottom;
}
.list thead th[colspan] {
  text-align: center;
  padding-bottom: 4px;
}
.list tbody tr:last-child > * {
  border-bottom: 0;
}
.list tbody tr {
  cursor: pointer;
}
.list tbody tr:hover {
  background: var(--tag-bg);
}
.list tbody th {
  font-weight: 600;
}
.list tbody th a {
  color: inherit;
  text-decoration: none;
}
.list tbody th a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.list .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.list .group-start {
  border-left: 1px solid var(--border);
}
.list-number,
.list-year {
  white-space: nowrap;
}
.list-none {
  color: var(--muted);
}
.list-meta {
  display: none;   /* narrow screens only, replacing the Number/Set/Year columns */
}

/* Narrow screens: each row becomes a block, name and meta line on top, then
   the five values in a labelled grid. */
@media (max-width: 700px) {
  .list-wrap {
    overflow: visible;
    background: none;
    border: 0;
  }
  .list,
  .list tbody {
    display: block;
  }
  .list thead,
  .list-number,
  .list-set,
  .list-year {
    display: none;
  }
  .list tbody tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 12px;
    margin-bottom: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
  }
  .list tbody th,
  .list td {
    padding: 0;
    border: 0;
  }
  .list tbody th {
    grid-column: 1 / -1;
  }
  .list-meta {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 400;
  }
  .list .num {
    text-align: left;
    font-weight: 600;
  }
  .list .group-start {
    border-left: 0;
  }
  .list td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 400;
  }
}

/* ---- Card detail dialog ---- */

body:has(.detail[open]) {
  overflow: hidden;   /* keep the page behind from scrolling */
}

.detail {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}
/* A card's own page (cards/<slug>/, from BuildPages.py) reuses the dialog's
   layout as a plain box on the page. */
.detail-page {
  display: block;
  max-height: none;
  margin: 8px auto 48px;
}
.detail-page .detail-body h1 {
  margin-right: 0;   /* no close button here */
}
.card-page-head .wrap {
  max-width: calc(760px + 32px);   /* line up with the box below */
}
.back-link {
  color: var(--muted);
  text-decoration: none;
}
.back-link:hover {
  color: var(--text);
  text-decoration: underline;
}

.detail::backdrop {
  background: rgb(0 0 0 / 0.6);
}

.detail-inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 24px;
  padding: 24px;
}

.detail-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.detail-close:hover { background: var(--tag-bg); color: var(--text); }
.detail-close:focus-visible { outline: 2px solid var(--accent); }

.detail-img {
  display: block;
}
.detail-img img {
  display: block;
  width: 100%;
  aspect-ratio: 63 / 88;
  object-fit: contain;
  border-radius: 10px;
}

.detail-body > h1,
.detail-body > h2 {
  margin: 0 40px 8px 0;   /* clear the close button */
  font-size: 1.4rem;
  line-height: 1.25;
}

.detail-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 16px 0;
  font-size: 0.9rem;
}
.detail-facts dt {
  color: var(--muted);
}
.detail-facts dd {
  margin: 0;
}
.detail-bullets {
  margin: 0;
  padding-left: 1.1em;
}
.detail-bullets li + li {
  margin-top: 2px;
}

.detail-price {
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.detail-pop {
  margin-top: 16px;
}
.detail-pop .detail-price-row {
  margin-bottom: 0;   /* no caption line under the counts */
}
.detail-section-title {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
}
.detail-price p {
  margin: 0;
}
.detail-price-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 32px;
  margin-bottom: 8px;
}
.detail-price-label {
  color: var(--muted);
  font-size: 0.85rem;
}
.detail-price-value {
  font-size: 1.6rem;
  font-weight: 700;
}
.detail-price-none {
  color: var(--muted);
  font-weight: 400;
}
.detail-price-meta {
  color: var(--muted);
  font-size: 0.85rem;
}
.detail-price a {
  color: var(--accent);
}
.detail-buy {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin-top: 12px;
}
.detail-price .buy-button {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.detail-price .buy-button:hover {
  filter: brightness(1.1);
}
.detail-price .buy-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.detail-buy .detail-price-meta {
  flex: 1 1 200px;
  font-size: 0.8rem;
}

@media (max-width: 600px) {
  .detail-inner {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
  }
  .detail-img {
    max-width: 260px;
    margin: 0 auto;
  }
}

.empty {
  margin: 0 0 48px;
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.error {
  color: var(--accent);
}
