:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6b6760;
  --line: #e4e0d8;
  --accent: #9b2335;
  --accent-soft: #f6e7e9;
  --on-accent: #ffffff;
  --series-2: #4a6f8a;
  --map-low: #f4efe7;
  --map-none: #eeebe5;
  --cat-1: #9b2335;
  --cat-2: #3f6e8c;
  --cat-3: #c9851f;
  --cat-4: #4f8a5b;
  --cat-5: #7a5aa6;
  --cat-6: #2a8f8f;
  --cat-7: #b5658a;
  --cat-other-n: #9c968b;
  --cat-other-r: #c9c2b5;
  --bar: #c9a3a9;
  --bar-win: #9b2335;
  --notice-bg: #fdf6e3;
  --notice-line: #e8d9a8;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --surface: #1f1e1c;
    --text: #ecebe8;
    --muted: #a19d95;
    --line: #34322e;
    --accent: #e0707f;
    --accent-soft: #3a2327;
    --on-accent: #1c1b19;
    --series-2: #8fb3cc;
    --map-low: #2b2926;
    --map-none: #2a2826;
    --cat-1: #e0707f;
    --cat-2: #7fb0d0;
    --cat-3: #e3b05a;
    --cat-4: #86c191;
    --cat-5: #ad94d6;
    --cat-6: #64c3c3;
    --cat-7: #dd98b8;
    --cat-other-n: #77726a;
    --cat-other-r: #56524b;
    --bar: #6e4a50;
    --bar-win: #e0707f;
    --notice-bg: #2c2717;
    --notice-line: #574c26;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #161514;
  --surface: #1f1e1c;
  --text: #ecebe8;
  --muted: #a19d95;
  --line: #34322e;
  --accent: #e0707f;
  --accent-soft: #3a2327;
  --on-accent: #1c1b19;
  --series-2: #8fb3cc;
  --map-low: #2b2926;
  --map-none: #2a2826;
  --cat-1: #e0707f;
  --cat-2: #7fb0d0;
  --cat-3: #e3b05a;
  --cat-4: #86c191;
  --cat-5: #ad94d6;
  --cat-6: #64c3c3;
  --cat-7: #dd98b8;
  --cat-other-n: #77726a;
  --cat-other-r: #56524b;
  --bar: #6e4a50;
  --bar-win: #e0707f;
  --notice-bg: #2c2717;
  --notice-line: #574c26;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}

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

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

/* cabecera */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}
.brand { text-decoration: none; color: inherit; display: flex; flex-direction: column; }
.brand-title { font: 700 1.15rem/1.2 var(--font-serif); }
.brand-sub { color: var(--muted); font-size: .85rem; }
.site-header nav a { font-size: .9rem; white-space: nowrap; }

