* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0f1117;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    touch-action: manipulation;
}

/* ── Controls bar ─────────────────────────────────── */
.controls {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
    background: #1a1d28;
    align-items: center;
    border-bottom: 1px solid #2a2d3a;
    flex-shrink: 0;
}


.controls button {
    padding: 10px 12px;
    min-height: 40px;
    border: 1px solid #3a3d4a;
    border-radius: 6px;
    background: #252836;
    color: #d0d0d0;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.mode-group {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.mode-group button {
    text-align: center;
}

/* Fixed width sized to the longest label ("⇄ Out & Back") so cycling
   modes doesn't push the rest of the toolbar around. HIG #9. */
#mode-btn {
    min-width: 120px;
}

.controls button:hover:not(:disabled) {
    background: #2f3344;
    border-color: #5a5d6a;
}

.controls button:active:not(:disabled) {
    background: #383c4f;
}

.controls button:disabled {
    opacity: 0.4;
    cursor: default;
}

.distance-wrapper {
    margin-left: auto;
    position: relative;
    display: flex;
    align-items: center;
}

.distance-pill {
    display: flex;
    align-items: center;
    background: #252836;
    border: 1px solid #3a3d4a;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: inherit;
    font: inherit;
    transition: background 0.15s, border-color 0.15s;
}

.distance-pill:hover:not(:disabled),
.distance-pill:focus-visible {
    background: #2d3142;
    border-color: #4a4d5a;
    outline: none;
}

.distance-pill:disabled {
    opacity: 0.55;
    cursor: default;
}

.controls .distance-display {
    font-size: 18px;
    font-weight: 700;
    color: #6ee7b7;
    padding: 0 2px;
    white-space: nowrap;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}

.distance-chevron {
    color: #9aa0b0;
    font-size: 11px;
    margin-left: 6px;
    transition: transform 0.15s;
}

.distance-wrapper.open .distance-chevron {
    transform: rotate(180deg);
}

.distance-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #1e2030;
    border: 1px solid #3a3d4a;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    min-width: 160px;
    z-index: 1000;
    overflow: hidden;
}

.distance-menu.hidden {
    display: none;
}

.distance-menu button {
    display: block;
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    color: #d0d0d0;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
}

.distance-menu button:hover {
    background: #252836;
    color: #6ee7b7;
}

/* ── GPS location dot ────────────────────────────── */
@keyframes gps-pulse {
    0% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 0.2; transform: scale(2.5); }
    100% { opacity: 0; transform: scale(3); }
}

.gps-dot {
    width: 14px;
    height: 14px;
    background: #4285f4;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    position: relative;
}

.gps-dot::after {
    content: "";
    position: absolute;
    top: -2px;
    left: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4285f4;
    animation: gps-pulse 2s ease-out 3;
}

/* ── Hamburger button ────────────────────────────── */
.menu-btn {
    font-size: 18px;
    padding: 8px 10px !important;
    line-height: 1;
}

/* ── Side menu ───────────────────────────────────── */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    transition: opacity 0.2s;
}

.menu-overlay.hidden {
    display: none;
}

.side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: #1a1d28;
    border-right: 1px solid #2a2d3a;
    z-index: 9999;
    transition: left 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.side-menu.open {
    left: 0;
}

.menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 16px);
    border-bottom: 1px solid #2a2d3a;
}

.menu-header .app-title {
    font-size: 16px;
    font-weight: 700;
    color: #f0f0f0;
    letter-spacing: -0.3px;
}

.menu-close {
    position: relative;
    background: none;
    border: none;
    color: #808390;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s;
}

.menu-close::before {
    content: "";
    position: absolute;
    inset: -8px;
}

.menu-close:hover {
    color: #f0f0f0;
}

.menu-body {
    padding: 12px 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    flex: 1;
}

.menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 18px;
    font-size: 14px;
    color: #d0d0d0;
    cursor: pointer;
    transition: background 0.1s;
    border: none;
    background: none;
    text-align: left;
}

.menu-item:hover {
    background: #252836;
}

button.menu-item {
    font-size: 14px;
    border-radius: 0;
}

.menu-toggle-row {
    justify-content: space-between;
}

.menu-toggle-value {
    color: #6ee7b7;
    font-weight: 600;
    font-size: 13px;
}

