:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-muted: #f4f4f5;
  --border: #e5e7eb;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-muted: #52525b;
  --text-subtle: #71717a;
  --accent: #0f5c6e;
  --accent-hover: #0b4856;
  --accent-fg: #0f5c6e;
  --accent-soft: #edf5f7;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --card-ratio: 4 / 3;
  --radius: 10px;
  --radius-sm: 6px;
  --max-width: 1200px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="warm"] {
  --bg: #f7f5f0;
  --surface: #fffefb;
  --surface-muted: #efeae0;
  --border: #e6e1d6;
  --border-strong: #d4cdbf;
  --text: #1c1917;
  --text-muted: #57534e;
  --text-subtle: #78716c;
}

[data-theme="dark"] {
  --bg: #111317;
  --surface: #191c22;
  --surface-muted: #222730;
  --border: #2a2f38;
  --border-strong: #3b4250;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-subtle: #71717a;
  --danger: #f87171;
  --danger-bg: rgba(185, 28, 28, 0.16);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img,
video {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.25rem;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

.site-brand {
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.site-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}

.site-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-link {
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.42rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.nav-link[aria-current="page"] {
  color: var(--accent-fg, var(--accent));
  background: var(--accent-soft);
}

/* Main */
.site-main {
  flex: 1;
  padding: 1.75rem 0 3.25rem;
}

/* Toolbar */
.gallery-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-bottom: 1.75rem;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.toolbar-right-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.pill:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.view-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.toggle-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.36rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.toggle-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent-fg, var(--accent));
}

.toolbar-filters {
  justify-content: flex-start;
}

.search-wrap {
  flex: 1 1 240px;
  max-width: 380px;
}

.search-input,
.location-select {
  width: 100%;
  height: 2.45rem;
  padding: 0 0.78rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text);
}

.location-select {
  width: auto;
  min-width: 190px;
  max-width: 280px;
}

.search-input::placeholder {
  color: var(--text-subtle);
}

.result-count {
  margin: 0;
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--text-subtle);
}

/* Species Grid & Density */
.species-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(275px, 1fr));
  gap: 1.5rem;
}

[data-density="compact"] .species-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.1rem;
}

[data-density="large"] .species-grid {
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1.75rem;
}

.species-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.species-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 6px 20px rgba(24, 24, 27, 0.08);
  transform: translateY(-2px);
}

.card-media {
  position: relative;
  aspect-ratio: var(--card-ratio, 4 / 3);
  background: var(--surface-muted);
  overflow: hidden;
}

.card-media-trigger {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.card-media-trigger img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s ease;
}

.species-card:hover .card-media-trigger img {
  transform: scale(1.025);
}

.card-placeholder,
.card-video-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  color: var(--text-subtle);
  font-size: 0.85rem;
}

.card-video-placeholder {
  background: #14181f;
  color: #e4e4e7;
}

.video-play-icon {
  font-size: 1.65rem;
  line-height: 1;
}

.media-badge {
  position: absolute;
  right: 0.55rem;
  bottom: 0.55rem;
  background: rgba(15, 20, 26, 0.78);
  color: #ffffff;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.18rem 0.52rem;
  border-radius: 999px;
  pointer-events: none;
  z-index: 2;
}

.card-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 20, 26, 0.6);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

.card-nav:hover {
  background: rgba(15, 20, 26, 0.85);
}

.species-card:hover .card-nav,
.species-card:focus-within .card-nav {
  opacity: 1;
}

.card-prev {
  left: 0.55rem;
}

.card-next {
  right: 0.55rem;
}

.card-dots {
  position: absolute;
  left: 50%;
  bottom: 0.55rem;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.26rem 0.5rem;
  border-radius: 999px;
  background: rgba(15, 20, 26, 0.55);
  z-index: 2;
}

.card-dot {
  width: 7px;
  height: 7px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.48);
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.card-dot.is-active {
  background: #ffffff;
  transform: scale(1.18);
}

.card-slide-counter {
  font-size: 0.72rem;
  color: #ffffff;
  font-weight: 500;
  padding: 0 0.2rem;
}

.card-body-link {
  display: block;
  text-decoration: none;
  flex: 1;
}

.card-body {
  padding: 0.95rem 1.05rem 1.05rem;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}

.card-meta-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-subtle);
  margin-bottom: 0.15rem;
}

.card-category {
  color: var(--accent-fg, var(--accent));
  font-weight: 500;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.card-sci {
  margin: 0;
  font-size: 0.86rem;
  font-style: italic;
  color: var(--text-muted);
}

.card-location {
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  color: var(--text-subtle);
}

/* All Photos & Species Media Grid */
.photos-grid,
.species-photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.15rem;
}

[data-density="compact"] .photos-grid,
[data-density="compact"] .species-photos-grid {
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.9rem;
}

[data-density="large"] .photos-grid,
[data-density="large"] .species-photos-grid {
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1.4rem;
}

.photo-tile {
  position: relative;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.photo-tile:hover {
  border-color: var(--border-strong);
  box-shadow: 0 5px 16px rgba(24, 24, 27, 0.06);
}

.photo-tile-media {
  position: relative;
}

.photo-tile-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: var(--surface-muted);
  aspect-ratio: var(--card-ratio, 4 / 3);
  overflow: hidden;
  cursor: zoom-in;
}

