:root {
  --peat: #5a3e2b;
  --peat-dark: #3d2a1d;
  --moss: #4f7a3a;
  --bg: #faf8f4;
  --text: #222;
  --muted: #6b6b6b;
  --border: #d8d2c8;
  --danger: #b3261e;
  --selected: #f2b705; /* border of the selected proposal pin */
  --topbar-h: 52px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Header, map and footer fill the window; the map takes whatever height is left. */
body {
  margin: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 6px 12px;
}
button:disabled { opacity: 0.6; cursor: default; }
button.primary { background: var(--peat); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--peat-dark); }
button.secondary { background: #fff; border-color: var(--border); color: var(--text); }
button.secondary:hover:not(:disabled) { background: #f1ede6; }
button.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
button.link-button {
  background: none;
  border: none;
  padding: 4px;
  color: var(--peat);
  text-decoration: underline;
}
button.icon-button {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 6px;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); }
.req { color: var(--danger); }
.optional { font-weight: 400; font-size: 0.85em; color: var(--muted); }

/* ---------- Layout ---------- */

.container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 16px;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--peat);
  white-space: nowrap;
}
.topbar nav { display: flex; gap: 8px; align-items: center; }
.topbar nav .narrow-only { display: none; }

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-top: 16px;
  padding-bottom: 16px;
}

.map-frame {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.map-area { position: relative; flex: 1; min-width: 0; }
#map { height: 100%; background: #fff; }
.sidebar {
  display: flex;
  flex-direction: column;
  width: 360px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: #fff;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 16px 0;
}
.site-footer p { margin: 0; }
#map.over-range { cursor: pointer; }
#map.placing { cursor: crosshair; }

.panel {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px;
}
.info-empty { margin: 40px 12px; text-align: center; }
.info-clear { position: absolute; top: 8px; right: 6px; color: var(--muted); }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { margin: 0; font-size: 1.1rem; }
.panel-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0;
  font-size: 0.9rem;
}

.pin-list { list-style: none; margin: 0; padding: 0; }
.pin-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.pin-list li:hover .pin-list-name { text-decoration: underline; }
.pin-list-votes {
  min-width: 2.5em;
  text-align: center;
  font-weight: 600;
  color: var(--moss);
}
.pin-list-name { font-weight: 600; }
.pin-list-desc {
  font-size: 0.85rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--peat);
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.banner .link-button { color: #fff; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: #222;
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  max-width: 90vw;
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Dialogs & forms ---------- */

dialog {
  width: min(560px, 94vw);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin-top: 0; color: var(--peat); }

form label { display: block; margin: 12px 0 4px; font-weight: 500; }
input[type="text"], input:not([type]), textarea, select {
  font: inherit;
  width: 100%;
  margin-top: 4px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}
select { width: auto; }
textarea { resize: vertical; }
.help-toggle {
  width: 1.4em;
  height: 1.4em;
  margin-left: 4px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--peat);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}
.help-toggle[aria-expanded="true"] { background: var(--peat); border-color: var(--peat); color: #fff; }
.help-text {
  margin: 4px 0 0;
  padding: 6px 10px;
  border-left: 3px solid var(--moss);
  background: #f4f1ea;
  font-size: 0.85rem;
  color: var(--text);
}
.captcha:not(:empty) { margin-top: 14px; }

.dialog-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 18px;
}
.spacer { flex: 1; }

/* ---------- Map elements ---------- */

.mascot-icon, .pin-marker {
  display: block;
  padding: 0;
  border: none;
  background: none;
  border-radius: 50%;
}
.mascot-icon { width: 56px; height: 56px; }
/* Only the round icon (or the pin) is clickable, not the square box around
   it, so ranges right next to an icon can still be clicked. While placing a
   pin, clicks go through to the map. */
