body {
    text-align: center;
    font-family: et-book, Palatino, Georgia, serif;
    color: #121212;
    font-size: 1.2em;
    background: #f8f8f9;
    line-height: 1.4em;
    margin: 0;
}

header,
menu,
#container,
footer {
    max-width: 700px;
    margin: 0 auto;
    padding: 0 0.5em;
    text-align: left;
}

header {
    margin-top: 1em;
    margin-bottom: 0.2em;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 500;
}

h1 {
    font-size: 2.2em;
    margin: 0 0 0.1em 0;
}

header h1 a,
header h1 a:hover {
    color: #121212;
}

h2, h3, h4 {
    margin: 1em 0 0.2em 0;
}

.description {
    display: block;
    font-size: 1.1em;
    color: #555;
}

menu {
    margin: 0.2em auto 0.5em auto;
    padding: 0;
    list-style: none;
}

menu li {
    display: inline;
    margin-right: 1em;
    font-size: 1em;
}

a {
    color: #007185;
    text-decoration: none;
}

a:hover {
    color: #C7511F;
}

#container {
    margin: 1em auto;
    min-height: 40vh;
}

sup {
    vertical-align: baseline;
    position: relative;
    top: -0.4em;
    font-size: 0.7em;
}

sub {
    vertical-align: baseline;
    position: relative;
    top: 0.3em;
    font-size: 0.7em;
}

/* Leaflet map */
.leaflet-container {
    max-width: 100%;
    margin: 1em 0;
    border: 1px solid #ccc;
    font-family: inherit;
}

/* Full-screen route planner */
.map-app {
    position: fixed;
    inset: 0;
    z-index: 1000;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    text-align: left;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.map-app .map-app__map.leaflet-container {
    width: 100%;
    height: 100%;
    margin: 0;
    border: 0;
}

.map-card {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1100;
    width: min(380px, calc(100vw - 40px));
    max-height: calc(100dvh - 40px);
    padding: 20px;
    overflow-y: auto;
    box-sizing: border-box;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.22);
}

.map-card__header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.2rem;
}

.map-card__brand {
    min-width: 0;
    color: #007185;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.map-card__links {
    display: flex;
    flex: 0 0 auto;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    font-size: 0.75rem;
}

.map-card .map-card__title {
    margin: 0.2rem 0 0.65rem;
    font-size: 1.4rem;
    font-weight: 650;
    line-height: 1.2;
}

.map-card__intro {
    margin: 0 0 1rem;
    color: #555;
    font-size: 0.9rem;
    line-height: 1.45;
}

.map-card__primary {
    width: 100%;
}

.map-card__actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 1.1rem;
}

.map-card__actions > * {
    min-width: 0;
    text-align: center;
}

/* Polygon tools live in the planner card instead of Leaflet's fly-out toolbar. */
.area-tools {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e6e6e6;
}

.area-tools button,
.map-card__actions button,
.map-card__actions .button-link {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid #ccd8da;
    border-radius: 6px;
    color: #007185;
    background: #f3f8f9;
}

.area-tools button:hover:not(:disabled),
.area-tools button.is-active,
.map-card__actions button:hover:not(:disabled),
.map-card__actions .button-link:hover {
    color: #fff;
    background: #007185;
}

.area-tools svg,
.map-card__actions svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.route-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 1rem 0 1.25rem;
}

.route-stats div {
    padding: 0.6rem;
    border-radius: 8px;
    background: #f1f3f4;
}

.route-stats dt {
    color: #666;
    font-size: 0.72rem;
    text-transform: uppercase;
}

.route-stats dd {
    margin: 0.1rem 0 0;
    font-size: 0.9rem;
    font-weight: 650;
}

/* Locally saved routes */
.saved-routes {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid #e6e6e6;
}

.saved-routes h2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 0 0.55rem;
    font-size: 0.9rem;
    font-weight: 650;
}

.saved-routes__toggle {
    display: none;
}

.saved-routes ul {
    display: grid;
    gap: 6px;
    max-height: 220px;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
}

.saved-routes li {
    display: flex;
    align-items: stretch;
    gap: 4px;
    border: 1px solid #e2e5e7;
    border-radius: 8px;
    background: #fff;
}

.saved-route__open {
    display: grid;
    flex: 1 1 auto;
    min-width: 0;
    gap: 1px;
    padding: 0.55rem 0.65rem;
    color: #121212;
    background: transparent;
    text-align: left;
}

.saved-route__open:hover:not(:disabled) {
    color: #121212;
    background: #f1f3f4;
}

.saved-route__open strong,
.saved-route__open span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-route__open strong {
    font-size: 0.82rem;
}

.saved-route__open span {
    color: #666;
    font-size: 0.7rem;
}

