:root {
  --bg: #0d1014;
  --bg2: #12161c;
  --panel: #171c24;
  --ink: #eef2f6;
  --muted: #8a94a3;
  --line: #262d38;
  --accent: #ffb454;
  --shadow: 0 2px 6px rgba(0,0,0,.35), 0 18px 50px rgba(0,0,0,.45);

  /* one hue per sound shape — reused by chips, map fill, and tags */
  --whistle: #ffd66b;
  --trill:   #7ddc8a;
  --chatter: #ff9a52;
  --hoot:    #6ea8ff;
  --honk:    #4fd3c4;
  --buzz:    #c08bff;
  --screech: #ff6b7a;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f1ea;
    --bg2: #ebe6db;
    --panel: #fffdf9;
    --ink: #1b1a17;
    --muted: #6d6759;
    --line: #ddd5c5;
    --accent: #c2622a;
    --shadow: 0 1px 3px rgba(80,60,25,.08), 0 14px 40px rgba(80,60,25,.12);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 700px at 50% -10%, var(--bg2), var(--bg));
  background-attachment: fixed;
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---------------- header ---------------- */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 24px;
  padding: 16px clamp(14px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
}

.brand h1 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.tag { margin: 1px 0 0; color: var(--muted); font-size: 12.5px; }

/* The map was an unlabelled 99-polygon blob; "Iowa" lived only in <title>. */
.where {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #0d1014;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .01em;
  vertical-align: 2px;
}

/* ---------------- first-run gate ---------------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 7, 10, .82);
  backdrop-filter: blur(10px);
  transition: opacity .35s ease;
}

.gate[hidden] { display: none; }
.gate.gone { opacity: 0; pointer-events: none; }

.gate-card {
  max-width: 420px;
  width: 100%;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px 26px 26px;
  box-shadow: var(--shadow);
}

.gate-card h2 { margin: 0; font-size: 27px; letter-spacing: -.03em; }
.gate-lead { margin: 10px 0 0; font-size: 15.5px; line-height: 1.45; }
.gate-lead strong { color: var(--accent); }
.gate-sub { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }

.gate-go {
  margin-top: 20px;
  padding: 13px 26px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #0d1014;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.gate-go:hover { filter: brightness(1.08); }

.gate-fine { margin: 14px 0 0; color: var(--muted); font-size: 11.5px; line-height: 1.5; }

.shapes { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.shapes-label { color: var(--muted); font-size: 12.5px; margin-right: 2px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}

.chip i {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--c, var(--muted));
}

.chip:hover { color: var(--ink); border-color: var(--c, var(--accent)); }

.tally {
  margin-left: 2px;
  padding: 0 5px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 18%, transparent);
  color: var(--c);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.chip.on .tally { background: rgba(0, 0, 0, .28); color: inherit; }
.chip.rare { opacity: .72; }   /* honest about the thin buckets */

.chip.on {
  color: #0d1014;
  background: var(--c);
  border-color: var(--c);
  font-weight: 650;
}
.chip.on i { background: rgba(0,0,0,.45); }

.chip[data-shape=whistle] { --c: var(--whistle); }
.chip[data-shape=trill]   { --c: var(--trill); }
.chip[data-shape=chatter] { --c: var(--chatter); }
.chip[data-shape=hoot]    { --c: var(--hoot); }
.chip[data-shape=honk]    { --c: var(--honk); }
.chip[data-shape=buzz]    { --c: var(--buzz); }
.chip[data-shape=screech] { --c: var(--screech); }

.toggle { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------------- stage / map ---------------- */

main { padding: 0 clamp(14px, 3vw, 32px); }

.stage {
  position: relative;
  margin: 18px auto 0;
  max-width: 1100px;
}

#map { width: 100%; height: auto; display: block; overflow: visible; }

#map path {
  fill: var(--f, #1c222b);
  stroke: var(--bg);
  stroke-width: .7;
  cursor: pointer;
  transition: fill .18s ease, filter .18s ease;
}

#map path:hover { filter: brightness(1.55); }

#map path.sel {
  stroke: var(--accent);
  stroke-width: 1.6;
  filter: brightness(1.35) drop-shadow(0 0 10px rgba(255,180,84,.55));
}

#map path:focus-visible { outline: none; stroke: var(--accent); stroke-width: 2; }

/* loading / failure state over the reserved map box */
.boot {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  text-align: center;
  padding: 20px;
}

.boot[hidden] { display: none; }
.boot-msg { margin: 0; color: var(--muted); font-size: 13.5px; max-width: 34ch; }

