/* ============================================================================
   ThEO map viewer — design system + theme
   Light/dark driven by [data-theme] on <html> (see assets/theme-init.js).
   ========================================================================== */

@font-face {
  font-family: 'SourceSansPro';
  font-weight: 400;
  font-display: swap;
  src: url('fonts/SourceSansPro-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'SourceSansPro';
  font-weight: 600;
  font-display: swap;
  src: url('fonts/SourceSansPro-SemiBold.woff2') format('woff2');
}
@font-face {
  font-family: 'SourceSansPro';
  font-weight: 700;
  font-display: swap;
  src: url('fonts/SourceSansPro-Bold.woff2') format('woff2');
}

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  --brand: #008cd2;
  --brand-strong: #0078b8;
  --brand-soft: #e8f6fd;

  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-2: #f6f8f9;
  --panel-glass: rgba(255, 255, 255, 0.9);
  --chip-bg: rgba(255, 255, 255, 0.92);

  --text: #151819;
  --text-muted: #5b6b72;
  --text-inverse: #ffffff;
  --border: #d9dfe6;
  --border-strong: #c3ccd4;

  --chart-text: #334155;
  --chart-grid: #e6ebef;

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 6px 18px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.18);

  --blur: 10px;
  --t-fast: 0.15s ease;
  --t: 0.22s cubic-bezier(0.2, 0.6, 0.2, 1);
}

[data-theme="dark"] {
  --brand: #38a9e3;
  --brand-strong: #1d93d3;
  --brand-soft: #12303d;

  --bg: #0e1417;
  --surface: #1a2227;
  --surface-2: #222c32;
  --panel-glass: rgba(23, 31, 36, 0.86);
  --chip-bg: rgba(23, 31, 36, 0.88);

  --text: #e9eff3;
  --text-muted: #9fb0b8;
  --text-inverse: #0e1417;
  --border: #2c383f;
  --border-strong: #3a4851;

  --chart-text: #c7d3da;
  --chart-grid: #2c383f;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
}

/* ── Base ────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

body {
  font-family: 'SourceSansPro', -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  transition: background var(--t), color var(--t);
}

label {
  font-family: 'SourceSansPro', 'Roboto', sans-serif;
  font-weight: 600;
  color: var(--text);
}

.slider-label { font-size: 14px; }

/* Shared glass surface */
.floating-header,
.floating-panel,
.pixel-popup,
.pixel-hint-popup,
.info-modal,
.stac-panel-box,
.thuenen-logo-box,
.dataset-tab-bar,
.legal-footer {
  background: var(--panel-glass);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  color: var(--text);
}

/* ── Logo + legal footer ─────────────────────────────────────────────────── */
.thuenen-logo-box {
  padding: 6px 10px;
  margin-left: 10px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: box-shadow var(--t-fast), transform var(--t-fast);
}
.thuenen-logo-box:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.thuenen-logo { display: block; height: 40px; width: auto; }

.legal-footer {
  padding: 0;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  background: var(--panel-glass);
}
.legal-footer a { color: var(--text-muted); text-decoration: none; }
.legal-footer a:hover { color: var(--brand); text-decoration: underline; }
.legal-footer-sep { color: var(--text-muted); opacity: 0.6; }
.legal-footer-mobile { display: none; }

/* ── STAC panel (bottom-right) ───────────────────────────────────────────── */
.stac-panel-box {
  position: absolute;
  bottom: 26px;
  right: 10px;
  z-index: 1000;
  padding: 5px 12px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  min-height: 24px;
  display: flex;
  align-items: center;
  transition: box-shadow var(--t-fast), transform var(--t-fast);
}
.stac-panel-box:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stac-panel-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
.stac-panel-text { font-size: 14px; font-weight: 700; color: var(--text); }
.stac-panel-logo { width: 80px; height: auto; display: block; }

.bottom-left-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.floating-header {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1000;
  padding: 12px 16px;
  border-left: 4px solid var(--brand);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  max-width: 380px;
}
.app-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
}
.app-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

.header-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.header-icon-group { display: flex; gap: 6px; flex-shrink: 0; }

.header-icon-btn {
  background: var(--brand);
  border: none;
  color: #f8fafc;
  border-radius: var(--r-sm);
  width: 28px;
  height: 28px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: background var(--t-fast), transform var(--t-fast);
}
.header-icon-btn:hover { background: var(--brand-strong); transform: translateY(-1px); }
.header-icon-btn:active { transform: translateY(0); }
.header-icon-img { width: 18px; height: 18px; display: block; }

