:root {
    --rm-primary: #e23126;
    --rm-radius-container: 8px;
    --rm-radius-map: 8px;
}

.race-map-wrapper.map-style-dark {
    --rm-overlay-bg: var(--rm-overlay-bg-dark);
    --rm-overlay-text: var(--rm-overlay-text-dark);
    --rm-overlay-blur: var(--rm-overlay-blur-dark);
}

.rundrm-header-container,
header,
.site-header,
#masthead,
.elementor-location-header {
    z-index: 999999 !important;
    position: relative;
}

.leaflet-container .leaflet-control-attribution {
    display: block;
    max-width: calc(100% - 16px);
    padding: 2px 6px;
    color: #394150;
    background: rgba(255, 255, 255, 0.82);
    border-radius: 5px 0 0 0;
    font-size: 10px;
    line-height: 1.35;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    position: relative;
    z-index: 1;
    opacity: 1;
    white-space: normal;
}

.leaflet-container .leaflet-control-attribution a {
    color: #1f5d93;
    text-decoration: underline;
}

/* Provider credits must remain above the map's custom controls and overlays. */
.race-map-wrapper .leaflet-control-container .leaflet-bottom {
    z-index: 120 !important;
}

.race-map-wrapper .leaflet-control-attribution {
    pointer-events: auto;
}

.race-map-wrapper {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
    margin-bottom: 30px;
    position: relative;
    z-index: 1;
    isolation: isolate;
    border-radius: var(--rm-radius-container);
    box-shadow: var(--rm-shortcode-shadow, none);
    display: block;
    border: var(--rm-border-width-container, 0px) solid var(--rm-border-color-container, transparent);
    box-sizing: border-box;
}

.race-map-wrapper:focus {
    outline: none;
}

.race-map-gesture-hint {
    position: absolute;
    left: 50%;
    bottom: 18px;
    z-index: 950;
    max-width: calc(100% - 32px);
    padding: 9px 14px;
    border: 1px solid color-mix(in srgb, var(--rm-overlay-text) 24%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--rm-overlay-bg) 88%, transparent);
    color: var(--rm-overlay-text);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-size: 14px;
    font-weight: 650;
    line-height: 1.25;
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, 8px);
    transition: opacity 160ms ease, transform 160ms ease;
}

.race-map-gesture-hint.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

@supports not (color: color-mix(in srgb, black, white)) {
    .race-map-gesture-hint {
        border-color: rgba(255, 255, 255, 0.25);
        background: rgba(22, 28, 40, 0.9);
        color: #fff;
    }
}

@media (max-width: 560px) {
    .race-map-gesture-hint {
        bottom: 12px;
        max-width: calc(100% - 24px);
        white-space: normal;
    }
}

.race-map-header-overlay {
    width: 250px;
    max-width: 100%;
}

.race-map-header-overlay.hidden {
    display: none;
}

