/* ---- design tokens: everything below uses these, so a re-theme is a change to this block ---- */
:root {
    /* colour: one dark theme (EpiCycle). There is no light theme and no switch; the page asks the browser for dark controls too. */
    color-scheme: dark;
    --bg: #0b1220;
    --surface: #0e1626;
    --surface-2: #172338;
    --text: #e6edf3;
    --muted: #9fb0c3;
    --border: #5a6d8e;
    --accent: #4ade80;
    --accent-text: #06210f;
    --accent-soft: color-mix(in srgb, var(--accent) 14%, var(--surface));
    --teal: #5eead4;
    --ok: #5ed39a;
    --warning: #fcd34d;
    --warning-bg: #3a2c0b;
    --danger: #fca5a5;
    --danger-bg: #3d1816;
    --focus: #ffffff;
    --route-selected: #4ade80;
    --route-other: #38bdf8;
    --route-casing: #0b1220;
    /* road works are drawn above the map tiles, which are dimmed by default, so these are light enough to show on dark tiles */
    --network: #facc15;
    --works-closed: #f87171;
    --works-lane: #fb923c;
    --works-works: #a78bfa;
    --start: #4ade80;
    --destination: #f87171;
    --marker-ring: #ffffff;
    --sun: #fbbf24;

    /* type */
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --text-s: 0.8125rem;
    --text-m: 1rem;
    --text-l: 1.25rem;
    --text-xl: 1.75rem;

    /* space, shape, elevation */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --radius-s: 8px;
    --radius: 14px;
    --radius-l: 22px;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
    --shadow-s: 0 2px 8px rgba(0, 0, 0, 0.5);

    /* the points list */
    --row-h: 48px;
    --badge: 30px;

    /* the bottom sheet (phone) */
    --sheet-collapsed: 112px;
    --sheet-half: 52dvh;
    --sheet-full: calc(100dvh - 56px - var(--tabbar-h));
    --sheet-offset: var(--sheet-collapsed);

    /* the tab bar under the sheet (phone): its buttons and the phone's bottom inset */
    --tabbar-h: calc(56px + env(safe-area-inset-bottom, 0px));
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--text-m);
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

#app { height: 100%; }

.loading-text { padding: var(--space-2) 0; color: var(--muted); }
.shell-map { background: var(--surface-2); }

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

h1 { font-size: var(--text-l); margin: 0; letter-spacing: -0.01em; }
h2 { font-size: var(--text-l); margin: 0 0 var(--space-1); }
h2:focus { outline: none; }
p { margin: 0 0 var(--space-2); }
a { color: var(--accent); }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    margin: -1px; padding: 0; border: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- layout: the map fills the screen; the planner floats over it ---- */
.app {
    position: relative;
    height: 100dvh;
    overflow: hidden;
    overflow: clip;   /* hidden can still be scrolled by focusing a field; clip cannot, so the map never slides out of place */
}

.map-area { position: absolute; inset: 0; }
.map { position: absolute; inset: 0; z-index: 0; }
.map.mmr-picking { cursor: crosshair; }

/* phone: a bottom sheet with three heights */
.sheet {
    position: absolute; left: 0; right: 0; bottom: var(--tabbar-h); z-index: 500;
    display: flex; flex-direction: column;
    height: var(--sheet-half);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    background: var(--surface);
    border-radius: var(--radius-l) var(--radius-l) 0 0;
    box-shadow: var(--shadow);
    transition: height 0.22s ease;
}
.app[data-sheet="collapsed"] { --sheet-offset: var(--sheet-collapsed); }
.app[data-sheet="half"] { --sheet-offset: var(--sheet-half); }
.app[data-sheet="full"] { --sheet-offset: var(--sheet-full); }
.sheet[data-state="collapsed"] { height: var(--sheet-collapsed); }
.sheet[data-state="half"] { height: var(--sheet-half); }
.sheet[data-state="full"] { height: var(--sheet-full); }
.sheet.dragging { transition: none; }

.sheet-handle {
    flex: none; display: flex; align-items: center; justify-content: center;
    width: 100%; min-height: 44px; padding: 0; border: 0; background: transparent; color: var(--muted);
    cursor: grab; touch-action: none;
}
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--border); }
.sheet-handle:hover .sheet-grip { background: var(--muted); }

