/* Car Info table: smaller, stylized font for Power, Weight, Engine, Drive */
.carinfo-meta {
    font-size: 0.87em !important;
    font-family: 'Segoe UI', 'Roboto', 'Arial', sans-serif;
    color: #b6c2d1;
    font-weight: 500;
    letter-spacing: 0.01em;
    opacity: 0.93;
}
/* Car Info badges (same as .pos-number, but color-coded) */
.car-badge {
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    font-weight: 800;
    font-size: 0.95rem;
    text-decoration: none !important;
    border: none;
    line-height: 1.2;
    display: inline-block;
    vertical-align: baseline;
    background: #b3e5fc;
    color: #222;
}
.car-badge.gt { background: #b3e5fc; color: #222; }
.car-badge.round { background: #ffe082; color: #222; }
.car-badge[title*="flat"], .car-badge.round-flat { background: #c8e6c9; color: #222; white-space: nowrap; }
.car-badge.trans { background: #1976d2; color: #fff; }
.car-badge.trans.sequential { background: #7b1fa2; color: #fff; }
.car-badge.trans.h { background: #c62828; color: #fff; }
.car-badge.unknown { background: #eee; color: #888; }

/* Detail header lines (Track, Layout, Class) - match other section title sizing */
.detail-header-line, #detail-track, #detail-class, #detail-layout {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    letter-spacing: 0.015em;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.detail-header-line .detail-label, #detail-track .detail-label, #detail-layout .detail-label, #detail-class .detail-label {
    color: var(--primary-color);
    font-weight: 700;
    margin-right: 0.25em;
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Remove tap highlight on mobile for better UX */
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-color: #3b82f6;
    --background: #0f172a;
    --surface: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
    --hover-bg: #334155;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* Better text rendering on mobile */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

header {
    background-color: var(--surface);
    padding: 2rem;
    text-align: center;
    box-shadow: 0 2px 4px var(--shadow);
}

header h1 {
    font-size: 2rem;
    color: var(--primary-color);
    font-weight: 700;
}

.home-link {
    color: var(--primary-color);
    text-decoration: none;
}

.home-link:hover {
    text-decoration: underline;
}

main {
    flex: 1;
    max-width: 1400px;
    width: 100%;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border);
}

.tab-button {
    background: none;
    border: none;
    padding: 1rem 2rem;
    font-size: 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
    font-weight: 500;
    text-align: center;
}

.tab-button:hover {
    color: var(--primary-color);
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    background-color: var(--surface);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px var(--shadow);
    min-height: 400px;
}

/* Ensure tables are scrollable within their container and fit the same width as other tabs */
.tab-panel {
    max-width: 1100px;
    margin: 0 auto;
}
.content-inner {
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}
.results-table {
    width: 100%;
    table-layout: auto;
}

/* Slightly tighter table cells so long names don't push layout */
.results-table th,
.results-table td {
    padding: 0.45rem 0.6rem; /* reduced from ~0.6-0.8 */
    text-align: left;
    vertical-align: middle;
}

/* Allow car names in Car Info to wrap (they were previously forced nowrap) */
.results-table td.no-wrap {
    white-space: normal;
}

/* Ensure search controls and table containers align identically */
.tab-panel > .search-container,
.tab-panel > #cars-info-table,
.tab-panel > #track-info-table,
.tab-panel > #results-container {
    max-width: 1100px;
    margin: 0 auto 1rem auto;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.search-container {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

#class-filter {
    padding: 0.78rem 0.9rem;
    font-size: 0.98rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent);
    color: var(--text-primary);
    max-width: 420px;
    appearance: none;
    -webkit-appearance: none;
}

#class-filter:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.06);
}

/* Small caret tweak for select */
#class-filter { padding-right: 2.5rem; }
#class-filter::-ms-expand { display: none; }

/* Style options inside the select so they are readable when the native dropdown opens */
#class-filter option {
    background-color: transparent;
    color: var(--text-primary);
}

/* On hover/active for supported browsers: don't change background, just darken the text */
#class-filter option:hover,
#class-filter option:active {
    background-color: transparent;
    color: var(--text-secondary);
}

/* Custom select UI */
.custom-select {
    position: relative;
    display: inline-block;
    flex: 1 1 0;
    min-width: 200px;
}

/* Row link anchors: allow browser link preview on hover and style inline content */
.row-link {
    color: inherit;
    text-decoration: none;
    display: inline-block;
    width: 100%;
    white-space: normal; /* allow wrapping of long car names */
}
.row-link:hover {
    text-decoration: underline;
}

/* Constrain the Power column so very long car names don't force the table wide */
.results-table th:nth-child(5),
.results-table td:nth-child(5) {
    width: 8rem;
    max-width: 8rem;
}

/* Car Info table specific column widths */
#cars-info-table .results-table th:nth-child(1),
#cars-info-table .results-table td:nth-child(1) {
    white-space: nowrap;
}

#cars-info-table .results-table th:nth-child(5),
#cars-info-table .results-table td:nth-child(5) {
    width: 6.5rem;
    max-width: 6.5rem;
}

