:root {
  /* the one accent color: Go button, selected layer, switches, hover states,
     precipitation in the charts and the map pin (JS reads --accent via ACCENT in js/config.js) */
  --accent: #4a7fc9;
  --accent-strong: #2f5f9e; /* text links: darker, for readable contrast on white */
  --accent-soft: #eaf1fb;   /* tinted backgrounds */
  --accent-line: #b9cdea;   /* borders on tinted backgrounds */
}
html {
  /* Fluid base size: every text size below is in rem, so the whole UI scales
     from this one rule. Percentages are of the browser's own default size (16px),
     so a user's font-size setting / zoom still applies.
       ~14px on a 1300px-wide window  ->  ~15.5px at 2000px, clamped to 14..16px.
     (The whole UI is then drawn at 90%: this clamp, and every px length below, is 0.9x the original design values.) */
  font-size: clamp(78.75%, calc(63% + 0.214vw), 90%); /* = 0.9 x the former clamp(87.5%, 70% + 0.238vw, 100%): the whole UI is drawn at 90% (like a 90% browser zoom) */
}
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
sub {
  font-size: 0.78em; /* subscripts stay readable (browser default is smaller) */
}
body {
  display: flex;
  flex-direction: column; /* thin header bar on top, the app fills the rest */
}
#site-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14.4px;
  padding: 0 16.2px;
  height: 2.9rem;
  background: #1f2d3d;
  color: white;
  position: relative;
  z-index: 2000;
}
.header-title {
  display: flex;
  align-items: baseline;
  gap: 12.6px;
  min-width: 0;
}
#site-header h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* very narrow windows: shorten the title rather than push the buttons off-screen */
}
.header-links {
  display: flex;
  gap: 7.2px;
  flex: 0 0 auto;
}
.header-links a, .header-links .header-btn {
  padding: 3.6px 10.8px;
  font-family: inherit;
  font-size: 0.93rem;
  line-height: normal;
  color: white;
  text-decoration: none;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 12.6px;
}
.header-links a[href]:hover {
  background: var(--accent);
  border-color: var(--accent);
}
.header-links a.pending {
  color: #8d9bab;
  border-color: rgba(255, 255, 255, 0.15);
  cursor: default;
}
#app {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}
#map-column {
  container-type: inline-size; /* lets the layer switcher adapt to the map column's own width */
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0; /* let flexbox shrink the map column instead of overflowing */
  height: 100%;
}
/* the four layer cards need ~770px: while the window can afford that next to a 300px panel, the
   map column keeps it and the panel narrows instead; below that the cards become a 2 x 2 grid */
@media (min-width: 1051px) {
  #map-column { min-width: 775px; }
}
#map-wrap {
  position: relative; /* anchors #map (fills it) and the floating #map-tools card */
  flex: 1 1 auto;
  min-height: 0; /* let the map shrink within the column instead of overflowing */
}
#map {
  position: absolute;
  inset: 0;
  overflow: hidden; /* the zoomed canvas/svg extend past the map box; without this they sit on top of the layer switcher and swallow its clicks */
  background: #eaf3f8;
}
#panel-resizer {
  flex: 0 0 5.4px;
  width: 5.4px;
  height: 100%;
  cursor: col-resize;
  background: #e5e5e5;
  z-index: 1001;
}
#panel-resizer:hover, #panel-resizer.dragging {
  background: var(--accent);
}
/* Keep the plain arrow cursor everywhere on the map -- d3.zoom defaults to a
   grab/hand cursor for panning, but this site is primarily a click-to-query
   tool, not a draggable canvas metaphor. */
