:root {
  color-scheme: light;
  --bg: #f4f2ec;
  --surface: #fffefa;
  --surface-raised: #f8f6f0;
  --surface-soft: #eeebe2;
  --border: #d6d1c6;
  --border-strong: #aaa397;
  --text: #20211f;
  --muted: #666a65;
  --faint: #8b8e89;
  --gold: #9a7627;
  --gold-soft: #72571e;
  --blue: #315d83;
  --green: #24704b;
  --red: #a3443d;
  --shadow: 0 12px 32px rgba(48, 43, 34, .07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

::selection { background: #e8d9ad; color: var(--text); }

a { color: inherit; }

button, input, select { font: inherit; }

button, select, input { outline: none; }

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

input:focus-visible, select:focus-visible { outline: none; }

.topbar {
  align-items: center;
  background: rgba(255, 254, 250, .96);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  min-height: 68px;
  padding: 0 clamp(18px, 4vw, 64px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  align-items: center;
  display: inline-flex;
  gap: 10px;
  text-decoration: none;
}

.brand-name {
  font-family: fantasy;
  font-size: 23px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-name span { color: var(--gold); font-size: .78em; }

.brand-section {
  border-left: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .12em;
  padding-left: 12px;
  text-transform: uppercase;
}

.live-state {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  gap: 8px;
  white-space: nowrap;
}

.live-dot {
  background: var(--green);
  border-radius: 999px;
  box-shadow: 0 0 0 4px rgba(90, 211, 141, .12);
  display: inline-block;
  height: 7px;
  width: 7px;
}

.live-state[data-status="stale"] { color: var(--gold-soft); }
.live-state[data-status="stale"] .live-dot {
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(217, 181, 91, .12);
}
.live-state[data-status="unavailable"] { color: var(--red); }
.live-state[data-status="unavailable"] .live-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(237, 139, 129, .12);
}

.search-band {
  background: #ebe8df;
  border-bottom: 1px solid var(--border);
  padding: 36px clamp(18px, 4vw, 64px) 24px;
}

.search-form {
  display: flex;
  gap: 10px;
  margin: 0;
  max-width: none;
}

.search-box {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  box-shadow: none;
  display: flex;
  flex: 1;
  gap: 10px;
  min-height: 48px;
  padding: 0 15px;
}

.search-box:focus-within {
  border-color: var(--gold);
  box-shadow: none;
}

.search-box svg, .search-button svg {
  fill: none;
  height: 19px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 19px;
}

.search-box svg { color: var(--faint); }

.search-box input {
  background: transparent;
  border: 0;
  color: var(--text);
  min-width: 0;
  width: 100%;
}

.search-box input::placeholder { color: var(--faint); }

.search-button, .page-button {
  align-items: center;
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 5px;
  color: #fffefa;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  gap: 8px;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.search-button:hover, .page-button:not(:disabled):hover {
  background: var(--gold-soft);
  border-color: var(--gold-soft);
  transform: translateY(-1px);
}

.index-summary {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 8px;
  margin: 15px 0 0;
  max-width: none;
}

.index-summary strong { color: var(--text); font-size: 15px; }

.summary-divider {
  background: var(--border);
  height: 16px;
  margin: 0 4px;
  width: 1px;
}

#updated-stat { color: var(--faint); margin-left: auto; }

.workspace {
  display: grid;
  gap: 24px;
  grid-template-columns: 230px minmax(0, 1fr);
  margin: 0;
  max-width: none;
  padding: 28px clamp(18px, 4vw, 64px) 60px;
}

.filters {
  align-self: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  box-shadow: none;
  padding: 17px;
  position: sticky;
  top: 94px;
}

.filter-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
}

.filter-heading h2 { font-size: 15px; margin: 0; }

.icon-button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.icon-button:hover { border-color: var(--gold); color: var(--gold-soft); }

.icon-button svg, .page-button svg, .action-cell svg {
  fill: none;
  height: 16px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  width: 16px;
}

.field { display: block; margin-bottom: 14px; }

.field > span, .sort-control > span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.field-row { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }

.field-row .field { min-width: 0; }

select, .field input {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  min-height: 38px;
  padding: 0 9px;
  width: 100%;
}

select:focus, .field input:focus { border-color: var(--gold); }

.check-field {
  align-items: center;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  font-size: 13px;
  gap: 9px;
  margin-top: 4px;
}

.check-field input { accent-color: var(--gold); height: 16px; width: 16px; }
.check-field + .check-field { margin-top: 10px; }

.primary-filter {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-weight: 650;
  margin: -4px 0 16px;
  padding: 10px;
}

.primary-filter:has(input:checked) {
  border-color: var(--gold);
}

.results-panel { min-width: 0; }

.results-toolbar {
  align-items: end;
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  min-height: 42px;
}

.results-toolbar strong { font-size: 17px; }

.results-context {
  align-items: center;
  display: flex;
  gap: 14px;
}

.view-switch {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: inline-flex;
  padding: 3px;
}

.view-switch button {
  background: transparent;
  border: 0;
  border-radius: 2px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  min-height: 30px;
  padding: 0 10px;
}

.view-switch button[aria-pressed="true"] {
  background: var(--surface-soft);
  color: var(--text);
}

#query-speed { color: var(--faint); font-size: 12px; margin-left: 8px; }

.sort-control { min-width: 175px; }
.sort-control select { min-height: 34px; }

.result-columns, .result-row, .coin-type-row {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(220px, 2.6fr) minmax(0, .95fr) minmax(0, .55fr) minmax(0, .9fr) minmax(0, .85fr) 154px;
}

.result-columns {
  color: var(--faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  padding: 0 16px 8px;
  text-transform: uppercase;
}

.result-columns > span:first-child { padding-left: 54px; }

.results { border-top: 1px solid var(--border); }

.result-row {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 88px;
  padding: 14px 16px;
  transition: background .15s ease;
}

.result-row:hover { background: var(--surface-raised); }

.coin-type-result {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.coin-type-row {
  align-items: center;
  min-height: 88px;
  padding: 14px 16px;
  transition: background .15s ease;
}

.coin-type-row:hover, .coin-type-result.expanded .coin-type-row { background: var(--surface-raised); }
.type-offers { display: flex; flex-direction: column; color: var(--text); font-weight: 650; }
.type-price { color: var(--text); }
.type-toggle { height: 34px; width: 34px; }
.type-toggle svg { fill: none; height: 17px; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; width: 17px; }
.coin-type-result.expanded .type-toggle svg { transform: rotate(180deg); }

.type-expansion {
  background: #f8f6f0;
  border-top: 1px solid var(--border);
  padding: 14px 16px 18px 70px;
}

.bucket-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.bucket-item {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 5px 8px;
}

.bucket-item:hover { border-color: var(--gold); color: var(--text); }
.bucket-item.selected, .bucket-item[aria-pressed="true"] {
  background: #eee5ce;
  border-color: var(--gold);
  color: var(--gold-soft);
}
.bucket-item:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.bucket-selection-status { color: var(--muted); font-size: 11px; margin: -3px 0 12px; }

.offer-list { border-top: 1px solid var(--border); }
.offer-row { background: transparent; min-height: 76px; padding-left: 0; padding-right: 0; }
.offer-row:last-child { border-bottom: 0; }
.offer-row .coin-mark { display: none; }
.offer-row .coin-cell { padding-left: 0; }

.coin-cell { align-items: center; display: flex; gap: 12px; min-width: 0; }

.coin-mark {
  align-items: center;
  background: #f0ede5;
  border: 1px solid #b9b3a8;
  border-radius: 50%;
  display: flex;
  flex: 0 0 auto;
  height: 42px;
  justify-content: center;
  position: relative;
  width: 42px;
}

.coin-mark::before, .coin-mark::after {
  border: 1px solid #c9c3b8;
  border-radius: 50%;
  content: "";
  position: absolute;
}

.coin-mark::before { height: 31px; width: 31px; }
.coin-mark::after { height: 23px; width: 23px; }
.coin-mark span { background: var(--gold); border-radius: 50%; height: 4px; width: 4px; }

.coin-mark.has-images {
  background: transparent;
  border-color: transparent;
}

.coin-mark.has-images::before, .coin-mark.has-images::after { content: none; }
.coin-mark.has-images span { display: none; }
.coin-mark.has-images:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.coin-image {
  height: 100%;
  inset: 0;
  object-fit: contain;
  padding: 2px;
  pointer-events: none;
  position: absolute;
  transition: opacity .16s ease;
  width: 100%;
}

.coin-image-main { opacity: 1; }
.coin-image-other { opacity: 0; }
.coin-mark.alternate-ready:hover .coin-image-main,
.coin-mark.alternate-ready:focus .coin-image-main,
.coin-mark.alternate-ready.show-other .coin-image-main { opacity: 0; }
.coin-mark.alternate-ready:hover .coin-image-other,
.coin-mark.alternate-ready:focus .coin-image-other,
.coin-mark.alternate-ready.show-other .coin-image-other { opacity: 1; }

.coin-copy { min-width: 0; }
.coin-copy h3 { font-size: 14px; line-height: 1.3; margin: 0; }
.coin-copy h3 a { text-decoration: none; }
.coin-copy h3 a:hover { color: var(--gold-soft); }
.canonical { color: var(--muted); font-size: 12px; margin: 4px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }

.badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  padding: 4px 7px;
}

.badge.authority { border-color: #aabfd0; color: var(--blue); }
.badge.mapped { border-color: #9fc3ae; color: var(--green); }
.badge.review { border-color: #d3aaa6; color: var(--red); }
.badge.auction { border-color: #c8af6a; color: var(--gold-soft); }
.badge.buy-now { border-color: #bbb7ae; color: var(--muted); }
.badge.sold { border-color: #b68b86; color: var(--red); }

.data-cell { color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grade-cell { color: var(--text); font-size: 16px; font-weight: 700; }
.type-grades { display: flex; flex-direction: column; overflow: visible; white-space: normal; }
.grade-meta { color: var(--muted); font-size: 10px; font-weight: 550; line-height: 1.35; }
.class-cell { color: var(--gold-soft); font-weight: 650; }
.price-cell { color: var(--text); display: flex; flex-direction: column; font-variant-numeric: tabular-nums; font-weight: 650; }
.price-meta { color: var(--muted); font-size: 10px; font-weight: 500; line-height: 1.35; }
.action-cell { align-items: center; display: flex; gap: 7px; justify-content: end; min-width: 0; }

.authority-link, .listing-link {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  display: inline-flex;
  gap: 4px;
  min-height: 32px;
  padding: 0 8px;
  text-decoration: none;
  white-space: nowrap;
}

.authority-link:hover, .listing-link:hover { border-color: var(--gold); color: var(--gold-soft); }
.listing-link { padding: 0 7px; }

.pagination { align-items: center; display: flex; gap: 15px; justify-content: center; padding: 24px 0 0; }

.page-button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  min-height: 36px;
  padding: 0 11px;
}

.page-button:disabled { cursor: not-allowed; opacity: .42; transform: none; }
.pagination > span { color: var(--muted); font-size: 12px; min-width: 66px; text-align: center; }

.loading, .empty, .error {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  padding: 45px 20px;
  text-align: center;
}

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

@media (max-width: 1100px) {
  .result-columns, .result-row, .coin-type-row { grid-template-columns: minmax(220px, 2fr) minmax(0, .8fr) minmax(0, .55fr) minmax(0, .8fr) minmax(0, .85fr) 154px; }
}

@media (max-width: 820px) {
  .workspace { grid-template-columns: 1fr; }
  .filters { position: static; }
  .filters .field-row { grid-template-columns: repeat(4, 1fr); }
  .filters .field-row .field:nth-child(1), .filters .field-row .field:nth-child(2) { grid-column: span 2; }
  .result-columns { display: none; }
  .result-row, .coin-type-row { grid-template-columns: minmax(0, 1fr) auto; }
  .data-cell { align-items: center; display: flex; gap: 7px; }
  .data-cell::before { color: var(--faint); content: attr(data-label); font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
  .country-cell, .grade-cell, .class-cell, .price-cell { grid-column: 2; justify-content: end; }
  .country-cell { grid-row: 1; }
  .grade-cell { grid-row: 2; }
  .class-cell { grid-row: 3; }
  .price-cell { grid-row: 4; }
  .action-cell { grid-column: 2; grid-row: 5; }
  .coin-cell { grid-column: 1; grid-row: 1 / span 5; }
  .type-expansion { padding-left: 16px; }
}

@media (max-width: 560px) {
  .topbar { min-height: 62px; padding: 0 16px; }
  .brand-section { display: none; }
  .search-band { padding: 22px 16px 18px; }
  .search-form { display: block; }
  .search-button { margin-top: 9px; width: 100%; }
  .index-summary { flex-wrap: wrap; font-size: 12px; }
  #updated-stat { flex-basis: 100%; margin-left: 0; }
  .workspace { padding: 20px 16px 45px; }
  .filters .field-row { display: grid; grid-template-columns: 1fr 1fr; }
  .filters .field-row .field:nth-child(1), .filters .field-row .field:nth-child(2) { grid-column: auto; }
  .results-toolbar { align-items: stretch; display: block; }
  .results-context { align-items: flex-start; display: block; }
  .view-switch { margin-bottom: 10px; width: 100%; }
  .view-switch button { flex: 1; }
  .sort-control { display: block; margin-top: 10px; }
  .sort-control select { width: 100%; }
  .result-row { gap: 7px; padding: 14px 11px; }
  .coin-type-row { gap: 7px; padding: 14px 11px; }
  .coin-mark { height: 34px; width: 34px; }
  .coin-mark::before { height: 25px; width: 25px; }
  .coin-mark::after { height: 18px; width: 18px; }
  .coin-copy h3 { font-size: 13px; }
  .canonical { max-width: 42vw; }
  .authority-link span { display: none; }
}
