/* ===== PROJECTS CAROUSEL =====
   Two layouts from the same cards (see js/carousel.js):
   - phones / no JS: a scroll-snap track. The script writes --p to each item,
     its distance from the active slot, -1 (previous) .. 0 (active) .. 1
     (next), and the scale, image parallax and text fade below come from it.
   - wide screens ([data-mode="squeeze"]): an image strip the script draws,
     with the cards stacked underneath as the active project's text. */

.carousel {
    --card-w: min(720px, 88%);
    --gap: 24px;
    --bleed: 0px; /* how far the track runs past the section padding */
}

/* previous / next buttons (only shown once the script is running) */
.carousel__controls {
    display: none;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 20px;
}

.carousel[data-ready] .carousel__controls {
    display: flex;
}

.carousel__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    color: var(--secondary-accent);
    background: transparent;
    border: 1px solid color-mix(in srgb, var(--secondary-accent) 35%, transparent);
    border-radius: 0;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.carousel__btn:hover {
    background: var(--secondary-dark);
    border-color: var(--secondary-accent);
}

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

.carousel__btn[aria-disabled="true"] {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

/* the track */
.carousel__scroller {
    position: relative; /* so offsetLeft is measured from the track */
    display: flex;
    gap: var(--gap);
    list-style: none;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    /* room above/below so the hover lift isn't clipped by overflow */
    padding: 12px var(--bleed);
    margin: -12px calc(-1 * var(--bleed));
    scroll-padding-inline: var(--bleed);
}

.carousel[data-ready] .carousel__scroller {
    scrollbar-width: none;
}

.carousel[data-ready] .carousel__scroller::-webkit-scrollbar {
    display: none;
}

/* trailing space so the last card can also snap to the start */
.carousel__scroller::after {
    content: '';
    flex: 0 0 calc(100% - var(--card-w) - var(--gap));
}

.carousel__item {
    flex: 0 0 var(--card-w);
    width: var(--card-w);
    scroll-snap-align: start;
    scroll-snap-stop: always;
}

/* scale: the neighbours shrink toward the edge facing the active card */
.carousel__inner {
    height: 100%;
    transform: scale(calc(1 - max(var(--p, 0), -1 * var(--p, 0)) * 0.05));
    transform-origin: var(--ox, 50%) 50%;
}

/* the card */
.card.carousel-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0;
    position: relative; /* anchors the stretched link */
    overflow: hidden;
    transition: background-color 0.3s ease, transform 0.3s ease;
}

.card.carousel-card:hover {
    background-color: var(--secondary-dark);
    transform: translateY(-6px);
}

.carousel-card__media {
    position: relative;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    background: var(--secondary-dark);
    pointer-events: none;
}

/* the image is wider than its frame so the parallax shift never shows an edge */
.carousel-card__media img {
    position: absolute;
    top: 0;
    left: -40px;
    width: calc(100% + 80px);
    height: 100%;
    object-fit: cover;
    user-select: none;
    -webkit-user-drag: none;
    transform: translate3d(calc(var(--p, 0) * -30px), 0, 0);
    transition: filter 0.4s ease;
}

/* every card but the active one in warm grey (only once the script has
   marked the active card, so no-JS visitors see colour) */
.carousel[data-ready] .carousel__item:not([data-active]) .carousel-card__media img {
    filter: grayscale(1) sepia(0.25);
}

.carousel-card__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 30px 32px 32px;
    opacity: calc(1 - max(var(--p, 0), -1 * var(--p, 0)));
}

.carousel-card__body h3 {
    margin-bottom: 12px;
}

.carousel-card__body p {
    margin-bottom: 24px;
}

.carousel-card__footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: auto;
}

.carousel-card__link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    color: var(--secondary-accent);
    font-weight: 700;
    text-decoration: none;
    border: 1px solid var(--secondary-accent);
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* stretch the link over the whole card so the card is one click target */
.carousel-card__link::after {
    content: '';
    position: absolute;
    inset: 0;
}

.carousel-card:hover .carousel-card__link {
    background: var(--secondary-accent);
    color: var(--primary-dark);
}

.carousel-card__link:focus-visible {
    outline: none;
}

.carousel-card__link:focus-visible::after {
    outline: 2px solid var(--primary-accent);
    outline-offset: -2px;
}