.sheet-body {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    padding: 0 var(--space-4) var(--space-4);
}

.panel-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.header-button {
    display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; margin-right: calc(-1 * var(--space-2));
    border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer;
}
.header-button:hover, .header-button[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.header-buttons { display: flex; margin-right: calc(-1 * var(--space-2)); }
.header-buttons .header-button { margin-right: 0; }

/* ---- sign-in: the login screen, and the account panel in the planner ---- */
.auth-page {
    min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: var(--space-4);
    background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--accent) 10%, var(--bg)) 0%, var(--bg) 60%);
}
.auth-column { width: 100%; max-width: 400px; display: flex; flex-direction: column; align-items: stretch; gap: var(--space-5); }
.auth-brand { text-align: center; }
.auth-brand h1 { display: flex; justify-content: center; margin: 0 0 var(--space-2); }
.auth-brand .tagline { margin: 0; color: var(--muted); font-weight: 600; }
.auth-card { width: 100%; padding: var(--space-5); border: 1px solid var(--border); border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 var(--space-2); }
.auth-card h2 { margin: 0 0 var(--space-1); font-size: var(--text-l); }
.auth-lead { color: var(--muted); margin-bottom: var(--space-4); }
.auth-card .providers { list-style: none; margin: var(--space-4) 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.provider-button {
    display: flex; align-items: center; justify-content: center; gap: var(--space-3); width: 100%; min-height: 48px; padding: 0 var(--space-4);
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.provider-button:hover { border-color: var(--text); }
.provider-icon { width: 20px; height: 20px; flex: none; }
.auth-note { color: var(--muted); font-size: var(--text-s); margin: var(--space-4) 0 0; text-align: center; }
.account-actions { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

/* ---- the form: sections one gap apart, the action always in reach ---- */
.planner-form { display: flex; flex-direction: column; }
.form-sections { display: flex; flex-direction: column; gap: var(--space-4); padding-bottom: var(--space-4); }
.form-sections > *, .form-sections .field, .form-sections fieldset { margin-bottom: 0; }
.form-action {
    position: sticky; bottom: 0; z-index: 3;
    padding: var(--space-3) 0 var(--space-1);
    background: linear-gradient(to bottom, color-mix(in srgb, var(--surface) 0%, transparent), var(--surface) 28%);
}

/* ---- the points list: start, route points, destination, one row each ---- */
.points-list { position: relative; list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.points-list.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
.point-row { position: relative; display: grid; grid-template-columns: 44px var(--badge) minmax(0, 1fr) 44px 44px; column-gap: 2px; align-items: start; }
/* the line between the badges */
.point-row:not(:last-child)::before {
    content: ""; position: absolute; z-index: 0; left: calc(44px + 2px + var(--badge) / 2 - 1px); top: calc(var(--row-h) / 2 + var(--badge) / 2);
    bottom: calc(-1 * var(--space-2) - 2px); width: 2px; background: var(--border);
}
.point-badge {
    position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; align-self: start;
    width: var(--badge); height: var(--badge); margin-top: calc((var(--row-h) - var(--badge)) / 2);
    border-radius: 50%; border: 2px solid var(--surface); font-size: 0.8125rem; font-weight: 800; box-shadow: var(--shadow-s);
}
.point-badge-start { background: var(--start); color: var(--bg); }
.point-badge-destination { background: var(--destination); color: var(--accent-text); }
.point-badge-via { background: var(--surface); color: var(--focus); border-color: var(--teal); }
.point-badge-add { background: var(--surface); color: var(--muted); border: 2px dashed var(--border); box-shadow: none; font-size: var(--text-m); }
.point-field { min-width: 0; padding-left: var(--space-1); }
.point-field .field { margin: 0; }
.location.compact .location-input input { padding-right: var(--space-3); }
.point-row.picking .location-input input { border-color: var(--accent); background: var(--surface); }
.point-grip, .point-action {
    display: flex; align-items: center; justify-content: center; width: 44px; height: var(--row-h); padding: 0;
    border: 0; border-radius: var(--radius); background: transparent; color: var(--muted);
}
.point-grip { cursor: grab; touch-action: none; }
.point-grip.placeholder, .point-action.placeholder { cursor: default; pointer-events: none; }
.point-action { cursor: pointer; }
.point-action:hover:not(:disabled), .point-grip:hover:not(:disabled) { color: var(--accent); }
.point-action[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.point-action:disabled, .point-grip:disabled { opacity: 0.35; cursor: default; }
.point-action .icon { width: 20px; height: 20px; }
.grip-dots {
    width: 12px; height: 18px; color: inherit;
    background-image: radial-gradient(circle, currentColor 1.4px, transparent 1.9px); background-size: 6px 6px;
}
.point-row.dragging { z-index: 4; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.point-row.dragging .point-grip { cursor: grabbing; }
.point-row.drop-before::after, .point-row.drop-after::after {
    content: ""; position: absolute; left: 0; right: 0; height: 3px; border-radius: 2px; background: var(--accent); z-index: 5;
}
.point-row.drop-before::after { top: calc(-1 * var(--space-2) / 2 - 2px); }
.point-row.drop-after::after { bottom: calc(-1 * var(--space-2) / 2 - 2px); }

/* ---- form ---- */
fieldset { border: 0; padding: 0; margin: 0 0 var(--space-4); min-width: 0; }
legend { font-weight: 700; font-size: var(--text-s); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 0; margin-bottom: var(--space-2); }

.field { margin-bottom: var(--space-4); position: relative; }
.field > label, .slider-head label { display: block; font-weight: 600; margin-bottom: var(--space-1); }

input[type="text"], input[type="number"], select {
    width: 100%;
    min-height: 48px;
    padding: var(--space-2) var(--space-3);
    font: inherit;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
}
input[type="text"]:focus, input[type="number"]:focus, select:focus { background: var(--surface); border-color: var(--accent); }

input.invalid { border-color: var(--danger); border-width: 2px; }
input:disabled { background: var(--surface-2); color: var(--muted); }

.location-input { position: relative; }
.location-input input { padding-right: 52px; }
.icon-button {
    position: absolute; right: 2px; top: 0;
    width: 44px; height: 48px;
    border: 0; background: transparent; color: var(--muted);
    font: inherit; cursor: pointer; border-radius: var(--radius);
}

.location-actions { margin-top: var(--space-1); }
.location-actions button { min-height: 44px; padding: 0 var(--space-2) 0 0; border: 0; background: transparent; color: var(--accent); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.location-actions button[aria-pressed="true"] { text-decoration: underline; }
.location-actions .icon { width: 18px; height: 18px; }

.suggestions {
    list-style: none; margin: var(--space-1) 0 0; padding: var(--space-1);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    max-height: 260px; overflow-y: auto;
    box-shadow: var(--shadow);
}
.suggestions li { display: flex; justify-content: space-between; gap: var(--space-2); align-items: baseline; min-height: 44px; padding: var(--space-2) 10px; border-radius: var(--radius-s); cursor: pointer; }
.suggestions li.highlight, .suggestions li:hover { background: var(--surface-2); }
.suggestions li.no-results { color: var(--muted); cursor: default; }
.suggestion-kind { color: var(--muted); font-size: var(--text-s); white-space: nowrap; }

.hint { color: var(--muted); font-size: 0.875rem; margin: var(--space-1) 0 0; }
.field-error { color: var(--danger); font-size: 0.9rem; margin: var(--space-1) 0 0; font-weight: 600; }

.checkbox label { display: flex; gap: 10px; align-items: flex-start; min-height: 44px; font-weight: 400; }
.checkbox input { width: 24px; height: 24px; margin-top: var(--space-2); flex: none; accent-color: var(--accent); }

/* ---- choices (real radio buttons, drawn as chips or a segmented control) ---- */
.segmented-items { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; }
.segment {
    position: relative; display: flex; align-items: center; justify-content: center; gap: 6px; text-align: center;
    min-height: 48px; padding: var(--space-2) 10px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); cursor: pointer; font-weight: 600;
}
.segment input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segment.selected { background: var(--accent-soft); color: var(--text); border: 2px solid var(--accent); }
.segment.selected .icon { color: var(--accent); }
.segment.disabled { opacity: 0.5; cursor: not-allowed; }
.segment:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

/* mode: icon over label */
.segmented.chips .segment { flex-direction: column; gap: 2px; min-height: 60px; padding: 6px 2px; font-size: 0.72rem; line-height: 1.2; }
.segmented.chips .icon { width: 24px; height: 24px; }
.segmented.chips .segmented-items { grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 4px; }

/* strategy: one joined control */
.segmented.joined .segmented-items { display: flex; gap: 0; background: var(--surface-2); border-radius: var(--radius); padding: 3px; }
.segmented.joined .segment { flex: 1 1 0; border: 0; border-radius: calc(var(--radius) - 3px); background: transparent; font-size: 0.875rem; padding: var(--space-2) 6px; }
.segmented.joined .segment .icon { width: 18px; height: 18px; }
.segmented.joined .segment.selected { background: var(--surface); border: 0; box-shadow: var(--shadow-s); }

/* four strategies on a narrow screen: icon over label, like the mode chips */
@media (max-width: 480px) {
    .segmented.joined .segment { flex-direction: column; gap: 2px; font-size: 0.75rem; min-height: 52px; padding: 6px 2px; }
    .form-sections { gap: var(--space-3); }
}

/* ---- sliders ---- */
.slider { margin-bottom: var(--space-4); }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); }
.slider-head output { color: var(--muted); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--accent); margin: 0; }

/* ---- advanced settings ---- */
.advanced { margin: 0 0 var(--space-4); border-top: 1px solid var(--border); }
.advanced-toggle {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 0;
    border: 0; background: transparent; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: left;
}
.advanced-toggle .label { flex: 1 1 auto; }
.advanced-toggle .chevron { transition: transform 0.15s ease; color: var(--muted); }
.advanced-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.advanced-count { padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent); font-size: var(--text-s); font-weight: 700; }
.advanced-body[hidden] { display: none; }
.advanced-body { padding-bottom: var(--space-1); }
.advanced-body .link-reset { margin-bottom: var(--space-2); }

/* ---- buttons ---- */
button { font: inherit; }
button.primary, button.secondary {
    min-height: 48px; padding: var(--space-2) var(--space-4); border-radius: var(--radius); cursor: pointer; font-weight: 700;
}
button.primary { width: 100%; border: 0; background: var(--accent); color: var(--accent-text); font-size: var(--text-m); box-shadow: var(--shadow-s); }
button.primary:disabled { opacity: 0.6; cursor: wait; }
button.secondary { border: 1.5px solid var(--accent); background: transparent; color: var(--accent); }
button.link { min-height: 44px; padding: 0 var(--space-2); border: 0; background: transparent; color: var(--accent); font-weight: 600; cursor: pointer; }
button.link-reset { min-height: 44px; padding: 0; border: 0; background: transparent; color: var(--accent); text-decoration: underline; cursor: pointer; }

/* ---- messages ---- */
.notice, .about { padding: 10px var(--space-3); border-radius: var(--radius); margin-bottom: var(--space-3); background: var(--surface-2); }
.notice.offline { background: var(--warning-bg); color: var(--warning); }
.error-banner { padding: var(--space-3); border-radius: var(--radius); background: var(--danger-bg); color: var(--danger); margin: var(--space-3) 0; }
.error-banner .error-title { font-weight: 700; margin-bottom: 2px; }
.error-banner ul { margin: var(--space-1) 0 var(--space-2); padding-left: 20px; }
.error-actions { display: flex; gap: var(--space-2); align-items: center; }

.progress { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) 0 10px; }
.progress-message { margin: 0; font-weight: 600; }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 3s; }
    .sheet, .advanced-toggle .chevron { transition: none; }
}