#map, #map * {
  cursor: default !important;
}
.location-pin, .click-marker, .compare-marker {
  pointer-events: none;
}
#layer-switcher {
  flex: 0 0 auto;
  /* the three groups sit side by side as equal columns (and wrap onto more
     rows on a narrow map), so the bar uses its full width instead of
     leaving a blank band on the right */
  display: grid;
  grid-template-columns: auto repeat(3, 1fr); /* dataset buttons + the three group cards */
  gap: 6px;
  padding: 4px 8px;
  background: white;
  border-bottom: 1px solid #ddd;
  font-size: 0.94rem;
}
/* dataset switch (ERA5-Land | GPCC): a card of its own at the left of the group cards */
.dataset-box {
  display: flex;
  flex-direction: column;
  gap: 2.7px;
  padding: 3px 9px 4px;
  background: #f5f7fa;
  border: 1px solid #e3e8ee;
  border-radius: 5.4px;
}
.dataset-switch {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dataset-switch button {
  /* same row metrics as the layer options below, so every card lines up row by row */
  box-sizing: border-box;
  font: inherit;
  line-height: 1.35;
  padding: 1px 9px;
  color: #34495e;
  text-align: left;
  white-space: nowrap;
  background: white;
  border: 1px solid var(--accent-line);
  border-radius: 5.4px;
  cursor: pointer;
}
.dataset-switch button:hover {
  background: var(--accent-soft);
}
.dataset-switch button.selected {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}
.dataset-switch button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
/* only the selected dataset's cards are shown (js sets #layer-switcher[data-dataset]) */
#layer-switcher[data-dataset="gpcc"] .switcher-group[data-dataset="era5"],
#layer-switcher[data-dataset="era5"] .switcher-group[data-dataset="gpcc"] {
  display: none;
}
.switcher-note {
  display: none;
  grid-column: span 2;
  align-self: center;
  padding: 0 7.2px;
  font-size: 0.93rem;
  line-height: 1.4;
  color: #4f5b66;
}
#layer-switcher[data-dataset="gpcc"] .switcher-note {
  display: block;
}
.switcher-group {
  display: flex;
  flex-direction: column; /* title on top, options beneath */
  gap: 2.7px;
  padding: 3px 9px 4px;
  background: #f5f7fa;
  border: 1px solid #e3e8ee;
  border-radius: 5.4px;
}
.switcher-group-title {
  font-size: 1.04em; /* level 2 (~12.5px) over the ~12px options */
  font-weight: 700;
  white-space: nowrap;
}
.switcher-options {
  /* one option per row: every card has the same rows, so nothing wraps unevenly;
     each row is only as wide as its text, so the selected fill hugs the label */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  margin-left: -3.6px; /* the pill's padding would otherwise indent the labels from the card title */
}
/* medium map column (the panel is next to it): still four cards side by side, tightened --
   smaller type, gaps and padding; the titles stay on one line */
