:root {
    color-scheme: dark;
    --scrollbar-thumb: #64748B;
    --scrollbar-track: #131820;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);

    /* Typography */
    --font-display: 'Clash Display', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-sans: 'General Sans', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Type Scale */
    --step-micro: 0.75rem;
    --step-small: clamp(0.8125rem, 0.79rem + 0.1vw, 0.875rem);
    --step-body: clamp(0.9375rem, 0.9rem + 0.2vw, 1.0625rem);
    --step-lead: clamp(1.1875rem, 1.08rem + 0.5vw, 1.5rem);
    --step-kpi: clamp(1.5rem, 1.25rem + 1.1vw, 2.25rem);
    --step-hero: clamp(2.125rem, 1.5rem + 2.8vw, 3.75rem);

    /* Obsidian Broadcast Studio (Permanent Dark UI) */
    --ground: #0B0E12;
    --surface: #131820;
    --raised: #1B222D;
    --subtle: #252E3C;
    --border-tone: #283241;

    --ink: #F2F4F7;
    --ink-secondary: #9CA6B4;
    --ink-muted: #8A96A8;

    --accent: #E61919;
    --accent-ink: #FFFFFF;
    --accent-soft: #2D1114;

    --gold: #F5B82E;
    --gold-soft: #2D230E;

    --signal: #E61919;
    --signal-ink: #FFFFFF;
    --signal-soft: #2D1114;

    --positive: #34D399;
    --positive-soft: #0E2E23;

    --warning: #FBBF24;
    --warning-soft: #2E220B;

    --danger: #F87171;
    --danger-soft: #321417;

    --pulse: #FB7185;
    --pulse-soft: #33131C;

    /* Geometry & Safe Areas */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-pill: 999px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

@supports not (scrollbar-color: auto) {
    *::-webkit-scrollbar {
        width: 12px;
        height: 12px;
    }

    *::-webkit-scrollbar-track {
        background: var(--scrollbar-track);
    }

    *::-webkit-scrollbar-thumb {
        background: var(--scrollbar-thumb);
        border: 3px solid var(--scrollbar-track);
        border-radius: 999px;
    }
}

/* Base Reset & Typography */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background-color: var(--ground);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.25s ease, color 0.25s ease;
}

.tnum {
    font-variant-numeric: tabular-nums;
}

.font-display {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.05;
}

/* Native Android WebView Adaptation */
html.rr-native-webview .rr-hide-in-webview {
    display: none !important;
}

/* Hide Map Attribution Clutter */
.leaflet-control-attribution,
.maplibregl-ctrl-attrib,
.maplibregl-ctrl-attrib-inner,
.maplibregl-ctrl-bottom-right,
.maplibregl-ctrl-bottom-left,
.mapboxgl-ctrl-attrib,
.leaflet-control-container .leaflet-bottom {
    display: none !important;
}

/* SVG Icon Helper */
.rr-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: -0.18em;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.85;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.rr-icon-sm {
    width: 14px;
    height: 14px;
}

.rr-icon-lg {
    width: 20px;
    height: 20px;
}

/* Full-Bleed Map Viewport */
.rr-map-stage {
    position: relative;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--ground);
}

.rr-map-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background-color: var(--ground);
}

html[data-theme="night"] .rr-map-canvas.leaflet-tile-fallback .leaflet-tile-pane {
    filter: invert(100%) hue-rotate(180deg) brightness(93%) contrast(92%) saturate(85%);
}

/* Top Broadcast Bar (Map Overlay & Page Header) */
.rr-broadcast-topbar {
    position: absolute;
    top: calc(var(--safe-top) + 12px);
    left: calc(var(--safe-left) + 12px);
    right: calc(var(--safe-right) + 12px);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.rr-topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background-color: var(--surface);
    border-top: 2px solid var(--accent);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    pointer-events: auto;
    transition: background-color 0.25s ease;
}

.rr-brand-group {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.rr-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background-color: var(--accent-soft);
    border: 1.5px solid var(--accent);
    flex-shrink: 0;
    text-decoration: none;
    overflow: hidden;
}

.rr-brand-mark img {
    width: 26px;
    height: 26px;
    object-fit: contain;
}

.rr-race-title-wrap {
    min-width: 0;
}

.rr-race-meta {
    font-size: 11px;
    font-weight: 700;
    color: #FF5252;
    line-height: 1.1;
}

