/* =========================================================================
   Map page
   ========================================================================= */

.map-shell { position: relative; }

#map {
  width: 100%;
  /* --chrome-h is measured in js/map.js (header + intro strip) so the map fills
     the viewport exactly, and grows when the intro strip is dismissed. */
  height: calc(100vh - var(--chrome-h, 64px));
  /* On phones 100vh is the LARGE viewport - the height the page would have if
     the browser's address bar and toolbar were hidden. The map therefore runs
     off the bottom of the screen, taking Leaflet's bottom-left legend and its
     bottom-right OSM attribution with it. dvh tracks the actually-visible
     viewport, so both stay on screen. The 100vh line above remains as the
     fallback for browsers without dvh. */
  height: calc(100dvh - var(--chrome-h, 64px));
  min-height: 420px;
  background: #aadaff;      /* sea tone before tiles load */
}

/* A 420px floor is taller than a landscape phone's viewport, which would push
   the map's bottom edge off screen again for exactly the same reason. */
@media (max-height: 520px) {
  #map { min-height: 0; }
}

/* intro strip above the map */
.map-intro {
  background: var(--parchment-2);
  border-bottom: 1px solid var(--border);
}
.map-intro[hidden] { display: none; }
.map-intro__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: nowrap;
}
.map-intro p { margin: 0; color: var(--muted); font-size: .92rem; }
.map-intro strong { color: var(--ink); }
.map-intro a.list-link {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .08em;
  font-weight: 700; text-decoration: none;
  /* kit sky blue is unreadable on parchment, so links use the deeper blue */
  color: var(--claret); border-bottom: 2px solid var(--blue-ink); padding-bottom: 2px;
}
.map-intro a.list-link:hover { color: var(--blue-ink); }

/* dismiss control - reclaims the strip's height for the map */
.map-intro__close {
  flex: none;
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--parchment);
  color: var(--muted);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.map-intro__close:hover {
  background: var(--claret);
  border-color: var(--claret);
  color: var(--parchment);
}
.map-intro__close svg { width: 13px; height: 13px; display: block; }

/* ---- custom pins -------------------------------------------------------- */
.nnm-pin-wrap { background: none; border: 0; }

.nnm-pin {
  position: relative;
  display: block;
  width: 100%; height: 100%;
  padding: 0; margin: 0;
  border: 0; background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nnm-pin__img {
  display: block;
  width: 100%; height: 100%;
  filter: drop-shadow(0 3px 3px rgba(34,19,26,.32));
  transform-origin: 50% 100%;
  transition: transform .16s cubic-bezier(.2,.7,.3,1.3), filter .16s ease;
}
.nnm-pin__img svg { width: 100%; height: 100%; display: block; }

/* hover + keyboard focus produce the SAME popped state */
.nnm-pin:hover .nnm-pin__img,
.nnm-pin:focus-visible .nnm-pin__img,
.nnm-pin.is-primed .nnm-pin__img {
  transform: scale(1.28) translateY(-2px);
  filter: drop-shadow(0 8px 8px rgba(34,19,26,.42));
}
.nnm-pin:focus-visible { outline: none; }
.nnm-pin:focus-visible .nnm-pin__img {
  filter: drop-shadow(0 0 0 2px var(--focus)) drop-shadow(0 8px 8px rgba(34,19,26,.42));
}

/* tooltip above the pin (latecheckout-style) */
.nnm-pin__tip {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, 4px);
  margin-bottom: 4px;
  background: var(--ink);
  color: var(--parchment);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 7px;
  box-shadow: 0 6px 16px rgba(34,19,26,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
  z-index: 5;
}
.nnm-pin__tip::after {
  content: "";
  position: absolute;
  top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--ink);
}
.nnm-pin:hover .nnm-pin__tip,
.nnm-pin:focus-visible .nnm-pin__tip,
.nnm-pin.is-primed .nnm-pin__tip {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* raise the hovered/focused marker above its neighbours */
.leaflet-marker-icon:hover,
.leaflet-marker-icon:focus-within { z-index: 1000 !important; }

/* ---- cluster bubbles (themed to match) ---------------------------------- */
.marker-cluster-nnm {
  background: transparent;
}
.marker-cluster-nnm div {
  width: 38px; height: 38px;
  margin-left: 1px; margin-top: 1px;
  text-align: center;
  border-radius: 50%;
  font-family: var(--font-sans);
  font-weight: 700;
  color: #f2efe6;
  background: var(--claret);
  border: 2px solid var(--sky);
  box-shadow: 0 3px 8px rgba(34,19,26,.35);
  line-height: 34px;
}
.marker-cluster-nnm.is-large div { width: 46px; height: 46px; line-height: 42px; }
.leaflet-cluster-anim .leaflet-marker-icon,
.leaflet-cluster-anim .leaflet-marker-shadow { transition: transform .25s ease, opacity .25s ease; }

/* ---- legend (persistent) ------------------------------------------------ */
.map-legend {
  background: rgba(242,239,230,.96);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 12px 14px;
  font-family: var(--font-sans);
  max-width: 250px;
}
/* header row: title/disclosure on the left, Clear on the right */
.legend-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
}
.legend-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 700;
  color: var(--muted);
  text-align: left;
}
.legend-toggle:hover { color: var(--claret); }

