:root {
  --ground: #0f1412;
  --glass: rgba(14, 19, 17, 0.84);
  --glass-solid: #121815;
  --line: rgba(222, 236, 226, 0.12);
  --line-strong: rgba(222, 236, 226, 0.28);
  --ink: #eef3ec;
  --ink-2: #c2cdc4;
  --muted: #8d9a91;
  --accent: #ff8cc6;
  --gold: #ffcf2e;
  --sans: "Bricolage Grotesque", "Helvetica Neue", Arial, sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  --mono: "Fragment Mono", ui-monospace, Menlo, Consolas, monospace;
  --gutter: 16px;
  --dock-h: 168px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--ground); color: var(--ink); font-family: var(--sans); font-size: 15px; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
a { color: var(--ink); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--ink); color: var(--ground); padding: 10px 14px; border-radius: 8px; }
.skip:focus { top: 8px; }
.noscript { position: absolute; inset: 40% 16px auto; text-align: center; z-index: 5; }

.map { position: absolute; inset: 0; }
.maplibregl-ctrl-group { background: var(--glass) !important; border: 1px solid var(--line); box-shadow: none !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) brightness(0.9); }
.maplibregl-ctrl-attrib { background: rgba(14, 19, 17, 0.7) !important; color: var(--muted); font-size: 11px; }
.maplibregl-ctrl-attrib a { color: var(--ink-2); }
.maplibregl-ctrl-attrib-button { filter: invert(1); }
.maplibregl-ctrl-top-right { top: 64px; }

/* Header */
.top { position: absolute; z-index: 10; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px 18px; padding: 12px var(--gutter); pointer-events: none; background: linear-gradient(rgba(15, 20, 18, 0.9), rgba(15, 20, 18, 0)); }
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 800; font-size: 22px; letter-spacing: -0.03em; }
.tagline { margin: 0; color: var(--ink-2); font-size: 14px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; gap: 8px; margin-left: auto; }
.tool { display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap; }
.tool svg { width: 18px; height: 18px; flex: none; }
.tool.icon { padding: 0; width: 40px; justify-content: center; }
.tool:hover { border-color: var(--ink-2); }
.tool.active { background: var(--ink); color: var(--ground); border-color: var(--ink); }
#filterLabel { max-width: 16ch; overflow: hidden; text-overflow: ellipsis; }

