:root {
  --accent: #3b5bdb;
  --accent-soft: #edf2ff;
  --ink: #1f2328;
  --muted: #6a737d;
  --line: #e4e7eb;
  --bg: #fff;
  --danger: #c92a2a;
  --panel-w: 340px;
  --profile-h: 140px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
#map { position: fixed; inset: 0; }

.panel {
  position: fixed; top: 12px; left: 12px; bottom: 12px; width: var(--panel-w);
  background: var(--bg); border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.18);
  overflow-y: auto; z-index: 1000; padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; }
h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.tag { font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 99px; }
section { display: flex; flex-direction: column; gap: 8px; }

button, .btn {
  font: inherit; font-size: 13px; padding: 7px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #f8f9fa; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; white-space: nowrap;
}
button:hover, .btn:hover { background: #eef0f3; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #364fc7; }
button.danger { color: var(--danger); }
button.icon { width: 36px; padding: 0; font-size: 16px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

input.text, .search input, select, .field input {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.field.inline select, .field.inline input { width: 55%; }

.search { display: flex; gap: 6px; }
.results, .saved { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.results:empty { display: none; }
.results li, .saved li {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; background: #f8f9fa;
}
.results li .name, .saved li .name { flex: 1; min-width: 0; cursor: pointer; }
.results li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.results li button, .saved li button { padding: 3px 8px; font-size: 12px; }
.saved .meta { display: block; font-size: 11px; color: var(--muted); }
.saved li .name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 13px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--accent-soft); border-radius: 10px; padding: 8px 10px; }
.stat span { display: block; font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat label { font-size: 11px; color: var(--muted); }
.stats .note { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--muted); }
.stats .note.warn { color: var(--danger); }

.hint, .credits { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.45; }
.credits a { color: inherit; }

/* Waypoint markers */
.wp {
  border-radius: 50%; display: grid; place-items: center; color: #fff;
  font: 700 11px/1 system-ui, sans-serif; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45);
}
.wp-start { background: #2f9e44; }
.wp-end { background: #e03131; }
.wp-via { background: #fff; border: 3px solid var(--accent); }
.wp-pop { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.wp-pop button { font-size: 12px; padding: 4px 8px; color: var(--danger); }

/* Elevation profile */
.profile {
  position: fixed; left: calc(var(--panel-w) + 24px); right: 12px; bottom: 12px; height: var(--profile-h);
  background: rgba(255,255,255,.96); border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.16); z-index: 900;
}
.profile canvas { position: absolute; inset: 0; }
#profileOverlay { cursor: crosshair; touch-action: none; }
.tip {
  position: absolute; top: 6px; transform: translateX(-50%); pointer-events: none; display: none;
  background: var(--ink); color: #fff; font-size: 12px; padding: 3px 8px; border-radius: 6px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
body.has-profile .leaflet-bottom { bottom: calc(var(--profile-h) + 12px); }

.toast {
  position: fixed; left: 50%; top: 14px; transform: translate(-50%, -80px); transition: transform .2s;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 2000;
  font-size: 13px; max-width: min(90vw, 520px); box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast.show { transform: translate(-50%, 0); }

/* Compare */
.btn.wide { width: 100%; }
.wp-b { background: #f76707; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
.dot.a { background: var(--accent); }
.dot.b { background: #f76707; }
.compare-table table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.compare-table th, .compare-table td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.compare-table th:first-child, .compare-table td:first-child { text-align: left; color: var(--muted); font-weight: 500; }
.compare-table thead th { font-size: 11px; font-weight: 600; vertical-align: bottom; }
.compare-table thead th .nm { display: inline-block; max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.compare-table td { white-space: nowrap; }
.compare-table td.delta { color: var(--muted); }
.tip .row { display: block; }

#map2 { position: fixed; top: 0; bottom: 0; right: 0; width: 50%; display: none; border-left: 3px solid #fff; }
body.split #map { right: 50%; }
body.split #map2 { display: block; }
.map-label {
  display: none; position: fixed; top: 12px; left: calc(50% + 14px); z-index: 950; max-width: 40%;
  background: #fff; border-radius: 8px; padding: 5px 10px; font-size: 13px; font-weight: 600;
  box-shadow: 0 2px 10px rgba(0,0,0,.2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.split .map-label { display: block; }

.hidden { display: none !important; }
.panel-toggle { display: none; }

@media (max-width: 760px) {
  :root { --profile-h: 110px; }
  .panel {
    top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 72vh;
    transform: translateY(calc(100% + 20px)); transition: transform .2s;
  }
  body.panel-open .panel { transform: none; }
  .panel-toggle {
    display: block; position: fixed; top: 10px; left: 10px; z-index: 1001;
    background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.2); font-weight: 600;
  }
  .profile { left: 8px; right: 8px; bottom: 8px; }
  body.panel-open .profile { display: none; }
  body.split #map { right: 0; bottom: 50%; }
  body.split #map2 { width: auto; left: 0; top: 50%; border-left: 0; border-top: 3px solid #fff; }
  .map-label { left: 12px; top: calc(50% + 12px); max-width: 70%; }
}
