:root {
    --bg-dark: #15151E;
    --bg-card: #1E1E28;
    --text-primary: #ffffff;
    --text-muted: #8b8b99;
    --border-color: #383842;
    --accent: #E10600;
}

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

body {
    font-family: 'Titillium Web', sans-serif;
    background: radial-gradient(circle at 50% 0%, #1e1e2d 0%, #111118 70%, #0a0a0f 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.5;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Montserrat', sans-serif;
    text-transform: uppercase;
    font-weight: 700;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: 
        repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.15) 0px, rgba(0, 0, 0, 0.15) 2px, transparent 2px, transparent 4px),
        repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.15) 0px, rgba(0, 0, 0, 0.15) 2px, transparent 2px, transparent 4px),
        rgba(26, 26, 35, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 3px solid var(--accent);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.f1-badge {
    background-color: var(--accent);
    color: #ffffff;
    font-family: 'Montserrat', sans-serif;
    font-weight: 900;
    font-style: italic;
    font-size: 1.15rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 28px;
    border-radius: 4px;
    letter-spacing: -1.5px;
    padding-right: 2px; /* Compensate for italic slant to ensure text feels flush-centered */
    box-shadow: 0 0 15px rgba(229, 0, 4, 0.4);
}

.logo-text {
    font-size: 1.125rem;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #f3f4f6;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.app-version-badge {
    font-size: 0.65rem;
    font-family: 'Titillium Web', sans-serif;
    font-weight: 600;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(0, 0, 0, 0.2);
}

.controls label {
    margin-right: 0.75rem;
    font-size: 0.8rem;
    font-family: 'Montserrat', sans-serif;
    color: var(--accent);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1.5px;
}

/* Visually Hidden but Accessible Native Select */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Custom Glassmorphic Select Menu */
.custom-select-container {
    position: relative;
    display: inline-block;
    min-width: 260px;
}

.custom-select-trigger {
    background-color: #111118;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1.25rem;
    border-radius: 4px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
    cursor: pointer;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.custom-select-trigger:hover, .custom-select-container.active .custom-select-trigger {
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(229, 0, 4, 0.25);
}

.custom-select-arrow {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--accent);
    transition: transform 0.2s ease;
}

.custom-select-container.active .custom-select-arrow {
    transform: rotate(180deg);
}

.custom-select-options {
    position: absolute;
    top: 105%;
    right: 0; /* Align right to ensure choices never go off the window edge! */
    width: 100%;
    background: rgba(20, 20, 28, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    margin-top: 0.25rem;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1001;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6), inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: all 0.2s ease-in-out;
}

.custom-select-options.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    pointer-events: none;
}

.custom-select-option {
    padding: 0.75rem 1.25rem;
    color: var(--text-primary);
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.custom-select-option:last-child {
    border-bottom: none;
}

.custom-select-option:hover {
    background-color: var(--accent);
    color: #ffffff;
}

.custom-select-option.selected {
    background-color: rgba(229, 0, 4, 0.15);
    border-left: 3px solid var(--accent);
    color: #ffffff;
}

.dashboard {
    padding: 2rem;
    max-width: 1600px;
    margin: 0 auto;
}

.dashboard-header {
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.dashboard-header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.25rem;
    letter-spacing: 1px;
}

.dashboard-header p {
    color: var(--text-muted);
    font-size: 1.125rem;
    font-weight: 600;
}

.viz-container {
    background: rgba(30, 30, 40, 0.65);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5), 
                inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
}

.viz-container h2 {
    font-size: 1.125rem;
    margin-bottom: 0;
    letter-spacing: 1px;
}

.viz-header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.viz-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-family: 'Montserrat', sans-serif;
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
}

.legend-container {
    display: flex;
    gap: 1rem;
    align-items: center;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    padding: 0.15rem 0.25rem;
    transition: opacity 0.2s;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
}

.legend-item:hover {
    opacity: 0.8;
}

.legend-item.inactive {
    opacity: 0.3;
}

.legend-color {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.chart {
    width: 100%;
    min-height: 400px;
    position: relative;
    overflow: hidden;
}

#beeswarm-plot {
    min-height: 600px;
}

/* Enhancements for SVG Circles */
circle.data-point {
    filter: drop-shadow(0px 1px 2px rgba(0,0,0,0.5));
    transition: r 0.2s ease, opacity 0.3s ease;
}

