:root {
    --bg: #0e0f12;
    --panel: #17191f;
    --panel2: #20232b;
    --panel3: #262a34;
    --text: #f2f4f8;
    --muted: #9ca5b5;
    --accent: #a970ff;
    --accent-soft: rgba(169, 112, 255, .14);
    --line: #303440;
    --good: #72d59a;
    --bad: #ff8585;
    --warn: #e8bd6b;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: 1rem 2rem;
    background: rgba(14, 15, 18, .94);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}

.brand {
    color: var(--accent);
    font-weight: 850;
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: .01em;
}

nav {
    display: flex;
    gap: 1.2rem;
    flex-wrap: wrap;
}

nav a {
    color: var(--muted);
    text-decoration: none;
}

nav a:hover { color: var(--text); }

.container {
    width: min(1280px, calc(100% - 2rem));
    margin: 2rem auto 5rem;
}

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.8rem;
}

.eyebrow {
    margin: 0 0 .35rem;
    color: var(--accent);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .14em;
}

h1 {
    font-size: clamp(2rem, 4vw, 3.2rem);
    margin: 0;
    line-height: 1.05;
}

h2 { margin: 0; }

.muted { color: var(--muted); }

.identity-line {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
    margin-top: .75rem;
    color: var(--muted);
}

.identity-line span + span::before {
    content: "•";
    margin-right: .75rem;
    color: var(--line);
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1.4rem;
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.card strong { font-size: 2rem; }
.card span { color: var(--muted); }

.section-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
    margin: 2.6rem 0 1rem;
}

.section-head a {
    color: var(--accent);
    text-decoration: none;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
}

th, td {
    text-align: left;
    padding: .9rem 1rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

th {
    background: var(--panel2);
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .055em;
}

tr:last-child td { border-bottom: 0; }

tbody tr:hover { background: rgba(255,255,255,.018); }

.time {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

.best-time {
    font-weight: 800;
    color: var(--text);
}

.theoretical { color: var(--accent); }

.rank {
    color: var(--muted);
    font-weight: 800;
}

.driver-name,
.row-link {
    text-decoration: none;
}

.driver-name {
    font-weight: 750;
}

.driver-name:hover,
.row-link:hover {
    color: var(--accent);
}

.subtext {
    display: block;
    margin-top: .18rem;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 500;
}

.filters {
    display: flex;
    gap: 1rem;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
}

.filters label {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    color: var(--muted);
    min-width: 180px;
}

.filters .grow { flex: 1 1 260px; }

input, select, button {
    min-height: 42px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: var(--panel2);
    color: var(--text);
    padding: .55rem .8rem;
    font: inherit;
}

select:disabled { opacity: .55; }

button {
    cursor: pointer;
    background: var(--accent);
    border-color: var(--accent);
    color: #101116;
    font-weight: 800;
}

.empty-state {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    padding: 1.4rem;
    border: 1px dashed var(--line);
    border-radius: 14px;
    background: var(--panel);
    color: var(--muted);
}

.empty-state strong { color: var(--text); }


.section-meta {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-wrap: wrap;
}

.class-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: .18rem .58rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel2);
    color: var(--text);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .025em;
    white-space: nowrap;
}

.class-gt3 {
    border-color: rgba(169, 112, 255, .38);
    background: rgba(169, 112, 255, .10);
}

.class-gt-trophy {
    border-color: rgba(232, 189, 107, .36);
    background: rgba(232, 189, 107, .08);
}

.class-gt4 {
    border-color: rgba(114, 213, 154, .34);
    background: rgba(114, 213, 154, .08);
}

.class-open {
    color: var(--muted);
}

.vehicle-meta {
    font-size: .74rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: .18rem .48rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .025em;
    vertical-align: middle;
}

.badge.valid {
    color: var(--good);
    background: rgba(114, 213, 154, .10);
}

.badge.invalid {
    color: var(--bad);
    background: rgba(255, 133, 133, .10);
}

.badge.unknown {
    color: var(--warn);
    background: rgba(232, 189, 107, .10);
}

.badge.best {
    margin-left: .35rem;
    color: var(--accent);
    background: var(--accent-soft);
}

.results {
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: var(--panel);
}

.result-grid {
    display: grid;
    grid-template-columns: 26px minmax(170px, 1.05fr) minmax(220px, 1.3fr) 110px 76px 76px 76px 100px;
    gap: .75rem;
    align-items: center;
    min-width: 940px;
}

.result-header {
    padding: .7rem 1rem;
    background: var(--panel2);
    color: var(--muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .055em;
}

.result-entry {
    border-top: 1px solid var(--line);
}

.result-entry:first-of-type {
    border-top: 0;
}

.result-entry summary {
    list-style: none;
    cursor: pointer;
    padding: .95rem 1rem;
    user-select: none;
}

.result-entry summary::-webkit-details-marker { display: none; }

.result-entry summary:hover {
    background: rgba(255,255,255,.022);
}

.chevron {
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
    transition: transform .16s ease;
}

.result-entry[open] .chevron {
    transform: rotate(90deg);
    color: var(--accent);
}

.driver-cell { min-width: 0; }

.lap-panel {
    padding: 0 1rem 1rem 3.25rem;
    background: rgba(0,0,0,.10);
}

.lap-panel-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .9rem .2rem .7rem;
}

.inner-table {
    border-radius: 10px;
}

.invalid-lap {
    opacity: .58;
}

.unknown-lap {
    background: rgba(232, 189, 107, .035);
}

footer {
    color: var(--muted);
    text-align: center;
    padding: 2rem;
}

@media (max-width: 760px) {
    .topbar {
        padding: .9rem 1rem;
        align-items: flex-start;
        flex-direction: column;
        gap: .75rem;
    }

    .container {
        width: min(100% - 1rem, 1280px);
        margin-top: 1.25rem;
    }

    .section-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .lap-panel {
        padding-left: .5rem;
        padding-right: .5rem;
    }

    .results {
        overflow-x: auto;
    }
}
