:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16181d;
  --ink-2: #5a616e;
  --ink-3: #8b93a1;
  --line: #e2e5ea;
  --line-2: #cfd4dc;
  --condo: #4f46e5;
  --hdb: #ea580c;
  --near: #0f766e;
  --accent: #1d4ed8;
  --accent-soft: #eaf0ff;
  --warn-bg: #fff8e6;
  --warn-line: #f0dca8;
  --radius: 8px;
  /* Leaflet's own panes run to 700 and its controls to 1000, so anything that has
     to cover the map starts above that. */
  --z-sticky: 2;
  --z-scrim: 1200;
  --z-sheet: 1210;
  --z-modal: 2000;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

/* Mobile browser chrome makes 100vh taller than the part you can actually see,
   which pushes the results bar off the bottom of the screen. */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------------------------------------------------------------- header */

header {
  flex: none;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

header .meta {
  color: var(--ink-3);
  font-size: 12px;
}

header .spacer { flex: 1; }

button.link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  text-decoration: underline;
}

#caveat {
  flex: none;
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-line);
  padding: 9px 16px 10px;
  font-size: 12.5px;
  color: #6b5a1e;
  line-height: 1.5;
  max-height: 40vh;
  overflow-y: auto;
}

#caveat ul {
  margin: 0;
  padding-left: 17px;
  display: grid;
  gap: 4px;
}

#caveat b { color: #52461a; }

#caveat[hidden] { display: none; }

/* ---------------------------------------------------------------- layout */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: 1fr;
}

#filters {
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 14px;
  min-height: 0;
}

/* Grid and flex items default to min-height:auto, which lets a long table push the
   whole page taller than the viewport instead of scrolling inside its own pane.
   Every ancestor of the scroll container has to opt out of that. */
#right {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(220px, 1fr) minmax(180px, 45%);
}

#map {
  min-height: 0;
  background: #dfe3e8;
}

#results {
  min-height: 0;
  border-top: 1px solid var(--line-2);
  background: var(--panel);
  display: flex;
  flex-direction: column;
}

/* Collapsed, the results keep only their bar, which doubles as the handle to
   bring them back, and the map grows into the space. */
#right.list-collapsed { grid-template-rows: 1fr auto; }

#right.list-collapsed #table-wrap,
#right.list-collapsed #empty { display: none; }

#toggle-list {
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 5px;
  padding: 3px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink-2);
  flex: none;
}

#toggle-list:hover { background: var(--bg); }

#toggle-list::before {
  content: "▾";
  display: inline-block;
  margin-right: 5px;
  font-size: 10px;
  transition: transform 0.12s ease;
}

#right.list-collapsed #toggle-list::before { transform: rotate(180deg); }

/* ---------------------------------------------------------------- filters */

.group { margin-bottom: 18px; }

.group > h2 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

.chips { display: flex; flex-wrap: wrap; gap: 5px; }

.chip {
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink-2);
  user-select: none;
  white-space: nowrap;
}

.chip:hover { border-color: var(--ink-3); }

.chip.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 550;
}

.chip .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: 1px;
}

.rowbtns { display: flex; gap: 6px; margin-top: 7px; }

.rowbtns button {
  flex: 1;
  font-size: 11px;
  padding: 3px 0;
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 5px;
  cursor: pointer;
  color: var(--ink-2);
}

.rowbtns button:hover { background: var(--bg); }

label.field {
  display: block;
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 7px;
}

label.field span { display: block; margin-bottom: 3px; }

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  font: inherit;
  font-size: 12.5px;
  background: #fff;
  color: var(--ink);
}

input:focus, select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.pair { display: flex; gap: 7px; }

.pair label.field { flex: 1; }

label.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink-2);
  margin-bottom: 5px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- results */

#results-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-2);
}

#count b { color: var(--ink); }

#results-bar .spacer { flex: 1; }

#export {
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink-2);
}

#export:hover { background: var(--bg); }

#table-wrap { flex: 1; min-height: 0; overflow: auto; }

/* Fixed layout is what makes a long table cheap: the browser takes column widths
   from the colgroup instead of measuring every row, so showing 1,800 rows no longer
   costs a second of layout. It also stops columns jumping as filters change. */
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
  table-layout: fixed;
}

tbody td.name { overflow: hidden; text-overflow: ellipsis; }

thead th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--panel);
  border-bottom: 1px solid var(--line-2);
  text-align: left;
  padding: 6px 9px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  cursor: pointer;
  white-space: nowrap;
}

thead th:hover { color: var(--ink); }

