:root {
  --bg-1: #eef4ff;
  --bg-2: #c2dfff;
  --ink: #0f1f38;
  --ink-soft: #33496b;
  --panel: #ffffff;
  --panel-shadow: 0 18px 40px rgba(12, 42, 88, 0.14);
  --line: #cad8ef;
  --accent: #1f67d2;
  --accent-soft: #4e8df2;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Source Sans 3", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(117, 180, 255, 0.38), transparent 34%),
    radial-gradient(circle at 90% 30%, rgba(255, 255, 255, 0.9), transparent 40%),
    linear-gradient(140deg, var(--bg-1), var(--bg-2));
}

body.is-sources-modal-open {
  overflow: hidden;
}

.page-shell {
  min-height: 100%;
  padding: 1rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: 340px 1fr;
}

.control-panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--panel-shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  min-height: calc(100vh - 2rem);
}

h1,
h2 {
  font-family: "Space Grotesk", sans-serif;
  margin: 0;
}

h1 {
  font-size: 1.35rem;
  line-height: 1.2;
}

h2 {
  font-size: 1.05rem;
}

.intro {
  margin: 0;
  color: var(--ink-soft);
}

label {
  font-weight: 700;
  font-size: 0.95rem;
}

select,
input[type="range"],
button {
  width: 100%;
}

select {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 0.5rem;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.control-stack {
  display: grid;
  gap: 0.7rem;
  margin-top: 0.6rem;
}

.metric-select-wrap {
  display: grid;
  gap: 0.35rem;
}

.range-wrap {
  display: grid;
  gap: 0.35rem;
}

.is-hidden {
  display: none !important;
}

output {
  font-weight: 700;
  color: var(--accent);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
}

button:hover {
  filter: brightness(1.03);
}

.legend,
.state-details {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7faff;
  padding: 0.75rem;
}

.legend {
  display: grid;
  gap: 0.35rem;
}

.legend-scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #bccff3;
}

.legend-swatch {
  height: 12px;
}

.legend-range {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.legend-koppen-list {
  display: grid;
  gap: 0.3rem;
}

.legend-koppen-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
}

.legend-koppen-row-selected {
  font-weight: 700;
}

.legend-koppen-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(20, 45, 84, 0.22);
}

.state-details p {
  margin: 0.3rem 0;
}

.control-panel-spacer {
  flex: 1 1 auto;
  min-height: 2rem;
}

.sources-control {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.sources-modal[hidden] {
  display: none;
}

.sources-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.sources-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 103, 210, 0.36);
  backdrop-filter: blur(2px);
}

.sources-dialog {
  position: relative;
  z-index: 1;
  width: min(940px, calc(100vw - 2rem));
  max-height: min(82vh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(202, 216, 239, 0.95);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 28px 70px rgba(7, 24, 51, 0.34);
}

.sources-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.85rem;
  border-bottom: 1px solid var(--line);
}

.sources-dialog-header h2 {
  font-size: 1.25rem;
}

.sources-close-button {
  width: 2.5rem;
  height: 2.5rem;
  min-width: 0;
  padding: 0;
  border-radius: 8px;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(12, 42, 88, 0.18);
}

.sources-modal-content {
  overflow: auto;
  padding: 0 1rem 1rem;
}

.source-entry {
  display: grid;
  gap: 0.35rem;
  padding: 0.95rem 0 1rem;
  border-top: 1px solid var(--line);
}

.source-entry:first-child {
  border-top: 0;
}

.source-entry h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
}

.source-entry p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.35;
}

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

.map-panel {
  min-height: 70vh;
  position: relative;
}

#map {
  height: 100%;
  min-height: 70vh;
  border-radius: 18px;
  border: 1px solid rgba(17, 52, 99, 0.2);
  overflow: hidden;
  box-shadow: var(--panel-shadow);
}

.metric-info-panel,
.legend-info-panel {
  position: absolute;
  z-index: 500;
  width: min(320px, calc(100% - 2rem));
  display: grid;
  gap: 0.5rem;
  pointer-events: none;
}

.metric-info-panel {
  top: 1rem;
  right: 1rem;
}

.legend-info-panel {
  bottom: 1rem;
  left: 1rem;
}

.metric-info-toggle,
.legend-info-toggle,
.metric-info-panel .state-details,
.legend-info-panel .legend {
  pointer-events: auto;
}

.metric-info-toggle,
.legend-info-toggle {
  justify-self: end;
  width: auto;
  min-width: 148px;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(12, 42, 88, 0.18);
}

.legend-info-toggle {
  justify-self: start;
}

.metric-info-panel.is-collapsed .state-details,
.legend-info-panel.is-collapsed .legend {
  display: none;
}

.metric-info-panel .state-details,
.legend-info-panel .legend {
  max-height: min(58vh, 430px);
  overflow: auto;
  box-shadow: var(--panel-shadow);
}

.leaflet-control-attribution,
.leaflet-control-attribution * {
  user-select: none;
  -webkit-user-select: none;
}

.leaflet-control-attribution {
  -webkit-tap-highlight-color: transparent;
}

.is-map-dragging .leaflet-tooltip {
  display: none;
}

.is-map-dragging .leaflet-interactive:focus {
  outline: none;
}

@media (max-width: 980px) {
  .page-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    order: 2;
    min-height: calc(100vh - 2rem);
  }

  .map-panel {
    order: 1;
    min-height: 62vh;
  }

  #map {
    min-height: 62vh;
  }

  .metric-info-panel,
  .legend-info-panel {
    top: 0.75rem;
    width: min(300px, calc(100% - 1.5rem));
  }

  .metric-info-panel {
    right: 0.75rem;
  }

  .legend-info-panel {
    top: auto;
    bottom: 0.75rem;
    left: 0.75rem;
  }

  .sources-dialog {
    width: calc(100vw - 1rem);
    max-height: calc(100vh - 1rem);
    border-radius: 14px;
  }

  .sources-dialog-header,
  .sources-modal-content {
    padding-left: 0.8rem;
    padding-right: 0.8rem;
  }
}
