:root {
  --surface: rgba(255, 255, 255, 0.95);
  --text: #1f2328;
  --muted: #5f6873;
  --line: rgba(31, 35, 40, 0.14);
  --hover: rgba(31, 35, 40, 0.06);
  --accent: #1f6feb;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 6px 20px rgba(0, 0, 0, 0.1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: rgba(28, 31, 36, 0.95);
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --line: rgba(230, 232, 235, 0.16);
    --hover: rgba(230, 232, 235, 0.08);
    --accent: #58a6ff;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #dfe3e8;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
}

#map {
  position: absolute;
  inset: 0;
}

.maplibregl-canvas-container.maplibregl-interactive,
.maplibregl-canvas-container.maplibregl-interactive:active {
  cursor: default;
}

.panel,
.legend,
.card {
  position: absolute;
  z-index: 2;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 10px;
  backdrop-filter: blur(6px);
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

select,
input[type="number"] {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
}

input[type="range"] {
  accent-color: var(--accent);
}

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

/* The controls */

.panel {
  top: 10px;
  left: 10px;
  width: 290px;
  max-height: calc(100% - 50px);
  overflow: auto;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: 10px 10px 0 0;
  z-index: 1;
}

.panel h1 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.collapse,
.add-filter,
.show-all {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
}

.collapse:hover,
.add-filter:hover,
.show-all:hover {
  background: var(--hover);
}

.panel.closed .panel-body {
  display: none;
}

.panel-body {
  padding: 0 12px 12px;
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  gap: 4px;
}

.field[hidden] {
  display: none;
}

.field > .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.field:has(> input[type="range"]) {
  grid-template-columns: 1fr auto;
}

.field:has(> input[type="range"]) > .label {
  grid-column: 1 / -1;
}

output {
  min-width: 3.5em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 3px 8px;
  cursor: pointer;
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.segmented button[aria-pressed="true"] {
  background: var(--text);
  color: var(--surface);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 10px;
  cursor: pointer;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 3px 2px;
}

.chip {
  cursor: pointer;
  border: 0;
  padding: 0;
}

.chip.ramp {
  width: 44px;
  height: 16px;
  border-radius: 4px;
}

.chip.scheme {
  display: grid;
  grid-template-columns: repeat(3, 9px);
  gap: 1px;
  background: transparent;
}

.chip.scheme i {
  display: block;
  width: 9px;
  height: 9px;
}

.chip[aria-pressed="true"] {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: 4px;
}

.about summary,
.scale-box summary {
  cursor: pointer;
  color: var(--muted);
}

.about-layer {
  margin-top: 4px;
}

.about-layer p {
  margin: 0 0 4px;
}

.about-layer .sources,
.hint,
.build {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.scale-box {
  display: grid;
  gap: 8px;
}

.scale-box > .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.scale-box[open] > :not(summary) {
  margin-top: 8px;
}

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

.boxes {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.boxes input {
  width: 100%;
  min-width: 0;
}

.filters h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.filter-list {
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
}

.filter {
  display: grid;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filter-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.filter select {
  min-width: 0;
}

.remove {
  border: 0;
  background: transparent;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.dual {
  position: relative;
  height: 24px;
}

.dual .track,
.dual .fill {
  position: absolute;
  top: 10px;
  height: 4px;
  border-radius: 2px;
}

.dual .track {
  left: 0;
  right: 0;
  background: var(--line);
}

.dual .fill {
  background: var(--accent);
}

.dual input {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  background: none;
  pointer-events: none;
  appearance: none;
  -webkit-appearance: none;
}

.dual input::-webkit-slider-runnable-track {
  background: none;
}

.dual input::-moz-range-track {
  background: none;
}

.dual input::-webkit-slider-thumb {
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: grab;
}

.dual input::-moz-range-thumb {
  pointer-events: auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: grab;
}

.filter.loading .dual {
  opacity: 0.4;
}

.overlays {
  display: grid;
  gap: 8px;
}

.overlays > .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.overlay-head {
  display: grid;
  grid-template-columns: 1fr 96px auto;
  align-items: center;
  gap: 6px;
}

.overlay-head .check {
  margin-right: 0;
}

.overlay-details[hidden] {
  display: none;
}

.swatches {
  list-style: none;
  margin: 4px 0 4px 20px;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 8px;
  font-size: 12px;
}

.swatches li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatches i {
  flex: none;
  width: 14px;
  height: 10px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px var(--line);
}

.overlay .hint {
  margin-left: 20px;
}

/* The legend */

.legend {
  right: 10px;
  bottom: 34px;
  width: 250px;
  padding: 10px 12px;
}

.legend.pair {
  width: 300px;
}

.legend-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
  cursor: pointer;
}

.legend.folded :is(.legend-axes, .legend-body, .legend-note) {
  display: none;
}

.legend-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.legend-unit {
  color: var(--muted);
}

.spinner {
  margin-left: auto;
  width: 10px;
  height: 10px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  visibility: hidden;
}

.legend.busy .spinner {
  visibility: visible;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.legend-axes .axis {
  margin: 0 0 2px;
}

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

.bins {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
}

.bin {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 2px 6px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.bin:hover {
  background: var(--hover);
}

.bin.active {
  box-shadow: inset 0 0 0 1.5px var(--text);
}

.swatch {
  display: block;
  width: 24px;
  height: 14px;
  border-radius: 3px;
}

.range,
.count {
  font-variant-numeric: tabular-nums;
}

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

.bin.off .swatch,
.class.off {
  opacity: 0.25;
}

.bin.off .range,
.bin.off .count {
  text-decoration: line-through;
  color: var(--muted);
}

.matrix {
  display: grid;
  gap: 2px;
  margin: 6px 0 2px;
}

.class {
  aspect-ratio: 1.3;
  border: 0;
  border-radius: 4px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.class.active {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.class.off {
  text-decoration: line-through;
}

.tick {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tick-y {
  align-self: end;
  justify-self: end;
  transform: translateY(50%);
  padding-right: 4px;
}

.tick-x {
  justify-self: start;
  transform: translateX(-50%);
}

.legend-note {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.show-all {
  font-size: 12px;
  padding: 0 6px;
}

.readout {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  min-height: 2.8em;
  font-variant-numeric: tabular-nums;
}

.readout strong {
  font-size: 14px;
}

/* The square kilometre that was clicked */

.card {
  top: 10px;
  right: 50px;
  width: 440px;
  max-height: calc(100% - 300px);
  overflow: auto;
  padding: 10px 12px;
}

.card[hidden] {
  display: none;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.card h2 {
  margin: 0;
  font-size: 13px;
}

.card p {
  margin: 2px 0 8px;
  font-size: 12px;
}

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

.close {
  border: 0;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.values {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.values th {
  text-align: left;
  font-weight: normal;
  color: var(--muted);
  padding: 2px 8px 2px 0;
}

.values td {
  text-align: right;
  white-space: nowrap;
  padding: 2px 0 2px 8px;
}

.values td.muted {
  font-size: 12px;
}

.failure {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 480px;
  padding: 16px 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 10px;
}

@media (max-width: 720px) {
  .panel {
    width: calc(100% - 20px);
    max-height: 60%;
  }

  .legend,
  .legend.pair {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: 30px;
  }

  .card {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: 30px;
    width: auto;
    max-height: 50%;
    z-index: 4;
  }
}
