:root {
  --ink: #1c2340;
  --muted: #5d6385;
  --line: #ddd8cb;
  --card: rgba(243, 240, 233, 0.97); /* paper-map cream */
  --accent: #1f35c8;                 /* paper-map blue */
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 "Overpass", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #e9edf1;
}
body { display: flex; flex-direction: column; }
#stage { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; }
a { color: var(--accent); }

/* ---------- control panel ---------- */
#panel {
  position: absolute; top: 16px; left: 16px; z-index: 2;
  width: 320px; max-height: calc(100% - 32px); overflow-y: auto;
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0, 0, 0, .18);
  --pad-x: 16px; --pad-y: 14px;
  padding: var(--pad-y) var(--pad-x);
}
#panel header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#panel h1 { font-size: 17px; margin: 0; color: var(--accent); }
#panel section { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
#panel header + #panel-body section:first-child { border-top: 0; padding-top: 0; margin-top: 10px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
#panel.collapsed #panel-body { display: none; }

button { font: inherit; cursor: pointer; }
.titles { min-width: 0; }
.titles .sub { margin: 2px 0 0 24px; font-size: 12px; line-height: 1.3; color: var(--muted); }
#panel.collapsed .titles .sub { display: none; }
.brand-mark { display: inline-flex; vertical-align: -1px; margin-right: 8px; color: var(--accent); }
.brand-mark:hover { opacity: .65; }
/* Overpass sits high in its line box, so the mark is nudged up to match the text's optical center. */
.brand-mark .mark { width: 16px; height: 16px; display: block; transform: translateY(-1.5px); }
#panel h1 { display: flex; align-items: center; }
.icon-btn { border: 0; background: transparent; padding: 4px 6px; color: var(--muted); border-radius: 6px; display: grid; place-items: center; }
.icon-btn svg { display: block; transition: transform .15s; }
.icon-btn[aria-expanded="false"] svg { transform: rotate(-90deg); }
.icon-btn:hover { background: #e6e2d6; }
button.primary {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--accent);
  background: transparent; color: var(--accent); font-weight: 600;
}
button.primary[aria-pressed="true"] { background: var(--accent); color: #fff; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }

/* ---------- legend ---------- */
#legend { list-style: none; margin: 0; padding: 0; }
#legend li { margin: 0; }
#legend label {
  display: grid; grid-template-columns: 40px 1fr 14px; align-items: center; gap: 10px;
  padding: 6px 6px; border-radius: 8px; cursor: pointer;
}
#legend label:hover { background: #e9e5d9; }

/* Quiet checkbox on the right edge of the row; the dimmed row carries the on/off state. */
#legend input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; margin: 0;
  grid-column: 3; grid-row: 1; justify-self: end;
  width: 14px; height: 14px; border-radius: 4px;
  border: 1.5px solid rgba(31, 53, 200, .35); background: transparent;
  display: grid; place-content: center; cursor: pointer;
  transition: background-color .12s, border-color .12s;
}
#legend input[type="checkbox"]::after {
  content: ""; width: 10px; height: 10px; margin: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5 6.5 12 13 4.75' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='butt' stroke-linejoin='miter'/%3E%3C/svg%3E") center / contain no-repeat;
  transform: scale(0); transition: transform .12s;
}
#legend label:hover input[type="checkbox"] { border-color: rgba(31, 53, 200, .7); }
#legend input[type="checkbox"]:checked { background: rgba(31, 53, 200, .6); border-color: transparent; }
#legend input[type="checkbox"]:checked::after { transform: scale(1); }
#legend input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Symbols are drawn at 56x16 and shown at 40px wide. */
#legend svg { display: block; grid-column: 1; grid-row: 1; width: 40px; height: auto; overflow: visible; }
#legend .name { grid-column: 2; grid-row: 1; }
#legend svg, #legend .name { transition: opacity .12s; }
#legend label:has(input:not(:checked)) svg,
#legend label:has(input:not(:checked)) .name { opacity: .4; }
#legend li.zoomed-out svg,
#legend li.zoomed-out .name { opacity: .55; }
#legend li.zoomed-out label:has(input:not(:checked)) svg,
#legend li.zoomed-out label:has(input:not(:checked)) .name { opacity: .4; }
#legend .name { font-weight: 700; color: var(--accent); }
#legend .name small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }

/* Site footer: a darker band across the page below the map. Two columns, each with its two items stacked. */
#site-footer {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 4px 32px;
  padding: 10px 16px 11px; font-size: 12px; line-height: 1.5; color: var(--muted);
  background: #e4dfd0; border-top: 1px solid #d6d0be;
}
#site-footer .foot-left, #site-footer .foot-right { display: flex; flex-direction: column; gap: 1px; }
#site-footer .foot-right { text-align: right; }
#site-footer #freshness { color: var(--ink); }
/* Shorter wording on small screens. */
#site-footer .short { display: none; }
@media (max-width: 600px) {
  #site-footer { padding: 8px 12px 9px; gap: 4px 16px; font-size: 11.5px; }
  #site-footer .long { display: none; }
  #site-footer .short { display: inline; }
}

/* ---------- popups ---------- */
.mapboxgl-popup-content { padding: 10px 12px; border-radius: 10px; font: 13px/1.4 "Overpass", system-ui, sans-serif; color: var(--ink); max-width: 280px; }
.hover-popup { pointer-events: none; }

/* Close button: the same flat-ended stroke as the panel chevron, in place of the default "×". */
.mapboxgl-popup-close-button {
  top: 6px; right: 6px; width: 24px; height: 24px; padding: 0; border-radius: 6px;
  font-size: 0; line-height: 0; color: transparent;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5' fill='none' stroke='%235d6385' stroke-width='2.25' stroke-linecap='butt'/%3E%3C/svg%3E") center / 16px 16px no-repeat;
}
.mapboxgl-popup-close-button:hover { background-color: #e6e2d6; }
.mapboxgl-popup-close-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-title { font-weight: 700; font-size: 14px; margin: 0 0 4px; padding-right: 14px; }
.seg-badge { display: inline-block; padding: 2px 8px 0; border-radius: 999px; color: #fff; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.seg-desc { color: var(--muted); font-size: 12px; margin: 0 0 6px; }
.seg-rows { display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; margin: 0; }
.seg-rows dt { color: var(--muted); }
.seg-rows dd { margin: 0; }
.seg-links { margin: 8px 0 0; font-size: 12px; }

/* ---------- misc ---------- */
.notice {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 24px; background: #f4f6f8; z-index: 1;
}
.notice code { background: #e6e9ee; padding: 1px 5px; border-radius: 4px; }
.mapboxgl-ctrl-bottom-right, .mapboxgl-ctrl-bottom-left { z-index: 1; }

@media (max-width: 600px) {
  /* Leave the right-hand column free for the map controls (zoom, compass, locate). */
  #panel { top: 8px; left: 8px; right: 54px; width: auto; max-height: 55%; --pad-x: 12px; --pad-y: 10px; }
  #legend label { padding: 8px 4px; }
}
