:root {
    --bg-main: #0f172a;       /* Slate 900 */
    --bg-card: #1e293b;       /* Slate 800 */
    --bg-input: #334155;      /* Slate 700 */
    --accent: #3b82f6;        /* Racing Blue */
    --accent-glow: rgba(59, 130, 246, 0.15);
    --text-main: #f8fafc;     /* Slate 50 */
    --text-muted: #94a3b8;    /* Slate 400 */
    --gold: #f59e0b;          /* Highlight Gold */
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    padding: 20px;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1300px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h2 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    margin: 0 0 8px 0;
    background: linear-gradient(to right, #fff, var(--text-muted));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-muted);
    margin: 0;
}

/* Premium Custom Dropdown Wrapper */
.selector-box {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 35px;
    flex-wrap: wrap; /* Prevents overflow on narrow screens */
}

.selector-box label {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

select {
    background-color: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--bg-input);
    padding: 10px 40px 10px 16px; /* Extra padding on the right for the arrow */
    font-size: 0.95rem;
    border-radius: 8px;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    
    min-width: 420px;
    max-width: 100%;
    text-overflow: ellipsis;

    /* Custom Arrow Styling */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    
    /* Subtle inline SVG arrow */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
}

select:hover {
    border-color: rgba(255, 255, 255, 0.25);
}

select:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

/* Responsive Grid Replacing the Old Table */
.leaderboard-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Driver Row Card - Optimized for 3 Columns */
.driver-card {
    background-color: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    display: grid;
    /* Columns: 260px Profile, 140px Best Time, and the remaining space for the Run Matrix */
    grid-template-columns: 260px 140px 1fr;
    align-items: center;
    padding: 16px;
    transition: transform 0.2s ease, border-color 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Delete or comment out the old .car-badge style block since we are dropping it */
.driver-card:hover {
    border-color: rgba(59, 130, 246, 0.3);
    transform: translateY(-1px);
}

/* Car Number Badge */
.car-badge {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
    padding: 8px;
    border-radius: 8px;
    text-align: center;
    max-width: 45px;
}

/* Profile Section */
.driver-profile strong {
    font-size: 1.1rem;
    font-weight: 700;
    display: block;
    margin-bottom: 2px;
}

.driver-profile span {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Outright Fastest Display */
.fastest-block {
    text-align: left;
    border-right: 1px solid var(--bg-input);
    padding-right: 15px;
}

.fastest-block .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    display: block;
}

.fastest-block .time {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--gold);
    font-variant-numeric: tabular-nums;
}

/* Horizontal Run Container */
.runs-container {
    display: grid;
    grid-template-columns: repeat(6, minmax(110px, 1fr));
    gap: 8px;
    padding-left: 15px;
}

/* Individual Run Block (Layout 2 Matrix Grid) */
.run-block {
    background: var(--bg-main);
    border: 1px solid var(--bg-input);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 52px;
}

.run-block .splits {
    display: grid;
    grid-template-columns: 1fr 1fr;
    font-size: 0.68rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.run-block .splits span {
    opacity: 0.25; /* Faded until hardware goes live */
}

.run-block .bottom-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 4px;
    border-top: 1px dashed rgba(255, 255, 255, 0.05);
    padding-top: 4px;
}

.run-block .run-time {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}

.run-block .speed {
    font-size: 0.7rem;
    font-weight: 600;
    color: #ea580c; /* Orange speed badge */
    opacity: 0.25;
}

/* Responsive Mobile Layout Override */
@media (max-width: 1024px) {
    .driver-card {
        grid-template-columns: 60px 1fr;
        gap: 12px;
    }
    .fastest-block {
        grid-column: span 2;
        border-right: none;
        border-bottom: 1px solid var(--bg-input);
        padding-bottom: 10px;
        margin-bottom: 5px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .runs-container {
        grid-column: span 2;
        grid-template-columns: repeat(3, 1fr);
        padding-left: 0;
        gap: 6px;
    }
}