/* set by the script for a frame while it switches layouts */
.carousel[data-instant] * {
    transition: none !important;
}

/* ===== WIDE SCREENS: SQUEEZE STRIP ===== */

.carousel__strip {
    position: relative;
    width: 100%;
    aspect-ratio: 1232 / 460;
    overflow: hidden;
    margin-bottom: 32px;
    user-select: none;
    -webkit-user-select: none;
}

.carousel__strip[hidden] {
    display: none;
}

/* each column is a full-size picture, moved and clipped by the script */
.carousel__col {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--secondary-dark);
    clip-path: inset(0 50%); /* hidden until the script places it */
    will-change: transform, clip-path;
}

.carousel__col img {
    display: block;
    width: 100%;
    max-width: none;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    -webkit-user-drag: none;
    /* every column but the active one in warm grey */
    filter: grayscale(1) sepia(0.25);
    transition: filter 0.4s ease;
}

.carousel__col[data-active] img {
    filter: none;
}

/* the cards become the text under the strip: all in one grid cell,
   only the active one visible, crossfading like Stripe's */
.carousel[data-mode="squeeze"] .carousel__scroller {
    display: grid;
    overflow: visible;
    padding: 0;
    margin: 0;
    scroll-snap-type: none;
}

.carousel[data-mode="squeeze"] .carousel__scroller::after {
    content: none;
}

.carousel[data-mode="squeeze"] .carousel__item {
    grid-area: 1 / 1;
    width: auto;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.carousel[data-mode="squeeze"] .carousel__item[data-active] {
    opacity: 1;
}

.carousel[data-mode="squeeze"] .carousel__inner {
    transform: none;
}

.carousel[data-mode="squeeze"] .card.carousel-card,
.carousel[data-mode="squeeze"] .card.carousel-card:hover {
    background: none;
    overflow: visible;
    transform: none;
    transition: none; /* or the phone-layout background fades out on load */
}

.carousel[data-mode="squeeze"] .carousel-card__media {
    display: none;
}

.carousel[data-mode="squeeze"] .carousel-card__body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 48px;
    align-items: start;
    align-content: start; /* the cell is as tall as the longest card; don't spread the rows */
    padding: 0;
    opacity: 1;
}

.carousel[data-mode="squeeze"] .carousel-card__body h3 {
    grid-column: 1;
    margin-bottom: 8px;
}

.carousel[data-mode="squeeze"] .carousel-card__body p {
    grid-column: 1;
    max-width: 70ch;
    margin-bottom: 0;
    color: color-mix(in srgb, var(--secondary-accent) 72%, transparent);
}

.carousel[data-mode="squeeze"] .carousel-card__footer {
    grid-column: 2;
    grid-row: 1 / span 2;
    flex-wrap: nowrap;
    gap: 16px;
    margin-top: 0;
}

/* only the button is a link here, not the whole text block */
.carousel[data-mode="squeeze"] .carousel-card__link::after {
    content: none;
}

.carousel[data-mode="squeeze"] .carousel-card:hover .carousel-card__link {
    background: transparent;
    color: var(--secondary-accent);
}

.carousel[data-mode="squeeze"] .carousel-card:hover .carousel-card__link:hover {
    background: var(--secondary-accent);
    color: var(--primary-dark);
}

.carousel[data-mode="squeeze"] .carousel-card__link:focus-visible {
    outline: 2px solid var(--primary-accent);
    outline-offset: 3px;
}

/* announced to screen readers when the slide changes */
.carousel__status {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Projects heading sits closer to the carousel than the other sections' headings */
#Projects .section-title {
    margin-bottom: 30px;
}

@media (max-width: 768px) {
    .carousel {
        --bleed: 20px;
    }

    .carousel-card__body {
        padding: 24px 24px 26px;
    }
}

@media (max-width: 480px) {
    .carousel {
        --bleed: 15px;
        --gap: 16px;
    }

    .carousel-card__media {
        aspect-ratio: 16 / 10;
    }
}

@media (prefers-reduced-motion: reduce) {
    .carousel__inner,
    .carousel-card__media img {
        transform: none;
    }

    .card.carousel-card,
    .card.carousel-card:hover {
        transform: none;
        transition: none;
    }
}
