:root {
  --paper: #edf0f4;
  --ink: #101b2b;
  --muted: #566274;
  --rule: #c9d1dc;
  --soft: #e1e6ed;
  --c-rfm: #d7263d;
  --c-rc: #1f6fb2;
  --c-mh: #7b4fd6;
  --on-color: #ffffff;
  --display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e141c;
    --ink: #e8edf3;
    --muted: #93a0b2;
    --rule: #26303d;
    --soft: #18212c;
    --c-rfm: #ff5a6e;
    --c-rc: #4fa3e8;
    --c-mh: #a98bff;
    --on-color: #0e141c;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
}

main, .hero, footer, .error {
  width: min(1080px, 100% - 2.5rem);
  margin-inline: auto;
}

/* ---------- hero ---------- */
.hero { padding: 3.5rem 0 2rem; }

h1 {
  margin: 0;
  font: 800 clamp(2.4rem, 7vw, 4.6rem)/0.98 var(--display);
  font-stretch: 125%;
  letter-spacing: -0.02em;
  max-width: 14ch;
}

.lede {
  margin: 1.25rem 0 2rem;
  max-width: 60ch;
  color: var(--muted);
  font-size: 1.1rem;
}

/* botões de sintonia (presets de rádio de carro) */
.presets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.preset {
  --c: var(--ink);
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-height: 5.6rem;
  padding: 0.8rem 1rem 0.9rem;
  text-align: left;
  color: var(--ink);
  background: var(--soft);
  border: 1px solid var(--rule);
  border-bottom: 5px solid var(--c);
  border-radius: 14px 14px 4px 4px;
  font: inherit;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.15s;
}

.preset:hover { transform: translateY(-2px); }
.preset .name { font: 700 1.05rem/1.2 var(--display); font-stretch: 112%; }
.preset .song { font-size: 0.88rem; line-height: 1.3; opacity: 0.85; }
.preset .song b { font-weight: 600; }

.preset[aria-pressed="true"] {
  background: var(--c);
  border-color: var(--c);
  color: var(--on-color);
}
.preset[aria-pressed="true"] .song { opacity: 1; }

:focus-visible { outline: 3px solid var(--c-rc); outline-offset: 3px; }

/* ---------- secções ---------- */
section { padding: 3rem 0 1rem; border-top: 1px solid var(--rule); margin-top: 2rem; }

h2 {
  margin: 0 0 0.5rem;
  font: 750 clamp(1.6rem, 3.6vw, 2.2rem)/1.1 var(--display);
  font-stretch: 112%;
  letter-spacing: -0.01em;
}

h3 { margin: 1.5rem 0 0.4rem; font: 650 1.05rem/1.3 var(--body); }

.note { margin: 0 0 1.5rem; max-width: 66ch; color: var(--muted); }
.hint { margin: 0 0 0.75rem; font-size: 0.9rem; color: var(--muted); max-width: 48ch; }

.two > div { min-width: 0; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 3rem; }

/* ---------- rankings ---------- */
.ranking { list-style: none; margin: 0; padding: 0; }

.ranking li {
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1fr) 3.2rem;
  align-items: center;
  column-gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--rule);
}

.ranking .pos { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.ranking .lbl { min-width: 0; }
.ranking .lbl strong { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .lbl small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.bar { grid-column: 2 / 4; display: flex; height: 6px; margin-top: 0.4rem; background: var(--soft); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; }

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; margin: -0.5rem 0 1rem; font-size: 0.9rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 50%; margin-right: 0.4rem; vertical-align: -0.1rem; background: var(--c); }

.presets-mini { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.presets-mini button {
  appearance: none; font: inherit; font-size: 0.9rem; cursor: pointer;
  padding: 0.25rem 0.8rem; color: var(--ink); background: transparent;
  border: 1px solid var(--rule); border-radius: 999px;
}
.presets-mini button[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: var(--on-color); }

/* ---------- gráficos ---------- */
.chart { position: relative; width: 100%; height: 300px; }
.chart.tall { height: 380px; }
.chart.short { height: 220px; }

/* ---------- tabelas ---------- */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 0.55rem 0.7rem 0.55rem 0; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 600; white-space: nowrap; }
.num { text-align: right; padding-right: 0; padding-left: 0.7rem; }
td small { display: block; color: var(--muted); }

.facts th[scope="col"] { color: var(--ink); }
.facts th[scope="col"]::before { content: ""; display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; margin-right: 0.45rem; background: var(--c); }
.facts th[scope="row"] { font-weight: 400; color: var(--muted); }
.facts { margin-bottom: 1rem; }

.matrix td, .matrix th { text-align: center; padding: 0.6rem; }
.matrix th:first-child { text-align: left; }
.matrix td { font-weight: 600; }
.matrix td.self { color: var(--muted); font-weight: 400; }

/* ---------- pesquisa ---------- */
.searchbox input {
  width: 100%; padding: 0.85rem 1rem; font: inherit; font-size: 1.1rem;
  color: var(--ink); background: var(--soft);
  border: 1px solid var(--rule); border-radius: 10px;
}
.searchbox { display: block; margin-bottom: 0.75rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- rodapé e erro ---------- */
footer { padding: 3rem 0 4rem; margin-top: 3rem; border-top: 1px solid var(--rule); color: var(--muted); font-size: 0.92rem; max-width: 1080px; }
footer p { max-width: 70ch; }
a { color: inherit; text-underline-offset: 3px; }
code { font-size: 0.92em; background: var(--soft); padding: 0.1rem 0.35rem; border-radius: 4px; }
.error { padding: 1rem 1.2rem; border-left: 5px solid var(--c-rfm); background: var(--soft); }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: minmax(0, 1fr); }
  .hero { padding-top: 2.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .preset { transition: none; }
  .preset:hover { transform: none; }
}

/* ---------- idioma ---------- */
.lang-switch { display: flex; gap: 0.4rem; margin: 0 0 1.25rem; }
.lang-switch button {
  appearance: none; font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
  padding: 0.2rem 0.75rem; color: var(--ink); background: transparent;
  border: 1px solid var(--rule); border-radius: 999px;
}
.lang-switch button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-color); }