/* chevron: points down when open, right when collapsed */
.legend-chev {
  width: 0; height: 0;
  flex: none;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .15s ease;
  transform-origin: 30% 50%;
}
.map-legend[data-collapsed="false"] .legend-chev { transform: rotate(90deg); }

/* "a filter is on" marker, only shown while the list is collapsed.
   Reserved space like the Clear button, so the collapsed pill never changes
   width when the marker appears. */
.legend-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--claret);
  flex: none;
  visibility: hidden;
}
.legend-dot.is-on { visibility: visible; }

/* Reserved space, not conditional rendering: the control must not change
   size when a filter goes on or off. */
.legend-clear {
  flex: none;
  visibility: hidden;
  font-family: var(--font-sans);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--parchment);
  color: var(--claret);
  cursor: pointer;
}
.legend-clear.is-on { visibility: visible; }
.legend-clear:hover { background: var(--claret); border-color: var(--claret); color: var(--parchment); }

.legend-body[hidden] { display: none; }
/* collapsed at any width, the legend shrinks to just its header row */
.map-legend[data-collapsed="true"] .legend-head { margin-bottom: 0; }
.map-legend ul { list-style: none; margin: 0; padding: 0; }
.map-legend li { margin: 0; }

/* each legend row is a real toggle button - keyboard reachable, and its
   pressed state is what drives the map filter */
.legend-btn {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  font-family: var(--font-sans);
  font-size: .86rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 6px;
  cursor: pointer;
  text-align: left;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.legend-btn:hover { background: rgba(103, 14, 54, .08); }
.legend-btn[aria-pressed="true"] {
  background: var(--claret);
  border-color: var(--claret);
  color: var(--parchment);
}
.legend-btn[aria-pressed="true"] .legend-count { color: rgba(242, 239, 230, .75); }
/* the cream swatch's claret ring would vanish against a claret background */
.legend-btn[aria-pressed="true"] .legend-swatch { border-color: rgba(242, 239, 230, .6); }

/* size cue: swatch grows with rank so hue isn't the only signal */
.legend-swatch { border-radius: 50%; flex: none; border: 1.5px solid rgba(34,19,26,.28); }
.legend-swatch--premier-league { width: 19px; height: 19px; background: var(--lv-premier-league); }
.legend-swatch--championship   { width: 17px; height: 17px; background: var(--lv-championship); }
.legend-swatch--league-1       { width: 15px; height: 15px; background: var(--lv-league-1); }
.legend-swatch--league-2       { width: 13px; height: 13px; background: var(--lv-league-2); }
/* cream on a cream panel needs the claret ring to be visible at all */
.legend-swatch--non-league {
  width: 11px; height: 11px;
  background: var(--lv-non-league); border-color: var(--claret);
}
/* off-ladder levels share one mid size so they don't imply a rank */
.legend-swatch--rest-of-uk    { width: 15px; height: 15px; background: var(--lv-rest-of-uk); }
.legend-swatch--womens        { width: 15px; height: 15px; background: var(--lv-womens); }
.legend-swatch--international { width: 15px; height: 15px; background: var(--lv-international); }
.legend-swatch--lost          { width: 15px; height: 15px; background: var(--lv-lost); }

.map-legend .legend-count {
  margin-left: auto;
  font-size: .74rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Leaflet control tweaks to match theme */
.leaflet-bar a {
  color: var(--claret);
  background: var(--parchment);
  border-bottom-color: var(--border);
}
.leaflet-bar a.map-restore-intro {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 700;
}
.leaflet-bar a:hover { background: #fff; }
.leaflet-control-attribution {
  background: rgba(242,239,230,.85) !important;
  font-family: var(--font-sans);
  font-size: 11px;
}

@media (max-width: 640px) {
  .map-intro__inner { padding: 11px 16px; gap: 10px; }
  .map-intro p { font-size: .86rem; }
  .map-legend { max-width: 190px; padding: 10px; }
  .legend-btn { font-size: .8rem; }
  /* collapsed, the legend is just its header - a compact pill over the map */
  .map-legend[data-collapsed="true"] { padding: 8px 12px; }
  .map-legend[data-collapsed="true"] .legend-head { margin-bottom: 0; }
}