/* controles */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--line);
}
.control { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.segmented button {
  font: inherit;
  font-size: .9rem;
  padding: 6px 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.places { flex-direction: row; flex-wrap: wrap; gap: 12px; flex: 1 1 100%; }
.places label { display: flex; flex-direction: column; gap: 6px; flex: 1 1 180px; min-width: 0; }
select {
  font: inherit;
  font-size: .9rem;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
select:disabled { opacity: .5; }

/* vista */
.view { padding: 20px 0 40px; }
.crumbs { font-size: .85rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.crumbs span + span::before, .crumbs a + span::before, .crumbs a + a::before { content: " › "; color: var(--muted); }
h1 { font: 700 1.6rem/1.2 var(--font-serif); margin: 4px 0 2px; }
.subtitle { color: var(--muted); margin: 0 0 16px; }

.notice {
  background: var(--notice-bg);
  border: 1px solid var(--notice-line);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0 0 16px;
  font-size: .92rem;
}
.notice strong { display: block; margin-bottom: 2px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.stat .label { display: block; }
.stat .value { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* tabla */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
}
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
td:not(:first-child) { white-space: nowrap; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
th:first-child, td:first-child { text-align: left; }
td.org { width: 55%; }
.org-name { display: block; }
.org-meta { display: block; font-size: .78rem; color: var(--muted); }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 5px; }
.bar > span { display: block; height: 100%; background: var(--bar); border-radius: 2px; }
tr.winner .bar > span { background: var(--bar-win); }
tr.winner .org-name { font-weight: 600; }
tbody.other td { color: var(--muted); }
tfoot td { font-weight: 600; border-bottom: 0; }

.site-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .82rem;
  padding: 16px 0 28px;
}

@media (max-width: 480px) {
  h1 { font-size: 1.35rem; }
  .site-header .wrap { align-items: flex-start; }
  .brand-title { font-size: 1rem; }
  table { font-size: .82rem; }
  th, td { padding: 7px 4px; }
  td.org { width: auto; }
}

.region-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px 16px;
}
.region-list a { text-decoration: none; }
.region-list a:hover { text-decoration: underline; }
.loading { color: var(--muted); }

/* serie */
.series:empty { display: none; }
.series { padding: 8px 0 40px; border-top: 1px solid var(--line); }
h2 { font: 700 1.25rem/1.25 var(--font-serif); margin: 20px 0 2px; }
.chart-box { position: relative; height: 220px; margin: 0 0 16px; }
.series-table th[scope="row"] { text-align: left; font-size: .9rem; color: var(--text); text-transform: none; letter-spacing: 0; }
.series-table td.org, .series-table .th-org { text-align: left; }
.series-table td.org { width: auto; min-width: 150px; white-space: normal; }
.series-table tr.missing td { text-align: left; color: var(--muted); font-style: italic; white-space: normal; }
.glossary { margin-top: 14px; font-size: .88rem; color: var(--muted); }
.glossary summary { cursor: pointer; color: var(--text); }
.glossary dl { margin: 8px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; }
.glossary dt { font-weight: 600; color: var(--text); }
.glossary dd { margin: 0; }
@media (max-width: 480px) {
  .glossary dl { grid-template-columns: 1fr; }
  .glossary dd { margin-bottom: 6px; }
}
.series-table th[scope="row"], .series-table thead th:first-child {
  position: sticky;
  left: 0;
  background: var(--bg);
  z-index: 1;
}

/* mapa */
.map { padding: 8px 0 32px; border-top: 1px solid var(--line); }
.map-controls { display: flex; flex-wrap: wrap; gap: 12px 24px; margin-bottom: 12px; }
.map-controls select { width: auto; max-width: 100%; }
.map-canvas { position: relative; max-width: 560px; margin: 0 auto; }
.map-canvas svg { display: block; width: 100%; height: auto; }
.map-canvas path.unit { stroke: var(--surface); stroke-width: .5; cursor: pointer; }
.map-canvas path.unit:hover { stroke: var(--text); stroke-width: 1; }
.map-canvas path.unit.selected { stroke: var(--text); stroke-width: 2; }
.map-tip {
  position: absolute;
  pointer-events: none;
  max-width: 240px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
  padding: 8px 10px;
  font-size: .82rem;
  line-height: 1.35;
  z-index: 2;
}
.map-tip strong, .map-tip span { display: block; }
.map-legend {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: .82rem;
}
.map-legend li { display: flex; align-items: center; gap: 6px; }
.map-legend .sw { width: 12px; height: 12px; border-radius: 2px; flex: none; }
.map-legend .sw-none { background: var(--map-none); outline: 1px solid var(--line); outline-offset: -1px; }
.map-legend .n { color: var(--muted); }
.map-note { font-size: .8rem; color: var(--muted); margin: 10px 0 0; }
.map-note:empty { display: none; }

/* metodología */
.prose { padding-top: 24px; padding-bottom: 40px; max-width: 760px; }
.prose h2 { margin-top: 32px; }
.prose p, .prose li, .prose dd { line-height: 1.6; }
.toc { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .9rem; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.refs { padding-left: 0; list-style: none; }
.refs li { padding-left: 2em; text-indent: -2em; margin-bottom: 8px; overflow-wrap: anywhere; }
.rules li { margin-bottom: 10px; }
.defs dt { font-weight: 600; margin-top: 10px; }
.defs dd { margin: 2px 0 0; }
.method-table { margin: 8px 0; }
.method-table td:first-child { white-space: normal; }
.note { font-size: .82rem; color: var(--muted); }