.rr-race-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
    line-height: 1.25;
}

.rr-topbar-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Pills & Badges */
.rr-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    background-color: var(--raised);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-decoration: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.12s ease;
}

.rr-pill:hover {
    background-color: var(--subtle);
}

.rr-pill:active {
    transform: scale(0.97);
}

.rr-pill-static {
    cursor: default;
}

.rr-pill-static:hover {
    background-color: var(--raised);
}

.rr-pill-live {
    background-color: var(--positive-soft);
    color: var(--positive);
}

.rr-pill-warning {
    background-color: var(--warning-soft);
    color: var(--warning);
}

.rr-pill-danger {
    background-color: var(--danger-soft);
    color: var(--danger);
}

.rr-pill-pulse {
    background-color: var(--pulse-soft);
    color: var(--pulse);
}

.rr-pill-gold {
    background-color: var(--gold-soft);
    color: var(--gold);
}

.rr-pill-signal {
    background-color: var(--signal);
    color: var(--signal-ink);
}

.rr-pill-signal:hover {
    background-color: var(--signal);
    opacity: 0.92;
}

.rr-pill-accent {
    background-color: var(--accent);
    color: var(--accent-ink);
}

.rr-pill-accent:hover {
    background-color: var(--accent);
    opacity: 0.92;
}

/* Live Status Dot */
.rr-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: currentColor;
    flex-shrink: 0;
}

@media (prefers-reduced-motion: no-preference) {
    .rr-live-dot {
        animation: rrPulseOpacity 1.6s ease-in-out infinite;
    }
}

@keyframes rrPulseOpacity {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.38;
        transform: scale(0.85);
    }
}

/* Crew Live Broadcast Ticker Banner */
.rr-broadcast-ticker {
    display: none;
    align-items: center;
    gap: 8px;
    background-color: var(--positive-soft);
    color: var(--positive);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    pointer-events: auto;
}

/* Architectural Cards & Sheets */
.rr-sheet {
    background-color: var(--surface);
    color: var(--ink);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: background-color 0.25s ease, color 0.25s ease;
}

.rr-cell {
    background-color: var(--raised);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}

.rr-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-muted);
    margin: 0 0 4px 0;
    line-height: 1.2;
}

.rr-value {
    font-size: var(--step-kpi);
    font-weight: 600;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    margin: 0;
}

.rr-sub {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-secondary);
    margin-top: 4px;
}

/* Editorial Race Bib Overlay Screens (Pre-Race, Standby, Finisher) */
.rr-overlay-backdrop {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
    background-color: rgba(11, 14, 18, 0.55);
}

dialog.rr-dialog-modal {
    border: none;
    padding: 0;
    margin: auto;
    background: transparent;
    max-width: min(94vw, 460px);
    width: 100%;
    color: var(--ink);
    overflow: visible;
}

dialog.rr-dialog-modal:modal {
    overscroll-behavior: contain;
}

dialog.rr-dialog-modal::backdrop {
    background-color: rgba(11, 14, 18, 0.65);
    overflow: hidden;
    overscroll-behavior: contain;
}

.rr-bib-card {
    position: relative;
    width: min(94vw, 460px);
    background-color: var(--surface);
    border-top: 3px solid var(--accent);
    color: var(--ink);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
    text-align: center;
    margin: auto;
}

.rr-bib-header-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    background-color: var(--accent-soft);
    border: 1.5px solid var(--accent);
    color: #FF5252;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 14px;
}

.rr-bib-title {
    font-family: var(--font-display);
    font-size: clamp(1.85rem, 1.45rem + 1.8vw, 2.5rem);
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin: 0 0 8px 0;
    line-height: 1.08;
}

.rr-bib-subtitle {
    font-size: 15px;
    color: var(--ink-secondary);
    margin: 0 0 20px 0;
    line-height: 1.45;
}

.rr-bib-media {
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    background-color: var(--raised);
}

.rr-bib-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 20px;
    text-align: left;
}

.rr-bib-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* Buttons */
.rr-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    border: none;
    background-color: var(--accent);
    color: var(--accent-ink);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.12s ease, background-color 0.2s ease;
}

.rr-btn:hover {
    opacity: 0.92;
}

.rr-btn:active {
    transform: scale(0.98);
}

.rr-btn-full {
    width: 100%;
}

.rr-btn-signal {
    background-color: var(--signal);
    color: var(--signal-ink);
}

