:root {
  --panel-width: 410px;
  --navy: #0f172a;
  --navy-soft: #172036;
  --navy-card: #25314a;
  --text: #f8fafc;
  --muted: #a7b3c8;
  --line: rgba(255, 255, 255, .12);
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --gold: #f4cc55;
  --shadow: 0 18px 55px rgba(3, 7, 18, .35);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--navy);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 9px 13px;
  background: rgba(255, 255, 255, .11);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}

button:hover {
  background: rgba(255, 255, 255, .18);
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button.primary {
  background: var(--accent);
  color: #082f49;
}

button.primary:hover {
  background: #7dd3fc;
}

.sitebar {
  height: 50px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  background: rgba(15, 23, 42, .98);
  color: rgba(255, 255, 255, .86);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .22);
}

.sitebar a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: white;
  font-weight: 800;
  text-decoration: none;
}

.sitebar a:hover {
  color: #7dd3fc;
}

.sitebar-title {
  color: rgba(255, 255, 255, .68);
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.app {
  min-height: calc(100% - 50px);
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr);
}

.sidebar {
  position: relative;
  z-index: 900;
  height: calc(100vh - 50px);
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  background:
    radial-gradient(circle at 0 0, rgba(56, 189, 248, .18), transparent 34rem),
    linear-gradient(180deg, rgba(15, 23, 42, .98), rgba(15, 23, 42, .94));
  box-shadow: var(--shadow);
}

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

.stat {
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, .07);
}

.stat strong {
  display: block;
  font-size: 1.08rem;
}

.stat span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.controls {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: visible;
  padding: 16px 22px 12px;
  border-bottom: 1px solid var(--line);
}

.field-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.location-picker {
  position: relative;
  z-index: 1050;
  margin-top: 10px;
}

.location-picker-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 14px;
  background: rgba(255, 255, 255, .09);
  color: var(--text);
  font-size: .8rem;
  text-align: left;
}

.location-picker-toggle span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.location-picker-panel {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  left: 0;
  z-index: 1100;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 14px;
  background: rgba(15, 23, 42, .985);
  box-shadow: 0 18px 48px rgba(3, 7, 18, .55);
}

.location-picker-panel[hidden] {
  display: none;
}

.location-picker-search,
.inline-filter {
  position: relative;
}

.location-picker-search input,
.inline-filter input {
  width: 100%;
  padding: 9px 34px 9px 11px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 11px;
  background: rgba(255, 255, 255, .09);
  color: var(--text);
  outline: none;
}

.location-picker-search input::placeholder,
.inline-filter input::placeholder {
  color: #8794a9;
}

.location-picker-search > span,
.inline-filter > span {
  position: absolute;
  top: 50%;
  right: 11px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.location-picker-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 1px;
  color: var(--muted);
  font-size: .72rem;
}

.location-picker-actions > div,
.filter-action-buttons {
  display: flex;
  gap: 7px;
}

.location-picker-actions button {
  padding: 5px 9px;
  font-size: .72rem;
}

.location-list {
  display: grid;
  align-content: start;
  gap: 5px;
  max-height: min(43vh, 330px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 5px;
  scrollbar-color: rgba(167, 179, 200, .72) rgba(255, 255, 255, .06);
  scrollbar-width: thin;
}

.location-check {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .055);
  font-size: .76rem;
  cursor: pointer;
}

.location-check:hover {
  background: rgba(255, 255, 255, .1);
}

.location-check input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
}

.location-check span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.location-check em {
  color: var(--muted);
  font-size: .65rem;
  font-style: normal;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 10px 0 0;
}

.action-row button {
  padding: 7px 11px;
  font-size: .78rem;
}

.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
}

.switch-row input {
  width: 17px;
  height: 17px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.switch-row strong,
.switch-row small {
  display: block;
}

.switch-row strong {
  font-size: .86rem;
}

.switch-row small {
  margin-top: 2px;
  color: var(--muted);
  line-height: 1.3;
}

.genera-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  flex: 0 1 230px;
  min-height: 130px;
  overflow: hidden;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.genera-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 7px;
  scrollbar-color: rgba(167, 179, 200, .72) rgba(255, 255, 255, .06);
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}