.race-map-select-overlay {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    background-color: var(--rm-overlay-bg);
    color: var(--rm-overlay-text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(var(--rm-overlay-blur, 12px));
    -webkit-backdrop-filter: blur(var(--rm-overlay-blur, 12px));
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-hyphens: none;
    hyphens: none;
    transition: color 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.race-map-select-overlay option {
    white-space: normal;
    word-break: normal;
    -webkit-hyphens: none !important;
    hyphens: none !important;
}

.race-map-select-overlay:hover {
    color: var(--rm-primary);
}

.race-map-container {
    position: relative;
    width: 100%;
    padding: 0;
}

.race-map-canvas {
    width: 100%;
    height: 100dvh;
    /* Default to 100 dynamic viewport height */
    /* Default to 100 dynamic viewport height */
    background: #222;
    z-index: 1;
    display: block;
    border-radius: var(--rm-radius-map);
    overflow: hidden;
    border: var(--rm-border-width-map, 0px) solid var(--rm-border-color-map, transparent);
    box-sizing: border-box;
}

.race-map-canvas .leaflet-tile-pane,
.race-map-canvas .leaflet-tile-pane .leaflet-layer,
.race-map-canvas .leaflet-tile-pane .leaflet-tile-container,
.race-map-canvas .leaflet-tile-pane img,
.race-map-canvas img.leaflet-tile {
    filter: var(--rm-tile-filter, none);
    -webkit-filter: var(--rm-tile-filter, none);
}

.race-map-controls-overlay {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    width: 50%;
    max-width: 800px;
    min-width: 320px;
    padding: 10px 15px;
    background: var(--rm-overlay-bg);
    display: grid;
    grid-template-columns: 44px 44px minmax(0, 1fr);
    align-items: center;
    column-gap: 15px;
    row-gap: 0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(var(--rm-overlay-blur, 12px));
    -webkit-backdrop-filter: blur(var(--rm-overlay-blur, 12px));
    z-index: 90;
    pointer-events: auto;
}

.race-map-controls-overlay > .race-play-btn {
    grid-row: 1 / 4;
    align-self: center;
}

.race-map-controls-overlay > .race-play-btn:first-child {
    grid-column: 1;
}

.race-map-controls-overlay > .race-play-btn:nth-child(2) {
    grid-column: 2;
}

.race-map-controls-overlay button {
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.race-map-controls-overlay button:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.race-map-controls-overlay button:active {
    transform: translateY(0);
}

.race-play-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    color: var(--rm-overlay-text);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.race-play-btn:hover {
    border-color: var(--rm-primary);
    color: var(--rm-primary);
}

.race-play-btn svg {
    fill: currentColor;
    width: 16px;
    height: 16px;
    filter: drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.4));
}

.race-play-btn.locked {
    color: var(--rm-primary);
    border-color: var(--rm-primary);
    background: rgba(226, 49, 38, 0.1);
}

.race-timeline-wrapper {
    display: contents;
}

.race-live-cue {
    grid-column: 3;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 38px;
    margin-bottom: 6px;
    padding: 8px 12px;
    box-sizing: border-box;
    color: var(--rm-overlay-text);
    background: rgba(0, 0, 0, 0.24);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-left: 3px solid var(--rm-primary);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.race-live-cue.hidden {
    display: none;
}

.race-live-cue.is-milestone {
    background: rgba(245, 183, 0, 0.14);
    border-left-color: #f5b700;
}

.race-live-cue.is-lap {
    background: rgba(85, 183, 255, 0.13);
    border-left-color: #55b7ff;
}

.race-live-cue.is-finish {
    background: rgba(57, 181, 74, 0.14);
    border-left-color: #39b54a;
}

.race-live-cue-icon {
    flex: 0 0 auto;
    font-size: 16px;
}

.race-live-cue-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}

.race-live-cue-text-inner {
    display: inline-block;
    white-space: nowrap;
}

.race-elevation-canvas {
    grid-column: 3;
    grid-row: 2;
    width: 100%;
    height: 60px;
    display: block;
    background: transparent;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.race-elevation-canvas:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transform: translateY(-2px) scale(1.02);
}



/* --- INLINE STATS UNDER ELEVATION CANVAS --- */
.race-map-stats-inline {
    grid-column: 3;
    grid-row: 3;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-size: 13px;
    font-weight: 400;
    color: var(--rm-overlay-text);
    pointer-events: none;
    line-height: 1;
}

.race-stat-box-inline {
    padding: 3px 0;
    white-space: nowrap;
}

.race-stat-box-inline+.race-stat-box-inline::before {
    content: '|';
    margin-right: 8px;
    color: rgba(255, 255, 255, 0.4);
    text-shadow: 1px 0 0 rgba(0, 0, 0, 0.6);
    font-weight: 400;
}

.race-map-zoom-container {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 15px;
    z-index: 90;
    display: flex;
    pointer-events: auto;
}

.race-info-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(980px, calc(100% - 30px));
    max-width: calc(100% - 30px);
    max-height: calc(100% - 30px);
    overflow-y: auto;
    background: var(--rm-overlay-bg);
    color: var(--rm-overlay-text);
    padding: clamp(14px, 2vw, 24px);
    border-radius: 6px;
    z-index: 9999;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    backdrop-filter: blur(var(--rm-overlay-blur, 12px));
    -webkit-backdrop-filter: blur(var(--rm-overlay-blur, 12px));
}

.race-info-overlay.collapsed {
    transform: translate(-50%, -48%) scale(0.95);
    opacity: 0;
    pointer-events: none;
}

.race-info-overlay.expanded {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.race-info-overlay.hidden {
    display: none !important;
}

/* Keep the race information panel inside the map with a small, fixed inset. */
.race-info-overlay[id^="info-overlay-"] {
    top: 50%;
    bottom: auto;
    width: min(820px, calc(100% - 20px));
    max-width: calc(100% - 20px);
    max-height: calc(100% - 10px);
    box-sizing: border-box;
    overflow: hidden;
    align-items: stretch;
}

.race-info-overlay[id^="info-overlay-"].collapsed {
    transform: translate(-50%, -50%) scale(0.95);
}

.race-info-overlay[id^="info-overlay-"].expanded {
    transform: translate(-50%, -50%) scale(1);
}

.race-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 15px;
    padding: 10px 0;
}

