:root {
  --color-fg: #1f2328;
  --color-fg-muted: #57606a;
  --color-bg: #ffffff;
  --color-bg-muted: #f6f8fa;
  --color-border: #d0d7de;
  --color-accent: #2166ac;
  --color-accent-soft: rgba(33, 102, 172, 0.18);
  --max-width: 1100px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--color-bg);
  color: var(--color-fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.container { max-width: var(--max-width); margin: 0 auto; padding: 0 18px; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--color-border);
}
.app-title { font-weight: 600; font-size: 17px; }
.app-nav { display: flex; gap: 18px; font-size: 15px; align-items: center; }
.app-nav a { color: var(--color-fg-muted); text-decoration: none; }
.app-nav a.active { color: var(--color-accent); font-weight: 600; }
.app-nav a:hover { color: var(--color-fg); }

.app-nav-group { position: relative; display: inline-block; }
.app-nav-toggle {
  cursor: pointer; user-select: none; display: inline-block;
  white-space: nowrap;
}
.app-nav-toggle:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: 2px; }
.app-nav-menu {
  position: absolute; top: 100%; left: -8px; min-width: 200px;
  background: #fff; border: 1px solid var(--color-border); border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  /* Extra top padding gives the menu a sticky landing zone so the mouse
     does not leave the dropdown while crossing from the toggle. */
  padding: 8px 0 4px; margin-top: 4px; z-index: 100;
  display: flex; flex-direction: column;
}
/* Invisible bridge between the toggle and the menu so the mouse stays
   inside the group while traversing the small visual gap. */
.app-nav-group.open .app-nav-toggle::after {
  content: ""; position: absolute; left: 0; right: 0;
  top: 100%; height: 12px;
}
.app-nav-menu[hidden] { display: none; }
.app-nav-menu a {
  padding: 8px 16px; font-size: 14px; line-height: 1.35;
  color: var(--color-fg-muted); text-decoration: none; white-space: nowrap;
}
.app-nav-menu a.active { color: var(--color-accent); font-weight: 600; }
.app-nav-menu a:hover { background: var(--color-bg-muted); color: var(--color-fg); }

.app-intro { margin: 32px 0 24px; }
.app-intro-body {
  max-width: 700px;
  margin: 0 auto 14px;
  font-size: 16px;
  line-height: 1.7;
  color: var(--color-fg);
}
.app-intro-body:last-of-type { margin-bottom: 22px; }
.app-intro-meta {
  text-align: center;
  font-size: 14px;
  color: var(--color-fg-muted);
  margin: 0;
  padding: 16px 0 4px;
  border-top: 1px solid var(--color-border);
  line-height: 1.9;
}
.app-intro-meta > span { display: inline-block; white-space: nowrap; }
.app-intro-meta strong { color: var(--color-fg); font-weight: 600; }
.app-intro-meta .sep { margin: 0 14px; color: var(--color-border); }
@media (max-width: 700px) {
  .app-intro-meta .sep { display: none; }
  .app-intro-meta > span { display: block; }
}

.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 10px 12px; background: var(--color-bg-muted);
  border: 1px solid var(--color-border); border-radius: 6px;
  margin: 16px 0 12px;
}
.picker-wrap { position: relative; min-width: 220px; }
.picker {
  width: 100%; padding: 5px 8px; font-size: 13px;
  border: 1px solid var(--color-border); border-radius: 4px; background: #fff;
  font-family: inherit; color: inherit;
}
.picker:focus { outline: 2px solid var(--color-accent); outline-offset: -1px; }
.picker.compare-mode { border-color: var(--color-accent); }
.picker-list {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0; z-index: 50;
  list-style: none; margin: 0; padding: 4px 0;
  background: #fff; border: 1px solid var(--color-border); border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  max-height: 320px; overflow-y: auto;
  font-size: 13px;
}
.picker-list[hidden] { display: none; }
.picker-item {
  padding: 4px 10px; cursor: pointer; white-space: nowrap;
  display: flex; justify-content: space-between; gap: 12px;
}
.picker-item .iso { color: var(--color-fg-muted); font-size: 11px; }
.picker-item.active, .picker-item:hover {
  background: var(--color-accent); color: #fff;
}
.picker-item.active .iso, .picker-item:hover .iso { color: rgba(255,255,255,0.85); }
.picker-empty { padding: 8px 10px; color: var(--color-fg-muted); font-style: italic; }
.toggle {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--color-fg-muted); cursor: pointer;
}

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 11px; font-size: 12px; font-weight: 500;
  border: 1px solid; background: #fff;
  margin-right: 4px;
}
.pill.primary { border-width: 1.5px; box-shadow: 0 0 0 1px currentColor inset; }
.pill .x { cursor: pointer; opacity: 0.55; font-weight: 700; }
.pill .x:hover { opacity: 1; }
.pill.add {
  background: #ddf4ff; border-color: #54aeff; color: #0969da; cursor: pointer;
}
#pick-random { margin-left: auto; }

#chart { width: 100%; height: 380px; }

/* Courts vs Parliament page intro: same visual weight as the explore
   page intro, narrower max width so the chart can sit closer to square
   without the prose looking like a stub. */
.bivar-intro { margin: 26px 0 16px; }
.bivar-intro-body {
  max-width: 720px;
  margin: 0 auto;
  font-size: 15px;
  line-height: 1.65;
  color: var(--color-fg);
}

/* Square chart on desktop; clamps on narrow viewports. The container
   reserves a 1:1 aspect ratio so the 45-degree reference line reads at
   45 degrees and the cloud isn't distorted. */
#chart.bivar-chart {
  width: 100%;
  max-width: 720px;
  height: 720px;
  margin: 6px auto 0;
}
@media (max-width: 760px) {
  #chart.bivar-chart { height: 520px; max-width: 100%; }
}
@media (max-width: 480px) {
  #chart.bivar-chart { height: 380px; }
}

/* Trust-gap page: landscape chart since the x-axis is time. */
.gap-intro { margin: 26px 0 16px; }
.gap-intro-body {
  max-width: 760px;
  margin: 0 auto;
  font-size: 15px;
  line-height: 1.65;
  color: var(--color-fg);
}
#chart.gap-chart {
  width: 100%;
  height: 480px;
  margin: 6px auto 0;
}
@media (max-width: 760px) {
  #chart.gap-chart { height: 380px; }
}
@media (max-width: 480px) {
  #chart.gap-chart { height: 320px; }
}

.caption {
  margin-top: 10px; font-size: 12px; color: var(--color-fg-muted);
}

.cite {
  margin: 28px 0 32px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
  font-size: 12px; line-height: 1.5;
  color: var(--color-fg-muted);
  font-style: italic;
}
.cite a {
  color: var(--color-accent); text-decoration: none;
  font-style: normal; font-weight: 500;
}
.cite a:hover { text-decoration: underline; }

.error-banner {
  background: #fff8f0; border: 1px solid #d0915a; border-radius: 4px;
  padding: 10px 14px; color: #884b1c; font-size: 13px;
}

@media (max-width: 700px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  #chart { height: 280px; }
}
