/* ---------- main ---------- */

main {
    flex: 1;
    padding: 32px 0 48px;
}

.controls {
    margin-bottom: 18px;
}

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 10px;
}

.filters .search-wrap {
    position: relative;
    flex: 1 1 220px;
    min-width: 180px;
    max-width: 320px;
}

.filters .search-wrap::before {
    content: "";
    position: absolute;
    left: 12px;
    top: 50%;
    width: 13px;
    height: 13px;
    transform: translateY(-50%);
    background: var(--muted);
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='m21 21-4.3-4.3'/></svg>") center/contain no-repeat;
    mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='m21 21-4.3-4.3'/></svg>") center/contain no-repeat;
    pointer-events: none;
}

.filters input[type="search"] {
    width: 100%;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 9px 12px 9px 34px;
    border-radius: var(--radius-sm);
    font: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.filters input[type="search"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(225, 6, 0, 0.15);
}

.filters input[type="search"]:not(:placeholder-shown) {
    border-color: var(--accent-dim);
}

.filters input[type="search"]::placeholder {
    color: var(--muted-dim);
}

.clear-btn {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    font: inherit;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap;
}

.clear-btn:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--accent);
    background: rgba(225, 6, 0, 0.08);
}

.clear-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

/* ---------- season range (dual-handle slider, widescreen) ---------- */

.season-range {
    flex: 1 1 250px;
    min-width: 210px;
    max-width: 330px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sr-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.sr-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sr-readout {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.sr-track {
    position: relative;
    height: 20px;
}

.sr-rail,
.sr-fill {
    position: absolute;
    top: 50%;
    height: 4px;
    margin-top: -2px;
    border-radius: 2px;
    pointer-events: none;
}

.sr-rail {
    left: 0;
    right: 0;
    background: var(--border);
}

.sr-fill {
    background: var(--accent);
}

/* Two range inputs share one track: the input surfaces are click-through so
   both thumbs stay grabbable, and only the thumbs take pointer events. */
.sr-input {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 20px;
    margin: 0;
    padding: 0;
    background: transparent;
    appearance: none;
    -webkit-appearance: none;
    pointer-events: none;
}

.sr-from {
    z-index: 3;
}

.sr-to {
    z-index: 4;
}

.sr-input:focus {
    outline: none;
}

.sr-input::-webkit-slider-runnable-track {
    height: 20px;
    background: transparent;
    border: none;
}

.sr-input::-moz-range-track {
    height: 20px;
    background: transparent;
    border: none;
}

.sr-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    pointer-events: auto;
    width: 16px;
    height: 16px;
    margin-top: 2px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--accent);
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.sr-input::-moz-range-thumb {
    pointer-events: auto;
    width: 16px;
    height: 16px;
    box-sizing: border-box;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--accent);
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.sr-input:hover::-webkit-slider-thumb,
.sr-input:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px rgba(225, 6, 0, 0.18);
}

.sr-input:hover::-moz-range-thumb,
.sr-input:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 4px rgba(225, 6, 0, 0.18);
}

.sr-bounds {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--muted-dim);
    font-variant-numeric: tabular-nums;
}

.filter-group.mobile-seasons {
    display: none;
}

.ms-pair {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ms-pair select {
    flex: 1 1 0;
    min-width: 0;
}

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

.filter-group.mobile-sort {
    display: none;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.filters select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 9px 12px;
    padding-right: 32px;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'><path d='M1 1l4 4 4-4' stroke='%238b949e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
}

.filters select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(225, 6, 0, 0.15);
}

.filters select:hover {
    border-color: var(--border-strong);
}

.hint {
    color: var(--muted);
    font-size: 0.85rem;
}

.hint strong {
    color: var(--text);
    font-weight: 600;
}

/* ---------- mobile filter panel ----------
   On widescreen the filters sit inline above the table and everything in this
   section is inert: .filter-panel is a plain wrapper, its head/foot and the
   trigger are display:none. Inside the 720px breakpoint the panel becomes a
   right-hand slide-out drawer so the table — not the controls — owns the top
   of a phone screen. The core is the same checkbox hack as the nav drawer
   (works with no JS); index.js only adds aria state, Escape, and the badge. */

