:root {
  --surface: rgba(12, 18, 28, 0.9);
  --surface-solid: #0f1722;
  --text: #e4ebf3;
  --muted: #8b9aab;
  --hover: rgba(255, 255, 255, 0.08);
  --accent: #5a9cd0;
}

html, body, #map {
  margin: 0;
  height: 100%;
}

body,
.mapboxgl-map {
  font: 13px/1.45 'Quattrocento Sans', system-ui, sans-serif;
  background: #08101c;
  color: var(--text);
}

#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 250px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  color: var(--text);
  accent-color: var(--accent);
}

/* On narrow screens the panel docks below the map at full width and scrolls on its own,
   so the map and its controls stay uncovered. */
@media (max-width: 600px) {
  body {
    display: flex;
    flex-direction: column;
  }

  #map {
    flex: 1;
    min-height: 0;
    height: auto;
  }

  #panel {
    position: static;
    flex: none;
    width: auto;
    max-height: 45dvh;
    overflow-y: auto;
    background: var(--surface-solid);
    border-radius: 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.4);
  }

  /* The two place lists sit side by side, headings on a shared row so the lists line up. */
  .places {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto;
    grid-auto-flow: column;
    column-gap: 12px;
  }

  .places .extremes button {
    white-space: normal;
  }

  /* Terrain toggle and legend share a row, as do the credit and the Stamen logo. */
  .controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 14px;
  }

  .controls .switch {
    flex: none;
    margin: 0 !important;
  }

  .controls #legend {
    flex: 1;
    min-width: 0;
    margin-top: 0;
  }

  .credit {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .credit p {
    margin: 0;
  }

  .credit a {
    flex: none;
  }
}

#panel h1 {
  display: inline-block;
  margin: 0 0 8px;
  font-family: 'Orbitron', system-ui, sans-serif;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.02em;
  transform: rotate(180deg);
  transition: transform 0.7s cubic-bezier(0.34, 1.4, 0.64, 1);
  cursor: default;
}

/* Spin the upside-down title the rest of the way round, so it lands right side up. */
#panel h1:hover {
  transform: rotate(360deg);
}

@media (prefers-reduced-motion: reduce) {
  #panel h1 {
    transition: none;
  }
}

#panel .description {
  margin: 0 0 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

#panel label {
  display: block;
  margin: 4px 0;
  cursor: pointer;
}

/* A checkbox drawn as a sliding switch. */
.switch {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin-top: 14px !important;
}

.switch input {
  appearance: none;
  position: relative;
  flex: none;
  width: 30px;
  height: 17px;
  margin: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.18);
  cursor: pointer;
  transition: background 0.2s;
}

.switch input::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.2s;
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::before {
  transform: translateX(13px);
}

.switch input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .switch input,
  .switch input::before {
    transition: none;
  }
}

#panel h2 {
  margin: 12px 0 4px;
  font-size: 12px;
  font-weight: 700;
}

.extremes button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 3px 6px;
  border: 0;
  border-radius: 3px;
  background: none;
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.extremes button:hover,
.extremes button:focus-visible {
  background: var(--hover);
}

/* Heights appear only on hover or keyboard focus. */
.extremes .value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.12s;
}

.extremes button:hover .value,
.extremes button:focus-visible .value {
  opacity: 1;
}

#legend {
  margin-top: 10px;
}

#legend .bar {
  height: 10px;
  border-radius: 2px;
}

/* Tick marks under the bar, one per label. */
#legend .marks {
  position: relative;
  height: 5px;
}

#legend .marks i {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: #fff;
}

#legend .ticks {
  position: relative;
  height: 15px;
  font-size: 11px;
  color: var(--muted);
}

#legend .ticks span {
  position: absolute;
  top: 0;
}

.credit {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 11.5px;
  color: var(--muted);
}

.credit p {
  margin: 0 0 6px;
}

.credit a {
  display: inline-block;
}

.credit img {
  display: block;
  height: 14px;
}

.credit a:hover img,
.credit a:focus-visible img {
  opacity: 0.8;
}

/* Dark Mapbox controls. */
.mapboxgl-ctrl-group:not(:empty) {
  background: var(--surface-solid);
}

.mapboxgl-ctrl-group button + button {
  border-top-color: rgba(255, 255, 255, 0.12);
}

.mapboxgl-ctrl-group button .mapboxgl-ctrl-icon {
  filter: invert(1);
}

.mapboxgl-ctrl-scale {
  background: rgba(12, 18, 28, 0.7);
  border-color: var(--muted);
  color: var(--text);
}

.mapboxgl-ctrl.mapboxgl-ctrl-attrib {
  background: rgba(12, 18, 28, 0.7);
}

.mapboxgl-ctrl-attrib,
.mapboxgl-ctrl-attrib a {
  color: var(--muted);
}