.race-desc-title {
    display: block;
    font-weight: bold;
    font-size: 15px;
    margin: 0;
    color: var(--rm-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.race-desc-text {
    font-size: 13px;
    line-height: 1.4;
    color: var(--rm-overlay-text);
    opacity: 0.9;
    display: none;
    white-space: pre-wrap;
}

.race-info-overlay.expanded .race-desc-text {
    display: block;
}

.race-auto-stats-section,
.race-auto-directions-section {
    width: 100%;
    min-width: 0;
}

.race-info-overlay[id^="info-overlay-"] .race-auto-stats-section {
    flex: 0 0 auto;
}

.race-info-overlay[id^="info-overlay-"] .race-auto-directions-section {
    display: flex;
    flex: 0 1 auto;
    flex-direction: column;
    min-height: 0;
    overflow: visible;
}

/* Auto Stats & Auto Turn-by-Turn Directions in Info Overlay */
.race-info-divider {
    width: 100%;
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
    margin: 8px 0;
}

.race-auto-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--rm-primary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.race-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    gap: 8px;
    width: 100%;
    margin-bottom: 4px;
}

.race-stat-card {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 9px 11px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.race-stat-card-label {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.65);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.race-stat-card-value {
    font-size: clamp(13px, 1.5vw, 15px);
    font-weight: 700;
    color: var(--rm-overlay-text);
}

.race-stat-card-wide {
    grid-column: auto;
}

.race-directions-heading {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.race-directions-heading .race-auto-section-title {
    margin-bottom: 0;
}

.race-description-mode {
    display: inline-flex;
    flex: 0 0 auto;
    gap: 3px;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.2);
}

.race-description-mode-btn {
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 6px 10px;
    background: transparent;
    color: var(--rm-overlay-text);
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    opacity: 0.72;
}

.race-description-mode-btn.is-active {
    background: var(--rm-primary);
    color: #fff;
    opacity: 1;
}

.race-directions-list {
    display: flex;
    flex: 0 1 auto;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    min-height: 0;
    max-height: min(46vh, 430px);
    box-sizing: border-box;
    overflow-y: auto;
    padding: 8px 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.12);
    scrollbar-color: var(--rm-primary) rgba(255, 255, 255, 0.1);
    scrollbar-width: thin;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.race-info-overlay[id^="info-overlay-"] .race-directions-list {
    max-height: none;
}

.race-directions-list::-webkit-scrollbar {
    width: 8px;
}

.race-directions-list::-webkit-scrollbar-track {
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
}

.race-directions-list::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;
    background: var(--rm-primary);
    background-clip: padding-box;
}

.race-directions-intro {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 10px 11px;
    margin-bottom: 2px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-left: 3px solid var(--rm-primary);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--rm-overlay-text);
    font-size: 12px;
    line-height: 1.55;
}

.race-directions-intro-icon {
    flex: 0 0 auto;
    font-size: 15px;
    line-height: 1.25;
}

.race-direction-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: rgba(0, 0, 0, 0.22);
    border-left: 3px solid var(--rm-primary);
    padding: 7px 9px;
    border-radius: 0 6px 6px 0;
    font-size: 12px;
    line-height: 1.35;
}

.race-directions-list.is-short .race-direction-item {
    display: none;
}

.race-directions-list.is-detailed .race-directions-intro {
    display: none;
}

.race-direction-type-milestone {
    border-left-color: #f5b700;
    background: rgba(245, 183, 0, 0.13);
}

.race-direction-type-milestone .race-direction-text {
    font-weight: 600;
}

.race-direction-type-lap {
    border-left-color: #55b7ff;
    background: rgba(85, 183, 255, 0.12);
}

.race-direction-icon {
    font-size: 13px;
    flex-shrink: 0;
    margin-top: 1px;
}

.race-direction-text {
    flex: 1;
    color: var(--rm-overlay-text);
}

.race-directions-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    padding: 6px 0;
}

.race-spinner-mini {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--rm-primary);
    border-radius: 50%;
    animation: race-spin 0.8s linear infinite;
}

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

.race-toggle-btn {
    background: rgba(128, 128, 128, 0.2);
    border: none;
    padding: 4px 10px;
    color: var(--rm-overlay-text);
    font-size: 11px;
    cursor: pointer;
    border-radius: 4px;
    white-space: nowrap;
    transition: all 0.2s;
}

