:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ee;
  --border: #dddcd7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --accent: #2a78d6;
  /* Tree colours: reference palette slots 1-3, which validate all-pairs */
  --tree-native: #1baf7a;
  --tree-introduced: #eb6834;
  --tree-highlight: #2a78d6;
  --tree-other: #a9a8a2;
  --outline: #3d3c39;
  --outside: #8f8e88;
  --pass: #008300;
  --fail: #c62f2e;
  /* Neighbourhood views. Effective number of species: a sequential blue scale */
  --species-low: #cde2fb;
  --species-high: #0d366b;
  /* 10-20-30 rule: an ordinal violet ramp for passing 0, 1, 2 and 3 parts */
  --rule-0: #b3a9ee;
  --rule-1: #8577e0;
  --rule-2: #5c49c9;
  --rule-3: #36278f;
  /* Trees per 1,000 people: an ordinal green ramp, one step per bin */
  --density-0: #82c38f;
  --density-1: #51a667;
  --density-2: #2e8548;
  --density-3: #1d6333;
  --density-4: #114320;
  /* Classification: the same colours as the charts in output/ */
  --class-nia: #843753;
  --class-emerging: #bd4c07;
  --class-other: #499e74;
  --panel-width: 380px;
  --insights-width: 300px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #242423;
    --border: #3a3a38;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #96958d;
    --accent: #3987e5;
    --tree-native: #199e70;
    --tree-introduced: #d95926;
    --tree-highlight: #3987e5;
    --tree-other: #5e5d58;
    --outline: #d6d5cf;
    --outside: #000000;
    --pass: #3fa63f;
    --fail: #e66767;
    --species-low: #16345c;
    --species-high: #b7d3f6;
    --rule-0: #5043a3;
    --rule-1: #7065d0;
    --rule-2: #9793e6;
    --rule-3: #c5c5f7;
    --density-0: #2b6339;
    --density-1: #3e8651;
    --density-2: #59aa6d;
    --density-3: #88ca95;
    --density-4: #c0e7c6;
    --class-nia: #c274a9;
    --class-emerging: #d55a12;
    --class-other: #3a9468;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #242423;
  --border: #3a3a38;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #96958d;
  --accent: #3987e5;
  --tree-native: #199e70;
  --tree-introduced: #d95926;
  --tree-highlight: #3987e5;
  --tree-other: #5e5d58;
  --outline: #d6d5cf;
  --outside: #000000;
  --pass: #3fa63f;
  --fail: #e66767;
  --species-low: #16345c;
  --species-high: #b7d3f6;
  --rule-0: #5043a3;
  --rule-1: #7065d0;
  --rule-2: #9793e6;
  --rule-3: #c5c5f7;
  --density-0: #2b6339;
  --density-1: #3e8651;
  --density-2: #59aa6d;
  --density-3: #88ca95;
  --density-4: #c0e7c6;
  --class-nia: #c274a9;
  --class-emerging: #d55a12;
  --class-other: #3a9468;
}

* {
  box-sizing: border-box;
}

/* Elements given a display below still hide when hidden */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--surface-1);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#map {
  position: absolute;
  inset: 0 0 0 var(--panel-width);
}

#panel {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--panel-width);
  overflow-y: auto;
  padding: 20px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

@media (max-width: 720px) {
  #map {
    inset: 0 0 45vh 0;
  }
  #panel {
    inset: auto 0 0 0;
    width: auto;
    height: 45vh;
    padding: 16px;
    border-right: 0;
    border-top: 1px solid var(--border);
  }
}

h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

h2 {
  font-size: 18px;
  margin: 0;
}

h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

p {
  margin: 0;
}

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

