:root {
  --font-sans: Montserrat, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-display: Montserrat, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --color-background: #0b0d10;
  --color-foreground: #f7f5f0;
  --color-surface: #141920;
  --color-surface-2: #1b2a3a;
  --color-muted: #8e98a6;
  --color-accent: #e8852b;
  --color-border: #223;
  --color-map-nodata: #2a2d33;
  --color-chroma-1: #1b2a3a;
  --color-chroma-2: #22405c;
  --color-chroma-3: #2f5a7d;
  --color-chroma-4: #4a7a9c;
  --color-chroma-5: #b8733a;
  --color-chroma-6: #e8852b;
  --color-chroma-7: #f2b577;
  --duration-quick: 150ms;
  --duration-slow: 0.4s;
  --ease-smooth-out: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--color-background);
  color: var(--color-foreground);
}
button, input { font: inherit; color: inherit; }
a { color: inherit; }
button { cursor: pointer; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--color-background);
}
.topbar {
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1rem;
}
.brand { display: flex; align-items: center; gap: 0.625rem; min-width: 0; }
.brand svg { width: 1.25rem; height: 1.25rem; flex-shrink: 0; color: var(--color-accent); }
.brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.125rem;
  line-height: 1;
  font-weight: 500;
  letter-spacing: -0.025em;
}
.brand-links { display: none; margin: 0.125rem 0 0; font-size: 0.75rem; letter-spacing: 0.025em; color: var(--color-muted); }
.brand-links a { text-decoration: underline; text-decoration-color: var(--color-border); text-underline-offset: 2px; }
.brand-links a:hover { color: var(--color-foreground); }
.nav { display: flex; align-items: center; gap: 0.25rem; }
.nav a {
  border-radius: 2px;
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.025em;
  color: var(--color-muted);
  text-decoration: none;
  transition: color var(--duration-quick);
}
.nav a:hover { color: var(--color-foreground); }
.nav a[aria-current="page"] { background: var(--color-surface-2); color: var(--color-foreground); }
.controls { min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 0.5rem; }
.metric-controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
.groups, .pills {
  display: flex;
  border-radius: 8px;
  background: var(--color-background);
  ring: 1px solid var(--color-border);
  box-shadow: inset 0 0 0 1px var(--color-border);
}
.groups { align-self: flex-end; width: max-content; max-width: 100%; padding: 2px; }
.groups button, .pills button {
  border: 0;
  background: transparent;
  border-radius: 2px;
  transition: color var(--duration-quick), background var(--duration-quick);
}
.groups button { height: 2rem; padding: 0 0.75rem; font-size: 0.75rem; font-weight: 500; letter-spacing: 0.025em; color: var(--color-muted); }
.groups button[aria-selected="true"] { background: var(--color-surface-2); color: var(--color-foreground); }
.groups button:hover { background: #233a52; color: var(--color-foreground); }
.groups button[aria-selected="true"]:hover { background: var(--color-surface-2); }
.pills {
  position: relative;
  max-width: 100%;
  flex-wrap: nowrap;
  gap: 2px;
  overflow-x: auto;
  padding: 4px;
  scrollbar-width: none;
}
.pills::-webkit-scrollbar { display: none; }
.pill-slide {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  border-radius: 2px;
  background: var(--color-surface-2);
  box-shadow: inset 0 0 0 1px var(--color-border);
  pointer-events: none;
  transition: transform 180ms var(--ease-smooth-out), width 180ms var(--ease-smooth-out);
}
.pills button {
  position: relative;
  z-index: 1;
  height: 2.25rem;
  flex-shrink: 0;
  padding: 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted);
}
.pills button[aria-checked="true"] { color: var(--color-foreground); }
.pills button:hover { background: #233a52; color: var(--color-foreground); }
.pills button[aria-checked="true"]:hover { background: transparent; }

.workspace { position: relative; display: flex; min-height: 0; flex: 1; flex-direction: column; }
.stage { position: relative; min-height: 0; flex: 1; }
.map { width: 100%; height: 100%; touch-action: none; user-select: none; display: block; }
.atlas-country {
  stroke: #2a2d33;
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}
.atlas-country.is-nodata { cursor: default; }
.atlas-marker { cursor: pointer; vector-effect: non-scaling-stroke; }
.atlas-mesh, .atlas-graticule, .atlas-highlight, .atlas-selected { fill: none; pointer-events: none; vector-effect: non-scaling-stroke; }
.atlas-mesh { stroke: #2a2d33; stroke-width: 0.6px; }
.atlas-graticule { stroke: #223; stroke-width: 0.5px; }
.atlas-sphere { fill: #0b0d10; stroke: #223; stroke-width: 0.8px; vector-effect: non-scaling-stroke; }
.atlas-highlight { stroke: #f7f5f0; stroke-width: 1.5px; }
.atlas-selected { stroke: #e8852b; stroke-width: 2px; }

.tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 20;
  width: 240px;
  pointer-events: none;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface-2);
  padding: 0.5rem 0.75rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  will-change: transform;
}
.tip[hidden] { display: none; }
.tip-name { margin: 0; font-family: var(--font-display); font-size: 15px; font-weight: 500; line-height: 1.25; letter-spacing: -0.025em; }
.tip-sub { margin: 0.125rem 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.75rem; color: var(--color-muted); }
.tip-metric { margin: 0.125rem 0 0; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-muted); }
.tip-value { margin: 0.25rem 0 0; font-weight: 500; font-variant-numeric: tabular-nums; }

.overlay {
  pointer-events: none;
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}
.note { max-width: 28rem; margin: 0; font-size: 11px; line-height: 1.35; color: var(--color-muted); }
.overlay-row { display: flex; width: 100%; align-items: flex-end; justify-content: space-between; gap: 0.75rem; }
.legend {
  pointer-events: none;
  max-width: min(100%, 22rem);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: rgba(20, 25, 32, 0.9);
  padding: 0.625rem 0.75rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
}
.legend-title {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-muted);
}
.est {
  margin-left: 0.5rem;
  border-radius: 2px;
  background: rgba(232, 133, 43, 0.15);
  padding: 0.125rem 0.375rem;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent);
  font-weight: 500;
}
.est-line {
  margin: 0.25rem 0 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-accent);
}
.ramp { display: flex; height: 0.5rem; margin-top: 0.5rem; overflow: hidden; border-radius: 999px; }
.ramp span { flex: 1; height: 100%; }
.ramp-labels, .nodata-key, .legend-note {
  margin-top: 0.375rem;
  font-size: 11px;
  color: var(--color-muted);
}
.ramp-labels { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.nodata-key { display: flex; align-items: center; gap: 0.375rem; }
.swatch { display: inline-block; width: 0.625rem; height: 0.625rem; border-radius: 2px; background: #2a2d33; }
.legend-note { margin-bottom: 0; line-height: 1.35; }
.zoom {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: rgba(20, 25, 32, 0.9);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
.zoom button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  background: transparent;
  color: var(--color-foreground);
}
.zoom button + button { border-top: 1px solid var(--color-border); }
.zoom button:hover { background: var(--color-surface-2); }
.zoom svg { width: 1rem; height: 1rem; }
.ranks-btn {
  display: none;
  pointer-events: auto;
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  align-items: center;
  gap: 0.5rem;
  height: 2.75rem;
  border: 0;
  border-radius: 8px;
  background: var(--color-surface-2);
  padding: 0 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
.ranks-btn svg { width: 1rem; height: 1rem; }

.panel {
  display: none;
  min-height: 0;
  flex-direction: column;
  background: var(--color-surface-2);
  border-left: 1px solid var(--color-border);
}
.panel-scroll { min-height: 0; flex: 1; overflow: auto; }
.panel-head, .detail-head { padding: 1.25rem 1.25rem 0.75rem; }
.kicker {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-muted);
}
.panel h2, .page h1, .page h2 {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.025em;
}
.panel h2 { margin: 0.25rem 0 0; font-size: 1.5rem; line-height: 1.2; }
.lede { margin: 0.5rem 0 0; font-size: 0.875rem; line-height: 1.35; color: var(--color-muted); }
.stats, .totals { display: grid; gap: 0.5rem; margin: 1rem 0 0; }
.stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat {
  border-radius: 8px;
  background: var(--color-background);
  padding: 0.5rem 0.625rem;
}
.stat dt {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-muted);
}
.stat dd { margin: 0.125rem 0 0; font-size: 0.875rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.rule { height: 1px; background: var(--color-border); border: 0; margin: 0; }
.search-wrap { position: relative; padding: 0.75rem 1.25rem; }
.search-wrap svg {
  position: absolute;
  top: 50%;
  left: 2.125rem;
  width: 1rem;
  height: 1rem;
  transform: translateY(-50%);
  color: var(--color-muted);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  height: 2.5rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-background);
  padding: 0 0.75rem 0 2.25rem;
  outline: none;
}
.search-wrap input:focus { box-shadow: 0 0 0 2px rgba(232, 133, 43, 0.4); }
.rank-list { list-style: none; margin: 0; padding: 0 0.5rem 1rem; }
.rank-list button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.75rem;
  border: 0;
  border-radius: 2px;
  background: transparent;
  padding: 0.5rem 0.75rem;
  text-align: left;
}
.rank-list button:hover, .rank-list button.is-hot { background: rgba(27, 42, 58, 0.7); }
.rank-list .n { width: 1.75rem; flex-shrink: 0; font-size: 0.75rem; font-variant-numeric: tabular-nums; color: var(--color-muted); }
.rank-list .nm { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; }
.rank-list .v { flex-shrink: 0; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.detail-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.icon-btn { border: 0; background: transparent; color: var(--color-foreground); width: 2rem; height: 2rem; border-radius: 8px; }
.icon-btn:hover { background: var(--color-background); }
.iso { margin: 0.25rem 0 0; font-size: 0.75rem; font-variant-numeric: tabular-nums; color: var(--color-muted); }
.big {
  margin: 0.25rem 0 0;
  font-family: var(--font-display);
  font-size: 1.875rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.025em;
}
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: rgba(74, 122, 156, 0.2);
  color: var(--color-chroma-6);
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
}
.pct-row { display: flex; justify-content: space-between; margin-bottom: 0.375rem; font-size: 11px; color: var(--color-muted); }
.pct { height: 0.375rem; border-radius: 999px; background: var(--color-background); overflow: hidden; }
.pct span { display: block; height: 100%; background: var(--color-accent); }
.meta-grid, .metric-grid { display: grid; gap: 0.5rem; }
.meta-grid { grid-template-columns: 1fr; margin-top: 1rem; }
.metric-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  margin-top: 0.75rem;
}
.metric-grid > .stat {
  min-width: 0;
  height: 100%;
}
.metric-grid .stat dt {
  min-width: 0;
  overflow-wrap: break-word;
}
.metric-grid .est {
  display: table;
  max-width: 100%;
  margin-top: 0.375rem;
  margin-left: 0;
}
.kv { display: flex; justify-content: space-between; gap: 0.75rem; font-size: 0.8125rem; }
.kv dt { color: var(--color-muted); }
.kv dd { margin: 0; text-align: right; }
.prose { margin: 0.75rem 0 0; font-size: 0.875rem; line-height: 1.6; }
.prose.muted, .fine { color: var(--color-muted); }
.fine { margin: 1.5rem 0 1rem; font-size: 11px; line-height: 1.5; }
.fine a { font-weight: 500; text-decoration: underline; text-decoration-color: var(--color-border); text-underline-offset: 2px; }
.wb {
  margin-top: 1rem;
  border-radius: 8px;
  background: var(--color-background);
  padding: 0.75rem;
  box-shadow: inset 0 0 0 1px var(--color-border);
}
.wb p { margin: 0; }
.all-metrics { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.all-metrics li { margin-top: 0.75rem; }
.all-metrics .row { display: flex; justify-content: space-between; gap: 0.75rem; font-size: 0.875rem; }
.all-metrics .on { color: var(--color-chroma-6); }
.h-label { margin: 1.5rem 0 0; font-size: 11px; font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-muted); }