/* ---- results: one card per route ---- */
.results { margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--border); }
.route-card { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3); background: var(--surface); opacity: 0.92; }
.route-card.selected { border: 2px solid var(--accent); padding: 11px 15px; background: var(--accent-soft); opacity: 1; }
.route-choice { display: grid; grid-template-columns: auto 1fr; column-gap: var(--space-3); align-items: center; min-height: 44px; cursor: pointer; }
.route-choice input { width: 24px; height: 24px; grid-row: span 2; margin: 0; accent-color: var(--accent); }
.route-title { font-weight: 700; font-size: var(--text-s); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.route-figures { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px var(--space-3); }
.route-distance { font-size: var(--text-xl); font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.route-duration { color: var(--muted); }
.route-line { margin: 6px 0 0; }
.route-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: 10px; }
.route-details { margin-top: var(--space-2); }
.route-details > summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; color: var(--accent); font-weight: 600; list-style: none; }
.route-details > summary::-webkit-details-marker { display: none; }
.route-details > summary::after { content: ""; width: 8px; height: 8px; margin-right: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform 0.15s ease; }
.route-details[open] > summary::after { transform: rotate(-135deg); }

.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 0.875rem; font-weight: 600; margin: 6px 0 0; }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }

.characteristics { margin: var(--space-2) 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 2px var(--space-3); font-size: 0.9rem; }
.characteristics dt { color: var(--muted); }
.characteristics dd { margin: 0; }