#cars-info-table .results-table th:nth-child(7),
#cars-info-table .results-table td:nth-child(7) {
    width: 7rem;
    max-width: 7rem;
}

.custom-select__toggle {
    width: 100%;
    text-align: left;
    padding: 0.78rem 0.9rem;
    font-size: 0.98rem;
    border-radius: 8px;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
}
.custom-select__menu {
    position: absolute;
    left: 0;
    right: 0;
    margin-top: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 240px;
    overflow: auto;
    box-shadow: 0 6px 18px rgba(2,6,23,0.6);
    z-index: 50;
}
.custom-select__option {
    padding: 0.6rem 0.9rem;
    cursor: pointer;
    color: var(--text-primary);
}
.custom-select__option:hover,
.custom-select__option[aria-selected="true"] {
    background: var(--hover-bg);
    color: var(--text-primary);
}

#driver-search {
    flex: 1 1 0;
    min-width: 200px;
    padding: 0.78rem 0.9rem;
    font-size: 0.98rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    transition: all 0.3s ease;
    background-color: var(--surface);
    color: var(--text-primary);
    /* Prevent zoom on mobile when focusing input */
    font-size: max(0.98rem, 16px);
}

#driver-search:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#results-container {
    margin-top: 1.5rem;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.error {
    background-color: #7f1d1d;
    color: #fecaca;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid #991b1b;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 12px 0 rgba(30, 41, 59, 0.10);
}

/* Allow horizontal scroll for wide tables on small screens */
#cars-info-table,
#track-info-table,
#results-container,
#detail-results-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Add scrollbar styling for webkit browsers */
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--surface);
}

#cars-info-table::-webkit-scrollbar,
#track-info-table::-webkit-scrollbar,
#results-container::-webkit-scrollbar,
#detail-results-container::-webkit-scrollbar {
    height: 8px;
}

#cars-info-table::-webkit-scrollbar-track,
#track-info-table::-webkit-scrollbar-track,
#results-container::-webkit-scrollbar-track,
#detail-results-container::-webkit-scrollbar-track {
    background: var(--surface);
}

#cars-info-table::-webkit-scrollbar-thumb,
#track-info-table::-webkit-scrollbar-thumb,
#results-container::-webkit-scrollbar-thumb,
#detail-results-container::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.results-table thead tr {
    background: #2563eb;
}

.results-table th,
.results-table td {
    padding: 0.875rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.results-table th {
    color: #fff;
    font-size: 1.05rem;
    font-weight: 700;
    padding: 0.85rem 1.25rem;
    border: none;
    letter-spacing: 0.01em;
}

.results-table tr:hover {
    background-color: var(--hover-bg);
}

.results-table td {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 1.05rem;
    transition: background 0.2s;
}

.results-table tr:hover td {
    background: var(--hover-bg);
}

.highlight-row td {
    background-color: rgba(59, 130, 246, 0.08) !important;
    box-shadow: inset 0 0 12px rgba(59,130,246,0.05);
    font-weight: 700;
}

.highlight-row {
    transition: background-color 0.25s ease, box-shadow 0.25s ease;
}

.results-table tr:last-child td {
    border-bottom: none;
}

.status-section {
    margin-top: 3rem;
    padding: 1.5rem;
    background-color: var(--surface);
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 6px 0 var(--shadow);
}

.status-section h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.125rem;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1rem 2rem;
    align-items: center;
}