.rr-btn-positive {
    background-color: var(--positive);
    color: #0B0E12;
}

.rr-btn-warning {
    background-color: var(--warning);
    color: #0B0E12;
}

.rr-btn-danger {
    background-color: var(--danger);
    color: #0B0E12;
}

.rr-btn-secondary {
    background-color: var(--raised);
    color: var(--ink);
}

.rr-btn-secondary:hover {
    background-color: var(--subtle);
    opacity: 1;
}

/* Form Elements */
.rr-field-group {
    margin-bottom: 14px;
}

.rr-field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-secondary);
    margin-bottom: 6px;
}

.rr-input,
.rr-select,
.rr-textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    background-color: var(--raised);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: max(1rem, 1em);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.rr-textarea {
    resize: vertical;
}

.rr-input:focus,
.rr-select:focus,
.rr-textarea:focus {
    border-color: var(--accent);
    background-color: var(--surface);
}

.rr-input:user-invalid,
.rr-select:user-invalid,
.rr-textarea:user-invalid {
    border-color: var(--danger);
}

.rr-input:focus-visible,
.rr-select:focus-visible,
.rr-textarea:focus-visible,
.rr-btn:focus-visible,
.rr-pill:focus-visible,
.rr-chip:focus-visible,
.rr-tab-btn:focus-visible,
.rr-admin-tab-btn:focus-visible,
.rr-cheer-fab:focus-visible,
.rr-cheer-tray-btn:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.visually-hidden:where(:not(:focus-within, :active)) {
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
}

/* Mobile PWA Install Banner */
.rr-pwa-banner {
    position: fixed;
    bottom: calc(var(--safe-bottom) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(150%);
    width: min(92vw, 420px);
    background-color: var(--surface);
    color: var(--ink);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    z-index: 100000;
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease, visibility 0.3s ease;
}

.rr-pwa-banner.pwa-visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.rr-pwa-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    flex-shrink: 0;
}

.rr-pwa-banner #pwaDismissBtn {
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
    flex-shrink: 0;
}

