:root {
  /* ---- palette: adjust page colors here (map layer colors live in js/config.js) ---- */
  --page-bg: #EEF0F0;        /* panel and footer background */
  --ink: #092F29;            /* titles and main text */
  --ink-muted: #4F6460;      /* deck, notes and sources */
  --rule: #D3D9D8;           /* hairlines between legend rows */
  --focus: #006A54;          /* keyboard focus ring */
  --popup-bg: #FCFCFC;       /* popup background */

  /* ---- type: adjust fonts and sizes here ---- */
  --font-title: 'Rowan', Georgia, 'Times New Roman', serif;
  --font-text: 'Public Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --size-title: 1.5rem;
  --size-deck: 0.95rem;
  --size-body: 0.92rem;
  --size-small: 0.8rem;

  /* ---- layout: adjust panel width and spacing here ---- */
  --panel-width: 400px;
  --gutter: 24px;

  /* ---- logo: sized to the title's letters, as on Mongabay's static graphics ---- */
  --logo-size: 1em;          /* adjust logo size here (1em spans the title's tallest letters to its descenders) */
  --logo-nudge: 0.146em;     /* lines the logo's top up with the top of the title's letters */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ---- layout: map left, panel right on desktop ---- */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-width);
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  min-height: 520px;
}

.map-wrap {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  min-height: 0;
}

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

/* The panel runs the full height on wide screens: the footnote and sources sit
   under the map instead, where the wider column costs them far fewer lines and
   leaves the legend room to grow. */
.panel {
  grid-column: 2;
  grid-row: 1 / span 2;
  overflow-y: auto;
  padding: var(--gutter) var(--gutter) 8px;
}

.foot {
  grid-column: 1;
  grid-row: 2;
  padding: 10px var(--gutter) 14px;
  /* marks where the box ends: it shares the page background with the panel beside it,
     so without this the bottom of the page reads as one band the full width */
  border-right: 1px solid var(--rule);
  font-size: var(--size-small);
  line-height: 1.4;
  color: var(--ink-muted);
}

.foot p {
  margin: 0 0 4px;
}

.foot p:empty {
  display: none;
}

/* ---- panel copy ---- */
.panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 16px;               /* adjust space between title and logo here */
  align-items: start;
  margin-bottom: 10px;
  font-size: var(--size-title);   /* lets the logo nudge below scale with the title */
}

.title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 400;
  font-size: var(--size-title);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.logo {
  display: block;
  width: var(--logo-size);
  height: auto;
  margin-top: var(--logo-nudge);  /* lines the logo up with the top of the title's letters */
}

.deck {
  margin: 0 0 18px;
  font-weight: 300;
  font-size: var(--size-deck);
  line-height: 1.45;
  color: var(--ink-muted);
}