/* Status timestamp: allow wrapping to avoid column overlap */
#status-timestamp {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: 1.15rem;
}

.status-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    align-self: stretch;
}

.status-item .status-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.status-item .status-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Prevent wrapping for compact fields like "pos / total" */
.no-wrap {
    white-space: nowrap;
}

.lap-time-cell {
    min-width: 120px;
    vertical-align: top;
    text-align: center;
}

.lap-time-cell .lap-main {
    display: block;
    white-space: nowrap;
}
.lap-time-cell .time-delta {
    display: block;
    white-space: nowrap;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.time-delta-inline {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-left: 0.4rem;
}

/* Position badge styling */
.pos-cell {
    white-space: nowrap;
    /* Use inline layout so badge baseline aligns with text baseline */
    /* Remove flex and alignment */
}
.pos-number {
    background: rgba(59,130,246,0.18);
    color: var(--text-primary);
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    font-weight: 800;
    font-size: 0.95rem;
    text-decoration: none !important;
    border: none;
    line-height: 1.2;
    display: inline-block;
    vertical-align: baseline;
}
.pos-total {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-left: 0.35rem;
    text-decoration: none !important;
}
.pos-sep {
    color: var(--text-secondary);
    opacity: 0.95;
}

/* Absolute position label (shown when car filter is active) */
.absolute-pos-label {
    font-size: 0.7rem;
    color: #94a3b8;
    font-weight: 500;
    opacity: 0.85;
    margin-right: 0.4rem;
    display: inline-block;
    vertical-align: baseline;
}

/* Remove underlines and default link styles inside result tables */
.results-table a {
    color: inherit;
    text-decoration: none;
}

/* Ensure table cells vertically center contents */
.results-table td {
    vertical-align: middle;
}

.lap-time-cell {
    min-width: 0;
}

.status-item .status-value {
    display: inline-block;
    min-width: 0;
}

.status-item-inline {
    display: flex;
    flex-direction: row;
    gap: 2rem;
    align-items: baseline;
}

.status-section .status-grid .status-item.status-item-inline > div {
    flex: 1 1 0 !important;
    min-width: 0 !important;
}

@media (max-width: 800px) {
    .status-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.status-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.status-value {
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
}

.driver-group-header {
    background-color: #3b4a6b !important;
    cursor: pointer;
    user-select: none;
    color: #f1f5fa;
    font-weight: 600;
    font-size: 1.08rem;
    border-top: 1px solid #475569;
    border-bottom: 1px solid #475569;
    transition: background 0.2s;
    box-shadow: none;
}

.driver-group-header:hover {
    background-color: #4b5d85 !important;
}

.driver-group-header td {
    padding: 1rem !important;
    font-weight: 600;
    border: none;
    background: none;
}

.toggle-icon {
    display: inline-block;
    margin-right: 0.5rem;
    font-size: 0.95rem;
    transition: transform 0.2s;
    color: #60a5fa;
}

.driver-meta {
    margin-left: 1rem;
    font-weight: 400;
    opacity: 0.9;
    font-size: 0.97rem;
    color: #a5b4fc;
}

.country-flag {
    display: inline-block;
    margin-right: 0.4rem;
    font-size: 1.05rem;
    vertical-align: middle;
}

.driver-data-row {
    transition: all 0.2s;
    cursor: pointer;
}

.driver-data-row:hover {
    background-color: var(--hover-bg);
}

.detail-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-top: 0.5rem;
}

.detail-content {
    background-color: var(--surface);
    padding: 2.5rem 2rem 2rem 2rem;
    border-radius: 14px;
    box-shadow: 0 2px 12px 0 rgba(30, 41, 59, 0.10);
    margin-top: 0;
}

.detail-header {
    display: flex;
    align-items: flex-start;
    gap: 2rem;
    margin-bottom: 2rem;
    background: #1e293b;
    border-radius: 12px;
    /* Remove the blue glow and use a subtle neutral shadow */
    box-shadow: 0 1px 4px 0 rgba(0,0,0,0.06);
    padding: 1.5rem 2rem;
    outline: none;
    border: none;
}

.detail-header .custom-select {
    min-width: 200px;
}

#car-filter-ui {
    margin-left: auto;
}

