.date {
    & {
        display: flex;

        justify-content: space-around;
    }

    & div {
        display: flex;
    }

    h1 {
        text-align: center;
    }

    button {
        border: none;
        background: none;

        color: var(--foreground);

        cursor: pointer;
    }
}

#games,
.games-container {
    & {
        --out-active-color: oklch(from var(--yellow) l c h);
        --base-active-color: oklch(from var(--yellow) l c h);

        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
        grid-auto-rows: max-content;
        gap: 1rem;
        
        font-family: var(--sans);
    }
}

:has(mlb-scorebug) {

    [data-first] .scorebug .bases .base:nth-child(3),
    [data-second] .scorebug .bases .base:nth-child(1),
    [data-third] .scorebug .bases .base:nth-child(2) {
        background: var(--base-active-color);
        border: none;
    }

    [data-outs="1"] .scorebug .outs .out:nth-child(1),
    [data-outs="2"] .scorebug .outs .out:nth-child(1),
    [data-outs="3"] .scorebug .outs .out:nth-child(1),
    [data-outs="2"] .scorebug .outs .out:nth-child(2),
    [data-outs="3"] .scorebug .outs .out:nth-child(2),
    [data-outs="3"] .scorebug .outs .out:nth-child(3) {
        background: var(--out-active-color);
        border: none;
    }

    mlb-scorebug {
        --length: 3rem;
        --padding: 0.5rex;
        --computed-length: calc((2 * var(--length) + 2 * var(--padding)) * cos(45deg));

        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .count {
        & {
            display: flex;
            gap: 0.5rex;
            font-size: 0.8rem;
            color: var(--gray);

            margin: -1ex 0 -1rem 0;
        }

        .balls::after {
            margin-left: 0.5rex;
            content: "\2013"
        }
    }

    .scorebug {
        & {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            width: var(--computed-length);
            height: var(--computed-length);
        }

        .outs {
            & {
                display: flex;
                width: var(--length);
                justify-content: space-around;
                height: calc(var(--length) / 4);
            }

            .out {
                border: 1px solid var(--gray);
                border-radius: 50%;

                width: calc(var(--length) / 4);
                height: calc(var(--length) / 4);
            }
        }

        .bases {
            display: grid;
            height: var(--length);
            width: var(--length);
            gap: var(--padding);

            grid-template-columns: repeat(2, 1fr);
            grid-auto-rows: max-content;

            transform: rotate(45deg) translateZ(1px);

            .base {
                width: calc(var(--length) / 2);
                height: calc(var(--length) / 2);

                border: 1px solid var(--gray);
                bottom: 0;
            }
        }
    }
}

mlb-game {
    & {
        --game-border-color: var(--border);
        --computed-border: oklch(from var(--game-border-color) calc(l - 0.125) calc(c - 0.025) h);
        position: relative;
        border: 1px solid var(--computed-border);
        border-radius: 1ex;
        overflow: hidden;

        display: flex;
        flex-direction: column;
        justify-content: center;

        padding-top: 1em;
    }

    &.delayed {
        background: repeating-linear-gradient(45deg,
                transparent,
                transparent 10px,
                oklch(from var(--background) calc(l + 3 / 64) c h) 10px,
                oklch(from var(--background) calc(l + 3 / 64) c h) 20px);

        .gutter {
            background: var(--background);
        }
    }

    &.warmup::before,
    .state,
    .date {
        content: "";
        position: absolute;
        display: inline;
        top: 0;
        right: 0;
        padding: 1ex;

        font-family: var(--monospace);
        font-size: 80%;
        line-height: 1rem;
        text-transform: uppercase;
        vertical-align: middle;

        background: var(--computed-border);
        border-radius: 0 0 0 1ex;
    }

    .state {
        min-width: 2.5em;
        text-align: right;
        text-transform: none;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .state.bottom::before,
    .state.top::before {
        display: block;
        font-size: 1.5rem;
        height: 0.5em;
        line-height: 0.5em;
        z-index: 1;
        margin-right: 0.25ex;
    }

    .state.bottom::before {
        content: '\2304';
        margin-top: -1.25ex;
    }

    .state.top::before {
        content: '\2303';
        margin-bottom: -0.75ex;
    }

    .date {
        text-transform: lowercase;
        bottom: 0;
        top: auto;
        border-radius: 1ex 0 0 0;
    }

    &.live,
    &.final {
        & .date {
            display: none;
        }
    }

    &.final {
        --game-border-color: var(--gray);
    }

    &.live.in-progress {
        --game-border-color: var(--red);
    }

    &.live.warmup {
        --game-border-color: var(--blue);

        &::before {
            content: "Warmup"
        }
    }

    &.final,
    &.live:not(.warmup) {

        .home,
        .away {
            &>:nth-child(5) {
                color: oklch(from var(--background) calc(l + 0.25) c h);
            }

            &>:nth-child(4),
            &>:nth-child(5) {
                font-weight: 400;
            }

            &>:nth-child(3) {
                font-weight: 800;
            }
        }
    }

    &:not(.final):not(.live),
    &.live.warmup {
        .game .teams {

            .header,
            .footer,
            .away,
            .home {
                grid-template-columns: 24px 1fr 5fr;

                width: 100%;
            }

            .header>div:nth-child(2)::before {
                content: 'Proj. SP';
            }

            .header>div:nth-child(3)::before {
                content: 'ERA';
            }

            .away,
            .home {
                &>div:nth-child(3) {
                    font-family: var(--monospace);
                }
            }
        }
    }
}

mlb-game .gutter {
    & {
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        border-top: 1px solid var(--computed-border);
        background: oklch(from var(--computed-border) l c h / 0.25);
        font-size: 0.8rem;
    }

    div {
        & {
            display: flex;
            flex-direction: row;
            justify-content: center;
        }

        &::before {
            color: var(--gray);

            font-weight: 300;
        }
    }

    .winner::before {
        content: "W:\A0";
    }

    .loser::before {
        content: "L:\A0";
    }

    .save::before {
        content: "S:\A0";
    }

    .pitcher::before {
        content: "P:\A0";
    }

    .batter::before {
        content: "AB:\A0";
    }

    .delay::before {
        content: "Delay Reason: \A0";
    }
}

mlb-game .game {
    & {
        display: flex;
        justify-content: space-around;
    }

    .teams {
        & {
            display: flex;
            width: max-content;
            flex-direction: column;
            /* font-family: var(--monospace); */
        }

        .away,
        .home,
        .header,
        .footer {
            position: relative;
            display: grid;
            text-align: center;

            grid-template-columns: 24px repeat(4, 1fr);
            grid-template-rows: 1;

            img {
                display: inline-block;
                height: 100%;
                width: 1.5rem;
                vertical-align: middle;
                margin: 0;
            }
        }

        .away {
            padding-bottom: 1ex;
        }

        .home {
            padding-top: 1ex;
        }

        .away::after,
        .home>div:nth-child(2)::before {
            content: '';
            position: absolute;
            width: 100%;
            left: 0;
        }

        .away::after {
            bottom: 0;
            height: 1px;
            background: var(--border);
        }

        .home>div:nth-child(2)::before {
            content: "@";
            top: -0.5lh;
            height: 1lh;
            font-family: var(--serif);
        }

        .header,
        .footer {

            font-size: 80%;
            padding: 0;
        }

        .header {
            margin: 0 0 -1ex;
        }

        .footer .record,
        .header .record {
            grid-column: span 2;
            color: var(--gray);
            font-size: 0.65rem;
        }

        .footer .record {
            margin-top: -1ex;
        }

        .header .record {
            margin-bottom: -1ex;
        }

        .header>div {
            &:not(:first-child) {
                position: relative;

                width: 75%;
                margin: 0 auto;
                border-bottom: 1px solid var(--border);
                line-height: 1rem;
                padding-bottom: 1ex;
                margin-bottom: 1ex;

                opacity: 70%;
            }

            &:nth-child(2)::before {
                content: 'R';
            }

            &:nth-child(3)::before {
                content: 'H';
            }

            &:nth-child(4)::before {
                content: 'E';
            }
        }
    }
}