thead th .arrow { color: var(--accent); }

tbody td {
  border-bottom: 1px solid var(--line);
  padding: 5px 9px;
  vertical-align: top;
}

tbody tr { cursor: pointer; }

tbody tr:hover { background: #f2f5fb; }

tbody tr.selected { background: var(--accent-soft); }

td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

td.name { font-weight: 550; }

td.name small { display: block; font-weight: 400; color: var(--ink-3); }

.tag {
  display: inline-block;
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tag.condo { background: #eeecfd; color: var(--condo); }
.tag.hdb { background: #fdeee3; color: var(--hdb); }
.tag.z1 { background: #dff2ef; color: var(--near); }
.tag.z2 { background: #f2f0e6; color: #857849; }

.muted { color: var(--ink-3); }

#empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}

/* ---------------------------------------------------------------- map bits */

.school-label {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.legend {
  background: rgba(255, 255, 255, 0.94);
  padding: 7px 9px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  font-size: 11.5px;
  line-height: 1.7;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -1px;
}

.hint {
  margin: 6px 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-3);
}

/* ---------------------------------------------------------------- detail modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(16, 18, 23, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal-card {
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  width: min(680px, 100%);
  max-height: min(660px, 92vh);
  padding: 18px 20px 14px;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 5px;
}

.modal-close:hover { background: var(--bg); color: var(--ink); }

.modal-card h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  padding-right: 32px;
}

.modal-card #detail-sub {
  margin: 3px 0 12px;
  font-size: 12.5px;
  color: var(--ink-3);
}

#detail-facts {
  margin: 0 0 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px 16px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

#detail-facts div { min-width: 0; }

#detail-facts dt {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  margin-bottom: 2px;
}

#detail-facts dd {
  margin: 0;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

#detail-facts dd small { color: var(--ink-3); font-size: 11.5px; font-weight: 400; }

/* The one outbound link in the panel, and a secondary action: it answers a
   different question from the figures around it. */
#detail-facts .route {
  display: inline-block;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  line-height: 1.3;
}

#detail-facts .route:hover { color: #16309c; }

/* A touch tablet in landscape is past the mobile breakpoint but still has no
   cursor, so it needs the same target the phone rule gives. */
@media (hover: none) and (pointer: coarse) {
  #detail-facts .route {
    display: block;
    width: fit-content;
    margin-top: 4px;
    padding: 8px 0;
    font-size: 12.5px;
  }
}

.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex: none; }

.tabs button {
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 6px;
  padding: 5px 12px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
}

.tabs button:hover:not(:disabled) { border-color: var(--ink-3); }

.tabs button[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.tabs button:disabled { opacity: 0.45; cursor: default; }

#detail-body { flex: 1; min-height: 0; overflow: auto; }

#detail-body table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

#detail-body th {
  position: sticky;
  top: 0;
  background: var(--panel);
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  font-weight: 600;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line-2);
}

#detail-body td { padding: 5px 8px; border-bottom: 1px solid var(--line); }

#detail-body .none { padding: 22px 8px; text-align: center; color: var(--ink-3); }

.pager {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 10px;
  font-size: 12px;
  color: var(--ink-3);
}

.pager button {
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 5px;
  padding: 3px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink-2);
}

.pager button:disabled { opacity: 0.4; cursor: default; }

.pager .spacer { flex: 1; }

/* ------------------------------------------------------------- peek card

   The card over a marker: hover with a mouse, first tap on a touch screen. It
   has to sit on a phone map without swamping it, so the head is allowed to wrap
   and only the figures are held on one line. */

.leaflet-tooltip.prop-tip {
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(16, 18, 23, 0.18);
  padding: 8px 10px 7px;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  white-space: normal;
  width: max-content;
  max-width: min(21rem, 88vw);
  /* Leaflet positions tooltips with a transform of its own, so opacity is the
     only thing here that is ours to animate. */
  animation: tip-in 0.15s var(--ease-out) both;
}

@keyframes tip-in { from { opacity: 0; } to { opacity: 1; } }

.leaflet-tooltip.prop-tip::before { border-top-color: var(--line-2); }

.prop-tip .tip-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.prop-tip .tip-name {
  font-weight: 650;
  font-size: 13px;
  letter-spacing: -0.005em;
}

.prop-tip .tip-head .tag { flex: none; }

.prop-tip .tip-sub { color: var(--ink-3); font-size: 11px; margin-top: 1px; }

.prop-tip .tip-line { margin-top: 5px; font-variant-numeric: tabular-nums; }

.prop-tip .tip-sale {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid var(--line);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

/* One flat type or five, the figures sit in labelled columns. Without the header
   row and a real column gap, "5-ROOM $4,700 $4.00 psf" reads as one run-on
   string -- which is exactly how the HDB card went wrong. */
.prop-tip .tip-beds {
  border-collapse: collapse;
  width: 100%;
  margin: 7px 0 0;
  font-variant-numeric: tabular-nums;
}

.prop-tip .tip-beds th {
  position: static;
  background: none;
  cursor: default;
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  text-align: left;
  white-space: nowrap;
  padding: 0 0 3px;
  border-bottom: 1px solid var(--line);
}

.prop-tip .tip-beds td {
  padding: 3px 0 0;
  border: none;
  white-space: nowrap;
  vertical-align: baseline;
}

.prop-tip .tip-beds th + th,
.prop-tip .tip-beds td + td { padding-left: 14px; }

.prop-tip .tip-beds .c-type { font-weight: 550; }
.prop-tip .tip-beds .c-rent { text-align: right; font-weight: 650; }

.prop-tip .tip-beds .c-psf,
.prop-tip .tip-beds .c-size { text-align: right; color: var(--ink-2); }

.prop-tip .tip-foot {
  color: var(--ink-3);
  font-size: 10.5px;
  margin-top: 5px;
}

.prop-tip .tip-hint {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid var(--line);
  color: var(--accent);
  font-size: 11px;
  font-weight: 550;
}

/* ------------------------------------------------------------ mobile shell

   Under 780px the sidebar stops being a sidebar: the filters become a sheet over
   the map, the map keeps its height, and each result becomes one row instead of
   nine columns, which cannot be read at 390px. */

#open-filters,
.sheet-head,
.sheet-foot,
#sort-field,
#scrim { display: none; }

@media (max-width: 1080px) and (min-width: 781px) {
  main { grid-template-columns: 258px 1fr; }
}

@media (max-width: 780px) {
  header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 3px 10px;
    padding: 8px 12px;
  }

  header h1 { font-size: 14.5px; }
  header .spacer { display: none; }
  header .meta { grid-area: 2 / 1; font-size: 11px; }
  header button.link { grid-area: 2 / 2; justify-self: end; align-self: start; }

  #open-filters {
    grid-area: 1 / 2;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line-2);
    background: #fff;
    border-radius: 7px;
    padding: 7px 12px;
    font: inherit;
    font-size: 12.5px;
    font-weight: 550;
    color: var(--ink-2);
    cursor: pointer;
  }

  #open-filters[aria-expanded="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
  }

  #open-filters .badge {
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
    min-width: 17px;
    padding: 0 5px;
    font-size: 10.5px;
    font-weight: 650;
    line-height: 17px;
    text-align: center;
  }

  #open-filters .badge[hidden] { display: none; }

  #caveat { font-size: 12px; max-height: 52dvh; padding: 9px 13px 11px; }

  main { grid-template-columns: 1fr; grid-template-rows: 1fr; }

  #scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--z-scrim);
    background: rgba(16, 18, 23, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-out;
  }

  body.filters-open #scrim { opacity: 1; pointer-events: auto; }

  #filters {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-sheet);
    max-height: min(80dvh, 640px);
    border: none;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 32px rgba(16, 18, 23, 0.26);
    padding: 0 14px calc(4px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
    transform: translateY(101%);
    transition: transform 0.28s var(--ease-out);
  }

  body.filters-open #filters { transform: translateY(0); }

  /* Head and foot stick to the sheet's own scrollport, so the title stays put and
     the dismiss button stays in reach however far down the filters you have got. */
  .sheet-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 11px 0 9px;
    margin-bottom: 14px;
  }

  .sheet-head h2 {
    margin: 0;
    flex: 1;
    font-size: 14px;
    font-weight: 650;
  }

  #close-filters {
    border: none;
    background: none;
    font-size: 24px;
    line-height: 1;
    color: var(--ink-3);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 6px;
  }

  .sheet-foot {
    position: sticky;
    bottom: 0;
    display: block;
    background: var(--panel);
    border-top: 1px solid var(--line);
    padding: 10px 0;
  }

  #apply-filters {
    width: 100%;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    padding: 11px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
  }

  /* Otherwise the last group hides behind the sticky footer. */
  #filters .group:last-of-type { margin-bottom: 10px; }

  /* The map is the point of the page, so the open list takes under half of what is
     left and the map keeps the rest. */
  #right { grid-template-rows: minmax(170px, 1fr) minmax(140px, 46%); }

  /* Two wrapped lines of attribution cost more of a phone screen than the map can
     spare. It stays legible, it just stops being a paragraph. */
  .leaflet-control-attribution {
    font-size: 9.5px;
    line-height: 1.45;
    padding: 0 4px;
  }

  .leaflet-control-attribution img { height: 12px !important; }

  /* The bar is the map's floor: every line it grows costs the map a line. The three
     controls have to hold one row at 360px, so each one is capped and none of them
     is allowed to wrap inside itself. */
  #results-bar { flex-wrap: wrap; gap: 7px 8px; padding: 7px 10px; }
  #results-bar .spacer { display: none; }
  #results-bar button { white-space: nowrap; }

  #count { order: 3; flex-basis: 100%; font-size: 11.5px; line-height: 1.35; }

  #export { margin-left: auto; }

  #sort-field {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    font-size: 11.5px;
    color: var(--ink-3);
  }

  /* A select is as wide as its longest option unless told otherwise, and "Rent:
     high to low" on its own pushes the CSV button onto a second row. */
  #sort-field select {
    width: auto;
    max-width: 104px;
    padding: 5px 4px;
    text-overflow: ellipsis;
  }

  /* One row per place. The nine-column head cannot be read this narrow, so it
     goes, and its sort moves into the select in the results bar. */
  #table-wrap thead { display: none; }

  tbody td.mrow { padding: 9px 12px; }

  .mr-top { display: flex; align-items: baseline; gap: 7px; min-width: 0; }

  .mr-name {
    font-weight: 600;
    font-size: 13.5px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mr-top .tag { flex: none; }

  .mr-sub {
    color: var(--ink-3);
    font-size: 11.5px;
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mr-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 3px 12px;
    margin-top: 5px;
    font-size: 12px;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
  }

  .mr-stats b { color: var(--ink); font-weight: 650; }

  .mr-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 5px;
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
  }

  .legend { font-size: 10.5px; padding: 5px 7px; line-height: 1.55; }

  .school-label { font-size: 10px; padding: 1px 4px; }

  /* Full height, no radius: a centred card with a 92dvh cap leaves a strip of map
     above and below and reads as a drawer stuck half-open. */
  .modal { padding: 0; align-items: stretch; }

  .modal-card {
    width: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    padding: 15px 14px calc(8px + env(safe-area-inset-bottom));
  }

  .modal-card h2 { font-size: 16px; }
  .modal-close { top: 5px; right: 6px; font-size: 26px; padding: 8px 12px; }

  /* Three columns at phone width leaves every value wrapping mid-phrase. */
  #detail-facts { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 11px 14px; }

  /* Keyed off the width, not the pointer: this has to be a real tap target on any
     phone, including the ones that claim a fine pointer. Nothing sits next to it,
     so the row it occupies is all target. */
  #detail-facts .route {
    display: block;
    width: fit-content;
    margin-top: 4px;
    padding: 8px 0;
    font-size: 12.5px;
  }
  #detail-body th, #detail-body td { padding: 6px 6px; }

  .pager { flex-wrap: wrap; gap: 8px; }
  .pager .spacer { display: none; }
  .pager span { flex-basis: 100%; order: 3; }
}

