:root {
  --bg: #ffffff;
  --bg-card: #ffffff;
  --bg-soft: #f3f6fb;
  --text: #1a1a1a;
  --muted: #4b5563;
  --accent: #1d4ed8;
  --border: #d5dee8;
  --heading: #1e293b;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: only light;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  color-scheme: only light;
  background-color: #ffffff;
}

body {
  margin: 0;
  font-family: var(--font);
  background-color: #ffffff;
  color: #1a1a1a;
  line-height: 1.55;
  font-size: 16px;
  overflow-x: clip;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

img, svg, video { max-width: 100%; }
canvas {
  max-width: 100%;
  background-color: #ffffff;
}

code {
  overflow-wrap: anywhere;
  font-size: 0.88em;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

header.site {
  background: linear-gradient(160deg, #f4f7fb 0%, #ffffff 70%);
  border-bottom: 1px solid var(--border);
  padding: 2rem 0 1.5rem;
  margin-bottom: 1.5rem;
}
header.site h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 700;
  color: var(--heading);
}
header.site .sub {
  color: var(--muted);
  margin: 0 0 1rem;
  max-width: 48rem;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  font-size: 0.95rem;
}
nav a {
  color: var(--text);
  border-bottom: 2px solid transparent;
  padding: 0.45rem 0.1rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
nav a:hover, nav a.active {
  border-color: var(--accent);
  text-decoration: none;
}

.view-nav {
  align-items: center;
  gap: 0.4rem;
}
.view-nav > a:not(.nav-quiet) {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
  background: #ffffff;
  border-bottom-width: 1px;
}
.view-nav > a:not(.nav-quiet)[aria-selected="true"],
.view-nav > a:not(.nav-quiet).active {
  background: #dbeafe;
  border-color: var(--accent);
  color: #1e3a8a;
  font-weight: 600;
  text-decoration: none;
}
.view-nav > a.nav-quiet {
  margin-left: 0.25rem;
  color: var(--muted);
  font-size: 0.92rem;
}

[hidden] { display: none !important; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--muted);
  vertical-align: middle;
}
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.ok { background: #dcfce7; color: #166534; }

section { margin: 2rem 0; }
section h2 {
  font-size: 1.35rem;
  margin: 0 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  color: var(--heading);
}
section h3 {
  font-size: 1.05rem;
  margin: 1.25rem 0 0.5rem;
  color: var(--heading);
}
.lead {
  color: var(--muted);
  margin: 0 0 1rem;
  font-size: 0.95rem;
}

.card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1rem 0;
}

.party-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.party-actions button {
  min-height: 44px;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font: inherit;
  cursor: pointer;
}
.party-actions button:hover { border-color: var(--accent); }
.party-actions button:focus-visible,
.modes label:focus-within,
select:focus-visible,
th button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.party-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
  gap: 0.15rem 0.75rem;
  max-height: 16rem;
  overflow: auto;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  margin-bottom: 1rem;
}
.party-grid label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  cursor: pointer;
}
.party-grid input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
.filter-row label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--heading);
}
select {
  min-height: 44px;
  font: inherit;
  font-weight: 400;
  color: #1a1a1a;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  width: 100%;
}

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.75rem;
}
.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.modes label {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
}
.modes input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.modes label:has(input:checked) {
  background: #dbeafe;
  border-color: var(--accent);
  color: #1e3a8a;
  font-weight: 600;
}
.scale-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 44px;
  padding: 0.4rem 0.95rem 0.4rem 0.7rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  user-select: none;
}
.scale-toggle input {
  width: 1.35rem;
  height: 1.35rem;
  margin: 0;
  accent-color: var(--accent);
}
.scale-toggle:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.scale-toggle:has(input:checked) {
  border-color: var(--accent);
  background: #dbeafe;
  color: #1e3a8a;
}

