:root {
  --surface: #fcfcfb;
  --ink: #1f1d1a;
  --ink-2: #57534c;
  --ink-3: #6b665e;
  --rule: #e6e3dc;
  --wash: #f1eee8;
  --selected: #6f286c; /* a picked chart column, matching the map's highlight */
  --shadow: 0 1px 2px rgb(31 29 26 / 0.06), 0 8px 28px rgb(31 29 26 / 0.1);
  --serif: "Young Serif", Georgia, serif;
  --sans: "Public Sans", system-ui, sans-serif;
  --rail-w: 340px;
  --panel-h: 420px;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --paper: #fffefb;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.4 var(--sans); color: var(--ink); background: var(--surface); overflow: hidden; display: flex; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- rail ---------- */
.rail {
  width: var(--rail-w); flex: none; height: 100%; display: flex; flex-direction: column;
  border-right: 1px solid var(--rule); background: var(--surface); z-index: 3;
}
.rail-head { padding: 20px 20px 16px; display: flex; flex-direction: column; gap: 12px; }
.rail-head h1 { margin: 0; font: 400 30px/1 var(--serif); letter-spacing: -0.02em; }
.intro p { margin: 0; color: var(--ink-2); font-size: 13.5px; line-height: 1.45; text-wrap: pretty; }
.intro .rail-links { margin-top: 6px; }
.rail-body { flex: 1; overflow-y: auto; padding: 0 20px 24px; }

.search { position: relative; }
.search input {
  width: 100%; height: 44px; padding: 0 14px; border: 1px solid var(--rule); border-radius: 10px;
  font: 500 15px var(--sans); color: var(--ink); background: var(--surface); outline: none;
}
.search input:focus { border-color: var(--ink-2); }
#q-list {
  position: absolute; top: 48px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; box-shadow: var(--shadow);
}
#q-list li { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
#q-list li.active, #q-list li:hover { background: var(--wash); }
#q-list li span { color: var(--ink-3); }

/* ---------- tour ---------- */
/* One slot under the search field: the start link, or the open stop. It keeps its height while
   content/tour.json loads, so nothing below it jumps. */
