:root {
    --blue: #087bbf;
    --blue-dark: #065a8c;
    --red: #e1060f;
    --ink: #17212b;
    --muted: #626e78;
    --line: #d8dee4;
    --surface: #ffffff;
    --page: #f4f6f8;
    --positive: #2e7d32;
    --negative: #c62828;
    --zero: #696969;
}

body {
    display: block;
    min-width: 0;
    background-color: var(--page);
    background-image: linear-gradient(rgba(8, 123, 191, .045) 1px, transparent 1px), linear-gradient(90deg, rgba(8, 123, 191, .045) 1px, transparent 1px);
    background-size: 32px 32px;
    color: var(--ink);
    font-family: 'Rhon Rounded', 'Segoe UI', sans-serif;
    letter-spacing: 0;
}

.rankings-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 28px;
    padding: 24px max(24px, calc((100vw - 1728px) / 2));
    border-bottom: 5px solid var(--red);
    background: #063f62;
    color: white;
}

.brand-link { display: block; line-height: 0; }
.rankings-logo { width: 170px; max-width: 30vw; }
.header-copy h1 { margin: 0; font-family: 'Racing Sans One', sans-serif; font-size: 2.65rem; font-weight: 400; line-height: 1; letter-spacing: 0; }
.header-copy p { margin: 7px 0 0; color: #e4f5fe; font-size: 1rem; line-height: 1.35; }
.header-copy .eyebrow { margin: 0 0 5px; color: #8ed5f7; font-size: .78rem; font-weight: 700; text-transform: uppercase; }
.header-nav { display: flex; align-items: center; gap: 8px; }
.header-nav a { padding: 9px 12px; border: 1px solid rgba(255,255,255,.45); border-radius: 4px; color: white; font-size: .9rem; font-weight: 700; text-decoration: none; }
.header-nav a:hover, .header-nav a:focus-visible { border-color: white; background: white; color: var(--blue-dark); }

.rankings-main { width: min(1728px, calc(100% - 40px)); margin: 24px auto 50px; }
.selector-panel, .panel, .summary-card { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.selector-panel { display: flex; align-items: end; justify-content: space-between; gap: 30px; padding: 18px 20px; }
.selector-panel h2, .panel h2 { margin: 0; color: var(--ink); font-size: 1.35rem; line-height: 1.2; }
.selector-panel p { margin: 3px 0 0; color: var(--muted); font-size: .92rem; line-height: 1.4; }
.rankings-layout { display: grid; grid-template-columns: minmax(360px, 25%) minmax(0, 1fr); gap: 16px; margin-top: 14px; align-items: start; }
.rankings-content-column { min-width: 0; }
.leaderboard-panel { padding: 18px 14px; position: sticky; top: 14px; }
.leaderboard-panel .panel-heading { margin-bottom: 10px; }
.leaderboard-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.leaderboard-item { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 8px; width: 100%; padding: 9px 10px; border: 1px solid #e4e9ee; border-radius: 6px; background: #f8fafb; color: var(--ink); text-align: left; cursor: pointer; }
.leaderboard-item:hover, .leaderboard-item.active { border-color: rgba(8, 123, 191, .45); background: #edf7fc; }
.leaderboard-rank { color: var(--muted); font-size: .82rem; font-weight: 700; }
.leaderboard-name { display: block; min-width: 0; overflow: hidden; color: var(--ink); font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-rating { color: var(--blue-dark); font-size: .82rem; font-weight: 800; }
.leaderboard-item.active .leaderboard-name { color: var(--blue-dark); }
.driver-controls { display: grid; grid-template-columns: minmax(260px, 430px) auto; gap: 5px 10px; align-items: end; }
.driver-controls label { grid-column: 1 / -1; color: var(--blue-dark); font-size: .82rem; font-weight: 700; }
.driver-combobox { position: relative; }
.driver-controls input { width: 100%; height: 44px; padding: 0 13px; border: 2px solid #9ca9b4; border-radius: 4px; background: white; color: var(--ink); font: inherit; font-size: 1rem; }
.driver-controls input:focus { border-color: var(--blue); outline: 3px solid rgba(8, 123, 191, .18); }
.driver-options { position: absolute; z-index: 10; top: calc(100% + 5px); right: 0; left: 0; max-height: 280px; overflow-y: auto; border: 1px solid #9ca9b4; border-radius: 4px; background: white; box-shadow: 0 10px 24px rgba(23, 33, 43, .18); }
.driver-options[hidden] { display: none; }
.driver-option { display: block; width: 100%; min-height: 42px; padding: 9px 12px; border: 0; border-bottom: 1px solid #e3e7ea; border-radius: 0; background: white; color: var(--ink); font: inherit; line-height: 1.25; text-align: left; cursor: pointer; }
.driver-option:last-child { border-bottom: 0; }
.driver-option:hover, .driver-option.active { background: #edf7fc; color: var(--blue-dark); }
.driver-option strong, .driver-option small { display: block; pointer-events: none; }
.driver-option small { margin-top: 2px; color: var(--muted); font-size: .76rem; }
.driver-options-empty { padding: 12px; color: var(--muted); font-size: .86rem; }
.driver-controls button { height: 44px; padding: 0 19px; border: 0; border-radius: 4px; background: var(--blue); color: white; font: inherit; font-weight: 700; cursor: pointer; }
.driver-controls .driver-option { height: auto; padding: 9px 12px; background: white; color: var(--ink); font-weight: 400; }
.driver-controls .driver-option:hover, .driver-controls .driver-option.active { background: #edf7fc; color: var(--blue-dark); }
.driver-controls button:hover:not(:disabled) { background: var(--blue-dark); }
.driver-controls button:disabled, .driver-controls input:disabled { cursor: wait; opacity: .62; }

.driver-profile-header { margin-top: 14px; }
.driver-profile-card { display: flex; align-items: center; gap: 18px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 6px; background: linear-gradient(180deg, #ffffff 0%, #f5f9fc 100%); }
.driver-avatar-wrap { position: relative; width: 80px; height: 80px; border-radius: 50%; overflow: hidden; border: 2px solid var(--line); background: #edf3f8; box-shadow: 0 8px 18px rgba(23, 33, 43, .09); }
.driver-profile-image { display: block; width: 100%; height: 100%; object-fit: cover; }
.driver-profile-placeholder { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; background: linear-gradient(135deg, #dfeef8, #bfd9ea); color: var(--blue-dark); font-size: 1.6rem; font-weight: 800; }
.driver-profile-meta { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.profile-meta-label { color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.team-inline { display: inline-flex; align-items: center; gap: 10px; min-height: 32px; }
.team-logo-image { width: 42px; height: 42px; object-fit: contain; border-radius: 8px; background: white; border: 1px solid var(--line); }
.team-name-display { color: var(--ink); font-size: 1.05rem; font-weight: 800; }
.status-panel { margin-top: 14px; padding: 28px; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--muted); text-align: center; }
.spinner { display: inline-block; width: 17px; height: 17px; margin-right: 8px; border: 2px solid #c9d1d8; border-top-color: var(--blue); border-radius: 50%; vertical-align: -3px; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.summary-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.summary-card { min-height: 112px; padding: 16px; border-top: 4px solid var(--blue); }
.summary-card span { display: block; color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; }
.summary-card strong { display: block; margin-top: 8px; color: var(--blue); font-family: 'Racing Sans One', sans-serif; font-size: 2rem; font-weight: 400; line-height: 1; letter-spacing: 0; }
.summary-card small { display: block; margin-top: 7px; overflow: hidden; color: var(--muted); font-size: .78rem; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.summary-card.peak { border-top-color: #6a1b9a; }
.summary-card.peak strong { color: #6a1b9a; }
.summary-card.net { border-top-color: var(--red); }
.summary-card.events { border-top-color: #00796b; }
.summary-card.events strong { color: #00796b; }
.summary-card.best { border-top-color: var(--positive); }

.panel { margin-top: 14px; padding: 20px; }
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.section-kicker { margin: 0 0 2px; color: var(--red); font-size: .76rem; font-weight: 700; text-transform: uppercase; }
.driver-name { color: var(--muted); font-size: .92rem; text-align: right; }
.chart-panel { position: relative; }
.chart { width: 100%; min-height: 260px; overflow: hidden; border: 1px solid #e1e6ea; background: white; }
.chart svg { display: block; width: 100%; height: auto; min-height: 260px; }
.chart circle { cursor: pointer; }
.chart circle:focus { outline: none; stroke: var(--red); stroke-width: 5; }
.chart-dates { display: flex; justify-content: space-between; padding: 5px 6.5% 0; color: var(--muted); font-size: .78rem; }
.chart-tooltip { position: absolute; z-index: 2; max-width: 260px; padding: 9px 11px; border-radius: 4px; background: var(--ink); color: white; font-size: .78rem; line-height: 1.45; pointer-events: none; white-space: pre-line; transform: translate(-50%, calc(-100% - 12px)); }

.table-panel { padding: 0; overflow: hidden; }
.table-panel .panel-heading { margin: 0; padding: 18px 20px 12px; }
.table-scroll { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 11px 13px; border-top: 1px solid #e0e5ea; text-align: right; white-space: nowrap; }
th { background: #edf2f5; color: #3c4953; font-size: .75rem; text-transform: uppercase; }
th[data-tooltip] { cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; }
th[data-tooltip]:focus-visible { outline: 2px solid var(--blue); outline-offset: -3px; }
.table-header-tooltip { position: fixed; z-index: 10000; width: max-content; max-width: min(280px, calc(100vw - 24px)); padding: 9px 11px; border-radius: 4px; background: var(--ink); color: white; font-size: .78rem; line-height: 1.4; text-align: left; pointer-events: none; transform: translateX(-50%); box-shadow: 0 5px 16px rgba(23, 33, 43, .22); }
.table-header-tooltip[hidden] { display: none; }
th:nth-child(1), th:nth-child(2), th:nth-child(3), td:nth-child(1), td:nth-child(2), td:nth-child(3) { text-align: left; }
tbody tr:nth-child(even) { background: #f7f9fa; }
tbody tr:hover { background: #edf7fc; }
td:nth-child(2) { min-width: 210px; font-weight: 700; }
.change-positive { color: var(--positive) !important; }
.change-negative { color: var(--negative) !important; }
.change-zero { color: var(--zero) !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 1050px) {
    .rankings-header { grid-template-columns: auto 1fr; }
    .header-nav { grid-column: 1 / -1; }
    .rankings-layout { grid-template-columns: 1fr; }
    .leaderboard-panel { position: static; }
    .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
    .rankings-header { grid-template-columns: 1fr; gap: 15px; padding: 20px; }
    .rankings-logo { max-width: none; width: 145px; }
    .header-copy h1 { font-size: 2.15rem; }
    .header-nav { grid-column: auto; flex-wrap: wrap; }
    .rankings-main { width: min(100% - 24px, 1440px); margin-top: 12px; }
    .selector-panel { align-items: stretch; flex-direction: column; gap: 14px; }
    .driver-controls { grid-template-columns: 1fr; }
    .driver-controls label { grid-column: auto; }
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .summary-card { min-height: 102px; }
    .summary-card.best { grid-column: 1 / -1; }
    .panel { padding: 14px 10px; }
    .panel-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
    .driver-name { text-align: left; }
    .chart { min-height: 220px; }
    .chart svg { min-height: 220px; }
    .table-panel { padding: 0; }
    .table-panel .panel-heading { padding: 15px 13px 10px; }
}