.boot-spin {
  width: 26px; height: 26px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.boot.failed .boot-spin { display: none; }
.boot.failed .boot-msg { color: var(--ink); }

.boot-retry {
  padding: 9px 18px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.boot-retry:hover { background: var(--accent); color: #0d1014; }

/* radial halo of birds around the opened county */
.ring { position: absolute; inset: 0; pointer-events: none; }

.pip {
  position: absolute;
  width: var(--pip, 52px);
  height: var(--pip, 52px);
  margin: calc(var(--pip, 52px) / -2) 0 0 calc(var(--pip, 52px) / -2);
  border-radius: 50%;
  border: 2px solid var(--panel);
  overflow: hidden;
  cursor: pointer;
  pointer-events: auto;
  background: var(--panel);
  box-shadow: 0 3px 12px rgba(0,0,0,.5);
  transition: transform .18s cubic-bezier(.34,1.56,.64,1), border-color .18s;
  animation: pop .28s backwards cubic-bezier(.34,1.56,.64,1);
}

@keyframes pop { from { transform: scale(.2); opacity: 0; } }

.pip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pip:hover { transform: scale(1.35); border-color: var(--accent); z-index: 5; }

.pip.sounding {
  border-color: var(--accent);
  animation: ping 1s ease-out infinite;
}

@keyframes ping {
  0%   { box-shadow: 0 0 0 0 rgba(255,180,84,.55); }
  100% { box-shadow: 0 0 0 16px rgba(255,180,84,0); }
}

.pip .n { display: none; }

.spoke { position: absolute; pointer-events: none; }

/* hover readout */
.peek {
  position: absolute;
  z-index: 20;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  pointer-events: none;
  transform: translate(-50%, -120%);
}

.peek-name { font-weight: 650; font-size: 13.5px; white-space: nowrap; }
.peek-sub { color: var(--muted); font-size: 11.5px; white-space: nowrap; }

.spec {
  display: block;
  border-radius: 7px;
  background: #05070a;
}

.spec.big { width: 100%; height: auto; margin: 10px 0; }

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}

.legend b { display: inline-flex; align-items: center; gap: 5px; font-weight: 400; }
.legend b::before { content: ""; width: 9px; height: 9px; border-radius: 2px; background: var(--c); }

.hint { margin: 8px 0 0; color: var(--muted); font-size: 11.5px; }

kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
  font: inherit;
  font-size: .92em;
}

/* Only present while audio is playing — the control appears exactly when the
   user wants it and never clutters the page otherwise. */
.stopbar {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--shadow);
  animation: rise .18s ease-out;
}

