/* Replay-specific styles (supplements /style.css) */

.offscreen-indicator {
    left: 0;
    right: 0;
    height: 4px;
    pointer-events: none;
    opacity: 1;
    transition: opacity 2s ease;
}

.offscreen-indicator.top {
    position: absolute;
    bottom: 0;
    z-index: 100001;
}

.offscreen-indicator.bottom {
    position: fixed;
    bottom: 0;
    z-index: 100001;
}

.offscreen-indicator.fading {
    opacity: 0;
}

#page-wide {
    margin-top: 0;
    padding-top: 0.5rem;
}

#replay-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.5rem 0;
}

#replay-header img {
    width: 64px;
    height: 64px;
}

#replay-header h1 {
    font-size: clamp(1.2rem, 4vw, 2.5rem);
    color: var(--navy);
    margin: 0;
}

#race-ticker {
    position: sticky;
    top: 0;
    background: white;
    z-index: 100000;
    padding: 0.25rem 0;
}

#race-ticker-top {
    display: flex;
    flex-wrap: wrap;
    /* Last baseline so that when the headline wraps to two lines,
       the clock sits alongside the last line (e.g. "remain … HH:MM:SS")
       rather than floating next to line 1. */
    align-items: last baseline;
    row-gap: 0.25rem;
    column-gap: 1rem;
}

#race-headline,
#race-clock {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--navy);
}

/* Let the headline fill whatever space the clock leaves on the
   flex line, so it sits left-of-clock at wide widths and shrinks
   (wrapping internally) as the window narrows.  Without flex-basis: 0
   the flex algorithm wraps the clock to its own line *before* the
   headline has a chance to shrink. */
#race-headline {
    flex: 1 1 0;
}

#race-clock {
    /* Allow the clock box to shrink below its content's intrinsic
       size (default min-width on flex items would otherwise pin it
       to the widest unbreakable token).  HH:MM:SS has no break
       opportunities so it stays atomic during the race; the
       pre-race countdown ("1 day 18 hours …") has wrappable
       regular spaces between groups so it wraps when the viewport
       is too narrow to fit it on one line. */
    flex: 0 1 auto;
    min-width: 0;
}

/* HH:MM:SS has no spaces and colons aren't soft-break opportunities,
   so it stays atomic without a nowrap rule.  Leaving wrap enabled
   here lets the pre-race countdown ("1 day 18 hours …") wrap when
   it's too long for one line; non-breaking spaces inside each
   number-unit pair (see frontend.js format_duration) keep "1 day"
   together at the wrap. */

#race-status {
    font-size: 0.85rem;
    color: var(--gray-muted);
}

#controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: var(--gray-muted);
}

#controls button {
    width: auto;
    font-size: 0.85rem;
    padding: 0.3rem 1rem;
}

#controls select {
    border: 1px solid var(--navy-muted);
    border-radius: 4px;
    padding: 0.2rem 0.4rem;
    font-size: 0.85rem;
}

#standings {
    width: 100%;
    border-collapse: collapse;
}

#standings tr {
    cursor: pointer;
    /* Always-present invisible outline; highlight_row() animates
       outline-color to flash a row (e.g. red on DNF). */
    outline: 2px solid transparent;
    outline-offset: -2px;
}

#standings tr.row-odd {
    background: var(--blue-muted);
}

#standings tr.row-even {
    background: var(--blue-faint);
}

#standings td,
#standings th {
    padding: 0.2rem 0.25rem;
    vertical-align: baseline;
}

/* ---- Team standings ---- */

#team-standings {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
}

#team-standings tr {
    outline: 2px solid transparent;
    outline-offset: -2px;
}

#team-standings tr.row-odd {
    background: var(--blue-muted);
}

#team-standings tr.row-even {
    background: var(--blue-faint);
}

#team-standings td {
    padding: 0.2em 0.25em;
    vertical-align: middle;
}

/* Discrete breakpoints for the team logo/name/score sizing.  A
   continuous-vw scale caused 1-line ↔ 2-line oscillation of long
   names like "Scrambled Legs" during smooth resize, because auto
   table layout renegotiates column widths as the base font
   shrinks.  Three fixed breakpoints give each width range a single
   stable layout.

   At narrow widths the team name wraps freely.  At the wider
   breakpoints we add `white-space: nowrap` to force the name
   column's min-content to equal its max-content, so auto table
   layout gives it the full unbreakable width rather than letting
   the 100%-width members column claim the remainder and squeeze
   the name into a wrap. */
#team-standings .team-col-logo {
    font-size: 2rem;
    text-align: center;
    line-height: 1;
    padding-left: 0.3em;
    padding-right: 0.3em;
}

#team-standings .team-col-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--gray);
    vertical-align: middle;
}

#team-standings .team-col-score {
    font-weight: bold;
    font-size: 2rem;
    color: var(--navy);
    text-align: right;
    vertical-align: middle;
    white-space: nowrap;
    line-height: 1;
    padding-left: 0.3em;
    padding-right: 0.3em;
}