@container (max-width: 917px) {
  #layer-switcher {
    gap: 5px;
    padding: 4px 8px;
  }
  .switcher-group, .dataset-box {
    padding: 3px 7px 4px;
  }
  .dataset-switch button {
    padding: 1px 6.3px;
  }
  .switcher-group label {
    padding: 1px 7.2px;
  }
}
/* narrow map column: a 2 x 2 grid of cards (dataset, precipitation / SWI / snow shift) */
@container (max-width: 774px) {
  #layer-switcher {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .switcher-note {
    grid-column: span 2;
  }
}
/* very narrow (phones): one card per row */
@container (max-width: 413px) {
  #layer-switcher {
    grid-template-columns: 1fr;
  }
  .switcher-note {
    grid-column: auto;
  }
}
.switcher-group label {
  /* each layer option is a row; the native radio dot is hidden (the input
     stays in the DOM for keyboard use) and the selected row is filled with the accent */
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2.7px;
  padding: 1px 9.9px;
  line-height: 1.35;
  border-radius: 12.6px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.switcher-group label input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switcher-group label:hover {
  background: var(--accent-soft);
}
.switcher-group label.selected {
  background: var(--accent);
  color: white;
}
.switcher-group label:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.switcher-group.has-selected {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
#zoom-controls {
  position: absolute;
  right: 12.6px;
  top: 10.8px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 3.6px;
}
#zoom-controls button {
  /* three identical squares: +, -, reset (icon) */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  color: #34495e;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #c9d3dd;
  border-radius: 5.4px;
  cursor: pointer !important; /* overrides the map-wide arrow-only cursor rule: these are real buttons */
}
#zoom-controls button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
/* hover readout: value of the active layer at the 0.1deg cell under the pointer */
#hover-tip {
  position: absolute;
  z-index: 650;
  padding: 5.4px 9px 6.3px;
  font-size: 1rem;
  line-height: 1.35;
  color: #2c3a47;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #c9d3dd;
  border-radius: 5.4px;
  box-shadow: 0 2px 9px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  pointer-events: none; /* never intercepts the pointer it is following */
}
#hover-tip[hidden] {
  display: none;
}
#hover-tip .tip-value {
  font-size: 0.98rem;
  font-weight: 700; /* the whole "symbol = value" line is bold */
}
#hover-tip .tip-sub {
  font-size: 0.82rem;
  color: #4f5b66;
}
#hover-tip .tip-hint {
  font-size: 0.82rem;
  color: #6b7785;
}
/* busy indicators (js/loading.js): a pill with a small spinner */
.loading-chip {
  display: inline-flex;
  align-items: center;
  gap: 7.2px;
  padding: 4.5px 11.7px 4.5px 9px;
  font-size: 0.93rem;
  color: #34495e;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #d5dde5;
  border-radius: 14.4px;
  box-shadow: 0 1px 5.4px rgba(0, 0, 0, 0.16);
  pointer-events: none;
}
.loading-chip[hidden] {
  display: none;
}
.spinner {
  flex: 0 0 auto;
  width: 0.95rem;
  height: 0.95rem;
  box-sizing: border-box;
  border: 2.2px solid var(--accent-line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
#map-loading {
  /* map re-render on layer switch: a large chip in the middle of the map */
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 700;
  gap: 0.9rem;
  padding: 0.9rem 1.6rem 0.9rem 1.3rem;
  font-size: 1.4rem;
  font-weight: 600;
  border-radius: 2.2rem;
  box-shadow: 0 2px 12.6px rgba(0, 0, 0, 0.22);
}
#data-credit {
  /* abbreviated data credit in the map's bottom-right corner, followed by an (i) icon; hovering or
     focusing the icon (or tapping it) opens the full wording */
  position: absolute;
  right: 8px;
  bottom: 6px;
  z-index: 650;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 0.82rem;
  color: #4a5a68;
}
#data-credit .credit-short {
  pointer-events: none; /* the text never blocks the map underneath */
  max-width: calc(100vw - 600px); /* narrow windows: wraps (right-aligned) instead of running into the colour wheel at the left */
  text-align: right;
  line-height: 1.25;
}
.credit-icon {
  flex: 0 0 auto;
  box-sizing: border-box;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  font: italic 700 0.82rem/1 Georgia, "Times New Roman", serif;
  color: #4a5a68;
  background: rgba(255, 255, 255, 0.9);
  border: 1.3px solid #8c99a6;
  border-radius: 50%;
  cursor: pointer;
}
.credit-icon:hover, .credit-icon[aria-expanded="true"], .credit-icon:focus-visible {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
  outline: none;
}
#credit-full {
  display: none;
  position: absolute;
  right: 0;
  bottom: 100%;
  box-sizing: border-box;
  width: min(34rem, calc(100vw - 20px));
  margin-bottom: 8px;
  padding: 9px 12px;
  line-height: 1.5;
  font-size: 0.94rem;
  color: #34495e;
  background: white;
  border: 1px solid #c9d3dd;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}