.page { min-height: 100dvh; background: var(--color-background); }
.page-bar { border-bottom: 1px solid var(--color-border); padding: 0.75rem 1rem; }
.page-bar-inner, .page-main { max-width: 72rem; margin: 0 auto; }
.page-main { padding: 1.5rem 1rem 2.5rem; }
.page-kicker { margin: 0; font-size: 11px; font-weight: 500; letter-spacing: 0.16em; text-transform: uppercase; color: var(--color-muted); }
.page h1 { margin: 0.25rem 0 0; font-size: 1.5rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.25rem; }
.filters button, .regions button {
  height: 2.25rem;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--color-muted);
  box-shadow: inset 0 0 0 1px var(--color-border);
  padding: 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
}
.regions { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.75rem; }
.regions button { height: 2rem; font-size: 0.75rem; box-shadow: none; }
.filters button[aria-pressed="true"], .regions button[aria-pressed="true"] {
  background: var(--color-surface-2);
  color: var(--color-foreground);
}
.commission {
  display: inline-flex;
  align-items: center;
  height: 2.5rem;
  border-radius: 2px;
  background: var(--color-foreground);
  color: var(--color-background);
  padding: 0 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
}
.sample { display: flex; align-items: center; gap: 0.5rem; margin-top: 1rem; font-size: 0.75rem; color: var(--color-muted); }
table { width: 100%; min-width: 52rem; border-collapse: collapse; font-size: 0.875rem; }
.table-wrap { margin-top: 1.25rem; overflow-x: auto; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--color-border); }
th, td { padding: 0.625rem 0.75rem; text-align: left; }
th {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-muted);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
td { border-bottom: 1px solid rgba(34, 34, 51, 0.7); }
tr:nth-child(even) td { background: rgba(20, 25, 32, 0.4); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.sources { max-width: 48rem; }
.card {
  margin-top: 0.75rem;
  border-radius: 8px;
  background: var(--color-surface);
  padding: 0.75rem 1rem;
  box-shadow: inset 0 0 0 1px var(--color-border);
}
.card h3 { margin: 0; font-size: 0.875rem; font-weight: 500; }
.card .when { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-muted); }
.card p { margin: 0.375rem 0 0; font-size: 0.875rem; line-height: 1.6; color: var(--color-muted); }
.card .src { font-size: 0.75rem; }
.page h2 { margin: 2rem 0 0.5rem; font-size: 1.25rem; }
.page p { font-size: 0.875rem; line-height: 1.6; color: var(--color-muted); }
.page ul, .page ol { font-size: 0.875rem; line-height: 1.6; color: var(--color-muted); padding-left: 1.25rem; }
.page strong { color: var(--color-foreground); font-weight: 500; }
.snippet {
  overflow-x: auto;
  border-radius: 8px;
  background: var(--color-surface);
  padding: 1rem;
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-wrap;
  box-shadow: inset 0 0 0 1px var(--color-border);
}
.copy {
  margin-top: 0.75rem;
  border: 0;
  border-radius: 2px;
  background: var(--color-surface-2);
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
}