.fp-toggle {
    display: none;
}

.controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.filter-toggle {
    display: none;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 13px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s, background 0.15s;
}

.filter-toggle:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(225, 6, 0, 0.15);
}

.filter-toggle .ft-icon {
    color: var(--muted);
    flex: 0 0 auto;
}

.filter-toggle .ft-count {
    display: none;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

.filter-toggle.has-active {
    border-color: var(--accent);
}

.filter-toggle.has-active .ft-icon {
    color: var(--accent);
}

.filter-toggle.has-active .ft-count {
    display: inline-block;
}

.fp-scrim {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.filter-panel:focus {
    outline: none;
}

.fp-head,
.fp-foot {
    display: none;
}

.fp-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.fp-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin: -6px -6px -6px 0;
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
}

.fp-close:hover {
    color: var(--text);
    background: var(--surface-2);
}

.fp-done {
    display: block;
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    user-select: none;
}

.fp-close:focus-visible,
.fp-done:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .filter-panel,
    .fp-scrim {
        transition: none;
    }
}

/* ---------- table ---------- */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

col.col-drivers {
    width: auto;
}

col.col-count {
    width: 92px;
}

col.col-last {
    width: 240px;
}

col.col-expand {
    width: 44px;
}

thead th {
    text-align: left;
    padding: 13px 18px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}

thead th[data-sort] {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: color 0.15s;
}

thead th[data-sort]:hover {
    color: var(--text);
}

thead th[data-sort]::after {
    content: "";
    display: inline-block;
    margin-left: 7px;
    vertical-align: middle;
    position: relative;
    top: -1px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--muted-dim);
    transition: transform 0.18s ease, border-top-color 0.15s;
}

thead th[data-sort]:hover::after {
    border-top-color: var(--muted);
}

thead th.active {
    color: var(--text);
}

thead th.active::after {
    border-top-color: var(--accent-bright);
}

thead th.active.dir-asc::after {
    transform: rotate(180deg);
}

tbody tr.combo {
    cursor: pointer;
    transition: background 0.12s;
}

tbody tr.combo>td {
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    vertical-align: middle;
    overflow-wrap: break-word;
}

tbody tr.combo:first-child>td {
    border-top: none;
}

tbody tr.combo:hover>td {
    background: var(--surface-2);
}

tbody tr.combo:nth-of-type(2n)>td {
    background: var(--stripe);
}

tbody tr.combo:nth-of-type(2n):hover>td {
    background: var(--surface-2);
}

tbody tr.combo.expanded>td {
    background: var(--surface-2);
}

td.drivers {
    font-weight: 500;
    color: var(--text);
}

td.drivers .driver {
    white-space: nowrap;
}

td.drivers .dn-abbr { display: none; }

td.drivers .sep {
    color: var(--muted-dim);
    margin: 0 8px;
    font-weight: 400;
}

td.count {
    font-weight: 700;
    color: var(--accent-bright);
    font-variant-numeric: tabular-nums;
    font-size: 16px;
}

td.last {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.35;
}

td.last .year {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-right: 8px;
}

td.last .race-name {
    color: var(--text-dim);
}

td.expand {
    text-align: center;
    color: var(--muted-dim);
    width: 44px;
}

td.expand .chev {
    display: inline-block;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    font-size: 10px;
    transition: transform 0.18s ease, color 0.15s, background 0.15s;
}

tr.combo:hover td.expand .chev {
    color: var(--text);
}

tr.combo.expanded td.expand .chev {
    transform: rotate(180deg);
    color: var(--accent-bright);
    background: rgba(225, 6, 0, 0.12);
}

/* expanded detail row */
tr.detail {
    display: none;
}

tr.detail.open {
    display: table-row;
}

tr.detail>td {
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    padding: 0;
}