@media screen and (min-width: 650px) {
    #team-standings .team-col-logo {
        font-size: 2.5rem;
    }
    #team-standings .team-col-name {
        font-size: 1.5rem;
        white-space: nowrap;
    }
    #team-standings .team-col-score {
        font-size: 2.5rem;
    }
}

@media screen and (min-width: 800px) {
    #team-standings .team-col-logo {
        font-size: 3rem;
    }
    #team-standings .team-col-name {
        font-size: 2rem;
    }
    #team-standings .team-col-score {
        font-size: 3rem;
    }
}

.team-col-members {
    width: 100%;
}

/* Two-column grid so team-member names and their scores form
   proper aligned columns: the name takes the available 1fr and
   the score takes a fixed 2em column at the right.  All
   member-lines within a team share the same column widths because
   their grid-template-columns are identical. */
.team-member-line {
    display: grid;
    grid-template-columns: 1fr 2em;
    column-gap: 0.5em;
    align-items: baseline;
    line-height: 1.4;
    padding: 0.15em 0;
}

.team-member {
    /* Right-align the name text within its 1fr cell, so wrapped
       lines flow toward the score column instead of collecting
       empty space on the right. */
    text-align: right;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
}

.team-member:hover {
    color: var(--navy-muted);
}

.team-member-score {
    text-align: right;
    font-weight: normal;
    color: var(--gray-muted);
    font-variant-numeric: tabular-nums;
}

.col-team {
    width: 1.5em;
    text-align: center;
    cursor: pointer;
    font-size: 0.85rem;
}

.team-badge {
    display: inline-block;
    width: 1.2em;
    text-align: center;
    cursor: pointer;
    font-size: 0.75rem;
    vertical-align: baseline;
}

.col-result {
    display: none;
}

.section-header td {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--navy);
    padding: 0.5rem 0.25rem 0.2rem;
}

#section-winner td,
#section-finisher td {
    color: var(--gray);
    background: var(--yellow);
    border-radius: 3px;
}


/* Shared runner-name styling used by the runner standings column
   and the team standings per-member lines so names appear
   identically in both tables. */
.col-name,
.team-member-line {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--gray);
}

.col-name {
    width: 100%;
}

.col-name .runner-detail {
    font-weight: normal;
    font-size: 0.75rem;
    color: var(--gray-muted);
    margin-left: 0.5rem;
}

/* Narrow-mode DNF rows: keep the Bib/Nat. detail on a single line
   so the row doesn't balloon to two-plus lines when the DNF reason
   column is also narrow.  If col-dnf-reason crowds in from the
   right the trailing nationality is clipped — that's fine; the bib
   is on the left and must always stay visible, which is why we
   moved it there. */
tr.dnf .col-name {
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
}

.col-dnf-reason {
    font-size: 0.75rem;
    color: var(--red);
    font-weight: 600;
    white-space: nowrap;
    text-align: right;
}

.col-loops {
    text-align: right;
    white-space: nowrap;
    font-weight: bold;
    color: var(--navy);
    font-size: 0.9rem;
}

.col-last-time {
    text-align: right;
    white-space: nowrap;
    font-size: 0.8rem;
    color: var(--gray-muted);
    font-variant-numeric: tabular-nums;
}

.col-last-time .expand-toggle {
    display: inline-block;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 4px 0 4px 6px;
    border-color: transparent transparent transparent var(--gray-muted);
    margin-left: 0.5rem;
    vertical-align: middle;
    transition: transform 0.2s ease;
}

tr.expanded .col-last-time .expand-toggle {
    transform: rotate(90deg);
}

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

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

tr.detail-row td {
    padding: 0.25rem 0.5rem 0.5rem;
    max-width: 0;
}

.loop-times-container {
    overflow-x: scroll;
    scrollbar-width: none;
    -ms-overflow-style: none;
    cursor: grab;
    user-select: none;
}

.loop-times-container::-webkit-scrollbar {
    display: none;
}

.loop-times-container:active {
    cursor: grabbing;
}

.loop-times {
    display: flex;
    justify-content: flex-end;
    /* width: max-content lets the flex box grow with its children
       so that overflowing entries become reachable via scrollLeft.
       min-width: 100% keeps the box at least as wide as the scroll
       container when content is short, so flex-end has room to
       right-align it. */
    width: max-content;
    min-width: 100%;
    white-space: nowrap;
    gap: 0;
    line-height: 1.5;
}

.loop-times-name {
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray);
    padding-right: 1em;
    white-space: nowrap;
}

.loop-times-result {
    display: none;
    font-size: 0.7rem;
    margin-right: 0.5em;
    width: 6.5em;
    min-width: 6.5em;
    text-align: center;
}

.loop-times-result.winner,
.loop-times-result.finisher {
    color: var(--gray);
    background: var(--yellow);
    padding: 0.05rem 0.3rem;
    border-radius: 3px;
}

.loop-times-result.DNF {
    color: var(--gray-muted);
}

.loop-times-result.on-course {
    color: var(--navy);
}

.loop-times-result.resting {
    color: var(--gray-muted);
}

.loop-times-count {
    display: none;
    color: var(--navy);
    font-weight: bold;
    margin-left: 0.5em;
}

