:root {
  /* "Field guide" palette: warm paper, ink, forest green */
  --bg: #f3eee2;
  --bg-raised: #fbf8f1;
  --bg-sunken: #e6dfcf;
  --line: #d9cfba;
  --text: #24261f;
  --muted: #5f5c4f;
  --faint: #7d7866;
  --accent: #3d6b47;      /* forest green */
  --accent-ink: #ffffff;
  /* Jost: geometric, Futura-style, mid-century like the kestrel illustration */
  --display: "Jost", "Futura", "Century Gothic", system-ui, sans-serif;
  --sans: "Jost", "Futura", "Century Gothic", system-ui, sans-serif;
  --row: 260px;
  --gap: 6px;
  --radius: 6px;
  color-scheme: light;
}

* { box-sizing: border-box; }
/* Components below set display:flex/grid, which would override the hidden attribute. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.wrap { max-width: 1600px; margin: 0 auto; padding: 0 24px; }

/* ---------- masthead ---------- */
.masthead { padding: 56px 0 28px; }
.brand { display: flex; align-items: center; gap: 22px; }
.mark { width: 88px; height: 88px; flex: none; }
/* Title + mark link home: plain page, no filters */
a.home { color: inherit; text-decoration: none; display: block; flex: none; }
a.home .mark { display: block; transition: transform .25s ease; }
a.home:hover .mark { transform: rotate(-6deg) scale(1.04); }
h1 a.home:hover { opacity: .85; }
h1 {
  margin: 0;
  font: 500 clamp(34px, 6vw, 64px)/1.05 var(--display);
  letter-spacing: -.02em;
}
h1 em { font-style: italic; color: var(--accent); }
h1 a.home { display: inline; }
/* Birds / Not Birds switch in the title */
.sets { white-space: nowrap; }
.sets button {
  font: inherit; letter-spacing: inherit; font-style: italic;
  background: none; border: 0; padding: 0; margin: 0; cursor: pointer; color: var(--faint);
}
.sets button[aria-pressed="true"] { color: var(--accent); cursor: default; }
.sets button[data-set="notbirds"][aria-pressed="true"] { color: #4f6d8f; } /* kestrel wing blue */
.sets button[aria-pressed="false"]:hover { color: var(--muted); }
.sets .slash { color: var(--line); margin: 0 .14em; font-weight: 300; }
/* Birds-only and Not-Birds-only parts of the toolbar */
body.is-notbirds .birds-only, body:not(.is-notbirds) .nb-only { display: none !important; }
.w-camera { width: 170px; } .w-lens { width: 210px; } .w-shutter { width: 165px; }
.w-aperture { width: 140px; } .w-iso { width: 120px; }
h1 .amp { color: var(--faint); }

/* ---------- toolbar ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-block: 1px solid var(--line);
}
.toolbar-inner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding-top: 10px; padding-bottom: 10px;
}
.tabs { display: flex; gap: 2px; background: var(--bg-sunken); padding: 3px; border-radius: 999px; }
.tabs button {
  border: 0; background: none; cursor: pointer;
  padding: 6px 14px; border-radius: 999px; font-size: 14px; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--bg-raised); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
/* external link styled like a tab: my eBird profile */
.tabs .tab-link {
  padding: 6px 14px; border-radius: 999px; font-size: 14px; color: var(--muted);
  text-decoration: none; text-align: center; white-space: nowrap;
}
.tabs .tab-link:hover { color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; justify-content: flex-end; }
.field select, .field input {
  height: 36px; padding: 0 12px;
  background: var(--bg-raised); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font: 14px var(--sans);
  max-width: 100%;
}
.field select { padding-right: 30px; appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px;
  background-size: 5px 5px; background-repeat: no-repeat; }
.field select.active { border-color: var(--accent); }
.field.search input { width: 180px; }
/* fixed widths keep the toolbar on one line; long choices end in "…" */
#group { width: 165px; } #species { width: 185px; } #place { width: 190px; }
.field select { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
.field input:focus, .field select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.resultbar { display: flex; align-items: baseline; gap: 14px; padding: 18px 0 12px; min-height: 56px; }
.resultbar p { margin: 0; color: var(--muted); }
.resultbar p b { color: var(--text); font-weight: 600; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- justified photo grid ---------- */
.grid { display: flex; flex-wrap: wrap; gap: var(--gap); }
.grid::after { content: ""; flex-grow: 1e9; }
.tile {
  position: relative; display: block; margin: 0; padding: 0; border: 0;
  background: var(--bg-raised); border-radius: var(--radius); overflow: hidden;
  cursor: zoom-in;
}
.tile i { display: block; }
.tile img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  transition: transform .5s ease, opacity .4s ease; opacity: 0;
}
.tile img.loaded { opacity: 1; }
.tile:hover img { transform: scale(1.03); }
.tile .cap {
  position: absolute; inset: auto 0 0 0; padding: 28px 12px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  text-align: left; opacity: 0; transition: opacity .25s ease;
}
.tile:hover .cap, .tile:focus-visible .cap { opacity: 1; }
.cap strong { display: block; font: 500 15px/1.25 var(--display); color: #f4f1e8; }
.cap span { font-size: 12px; color: #d8d4c6; }

/* ---------- species / places cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px 14px; }
.group-h {
  grid-column: 1 / -1; margin: 18px 0 -4px; padding-bottom: 6px;
  font: 400 22px var(--display); border-bottom: 1px solid var(--line);
}
.group-h small { font: 13px var(--sans); color: var(--faint); margin-left: 8px; white-space: nowrap; }
.group-h:first-child { margin-top: 0; }
.card {
  display: block; text-align: left; border: 0; padding: 0; background: none; cursor: pointer;
}
.card .thumb { aspect-ratio: 4 / 3; border-radius: var(--radius); overflow: hidden; background: var(--bg-raised); }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s ease; }
.card:hover .thumb img { transform: scale(1.04); }
.card h3 { margin: 8px 0 0; font: 500 17px/1.25 var(--display); }
.card p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.card .sci { font-style: italic; }

.empty { text-align: center; color: var(--muted); padding: 80px 0; }
.foot { padding: 48px 24px 40px; color: var(--faint); font-size: 13px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.foot p { margin: 0; }

/* ---------- photo view ---------- */
/* Dark warm-charcoal stage for the photo (lightbox effect) beside a light,
   field-guide-style text page. */
dialog#lightbox {
  --stage: #171612;
  --entry-serif: "Libre Baskerville", Baskerville, Georgia, serif;
  --rule: #c9472a;   /* field-guide red-orange rule */
  width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; background: var(--stage); color: #ece8dc;
}
dialog#lightbox::backdrop { background: rgba(0,0,0,.6); }
/* Not Birds: the photo full width, no details */
dialog#lightbox.bare .lb { grid-template-columns: minmax(0, 1fr); }
dialog#lightbox.bare .lb-tab, dialog#lightbox.bare .lb-info { display: none; }
/* Not Birds with GPS: the page without the spine tab */
dialog#lightbox.nb-entry .lb { grid-template-columns: minmax(0, 1fr) clamp(300px, 22vw, 360px); }
dialog#lightbox.nb-entry .lb-tab { display: none; }
.lb { display: grid; grid-template-columns: minmax(0, 1fr) 32px clamp(300px, 22vw, 360px); height: 100%; }
.lb-media { position: relative; margin: 0; display: flex; align-items: center; justify-content: center; padding: 12px; min-height: 0; }
.lb-media img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 20px 60px rgba(0,0,0,.5); }

/* round floating controls over the photo */
.lb-nav, .lb-close {
  position: absolute; width: 52px; height: 52px; border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(38, 37, 33, .62); color: #fff; line-height: 1;
  display: grid; place-items: center; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  transition: background .2s ease;
}
.lb-nav:hover, .lb-close:hover { background: rgba(38, 37, 33, .85); }
.lb-nav { top: 50%; transform: translateY(-50%); font-size: 34px; padding-bottom: 4px; }
.lb-nav.prev { left: 20px; } .lb-nav.next { right: 20px; }
.lb-close { top: 18px; right: 20px; font-size: 30px; }

/* the "spine" tab with the family name, like the guide's section tabs */
.lb-tab {
  /* tinted with the bird group's color (set per photo as --rule) */
  background: color-mix(in srgb, var(--rule) 16%, #ece8df);
  border-left: 1px solid color-mix(in srgb, var(--rule) 35%, #cfc9ba);
  border-right: 1px solid color-mix(in srgb, var(--rule) 25%, #d9d3c5);
  writing-mode: vertical-rl; transform: rotate(180deg);
  padding: 28px 0; text-align: left;
  font: 500 17px/32px var(--sans); letter-spacing: .02em; color: var(--rule);
  overflow: hidden; white-space: nowrap;
}

/* the page */
.lb-info {
  --bg: #fcfbf7; --bg-raised: #ffffff; --line: #e2dccd;
  --text: #1e1d1a; --muted: #57534a; --faint: #8a8475;
  --accent: var(--rule); --accent-ink: #ffffff;
  color-scheme: light; background: var(--bg); color: var(--text);
  padding: 36px 24px 24px; overflow-y: auto;
}
.entry-h { padding-bottom: 12px; border-bottom: 5px solid var(--rule); }
.lb-info h2 {
  margin: 0; font: 700 23px/1.2 var(--entry-serif);
  text-transform: uppercase; letter-spacing: .06em;
}
.lb-info .sci { margin: 6px 0 0; font: italic 16px/1.3 var(--entry-serif); letter-spacing: .07em; color: #3d3a33; }
.lb-info .status { margin: 4px 0 0; font: 15px var(--sans); letter-spacing: .03em; color: var(--muted); }
.lb-info .about { margin: 16px 0 0; font: 16px/1.7 var(--sans); letter-spacing: .02em; }
.lb-info .fact { margin: 8px 0 0; font: 16px/1.6 var(--sans); letter-spacing: .02em; }
.lb-info .fact em { font: italic 15px var(--entry-serif); letter-spacing: .06em; }
.lb-info .aside { color: var(--faint); }
.lb-info .desc { white-space: pre-line; }
.lb-map {
  height: 200px; margin: 14px 0 0; border-radius: 6px; border: 1px solid var(--line);
  background: #ebe7dd; isolation: isolate; /* keep Leaflet's z-indexes inside the map */
}
.lb-map .leaflet-control-attribution { font-size: 10px; }
/* soften OSM's bright default colors to suit the page */
.lb-map .leaflet-tile-pane { filter: saturate(.7) sepia(.12) brightness(1.02); }
.lb-info .map-cap { margin: 6px 0 0; font-size: 13px; }
.lb-info .links { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 14px 0 0; font-size: 14px; }
/* Not Birds "More like this" filter buttons */
.lb-info .more { margin-top: 18px; }
.lb-info .more h3 { margin: 0 0 8px; font: 600 11px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--faint); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 5px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-raised); color: var(--text); font: 14px var(--sans);
}
.pill span { font-size: 12px; color: var(--faint); }
.pill:hover { border-color: var(--accent); color: var(--accent); }
.lb-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.btn {
  display: block; text-align: center; padding: 10px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-raised); color: var(--text); text-decoration: none; font-size: 15px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
.counter { margin-top: 16px; font-size: 13px; color: var(--faint); }

@media (max-width: 900px) {
  :root { --row: 180px; }
  .lb { display: block; overflow-y: auto; height: 100%; background: var(--stage); }
  .lb-media { padding: 64px 0 12px; }
  .lb-media img { max-height: 58vh; box-shadow: none; }
  dialog#lightbox.bare .lb-media { height: 100%; padding: 64px 0; }
  dialog#lightbox.bare .lb-media img { max-height: 100%; }
  .lb-nav, .lb-close { width: 42px; height: 42px; }
  .lb-nav { font-size: 28px; } .lb-close { font-size: 26px; top: 12px; right: 12px; }
  .lb-nav.prev { left: 8px; } .lb-nav.next { right: 8px; }
  /* the tab becomes a strip across the top of the page */
  .lb-tab { writing-mode: horizontal-tb; transform: none; padding: 0 16px; border: 0; border-bottom: 1px solid #d9d3c5;
    font: 500 14px/36px var(--sans); letter-spacing: .04em; }
  .lb-tab:empty { display: none; }
  .lb-info { padding: 22px 18px 36px; overflow: visible; }
}
@media (max-width: 640px) {
  :root { --row: 108px; --gap: 4px; }
  .wrap { padding: 0 16px; }
  .masthead { padding: 32px 0 18px; }
  .brand { gap: 14px; }
  .mark { width: 60px; height: 60px; }
  .filters { justify-content: stretch; }
  .filters .field { flex: 1 1 45%; }
  .field.search { flex-basis: 100%; }
  .field.search input, .field select, #group, #species, #place { width: 100%; }
  .tabs { width: 100%; } .tabs button, .tabs .tab-link { flex: 1; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 10px; }
  .card h3 { font-size: 15px; }
  .tile .cap { display: none; }
  .foot { padding: 32px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