/* --------------------------------------------------------- touch targets

   Keyed off the input method rather than the screen: a touch laptop needs these
   and a narrow desktop window does not. */

/* On the narrowest phones the word "Sort" is the difference between one row of
   controls and two. The select keeps its aria-label. */
@media (max-width: 380px) {
  #sort-field > span { display: none; }
}

@media (hover: none) and (pointer: coarse) {
  .chip { padding: 7px 13px; font-size: 12.5px; }
  .rowbtns button { padding: 8px 0; font-size: 12px; }
  label.check { padding: 5px 0; }
  #toggle-list, #export, .tabs button, .pager button { padding: 8px 13px; }
  .modal-close { padding: 9px 13px; }

  /* iOS zooms the page in on focus for any input whose text is under 16px. */
  input[type="text"], input[type="number"], select { font-size: 16px; padding: 8px 9px; }

  /* Hover styling sticks after a tap on touch, leaving rows looking selected. */
  .chip:hover, #toggle-list:hover, #export:hover { background: #fff; }
  tbody tr:hover { background: none; }
  tbody tr.selected, tbody tr.selected:hover { background: var(--accent-soft); }
}

@media (prefers-reduced-motion: reduce) {
  #filters, #scrim, #toggle-list::before { transition: none; }
  .leaflet-tooltip.prop-tip { animation: none; }
}