/* ---- layer toggles and legend ---- */
.layers {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.layer {
  display: grid;
  grid-template-columns: 18px 18px minmax(0, 1fr);
  column-gap: 10px;
  align-items: start;
  padding: 8px 0;
  border-top: 1px solid var(--rule);
  cursor: pointer;
}

.layer:last-child {
  border-bottom: 1px solid var(--rule);
}

.layer.is-static {
  cursor: default;
}

.layer input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.check {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;           /* adjust checkbox rounding here */
  display: grid;
  place-items: center;
  background: transparent;
  transition: background-color 0.15s ease;
}

.check svg {
  opacity: 0;
}

.layer input:checked + .check {
  background: var(--ink);
}

.layer input:checked + .check svg {
  opacity: 1;
}

.layer input:focus-visible + .check {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.swatch {
  display: block;
  margin-top: 1px;
  transition: opacity 0.15s ease;
}

.layer-name {
  display: block;
  font-size: var(--size-body);
  font-weight: 500;
  line-height: 1.3;
}

.layer-note {
  display: block;
  margin-top: 2px;
  font-size: var(--size-small);
  line-height: 1.35;
  color: var(--ink-muted);
}

.layer.is-off .swatch,
.layer.is-off .layer-text {
  opacity: 0.45;
}

/* Overlap sub-rows: every kind is drawn in the same color, so only the indent and the
   lighter type set them apart from the row they belong to. No swatch, no hairline.
   Both selectors are needed so the narrow layout's own .layer padding does not win. */
.layer.layer-child {
  padding: 3px 0 3px 26px;      /* adjust the indent of the overlap sub-rows here */
  border-top: none;
}

.layer-child .layer-name {
  font-size: var(--size-small); /* adjust the sub-row type size here */
  font-weight: 400;
  color: var(--ink-muted);
}

.hint {
  margin: 10px 0 0;
  font-size: var(--size-small);
  color: var(--ink-muted);
}

.map-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  text-align: center;
  color: var(--ink-muted);
}

/* ---- popups ---- */
.area-popup .mapboxgl-popup-content {
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;           /* adjust popup rounding here */
  background: var(--popup-bg);
  box-shadow: none;
  font-family: var(--font-text);
  color: var(--ink);
}

.area-popup.is-hover {
  pointer-events: none;         /* keeps the popup from stealing the cursor */
}

.area-popup .mapboxgl-popup-tip {
  display: none;
}

.area-popup .mapboxgl-popup-content {
  overflow: hidden;             /* clips the colored strip to the rounded corners */
}

.area-popup .mapboxgl-popup-close-button {
  top: 2px;
  right: 3px;
  width: 24px;
  height: 24px;
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
  border-radius: 4px;
}

.area-popup.shows-us .mapboxgl-popup-close-button {
  color: #FFFFFF;
}

/* colored strip naming who manages the area */
.pop-band {
  margin: -10px -12px 8px;
  padding: 5px 34px 5px 12px;
  font-size: 0.74rem;           /* adjust strip text size here */
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

.is-us .pop-band {
  background: var(--us-color);
  color: #FFFFFF;               /* adjust US strip text color here */
}

.is-isa .pop-band {
  background: var(--isa-color);
  color: var(--ink);
}

.is-overlap .pop-band {
  background: var(--overlap-color);
  color: var(--ink);
}

.pop-item + .pop-item {
  margin-top: 10px;
}

.pop-item + .pop-item .pop-band {
  margin-top: 0;
}

/* "Company:" label, styled like the row labels ("Area name") */
.pop-label {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--ink-muted);
}

.pop-title {
  margin: 0 0 6px;
  font-size: 0.9rem;            /* adjust popup title size here */
  font-weight: 600;
  line-height: 1.25;
}

.pop-rows {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  row-gap: 2px;
  margin: 0;
  font-size: 0.8rem;            /* adjust popup text size here */
  line-height: 1.35;
}

.pop-rows dt {
  color: var(--ink-muted);
  white-space: nowrap;
}

.pop-rows dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.pop-rows dd.nowrap {
  white-space: nowrap;
}

/* footnote inside a popup */
.pop-note {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
  font-size: 0.75rem;           /* adjust popup footnote size here */
  line-height: 1.35;
  color: var(--ink-muted);
}

.pop-members {
  list-style: none;
  margin: 8px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--rule);
}

.pop-members li + li {
  margin-top: 6px;
}

.m-company {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.3;
}

.m-meta {
  display: block;
  font-size: 0.78rem;
  line-height: 1.3;
  color: var(--ink-muted);
}

/* ---- map controls ---- */
.mapboxgl-ctrl-attrib {
  font-family: var(--font-text);
  font-size: 10px;
}

/* scale bars as two plain lines with the label above, km over mi */
.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-scale {
  margin: 0 0 6px 12px;
  padding: 0 0 2px;
  border: 0;
  border-bottom: 1.5px solid rgba(255, 255, 255, 0.9); /* adjust scale bar line color here */
  background: none;
  color: #FFFFFF;                                        /* adjust scale bar text color here */
  font-family: var(--font-text);
  font-size: 11px;
  line-height: 1.2;
}

.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-scale:first-child {
  margin-bottom: 2px;
}

/* ---- article embed (?fill=1) --------------------------------------------
   Inside a story column the frame is never wider than the column, so the panel
   always sits above the map and the map gets the full width. The grid fills the
   frame and the map row is the flexible one, which is what keeps spare frame
   height out of the gap below the footnote. */
@media (max-width: 820px) {
  .is-embedded .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(220px, 1fr) auto;  /* adjust the map's floor here */
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .is-embedded .panel {
    grid-column: 1;
    grid-row: 1;
    overflow: visible;
    padding-bottom: 10px;
  }

  .is-embedded .map-wrap {
    grid-column: 1;
    grid-row: 2;
    height: auto;
    min-height: 0;
  }

  .is-embedded .foot {
    grid-column: 1;
    grid-row: 3;
    border-right: none;   /* nothing sits beside it here */
    padding-top: 8px;
  }
}

/* ---- phones and narrow embeds: panel above the map, sources below ---- */
@media (max-width: 760px) {
  :root {
    --size-title: 1.4rem;
    --size-deck: 0.92rem;
    --gutter: 16px;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    height: auto;
    min-height: 0;
  }

  .panel {
    grid-column: 1;
    grid-row: 1;
    overflow: visible;
    padding-bottom: 12px;
  }

  .deck {
    margin-bottom: 14px;
  }

  /* legend rows keep their notes here, so they stay top-aligned like the wide
     layout; only the row spacing tightens */
  .layer {
    padding: 6px 0;             /* adjust the gap between legend rows on phones here */
  }

  .map-wrap {
    grid-column: 1;
    grid-row: 2;
    height: 60vh;               /* adjust the map height on phones here */
    min-height: 340px;
  }

  .foot {
    grid-column: 1;
    grid-row: 3;
    padding-top: 10px;
    border-right: none;   /* nothing sits beside it in the stacked layout */
  }
}