/* Panel header + theme icon button (top-right of the controls panel) */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.panel-header .panel-title { margin-bottom: 0; }

.icon-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.panel-header-actions { display: flex; gap: 6px; }

.theme-icon,
.ui-icon {
  width: 17px;
  height: 17px;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}
.theme-icon-sun { -webkit-mask-image: url('icons/icon-sun.svg'); mask-image: url('icons/icon-sun.svg'); }
.theme-icon-moon { -webkit-mask-image: url('icons/icon-moon.svg'); mask-image: url('icons/icon-moon.svg'); }
.ui-icon-fullscreen { -webkit-mask-image: url('icons/icon-fullscreen.svg'); mask-image: url('icons/icon-fullscreen.svg'); }
.ui-icon-menu { -webkit-mask-image: url('icons/icon-menu.svg'); mask-image: url('icons/icon-menu.svg'); }

[data-theme="light"] .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-moon { display: none; }

.panel-action-btn {
  width: 100%;
  margin-top: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.panel-action-btn:hover {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
}

/* ── Info modal ──────────────────────────────────────────────────────────── */
.info-modal {
  position: absolute;
  top: calc(var(--header-bottom, 82px) + 10px);
  left: 10px;
  z-index: 1200;
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100vh - var(--header-bottom, 82px) - 24px);
  overflow-y: auto;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 16px;
}
.info-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.info-modal-title { font-size: 15px; font-weight: 700; color: var(--text); }
.info-modal-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 2px;
}
.info-modal-close:hover { color: var(--text); }
.info-modal-body {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: 12px;
}
.info-modal-body a { color: var(--brand); }
.info-modal-stac-link {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
  text-decoration: none;
}
.info-modal-stac-link:hover { text-decoration: underline; }

/* ── Controls panel (right) ──────────────────────────────────────────────── */
.floating-panel {
  position: absolute;
  top: 12px;
  right: 10px;
  z-index: 1000;
  width: 312px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 14px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}