.detail-inner {
    padding: 18px 24px 20px;
    border-left: 3px solid var(--accent);
}

.season-row {
    display: grid;
    grid-template-columns: 70px 1fr;
    gap: 14px;
    padding: 6px 0;
    border-top: 1px solid var(--border);
    align-items: baseline;
}

.season-row:first-child {
    border-top: none;
    padding-top: 0;
}

.season-row .season-label {
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    letter-spacing: -0.2px;
}

.season-row .season-label .ct {
    color: var(--muted-dim);
    font-weight: 500;
    font-size: 13px;
    margin-left: 4px;
}

.season-row .race-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.race-pill {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text-dim);
    line-height: 1.3;
    white-space: nowrap;
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

a.race-pill:hover {
    border-color: var(--accent);
    background: var(--surface-3);
    color: var(--text);
}

.race-pill .round {
    color: var(--muted-dim);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 12px;
}

/* Shared-drive podiums: pre-1961 races where two drivers shared one car, so a
   single podium step belongs to both of them. */
.shared-badge,
.shared-mark {
    margin-left: 0.35em;
    font-size: 0.85em;
    color: var(--muted);
    cursor: help;
}

.race-pill-shared {
    border-style: dashed;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
    font-size: 14px;
}

.empty-state strong {
    color: var(--text);
    display: block;
    margin-bottom: 4px;
}

/* 600-720px: compact horizontal-scroll table + stacked filters */
@media (max-width: 720px) {
    main {
        padding: 24px 0 32px;
    }

    /* the filters leave the flow entirely: a right slide-out panel behind
       the "Filters" trigger, so the table starts at the top of the screen */
    .filter-toggle {
        display: inline-flex;
    }

    .fp-scrim {
        display: block;
    }

    .fp-toggle:checked ~ .fp-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .filter-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 70;
        width: min(86vw, 340px);
        display: flex;
        flex-direction: column;
        background: var(--surface);
        border-left: 1px solid var(--border);
        transform: translateX(105%);
        transition: transform 0.25s ease;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .fp-toggle:checked ~ .filter-panel {
        transform: translateX(0);
    }

    .fp-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 14px 16px;
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        background: var(--surface);
        z-index: 1;
    }

    .fp-foot {
        display: block;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border);
        margin-top: auto;
        position: sticky;
        bottom: 0;
        background: var(--surface);
    }

    .controls-bar {
        align-items: flex-start;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 14px 16px;
        margin-bottom: 0;
    }

    .filters .search-wrap {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
    }

    .filters input[type="search"] {
        font-size: 16px;
    }

    /* >=16px prevents iOS zoom-on-focus */
    .filters select {
        font-size: 16px;
        width: 100%;
    }

    .clear-btn {
        width: 100%;
        padding: 11px 14px;
    }

    .season-range {
        display: none;
    }

    .filter-group.mobile-seasons {
        display: flex;
    }

    .filter-group.mobile-sort {
        display: flex;
    }

    table {
        table-layout: auto;
        min-width: 500px;
    }

    col.col-drivers {
        width: 160px;
    }

    col.col-count {
        width: 50px;
    }

    col.col-last {
        width: 100px;
    }

    col.col-expand {
        width: 30px;
    }

    thead th,
    tbody tr.combo>td {
        padding: 10px 8px;
        font-size: 13px;
    }

    td.last {
        font-size: 13px;
    }

    td.last .race-name {
        display: none;
    }

    .detail-inner {
        padding: 14px 14px 16px;
    }

    .season-row {
        grid-template-columns: 56px 1fr;
    }
}

