:root {
  color-scheme: light;
  --ink: #27343e;
  --muted: #5f6d65;
  --paper: #f6f2e9;
  --panel: #f0f8ff;
  --line: #bdc6d8;
  --forest: #1b466d;
  --river: #3e86a0;
  --sun: #f6a313;
  --ember: #c7492d;
  --shadow: 0 24px 70px rgba(28, 40, 32, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Libre Franklin", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(19, 117, 246, 0.18), transparent 28rem),
    linear-gradient(135deg, #f9f9f9 0%, #edf1f4 42%, #e7f0f4 100%);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 430px) 1fr;
  min-height: 100vh;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
  padding: clamp(1.25rem, 3vw, 2.4rem);
  background: rgba(240, 247, 255, 0.92);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 2;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--river);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: "Source Serif 4", serif;
  font-size: clamp(2.45rem, 6vw, 4.5rem);
  line-height: 0.92;
}

.intro {
  max-width: 28rem;
  margin-top: 0.8rem;
  color: var(--muted);
  line-height: 1.55;
}

.home-page {
  display: flex;
  flex-direction: column;
}

.home-shell {
  width: min(100%, 72rem);
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 5rem) clamp(1.25rem, 4vw, 3rem) 2rem;
}

.home-hero {
  min-height: min(52rem, 68vh);
  display: grid;
  align-content: center;
  padding: clamp(1rem, 3vw, 2rem) 0;
}

.home-description {
  max-width: 48rem;
  margin-top: 1.25rem;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  line-height: 1.65;
}

.tools-section {
  position: relative;
  padding: clamp(1.4rem, 4vw, 2.25rem) 0 clamp(2.5rem, 6vw, 5rem);
  border-top: 1px solid rgba(189, 204, 216, 0.85);
}

.tools-section::before {
  position: absolute;
  top: -1px;
  left: 0;
  width: 8rem;
  height: 3px;
  background: linear-gradient(90deg, var(--forest), var(--river), var(--sun));
  content: "";
}

.tools-section .section-heading {
  margin-bottom: 1rem;
}

.tools-section h2 {
  color: var(--forest);
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  font-weight: 800;
}

.tool-link {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem 1.25rem;
  max-width: 42rem;
  padding: clamp(1.15rem, 3vw, 1.6rem);
  color: inherit;
  text-decoration: none;
  background: rgba(240, 247, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(28, 35, 40, 0.1);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.tool-link::after {
  display: grid;
  width: 2.3rem;
  height: 2.3rem;
  grid-row: 1 / span 2;
  grid-column: 2;
  place-items: center;
  align-self: center;
  color: white;
  font-size: 1.15rem;
  font-weight: 800;
  background: var(--forest);
  border-radius: 50%;
  content: ">";
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.tool-link:hover,
.tool-link:focus-visible {
  border-color: rgba(13, 49, 77, 0.42);
  box-shadow: 0 22px 55px rgba(28, 36, 40, 0.15);
  transform: translateY(-2px);
}

.tool-link:hover::after,
.tool-link:focus-visible::after {
  background: var(--river);
  transform: translateX(2px);
}

.tool-link:focus-visible {
  outline: 3px solid rgba(27, 127, 143, 0.32);
  outline-offset: 3px;
}

.tool-title {
  grid-column: 1;
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 800;
}

.tool-description {
  grid-column: 1;
  max-width: 36rem;
  color: var(--muted);
  line-height: 1.6;
}

.site-footer {
  margin-top: auto;
  padding: 1.25rem clamp(1.25rem, 4vw, 3rem);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.55;
  background: rgba(240, 246, 255, 0.76);
  border-top: 1px solid var(--line);
}

.site-footer p {
  max-width: 72rem;
  margin: 0 auto;
}

.controls {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

.field select {
  min-height: 2.8rem;
  padding: 0 0.8rem;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-transform: none;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toggle-field {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.toggle-field input {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  accent-color: var(--forest);
}

.year-row {
  display: grid;
  grid-template-columns: 1fr 4.5rem;
  gap: 0.8rem;
  align-items: center;
}

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

output {
  display: grid;
  min-height: 2.8rem;
  place-items: center;
  color: white;
  font-size: 1.05rem;
  font-weight: 800;
  background: var(--forest);
  border-radius: 8px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
}

.stats div {
  min-width: 0;
  padding: 0.85rem;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats span,
.section-heading span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stats strong {
  display: block;
  margin-top: 0.25rem;
  overflow-wrap: anywhere;
  font-size: clamp(1.05rem, 2vw, 1.45rem);
}

.details {
  min-height: 0;
}

.details h5 {
  margin: 1rem 0 0.45rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.details ul {
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.details li {
  min-width: 0;
}

.details a {
  display: block;
  padding: 0.7rem 0.8rem;
  overflow: hidden;
  color: var(--forest);
  font-size: 0.86rem;
  font-weight: 800;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.details a:hover,
.details a:focus-visible {
  color: var(--river);
  background: white;
  border-color: rgba(27, 127, 143, 0.38);
  transform: translateY(-1px);
}

.details a:focus-visible {
  outline: 3px solid rgba(27, 127, 143, 0.28);
  outline-offset: 2px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

h2 {
  font-size: 1rem;
}

.rank-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-value {
  color: var(--ember);
  font-weight: 800;
}

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

#map {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  background: #dfe3e9;
}

.legend {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  gap: 0.55rem;
  align-items: center;
  padding: 0.65rem 0.75rem;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  background: rgba(240, 247, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
  z-index: 500;
}

.legend-ramp {
  width: 8rem;
  height: 0.7rem;
  background: linear-gradient(90deg, #2f9c95, #f2b33d, #c7492d);
  border-radius: 999px;
}

.department-caption {
  width: 5.8rem !important;
  height: auto !important;
  margin-left: -2.9rem !important;
  margin-top: -0.9rem !important;
  color: #1d2024;
  font-family: "Libre Franklin", sans-serif;
  line-height: 1.1;
  pointer-events: none;
  text-align: center;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.86),
    1px 0 0 rgba(255, 255, 255, 0.86),
    0 -1px 0 rgba(255, 255, 255, 0.86),
    -1px 0 0 rgba(255, 255, 255, 0.86);
}

.department-caption-name,
.department-caption-value {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.department-caption-name {
  font-size: 0.48rem;
  font-weight: 800;
}

.department-caption-value {
  margin-top: 0.08rem;
  color: var(--ember);
  font-size: 0.44rem;
  font-weight: 800;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  color: var(--ink);
  font-family: "Libre Franklin", sans-serif;
}

.popup-title {
  margin-bottom: 0.25rem;
  font-weight: 800;
}

.popup-value {
  color: var(--ember);
  font-size: 1.25rem;
  font-weight: 800;
}

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

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-panel,
  #map {
    min-height: 62vh;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .department-caption {
    width: 4.8rem !important;
    margin-left: -2.4rem !important;
  }

  .department-caption-name {
    font-size: 0.52rem;
  }

  .department-caption-value {
    font-size: 0.5rem;
  }
}
