:root {
  --bg: #d9e5ef;
  --panel: #EFEDD8;
  --panel-glass: #EFEDD8;
  --accent: #0f85cc;
  --accent-soft: #0f85cc22;
  --text: #163042;
  --text-muted: #4a6578;
  --chip-bg: #fff;
  --chip-active: #0f85cc;
}

* {
  box-sizing: border-box;
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.btn {
  min-height: 48px;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

.btn-secondary {
  background: #758a99;
}

.content {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 58% 42%;
}

.page-bg-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  will-change: width, height, left, top;
  background-color: #4c70b7;
}

.page-bg-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  user-select: none;
  pointer-events: none;
}

.map-area {
  position: relative;
  z-index: 1;
  overflow: hidden;
  background: transparent;
}

.map-viewport {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  touch-action: none;
}

.map-ui {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.map-ui .map-help,
.map-ui .zoom-controls,
.map-ui .clear-btn,
.map-ui .map-ui-icon {
  pointer-events: auto;
}

.map-frame {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  will-change: transform, width, height;
}

.map-image {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  user-select: none;
  pointer-events: none;
  shape-rendering: geometricPrecision;
}

.overlay {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  shape-rendering: geometricPrecision;
}

/* Painterly brush-stroke highlight (see zone-brush.js filters) */
.zone-brush {
  opacity: 0;
  pointer-events: none;
  overflow: visible;
}

.zone-brush .zone-polygon-outer {
  fill: #EFEDD8;
  fill-opacity: 0;
  stroke: none;
}

.zone-brush .zone-polygon-inner {
  fill: #EFEDD8;
  fill-opacity: 0;
  stroke: #fff9f0;
  stroke-width: 2;
  stroke-opacity: 0;
  vector-effect: non-scaling-stroke;
}

.zone-brush.is-hiding {
  transition: opacity 0.35s ease-in;
  opacity: 0 !important;
  animation: none !important;
}

.zone-brush.is-hiding .zone-polygon-outer,
.zone-brush.is-hiding .zone-polygon-inner {
  fill-opacity: 0 !important;
  stroke-opacity: 0 !important;
}

/* Stay visible while JS runs icon exit + path shrink (do not only remove .is-visible). */
.zone-brush.is-exiting {
  opacity: 1;
  pointer-events: none;
  isolation: isolate;
}

.zone-brush.is-appearing,
.zone-brush.is-visible,
.zone-brush.is-exiting {
  opacity: 1;
}

.zone-brush.is-appearing .zone-polygon-outer,
.zone-brush.is-visible .zone-polygon-outer,
.zone-brush.is-exiting .zone-polygon-outer {
  fill-opacity: 1;
}

.zone-brush.is-appearing .zone-polygon-inner,
.zone-brush.is-visible .zone-polygon-inner,
.zone-brush.is-exiting .zone-polygon-inner {
  fill-opacity: 1;
  stroke-opacity: 0.35;
}

/* Hidden until reveal() runs enter animation (avoids full-size flash). */
.zone-species-icon--waiting {
  opacity: 0;
  visibility: hidden;
}

.zone-species-icon.is-exiting .zone-species-icon-anim {
  visibility: visible;
}

/* Pop-in/out uses SVG transform in species-zone-icon.js (CSS scale blurs vectors). */
.zone-species-icon-art path,
.zone-species-icon-art circle,
.zone-species-icon-art ellipse,
.zone-species-icon-art polygon,
.zone-species-icon-art polyline {
  shape-rendering: geometricPrecision;
}

.map-help {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: #ffffffc5;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
}

.zoom-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 8px;
}

.clear-btn {
  position: absolute;
  top: 12px;
  right: 12px;
}