/* When car filter is hidden, difficulty filter takes its place */
#car-filter-ui[style*="display: none"] + #difficulty-filter-ui {
    margin-left: auto;
}

.detail-header h2 {
    color: var(--primary-color);
    margin: 0;
}

.detail-header-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.back-btn {
    padding: 0.5rem 1.25rem;
    background: #fff;
    color: #2563eb;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 1px 4px 0 rgba(30, 41, 59, 0.10);
    transition: background 0.2s, color 0.2s;
    margin: 0 0 0.75rem 0;
    display: inline-block;
}

.back-btn:hover {
    background: #2563eb;
    color: #fff;
}

.no-results {
    text-align: center;
    color: #f87171;
    font-size: 1.2rem;
    margin: 2rem 0;
    font-weight: 600;
}

.pagination {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.pagination-info {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
}

.pagination-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.page-btn {
    padding: 0.5rem 0.95rem;
    background-color: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    font-weight: 600;
}

.page-btn:hover {
    background-color: var(--hover-bg);
    border-color: var(--primary-color);
}

.page-btn.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    font-weight: 700;
}

.page-ellipsis {
    color: var(--text-secondary);
    padding: 0 0.25rem;
    font-size: 1.1rem;
}

footer {
    background-color: var(--surface);
    padding: 1.5rem;
    color: var(--text-secondary);
    box-shadow: 0 -2px 4px var(--shadow);
    margin-top: 2rem;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.footer-text {
    text-align: center;
    flex: 1;
}

footer p {
    font-size: 0.875rem;
}

.footer-donate {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 180px;
}

.paypal-button {
    background: #0070ba;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
    width: 100%;
}

.paypal-button:hover {
    background: #0f94ec;
}

.paypal-button span {
    display: inline-block;
}

.raceroom-button {
    background: #691313;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
}

.raceroom-button:hover {
    background: #a32929;
}

.raceroom-button span {
    display: inline-block;
}

/* Track Info table mobile optimization - apply for all small screens */
@media (max-width: 768px) {
    #track-info-table {
        overflow-x: visible !important;
        width: 100% !important;
    }
    
    #track-info-table .results-table {
        table-layout: fixed !important;
        width: 100% !important;
        min-width: 0 !important;
    }
    
    #track-info-table .results-table th,
    #track-info-table .results-table td {
        padding: 0.4rem 0.25rem !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }
    
    /* First column - Track name */
    #track-info-table .results-table th:nth-child(1),
    #track-info-table .results-table td:nth-child(1),
    #track-info-table .track-cell { 
        width: 50% !important;
        max-width: 50% !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }
    
    /* Second column - Car Class */
    #track-info-table .results-table th:nth-child(2),
    #track-info-table .results-table td:nth-child(2),
    #track-info-table .class-cell { 
        width: 35% !important;
        max-width: 35% !important;
        white-space: normal !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }
    
    /* Third column - Entry count */
    #track-info-table .results-table th:nth-child(3),
    #track-info-table .results-table td:nth-child(3),
    #track-info-table td.no-wrap,
    #track-info-table th.no-wrap { 
        width: 15% !important;
        max-width: 15% !important;
        text-align: right !important;
        white-space: nowrap !important;
        overflow: visible !important;
    }
}

