:root {
  --bg: #fbf8f3;
  --surface: #ffffff;
  --surface-2: #f4efe6;
  --text: #1f1a14;
  --muted: #6d6458;
  --border: #e6ddd0;
  --accent: #c8201a;
  --accent-ink: #ffffff;
  --gold: #f2b705;
  --star-empty: #d9d0c2;
  --good: #1f8a4c;
  --bad: #c8201a;
  --hero-bg: #c8201a;
  --hero-text: #fff7e6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 25, 10, 0.06), 0 4px 16px rgba(40, 25, 10, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120f;
    --surface: #1e1a16;
    --surface-2: #27221d;
    --text: #f3ece2;
    --muted: #a99e90;
    --border: #352e27;
    --accent: #ff5a4e;
    --accent-ink: #1a0f0d;
    --gold: #ffc72c;
    --star-empty: #4a4139;
    --good: #4cc982;
    --bad: #ff6b60;
    --hero-bg: #7d140f;
    --hero-text: #fff1dc;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Hero */
.hero { background: var(--hero-bg); color: var(--hero-text); padding: 48px 0 72px; }
.eyebrow { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.8; }
.hero h1 { margin: 0; font-size: clamp(36px, 7vw, 60px); line-height: 1.05; letter-spacing: -0.02em; }
.lede { margin: 12px 0 0; font-size: 18px; max-width: 46ch; opacity: 0.92; }
.updated { margin: 16px 0 0; font-size: 13px; opacity: 0.75; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: -44px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Best / worst */
.extremes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel h2 { margin: 0 0 10px; font-size: 18px; }
.panel.best h2 { color: var(--good); }
.panel.worst h2 { color: var(--bad); }
.panel ol { margin: 0; padding: 0; list-style: none; }
.panel li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.panel li:first-child { border-top: 0; }
.panel .pos { font-weight: 700; color: var(--muted); width: 1.5em; flex: none; font-variant-numeric: tabular-nums; }
.panel .who { min-width: 0; flex: 1; }
.panel .who a { color: inherit; text-decoration: none; font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel .who a:hover { text-decoration: underline; }
.panel .where { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel .num { font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }

/* Controls */
.controls { margin-top: 32px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip .count { opacity: 0.7; margin-left: 4px; font-variant-numeric: tabular-nums; }

.control-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; align-items: end; }
.control-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.control-row .search { flex: 1 1 260px; }
input, select {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  min-width: 0;
}
input:focus-visible, select:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.method-note { font-size: 13px; color: var(--muted); margin: 10px 0 0; max-width: 80ch; }

/* Table */
.list { margin-top: 16px; }
.ranking {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.ranking th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--surface-2);
  padding: 10px 14px;
  font-weight: 600;
}
.ranking td { padding: 12px 14px; border-top: 1px solid var(--border); vertical-align: middle; }
.ranking tbody tr:hover { background: var(--surface-2); }
.col-rank, .col-reviews, .col-score { text-align: right !important; }
td.col-rank { font-weight: 700; font-variant-numeric: tabular-nums; width: 3.5em; }
td.col-reviews, td.col-score { font-variant-numeric: tabular-nums; }
td.col-score { font-weight: 600; }
.rank-medal { font-size: 18px; }
.name a { color: var(--text); font-weight: 600; text-decoration: none; }
.name a:hover { text-decoration: underline; color: var(--accent); }
.addr { font-size: 13px; color: var(--muted); }
.flag { margin-right: 6px; }
.unrated td { color: var(--muted); }

.rating-cell { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.rating-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.stars { position: relative; display: inline-block; font-size: 15px; line-height: 1; letter-spacing: 1px; color: var(--star-empty); }
.stars::before { content: "★★★★★"; }
.stars .fill { position: absolute; inset: 0 auto 0 0; overflow: hidden; color: var(--gold); white-space: nowrap; }
.stars .fill::before { content: "★★★★★"; }
.trend { font-size: 12px; font-weight: 600; }
.trend.up { color: var(--good); }
.trend.down { color: var(--bad); }

.ranking:not(.show-score) .col-score { display: none; }

.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* Setup / footer */
.setup { padding-top: 40px; padding-bottom: 40px; }
.setup pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-x: auto; }
.footer { color: var(--muted); font-size: 13px; padding-top: 32px; padding-bottom: 48px; }

/* Mobile: table rows become cards */
@media (max-width: 720px) {
  .hero { padding: 32px 0 64px; }
  .extremes { grid-template-columns: 1fr; }
  .ranking, .ranking tbody, .ranking tr, .ranking td { display: block; }
  .ranking thead { display: none; }
  .ranking { border: 0; background: none; box-shadow: none; }
  .ranking tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "rank name score" "rank rating rating";
    column-gap: 12px;
    row-gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
  }
  .ranking td { border: 0; padding: 0; }
  td.col-rank { grid-area: rank; width: auto; align-self: center; text-align: left !important; font-size: 18px; }
  td.name { grid-area: name; min-width: 0; }
  td.col-score { grid-area: score; }
  td.col-rating { grid-area: rating; }
  td.col-country, td.col-reviews { display: none; }
  .mobile-reviews { display: inline; }
}
@media (min-width: 721px) { .mobile-reviews { display: none; } }
