body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
}

#map {
    height: 100vh; /* fallback for browsers without dvh support */
    height: 100dvh; /* mobile Chrome: track the visible viewport as the URL bar shows/hides */
    width: 100%;
}

/* --- CONTROL PANEL --- */
#controls {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 2000;
    width: 340px;
    background: rgba(255, 255, 255, 0.5);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 10px;
    backdrop-filter: blur(5px);
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
}

@media (max-width: 600px) {
    #controls {
        width: auto;
        left: 10px;
        right: 10px;
        top: 10px;
    }

    .live-height-box {
        display: none;
    }
}

#controls.minimized #controls-content {
    display: none;
}

#controls.minimized {
    overflow: hidden;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
}

.header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

h3 {
    margin: 0;
    font-size: 18px;
    color: #333;
    white-space: nowrap;
}

.toggle-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #555;
    padding: 0 5px;
    line-height: 1;
}

/* BUTTONS IN HEADER (INFO & LANGUAGE) */
.circle-btn {
    background: none;
    border: none;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: opacity 0.2s;
    overflow: hidden;
}

.circle-btn:hover {
    color: #2563eb;
}

.info-btn {
    font-size: 14px;
    font-family: serif;
    font-weight: bold;
    font-style: italic;
    color: #555;
}

.share-circle-btn {
    color: #555;
}

/* Share button: Android-style (three connected dots) icon by default; swap to the
   Apple-style icon on Apple platforms (<html class="apple-platform">, set in index.html). */
.share-circle-btn .share-icon-apple {
    display: none;
}

.apple-platform .share-circle-btn .share-icon-android {
    display: none;
}

.apple-platform .share-circle-btn .share-icon-apple {
    display: block;
}

.footer-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 4px;
}

.footer-metrics {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

/* MODAL (COMMON DESIGN) */
.modal-overlay {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fff;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    text-align: center;
}

/* Inline help icon + hover/tap tooltip for each Advanced-settings row. The row
   (a <label>) is the positioning context; the tip spans its width and opens below. */
.modal-content label:has(> .adv-tip) {
    position: relative;
}

.adv-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #c2c2c2;
    color: #fff;
    font: italic 700 11px/1 Georgia, "Times New Roman", serif;
    cursor: help;
    user-select: none;
    -webkit-user-select: none;
}

.adv-help:hover,
.adv-help:focus {
    background: #777;
    outline: none;
}

.adv-tip {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 5px);
    z-index: 30;
    background: #2b2b2b;
    color: #fff;
    padding: 7px 9px;
    border-radius: 6px;
    font-size: 11.5px;
    font-style: normal;
    font-weight: 400;
    line-height: 1.4;
    text-align: left;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

.adv-help:hover + .adv-tip,
.adv-help:focus + .adv-tip {
    display: block;
}

.modal-content h4 {
    margin-top: 0;
    color: #333;
    margin-bottom: 10px;
    font-size: 18px;
}

.modal-content p {
    font-size: 14px;
    color: #555;
    line-height: 1.5;
    margin-bottom: 15px;
}

.modal-content a {
    color: #007bff;
    text-decoration: none;
    font-weight: bold;
}

.modal-content input {
    width: 90%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-family: monospace;
}

.modal-btns {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
}

/* iPhone/iPad "Add to Home Screen" instruction steps */
.ios-install-steps {
    list-style: none;
    padding: 0;
    margin: 14px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ios-install-step {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 14px;
    line-height: 1.4;
    color: #555;
}

.ios-step-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    margin-top: 1px;
    color: #007bff;
}

.save-btn {
    background-color: #28a745;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

.cancel-btn {
    background-color: #6c757d;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.save-btn:hover {
    background-color: #218838;
}

/* OTHER DESIGN */
#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    z-index: 900;
    pointer-events: none;
    display: none;
}

#crosshair::before,
#crosshair::after {
    content: '';
    position: absolute;
    background: var(--crosshair-color, #333);
}

#crosshair::before {
    top: 9px;
    left: 0;
    width: 20px;
    height: 2px;
}

#crosshair::after {
    top: 0;
    left: 9px;
    width: 2px;
    height: 20px;
}

/* Live GPS position marker */
.gps-marker {
    width: 14px;
    height: 14px;
    background: #007bff;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
}

.live-height-box {
    background-color: #e3f2fd;
    border: 1px solid #90caf9;
    color: #1565c0;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 5px;
}

