* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: #f5f5f4; --card-bg: #ffffff; --text: #1c1917; --text-secondary: #78716c;
    --border: #e7e5e4; --radius: 20px; --shadow: 0 1px 3px rgba(0,0,0,0.04);
    --accent: #16a34a; --accent-soft: rgba(22,163,74,0.12); --bar: #16a34a; --bar-dim: #e7e5e4;
    --ink-soft: #a8a29e;
    /* sky palette: bars are tinted by the hour they belong to */
    --sky-night: #4c5a86; --sky-dawn: #f2a65a; --sky-day: #5ba8e0; --sky-dusk: #e8735c;
}
:root.dark {
    --bg: #0a0a0a; --card-bg: #141414; --text: #fafafa; --text-secondary: #a3a3a3;
    --border: #262626; --shadow: 0 1px 3px rgba(0,0,0,0.2);
    --accent: #4ade80; --accent-soft: rgba(74,222,128,0.14); --bar: #4ade80; --bar-dim: #262626;
    --ink-soft: #525252;
    --sky-night: #7d8fc4; --sky-dawn: #f7b978; --sky-day: #7fc3f2; --sky-dusk: #f4907a;
}
body {
    font-family: 'Space Grotesk', sans-serif; background: var(--bg); color: var(--text);
    min-height: 100vh; padding: 1.5rem 1rem 3rem; transition: background .4s, color .4s;
}
.container { width: 100%; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.header { display: flex; align-items: center; justify-content: space-between; padding: .5rem 0; }
.logo { font-family: 'Space Mono', monospace; font-size: .85rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); text-decoration: none; }
.logo-sub { color: var(--accent); }
.header-right { display: flex; align-items: center; gap: .75rem; }
.time { font-family: 'Space Mono', monospace; font-size: .8rem; color: var(--text-secondary); }
.theme-toggle { background: var(--card-bg); border: 1px solid var(--border); color: var(--text-secondary); border-radius: 50%; width: 30px; height: 30px; cursor: pointer; font-size: 1rem; line-height: 1; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #555; display: inline-block; }
.live-dot.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.live-dot.stale { background: #f59e0b; }
.live-dot.err { background: #ef4444; }
.intro { font-size: .9rem; color: var(--text-secondary); line-height: 1.5; padding: 0 .25rem; }
.intro strong { color: var(--text); font-weight: 600; }

.card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.card-title { font-weight: 600; font-size: .95rem; margin-bottom: .8rem; display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.card-sub { font-size: .75rem; color: var(--text-secondary); font-weight: 400; font-family: 'Space Mono', monospace; }

/* hero */
.hero { display: flex; gap: 1rem; align-items: stretch; padding: 0; overflow: hidden; min-height: 150px; position: relative; --tod: var(--sky-day); }
.hero.tod-night { --tod: var(--sky-night); } .hero.tod-dawn { --tod: var(--sky-dawn); } .hero.tod-dusk { --tod: var(--sky-dusk); }
.hero::before { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(115deg, transparent 45%, color-mix(in srgb, var(--tod) 14%, transparent)); }
.hero-glyph { position: absolute; top: .9rem; right: 1.1rem; font-size: 1.35rem; line-height: 1; opacity: .85; }
.hero-photo-wrap { flex: 0 0 150px; background: var(--bar-dim); }
.hero-photo { width: 150px; height: 100%; object-fit: cover; display: block; }
.hero-body { padding: 1.1rem 2.6rem 1.1rem 0; display: flex; flex-direction: column; gap: .2rem; min-width: 0; flex: 1; }
.hero-label { font-family: 'Space Mono', monospace; font-size: .72rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: .4rem; }
.hero-label .pulse { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1);} 50% { opacity: .4; transform: scale(.7);} }
.hero-name { font-size: 1.5rem; font-weight: 600; line-height: 1.15; }
.hero-sci { font-style: italic; color: var(--text-secondary); font-size: .9rem; }
.hero-meta { font-size: .8rem; color: var(--text-secondary); margin-top: .35rem; display: flex; flex-wrap: wrap; gap: .3rem .8rem; }
.hero-actions { margin-top: auto; padding-top: .6rem; }
@media (max-width: 420px) { .hero-photo-wrap { flex-basis: 110px; } .hero-photo { width: 110px; } .hero-name { font-size: 1.2rem; } }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; }
.stat { background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; padding: .7rem .5rem; text-align: center; }
.stat-v { font-family: 'Space Mono', monospace; font-weight: 700; font-size: 1.1rem; }
.stat-k { font-size: .68rem; color: var(--text-secondary); margin-top: .15rem; }
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* hourly chart */
.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; height: 70px; align-items: end; }
.hours .h { background: var(--bar); border-radius: 3px 3px 0 0; min-height: 2px; transition: height .4s; position: relative; }
.hours .h.now { outline: 2px solid var(--text); outline-offset: 1px; z-index: 1; }
.hours .h.now.zero { outline: none; background: var(--text) !important; min-height: 4px; opacity: .8; }
.hours .h { cursor: pointer; }
.hours .h.zero { cursor: default; }
.hours .h:hover:not(.zero) { filter: brightness(1.12); }
.hours .h:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.hours.filtering .h:not(.sel) { opacity: .3; }
.hours.filtering .h.zero { opacity: .5; }
.hours .h.sel { opacity: 1; outline: 2px solid var(--text); outline-offset: 1px; z-index: 1; border-radius: 3px; }
.clear { font: inherit; font-size: .68rem; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); background: var(--card-bg); color: var(--text); cursor: pointer; margin-left: .2rem; }
.clear:hover { border-color: var(--text-secondary); }
.hours .h.zero { background: var(--bar-dim) !important; }
.hours-axis { display: flex; justify-content: space-between; font-family: 'Space Mono', monospace; font-size: .62rem; color: var(--text-secondary); margin-top: .3rem; }
.sun-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-family: 'Space Mono', monospace; font-size: .62rem; color: var(--text-secondary); margin-top: .5rem; }
.sun-legend span { display: inline-flex; align-items: center; gap: .3rem; }
.sun-legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* species list */
.species-list { list-style: none; display: flex; flex-direction: column; gap: .55rem; }
.sp { display: grid; grid-template-columns: 40px 1fr auto; gap: .7rem; align-items: center; }
.sp img { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; background: var(--bar-dim); }
.sp-name { font-weight: 500; font-size: .9rem; display: block; }
.sp-sci { font-size: .72rem; color: var(--text-secondary); font-style: italic; }
.sp-count { font-family: 'Space Mono', monospace; font-size: .8rem; text-align: right; }
.spark { display: flex; gap: 1px; height: 14px; align-items: end; width: 72px; margin-left: auto; margin-top: 3px; }
.spark i { flex: 1; background: var(--ink-soft); min-height: 1px; border-radius: 1px; opacity: .9; }
.spark i.z { background: var(--bar-dim) !important; opacity: 1; }
.spark.filtering i:not(.sel) { opacity: .25; }
.spark.filtering i.sel { opacity: 1; outline: 1px solid var(--text); }
.sp-count small { font-size: .62rem; color: var(--text-secondary); font-weight: 400; }
.badge { font-family: 'Space Mono', monospace; font-size: .6rem; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 700; letter-spacing: .04em; white-space: nowrap; font-style: normal; display: inline-block; line-height: 1.4; vertical-align: middle; }
.badge.season { background: color-mix(in srgb, var(--sky-dawn) 18%, transparent); color: color-mix(in srgb, var(--sky-dawn) 75%, var(--text)); }
.badge.count { background: var(--bar-dim); color: var(--text-secondary); }
.badge.rare { background: color-mix(in srgb, var(--sky-night) 16%, transparent); color: color-mix(in srgb, var(--sky-night) 70%, var(--text)); }
.fd-name { display: block; }
.fd-name .badge, .fd-name .cls, .sp-name .badge, .sp-name .cls, .tp-name + .cls { vertical-align: middle; margin-left: .35rem; }
.badge-key { display: flex; flex-wrap: wrap; gap: .35rem 1rem; align-items: center; font-size: .7rem; color: var(--text-secondary); padding: 0 .25rem; }
.badge-key span { display: inline-flex; align-items: center; gap: .35rem; }

