:root {
  --bg: #f4f6fb;
  --bg-gradient: linear-gradient(160deg, #f9fbff 0%, #eef2ff 40%, #f4f6fb 100%);
  --text: #111a2e;
  --muted: #5a637a;
  --card: rgba(255, 255, 255, 0.92);
  --border: rgba(20, 32, 56, 0.12);
  --shadow-lg: 0 28px 60px -35px rgba(20, 32, 56, 0.5);
  --shadow-sm: 0 18px 40px -32px rgba(20, 32, 56, 0.45);
  --primary-bg: linear-gradient(135deg, #2563ff 0%, #19a2ff 100%);
  --primary-text: #ffffff;
  --accent: #2563ff;
  --accent-soft: rgba(37, 99, 255, 0.12);
  --accent-border: rgba(37, 99, 255, 0.28);
  --outline: rgba(37, 99, 255, 0.4);
  --toast-bg: rgba(20, 32, 56, 0.88);
  --toast-text: #ffffff;
  --scale-bg: rgba(255, 255, 255, 0.92);
  --btn-glass-bg: rgba(255, 255, 255, 0.6);
  --btn-glass-border: rgba(20, 32, 56, 0.16);
  --btn-glass-highlight: rgba(255, 255, 255, 0.65);
  --success-bg: linear-gradient(135deg, rgba(16,185,129,0.98), rgba(16,185,129,0.9));
  --purple-bg: linear-gradient(135deg, #7c3aed 0%, #a855f7 50%, #ec4899 100%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #05060d;
    --bg-gradient: linear-gradient(180deg, #0b1120 0%, #05060d 100%);
    --text: #e8edf8;
    --muted: #96a1c2;
    --card: rgba(14, 21, 34, 0.96);
    --border: rgba(150, 170, 220, 0.16);
    --shadow-lg: 0 30px 70px -40px rgba(0, 0, 0, 0.85);
    --shadow-sm: 0 20px 50px -38px rgba(0, 0, 0, 0.78);
    --primary-bg: linear-gradient(135deg, #6a8bff 0%, #36d2ff 100%);
    --primary-text: #031024;
    --accent: #6a8bff;
    --accent-soft: rgba(106, 139, 255, 0.18);
    --accent-border: rgba(106, 139, 255, 0.36);
    --outline: rgba(106, 139, 255, 0.48);
    --toast-bg: rgba(5, 7, 16, 0.9);
    --toast-text: #e8edf8;
    --scale-bg: rgba(14, 21, 34, 0.9);
    --btn-glass-bg: rgba(21, 27, 43, 0.6);
    --btn-glass-border: rgba(150, 170, 220, 0.2);
    --btn-glass-highlight: rgba(255, 255, 255, 0.08);
    --success-bg: linear-gradient(135deg, rgba(16,185,129,0.9), rgba(16,185,129,0.85));
    --purple-bg: linear-gradient(135deg, #8b5cf6 0%, #c084fc 50%, #f0abfc 100%);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-gradient);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: rgba(37, 99, 255, 0.35);
  color: #ffffff;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  backdrop-filter: blur(14px);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.topbar-inner { display: flex; align-items: center; gap: 12px; padding: 12px clamp(16px, 4vw, 32px); }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: 0.01em; }

.container {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 26px clamp(16px, 5vw, 36px) 40px;
  display: grid;
  gap: 24px;
}

.actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.btn {
  appearance: none;
  cursor: pointer;
  border: 1px solid var(--btn-glass-border);
  background: var(--btn-glass-bg);
  color: var(--text);
  border-radius: 18px;
  padding: 16px 22px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px) saturate(160%);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
  position: relative;
  overflow: hidden;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 24px 48px -32px rgba(20, 32, 56, 0.55);
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, var(--btn-glass-highlight), transparent 40%);
  pointer-events: none;
  opacity: 0.7;
}

.btn.primary {
  background: var(--primary-bg);
  color: var(--primary-text);
  border-color: transparent;
  backdrop-filter: blur(12px) saturate(160%);
  box-shadow: 0 20px 40px -26px rgba(37, 99, 255, 0.6);
}

.btn.active {
  background: linear-gradient(135deg, rgba(37, 99, 255, 0.9), rgba(25, 162, 255, 0.9));
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 25px 48px -30px rgba(37, 99, 255, 0.75);
}

.btn.ghost {
  background: transparent;
  border-color: var(--btn-glass-border);
  backdrop-filter: none;
  box-shadow: none;
}
.btn.ghost:hover {
  background: var(--accent-soft);
  box-shadow: none;
}

.btn.purple {
  background: var(--purple-bg);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 24px 48px -28px rgba(124, 58, 237, 0.65);
}

.btn[disabled] {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn:focus-visible {
  outline: 3px solid var(--outline);
  outline-offset: 3px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 24px clamp(22px, 5vw, 32px);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.card h2 {
  font-size: 19px;
  font-weight: 600;
  margin: 0 0 18px 0;
}

.details {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}

.row {
  display: flex;
  gap: 12px;
  align-items: baseline;
}

.row .label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-width: 96px;
}

.value {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
}

.row-elevation {
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 22px;
  border-radius: 20px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.row-elevation .label {
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.value-elevation {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: clamp(44px, 10vw, 58px);
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.value-elevation span::after {
  content: '';
}

.value-elevation span[data-ready="true"]::after {
  content: ' m';
  font-size: clamp(16px, 4vw, 20px);
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
}

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

.actions-below { margin-top: 12px; }

.actions-inline .btn {
  min-width: 170px;
}

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

.status {
  margin-top: 14px;
  min-height: 1.3em;
  font-size: 15px;
  color: var(--muted);
}

.map-wrap {
  height: clamp(360px, 60vh, 540px);
  border-radius: 26px;
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.map {
  height: 100%;
  width: 100%;
}

.map::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid var(--border);
  border-radius: 26px;
  pointer-events: none;
}

.select-mode .leaflet-container,
.map.select-mode {
  cursor: crosshair !important;
}

.leaflet-control-scale-line {
  color: var(--text);
  border-color: var(--border);
  background: var(--scale-bg);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%) translateY(22px);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 12px 20px;
  border-radius: 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: 0 18px 38px -20px rgba(0, 0, 0, 0.45);
  z-index: 2000; /* Above Leaflet popups (700) and controls */
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: var(--success-bg);
}

@media (hover: none) and (pointer: coarse) {
  .btn {
    padding: 18px 24px;
    font-size: 18px;
  }
  .topbar .back { display: none; }
}

.intro-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 16, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1000;
}

.intro-overlay.show {
  display: flex;
}

.intro-card {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 22px;
  max-width: 480px;
  width: 100%;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.intro-card h2 {
  margin: 0 0 12px 0;
  font-size: 20px;
}

.intro-card p {
  margin: 0 0 18px 0;
  color: var(--muted);
  font-size: 15px;
}
