:root {
  color-scheme: light;
  --stage: #d7dbd2;
  --bg: #f4f6f2;
  --panel: #ffffff;
  --ink: #14170f;
  --muted: #666f60;
  --line: #d9ddd1;
  --soft: #edf0e7;
  --accent: #dfff32;
  --accent-ink: #172000;
  --teal: #167267;
  --red: #b42318;
  --display: "Anton", "Arial Narrow", sans-serif;
  --body: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--stage);
  color: var(--ink);
  font-family: var(--body);
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.stage {
  min-height: 100vh;
  padding: clamp(0px, 3vw, 28px) 0;
  background:
    radial-gradient(120% 160% at 8% -10%, rgba(223, 255, 50, 0.14), transparent 55%),
    var(--stage);
}

.app-shell {
  width: min(1320px, calc(100vw - 32px));
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(20, 23, 15, 0.14);
  overflow: hidden;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--ink);
  color: var(--bg);
  padding: 14px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: var(--ink);
  border: 1.5px solid var(--accent);
}

.brand-text {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: #9aa78f;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand-name {
  margin: 0;
  font-family: var(--display);
  font-size: 1.2rem;
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--bg);
}

.source-link {
  flex: none;
  min-height: 36px;
  border: 1px solid #3a4034;
  background: transparent;
  color: var(--bg);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 700;
}

