@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700&display=swap");

:root {
  color-scheme: dark;
  --ink: #edf8f7;
  --muted: #94adae;
  --deep: #06151d;
  --panel: #0a2029;
  --panel-2: #0d2a34;
  --line: rgba(185, 229, 224, 0.13);
  --line-strong: rgba(185, 229, 224, 0.24);
  --accent: #57dbc8;
  --accent-strong: #8ff0df;
  --accent-dark: #073f3d;
  --danger: #ff9f93;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
  font-family: "DM Sans", system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--deep);
  color: var(--ink);
}

body {
  min-width: 320px;
}

button,
select {
  font: inherit;
}

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(87, 219, 200, 0.52);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 2000;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #05201e;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  height: 100dvh;
  overflow: hidden;
}

.map-panel {
  position: relative;
  min-width: 0;
  background: #09232e;
}

#map {
  width: 100%;
  height: 100%;
  background: #09232e;
}

.leaflet-tile-pane {
  filter: saturate(0.64) brightness(0.72) contrast(1.12) hue-rotate(142deg);
}

.leaflet-control-zoom {
  border: 1px solid var(--line-strong) !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
  border-color: var(--line) !important;
  background: rgba(7, 27, 35, 0.94) !important;
  color: var(--ink) !important;
}

.leaflet-control-attribution {
  background: rgba(6, 21, 29, 0.76) !important;
  color: var(--muted) !important;
}

.leaflet-control-attribution a {
  color: var(--accent-strong) !important;
}

.map-topbar {
  position: absolute;
  z-index: 500;
  top: 22px;
  left: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 13px 10px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  background: rgba(6, 21, 29, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent-strong), #2db7b6);
  color: #052827;
}

.brand-mark svg {
  width: 28px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 3;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: "Manrope", sans-serif;
  font-size: 1rem;
  line-height: 1.2;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.icon-button,
.map-action {
  pointer-events: auto;
  border: 1px solid var(--line-strong);
  background: rgba(6, 21, 29, 0.9);
  color: var(--ink);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.icon-button {
  display: grid;
  min-width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 14px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
}

.map-instruction,
.map-action {
  position: absolute;
  z-index: 500;
  bottom: 28px;
}

.map-instruction {
  left: 50%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(6, 21, 29, 0.9);
  color: var(--ink);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  backdrop-filter: blur(16px);
  font-size: 0.86rem;
  pointer-events: none;
}

.map-instruction svg,
.map-action svg,
.location-pin svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.map-action {
  right: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  cursor: pointer;
}

.explorer-panel {
  z-index: 600;
  padding: 32px 30px 42px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background:
    radial-gradient(circle at 100% 0%, rgba(42, 178, 169, 0.11), transparent 32%),
    var(--deep);
  box-shadow: -22px 0 70px rgba(0, 0, 0, 0.22);
  scrollbar-color: var(--line-strong) transparent;
}

.explorer-header {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  font-family: "Manrope", sans-serif;
}

h1 {
  max-width: 350px;
  margin-bottom: 10px;
  font-size: clamp(1.85rem, 3.1vw, 2.55rem);
  line-height: 1.07;
  letter-spacing: -0.045em;
}

.explorer-header > p:last-child {
  max-width: 350px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
}

.search-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(13, 42, 52, 0.94), rgba(9, 31, 40, 0.94));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.15);
}

.location-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 17px;
  border-bottom: 1px solid var(--line);
}

.field-label,
.location-row strong,
.location-row small {
  display: block;
}

