/**
 * Game Log
 *
 * The "Game Log" link under a finished or live matchup card, and the modal
 * it opens: the team modal's shell (css/team-modal.css) with a two-team
 * header, a lead chart, and a point-by-point timeline down the middle
 * between each team's player stats. Built by js/game-log.js from
 * functions/rest-game-log.php.
 *
 * @package Condor
 */

/* ==========================================================================
   Link — mirrors the Watch link on the card's left edge
   ========================================================================== */

.usau-results__matchup-log {
    position: absolute;
    bottom: -32px;
    left: 0;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: 0;
    border-radius: 4px;
    background: none;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: inherit;
    color: var(--wp--preset--color--blue);
    cursor: pointer;
    transition:
        color 0.15s ease,
        background-color 0.15s ease;

    &:hover,
    &:focus-visible {
        color: var(--wp--preset--color--red);
        background-color: var(--wp--preset--color--off-white);
    }

    /* Same size as the Watch link's play icon. */
    svg {
        width: 16px;
        height: 16px;
        flex-shrink: 0;
    }
}

/* Same stacking lift the Watch link gets (see results.css). */
.usau-results__bracket-rounds
    .usau-results__matchup-container:has(.usau-results__matchup-log) {
    z-index: 1;
}

/* Mobile/tablet bracket: the links flow under the card, Game Log left and
   Watch right, on one line. */
@media (max-width: 1199px) {
    .usau-results__bracket-rounds .usau-results__matchup-container:has(.usau-results__matchup-log) {
        flex-flow: row wrap;

        > .usau-results__matchup {
            flex: 1 0 100%;
        }

        > .usau-results__matchup-video {
            margin-left: auto;
        }
    }

    .usau-results__bracket-rounds .usau-results__matchup-log {
        position: static;
        margin-top: 4px;
        margin-right: auto;
    }
}

/* ==========================================================================
   Modal — the team modal's card, wider for three columns
   ========================================================================== */

.team-modal.game-log {
    --log-home: var(--wp--preset--color--blue);
    --log-away: var(--wp--preset--color--red);
    --log-hairline: var(--wp--preset--color--hairline, #ececec);

    .team-modal__card {
        max-width: 1200px;
    }

    /* No tabs in the log. */
    .team-modal__tabs {
        display: none;
    }

    .team-modal__header {
        padding-bottom: 18px;
        border-bottom: 1px solid var(--log-hairline);
    }

    .team-modal__body {
        padding-top: 20px;
    }
}

.game-log__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Header: home team left, away team right, the score between. */
.game-log__identity {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas:
        "home result away"
        "home where  away";
    align-items: center;
    column-gap: 24px;
    padding-right: 44px; /* clear of the close button */
}

.game-log__team--home {
    grid-area: home;
}

.game-log__team--away {
    grid-area: away;
}

.game-log__team {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;

    .team-modal__title-row {
        align-items: center;
        flex-wrap: nowrap;
        margin-bottom: 0;
    }

    .team-modal__name {
        min-width: 0;
        overflow-wrap: break-word;
    }
}

.game-log__team--away {
    flex-direction: row-reverse;
    text-align: right;

    .team-modal__title-row {
        justify-content: flex-end;
    }
}

.game-log__result {
    grid-area: result;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}

/* Scoreboard: each number in its own fixed slot around a fixed dash, so
   every score of a size takes the same box (header, chips, milestones). */
.game-log__board {
    display: inline-grid;
    grid-template-columns: var(--_num, 2ch) var(--_dash, 1ch) var(--_num, 2ch);
    align-items: center;
    font-variant-numeric: tabular-nums;
}

.game-log__score {
    --_num: 1.3em;
    --_dash: 0.7em;

    font-family: var(--wp--preset--font-family--heading);
    font-size: 40px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--wp--preset--color--slate);
}

/* Each number hugs the dash, so the gap is the same on both sides. */
.game-log__num:first-child {
    text-align: right;
}