/* feed */
.feed { list-style: none; display: flex; flex-direction: column; gap: .5rem; }
.fd { display: grid; grid-template-columns: 34px 1fr auto auto; gap: .6rem; align-items: center; padding: .35rem 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.fd:last-child { border-bottom: none; }
.fd img { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; background: var(--bar-dim); }
.fd-name { font-size: .88rem; font-weight: 500; }
.fd-time { font-family: 'Space Mono', monospace; font-size: .7rem; color: var(--text-secondary); }
.conf-wrap { display: flex; flex-direction: column; align-items: flex-end; font-family: 'Space Mono', monospace; font-size: .72rem; color: var(--text-secondary); min-width: 2.6rem; }
.conf-wrap.hi { color: var(--text); font-weight: 700; }
.conf-wrap small { font-size: .58rem; opacity: .7; }
.play { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); background: var(--card-bg); color: var(--text); cursor: pointer; font-size: .8rem; display: grid; place-items: center; }
.play.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.play:disabled { opacity: .35; cursor: default; }
.spec { grid-column: 1 / -1; margin-top: .3rem; }
.spec img { width: 100%; border-radius: 10px; display: block; border: 1px solid var(--border); }
.btn { display: inline-flex; align-items: center; gap: .4rem; font: inherit; font-size: .8rem; padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--border); background: var(--card-bg); color: var(--text); cursor: pointer; }
.btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* daily: soft area chart */
.days { height: 96px; position: relative; margin-bottom: 2.2rem; }
.days svg { width: 100%; height: 100%; display: block; overflow: visible; }
.days .area { fill: url(#dayfill); }
.days .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.days .pt { fill: var(--card-bg); stroke: var(--accent); stroke-width: 1.5; }
.days .pt.today { fill: var(--accent); r: 4; }
.days .grid { stroke: var(--border); stroke-width: 1; }
.days .lbl { font-family: 'Space Mono', monospace; font-size: 9px; fill: var(--text-secondary); text-anchor: middle; }
.days .val { font-family: 'Space Mono', monospace; font-size: 9px; fill: var(--text-secondary); text-anchor: start; }
.days .hit { fill: transparent; }
.days .hit:hover + .pt { r: 4.5; }

/* top list */
.top-list { list-style: none; counter-reset: n; display: flex; flex-direction: column; gap: .55rem; }
.tp { display: grid; grid-template-columns: 1.2rem 36px 1fr auto; gap: .6rem; align-items: center; counter-increment: n; }
.tp::before { content: counter(n); font-family: 'Space Mono', monospace; font-size: .72rem; color: var(--text-secondary); text-align: right; }
.tp img { width: 36px; height: 36px; border-radius: 9px; object-fit: cover; background: var(--bar-dim); grid-row: 1 / 3; }
.tp:nth-child(-n+3)::before { color: var(--text); font-weight: 700; }
.tp-name { font-size: .9rem; font-weight: 500; }
.tp-meta { font-size: .68rem; color: var(--text-secondary); }
.tp-count { font-family: 'Space Mono', monospace; font-size: .8rem; }
.tp-bar { grid-column: 3 / -1; height: 2px; background: var(--bar-dim); border-radius: 1px; overflow: hidden; }
.tp-bar i { display: block; height: 100%; background: var(--ink-soft); }

.empty { color: var(--text-secondary); font-size: .85rem; }
.footer { text-align: center; font-size: .7rem; color: var(--text-secondary); line-height: 1.6; font-family: 'Space Mono', monospace; }
.footer a { color: inherit; }

/* ---------- desktop: grid instead of one long column ---------- */
@media (min-width: 960px) {
    body { padding: 2rem 2rem 3rem; }
    .container {
        max-width: 1120px;
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        grid-template-areas:
            "header header header"
            "intro  intro  intro"
            "hero   hero   stats"
            "sound  sound  days"
            "feed   today  today"
            "top    top    top"
            "key    key    key"
            "footer footer footer";
        gap: 1rem;
        align-items: stretch;
    }
    .a-header { grid-area: header; } .a-intro { grid-area: intro; max-width: 720px; }
    .a-hero { grid-area: hero; } .a-stats { grid-area: stats; } .a-sound { grid-area: sound; }
    .a-days { grid-area: days; } .a-feed { grid-area: feed; } .a-today { grid-area: today; }
    .a-top { grid-area: top; } .a-key { grid-area: key; } .a-footer { grid-area: footer; }

    .hero { min-height: 200px; }
    .hero-photo-wrap { flex-basis: 220px; } .hero-photo { width: 220px; }
    .hero-name { font-size: 2rem; }

    .stats { grid-template-columns: 1fr 1fr; gap: .75rem; }
    .stat { display: flex; flex-direction: column; justify-content: center; }
    .stat-v { font-size: 1.35rem; }

    .hours { height: 110px; }
    .days { height: 120px; }

    /* latest calls: a fixed-height scrolling column beside the species grid */
    .a-feed { display: flex; flex-direction: column; max-height: 720px; }
    .a-feed .feed { overflow-y: auto; padding-right: .25rem; flex: 1; min-height: 0; }

    /* heard today: tiles instead of rows */
    .species-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .6rem; }
    .sp { grid-template-columns: 44px 1fr; grid-template-rows: auto auto; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 14px; background: var(--bg); align-items: center; }
    .sp img { width: 44px; height: 44px; grid-row: 1 / 3; }
    .sp > div:last-child { grid-column: 2; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
    .spark { margin-left: 0; }

    /* all-time regulars: two columns */
    .top-list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 2.5rem; row-gap: .45rem; }
}
@media (min-width: 1280px) {
    .species-list { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
}

/* ---------- species panel ---------- */
.clickable { cursor: pointer; }
.sp.clickable:hover { border-color: var(--text-secondary); }
.tp.clickable:hover .tp-name, .fd.clickable:hover .fd-name { text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.hero-name.clickable:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; }
.no-scroll { overflow: hidden; }
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-back { position: absolute; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.sheet { position: relative; background: var(--card-bg); color: var(--text); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; border: 1px solid var(--border); box-shadow: 0 -8px 40px rgba(0,0,0,.25); padding: 1.1rem 1.2rem 2.2rem; animation: rise .22s ease-out; overscroll-behavior: contain; }
@keyframes rise { from { transform: translateY(28px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-close { position: absolute; top: .8rem; right: .8rem; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); background: var(--card-bg); color: var(--text-secondary); cursor: pointer; font-size: .9rem; display: grid; place-items: center; z-index: 1; }
.sheet-close:hover { color: var(--text); border-color: var(--text-secondary); }
.sheet-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; padding-right: 2.4rem; }
.sheet-photo { width: 84px; height: 84px; border-radius: 16px; object-fit: cover; background: var(--bar-dim); flex: none; }
.sheet-name { font-size: 1.4rem; font-weight: 600; line-height: 1.15; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.sheet-sci { font-style: italic; color: var(--text-secondary); font-size: .9rem; margin-top: .15rem; }
.sheet-body { display: flex; flex-direction: column; gap: 1.2rem; }
.sheet-about { font-size: .9rem; line-height: 1.55; color: var(--text); }
.sheet-about a { color: var(--accent); text-decoration: none; font-family: 'Space Mono', monospace; font-size: .72rem; margin-left: .4rem; white-space: nowrap; }
.sheet-about a:hover { text-decoration: underline; }
.sheet-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.sheet-stats .stat { background: var(--bg); }
.sheet-stats .stat-v { font-size: 1rem; }
@media (max-width: 420px) { .sheet-stats { grid-template-columns: repeat(2, 1fr); } }
.sheet .hours { height: 80px; }
.hours.static .h { cursor: default; }
.hours.static .h:hover { filter: none; }
.days30 { display: grid; grid-template-columns: repeat(30, 1fr); gap: 2px; height: 64px; align-items: end; }
.days30 i { display: block; background: var(--ink-soft); border-radius: 2px 2px 0 0; min-height: 2px; }
.days30 i.z { background: var(--bar-dim); }
.days30 i.today { background: var(--accent); }
.fd-mini { grid-template-columns: 1fr auto auto; cursor: default; }
@media (min-width: 960px) { .sheet-wrap { align-items: center; padding: 2rem; } .sheet { border-radius: var(--radius); max-height: 88vh; } }

/* ---------- day picker, chips, weather ---------- */
.card-title { flex-wrap: wrap; }
.card-title .card-sub { margin-left: auto; text-align: right; }
.a-feed .card-title .card-sub { flex-basis: auto; }
.day-nav { display: inline-flex; align-items: center; gap: .25rem; }
.day-nav button { font: inherit; font-family: 'Space Mono', monospace; font-size: .72rem; line-height: 1; padding: .2rem .5rem; border-radius: 999px; border: 1px solid var(--border); background: var(--card-bg); color: var(--text); cursor: pointer; }
.day-nav button:hover:not(:disabled) { border-color: var(--text-secondary); }
.day-nav button:disabled { opacity: .3; cursor: default; }
.day-nav button.today-btn { color: var(--accent); }
.sun-legend .hint { margin-left: auto; opacity: .8; }
.chips { display: inline-flex; gap: .3rem; flex-wrap: wrap; }
.chip { font: inherit; font-family: 'Space Mono', monospace; font-size: .66rem; padding: .18rem .55rem; border-radius: 999px; border: 1px solid var(--border); background: var(--card-bg); color: var(--text-secondary); cursor: pointer; white-space: nowrap; }
.chip:hover { border-color: var(--text-secondary); color: var(--text); }
.chip.on { background: var(--text); color: var(--card-bg); border-color: var(--text); }
.chip.static { cursor: default; color: var(--text); }
.chip.reg-rare, .chip.reg-very_rare { border-color: color-mix(in srgb, var(--sky-night) 60%, transparent); background: color-mix(in srgb, var(--sky-night) 12%, transparent); }
.chip.reg-uncommon { border-color: color-mix(in srgb, var(--sky-dawn) 60%, transparent); background: color-mix(in srgb, var(--sky-dawn) 12%, transparent); }
.sheet-meta { display: flex; gap: .4rem; flex-wrap: wrap; }
.cls { font-size: .8em; margin-left: .1rem; }
.days .temp { fill: none; stroke-width: 1.5; stroke-dasharray: 4 3; opacity: .8; }
.daypt { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--card-bg); border: 1.5px solid var(--accent); transform: translate(-50%, -50%); cursor: pointer; }
.daypt:hover { width: 11px; height: 11px; }
.daypt.today { width: 10px; height: 10px; background: var(--accent); }
.daypt.sel { background: var(--text); border-color: var(--text); width: 10px; height: 10px; box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 18%, transparent); }
.daylbl { position: absolute; bottom: -.95rem; transform: translateX(-50%); font-family: 'Space Mono', monospace; font-size: .55rem; color: var(--text-secondary); white-space: nowrap; }
.daylbl.today { font-weight: 700; color: var(--text); }
.daywx { position: absolute; bottom: -2.1rem; transform: translateX(-50%); font-size: .72rem; line-height: 1; }
.days-legend { display: flex; gap: 1rem; font-family: 'Space Mono', monospace; font-size: .62rem; color: var(--text-secondary); margin-top: .2rem; flex-wrap: wrap; }
.days-legend i { display: inline-block; width: 14px; border-top: 2px solid var(--accent); vertical-align: middle; margin-right: .3rem; }
.days-legend i.t { border-top: 2px dashed var(--sky-dusk); }

/* ---------- day-view exits + touch targets ---------- */
.daypt::before { content: ''; position: absolute; inset: -11px; }
.daylbl { cursor: pointer; padding: 4px 6px; margin: -4px -6px; }
.daylbl.today { text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.day-nav button { min-height: 30px; min-width: 30px; }
.chip.back { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: var(--accent-soft); font-weight: 700; }
.clear, .chip { min-height: 26px; }
@media (max-width: 959px) { .card-title .card-sub .clear { padding: 3px 9px; } }
