:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e2dc;
  --accent: #1f5fbf;
  --accent-soft: #e6eefb;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --radius: 10px;
  --skeleton: #ecece6;
  --skeleton-shine: #f8f8f4;
  --cell: 7.5rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --surface: #1f1f1d;
    --text: #ecece8;
    --muted: #a3a39c;
    --line: #34342f;
    --accent: #7fb0ff;
    --accent-soft: #1f2d45;
    --warn: #f0b45a;
    --warn-soft: #3a2c15;
    --skeleton: #2a2a27;
    --skeleton-shine: #353531;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Header: title and search stay pinned; filters fold away on phones */

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0.75rem 1rem 0.5rem;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}

.bar {
  display: flex;
  gap: 0.75rem 1.25rem;
  align-items: center;
}

.bar h1 {
  margin: 0;
  font-size: 1.25rem;
  white-space: nowrap;
}

.filters summary {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.5rem 0 0.25rem;
  font-size: 0.85rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.filters summary::-webkit-details-marker {
  display: none;
}

.filters-label {
  font-weight: 600;
}

.filters-label::after {
  content: " ▾";
  color: var(--muted);
}

.filters[open] .filters-label::after {
  content: " ▴";
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  padding-bottom: 0.25rem;
}

input[type="search"],
select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
}

.search {
  flex: 1;
  display: flex;
  max-width: 36rem;
}

.search input {
  width: 100%;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  border: 0;
  margin: 0;
  padding: 0;
}

.chips label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}

.chips input {
  margin: 0;
}

/* Regions of a country (US states): one chip that opens onto theirs. */
.chips .regions {
  flex-basis: 100%;
}

