:root {
  --bg: #0f1720;
  --panel: #16212e;
  --panel-2: #1d2b3a;
  --text: #e7eef5;
  --muted: #9fb0c0;
  --accent: #4ea1ff;
  --band-low: #5cb85c;
  --band-mid: #f0ad4e;
  --band-high: #e8743b;
  --band-top: #d9534f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

#app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
}

#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid #0a1118;
}

#sidebar header {
  padding: 18px 18px 12px;
}

h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.3px;
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* Mobile-only map collapse toggle (hidden on desktop where map is always shown). */
.map-toggle {
  display: none;
  margin-top: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #2a3a4c;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.map-toggle:hover {
  border-color: #3d5269;
}

/* Mobile-only "back to top" button. Hidden on desktop and until scrolled. */
.to-top {
  display: none;
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1200;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #06203b;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.to-top.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 18px 14px;
}

.tab {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 6px;
  border-radius: 9px;
  border: 1px solid #2a3a4c;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}

.tab .flag {
  width: 22px;
  height: auto;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.tab-name {
  max-width: 100%;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-sub {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--muted);
}

.tab:hover {
  border-color: #3d5269;
}

.tab.active {
  border-color: var(--accent);
  background: #1b3349;
}

.tab.active .tab-sub {
  color: var(--accent);
}

.controls {
  padding: 0 18px 12px;
  border-bottom: 1px solid #0a1118;
}

#search {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #2a3a4c;
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}

#search:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

.height-filter {
  display: block;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.height-filter span {
  color: var(--text);
  font-weight: 600;
}

#height {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--accent);
}

.climbed-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

#climbed-filter {
  flex: 1;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid #2a3a4c;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

#climbed-filter:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.progress-track {
  flex: 1;
  height: 7px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden;
}

#progress-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: var(--band-low);
  transition: width 0.25s ease;
}

.progress-text {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.count {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}

#list {
  list-style: none;
  margin: 0;
  padding: 6px 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

#list li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
}

#list li:hover {
  background: var(--panel-2);
}

.climb {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.peak-body {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
}

.peak.climbed .peak-body {
  opacity: 0.5;
}

.peak.climbed .name {
  text-decoration: line-through;
  text-decoration-color: var(--muted);
}

#list .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#list .h {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  flex-shrink: 0;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
}

#sidebar footer {
  padding: 12px 18px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid #0a1118;
}

#sidebar footer a {
  color: var(--accent);
}

#map {
  height: 100%;
  background: #0b1016;
}

/* Munro circle markers */
.munro-marker {
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.leaflet-popup-content {
  margin: 12px 14px;
  font-size: 14px;
}

.popup-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}

.popup-height {
  font-size: 16px;
  font-weight: 700;
}

.popup-meta {
  color: #555;
  font-size: 12px;
  margin-top: 4px;
}

.popup-climbed {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #2e8b57;
}

.popup-dist {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #2563c9;
}

/* Locate / nearest-peak / full-screen controls (match Leaflet's zoom control) */
.locate-bar a,
.fs-bar a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  color: #333;
}

.locate-bar a:hover,
.fs-bar a:hover {
  color: var(--accent);
}

.locate-bar svg,
.fs-bar svg {
  display: block;
}

/* Full-screen toggle is mobile-only. */
.fs-bar {
  display: none;
}

/* Transient status toast (location feedback) */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 10px);
  z-index: 1600; /* above the mobile full-screen map */
  max-width: min(90vw, 360px);
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(22, 33, 46, 0.96);
  color: var(--text);
  border: 1px solid #2a3a4c;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

/* Map legend */
.legend {
  background: rgba(22, 33, 46, 0.92);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.8;
}

.legend .dot {
  margin-right: 6px;
}

@media (max-width: 720px) {
  /* Stack into a single scrolling column: a fixed-height map on top, then the
     full sidebar (tabs, controls and the complete peak list) flowing beneath.
     The list expands to its content and the page scrolls — on desktop it keeps
     its own internal scroll inside a fixed-height sidebar. */
  html,
  body {
    height: auto;
  }

  #app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  #map {
    order: -1; /* map sits above the sidebar */
    height: 42vh;
    min-height: 260px;
  }

  #sidebar {
    border-right: none;
    border-top: 1px solid #0a1118;
  }

  #list {
    flex: none;
    overflow: visible; /* grow to full height; the page handles scrolling */
  }

  /* Roomier tap targets for touch. */
  #list li {
    padding: 9px 10px;
    font-size: 15px;
  }

  .climb {
    width: 20px;
    height: 20px;
  }

  /* Reveal the mobile-only controls. */
  .map-toggle {
    display: inline-block;
  }

  .to-top {
    display: flex;
  }

  /* Collapsed map: hand the freed space to the list. */
  body.map-hidden #map {
    display: none;
  }

  /* Full-screen toggle button (top-right of the map). */
  .fs-bar {
    display: block;
  }

  /* Full-screen map: fill the viewport and lock the page behind it. */
  body.map-fullscreen {
    overflow: hidden;
  }

  body.map-fullscreen #map {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 1500;
  }
}