/* <=600px: each combo row becomes a self-contained card (no sideways scroll) */
@media (max-width: 600px) {
    table,
    tbody {
        display: block;
        width: 100%;
    }

    table {
        min-width: 0;
    }

    thead,
    colgroup {
        display: none;
    }

    tbody tr.combo {
        display: grid;
        /* fixed count/chevron tracks, so both line up down the whole list
           instead of drifting with the length of each trio */
        grid-template-columns: minmax(0, 1fr) 24px 24px;
        align-items: center;
        column-gap: 10px;
        /* rows sit flush inside the table frame, divided by one hairline each
           (mirroring the desktop table) rather than floating as separate
           cards — 754 of them read as a list, not a stack of panels. The
           rule is the strong border so it outweighs the faint hairlines
           between a trio's own stacked names. */
        border-top: 1px solid var(--border-strong);
        padding: 14px;
    }

    tbody tr.combo:first-child {
        border-top: none;
    }

    /* neutralize desktop cell borders / zebra / hover backgrounds in card mode */
    tbody tr.combo>td,
    tbody tr.combo:hover>td,
    tbody tr.combo:nth-of-type(2n)>td,
    tbody tr.combo:nth-of-type(2n):hover>td,
    tbody tr.combo.expanded>td {
        display: block;
        padding: 0;
        border: none;
        background: transparent;
    }

    /* One grid row per trio: names, count, chevron, each pinned to an explicit
       grid cell. "Last seen" claims row 2 across all three columns when the
       row expands, so revealing it can never displace the chevron. */
    tbody tr.combo td.drivers {
        grid-area: 1 / 1;
        min-width: 0;
        font-size: 15px;
        font-weight: 600;
        line-height: 1.35;
    }

    /* One driver per line, a hairline between them in place of the "/" —
       a name is never split, and the trio reads as a list of three. */
    tbody tr.combo td.drivers .driver {
        display: block;
    }

    tbody tr.combo td.drivers .driver + .driver {
        border-top: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
        margin-top: 5px;
        padding-top: 5px;
    }

    tbody tr.combo td.drivers .dn-full { display: none; }
    tbody tr.combo td.drivers .dn-abbr { display: inline; }

    tbody tr.combo td.drivers .sep {
        display: none;
    }

    /* The sort is podium count, so the number stays on the collapsed face —
       unlabelled, since the trio beside it leaves no room to misread it. */
    tbody tr.combo td.count {
        grid-area: 1 / 2;
        text-align: right;
        font-size: 14px;
        font-weight: 700;
        line-height: 1;
        font-variant-numeric: tabular-nums;
        color: var(--accent-bright);
    }

    tbody tr.combo td.expand {
        grid-area: 1 / 3;
        width: auto;
        padding: 0;
        text-align: center;
        /* the only affordance left on the face, so it carries a little more
           ink than the desktop chevron */
        color: var(--muted);
    }

    tbody tr.combo td.expand .chev {
        width: 24px;
        height: 24px;
        line-height: 24px;
        font-size: 12px;
    }

    tbody tr.combo td.last {
        display: none;
    }

    tbody tr.combo.expanded td.last {
        grid-row: 2;
        grid-column: 1 / -1;
        display: block;
        margin-top: 9px;
        padding-top: 8px;
        border-top: 1px solid var(--border);
        font-size: 13.5px;
        line-height: 1.4;
        color: var(--text-dim);
    }

    tbody tr.combo.expanded td.last::before {
        content: "Last";
        display: inline-block;
        width: 44px;
        color: var(--muted);
        text-transform: uppercase;
        letter-spacing: 0.6px;
        font-size: 10px;
        font-weight: 700;
        vertical-align: middle;
    }

    tbody tr.combo td.last .year {
        color: var(--text);
    }

    tbody tr.combo td.last .race-name {
        display: inline;
        color: var(--text-dim);
    }

    /* card + its expanded detail join into one connected block */
    tr.detail {
        display: none;
    }

    tr.detail.open {
        display: block;
        margin: 0;
        background: var(--bg-2);
        border-top: 1px solid var(--border);
    }

    tr.detail.open>td {
        display: block;
        padding: 0;
    }

    .detail-inner {
        padding: 12px 14px 14px;
    }

    .season-row {
        grid-template-columns: 50px 1fr;
        gap: 10px;
    }

    .race-list {
        gap: 5px;
    }
}