.race-toggle-btn:hover {
    background: rgba(128, 128, 128, 0.3);
    color: var(--rm-primary);
}

/* --- ROUTE POINTS PANEL --- */
.race-info-overlay[id^="emoji-overlay-"] {
    top: 5px;
    bottom: 5px;
    width: min(640px, calc(100% - 20px));
    max-width: calc(100% - 20px);
    max-height: none;
    box-sizing: border-box;
    overflow: hidden;
}

.race-info-overlay[id^="emoji-overlay-"].collapsed {
    transform: translateX(-50%) scale(0.95);
}

.race-info-overlay[id^="emoji-overlay-"].expanded {
    transform: translateX(-50%) scale(1);
}

.race-info-overlay[id^="emoji-overlay-"] .race-info-header {
    flex: 0 0 auto;
}

.race-emoji-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding-right: 3px;
    scrollbar-gutter: stable;
}

.race-points-toolbar {
    width: 100%;
    margin-bottom: 10px;
}

.race-points-search {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 11px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.2);
    color: inherit;
    font: inherit;
    font-size: 13px;
    outline: none;
}

.race-points-search:focus {
    border-color: var(--rm-primary);
    box-shadow: 0 0 0 2px rgba(226, 49, 38, 0.2);
}

.race-points-search::placeholder { color: currentColor; opacity: 0.65; }

.race-points-category {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    margin-bottom: 12px;
}

.race-points-category-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 3px 2px;
    color: var(--rm-primary);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.race-points-category-count {
    display: inline-flex;
    min-width: 20px;
    height: 20px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    font-size: 11px;
}

.race-points-category-meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.race-points-category-toggle {
    border: 0;
    padding: 3px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    color: inherit;
    font: inherit;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    text-transform: none;
}

.race-points-category-toggle:hover,
.race-points-category-toggle:focus-visible {
    background: var(--rm-primary);
    color: #fff;
}

.race-point-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border-radius: 6px;
    background: rgba(128, 128, 128, 0.2);
    transition: opacity 0.2s ease, background 0.2s ease;
}

.race-point-item.is-hidden { opacity: 0.5; }

.race-point-label {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
}

.race-point-icon { flex: 0 0 auto; font-size: 18px; line-height: 1; }

.race-point-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.race-point-distance { flex: 0 0 auto; opacity: 0.68; font-size: 11px; }

.race-point-actions { display: inline-flex; flex: 0 0 auto; gap: 5px; }

.race-point-actions button {
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    padding: 5px 7px;
    background: rgba(0, 0, 0, 0.2);
    color: inherit;
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.race-point-actions button:hover,
.race-point-actions button:focus-visible {
    border-color: var(--rm-primary);
    background: var(--rm-primary);
    color: #fff;
}

.race-point-actions .race-point-spotlight {
    min-width: 30px;
    padding-inline: 5px;
    font-size: 14px;
}

.race-map-wrapper .leaflet-tile-pane,
.race-map-wrapper .leaflet-overlay-pane,
.race-map-wrapper .leaflet-marker-icon,
.race-map-wrapper .leaflet-marker-shadow {
    transition: opacity 0.22s ease, filter 0.22s ease;
}

.race-map-wrapper.race-marker-spotlight-active .leaflet-marker-shadow,
.race-map-wrapper.race-marker-spotlight-active .leaflet-marker-icon:not(.race-marker-spotlight-selected) {
    opacity: 0.05 !important;
}

.race-map-wrapper.race-marker-spotlight-active .race-info-overlay:not(.hidden) {
    opacity: 0.1 !important;
    pointer-events: none;
}

.race-map-wrapper.race-marker-spotlight-active .leaflet-marker-icon.race-marker-spotlight-selected {
    z-index: 10000 !important;
    opacity: 1 !important;
    filter: drop-shadow(0 0 7px rgba(255, 255, 255, 0.95));
}

.race-marker-spotlight-halo {
    width: 0 !important;
    height: 0 !important;
    overflow: visible;
    pointer-events: none !important;
}

.race-marker-spotlight-halo span {
    position: absolute;
    top: 0;
    left: 0;
    width: 116px;
    height: 116px;
    transform: translate(-50%, -50%) scale(0.72);
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.75) 0%, rgba(255, 255, 255, 0.28) 32%, rgba(255, 255, 255, 0) 72%);
    box-shadow: 0 0 24px rgba(255, 255, 255, 0.75), 0 0 48px rgba(226, 49, 38, 0.55);
    box-shadow: 0 0 24px rgba(255, 255, 255, 0.75), 0 0 48px color-mix(in srgb, var(--rm-primary, #e23126) 55%, transparent);
    animation: race-marker-spotlight-glow 1s ease-in-out infinite alternate;
}

@keyframes race-marker-spotlight-glow {
    from {
        transform: translate(-50%, -50%) scale(0.72);
        opacity: 0.68;
    }
    to {
        transform: translate(-50%, -50%) scale(1.08);
        opacity: 1;
    }
}

/* --- UPDATED MARKER CSS --- */
.race-marker-container {
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    overflow: visible;
}

.race-marker-cluster-container {
    pointer-events: auto !important;
    width: 0 !important;
    height: 0 !important;
    overflow: visible;
}

.race-marker-cluster {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 42px;
    height: 42px;
    padding: 0 8px;
    transform: translate(-50%, -50%);
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    background: rgba(55, 65, 72, 0.88);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.18);
    color: #fff;
    cursor: pointer;
    font-size: 17px;
    line-height: 1;
    white-space: nowrap;
    transition: transform 0.16s ease, background 0.16s ease;
}

