/* =========================================================================
   Manam: interactive plot availability map (/plots/).
   Loaded after ../type.css (type scale) and ../pages.css, which supplies the
   tokens, reset, top bar and footer shared with About / Team.
   Under the shared black header band (pages.css .ab-hero), a white section
   holds the status ledger (each count is a filter toggle), the site-area
   pills, the map and, below it, the key table and the intro copy. Plot details
   open as a card over the map's lower-left corner on wide screens, a drawer
   from 720 to 1024px, and a bottom sheet on phones.
   ========================================================================= */

/* ---- Legend (status filter) ---------------------------------------------
   Same voice as the site's pill buttons: Canva Sans caps, thin outline pills.
   "Show all plots" sits at the end as the black primary action. On phones
   the row scrolls sideways instead of wrapping into a tall block. */

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 20px;
}

@media (max-width: 720px) {
  .legend {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin-right: calc(-1 * var(--gutter));
    padding: 0 var(--gutter) 2px 0;
  }
}

.legend::-webkit-scrollbar {
  display: none;
}

.legend li {
  display: inline-flex;
  flex: none;
}

.legend li:last-child {
  margin-left: auto;
  padding-left: 8px;
}

/* the legend is the filter control, so each entry is a real button */
.legend .legend-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--color-line);
  border-radius: 999px;
  background: transparent;
  font-family: var(--font-sans);
  font-size: var(--text-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--color-fg);
  cursor: pointer;
  transition:
    border-color 0.3s var(--ease-out-expo),
    color 0.3s var(--ease-out-expo),
    background 0.3s var(--ease-out-expo);
}

.legend .legend-toggle:hover {
  border-color: var(--color-fg);
}

.legend .legend-toggle.is-on {
  background: var(--color-fg);
  border-color: var(--color-fg);
  color: var(--color-bg);
}

.legend .legend-toggle:focus-visible {
  outline: 2px solid var(--color-fg);
  outline-offset: 2px;
}

.legend .legend-all {
  background: var(--black);
  border-color: var(--black);
  color: var(--on-dark);
}

.legend .legend-all:hover {
  background: transparent;
  border-color: var(--black);
  color: var(--black);
}

.legend .legend-all.is-on {
  background: transparent;
  color: var(--black);
}

.legend .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.legend .count {
  min-width: 1.6em;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(22, 19, 15, 0.07);
  font-size: var(--text-fine);
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--color-mute);
}

.legend .legend-toggle.is-on .count {
  background: rgba(255, 255, 255, 0.16);
  color: var(--color-bg);
}

/* ---- Map ----------------------------------------------------------------- */

/* The aerial is landscape, so it fits the column width instead of scrolling
   sideways as the portrait plan did. Zoom replaces the horizontal scroll. */
.map-viewport {
  position: relative;
  overflow: hidden;
  aspect-ratio: 3000 / 1687;
  border: 1px solid var(--color-line);
  border-radius: 14px;
  background: var(--plaster-hi);
  cursor: grab;
  /* phones: a finger on the whole-site map still scrolls the page (plots.js
     handles pinch); once zoomed in, one finger pans the map instead */
  touch-action: pan-y;
}

.map-viewport.is-zoomed {
  touch-action: none;
}

.map-viewport.is-grabbing {
  cursor: grabbing;
}

/* Zoom by RESIZING the stage, not transform:scale(). A scaled compositor layer is
   rasterised once at its base size and then stretched by the GPU, so the browser never
   re-samples the source image and everything goes soft. Width/height keeps it sharp. */
.map-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  margin: 0;
}

.map-stage.is-gliding {
  transition:
    left 0.45s var(--ease-out-expo),
    top 0.45s var(--ease-out-expo),
    width 0.45s var(--ease-out-expo),
    height 0.45s var(--ease-out-expo);
}

/* Whole site, minus and plus: always shown, in the map's bottom-right corner at
   every zoom and screen size; the light buttons carry a soft dark shadow so they
   read over the green surround */
.map-controls {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  gap: 6px;
}

.map-controls button {
  border: 1px solid var(--color-line);
  border-radius: 7px;
  background: var(--color-bg);
  color: var(--color-fg);
  padding: 7px 11px;
  box-shadow: 0 1px 4px rgba(22, 19, 15, 0.35);
  cursor: pointer;
}

.map-controls button:hover {
  border-color: var(--color-fg);
}

/* touch screens: finger-sized buttons */
@media (pointer: coarse) {
  .map-controls button {
    min-width: 40px;
    min-height: 40px;
  }
}

