*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Homenaje", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.01em;
  background: #f6f7fb;
  color: #1f2630;
}

/* Homenaje only ships one weight, so emulate emphasis without faux-bold
   wobble by keeping weight 400 and leaning on color/size for hierarchy. */
strong,
b {
  font-weight: 400;
}

.page-shell {
  width: min(1040px, 100% - 2.5rem);
  margin: 1.4rem auto 1.6rem;
}

.intro {
  margin-bottom: 1.2rem;
}

.app-title {
  margin: 0 0 0.8rem;
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  line-height: 1.05;
  color: #fc4c02;
  letter-spacing: 0.01em;
}

.intro-copy {
  margin: 0;
  max-width: 72ch;
  font-size: clamp(0.95rem, 1.8vw, 1.12rem);
  line-height: 1.55;
  color: #3a4558;
}

.map-frame {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.9rem 1.1rem;
  padding: 1rem 1.1rem;
  background: #fff;
  border: 1px solid #dce3ef;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(20, 31, 46, 0.05);
}

.map-wrap {
  position: relative;
}

#map {
  width: 100%;
  height: clamp(340px, 56vh, 540px);
  min-height: 320px;
  border: 1px solid #cfd7e6;
  border-radius: 10px;
  overflow: hidden;
}

/* Compact status pill shown while a route is generating. It sits at the top
   of the map so the live "show the work" animation underneath stays visible. */
.map-loading {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  max-width: calc(100% - 24px);
  padding: 0.45rem 0.85rem;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #ecc8b7;
  border-radius: 999px;
  box-shadow: 0 3px 12px rgba(20, 31, 46, 0.16);
}

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

.spinner {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(252, 76, 2, 0.25);
  border-top-color: #fc4c02;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.map-loading-text {
  font-size: 0.86rem;
  color: #2a3550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.field {
  flex: 1 1 280px;
  margin: 0;
}

.field label {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 0.45rem;
  color: #253047;
}

.distance-readout {
  font-weight: 600;
  color: #fc4c02;
}

.search-field {
  position: relative;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.42rem 0.55rem;
  font: inherit;
  font-size: 0.92rem;
  color: #1f2630;
  background: #fff;
  border: 1px solid #c5cee0;
  border-radius: 6px;
  -webkit-appearance: none;
  appearance: none;
}

.search-input:focus-visible {
  outline: 2px solid #fc4c02;
  outline-offset: 1px;
  border-color: #fc4c02;
}

.search-btn {
  flex: 0 0 auto;
  padding: 0.42rem 0.75rem;
  font: inherit;
  font-size: 0.9rem;
  color: #2a3550;
  background: #f2f5fb;
  border: 1px solid #c5cee0;
  border-radius: 6px;
  cursor: pointer;
}

.search-btn:hover {
  background: #e7ecf7;
}

.search-btn:focus-visible {
  outline: 2px solid #fc4c02;
  outline-offset: 2px;
}

.search-btn:disabled {
  cursor: progress;
  opacity: 0.6;
}

/* The match list overlays the panel instead of pushing the controls down.
   Leaflet's map panes sit at z-index 400, so this has to clear that. */
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1000;
  max-height: 232px;
  margin: 0;
  padding: 0.25rem;
  overflow-y: auto;
  list-style: none;
  background: #fff;
  border: 1px solid #c5cee0;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(20, 31, 46, 0.16);
}

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

.search-result-btn {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  font: inherit;
  text-align: left;
  color: #253047;
  background: none;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

/* `is-active` is the arrow-key highlight; it matches hover so both feel the
   same whether the user is on a mouse or the keyboard. */
.search-result-btn:hover,
.search-result-btn:focus-visible,
.search-result-btn.is-active {
  outline: none;
  background: #fff1ea;
  color: #b93a02;
}

.search-result-primary {
  font-size: 0.9rem;
  line-height: 1.3;
}

.search-result-secondary {
  font-size: 0.78rem;
  line-height: 1.25;
  color: #6b7690;
}

.search-result-btn:hover .search-result-secondary,
.search-result-btn:focus-visible .search-result-secondary,
.search-result-btn.is-active .search-result-secondary {
  color: #a8562f;
}

.search-empty {
  padding: 0.45rem 0.55rem;
  font-size: 0.84rem;
  color: #6b7690;
}

#distance-slider {
  width: 100%;
}

.distance-controls {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.distance-controls #distance-slider {
  flex: 1 1 auto;
  min-width: 0;
}

.distance-input {
  flex: 0 0 4.5rem;
  width: 4.5rem;
  padding: 0.38rem 0.45rem;
  font: inherit;
  font-size: 0.92rem;
  color: #1f2630;
  background: #fff;
  border: 1px solid #c5cee0;
  border-radius: 6px;
  text-align: right;
  -moz-appearance: textfield;
}

.distance-input::-webkit-outer-spin-button,
.distance-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.distance-input:focus-visible {
  outline: 2px solid #fc4c02;
  outline-offset: 1px;
  border-color: #fc4c02;
}

.distance-input.invalid {
  border-color: #c62828;
  background: #fff5f5;
}

.distance-unit {
  flex: 0 0 auto;
  font-size: 0.88rem;
  color: #47556f;
}

.primary-btn {
  width: 170px;
  padding: 0.62rem 0.9rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: #fc4c02;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  flex: 0 0 auto;
}

.primary-btn:hover {
  background: #e84502;
}

.primary-btn:focus-visible {
  outline: 2px solid #fc4c02;
  outline-offset: 2px;
}

.primary-btn:disabled {
  cursor: wait;
  opacity: 0.75;
}

.route-stats {
  flex: 1 1 100%;
  margin-top: 0.3rem;
  padding-top: 0.8rem;
  border-top: 1px solid #e0e6f2;
}

.stats-heading {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.stats-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #333;
}

.stats-list strong {
  color: #1d2f56;
}

.hint {
  margin: 0;
  flex: 1 1 100%;
  font-size: 0.84rem;
  line-height: 1.35;
  color: #445068;
}

.status-msg {
  margin: 0;
  flex: 1 1 220px;
  min-height: 1.2em;
  font-size: 0.84rem;
  color: #47556f;
}

.status-msg.error {
  color: #c62828;
}

.project-blurb {
  margin: 0;
  padding: 0.3rem 0.2rem 0;
  font-size: 0.9rem;
  line-height: 1.55;
  color: #33415b;
}

.startfinish-flag-icon {
  background: transparent !important;
  border: none !important;
  overflow: visible !important;
}

.route-flag {
  display: flex;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
}

.route-flag-label {
  padding: 5px 10px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.08em;
  background: #ffffff;
  border-radius: 4px;
  border: 2px solid #111111;
  color: #111111;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.22);
  white-space: nowrap;
  text-transform: uppercase;
}

@media (max-width: 740px) {
  .page-shell {
    width: calc(100% - 1rem);
    margin: 0.8rem auto 1rem;
  }

  .control-panel {
    align-items: stretch;
  }

  .primary-btn {
    width: 100%;
  }

  #map {
    height: clamp(300px, 52vh, 460px);
    min-height: 300px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}