.game-log__num:last-child {
    text-align: left;
}

.game-log__dash {
    text-align: center;
}

.game-log__dash {
    color: var(--wp--preset--color--mid-gray);
    font-weight: 500;
}

.game-log__status {
    display: block;
    line-height: 1;
}

/* Round, then the EMS round name, then field and start time. */
.game-log__where {
    grid-area: where;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 2px;
    margin-top: 6px;
    font-family: var(--wp--preset--font-family--body);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--wp--preset--color--charcoal);
}

/* The card's Watch link, under the meta lines. */
.game-log__watch {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--wp--preset--color--blue);
    text-decoration: none;

    &:hover,
    &:focus-visible {
        color: var(--wp--preset--color--red);
        background-color: var(--wp--preset--color--off-white);
    }

    svg {
        width: 16px;
        height: 16px;
        flex-shrink: 0;
    }
}

/* A game yet to start: the score steps back. */
.game-log__result.is-upcoming .game-log__score {
    opacity: 0.3;
}

.game-log__upcoming {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin: 24px 0;
    font-size: 16px;
    color: var(--wp--preset--color--charcoal);
    text-align: center;
}

.game-log__upcoming-when {
    font-size: 14px;
    font-weight: 600;
    color: var(--wp--preset--color--mid-gray);
}

/* Points that arrive with a live refresh. */
.game-log__point.is-new {
    animation: game-log-arrive 0.6s ease-out;
}

@keyframes game-log-arrive {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .game-log__point.is-new {
        animation: none;
    }
}

.game-log__where-line {
    display: block;

    &:first-child {
        color: var(--wp--preset--color--slate);
    }
}

/* ==========================================================================
   Lead chart — a step line of the lead around a hairline zero, tinted by
   whoever leads (home above, away below). Labels: each team's largest
   lead; a tick for halftime.
   ========================================================================== */

.game-log__chart {
    padding: 14px 8px;
}

.game-log__plot {
    position: relative;
    height: 32px;
    cursor: pointer;
    touch-action: pan-y;

    svg {
        display: block;
        width: 100%;
        height: 100%;
        overflow: visible;
    }
}

.game-log__zero {
    stroke: var(--wp--preset--color--mid-gray);
    stroke-width: 1;
}

.game-log__line {
    fill: none;
    stroke-width: 1.5;
    stroke-linejoin: round;

    &.is-home {
        stroke: var(--log-home);
    }

    &.is-away {
        stroke: var(--log-away);
    }
}

.game-log__area {
    stroke: none;

    &.is-home {
        fill: var(--log-home);
        fill-opacity: 0.1;
    }

    &.is-away {
        fill: var(--log-away);
        fill-opacity: 0.1;
    }
}

.game-log__chart-label {
    position: absolute;
    font-family: var(--wp--preset--font-family--mono, ui-monospace, Menlo, monospace);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    color: var(--wp--preset--color--mid-gray);

    &.is-home {
        color: var(--log-home);
    }

    &.is-away {
        color: var(--log-away);
    }

    /* Peaks sit just outside the line: above a home lead, below an away one. */
    &.is-peak.is-home {
        transform: translate(-50%, calc(-100% - 3px));
    }

    &.is-peak.is-away {
        transform: translate(-50%, 3px);
    }

}

/* Hover or tap: a hairline at the point and a popover with its score and
   scorers. */
.game-log__hover {
    position: absolute;
    top: -6px;
    bottom: -6px;
    border-left: 1px solid var(--wp--preset--color--slate);
    pointer-events: none;
}

.game-log__tip {
    position: absolute;
    bottom: calc(100% + 10px);
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 150px;
    padding: 8px 10px;
    border: 1px solid var(--log-hairline);
    border-radius: 6px;
    background: var(--wp--preset--color--white);
    box-shadow: 0 6px 20px -6px rgba(0, 0, 0, 0.25);
    font-size: 13px;
    line-height: 1.3;
    white-space: nowrap;
    pointer-events: none;

    .game-log__chip {
        align-self: flex-start;
    }
}

