@layer components {
    /* the works section: heading, filters and the card list */
    @scope (.works) to (.tag > *, .work > *) {
        :scope {
            position: relative;
            width: var(--content-width);
            margin-block-start: 72px;
            margin-inline: auto;

            @media (width < 768px) {
                margin-block-start: 36px;
            }
        }

        .works-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-block-end: 30px;

            @media (width < 768px) {
                flex-wrap: wrap;
                gap: 16px;
            }
        }

        .works-filters {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
        }

        .works-list {
            display: grid;
            grid-template-columns: minmax(0, 1fr);
            gap: 38px;
        }
    }

    /* a discipline pill; --toggle makes it a filter checkbox label */
    @scope (.tag) {
        :scope {
            --tag-color: currentColor;
            display: inline-flex;
            align-items: center;
            gap: 7px;
            height: 18px;
            padding-inline: 8px 10px;
            border: 1px solid var(--fg);
            border-radius: 999px;
            font-size: var(--text-xs);

            &::before {
                content: "";
                width: 6px;
                height: 6px;
                border-radius: 50%;
                background: var(--tag-color);
            }

            &.tag--software {
                --tag-color: var(--software);
            }
            &.tag--electronics {
                --tag-color: var(--electronics);
            }
            &.tag--arts {
                --tag-color: var(--arts);
            }

            &.tag--toggle {
                height: 28px;
                gap: 8px;
                padding-inline: 10px 11px;
                font-size: var(--text-md);
                cursor: pointer;
                transition:
                    background var(--t-fast),
                    color var(--t-fast);

                &:hover {
                    background: var(--tint);
                }

                &:has(:checked) {
                    background: var(--fg);
                    color: var(--bg);

                    &:hover {
                        background: color-mix(in srgb, var(--fg) 85%, var(--bg));
                    }
                }
            }
        }

        .tag-input {
            display: none;
        }
    }

    /* a project card: media on one side, text on the other; stacked on phones */
    @scope (.work) to (.tag > *) {
        :scope {
            --work-media-width: 400px;
            /* body padding on the side facing the media, and on the outer side */
            --work-pad-inner: 34px;
            --work-pad-outer: 26px;
            /* clear the fixed header when a link jumps to a card */
            scroll-margin-block-start: calc(var(--bar-height) + 24px);
            display: grid;
            grid-template-columns: var(--work-media-width) 1fr;
            grid-template-rows: 100%;
            height: 366px;
            border: var(--border);
            border-radius: 32px;
            overflow: hidden;
            transition:
                border-color var(--t-base) ease,
                box-shadow var(--t-base) ease,
                translate var(--t-base) ease;

            &.is-active {
                translate: 0 -4px;
                box-shadow: var(--shadow);
            }

            /* alternate cards put the media on the right */
            &:nth-of-type(even) {
                @media (width >= 768px) {
                    grid-template-columns: 1fr var(--work-media-width);

                    .work-media {
                        order: 1;
                    }

                    .work-body {
                        padding-inline: var(--work-pad-outer) var(--work-pad-inner);
                    }
                }
            }

            @media (width < 1200px) {
                --work-media-width: 364px;
            }

            @media (width < 768px) {
                grid-template-columns: minmax(0, 1fr);
                grid-template-rows: auto;
                height: auto;
            }
        }

        .work-media {
            position: relative;
            overflow: hidden;

            @media (width < 768px) {
                aspect-ratio: 1;
            }
        }

        .work-poster,
        .work-video {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        /* the script waits this long before pausing a card that lost focus */
        .work-video {
            opacity: 0;
            transition: opacity var(--t-slow) ease;
        }

        :scope.is-active .work-video {
            opacity: 1;
        }

        .work-body {
            display: flex;
            flex-direction: column;
            gap: 8px;
            padding-block: 29px 25px;
            padding-inline: var(--work-pad-inner) var(--work-pad-outer);
            font-size: var(--text-sm);

            @media (width < 768px) {
                padding: var(--card-pad-phone);
            }
        }

        .work-title {
            font-size: 38px;

            @media (width < 768px) {
                font-size: 30px;
            }
        }

        .work-link {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            text-decoration: none;
            outline: none;

            &::after {
                content: "";
                position: absolute;
                inset: 0;
                border-radius: inherit;
            }
        }

        .work-external {
            width: 0.85em;
            height: 0.85em;
            stroke-width: 0.9;
            stroke-linejoin: round;
            opacity: 0;
            transition: opacity var(--t-fast) ease;

            @media (hover: none) {
                opacity: 1;
            }
        }

        :scope:has(.work-link) {
            position: relative;
            cursor: pointer;
        }

        :scope:has(.work-link:hover, .work-link:focus-visible) {
            translate: 0 -4px;
            box-shadow: var(--shadow);
            border-color: var(--muted);

            .work-external {
                opacity: 1;
            }
        }

        :scope:has(.work-link:focus-visible) {
            outline: 2px solid var(--fg);
            outline-offset: 4px;
        }

        .work-subtitle {
            margin-block-start: 8px;
        }

        /* tags wrap in whatever room the year leaves; the year sits on their last line */
        .work-footer {
            margin-block-start: auto;
            display: flex;
            align-items: last baseline;
            gap: 5px;

            @media (width < 768px) {
                margin-block-start: 16px;
            }
        }

        .work-tags {
            display: flex;
            flex-wrap: wrap;
            gap: 5px;
        }

        .work-year {
            margin-inline-start: auto;
            font-size: var(--text-xs);
            color: var(--muted);
        }
    }
}

@layer components {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation-duration: var(--t-base);
        animation-timing-function: var(--ease);
    }
}
