* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1f2937;
}

body { display: flex; flex-direction: column; }

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #065f46;
  color: #fff;
  z-index: 1000;
}

h1 { margin: 0; font-size: clamp(15px, 2.2vw, 22px); font-weight: 700; }

.back {
  flex-shrink: 0;
  padding: 10px 14px;
  border: 0;
  border-radius: 12px;
  background: #fbbf24;
  color: #1f2937;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

#map { flex: 1; background: #eef2f0; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(6, 95, 70, 0.9);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  z-index: 900;
  pointer-events: none;
}

/* District name labels */
.district-label { background: none; border: 0; }
.district-label .name {
  position: absolute;
  /* --dx/--dy: nudge set by layoutLabels() in app.js to avoid overlaps */
  transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px)));
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.district-label .count {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #b91c1c;
  color: #fff;
  font-size: 13px;
  line-height: 22px;
  text-align: center;
}
.district-label.city .name { background: #1f2937; color: #fff; cursor: default; }
.dimmed .name { opacity: 0.35; }
.district-label .name.collapsed { padding: 3px; }
.district-label .name.collapsed .text { display: none; }
.district-label .name.hidden { visibility: hidden; }

/* Species icons shown over the selected district */
.species-tray { background: none; border: 0; }
.species-tray .row {
  position: absolute;
  transform: translate(-50%, 24px);
  display: flex;
  gap: 10px;
}
.species-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 84px;
  padding: 8px 4px 6px;
  border: 3px solid #fff;
  border-radius: 18px;
  background: #ecfdf5;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
  animation: pop 0.35s ease-out backwards;
}
.species-btn .pic { font-size: 38px; line-height: 1; }
.species-btn img.pic { width: 56px; height: 56px; object-fit: cover; border-radius: 12px; }
.species-btn:hover, .species-btn.active { border-color: #fbbf24; transform: scale(1.06); }

@keyframes pop {
  from { opacity: 0; transform: scale(0.3) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Species card */
.card {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: min(380px, calc(100% - 32px));
  max-height: 70%;
  overflow-y: auto;
  padding: 18px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  animation: slide-up 0.3s ease-out;
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(40px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: #f3f4f6;
  font-size: 18px;
  cursor: pointer;
}
.card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; padding-right: 44px; }
.card-pic { font-size: 64px; line-height: 1; }
.card-pic img { width: 96px; height: 96px; object-fit: cover; border-radius: 16px; }
.card h2 { margin: 0 0 4px; font-size: 22px; }
.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: #d1fae5;
  color: #065f46;
  font-size: 13px;
  font-weight: 700;
}
.card dl { margin: 0; }
.card dt { margin-top: 10px; font-size: 13px; font-weight: 700; color: #6b7280; }
.card dd { margin: 2px 0 0; font-size: 17px; }
.card-text { font-size: 16px; line-height: 1.45; }
.card-text.placeholder {
  padding: 10px;
  border: 2px dashed #d1d5db;
  border-radius: 12px;
  color: #9ca3af;
}
.card-source { margin-bottom: 0; font-size: 12px; color: #6b7280; }
.card-source a { color: #065f46; }

@media (max-width: 600px) {
  .card { right: 8px; left: 8px; bottom: 8px; width: auto; }
  .district-label .name { gap: 4px; padding: 3px 7px; font-size: 12px; }
  .district-label .count { min-width: 18px; height: 18px; padding: 0 4px; font-size: 11px; line-height: 18px; }
  .species-btn { width: 70px; font-size: 11px; }
  .species-btn .pic { font-size: 30px; }
}
