/* ── Logo ────────────────────────────────────────────────── */
.logo {
    font-family: var(--f-display);
    font-weight: 900;
    font-size: 2rem;
    letter-spacing: -0.01em;
    text-transform: uppercase;
    color: var(--ink);
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    transition: color var(--t) var(--ease), transform var(--t) var(--ease);
    display: inline-block;
}

.logo:hover {
    color: var(--accent);
    transform: scale(1.03);
}

.logo:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ── Verdict input wrap (inputs sit inside the verdict racer sides) ── */
.verdict-input-wrap {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sp-2);
    width: 100%;
    max-width: 420px;
    position: relative;
}

/* Race B fills its column from the left */
.verdict-racer--b .verdict-input-wrap {
    width: 100%;
}

/* Race A: explicit minimum so the wrap has a real width, then margin-left
   pushes it to the right edge of the column (near VS) */
.verdict-racer--a .verdict-input-wrap {
    min-width: min(320px, 100%);
    margin-left: auto;
}

/* Race B input stays left-aligned; Race A inherits text-align: right from parent */
.verdict-racer--b .verdict-input-wrap .race-input-field {
    text-align: left;
}

.race-input-field {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-str);
    color: var(--ink);
    padding: var(--sp-2) 0;
    font-size: 0.8125rem;
    font-family: var(--f-body);
    flex: 1 1 auto;
    min-width: 0;
    transition: border-color var(--t) var(--ease);
    outline: none;
}

.race-input-field:hover {
    border-bottom-color: var(--ink-2);
}

.race-input-field:focus {
    border-bottom-color: var(--ink);
}

.race-input-field:focus-visible {
    border-bottom-color: var(--accent);
    box-shadow: 0 1px 0 var(--accent);
}

.race-input-field::placeholder {
    color: var(--ink-3);
}

.parse-button {
    background: transparent;
    border: 1px solid var(--border-str);
    border-radius: var(--r-sm);
    color: var(--ink-3);
    padding: 4px 8px;
    font-size: 0.875rem;
    font-family: var(--f-body);
    cursor: pointer;
    transition: color var(--t), border-color var(--t);
    flex-shrink: 0;
}

.parse-button:hover {
    color: var(--bg);
    border-color: var(--ink);
    background: var(--ink);
}

.parse-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.parse-button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Autocomplete dropdown ─────────────────────────────── */
.ac-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bg);
    border: 1px solid var(--border-str);
    border-radius: var(--r-md);
    box-shadow: 0 8px 32px oklch(13% 0.007 50 / 0.12), 0 2px 8px oklch(13% 0.007 50 / 0.06);
    max-height: 320px;
    overflow-y: auto;
    margin-top: var(--sp-1);
}

.ac-dropdown[hidden] {
    display: none;
}

.ac-item {
    padding: var(--sp-3) var(--sp-4);
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--t) var(--ease);
}

.ac-item:last-child {
    border-bottom: none;
}

.ac-item:hover,
.ac-item.is-active {
    background: var(--bg-subtle);
}

.ac-item.is-active {
    box-shadow: inset 3px 0 0 var(--accent);
}

.ac-name {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--ink);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.2;
}

.ac-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-top: 2px;
    font-size: 0.6875rem;
    color: var(--ink-3);
    font-family: var(--f-body);
}

.ac-event {
    color: var(--ink-2);
    font-weight: 500;
}

.ac-time {
    font-family: var(--f-mono);
    font-variant-numeric: tabular-nums;
    color: var(--ink-2);
}

.ac-division {
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.625rem;
}

.ac-nation {
    color: var(--ink-3);
    font-weight: 500;
}

.ac-season {
    color: var(--ink-3);
    font-size: 0.625rem;
}

.ac-empty {
    padding: var(--sp-4);
    text-align: center;
    color: var(--ink-3);
    font-size: 0.8125rem;
}

.input-error {
    font-size: 0.75rem;
    color: var(--slower);
    margin: var(--sp-1) 0 0;
    min-height: 0;
    line-height: 1.4;
    width: 100%;
    flex-basis: 100%;
}

.vs-separator {
    font-size: 0.6875rem;
    color: var(--ink-3);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    flex-shrink: 0;
}

/* ── Race display (after URL parsed) ───────────────────── */
.race-display {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    min-width: 0;
}

.verdict-racer--a .race-display { justify-content: flex-end; }
.verdict-racer--b .race-display { justify-content: flex-start; }

