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

:root {
  --green-900: #052e16;
  --green-800: #14532d;
  --green-700: #15803d;
  --green-600: #16a34a;
  --green-500: #22c55e;
  --green-400: #4ade80;
  --green-300: #86efac;
  --surface:   #0a1a0e;
  --border:    #1a3a20;
  --text-hi:   #f0fdf4;
  --text-mid:  #86efac;
  --text-lo:   #4a7c5a;
  --map-bg:    #18201b;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--surface);
  color: var(--text-hi);
  /* dvh: on a phone the visible height, without the browser's address bar */
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; overflow: hidden;
}

/* ── Logo (in sidebar) ──────────────────────────────────────────────── */
/* Set in from the left, between flush and centred; the link only as wide as the image. */
.logo {
  display: flex; align-items: center; width: fit-content; margin: 8px 0 6px 16px;
  text-decoration: none; color: inherit;
}
/* The sidebar's logo image; its background is already the page's --surface. */
.logo-img { display: block; height: 48px; width: auto; max-width: 100%; }

/* ── Layout ─────────────────────────────────────────────────────────── */
.main { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  /* a fixed width: the sidebar is not resizable */
  width: 321px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-top {
  padding: 14px 12px 10px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.plant-item {
  padding: 10px 14px; cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  margin: 1px 6px; border-radius: 0 8px 8px 0;
}
.plant-item:hover { background: var(--border); }
.plant-item.active {
  background: rgba(22,163,74,0.15);
  border-left-color: var(--green-500);
}
.plant-name {
  font-size: 0.83rem; font-weight: 500; font-style: italic;
  color: var(--text-mid); line-height: 1.3;
}
.plant-item.active .plant-name { color: var(--green-400); }
.plant-family { font-size: 0.7rem; color: var(--text-lo); margin-top: 2px; }
/* ── Describe a plant (the only input while there is no species dataset) ── */
/* Takes the rest of the sidebar and scrolls: with a few month grids open
   the form is far taller than the window. */
.custom-wrap {
  padding: 6px 0; flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column;
}
.custom-wrap .plant-name { font-style: normal; }
/* The entry is a button in a deep, muted green, so it stands apart from the tinted green of a selected row.
   Only the face is filled; the form opens below it on the plain panel. */
.custom-wrap .plant-item,
.custom-wrap .plant-item:hover,
.custom-wrap .plant-item.active { background: none; border-left-color: transparent; }
.custom-wrap > .plant-item { flex-shrink: 0; }
.custom-wrap .plant-item { padding: 4px 0; margin: 4px 8px; border-radius: 0; border-left: 0; }
.compose-btn {
  padding: 10px 14px; border-radius: 8px;
  background: rgba(20,83,45,0.35); border: 1px solid var(--border);
  transition: background 0.12s, border-color 0.12s;
}
.plant-item:hover .compose-btn { background: rgba(20,83,45,0.6); border-color: var(--green-700); }
.plant-item.active .compose-btn { background: var(--green-800); border-color: var(--green-500); }
.compose-btn .plant-name,
.custom-wrap .compose-btn .plant-name { color: var(--text-mid); font-weight: 600; font-size: 0.95rem; }
.plant-item:hover .compose-btn .plant-name, .plant-item.active .compose-btn .plant-name { color: var(--text-hi); }
.compose-btn .plant-family, .custom-wrap .compose-btn .plant-family { color: var(--text-mid); }
/* All the credits, top right over the map: one muted line, the full licence
   statements on click. Opened, it is capped so it can't cover the map. */
.map-credits {
  position: absolute; top: 0; right: 0; z-index: 650; max-width: min(380px, 100%);
  background: rgba(10,26,14,0.85); color: var(--text-lo);
  border-radius: 0 0 0 8px; padding: 2px 8px;
  font-size: 10px; line-height: 1.45; max-height: 60%; overflow-y: auto;
}
.map-credits summary { cursor: pointer; }
.map-credits summary:hover { color: var(--text-mid); }
.map-credits p { margin-top: 6px; }
.map-credits a { color: var(--text-mid); }
/* Sidebar scrollbars: the same slim green bar on every OS and browser. */
.custom-wrap, .custom-form, .tpl-list, .map-credits {
  scrollbar-width: thin; scrollbar-color: var(--green-800) transparent;
}
@supports selector(::-webkit-scrollbar) {
  .custom-wrap, .custom-form, .tpl-list, .map-credits { scrollbar-width: auto; scrollbar-color: auto; }
  .custom-wrap::-webkit-scrollbar, .custom-form::-webkit-scrollbar, .tpl-list::-webkit-scrollbar,
  .map-credits::-webkit-scrollbar { width: 8px; }
  .custom-wrap::-webkit-scrollbar-track, .custom-form::-webkit-scrollbar-track, .tpl-list::-webkit-scrollbar-track,
  .map-credits::-webkit-scrollbar-track { background: transparent; }
  .custom-wrap::-webkit-scrollbar-thumb, .custom-form::-webkit-scrollbar-thumb, .tpl-list::-webkit-scrollbar-thumb,
  .map-credits::-webkit-scrollbar-thumb {
    background: var(--green-800); border-radius: 4px;
    border: 2px solid var(--surface); background-clip: padding-box;
  }
  .custom-wrap::-webkit-scrollbar-thumb:hover, .custom-form::-webkit-scrollbar-thumb:hover, .tpl-list::-webkit-scrollbar-thumb:hover,
  .map-credits::-webkit-scrollbar-thumb:hover { background: var(--green-600); background-clip: padding-box; }
}
/* The form for "Describe a plant" is laid over the map, flush against the
   sidebar like an extension of it. The map and timeline stay where they are;
   its bottom is set from JS to clear the timeline. */
.desc-panel {
  display: none; position: absolute; top: 0; left: 0; bottom: 120px; z-index: 700;
  width: min(340px, 90%); box-sizing: border-box; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-left: 0;
  border-radius: 0 12px 12px 0; box-shadow: 4px 0 16px rgba(0,0,0,0.4);
}
.desc-panel.open { display: flex; }
.view-row { margin-bottom: 10px; }
.view-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-lo); }
.view-value { font-size: 0.8rem; color: var(--text-hi); line-height: 1.45; white-space: pre-wrap; }
.view-value.is-empty { color: var(--text-lo); font-style: italic; }
/* Plant details of a previewed template, laid out like the top of an encyclopedia entry. */
.view-names { padding-bottom: 10px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.view-sci { font-family: 'Source Serif 4', Georgia, serif; font-size: 1.35rem; font-weight: 600; font-style: italic;
            line-height: 1.25; color: var(--text-hi); overflow-wrap: anywhere; }
.view-common { font-family: 'Source Serif 4', Georgia, serif; font-size: 1rem;
               color: var(--text-hi); margin-top: 4px; overflow-wrap: anywhere; }
.view-common-label { color: var(--text-lo); }
.view-common.is-empty, .view-sci.is-empty { font-size: 0.85rem; font-weight: 400; color: var(--text-lo); }
.view-box { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px;
            background: rgba(255,255,255,0.025); }
.view-box .view-label { margin-bottom: 4px; }
.view-box .view-value { font-family: 'Source Serif 4', Georgia, serif; font-size: 0.88rem; line-height: 1.55; }
.view-box .view-value b { font-family: 'Inter', sans-serif; }
.view-box.has-tag { border-left: 3px solid var(--tag); }
.view-box.has-tag .view-label { display: flex; align-items: center; color: var(--tag); font-weight: 600; }
.view-box.has-tag .tag-ico { margin-right: 5px; }
.view-box { position: relative; }
.view-value.is-clamped { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.view-box.is-collapsible .view-label { padding-right: 26px; }
.view-expand {
  position: absolute; top: 5px; right: 6px; width: 22px; height: 22px; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid transparent; border-radius: 6px; color: var(--tag, var(--text-mid));
}
.view-expand[hidden] { display: none; }
.view-expand:hover { border-color: var(--border); background: rgba(255,255,255,0.05); }
.view-expand:focus-visible { outline: 2px solid var(--green-600); outline-offset: 1px; }
.view-expand svg { width: 14px; height: 14px; transition: transform 0.15s; }
.view-box.is-expanded .view-expand svg { transform: rotate(180deg); }
.view-head-text { min-width: 0; }
.view-by { font-size: 0.68rem; color: var(--text-lo); margin-top: 2px; }
.view-by:empty { display: none; }
#view-body .custom-input:disabled { opacity: 1; cursor: default; color: var(--text-hi); }
.desc-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px 8px; flex-shrink: 0; border-bottom: 1px solid var(--border);
}
.desc-panel-title { font-size: 0.83rem; font-weight: 600; color: var(--text-hi); }
.desc-panel-close {
  width: 24px; height: 24px; padding: 0; display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border); border-radius: 7px;
  color: var(--text-mid); cursor: pointer;
}
.desc-panel-close { display: none; }   /* desktop: the handle on the panel's edge does this; a phone shows it again */
.desc-panel-close:hover { background: var(--border); color: var(--text-hi); }
.desc-panel-close svg, .panel-reopen svg {
  width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
/* A hidden side panel stays open as far as the app is concerned (an edit goes on);
   only this arrow, at the map's left edge, shows it again. */
.desc-panel.collapsed { display: none; }
/* Opening replays the animation (display goes from none to flex), so it needs no JS. Closing is
   the `is-closing` class from playClose: it keeps the panel on screen while it slides away.
   Later and more specific than the rules above, so it wins over `collapsed` and the not-open state.
   The panel slides its whole width behind the sidebar (.map-col clips it), with the same timing as
   the handle's move below, so the handle stays on the panel's edge all the way. */
@keyframes panel-in { from { transform: translateX(-100%); } }
@keyframes panel-out { to { transform: translateX(-100%); } }
.desc-panel.open:not(.collapsed) { animation: panel-in var(--panel-motion); }
.desc-panel.desc-panel.is-closing { display: flex; animation: panel-out var(--panel-motion) forwards; pointer-events: none; }
:root { --panel-motion: 0.25s cubic-bezier(0.4, 0, 0.2, 1); }
.panel-reopen {
  position: absolute; top: calc((100% - var(--tl-clear, 120px)) / 2); transform: translateY(-50%);
  left: 0; z-index: 700; width: 24px; height: 72px; padding: 0;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-left: 0;
  border-radius: 0 8px 8px 0; color: var(--text-mid); box-shadow: 4px 0 12px rgba(0,0,0,0.4);
}
.panel-reopen[hidden] { display: none; }
/* While the panel is shown the handle sticks out of its right edge, arrow pointing back at the sidebar. */
.panel-reopen.is-open { left: min(340px, 90%); }
.panel-reopen.is-open svg { transform: rotate(180deg); }
.panel-reopen, .panel-reopen svg { transition: left var(--panel-motion), transform var(--panel-motion); }
/* The first time a panel opens the handle was hidden: it starts from the map's edge, as the panel does. */
@starting-style {
  .panel-reopen.is-open { left: 0; }
  .panel-reopen.is-open svg { transform: none; }
}
.panel-reopen-text { display: none; }   /* a phone shows the panel's name beside the arrow */
.panel-reopen:hover { background: var(--border); color: var(--text-hi); }
.panel-reopen:focus-visible { outline: 2px solid var(--green-500); outline-offset: 1px; }
.custom-form { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 10px 14px 14px; cursor: default; }
/* One tab per kind of indicator. The strip wraps rather than scrolls, so
   every tab — and its "N set" badge — stays visible at the narrowest width. */
.custom-tabs {
  display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 9px;
}
.custom-tab {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 8px; border-radius: 6px; cursor: pointer;
  background: var(--border); border: 1px solid transparent;
  color: var(--text-mid); font-family: 'Inter', sans-serif;
  font-size: 0.68rem; font-weight: 500;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.custom-tab:hover { color: var(--text-hi); }
.custom-tab.active {
  background: rgba(22,163,74,0.15); border-color: var(--green-600); color: var(--green-400);
}
.custom-tab:focus-visible { outline: 2px solid var(--green-600); outline-offset: 1px; }
.custom-group-count {
  font-size: 0.62rem; font-weight: 600; color: var(--green-400);
}
.custom-group-count:empty { display: none; }
/* In the Edit panel: what differs from the saved template, in the "modified" amber. */
.custom-edit-count {
  font-size: 0.62rem; font-weight: 600; color: #fbbf24; margin-left: 4px;
  padding: 0 5px; border-radius: 8px; background: rgba(251,191,36,0.15);
}
.custom-edit-count:empty { display: none; }
#edit-body .custom-input.is-edited { border-color: #fbbf24; background: rgba(251,191,36,0.12); }
#edit-body .month-toggle.is-edited { color: #fbbf24; }
#edit-body .dlg-tag.is-edited { border-color: #fbbf24; }
#edit-body .dlg-field > span { display: flex; align-items: center; }
.edit-revert {
  margin-left: auto; padding: 1px 7px; font-size: 0.64rem; font-weight: 500; cursor: pointer;
  background: transparent; color: #fbbf24; border: 1px solid rgba(251,191,36,0.5); border-radius: 6px;
}
.edit-revert:hover { background: rgba(251,191,36,0.15); }
.edit-revert[hidden] { display: none; }
.edit-revert:not([hidden]) + .month-toggle { margin-left: 0; }
.custom-panel[hidden] { display: none; }
.custom-panel-title {
  font-size: 0.72rem; font-weight: 600; color: var(--text-hi); margin-bottom: 3px;
}
.custom-group-note {
  font-size: 0.66rem; color: var(--text-lo); line-height: 1.4; margin: 0 0 9px;
}
.custom-row { margin-bottom: 9px; }
.custom-label {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 0.7rem; color: var(--text-mid); font-weight: 500;
  margin-bottom: 4px;
}
/* "By month" toggle beside a field's name, opening its Jan–Dec grid. */
.month-toggle {
  margin-left: auto; flex-shrink: 0; padding: 0; cursor: pointer;
  background: none; border: none; color: var(--text-lo);
  font-family: 'Inter', sans-serif; font-size: 0.64rem; font-weight: 500;
  white-space: nowrap;
}
.month-toggle:hover { color: var(--text-hi); }
.month-toggle.has-bounds { color: var(--green-400); }
.month-toggle::after { content: ' ▸'; display: inline-block; transition: transform 0.15s; }
.month-toggle[aria-expanded="true"]::after { transform: rotate(90deg); }
.month-grid {
  margin: 6px 0 2px 2px; padding-left: 8px; border-left: 2px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.month-grid[hidden] { display: none; }
.month-grid-unit { font-size: 0.64rem; color: var(--text-lo); }
.month-grid .custom-inputs .month-name {
  flex: 0 0 26px; font-size: 0.68rem; color: var(--text-mid);
}
.month-grid .custom-input { padding: 3px 6px; font-size: 0.74rem; }
.custom-label .custom-unit { color: var(--text-lo); font-weight: 400; }
/* What the field measures, under its name. */
.custom-desc {
  font-size: 0.64rem; color: var(--text-lo); line-height: 1.35; margin: -2px 0 5px;
}
.custom-inputs { display: flex; align-items: center; gap: 6px; }
.custom-inputs span { font-size: 0.75rem; color: var(--text-lo); }
.custom-input {
  width: 0; flex: 1; padding: 5px 8px;
  background: var(--border); border: 1px solid transparent;
  border-radius: 6px; color: var(--text-hi);
  font-family: 'Inter', sans-serif; font-size: 0.8rem; outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.custom-input:focus { border-color: var(--green-600); background: #12261a; }
.custom-input::placeholder { color: var(--text-lo); }
.custom-input.is-invalid { border-color: #dc2626; }
.custom-note { font-size: 0.68rem; color: var(--text-lo); line-height: 1.4; }
.custom-note.is-error { color: #f87171; }
/* The species name above the tabs, and its GBIF button. */
.species-row { margin-bottom: 10px; }
.species-msg { font-size: 0.68rem; color: #f87171; line-height: 1.4; margin-top: 5px; }
.species-msg:empty { display: none; }
.species-label { display: block; font-size: 0.75rem; color: var(--text-mid); margin-bottom: 4px; }
.species-row .btn { flex: none; white-space: nowrap; }

/* ── Plant templates (saved custom species; hidden without a database) ── */
.tpl-section {
  padding: 10px 0 0; margin: 6px 8px 0; border-top: 1px solid var(--border);
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
}
.tpl-section > * { flex-shrink: 0; }
.tpl-section[hidden] { display: none; }
.tpl-heading {
  font-size: 0.95rem; font-weight: 600;
  color: var(--text-mid); margin: 4px 0 8px;
}
.tpl-section .custom-input, .sp-dialog .custom-input,
.dlg-field .custom-input, .dlg-tag .custom-input { width: 100%; flex: none; box-sizing: border-box; }
.tpl-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 7px 0 6px; }
.tpl-chip-break { flex-basis: 100%; height: 0; }
.tpl-chip {
  padding: 3px 9px; border-radius: 999px; cursor: pointer;
  background: none; border: 1px solid var(--border); color: var(--text-lo);
  font-family: 'Inter', sans-serif; font-size: 0.8rem; font-weight: 500;
}
.tpl-chip:hover { color: var(--text-hi); }
.tpl-chip.active { color: var(--green-400); border-color: var(--green-700); background: rgba(22,163,74,0.12); }
/* The list takes whatever height is left in the sidebar and scrolls inside it. */
.tpl-section > .tpl-list {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  scrollbar-gutter: stable;
}
.tpl-list > * { flex-shrink: 0; }
.tpl-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent;
            display: flex; align-items: center; gap: 8px; }
.tpl-item-body { flex: 1; min-width: 0; }
.vis-ico { display: inline-flex; vertical-align: -2px; }
.vis-ico svg { width: 1em; height: 1em; }
.view-vis { margin: 0 0 8px; }
.view-vis .btn { flex: 1 1 auto; height: 36px; justify-content: center; padding: 0 8px; font-size: 0.8rem; white-space: nowrap; }
.view-vis .btn svg { width: 16px; height: 16px; }
.view-vis + .view-vis .btn { font-size: 0.7rem; gap: 4px; }
.view-vis + .view-vis .btn svg { width: 13px; height: 13px; }
.view-btns { display: flex; gap: 6px; margin: 0 0 12px; }
/* "Read only. …": under the buttons, above the tabs, so it applies to every section. */
.view-readonly { margin-bottom: 12px; }
.view-btns .btn { display: inline-flex; align-items: center; gap: 5px; }
.view-btns svg { width: 13px; height: 13px; }
#edit-form { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#edit-form .dlg-error { padding: 0 14px; }
.edit-actions {
  display: flex; gap: 8px; justify-content: flex-end; flex-shrink: 0;
  padding: 10px 14px; border-top: 1px solid var(--border);
}
#edit-body .custom-input.is-invalid { border-color: #dc2626; }
.tpl-item:hover { background: var(--border); }
.tpl-item:focus-visible { outline: 2px solid var(--green-600); outline-offset: -2px; }
.tpl-item.active { background: rgba(22,163,74,0.15); border-color: var(--green-700); }
.tpl-item-name { font-size: 0.8rem; color: var(--text-hi); font-weight: 500; }
/* A long name is cut with an ellipsis so the badge always stays whole, on the name's line. */
.tpl-item-name { display: flex; align-items: center; gap: 6px; }
.tpl-item-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-item-name .tpl-badge { flex-shrink: 0; white-space: nowrap; }
.tpl-item-sci { font-size: 0.7rem; color: var(--text-mid); font-style: italic; }
.tpl-item-sci span { display: block; font-style: normal; color: var(--text-lo); }
.tpl-item-by { font-size: 0.66rem; color: var(--text-lo); }
.tpl-badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.tpl-badges:empty { display: none; }
.tpl-badge {
  font-size: 0.6rem; padding: 1px 6px; border-radius: 10px;
  background: rgba(74,222,128,0.1); color: var(--green-400); font-style: normal;
}
.tpl-badge.is-private { background: #4b5563; color: #fff; }
.tpl-badge.is-public { background: #0284c7; color: #fff; }
/* Tag glyphs and colours: --tag is set per tag, and everything tag-coloured reads it. */
.tag-culinary { --tag: #fb923c; }
.tag-medicinal { --tag: #34d399; }
.tag-cultural_keystone { --tag: #facc15; }
.tag-ico { display: inline-flex; vertical-align: -2px; margin-right: 4px; color: var(--tag); }
.tag-ico svg { width: 1.1em; height: 1.1em; }
.tpl-chip.has-tag.active { color: var(--tag); border-color: color-mix(in srgb, var(--tag) 60%, transparent);
                           background: color-mix(in srgb, var(--tag) 14%, transparent); }
.tpl-badge.has-tag { color: var(--tag); background: color-mix(in srgb, var(--tag) 14%, transparent); }
.view-value .tag-ico svg { width: 1em; height: 1em; }
.dlg-tag.has-tag { border-color: color-mix(in srgb, var(--tag) 35%, var(--border)); }
.tpl-empty { font-size: 0.7rem; color: var(--text-lo); padding: 2px 0; }
.tpl-empty.is-error { color: #f87171; }
.tpl-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tpl-actions[hidden], .tpl-actions .btn[hidden] { display: none; }
.btn {
  font-family: 'Inter', sans-serif; font-size: 0.72rem; font-weight: 500;
  padding: 5px 11px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--text-mid);
}
.btn:hover:not(:disabled) { border-color: var(--green-600); color: var(--text-hi); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--green-700); border-color: var(--green-700); color: var(--text-hi); }
.btn-primary:hover:not(:disabled) { background: var(--green-600); }
.btn-danger:hover:not(:disabled) { border-color: #dc2626; color: #f87171; }
.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  font: inherit; color: var(--text-mid); text-decoration: underline;
}
.link-btn:hover { color: var(--text-hi); }
/* Who is logged in, pinned at the bottom of the sidebar. */
.sidebar-account {
  flex-shrink: 0; border-top: 1px solid var(--border); padding: 6px 14px;
  min-height: 56px; box-sizing: border-box;   /* twice the one-line height */
  font-size: 0.68rem; color: var(--text-lo);
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
}
.sidebar-account[hidden] { display: none; }
.sidebar-account b { color: var(--text-mid); font-weight: 600; }
/* The link to teamnagoya.org at the very bottom of the sidebar (and of the phone drawer). */
.sidebar-footer {
  flex-shrink: 0; border-top: 1px solid var(--border); padding: 8px 14px;
  font-size: 0.66rem; color: var(--text-lo);
}
.sidebar-footer a { color: var(--text-mid); text-decoration: none; font-weight: 500; }
.sidebar-footer a:hover { color: var(--text-hi); text-decoration: underline; }
.sidebar-footer a:focus-visible { outline: 2px solid var(--green-500); outline-offset: 1px; border-radius: 2px; }
/* Dialogs (login, save template, manage users): native <dialog>, shown in
   the top layer, so they sit above the map and its controls. */
.sp-dialog {
  margin: auto; width: min(460px, 92vw); max-height: 88vh; overflow-y: auto;
  background: var(--surface); color: var(--text-hi);
  border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.sp-dialog.is-wide { width: min(620px, 94vw); }
.sp-dialog::backdrop { background: rgba(0,0,0,0.55); }
.dlg-title { font-family: 'Sora', sans-serif; font-size: 1rem; margin-bottom: 14px; }
.dlg-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 11px; }
.dlg-field > span, .dlg-label { font-size: 0.7rem; color: var(--text-mid); font-weight: 500; }
.dlg-hint { font-size: 0.64rem; color: var(--text-lo); line-height: 1.4; }
.dlg-contact { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.82rem; color: var(--text-mid); line-height: 1.5; }
.dlg-contact p { margin: 0 0 8px; }
.dlg-contact b { color: var(--text-hi); font-weight: 600; }
.dlg-actions.is-centered { justify-content: center; }
.dlg-contact a { color: var(--green-600); }
.dlg-contact a:hover { color: var(--text-hi); }
textarea.custom-input { resize: vertical; min-height: 64px; line-height: 1.4; }
select.custom-input { cursor: pointer; }
.dlg-field[hidden] { display: none; }
.dlg-radio { display: flex; gap: 16px; font-size: 0.74rem; color: var(--text-mid); margin-top: 2px; }
.dlg-radio.is-stacked { flex-direction: column; gap: 10px; margin: 8px 0 12px; }
.dlg-radio label, .dlg-tag label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.dlg-tag { border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; margin-top: 6px; }
.dlg-tag label { font-size: 0.74rem; color: var(--text-mid); }
.dlg-tag textarea { margin-top: 6px; min-height: 48px; }
.dlg-tag textarea[hidden] { display: none; }
.dlg-error { color: #f87171; font-size: 0.72rem; min-height: 1.1em; margin-bottom: 8px; }
.dlg-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.password-box {
  margin: 6px 0 12px; padding: 9px 11px; border-radius: 8px;
  background: rgba(251,191,36,0.08); border: 1px solid rgba(251,191,36,0.35);
  font-size: 0.72rem; color: var(--text-mid); line-height: 1.5;
}
.password-box[hidden] { display: none; }
.password-box code {
  display: block; margin: 5px 0; padding: 6px 8px; border-radius: 6px;
  background: var(--border); color: var(--text-hi); font-size: 0.85rem;
  user-select: all; word-break: break-all;
}
.users-table { width: 100%; border-collapse: collapse; font-size: 0.74rem; margin-bottom: 14px; }
.users-table th {
  text-align: left; font-size: 0.62rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-lo); padding: 0 6px 6px;
}
.users-table td { padding: 5px 6px; border-top: 1px solid var(--border); color: var(--text-mid); }
.users-table td:last-child { text-align: right; white-space: nowrap; }
.users-table .btn { padding: 3px 8px; font-size: 0.66rem; }
.new-user { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.new-user .custom-input { flex: 1; width: 0; }
.new-user select.custom-input { flex: 0 0 auto; width: auto; }
/* "How the score is calculated" (the legend's "?"): long-form reading, with
   the maths in native MathML, so no maths library is loaded. */
.sp-dialog.is-help { width: min(760px, 94vw); padding: 22px 26px; }
/* The title bar stays in view while the text scrolls under it. */
.help-head {
  position: sticky; top: -22px; z-index: 1; margin: -22px 0 4px; padding: 22px 0 8px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.help-head .dlg-title { margin-bottom: 0; }
.help-close {
  width: 26px; height: 26px; flex-shrink: 0; padding: 0; border-radius: 7px; cursor: pointer;
  background: transparent; border: 1px solid var(--border); color: var(--text-mid);
  font-size: 1.05rem; line-height: 1;
}
.help-close:hover { background: var(--border); color: var(--text-hi); }
.help-close:focus-visible { outline: 2px solid var(--green-500); outline-offset: 1px; }
.help-body { font-size: 0.8rem; line-height: 1.6; color: var(--text-mid); }
.help-body h3 {
  font-family: 'Sora', sans-serif; font-size: 0.86rem; color: var(--text-hi);
  margin: 20px 0 6px;
}
.help-body p, .help-body ul, .help-body table { margin-bottom: 9px; }
.help-body ul { padding-left: 18px; }
.help-body li { margin-bottom: 3px; }
.help-body b, .help-body strong { color: var(--text-hi); font-weight: 600; }
.help-body a { color: var(--green-400); }
.help-body a:hover { color: var(--text-hi); }
.help-body code {
  font-family: ui-monospace, Consolas, monospace; font-size: 0.92em;
  background: var(--border); color: var(--text-hi); padding: 0 4px; border-radius: 4px;
}
.help-body math { font-family: 'Cambria Math', 'STIX Two Math', 'Latin Modern Math', math; color: var(--text-hi); font-size: 1.08em; }
.help-body math[display="block"] {
  margin: 10px 0 12px; padding: 10px 12px; overflow-x: auto;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 8px;
}
.help-lead { font-size: 0.84rem; color: var(--text-hi); }
.help-table { width: 100%; border-collapse: collapse; font-size: 0.76rem; }
.help-table th {
  text-align: left; font-size: 0.62rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-lo); padding: 0 8px 6px;
}
.help-table td { padding: 5px 8px; border-top: 1px solid var(--border); vertical-align: middle; }
.help-table .legend-swatch { display: inline-block; vertical-align: -1px; margin-right: 7px; }
.help-aside {
  border-left: 2px solid var(--green-700); padding: 4px 0 4px 12px; margin: 10px 0 12px;
  font-size: 0.76rem; color: var(--text-mid);
}

/* ── Right column (map + timeline) ──────────────────────────────────── */
.map-col { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; position: relative; }

/* ── Map area ─────────────────────────────────────────────────────────── */
.map-wrap { flex: 1; position: relative; overflow: hidden; }

/* Leaflet map background = dark green, shown wherever the base map is off or
   still loading. */
#map { width: 100%; height: 100%; }
.leaflet-container { background: var(--map-bg) !important; }
/* OSM's bright tiles, turned into a dark grey map: invert, drop the colour,
   tone it down. Only the tile pane is filtered, never the suitability overlay. */
.leaflet-tile-pane { filter: invert(1) grayscale(1) brightness(0.75) contrast(0.9); }

/* Plain arrow over the map instead of Leaflet's grab hand. The map's
   primary action is picking one specific cell, and an arrow points at a
   single point — the hand reads as "drag this around" and hides exactly
   which cell is under the cursor. While actually panning, though, show
   the 4-way move cursor (Google Maps-style) as feedback that the view is
   being dragged. */
.leaflet-container.leaflet-grab { cursor: default !important; }
.leaflet-dragging .leaflet-container.leaflet-grab { cursor: move !important; }

/* Zoom controls — match legend style; positioned left of the legend, see .bottom-right-overlay */
.leaflet-control-zoom {
  margin: 0 !important;
  background: rgba(10,26,14,0.95) !important;
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: none !important;
}
.leaflet-control-zoom a {
  background: transparent !important;
  color: var(--green-400) !important;
  border-bottom-color: var(--border) !important;
}
.leaflet-control-zoom a:last-child { border-bottom: none !important; }
.leaflet-control-zoom a:hover {
  background: rgba(22,163,74,0.12) !important;
}
.leaflet-control-zoom a.leaflet-disabled {
  color: var(--text-lo) !important;
  opacity: 0.4;
  cursor: default !important;
}
.leaflet-control-zoom a.leaflet-disabled:hover {
  background: transparent !important;
}

/* ── Prompt ─────────────────────────────────────────────────────────── */
.prompt {
  position: absolute; inset: 0;
  z-index: 600; text-align: center;
  display: flex; align-items: center; justify-content: center;
}
.prompt-inner {
  background: rgba(10,26,14,0.92); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 36px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  max-width: min(760px, 90vw);
}
.prompt-logo {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; margin-bottom: 20px;
}
/* The transparent version of the logo: the panel behind it is translucent,
   so the sidebar's version, whose background is solid --surface, would show as a box. */
.prompt-logo-img { display: block; height: 84px; width: auto; max-width: 100%; }
.prompt-cards {
  display: flex; gap: 16px; flex-wrap: wrap; justify-content: center;
}
.prompt-card {
  flex: 1 1 180px; max-width: 220px;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px 16px;
}
.prompt-icon { font-size: 2rem; margin-bottom: 10px; }
.prompt-card h3 {
  font-family: 'Sora', sans-serif; font-size: 0.95rem;
  color: var(--text-hi); margin-bottom: 6px;
}
.prompt-card p { font-size: 0.78rem; color: var(--text-lo); line-height: 1.45; }

/* ── Loading ─────────────────────────────────────────────────────────── */
.loading {
  display: none; position: absolute; top: 14px; left: 50%;
  transform: translateX(-50%); z-index: 700;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 7px 16px;
  font-size: 0.78rem; color: var(--green-400); font-weight: 500;
  white-space: nowrap;
}
.loading.visible { display: flex; align-items: center; gap: 7px; }
.loading-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green-500); animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

/* ── Legend ─────────────────────────────────────────────────────────── */
/* Bottom-right overlay group: zoom control (left) + layers button (right), sitting above the timeline */
.bottom-right-overlay {
  display: none; position: absolute; bottom: 120px; right: 12px;
  z-index: 600; align-items: flex-end; gap: 10px;
}
.bottom-right-overlay.visible { display: flex; }
.legend {
  position: absolute; right: 0; bottom: calc(100% + 8px);
  width: min(300px, calc(100vw - 16px)); padding: 14px 16px;
  max-height: calc(100dvh - var(--tl-clear, 120px) - 120px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
/* !important: app.js shows the legend with an inline style once a plant is picked. */
body:not(.layers-open) .legend { display: none !important; }
/* The title bar stays in view while the legend scrolls under it: it reaches out over the
   popup's padding (--lg-y, --lg-x) so nothing shows above or beside it. */
.legend { --lg-y: 14px; --lg-x: 16px; }
.legend-head {
  position: sticky; top: calc(-1 * var(--lg-y)); z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin: calc(-1 * var(--lg-y)) calc(-1 * var(--lg-x)) 9px;
  padding: var(--lg-y) var(--lg-x) 7px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
/* The same title style as Location Data (.tooltip-title). */
.legend-title {
  font-family: 'Sora', sans-serif; font-weight: 700; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-mid);
}
/* The layers button stands in for the legend, which opens above it as a popup:
   scrolling inside, behind the button's own toggle, and closed by the × in its header. */
.layers-btn, .legend-close, .tooltip-close {
  display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer;
  flex-shrink: 0; color: var(--text-mid);
}
.layers-btn {
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(10,26,14,0.95); border: 1px solid var(--border);
}
.layers-btn:hover, .legend-close:hover, .tooltip-close:hover { background: var(--border); color: var(--text-hi); }
body.layers-open .layers-btn { color: var(--green-400); border-color: var(--green-700); }
.legend-close, .tooltip-close {
  width: 28px; height: 28px; border-radius: 8px;
  background: transparent; border: 1px solid var(--border);
}
.layers-btn svg, .legend-close svg, .tooltip-close svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.legend-close svg, .tooltip-close svg { width: 16px; height: 16px; }
.layers-btn:focus-visible, .legend-close:focus-visible, .tooltip-close:focus-visible { outline: 2px solid var(--green-500); outline-offset: 1px; }
.legend-section {
  margin-bottom: 10px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
/* The last section shown: the GBIF one is often hidden after it. */
.credits-btn { display: none; }   /* phones only, see the Phones block */
.legend-section:not(:has(~ .legend-section:not([hidden]))) {
  margin-bottom: 0; padding-bottom: 0; border-bottom: none;
}
.legend-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 5px; font-size: 0.76rem;
}
.legend-row:last-child { margin-bottom: 0; }
.legend-row[hidden] { display: none; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
/* "No data": the cells are transparent, so the street map shows through. */
.legend-swatch.is-none { border: 1px dashed var(--text-lo); box-sizing: border-box; }
.legend-text { color: var(--text-mid); }
.legend-note {
  margin-top: 8px; max-width: 210px;
  font-size: 0.66rem; line-height: 1.45; color: var(--text-lo);
}
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legend-toggle { cursor: pointer; }
/* An on/off switch: the checkbox drawn as a track with a knob, at the row's right end. */
.legend-switch-row { justify-content: space-between; }
/* No section labels: a thin line separates one setting from the next (grid lines | intensity). */
#base-section .legend-switch-row {
  margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.legend-switch {
  appearance: none; -webkit-appearance: none; position: relative; flex-shrink: 0;
  width: 30px; height: 17px; margin: 0; border-radius: 999px; cursor: pointer;
  background: var(--border); border: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}
.legend-switch::before {
  content: ''; position: absolute; top: 1px; left: 1px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--text-mid); transition: transform 0.15s, background 0.15s;
}
.legend-switch:checked { background: var(--green-700); border-color: var(--green-600); }
.legend-switch:checked::before { transform: translateX(13px); background: var(--text-hi); }
.legend-switch:focus-visible { outline: 2px solid var(--green-500); outline-offset: 2px; }
.legend-slider-label { display: flex; justify-content: space-between; }
/* The intensity slider: under its label and percentage, with a square at each end showing what the
   ends look like: the map at the lowest intensity, the full Ideal colour. The bar and the knob are
   drawn here; --p (0 to 1, set from app.js) is how far along the knob is, for the filled part. */
.legend-slider-wrap { --knob: 22px; display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.slider-swatch {
  display: block; flex: none; box-sizing: border-box; width: 32px; height: 32px;
  border-radius: 8px; border: 1px solid var(--border); object-fit: cover;
}
.slider-swatch.is-full { background: #15803d; }   /* the legend's Ideal swatch */
.legend-slider {
  -webkit-appearance: none; appearance: none; display: block; flex: 1; min-width: 0;
  height: var(--knob); margin: 0; background: transparent; cursor: pointer;
}
.legend-slider::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--green-500) calc(var(--p, 0.5) * 100%), var(--border) 0);
}
.legend-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: var(--knob); height: var(--knob); margin-top: -8px;
  border-radius: 50%; background: var(--green-400); border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--green-600); box-sizing: border-box;
}
.legend-slider::-moz-range-track { height: 6px; border-radius: 3px; background: var(--border); }
.legend-slider::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--green-500); }
.legend-slider::-moz-range-thumb {
  width: var(--knob); height: var(--knob); border-radius: 50%; background: var(--green-400);
  border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--green-600); box-sizing: border-box;
}
.legend-spinner {
  width: 12px; height: 12px; margin-left: auto; flex-shrink: 0;
  border: 2px solid var(--border); border-top-color: var(--green-400);
  border-radius: 50%; animation: spin 0.7s linear infinite;
  visibility: hidden;  /* keep the box reserved so showing it never reflows the legend */
}
.legend-spinner.visible { visibility: visible; }
#occ-legend-row .legend-spinner { margin-left: 0; }   /* right after "Plant GBIF location" */
#occ-none[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
/* The colour scale, and to its right the "?" that explains how the score is made. */
.legend-scale { display: flex; align-items: center; gap: 14px; }
.legend-scale-rows { flex: 1; min-width: 0; }
.legend-help-btn {
  width: 38px; height: 38px; flex-shrink: 0; padding: 0; border-radius: 50%;
  background: transparent; border: 1px solid var(--border); cursor: pointer;
  color: var(--text-mid); font-family: 'Inter', sans-serif; font-size: 1.1rem; font-weight: 600;
}
.legend-help-btn:hover { background: var(--border); color: var(--text-hi); }
.legend-help-btn:focus-visible { outline: 2px solid var(--green-500); outline-offset: 1px; }

/* ── Timeline ────────────────────────────────────────────────────────── */
.timeline {
  display: none;
  position: absolute; bottom: 12px; left: 12px; right: 12px;
  background: rgba(10,26,14,0.95); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 24px 28px;
  z-index: 600;
}
.timeline.visible { display: block; }
.tl-header { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-bottom: 10px; }
/* In One year the label is as wide as the longest one ("Sep 21–30, 2099"),
   so the controls beside it never shift as the month or year changes. */
.tl-year.is-one { min-width: 10em; }
/* On desktop the settings sit in the row as if unwrapped; on a phone they are a popup. */
.tl-settings { display: contents; }
.tl-settings-label, .tl-settings-btn { display: none; }
.tl-scenario { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.tl-scenario[hidden] { display: none; }
.tl-scenario .tl-label { text-transform: none; letter-spacing: 0; font-weight: 500; }
/* The range switch (All time / 5 years / One year) and its controls. */
.tl-modes, .tl-unit {
  display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden;
}
.tl-modes button, .tl-unit button {
  padding: 4px 11px; background: none; border: none; cursor: pointer;
  color: var(--text-lo); font-family: 'Inter', sans-serif; font-size: 0.68rem; font-weight: 500;
}
.tl-modes button:hover, .tl-unit button:hover { color: var(--text-hi); }
.tl-modes button.active, .tl-unit button.active {
  color: var(--green-400); background: rgba(22,163,74,0.15);
}
.tl-modes button:focus-visible, .tl-unit button:focus-visible,
.tl-step:focus-visible, .tl-select:focus-visible { outline: 2px solid var(--green-600); outline-offset: -2px; }
.tl-controls { display: none; align-items: center; gap: 6px; }
.tl-controls.is-on { display: flex; }
.tl-step {
  width: 24px; height: 24px; padding: 0; border-radius: 6px; cursor: pointer; line-height: 1;
  background: none; border: 1px solid var(--border); color: var(--text-mid); font-size: 0.95rem;
}
.tl-step:hover:not(:disabled) { color: var(--green-400); border-color: var(--green-700); }
.tl-step:disabled { opacity: 0.35; cursor: default; }
.tl-window { font-size: 0.78rem; color: var(--text-hi); min-width: 92px; text-align: center; font-variant-numeric: tabular-nums; }
.tl-select {
  background: var(--surface); color: var(--text-hi); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 6px; font-family: 'Inter', sans-serif; font-size: 0.74rem;
}
.tl-unit { margin-left: 10px; }
.tl-track:focus-visible { outline: 2px solid var(--green-600); outline-offset: 6px; }
.tl-label {
  font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text-lo);
}
.tl-year {
  font-family: 'Sora', sans-serif; font-size: 1.4rem;
  font-weight: 800; color: var(--green-400); line-height: 1;
}
.tl-track {
  position: relative; height: 20px; background: transparent;
  border-radius: 4px; cursor: pointer; user-select: none; touch-action: none;
  overflow: visible;
}
.tl-track::before {
  content: ''; position: absolute; left: 0; right: 0;
  top: 50%; transform: translateY(-50%); height: 4px;
  background: var(--border); border-radius: 4px;
  transition: height 0.15s ease; pointer-events: none;
}
.tl-track:hover::before { height: 7px; }
.tl-fill {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%); height: 4px;
  background: linear-gradient(90deg, var(--green-700), var(--green-500));
  border-radius: 4px; pointer-events: none;
  transition: height 0.15s ease; z-index: 1;
}
.tl-track:hover .tl-fill { height: 7px; }
.tl-thumb {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 16px; height: 16px; background: var(--green-400);
  border: 3px solid var(--surface); border-radius: 50%; cursor: grab;
  box-shadow: 0 0 0 2px var(--green-600);
  transition: box-shadow 0.15s, width 0.15s ease, height 0.15s ease;
  z-index: 2;
}
.tl-track:hover .tl-thumb,
.tl-thumb.is-dragging {
  width: 20px; height: 20px;
  box-shadow: 0 0 0 3px var(--green-600);
}
.tl-thumb.is-dragging { cursor: grabbing; }
.tl-tick {
  position: absolute; top: calc(50% + 4px); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  pointer-events: none;
}
.tl-tick-line {
  width: 2px; height: 10px;
  background: var(--text-lo); border-radius: 1px; opacity: 0.75;
}
.tl-tick-label {
  font-size: 0.64rem; color: var(--text-lo); font-weight: 500;
  white-space: nowrap; letter-spacing: 0.02em;
}
.tl-tick-small {
  position: absolute; top: calc(50% + 4px); transform: translateX(-50%);
  pointer-events: none;
}
.tl-tick-small-line {
  width: 1.5px; height: 7px;
  background: var(--text-lo); border-radius: 1px; opacity: 0.5;
}

/* ── Selected cell panel (opens on click) ────────────────────────────── */
/* Docked to the top-left of the map area rather than following the cell,
   so it never covers what the user is looking at. Sized to match the
   legend and the other map overlays.

   The panel has exactly two widths, and which one it gets depends on one
   thing only: whether the cell has climate data. Letting it size to its
   content instead made it jump on nearly every click, since both the row
   set and the length of the values change cell to cell. The rows fill the
   chosen width rather than the width following the rows — see .tip-full. */
#cell-tooltip {
  position: absolute;
  top: 14px;
  left: 14px;
  /* Swallows the cursor rather than letting clicks fall through to the
     cells underneath it. */
  pointer-events: auto;
  cursor: default;
  z-index: 800;
  display: none;
  background: rgba(10,26,14,0.95);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  /* No climate data: latitude and longitude alone. */
  width: 210px;
}
/* Climate data: the full row set. Wide enough for the longest line the
   panel can ever hold — "Area in altitude range" against "3,091 km²
   (100.0% of cell's land)", 3,091 km² being the largest a 0.5° cell gets
   (equator, all land). Every other row is shorter, so nothing wraps and
   the height is fixed by the row count alone. */
#cell-tooltip.tip-full { width: 400px; }
/* One climate row per bounded indicator, so with many set the panel can
   outgrow the map; it scrolls rather than running under the timeline. */
#cell-tooltip { max-height: calc(100% - 150px); overflow-y: auto; }
/* A side panel (template details, Describe a plant, Edit) is docked at the
   same top-left corner: the cell panel moves to its right instead of
   covering it, and stays inside the map. */
.desc-panel.open:not(.collapsed) ~ .map-wrap #cell-tooltip {
  /* 24px for the handle sticking out of the panel's edge (.panel-reopen.is-open), then the 14px gap */
  left: calc(min(340px, 90%) + 38px);
  max-width: calc(100% - min(340px, 90%) - 86px);   /* 52px of margins + 34px of padding and border */
}
/* With the panel hidden, clear the arrow that brings it back. */
.map-col.panel-collapsed #cell-tooltip { left: 40px; }
/* Stays in view while the rows scroll under it, reaching out over the panel's
   12px / 16px padding so nothing shows above or beside it. */
.tooltip-title {
  position: sticky; top: -12px; z-index: 1;
  margin: -12px -16px 9px; padding: 12px 16px 7px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 0.72rem;
  color: var(--text-mid);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 9px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
}
/* .tooltip-close is styled with .legend-close (see Map Details): all close buttons look and measure alike. */
.tooltip-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.76rem;
  color: var(--text-lo);
  padding: 3px 0;
  /* The panel's height is meant to be the row count and nothing else, so a
     row that no longer fits must overflow visibly rather than wrap
     silently and push the box taller. */
  white-space: nowrap;
}
.tooltip-row > span:first-child { flex: 0 0 auto; }
.tooltip-val {
  font-weight: 600;
  color: var(--green-400);
  font-variant-numeric: tabular-nums;
}
/* The dash standing in for a value the data doesn't have. Muted and lighter
   than a real value, so an absence never reads as a measurement. */
.tooltip-val.is-empty {
  color: var(--text-lo);
  font-weight: 500;
}
/* A limit the cell misses: a yearly one rules it out, a monthly one costs
   that month's share of the year. */
.tooltip-val.is-miss { color: #f87171; }
/* time shares, tinted like the map's suitability classes (same thresholds) */
.tooltip-val.share-4 { color: #22c55e; }
.tooltip-val.share-3 { color: #4ade80; }
.tooltip-val.share-2 { color: #facc15; }
.tooltip-val.share-1 { color: #f97316; }
.tooltip-val.share-0 { color: #f87171; }
/* The cell's suitability score, above the rows: the number the map colours,
   in its legend colour (class set by app.js), with the class name beside it. */
#tooltip-score {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
#tooltip-score[hidden] { display: none; }
.score-num {
  font-family: 'Sora', sans-serif;
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score-num .tooltip-skeleton { width: 90px; height: 1.6rem; vertical-align: middle; }
.score-label { font-size: 0.76rem; color: var(--text-lo); }
.score-label strong { font-weight: 600; }
.score-4 { color: #15803d; }
.score-3 { color: #4ade80; }
.score-2 { color: #facc15; }
.score-1 { color: #f97316; }
.score-0 { color: #dc2626; }
/* Stand-in for a value still being computed (e.g. re-fetching after a
   year/species change) — an animated bar instead of a number. */
.tooltip-skeleton {
  display: inline-block;
  width: 44px;
  height: 0.85em;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--border) 25%, rgba(255,255,255,0.10) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: tooltip-shimmer 1.2s ease-in-out infinite;
}
@keyframes tooltip-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Selected-cell pin. The SVG's point sits at the cell centre (see
   iconAnchor); the default leaflet-div-icon chrome is opted out of by
   passing our own className. */
.sel-pin { background: none; border: none; }
.sel-pin svg { display: block; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5)); }

/* ── Phones ──────────────────────────────────────────────────────────── */
/* One breakpoint, the same as mobileQuery in app.js. Below it the sidebar is a
   drawer behind the menu button, and the side panels and the Location Data
   panel are sheets along the bottom of the map, above the timeline
   (--tl-clear, set from JS, is how far up that is). Desktop is untouched. */
.menu-btn, .drawer-close, .drawer-backdrop { display: none; }
@media (max-width: 760px) {
  /* iOS zooms the page into any field under 16px as it gets focus. */
  .custom-input, .month-grid .custom-input, .tl-select { font-size: 16px; }
  /* The search can't go under 16px (iOS would zoom), so the heading goes above it and the box gets slimmer. */
  .tpl-heading, .compose-btn .plant-name, .custom-wrap .compose-btn .plant-name { font-size: 1.1rem; }
  #tpl-search { padding: 4px 8px; }

  /* The sidebar, slid in from the left over a dimmed page. */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 1000;
    width: 100%;
    transform: translateX(-100%); visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
  }
  body.drawer-open .sidebar { transform: none; visibility: visible; box-shadow: 4px 0 24px rgba(0,0,0,0.5); }
  body.drawer-open .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 999; background: rgba(0,0,0,0.55);
  }
  .sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .menu-btn, .drawer-close {
    display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer;
    width: 40px; height: 40px; flex-shrink: 0; border-radius: 10px;
    background: rgba(10,26,14,0.95); border: 1px solid var(--border); color: var(--text-mid);
  }
  .menu-btn { position: absolute; top: 10px; left: 10px; z-index: 750; }
  .menu-btn svg, .drawer-close svg {
    width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
  }
  .menu-btn:focus-visible, .drawer-close:focus-visible { outline: 2px solid var(--green-500); outline-offset: 1px; }

  /* The top edge holds the menu button, the map details button and the loading pill: keep them apart. */
  .loading { top: 60px; }

  /* Welcome: the cards stacked. No button to the plants: users find the menu button themselves. */
  .prompt { align-items: flex-start; overflow-y: auto; padding: 60px 10px 16px; }
  .prompt-inner { width: 100%; max-width: none; padding: 18px 14px; }
  .prompt-logo { margin-bottom: 14px; }
  .prompt-logo-img { height: 56px; }
  .prompt-cards { flex-direction: column; gap: 8px; }
  .prompt-card {
    flex: none; max-width: none; padding: 12px 14px; text-align: left;
    display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center;
  }
  .prompt-icon { grid-row: span 2; font-size: 1.6rem; margin-bottom: 0; }

  /* Side panels: a sheet along the bottom, scrolling inside, under the menu button.
     Always its full height, so it doesn't jump as the form's tabs change, as on desktop. */
  .desc-panel {
    top: auto; left: 8px; right: 8px; width: auto;
    height: min(60%, calc(100% - var(--tl-clear, 120px) - 60px));
    border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.4);
  }
  /* Hiding shrinks the sheet down into the show bar: the title row stays in view and travels down
     to where the bar sits (--bar-h, the header's height, set from app.js), the content is cut off
     under it, and its arrow turns to point up as the bar's does. Showing grows the bar back up. */
  @keyframes panel-up { from { height: var(--bar-h, 56px); } }
  @keyframes panel-down { to { height: var(--bar-h, 56px); } }
  @keyframes panel-arrow-up { to { transform: rotate(90deg); } }
  @keyframes panel-arrow-down { from { transform: rotate(90deg); } }
  .desc-panel.open:not(.collapsed) { animation: panel-up var(--panel-motion); overflow: hidden; }
  .desc-panel.desc-panel.is-closing { animation: panel-down var(--panel-motion) forwards; overflow: hidden; }
  .desc-panel.open:not(.collapsed) .desc-panel-close svg { animation: panel-arrow-down var(--panel-motion); }
  .desc-panel.is-closing .desc-panel-close svg { animation: panel-arrow-up var(--panel-motion) forwards; }
  .panel-reopen, .panel-reopen svg { transition: none; }   /* the bar doesn't move */
  /* The arrows that hide and show it point down and up rather than sideways. */
  .desc-panel-close { display: flex; flex-shrink: 0; width: 34px; height: 34px; border: 0; border-radius: 0; }
  .desc-panel-close:hover { background: transparent; }
  .desc-panel-close svg { width: 22px; height: 22px; }   /* as the show arrow in the bar */
  .desc-panel-close svg, .panel-reopen svg { transform: rotate(-90deg); }
  /* A bar as wide as the screen: the template's name and its info line. */
  .panel-reopen {
    top: auto; transform: none; bottom: var(--tl-clear, 120px); left: 8px; right: 8px;
    width: auto; height: auto; padding: 12px 14px 8px; gap: 8px;   /* as tall as a panel's header */
    justify-content: flex-start; text-align: left;
    border: 1px solid var(--border); border-radius: 10px;
  }
  /* The arrow at the right end, unboxed, in a 34px square like the open panel's hide arrow,
     so the bar is exactly as tall as the header it stands in for. */
  .panel-reopen svg {
    flex-shrink: 0; order: 2; box-sizing: border-box; width: 34px; height: 34px; padding: 6px;
  }
  .panel-reopen { border-bottom-width: 1px; }
  .panel-reopen-text { align-self: center; }
  /* Tapping a panel's header hides it, as the arrow does. */
  .desc-panel-head { cursor: pointer; }
  .panel-reopen-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
  .panel-reopen-label {
    display: block; font-family: 'Inter', sans-serif; font-size: 0.83rem; font-weight: 600;
    color: var(--text-hi); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .panel-reopen-info {
    display: block; font-family: 'Inter', sans-serif; font-size: 0.68rem; color: var(--text-lo);   /* as the header's line */
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .panel-reopen-info:empty { display: none; }
  /* The template's "Template by … · updated …" line on one line, cut off like the bar's: the header
     is then laid out like the bar, so the sheet shrinks into it with no jump at the end. */
  .view-by { margin-top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Location Data: the same place as the side panels, which hide while it shows. */
  #cell-tooltip, #cell-tooltip.tip-full,
  .desc-panel.open:not(.collapsed) ~ .map-wrap #cell-tooltip,
  .map-col.panel-collapsed #cell-tooltip {
    top: auto; left: 8px; right: 8px; bottom: var(--tl-clear, 120px);
    width: auto; max-width: none; max-height: 45%;
    background: var(--surface);   /* opaque: the legend is under it */
  }
  /* No fixed width to fit the longest line in, so a long value wraps. */
  .tooltip-row { white-space: normal; }
  .tooltip-val { text-align: right; }

  /* No zoom buttons (pinch to zoom); the legend popup's close button is finger-sized. */
  .leaflet-control-zoom { display: none; }
  /* The layers button sits at the top right. Map details come up from the bottom as a sheet,
     over the timeline, and stop short of the top so the map stays in view: changing a
     switch or the intensity shows on the map right away. The overlay is unpositioned here,
     so the sheet is placed against the map and not against the button. */
  .bottom-right-overlay { position: static; }
  .layers-btn { position: absolute; top: 10px; right: 8px; z-index: 750; }
  .legend {
    left: 8px; right: 8px; width: auto; top: auto; bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 720; max-height: calc(100% - 60px);   /* as tall as its content; scrolls only on a very short screen */
    box-shadow: 0 -4px 16px rgba(0,0,0,0.4);
    animation: sheet-up 0.2s ease-out;
  }
  @keyframes sheet-up { from { transform: translateY(32px); opacity: 0; } }
  /* Closing plays it backwards; app.js keeps the sheet shown until it ends. */
  @keyframes sheet-down { to { transform: translateY(32px); opacity: 0; } }
  .legend.is-closing { animation: sheet-down 0.18s ease-in forwards; }
  @media (prefers-reduced-motion: reduce) { .legend, .legend.is-closing { animation: none; } }
  .legend { --lg-y: 12px; --lg-x: 14px; padding: 12px 14px; }
  .legend-close, .tooltip-close { width: 34px; height: 34px; }
  /* The credits are not over the map here: a button at the end of Map details opens them in a
     popup (app.js moves their text into that dialog). */
  .map-credits { display: none; }
  .credits-btn {
    display: block; width: 100%; margin-top: 0; padding: 9px 6px; min-height: 40px;
    box-sizing: border-box; cursor: pointer; text-align: center;
    background: none; border: 1px solid var(--border); border-radius: 10px;
    color: var(--text-mid); font: inherit; font-size: 0.7rem; font-weight: 600;
  }
  .credits-btn:hover { background: var(--border); color: var(--text-hi); }
  .credits-btn:focus-visible { outline: 2px solid var(--green-500); outline-offset: 1px; }
  /* The line above the credits button, which ends the sheet. */
  #occ-section { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }

  /* Timeline: tighter, with controls big enough for a finger. */
  .timeline {
    left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
    padding: 10px 18px 26px;
  }
  .tl-header { gap: 6px 8px; margin-bottom: 8px; }
  .tl-year { font-size: 1.15rem; }
  .tl-year.is-one { min-width: 0; }
  .tl-unit { margin-left: 0; }
  .tl-step { width: 34px; height: 34px; }
  .tl-modes button, .tl-unit button { padding: 8px 11px; }
  .tl-track { height: 28px; }
  /* The climate prediction and the range switch: a popup above the timeline's
     right end, behind the settings button at the end of its row. */
  .tl-settings-btn {
    display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer;
    margin-left: auto; width: 34px; height: 34px; flex-shrink: 0; border-radius: 8px;
    background: none; border: 1px solid var(--border); color: var(--text-mid);
  }
  .tl-settings-btn svg {
    width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
    transition: transform 0.3s ease;   /* the gear turns when the popup opens and back when it closes */
  }
  body.tl-settings-open .tl-settings-btn svg { transform: rotate(90deg); }
  @media (prefers-reduced-motion: reduce) { .tl-settings-btn svg { transition: none; } }
  .tl-settings-btn:focus-visible { outline: 2px solid var(--green-500); outline-offset: 1px; }
  body.tl-settings-open .tl-settings-btn { color: var(--green-400); border-color: var(--green-700); }
  /* The button stays at the end of the first row; the 5 years / One year controls go under it. */
  .tl-controls.is-on { order: 1; flex-basis: 100%; }
  .tl-settings {
    display: none; position: absolute; right: 0; bottom: calc(100% + 8px);
    width: min(300px, calc(100vw - 16px)); box-sizing: border-box; padding: 12px 14px;
    flex-direction: column; align-items: stretch; gap: 8px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  }
  body.tl-settings-open .tl-settings { display: flex; }
  /* Over the side panel's show button, which sits where the popup opens. */
  body.tl-settings-open .timeline { z-index: 710; }
  .tl-settings .tl-scenario { margin: 0 0 6px; flex-direction: column; align-items: stretch; gap: 6px; }
  .tl-settings .tl-scenario[hidden] { display: none; }
  .tl-settings .tl-scenario .tl-label { text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }
  .tl-settings-label { display: block; }
  .tl-settings .tl-modes button { flex: 1; }

  .sp-dialog { max-height: 88dvh; }
}

/* No motion: no animation either way, so playClose finishes at once. */
@media (prefers-reduced-motion: reduce) {
  .desc-panel.open:not(.collapsed), .desc-panel.desc-panel.is-closing,
  .desc-panel .desc-panel-close svg { animation: none !important; }
  .panel-reopen, .panel-reopen svg { transition: none; }
}