.panel-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; color: var(--text); }
.panel-label { display: block; margin: 10px 0 6px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
#class-filter-label { margin-top: 0; }

.opacity-slider-box {
  width: 100%;
  background: transparent;
  padding: 8px 0 0;
  box-shadow: none;
  min-height: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.opacity-slider-box .rc-slider { width: 100%; margin: 0; }
.opacity-slider-box .rc-slider-tooltip { display: none !important; }

/* ── Legend / class filter ───────────────────────────────────────────────── */
.class-filter {
  display: grid;
  gap: 4px;
  margin-bottom: 6px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 2px;
}
.class-filter label {
  font-weight: 500;
  font-size: 13px;
  display: flex;
  align-items: center;
  padding: 5px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}
.class-filter label:hover { background: var(--surface-2); }

/* ── Dataset tabs (custom bar with a Crop Types submenu) ─────────────────── */
.dataset-tab-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  border-radius: var(--r-pill);
  padding: 5px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}
.tab-list { display: flex; gap: 6px; align-items: center; }

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 26px;
  border-radius: var(--r-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}
.tab-btn:hover { background: var(--brand-soft); color: var(--brand); }

[data-active="ctm"] .tab-btn[data-value="cropland"],
[data-active="hist"] .tab-btn[data-value="cropland"],
[data-active="winter"] .tab-btn[data-value="cropland"],
[data-active="fcover"] .tab-btn[data-value="cropland"],
[data-active="mowing"] .tab-btn[data-value="mowing"],
[data-active="age"] .tab-btn[data-value="mowing"],
[data-active="soil"] .tab-btn[data-value="soil"],
[data-active="soc_stock"] .tab-btn[data-value="soil"],
[data-active="soc_content"] .tab-btn[data-value="soil"],
[data-active="clay"] .tab-btn[data-value="soil"] {
  background: var(--brand);
  color: #ffffff;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.tab-group { position: relative; }

/* Invisible bridge across the gap so the submenu stays open while the mouse
   travels from the tab down onto the menu (no click required). */
.has-submenu::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 12px;
}

.tab-caret {
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  margin-top: -3px;
}

/* Vertical context menu under "Crop Types" */
.submenu {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  min-width: 215px;
  display: none;
  flex-direction: column;
  gap: 3px;
  padding: 6px;
  background: var(--panel-glass);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  z-index: 1200;
  white-space: normal;
}
.has-submenu:hover .submenu {
  display: flex;
  transform: translateX(-50%) translateY(0);
  transition: transform var(--t);
}

/* Touch devices can't hover: keep the menu available while a crop-type layer
   is active so it can still be reached. */
@media (hover: none) {
  [data-active="ctm"] .has-submenu .submenu,
  [data-active="hist"] .has-submenu .submenu,
  [data-active="winter"] .has-submenu .submenu,
  [data-active="fcover"] .has-submenu .submenu,
  [data-active="mowing"] .has-submenu .submenu,
  [data-active="age"] .has-submenu .submenu,
  [data-active="soil"] .has-submenu .submenu,
  [data-active="soc_stock"] .has-submenu .submenu,
  [data-active="soc_content"] .has-submenu .submenu,
  [data-active="clay"] .has-submenu .submenu {
    display: flex;
  }
}
.sub-item {
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.sub-item:hover { background: var(--brand-soft); color: var(--brand); }
[data-active="ctm"] .sub-item[data-value="ctm"],
[data-active="hist"] .sub-item[data-value="hist"],
[data-active="winter"] .sub-item[data-value="winter"],
[data-active="fcover"] .sub-item[data-value="fcover"],
[data-active="mowing"] .sub-item[data-value="mowing"],
[data-active="age"] .sub-item[data-value="age"],
[data-active="soil"] .sub-item[data-value="soil"],
[data-active="soc_stock"] .sub-item[data-value="soc_stock"],
[data-active="soc_content"] .sub-item[data-value="soc_content"],
[data-active="clay"] .sub-item[data-value="clay"] {
  background: var(--brand);
  color: #ffffff;
}

/* ── Mobile layer list (inside the collapsible Map Controls menu) ────────── */
.mobile-layer { display: none; }

.layer-list { display: flex; flex-direction: column; gap: 3px; }
.layer-item {
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  width: 100%;
  transition: background var(--t-fast), color var(--t-fast);
}
.layer-item:hover { background: var(--brand-soft); color: var(--brand); }
.layer-sub { font-size: 13px; font-weight: 500; padding-left: 24px; }
.layer-group { display: flex; flex-direction: column; gap: 3px; margin: 2px 0; }
.layer-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 8px 12px 2px;
}
[data-active="winter"] .layer-item[data-value="winter"],
[data-active="mowing"] .layer-item[data-value="mowing"],
[data-active="age"] .layer-item[data-value="age"],
[data-active="soil"] .layer-item[data-value="soil"],
[data-active="soc_stock"] .layer-item[data-value="soc_stock"],
[data-active="soc_content"] .layer-item[data-value="soc_content"],
[data-active="clay"] .layer-item[data-value="clay"],
[data-active="ctm"] .layer-item[data-value="ctm"],
[data-active="hist"] .layer-item[data-value="hist"],
[data-active="fcover"] .layer-item[data-value="fcover"] {
  background: var(--brand);
  color: #ffffff;
}

/* ── Continuous legend (colour bar) ──────────────────────────────────────── */
.colorbar {
  height: 12px;
  border-radius: var(--r-xs);
  border: 1px solid var(--border);
  margin: 6px 0 3px;
}
.colorbar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.stats-graph { margin-top: 10px; }

/* ── Pixel analysis popup ────────────────────────────────────────────────── */
.pixel-popup {
  position: absolute;
  left: 10px;
  top: calc(var(--header-bottom, 82px) + 10px);
  z-index: 1100;
  width: min(410px, calc(100vw - 32px));
  max-height: calc(100vh - var(--header-bottom, 82px) - 24px);
  overflow-y: auto;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 12px;
}
.pixel-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.pixel-popup-title { font-size: 15px; font-weight: 700; color: var(--text); }
.pixel-popup-coords { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.pixel-popup-close {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--r-pill);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-fast);
}
.pixel-popup-close:hover { background: var(--brand-strong); }

#pixel-diversity-container { margin-top: 8px; }
#pixel-timeseries-graph { margin-bottom: 4px; }