#controls.minimized .live-height-box {
    background-color: rgba(227, 242, 253, 0.6);
    border: 1px solid rgba(144, 202, 249, 0.4);
    backdrop-filter: blur(2px);
}

.live-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
    display: block;
    margin-bottom: 2px;
    color: #555;
}

.live-value {
    font-size: 24px;
    font-weight: 800;
    font-family: monospace;
}

.gold-icon {
    filter: hue-rotate(140deg) saturate(3) brightness(1.1);
}

button {
    cursor: pointer;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    transition: background 0.2s;
}

.action-btn {
    background-color: #d9534f;
    color: white;
    padding: 12px;
    font-size: 14px;
    width: 100%;
    margin-top: 5px;
    transition: all 0.3s ease;
}

.action-btn:hover {
    background-color: #c9302c;
}

.action-btn:disabled {
    background-color: #cccccc;
    color: #666666;
    cursor: not-allowed;
}

.climb-btn {
    background-color: #d9534f;
    color: white;
    padding: 12px;
    font-size: 14px;
    width: 100%;
    margin-top: 5px;
    transition: all 0.3s ease;
}

.climb-btn:hover {
    background-color: #c9302c;
}

.climb-btn:disabled {
    background-color: #cccccc;
    color: #666666;
    cursor: not-allowed;
}

.climb-mode-toggle-row {
    display: flex;
    gap: 6px;
    margin-top: 5px;
}

.climb-mode-btn {
    flex: 1;
    width: auto;
    margin-top: 0;
    padding: 10px;
    font-size: 13px;
}

.slope-btn {
    background-color: #d9534f;
    color: white;
    padding: 12px;
    font-size: 14px;
    width: 100%;
    margin-top: 5px;
    transition: all 0.3s ease;
}

.slope-btn:hover {
    background-color: #c9302c;
}

.slope-btn:disabled {
    background-color: #cccccc;
    color: #666666;
    cursor: not-allowed;
}

/* --- COLLAPSIBLE SECTIONS --- */
.section-group {
    border-top: 1px solid #e0e0e0;
    padding-top: 6px;
    margin-top: 4px;
}

.section-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    cursor: pointer;
    padding: 4px 0;
    user-select: none;
}

.section-header:hover .btn-icon {
    color: #2563eb;
}

.section-header span:not(.section-toggle) {
    font-size: 14px;
    font-weight: 700;
    color: #333;
}

.section-toggle {
    font-size: 16px;
    color: #555;
    line-height: 1;
    opacity: 0.45;
    margin-left: auto;
    display: inline-flex;
    align-items: center;
}

.section-content {
    display: none;
    padding-top: 6px;
}

.gpx-btn {
    background-color: #d9534f;
    color: white;
    padding: 12px;
    font-size: 14px;
    width: 100%;
    margin-top: 5px;
    transition: all 0.3s ease;
}

.gpx-btn:hover {
    background-color: #c9302c;
}

.gpx-clear-btn {
    background-color: #78909C;
    color: white;
    padding: 8px;
    font-size: 13px;
    width: 100%;
    margin-top: 5px;
    transition: all 0.3s ease;
}

.gpx-clear-btn:hover {
    background-color: #546E7A;
}

.gpx-download-btn {
    background-color: #4a7ba6;
    color: white;
    padding: 8px;
    font-size: 13px;
    width: 100%;
    margin-top: 5px;
    transition: all 0.3s ease;
}

.gpx-download-btn:hover {
    background-color: #3a6489;
}

.gpx-action-row {
    display: flex;
    gap: 6px;
    margin-top: 5px;
}

.gpx-action-row .gpx-clear-btn,
.gpx-action-row .gpx-download-btn {
    flex: 1;
    width: auto;
    margin-top: 0;
}

/* --- Points of Interest --- */
.poi-btn {
    background-color: #2e8b57;
    color: white;
    padding: 12px;
    font-size: 14px;
    width: 100%;
    margin-top: 5px;
    transition: all 0.3s ease;
}

.poi-btn:hover {
    background-color: #256f46;
}

.gpx-action-row .gpx-btn,
.gpx-action-row .poi-btn {
    flex: 1;
    width: auto;
    margin-top: 0;
}

.poi-signedin-body {
    margin-top: 4px;
}

.poi-form-field {
    margin-bottom: 10px;
    text-align: left;
}

.poi-form-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #444;
    margin-bottom: 4px;
}