.map-scale {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 4;
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--color-bg);
  border: 1px solid var(--color-line);
}

@media (prefers-reduced-motion: reduce) {
  .map-stage.is-gliding {
    transition: none;
  }
}

.map-stage img {
  display: block;
  width: 100%;
  height: 100%;
}

/* traffic loop sits exactly over the still and cross-fades in once it can play */
.map-stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  opacity: 0;
  transition: opacity 0.6s var(--ease-out-expo);
  pointer-events: none;
}

.map-stage video.is-ready {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .map-stage video {
    display: none;
  }
}

.map-stage svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Unpainted by default so the aerial reads as a photograph. Status colour appears
   on hover, or for a whole status when its legend chip is switched on. */
.map-stage svg polygon {
  cursor: pointer;
  /* Plots are fully transparent until hovered/filtered, so don't leave hit-testing to
     the SVG default (visiblePainted), which ties it to what is actually painted.
     `all` makes the whole plot clickable regardless of fill or stroke opacity. */
  pointer-events: all;
  stroke: transparent;
  stroke-width: 1;
  fill-opacity: 0;
  transition:
    fill-opacity 0.18s var(--ease-out-expo),
    stroke 0.18s var(--ease-out-expo);
}

/* The plan in its legend colours (#map-ground, drawn by plots.js): the site in
   road grey, green verges, one sand ground for every plot, zones in their
   colours. Opaque, so none of the render's own textures show inside the site.
   Plots have no outline at rest; hover, selection and filters add one. */
#map-ground,
.map-stage svg .patch {
  pointer-events: none;
}

/* Slot for a transparent overlay (trees, statue) between the plan and the plots */
.map-stage .map-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.map-stage .map-overlay:not([src]) {
  display: none;
}

.map-stage svg polygon.is-lit {
  fill-opacity: 0.42;
  stroke: rgba(255, 255, 255, 0.55);
}

/* while a filter is on, un-lit plots stay readable but recede */
.map-stage svg.is-filtered polygon:not(.is-lit) {
  stroke: rgba(255, 255, 255, 0.16);
}

.map-stage svg polygon:hover,
.map-stage svg polygon:focus-visible,
.map-stage svg polygon.is-active {
  fill-opacity: 0.72;
  stroke: var(--color-fg);
  stroke-width: 1.5;
  outline: none;
}

/* zones (totlot / social / utility) read as context, not product */
.map-stage svg polygon.is-zone {
  fill-opacity: 0.18;
}

.map-stage svg polygon.is-zone:hover,
.map-stage svg polygon.is-zone:focus-visible,
.map-stage svg polygon.is-zone.is-active {
  fill-opacity: 0.4;
}

/* future development / expansion carry the drawing's hatching, visible at rest */
.map-stage svg polygon.is-zone.is-hatch {
  fill-opacity: 0.85;
}

.map-stage svg polygon.is-zone.is-hatch:hover,
.map-stage svg polygon.is-zone.is-hatch:focus-visible,
.map-stage svg polygon.is-zone.is-hatch.is-active {
  fill-opacity: 1;
}

/* the plan's 2.0 m cycling track: a light band with its own white rails, rungs
   and ticks, to scale; and the thin orange division across the totlot */
.map-stage svg .line {
  fill: none;
  pointer-events: none;
}

.map-stage svg .line-track-band {
  fill: #ffffff;
  fill-opacity: 0.35;
}

.map-stage svg .line-track {
  stroke: #ffffff;
  stroke-width: 1;
}

.map-stage svg .line-divider {
  stroke: #ff8000;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

/* plot numbers (white on the sand ground) and the plan's road names (ink on
   the road grey), drawn by plots.js; they never take the pointer */
.map-stage svg .num,
.map-stage svg .road-label {
  pointer-events: none;
  font-family: var(--font-sans);
  text-anchor: middle;
  dominant-baseline: central;
}

.map-stage svg .num {
  fill: #ffffff;
  font-weight: 600;
}

.map-stage svg .road-label {
  fill: #16130f;
  font-weight: 500;
  letter-spacing: 0.04em;
}

/* debug mode (?debug=1) */
.map-stage svg .debug-label {
  font: var(--text-fine) var(--font-mono);
  fill: #c00;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 2.5px;
  pointer-events: none;
}

body.debug .map-stage svg polygon {
  stroke: #c00 !important;
  stroke-width: 1.5;
  fill-opacity: 0.25;
}


/* ---- Tooltip ------------------------------------------------------------- */

.tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  background: var(--color-fg);
  color: var(--color-bg);
  padding: 7px 10px;
  border-radius: 6px;
  white-space: nowrap;
  transform: translate(14px, 18px);
}