/* ── Pixel hint ──────────────────────────────────────────────────────────── */
.pixel-hint-popup {
  position: absolute;
  left: 10px;
  top: calc(var(--header-bottom, 82px) + 10px);
  z-index: 1090;
  width: min(320px, calc(100vw - 32px));
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  padding: 12px;
  pointer-events: none;
}
.pixel-hint-title,
.pixel-hint-text { pointer-events: none; }
.pixel-hint-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.pixel-hint-text { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.pixel-hint-close {
  pointer-events: auto;
  background: var(--text);
  color: var(--surface);
  border: none;
  border-radius: var(--r-pill);
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}
.pixel-hint-close:hover { opacity: 0.85; }

/* ── Map controls toggle + panel close (mobile) ──────────────────────────── */
.map-controls-toggle { display: none; }
.panel-close-btn { display: none; }

/* ── Leaflet chrome ──────────────────────────────────────────────────────── */
.leaflet-bar,
.leaflet-touch .leaflet-bar {
  border: none;
  box-shadow: var(--shadow-md);
  border-radius: var(--r-sm);
  overflow: hidden;
}
/* !important to beat Leaflet's own stylesheet, which loads after ours */
.leaflet-bar a,
.leaflet-touch .leaflet-bar a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-bottom: 1px solid var(--border) !important;
  font-weight: 700;
  transition: background var(--t-fast), color var(--t-fast);
}
.leaflet-bar a:hover {
  background: var(--brand-soft) !important;
  color: var(--brand) !important;
}
.leaflet-bar a.leaflet-disabled {
  color: var(--text-muted) !important;
  opacity: 0.45;
}

.leaflet-control-attribution {
  background: var(--panel-glass) !important;
  color: var(--text-muted) !important;
  border-radius: var(--r-xs) 0 0 0;
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--text-muted) !important; }

/* Zoom control sits bottom-left */
.leaflet-bottom.leaflet-left { margin-bottom: 88px; }

/* Scale bar: pinned to the bottom, just right of the legal notice box */
.leaflet-bottom.leaflet-left .leaflet-control-scale {
  position: fixed;
  left: 258px;
  bottom: 6px;
  margin: 0;
}
.leaflet-control-scale-line {
  background: var(--panel-glass) !important;
  color: var(--text) !important;
  border-color: var(--text-muted) !important;
  border-radius: var(--r-xs);
  font-size: 10px;
  /* Leaflet adds a white text-shadow for legibility on light maps, which
     looks wrong on the dark theme. */
  text-shadow: none !important;
}

/* ── Plotly (theme bridge) ───────────────────────────────────────────────── */
.js-plotly-plot .main-svg { background: transparent !important; }
.js-plotly-plot .main-svg .bg { fill: transparent !important; }
.js-plotly-plot text { fill: var(--chart-text) !important; }
.js-plotly-plot .gridlayer path,
.js-plotly-plot .zerolinelayer path { stroke: var(--chart-grid) !important; }

/* ── Sliders + dropdowns ─────────────────────────────────────────────────── */
.rc-slider-rail { background-color: var(--border); }
.rc-slider-mark-text { font-size: 11px; white-space: nowrap; color: var(--text-muted); }
.rc-slider-track, .rc-slider-handle { border-color: var(--brand); }
.rc-slider-handle { background-color: var(--surface); }
.rc-slider-handle:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 25%, transparent); }

