/* UK bird flu map. Colour roles are tokens; dark values are chosen, not flipped. */
:root {
  color-scheme: light;
  --page: #fafaf9;
  --surface: #ffffff;
  --sea: #f4f5f5;
  --land: #e6e6e3;
  --land-line: #cfcfcb;
  --ink: #191919;
  --ink-2: #5f5f5f;
  --line: #e2e2df;
  --chip: #f0f0ee;
  --chip-on: #191919;
  --chip-on-ink: #ffffff;
  --focus: #257de0;
  --wild: #257de0;     /* categorical slot 1: wild birds in timeline mode */
  --kept: #f47230;     /* categorical slot 2: kept birds in timeline mode */
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --risk: #191919;     /* risk lines and washes: neutral, so they never read as a month or a series */
  --shadow: 0 1px 2px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.08);
  /* Month ramp Jan -> Dec: one hue (blue), light -> dark, from the documented
     sequential ramp (steps 250 -> 700, interpolated to 12). */
  --m1: #84b9f3; --m2: #6faef1; --m3: #5aa1ee; --m4: #4495ed; --m5: #2f88e9; --m6: #257cde;
  --m7: #2371cf; --m8: #1d67c2; --m9: #195db4; --m10: #1452a4; --m11: #0f4892; --m12: #0e3d7e;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #131313; --surface: #1b1b1b; --sea: #111111; --land: #262626; --land-line: #3a3a3a;
    --ink: #efefef; --ink-2: #a3a3a3; --line: #303030; --chip: #262626; --chip-on: #efefef; --chip-on-ink: #131313;
    --focus: #338ced; --wild: #338ced; --kept: #e76624; --grid: #303030; --axis: #474747; --risk: #efefef;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 4px 16px rgba(0,0,0,.5);
    /* Dark: anchor flips - early months sit near the surface, recent months are brightest (steps 600 -> 100). */
    --m1: #1757ac; --m2: #1b63bc; --m3: #226eca; --m4: #2479db; --m5: #2e87e8; --m6: #4495ed;
    --m7: #5da3ef; --m8: #74b0f2; --m9: #8bbdf4; --m10: #a2caf7; --m11: #b8d6f8; --m12: #cce3fd;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #131313; --surface: #1b1b1b; --sea: #111111; --land: #262626; --land-line: #3a3a3a;
  --ink: #efefef; --ink-2: #a3a3a3; --line: #303030; --chip: #262626; --chip-on: #efefef; --chip-on-ink: #131313;
  --focus: #338ced; --wild: #338ced; --kept: #e76624; --grid: #303030; --axis: #474747; --risk: #efefef;
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 4px 16px rgba(0,0,0,.5);
  --m1: #1757ac; --m2: #1b63bc; --m3: #226eca; --m4: #2479db; --m5: #2e87e8; --m6: #4495ed;
  --m7: #5da3ef; --m8: #74b0f2; --m9: #8bbdf4; --m10: #a2caf7; --m11: #b8d6f8; --m12: #cce3fd;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 var(--font);
  color: var(--ink);
  background: var(--page);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--ink-2); font-weight: normal; }
[hidden] { display: none !important; }

