:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --forest: #165a47;
  --forest-dark: #0d4435;
  --cream: #fffdf7;
  --ink: #24332d;
  --muted: #607068;
  --blue: #1677d2;
  --shadow: 0 10px 30px rgba(25, 48, 39, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body,
#app,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #e6ecdd;
  color: var(--ink);
  overscroll-behavior: none;
}

button {
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  position: fixed;
  z-index: 5;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.brand,
.top-actions {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 7px 13px 7px 8px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.brand img {
  flex: 0 0 auto;
  border-radius: 12px;
  margin-right: 9px;
}

.brand strong,
.brand span {
  display: block;
  white-space: nowrap;
}

.brand strong {
  font-size: 15px;
  line-height: 1.15;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.brand span.is-active {
  color: var(--blue);
  font-weight: 700;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.search-panel {
  position: fixed;
  z-index: 7;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  width: min(440px, calc(100% - 500px));
  min-width: 320px;
  transform: translateX(-50%);
}

.search-form {
  position: relative;
  display: flex;
  height: 50px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 17px;
  background: rgba(255, 253, 247, 0.97);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.search-form:focus-within {
  outline: 3px solid rgba(22, 119, 210, 0.2);
}

.search-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  margin-left: 16px;
  border: 2px solid #315a49;
  border-radius: 50%;
}

.search-icon::after {
  display: block;
  width: 7px;
  height: 2px;
  margin: 12px 0 0 11px;
  border-radius: 2px;
  background: #315a49;
  content: "";
  transform: rotate(45deg);
}

#searchInput {
  min-width: 0;
  height: 100%;
  flex: 1 1 auto;
  padding: 0 10px 0 13px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  appearance: none;
}

#searchInput::-webkit-search-cancel-button {
  display: none;
}

#searchInput::placeholder {
  color: #718078;
  font-weight: 500;
}

.search-clear {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  margin-right: 7px;
  border: 0;
  border-radius: 50%;
  background: #edf2e9;
  color: #486057;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.search-results {
  overflow: hidden;
  margin-top: 8px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 17px;
  background: rgba(255, 253, 247, 0.98);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.search-results ul {
  max-height: min(55vh, 430px);
  padding: 0;
  margin: 0;
  overflow-y: auto;
  list-style: none;
}

.search-result {
  display: grid;
  width: 100%;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-top: 1px solid #e9eee5;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.search-result:hover,
.search-result:focus-visible {
  outline: 0;
  background: #eef5ec;
}

.result-symbol {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 11px;
  background: #e6f0e8;
  color: var(--forest);
  font-size: 18px;
  font-weight: 900;
}

.result-symbol[data-kind="trail"] {
  color: #a52a25;
  background: #fce9e5;
}

.result-symbol[data-kind="peak"] {
  color: #725018;
  background: #f7edcf;
}

.result-copy,
.result-copy strong,
.result-copy span {
  display: block;
  min-width: 0;
}

.result-copy strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-copy span,
.result-distance {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.result-distance {
  white-space: nowrap;
}

.search-status {
  padding: 12px 14px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.search-marker {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 3px solid white;
  border-radius: 50% 50% 50% 8px;
  background: #b8322b;
  color: white;
  box-shadow: 0 5px 15px rgba(46, 39, 25, 0.3);
  transform: rotate(-45deg);
}

.search-marker span {
  transform: rotate(45deg);
  font-size: 15px;
  font-weight: 900;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  box-shadow: 0 7px 20px rgba(28, 54, 44, 0.2);
  cursor: pointer;
  font-weight: 750;
  transition: transform 120ms ease, background 120ms ease;
}

.button:active {
  transform: scale(0.97);
}

.button-primary {
  color: white;
  background: var(--forest);
}

.button-primary:hover {
  background: var(--forest-dark);
}

.button-secondary {
  color: var(--forest-dark);
  background: rgba(255, 253, 247, 0.96);
}

.target-icon {
  width: 17px;
  height: 17px;
  border: 2px solid currentColor;
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px var(--forest);
  background: white;
}

.position-card {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 290px;
  padding: 10px 13px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  background: rgba(255, 253, 247, 0.94);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

.route-planner,
.navigation-card {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(430px, calc(100% - 24px));
  padding: 15px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 19px;
  background: rgba(255, 253, 247, 0.97);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  backdrop-filter: blur(16px);
}

.route-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.route-overview-actions {
  position: fixed;
  z-index: 6;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 58px;
  right: 58px;
  display: flex;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

.route-overview-actions .button {
  pointer-events: auto;
  width: auto;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 13px;
}

.route-overview .position-card,
.navigation-active .position-card {
  display: none;
}

.navigation-marker {
  width: 46px;
  height: 46px;
  pointer-events: none;
  z-index: 3;
}

.navigation-marker svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 5px rgba(0, 42, 85, 0.5));
}

.route-heading > div {
  min-width: 0;
  flex: 1;
}

.route-eyebrow,
.route-metrics span {
  display: block;
  color: #6a796f;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.1em;
}

#routeDestination {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-close {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  color: #597066;
  background: #edf2e9;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.travel-modes {
  display: flex;
  gap: 7px;
  margin: 13px 0 10px;
}

.travel-mode {
  flex: 1;
  min-height: 34px;
  border: 1px solid #d9e5d7;
  border-radius: 10px;
  color: #4d6559;
  background: #f2f6ee;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.travel-mode.is-active {
  border-color: var(--forest);
  color: white;
  background: var(--forest);
}

.route-main-button {
  width: 100%;
  min-height: 40px;
}

.route-status {
  min-height: 18px;
  margin: 8px 1px 0;
  color: var(--muted);
  font-size: 12px;
}

.route-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 8px;
}

.route-metrics > div {
  min-width: 0;
  padding: 8px;
  border-radius: 10px;
  background: #eef4e9;
}

.route-metrics strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: #294538;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.elevation-chart {
  display: block;
  width: 100%;
  height: 58px;
  margin: 12px 0 2px;
  border-bottom: 1px solid #d9e5d7;
  overflow: hidden;
}

.elevation-chart polygon {
  fill: rgba(22, 90, 71, 0.13);
}

.elevation-chart polyline {
  fill: none;
  stroke: var(--forest);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.3;
}

.route-actions {
  display: flex;
  gap: 8px;
  margin-top: 9px;
}

.route-actions .button {
  flex: 1;
  min-height: 40px;
  padding: 0 10px;
  font-size: 12px;
}

.navigation-card {
  padding: 16px;
}

.navigation-instruction {
  padding: 4px 2px 12px;
}

.navigation-instruction span {
  display: block;
  color: var(--blue);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.09em;
}

.navigation-instruction strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.2;
}

.navigation-summary {
  display: flex;
  justify-content: space-between;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 11px;
  background: #eef4e9;
  color: #557065;
  font-size: 11px;
}

.navigation-summary strong {
  color: #294538;
  font-size: 12px;
}

.navigation-card .button-danger {
  width: 100%;
  min-height: 38px;
  margin-top: 10px;
}

.position-label {
  display: block;
  color: var(--blue);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.11em;
}

#coordinates {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.accuracy {
  margin-left: auto;
  padding: 6px 9px;
  border-radius: 999px;
  background: #e7f2fd;
  color: #115d9e;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.round-button {
  position: fixed;
  z-index: 5;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 253, 247, 0.96);
  color: var(--forest);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 900;
}