/* The scoring team's number leads; the other steps back. */
.game-log__tip.is-home .game-log__num:last-child,
.game-log__tip.is-away .game-log__num:first-child {
    opacity: 0.6;
    font-weight: 500;
}

/* Its display: flex would otherwise override the hidden attribute. */
.game-log__tip[hidden],
.game-log__hover[hidden] {
    display: none;
}

/* No room above inside the scrolling body: open below the line. */
.game-log__tip.is-below {
    top: calc(100% + 10px);
    bottom: auto;
}

.game-log__chart-half {
    position: absolute;
    top: -6px;
    bottom: -6px;
    border-left: 1px dashed var(--wp--preset--color--light-gray);
    font-size: 0;

    &::after {
        content: "Half";
        position: absolute;
        top: 100%;
        left: 0;
        transform: translate(-50%, 2px);
        font-family: var(--wp--preset--font-family--body);
        font-size: 10px;
        line-height: 1;
        color: var(--wp--preset--color--mid-gray);
    }
}

/* ==========================================================================
   Body — home stats, the timeline dead center, away stats
   ========================================================================== */

.game-log__layout {
    display: grid;
    grid-template-areas: "home log away";
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 28px;
    margin-top: 24px;
    align-items: start;

    @media (max-width: 999px) {
        grid-template-areas: "log log" "home away";
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    @media (max-width: 640px) {
        grid-template-areas: "log" "home" "away";
        grid-template-columns: minmax(0, 1fr);
    }
}

.game-log__stats--home {
    grid-area: home;
}

.game-log__stats--away {
    grid-area: away;
}

/* The team's name is in the header beside its table; the heading is for
   screen readers, and shows only on phones, where the tables stack. */
.game-log__stats-title {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* The team modal's roster table, tightened for a sidebar column. */
.team-modal .game-log__table {
    min-width: 0;

    thead th {
        padding: 10px 6px 8px;
    }

    tbody td {
        padding: 9px 6px;
    }

    .col-jersey {
        width: 28px;
    }

    .col-name {
        font-size: 14px;
    }

    .col-stat {
        width: 28px;
    }
}

/* Players with no stats this game, behind "Show full roster". */
.game-log__stats:not(.is-expanded) .game-log__no-stats {
    display: none;
}

.game-log__roster-toggle {
    margin-top: 8px;
    padding: 6px 10px;
    border: 0;
    border-radius: 4px;
    background: none;
    font-family: var(--wp--preset--font-family--heading);
    font-size: 13px;
    font-weight: 600;
    color: var(--wp--preset--color--mid-gray);
    cursor: pointer;

    &:hover,
    &:focus-visible {
        background: var(--wp--preset--color--off-white);
        color: var(--wp--preset--color--charcoal);
    }
}

/* ==========================================================================
   Timeline — home team left of the spine, away team right, score on it
   ========================================================================== */

.game-log__timeline {
    grid-area: log;
    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;

    &::before {
        content: "";
        position: absolute;
        top: 0;
        bottom: 0;
        left: 50%;
        width: 2px;
        transform: translateX(-50%);
        background: var(--wp--preset--color--light-gray);
    }
}

.game-log__milestone {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
    padding: 7px 12px;
    border: 1px solid var(--log-hairline);
    border-radius: 6px;
    background: var(--wp--preset--color--off-white);
    font-family: var(--wp--preset--font-family--heading);
    font-size: 14px;
    font-weight: 700;
    color: var(--wp--preset--color--slate);

    &:first-child {
        margin-top: 0;
    }

    &:last-child {
        margin-bottom: 0;
    }
}

.game-log__milestone-score {
    font-family: var(--wp--preset--font-family--mono, ui-monospace, Menlo, monospace);
}

.game-log__point {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: start;
    column-gap: 14px;
    padding: 10px 0;
}

.game-log__cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 13px;
    line-height: 1.35;
    color: var(--wp--preset--color--charcoal);
}

.game-log__cell--home {
    align-items: flex-end;
    text-align: right;
}

/* "G" and "A": tiny mono badges in the scoring team's color. */
.game-log__ga {
    display: inline-block;
    min-width: 15px;
    margin-right: 2px;
    padding: 1px 3px;
    border-radius: 3px;
    font-family: var(--wp--preset--font-family--mono, ui-monospace, Menlo, monospace);
    font-size: 10px;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
    text-decoration: none;
    vertical-align: 1px;

    .is-home & {
        color: var(--log-home);
        background: rgba(0, 43, 92, 0.1);
    }

    .is-away & {
        color: var(--log-away);
        background: rgba(157, 21, 53, 0.1);
    }
}

.game-log__player {
    font-family: var(--wp--preset--font-family--heading);
    font-weight: 600;
    color: var(--wp--preset--color--slate);
}

/* Score after the point, filled in the scoring team's color. */
.game-log__chip {
    position: relative;
    padding: 3px 6px;
    border-radius: 4px;
    text-align: center;
    font-family: var(--wp--preset--font-family--mono, ui-monospace, Menlo, monospace);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
    color: var(--wp--preset--color--white);

    .game-log__point.is-home &,
    .game-log__tip.is-home & {
        background: var(--log-home);
    }

    .game-log__point.is-away &,
    .game-log__tip.is-away & {
        background: var(--log-away);
    }
}

/* ==========================================================================
   Phone — the team modal's bottom sheet; logos stay, smaller
   ========================================================================== */

@media (max-width: 640px) {
    .team-modal.game-log {
        .team-modal__header {
            padding-bottom: 12px;
        }

        .team-modal__body {
            padding-top: 14px;
            overflow-x: hidden;
        }

        .team-modal__name {
            font-size: 17px;
        }

        .team-modal__logo {
            display: block;
            width: 32px;
            height: 32px;
            padding: 3px;
        }
    }

    /* A compact scoreboard row, the meta lines across the full width
       under it. */
    .game-log__identity {
        grid-template-areas:
            "home result away"
            "where where where";
        align-items: start;
        column-gap: 8px;
        row-gap: 10px;
        padding-right: 0;
    }

    /* Only the away logo shares a row with the close button. */
    .team-modal.game-log .game-log__team--away .team-modal__logo {
        margin-right: 44px;
    }

    .game-log__team {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .game-log__team--away {
        align-items: flex-end;
    }

    /* The badge sits over the name, which keeps its words whole and runs
       to two lines at most. */
    .game-log__team .team-modal__title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .game-log__team--away .team-modal__title-row {
        align-items: flex-end;
    }

    .team-modal.game-log .game-log__team .team-modal__name {
        display: -webkit-box;
        overflow: hidden;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow-wrap: normal;
        font-size: 14px;
        line-height: 1.2;
    }

    .game-log__result {
        gap: 4px;
        padding-top: 6px;
    }

    .game-log__score {
        font-size: 26px;
    }

    .game-log__where {
        gap: 0;
        margin-top: 0;
        font-size: 12px;
        font-weight: 500;
    }

    .game-log__watch {
        margin-top: 0;
        padding: 0 4px;
        font-size: 12px;

        svg {
            width: 14px;
            height: 14px;
        }
    }


    .game-log__stats-title {
        position: static;
        width: auto;
        height: auto;
        overflow: visible;
        clip-path: none;
        margin: 0;
        padding: 0 0 8px;
        border-bottom: 1px solid var(--wp--preset--color--light-gray);
        font-family: var(--wp--preset--font-family--heading);
        font-size: 15px;
        font-weight: 700;
        color: var(--wp--preset--color--blue);
    }

    .game-log__point {
        column-gap: 8px;
    }

    .game-log__chip {
        padding-inline: 4px;
    }
}