.stopbar[hidden] { display: none; }
.stopbar:hover { border-color: var(--accent); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.stopbar-ico {
  width: 11px; height: 11px;
  border-radius: 2px;
  background: var(--accent);
}

/* ---------------- timeline ---------------- */

.timeline {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 1100px;
  margin: 14px auto 0;
}

.yearplay {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
}

.yearplay:hover { border-color: var(--accent); color: var(--accent); }
.yearplay.on { background: var(--accent); color: #0d1014; border-color: var(--accent); }

.months { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; flex: 1; }

.mbtn {
  padding: 7px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}

.mbtn:hover { color: var(--ink); border-color: var(--accent); }
.mbtn.on { background: var(--accent); border-color: var(--accent); color: #0d1014; font-weight: 650; }

/* ---------------- tray ---------------- */

.tray { max-width: 1100px; margin: 22px auto 0; }
.tray-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.tray-head h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.tray-head p { margin: 0; color: var(--muted); font-size: 12.5px; }

.rail {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 14px;
  scrollbar-width: thin;
}

.bird {
  flex: none;
  width: 128px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  color: inherit;
  font: inherit;
  transition: transform .15s, border-color .15s;
}

.bird:hover, .bird:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent);
  outline: none;
}

.bird.sounding { border-color: var(--accent); }
.bird figure { margin: 0; aspect-ratio: 1; background: #10151c; }
.bird img { width: 100%; height: 100%; object-fit: cover; display: block; }

.bird .cap { padding: 8px 9px 10px; }
.bird .cn { font-size: 12.5px; font-weight: 600; line-height: 1.25; }
.bird .cs { margin-top: 3px; display: flex; gap: 4px; flex-wrap: wrap; }

.tag {
  font-size: 9.5px;
  padding: 1.5px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 22%, transparent);
  color: var(--c);
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
}

.tag[data-t=whistle] { --c: var(--whistle); }
.tag[data-t=trill]   { --c: var(--trill); }
.tag[data-t=chatter] { --c: var(--chatter); }
.tag[data-t=hoot]    { --c: var(--hoot); }
.tag[data-t=honk]    { --c: var(--honk); }
.tag[data-t=buzz]    { --c: var(--buzz); }
.tag[data-t=screech] { --c: var(--screech); }

/* ---------------- detail sheet ---------------- */

/* class display would otherwise beat the UA rule for [hidden] */
.sheet[hidden], .peek[hidden] { display: none; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(5,7,10,.72);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.sheet-body {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 18px;
  max-width: 700px;
  width: 100%;
  max-height: 88vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}

@media (max-width: 620px) { .sheet-body { grid-template-columns: 1fr; } }

.sheet-body > img { width: 100%; border-radius: 12px; aspect-ratio: 1; object-fit: cover; }

/*
 * Grid items default to min-width:auto, so this column refuses to shrink below
 * its widest content -- the 440px-wide spectrogram canvas -- and the sheet
 * burst out of any viewport under ~470px. min-width:0 lets it actually shrink.
 */
.sheet-main { min-width: 0; }
.sheet-main h3 { margin: 0; font-size: 22px; letter-spacing: -.02em; }

.sheet-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

/* Without this you reach the bird you care about and can never hear it again. */
.replay {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #0d1014;
  font-size: 16px;
  cursor: pointer;
}

.replay:hover { filter: brightness(1.08); transform: scale(1.05); }
.replay:active { transform: scale(.96); }
.sheet-sci { color: var(--muted); font-style: italic; font-size: 13px; }
.sheet-tags { display: flex; gap: 5px; flex-wrap: wrap; }
.sheet-blurb { font-size: 13.5px; color: var(--ink); opacity: .88; }

.sheet-x {
  position: absolute;
  top: 24px; right: 26px;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.alike-h { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 12px 0 6px; }
.alike-row { display: flex; gap: 8px; }

.alike-row button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 10px;
  padding: 5px 5px 6px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  width: 78px;
}

.alike-row button:hover { border-color: var(--accent); }
.alike-row img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; display: block; }
.alike-row span { display: block; font-size: 10px; margin-top: 4px; line-height: 1.2; }

.sheet-attrib { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 10.5px; color: var(--muted); }
.sheet-attrib a { color: var(--muted); }

/* ---------------- footer ---------------- */

.credits {
  max-width: 1100px;
  margin: 26px auto 0;
  padding: 16px clamp(14px, 3vw, 32px) 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
}

.credits p { margin: 0 0 6px; }
.fine { opacity: .8; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------- touch ---------------- */

/*
 * Measured on a 375px viewport: month buttons came out 21x33 px and the halo
 * pips 38 px — both under the 44 px minimum, and the months were 12-across.
 * Two rows of six gives real targets without hiding anything.
 */
@media (hover: none) {
  .months {
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
  }

  .mbtn { padding: 12px 0; font-size: 13px; }

  .chip { padding: 9px 13px 9px 10px; font-size: 13px; }

  .yearplay { width: 44px; height: 44px; }

  .timeline { align-items: flex-start; }

  /* No hover means no accidental audio; the toggle only confuses here. */
  .toggle { display: none; }

  /* .pip sizing stays in JS — drawRing() derives the ring radius from it. */

  .hint { font-size: 12px; }
}

@media (max-width: 560px) {
  .top { gap: 10px 14px; padding: 12px; }
  .shapes { margin-left: 0; }
  .tray-head { flex-wrap: wrap; gap: 2px 10px; }
}

/* An identification tool must say when it is not sure. */
.tag.unver {
  --c: var(--muted);
  font-style: italic;
}

/* Reported here, but with no recording we can vouch for. Shown, not hidden —
   omitting them made the list quietly wrong. */
.bird.silent { opacity: .58; cursor: default; }
.bird.silent:hover { transform: none; border-color: var(--line); }
.bird.silent figure img { filter: grayscale(.85); }

.tag.nosound { --c: var(--muted); font-style: italic; }
.replay[hidden] { display: none; }

/* ---------------- ecoregion ---------------- */

/* Counties sharing the selected county's ecoregion — the habitat region made
   visible, since that is what actually decides which birds are here. */
#map path.kin { stroke: var(--accent); stroke-width: 1.1; stroke-opacity: .5; }

.eco {
  margin: 0 0 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.eco[hidden] { display: none; }

.eco-name {
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
  font-weight: 650;
}

.eco-l2 { opacity: .8; }
.eco-why b { color: var(--ink); font-weight: 600; cursor: pointer; }
.eco-why b:hover { color: var(--accent); }

/* ---------------- layer switch ---------------- */

.layers { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.layers[hidden] { display: none; }

.layer-btn {
  padding: 7px 14px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.layer-btn:hover { color: var(--ink); }
.layer-btn.on { background: var(--accent); color: #0d1014; font-weight: 650; }

/* In ecoregion mode the county lines are scaffolding — fade them so the
   habitat region reads as one shape rather than 81 rectangles. */
#map path.eco-mode { stroke-opacity: .18; }
#map path.eco-mode.sel { stroke-opacity: 1; stroke-width: 1.2; }