.field-label,
.radius-control label {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.location-row strong {
  font-size: 1rem;
}

.location-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.location-pin {
  display: grid;
  flex: 0 0 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(87, 219, 200, 0.2);
  border-radius: 11px;
  background: rgba(87, 219, 200, 0.09);
  color: var(--accent);
}

.radius-control {
  display: grid;
  grid-template-columns: 1fr 130px;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.radius-control label {
  margin: 0;
  font-size: 0.88rem;
}

.select-wrap {
  position: relative;
}

.select-wrap select {
  width: 100%;
  min-height: 42px;
  padding: 0 38px 0 13px;
  appearance: none;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #09202a;
  color: var(--ink);
  cursor: pointer;
}

.select-wrap svg {
  position: absolute;
  top: 50%;
  right: 12px;
  width: 17px;
  fill: none;
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transform: translateY(-50%);
  pointer-events: none;
}

.primary-button {
  display: flex;
  width: 100%;
  min-height: 49px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: #052624;
  cursor: pointer;
  font-weight: 700;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.primary-button:hover {
  box-shadow: 0 10px 28px rgba(87, 219, 200, 0.18);
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.primary-button svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.status {
  display: none;
  margin-top: 18px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.status.visible {
  display: flex;
  align-items: center;
  gap: 11px;
}

.status.error {
  border-color: rgba(255, 159, 147, 0.24);
  color: var(--danger);
}

.spinner {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 2px solid rgba(87, 219, 200, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

.results {
  margin-top: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 26px;
}

.stat {
  min-width: 0;
  padding: 13px 9px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(13, 42, 52, 0.44);
  text-align: center;
}

.stat span,
.stat small {
  display: block;
}

.stat span {
  overflow: hidden;
  font-family: "Manrope", sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  text-overflow: ellipsis;
}

.stat small {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.7rem;
  text-overflow: ellipsis;
}

.results-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.results-heading .eyebrow {
  margin-bottom: 3px;
}

h2 {
  margin-bottom: 0;
  font-size: 1.22rem;
  letter-spacing: -0.025em;
}

.year-range {
  padding-bottom: 2px;
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.species-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.load-more-button {
  display: flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(87, 219, 200, 0.07);
  color: var(--accent);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.load-more-button:hover {
  background: rgba(87, 219, 200, 0.13);
}

.load-more-button:focus-visible {
  outline: 3px solid rgba(87, 219, 200, 0.38);
  outline-offset: 2px;
}

.load-more-button svg {
  width: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.load-more-button[hidden] {
  display: none;
}

.species-card {
  display: grid;
  width: 100%;
  min-height: 64px;
  grid-template-columns: 29px minmax(0, 1fr) auto 18px;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background 150ms ease, border-color 150ms ease;
}

.species-card:hover {
  border-color: var(--line);
  background: rgba(13, 42, 52, 0.58);
}

.species-card.active {
  border-color: rgba(87, 219, 200, 0.36);
  background: rgba(87, 219, 200, 0.1);
}

.species-card.active .chevron {
  stroke: var(--accent);
}

.rank-number {
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border-radius: 9px;
  background: rgba(87, 219, 200, 0.08);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}

.species-name {
  min-width: 0;
}

.species-name strong,
.species-name small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.species-name strong {
  font-size: 0.92rem;
  font-style: italic;
  font-weight: 600;
}

.species-name small,
.record-total {
  color: var(--muted);
  font-size: 0.73rem;
}

.record-total {
  white-space: nowrap;
}

.chevron {
  width: 17px;
  fill: none;
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.data-note {
  margin: 17px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.data-note a,
.detail-link {
  color: var(--accent);
}

.detail-backdrop {
  position: fixed;
  z-index: 900;
  inset: 0;
  display: none;
  background: rgba(0, 8, 12, 0.2);
}

.detail-backdrop[hidden] {
  display: none;
  pointer-events: none;
}

.species-detail {
  position: fixed;
  z-index: 700;
  top: 0;
  right: 430px;
  width: min(420px, calc(100vw - 430px));
  height: 100dvh;
  padding: 72px 30px 34px;
  overflow-y: auto;
  border-left: 1px solid var(--line-strong);
  background:
    radial-gradient(circle at 100% 0%, rgba(87, 219, 200, 0.13), transparent 30%),
    #071a23;
  box-shadow: -25px 0 80px rgba(0, 0, 0, 0.42);
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateX(105%);
  transition: transform 230ms ease, opacity 160ms ease;
}

.species-detail.open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.detail-toolbar {
  position: absolute;
  top: 24px;
  left: 30px;
  right: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.species-navigation {
  display: flex;
  align-items: center;
  gap: 7px;
}

.species-navigation button,
.close-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(13, 42, 52, 0.7);
  color: var(--ink);
  cursor: pointer;
}

.species-navigation button {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

.species-navigation button:disabled {
  cursor: default;
  opacity: 0.34;
}

.species-navigation span {
  min-width: 45px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.close-button {
  flex: 0 0 auto;
}

.close-button svg,
.species-navigation svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.detail-kicker {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.detail-title {
  margin-bottom: 8px;
  font-family: "Manrope", sans-serif;
  font-size: 2rem;
  font-style: italic;
  letter-spacing: -0.045em;
  line-height: 1.1;
}

.detail-authority {
  margin-bottom: 20px;
  color: var(--muted);
}

.species-photo {
  margin: 0 0 24px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  background: var(--panel-2);
}

.species-photo a {
  display: block;
}

.species-photo img {
  display: block;
  width: 100%;
  height: 210px;
  object-fit: cover;
}

.species-photo figcaption {
  padding: 9px 12px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.species-photo figcaption a {
  display: inline;
  color: var(--accent);
  text-decoration: none;
}

.species-photo figcaption a:hover {
  text-decoration: underline;
}

.detail-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-bottom: 27px;
}

.detail-summary > div,
.taxonomy-row {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(13, 42, 52, 0.44);
}

.detail-summary span,
.detail-summary strong {
  display: block;
}

.detail-summary span,
.taxonomy-row span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.72rem;
}

.detail-section-title {
  margin: 0 0 10px;
  font-family: "Manrope", sans-serif;
  font-size: 1rem;
}

.taxonomy-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 24px;
}

.taxonomy-row strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.88rem;
}

.detail-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  text-decoration: none;
}

.detail-link:hover {
  text-decoration: underline;
}

.detail-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .app-shell {
    display: flex;
    height: auto;
    min-height: 100dvh;
    flex-direction: column;
    overflow: visible;
  }

  .map-panel {
    height: 48dvh;
    min-height: 390px;
  }

  .explorer-panel {
    min-height: 52dvh;
    padding: 28px clamp(18px, 5vw, 38px) 48px;
    overflow: visible;
    border-top: 1px solid var(--line);
    border-left: 0;
    box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.28);
  }

  .explorer-header,
  .search-card,
  .status,
  .results {
    max-width: 650px;
    margin-right: auto;
    margin-left: auto;
  }

  .detail-backdrop {
    display: block;
  }

  .species-detail {
    z-index: 1000;
    right: 0;
    width: min(440px, 100%);
  }
}

@media (min-width: 901px) and (max-width: 1150px) {
  .detail-backdrop {
    display: block;
  }

  .species-detail {
    z-index: 1000;
    right: 0;
    width: min(440px, 100%);
  }
}

@media (max-width: 560px) {
  .map-panel {
    height: 52dvh;
    min-height: 355px;
  }

  .map-topbar {
    top: 14px;
    left: 14px;
    right: 14px;
  }

  .brand {
    gap: 9px;
    padding: 7px 10px 7px 7px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .brand-mark svg {
    width: 24px;
  }

  .icon-button {
    min-width: 44px;
    height: 44px;
  }

  .map-instruction {
    bottom: 18px;
    left: 14px;
    max-width: calc(100% - 85px);
    transform: none;
    font-size: 0.78rem;
  }

  .map-action {
    right: 14px;
    bottom: 18px;
    width: 45px;
    padding: 0;
    justify-content: center;
  }

  .map-action span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  h1 {
    font-size: 2rem;
  }

  .explorer-panel {
    padding-top: 25px;
  }

  .radius-control {
    grid-template-columns: 1fr 112px;
  }

  .species-detail {
    top: auto;
    bottom: 0;
    width: 100%;
    height: min(82dvh, 720px);
    padding: 66px 22px 30px;
    border-top: 1px solid var(--line-strong);
    border-left: 0;
    border-radius: 22px 22px 0 0;
    transform: translateY(105%);
  }

  .detail-toolbar {
    top: 17px;
    left: 22px;
    right: 17px;
  }

  .species-photo img {
    height: 190px;
  }

  .species-detail.open {
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