.source-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Search / locator bar */
.locator-bar {
  display: grid;
  gap: 16px;
  padding: 22px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

h1 {
  font-family: var(--display);
  font-size: clamp(1.9rem, 3.6vw, 3rem);
  line-height: 0.96;
  letter-spacing: 0.005em;
  text-transform: uppercase;
  max-width: 22ch;
}

h2 {
  font-family: var(--display);
  font-size: 1.02rem;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

h3 {
  font-size: 1rem;
  line-height: 1.25;
  font-weight: 700;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
  margin-bottom: 12px;
}

.map-hint {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
}

button,
.map-link {
  min-height: 44px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  transition: transform 0.12s ease, background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

/*
 * Leaflet's own stylesheet targets ".leaflet-container a" (class + type),
 * which outranks a bare ".map-link" class selector for popup content.
 * Repeat the type selector here so map-link color/background always wins,
 * regardless of whether the link renders inside a Leaflet popup.
 */
button,
a.map-link {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
}

button:hover,
a.map-link:hover {
  background: #232920;
}

button.secondary {
  background: var(--panel);
  color: var(--ink);
}

button.secondary:hover {
  background: var(--soft);
}

button:disabled {
  cursor: default;
  background: var(--soft);
  color: var(--muted);
  border-color: var(--line);
}

.search-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
}

.input-wrap {
  position: relative;
  color: var(--muted);
}

.input-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px 0 36px;
  /* Overrides the `font: inherit` reset above: without an explicit size,
     inputs nested in a <label> inherit its small 0.8rem caption text, and
     any input under 16px triggers iOS Safari's auto-zoom-on-focus. */
  font-size: 1rem;
}

input:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(22, 114, 103, 0.32);
  outline-offset: 2px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.status {
  min-height: 20px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.status[data-tone="success"] {
  color: var(--teal);
}

.status[data-tone="error"] {
  color: var(--red);
}

/* Layout */
.finder-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  align-items: stretch;
  gap: 1px;
  background: var(--line);
}

/* Both panels stretch to the same grid height; pinning their inner content
   to explicit rows (heading / fill / pager) keeps their bottom edges flush
   instead of ending at unrelated 100vh-based caps. */
.map-panel,
.results-panel {
  min-height: calc(100vh - 260px);
  padding: 16px;
  background: var(--bg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.results-panel {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.pill {
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

/* Map */
.map-canvas-wrap {
  position: relative;
  height: auto;
  min-height: 420px;
  border: 1px solid var(--line);
}

.map-canvas {
  position: absolute;
  inset: 0;
  background: #e9e5d8;
}

.map-empty-overlay {
  position: absolute;
  inset: 0;
  z-index: 400;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.map-empty-overlay[hidden] {
  display: none;
}

.map-empty-overlay .empty-map {
  border: 1px solid var(--line);
  background: rgba(244, 246, 242, 0.92);
  min-height: 0;
  padding: 16px 20px;
}

.origin-pin-wrap,
.gym-pin-wrap {
  background: transparent;
  border: none;
}

.recenter-btn {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 500;
  width: 42px;
  min-height: 42px;
  padding: 0;
  border: 1px solid var(--ink);
  background: var(--panel);
  color: var(--ink);
}

.recenter-btn:hover {
  background: var(--soft);
}

@keyframes hg-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(223, 255, 50, 0.55);
  }
  70% {
    box-shadow: 0 0 0 14px rgba(223, 255, 50, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(223, 255, 50, 0);
  }
}

.origin-pin {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--accent);
  display: grid;
  place-items: center;
  animation: hg-pulse 2.2s infinite;
}

.origin-pin span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--ink);
}

.gym-pin {
  border-radius: 999px;
  border: 2px solid #ffffff;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-family: var(--body);
  color: #ffffff;
  background: var(--teal);
  box-shadow: 0 2px 6px rgba(20, 23, 15, 0.25);
  width: 30px;
  height: 30px;
  font-size: 0.78rem;
  transition: transform 0.12s ease, background-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

.gym-pin:hover {
  background: var(--ink);
  color: var(--accent);
  transform: scale(1.15);
  box-shadow: 0 4px 10px rgba(20, 23, 15, 0.35);
}

.gym-pin.is-selected {
  width: 40px;
  height: 40px;
  font-size: 0.9rem;
  background: var(--ink);
  color: var(--accent);
  box-shadow: 0 6px 16px rgba(20, 23, 15, 0.4);
}

.gym-pin.is-selected:hover {
  background: var(--teal);
  color: #ffffff;
  transform: scale(1.08);
  box-shadow: 0 8px 20px rgba(20, 23, 15, 0.45);
}

.map-popup .leaflet-popup-content-wrapper {
  border-radius: 0;
  border: 1px solid var(--ink);
  box-shadow: 0 10px 24px rgba(20, 23, 15, 0.22);
}

.map-popup .leaflet-popup-content {
  margin: 12px 14px;
  font-family: var(--body);
}

.map-popup .leaflet-popup-tip {
  border: 1px solid var(--ink);
}

.popup-card {
  display: grid;
  gap: 6px;
  min-width: 200px;
}

.popup-kicker {
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.popup-card p {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.popup-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.popup-links .map-link {
  min-height: 30px;
  padding: 0 9px;
  font-size: 0.74rem;
}

.leaflet-control-attribution {
  font-family: var(--body);
  font-size: 10px;
}

/* Leaflet's default zoom buttons are 30x30px, under the 44x44px minimum
   touch target every other control in this app already meets. */
.leaflet-bar a.leaflet-control-zoom-in,
.leaflet-bar a.leaflet-control-zoom-out {
  width: 44px;
  height: 44px;
  line-height: 44px;
  font-size: 1.1rem;
}

.empty-map {
  display: grid;
  place-content: center;
  gap: 8px;
  min-height: 240px;
  padding: 18px;
  text-align: center;
}

.empty-map strong {
  font-size: 1rem;
}

.empty-map span,
.empty-state p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

/* Results */
.results-list {
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.results-pager {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.results-pager[hidden] {
  display: none;
}

.results-pager .pager-status {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.results-pager button {
  min-height: 40px;
  padding: 0 14px;
  font-size: 0.8rem;
}

.result-card {
  display: grid;
  width: 100%;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.result-card.is-selected {
  border-color: var(--ink);
  border-width: 2px;
  padding: 11px;
  box-shadow: inset 4px 0 0 var(--accent);
}

.result-hit {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-height: 0;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.result-hit:hover .rank {
  background: var(--ink);
  color: var(--accent);
}

.result-card.is-selected .result-hit:hover .rank {
  background: var(--teal);
  color: #ffffff;
}

.rank {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 900;
  font-family: var(--display);
  font-size: 1.02rem;
}

.result-card.is-selected .rank {
  background: var(--ink);
  color: var(--accent);
}

.result-body {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.result-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.result-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
  line-height: 1.25;
}

.result-title span {
  white-space: nowrap;
  color: var(--teal);
  font-weight: 900;
  font-size: 0.84rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: max-content;
  border: 1px solid var(--teal);
  color: var(--teal);
  padding: 2px 7px;
  font-size: 0.64rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result-region {
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
}

.result-address {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.result-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.map-link {
  width: max-content;
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.78rem;
}

a.map-link.secondary {
  background: var(--panel);
  color: var(--ink);
}

a.map-link.secondary:hover {
  background: var(--soft);
}

.empty-state {
  display: grid;
  place-content: center;
  gap: 12px;
  min-height: 280px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 18px;
  text-align: center;
}

.mobile-view-toggle {
  display: none;
}

@media (max-width: 920px) {
  .stage {
    padding: 0;
  }

  .app-shell {
    width: 100%;
    border-inline: none;
    box-shadow: none;
  }

  .finder-layout {
    grid-template-columns: 1fr;
  }

  .actions button {
    width: 100%;
  }

  .map-panel,
  .results-panel {
    min-height: auto;
  }

  .map-canvas-wrap {
    height: 60vh;
    min-height: 360px;
  }

  .results-list {
    max-height: none;
  }

  /* Mobile-only List/Map toggle: reaching the actionable ranked list
     shouldn't require scrolling past the whole map first. Desktop keeps
     the existing side-by-side layout untouched (toggle hidden above). */
  .mobile-view-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--line);
    border-bottom: 1px solid var(--line);
  }

  .mobile-view-btn {
    min-height: 46px;
    border: none;
    border-radius: 0;
    background: var(--bg);
    color: var(--muted);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.82rem;
    letter-spacing: 0.02em;
  }

  .mobile-view-btn[aria-selected="true"] {
    background: var(--ink);
    color: var(--accent);
  }

  .finder-layout[data-mobile-view="list"] .map-panel {
    display: none;
  }

  .finder-layout[data-mobile-view="map"] .results-panel {
    display: none;
  }
}

@media (max-width: 520px) {
  .app-header {
    padding: 12px 14px;
  }

  .locator-bar,
  .map-panel,
  .results-panel {
    padding: 14px;
  }

  .result-links,
  .result-links .map-link {
    width: 100%;
  }

  .result-links {
    flex-direction: column;
  }

  .map-canvas-wrap {
    height: 52vh;
    min-height: 320px;
  }
}