/* ---- Detail panel -------------------------------------------------------- */

.panel {
  position: fixed;
  z-index: 40;
  top: 0;
  right: 0;
  height: 100dvh;
  width: min(340px, 92vw);
  background: var(--plaster-hi);
  border-left: 1px solid var(--color-line);
  box-shadow: -24px 0 48px rgba(22, 19, 15, 0.08);
  padding: 56px 28px 28px;
  transform: translateX(105%);
  transition: transform 0.4s var(--ease-out-expo);
  overflow-y: auto;
}

.panel.is-open {
  transform: translateX(0);
}

.panel-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--color-line);
  border-radius: 50%;
  background: transparent;
  color: var(--color-fg);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

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

.panel-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.panel-status .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.panel-title {
  font-size: var(--text-h3);
  line-height: 1.05;
  margin: 10px 0 22px;
}

.panel-meta {
  border-top: 1px solid var(--color-line);
}

.panel-meta div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--color-line);
  font-size: var(--text-body-sm);
}

.panel-meta dt {
  color: var(--color-mute);
}

.panel-meta dd {
  text-align: right;
}

.panel-note {
  margin-top: 16px;
  font-size: var(--text-body-sm);
  color: var(--color-mute);
}

.panel-cta {
  display: block;
  margin-top: 24px;
  padding: 13px 18px;
  text-align: center;
  background: var(--color-fg);
  color: var(--color-bg);
  border-radius: 8px;
  font-size: var(--text-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  transition: opacity 0.18s;
}

.panel-cta:hover {
  opacity: 0.85;
}

/* display:block above outranks the browser's [hidden] rule, so plots.js's
   panelCta.hidden (zones, sold plots) needs this to actually hide it */
.panel-cta[hidden] {
  display: none;
}

/* ---- Mobile -------------------------------------------------------------- */

@media (max-width: 720px) {
  .panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: auto;
    max-height: 55dvh; /* leaves the map visible above it (plots.js scrolls it up) */
    border-left: none;
    border-top: 1px solid var(--color-line);
    border-radius: 16px 16px 0 0;
    transform: translateY(105%);
    padding-top: 44px;
  }

  .panel.is-open {
    transform: translateY(0);
  }

  .tooltip {
    display: none; /* touch: the panel is the detail surface */
  }
}

/* ---- Ledger: the status counts at the top of the map section, one row
   between hairlines; the figures are the filter, each status count a toggle. */

.c-ledger.legend {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  align-items: stretch;
  gap: 0;
  margin: 0 0 18px;
  border-top: 1px solid var(--color-line);
  border-bottom: 1px solid var(--color-line);
}

.c-ledger li {
  display: flex;
  min-width: 0;
}

.c-ledger li + li {
  border-left: 1px solid var(--color-line);
}

/* plots.css pushes the last legend item right for "Show all"; not here */
.c-ledger li:last-child {
  margin-left: 0;
  padding-left: 0;
}

.c-ledger .legend-toggle,
.c-ledger .c-total {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  gap: 12px 8px;
  padding: clamp(18px, 2.2vw, 28px) clamp(14px, 1.8vw, 24px);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-fg);
  font-size: var(--text-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  text-align: left;
  white-space: normal;
}

.c-ledger .count {
  order: -1;
  flex-basis: 100%;
  min-width: 0;
  padding: 0;
  border-radius: 0;
  background: none;
  font-family: var(--font-display);
  font-size: var(--text-stat);
  line-height: 0.9;
  letter-spacing: 0;
  text-align: left;
  color: var(--color-fg);
}

.c-ledger .c-total .name {
  color: var(--color-mute);
}

.c-ledger .legend-toggle:hover {
  background: rgba(22, 19, 15, 0.05);
}

/* switched on: the tile inverts, like the site's outline buttons on hover */
.c-ledger .legend-toggle.is-on {
  background: var(--color-fg);
  color: #ffffff;
}

.c-ledger .legend-toggle.is-on .count {
  background: none;
  color: #ffffff;
}

.c-ledger .legend-toggle:focus-visible {
  outline-offset: -4px;
}

.c-ledger .legend-toggle.is-on:focus-visible {
  outline-color: #ffffff;
}

/* ---- Map section: ledger, site-area pills, map, then the lede ------------- */

.c-stage-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* Under the map: the key as a table on the left, the page copy on the right;
   one column on phones, table first */