/* ── Menu search input ────────────────────────────── */
.menu-search {
    position: relative;
    padding: 12px 18px;
}

.menu-search input[type="text"] {
    width: 100%;
    padding: 10px 32px 10px 12px;
    border: 1px solid #3a3d4a;
    border-radius: 6px;
    background: #12141c;
    color: #f0f0f0;
    font-size: 14px;
    transition: border-color 0.15s;
}

.menu-search input[type="text"]:focus {
    outline: none;
    border-color: #6ee7b7;
}

.address-clear {
    position: absolute;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: #6b6e7a;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}

.address-clear::before {
    content: "";
    position: absolute;
    inset: -8px;
}

.address-clear:hover {
    background: #252836;
    color: #d0d0d0;
}

.address-clear.hidden {
    display: none;
}

.menu-search .autocomplete-list {
    left: 18px;
    right: 18px;
}

.menu-divider {
    height: 1px;
    background: #2a2d3a;
    margin: 8px 0;
}

/* ── Install prompt ──────────────────────────────── */
.menu-install {
    font-size: 13px;
    color: #6ee7b7;
    border-left: 3px solid #6ee7b7;
    background: rgba(110, 231, 183, 0.06);
    cursor: default;
}

.menu-install[role="button"] {
    cursor: pointer;
    font-weight: 600;
}

.menu-install:hover {
    background: rgba(110, 231, 183, 0.12);
}

.menu-install:focus-visible {
    outline: 2px solid #6ee7b7;
    outline-offset: -2px;
}

.menu-install.hidden {
    display: none;
}

/* ── Saved areas & routes ────────────────────────── */
.menu-section-title {
    padding: 8px 18px 4px;
    font-size: 11px;
    font-weight: 600;
    color: #6b6e7a;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.saved-list {
    padding: 0 18px;
}

#saved-routes-list {
    max-height: 40vh;
    overflow-y: auto;
}

.saved-list.hidden {
    display: none;
}

.saved-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #1e2030;
}

.saved-item:last-child {
    border-bottom: none;
}

.saved-item-name {
    flex: 1;
    font-size: 13px;
    color: #d0d0d0;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-item-name:hover {
    color: #6ee7b7;
}

.saved-item-edit {
    position: relative;
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 6px;
    opacity: 0.6;
}
.saved-item-edit::before {
    content: "";
    position: absolute;
    inset: -8px -4px;
}
.saved-item-edit:hover {
    opacity: 1;
}
.saved-item-rename-input {
    flex: 1;
    background: transparent;
    border: 1px solid currentColor;
    color: inherit;
    padding: 2px 6px;
    border-radius: 3px;
    font: inherit;
}

.saved-item-delete {
    position: relative;
    background: none;
    border: none;
    color: #6b6e7a;
    font-size: 16px;
    cursor: pointer;
    padding: 0 0 0 8px;
    line-height: 1;
}

.saved-item-delete::before {
    content: "";
    position: absolute;
    inset: -10px -4px -10px -2px;
}

.saved-item-delete:hover {
    color: #f87171;
}

.menu-progress {
    font-size: 12px;
    color: #6ee7b7;
    padding: 4px 18px;
}

.menu-progress.hidden {
    display: none;
}

button.menu-item:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Inline save input ────────────────────────────── */
.save-input-row {
    display: flex;
    gap: 6px;
    padding: 6px 18px 12px;
}

.save-input-row.hidden {
    display: none;
}

.save-input-row input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #3a3d4a;
    border-radius: 6px;
    background: #12141c;
    color: #f0f0f0;
    font-size: 13px;
}

.save-input-row input:focus {
    outline: none;
    border-color: #6ee7b7;
}

