:root {
  --bg: #ffffff;
  --fg: #1d2420;
  --muted: #5b665f;
  --line: #d9dfdb;
  --brand: #1f4d2b;
  --brand-fg: #ffffff;
  --permit: #2e8540;
  --ask: #b7791f;
  --no: #c0392b;
  --unknown: #6b7280;
  --farm: #c2410c;
  --shadow: 0 4px 18px rgba(0, 0, 0, .18);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18201b;
    --fg: #e8ede9;
    --muted: #a3afa7;
    --line: #34413a;
    --brand: #173a21;
    --permit: #4caf61;
    --ask: #e0a43a;
    --no: #e5675a;
    --farm: #f07a3c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
a { color: inherit; }

.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-fg);
  z-index: 1000;
}
.bar h1 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 8px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.12); color: inherit;
}
.btn:hover { background: rgba(255,255,255,.22); }
.btn:focus-visible, .btn:focus-within { outline: 2px solid #fff; outline-offset: 2px; }
.btn.primary { background: #fff; color: var(--brand); border-color: #fff; }
.btn.ghost { border-color: transparent; }
.btn[disabled] { opacity: .6; cursor: progress; }

#stage { flex: 1; min-height: 0; position: relative; }
#map { position: absolute; inset: 0; }
.leaflet-container { font: inherit; background: #dfe7e1; }

.hint {
  position: absolute; left: 50%; transform: translateX(-50%); top: 12px; margin: 0;
  background: var(--bg); color: var(--fg); padding: 6px 12px; border-radius: 999px;
  box-shadow: var(--shadow); font-size: 13px; z-index: 900; pointer-events: none;
  white-space: nowrap;
}

.panel {
  position: absolute; z-index: 950; background: var(--bg); color: var(--fg);
  box-shadow: var(--shadow); border-radius: 12px; padding: 16px 18px;
  left: 12px; bottom: 24px; width: min(400px, calc(100vw - 24px));
  max-height: calc(100% - 120px); overflow: auto;
}
.panel[hidden] { display: none; }
.close {
  position: absolute; right: 8px; top: 6px; border: 0; background: none;
  font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px;
}
.verdict { display: flex; gap: 10px; align-items: flex-start; margin: 0 24px 8px 0; }
.verdict .badge {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 18px;
}
.verdict h2 { margin: 4px 0 0; font-size: 17px; }
.s-permit .badge { background: var(--permit); }
.s-ask .badge { background: var(--ask); }
.s-no .badge { background: var(--no); }
.s-unknown .badge { background: var(--unknown); }
.panel p { margin: 6px 0; }
.panel ul { margin: 6px 0; padding-left: 20px; }
.panel .links a { display: block; font-weight: 600; margin: 6px 0; color: var(--permit); }
.panel .meta { color: var(--muted); font-size: 13px; }
.panel .warn { background: color-mix(in srgb, var(--ask) 16%, transparent); border-left: 3px solid var(--ask); padding: 6px 10px; border-radius: 4px; }
.panel .share { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn.small { padding: 6px 10px; font-size: 14px; color: var(--fg); border-color: var(--line); background: transparent; }
.btn.small:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); }
.share-url { width: 100%; font: inherit; font-size: 13px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
.panel .disclaimer { color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 10px; }
.panel img.thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; float: right; margin: 0 0 6px 10px; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--permit); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

.legend {
  position: absolute; right: 12px; bottom: 24px; z-index: 900;
  background: var(--bg); color: var(--fg); box-shadow: var(--shadow); border-radius: 10px;
  padding: 8px 12px; font-size: 12.5px; max-width: 230px;
}
.legend div { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.legend .sma { display: block; margin-top: 6px; }
.legend .sma em { font-style: normal; color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.3); flex: none; }
.dot.permit { background: var(--permit); }
.dot.nopermit { background: var(--unknown); }
.dot.farm { background: var(--farm); border-radius: 3px; }
.sw { width: 16px; height: 12px; flex: none; }
.sw.wild { background: repeating-linear-gradient(45deg, rgba(192,57,43,.55) 0 3px, transparent 3px 6px); border: 1px solid rgba(192,57,43,.8); }

/* Map markers */
.pin { border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); display: grid; place-items: center; font-size: 13px; }
.pin.permit { background: var(--permit); }
.pin.nopermit { background: var(--unknown); }
.pin.farm { background: var(--farm); border-radius: 5px; }
.pin.here { background: #2563eb; }
.leaflet-popup-content { margin: 10px 14px; }
.leaflet-popup-content h3 { margin: 0 0 4px; font-size: 15px; }
.leaflet-popup-content p { margin: 4px 0; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg); color: var(--fg); }
.leaflet-control-layers { background: var(--bg); color: var(--fg); }
.status-chip { position: absolute; top: 12px; left: 12px; z-index: 900; background: var(--bg); padding: 4px 10px; border-radius: 999px; box-shadow: var(--shadow); font-size: 12.5px; }

dialog {
  border: 0; border-radius: 14px; padding: 18px 22px; max-width: min(560px, calc(100vw - 32px));
  background: var(--bg); color: var(--fg); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin-top: 0; }
dialog h3 { margin-bottom: 4px; font-size: 15px; }

@media (max-width: 640px) {
  .bar h1 { font-size: 16px; }
  .actions { margin-left: 0; width: 100%; }
  .actions .btn { flex: 1 1 auto; justify-content: center; padding: 8px; font-size: 14px; }
  .bar { position: relative; }
  .btn.ghost { position: absolute; top: max(6px, env(safe-area-inset-top)); right: 8px; padding: 6px 8px; font-size: 13px; }
  .hint { top: auto; }
  .hint { bottom: 28px; }
  .status-chip { top: 12px; bottom: auto; }
  .panel { left: 8px; right: 8px; width: auto; bottom: 24px; max-height: 62%; }
  .legend { display: none; }
  .legend.open { display: block; }
}