.genera-list::-webkit-scrollbar {
  width: 9px;
}

.genera-list::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
}

.genera-list::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(167, 179, 200, .72);
  background-clip: padding-box;
}

.genus-check {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .055);
  font-size: .72rem;
  cursor: pointer;
}

.genus-check:hover {
  background: rgba(255, 255, 255, .1);
}

.genus-check input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
}

.genus-check span:nth-of-type(2) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.genus-check em {
  color: var(--muted);
  font-size: .64rem;
  font-style: normal;
}

.genus-color {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--genus-color);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .72);
}

.species-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  margin-top: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.filter-summary,
.species-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 8px;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.filter-summary span:last-child,
.species-summary span:last-child {
  color: var(--text);
  font-size: .7rem;
  letter-spacing: 0;
  text-transform: none;
}

.filter-actions,
.species-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  margin-bottom: 8px;
}

.inline-filter {
  min-width: 0;
  flex: 1 1 auto;
}

.inline-filter input {
  padding-top: 7px;
  padding-bottom: 7px;
  font-size: .74rem;
}

.filter-action-buttons {
  flex: 0 0 auto;
}

.filter-actions button,
.species-actions button {
  padding: 6px 10px;
  font-size: .76rem;
}

.empty-filter {
  grid-column: 1 / -1;
  margin: 10px 0;
  color: var(--muted);
  font-size: .78rem;
  text-align: center;
}

.species-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(167, 179, 200, .72) rgba(255, 255, 255, .06);
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  display: grid;
  align-content: start;
  gap: 6px;
  padding-right: 7px;
}

.species-list::-webkit-scrollbar {
  width: 9px;
}

.species-list::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
}

.species-list::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(167, 179, 200, .72);
  background-clip: padding-box;
}

.species-check {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, .055);
  font-size: .82rem;
  cursor: pointer;
}

.species-check:hover {
  background: rgba(255, 255, 255, .1);
}

.species-check input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.species-color {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--species-color);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .72);
}

.species-check em {
  color: var(--muted);
  font-size: .7rem;
  font-style: normal;
}

.details {
  min-height: 0;
  overflow-y: auto;
  padding: 16px 22px 28px;
}

.details.empty {
  display: grid;
  place-items: center;
}

.empty-state {
  display: grid;
  gap: 4px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
}

.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-heading h2 {
  margin: 0;
  font-size: 1.16rem;
}

.detail-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .78rem;
}

.detail-cards {
  display: grid;
  gap: 10px;
}

.fish-card {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  min-height: 78px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--navy-card);
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s ease, transform .15s ease;
}

.fish-card:hover {
  border-color: rgba(56, 189, 248, .7);
  transform: translateY(-1px);
}

.fish-card img {
  width: 108px;
  height: 100%;
  min-height: 78px;
  object-fit: cover;
  background: var(--navy-soft);
}

.fish-copy {
  align-self: center;
  padding: 9px 10px;
}

.fish-copy strong,
.fish-copy span {
  display: block;
}

.fish-copy strong {
  font-size: .82rem;
  line-height: 1.28;
}

.fish-copy span {
  margin-top: 5px;
  color: var(--accent);
  font-size: .72rem;
  font-weight: 700;
}

.map-wrap {
  position: relative;
  min-width: 0;
  min-height: calc(100vh - 50px);
}

#map {
  position: absolute;
  inset: 0;
  background: #6f7f67;
}

