:root {
  --ink: #12201a;
  --mist: #e8f0ea;
  --fog: rgba(18, 32, 26, 0.55);
  --panel: rgba(244, 248, 245, 0.92);
  --accent: #1f6b4a;
  --accent-deep: #0f3d2c;
  --warn: #8a3b12;
  --map-low: #d7e8d4;
  --map-mid: #5fa06a;
  --map-high: #0d3b28;
  --shadow: 0 18px 40px rgba(8, 20, 14, 0.22);
  --radius: 14px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

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

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #cfe3d5 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #b7cfc4 0%, transparent 50%),
    linear-gradient(160deg, #f3f7f4 0%, #dbe7df 45%, #c5d5c8 100%);
}

#app {
  position: relative;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
}

#login-gate {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 500px at 20% 0%, #cfe3d5 0%, transparent 55%),
    linear-gradient(160deg, #f3f7f4 0%, #dbe7df 50%, #c5d5c8 100%);
}

#login-gate[hidden],
#app[hidden] {
  display: none !important;
}

.login-card {
  width: min(26rem, 100%);
  padding: 1.75rem 1.6rem;
  background: var(--panel);
  border: 1px solid rgba(18, 32, 26, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 500ms ease-out both;
}

.login-brand {
  margin: 0 0 0.35rem;
  font-size: 1.85rem;
}

.login-card h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.login-card > p {
  margin: 0 0 1rem;
  color: var(--fog);
  font-size: 0.95rem;
  line-height: 1.45;
}

.login-card label {
  display: block;
  font-size: 0.85rem;
  color: var(--fog);
  margin-bottom: 0.35rem;
}

.login-card input {
  width: 100%;
  border: 1px solid rgba(18, 32, 26, 0.12);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 107, 74, 0.15);
}

.btn-login {
  margin-top: 0.9rem;
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.2rem;
  background: linear-gradient(180deg, #2a8059 0%, var(--accent-deep) 100%);
  color: #f4faf6;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn-login:disabled {
  opacity: 0.65;
  cursor: wait;
}

.login-err,
.login-msg {
  margin-top: 0.75rem;
  font-size: 0.88rem;
  line-height: 1.35;
}

.login-err {
  color: var(--warn);
}

.login-msg {
  color: var(--accent-deep);
}

.login-trust {
  margin: 1rem 0 0;
  font-size: 0.78rem;
  color: var(--fog);
}

.brand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.82rem;
  color: var(--fog);
  background: var(--panel);
  border: 1px solid rgba(18, 32, 26, 0.08);
  border-radius: 999px;
  padding: 0.25rem 0.35rem 0.25rem 0.75rem;
  box-shadow: 0 8px 20px rgba(8, 20, 14, 0.12);
}

.btn-ghost {
  border: 0;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  background: rgba(18, 32, 26, 0.06);
  color: var(--ink);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-ghost:hover {
  background: rgba(18, 32, 26, 0.1);
}

.chrome {
  position: absolute;
  z-index: 1000;
  top: 1.1rem;
  left: 1.1rem;
  right: 1.1rem;
  display: grid;
  gap: 0.85rem;
  max-width: 42rem;
  pointer-events: none;
  animation: rise 700ms ease-out both;
}

.chrome > * {
  pointer-events: auto;
}

.brand-block {
  padding: 0.2rem 0.15rem;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 4vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--accent-deep);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.tagline {
  margin: 0.35rem 0 0;
  font-size: 0.98rem;
  color: var(--fog);
  max-width: 28rem;
}

.search {
  display: flex;
  gap: 0.5rem;
  padding: 0.45rem;
  background: var(--panel);
  border: 1px solid rgba(18, 32, 26, 0.08);
  border-radius: 999px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0.75rem 1rem;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  outline: none;
}

.search button {
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(180deg, #2a8059 0%, var(--accent-deep) 100%);
  color: #f4faf6;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease;
}

.search button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.search button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.status {
  min-height: 1.25rem;
  padding: 0 0.4rem;
  font-size: 0.92rem;
  color: var(--fog);
}

.status.error {
  color: var(--warn);
}

.status.loading::before {
  content: "";
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  margin-right: 0.45rem;
  border-radius: 50%;
  border: 2px solid rgba(31, 107, 74, 0.25);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
  vertical-align: -1px;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  animation: map-in 900ms ease-out both;
}

.legend {
  position: absolute;
  z-index: 1000;
  right: 1.1rem;
  bottom: 1.4rem;
  width: min(16.5rem, calc(100vw - 2rem));
  padding: 1rem 1.1rem;
  background: var(--panel);
  border: 1px solid rgba(18, 32, 26, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 500ms ease-out both;
}

.legend h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
}

.legend-bird {
  margin: 0.25rem 0 0.75rem;
  font-size: 0.92rem;
  color: var(--fog);
}

.legend-scale {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.8rem;
  color: var(--fog);
}

.legend-bar {
  height: 0.7rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--map-low), var(--map-mid), var(--map-high));
}

.legend-note {
  margin: 0.7rem 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--fog);
}

/* Leaflet tooltip / popup polish */
.leaflet-tooltip.density-tooltip {
  border: 0;
  border-radius: 10px;
  background: rgba(15, 37, 28, 0.94);
  color: #eef6f1;
  box-shadow: var(--shadow);
  padding: 0.65rem 0.8rem;
  font-family: var(--font-body);
  font-size: 0.86rem;
  line-height: 1.35;
}

.leaflet-tooltip.density-tooltip::before {
  border-top-color: rgba(15, 37, 28, 0.94);
}

.density-tooltip strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.98rem;
  margin-bottom: 0.2rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes map-in {
  from {
    opacity: 0;
    filter: saturate(0.7) brightness(1.05);
  }
  to {
    opacity: 1;
    filter: none;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 720px) {
  .chrome {
    top: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
  }

  .search {
    flex-direction: column;
    border-radius: var(--radius);
  }

  .search button {
    width: 100%;
  }

  .legend {
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    bottom: 0.9rem;
  }
}