[data-theme="dark"] .Select-control,
[data-theme="dark"] .Select-menu-outer,
[data-theme="dark"] .VirtualizedSelectOption {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
[data-theme="dark"] .Select-value-label,
[data-theme="dark"] .Select-placeholder,
[data-theme="dark"] .Select-input { color: var(--text) !important; }
[data-theme="dark"] .VirtualizedSelectFocusedOption {
  background: var(--brand-soft);
  color: var(--text);
}
[data-theme="dark"] .Select-arrow { border-top-color: var(--text-muted); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .floating-panel {
    top: auto;
    bottom: 84px;
    right: 10px;
    width: min(88vw, 320px);
    max-height: 42vh;
  }
  .floating-header { max-width: calc(100vw - 24px); }

  .bottom-left-controls { left: 10px; bottom: 88px; gap: 6px; }
  .opacity-slider-box { width: min(56vw, 230px); }
  .pixel-popup {
    top: calc(var(--header-bottom, 66px) + 10px);
    left: 10px;
    width: min(92vw, 410px);
  }
  .pixel-hint-popup {
    top: calc(var(--header-bottom, 66px) + 10px);
    left: 10px;
    width: min(92vw, 320px);
  }
}

@media (max-width: 600px) {
  /* Phones: pinch to zoom — drop the Leaflet zoom + scale controls */
  .leaflet-control-zoom,
  .leaflet-control-scale { display: none !important; }
  .leaflet-bottom.leaflet-left { margin-bottom: 0 !important; }
  .leaflet-control-attribution { margin-bottom: 0 !important; font-size: 9px; }

  /* Desktop-only chrome */
  .stac-panel-box,
  .thuenen-logo-box,
  .pixel-hint-popup,
  .bottom-left-controls .legal-footer { display: none !important; }

  .legal-footer-mobile {
    display: flex;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }

  #map { height: 100dvh; }

  /* Header: leave room for the controls toggle, ellipsize long titles */
  .floating-header { max-width: calc(100vw - 150px); padding: 9px 12px; }
  .app-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .app-subtitle { display: none; }

  /* Layer selection lives inside the Map Controls menu on phones */
  .dataset-tab-bar { display: none !important; }
  .mobile-layer { display: block; }

  /* Small burger FAB, bottom-right above the year slider */
  .map-controls-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 12px;
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    top: auto;
    width: 46px;
    height: 46px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 1003;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  .map-controls-toggle:hover { background: var(--brand-strong); }
  .map-controls-toggle .ui-icon { width: 20px; height: 20px; }

  .panel-close-btn { display: inline-flex !important; }

  /* Skip the crop-type diversity metric on phones (keeps the sheet compact) */
  #pixel-diversity-container { display: none !important; }

  /* Pixel analysis as a bottom sheet too */
  .pixel-popup {
    position: absolute;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 82vh;
    overflow-y: auto;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    z-index: 1006;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  }

  /* Map Controls panel: bottom sheet; the X button closes it */
  #map-controls-panel { display: none; }
  .floating-panel {
    position: absolute;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 74vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    z-index: 1004;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4);
  }

  /* Info panel sits below the tabs */
  .info-modal {
    top: calc(var(--header-bottom, 56px) + 10px);
    left: 10px;
    width: calc(100vw - 20px);
  }

  /* Year slider along the bottom, above the attribution */
  #year-slider-label { display: none; }
  #year-slider-container {
    left: 10px !important;
    right: 10px !important;
    transform: none !important;
    width: auto !important;
    bottom: calc(34px + env(safe-area-inset-bottom, 0px)) !important;
    padding: 6px 10px !important;
    border-radius: 14px;
    z-index: 1000;
  }
  .rc-slider-mark-text { font-size: 9px; }
}

/* ── Fractional-cover RGB ternary legend ─────────────────────────────────── */
.fcover-rgb-legend { margin: 8px auto 2px; text-align: center; }
.fcover-ternary-img { display: block; width: 158px; max-width: 100%; margin: 0 auto; }
.fcover-ternary-caption { font-size: 11px; color: var(--text-muted, #64748b); margin-top: 2px; }

/* ── Fractional-cover time controls (season row + year row + latest button) ─ */
.time-control-column {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas:
    ". season"
    "prev slider";
  gap: 6px;
  align-items: center;
  justify-content: center;
}
#season-toggle { grid-area: season; }
#prev-season-btn { grid-area: prev; }
#year-slider-container { grid-area: slider; }
.season-toggle {
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 999px;
  background-color: var(--panel-glass);
  border: 1px solid var(--border);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
}
.season-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}
.season-btn:hover { background: var(--brand-soft); color: var(--brand); }
#season-toggle[data-active="DJF"] .season-btn[data-value="DJF"],
#season-toggle[data-active="MAM"] .season-btn[data-value="MAM"],
#season-toggle[data-active="JJA"] .season-btn[data-value="JJA"],
#season-toggle[data-active="SON"] .season-btn[data-value="SON"] {
  background: var(--brand);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

/* Separate "see latest observation" button, right of the season pills. */
.latest-btn {
  border: 1px solid var(--border);
  background-color: var(--panel-glass);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  transition: background var(--t-fast), color var(--t-fast);
}
.latest-btn:hover { background: var(--brand-soft); color: var(--brand); }
.latest-btn.active {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
  box-shadow: var(--shadow-sm);
}

/* Latest + next-season actions, stacked to the right of the time control. */
.time-action-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}