.help-button {
  left: max(12px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
}

.offline-button {
  left: max(12px, env(safe-area-inset-left));
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 52px);
  color: white;
  background: var(--forest);
  font-size: 22px;
}

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  top: calc(max(12px, env(safe-area-inset-top)) + 78px);
  max-width: min(420px, calc(100vw - 28px));
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(26, 40, 34, 0.94);
  color: white;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  text-align: center;
  font-size: 13px;
}

.app-dialog {
  width: min(430px, calc(100% - 28px));
  border: 0;
  border-radius: 22px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(9, 31, 23, 0.34);
}

.app-dialog::backdrop {
  background: rgba(14, 31, 25, 0.48);
  backdrop-filter: blur(3px);
}

.app-dialog form {
  padding: 22px;
}

.dialog-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.dialog-heading img {
  border-radius: 15px;
}

.dialog-heading h1,
.dialog-heading p {
  margin: 0;
}

.dialog-heading h1 {
  font-size: 21px;
}

.dialog-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.app-dialog ul {
  padding-left: 21px;
  line-height: 1.48;
  font-size: 14px;
}

.app-dialog li + li {
  margin-top: 7px;
}

.install-help {
  padding: 11px 12px;
  border-radius: 12px;
  background: #eef4e7;
  color: #365346;
  font-size: 13px;
  line-height: 1.4;
}