.saved-route__delete {
    flex: 0 0 auto;
    padding: 0.45rem 0.6rem;
    border-left: 1px solid #e2e5e7;
    border-radius: 0 8px 8px 0;
    color: #a12828;
    background: transparent;
    font-size: 0.7rem;
}

.saved-route__delete:hover:not(:disabled) {
    color: #fff;
    background: #a12828;
}

/* Distance-based route playback control. */
.route-scrubber {
    margin: 0;
}

.route-scrubber__labels {
    display: flex;
    justify-content: space-between;
    gap: 1em;
    margin-bottom: 0.25em;
    color: #555;
    font-size: 0.85em;
}

.route-scrubber__range {
    width: 100%;
    height: 8px;
    margin: 0;
    appearance: none;
    -webkit-appearance: none;
    border-radius: 999px;
    background: linear-gradient(90deg, #ff6a00, #e600ff);
    cursor: pointer;
}

.route-scrubber__range::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
    appearance: none;
    -webkit-appearance: none;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 2px #444, 0 1px 4px rgba(0, 0, 0, 0.35);
}

.route-scrubber__range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 2px #444, 0 1px 4px rgba(0, 0, 0, 0.35);
}

.route-scrubber__range:focus-visible {
    outline: 2px solid #007185;
    outline-offset: 5px;
}

.route-playback {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 0.9rem;
}

.route-playback__main {
    min-width: 88px;
}

.route-playback__speed {
    display: flex;
    align-items: center;
    gap: 8px;
}

.route-playback__speed button {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.15rem;
    line-height: 1;
}

.route-playback__speed output {
    min-width: 2.2rem;
    color: #555;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

/* Current playback position and direction on the map. */
.route-position-marker {
    border: 0;
    background: transparent;
}

.route-position-arrow {
    display: block;
    width: 32px;
    height: 32px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.65));
    transform-origin: 50% 50%;
}

.route-position-arrow svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
    stroke: #fff;
    stroke-width: 2px;
    stroke-linejoin: round;
}

/* Route start and finish flags. */
.route-endpoint-marker {
    border: 0;
    background: transparent;
}

.route-flag {
    position: relative;
    display: grid;
    width: 26px;
    height: 24px;
    place-items: center;
    border: 2px solid #fff;
    border-radius: 4px 4px 4px 0;
    box-sizing: border-box;
    color: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
    font: 700 13px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.route-flag::after {
    position: absolute;
    top: 22px;
    left: -2px;
    width: 3px;
    height: 12px;
    border-radius: 0 0 2px 2px;
    background: #444;
    content: "";
}

.route-flag--start {
    background: #ff6a00;
}

.route-flag--finish {
    background: #e600ff;
}

/* Credits modal */
.credits-link {
    padding: 0;
    border: 0;
    color: #007185;
    background: transparent;
    font: inherit;
}

.credits-link:hover:not(:disabled) {
    color: #C7511F;
    background: transparent;
}

.credits-modal__backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(18, 18, 18, 0.5);
}

.credits-modal {
    position: relative;
    width: min(420px, 100%);
    padding: 24px;
    box-sizing: border-box;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.credits-modal h2 {
    margin: 0 2rem 1rem 0;
    font-size: 1.35rem;
    font-weight: 650;
}

.credits-modal p {
    margin: 0 0 0.9rem;
    font-size: 0.9rem;
    line-height: 1.45;
}

.credits-modal .credits-modal__copyright {
    padding: 0.65rem 0.75rem;
    border-left: 3px solid #007185;
    background: #f1f3f4;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
}

.credits-modal__close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    color: #444;
    background: #f1f3f4;
    font-size: 1.4rem;
    line-height: 1;
}

.route-name-modal label {
    display: block;
    margin-bottom: 0.35rem;
    color: #555;
    font-size: 0.82rem;
    font-weight: 600;
}

.route-name-modal input {
    width: 100%;
    padding: 0.65rem 0.7rem;
    box-sizing: border-box;
    border: 1px solid #bbb;
    border-radius: 6px;
    color: #121212;
    background: #fff;
    font: inherit;
}

.route-name-modal input:focus {
    border-color: #007185;
    outline: 2px solid rgba(0, 113, 133, 0.2);
}

.route-name-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 1rem;
}

/* Search form */
.search-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    width: 100%;
}

.search {
    min-width: 0;
    padding: 0.45em;
    font-family: inherit;
    font-size: 0.9em;
    border: 1px solid #ccc;
    border-right: 0;
    border-radius: 6px 0 0 6px;
    background: #fff;
    color: #121212;
    box-sizing: border-box;
}

.search:focus {
    position: relative;
    z-index: 1;
    border-color: #007185;
    outline: 2px solid rgba(0, 113, 133, 0.2);
}