.map-ui-icon {
  display: block;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.species-panel {
  position: relative;
  z-index: 1;
  background: var(--panel-glass);
  backdrop-filter: blur(10px);
  border-top: 1px solid #b8cddc;
  box-shadow: 0 -6px 24px #16304214;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.species-panel-header {
  flex-shrink: 0;
  padding: 10px 12px 8px;
  border-bottom: 1px solid #c5d5e3;
  background: linear-gradient(180deg, #ffffffcc 0%, #f3f8fb00 100%);
}

.species-panel-intro {
  margin-bottom: 10px;
}

.species-panel-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.species-panel-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.species-panel-lead {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-muted);
}

.species-count {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
}

.species-filters {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior: contain;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.species-filters::-webkit-scrollbar {
  display: none;
}

.species-filter-chip {
  flex-shrink: 0;
  border: 2px solid #c5d5e3;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--chip-bg);
  color: var(--text);
  box-shadow: 0 2px 0 #c5d5e3;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.1s ease;
}

.species-filter-chip.is-active {
  background: var(--chip-active);
  border-color: #0a6fa8;
  color: #fff;
  box-shadow: 0 2px 0 #0a6fa8;
}

.species-filter-chip:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #c5d5e3;
}

.species-filter-chip.is-active:active {
  box-shadow: 0 1px 0 #0a6fa8;
}

.species-empty {
  flex-shrink: 0;
  margin: 0;
  padding: 16px 16px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
}

.species-list {
  flex: 1;
  min-height: 0;
  padding: 10px 10px 14px 12px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  scrollbar-width: auto;
  scrollbar-color: var(--accent) #c5d5e3;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  grid-auto-rows: min-content;
  align-content: start;
}

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

.species-list::-webkit-scrollbar-track {
  background: #c5d5e3;
  border-radius: 11px;
  margin: 4px 0;
}

.species-list::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 11px;
  border: 5px solid #c5d5e3;
  min-height: 72px;
}

.species-list::-webkit-scrollbar-thumb:hover {
  background: #0a6fa8;
}

.species-item {
  position: relative;
  overflow: visible;
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 10px;
  background-color: #faf8f2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
  cursor: pointer;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  box-shadow: 0 3px 12px #16304218;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.species-item:active {
  transform: scale(0.98);
}

.species-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 4px 12px #0f85cc28;
}

.species-photo {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  flex: 0 0 auto;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(145deg, #dce8f0 0%, #c5d5e3 100%);
  border: 1px solid #d8d0c0;
}

.species-photo.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.55) 50%,
    transparent 100%
  );
  animation: species-photo-shimmer 1.1s ease-in-out infinite;
}

@keyframes species-photo-shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

.species-photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  object-position: center 20%;
  display: block;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.species-photo.has-photo img {
  opacity: 1;
}

.species-photo.no-photo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.species-photo-initials {
  font-size: 42px;
  font-weight: 700;
  color: #5a7a92;
  line-height: 1;
}

.species-caption {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 4px 0 2px;
  margin-left: -2px;
  text-align: left;
}

.species-caption-text {
  flex: 1;
  min-width: 0;
  padding-top: 1px;
}

.species-list-badge {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  overflow: visible;
}

.species-list-badge--caption {
  width: 32px;
  height: auto;
  min-height: 0;
  align-self: flex-start;
  flex-shrink: 0;
}

.species-list-badge--caption .species-list-badge-icon {
  position: static;
  display: block;
  width: 32px;
  height: 32px;
  margin: 0;
  transform: none;
  filter: grayscale(1) contrast(1.15) brightness(0.35);
}

.species-list-badge--caption .species-list-badge-svg--icon {
  position: static;
  display: block;
  width: 32px;
  height: 32px;
}

.species-list-badge--caption .species-list-badge-art,
.species-list-badge--caption .species-list-badge-art * {
  fill: #2a3540;
}

.species-list-badge-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.species-list-badge-svg--icon {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.species-list-badge-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 30px;
  height: 30px;
  transform: translate(-50%, -50%);
  object-fit: contain;
  pointer-events: none;
}

.species-list-badge-svg--icon {
  z-index: 1;
}

.species-list-badge-blob {
  fill: #ffffff;
  stroke: #b8cddc;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.species-list-badge-art,
.species-list-badge-art * {
  fill: var(--accent);
}

.species-name {
  min-width: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.species-meta {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--text-muted);
}

@media (min-width: 1100px) and (orientation: landscape) {
  .content {
    grid-template-columns: 2fr 1.2fr;
    grid-template-rows: 1fr;
  }

  .species-panel {
    border-top: none;
    border-left: 1px solid #b8cddc;
    box-shadow: -6px 0 24px #16304214;
  }

  .species-list {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
  }

  .species-name {
    font-size: 16px;
  }
}