@media (max-width: 768px) {
    header {
        padding: 1.25rem 1rem;
    }

    header h1 {
        font-size: 1.35rem;
        line-height: 1.3;
    }

    main {
        padding: 0 0.75rem;
    }

    .tabs {
        flex-direction: row;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.25rem;
        padding: 0.25rem;
    }

    .tab-button {
        padding: 0.65rem 1rem;
        font-size: 0.9rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .tab-content {
        padding: 1rem 0.5rem;
    }

    /* Make tables horizontally scrollable on mobile */
    .results-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.5rem;
        padding: 0 0.5rem;
    }

    .results-table {
        font-size: 0.7rem;
        min-width: 600px; /* Prevent table from being too cramped */
    }

    .results-table th,
    .results-table td {
        padding: 0.45rem 0.35rem;
        font-size: 0.7rem;
    }

    .results-table th {
        font-size: 0.75rem;
    }

    /* Reduce Driver column width on mobile */
    .results-table th:nth-child(2),
    .results-table td:nth-child(2) {
        max-width: 7rem;
    }

    .results-table th:nth-child(4),
    .results-table td:nth-child(4) {
        max-width: 7rem;
    }

    /* Reduce Difficulty column width on mobile */
    .results-table th:nth-child(5),
    .results-table td:nth-child(5) {
        width: 4rem;
        max-width: 4rem;
    }

    /* Position badges stay readable */
    .pos-number {
        font-size: 0.7rem;
        padding: 0.12rem 0.4rem;
    }

    .pos-total {
        font-size: 0.7rem;
    }

    /* Gap time deltas */
    .time-delta-inline,
    .lap-time-cell .time-delta {
        font-size: 0.7rem;
    }

    /* Difficulty pills */
    .difficulty-pill {
        font-size: 0.6rem !important;
        padding: 0.1rem 0.35rem !important;
    }

    /* Driver names and metadata */
    .driver-group-header strong {
        font-size: 0.85rem;
    }

    .driver-meta {
        font-size: 0.75rem;
    }

    .country-flag {
        font-size: 0.85rem;
    }

    /* Search filters: keep gap consistent */
    .search-container {
        gap: 0.75rem;
        flex-wrap: wrap;
    }
    
    #driver-search {
        flex: 1 1 100%;
        min-width: 100%;
    }
    
    .custom-select {
        flex: 1 1 calc(50% - 0.375rem);
        min-width: 0;
        max-width: none;
    }
    
    /* Car Info page: all 3 dropdowns stack vertically, each on its own line */
    #cars-search-container .custom-select {
        flex: 1 1 100%;
        min-width: 100%;
        max-width: 100%;
    }
    
    .custom-select__toggle {
        white-space: normal;
        padding: 0.7rem 0.9rem;
        font-size: 0.9rem;
    }

    .custom-select__menu {
        max-height: 60vh;
    }

    /* Detail page improvements */
    .detail-content {
        padding: 1.25rem 0.75rem;
        margin-top: 1rem;
    }

    .detail-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
        align-items: stretch;
    }

    .detail-header-info {
        order: 1;
    }

    .detail-header .custom-select {
        margin-left: 0;
        min-width: 100%;
    }
    
    #car-filter-ui {
        order: 2;
        margin-left: 0;
        min-width: 100%;
    }
    
    #difficulty-filter-ui {
        order: 3;
        margin-left: 0;
        min-width: 100%;
    }

    .back-btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
        width: fit-content;
        margin: 0;
    }

    .detail-header-line,
    #detail-track,
    #detail-class,
    #detail-layout {
        font-size: 1.1rem;
        word-break: break-word;
    }

    /* Pagination improvements */
    .pagination-buttons {
        gap: 0.35rem;
    }

    .page-btn {
        padding: 0.45rem 0.7rem;
        font-size: 0.85rem;
        min-width: 36px;
    }

    /* Status section on mobile: more compact */
    .status-section {
        padding: 0.75rem;
    }

    .status-section h3 {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }

    .status-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.4rem;
    }

    .status-item {
        padding: 0.4rem;
        gap: 0.2rem;
        align-items: flex-start;
    }

    /* Use higher specificity so mobile sizes override desktop */
    .status-item .status-label {
        font-size: 0.7rem !important;
    }

    .status-item .status-value {
        font-size: 0.9rem !important;
        font-weight: 600;
        line-height: 1.2;
        word-break: break-word;
    }

    /* Timestamp: allow wrapping and shrink font on mobile */
    #status-timestamp {
        white-space: normal;
        font-size: 0.9rem;
    }

    /* Inline status items should stack on mobile to avoid overflow */
    .status-item-inline {
        flex-direction: column;
        gap: 0.25rem;
        align-items: flex-start;
    }

    /* Keep table usable with horizontal scroll */
    #cars-info-table,
    #track-info-table,
    #detail-results-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Car/track info tables */
    .car-badge {
        font-size: 0.7rem;
        padding: 0.12rem 0.4rem;
    }

    /* Make Power and Engine columns narrower on mobile for Car Info page */
    #cars-info-table .results-table th:nth-child(5),
    #cars-info-table .results-table td:nth-child(5) {
        width: 4rem;
        max-width: 4rem;
    }
    
    #cars-info-table .results-table th:nth-child(7),
    #cars-info-table .results-table td:nth-child(7) {
        width: 4.5rem;
        max-width: 4.5rem;
    }

    /* Footer adjustments */
    footer {
        padding: 1.25rem 0.75rem;
        margin-top: 1.5rem;
    }

    .footer-content {
        flex-direction: column;
        gap: 1.25rem;
    }

    footer p {
        font-size: 0.8rem;
    }

    .paypal-button {
        font-size: 0.85rem;
        padding: 0.45rem 0.85rem;
    }
}