.save-confirm {
    padding: 8px 14px;
    background: #2d6a4f;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

.save-confirm:hover {
    background: #3a8063;
}

/* ── Saved route detail ──────────────────────────── */
.saved-item-detail {
    font-size: 11px;
    color: #6b6e7a;
    margin-top: 1px;
}

/* ── City request link ───────────────────────────── */
.menu-request {
    color: #6b6e7a;
    font-size: 12px;
    text-decoration: none;
}

.menu-request:hover {
    color: #6ee7b7;
}

.menu-request.hidden {
    display: none;
}

/* ── Gradient legend (in menu) ───────────────────── */
.menu-legend {
    padding: 12px 18px;
    font-size: 12px;
    line-height: 2;
    color: #808390;
}

.menu-legend strong {
    color: #d0d0d0;
    font-size: 13px;
}

.menu-legend i {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 6px;
}

/* ── Ko-fi support ───────────────────────────────── */
.menu-support {
    color: #d0d0d0;
    font-weight: 500;
    text-decoration: none;
}

.menu-support:hover {
    color: #6ee7b7;
}

.menu-support-blurb {
    padding: 0 18px 8px;
    font-size: 11px;
    color: #6b6e7a;
    line-height: 1.5;
}

/* ── Credits footer ─────────────────────────────── */
.menu-credits {
    padding: 10px 18px 16px;
    font-size: 11px;
    line-height: 1.6;
    color: #6b6e7a;
}

.menu-credits a {
    color: #6b6e7a;
    text-decoration: underline;
    text-decoration-color: #3a3d4a;
}

.menu-credits a:hover {
    color: #d0d0d0;
    text-decoration-color: #6ee7b7;
}

.menu-version {
    padding: 0 18px 16px;
    font-size: 10px;
    color: #4a4d5a;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    text-align: right;
    letter-spacing: 0.02em;
}

/* ── Autocomplete ─────────────────────────────────── */
.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1a1d28;
    border: 1px solid #3a3d4a;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 220px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #b0b0b0;
    border-bottom: 1px solid #252836;
    transition: background 0.1s;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: #252836;
    color: #f0f0f0;
}

.autocomplete-item:last-child { border-bottom: none; }

/* ── Map area (contains map + docked elevation) ──── */
.map-area {
    flex: 1;
    position: relative;
    min-height: 0;
    overflow: hidden;
}

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

/* Greyscale base tiles so coloured route stands out */
.leaflet-tile {
    filter: grayscale(1) brightness(0.7) contrast(1.1);
}

/* ── Elevation panel (docked to bottom of map) ───── */
.elevation-panel {
    position: absolute;
    /* Background stretches to the bottom edge; safe-area padding on the
       last visible child pushes interactive content above the iPhone
       home-indicator gesture zone. */
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 800;
    pointer-events: none;
}

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

.elevation-stats {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 12px;
    background: rgba(26, 29, 40, 0.92);
    backdrop-filter: blur(8px);
    font-size: 11px;
    color: #808390;
    border-top: 1px solid #2a2d3a;
}

.elevation-stats-row {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.elevation-stats-row span {
    color: #6ee7b7;
    font-weight: 600;
}

.elevation-toggle {
    flex-shrink: 0;
    position: relative;
    background: #252836;
    border: 1px solid #2a2d3a;
    color: #d0d0d0;
    font-size: 20px;
    line-height: 1;
    padding: 4px 14px;
    margin: -4px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    /* Expand the touch target above the visible pill so the collapsed strip
       has a finger-sized hitbox that clears the Leaflet attribution row. */
    min-height: 32px;
    min-width: 48px;
}

.elevation-toggle::before {
    content: "";
    position: absolute;
    inset: -10px -8px -10px -8px;
}

.elevation-toggle:hover {
    background: #2f3342;
    border-color: #3a3e4d;
    color: #ffffff;
}

#elevation-container {
    /* Height is the chart's drawable area; extra padding-bottom stretches the
       panel background down across the safe-area without squeezing the chart. */
    height: 140px;
    background: rgba(26, 29, 40, 0.92);
    backdrop-filter: blur(8px);
    padding: 2px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    display: none;
}

.elevation-panel.collapsed #elevation-container {
    display: none !important;
}

/* When collapsed, the stats strip is the last visible child — extend its
   background to the bottom edge while keeping content above the gesture zone. */
.elevation-panel.collapsed .elevation-stats {
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
}

#elevation-canvas {
    width: 100%;
    height: 100%;
}

/* Larger elevation on taller screens */
@media (min-height: 700px) {
    #elevation-container { height: 170px; }
}
@media (min-height: 900px) {
    #elevation-container { height: 210px; }
}

/* ── Info banner ──────────────────────────────────── */
.info-banner {
    padding: 8px 16px;
    text-align: center;
    font-size: 13px;
    display: none;
    border-bottom: 1px solid #2a2d3a;
}