/* ── Scoreboard name block ──────────────────────────────── */
.racer-name-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
    cursor: pointer;
    transition: opacity var(--t) var(--ease);
}

.racer-name-block:hover {
    opacity: 0.65;
}

.racer-name-block:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 2px;
    opacity: 0.65;
}

.verdict-racer--a .racer-name-block { align-items: flex-end; }
.verdict-racer--b .racer-name-block { align-items: flex-start; }

.racer-surname {
    font-family: var(--f-display);
    font-weight: 900;
    font-size: clamp(1.375rem, 3.5vw, 2.125rem);
    line-height: 0.92;
    letter-spacing: -0.01em;
    text-transform: uppercase;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

#race1-surname { color: var(--race-a); }
#race2-surname { color: var(--race-b); }

.racer-firstname {
    font-family: var(--f-body);
    font-weight: 400;
    font-size: clamp(0.6875rem, 1.1vw, 0.75rem);
    letter-spacing: 0.04em;
    color: var(--ink-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}


/* ── Racer verdict badges ────────────────────────────────── */
.racer-verdict-badge {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    /* Empty by default — takes no space until a state class is applied */
}

.racer-verdict-badge.badge-faster,
.racer-verdict-badge.badge-slower,
.racer-verdict-badge.badge-tied {
    display: inline-flex;
    align-items: center;
    padding: 5px 7px;
    font-size: 0.6875rem;
    letter-spacing: 0.20em;
    animation: badge-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Solid fill — decisive, timing-board style */
.racer-verdict-badge.badge-faster {
    color: oklch(97% 0.012 148); /* near-white, green-tinted */
    background: var(--faster);
    border-color: transparent;
}

.racer-verdict-badge.badge-slower {
    color: oklch(97% 0.012 10); /* near-white, red-tinted */
    background: var(--slower);
    border-color: transparent;
}

.racer-verdict-badge.badge-tied {
    color: var(--ink);
    background: var(--border-str);
    border-color: transparent;
}

@keyframes badge-in {
    from {
        opacity: 0;
        transform: translateY(7px) scale(0.84);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ── Winner name pulse ───────────────────────────────────── */
@keyframes winner-pulse {
    0%   { transform: scale(1); }
    38%  { transform: scale(1.07); }
    68%  { transform: scale(0.97); }
    100% { transform: scale(1); }
}

.verdict-racer.is-winner .race-label {
    animation: winner-pulse 0.55s 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ── Warnings ────────────────────────────────────────────── */
.warnings-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.warnings-container {
    background: var(--accent-bg);
    border-left: 3px solid var(--accent);
    padding: var(--sp-4) var(--sp-5);
    margin: var(--sp-5) 0 0;
    display: none;
}

.warnings-container.visible {
    display: block;
}

.warnings-title {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--accent-dk);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: var(--sp-2);
}

.warning-item {
    font-size: 0.8125rem;
    color: var(--ink-2);
    margin-bottom: var(--sp-1);
    padding-left: var(--sp-4);
    position: relative;
    line-height: 1.5;
}

.warning-item::before {
    content: "—";
    position: absolute;
    left: 0;
    color: var(--accent-dk);
}

.warning-item:last-child { margin-bottom: 0; }

/* ── Section title ───────────────────────────────────────── */
.section-title {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 0.9375rem;
    color: var(--ink);
    margin-bottom: 0;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-title .summary-value {
    font-weight: 600;
}

.section-title .summary-value.negative {
    color: var(--faster);
}

.section-title .summary-value.positive {
    color: var(--slower);
}

.section-title .race-label {
    color: var(--ink);
    font-weight: 700;
}

/* ── Verdict actions (swap button row) ───────────────────── */
.verdict-actions {
    display: flex;
    justify-content: center;
    padding: var(--sp-3) 0 0;
}

.swap-btn {
    background: transparent;
    border: 1px solid var(--border-str);
    border-radius: var(--r-sm);
    color: var(--ink-3);
    padding: 5px 14px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all var(--t) var(--ease);
    font-family: var(--f-body);
    font-weight: 500;
    white-space: nowrap;
}

.swap-btn:hover {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--bg);
}

.swap-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Toggle / utility buttons ────────────────────────────── */
.expand-toggle {
    background: transparent;
    border: 1px solid var(--border-str);
    border-radius: var(--r-sm);
    color: var(--ink-2);
    padding: 5px 10px;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all var(--t) var(--ease);
    font-family: var(--f-body);
    font-weight: 500;
    white-space: nowrap;
    min-height: 28px;
}

.expand-toggle:hover {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--bg);
}

.expand-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Data Table ──────────────────────────────────────────── */
.data-table {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    contain: content;
}

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

thead {
    background: var(--bg);
    border-bottom: 1px solid var(--border-str);
}

th {
    padding: var(--sp-3) var(--sp-4);
    text-align: left;
    color: var(--ink-3);
    font-weight: 600;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    font-family: var(--f-body);
}

th:last-child,
td:last-child {
    text-align: right;
}

th.race-time-col,
td.race-time-col {
    display: table-cell; /* explicit — prevents ambiguous restore after display:none toggle */
    text-align: right;
}

th.race-1-col { color: var(--race-a); }
th.race-2-col { color: var(--race-b); }

td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    font-weight: 400;
    font-size: 0.8125rem;
    color: var(--ink);
}

tbody tr {
    transition: background var(--t) var(--ease);
}

tbody tr td:first-child {
    box-shadow: inset 3px 0 0 transparent;
    transition: box-shadow 0.18s var(--ease);
}

tbody tr:hover {
    background: var(--bg-subtle);
}

tbody tr:hover td:first-child,
tbody tr.highlighted td:first-child {
    box-shadow: inset 3px 0 0 var(--ink);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr.total-row {
    background: var(--bg-subtle);
    border-top: 2px solid var(--border-str);
}

tbody tr.total-row td {
    font-weight: 600;
    padding: 14px var(--sp-4);
    color: var(--ink);
}

tbody tr.highlighted {
    background: var(--faster-bg);
}

.section-name {
    font-weight: 400;
    color: var(--ink);
    font-size: 0.8125rem;
}

.time-value {
    font-family: var(--f-mono);
    font-variant-numeric: tabular-nums;
    color: var(--ink-2);
    font-size: 0.75rem;
}

.diff-positive {
    font-family: var(--f-mono);
    color: var(--slower);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-size: 0.75rem;
}

.diff-negative {
    font-family: var(--f-mono);
    color: var(--faster);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-size: 0.75rem;
}

/* Race time columns: visible by default */
.race-time-col {
    opacity: 1;
    transition: opacity var(--t) var(--ease);
}

.race-time-col.hidden-col {
    display: none;
}

/* ── D3 Waterfall Tooltip ────────────────────────────────── */
.d3-waterfall-tooltip {
    position: absolute;
    opacity: 0;
    background: var(--bg);
    border: 1px solid var(--ink-3);
    border-radius: 3px;
    padding: 14px 16px;
    font-family: var(--f-body);
    box-shadow: 0 8px 32px oklch(13% 0.007 50 / 0.14), 0 2px 8px oklch(13% 0.007 50 / 0.06);
    pointer-events: none;
    z-index: 1000;
    transition: opacity 0.1s ease;
    min-width: 160px;
}

.tooltip-section {
    font-family: var(--f-display);
    font-size: 10px;
    font-weight: 700;
    color: var(--ink-3);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.tooltip-diff {
    font-family: var(--f-display);
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.01em;
    margin-bottom: 8px;
}

.tooltip-times {
    font-family: var(--f-mono);
    font-size: 11px;
    color: var(--ink-2);
    display: flex;
    align-items: center;
    gap: 8px;
}

.tooltip-vs {
    color: var(--ink-3);
    font-size: 9px;
    letter-spacing: 0.06em;
}

/* ── Chart container ─────────────────────────────────────── */
.chart-container {
    background: var(--bg-subtle);
    padding: var(--sp-8) var(--sp-6);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
}

#waterfallChart {
    width: 100%;
    min-height: 500px;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: var(--sp-6);
    margin-top: var(--sp-5);
    padding-top: var(--sp-5);
    border-top: 1px solid var(--border);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.6875rem;
    color: var(--ink-2);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.legend-marker {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.legend-marker.race1  { background: var(--race-a); }
.legend-marker.race2  { background: var(--race-b); }
.legend-marker.faster { background: var(--faster); }
.legend-marker.slower { background: var(--slower); }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
}

/* ── Back link ───────────────────────────────────────────── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-5);
    background: transparent;
    border: 1px solid var(--border-str);
    border-radius: var(--r-sm);
    color: var(--ink-2);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: all var(--t) var(--ease);
}

.back-link:hover {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--bg);
}

.back-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
