:root {
  --bg: #111217;
  --surface: #181b1f;
  --surface-2: #202226;
  --line: #34373d;
  --text: #d8d9da;
  --muted: #9fa2a7;
  --accent: #5794f2;
  --accent-strong: #8ab8ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 300px;
  color: var(--text);
  background:
    var(--bg);
  font: 16px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent-strong); }

.hero, main, footer {
  width: min(1600px, calc(100% - 24px));
  margin-inline: auto;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  padding: 18px 4px 14px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 1.55rem; line-height: 1.1; letter-spacing: -.02em; }
h2 { margin-bottom: 4px; font-size: 1rem; line-height: 1.2; letter-spacing: 0; }
.eyebrow { margin-bottom: 9px; color: var(--accent); font-size: .76rem; font-weight: 750; letter-spacing: .14em; text-transform: uppercase; }
.intro, .scientific { margin-bottom: 0; color: var(--muted); }
.scientific { font-style: italic; }

.freshness {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  color: var(--muted);
  background: rgba(13, 32, 24, .78);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px rgba(87, 148, 242, .13); }

.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 0;
}
.metric {
  min-height: 94px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.metric:nth-child(-n+2) {
  color: #f4f6f7;
  background: linear-gradient(100deg, #56964a, #7cb35f);
  border-color: #709f63;
}
.metric-value { display: block; margin-bottom: 6px; color: #81bb6f; font-size: clamp(1.7rem, 3.2vw, 2.7rem); font-weight: 760; letter-spacing: -.045em; }
.metric-label { color: var(--muted); font-size: .86rem; }
.metric:nth-child(-n+2) .metric-value { color: #f4f6f7; }
.metric:nth-child(-n+2) .metric-label { color: rgba(255, 255, 255, .9); }

.gallery-section, .panel {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: var(--shadow);
}
.current-detections { margin-bottom: 22px; }
.current-detections iframe {
  display: block;
  width: 100%;
  height: 170px;
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.gallery-section { margin-bottom: 0; min-width: 0; }
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
}
.section-heading.compact { padding: 20px; }
.gallery-controls { display: flex; align-items: center; gap: 8px; }
.soft-button, .limit-control select, #species-search {
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.soft-button { padding: 9px 13px; cursor: pointer; text-decoration: none; }
.soft-button:hover { border-color: rgba(87, 148, 242, .65); }

.gallery { display: grid; grid-template-columns: 1fr; border-top: 1px solid var(--line); }
.image-stage { position: relative; min-height: 500px; overflow: hidden; background: #090a0b; touch-action: pan-y; }
.image-stage img { width: 100%; height: 100%; min-height: inherit; display: block; object-fit: contain; opacity: 0; transition: opacity .25s ease; }
.image-stage img.loaded { opacity: 1; }
.gallery-arrow {
  position: absolute;
  top: 50%;
  width: 48px;
  height: 62px;
  padding: 0;
  transform: translateY(-50%);
  color: white;
  background: rgba(3, 12, 8, .65);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  font-size: 2.3rem;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.gallery-arrow:hover { background: rgba(31, 78, 140, .88); }
.gallery-arrow.previous { left: 16px; }
.gallery-arrow.next { right: 16px; }
.image-position { position: absolute; right: 17px; bottom: 15px; padding: 6px 10px; background: rgba(3, 12, 8, .72); border-radius: 999px; font-size: .8rem; }
.progress-track { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.12); }
.progress-fill { width: 0; height: 100%; background: var(--accent); }
.image-details { min-height: 128px; padding: 16px; border-top: 1px solid var(--line); }
.slideshow-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.selector-status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
}
.image-selectors {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.image-selector {
  width: 12px;
  height: 12px;
  padding: 0;
  border: 1px solid #747980;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.image-selector:hover { border-color: var(--accent-strong); background: rgba(87, 148, 242, .28); }
.image-selector.active { border-color: var(--accent); background: var(--accent); }
.image-selector:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.slideshow-controls .soft-button { flex: 0 0 auto; padding-block: 6px; }
.image-comment { font-size: 1.05rem; }
.image-credit { color: var(--muted); font-size: .87rem; }
.source-link { display: inline-block; margin-top: 8px; font-size: .85rem; }

.gallery-section:fullscreen,
.gallery-section.fullscreen-fallback {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--surface);
}
.gallery-section:fullscreen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.gallery-section:fullscreen::backdrop { background: #090a0b; }
.gallery-section.fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.gallery-section:fullscreen .gallery,
.gallery-section.fullscreen-fallback .gallery {
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
}
.gallery-section:fullscreen .image-stage,
.gallery-section.fullscreen-fallback .image-stage {
  height: 100%;
  min-height: 0;
}
.gallery-section:fullscreen .image-details,
.gallery-section.fullscreen-fallback .image-details {
  min-height: 0;
  max-height: 24vh;
  overflow: auto;
}
body.carousel-fullscreen-open { overflow: hidden; }

.dashboard-top { display: grid; grid-template-columns: minmax(0, 10fr) minmax(500px, 14fr); gap: 8px; margin-bottom: 8px; }
.right-stack { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px; min-width: 0; }
.limit-control { color: var(--muted); font-size: .84rem; white-space: nowrap; }
.limit-control select { margin-left: 5px; padding: 6px 8px; }
.recent-list { border-top: 1px solid var(--line); }
.recent-item { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--line); }
.recent-item:last-child { border-bottom: 0; }
.recent-name { border: 0; padding: 0; color: var(--accent-strong); background: transparent; text-align: left; cursor: pointer; font-weight: 700; }
.recent-meta, .secondary { color: var(--muted); font-size: .78rem; }
.audio-link { align-self: center; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; font-size: .82rem; }

#species-search { width: min(230px, 42vw); padding: 9px 12px; }
.table-wrap { height: 342px; overflow: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; }
th { position: sticky; top: 0; z-index: 1; background: #10261c; text-align: left; }
th button { width: 100%; padding: 11px 14px; color: var(--muted); background: transparent; border: 0; text-align: left; cursor: pointer; font-size: .78rem; font-weight: 700; text-transform: uppercase; }
td { padding: 11px 14px; border-top: 1px solid var(--line); vertical-align: top; font-size: .88rem; }
td:last-child, th:last-child { text-align: right; }
.species-button { border: 0; padding: 0; color: var(--accent-strong); background: transparent; text-align: left; cursor: pointer; font-weight: 700; }
.species-button:hover { text-decoration: underline; }

.birdtunes { margin-bottom: 22px; }
.birdtunes iframe { display: block; width: 100%; height: 1240px; border: 0; border-top: 1px solid var(--line); background: white; }
footer { padding: 10px 0 38px; color: var(--muted); font-size: .8rem; }
.error-banner { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100% - 30px); padding: 12px 16px; color: #fff4e5; background: #713f12; border: 1px solid #f59e0b; border-radius: 12px; box-shadow: var(--shadow); }

.activity-panel { margin-bottom: 8px; }
.activity-wrap { overflow: auto; max-height: 780px; border-top: 1px solid var(--line); }
.activity-table {
  min-width: 1420px;
  border-collapse: separate;
  border-spacing: 4px 5px;
  font-size: .77rem;
}
.activity-table th, .activity-table td { height: 34px; padding: 0 6px; text-align: center; }
.activity-table th:first-child, .activity-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 275px;
  max-width: 275px;
  background: var(--surface);
  text-align: left;
}
.activity-species { display: flex; align-items: center; gap: 8px; min-width: 0; }
.activity-thumbnail-button {
  flex: 0 0 36px;
  width: 36px;
  height: 34px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: zoom-in;
}
.activity-thumbnail-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.activity-thumbnail {
  flex: 0 0 auto;
  width: 36px;
  height: 34px;
  object-fit: cover;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 10px;
  background: #090a0b;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 2px 5px rgba(0,0,0,.24);
}
.species-recordings-link {
  overflow: hidden;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.species-recordings-link:hover { color: var(--accent); text-decoration: underline; }
.activity-table thead th:first-child { z-index: 3; background: #202226; }
.activity-cell {
  min-width: 44px;
  padding: 0;
  color: #e7f9ff;
  border: 0;
  border-radius: 5px;
  font-weight: 700;
  transition: filter 100ms ease, transform 100ms ease;
}
.activity-cell:hover { filter: brightness(1.18); transform: translateY(-1px); }
.activity-zero {
  color: transparent;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
}
.activity-total { font-weight: 700; }

@media (max-width: 1000px) {
  .dashboard-top { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .gallery { grid-template-columns: 1fr; }
  .image-details { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 650px) {
  .hero { align-items: start; flex-direction: column; padding-top: 34px; }
  .dashboard-top { display: block; }
  .right-stack { margin-top: 8px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .section-heading { align-items: start; flex-wrap: wrap; }
  .gallery-controls { width: 100%; }
  .gallery-controls .soft-button { flex: 1; }
  .slideshow-controls { align-items: flex-start; flex-wrap: wrap; }
  .image-selectors { min-width: calc(100% - 60px); }
  .image-stage { min-height: 56vh; }
  .gallery-section:fullscreen .section-heading,
  .gallery-section.fullscreen-fallback .section-heading { padding: 14px 16px; }
  .gallery-section:fullscreen .image-details,
  .gallery-section.fullscreen-fallback .image-details { max-height: 30vh; }
  .gallery-arrow { width: 42px; height: 54px; }
  .birdtunes iframe { height: 1040px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