table.compare { width: 100%; border-collapse: collapse; margin: var(--space-3) 0; font-size: 0.9rem; }
table.compare caption { text-align: left; font-weight: 700; margin-bottom: var(--space-1); }
table.compare th, table.compare td { text-align: left; padding: 6px var(--space-2); border-bottom: 1px solid var(--border); }

/* ---- map markers ---- */
.mmr-marker { background: transparent; border: 0; }
.mmr-marker span {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 50%;
    color: var(--text); font-weight: 800; border: 3px solid var(--marker-ring);
    box-shadow: var(--shadow-s);
}
.mmr-marker-start span { background: var(--start); color: var(--bg); }
.mmr-marker-destination span { background: var(--destination); color: var(--accent-text); }
.mmr-marker-via span { background: var(--surface); color: var(--focus); border-color: var(--teal); }

/* ---- the dimmed map: the standard tiles are light, so by default they are inverted and turned back in hue (water stays blue, parks green).
   Only the tile pane is filtered; routes, markers and the road works are drawn above it and keep their colours. js/display.js sets the class. ---- */
html.map-dim .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9) saturate(0.8); }

/* ---- road works: a layer button under the zoom buttons; its note beside it, its switch and legend in a card that opens ---- */
.works-control, .settings-control { position: absolute; z-index: 400; right: 10px; width: 44px; font-size: var(--text-s); }
.works-control { top: 112px; }
.settings-control { top: 164px; }   /* one button (44px) and a gap below the road works button */
.works-control.open, .settings-control.open { z-index: 401; }   /* an open card sits above the other button */
.works-button {
    display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0;
    border: 2px solid var(--border); border-radius: var(--radius-s); background: var(--surface); color: var(--muted); cursor: pointer; box-shadow: var(--shadow-s);
}
.works-control.on .works-button { color: var(--accent); border-color: var(--accent); }
.works-button[aria-expanded="true"] { background: var(--accent-soft); }
.works-note {
    position: absolute; top: 0; right: 52px; width: max-content; max-width: min(240px, calc(100vw - 20px - 52px - 44px - env(safe-area-inset-right)));
    margin: 0; padding: 6px 10px; border-radius: var(--radius-s); background: var(--surface); color: var(--muted); box-shadow: var(--shadow-s); font-size: 0.75rem; line-height: 1.35;
    pointer-events: none;   /* information only: a tap under it still reaches the map */
}
.works-note:empty { display: none; }
.works-card {
    position: absolute; top: 52px; right: 0; width: min(232px, calc(100vw - 20px - env(safe-area-inset-right)));
    padding: var(--space-1) var(--space-3) var(--space-3); border-radius: var(--radius-s); background: var(--surface); color: var(--text); box-shadow: var(--shadow-s);
}
.works-toggle { display: flex; align-items: center; gap: var(--space-2); min-height: 44px; font-weight: 700; cursor: pointer; }
.works-toggle input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.works-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.works-legend li { display: flex; align-items: center; gap: var(--space-2); }
.swatch { flex: none; width: 28px; height: 0; border-top: 5px solid var(--works-closed); }
.swatch-lane { border-top: 5px dashed var(--works-lane); }
.swatch-works { border-top: 5px dotted var(--works-works); }
.swatch-upcoming { border-top: 5px solid var(--muted); opacity: 0.5; }
/* ---- junction network: the note sits top left, clear of the zoom and layer buttons on the right; the numbers are solid badges with a border ---- */
.network-note {
    position: absolute; top: 10px; left: 10px; z-index: 400; margin: 0; max-width: min(300px, calc(100% - 10px - 64px - env(safe-area-inset-left)));
    padding: 6px 10px; border-radius: var(--radius-s); background: var(--surface); color: var(--muted); box-shadow: var(--shadow-s); font-size: 0.75rem; line-height: 1.35;
    border-left: 4px solid var(--network); pointer-events: none;
}
.network-note:empty { display: none; }
.mmr-junction { background: transparent; border: 0; width: 0; height: 0; }
.mmr-junction span {
    position: absolute; transform: translate(-50%, -50%); box-sizing: border-box; min-width: 32px; height: 28px; padding: 0 6px;
    display: flex; align-items: center; justify-content: center; border-radius: var(--radius-s); border: 2px solid var(--network);
    background: var(--surface); color: var(--text); font-weight: 800; font-size: 1rem; line-height: 1; box-shadow: var(--shadow-s); white-space: nowrap;
}
.works-popup { max-width: 260px; }
.works-popup p { margin: 4px 0 0; }