@media (min-width: 640px) {
  .brand-links { display: block; }
}
@media (min-width: 768px) {
  .topbar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem; padding: 0.75rem 1.5rem; }
  .brand { flex: 0 1 auto; min-width: min(100%, max-content); }
  .brand-name { font-size: 1.25rem; }
  .nav { order: 3; flex: 0 0 auto; }
  .controls { flex: 1 1 16rem; margin-left: auto; max-width: 42rem; min-width: 0; }
  .workspace.with-panel { display: grid; grid-template-columns: minmax(0, 1fr) 22.5rem; }
  .panel { display: flex; }
  .overlay { left: 1rem; right: 1rem; bottom: 1rem; }
}
@media (min-width: 1024px) {
  .workspace.with-panel { grid-template-columns: minmax(0, 1fr) 24.5rem; }
}
@media (max-width: 767px) {
  .ranks-btn { display: inline-flex; }
  .app.show-ranks .panel {
    display: flex;
    position: absolute;
    inset: 0;
    z-index: 40;
    border-left: 0;
  }
  .app.has-selection:not(.show-ranks) .panel {
    display: flex;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    max-height: 70%;
    border-left: 0;
    border-top: 1px solid var(--color-border);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35);
  }
  .page-bar-inner { display: flex; flex-direction: column; gap: 0.75rem; }
}
@media (min-width: 768px) {
  .page-bar-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0 1rem; }
  .page-main { padding: 1.5rem 2rem 2.5rem; }
}