/* Custom Map Markers */
.rr-runner-pin-wrap {
    position: relative;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rr-runner-pin-pulse {
    display: none;
}

.rr-runner-pin-avatar {
    position: relative;
    width: 34px;
    height: 34px;
    object-fit: contain;
    z-index: 2;
}

.rr-runner-pin-core {
    position: relative;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: var(--accent);
    border: 3px solid #FFFFFF;
    z-index: 2;
}

@keyframes rrPinExpand {
    0% {
        transform: scale(0.55);
        opacity: 0.65;
    }

    100% {
        transform: scale(1.75);
        opacity: 0;
    }
}

/* YouTube Live-Style Broadcast Cheer Dock, Reaction Tray & Floating Fountain */
.rr-cheer-dock {
    position: absolute;
    right: calc(var(--safe-right) + 16px);
    bottom: var(--cheer-bottom, calc(var(--safe-bottom) + 22px));
    z-index: 1250;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
    transition: bottom 0.25s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}

.rr-cheer-dock.cheer-sheet-hidden {
    opacity: 0;
    pointer-events: none !important;
}

.rr-cheer-tray {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: var(--radius-pill);
    background-color: var(--surface);
    border: 1.5px solid var(--accent);
    opacity: 0;
    transform: translateY(10px) scale(0.92);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.rr-cheer-dock.tray-open .rr-cheer-tray {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.rr-cheer-tray-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #FFFFFF;
    background-color: var(--raised);
    transition: transform 0.14s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.15s ease;
}

.rr-cheer-tray-btn:hover {
    transform: scale(1.14);
}

.rr-cheer-tray-btn:active {
    transform: scale(0.88);
}

.rr-cheer-tray-btn[data-reaction="love"] {
    background-color: #FF2D55;
    color: #FFFFFF;
}

.rr-cheer-tray-btn[data-reaction="flame"] {
    background-color: #FF6B1A;
    color: #FFFFFF;
}

.rr-cheer-tray-btn[data-reaction="clap"] {
    background-color: #E61919;
    color: #FFFFFF;
}

.rr-cheer-tray-btn[data-reaction="trophy"] {
    background-color: #F5B82E;
    color: #0B0E12;
}

.rr-cheer-tray-btn[data-reaction="bolt"] {
    background-color: #18B76A;
    color: #FFFFFF;
}

.rr-cheer-fab {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 9px 16px;
    border-radius: var(--radius-pill);
    border: 1.5px solid rgba(255, 255, 255, 0.14);
    background-color: var(--accent);
    color: var(--accent-ink);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: transform 0.14s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.2s ease;
}

.rr-cheer-fab:active,
.rr-cheer-fab.fab-pop {
    transform: scale(0.92);
}

.rr-cheer-bubble {
    position: fixed;
    z-index: 2600;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    border: 1.5px solid rgba(255, 255, 255, 0.22);
    will-change: transform, opacity;
}

@media (prefers-reduced-motion: no-preference) {
    .rr-cheer-bubble {
        animation: rrYoutubeFloatWave var(--float-dur, 3.1s) cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
    }
}

.rr-cheer-bubble[data-reaction="love"] {
    background-color: #FF2D55;
    color: #FFFFFF;
}

.rr-cheer-bubble[data-reaction="flame"] {
    background-color: #FF6B1A;
    color: #FFFFFF;
}

.rr-cheer-bubble[data-reaction="clap"],
.rr-cheer-bubble[data-reaction="cheer"] {
    background-color: #E61919;
    color: #FFFFFF;
}

.rr-cheer-bubble[data-reaction="trophy"] {
    background-color: #F5B82E;
    color: #0B0E12;
}

.rr-cheer-bubble[data-reaction="bolt"] {
    background-color: #18B76A;
    color: #FFFFFF;
}

@keyframes rrYoutubeFloatWave {
    0% {
        opacity: 0;
        transform: translate3d(0, 0, 0) scale(0.32);
    }
    10% {
        opacity: 1;
        transform: translate3d(var(--sway-1, -12px), var(--y-1, -28px), 0) scale(1.14);
    }
    28% {
        opacity: 1;
        transform: translate3d(var(--sway-2, 16px), var(--y-2, -78px), 0) scale(1);
    }
    55% {
        opacity: 1;
        transform: translate3d(var(--sway-3, -18px), var(--y-3, -150px), 0) scale(1);
    }
    78% {
        opacity: 0.92;
        transform: translate3d(var(--sway-4, 14px), var(--y-4, -210px), 0) scale(0.95);
    }
    100% {
        opacity: 0;
        transform: translate3d(var(--sway-5, -8px), var(--y-5, -260px), 0) scale(0.74);
    }
}

/* Toast Notification */
.rr-toast-container {
    position: fixed;
    bottom: calc(var(--safe-bottom) + 20px);
    right: calc(var(--safe-right) + 20px);
    z-index: 200000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.rr-toast {
    background-color: var(--ink);
    color: var(--ground);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    pointer-events: auto;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

@media (display-mode: standalone) {
    .rr-pwa-banner {
        display: none !important;
    }
}

/* Mobile Responsive Reflows (Phones <= 768px) */
@media (max-width: 768px) {
    .rr-broadcast-topbar {
        top: calc(var(--safe-top) + 8px);
        left: calc(var(--safe-left) + 8px);
        right: calc(var(--safe-right) + 8px);
    }

    .rr-topbar-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px 12px;
    }

    .rr-brand-group {
        width: 100%;
    }

    .rr-topbar-controls {
        width: 100%;
        flex-wrap: nowrap;
        justify-content: flex-start;
        overflow-x: auto;
        scrollbar-width: none;
        gap: 6px;
    }

    .rr-topbar-controls::-webkit-scrollbar {
        display: none;
    }

    .rr-hide-mobile {
        display: none !important;
    }

    .rr-pill {
        min-height: 36px;
        padding: 5px 10px;
        font-size: 12px;
        flex-shrink: 0;
    }

    .rr-bib-card {
        padding: 22px 18px;
    }

    .rr-bib-grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .rr-cheer-dock {
        right: calc(var(--safe-right) + 12px);
    }

    .rr-cheer-fab {
        min-height: 40px;
        padding: 7px 14px;
        font-size: 13px;
    }

    .rr-cheer-tray-btn {
        width: 34px;
        height: 34px;
    }

    .rr-cheer-bubble {
        width: 34px;
        height: 34px;
    }
}

@media (pointer: coarse) {
    .rr-pwa-banner #pwaDismissBtn,
    .rr-chip {
        min-block-size: 44px;
        min-inline-size: 44px;
    }
}