:root {
  --bg: #f6f3ea; --ink: #2b2a26; --muted: #8a8574; --card: #fffdf6;
  --accent: #4a6b4f; --line: #e0dccd;
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: Georgia, "Times New Roman", serif;
  background: var(--bg); color: var(--ink); min-height: 100vh;
}
nav {
  display: flex; gap: 1.2rem; align-items: baseline;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--line);
}
nav .brand { font-size: 1.3rem; font-weight: bold; color: var(--accent); margin-right: 0.6rem; }
/* "last bird N min ago": newest detection of any species, refreshed per page load */
.nav-last { color: var(--muted); font-size: 0.8rem; margin-right: auto; white-space: nowrap; }
nav a { color: var(--muted); text-decoration: none; }
nav a:hover { color: var(--ink); }
.stale-banner {
  background: #b3542e; color: #fff; text-align: center;
  padding: 0.3rem; font-size: 0.85rem;
}
main { padding: 1.5rem; }
body.frame nav { display: none; }
/* Frame mode: content must FIT the viewport — a screenshot of a scrolling page
   crops mid-row. Views cap item counts; vh-based sizing does the rest. */
body.frame { height: 100vh; overflow: hidden; }
body.frame main { padding: 1.2vh 1.2vw; height: 100vh; }
body.frame .cards { grid-template-columns: repeat(4, 1fr); gap: 1.2vh 1vw; }
body.frame .card { padding: 1.2vh 0.8vw; }
body.frame .card img { height: 26vh; }
body.frame .card h2 { font-size: 2.8vh; margin-top: 0.6vh; }
body.frame .card .sci { font-size: 2vh; }
body.frame .card .meta { font-size: 1.9vh; margin-top: 0.4vh; }
body.frame .collage { grid-template-columns: repeat(6, 1fr); gap: 1.5vh 0.8vw; }
body.frame .collage img { height: 24vh; }
body.frame .collage figcaption { font-size: 2vh; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 1rem; text-align: center;
}
.card img { width: 100%; height: 160px; object-fit: contain; }
.card h2 { font-size: 1.05rem; margin-top: 0.5rem; }
.card .sci { font-style: italic; color: var(--muted); font-size: 0.85rem; }
.card .meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.3rem; }

.windows { display: flex; gap: 0.4rem; margin-bottom: 1rem; }
.windows a {
  color: var(--muted); text-decoration: none; font-size: 0.85rem;
  padding: 0.15rem 0.6rem; border: 1px solid var(--line); border-radius: 999px;
}
.windows a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
body.frame .windows { display: none; }
.card .badge { color: var(--accent); }

