.dgm {
  --dgm-line: var(--gw-rule-strong, #ddd);
  --dgm-ink: var(--gw-ink, #222);
  --dgm-muted: var(--gw-muted, #6a6a6a);
  box-sizing: border-box;
  width: min(calc(100% - 2 * var(--gw-gutter, 24px)), 1320px);
  margin: 0 auto;
  padding: clamp(26px, 4vw, 54px) 0 28px;
  color: var(--dgm-ink);
  font-family: var(--gw-font, system-ui, sans-serif);
}
.dgm [hidden] { display: none !important; }
.dgm h1, .dgm h2, .dgm p, .dgm figure { margin: 0; }
.dgm-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 24px;
}
.dgm h1 { font-size: var(--gw-h1, 36px); line-height: 1.08; letter-spacing: -.035em; }
.dgm-heading p { margin-top: 8px; color: var(--dgm-muted); font-size: 17px; }
.dgm a { color: inherit; text-underline-offset: .18em; }
.dgm-heading > a { display: inline-flex; align-items: center; min-height: 44px; font-size: 15px; font-weight: 650; }
.dgm-search { display: grid; gap: 4px; width: min(100%, 440px); margin-bottom: 18px; }
.dgm-search label { font-size: 14px; font-weight: 700; }
.dgm-search input {
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  border: 1px solid var(--gw-input-line, #b0b0b0);
  border-radius: 24px;
  background: var(--gw-paper, #fff);
  color: inherit;
  font: inherit;
}
.dgm-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: clamp(18px, 3vw, 34px); }
.dgm-map {
  position: relative;
  height: clamp(340px, 58vh, 600px);
  overflow: hidden;
  border: 1px solid var(--dgm-line);
  border-radius: 16px;
  background: #f5f5f0;
}
.dgm-svg { display: block; width: 100%; height: 100%; }
.dgm-map[data-ready] .dgm-svg { touch-action: none; cursor: grab; }
.dgm-map[data-dragging] .dgm-svg { cursor: grabbing; }
.dgm-parks { fill: #dfebdc; }
.dgm-streets, .dgm-main-roads, .dgm-street-casing, .dgm-main-road-casing { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.dgm-street-casing { stroke: #deded5; stroke-width: 1.25; }
.dgm-main-road-casing { stroke: #d9d8ce; stroke-width: 1.95; }
.dgm-streets { stroke: #fff; stroke-width: .9; }
.dgm-main-roads { stroke: #fff; stroke-width: 1.55; }
.dgm-street-labels, .dgm-campus text {
  fill: #51564e;
  stroke: #f5f5f0;
  stroke-linejoin: round;
  paint-order: stroke;
  font-weight: 650;
  pointer-events: none;
}
.dgm-campus text { text-anchor: middle; font-weight: 780; fill: #633624; }
.dgm-campus circle { fill: #9d4629; stroke: #fff; stroke-width: 1.3px; vector-effect: non-scaling-stroke; }
.dgm-pin { fill: #324343; stroke: #fff; stroke-width: 1.2px; vector-effect: non-scaling-stroke; }
.dgm-map[data-ready] .dgm-pin { cursor: pointer; }
.dgm-pin:is(:hover, [data-selected]) { fill: #a3472a; stroke-width: 2px; }
.dgm-map-buttons { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 5px; }
.dgm button, .dgm .dgm-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--dgm-line);
  border-radius: 24px;
  background: var(--gw-paper, #fff);
  color: inherit;
  font: 650 14px/1.25 var(--gw-font, system-ui, sans-serif);
  cursor: pointer;
}
.dgm button:hover { background: var(--gw-card, #f7f7f7); }
.dgm button:focus-visible, .dgm a:focus-visible, .dgm input:focus-visible { outline: 2px solid var(--dgm-ink); outline-offset: 3px; }
.dgm-map-buttons button:not([data-map-zoom="reset"]) { font-size: 20px; }
.dgm figcaption { margin-top: 8px; color: var(--dgm-muted); font-size: 13px; }
.dgm-results { min-width: 0; }
/* Walk time to the student's own building: a field, the longest walk and the order, above the list. */
.dgm-walkto { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px 14px; margin: 0 0 18px; padding: 14px 16px; border: 1px solid var(--dgm-line); border-radius: 14px; }
.dgm-walkto[hidden] { display: none; }
.dgm-walkto :is(label, .dgm-walk-label) { font-size: 14px; font-weight: 700; white-space: nowrap; }
.dgm-walkto :is(input, select) { box-sizing: border-box; width: 100%; min-width: 0; min-height: 44px; padding: 8px 14px; border: 1px solid var(--gw-input-line, #b0b0b0); border-radius: 22px; background-color: var(--gw-paper, #fff); color: inherit; font: inherit; text-overflow: ellipsis; }
.dgm-walkto select { width: auto; max-width: 100%; justify-self: start; padding-right: 30px; cursor: pointer; }
.dgm-walkto input[aria-invalid="true"] { border-color: var(--gw-signal, #bd502c); }
.dgm-walk-miss { grid-column: 2; margin: -4px 0 0; color: var(--gw-signal-text, #963e26); font-size: 14px; line-height: 1.4; }
.dgm-walk-miss[hidden] { display: none; }
.dgm-walk-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.dgm .dgm-walk-chips button { min-height: 40px; padding: 0 14px; font-weight: 600; }
.dgm .dgm-walk-chips button[aria-pressed="true"] { background: var(--dgm-ink); border-color: var(--dgm-ink); color: var(--gw-paper, #fff); }
.dgm-place small[data-map-walk] b { color: var(--dgm-ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.dgm-result-title { font-size: 22px; }
.dgm-count, .dgm-empty { color: var(--dgm-muted); }
.dgm-results .dgm-count { margin: 2px 0 10px; font-size: 14px; }
.dgm-places { box-sizing: border-box; max-height: clamp(290px, 51vh, 548px); overflow-y: auto; margin: 0; padding: 0 6px 0 0; list-style: none; }
.dgm-place {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gw-rule, #ebebeb);
}
.dgm-place > div { min-width: 0; }
.dgm-place a { display: inline-flex; align-items: center; min-height: 44px; font-size: 16px; font-weight: 750; text-decoration-color: transparent; }
.dgm-place a:hover { text-decoration-color: currentColor; }
.dgm-place :is(span, small) { display: block; font-size: 14px; color: var(--dgm-muted); }
.dgm-place button { flex: none; padding-inline: 11px; }
.dgm-selection { margin-bottom: 18px; padding: 16px; border: 1px solid var(--dgm-line); border-radius: 14px; }
.dgm-selection h2 { margin-top: 10px; font-size: 23px; }
.dgm-selection h2:focus { outline: none; }
.dgm-selection p { margin: 5px 0; color: var(--dgm-muted); }
.dgm-selection .dgm-primary {
  margin-top: 8px;
  background: var(--dgm-ink);
  border-color: var(--dgm-ink);
  color: #fff;
  text-decoration: none;
}
.dgm-footer { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--dgm-line); color: var(--dgm-muted); font-size: 14px; }
@media (max-width: 740px) {
  .dgm { width: calc(100% - 36px); }
  .dgm-heading { align-items: start; margin-bottom: 14px; }
  .dgm-heading > a { min-height: 36px; }
  .dgm-layout { grid-template-columns: minmax(0, 1fr); }
  .dgm-map { height: 300px; }
  .dgm-places { max-height: none; overflow: visible; }
}

/* The shared Field Guide map (/assets/fg/map.mjs + map.css) draws over the flat SVG once it loads. */
.dgm-map:has(.fg-map-canvas:not(:empty)) .dgm-svg { visibility: hidden; }
.dgm-map.fgm .dgm-map-buttons { top: 12px; bottom: auto; z-index: 5; }
.dgm-map .fg-map-canvas:empty { display: none; }

/* Prices first: priced rows show the rent; places without a posted rent wait in a closed group. */
.dgm-place { cursor: pointer; }
.dgm-place[data-selected] { background: var(--gw-card, #f7f7f7); box-shadow: inset 3px 0 0 var(--dgm-ink); }
.dgm-rent { flex: none; display: grid; justify-items: end; font-size: 16px; font-weight: 750; font-variant-numeric: tabular-nums; }
.dgm-rent small { font-size: 12px; font-weight: 500; color: var(--dgm-muted); }
.dgm-unpriced { margin-top: 12px; border-top: 1px solid var(--dgm-line); }
.dgm-unpriced summary { display: flex; align-items: center; min-height: 48px; font-weight: 650; cursor: pointer; }
.dgm-unpriced .dgm-places { max-height: none; overflow: visible; }
.dgm-attrib { position: absolute; right: 8px; bottom: 6px; margin: 0; font-size: 11px; text-shadow: 0 0 2px #fff, 0 0 3px #fff; }
.dgm-attrib a { color: #5a5a5a; text-decoration: none; }
.dgm-map:has(.fg-map-canvas:not(:empty)) .dgm-attrib { display: none; }
.dgm-results .dgm-footer { margin-top: 16px; }
.dgm-sheet-handle[hidden] { display: none !important; }

/* Phones: the shared map pattern. The map fills the screen under the site header, the search pill sits on it,
   and the list lives in a sheet that peeks with the count; tap or drag it up for the list. */
@media (max-width: 740px) {
  html.dgm-phone, html.dgm-phone body { overflow: hidden; }
  .dgm { width: 100%; padding: 0; }
  .dgm-heading { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .dgm-search { position: fixed; top: calc(var(--fg-map-top, 64px) + 12px); left: 16px; right: 16px; z-index: 6; width: auto; margin: 0; }
  .dgm-search label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .dgm-search input { border-color: transparent; box-shadow: 0 2px 10px rgb(0 0 0 / .18); }
  .dgm-layout { display: block; }
  .dgm-figure { margin: 0; }
  html.dgm-phone .dgm-map { position: fixed; inset: var(--fg-map-top, 64px) 0 0 0; height: auto; border: 0; border-radius: 0; z-index: 1; }
  .dgm-map-buttons { display: none !important; }
  .dgm .dgm-map.fgm .maplibregl-ctrl-bottom-right, .dgm-attrib { bottom: calc(var(--dgm-sheet-h, 120px) + 2px); }
  .dgm-map .fgm .fg-map-layers { top: 76px; }
  .dgm-results { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; flex-direction: column; box-sizing: border-box;
    max-height: calc(100dvh - var(--fg-map-top, 64px) - 72px); padding: 0 16px calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--gw-paper, #fff); border-radius: 12px 12px 0 0; box-shadow: 0 -4px 20px rgb(0 0 0 / .14); overflow: hidden; }
  .dgm-sheet-handle { display: flex !important; justify-content: center; width: 100%; min-height: 28px !important; padding: 10px 0 6px !important; border: 0 !important; background: none !important; touch-action: none; }
  .dgm-grip { width: 36px; height: 4px; border-radius: 999px; background: #d0d0d0; }
  .dgm-result-title { font-size: 18px; cursor: pointer; }
  .dgm-results .dgm-count { margin: 0 0 8px; }
  .dgm-results[data-map-sheet="peek"] :is(.dgm-places, .dgm-unpriced, .dgm-empty, .dgm-footer) { display: none; }
  .dgm-results[data-map-sheet="open"] { height: calc(100dvh - var(--fg-map-top, 64px) - 72px); overflow-y: auto; }
  .dgm-results[data-map-sheet="open"] .dgm-places { max-height: none; overflow: visible; padding: 0; }
  .dgm-selection { margin: 0 0 10px; padding: 12px 14px; }
  .dgm-selection h2 { margin-top: 6px; font-size: 19px; }
}
@media (min-width: 741px) { .dgm-sheet-handle { display: none !important; } }

/* Explore lenses on the housing map: keep the chip row clear of the zoom buttons (desktop) and the search pill (phone). */
/* Desktop: an explorer-sized map; zoom buttons move bottom right so the lens chips get the top edge. */
/* Desktop explorer layout: the map is tall and sticky on the left; title, search and list stack on the right. */
@media (min-width: 741px) {
  .dgm { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(320px, 1fr); column-gap: clamp(18px, 3vw, 34px); align-items: start; padding-top: 20px; }
  .dgm-layout { display: contents; }
  .dgm-heading, .dgm-search, .dgm-results { grid-column: 2; }
  .dgm-heading { margin-bottom: 14px; }
  .dgm-search { width: 100%; }
  /* --fg-map-top is a header that stays on screen (none on this site); --dgm-head is the header still in view while the
     page scrolls, so the sticky map always ends 20 px above the bottom of the screen. */
  .dgm-figure { grid-column: 1; grid-row: 1 / span 3; position: sticky; top: calc(var(--fg-map-top, 0px) + 20px); }
  .dgm-map { height: calc(100vh - var(--dgm-head, var(--fg-map-top, 0px)) - 40px); min-height: 520px; }
  .dgm-map.fgm .dgm-map-buttons { top: auto; bottom: 30px; }
  .dgm-places { max-height: none; overflow: visible; }
}
@media (max-width: 740px) { .dgm-map.fgm.fgm .fg-map-lenses { top: 76px; right: 16px; } .dgm-map.fgm.fgm .fg-map-here { max-height: 34vh; } }

/* Places · Explore · Compare: one tab bar at the top of the column (desktop) or the sheet (phones).
   Explore, Find and Compare read here; the map keeps the homes, the active layer and the zoom buttons.
   Underlined tabs, so the in-topic toggles (pill segments) read as a level below. */
.dgm-tabs { display: flex; gap: 22px; margin: 0 0 16px; border-bottom: 1px solid var(--dgm-line); }
.dgm-tabs:empty { display: none; }
.dgm .dgm-tabs .fg-map-tab { flex: none; min-width: 0; min-height: 44px; margin-bottom: -1px; padding: 0 2px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--dgm-muted); font-size: 15px; font-weight: 600; white-space: nowrap; }
.dgm .dgm-tabs .fg-map-tab:hover { background: none; color: var(--dgm-ink); }
.dgm .dgm-tabs .fg-map-tab[aria-selected="true"] { border-bottom-color: var(--dgm-ink); color: var(--dgm-ink); }
.dgm .dgm-tabs .fg-map-tab:focus-visible { outline-offset: -2px; }
.dgm-explore, .dgm-placesview { min-width: 0; }
@media (min-width: 741px) {
  /* Short panels (one topic) must not stretch the heading and search rows: spare height goes to an empty fourth row. */
  .dgm { grid-template-rows: auto auto auto 1fr; }
  .dgm-figure { grid-row: 1 / span 4; }
  .dgm-tabs { position: sticky; top: var(--fg-map-top, 0px); z-index: 3; padding-top: 6px; background: var(--gw-paper, #fff); }
}
@media (max-width: 740px) {
  .dgm-tabs { flex: none; gap: 20px; margin: 0 0 10px; }
  .dgm-results[data-map-sheet="peek"] :is(.dgm-filters, .dgm-walkto) { display: none; }
  .dgm-walkto { margin-bottom: 14px; padding: 12px; gap: 8px 10px; }
  .dgm-walk-chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .dgm .dgm-walk-chips button { min-width: 0; padding: 0 4px; font-size: 13px; }
  .dgm-walkto select { width: 100%; }
  .dgm-count { cursor: pointer; }
  /* Peeked on a topic: the sheet keeps its name and answer; drag up for the key, sources and the rest. */
  .dgm-results[data-map-sheet="peek"] .dgm-explore :is(.fg-map-topics, .fg-map-back) { display: none !important; }
  .dgm-results[data-map-sheet="peek"] .dgm-explore .fg-map-here :is(.fg-map-here-item:nth-of-type(n+4), .fg-map-here-note) { display: none !important; }
  .dgm-results[data-map-sheet="peek"] .dgm-explore .fg-map-legend-body > :not(.fg-map-legend-head, .fg-map-stat) { display: none !important; }
  .dgm-results[data-map-sheet="peek"] .dgm-explore .fg-map-legend-head { margin-top: 0; }
  .dgm-results[data-map-sheet="open"] .dgm-explore { padding-bottom: 8px; }
}

/* Map explorer release (November 11): Full screen, the selection card's Compare, a column that never shifts,
   the phone sheet that follows the finger. */
.dgm-map:focus-visible { outline: 2px solid var(--dgm-ink); outline-offset: 2px; }
.dgm .dgm-full {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; box-sizing: border-box;
  border: 1px solid var(--dgm-line); border-radius: 24px; background: var(--gw-paper, #fff); color: inherit;
  font: 650 14px/1.25 var(--gw-font, system-ui, sans-serif); text-decoration: none; white-space: nowrap;
}
.dgm .dgm-full:hover { background: var(--gw-card, #f7f7f7); }
.dgm-map.fgm .dgm-map-buttons > * { box-shadow: 0 1px 2px rgb(0 0 0 / .14), 0 2px 8px rgb(0 0 0 / .1); border-color: transparent; }
.dgm-selection-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.dgm-selection-actions .dgm-primary { margin-top: 0 !important; }
.dgm-selection-actions [data-map-selected-compare][aria-pressed="true"] { border-color: var(--dgm-ink); }
/* Filter homes: the row is held from the first paint (its height matches the map's filter box), so the list never jumps. */
.dgm-filters[data-reserved]:empty {
  box-sizing: border-box; height: 50px; margin: 0 0 12px; padding: 0 14px 0 38px; border: 1px solid var(--m-line-strong, #dcdcdc); border-radius: 12px;
  display: flex; align-items: center; color: var(--dgm-ink); font: 600 14px/1 var(--gw-font, system-ui, sans-serif);
}
.dgm-filters[data-reserved]:empty::before { content: "Filter homes"; }
@media (max-width: 740px) {
  /* Phones: the zoom buttons give way to pinch; Full screen stays, under the search pill on the right. */
  .dgm .dgm-map .dgm-map-buttons:not([hidden]) { display: flex !important; top: 70px; right: 16px; bottom: auto; z-index: 5; }
  .dgm-map-buttons > button { display: none !important; }
  .dgm .dgm-full { min-height: 40px; padding: 0 12px; border-color: transparent; box-shadow: 0 2px 10px rgb(0 0 0 / .18); font-size: 13px; }
  /* The sheet's head (grip, tabs, title, count) drags it; the grip and tabs stay on top while the list scrolls. */
  .dgm-results :is(.dgm-sheet-handle, .dgm-tabs, .dgm-result-title, .dgm-count) { touch-action: none; user-select: none; -webkit-user-select: none; }
  .dgm-results[data-map-sheet="open"] .dgm-sheet-handle { position: sticky; top: 0; z-index: 2; background: var(--gw-paper, #fff) !important; }
  .dgm-results[data-map-sheet="open"] .dgm-tabs { position: sticky; top: 28px; z-index: 2; background: var(--gw-paper, #fff); }
  .dgm-results[data-dragging] { transition: none; overflow: hidden; }
  .dgm-results[data-dragging] * { pointer-events: none; }
}