.c-below {
  display: grid;
  grid-template-columns: minmax(0, 440px) minmax(0, 1fr);
  align-items: start;
  gap: 28px clamp(32px, 5vw, 72px);
  margin-top: 24px;
}

@media (max-width: 860px) {
  .c-below {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* The drawing's legend table: number | name | swatch | area, thin single borders */
.map-key {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body-sm);
  line-height: 1.35;
  color: var(--color-fg);
}

.map-key td {
  padding: 8px 12px;
  border: 1px solid var(--color-line);
  text-align: left;
  vertical-align: middle;
}

.map-key td:first-child {
  width: 3em;
  font-variant-numeric: tabular-nums;
}

.map-key td:nth-child(2) {
  letter-spacing: var(--track-label);
}

.map-key td:nth-child(3) {
  width: 92px;
}

.map-key .swatch {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 22px;
  margin: 0 auto;
  box-shadow: inset 0 0 0 1px rgba(22, 19, 15, 0.18);
  font-size: 13px;
  line-height: 1;
  color: #ffffff;
}

/* phones: the four columns fit in 320-390px (less padding and tracking, a smaller
   swatch, long names may break) instead of being cut off at the screen edge */
@media (max-width: 560px) {
  .map-key {
    font-size: 13px;
  }

  .map-key td {
    padding: 6px 8px;
  }

  .map-key td:first-child {
    width: 2em;
  }

  .map-key td:nth-child(2) {
    letter-spacing: 0.04em;
    overflow-wrap: anywhere;
  }

  .map-key td:nth-child(3) {
    width: 44px;
  }

  .map-key .swatch {
    width: 40px;
    height: 16px;
    font-size: 11px;
  }
}

.c-lede {
  max-width: 62ch;
  font-size: var(--text-body);
  line-height: 1.65;
  color: var(--color-mute);
}

.c-stage {
  background: #ffffff;
  padding: clamp(28px, 4vw, 48px) 0 clamp(56px, 7vw, 96px);
}

.c-map-wrap {
  position: relative;
}

.c-map-wrap .map-viewport {
  border-radius: 12px;
}

.c-notes {
  max-width: 62ch;
  margin-top: 16px;
  font-size: var(--text-body-sm);
  line-height: 1.6;
  color: var(--color-mute);
}

.c-notes p + p {
  margin-top: 10px;
}

.c-notes a {
  color: var(--color-fg);
  border-bottom: 1px solid var(--color-line);
}

.c-notes a:hover {
  border-color: var(--color-fg);
}

/* ---- Details: plaster card ------------------------------------------------- */

.c-map-wrap .panel-cta {
  border-radius: 999px;
  background: var(--black);
}

@media (min-width: 1024px) {
  .c-map-wrap .panel {
    position: absolute;
    top: auto;
    right: auto;
    left: 16px;
    bottom: 16px;
    z-index: 6;
    width: 320px;
    height: auto;
    max-height: calc(100% - 32px);
    padding: 20px 22px 22px;
    border: 1px solid var(--color-line);
    border-radius: 14px;
    box-shadow: 0 28px 60px -28px rgba(22, 19, 15, 0.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px);
    transition:
      opacity 0.25s var(--ease-out-expo),
      transform 0.4s var(--ease-out-expo),
      visibility 0s linear 0.4s;
  }

  .c-map-wrap .panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition:
      opacity 0.25s var(--ease-out-expo),
      transform 0.4s var(--ease-out-expo);
  }

  .c-map-wrap .panel-close {
    top: 14px;
    right: 14px;
    width: 30px;
    height: 30px;
    font-size: 16px;
  }

  .c-map-wrap .panel-title {
    font-size: var(--text-h3);
    margin: 8px 0 16px;
  }

  .c-map-wrap .panel-meta div {
    padding: 9px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .c-map-wrap .panel,
  .c-map-wrap .panel.is-open {
    transition: none;
  }
}

@media (max-width: 720px) {
  /* ledger: total across the top, statuses two by two */
  .c-ledger.legend {
    grid-auto-flow: row;
    grid-template-columns: 1fr 1fr;
    overflow: visible;
    margin-right: 0;
    padding: 0;
  }

  .c-ledger .c-total {
    grid-column: 1 / -1;
  }

  .c-ledger li + li {
    border-left: 0;
    border-top: 1px solid var(--color-line);
  }

  .c-ledger li:nth-child(2n + 3) {
    border-left: 1px solid var(--color-line);
  }
}