.poi-form-field input[type="text"],
.poi-form-field textarea,
.poi-form-field select {
    width: 100%;
    box-sizing: border-box;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.poi-form-field textarea {
    resize: vertical;
}

.poi-form-coords {
    font-size: 12px;
    color: #666;
    margin: 2px 0 12px;
}

.poi-popup-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.poi-popup-btn {
    flex: 1;
    padding: 5px 8px;
    font-size: 12px;
}

.poi-popup-desc {
    font-size: 13px;
    color: #333;
    margin: 2px 0 4px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.poi-popup-desc a {
    color: #2a6db0;
}

.poi-popup-elev {
    font-size: 11px;
    color: #888;
    margin-top: 4px;
}

.poi-color-swatches {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.poi-color-swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #ccc;
    padding: 0;
    cursor: pointer;
}

.poi-color-swatch.selected {
    box-shadow: 0 0 0 2px #333;
}

#map.poi-placement-active {
    cursor: crosshair;
}

.gpx-track-info {
    background: #f5f5f5;
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.6;
    color: #444;
}

.gpx-track-info span {
    font-weight: 600;
}

.gpx-km-label {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid #666;
    border-radius: 3px;
    padding: 2px 5px;
    font-size: 10px;
    font-weight: 700;
    color: #333;
    white-space: nowrap;
    line-height: normal;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.gpx-elev-label {
    background: rgba(255, 255, 255, 0.92);
    border: 2px solid #D32F2F;
    border-radius: 5px;
    padding: 3px 6px;
    font-size: 11px;
    font-weight: 800;
    color: #B71C1C;
    white-space: nowrap;
    line-height: normal;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.gpx-elev-label.min-elev {
    border-color: #1565C0;
    color: #0D47A1;
}

.gpx-waypoint-label {
    background: rgba(255, 255, 255, 0.92);
    border: 2px solid #2E7D32;
    border-radius: 5px;
    padding: 3px 6px;
    font-size: 11px;
    font-weight: 800;
    color: #1B5E20;
    white-space: nowrap;
    line-height: normal;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.gpx-start-end-label {
    background: rgba(40, 40, 40, 0.88);
    border: 2px solid #fff;
    border-radius: 5px;
    padding: 3px 6px;
    font-size: 11px;
    font-weight: 800;
    color: #fff;
    white-space: nowrap;
    line-height: normal;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.slope-legend {
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    font-size: 12px;
    line-height: 1.6;
}

.slope-legend-title {
    font-weight: bold;
    margin-bottom: 4px;
}

.slope-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.slope-legend-color {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid rgba(0,0,0,0.15);
    display: inline-block;
}

/* While the route-names legend is shown, hide the zoom controls so the legend
   occupies the bottom-right corner on its own. On mobile the groups are instead
   moved to the bottom-left corner by updateZoomControlVisibility(), where this
   selector no longer matches them. The legend stays below the right-docked
   controls panel (#controls, z-index 2000), which is always on top. */
body.route-legend-on .maplibregl-ctrl-bottom-right .maplibregl-ctrl-group {
    display: none;
}

/* Mobile: while the route-names legend is shown, updateZoomControlVisibility()
   moves the GPS + navigation groups into the bottom-left corner (MapLibre's own
   corner CSS mirrors the right-side layout: vertical stack, 10px inset). Hide
   the attribution banner in the meantime. A slope legend sharing the corner
   clears the floated groups so everything stacks in a single column. */
@media (max-width: 600px) {
    body.route-legend-on .maplibregl-ctrl-bottom-left .maplibregl-ctrl-attrib {
        display: none;
    }
    body.route-legend-on .maplibregl-ctrl-bottom-left .slope-legend {
        clear: both;
    }
}

/* While any on-map slider is visible it replaces the bottom-left attribution and
   slope legend (updateMapSliderChrome toggles body.map-sliders-on). Hidden
   per-element rather than hiding the whole corner so the GPS + nav groups
   relocated there by the route legend (rules above) stay visible. */
body.map-sliders-on .maplibregl-ctrl-bottom-left .maplibregl-ctrl-attrib,
body.map-sliders-on .maplibregl-ctrl-bottom-left .slope-legend {
    display: none;
}

.route-legend {
    pointer-events: auto; /* the bottom-right ctrl container is none; re-enable so the refresh button is clickable */
    margin: 0 10px 10px 0; /* match the zoom controls' inset from the map edges */
    background: rgba(255, 255, 255, 0.92);
    padding: 8px 10px;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
    font-size: 12px;
    line-height: 1.5;
    max-height: 40vh;
    max-height: 40dvh;
    max-width: 220px;
    overflow-y: auto;
}

.route-legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
    cursor: pointer;
}

.route-legend-title {
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.route-legend-title .route-legend-color,
.route-legend-title .route-legend-symbol {
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
}

.route-legend-count {
    font-weight: 400;
}

.route-legend-refresh {
    display: none;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 22px;
    flex: 0 0 24px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: #43a047;
    color: #fff;
    cursor: pointer;
}

.route-legend-refresh:hover {
    background: #2e7d32;
}

.route-legend-refresh svg {
    width: 14px;
    height: 14px;
    display: block;
}

.route-legend.stale .route-legend-refresh {
    display: inline-flex;
}

.route-legend-collapse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #555;
    cursor: pointer;
}

.route-legend-collapse:hover {
    background: rgba(0, 0, 0, 0.06);
}

.route-legend-collapse svg {
    width: 16px;
    height: 16px;
    display: block;
    transition: transform 0.15s ease;
}

/* Caret points up when expanded (click to collapse), down when collapsed. */
.route-legend.collapsed .route-legend-collapse svg {
    transform: rotate(180deg);
}

.route-legend.collapsed .route-legend-header {
    margin-bottom: 0;
}

.route-legend.collapsed .route-legend-body {
    display: none;
}

.route-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 2px 0;
    padding: 1px 3px;
    border-radius: 4px;
    cursor: pointer;
}

.route-legend-item:hover {
    background: rgba(0, 0, 0, 0.06);
}

.route-legend-item.active {
    background: rgba(21, 101, 192, 0.15);
    font-weight: 600;
}

.route-legend.isolated .route-legend-item:not(.active) {
    opacity: 0.45;
}

.route-legend-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.route-legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.25);
    flex: 0 0 10px;
}

.route-legend-symbol {
    width: 24px;
    height: 18px;
    flex: 0 0 24px;
    object-fit: contain;
    object-position: center;
}

.route-legend-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.route-legend-msg {
    color: #555;
    font-style: italic;
    margin: 2px 0;
}

.route-legend-footer {
    margin-top: 6px;
    font-size: 10px;
    color: #666;
}

.route-legend-footer a {
    color: inherit;
}

.clear-btn {
    background-color: #6c757d;
    color: white;
    padding: 8px;
    font-size: 13px;
    width: 100%;
    margin-top: 10px;
    transition: background-color 0.2s ease;
}

.clear-btn:hover {
    background-color: #dc3545;
}

.icon-btn {
    background: #f8f9fa;
    border: 1px solid #ced4da;
    padding: 0;
    width: 32px;
    height: 32px;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    margin: 0;
}

.icon-btn:hover {
    background: #e2e6ea;
    color: #2563eb;
}

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

.icon-btn.active {
    background: #1565c0;
    border-color: #1565c0;
    color: #fff;
}

.icon-btn.active:hover {
    background: #0d47a1;
}

.search-group {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    align-items: center;
}

#searchInput {
    flex-grow: 1;
    height: 32px;
    padding: 0 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    line-height: normal;
    outline: none;
    box-sizing: border-box;
    margin: 0;
    appearance: none;
    -webkit-appearance: none;
}

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.control-label {
    font-size: 14px;
    font-weight: 600;
    color: #444;
}

