/* Layout: fixed top bar, left rail (bottom sheet on phones), full-bleed map with floating place card and legend.
   Single light look on purpose: the data colours are tuned for a light ground. */
:root {
  --ink: #141a2b; --ink-2: #3a4256; --muted: #667085; --line: #e3e6ec; --line-2: #eef0f4;
  --paper: #ffffff; --rail: #f7f8fa; --accent: #c8432b; --accent-ink: #ffffff; --focus: #2457d6;
  --t-climate: #c8432b; --t-people: #d9822b; --t-city: #3d4a6b; --t-health: #a8326e; --t-ses: #8a5a2b; --t-ej: #800026;
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Public Sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --rail-w: 340px; --top-h: 60px; --r: 10px;
  --shadow: 0 1px 2px rgba(20, 26, 43, .06), 0 6px 20px rgba(20, 26, 43, .10);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font: 15px/1.45 var(--f-body); }
body { display: flex; flex-direction: column; overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); 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: -999px; top: 0; z-index: 3000; background: var(--paper); padding: 8px 12px; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.eyebrow { margin: 0; font-size: .7rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar { height: var(--top-h); flex: none; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--paper); border-bottom: 1px solid var(--line); z-index: 1100; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; min-width: 0; flex: none; }
.mark { width: 26px; height: 26px; fill: var(--accent); }
.mark circle { fill: var(--ink); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font: 700 1.08rem/1.1 var(--f-display); letter-spacing: -.01em; }
.brand-text small { font-size: .72rem; color: var(--muted); margin-top: 2px; }

.search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search input { width: 100%; height: 38px; padding: 0 12px 0 36px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--rail); transition: border-color .15s, background .15s; }
.search input:focus { background: var(--paper); border-color: var(--ink-2); outline: none; box-shadow: 0 0 0 3px rgba(36, 87, 214, .15); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search-icon { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%);
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
#search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); z-index: 1200; max-height: 60vh; overflow: auto; }
#search-results li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
#search-results li small { color: var(--muted); }
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--line-2); }
#search-results li.empty { color: var(--muted); cursor: default; }

.actions { display: flex; align-items: center; gap: 8px; flex: none; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper);
  font-weight: 700; color: var(--ink-2); display: inline-grid; place-items: center; line-height: 1; }