.mascot-container, .pin-container { pointer-events: none !important; }
.mascot-icon, .pin-marker { pointer-events: auto; }
#map.placing .mascot-icon, #map.placing .pin-marker { pointer-events: none; }
.mascot-container:hover, .pin-container:hover { z-index: 1; }
.mascot-container:has(.selected), .pin-container:has(.selected) { z-index: 2; }
.hide-mascots .mascot-container, .hide-pins .pin-container { display: none; }
.mascot-icon img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid var(--ring, #fff);
  background: #fff;
  object-fit: cover;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}
.mascot-icon.selected img { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ring, var(--peat)), 0 1px 8px rgba(0, 0, 0, 0.4); }

/* The pin is a rotated square whose corner points at the location. */
.pin-marker { width: 28px; height: 34px; border-radius: 0; }
.community-pin {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--moss);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.community-pin::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}
.pin-marker.selected { transform: scale(1.2); transform-origin: 50% 100%; }
.pin-marker.selected .community-pin {
  border: 3px solid var(--selected);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25), 0 1px 6px rgba(0, 0, 0, 0.45);
}

/* What the info sidebar shows: a mascot (or several where ranges overlap) or a proposal. */
.details { font-size: 0.9rem; line-height: 1.5; }
.details + .details { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 16px; }
.details .region {
  margin: 0 28px 10px 0; /* clear of the close button */
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--moss);
}
.details-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.details h3 { margin: 0 0 2px; font-size: 1.2rem; color: var(--peat-dark); }
.details .sci { margin: 0; font-style: italic; color: var(--muted); }
.details .mascot-img { width: 72px; height: 72px; flex-shrink: 0; object-fit: cover; border-radius: 50%; }
.details p { white-space: pre-line; overflow-wrap: anywhere; }
.pin-section h4 { margin: 14px 0 2px; font-size: 0.8rem; color: var(--moss); }
.pin-section p { margin: 0; }
.details .back-link { margin: 0 0 10px; padding: 0; font-size: 0.85rem; }
.details-actions { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.vote-button { background: #fff; border: 1px solid var(--moss); color: var(--moss); }
.vote-button.voted { background: var(--moss); color: #fff; }

.map-layers {
  top: 0.5em;
  right: 0.5em;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 6px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
  font-size: 0.85rem;
}
.map-layers:hover { background: #fff; }
.map-layers summary { cursor: pointer; font-weight: 600; }
.map-layers-group { margin-top: 6px; }
.map-layers-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.map-layers label { display: block; margin: 2px 0; cursor: pointer; }

.legend {
  position: absolute;
  left: 0.5em;
  bottom: 2.2em; /* above the attribution; app.js adjusts it when that wraps */
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 18px; /* room for the end labels, which are centered on the bar's ends */
  border-radius: 6px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
  font-size: 0.8rem;
  line-height: 1.3;
}
.legend-title { font-weight: 600; margin-bottom: 4px; }
.legend-gradient { width: 180px; height: 12px; border: 1px solid rgba(0, 0, 0, 0.15); }
.legend-ticks { position: relative; height: 1.3em; width: 180px; }
.legend-ticks span { position: absolute; transform: translateX(-50%); }
/* Keeps peat cells sharp while a zoom animation stretches the last frame. */
.peat-layer canvas { image-rendering: pixelated; }

@media (max-width: 700px) {
  .container { padding: 0 10px; }
  .page { padding-top: 10px; padding-bottom: 10px; }
  .map-frame { flex: none; flex-direction: column; min-height: 0; }
  .map-area { flex: none; height: 65vh; }
  .sidebar { width: auto; border-left: none; border-top: 1px solid var(--border); }
  .panel { overflow-y: visible; }
  .topbar h1 { font-size: 1rem; }
  .topbar nav { gap: 6px; }
  .topbar nav button { padding: 5px 8px; font-size: 0.875rem; white-space: nowrap; }
  .topbar nav .wide-only { display: none; }
  .topbar nav .narrow-only { display: inline; }
  #btn-about { display: none; }
  .legend { display: none; }
}