#blazor-error-ui { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; padding: var(--space-3) var(--space-4); background: var(--danger-bg); color: var(--danger); }
#blazor-error-ui .dismiss { float: right; background: transparent; border: 0; color: inherit; cursor: pointer; min-width: 44px; min-height: 44px; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

.search-button { margin-top: 6px; }

/* ---- map controls: sized for fingers, kept clear of the sheet ---- */
.leaflet-touch .leaflet-bar a, .leaflet-bar a {
    width: 44px; height: 44px; line-height: 44px; font-size: 22px;
}
.leaflet-control-attribution a { display: inline-block; padding: 5px 3px; }
.leaflet-bottom { bottom: calc(var(--sheet-offset) + var(--tabbar-h)); transition: bottom 0.22s ease; }
@media (prefers-reduced-motion: reduce) { .leaflet-bottom { transition: none; } }

/* Leaflet's own controls come in light colours: the zoom buttons, the attribution, popups. The vendored leaflet.css is left alone. */
.leaflet-container { background: var(--bg); font-family: var(--font); }
.leaflet-bar { border: 2px solid var(--border); box-shadow: var(--shadow-s); }
.leaflet-bar a, .leaflet-bar a:hover, .leaflet-bar a:focus { background-color: var(--surface); color: var(--text); border-bottom-color: var(--border); }
.leaflet-bar a:hover, .leaflet-bar a:focus { background-color: var(--surface-2); }
.leaflet-bar a.leaflet-disabled { background-color: var(--surface); color: var(--muted); opacity: 0.6; }
.leaflet-container .leaflet-control-attribution { background: color-mix(in srgb, var(--bg) 82%, transparent); color: var(--muted); }
.leaflet-container .leaflet-control-attribution a { color: var(--accent); }
.leaflet-container a { color: var(--accent); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--shadow-s); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