circle.data-point:hover {
    filter: drop-shadow(0px 2px 4px rgba(255,255,255,0.2));
}

.driver-label {
    cursor: pointer;
    transition: fill 0.2s;
}

.driver-label:hover {
    fill: #ffffff !important;
}

.median-line {
    stroke-width: 4px;
    stroke-linecap: round;
    opacity: 1;
    filter: drop-shadow(0px 1px 3px rgba(0,0,0,0.9));
}

#corner-speed-chart {
    min-height: auto;
}

.speed-subplots {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 1200px) {
    .speed-subplots {
        grid-template-columns: 1fr;
    }
}

.subplot-container {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
}

.subplot-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    text-align: center;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.team-node {
    transition: filter 0.2s, transform 0.2s;
    filter: drop-shadow(0px 1px 3px rgba(0,0,0,0.8));
}

.team-node:hover {
    filter: drop-shadow(0px 2px 5px rgba(255,255,255,0.3));
    /* transform scale removed to prevent breaking SVG transform attribute, handled via d3 radius */
}

.tooltip {
    position: absolute;
    background: rgba(20, 20, 28, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    border-left: 4px solid var(--accent);
    pointer-events: none;
    font-size: 0.875rem;
    z-index: 1000;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5),
                inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
    font-family: 'Titillium Web', sans-serif;
    color: var(--text-primary);
}

.tooltip.hidden {
    opacity: 0;
}

/* D3 SVG Styles */
.domain, .tick line {
    stroke: var(--border-color);
}
.tick text {
    fill: var(--text-muted);
    font-family: 'Titillium Web', sans-serif;
    font-weight: 600;
    font-size: 12px;
}
.gridline line {
    stroke: var(--border-color);
    stroke-opacity: 0.3;
    shape-rendering: crispEdges;
}
.gridline path {
    stroke-width: 0;
}

/* Disclaimer Badge for Simulated Telemetry */
.badge-estimate {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    margin-left: 0.75rem;
    letter-spacing: 0.75px;
    vertical-align: middle;
    border: 1px solid var(--border-color);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    display: inline-block;
}

/* Responsive design adjustments */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        padding: 1rem 1.5rem;
    }
    
    .controls {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
    }
    
    select {
        flex-grow: 1;
        max-width: 70%;
        min-width: 100%;
    }
}

/* F1 Track Orbit Loader Overlay */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    opacity: 1;
    visibility: visible;
}

.loader-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.f1-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.loader-spinner-container {
    width: 120px;
    height: 120px;
    position: relative;
}

.tire-tread {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 6px dashed var(--border-color);
    animation: rotate-tire 6s linear infinite;
    position: absolute;
    top: 0;
    left: 0;
}

.track-orbit {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 2px solid rgba(229, 0, 4, 0.2);
    position: absolute;
    top: 10px;
    left: 10px;
    box-shadow: 0 0 15px rgba(229, 0, 4, 0.1);
}

.f1-car-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent);
    position: absolute;
    top: 6px;
    left: 56px;
    box-shadow: 0 0 10px var(--accent), 0 0 20px var(--accent);
    transform-origin: 4px 54px; /* Perfectly concentric rotation (60px center relative to 6px top-left) */
    animation: orbit-car 1.2s cubic-bezier(0.5, 0.1, 0.5, 0.9) infinite;
}

.loader-text {
    margin-top: 1.5rem;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 0.875rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--text-primary);
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    animation: pulse-text 1.5s ease-in-out infinite;
}

@keyframes rotate-tire {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes orbit-car {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

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

/* Two-Column Grid and Standings Sidebar Widget */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    align-items: start;
}

@media (min-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: 74% 26%;
    }
}

.main-column {
    display: flex;
    flex-direction: column;
}

.sidebar-column {
    position: sticky;
    top: 100px;
    z-index: 100;
}

#standings-container h2 {
    font-size: 1.125rem;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.standings-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.standings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
    font-family: 'Titillium Web', sans-serif;
    cursor: pointer;
}

.standings-row:hover {
    transform: translateX(4px);
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.08);
}

.standings-row-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.standings-pos {
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--accent);
    width: 24px;
    text-align: center;
}

.standings-color-bar {
    width: 4px;
    height: 20px;
    border-radius: 2px;
}

.standings-driver-info {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.standings-code-team {
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.standings-team-name {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.standings-row-right {
    text-align: right;
}

.standings-gap {
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.standings-laps-dnf {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}