.search-submit {
    display: grid;
    width: 44px;
    padding: 0;
    place-items: center;
    border-radius: 0 6px 6px 0;
}

.search-submit svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-width: 2;
}

.search-form em {
    grid-column: 1 / -1;
    margin-top: 0.4rem;
}

/* Right-aligns the Download GPX action, opposite the Generate button. */
.route-actions {
    display: flex;
    justify-content: flex-end;
}

.start-hint {
    font-size: 0.85em;
    color: #555;
    margin: 0.4em 0;
}

/* Draggable "start here" pin dropped on the map. */
.start-pin__dot {
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #007185;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px #007185, 0 1px 4px rgba(0, 0, 0, 0.4);
    cursor: grab;
}

/* Buttons */
button,
.submit {
    padding: 0.45em 0.9em;
    font-family: inherit;
    font-size: 0.9em;
    color: #fff;
    background: #007185;
    border: none;
    cursor: pointer;
    box-sizing: border-box;
}

button:hover:not(:disabled),
.submit:hover:not(:disabled) {
    background: #C7511F;
}

button:disabled {
    background: #bbb;
    cursor: not-allowed;
}

.button-secondary {
    color: #007185;
    background: #e7f2f4;
}

.button-link {
    padding: 0.45em 0.9em;
    box-sizing: border-box;
    color: #fff;
    background: #007185;
    font-size: 0.9em;
}

.button-link:hover {
    color: #fff;
    background: #C7511F;
}

.warning {
    background: #fff8e1;
    padding: 0.5em 0.8em;
    margin: 1em 0;
}

/* --- Route loader (fancy loading state) --- */
/* Sized to match the search form it replaces while a route generates. */
.route-loader {
    display: flex;
    align-items: center;
    width: 100%;
    /* input: 0.45em*2 padding + ~1.08em line + 2px border ≈ same row height */
    min-height: calc(0.9em + 1.08em + 2px);
    margin: 0;
    box-sizing: border-box;
}

.route-loader__headline {
    display: flex;
    align-items: center;
    gap: 0.5em;
    font-size: 0.9em;
    color: #121212;
}

.route-loader__spin {
    width: 1em;
    height: 1em;
    flex: 0 0 auto;
    border-radius: 50%;
    border: 2px solid #d3dadd;
    border-top-color: #007185;
    animation: esc-spin 0.8s linear infinite;
}

.route-loader__flavor {
    animation: esc-rise 0.45s ease both;
}

.route-loader__ellipsis {
    margin-left: -0.35em;
}
.route-loader__ellipsis i {
    font-style: normal;
    animation: esc-blink 1.4s infinite both;
}
.route-loader__ellipsis i:nth-child(2) { animation-delay: 0.2s; }
.route-loader__ellipsis i:nth-child(3) { animation-delay: 0.4s; }

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

@keyframes esc-blink {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 1; }
}

@keyframes esc-rise {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .route-loader__spin,
    .route-loader__ellipsis i,
    .route-loader__flavor {
        animation: none;
    }
}

footer {
    color: #555;
    font-size: 0.8em;
    border-top: 1px solid #ccc;
    margin: 2em auto 1.5em auto;
    padding-top: 0.8em;
}

footer p {
    margin: 0;
}

footer img {
    padding: 0 4px;
    margin-bottom: -3px;
    height: 1em;
}

@media only screen and (max-width: 720px) {
    header,
    menu,
    #container,
    footer {
        max-width: 100%;
    }

    .map-card {
        top: 12px;
        left: 12px;
        width: calc(100vw - 24px);
        max-height: calc(100dvh - 24px);
        padding: 16px;
        border-radius: 10px;
    }

    .map-card__intro {
        display: none;
    }

    .map-card--planner {
        display: grid;
        grid-template-columns: 40px minmax(0, 1fr);
        column-gap: 12px;
    }

    .map-card--planner .map-card__content {
        min-width: 0;
        grid-column: 2;
        grid-row: 1;
    }

    .area-tools {
        display: flex;
        grid-column: 1;
        grid-row: 1;
        flex-direction: column;
        align-self: start;
        gap: 8px;
        margin: 0;
        padding: 0;
        border: 0;
    }

    .area-tools button {
        width: 40px;
        height: 40px;
        padding: 0;
    }

    .area-tools button span {
        display: none;
    }

    .map-card__actions > * {
        padding-right: 0.4em;
        padding-left: 0.4em;
    }

    .saved-routes__toggle {
        display: inline;
        padding: 0;
        color: #007185;
        background: transparent;
        font-size: 0.78rem;
    }

    .saved-routes__toggle:hover:not(:disabled) {
        color: #C7511F;
        background: transparent;
    }

    .saved-routes--collapsed h2 {
        margin-bottom: 0;
    }

    .saved-routes--collapsed ul {
        display: none;
    }
}