.race-marker-cluster:hover,
.race-marker-cluster:focus-visible {
    transform: translate(-50%, -50%) scale(1.08);
    background: rgba(35, 45, 52, 0.96);
    outline: none;
}

.race-marker-cluster-popup .leaflet-popup-content-wrapper,
.race-marker-focus-popup .leaflet-popup-content-wrapper {
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.75);
    border-radius: 6px;
    background: var(--rm-overlay-bg);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    color: var(--rm-overlay-text);
    backdrop-filter: blur(var(--rm-overlay-blur, 12px));
    -webkit-backdrop-filter: blur(var(--rm-overlay-blur, 12px));
}

.race-marker-cluster-popup .leaflet-popup-content,
.race-marker-focus-popup .leaflet-popup-content {
    margin: 0;
    width: auto !important;
}

.race-marker-cluster-popup .leaflet-popup-tip,
.race-marker-focus-popup .leaflet-popup-tip {
    box-sizing: border-box;
    border-right: 1px solid rgba(255, 255, 255, 0.75);
    border-bottom: 1px solid rgba(255, 255, 255, 0.75);
    background: var(--rm-overlay-bg);
}

.race-marker-cluster-popup .leaflet-popup-close-button,
.race-marker-focus-popup .leaflet-popup-close-button {
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: var(--rm-overlay-text);
    opacity: 0.8;
    font-size: 22px;
    line-height: 26px;
}

.race-marker-cluster-panel {
    width: min(300px, calc(100vw - 52px));
}

.race-marker-cluster-panel-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 48px 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 15px;
}

.race-marker-cluster-panel-heading span {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--rm-primary, #e23126);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    line-height: 22px;
    text-align: center;
}

.race-marker-cluster-panel-list {
    max-height: min(280px, 45vh);
    overflow-x: hidden;
    overflow-y: auto;
    padding: 6px;
    scrollbar-width: thin;
}

.race-marker-cluster-panel-item {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 18px;
    align-items: center;
    width: 100%;
    min-height: 48px;
    padding: 6px 8px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--rm-overlay-text);
    text-align: left;
    cursor: pointer;
}

.race-marker-cluster-panel-item:hover,
.race-marker-cluster-panel-item:focus-visible {
    background: rgba(255, 255, 255, 0.12);
    outline: none;
}

.race-marker-cluster-panel-icon {
    font-size: 23px;
    line-height: 1;
}

.race-marker-cluster-panel-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
}

.race-marker-cluster-panel-copy strong,
.race-marker-cluster-panel-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.race-marker-cluster-panel-copy strong {
    font-size: 14px;
}

.race-marker-cluster-panel-copy small {
    color: var(--rm-overlay-text);
    opacity: 0.62;
    font-size: 11px;
    text-transform: capitalize;
}

.race-marker-cluster-panel-arrow {
    color: var(--rm-overlay-text);
    font-size: 24px;
    line-height: 1;
    opacity: 0.5;
}

.race-marker-focus-card {
    display: flex;
    align-items: center;
    width: min(300px, calc(100vw - 64px));
    flex-direction: column;
    gap: 10px;
    padding: 18px 42px 16px;
    text-align: center;
}

