:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  color: #263b31;
  background: #dfe8cd;
  --paper: #fbfaf3;
  --edge: #64705c;
  --line: #cbd1bf;
  --ink: #263b31;
  --muted: #536458;
  --deep: #244b39;
  --sunny: #f5c567;
  --gold-text: #69421a;
  --soft: #eff2e6;
}

* { box-sizing: border-box; }
body, h1, h2, h3, p { margin: 0; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
:where(button, input, a, summary):focus-visible { outline: 3px solid #305a98; outline-offset: 3px; }
a { color: var(--deep); }
button:disabled { cursor: default; opacity: .55; }
[hidden] { display: none !important; }

.map-app {
  position: relative;
  isolation: isolate;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  --gutter: clamp(12px, 2vw, 26px);
}
.scene, .map-light, .markers { position: absolute; inset: 0; }
.scene { isolation: isolate; overflow: hidden; background: linear-gradient(142deg, #e7ebd5, #c9d9b8); }
#map { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
.map-light {
  --haze: linear-gradient(#f3f0d995, #f3f0d911 21%, #fae6b400 84%, #f9e0a639);
  background-image: var(--haze);
  pointer-events: none;
}
.scene[data-light="dusk"] .map-light { background-image: linear-gradient(#ce8b5722, #ce8b5722), var(--haze); }
.scene[data-light="night"] .map-light { background-image: linear-gradient(#46567844, #46567844), var(--haze); }
.markers { pointer-events: none; }
.map-pin {
  display: grid;
  place-items: center;
  position: absolute;
  top: 0;
  left: 0;
  width: 27px;
  height: 27px;
  padding: 0;
  pointer-events: auto;
  border: 1px solid var(--ink);
  color: #25372c;
  background: var(--sunny);
  font-size: .75rem;
  line-height: 1;
  font-weight: 800;
}
.map-pin[data-shaded="true"] { background: #aec6a0; }
.map-pin:hover, .map-pin[aria-pressed="true"] {
  z-index: 2;
  width: 33px;
  height: 33px;
  background: var(--deep);
  color: var(--paper);
  border-color: var(--paper);
}
.load-message {
  position: absolute;
  top: 48%;
  left: 50%;
  max-width: calc(100% - 36px);
  transform: translate(-50%, -50%);
  padding: .7rem 1rem;
  border: 1px solid var(--edge);
  background: var(--paper);
  font-weight: 650;
  text-align: center;
}

.map-ui {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(276px, 24vw, 320px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: var(--gutter);
  padding-top: max(var(--gutter), env(safe-area-inset-top));
  padding-bottom: max(var(--gutter), env(safe-area-inset-bottom));
  pointer-events: none;
}
.panel {
  background: var(--paper);
  border: 1px solid var(--edge);
}
.map-header, .map-settings > *, .inspection, .time-panel { pointer-events: auto; }

.map-header {
  grid-area: 1 / 1;
  justify-self: start;
  width: min(295px, calc(100% - 126px));
  padding: 14px 15px 15px;
}
.header-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; }
.wordmark {
  color: var(--deep);
  font-size: .94rem;
  font-weight: 790;
  letter-spacing: -.04em;
  text-decoration: none;
}
.text-button { padding: .24rem .06rem .24rem .4rem; border: 0; background: transparent; color: var(--muted); font-size: .85rem; font-weight: 650; }
.text-button span { margin-left: .1rem; }
.text-button:hover { color: var(--deep); }
h1 { margin: .38rem 0 .7rem; font-family: Georgia, serif; font-size: clamp(1.85rem, 3vw, 2.4rem); font-weight: 500; letter-spacing: -.055em; line-height: 1.02; }
.neighborhoods, .rank-mode {
  display: flex;
  border: 1px solid var(--line);
}
.neighborhoods button, .rank-mode button {
  flex: 1;
  padding: .48rem .38rem;
  border: 0;
  color: var(--deep);
  background: transparent;
  font-size: .85rem;
  font-weight: 690;
  white-space: nowrap;
}
.neighborhoods button + button, .rank-mode button + button { border-left: 1px solid var(--line); }
.neighborhoods button:hover, .rank-mode button:hover { background: var(--soft); }
.neighborhoods button[aria-pressed="true"] { background: var(--deep); color: #fffdf4; }
.rank-mode button { border-bottom: 2px solid transparent; }
.rank-mode button[aria-pressed="true"] { border-bottom-color: var(--deep); background: var(--soft); }

.map-focus { grid-area: 2 / 1; min-height: 0; }
.map-settings {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  align-self: start;
  justify-self: end;
  gap: 7px;
}
.map-layer { min-height: 38px; padding: .3rem .72rem; font-size: .86rem; font-weight: 720; }
.map-layer:hover, .map-layer[aria-pressed="true"] { background: var(--deep); color: var(--paper); }
.map-tools { display: grid; }
.map-tools button { width: 38px; height: 36px; border: 0; background: transparent; font-size: 1.2rem; line-height: 1; }
.map-tools button + button { border-top: 1px solid var(--line); }
.map-tools button:hover { background: #e9efdc; }
.map-tools button:focus-visible { outline-offset: -4px; }

.map-bottom { grid-area: 3 / 1; width: min(510px, 100%); min-width: 0; justify-self: center; }
.legends { display: flex; gap: 6px; align-items: end; justify-content: space-between; margin-bottom: 7px; }
.map-key, .sun-angle { display: flex; align-items: center; gap: .65rem; padding: .42rem .55rem; font-size: .8rem; font-weight: 650; }
.map-key span { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.heat-key { display: grid; gap: 4px; }
.heat-key > span { justify-content: space-between; font-size: .75rem; }
.heat-scale { height: 8px; width: 118px; background: linear-gradient(90deg,#7bbab5,#dcd38d,#eea857,#d06b47,#9c424b); }
.swatch { width: .63rem; height: .63rem; border: 1px solid var(--edge); }
.swatch.sunny { background: var(--sunny); }
.swatch.shaded { background: #aec6a0; }
.sun-angle { gap: 5px; white-space: nowrap; }
.sun-angle::before { content: "☀"; color: #885819; }
.time-panel { padding: 11px 14px 10px; }
.time-line { display: flex; align-items: center; gap: 9px; }
.play { flex: 0 0 40px; width: 40px; height: 40px; border: 0; background: var(--deep); color: #ffdf96; font-size: .9rem; }
.play:hover { background: #3d654d; }
.time-line label { display: block; margin-bottom: 2px; color: var(--muted); font-size: .79rem; font-weight: 690; white-space: nowrap; }
.time-line output { display: block; font-size: 1.27rem; line-height: 1.04; font-weight: 760; font-variant-numeric: tabular-nums; white-space: nowrap; }
.date-control { margin-left: auto; }
.date-control input { max-width: 100%; padding: .24rem .4rem; border: 1px solid var(--line); color: var(--ink); background: var(--paper); font-size: .88rem; }
#time { display: block; width: 100%; height: 22px; margin: 6px 0 0; appearance: none; background: transparent; cursor: ew-resize; }
#time::-webkit-slider-runnable-track { height: 3px; background: var(--line); }
#time::-webkit-slider-thumb { appearance: none; width: 12px; height: 16px; margin-top: -6.5px; border: 0; background: var(--deep); }
#time::-moz-range-track { height: 3px; background: var(--line); }
#time::-moz-range-thumb { width: 12px; height: 16px; border: 0; border-radius: 0; background: var(--deep); }
.ticks { position: relative; min-height: 1.1rem; color: var(--muted); font-size: .74rem; font-weight: 650; }
.ticks span { position: absolute; }
.ticks span:nth-child(2) { left: 43%; transform: translateX(-50%); }
.ticks span:nth-child(3) { left: 64%; transform: translateX(-50%); }
.ticks span:nth-child(4) { left: 86%; transform: translateX(-50%); }
.ticks span:last-child { right: 0; }

.inspection-dock { grid-area: 1 / 2 / -1; min-width: 0; min-height: 0; }
.inspection { max-height: 100%; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.inspection summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 46px;
  padding: 0 15px;
  color: var(--deep);
  font-size: .9rem;
  font-weight: 750;
  list-style: none;
  cursor: pointer;
}
.inspection summary::-webkit-details-marker { display: none; }
.inspection summary:focus-visible { outline-offset: -4px; }
.inspection summary::after { content: ""; width: 7px; height: 7px; margin: -3px 1px 0 auto; transform: rotate(45deg); border-bottom: 2px solid currentColor; border-right: 2px solid currentColor; }
.inspection[open] summary::after { margin-top: 4px; transform: rotate(225deg); }
.stop-count { padding-left: .5rem; border-left: 1px solid var(--line); color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.stop-count:empty { display: none; }
.inspection-content { padding: 0 14px 14px; }
.stop-card, .ranks-card { padding: 13px 0 0; border-top: 1px solid var(--line); }
.ranks-card { margin-top: 13px; }
.stop-top { display: flex; justify-content: space-between; gap: 4px; align-items: center; }
.stop-id { color: var(--muted); font-size: .82rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.shelter-status { color: var(--muted); font-size: .79rem; font-weight: 550; white-space: nowrap; }
.shelter-status[data-review="true"] { color: var(--gold-text); }
.stop-card h2, .ranks-card h2 { font-size: 1.21rem; line-height: 1.15; font-weight: 670; letter-spacing: -.037em; }
.stop-card h2 { margin-top: .5rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; margin: .78rem 0 .72rem; border-block: 1px solid var(--line); }
.stats > div { min-width: 0; display: grid; align-content: start; gap: 4px; padding: 9px 9px 9px 0; }
.stats > div + div { padding-left: 10px; border-left: 1px solid var(--line); }
.stats strong { font-size: 1.53rem; letter-spacing: -.05em; line-height: 1; font-weight: 710; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: .76rem; font-weight: 650; line-height: 1.26; }
.chart { display: grid; grid-template-columns: repeat(15, minmax(0, 1fr)); gap: 3px; height: 39px; border-bottom: 1px solid #cfd9c5; }
.chart button { position: relative; padding: 0; border: 0; background: transparent; }
.chart button::before { content: ""; position: absolute; inset: auto 0 0; height: var(--bar); background: #819979; }
.chart button[aria-pressed="true"]::before { background: #c28133; }
.chart button:hover::before { background: #548461; }
.chart button:focus-visible { outline-offset: 0; }
.chart-ticks { display: flex; justify-content: space-between; padding-top: 3px; color: var(--muted); font-size: .72rem; }
.stop-note { margin-top: .62rem; color: var(--muted); font-size: .83rem; line-height: 1.38; }
.rank-period { margin-top: .22rem; color: var(--muted); font-size: .81rem; }
.rank-mode { margin-top: .6rem; }
.rank-mode button { font-size: .79rem; }
.rank-list { list-style: none; max-height: 190px; margin: .45rem -3px 0; padding: 0 3px; overflow: auto; scrollbar-width: thin; scrollbar-color: #b3bca7 transparent; }
.rank-list li + li { border-top: 1px solid #e7eadf; }
.rank-list button { display: grid; grid-template-columns: 1.5rem 1fr auto; gap: .4rem; align-items: center; width: 100%; padding: .43rem .3rem; border: 0; border-left: 2px solid transparent; background: transparent; text-align: left; }
.rank-list button:hover, .rank-list button[aria-pressed="true"] { background: var(--soft); }
.rank-list button[aria-pressed="true"] { border-left-color: var(--deep); }
.rank-list button:focus-visible { outline-offset: -2px; }
.rank-number { color: var(--muted); text-align: center; font-weight: 730; font-size: .77rem; }
.rank-name { font-size: .85rem; font-weight: 710; }
.rank-detail { display: block; margin-top: .12rem; color: var(--muted); font-size: .73rem; }
.rank-count { font-variant-numeric: tabular-nums; font-size: .9rem; font-weight: 750; }

dialog { max-width: min(36rem, calc(100vw - 32px)); max-height: 85dvh; padding: 19px; border: 1px solid var(--edge); color: var(--ink); background: var(--paper); }
dialog::backdrop { background: #182f25a8; }
.dialog-header { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.dialog-header h2 { font-weight: 600; }
.dialog-header button { width: 36px; height: 36px; border: 1px solid var(--line); background: var(--paper); font-size: 1.35rem; }
dialog p { margin-top: .85rem; line-height: 1.48; }
dialog h3 { margin-top: .9rem; font-size: .95rem; }
dialog ul { padding-left: 1.2em; font-size: .94rem; line-height: 1.49; }

@media (min-width: 721px) {
  .map-ui:has(.inspection:not([open])) .map-focus,
  .map-ui:has(.inspection:not([open])) .map-bottom { grid-column-end: -1; }
}
@media (max-width: 720px) {
  .map-ui { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) 43px auto; gap: 7px; }
  .map-header { width: min(282px, 100%); padding: 9px 11px 10px; }
  h1 { margin: .25rem 0 .48rem; }
  .map-focus { margin-top: 36px; }
  .map-settings { grid-area: 2 / 1; flex-direction: row; align-items: start; gap: 5px; }
  .map-tools { display: flex; }
  .map-tools button, .map-layer { min-height: 34px; height: 34px; }
  .map-tools button { width: 35px; }
  .map-tools button + button { border-top: 0; border-left: 1px solid var(--line); }
  .inspection-dock { position: relative; grid-area: 3 / 1; width: min(510px, 100%); justify-self: center; }
  .inspection { position: absolute; inset: auto 0 0; max-height: min(60dvh, calc(100dvh - 180px)); }
  .inspection summary { min-height: 41px; }
  .map-bottom { grid-area: 4 / 1; }
  .time-panel { padding: 9px 10px 7px; }
  .legends { margin-bottom: 5px; }
}
@media (max-width: 410px) {
  .map-key, .sun-angle { gap: .39rem; font-size: .73rem; }
  .ticks span:nth-child(4) { display: none; }
}
@media (max-height: 510px) and (min-width: 540px) and (max-width: 720px) {
  .map-ui {
    grid-template-columns: minmax(0, 1fr) minmax(257px, 39%);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }
  .map-header { width: min(255px, 100%); }
  .map-focus { grid-area: 2 / 1 / -1; margin-top: 0; }
  .map-settings { grid-area: 1 / 2; }
  .inspection-dock { grid-area: 2 / 2; align-self: end; min-height: 43px; width: 100%; }
  .map-bottom { grid-area: 3 / 2; }
  .inspection { max-height: calc(100dvh - 165px); }
  .time-line { gap: 6px; }
  .time-line label { font-size: .72rem; }
  .time-line output { font-size: 1.12rem; }
  .play { width: 34px; height: 34px; flex-basis: 34px; }
  .date-control input { width: 7.2rem; font-size: .8rem; }
  .map-key, .sun-angle { gap: .35rem; padding: .35rem .4rem; font-size: .69rem; }
  .ticks span:nth-child(4) { display: none; }
}