/* Legend */
.legend { position: absolute; z-index: 9; left: var(--gutter); top: 66px; display: flex; flex-direction: column; gap: 4px; }
.leg { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 4px 10px 4px 6px; border-radius: 999px; border: 1px solid transparent; background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); cursor: pointer; font-size: 13px; text-align: left; }
.leg:hover { border-color: var(--line-strong); }
.leg[aria-pressed="true"] { border-color: var(--ink); }
.legend.isolating .leg[aria-pressed="false"] { opacity: 0.55; }
.leg-name { font-weight: 600; }
.leg-pct { font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 4ch; }
/* Swatches carry a shape as well as a color, so states read without color. */
.sw { width: 18px; height: 18px; flex: none; border-radius: 50%; position: relative; }
.sw-bloom { background: conic-gradient(#ff8cc6 0 25%, #fbf6ef 0 50%, #b78cff 0 75%, #ffe05a 0); clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); border-radius: 0; }
.sw-budding { background: #c9e265; border-radius: 50% 0 50% 0; }
.sw-green { background: #237f43; }
.sw-fall { background: linear-gradient(135deg, #ffcf2e, #ff8a1f 50%, #ff7a66); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); border-radius: 0; }
.sw-bare { background: transparent; border: 2px solid #7a6a5e; }
.sw-evergreen { background: #1d6b5f; clip-path: polygon(50% 0, 95% 100%, 5% 100%); border-radius: 0; }

/* Toast */
.toast { position: absolute; z-index: 12; left: 50%; transform: translateX(-50%); bottom: calc(var(--dock-h) + var(--safe-b) + 12px); margin: 0; max-width: min(560px, calc(100% - 32px)); padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--ground); font-weight: 600; font-size: 14px; line-height: 1.4; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); }

/* Dock + scrubber */
.dock { position: absolute; z-index: 10; left: 0; right: 0; bottom: 0; padding: 14px var(--gutter) calc(10px + var(--safe-b)); background: linear-gradient(rgba(15, 20, 18, 0), rgba(15, 20, 18, 0.92) 26%); }
.date-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 4px 20px; margin-bottom: 8px; }
.date { margin: 0; font-weight: 800; font-size: clamp(34px, 6vw, 64px); letter-spacing: -0.045em; line-height: 0.9; font-variant-numeric: tabular-nums; min-width: 6.2ch; }
.typical { margin: 6px 0 0; font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.now-line { margin: 0 0 4px; flex: 1; min-width: 12ch; font-size: 16px; color: var(--ink-2); }
.date-actions { display: flex; gap: 6px; margin-bottom: 2px; }
.chip { min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--glass); cursor: pointer; font-size: 13px; font-weight: 600; }
.chip:hover { border-color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--ground); border-color: var(--ink); }
.chip .n { font-family: var(--mono); font-weight: 400; font-size: 11px; opacity: 0.7; margin-left: 4px; }

.scrubber { display: flex; align-items: flex-end; gap: 12px; }
.play { flex: none; width: 52px; height: 52px; border-radius: 50%; border: none; background: var(--ink); color: var(--ground); cursor: pointer; display: grid; place-items: center; margin-bottom: 18px; }
.play svg { width: 22px; height: 22px; }
.play .i-pause, .playing .play .i-play { display: none; }
.playing .play .i-pause { display: block; }
.track-wrap { flex: 1; min-width: 0; position: relative; }
.moments { position: relative; height: 66px; }
.moment { position: absolute; bottom: 0; transform: translateX(-50%); background: none; border: none; padding: 0 0 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; color: var(--ink-2); font-size: 12px; font-weight: 600; white-space: nowrap; }
.moment span { padding: 2px 7px; border-radius: 6px; }
.moment[hidden] { display: none; }
.moment::after { content: ""; width: 1px; height: 8px; background: var(--line-strong); }
.moment[data-lane="1"]::after { height: 26px; }
.moment[data-lane="2"]::after { height: 44px; }
.moment.here span, .moment:hover span { background: var(--ink); color: var(--ground); }
.track { position: relative; height: 46px; border-radius: 8px; overflow: visible; cursor: ew-resize; touch-action: none; }
.track canvas { display: block; width: 100%; height: 100%; border-radius: 8px; }
.track:focus-visible { outline-offset: 4px; }
.thumb { position: absolute; top: -6px; bottom: -6px; width: 0; pointer-events: none; }
.thumb::before { content: ""; position: absolute; left: -1.5px; top: 0; bottom: 0; width: 3px; border-radius: 2px; background: #fff; box-shadow: 0 0 0 1.5px rgba(15, 20, 18, 0.8); }
.thumb::after { content: ""; position: absolute; left: -9px; top: -6px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(15, 20, 18, 0.8); }
.track.dragging .thumb::after { transform: scale(1.25); }
.months { display: grid; grid-template-columns: repeat(12, 1fr); margin-top: 5px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.months span { padding-left: 3px; border-left: 1px solid var(--line); }
.credit { margin: 8px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--muted); }
.credit a { color: var(--ink-2); }
.linkish { background: none; border: none; padding: 0; color: var(--ink-2); text-decoration: underline; cursor: pointer; font-size: inherit; }

/* Tree card */
.card { position: absolute; z-index: 11; right: var(--gutter); top: 66px; width: 340px; max-height: calc(100% - var(--dock-h) - 90px); overflow: auto; padding: 18px 18px 16px; border-radius: 18px; background: var(--glass-solid); border: 1px solid var(--line); box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5); opacity: 0; transform: translateY(8px); transition: opacity 0.18s, transform 0.18s; }
.card.open { opacity: 1; transform: none; }
.close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 22px; line-height: 1; color: var(--ink-2); }
.card-state { margin: 0 40px 10px 0; display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.card-name { margin: 0; font-size: 30px; line-height: 1; letter-spacing: -0.035em; font-weight: 800; padding-right: 30px; }
.card-latin { margin: 4px 0 12px; font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--ink-2); }
.card-facts { display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 0 0 12px; }
.card-facts dt { font-family: var(--mono); font-size: 11px; text-transform: uppercase; color: var(--muted); }
.card-facts dd { margin: 2px 0 0; font-weight: 600; }
.card-story { margin: 0 0 10px; font-size: 17px; line-height: 1.35; }
.card-strip { display: block; width: 100%; height: 14px; border-radius: 4px; image-rendering: pixelated; }
.card-strip-months { display: grid; grid-template-columns: repeat(12, 1fr); font-family: var(--mono); font-size: 10px; color: var(--muted); margin: 3px 0 12px; }
.card-fact { margin: 0 0 6px; font-size: 14px; line-height: 1.4; color: var(--ink-2); }
.card-note { margin: 0 0 12px; font-size: 13px; line-height: 1.4; color: var(--muted); }
.card-note:empty { display: none; }
.pin { width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid #fff; box-shadow: 0 0 0 2px rgba(15, 20, 18, 0.7), 0 0 18px rgba(255, 255, 255, 0.35); pointer-events: none; }
.me { width: 16px; height: 16px; border-radius: 50%; background: #5cc8ff; border: 3px solid #fff; box-shadow: 0 0 0 8px rgba(92, 200, 255, 0.25); }

/* Panels */
.panel { position: absolute; z-index: 20; top: 64px; right: var(--gutter); width: min(420px, calc(100% - 2 * var(--gutter))); max-height: calc(100% - 80px); overflow: auto; padding: 18px; border-radius: 18px; background: var(--glass-solid); border: 1px solid var(--line); box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.03em; }
.panel .close { position: static; }
.groups { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.search input { width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--ground); color: var(--ink); font: inherit; font-size: 16px; }
.species-list { list-style: none; margin: 10px 0 0; padding: 0; }
.species-list button { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 0 10px; padding: 9px 4px; border: none; border-bottom: 1px solid var(--line); background: none; cursor: pointer; text-align: left; }
.species-list button:hover { background: rgba(255, 255, 255, 0.04); }
.sp-name { font-weight: 600; }
.sp-latin { grid-row: 2; font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 15px; }
.species-list .n { grid-row: 1 / 3; grid-column: 2; align-self: center; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.species-list .empty { padding: 12px 4px; color: var(--muted); }

.about { width: min(560px, calc(100% - 2 * var(--gutter))); }
.about-body { line-height: 1.5; color: var(--ink-2); }
.about-body .lede { font-size: 18px; color: var(--ink); margin-top: 0; }
.about-body h3 { margin: 22px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 12px; border-radius: 12px; border: 1px solid var(--line); }
.stat p { margin: 0; }
.stat .k { font-family: var(--mono); font-size: 11px; text-transform: uppercase; color: var(--muted); }
.stat .v { font-weight: 800; font-size: 19px; color: var(--ink); line-height: 1.15; margin: 4px 0; }
.stat .s { font-size: 13px; }
.sources, .coverage { padding-left: 18px; }
.coverage li, .sources li { margin-bottom: 6px; }
.fine { font-size: 12px; color: var(--muted); }

/* Loading */
.loading { position: absolute; z-index: 30; inset: 0; display: grid; place-items: center; background: var(--ground); transition: opacity 0.6s; pointer-events: none; }
.loading p { font-family: var(--mono); font-size: 13px; color: var(--ink-2); }
.loading.done { opacity: 0; }

/* Phones */
@media (max-width: 719px) {
  :root { --dock-h: 186px; }
  .tagline { display: none; }
  .tool span { display: none; }
  .tool { padding: 0; width: 40px; justify-content: center; }
  .tool.active span { display: inline; }
  .tool.active { width: auto; padding: 0 12px; }
  .legend { top: 60px; left: 0; right: 0; flex-direction: row; overflow-x: auto; padding: 0 var(--gutter) 4px; scrollbar-width: none; }
  .legend::-webkit-scrollbar { display: none; }
  .leg { flex: none; }
  .maplibregl-ctrl-top-right { top: 104px; }
  .maplibregl-ctrl-group:not(.maplibregl-ctrl-attrib) { display: none; }
  .date-row { gap: 2px 12px; }
  .now-line { font-size: 14px; flex-basis: 100%; order: 3; margin: 2px 0 0; }
  .date-actions { margin-left: auto; }
  .chip { min-height: 32px; padding: 0 10px; font-size: 12px; }
  .play { width: 46px; height: 46px; margin-bottom: 18px; }
  .card { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 62%; border-radius: 20px 20px 0 0; padding-bottom: calc(16px + var(--safe-b)); z-index: 15; }
  .panel { left: var(--gutter); right: var(--gutter); top: 60px; width: auto; }
  .stats { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .loading { transition: none; }
}