.race-marker-focus-icon {
    display: block;
    width: 100%;
    font-size: 27px;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.race-marker-focus-text {
    display: block;
    width: 100%;
    font-size: 14px;
    font-weight: 750;
    line-height: 1.4;
    overflow-wrap: anywhere;
    white-space: normal;
}

.race-marker-focus-pulse {
    animation: race-marker-focus-pulse 1.4s ease-out infinite;
}

@keyframes race-marker-focus-pulse {
    0% { stroke-opacity: 1; stroke-width: 3; fill-opacity: 0.75; }
    70% { stroke-opacity: 0.25; stroke-width: 10; fill-opacity: 0.55; }
    100% { stroke-opacity: 0; stroke-width: 12; fill-opacity: 0.7; }
}

.race-marker-cluster-icons {
    max-width: 78px;
    overflow: hidden;
    letter-spacing: -3px;
}

.race-marker-cluster-count {
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--rm-primary, #e23126);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
}

.race-pin-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    pointer-events: none !important;
    transition: opacity 0.3s ease;
    position: absolute;
    bottom: 0;
    left: 0;
    transform: translateX(-50%);
    width: max-content;
}

.race-pin-wrapper:hover {
    transform: translateX(-50%) scale(1.1);
    z-index: 5000 !important;
}

.race-pin-emoji {
    font-size: 24px;
    line-height: 30px;
    z-index: 20;
    /* Ensure emoji is ON TOP of line */
    background: var(--rm-emoji-bg, rgba(255, 255, 255, 0.65));
    backdrop-filter: blur(var(--rm-emoji-blur, 8px));
    -webkit-backdrop-filter: blur(var(--rm-emoji-blur, 8px));
    border-radius: 15px;
    min-width: 30px;
    height: 30px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15), 0 2px 5px rgba(0, 0, 0, 0.1);
    color: var(--rm-emoji-text, #111111);
    pointer-events: auto !important;
    cursor: default;
    white-space: nowrap;
    position: relative;
}

.race-pin-line {
    width: 2px;
    background: #fff;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
    flex-grow: 1;
    z-index: 10;
    /* Lower z-index than emoji */
    position: relative;
}

