:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --panel: #ffffff;
  --ink: #1d2528;
  --muted: #617074;
  --line: #d7ddd7;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --sun: #f6c453;
  --ember: #d9480f;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(23, 35, 38, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(330px, 0.55fr) minmax(760px, 1.45fr);
  gap: 24px;
  align-items: end;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  z-index: 500;
}

.brand-kicker,
.panel-kicker,
legend,
.metric span,
.data-credit,
.chart-header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 4px;
  min-height: 2.1em;
  display: flex;
  align-items: end;
  font-size: clamp(24px, 2.4vw, 34px);
  line-height: 1.05;
  text-wrap: balance;
}

h2 {
  margin-top: 4px;
  font-size: 28px;
  line-height: 1.1;
}

h3 {
  font-size: 15px;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(250px, 0.95fr) minmax(235px, 0.85fr) minmax(250px, 1fr) 72px;
  gap: 12px;
  align-items: end;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 7px;
}

.segmented {
  min-width: 0;
}

.segmented button,
.icon-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.segmented {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}

.segmented legend {
  flex-basis: 100%;
}

.segment {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 760;
  white-space: nowrap;
}

.segment.is-active {
  border-color: var(--teal);
  background: #dff4ee;
  color: var(--teal-dark);
}

.year-control label,
.language-control label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.year-control strong {
  color: var(--ink);
  font-size: 13px;
}

.language-control select {
  width: 72px;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 760;
  text-align: center;
}

.year-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
}

.icon-button {
  width: 42px;
  height: 38px;
  border-radius: 8px;
  font-weight: 800;
}

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

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
}

.map-frame {
  position: relative;
  min-height: calc(100vh - 112px);
}

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

.leaflet-container {
  font-family: inherit;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.territory-tooltip {
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(22, 33, 36, 0.18);
  color: var(--ink);
  font-weight: 780;
}

.territory-tooltip span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 740;
  text-transform: uppercase;
}

.legend,
.data-credit {
  position: absolute;
  z-index: 430;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.legend {
  left: 18px;
  bottom: 22px;
  width: min(360px, calc(100% - 36px));
  padding: 14px;
  border-radius: 8px;
}

.legend-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-weight: 820;
}

.legend-ramp {
  height: 12px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  overflow: hidden;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(29, 37, 40, 0.16);
}

.legend-swatch {
  min-width: 0;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.data-credit {
  left: 18px;
  top: 18px;
  padding: 8px 10px;
  border-radius: 8px;
  text-transform: none;
}

.data-credit a {
  color: var(--teal-dark);
  font-weight: 850;
  text-decoration: none;
}

.data-credit a:hover {
  text-decoration: underline;
}

.detail-panel {
  min-height: 0;
  overflow: auto;
  padding: 22px;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.panel-title-row,
.chart-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 22px 0;
}

.metric {
  min-height: 82px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 25px;
  line-height: 1;
}

#trendChart {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 12px;
  overflow: visible;
}

.axis-text {
  fill: var(--muted);
  font-size: 20px;
  font-weight: 700;
}

.grid-line {
  stroke: #dbe2dd;
  stroke-width: 1;
}

.trend-area {
  fill: rgba(15, 118, 110, 0.12);
}

.trend-line {
  fill: none;
  stroke: var(--teal);
  stroke-width: 5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.trend-dot {
  fill: #fff;
  stroke: var(--ember);
  stroke-width: 5;
}

.ranking {
  margin-top: 24px;
}

.rank-item {
  position: relative;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid #edf0ed;
}

.rank-item.is-selected {
  margin: 4px -8px;
  padding: 10px 8px 10px 12px;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: #dff4ee;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.1);
}

.rank-item.is-selected .rank-index,
.rank-item.is-selected .rank-value {
  color: var(--teal-dark);
}

.rank-item.is-pinned {
  margin-top: 12px;
}

.rank-item:last-child {
  border-bottom: 0;
}

.rank-index {
  color: var(--muted);
  font-size: 12px;
  font-weight: 820;
}

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

.rank-value {
  font-variant-numeric: tabular-nums;
  font-weight: 820;
}

@media (max-width: 1100px) {
  .toolbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .year-control {
    grid-column: auto;
  }

  .language-control {
    max-width: 88px;
  }

  .map-frame {
    min-height: 58vh;
  }

  .detail-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 680px) {
  .toolbar {
    gap: 18px;
    padding: 14px;
  }

  h1 {
    min-height: 2.16em;
    font-size: 22px;
    line-height: 1.08;
  }

  .brand-kicker,
  legend,
  .year-control label,
  .language-control label {
    font-size: 11px;
  }

  .control-grid,
  .metric-grid {
    grid-template-columns: 1fr;
    gap: 11px;
  }

  .segmented {
    flex-wrap: wrap;
    gap: 6px;
  }

  .segment {
    min-height: 34px;
    padding: 0 9px;
    font-size: 13px;
  }

  .year-row {
    grid-template-columns: 38px 1fr;
  }

  .icon-button {
    width: 38px;
    height: 34px;
  }

  .language-control {
    max-width: 92px;
  }

  .language-control select {
    min-height: 34px;
  }

  .workspace {
    display: block;
  }

  .map-frame {
    min-height: 70vh;
  }

  .detail-panel {
    padding: 18px 16px;
  }

  .data-credit {
    max-width: calc(100% - 36px);
  }
}