.collage { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.8rem; }
.collage figure { text-align: center; }
.collage img { width: 100%; height: 120px; object-fit: contain; }
.collage figcaption { display: flex; justify-content: space-between; font-size: 0.8rem; padding: 0 0.2rem; }
.collage figcaption span { color: var(--muted); }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 1.2rem; text-align: center; display: flex; flex-direction: column;
}
.tile .n { font-size: 2.2rem; color: var(--accent); }
.tile .l { color: var(--muted); font-size: 0.85rem; }
.hourly, .top { margin-top: 1.5rem; }
.hourly h2, .top h2 { font-size: 1rem; color: var(--muted); margin-bottom: 0.6rem; }
.hourly h2 .sub { font-size: 0.8rem; font-weight: normal; margin-left: 0.5rem; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bar { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; }
.bar-hours { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.75rem; margin-top: 0.2rem; }
.top ol { padding-left: 1.4rem; }
.top .count { color: var(--muted); margin-left: 0.5rem; }
/* drill-down: rows and tiles lead to the species page / a filtered grid */
a.tile { text-decoration: none; color: inherit; }
a.tile:hover { border-color: var(--accent); }
.top a, .hm-name a { color: inherit; text-decoration: none; }
.top a:hover, .hm-name a:hover { color: var(--accent); }

/* species detail page */
.species-head { display: flex; gap: 1.5rem; align-items: center; }
.species-head img { width: 220px; height: 220px; object-fit: contain; }
.species-head h1 { font-size: 1.6rem; }
.sp-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem 1.2rem; margin-top: 0.8rem; max-width: 26rem; }
.sp-stats > div { display: flex; flex-direction: column; }
.sp-stats .n { font-size: 1.1rem; }
.sp-stats .l { color: var(--muted); font-size: 0.75rem; }
.clips { margin-top: 1.5rem; max-width: 720px; }
.clip { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0.8rem; margin-bottom: 0.8rem; }
.clip img { width: 100%; }
.clip.gone { display: none; }
.clip audio { width: 100%; }
.clip-meta { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.3rem; }
.card h2 a, .tile-link { color: inherit; text-decoration: none; }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--accent); }
a.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* corner chip: weather + time (web + frame renders) */
.chip {
  position: fixed; bottom: 0.4rem; right: 0.6rem;
  font-size: 0.85rem; color: var(--muted); opacity: 0.85;
}
body.frame .chip { bottom: 0.6vh; right: 0.8vw; font-size: 1.9vh; opacity: 0.8; }
.chip-stale { color: #b3542e; }  /* frame-mode staleness marker (the banner would crop the render) */

.site-foot {
  margin: 2.5rem 0 1.6rem; text-align: center;
  color: var(--muted); font-size: 0.78rem;
}
.site-foot a { color: var(--muted); }

/* species x hour heatmap */
.heatmap-wrap { margin-top: 1.5rem; }
.heatmap-wrap h2 { font-size: 1rem; color: var(--muted); margin-bottom: 0.6rem; }
.heatmap-wrap h2 .sub { font-size: 0.8rem; font-weight: normal; margin-left: 0.5rem; }
.heatmap { display: grid; grid-template-columns: 10rem repeat(24, 1fr); gap: 2px; }
.hm-name { font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 0.4rem; }
.hm-cell { background: var(--accent); border-radius: 2px; min-height: 0.95rem; }
.hm-hours { margin-left: 10rem; }

.windows .bug-pill { margin-left: auto; }

/* live packed collage (d3-force, client-side) */
.packed-live { position: relative; width: 100%; height: calc(100vh - 96px); overflow: hidden; }
body.frame .packed-live { height: 100vh; }
.packed-live .ptile { will-change: transform; transition: transform 0.6s ease, width 0.6s ease, height 0.6s ease; }
body.frame .packed-live .ptile { transition: none; } /* renders must not animate */
.ptile { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; text-decoration: none; color: inherit; }
.ptile img { width: 100%; flex: 1; min-height: 0; object-fit: contain; }
.ptile span { text-align: center; font-size: inherit; color: var(--ink); line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ptile span em { color: var(--muted); font-style: normal; }
body.frame .windows { display: none; }
body.frame .heatmap-wrap { display: none; }  /* doesn't fit frame viewports; web only */

/* single-bird realtime panel */
.bird-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 1rem; min-height: 70vh; }
.bird-panel img { max-width: min(90vw, 70vh); max-height: 62vh; object-fit: contain; }
.bird-id h1 { font-size: clamp(1.4rem, 4.5vh, 2.6rem); }
/* live pulse: freshly-detected species (web only; frame renders never poll) */
.ptile.pulse { animation: pulse-glow 5s ease-out; }
.ptile.pulse img { animation: pulse-img 5s ease-out; }
@keyframes pulse-glow {
  0% { filter: none; }
  10% { filter: drop-shadow(0 0 12px rgba(255, 200, 60, 0.9)); }
  70% { filter: drop-shadow(0 0 6px rgba(255, 200, 60, 0.4)); }
  100% { filter: none; }
}
@keyframes pulse-img {
  0% { transform: scale(1); }
  12% { transform: scale(1.08); }
  30% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

/* weekly digest */
.digest { display: flex; flex-direction: column; gap: 1.2rem; }
.digest-head h1 { font-size: clamp(1.3rem, 4vh, 2.2rem); }
.digest-head .meta { color: var(--muted); margin-top: 0.3rem; }
.digest-tiles { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.digest-lines p { margin: 0.3rem 0; }
body.frame .digest { gap: 1.5vh; height: 92vh; overflow: hidden; justify-content: center; }
body.frame .digest-tiles { grid-template-columns: repeat(5, 1fr); gap: 1vh 0.8vw; }
body.frame .digest-tiles img { height: 34vh; }
body.frame .digest-tiles figcaption { font-size: 2vh; }
body.frame .digest-lines p { font-size: 2.4vh; margin: 0.5vh 0; }

.bird-id .fresh { color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }
body.frame .bird-id .fresh { font-size: 2.1vh; }
.bird-empty p { color: var(--muted); font-size: 1.4rem; }
body.frame .bird-panel { min-height: 92vh; gap: 0.5vh; }
body.frame .bird-panel img { max-height: 72vh; max-width: 92vw; }

/* field-journal plate panel (inky-bird-frame catalog) */
.plate-panel { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.plate-panel img { max-width: 100%; max-height: 82vh; object-fit: contain; touch-action: pan-y; }
.plate-nav { display: flex; align-items: center; gap: 1rem; color: var(--muted); }
.plate-nav button {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink); font-size: 1.5rem; line-height: 1; padding: 0.2rem 0.9rem; cursor: pointer;
}
.plate-nav button:hover { color: var(--accent); }
body.frame .plate-panel { position: fixed; inset: 0; }
body.frame .plate-panel img { width: 100vw; height: 100vh; max-height: none; object-fit: contain; }

/* --- nav: the old flex row on desktop, a burger menu below the phone
       breakpoint. Checkbox + label rather than <details>: a closed <details>
       hides its own children in current Chrome no matter what `display` the
       child carries, which blanks the desktop nav entirely. --- */
.navtoggle, .burger { display: none; }
.navlinks { display: flex; gap: 1.2rem; align-items: baseline; }

/* --- phone breakpoint. body.frame never matches anything here: nav is already
       hidden in frame mode and the chip rule is scoped to body:not(.frame). --- */
@media (max-width: 640px) {
  nav { padding: 0.8rem 1rem; }
  main { padding: 1rem; }
  nav { position: relative; }
  .burger {
    display: block; cursor: pointer; user-select: none;
    font-size: 1.4rem; color: var(--muted); padding: 0 0.2rem;
  }
  .navlinks { display: none; }
  .navtoggle:checked ~ .navlinks {
    display: flex; position: absolute; right: 1rem; top: 3rem; z-index: 5;
    flex-direction: column; align-items: flex-end; gap: 0.9rem;
    background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    padding: 0.9rem 1.2rem; min-width: 8rem;
  }
  /* keyboard: the checkbox is visually hidden but must stay focusable */
  .navtoggle {
    display: block; position: absolute; opacity: 0;
    width: 1px; height: 1px; right: 1rem; top: 1rem;
  }
  .navtoggle:focus-visible ~ .burger { color: var(--accent); outline: 2px solid var(--accent); }
  body:not(.frame) .chip {
    position: static; display: block; text-align: center;
    margin: 1.5rem 1rem 0; opacity: 0.7;
  }
  .species-head { flex-direction: column; align-items: flex-start; }
  .species-head img { width: 100%; height: auto; max-height: 40vh; object-fit: contain; }
  .sp-stats { max-width: none; }
  .collage { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .collage figcaption {
    flex-direction: column; align-items: center; gap: 0.1rem;
    font-size: 0.75rem; overflow-wrap: anywhere;
  }
  .card h2, .collage figcaption strong { overflow-wrap: anywhere; }
  .stat-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
  .heatmap-wrap { overflow-x: auto; }
  .vis-cols { grid-template-columns: 1fr; }
}

/* /recent auto-refresh toggle (web only; the template omits it in frame mode) */
.refresh-bar { display: flex; justify-content: flex-end; margin-bottom: 0.8rem; }
.refresh-bar label { color: var(--muted); font-size: 0.85rem; cursor: pointer; }
.refresh-bar input { margin-right: 0.35rem; vertical-align: middle; }

/* collage density toggle + dropped-species note (web only) */
.pill {
  color: var(--muted); font-size: 0.85rem; font-family: inherit; cursor: pointer;
  padding: 0.15rem 0.6rem; border: 1px solid var(--line); border-radius: 999px;
  background: none;
}
.pill[data-mode="dense"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.pill.busy { opacity: 0.5; cursor: wait; }
.drop-note { color: var(--muted); font-size: 0.8rem; text-align: center; margin-top: 0.8rem; }
.drop-note a { color: var(--accent); }

/* /visitors (LAN only) */
.vis .stat-tiles { margin: 1rem 0; max-width: 32rem; }
.vis .note { color: var(--muted); font-size: 0.8rem; margin: 0.4rem 0 1.2rem; }
.vis h2 { font-size: 1rem; color: var(--muted); margin: 1.2rem 0 0.5rem; }
.vis table { border-collapse: collapse; font-size: 0.85rem; width: 100%; }
.vis th, .vis td { text-align: left; padding: 0.3rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.vis th { color: var(--muted); font-weight: normal; }
.vis .r { text-align: right; }
.vis .ip { font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; white-space: nowrap; }
.vis-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.vis section { overflow-x: auto; }
.vis td { white-space: nowrap; }

/* about page */
.about { max-width: 38rem; margin: 0 auto; line-height: 1.6; }
.about h1 { margin-bottom: 1rem; }
.about p { margin-bottom: 1rem; }
.site-foot .ver { opacity: 0.7; }
/* dense collage: caption keeps the name, drops the count (still in the tooltip) */
.packed-live.dense .ptile span em { display: none; }