#credit-full::after { /* keeps the card open while the pointer crosses the gap to the icon */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 12px;
}
#data-credit:hover #credit-full, #data-credit:focus-within #credit-full, #data-credit.open #credit-full {
  display: block;
}
#credit-full div + div {
  margin-top: 4px;
}
#map-loading .spinner {
  width: 1.5rem;
  height: 1.5rem;
  border-width: 3.1px;
}
#panel-loading-anchor {
  position: sticky;
  top: 0;
  height: 0;
  z-index: 10;
}
#panel-loading {
  position: absolute;
  top: 9px;
  right: 12.6px;
}
#map-tools {
  /* top-left overlay stack: the lat/lon + compare card, then the usage hint */
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 600; /* above the map's own overlays (legend, zoom buttons) */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7.2px;
  max-width: calc(100% - 59.4px); /* leaves room for the zoom buttons on the right */
}
#map-hint {
  /* second line of the lat/lon card: same width as the card, a hairline above it,
     no pill of its own (it used to float separately below the card and looked tacked on) */
  flex: 0 0 0;
  min-width: 100%; /* zero natural width (so it can't widen the shrink-to-fit card), stretched to the card's width, which forces its own row */
  padding-top: 2.5px;
  border-top: 1px solid #e7ecf1;
  font-size: 0.82rem;
  line-height: 1.3;
  color: #4f5b66;
}
#legend-box {
  position: absolute;
  left: max(6.5%, 46.8px); /* floor keeps the (negatively offset) circular wheel from being clipped on narrow maps */
  top: 53%;
  z-index: 500;
  background: transparent;
  padding: 2px 3.6px;
}
#legend-box img {
  /* Constrain by HEIGHT, not width: the linear colorbars (concentration/
     bimodality/shift-magnitude) have different source-image aspect ratios
     (label text of varying width next to the same-height gradient bar), so
     a shared max-width made their rendered bar heights inconsistent. A
     shared height keeps the actual color bars visually the same size,
     even though the overall image width (and thus label width) still varies. */
  display: block;
  height: 153px;
  width: auto;
}
#legend-box img.legend-img-large {
  height: auto;
  width: 153px;
  margin-left: -45px; /* nudge the circular timing wheel further left, per request */
}
.var {
  font-style: italic;
}
#panel {
  position: relative;
  flex: 0 1 32.5rem; /* ~475px on a wide window; gives up width (down to min-width) when the map column needs it */
  min-width: 270px;
  width: 32.5rem;
  height: 100%;
  background: white;
  box-shadow: -2px 0 7.2px rgba(0,0,0,0.15);
  overflow-y: auto;
  z-index: 1000;
}
@media (max-width: 1050px) {
  #panel { flex-basis: 21.5rem; }   /* the cards are a 2 x 2 grid here: keep the panel at its minimum and give the rest to the map */
}
#query-controls {
  /* floating card over the map's top-left corner (see #map-tools) */
  box-sizing: border-box;
  display: flex;          /* one row: Lat, Lon, Go, then the Compare switch */
  flex-wrap: wrap;        /* (wraps only on a very narrow map; the error message gets its own line) */
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
  max-width: 100%;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #d5dde5;
  border-radius: 7.2px;
  box-shadow: 0 1px 5.4px rgba(0, 0, 0, 0.14);
}
.coord-form {
  display: flex;
  align-items: center;
  gap: 6px;
}
.coord-form label {
  display: flex;
  align-items: center;
  gap: 4.5px;
  font-size: 0.93rem;
  color: #444;
}
.coord-form input[type="number"] {
  width: 4.7rem;
  min-width: 0;
  padding: 2.5px 5px;
  font-size: 0.93rem;
  border: 1px solid #ccc;
  border-radius: 3.6px;
}
.coord-form button {
  flex: 0 0 auto;
  padding: 2.5px 10px;
  font-size: 0.93rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 3.6px;
  cursor: pointer;
}
.coord-msg {
  flex: 1 0 100%; /* own line under the row, takes no space while empty */
  min-height: 0;
  font-size: 0.82rem;
  color: #c0392b;
}
.coord-msg:empty {
  display: none;
}
/* compact on/off switch for compare mode (the real checkbox stays in the DOM, visually hidden) */
.compare-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6.3px;
  font-size: 0.93rem;
  color: #444;
  cursor: pointer;
  user-select: none;
}
.compare-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 2.1rem;
  height: 1.2rem;
  border-radius: 8.1px;
  background: #b8c2cc;
  transition: background 0.15s;
}
.switch-knob {
  position: absolute;
  top: 0.15rem;
  left: 0.15rem;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.compare-switch input:checked + .switch-track {
  background: var(--accent);
}
.compare-switch input:checked + .switch-track .switch-knob {
  transform: translateX(0.9rem);
}
.compare-switch.disabled {
  /* compare mode is ERA5-Land only; parked while GPCC is shown */
  opacity: 0.45;
  cursor: not-allowed;
}
.compare-switch.disabled input {
  pointer-events: none;
}
.dataset-badge {
  display: inline-block;
  margin: -2px 0 7.2px;
  padding: 1px 9px;
  font-size: 0.82rem;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 10.8px;
}
.compare-switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
#panel-content {
  padding: 18px 18px;
}
#panel-content .placeholder {
  color: #5f6b76;
  font-size: 0.94rem;
  line-height: 1.5;
  margin-top: 21.6px;
}
#panel-content h2 {
  margin: 0 0 5.4px 0;
  font-size: 1.17rem;
}
#panel-content .subtitle {
  color: #666;
  font-size: 0.93rem;
  margin-bottom: 10.8px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.94rem;
  padding: 3.6px 0;
  border-bottom: 1px solid #f0f0f0;
}
.stat-row .k { color: #555; }
.stat-row .v { font-weight: 600; }
.section-title {
  margin: 16.2px 0 7.2px 0;
  font-size: 0.98rem;
  font-weight: 700;
  color: #333;
  border-top: 1px solid #eee;
  padding-top: 10.8px;
}
.na-note {
  color: #4f5b66;
  font-style: italic;
  font-size: 0.82rem;
  line-height: 1.4;
}
#chart-container {
  display: flex;
  justify-content: center;
}
.chart-caption {
  font-size: 0.94rem;
  color: #4f5b66;
  text-align: center;
  margin-top: 2px;
}
.chart-legend {
  margin: 3.6px 0 2px;
  font-size: 0.94rem;
  color: #4f5b66;
}
.legend-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  column-gap: 16.2px;
  row-gap: 2px;
  margin-top: 2.7px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5.4px;
}
.legend-chip {
  display: inline-block;
  width: 0.87rem;
  height: 0.87rem;
  border-radius: 2.7px;
  opacity: 0.8; /* the chart's band is drawn at 55% fill; slightly translucent chip reads as the same hue */
}
.legend-com {
  flex: 0 0 auto;
}
.compare-cards {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 9px;
}
.compare-card {
  border: 1px solid #eee;
  border-radius: 5.4px;
  padding: 7.2px 9px 3.6px;
}
.compare-card-header {
  display: flex;
  align-items: center;
  gap: 5.4px;
  font-size: 0.94rem;
  margin-bottom: 3.6px;
}
.compare-card [id^="compare-chart-"] {
  display: flex;
  justify-content: center;
}
.compare-no {
  /* same color as the location's numbered marker on the map */
  flex: 0 0 auto;
  padding: 1px 8.1px;
  border-radius: 9px;
  color: white;
  font-size: 0.94rem;
  font-weight: 700;
}
.compare-swatch {
  display: inline-block;
  width: 0.67rem;
  height: 0.67rem;
  border-radius: 50%;
  flex: 0 0 auto;
}
.compare-chip-label {
  flex: 1 1 auto;
}
.compare-remove {
  flex: 0 0 auto;
  border: none;
  background: none;
  color: #66707a;
  font-size: 0.94rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.compare-remove:hover {
  color: #d64545;
}
#btn-clear-compare {
  font-size: 0.94rem;
  padding: 3.6px 9px;
  border: 1px solid #ccc;
  background: white;
  border-radius: 3.6px;
  cursor: pointer;
  margin-bottom: 9px;
}
#chart-container svg, .compare-card [id^="compare-chart-"] svg {
  max-width: 100%; /* shrink with a narrower panel instead of overflowing */
  height: auto;
}