.info-banner.error {
    background: #3a2020;
    color: #f5a0a0;
    border-bottom-color: #4a2a2a;
}

.info-banner.loading {
    background: #1a1d28;
    color: #a0a4b8;
}

.info-banner.share {
    background: #1a1d28;
    color: #e8e9ef;
}

.info-banner.hint {
    background: #1a2a24;
    color: #a8e0c4;
    border-bottom-color: #2a3a34;
}

.banner-retry {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 10px;
    background: transparent;
    border: 1px solid currentColor;
    border-radius: 4px;
    color: inherit;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.banner-retry:hover {
    background: rgba(255, 255, 255, 0.08);
}

.info-banner-action {
    background: transparent;
    border: 1px solid currentColor;
    color: inherit;
    padding: 2px 10px;
    margin-left: 4px;
    border-radius: 4px;
    font: inherit;
    cursor: pointer;
}

.info-banner-action:hover {
    background: rgba(255, 255, 255, 0.1);
}

.info-banner.offline {
    background: #2a2a1a;
    color: #e0d48a;
    border-bottom-color: #3a3a2a;
}

.info-banner .share-input {
    width: 60%;
    max-width: 420px;
    padding: 4px 8px;
    border: 1px solid #2a2d3a;
    border-radius: 4px;
    background: #0f1117;
    color: #e8e9ef;
    font-family: inherit;
    font-size: 12px;
    margin-left: 4px;
}

.info-banner.loading::after {
    content: '...';
    display: inline-block;
    width: 1.2em;
    text-align: left;
    vertical-align: bottom;
    color: inherit;
    animation: loadEllipsis 1.2s steps(3, jump-none) infinite;
}

@keyframes loadEllipsis {
    from { clip-path: inset(0 calc(100% - 0.4em) 0 0); }
    to { clip-path: inset(0 0 0 0); }
}

/* ── Welcome modal ────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal {
    background: #1a1d28;
    border: 1px solid #3a3d4a;
    border-radius: 12px;
    padding: 28px 32px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal h2 {
    font-size: 20px;
    color: #f0f0f0;
    margin-bottom: 16px;
}

.modal ul {
    list-style: none;
    padding: 0;
    margin: 0 0 20px;
}

.modal li {
    font-size: 14px;
    color: #b0b0b0;
    padding: 6px 0;
    line-height: 1.5;
}

.modal li strong {
    color: #e0e0e0;
}

.modal button {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: #2d6a4f;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.modal button:hover {
    background: #3a8063;
}

@media (hover: none), (pointer: coarse) {
    .desktop-only { display: none; }
}

/* ── Keyboard shortcut keycaps ───────────────────── */
kbd {
    display: inline-block;
    padding: 2px 6px;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.4;
    color: #d0d0d0;
    background: #252836;
    border: 1px solid #3a3d4a;
    border-bottom-width: 2px;
    border-radius: 4px;
    box-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

/* ── Route markers ────────────────────────────────── */
.wp-marker {
    position: relative;
    background: #2e86de;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

/* Pending state — pin is rendered but path data is still loading */
.wp-marker--pending {
    background: #d63031;
}

.wp-marker--pending .wp-spinner {
    position: absolute;
    inset: -5px;
    border: 2px solid transparent;
    border-top-color: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    animation: wp-spin 0.9s linear infinite;
    pointer-events: none;
}

@keyframes wp-spin {
    to { transform: rotate(360deg); }
}

/* Failed state — path load failed; tap to retry */
.wp-marker--failed {
    background: #f39c12;
    cursor: pointer;
}

.wp-marker--failed .wp-retry {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    pointer-events: none;
}

.wp-midpoint {
    background: rgba(110,231,183,0.4);
    border: 2px dashed #6ee7b7;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    cursor: grab;
}

.distance-pill {
    background: #fff;
    color: #1a1d28;
    border-radius: 8px;
    padding: 1px 5px;
    font-size: 10px;
    font-weight: 700;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

/* ── POI markers (toilets, drinking water) ────────── */
.poi-marker {
    background: #1a1d28;
    border: 2px solid #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
    cursor: pointer;
}

.poi-marker.poi-drinking_water {
    background: #1a2a3a;
    border-color: #60a5fa;
}

.poi-marker.poi-toilets {
    background: #2a2030;
    border-color: #c4b5fd;
}
