:root {
  --bg: #f5f5f7;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --accent: #1f5138;
  --accent-contrast: #ffffff;
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(0, 0, 0, 0.08);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.06);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --route-line: #b5432d;
  --wp-mid: #3a3a3c;
  --tab-route: var(--accent);
  --tab-wanderwege: #5b7fd6;
  --tab-gespeichert: #b08d57;
  --tab-einstellungen: #7d7d84;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --accent: #34c185;
    --accent-contrast: #04140c;
    --glass-bg: rgba(30, 30, 32, 0.68);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
    --route-line: #ff8a5c;
    --wp-mid: #c7c7cc;
    --tab-wanderwege: #7c9ce8;
    --tab-gespeichert: #cda86f;
    --tab-einstellungen: #a0a0a8;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app {
  position: relative;
  height: 100vh;
  width: 100%;
}

/* --- Base map --- */

#map {
  position: fixed;
  inset: 0;
}

.maplibregl-ctrl-attrib {
  font-size: 10px;
  background: var(--glass-bg) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-sm) !important;
  color: var(--text-secondary);
}

.maplibregl-ctrl-attrib a {
  color: var(--text-secondary);
}

.maplibregl-ctrl-bottom-left {
  z-index: 950;
  /* Über der Gelände/Satellit-Pille (die bei bottom:20px, ~44px hoch sitzt)
     einhängen, statt sie zu überlappen. */
  bottom: 74px !important;
  left: 10px !important;
}

.maplibregl-ctrl-group {
  background: var(--glass-bg) !important;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}

.maplibregl-ctrl-group button {
  background: transparent !important;
}

.maplibregl-ctrl-group button:hover {
  background: rgba(127, 127, 127, 0.14) !important;
}

.maplibregl-popup-content {
  background: var(--glass-bg) !important;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow) !important;
  color: var(--text);
  padding: 12px 14px !important;
  font-family: inherit;
}

.maplibregl-popup-tip {
  display: none;
}

.peak-popup strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.peak-popup-ele {
  font-size: 12px;
  color: var(--text-secondary);
}

.trail-popup strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.trail-popup-btn {
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.trail-popup-btn:hover {
  filter: brightness(1.08);
}

.poi-popup-category {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: capitalize;
  margin-top: 2px;
}

/* --- Glass panel base --- */

.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

/* --- Top bar --- */

#top-bar {
  position: fixed;
  top: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  z-index: 1000;
}

.menu-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  color: var(--text);
  transition: color 0.15s ease, background 0.15s ease;
}

.menu-btn svg {
  width: 18px;
  height: 18px;
}

.menu-btn:hover {
  color: var(--accent);
}

.menu-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

#brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  color: var(--text);
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
}

#brand:hover {
  background: rgba(127, 127, 127, 0.1);
}

.brand-icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
  flex-shrink: 0;
}

#search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 420px;
  display: flex;
  align-items: center;
  padding: 0 14px;
}

.search-icon {
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 13px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
}

#search-input::placeholder {
  color: var(--text-secondary);
}

#search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  list-style: none;
  margin: 0;
  padding: 6px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
}

#search-results li {
  padding: 9px 10px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  border-radius: 8px;
  color: var(--text);
}

#search-results li:hover {
  background: rgba(127, 127, 127, 0.14);
}

#toolbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  margin-left: auto;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:hover {
  background: rgba(127, 127, 127, 0.16);
  color: var(--accent);
}

.icon-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.icon-btn.active:hover {
  background: var(--accent);
  color: var(--accent-contrast);
}

.divider {
  width: 1px;
  height: 22px;
  background: var(--glass-border);
  margin: 0 3px;
}

/* --- Layer toggle (Gelände / Satellit) --- */

#layer-toggle {
  position: fixed;
  left: 20px;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  z-index: 900;
}

.zoom-indicator {
  padding: 8px 12px 8px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  border-left: 1px solid var(--glass-border);
  margin-left: 2px;
}

.segment {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.segment:hover {
  background: rgba(127, 127, 127, 0.12);
}

.segment.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* --- Sidebar --- */

#sidebar {
  position: fixed;
  top: 88px;
  right: 20px;
  bottom: 20px;
  /* Schrumpft rechtzeitig, damit bei geöffnetem Menü-Drawer (links) links davon
     immer noch sichtbar Kartenfläche bleibt statt dass sich beide überlappen. */
  width: min(560px, calc(100vw - 460px));
  overflow-y: auto;
  padding: 24px 30px 30px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 900;
}

/* --- Hamburger-Menü (links): Wanderwege / Gespeichert / Einstellungen --- */

#menu-drawer {
  position: fixed;
  top: 88px;
  left: 20px;
  bottom: 20px;
  width: min(380px, max(220px, calc(100vw - 640px)));
  overflow-y: auto;
  padding: 22px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 950;
}

#menu-tab-bar {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* --- Tabs --- */

#tab-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
  padding-bottom: 2px;
}