.muted {
  color: var(--text-muted);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

select,
button {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

button {
  cursor: pointer;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend .value {
  margin-left: auto;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

#stats {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.area-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.area-header button {
  margin-left: auto;
  padding: 3px 8px;
  font-size: 12px;
}

.tag {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tile {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
}

.tile .value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tile .label {
  font-size: 11px;
  color: var(--text-secondary);
}

.tile .compare {
  font-size: 11px;
  color: var(--text-muted);
}

.rules {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rules li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  align-items: baseline;
}

.status {
  font-weight: 600;
  white-space: nowrap;
}

.status.pass {
  color: var(--pass);
}

.status.fail {
  color: var(--fail);
}

.rules .detail {
  grid-column: 2;
  color: var(--text-secondary);
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.tabs button {
  padding: 3px 10px;
  font-size: 12px;
  background: transparent;
}

.tabs button[aria-pressed="true"] {
  background: var(--surface-2);
  font-weight: 600;
}

.bars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.bar-label .value {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.bar-label i {
  color: var(--text-muted);
  font-size: 12px;
}

.bar-track {
  position: relative;
  height: 8px;
  margin-top: 3px;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
}

.bar-limit {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 0;
  border-left: 1.5px dashed var(--text-secondary);
}

.note {
  font-size: 12px;
  color: var(--text-muted);
}

.map-button {
  padding: 7px 12px;
  font-weight: 600;
  background: var(--surface-1);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
}

/* Beats MapLibre's see-through hover background on control buttons */
.maplibregl-ctrl button.map-button:not(:disabled):hover {
  background: var(--surface-2);
}

.map-button[hidden] {
  display: none;
}

#insights {
  position: absolute;
  inset: 0 0 0 auto;
  width: var(--insights-width);
  overflow-y: auto;
  padding: 20px;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  display: none;
  flex-direction: column;
  gap: 18px;
}

.insights-open #insights {
  display: flex;
}

.insights-open #map {
  right: var(--insights-width);
}

@media (max-width: 720px) {
  /* On phones the list covers the map instead of squeezing it */
  #insights {
    inset: 0 0 45vh 0;
    width: auto;
    z-index: 6;
    border-left: 0;
    padding: 16px;
  }
  .insights-open #map {
    right: 0;
  }
}

.insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.insights-header button {
  padding: 2px 8px;
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.insights-header button:hover {
  background: var(--surface-2);
}

#insights-body {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

#insights section .note {
  margin-bottom: 6px;
}

.insight-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  counter-reset: insight;
}

.insight-list li {
  counter-increment: insight;
}

.insight-list button {
  width: 100%;
  display: grid;
  grid-template-columns: 1.4em 1fr auto;
  gap: 0 6px;
  text-align: left;
  background: transparent;
  border-color: transparent;
  padding: 5px 6px;
}

.insight-list button::before {
  content: counter(insight);
  grid-row: span 2;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.insight-list button:hover,
.insight-list button[aria-current="true"] {
  background: var(--surface-2);
}

.insight-list button[aria-current="true"] {
  border-color: var(--border);
}

.insight-list .name {
  font-weight: 500;
}

.insight-list .value {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.insight-list .detail {
  grid-column: 2 / 4;
  font-size: 12px;
  color: var(--text-muted);
}

#tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  max-width: 260px;
  padding: 6px 9px;
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
  font-size: 12px;
}

#tooltip .muted {
  font-size: 11px;
}

#loading {
  position: absolute;
  z-index: 5;
  top: 12px;
  left: calc(var(--panel-width) + 12px);
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  font-size: 12px;
}

@media (max-width: 720px) {
  #loading {
    left: 12px;
  }
}

footer {
  margin-top: auto;
  font-size: 11px;
}

/* Neighbourhood views: colour bars, area swatches and the labels for the highest and
   lowest neighbourhoods */

.swatch.area {
  border-radius: 2px;
}

.legend .detail {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
}

#view-legend .legend {
  margin-bottom: 8px;
}

.scale-bar {
  height: 12px;
  border-radius: 4px;
}

.scale-ticks {
  display: flex;
  justify-content: space-between;
  margin: 4px 0 8px;
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

#callouts {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}

#callouts svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#callouts line {
  stroke: var(--outline);
  stroke-width: 1;
}

#callouts circle {
  fill: var(--outline);
  stroke: var(--surface-1);
  stroke-width: 1.5;
}

.callout {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 7px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: auto;
  background: var(--surface-1);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.15);
}

.callout:hover {
  background: var(--surface-2);
}

.callout .value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