/* header */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.top h1 { font-size: 17px; margin: 0; font-weight: 650; white-space: nowrap; }
.modes { display: flex; background: var(--chip); border-radius: 999px; padding: 3px; margin-left: auto; }
.mode {
  border: 0; background: transparent; padding: 5px 14px; border-radius: 999px; cursor: pointer; font-weight: 550;
  min-height: 32px;
}
.mode[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.hdr-link {
  display: inline-flex; align-items: center; min-height: 34px; padding: 4px 12px; border-radius: 999px; flex: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 550; white-space: nowrap;
}
.hdr-link:hover { background: var(--chip); }
.hdr-link .short, .h-short { display: none; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  width: 34px; height: 34px; cursor: pointer; font-weight: 650; flex: none; line-height: 1;
}

/* toolbar */
.toolbar { padding: 8px 16px 6px; background: var(--surface); border-bottom: 1px solid var(--line); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.toggle, .chip-btn, .chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px;
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--chip); cursor: pointer; user-select: none; white-space: nowrap;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle:has(input:checked) { border-color: var(--ink-2); background: var(--surface); }
.toggle:has(input:not(:checked)) { opacity: .55; }
.toggle:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.key-circle, .key-diamond { width: 12px; height: 12px; display: inline-block; background: var(--m9); }
.key-circle { border-radius: 50%; }
.key-diamond { transform: rotate(45deg) scale(.85); outline: 1.5px solid var(--ink); outline-offset: -1px; }
body.timeline .wild .key-circle { background: var(--wild); }
body.timeline .kept .key-diamond { background: var(--kept); }
.key-shade { width: 14px; height: 13px; border-radius: 3px; display: inline-block; border: 1px solid var(--line);
             background: linear-gradient(90deg, color-mix(in srgb, var(--risk) 5%, var(--land)), color-mix(in srgb, var(--risk) 55%, var(--land))); }
.key-ring-poultry { width: 14px; height: 14px; border-radius: 50%; border: 2px dashed var(--kept); display: inline-block; flex: none; }
.shade-ramp { display: inline-flex; align-items: flex-start; }
.shade-ramp span { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }
.shade-ramp i { width: 36px; height: 12px; display: block; border-block: 1px solid var(--line); }
.shade-ramp span:first-child i { border-left: 1px solid var(--line); border-radius: 3px 0 0 3px; }
.shade-ramp span:last-child i { border-right: 1px solid var(--line); border-radius: 0 3px 3px 0; }
.shade-ramp b { font-weight: normal; font-size: 10px; color: var(--ink-2); white-space: nowrap; }
.chip-btn[aria-expanded="true"] { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
#filter-count:not(:empty)::before { content: " · "; }
.period { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.period select, .dock select {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 5px 8px; min-height: 34px; color: var(--ink);
}
.filters { display: grid; gap: 8px; padding: 10px 0 4px; }
.filters fieldset { border: 0; margin: 0; padding: 0; }
.filters legend { font-size: 13px; font-weight: 600; margin-bottom: 4px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
.link-btn { border: 0; background: none; padding: 0; color: var(--focus); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; justify-self: start; }
.summary { margin: 6px 0 0; font-size: 13px; color: var(--ink-2); }
.summary strong { color: var(--ink); font-weight: 600; }

/* map */
.stage { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--sea); }
.leaflet-container { font: inherit; background: var(--sea); }
.leaflet-control-attribution { font-size: 11px; background: color-mix(in srgb, var(--surface) 85%, transparent) !important; color: var(--ink-2); }
.leaflet-control-attribution a { color: var(--ink-2); }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--chip); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 12px 14px; font-size: 14px; line-height: 1.4; }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink-2); }

.legend {
  position: absolute; left: 10px; bottom: 22px; z-index: 500;
  background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; box-shadow: var(--shadow); font-size: 12px; max-width: min(330px, calc(100% - 20px));
}
.legend .ramp { display: flex; gap: 2px; margin: 4px 0 2px; }
.legend .ramp button {
  width: 22px; height: 26px; border: 0; padding: 0; border-radius: 4px; cursor: pointer;
  display: flex; align-items: flex-end; justify-content: center; font-size: 10px; color: transparent;
}
.legend .ramp button[aria-pressed="false"] { opacity: .2; }
.legend .ramp-labels { display: flex; gap: 2px; color: var(--ink-2); }
.legend .ramp-labels span { width: 22px; text-align: center; font-size: 10px; }
.legend .keys { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; color: var(--ink-2); align-items: center; }
.legend .keys span { display: inline-flex; align-items: center; gap: 5px; }
.legend .note { color: var(--ink-2); margin-top: 4px; }
.legend .title { font-weight: 600; }
.legend .risk-key:not(:empty) { margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--line); }
.legend .risk-key .keys { margin-top: 4px; }
.legend a.more { color: var(--focus); }
.legend .risk-key .keys a.more { display: none; }

.list-panel {
  position: absolute; z-index: 600; inset: 8px 8px auto auto; width: min(420px, calc(100% - 16px)); max-height: calc(100% - 16px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); }
.list-head h2 { font-size: 15px; margin: 0; }
.list-body { overflow: auto; padding: 0 0 8px; }
.list-body table { border-collapse: collapse; width: 100%; font-size: 13px; }
.list-body th, .list-body td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list-body th { position: sticky; top: 0; background: var(--surface); font-weight: 600; }
.list-body td.num, .list-body th.num { text-align: right; font-variant-numeric: tabular-nums; }
.list-body h3 { font-size: 13px; margin: 12px 10px 4px; }
.list-body tr { cursor: pointer; }
.list-body tr:hover td { background: var(--chip); }