.photo-tile-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.photo-tile:hover .photo-tile-btn img {
  transform: scale(1.02);
}

.photo-tile-caption {
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.photo-tile-species {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.photo-caption-text {
  font-size: 0.86rem;
  color: var(--text);
  line-height: 1.4;
}

.photo-meta-text {
  font-size: 0.79rem;
  color: var(--text-subtle);
}

/* Species Detail Page */
.breadcrumb {
  margin-bottom: 1.25rem;
}

.back-link {
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--accent-fg, var(--accent));
}

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

.species-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.species-meta-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.species-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--accent-fg, var(--accent));
  background: var(--accent-soft);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}

.species-count {
  font-size: 0.84rem;
  color: var(--text-subtle);
}

.species-heading {
  margin: 0;
  font-size: clamp(1.65rem, 3vw, 2.2rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.species-subrow {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.85rem;
  margin-top: 0.3rem;
}

.species-scientific {
  margin: 0;
  font-size: 1.05rem;
  font-style: italic;
  color: var(--text-muted);
}

.species-wiki-link {
  font-size: 0.84rem;
  color: var(--text-subtle);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.species-wiki-link:hover {
  color: var(--accent-fg, var(--accent));
  border-color: var(--accent-fg, var(--accent));
}

.species-notes {
  margin: 0.95rem 0 0;
  max-width: 66ch;
  color: var(--text);
  font-size: 0.98rem;
}

.species-locations {
  margin: 0.85rem 0 0;
  font-size: 0.86rem;
  color: var(--text-subtle);
}

.species-pager {
  margin-top: 2.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.pager-link {
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--accent-fg, var(--accent));
}

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

/* About Page */
.about-container {
  max-width: 780px;
}

.about-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.about-card h1 {
  margin: 0 0 1rem;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}

.about-prose p {
  margin: 0 0 1rem;
  color: var(--text);
  max-width: 65ch;
}

.about-prose p:last-child {
  margin-bottom: 0;
}

.about-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.75rem 0 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.about-stats dt {
  font-size: 0.8rem;
  color: var(--text-subtle);
}

.about-stats dd {
  margin: 0.15rem 0 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.about-locations {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.about-locations h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.location-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.location-list li {
  font-size: 0.86rem;
  color: var(--text-muted);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
}

/* Buttons & Empty States */
.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-muted);
}

.empty-state {
  text-align: center;
  padding: 3.25rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

.empty-state h1 {
  margin: 0 0 0.5rem;
  font-size: 1.4rem;
  color: var(--text);
}

.empty-state p {
  margin: 0 0 1.25rem;
}

/* Lightbox */
.lightbox[hidden] {
  display: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(10, 12, 16, 0.96);
  color: #f4f4f5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.lb-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 4.25rem 0.75rem;
}

.lb-image,
.lb-video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
}

.lb-image {
  object-fit: contain;
}

.lb-video {
  background: #000000;
}

.lb-btn {
  position: absolute;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  cursor: pointer;
  display: grid;
  place-items: center;
  border-radius: 999px;
  transition: background-color 0.15s ease;
  z-index: 2;
}

.lb-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.lb-close {
  top: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.65rem;
  line-height: 1;
}

.lb-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 2.75rem;
  height: 2.75rem;
  font-size: 1.8rem;
  line-height: 1;
}

.lb-prev {
  left: 1rem;
}

.lb-next {
  right: 1rem;
}

.lb-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.5rem 1.15rem;
  background: linear-gradient(to top, rgba(10, 12, 16, 0.9), rgba(10, 12, 16, 0));
}

.lb-info {
  min-width: 0;
}

.lb-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.55rem;
}

.lb-species {
  font-weight: 600;
  font-size: 1rem;
  color: #ffffff;
  text-decoration: none;
}

.lb-species:hover {
  text-decoration: underline;
}

.lb-scientific {
  font-style: italic;
  font-size: 0.88rem;
  color: #d4d4d8;
}

.lb-caption {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: #e4e4e7;
}

.lb-meta {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  color: #a1a1aa;
}

.lb-counter {
  flex-shrink: 0;
  font-size: 0.85rem;
  color: #a1a1aa;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 1.1rem 0;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.footer-note {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-subtle);
}

[hidden] {
  display: none !important;
}

@media (hover: none) {
  .card-nav {
    opacity: 0.85;
  }
}

@media (max-width: 640px) {
  .header-inner {
    flex-wrap: wrap;
  }

  .search-wrap {
    max-width: none;
    flex-basis: 100%;
  }

  .location-select {
    flex: 1 1 auto;
    max-width: none;
  }

  .result-count {
    margin-left: 0;
    width: 100%;
  }

  .about-card {
    padding: 1.35rem;
  }

  .about-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.65rem;
  }

  .lb-stage {
    padding: 3.5rem 0.75rem 0.5rem;
  }

  .lb-nav {
    width: 2.35rem;
    height: 2.35rem;
    font-size: 1.5rem;
    background: rgba(10, 12, 16, 0.55);
  }

  .lb-prev {
    left: 0.5rem;
  }

  .lb-next {
    right: 0.5rem;
  }

  .lb-bar {
    padding: 0.75rem 1rem 1rem;
  }
}