.chart-scroll {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}
.chart-wrap {
  position: relative;
  width: 100%;
  max-width: none;
  background: #ffffff;
  height: 460px;
}
#wrap-evo { min-width: 880px; }
#wrap-rank { height: 640px; min-width: 720px; }
.scroll-hint { display: none; }
@media (max-width: 860px) {
  .scroll-hint { display: block; }
}
.chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}
.source-line,
.source-list {
  color: var(--muted);
  font-size: 0.88rem;
}
.source-line {
  margin: 0.65rem 0 0;
}
.source-line a,
.source-list a {
  font-weight: 600;
}
.source-list {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
}
.source-list li { margin: 0.55rem 0; }

.chart-note {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0.5rem 0 0;
}
.empty {
  margin: 0;
  padding: 1rem 1.1rem;
  background: var(--bg-soft);
  border-radius: 8px;
  color: var(--text);
}

.multiples {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
.mini {
  margin: 0;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.55rem 0.3rem;
}
.mini h3 {
  margin: 0 0 0.15rem;
  font-size: 0.88rem;
}
.mini .chart-wrap { height: 150px; }
.mini .muted-mini {
  margin: 0.4rem 0 0.6rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #ffffff;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: #ffffff;
}
caption {
  caption-side: bottom;
  text-align: left;
  padding: 0.55rem 0.75rem;
  color: var(--muted);
  font-size: 0.8rem;
}
th, td {
  padding: 0.45rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: var(--bg-soft);
  color: var(--heading);
  font-weight: 600;
  position: sticky;
  top: 0;
}
.table-wrap tbody th.party,
.table-wrap tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #ffffff;
}
.table-wrap thead th:first-child {
  left: 0;
  z-index: 3;
  background: var(--bg-soft);
}
th button {
  all: unset;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  color: inherit;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}
td.party { white-space: normal; min-width: 10rem; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.is-focus, td.is-focus { background: #eff6ff; }
tr:last-child td { border-bottom: none; }

.lists {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
.list-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.list-card h3 { margin-top: 0; }
.list-card ol, .list-card ul {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
}
.list-card li { margin: 0.35rem 0; font-size: 0.92rem; }
.list-card .meta-src {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.75rem;
}
.list-card.provisional {
  border-color: #e6d3a1;
  background: #fffbeb;
}

footer.site {
  margin-top: 3rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.sources-body {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}
.sources-body h1 { font-size: 1.6rem; color: var(--heading); }
.sources-body h2 {
  font-size: 1.2rem;
  margin-top: 2rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
  color: var(--heading);
}
.sources-body table { margin: 1rem 0; font-size: 0.85rem; }
.sources-body td, .sources-body th,
.sources-body a, .table-wrap a {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.sources-body p { color: var(--muted); }
.sources-body strong { color: var(--text); }

.notice {
  background: #fffbeb;
  border: 1px solid #e6d3a1;
  color: #92400e;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-weight: 600;
}
.glossary {
  display: grid;
  gap: 0.75rem;
}
.glossary article {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.glossary h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  color: var(--heading);
}
.glossary p { margin: 0.35rem 0; }
.glossary .caveat { color: #92400e; }

.loading { color: var(--muted); font-style: italic; }
.error {
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 0.75rem 1rem;
  border-radius: 8px;
}

@media (min-width: 720px) {
  .filter-row { grid-template-columns: 1.4fr repeat(3, minmax(0, 0.7fr)); }
  .filter-row.single { grid-template-columns: minmax(8rem, 14rem); }
  .lists { grid-template-columns: repeat(3, 1fr); }
}
.filter-row.single { max-width: 16rem; }
@media (min-width: 800px) {
  .multiples { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1100px) {
  .multiples { grid-template-columns: 1fr 1fr 1fr; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 1rem 2rem; }
  header.site { padding: 1.15rem 0 0.85rem; margin-bottom: 1rem; }
  header.site h1 { font-size: 1.45rem; }
  section { margin: 1.5rem 0; }
  section h2 { font-size: 1.2rem; }
  .card { padding: 1rem; }
  .party-grid { max-height: 14rem; }
  th, td { padding: 0.4rem 0.55rem; }
  table { font-size: 0.82rem; }
  .sources-body { padding: 0 1rem 2rem; }
  .sources-body h1 { font-size: 1.35rem; }
  footer.site { margin-top: 2rem; }
}