input[type="number"] {
    width: 40px;
    height: 32px;
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 0;
    border-left: none;
    border-right: none;
    text-align: center;
    -moz-appearance: textfield;
    appearance: textfield;
    box-sizing: border-box;
    margin: 0;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.number-input-group {
    display: flex;
    align-items: center;
}

.num-btn {
    width: 30px;
    height: 32px;
    background: #f8f9fa;
    border: 1px solid #ccc;
    color: #333;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    box-sizing: border-box;
    margin: 0;
}

.num-btn:hover {
    background: #e2e6ea;
}

.num-btn:first-child {
    border-radius: 6px 0 0 6px;
}

.num-btn:last-child {
    border-radius: 0 6px 6px 0;
}

.select-container {
    display: flex;
    gap: 5px;
    width: 100%;
}

.layer-row {
    margin-bottom: 0;
    gap: 8px;
    justify-content: flex-start;
}

.layer-row .control-label {
    flex: 0 0 110px;
    white-space: nowrap;
}

.layer-row .select-container {
    width: auto;
    flex: 1 1 0;
    min-width: 0;
}

.layer-row select {
    min-width: 0;
    flex: 1 1 0;
    box-sizing: border-box;
}

select {
    flex-grow: 1;
    padding: 8px 28px 8px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 13px;
    background-color: #fff;
    margin-top: 2px;
}

#edit-key-btn {
    display: none;
    padding: 0 8px;
    font-size: 14px;
    margin-top: 2px;
}