@media (max-width: 480px) {
    .characteristics { grid-template-columns: 1fr; gap: 0; }
    .characteristics dt { margin-top: 6px; }
}

/* ---- a new version is ready ---- */
.update-banner {
    position: fixed; left: var(--space-3); right: var(--space-3); bottom: calc(var(--space-3) + env(safe-area-inset-bottom)); z-index: 1100;
    display: flex; gap: var(--space-3); align-items: center; justify-content: space-between;
    padding: 10px var(--space-3); border-radius: var(--radius);
    background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow);
}
.update-banner[hidden] { display: none; }
.update-banner button { min-height: 44px; padding: var(--space-2) 14px; border-radius: var(--radius); border: 2px solid currentColor; background: transparent; color: inherit; font-weight: 700; cursor: pointer; }

/* saved routes */
.saved-list { list-style: none; margin: 0; padding: 0; }
.saved-item { display: flex; align-items: stretch; gap: var(--space-2); border-bottom: 1px solid var(--border, var(--surface-2)); }
.saved-item:last-child { border-bottom: 0; }
.saved-open { flex: 1 1 auto; min-width: 0; min-height: 44px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; padding: var(--space-2) 0; border: 0; background: transparent; color: var(--text); text-align: left; cursor: pointer; font: inherit; }
.saved-open:disabled { cursor: default; color: var(--muted); }
.saved-name { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-meta { color: var(--muted); font-size: 0.875rem; }
.saved-delete { flex: 0 0 auto; align-self: center; }
.saved-item .error-banner { flex: 1 1 auto; margin: var(--space-2) 0; }
.save-form { display: flex; flex-direction: column; gap: var(--space-1); width: 100%; }
.save-form input { min-height: 44px; }
.save-actions { display: flex; align-items: center; gap: var(--space-2); }
.saved-route-notice { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
.saved-route-notice p { margin: 0; }

/* share link */
.share-box { flex: 1 1 100%; display: flex; flex-direction: column; gap: var(--space-1); }
.share-box input { min-height: 44px; width: 100%; box-sizing: border-box; }
.shared-link-notice, .shared-route-waiting { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.shared-link-notice p, .shared-route-waiting { margin: 0; }

/* the EpiCycle mark and name */
.logo { display: inline-flex; align-items: center; gap: var(--space-2); }
.logo-mark { width: 32px; height: 32px; flex: none; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.logo-mountain, .logo-road { stroke: var(--accent); stroke-width: 3; }
.logo-sun { fill: var(--sun); stroke: none; }
.logo-name { font-weight: 800; letter-spacing: -0.02em; }
.logo-epi, .logo-ycle { color: var(--accent); }
.logo-c { color: var(--text); }
.logo-large .logo-mark { width: 56px; height: 56px; }
.logo-large .logo-name { font-size: var(--text-xl); }

/* the surface breakdown in the route details */
.surface-bars { margin-top: var(--space-4); }
.surface-title { font-size: var(--text-s); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 var(--space-2); }
.surface-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.surface-row { display: grid; grid-template-columns: minmax(0, 9em) 1fr 3.2em; align-items: center; gap: var(--space-2); font-size: var(--text-s); }
.surface-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.surface-track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.surface-fill { display: block; height: 100%; border-radius: 4px; background: var(--route-other); }
.surface-unknown .surface-fill { background: var(--border); }
.surface-share { text-align: right; color: var(--muted); }

/* ---- the wide layout: a top bar, the planning panel, the map with the route cards, the details of the chosen route ---- */
.shell {
    --side-w: clamp(300px, 28vw, 380px);
    --details-w: clamp(300px, 28vw, 400px);
    --top-h: 56px;
    height: 100dvh; display: grid; grid-template-rows: var(--top-h) minmax(0, 1fr); background: var(--bg); overflow: hidden;
}
.top-bar {
    position: relative; z-index: 600; display: flex; align-items: center; gap: var(--space-5); padding: 0 var(--space-4);
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.top-bar h1 { font-size: var(--text-l); }
.top-tabs { display: flex; gap: var(--space-1); align-self: stretch; }
.top-tab {
    display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 var(--space-3); border: 0; border-bottom: 3px solid transparent;
    background: transparent; color: var(--muted); font: inherit; font-weight: 700; cursor: pointer;
}
.top-tab:hover { color: var(--text); }
.top-tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.top-menu { position: relative; }
.top-button, .top-account {
    display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; min-width: 44px; padding: 0 var(--space-2); justify-content: center;
    border: 0; border-radius: 22px; background: transparent; color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.top-button { color: var(--muted); }
.top-button:hover, .top-account:hover, .top-button[aria-expanded="true"], .top-account[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.top-avatar {
    display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%;
    background: var(--accent); color: var(--accent-text); font-weight: 800;
}
.top-name { max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-card {
    position: absolute; right: 0; top: calc(100% + var(--space-2)); z-index: 700; width: min(340px, 90vw); max-height: calc(100dvh - var(--top-h) - 2 * var(--space-2)); overflow-y: auto;
    padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
}
.top-card:focus { outline: none; }
.top-card .about { margin-bottom: 0; background: transparent; padding: 0; }

/* the route cards along the bottom of the map, above the attribution */
.shell .leaflet-bottom { bottom: 0; transition: none; }
.route-cards {
    position: absolute; left: var(--space-3); right: var(--space-3); bottom: 40px; z-index: 450;
    display: flex; gap: var(--space-2); margin: 0; padding: 0; border: 0; min-width: 0; overflow-x: auto;
    pointer-events: none;   /* only the cards take the pointer; the map shows and answers between them */
}
.route-cards .route-card { pointer-events: auto; flex: 0 0 auto; width: 220px; margin: 0; box-shadow: var(--shadow); }

/* the details of the chosen route, in the right-hand panel */
.route-panel h2 { margin: 0; }
.details-places { color: var(--muted); margin: var(--space-1) 0 var(--space-3); }
.details-figures { display: flex; align-items: baseline; gap: var(--space-3); margin: var(--space-3) 0 var(--space-1); }
.details-figures .route-distance { font-size: var(--text-xl); }
.route-panel .route-actions { margin: var(--space-3) 0; }
.route-panel .compare { margin-top: var(--space-4); }

/* the three regions under the top bar */
.shell-body { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 0; }
.shell-body[data-details="true"] { grid-template-columns: var(--side-w) minmax(0, 1fr) var(--details-w); }
.side-panel, .details-panel { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--space-4); background: var(--surface); }
.side-panel { border-right: 1px solid var(--border); }
.details-panel { border-left: 1px solid var(--border); }
.map-region { position: relative; min-width: 0; min-height: 0; overflow: hidden; }

/* the planning panel is as narrow as a phone: four strategies fit as icon over label, like on a phone */
.side-panel .segmented.joined .segment { flex-direction: column; gap: 2px; font-size: 0.75rem; min-height: 52px; padding: 6px 2px; }

/* the tab bar of the phone layout, under the sheet */
.tab-bar {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 510; display: flex; height: var(--tabbar-h);
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: var(--surface); border-top: 1px solid var(--border);
}
.tab {
    flex: 1 1 0; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 0.75rem; font-weight: 700; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--accent); }

/* in the phone layout the route cards are a row inside the sheet, swiped sideways, instead of lying over the map */
.sheet .route-cards {
    position: static; inset: auto; z-index: auto; pointer-events: auto;
    margin: 0 calc(-1 * var(--space-4)); padding: var(--space-1) var(--space-4) var(--space-2);
    scroll-snap-type: x proximity; scroll-padding: 0 var(--space-4); overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
}
.sheet .route-cards .route-card { width: 210px; scroll-snap-align: start; box-shadow: none; }
.sheet .results { padding-top: var(--space-2); }
@media (prefers-reduced-motion: reduce) { .sheet .route-cards { scroll-behavior: auto; } }

/* on/off settings are switches: the same checkbox, with a track and a thumb (role="switch" makes it announce as one) */
input[role="switch"] {
    -webkit-appearance: none; appearance: none; position: relative; flex: none; width: 48px; height: 28px; margin: 0;
    border: 2px solid var(--border); border-radius: 14px; background: var(--surface-2); cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
input[role="switch"]::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted);
    transition: transform 0.15s ease, background 0.15s ease;
}
input[role="switch"]:checked { background: var(--accent); border-color: var(--accent); }
input[role="switch"]:checked::after { transform: translateX(20px); background: var(--accent-text); }
.checkbox input[role="switch"] { width: 48px; height: 28px; margin-top: 8px; }   /* centred in its 44px row */
.works-toggle input[role="switch"] { width: 48px; height: 28px; }
@media (prefers-reduced-motion: reduce) { input[role="switch"], input[role="switch"]::after { transition: none; } }

/* sliders: a track that fills with the accent up to the thumb, and a round thumb */
input[type="range"] { -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; --fill: 0%; }
input[type="range"]::-webkit-slider-runnable-track {
    height: 6px; border-radius: 3px; border: 1px solid var(--border);
    background: linear-gradient(to right, var(--accent) var(--fill), var(--surface-2) var(--fill));
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; border: 1px solid var(--border); background: var(--surface-2); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none; width: 24px; height: 24px; margin-top: -10px; border-radius: 50%;
    background: var(--accent); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--accent); }

.import-panel input[type="file"] { max-width: 100%; margin-top: var(--space-2); }