.leaflet-control-layers {
  border: 0 !important;
  border-radius: 14px !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-tooltip.tropheus-tooltip {
  min-width: 175px;
  max-width: 290px;
  padding: 10px 11px;
  border: 0;
  border-radius: 10px;
  background: rgba(15, 23, 42, .94);
  color: white;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
}

.leaflet-tooltip.tropheus-tooltip::before {
  border-top-color: rgba(15, 23, 42, .94);
}

.leaflet-popup.tropheus-location-popup .leaflet-popup-content-wrapper,
.leaflet-popup.tropheus-location-popup .leaflet-popup-tip {
  background: rgba(15, 23, 42, .97);
  color: var(--text);
}

.leaflet-popup.tropheus-location-popup .leaflet-popup-content-wrapper {
  border-radius: 15px;
  box-shadow: 0 20px 55px rgba(0, 0, 0, .42);
}

.leaflet-popup.tropheus-location-popup .leaflet-popup-content {
  width: auto !important;
  margin: 13px;
}

.leaflet-popup.tropheus-location-popup .leaflet-popup-close-button {
  color: white;
  font-size: 22px;
}

.map-location-popup {
  width: min(580px, calc(100vw - 82px));
  max-height: min(var(--popup-nine-height, 9999px), calc(100dvh - 130px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 6px;
  scrollbar-color: rgba(167, 179, 200, .78) rgba(255, 255, 255, .06);
  scrollbar-width: thin;
}

.map-location-popup::-webkit-scrollbar {
  width: 9px;
}

.map-location-popup::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
}

.map-location-popup::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(167, 179, 200, .78);
  background-clip: padding-box;
}

.map-location-popup.popup-columns-1 {
  width: min(390px, calc(100vw - 82px));
}

.map-location-popup.popup-columns-3 {
  width: min(860px, calc(100vw - 82px));
}

.popup-heading {
  padding: 1px 28px 10px 1px;
}

.popup-heading h2 {
  margin: 0;
  color: white;
  font-size: 1.05rem;
  line-height: 1.2;
}

.popup-heading p {
  margin: 4px 0 0;
  color: #aebbd0;
  font-size: .74rem;
}

.popup-fish-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 9px;
}

.popup-fish-cards.popup-columns-1 {
  grid-template-columns: minmax(0, 1fr);
}

.popup-fish-cards.popup-columns-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.popup-fish-card {
  display: block;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 11px;
  background: var(--navy-card);
  color: white;
  text-decoration: none;
  transition: border-color .15s ease, transform .15s ease;
}

.popup-fish-card:hover {
  border-color: rgba(56, 189, 248, .75);
  transform: translateY(-1px);
}

.popup-fish-card[hidden] {
  display: none;
}

.popup-location-card {
  border-color: rgba(56, 189, 248, .48);
  background: linear-gradient(145deg, #183451, var(--navy-card));
}

.popup-location-card .popup-fish-copy em {
  color: #7dd3fc;
  font-weight: 700;
}

.popup-fish-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 5;
  object-fit: cover;
  background: var(--navy-soft);
}

.popup-fish-copy {
  padding: 8px 10px 9px;
}

.popup-fish-copy strong,
.popup-fish-copy em,
.popup-fish-copy span {
  display: block;
}

.popup-scroll-hint {
  position: sticky;
  bottom: 0;
  z-index: 3;
  width: 100%;
  margin-top: 9px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(20, 72, 105, .96);
  color: #7dd3fc;
  text-align: center;
  font-size: .75rem;
  font-weight: 700;
  pointer-events: none;
  box-shadow: 0 -10px 22px rgba(10, 19, 38, .72);
  transition: opacity .16s ease;
}

.popup-scroll-hint.is-hidden {
  opacity: 0;
}

.popup-fish-copy strong {
  color: white;
  font-size: .78rem;
  line-height: 1.28;
}

.popup-fish-copy em {
  margin-top: 3px;
  color: #a7b3c8;
  font-size: .72rem;
  font-style: normal;
  line-height: 1.25;
}

.popup-fish-copy .tone-gray {
  color: #a7b3c8;
}

.popup-fish-copy .tone-red {
  color: #fb7185;
}