.race-km-marker {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #666;
    border-radius: 50%;
    text-align: center;
    color: #333;
    font-weight: bold;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    line-height: 1;
    padding: 0;
    padding-top: 2.5px;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.race-km-marker.active {
    background: var(--rm-primary);
    border: 2px solid #ffffff;
    color: #ffffff;
    transform: scale(1.15);
    z-index: 3000 !important;
}

.race-km-marker.active span {
    transform: translateY(-0.5px) !important;
}


/* Scrubbing Mode */
.race-map-wrapper.scrubbing .race-pin-wrapper,
.race-map-wrapper.scrubbing .race-km-marker {
    opacity: 0.5;
}

.race-map-tooltip {
    background: rgba(0, 0, 0, 0.8);
    border: none;
    color: #fff;
    font-weight: bold;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
}

.leaflet-tooltip-left:before {
    border-left-color: rgba(0, 0, 0, 0.8);
}

.leaflet-tooltip-right:before {
    border-right-color: rgba(0, 0, 0, 0.8);
}

.leaflet-tooltip-top:before {
    border-top-color: rgba(0, 0, 0, 0.8);
}

.leaflet-tooltip-bottom:before {
    border-bottom-color: rgba(0, 0, 0, 0.8);
}



.race-download-btn {
    background-color: var(--rm-primary);
    color: #fff !important;
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.race-download-btn:hover {
    background-color: #c02015;
}

.race-download-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.race-map-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 60;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(20, 20, 20, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 30px 40px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.race-map-wrapper.loading .race-map-loader {
    display: flex;
}

.race-loader-content {
    position: relative;
    width: 60px;
    height: 50px;
    display: flex;
    justify-content: center;
}

.race-loader-pin {
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    background: var(--rm-primary);
    position: absolute;
    transform: rotate(-45deg);
    top: 0;
    animation: race-pin-bounce 1.2s infinite cubic-bezier(0.28, 0.84, 0.42, 1);
    box-shadow: inset -4px -4px 6px rgba(0,0,0,0.2);
}

.race-loader-pin::after {
    content: '';
    width: 14px;
    height: 14px;
    background: #fff;
    position: absolute;
    border-radius: 50%;
    top: 8px;
    left: 8px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.race-loader-shadow {
    width: 20px;
    height: 6px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    position: absolute;
    bottom: 0px;
    animation: race-shadow-scale 1.2s infinite cubic-bezier(0.28, 0.84, 0.42, 1);
    filter: blur(2px);
}

.race-loader-text {
    margin-top: 15px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    animation: race-text-pulse 1.5s infinite;
}

@keyframes race-pin-bounce {
    0%, 100% { transform: rotate(-45deg) translate(0, 0); }
    50% { transform: rotate(-45deg) translate(15px, -15px); }
}

@keyframes race-shadow-scale {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(0.5); opacity: 0.2; }
}

@keyframes race-text-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.race-download-btn-small {
    /* Inherits from .race-control-btn but adds specific tweaks if needed */
    display: flex;
    /* Make sure it uses flexbox */
}

.race-download-btn-small:hover {
    color: var(--rm-primary);
    /* Use primary color on hover like other buttons usually do or keep grey */
}

/* --- MAP TOOLS (Top Right) --- */
.race-map-tools {
    position: absolute;
    top: var(--rm-tools-margin-top, 15px);
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 90;
    align-items: flex-end;
    pointer-events: none;
}

.race-map-tools>* {
    pointer-events: auto;
}

.race-tools-toggle {
    display: none;
}

.race-control-group {
    background: var(--rm-overlay-bg);
    padding: 4px;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 4px;
    align-items: center;
    backdrop-filter: blur(var(--rm-overlay-blur, 12px));
    -webkit-backdrop-filter: blur(var(--rm-overlay-blur, 12px));
}

/* Layer Buttons */
.race-layer-btn {
    background: none;
    border: none;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    color: var(--rm-overlay-text);
    transition: all 0.2s;
}

.race-layer-btn.active {
    background: var(--rm-primary);
    color: #fff;
}

.race-layer-btn:hover:not(.active) {
    background: rgba(128, 128, 128, 0.2);
    color: var(--rm-primary);
}

/* Vertical Zoom Control */
.race-zoom-control {
    display: flex;
    flex-direction: column;
    padding: 4px;
    gap: 0;
    background: var(--rm-overlay-bg);
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: fit-content;
    backdrop-filter: blur(var(--rm-overlay-blur, 12px));
    -webkit-backdrop-filter: blur(var(--rm-overlay-blur, 12px));
}

.zoom-btn {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    font-size: 18px;
    font-weight: bold;
    color: var(--rm-overlay-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.zoom-btn:hover {
    background: rgba(128, 128, 128, 0.2);
    color: var(--rm-primary);
}

.zoom-btn.in {
    border-radius: 0;
}

.zoom-btn.center {
    border-radius: 6px 6px 0 0;
}

.zoom-btn.out {
    border-radius: 0 0 6px 6px;
}

/* Vertical Slider */
.zoom-slider {
    -webkit-appearance: slider-vertical;
    appearance: slider-vertical;
    width: 8px;
    height: 80px;
    background: #ddd;
    border-radius: 3px;
    outline: none;
    margin: 5px auto;
}

/* Fallback */
@supports not (-webkit-appearance: slider-vertical) {
    .zoom-slider {
        writing-mode: bt-lr;
        -webkit-appearance: none;
        appearance: none;
        width: 80px;
        height: 8px;
        transform: rotate(270deg);
        margin: 40px -36px;
    }
}

.race-control-btn {
    background: var(--rm-overlay-bg);
    border: none;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    color: var(--rm-overlay-text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s;
    backdrop-filter: blur(var(--rm-overlay-blur, 12px));
    -webkit-backdrop-filter: blur(var(--rm-overlay-blur, 12px));
}

.race-control-btn:hover {
    background: rgba(128, 128, 128, 0.2);
    color: var(--rm-primary);
}

/* Override Leaflet controls z-index to be lower than sticky headers */
.leaflet-top,
.leaflet-bottom {
    z-index: 40 !important;
}

/* Fullscreen overrrides */
.race-map-wrapper:fullscreen {
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
}

.race-map-wrapper:fullscreen .race-map-canvas {
    border-radius: 0 !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
}

.race-map-wrapper:-webkit-full-screen {
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 100vh !important;
}

.race-map-wrapper:-webkit-full-screen .race-map-canvas {
    border-radius: 0 !important;
    height: 100vh !important;
}

/* Photo Popup Overlay */
.race-photo-popup {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.race-photo-popup.hidden {
    opacity: 0;
    pointer-events: none;
}

.race-photo-popup-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    background: #000;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.race-photo-popup-content img {
    max-width: 100%;
    max-height: 90vh;
    display: block;
    object-fit: contain;
}

.race-photo-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: #fff;
    font-size: 14px;
    text-align: center;
    box-sizing: border-box;
    font-weight: 500;
    z-index: 10;
}

.close-photo {
    position: absolute;
    top: 10px;
    right: 15px;
    color: var(--rm-primary);
    font-size: 26px;
    font-weight: bold;
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    z-index: 10;
    line-height: 1;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
}

.close-photo:hover {
    background: rgba(0, 0, 0, 0.85);
    transform: scale(1.05);
}

/* --- ACCESSIBILITY / FOCUS STATES --- */
.race-map-wrapper button:focus-visible,
.race-map-wrapper a:focus-visible,
.race-map-wrapper select:focus-visible,
.race-map-wrapper input[type="range"]:focus-visible {
    outline: 2px solid var(--rm-primary);
    outline-offset: 2px;
}

@media (max-width: 768px) {
    .race-map-canvas .leaflet-bottom.leaflet-right {
        bottom: 125px;
    }

    .race-map-left-panel {
        right: 15px;
    }

    .race-map-header-overlay {
        width: 100%;
    }

    .race-map-tools> :not(.race-tools-toggle) {
        transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s;
    }

    .race-tools-toggle {
        display: flex;
        position: relative;
        width: 46px;
        height: 46px;
        justify-content: center;
        align-items: center;
        padding: 0;
        border-radius: 50% !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
        align-self: flex-end;
        flex-shrink: 0;
        margin-top: 4px;
    }

    .race-map-tools.is-hidden> :not(.race-tools-toggle) {
        transform: translateX(120%);
        opacity: 0;
        pointer-events: none;
    }

    .race-control-group {
        flex-wrap: nowrap;
        width: auto;
        justify-content: flex-end;
    }

    .race-map-controls-overlay {
        bottom: 15px;
        left: 15px;
        right: 15px;
        transform: none;
        width: auto;
        padding: 8px 10px;
        grid-template-columns: 44px 44px minmax(0, 1fr);
        column-gap: 10px;
        row-gap: 4px;
    }

    .race-map-controls-overlay > .race-play-btn {
        grid-row: 2 / 4;
    }


    .race-live-cue {
        grid-column: 1 / -1;
        grid-row: 1;
        min-height: 0;
        margin-bottom: 0;
        padding: 5px 7px;
        gap: 5px;
        font-size: clamp(8.5px, 2.45vw, 10px);
        line-height: 1.2;
    }

    .race-live-cue-text {
        display: block;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: clip;
    }

    .race-live-cue.is-scrolling .race-live-cue-text-inner {
        animation: race-cue-ping-pong var(--race-cue-scroll-duration, 12s) ease-in-out infinite;
    }

    .race-live-cue-icon {
        font-size: 13px;
    }

    button[id^="fullscreen-"] {
        display: none !important;
    }

    .race-map-stats-inline {
        justify-content: flex-start;
        font-size: 11px;
        gap: 5px;
        flex-wrap: wrap;
        /* Let it wrap if really tight */
    }

    .race-stat-box-inline+.race-stat-box-inline::before {
        margin-right: 5px;
    }

    .race-info-overlay {
        width: calc(100% - 20px);
        max-width: calc(100% - 20px);
        max-height: calc(100% - 20px);
        padding: 14px;
    }

    .race-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px 14px;
    }

    .race-stat-card {
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    .race-stat-card-wide {
        grid-column: 1 / -1;
    }

    .race-stat-card-label {
        font-size: 9px;
        opacity: 0.72;
    }

    .race-stat-card-value {
        font-size: 12px;
        line-height: 1.3;
    }

    .race-directions-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }

    .race-description-mode {
        width: 100%;
    }

    .race-description-mode-btn {
        flex: 1 1 50%;
    }
}

@keyframes race-cue-ping-pong {
    0%, 15% { transform: translateX(0); }
    45%, 55% { transform: translateX(var(--race-cue-scroll-distance, 0)); }
    85%, 100% { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
    .race-live-cue.is-scrolling .race-live-cue-text-inner { animation: none; }
    .race-live-cue-text { text-overflow: ellipsis; }
}

/* Route line styling */
.race-route-polyline {
    fill: none !important;
    stroke-linejoin: round;
    stroke-linecap: round;
}

/* SVG Arch style transitions */
.race-arch-wrapper {
    transition: transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.race-arch-wrapper:hover {
    transform: scale(1.15);
}