.icon-btn:hover { border-color: var(--ink-2); }
.icon-btn.sm { width: 28px; height: 28px; font-size: 1.1rem; font-weight: 400; }
.lang { display: flex; padding: 3px; border-radius: 999px; background: var(--line-2); }
.lang button { border: 0; background: none; padding: 4px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.panel { width: var(--rail-w); flex: none; background: var(--rail); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow-y: auto; z-index: 1000; }
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #e9edf1; }
.sheet-handle { display: none; }

.tabs { display: flex; gap: 4px; padding: 10px 16px 0; position: sticky; top: 0; background: var(--rail); z-index: 2; border-bottom: 1px solid var(--line); }
.tabs [role="tab"] { border: 0; background: none; padding: 8px 2px 10px; margin-right: 16px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.view { padding: 14px 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.view > .eyebrow { margin-top: 8px; }

/* base layer list */
.base-list { display: flex; flex-direction: column; gap: 2px; }
.theme-group { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.theme-group h3 { margin: 6px 0 2px; font-size: .74rem; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.theme-group h3::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--t-climate); }
.theme-group[data-theme="people"] h3::before { background: var(--t-people); }
.theme-group[data-theme="city"] h3::before { background: var(--t-city); }
.theme-group[data-theme="health"] h3::before { background: var(--t-health); }
.theme-group[data-theme="ses"] h3::before { background: var(--t-ses); }
.theme-group[data-theme="ej"] h3::before { background: var(--t-ej); }
.base-item { border-radius: 8px; }
.base-item.on { background: var(--paper); box-shadow: 0 0 0 1px var(--line); }
.base-row { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.base-row:hover { background: rgba(20, 26, 43, .04); }
.base-item.on .base-row:hover { background: none; }
.base-row input { position: absolute; opacity: 0; pointer-events: none; }
.base-row:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; }
.base-row.none { color: var(--muted); font-size: .88rem; }
.base-title { font-size: .9rem; font-weight: 500; line-height: 1.3; }
.base-item.on .base-title { font-weight: 650; }
.sw { display: inline-flex; flex: none; width: 34px; height: 10px; border-radius: 3px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.sw i { flex: 1; }
.base-desc { margin: 0 10px 8px 52px; font-size: .8rem; color: var(--muted); }
.pairs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 10px 10px 52px; }
.chip { border: 1px solid var(--line); background: var(--rail); border-radius: 999px; padding: 3px 10px; font-size: .76rem; color: var(--ink-2); }
.chip:hover { border-color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* overlays as switches */
.overlay-list { display: flex; flex-direction: column; gap: 2px; }
.switch-row { display: flex; align-items: flex-start; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.switch-row:hover { background: rgba(20, 26, 43, .04); }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row small { display: block; font-size: .78rem; color: var(--muted); margin-top: 2px; }
.switch { flex: none; width: 30px; height: 18px; border-radius: 999px; background: #cfd4dd; position: relative; transition: background .15s; margin-top: 1px; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch-row input:checked + .switch { background: var(--ink); }
.switch-row input:checked + .switch::after { transform: translateX(12px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--focus); outline-offset: 2px; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.seg { display: flex; padding: 3px; border-radius: 8px; background: var(--line-2); }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; font-size: .8rem; color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--paper); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.soon { margin: 8px 0 0; font-size: .78rem; color: var(--muted); line-height: 1.5; padding-top: 12px; border-top: 1px solid var(--line); }
.soon b { color: var(--ink-2); font-weight: 600; }

/* stories */
.story-card { display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: left; background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px 14px; margin-bottom: 8px; }
.story-card:hover { border-color: var(--ink-2); }
.story-card strong { font: 650 1rem/1.25 var(--f-display); }
.story-card small { color: var(--muted); }
#story h2 { margin: 2px 0 6px; font: 700 1.35rem/1.2 var(--f-display); letter-spacing: -.01em; text-wrap: balance; }
.prose { font-size: .93rem; line-height: 1.6; max-width: 65ch; }
.prose p { margin: 0 0 .8em; }
.prose blockquote { margin: 1em 0; padding: .2em 0 .2em 14px; border-left: 3px solid var(--accent); color: var(--ink-2); font-style: italic; }
.text-btn { align-self: flex-start; background: none; border: 0; padding: 0; color: var(--focus); font-size: .85rem; margin-bottom: 8px; }
.story-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; }
.count { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 7px 14px; font-weight: 600; font-size: .85rem; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.notice { margin: 0 16px 16px; padding: 10px 12px; background: #fff6e5; border: 1px solid #f0d49a; border-radius: 8px; font-size: .84rem; }

/* ---------- place card ---------- */
.place { position: absolute; top: 12px; left: 12px; z-index: 900; width: 300px; max-width: calc(100% - 70px);
  background: var(--paper); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px 14px; max-height: calc(100% - 24px); overflow: auto; }
.place header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.place h3 { margin: 2px 0 0; font: 700 1.15rem/1.2 var(--f-display); letter-spacing: -.01em; }
.place dl { margin: 0; display: flex; flex-direction: column; }
.pv { padding: 8px 0; border-top: 1px solid var(--line-2); display: grid; gap: 3px; }
.pv dt { font-size: .74rem; color: var(--muted); }
.pv.cur dt { color: var(--ink); font-weight: 600; }
.pv dd { margin: 0; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 10px; }
.pv dd small { grid-column: 1 / -1; font-size: .72rem; color: var(--muted); }
.pv-val { font-size: .92rem; font-variant-numeric: tabular-nums; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.pv-val b { font-weight: 700; font-size: 1rem; }
.pv-bar { height: 6px; background: var(--line-2); border-radius: 3px; overflow: hidden; }
.pv-bar i { display: block; height: 100%; border-radius: 3px; }
.pv-dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.pv-flag { width: 12px; height: 10px; border: 2px dashed; display: inline-block; }

/* ---------- legend ---------- */
.legend { background: var(--paper); padding: 10px 12px; border-radius: var(--r); box-shadow: var(--shadow);
  font-size: .78rem; width: 250px; max-height: 50vh; overflow: auto; color: var(--ink); }
.legend h4 { margin: 0 0 8px; font-size: .82rem; font-weight: 650; line-height: 1.3; }
.legend h4 small { font-weight: 400; color: var(--muted); }
.ramp { display: flex; height: 10px; border-radius: 3px; overflow: hidden; }
.ramp i { flex: 1; }
.ticks { display: flex; justify-content: space-around; font-size: .68rem; color: var(--ink-2); margin-top: 3px; font-variant-numeric: tabular-nums; }
.ticks span { flex: 1; text-align: center; }
.ticks span:first-child { margin-left: 10%; }
.ticks span:last-child { margin-right: 10%; }
.ends { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted); margin-top: 2px; }
.legend ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend li i { width: 14px; height: 10px; border-radius: 2px; flex: none; }
.legend i.dot { width: 10px; height: 10px; border-radius: 50%; }
.legend i.line { height: 0; border-top: 3px solid; border-radius: 0; }
.legend i.hatch-sw { background: repeating-linear-gradient(45deg, rgba(20,26,43,.55) 0 1.3px, transparent 1.3px 4px); box-shadow: inset 0 0 0 1px var(--line); }
.lg-extra { margin-top: 8px !important; }
.legend i.hatch { border: 2px dashed; background: none; }
.lg-ov { margin-top: 10px !important; padding-top: 8px !important; border-top: 1px solid var(--line-2); }
.lg-more { margin-top: 8px; }
.lg-more summary { cursor: pointer; color: var(--muted); font-size: .72rem; }
.lg-more p { margin: 6px 0 0; font-size: .72rem; line-height: 1.45; color: var(--ink-2); }
.lg-more .src { color: var(--muted); }

.leaflet-container { font-family: var(--f-body); }
.leaflet-control-zoom a { color: var(--ink) !important; }
.leaflet-bar { border: 0 !important; box-shadow: var(--shadow) !important; border-radius: 8px !important; overflow: hidden; }
.tip { font-size: .78rem; border-radius: 6px; }

dialog { max-width: 620px; width: calc(100% - 32px); border: 0; border-radius: 14px; padding: 22px 24px; box-shadow: var(--shadow); color: var(--ink); }
dialog h2 { margin-top: 0; font: 700 1.3rem/1.2 var(--f-display); }
dialog { max-height: calc(100dvh - 32px); }
dialog h2:focus { outline: none; }
.dialog-foot { position: sticky; bottom: -22px; margin: 16px -24px -22px; padding: 12px 24px 16px; background: inherit; display: flex; justify-content: flex-end; }
dialog::backdrop { background: rgba(20, 26, 43, .45); }
#sources { padding-left: 18px; font-size: .85rem; line-height: 1.5; }

.pt-pop .leaflet-popup-content-wrapper { border-radius: 14px; }
.pt-pop .leaflet-popup-content { margin: 12px 14px; font: 400 .8rem/1.4 var(--f-body, inherit); color: var(--ink); }
.pp strong { display: block; font-size: .92rem; }
.pp small { display: block; color: var(--muted); margin-bottom: 6px; }
.pp table { border-collapse: collapse; width: 100%; }
.pp th { text-align: left; font-weight: 400; color: var(--ink-2); padding: 3px 8px 3px 0; vertical-align: top; }
.pp td { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; padding: 3px 0; white-space: nowrap; }
.pp tr + tr th, .pp tr + tr td { border-top: 1px solid var(--line-2); }

/* ---------- phones: rail becomes a bottom sheet ---------- */
@media (max-width: 760px) {
  :root { --top-h: 56px; }
  .topbar { gap: 10px; padding: 0 max(12px, env(safe-area-inset-left, 0px)) 0 max(12px, env(safe-area-inset-right, 0px)); }
  .brand-text { display: none; }
  .search { max-width: none; }
  .layout { flex-direction: column; }
  .map-wrap { order: 1; flex: 1; }
  .panel { order: 2; width: auto; max-height: 46%; border-right: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: 0 -6px 18px rgba(20, 26, 43, .10); transition: max-height .25s ease;
    padding-bottom: env(safe-area-inset-bottom, 0px); }
  .panel.collapsed { max-height: 74px; overflow: hidden; }
  .sheet-handle { display: flex; justify-content: center; border: 0; background: none; padding: 8px 0 0; flex: none; }
  .grip { width: 40px; height: 4px; border-radius: 2px; background: #c6cbd4; }
  .tabs { padding-top: 4px; }
  .place { left: 8px; right: 8px; top: 8px; width: auto; max-width: none; max-height: 58%; padding: 10px 12px; }
  .legend { width: 176px; max-height: 30vh; font-size: .7rem; padding: 8px 10px; }
  .legend h4 { font-size: .74rem; margin-bottom: 6px; }
  .leaflet-control-attribution { font-size: 9px; }
  .leaflet-control-zoom { display: none; }
  /* compact legend: tap the title for words, notes and sources */
  .legend { width: 150px; cursor: pointer; }
  .legend h4 { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 4px; }
  .legend h4::after { content: "+"; color: var(--muted); font-weight: 400; }
  .legend.open h4::after { content: "−"; }
  .legend:not(.open) .ends, .legend:not(.open) .lg-extra, .legend:not(.open) .lg-more, .legend:not(.open) .lg-ov { display: none; }
  .legend.open { width: 200px; overflow: auto; }
  .legend .ticks span { font-size: .62rem; }
  dialog { padding: 18px 18px; width: calc(100% - 20px); max-height: calc(100dvh - 20px); }
  .dialog-foot { bottom: -18px; margin: 12px -18px -18px; padding: 10px 18px 14px; }
}
/* phones held sideways: rail on the left again */
@media (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  .brand-text { display: none; }
  .layout { flex-direction: row; }
  .map-wrap { order: 2; }
  .panel { order: 1; width: 260px; max-height: none; border-radius: 0; border-top: 0; }
  .panel.collapsed { max-height: none; }
  .sheet-handle { display: none; }
  .place { left: auto; right: 8px; top: 8px; width: 260px; max-height: calc(100% - 16px); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