/* popups */
.pop h3 { font-size: 15px; margin: 0 0 2px; }
.pop .sub { color: var(--ink-2); font-size: 12px; margin-bottom: 8px; }
.pop .entry { border-top: 1px solid var(--line); padding: 6px 0; }
.pop .entry:first-of-type { border-top: 0; padding-top: 0; }
.pop .when { font-weight: 600; }
.pop .big { font-weight: 650; }
.pop ul { margin: 4px 0 0; padding-left: 16px; }
.pop li { margin: 1px 0; }
.pop .latin { color: var(--ink-2); font-style: italic; }
.pop dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 4px 0; }
.pop dt { color: var(--ink-2); }
.pop dd { margin: 0; }
.pop a { color: var(--focus); }
.pop details.note { margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.pop details.note summary { cursor: pointer; }
.pop details.note p { margin: 4px 0 0; }

/* timeline dock */
.dock { background: var(--surface); border-top: 1px solid var(--line); padding: 8px 16px 4px; }
.dock-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.play {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--ink); color: var(--surface); cursor: pointer; flex: none;
  display: grid; place-items: center;
}
.play svg { width: 22px; height: 22px; fill: currentColor; }
.frame-label { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.frame-label strong { font-size: 15px; }
.frame-label span { color: var(--ink-2); font-size: 13px; }
.small { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); font-size: 13px; }
#scrubber { width: 100%; margin: 8px 0 2px; accent-color: var(--ink); height: 28px; }
.chart { position: relative; height: 128px; touch-action: none; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart text { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.dock-note { margin: 2px 0 4px; font-size: 12px; color: var(--ink-2); min-height: 1em; }

.tip {
  position: fixed; z-index: 2000; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); max-width: 240px;
}
.tip .v { font-weight: 650; font-size: 13px; }
.tip .k { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 5px; }

/* footer */
.foot {
  display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center;
  padding: 6px 16px; padding-bottom: max(6px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--surface); font-size: 12px; color: var(--ink-2);
}

/* about dialog */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.dlg-head h2 { margin: 0; font-size: 17px; }
.dlg-body { padding: 4px 18px 18px; font-size: 14px; }
.dlg-body h3 { font-size: 14px; margin: 16px 0 4px; }
.dlg-body p, .dlg-body li { color: var(--ink); }
.dlg-body a { color: var(--focus); }
.dlg-body table { border-collapse: collapse; font-size: 13px; }
.dlg-body td, .dlg-body th { padding: 3px 10px 3px 0; text-align: left; }
.dlg-body td.num, .dlg-body th.num { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  body { font-size: 14px; }
  .top { padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top)); gap: 8px; }
  .top h1 { font-size: 15px; }
  .h-map { display: none; }
  .hdr-link { min-height: 30px; padding: 3px 10px; }
  .hdr-link .long { display: none; }
  .hdr-link .short { display: inline; }
  .mode { padding: 4px 11px; min-height: 30px; }
  .icon-btn { width: 30px; height: 30px; }
  .toolbar { padding: 6px 0 4px; }
  .toolbar .row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 0 12px; gap: 6px; }
  .toolbar .row::-webkit-scrollbar { display: none; }
  .toggle, .chip-btn { min-height: 32px; padding: 3px 10px; }
  .period .lbl { display: none; }
  .period select { min-height: 32px; padding: 3px 6px; }
  .filters, .summary { padding-left: 12px; padding-right: 12px; }
  .summary { font-size: 12px; margin-top: 4px; }
  .dock, .foot { padding-left: 12px; padding-right: 12px; }
  .foot { font-size: 11px; padding-top: 4px; }
  .stage { display: flex; flex-direction: column; }
  #map { position: relative; inset: auto; flex: 1; min-height: 0; }
  .legend { position: static; border-radius: 0; border-width: 1px 0 0; box-shadow: none; max-width: none;
            padding: 5px 12px; font-size: 11px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; background: var(--surface); }
  .legend .title { display: none; }
  .legend .ramp-wrap { display: flex; flex-direction: column; }
  .leaflet-control-zoom { display: none; }
  .wide { display: none; }
  .legend .ramp button { width: 15px; height: 13px; border-radius: 3px; }
  .legend .ramp-labels span { width: 15px; font-size: 9px; }
  .legend .note { display: none; }
  .legend .risk-key:not(:empty) { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px;
                                  margin-top: 1px; padding-top: 0; border-top: 0; }
  .legend .risk-key .keys { margin-top: 0; }
  .legend .risk-key .keys a.more { display: inline; }
  .shade-ramp i { width: 30px; height: 10px; }
  .shade-ramp b { font-size: 9px; }
  .legend .risk-key .note.risk-note { display: block; }
  .legend .keys { gap: 8px; margin-top: 0; }
  .chart { height: 92px; }
  .play { width: 40px; height: 40px; }
  .dock { padding-top: 6px; }
  .dock-row { flex-wrap: nowrap; gap: 8px; }
  .dock .lbl { display: none; }
  .dock select { padding: 3px 4px; min-height: 32px; }
  .frame-label strong, .frame-label span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .frame-label strong { font-size: 14px; }
  .frame-label span { font-size: 12px; }
  #scrubber { margin: 4px 0 0; }
  .dock-note { font-size: 11px; }
  body.timeline .summary { display: none; }
  .spacer { display: none; }
}
@media (max-width: 400px) {
  .top { gap: 6px; }
  .h-long { display: none; }
  .h-short { display: inline; }
  .mode { padding: 4px 9px; }
}
@media (forced-colors: active) {
  .chip[aria-pressed="true"], .chip-btn[aria-expanded="true"] { border: 2px solid CanvasText; }
}