.tour { min-height: 40px; }
.tour a { color: var(--ink); text-decoration: none; }
.tour-start, .tour-stop { background: var(--wash); border-radius: 10px; }
.tour-start { display: flex; align-items: center; justify-content: space-between; height: 40px; padding: 0 14px; font-weight: 600; }
/* One drawn chevron for the start link and both steps: a glyph sits low in the row. */
.tour-start::after, .tour-step::before {
  content: ""; width: 7px; height: 7px; border: solid currentColor; border-width: 2px 2px 0 0;
  transform: translateX(-1px) rotate(45deg);
}
.tour-start::after { color: var(--ink-3); }
.tour-step.back::before { transform: translateX(1px) rotate(-135deg); }
.tour-start:hover { background: var(--rule); }
.tour-stop { padding: 0 2px 12px 14px; }
.tour-bar { display: flex; align-items: center; height: 40px; }
.tour-place { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tour-count { margin: 0 6px; color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.tour-step { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; }
.tour-step[href]:hover { background: var(--rule); }
.tour-step:not([href]) { color: var(--ink-3); opacity: 0.4; }
.tour-line { margin: 0; padding-right: 12px; color: var(--ink-2); font-size: 13.5px; line-height: 1.45; text-wrap: pretty; }

.stat { padding: 6px 0 18px; border-bottom: 1px solid var(--rule); }
.stat-value { font: 700 44px/1 var(--sans); letter-spacing: -0.03em; }
.stat-label { margin-top: 6px; color: var(--ink-2); font-size: 13px; }

.rail-section { padding: 18px 0 6px; border-bottom: 1px solid var(--rule); }
.rail-section:last-of-type { border-bottom: 0; }
.rail-section h3 { margin: 0 0 10px; font: 600 13px var(--sans); color: var(--ink); }

.chart-wrap { position: relative; margin: 0; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: #efece6; stroke-width: 1; }
.chart .grid.base { stroke: var(--rule); }
.chart .tick { font: 500 11px var(--sans); fill: var(--ink-3); text-anchor: end; font-variant-numeric: tabular-nums; }
.chart .column { fill: var(--ink); }
.chart .col:hover .column, .chart .col:focus .column { fill: var(--ink-2); }
.chart .col.sel .column { fill: var(--selected); }
.chart .val { font: 600 11px var(--sans); fill: var(--ink); text-anchor: middle; }
.chart .cat { font: 500 11px var(--sans); fill: var(--ink-3); text-anchor: middle; }
.chart .col.sel .cat { fill: var(--ink); font-weight: 700; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .col { outline: none; }
.chart-tip {
  position: absolute; top: -6px; transform: translate(-50%, -100%); pointer-events: none; white-space: nowrap;
  padding: 6px 9px; background: var(--ink); color: var(--surface); border-radius: 7px; font-size: 12px;
  display: flex; flex-direction: column;
}
.chart-tip span { color: #cfcac0; }

.meters { display: flex; flex-direction: column; gap: 4px; padding-bottom: 10px; }
.meter {
  display: grid; grid-template-columns: 148px 1fr 52px; align-items: center; gap: 10px;
  padding: 4px 0; font: 500 13px/1.25 var(--sans); color: var(--ink);
}
.meter-track { height: 8px; border-radius: 4px; background: var(--wash); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 4px; background: var(--ink); }
.meter-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.rail-source { display: block; margin: 4px 0 12px; font-size: 11px; color: var(--ink-3); }

.rail-links { display: flex; gap: 16px; }
.rail-links a { color: var(--ink); font-weight: 600; text-decoration-color: var(--rule); text-underline-offset: 3px; }

/* ---------- stage (map + overlays) ---------- */
.stage { position: relative; flex: 1; height: 100%; min-width: 0; }
/* the map and the overlays that sit on it, so they move together when the page stacks */
.map-frame { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; }
.no-map .map-frame { display: none; }

/* One row on a wide map: modes | ramp + gray. Neighborhood measures, the kind filter and the
   3D height key add a second row only while they apply. */
.legend {
  position: absolute; z-index: 2; right: 16px; top: 16px; max-width: calc(100% - 120px);
  display: grid; grid-template-columns: auto auto; align-items: center; gap: 6px 16px; padding: 6px 14px 6px 6px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow);
}
.legend .seg { margin: 0; grid-column: 1; }
.legend .seg button { flex: 1 1 auto; padding: 6px 10px; }
.legend .height-key { grid-column: 2; grid-row: 2; margin: 0; }
.seg { display: flex; gap: 2px; padding: 2px; background: var(--wash); border-radius: 8px; margin-bottom: 8px; }
.seg button {
  flex: 1; border: 0; padding: 6px; border-radius: 6px; background: transparent;
  font: 500 12px var(--sans); color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }
.scale {
  display: grid; grid-template-columns: 240px 132px; align-items: center; column-gap: 12px;
  font-size: 11px; color: var(--ink-2); white-space: nowrap;
}
.scale-title { grid-column: 1 / -1; margin-bottom: 3px; font-weight: 600; color: var(--ink); }
.scale-ramp { grid-row: 2; display: grid; grid-template-columns: repeat(6, 1fr); height: 10px; border-radius: 2px; overflow: hidden; }
.scale-ticks { grid-row: 3; position: relative; height: 15px; font-variant-numeric: tabular-nums; }
.scale-ticks span { position: absolute; top: 2px; transform: translateX(-50%); line-height: 13px; }
.scale-ticks span::before { content: ""; position: absolute; left: 50%; top: -4px; height: 4px; border-left: 1px solid var(--ink-3); }
.scale-gray { grid-row: 2 / 4; grid-column: 2; display: inline-flex; align-items: center; gap: 6px; }
.scale-gray i { width: 10px; height: 10px; border-radius: 2px; }
.height-key { display: flex; align-items: flex-end; gap: 14px; margin-top: 8px; font-size: 11px; color: var(--ink-2); }
.height-tick { display: inline-flex; align-items: flex-end; gap: 4px; font-variant-numeric: tabular-nums; }
.height-tick i { width: 6px; border-radius: 1px 1px 0 0; background: var(--ink-2); }
/* a narrow map stacks the legend into one column */
@media (max-width: 1240px) {
  .legend { grid-template-columns: auto; }
  .legend .height-key { grid-column: 1; grid-row: auto; }
}

.map-tools { position: absolute; z-index: 2; left: 56px; top: 16px; right: 16px; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; pointer-events: none; }
.map-tools > * { pointer-events: auto; }
.tool {
  border: 1px solid var(--rule); background: var(--surface); border-radius: 10px; padding: 8px 12px;
  font: 600 13px var(--sans); color: var(--ink); cursor: pointer; box-shadow: var(--shadow);
}
.tool[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.map-tip {
  position: absolute; top: 0; left: 0; z-index: 4; pointer-events: none;
  padding: 7px 10px; background: var(--ink); color: var(--surface); border-radius: 8px;
  display: flex; flex-direction: column; gap: 1px; font-size: 12px; white-space: nowrap;
}
.map-tip strong { font-size: 14px; }
.map-tip strong span, .map-tip > span { color: #cfcac0; font-weight: 400; font-size: 12px; }

/* zoom buttons at the top left, the map tools beside them (no zoom buttons on phones) */
.maplibregl-ctrl-top-left { top: 16px; left: 16px; }
.maplibregl-ctrl-top-left .maplibregl-ctrl { margin: 0; }
.maplibregl-ctrl-group { border-radius: 10px !important; box-shadow: var(--shadow) !important; }

/* ---------- block panel ---------- */
.block {
  position: absolute; z-index: 3; left: 16px; right: 16px; bottom: 16px; height: var(--panel-h);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 16px; box-shadow: var(--shadow);
  animation: rise 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.block.has-focus { --panel-h: 484px; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .block { animation: none; } }
.block-head { display: flex; align-items: flex-start; gap: 20px; padding: 16px 20px 0; }
.block-head > div:first-child { flex: 1; }
.block-head h2 { margin: 0; font: 400 22px/1.1 var(--serif); letter-spacing: -0.01em; }
.block-head .range { margin: 4px 0 0; font-weight: 600; }
.block-head .range span { font-weight: 400; color: var(--ink-3); }
.block-head .view { margin: 2px 0 0; }
.close { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--ink-3); cursor: pointer; padding: 0 2px; }
.close:hover { color: var(--ink); }

.yours {
  display: flex; align-items: flex-end; gap: 28px; margin: 12px 20px 0; padding: 10px 14px;
  background: var(--wash); border-radius: 10px;
}
.yours-addr { flex: 1; font-weight: 600; }
.yours .fig { display: flex; flex-direction: column; }
.yours .fig span { font-size: 11.5px; color: var(--ink-2); }
.yours .fig strong { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }

/* Parcel card: a searched parcel on no block face, in the block panel's slot. */
.block[data-view="parcel"] { height: auto; padding-bottom: 16px; }
.parcel-figs { display: flex; flex-wrap: wrap; gap: 12px 28px; padding: 12px 20px 0; }
.parcel-figs .fig { display: flex; flex-direction: column; }
.parcel-figs .fig span { font-size: 11.5px; color: var(--ink-2); }
.parcel-figs .fig strong { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }

/* receipts on top, the row (or table) below */
.block-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.block-view { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* Receipts: the block's lowest and highest tax per sq ft, printed like till slips, the multiple between. */
.receipts { display: flex; align-items: center; gap: 18px; padding: 12px 20px 6px; }
.receipt { flex: 0 1 260px; min-width: 0; filter: drop-shadow(0 1px 1.5px rgb(31 29 26 / 0.18)) drop-shadow(0 0 0.5px rgb(31 29 26 / 0.2)); }
.receipt .paper {
  --tooth: 6px;
  padding: 9px 12px calc(10px + var(--tooth)); background: var(--paper);
  font: 400 11.5px/1.5 var(--mono); color: var(--ink-2); font-variant-numeric: tabular-nums;
  /* torn bottom edge */
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(2 * var(--tooth)) 100%;
}
.receipt h3 { margin: 0 0 4px; font: 600 11.5px/1.35 var(--mono); color: var(--ink); text-transform: uppercase; letter-spacing: 0.02em; }
.receipt .line { display: flex; justify-content: space-between; gap: 8px; }
.receipt .total {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--ink-3); color: var(--ink);
}
.receipt .total strong { font: 600 19px/1 var(--mono); letter-spacing: -0.02em; }
.times { flex: none; text-align: center; font: 700 34px/1 var(--sans); letter-spacing: -0.03em; color: var(--ink); }
.times span { display: block; margin-top: 4px; font: 500 12px var(--sans); letter-spacing: 0; color: var(--ink-2); }
.table-wrap { flex: 1; overflow: auto; padding: 8px 20px 12px; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap th, .table-wrap td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--rule); }
.table-wrap th:first-child { text-align: left; font-weight: 500; }
.table-wrap thead th { position: sticky; top: 0; background: var(--surface); font-weight: 500; color: var(--ink-2); }
.table-wrap td { font-variant-numeric: tabular-nums; }
.table-wrap tr.focus th, .table-wrap tr.focus td { font-weight: 700; }
.row-wrap { position: relative; flex: 1; overflow-x: auto; overflow-y: hidden; padding: 0 12px; }
/* the row's own key, only while the map legend shows another scale (main.js sets .needs-key) */
.row-key { display: none; padding: 4px 20px 0; }
.needs-key .row-key { display: block; }
.row-key .scale { justify-content: start; }
.row { display: block; }
.row .ground { stroke: var(--rule); stroke-width: 2; }
.row .grid { stroke: #efece6; stroke-width: 1; }
.row .tick { font: 500 11px var(--sans); fill: var(--ink-3); text-anchor: end; font-variant-numeric: tabular-nums; }
.row .base { fill: #cfcac0; }
/* a new buyer's tax: an empty box over the bar */
.row .ghost { fill: none; stroke: var(--ink-2); stroke-width: 1.25; stroke-dasharray: 3 2; }
.row .val { font: 600 12px var(--sans); fill: var(--ink); text-anchor: middle; font-variant-numeric: tabular-nums;
  paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.row .num { font: 500 11px var(--sans); fill: var(--ink-3); text-anchor: middle; font-variant-numeric: tabular-nums; }
.row .hit { fill: transparent; }
.row .house { outline: none; }
.row .house.focus .num { fill: var(--ink); font-weight: 700; }
.row .pin { fill: var(--ink); }
.row .house.on .bar { stroke: var(--ink); stroke-width: 1.5; }
.row .house.on .num { fill: var(--ink); }

.tip {
  position: absolute; top: 8px; z-index: 1; width: 200px; padding: 10px 12px; pointer-events: none;
  background: var(--ink); color: var(--surface); border-radius: 10px; font-size: 12px;
}
.tip-value { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.tip-value span { font-size: 12px; font-weight: 400; color: #b9b3a8; }
.tip-label { margin-top: 1px; color: #d8d3c9; }
.tip dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0 0; }
.tip dt { color: #b9b3a8; }
.tip dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- small screens: one scrolling column ---------- */
@media (max-width: 820px) {
  /* search, then the map, then the rail's charts; an open block goes above a shorter map */
  body { display: flex; flex-direction: column; overflow: auto; height: auto; }
  .rail { display: contents; }
  .rail-head { order: 0; }
  .stage { order: 1; }
  .rail-body { order: 2; }
  .rail-head { padding: 16px; }
  .rail-head h1 { font-size: 24px; }
  .tour { min-height: 44px; scroll-margin-top: 16px; }
  .tour-start, .tour-bar { height: 44px; }
  .tour-step { width: 44px; height: 44px; }
  .tour-stop { padding-right: 0; }
  .stage { height: auto; display: flex; flex-direction: column; }
  .map-frame { position: relative; inset: auto; height: 62vh; }
  .block-open .map-frame { order: 1; height: 34vh; }
  .rail-body { padding: 0 16px 32px; }
  .rail-links a { display: inline-flex; align-items: center; min-height: 40px; }
  .intro .rail-links { margin-top: 0; }
  .rail-section .seg button, .rail-source { min-height: 40px; }
  .rail-source { display: flex; align-items: center; margin: 0 0 4px; }
  .legend { top: auto; bottom: 12px; right: 12px; left: 12px; max-width: none; padding: 4px 10px 4px 4px; gap: 4px; }
  .legend .seg button { min-height: 40px; padding: 4px 6px; }
  .legend .scale, .row-key .scale { grid-template-columns: minmax(0, 1fr) auto; }
  .legend .scale { padding-left: 6px; }
  .map-tools { left: 12px; top: 12px; right: 12px; }
  #q-list li { display: flex; align-items: center; min-height: 40px; }
  .map-tools .tool { min-height: 40px; min-width: 40px; }
  /* the legend spans the map's bottom, so the attribution (i) sits at the top right */
  .maplibregl-ctrl-bottom-right { top: 0; bottom: auto; }
  /* The panel's parts join the stage's column: header and receipts (or the searched house) above
     the map (.map-frame, order 1), the row or table below it. */
  .block, .block-body { display: contents; }
  .block-view { order: 2; height: 240px; flex: none; margin-bottom: 8px; }
  .has-focus .receipts { display: none; }
  /* the multiple above, the two receipts side by side */
  .receipts { flex-wrap: wrap; gap: 8px 10px; padding: 12px 16px 14px; }
  .receipt { flex: 1 1 0; }
  .times { flex-basis: 100%; order: -1; text-align: left; font-size: 24px; }
  .times span { display: inline; margin-left: 6px; }
  .receipt .total { flex-direction: column; align-items: flex-start; gap: 2px; }
  .block-head { flex-wrap: wrap; align-items: center; gap: 8px 16px; position: relative; padding: 14px 16px 0; }
  .block-head > div:first-child { flex: 1 1 100%; padding-right: 40px; }
  .block-head h2 { font-size: 20px; }
  .block-head .close { position: absolute; top: 6px; right: 6px; width: 40px; height: 40px; }
  .block-head .view button { min-height: 40px; min-width: 48px; }
  .block[data-view="parcel"] .parcel-figs { padding-bottom: 14px; }
  .yours { flex-wrap: wrap; gap: 14px; margin: 12px 16px; }
  .yours-addr { flex-basis: 100%; }
}