.popup-fish-copy span {
  margin-top: 4px;
  color: var(--accent);
  font-size: .7rem;
  font-weight: 700;
}

.tooltip-place {
  margin-bottom: 7px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(255, 255, 255, .16);
  font-size: .84rem;
  font-weight: 800;
}

.tooltip-species-list {
  display: grid;
  gap: 6px;
}

.tooltip-species-row {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr);
  align-items: start;
  gap: 7px;
}

.tooltip-species-row strong,
.tooltip-species-row small {
  display: block;
}

.tooltip-species-row strong {
  font-size: .76rem;
  line-height: 1.25;
}

.tooltip-species-row small {
  margin-top: 1px;
  color: #b9c4d5;
  font-size: .66rem;
}

.tooltip-species-dot {
  width: 8px;
  height: 8px;
  margin-top: 3px;
  border: 1px solid rgba(255, 255, 255, .8);
  border-radius: 50%;
}

.tooltip-hint {
  margin-top: 8px;
  color: #9eabc0;
  font-size: .65rem;
}

.tropheus-marker {
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border: 1.5px solid white;
  border-radius: 50%;
  background: var(--marker-color);
  color: #111827;
  box-shadow: 0 2px 9px rgba(0, 0, 0, .42);
  font-size: 8px;
  font-weight: 900;
}

.leaflet-tooltip.location-label {
  margin-left: 1px;
  padding: 3px 6px;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 5px;
  background: rgba(15, 23, 42, .86);
  color: white;
  box-shadow: 0 2px 7px rgba(0, 0, 0, .3);
  font-size: 10px;
  font-weight: 750;
  line-height: 1.15;
  white-space: nowrap;
  pointer-events: none;
}

.leaflet-tooltip.location-label::before {
  display: none;
}

.map-key {
  position: absolute;
  z-index: 500;
  right: 13px;
  bottom: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 12px;
  background: rgba(15, 23, 42, .86);
  color: white;
  font-size: .72rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  backdrop-filter: blur(8px);
}

.key-dot {
  width: 13px;
  height: 13px;
  border: 2px solid white;
  border-radius: 50%;
  background: var(--gold);
}

.loading {
  position: absolute;
  z-index: 700;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 13px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .9);
  color: white;
  font-size: .78rem;
  box-shadow: var(--shadow);
}

.loading[hidden] {
  display: none;
}

.mobile-open,
.mobile-close {
  display: none;
}

@media (max-width: 900px) {
  .sitebar {
    padding: 0 14px;
  }

  .sitebar-title {
    font-size: .78rem;
  }

  .app {
    display: block;
  }

  .map-wrap {
    min-height: calc(100dvh - 50px);
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0;
    z-index: 1200;
    width: 100%;
    height: min(78dvh, 720px);
    border-radius: 22px 22px 0 0;
    transform: translateY(calc(100% + 10px));
    transition: transform .22s ease;
  }

  .sidebar.open {
    transform: translateY(0);
  }

  .mobile-close {
    display: block;
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 1.35rem;
  }

  .mobile-open {
    display: block;
    position: absolute;
    z-index: 800;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--navy);
    box-shadow: var(--shadow);
  }

  .map-key {
    right: 10px;
    bottom: 10px;
    max-width: calc(100% - 20px);
  }
}

@media (max-width: 520px) {
  .sidebar {
    height: 86dvh;
  }

  .controls,
  .details {
    padding-left: 16px;
    padding-right: 16px;
  }

  .stats {
    padding-right: 40px;
  }

  .fish-card {
    grid-template-columns: 94px minmax(0, 1fr);
  }

  .fish-card img {
    width: 94px;
  }

  .popup-fish-cards.popup-columns-1,
  .popup-fish-cards.popup-columns-2,
  .popup-fish-cards.popup-columns-3 {
    grid-template-columns: minmax(0, 1fr);
  }

  .map-location-popup {
    max-height: min(var(--popup-nine-height, 9999px), calc(100dvh - 105px));
  }

}