.checkbox-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 5px;
}

/* Two balanced columns (3 checkboxes per side) for the Add routes & POIs section.
   Columns size to content and spread to the panel edges like the legacy rows. */
.checkbox-grid {
    display: grid;
    grid-template-columns: auto auto;
    justify-content: space-between;
    column-gap: 12px;
    row-gap: 6px;
    margin-top: 5px;
    align-items: center;
}

.checkbox-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.checkbox-row label {
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}

#extra-layer-row {
    margin-bottom: 10px;
}

.zoom-badge {
    color: #495057;
    padding: 0;
    font-size: 11px;
    font-weight: bold;
    font-family: monospace;
}

#status {
    font-size: 13px;
    font-weight: 500;
    color: #444;
}

#analysis-canvas,
#single-point-canvas {
    display: none;
}

.coord-box {
    margin-top: 6px;
    background: #f1f3f5;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 4px 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: monospace;
    font-size: 12px;
    gap: 8px;
}

.copy-btn {
    background: white;
    border: 1px solid #ced4da;
    border-radius: 3px;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 12px;
}

.popup-header {
    font-weight: bold;
    font-size: 14px;
    display: block;
    margin-bottom: 2px;
}

.popup-height {
    font-size: 18px;
    color: #d9534f;
    font-weight: 800;
    display: block;
    white-space: nowrap;
    margin-bottom: 2px;
}

.popup-meta {
    font-size: 11px;
    color: #666;
    display: block;
    margin-bottom: 1px;
}

/* Shadow on the whole popup (content + tip) via drop-shadow so the tip blends in
   with no seam line where the triangle meets the box. */
.maplibregl-popup.result-popup {
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.22));
}

.maplibregl-popup.result-popup .maplibregl-popup-content {
    padding: 14px 16px 12px;
    border-radius: 14px;
    border: none;
    background: #fff;
    box-shadow: none;
}

.maplibregl-popup.result-popup .maplibregl-popup-tip {
    border-top-color: #fff;
    border-bottom-color: #fff;
}

/* Pull the tip 1px into the content so no hairline gap (map showing through the
   seam between the box and the triangle) is visible. Scoped per anchor so the
   tip always overlaps toward the content side. */
.maplibregl-popup.result-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.maplibregl-popup.result-popup.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup.result-popup.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
    margin-top: -1px;
}

.maplibregl-popup.result-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.maplibregl-popup.result-popup.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.maplibregl-popup.result-popup.maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
    margin-bottom: -1px;
}

.maplibregl-popup.result-popup .maplibregl-popup-close-button {
    color: #777;
    font-size: 18px;
    line-height: 1;
    padding: 6px 8px 0 0;
}

.maplibregl-popup.result-popup .maplibregl-popup-close-button:hover {
    background: transparent;
    color: #333;
}

/* CHANGELOG ACCORDION */
details summary:hover {
    color: #007bff !important;
}

details[open] summary {
    margin-bottom: 5px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}

/* --- UPDATE NOTIFICATION --- */
.notification-snackbar {
    position: fixed;
    bottom: calc(25px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(calc(100% + 25px + env(safe-area-inset-bottom, 0px) + 20px));
    background: rgba(33, 33, 33, 0.95);
    color: white;
    padding: 12px 20px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 9999;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    width: max-content;
    max-width: 90vw;
}

.notification-snackbar.show {
    transform: translateX(-50%) translateY(0);
}

.notification-snackbar span {
    font-size: 14px;
    font-weight: 500;
}

.notification-snackbar button {
    background-color: #2196F3;
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.notification-snackbar button:hover {
    background-color: #1976D2;
}

/* --- INSTALL BUTTON --- */
#install-app-btn {
    display: none;
    background-color: #2196F3;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
}

#install-app-btn:hover {
    background-color: #1976D2;
}

/* Equal-width buttons in the About modal action row */
#info-modal .modal-btns button {
    flex: 1;
}

/* --- MOBILE INSTALL BAR dismiss button --- */
#mobile-install-dismiss {
    background: transparent !important;
    color: rgba(255, 255, 255, 0.7) !important;
    padding: 2px 6px !important;
    font-size: 15px !important;
    border-radius: 50% !important;
    line-height: 1;
}