/* Extra small screens (under 480px) */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.15rem;
    }

    .results-table {
        font-size: 0.65rem;
    }

    .results-table th,
    .results-table td {
        padding: 0.35rem 0.25rem;
        font-size: 0.65rem;
    }

    .results-table th {
        font-size: 0.7rem;
    }

    .detail-header-line,
    #detail-track,
    #detail-class,
    #detail-layout {
        font-size: 1rem;
    }

    .page-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
        min-width: 32px;
    }

    .pagination-info {
        font-size: 0.85rem;
    }

    /* Make Power and Engine columns even narrower on extra small screens for Car Info page */
    #cars-info-table .results-table th:nth-child(5),
    #cars-info-table .results-table td:nth-child(5) {
        width: 3.5rem;
        max-width: 3.5rem;
    }
    
    #cars-info-table .results-table th:nth-child(7),
    #cars-info-table .results-table td:nth-child(7) {
        width: 4rem;
        max-width: 4rem;
    }

    /* Further reduce special elements */
    .pos-number {
        font-size: 0.65rem;
        padding: 0.1rem 0.35rem;
    }

    .pos-total {
        font-size: 0.65rem;
    }

    .time-delta-inline,
    .lap-time-cell .time-delta {
        font-size: 0.65rem;
    }

    .difficulty-pill {
        font-size: 0.55rem !important;
        padding: 0.08rem 0.3rem !important;
    }

    /* Driver names and metadata even smaller */
    .driver-group-header strong {
        font-size: 0.8rem;
    }

    .driver-meta {
        font-size: 0.7rem;
    }

    .country-flag {
        font-size: 0.8rem;
    }
}

/* Difficulty color scheme - subtle pill styling */
.difficulty-cell { white-space: nowrap; }
.difficulty-pill {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1;
}
.difficulty-pill.difficulty-get-real {
    /* Gold */
    background-color: rgba(255, 215, 0, 0.14);
    border-color: rgba(255, 215, 0, 0.30);
    border-style: solid;
    border-width: 1px;
}
.difficulty-pill.difficulty-amateur {
    /* Silver */
    background-color: rgba(192, 192, 192, 0.14);
    border-color: rgba(192, 192, 192, 0.30);
    border-style: solid;
    border-width: 1px;
}
.difficulty-pill.difficulty-novice {
    /* Bronze */
    background-color: rgba(205, 127, 50, 0.14);
    border-color: rgba(205, 127, 50, 0.30);
    border-style: solid;
    border-width: 1px;
}

/* Apply subtle cell background for leaderboards table cells as well */
.difficulty-get-real { background-color: rgba(255, 215, 0, 0.10); }
.difficulty-amateur { background-color: rgba(192, 192, 192, 0.10); }
.difficulty-novice { background-color: rgba(205, 127, 50, 0.10); }

/* Legend for difficulty meanings */
.difficulty-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}
.difficulty-legend .legend-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}
.difficulty-legend .difficulty-pill {
    font-weight: 700;
    font-size: 0.8rem;
    padding: 0.12rem 0.45rem;
}