#tab-bar::-webkit-scrollbar {
  display: none;
}

/* Gleicher freischwebender Pill-Look wie #brand / #search-wrap oben */
.tab-btn {
  flex: 1 0 auto;
  white-space: nowrap;
  border: 1px solid var(--glass-border);
  background: rgba(127, 127, 127, 0.08);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 9px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tab-btn:hover {
  background: rgba(127, 127, 127, 0.16);
  color: var(--text);
}

.tab-route.active {
  background: var(--tab-route);
  border-color: var(--tab-route);
  color: var(--accent-contrast);
}

.tab-wanderwege.active {
  background: var(--tab-wanderwege);
  border-color: var(--tab-wanderwege);
  color: #fff;
}

.tab-gespeichert.active {
  background: var(--tab-gespeichert);
  border-color: var(--tab-gespeichert);
  color: #fff;
}

.tab-einstellungen.active {
  background: var(--tab-einstellungen);
  border-color: var(--tab-einstellungen);
  color: #fff;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.tab-hint {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0;
}

/* --- Toggle switches --- */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
}

.toggle-row:not(:last-child) {
  border-bottom: 1px solid var(--glass-border);
}

.toggle-row span {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.toggle-row span small {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
}

.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 24px;
  min-width: 40px;
  border-radius: 12px;
  background: rgba(127, 127, 127, 0.3);
  position: relative;
  cursor: pointer;
  margin: 0;
  transition: background 0.2s ease;
}

.switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease;
}

.switch:checked {
  background: var(--accent);
}

.switch:checked::before {
  transform: translateX(16px);
}

/* --- Settings --- */

#settings {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.setting-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.setting-value {
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

input[type='range'] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(127, 127, 127, 0.25);
  outline: none;
  margin: 4px 0;
}

input[type='range']::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--accent-contrast);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

input[type='range']::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--accent-contrast);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  border: none;
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: rgba(127, 127, 127, 0.1);
  border-radius: var(--radius-sm);
}

.segmented-option {
  flex: 1;
  position: relative;
}

.segmented-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.segmented-option span {
  display: block;
  text-align: center;
  padding: 7px 4px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented-option input:checked + span {
  background: var(--accent);
  color: var(--accent-contrast);
}

#btn-settings-reset {
  width: 100%;
  margin-top: 4px;
}

/* --- Surface composition --- */

#surface-section h2,
#trails-controls + .tab-hint {
  margin-top: 0;
}

#surface-section h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 10px;
  color: var(--text-secondary);
}

#surface-bar {
  display: flex;
  height: 10px;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(127, 127, 127, 0.15);
}

.surface-segment {
  height: 100%;
}

#surface-legend {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#surface-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.surface-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.surface-empty {
  font-style: italic;
}

/* --- Stats --- */

#stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.stat {
  text-align: center;
  padding: 6px 4px;
}

.stat:nth-child(-n + 2) {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--glass-border);
}

.stat:nth-child(n + 3) {
  padding-top: 16px;
}

.stat:nth-child(odd) {
  border-right: 1px solid var(--glass-border);
}

.stat-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-value {
  display: block;
  margin-top: 5px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* --- Elevation chart --- */

#chart-wrap {
  position: relative;
  height: 300px;
}

#chart-placeholder {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 70px;
}

/* --- Saved routes --- */

#saved-routes h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 10px;
  color: var(--text-secondary);
}

#saved-routes-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: rgba(127, 127, 127, 0.08);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 10px;
  outline: none;
}

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

.text-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.text-btn svg {
  width: 15px;
  height: 15px;
}

.text-btn:hover {
  background: rgba(127, 127, 127, 0.12);
}

.text-btn.danger:hover {
  color: #d64545;
  border-color: rgba(214, 69, 69, 0.4);
}

#hint {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0;
}

/* --- Toast --- */

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 11px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  z-index: 2000;
}

/* --- Waypoint markers --- */

.wp-icon {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: grab;
}

.wp-icon:active {
  cursor: grabbing;
}

.wp-start,
.wp-end {
  width: 15px;
  height: 15px;
  border-width: 2.5px;
}

.wp-start {
  background: var(--accent);
}

.wp-end {
  background: var(--route-line);
}

.wp-mid {
  background: var(--wp-mid);
}

/* --- Responsive --- */

@media (max-width: 760px) {
  #sidebar {
    top: auto;
    left: 16px;
    right: 16px;
    bottom: 16px;
    width: auto;
    max-height: 38vh;
  }

  #top-bar {
    left: 16px;
    right: 16px;
    top: 16px;
  }

  #brand span {
    display: none;
  }

  #brand {
    padding: 12px;
  }

  #toolbar-actions {
    margin-left: 0;
  }

  #layer-toggle {
    left: 16px;
    bottom: calc(38vh + 28px);
  }

  #menu-drawer {
    top: auto;
    left: 16px;
    right: 16px;
    bottom: calc(38vh + 28px);
    width: auto;
    max-height: 42vh;
  }
}