#mobile-install-dismiss:hover {
    background: rgba(255, 255, 255, 0.15) !important;
    color: white !important;
}
/* --- TUTORIAL SPOTLIGHT --- */
#tutorial-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 5000;
    pointer-events: none;
}

#tutorial-spotlight,
#tutorial-spotlight-secondary {
    position: absolute;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
    transition: all 0.4s ease;
    pointer-events: none;
}

#tutorial-tooltip {
    position: absolute;
    background: white;
    border-radius: 12px;
    padding: 20px;
    max-width: 320px;
    width: 90vw;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    z-index: 5001;
    transition: all 0.4s ease;
}

#tutorial-tooltip h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: #333;
}

#tutorial-tooltip p {
    margin: 0 0 15px 0;
    font-size: 13px;
    color: #555;
    line-height: 1.6;
    white-space: pre-line;
}

.tutorial-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.tutorial-nav-btn {
    background: #2196F3;
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.tutorial-nav-btn:hover {
    background: #1976D2;
}

#tutorial-progress {
    font-size: 12px;
    color: #999;
    font-weight: 600;
}

#tutorial-prev {
    background: #e0e0e0;
    color: #333;
}

#tutorial-prev:hover {
    background: #bdbdbd;
}

/* --- MAP CONTROLS (zoom / compass / GPS) --- */
/* The global `button` rule (rounded corners + bold) leaks into the native
   MapLibre control buttons; undo it so they keep the default grouped look. */
.maplibregl-ctrl-group > button {
    border-radius: 0;
    font-weight: normal;
}
.maplibregl-ctrl-group > button:first-child { border-radius: 4px 4px 0 0; }
.maplibregl-ctrl-group > button:last-child  { border-radius: 0 0 4px 4px; }
.maplibregl-ctrl-group > button:only-child  { border-radius: 4px; }

/* Auto-hide the built-in compass while the map is north-up. The zoom-out button
   then becomes the last visible control, so round its bottom corners. */
body.north-up .maplibregl-ctrl-compass { display: none; }
body.north-up .maplibregl-ctrl-zoom-out { border-radius: 0 0 4px 4px; }

/* On-map GPS button: a single-button control group above the zoom controls. The
   icon is MapLibre's official geolocate icon, supplied by maplibre-gl.css through
   the .maplibregl-ctrl-geolocate class (no inline SVG). Default sizing/hover come
   from MapLibre's control button styles. The active (live-tracking) state mirrors
   the search-panel GPS button with a blue fill; invert the icon to white for it. */
.gps-ctrl-btn.active {
    background: #1565c0;
}

.gps-ctrl-btn.active:hover {
    background: #0d47a1;
}

.gps-ctrl-btn.active .maplibregl-ctrl-icon {
    filter: brightness(0) invert(1);
}

/* ── Manual Climb ────────────────────────────────────────────────── */
.manual-climb-toggle-btn {
    background-color: #4a7ba6;
    color: white;
    padding: 10px;
    font-size: 14px;
    width: 100%;
    transition: background 0.2s;
}

.manual-climb-toggle-btn:hover {
    background-color: #3a6489;
}

.manual-climb-toggle-btn.active {
    background-color: #3a6489;
    outline: 2px solid #9dc3da;
}

.manual-climb-toggle-btn:disabled {
    background-color: #ccc;
    color: #666;
    cursor: not-allowed;
}

.manual-climb-hint {
    font-size: 12px;
    color: #555;
    margin: 0 0 4px;
    line-height: 1.4;
}

.manual-climb-count {
    font-size: 12px;
    font-weight: 600;
    color: #1565C0;
    margin: 0 0 8px;
}

.manual-climb-btns {
    display: flex;
    gap: 6px;
    align-items: center;
}

.manual-climb-calc {
    flex: 1;
    margin: 0;
    padding: 8px;
    font-size: 13px;
    background-color: #1565C0;
}

.manual-climb-calc:hover {
    background-color: #0d47a1;
}

.manual-climb-calc:disabled {
    background-color: #ccc;
    color: #666;
    cursor: not-allowed;
}

.manual-climb-cancel-btn {
    padding: 8px 12px;
}

/* Crosshair cursor while placing points */
#map.manual-climb-active .maplibregl-canvas {
    cursor: crosshair !important;
}

/* Waypoint dot markers shown during point selection */
.manual-climb-dot {
    width: 12px;
    height: 12px;
    background: #1565C0;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

.manual-climb-dot.first {
    background: #2AAD27;
}

/* Radius controls injected inside an analysis section */
.section-content > #radius-controls {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-bottom: 0;
    margin-bottom: 0;
}