.chips .regions summary {
  display: inline-block;
  padding: 0.3rem 0.65rem;
  border: 1px dashed var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.chips .regions[open] summary {
  margin-bottom: 0.35rem;
}

.chips label:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Type buttons: one per category, with how many signs the other filters leave in it. */
.types {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-basis: 100%;
}

button.type,
button.bulk {
  font: inherit;
  font-size: 0.9rem;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

button.type .count {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

button.type:hover,
button.bulk:hover {
  border-color: var(--accent);
}

button.type[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
  font-weight: 600;
}

button.type[aria-pressed="true"] .count {
  color: inherit;
  opacity: 0.85;
}

/* Nothing left of this type under the other filters: still clickable, but quiet. */
button.type.empty:not([aria-pressed="true"]) {
  opacity: 0.5;
}

/* "All" / "None" next to the country chips, "Select all US states" / "Clear" in the regions. */
.bulk-buttons {
  display: inline-flex;
  gap: 0.35rem;
}

button.bulk {
  font-size: 0.82rem;
  color: var(--accent);
  border-style: dashed;
}

.check {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.9rem;
  white-space: nowrap;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
.row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Comparison table: one row per sign, one column per country */

main {
  padding: 1rem;
  max-width: 100%;
}

.group {
  margin-bottom: 2rem;
}

.group h2 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.group h2 small {
  font-weight: normal;
  color: var(--muted);
}

.table {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

/* Cells line up at the top and every image box is the same size, with the
   sign drawn at its bottom: all signs in a row stand on one line. */
.row {
  display: grid;
  grid-template-columns: minmax(12rem, 20rem) repeat(var(--columns), var(--cell));
  gap: 0.75rem;
  align-items: start;
  padding: 0.6rem 0.9rem;
  border-top: 1px solid var(--line);
  min-width: max-content;
  cursor: pointer;
  text-align: left;
  color: inherit;
  text-decoration: none;
}

.row:hover {
  background: var(--accent-soft);
}

.row.head {
  border-top: 0;
  cursor: default;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.row.head:hover {
  background: none;
}

.row .name,
.row.head > * {
  align-self: center;
}

.name strong {
  display: block;
}

.name code {
  font-size: 0.8rem;
  color: var(--muted);
}

.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  text-align: center;
  font-size: 0.78rem;
}

.cell img,
.cell .missing {
  width: 4.5rem;
  height: 4.5rem;
  object-fit: contain;
  object-position: center bottom;
}

/* Placeholder while an image downloads (img.pending until its load event). */
img.pending {
  border-radius: 8px;
  background: linear-gradient(90deg, var(--skeleton) 25%, var(--skeleton-shine) 50%, var(--skeleton) 75%) 0 0 / 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

img {
  transition: opacity 0.2s;
}

img.pending {
  opacity: 0.6;
}

.cell .missing {
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.2;
  text-align: center;
}

/* The country does not have this sign. */
.cell.absent {
  color: var(--line);
  font-size: 1.5rem;
}

/* Country code inside each cell; only shown on phones, where there is no header row. */
.cell .country {
  display: none;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.cell .local {
  color: var(--muted);
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  background: var(--warn-soft);
  color: var(--warn);
  white-space: nowrap;
}

/* Reset filters: shown only while a filter differs from a first visit */

button.reset {
  font: inherit;
  font-size: 0.9rem;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

button.reset::before {
  content: "✕ ";
}

button.reset:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

button.reset[hidden] {
  display: none;
}

/* Sharing: a small pill button, and a note when a link was copied */

button.share {
  font: inherit;
  font-size: 0.8rem;
  font-weight: normal;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
  vertical-align: middle;
}

button.share::before {
  content: "↗ ";
}

button.share:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.detail-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  margin-right: 2rem;
}

.detail-head h2 {
  margin: 0;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  margin: 0;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
}

.toast[hidden] {
  display: none;
}

.empty {
  padding: 3rem 1rem;
  text-align: center;
}

/* Loading data.json, and the "show more" footer under the list */

.loading {
  display: grid;
  gap: 1.25rem;
}

.loading-status {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  padding: 1rem 1rem 0;
}

.loading progress {
  width: min(20rem, 80%);
  accent-color: var(--accent);
}

.loading p,
.more p {
  margin: 0;
  font-size: 0.9rem;
}

.more {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  padding: 1rem 0 2rem;
}

/* Rows shaped like the list, shimmering until data.json is in. */
.skeleton {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.skeleton-title,
.skeleton i,
.skeleton b {
  display: block;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--skeleton) 25%, var(--skeleton-shine) 50%, var(--skeleton) 75%) 0 0 / 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-title {
  width: 12rem;
  height: 1rem;
  margin: 0.9rem;
}

.skeleton-row {
  display: grid;
  grid-template-columns: minmax(12rem, 20rem) repeat(8, var(--cell));
  gap: 0.75rem;
  align-items: end;
  padding: 0.6rem 0.9rem;
  border-top: 1px solid var(--line);
  overflow: hidden;
}

.skeleton i {
  height: 2.2rem;
  align-self: center;
}

.skeleton b {
  width: 4.5rem;
  height: 4.5rem;
  justify-self: center;
}

/* Each row's shimmer starts a little later, so it rolls down the list. */
.skeleton-row:nth-child(3) > * { animation-delay: 0.1s; }
.skeleton-row:nth-child(4) > * { animation-delay: 0.2s; }
.skeleton-row:nth-child(5) > * { animation-delay: 0.3s; }
.skeleton-row:nth-child(6) > * { animation-delay: 0.4s; }
.skeleton-row:nth-child(7) > * { animation-delay: 0.5s; }

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-title,
  .skeleton i,
  .skeleton b,
  img.pending {
    animation: none;
  }
}

.more[hidden],
.loading[hidden] {
  display: none;
}

.more button {
  font: inherit;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
}

.more button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Detail dialog */

dialog {
  width: min(64rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.25rem 1.5rem;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

dialog .close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
}

dialog .close button {
  font-size: 1.5rem;
  line-height: 1;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

dialog h2 {
  margin: 0 2rem 0.25rem 0;
}

.names {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.compare {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 1rem;
}

/* Each panel's heading, image, details and archive share rows with the other
   panels on its line, so a heading that wraps does not push one image lower:
   the large images stand on one line too. */
.panel {
  display: grid;
  grid-row: span 4;
  grid-template-rows: subgrid;
  row-gap: 0;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
}

.panel h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.panel .big {
  width: 100%;
  height: 11rem;
  object-fit: contain;
  object-position: center bottom;
}

.panel .missing {
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.panel dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.75rem;
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
}

.panel dt {
  color: var(--muted);
}

.panel dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.archive {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.archive figure {
  margin: 0;
  text-align: center;
  font-size: 0.75rem;
}

.archive img {
  width: 3.5rem;
  height: 3.5rem;
  object-fit: contain;
  object-position: center bottom;
  opacity: 0.8;
}

footer {
  padding: 1.5rem 1rem 2rem;
  font-size: 0.85rem;
}

/* Phones: each sign is a card, name on top and the countries wrapping below. */
@media (max-width: 640px) {
  .top {
    padding: 0.5rem 0.75rem 0.25rem;
  }

  .bar h1 {
    font-size: 1.05rem;
  }

  .controls {
    gap: 0.5rem;
  }

  .controls select {
    width: 100%;
  }

  main {
    padding: 0.75rem;
  }

  .group h2 {
    font-size: 0.95rem;
  }

  .row.head {
    display: none;
  }

  .skeleton-row {
    grid-template-columns: repeat(auto-fill, minmax(4.75rem, 1fr));
    gap: 0.4rem 0.5rem;
  }

  .skeleton i {
    grid-column: 1 / -1;
    height: 1.4rem;
    width: 60%;
  }

  .skeleton b {
    width: 3.5rem;
    height: 3.5rem;
  }

  /* Type buttons scroll sideways in one line rather than taking half the screen. */
  .types {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 0.1rem;
  }

  /* As many countries per line as fit, so a card never needs sideways scrolling. */
  .row {
    grid-template-columns: repeat(auto-fill, minmax(4.75rem, 1fr));
    align-items: start;
    gap: 0.4rem 0.5rem;
    padding: 0.65rem 0.75rem;
    min-width: 0;
  }

  .row .name {
    grid-column: 1 / -1;
  }

  .name strong {
    font-size: 0.95rem;
  }

  .cell {
    font-size: 0.72rem;
  }

  .cell img,
  .cell .missing {
    width: 3.5rem;
    height: 3.5rem;
  }

  .cell .country {
    display: block;
  }

  /* A country without the sign keeps its place as an empty slot, so every
     country sits in the same spot on every card. */
  .cell.absent .gap {
    display: block;
    width: 3.5rem;
    height: 3.5rem;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: transparent;
  }

  .cell.absent .country {
    opacity: 0.5;
  }

  /* Detail: full screen, close button always in reach, two countries per row. */
  dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: 0 1rem 1.5rem;
  }

  dialog .close {
    position: sticky;
    top: 0;
    right: auto;
    display: flex;
    justify-content: flex-end;
    margin: 0 -1rem;
    padding: 0.25rem 0.5rem;
    background: var(--surface);
    z-index: 1;
  }

  dialog .close button {
    font-size: 1.9rem;
    padding: 0.25rem 0.6rem;
  }

  dialog h2 {
    margin: 0 0 0.25rem;
    font-size: 1.2rem;
  }

  .compare {
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    gap: 0.6rem;
  }

  .panel {
    padding: 0.65rem;
  }

  .panel .big {
    height: 6.5rem;
  }

  .panel dl {
    grid-template-columns: 1fr;
    gap: 0;
    font-size: 0.8rem;
  }

  .panel dt {
    margin-top: 0.35rem;
    font-size: 0.72rem;
  }
}