.dialog-close {
  width: 100%;
  margin-top: 4px;
}

.offline-mark {
  display: grid;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 15px;
  color: white;
  background: var(--forest);
  font-size: 27px;
  font-weight: 900;
}

.offline-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0 12px;
}

.offline-summary > div {
  min-width: 0;
  padding: 10px;
  border-radius: 12px;
  background: #f0f4e9;
}

.offline-summary span,
.offline-summary strong {
  display: block;
}

.offline-summary span {
  color: #6a796f;
  font-size: 8px;
  font-weight: 850;
  letter-spacing: 0.09em;
}

.offline-summary strong {
  margin-top: 5px;
  overflow: hidden;
  color: #294538;
  font-size: 12px;
  text-overflow: ellipsis;
}

.offline-note,
.offline-saved,
.offline-status {
  font-size: 13px;
  line-height: 1.42;
}

.offline-note {
  margin: 0 0 10px;
  color: var(--muted);
}

.offline-saved {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 11px;
  color: #305447;
  background: #e8f2e8;
}

.offline-status {
  min-height: 20px;
  margin: 8px 0 10px;
  color: #455b51;
}

.offline-dialog progress {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  accent-color: var(--forest);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dialog-actions .button {
  flex: 1 1 auto;
}

.button-danger {
  color: #9a342e;
  background: #fdeae7;
  box-shadow: none;
}

.maplibregl-ctrl-bottom-right {
  right: max(6px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
}

.maplibregl-ctrl-group {
  overflow: hidden;
  border-radius: 13px;
  box-shadow: var(--shadow);
}

.maplibregl-user-location-dot,
.maplibregl-user-location-dot:before {
  background-color: #1688e6;
}

.maplibregl-user-location-accuracy-circle {
  background-color: rgba(22, 136, 230, 0.13);
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
  }

  .brand {
    padding-right: 10px;
  }

  .brand img {
    width: 38px;
    height: 38px;
  }

  .button {
    padding: 0 13px;
  }

  .button-secondary {
    width: 44px;
    padding: 0;
    font-size: 0;
  }

  .button-secondary span {
    font-size: 20px;
  }

  .position-card {
    min-width: 0;
    width: calc(100% - 126px);
    max-width: 360px;
  }

  .search-panel {
    top: calc(max(12px, env(safe-area-inset-top)) + 62px);
    width: calc(100% - 24px);
    min-width: 0;
  }

  .search-form {
    height: 46px;
  }
}

@media (min-width: 641px) and (max-width: 980px) {
  .search-panel {
    top: calc(max(12px, env(safe-area-inset-top)) + 66px);
    width: min(500px, calc(100% - 24px));
  }
}

@media (max-width: 430px) {
  .brand span {
    max-width: 128px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .top-actions .button-primary {
    width: 46px;
    padding: 0;
    font-size: 0;
  }

  .top-actions .target-icon {
    width: 19px;
    height: 19px;
  }

  .offline-summary {
    grid-template-columns: 1fr 1fr;
  }

  .offline-summary > div:first-child {
    grid-column: 1 / -1;
  }

  .route-metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .route-actions {
    flex-direction: column;
  }

  .navigation-summary {
    flex-wrap: wrap;
  }
}

@media (display-mode: standalone) {
  #installButton {
    display: none;
  }
}