/* --- GPX MODAL & UPLOADED FILES --- */
.gpx-modal-content {
    max-width: 520px;
    text-align: left;
}

.gpx-modal-content h4,
.gpx-modal-content p {
    text-align: left;
}

.gpx-modal-actions {
    margin: 12px 0;
}

.gpx-modal-actions .gpx-btn,
#gpx-modal-close {
    margin-top: 0;
}

.gpx-modal-panel {
    margin-top: 0;
    margin-bottom: 14px;
}

.gpx-auth {
    margin: 12px 0;
    padding: 12px;
    border-radius: 8px;
    background: rgba(236, 239, 241, 0.6);
    border: 1px solid rgba(120, 144, 156, 0.35);
}

.gpx-auth-desc {
    font-size: 12px;
    color: #455A64;
    margin: 0 0 8px 0;
}

.google-signin-btn {
    display: flex;
    min-height: 40px;
}

.gpx-auth-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.gpx-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    background: #CFD8DC;
}

.gpx-user-email {
    font-size: 13px;
    font-weight: 600;
    color: #263238;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.gpx-signout-btn {
    flex-shrink: 0;
    margin: 0;
}

.secondary-btn {
    background-color: #ECEFF1;
    color: #37474F;
    padding: 7px 10px;
    font-size: 12px;
    line-height: 1.2;
}

.secondary-btn:hover {
    background-color: #CFD8DC;
}

.danger-btn {
    background-color: #FDECEA;
    color: #B42318;
    padding: 7px 10px;
    font-size: 12px;
    line-height: 1.2;
}

.danger-btn:hover {
    background-color: #FCDAD7;
}

.uploaded-gpx-panel {
    margin-top: 8px;
    padding: 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(120, 144, 156, 0.35);
}

.gpx-modal-panel .uploaded-gpx-list {
    max-height: 280px;
    overflow-y: auto;
    padding-right: 2px;
}

.uploaded-gpx-title {
    font-size: 12px;
    font-weight: 700;
    color: #37474F;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.uploaded-gpx-empty {
    font-size: 12px;
    color: #607D8B;
}

.uploaded-gpx-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.uploaded-gpx-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    background: rgba(236, 239, 241, 0.9);
}

.uploaded-gpx-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 2px;
}

.uploaded-gpx-name {
    font-size: 13px;
    font-weight: 700;
    color: #263238;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.uploaded-gpx-date {
    font-size: 11px;
    color: #607D8B;
}

.uploaded-gpx-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.uploaded-gpx-actions button {
    white-space: nowrap;
}

@media (max-width: 600px) {
    .uploaded-gpx-item {
        flex-direction: column;
        align-items: stretch;
    }

    .uploaded-gpx-actions {
        width: 100%;
    }

    .uploaded-gpx-actions .secondary-btn,
    .uploaded-gpx-actions .danger-btn {
        flex: 1;
    }
}

/* --- ELEVATION PROFILE BAR --- */
.elevation-profile {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    transition: none;
}

.elevation-profile-body {
    position: relative;
    height: 130px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(5px);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.2);
    transition: height 0.3s ease;
}

.elevation-profile.minimized .elevation-profile-body {
    height: 26px;
}

@media (min-width: 600px) {
    .elevation-profile-body {
        height: 150px;
    }
}

.elevation-profile-overlay {
    position: absolute;
    top: 0;
    left: 52px;
    right: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 4px;
    min-height: 24px;
    pointer-events: none;
    user-select: none;
    z-index: 1;
}

@media (max-width: 600px) {
    .elevation-profile-overlay {
        pointer-events: auto;
        cursor: pointer;
        left: 0;
        right: 0;
        padding: 4px 10px;
    }
}

.elevation-profile-overlay > * {
    pointer-events: auto;
}

.elevation-profile-label {
    font-size: 11px;
    font-weight: 700;
    color: #555;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.75);
    border-radius: 3px;
    padding: 1px 5px;
}

.elevation-profile-info {
    font-size: 11px;
    color: #333;
    font-weight: 600;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 8px;
    background: rgba(255, 255, 255, 0.75);
    border-radius: 3px;
    margin: 0 4px;
}

.elevation-profile-info:empty {
    display: none;
}

.elevation-profile-toggle {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #bbb;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    color: #555;
    padding: 1px 6px;
    line-height: 1;
    transition: transform 0.3s ease;
}

.elevation-profile-toggle:hover {
    background: #fff;
    border-color: #888;
}