.loop-times-detail {
    display: none;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: normal;
    color: var(--gray-muted) !important;
    white-space: nowrap;
}

.loop-time-entry {
    display: inline-block;
    width: 5.5em;
    min-width: 5.5em;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    color: var(--gray);
}


#standings .loop-time-entry.pr-loop {
    outline: 2px solid var(--yellow);
    outline-offset: -2px;
}

.loop-time-entry.dnf-reason-cell {
    color: var(--red);
    font-weight: 600;
    font-size: 0.7rem;
    position: relative;
}

.loop-time-entry.dnf-reason-cell span {
    white-space: nowrap;
    text-align: left;
    padding-left: 0.5em;
}

tr.row-odd .loop-time-entry.no-data {
    background: var(--red-muted);
}

tr.row-even .loop-time-entry.no-data {
    background: var(--red-faint);
}

/* On DNF rows the row itself already has a red background (from
   tr.dnf.row-*), so leave the no-data cells transparent.  Opaque
   cell backgrounds would paint over the row's highlight outline. */
tr.dnf .loop-time-entry.no-data {
    background: transparent;
}

/* In narrow mode the DNF reason is already shown in the main runner
   row, so hide it in the detail row.  Also drop the trailing empty
   placeholders past it — otherwise they extend the row and let the
   user scroll empty space into view.  Wide (spreadsheet) mode
   re-enables both below. */
tr.dnf .loop-time-entry.no-data {
    display: none;
}

#standings tr.dnf.row-odd {
    background: var(--red-muted);
}

#standings tr.dnf.row-even {
    background: var(--red-faint);
}

.loop-time-entry .loop-num {
    display: inline-block;
    width: 2.5em;
    text-align: right;
    color: var(--gray-muted);
    margin-right: 0.15em;
}

tr.loop-header {
    display: none;
}

tr.loop-header td {
    padding: 0;
    max-width: 0;
    position: sticky;
    top: 0;
    z-index: 3;
    background: white;
}

.loop-header-name,
.loop-header-detail,
.loop-header-num {
    display: inline-block;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: bold;
    text-align: center;
    color: var(--navy);
}

.loop-header-name {
    padding-right: 1em;
}


.loop-header-num {
    width: 5.5em;
    min-width: 5.5em;
}

/* Hide sticky name in non-wide mode */
.loop-times-name {
    display: none;
}

/* Wide viewport: spreadsheet mode — one row per runner */
/* Spreadsheet mode breakpoint — also in replay.js wide_query */
@media (min-width: 1200px) {
    .col-result {
        display: table-cell;
        font-size: 0.75rem;
        font-weight: 600;
        text-align: center;
        white-space: nowrap;
        min-width: 5.5rem;
    }

    .col-result.winner,
    .col-result.finisher {
        color: var(--gray);
    }

    .col-result.winner span,
    .col-result.finisher span {
        background: var(--yellow);
        padding: 0.1rem 0.4rem;
        border-radius: 3px;
    }

    .col-result.DNF {
        color: var(--gray-muted);
    }

    .col-result.on-course {
        color: var(--navy);
    }

    .col-result.resting {
        color: var(--gray-muted);
    }

    .section-header {
        display: none;
    }

    #standings {
        table-layout: fixed;
    }

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


    .loop-times {
        justify-content: flex-start;
    }

    .loop-time-entry .loop-num {
        display: none;
    }

    .loop-time-entry {
        width: 3.5em;
        min-width: 3.5em;
        text-align: center;
    }

    .loop-header-num {
        width: 3.5em;
        min-width: 3.5em;
        text-align: center;
    }


    tr.loop-header {
        display: table-row;
    }

    .loop-times-name {
        display: inline-block;
    }

    #standings tr.detail-row td,
    #standings tr.loop-header td {
        padding: 0;
        max-width: none;
        display: flex;
        align-items: baseline;
    }

    #standings tr.detail-row .loop-times-container,
    #standings tr.loop-header .loop-times-container {
        flex: 1;
        min-width: 0;
    }

    tr[id^="runner-"] {
        display: none;
    }

    .col-last-time .expand-toggle {
        display: none;
    }

    .loop-times-result {
        display: inline-block;
    }

    .loop-times-count {
        display: inline;
    }

    .loop-times-detail {
        display: inline-block;
    }

    /* Spreadsheet mode only: pin the DNF-reason text out of the
       layout flow so the cell stays the width of a normal loop-time
       entry and columns line up across rows.  In narrow mode the
       cell is allowed to grow naturally. */
    .loop-time-entry.dnf-reason-cell span {
        position: absolute;
        left: 0;
    }

    /* Re-enable the DNF reason cell and trailing empty placeholders
       for DNF rows so the row visually extends to the right and
       aligns with longer rows. */
    tr.dnf .loop-time-entry.no-data {
        display: inline-block;
    }

}

/* Connection-lost overlay */

#standings.disconnected {
    opacity: 0.4;
}

#connection-lost {
    display: none;
}

#connection-lost.visible {
    display: inline;
}

.disconnected #race-clock-text {
    opacity: 0.4;
    text-decoration: line-through;
}