.elevation-profile.minimized .elevation-profile-toggle {
    transform: rotate(180deg);
}

#elevation-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
}

.elevation-profile.minimized #elevation-canvas {
    display: none;
}

/* ============================================================
   Inline SVG icon system (replaces emoji/glyph icons)
   ============================================================ */
.icon-svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* On-map sliders (toggled from Advanced settings). The stack sits in the bottom-left
   corner, temporarily replacing the attribution control while any slider is shown. */
#map-slider-stack {
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

.map-slider {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.6);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    color: #333;
}

.map-slider.visible {
    display: flex;
}

.map-slider .icon-svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.map-slider input[type="range"] {
    width: 110px;
    margin: 0;
}

.map-slider .map-slider-val {
    font-size: 12px;
    min-width: 34px;
    text-align: right;
}

/* Leading icon inside a text button or label */
.btn-icon {
    width: 18px;
    height: 18px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
    flex: 0 0 auto;
}

.btn-label {
    vertical-align: middle;
}

/* Header circle buttons (share, info) */
.circle-btn svg {
    width: 22px;
    height: 22px;
    display: block;
}

/* Header app logo */
.title-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.app-logo {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    color: #333;
}

/* Desktop: the header logo (only) doubles as the Print map launcher. The whole logo box
   is clickable via bounding-box hit testing, not just its unfilled strokes. */
.app-logo.printmap-launch {
    cursor: pointer;
    pointer-events: bounding-box;
}

.app-logo.printmap-launch:hover {
    color: #2196F3;
}

/* Panel minimize +/- toggle */
.toggle-btn {
    display: flex;
    align-items: center;
}

.toggle-btn:hover {
    color: #2563eb;
}

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

/* Panel expanded shows "−"; minimized shows "+" */
.toggle-btn .pm-v {
    opacity: 0;
    transition: opacity 0.2s ease;
}

#controls.minimized .toggle-btn .pm-v {
    opacity: 1;
}

/* Section expand/collapse +/- toggle */
.section-toggle .icon-svg {
    width: 16px;
    height: 16px;
    display: block;
}

/* Section collapsed shows "+"; expanded shows "−" */
.section-toggle .pm-v {
    transition: opacity 0.2s ease;
}

.section-toggle.expanded .pm-v {
    opacity: 0;
}

/* Elevation profile chevron (the button itself rotates via the .minimized rule above) */
.elevation-profile-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.elevation-profile-toggle .icon-svg {
    width: 14px;
    height: 14px;
    display: block;
}

/* Lock-radius label icon */
#lbl-lock-circle {
    display: inline-flex;
    align-items: center;
}

#lbl-lock-circle .btn-icon {
    width: 15px;
    height: 15px;
    margin-right: 6px;
}

/* Icon-only buttons that aren't .icon-btn (manual-climb cancel, install-bar dismiss) */
.manual-climb-cancel-btn,
#mobile-install-dismiss {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.manual-climb-cancel-btn svg,
#mobile-install-dismiss svg {
    width: 16px;
    height: 16px;
    display: block;
}

/* ---- Print map mode (?printmap) ---- */
#printmap-overlay {
    position: absolute;
    inset: 0;
    z-index: 900;
    pointer-events: none; /* let pan/zoom pass through to the map for framing */
}

#printmap-overlay svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#printmap-overlay .printmap-shade {
    fill: rgba(0, 0, 0, 0.45);
}

#printmap-overlay .printmap-window-border {
    fill: none;
    stroke: #ffffff;
    stroke-width: 2;
    stroke-dasharray: 8 5;
    paint-order: stroke;
}

#printmap-panel {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 1200;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
    padding: 12px 14px;
    width: min(270px, calc(100vw - 24px));
    font-size: 13px;
    color: #222;
}

#printmap-panel .printmap-panel-title {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 10px;
    text-align: center;
}

#printmap-panel .printmap-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

#printmap-panel .printmap-row select {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
}

#printmap-panel .printmap-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 8px;
    cursor: pointer;
}

#printmap-panel .printmap-hint {
    font-size: 11.5px;
    color: #666;
    line-height: 1.4;
    margin-bottom: 10px;
}

#printmap-panel .printmap-btns {
    display: flex;
    gap: 8px;
}

#printmap-panel .printmap-btns .action-btn {
    flex: 1;
    justify-content: center;
}

#printmap-panel .printmap-btns .action-btn.secondary {
    background: #eceff1;
    color: #333;
}
