.projects {
    --decoration: #ccc;
    --decoration-width: 2px;
    --checkers: #d7d7cd;
    --metrobeat: #f8fafc;
    color: #000;
}

.projects-intro {
    --intro-inset: calc(2.5 * var(--content-unit));
    padding: calc(7.5 * var(--content-unit)) var(--intro-inset) calc(5 * var(--content-unit));
}

.project-grid {
    display: grid;
    --project-columns: 2;
    --project-gap: calc(2.5 * var(--content-unit));
    --grid-width: calc(var(--content-width) - 2 * var(--intro-inset));
    --track-width: calc((var(--grid-width) - (var(--project-columns) - 1) * var(--project-gap)) / var(--project-columns));
    grid-template-columns: repeat(var(--project-columns), minmax(0, 1fr));
    gap: var(--project-gap);
}

.project-in-progress {
    --rail: 5%;
    --rule-start: 7.5%;
    --mark: 1.5rem;
    --rail-size: calc(var(--track-width) * 0.05);
    position: relative;
    min-width: 0;
    padding: calc(var(--rail-size) + 0.75rem) 0 0 var(--rail);
}

.project-in-progress::before,
.project-in-progress::after {
    position: absolute;
    content: "";
    background: var(--decoration);
}

.project-in-progress::before {
    top: var(--rail-size);
    left: var(--rule-start);
    right: 0;
    height: var(--decoration-width);
}

.project-in-progress::after {
    top: calc(var(--rail-size) + var(--mark));
    bottom: 0;
    left: calc(var(--rail) / 2 - var(--decoration-width) / 2);
    width: var(--decoration-width);
}

.project-mark {
    position: absolute;
    top: calc(var(--rail-size) + var(--decoration-width) / 2);
    left: calc(var(--rail) / 2);
    width: min(var(--mark), var(--rail));
    height: var(--mark);
    transform: translate(-50%, -50%);
    background:
        linear-gradient(var(--decoration) 0 0) center / 100% var(--decoration-width) no-repeat,
        linear-gradient(var(--decoration) 0 0) center / var(--decoration-width) 100% no-repeat;
}

.project-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.75rem;
    margin: 0 0 2rem;
    font-size: 24px;
    font-weight: 500;
    line-height: 1.25;
}

.project-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 1.25em;
    box-sizing: border-box;
    padding: 0 0.6rem;
    border-radius: 999px;
    background: var(--status-bg);
    white-space: nowrap;
}

.project-status::before {
    content: "";
    width: calc(1.25em / 3);
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--status-dot);
}

.project-status span { font-size: 14px; }
.project-status--progress { --status-bg: #ffffaa; --status-dot: #ffeb00; }
.project-status--complete { --status-bg: #e1ffaa; --status-dot: #96ff32; }

.project-cover {
    width: 90%;
    margin: 0 auto 1rem;
    aspect-ratio: 14 / 10;
    border-radius: var(--content-unit);
    background: #f4f4f4;
}

.project-complete {
    --complete-inset: calc(5 * var(--content-unit));
    /* Only the background fills the viewport; the article contents stay aligned. */
    padding-block: var(--complete-inset);
    padding-inline: calc((100cqw - var(--content-width)) / 2 + var(--complete-inset));
}
.project-complete--checkers {
    display: flex;
    flex-direction: column;
    background: var(--checkers);
}
.project-complete--metrobeat { background: var(--metrobeat); }

.project-heading a {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    color: inherit;
    text-decoration: none;
}

.project-link-icon {
    width: 1em;
    height: 1em;
    flex: none;
}
.project-heading a:hover, .project-heading a:focus-visible { text-decoration: underline; }

.project-gallery {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: calc(3 * var(--content-unit));
    align-items: start;
}

.project-gallery img {
    display: block;
    width: 100%;
    height: auto;
}

.project-gallery img,
.about-photo {
    border-radius: var(--content-unit);
    outline: 1px solid rgb(0 0 0 / 30%);
}
.project-gallery--checkers {
    --gallery-width: calc(var(--content-width) - 2 * var(--complete-inset));
    --shot-gap: calc(0.03 * var(--gallery-width));
    --caption-gap: calc(3 * var(--content-unit));
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: var(--shot-gap);
}

.project-checkers-main,
.project-checkers-side { display: grid; }
.project-checkers-main { gap: var(--caption-gap); }
.project-checkers-side { gap: var(--shot-gap); }

@media (max-width: 48rem), (max-height: 36rem) and (pointer: coarse) {
    .project-gallery--checkers { grid-template-columns: minmax(0, 1fr); }
    .project-checkers-main,
    .project-checkers-side { display: contents; }
    .project-checkers-side img:first-child { grid-row: 1; }
    .project-checkers-main img { grid-row: 2; }
    .project-checkers-side img:last-child { grid-row: 3; }
    .project-checkers-main .section-copy { grid-row: 4; }
}

.project-metrobeat-content {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    align-items: start;
    gap: calc(3 * var(--content-unit));
}

.project-metrobeat-preview { position: relative; }

.project-gallery-hint {
    margin: 0 0 0.45rem;
    color: #4b5563;
    font-size: 0.875rem;
    line-height: 1.25;
}

.project-gallery-hint--hover { display: none; }

.project-flip {
    display: block;
    width: 100%;
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: var(--content-unit);
    background: none;
    --flip-angle: 0deg;
    cursor: pointer;
}

.project-flip:focus-visible { outline: 2px solid #1677c8; outline-offset: 4px; }

.project-flip__inner {
    position: relative;
    display: block;
    aspect-ratio: 1179 / 2556;
    pointer-events: none;
}

/* Rotate both faces in their own layers; no shared 3D scene to rebuild on resize. */
.project-flip img {
    position: absolute;
    inset: 0;
    height: 100%;
    backface-visibility: hidden;
    transform: perspective(1800px) rotateY(var(--face-angle, var(--flip-angle)));
    transition: transform 540ms cubic-bezier(0.35, 0.15, 0.35, 1);
    will-change: transform;
}

.project-flip__back { --face-angle: calc(var(--flip-angle) - 180deg); }

.project-flip[aria-pressed="true"] { --flip-angle: 180deg; }

@media (hover: hover) {
    .project-gallery-hint--hover { display: inline; }
    .project-gallery-hint--tap { display: none; }
    .project-flip:hover { --flip-angle: 180deg; }
}

@media (orientation: landscape) {
    .project-gallery-hint {
        position: absolute;
        inset: auto 0 calc(100% + 0.45rem);
        margin: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .project-flip img { transition: none; }
}

.project-divider {
    /* Keep the original tile pitch and phase inside the capped content width. */
    --teeth: 39;
    --tooth-width: calc(var(--content-width) / var(--teeth));
    height: calc(var(--tooth-width) / 2);
    background-color: var(--below, #fff);
}

.project-divider::before {
    content: "";
    display: block;
    height: 100%;
    background-color: var(--above);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Cpath d='M0 0H2L1 1Z'/%3E%3C/svg%3E")
        center top / var(--tooth-width) 100% repeat-x;
}

.project-divider--checkers-top { --above: #fff; --below: var(--checkers); }
.project-divider--between { --above: var(--checkers); --below: var(--metrobeat); }
.project-divider--metrobeat-bottom { --above: var(--metrobeat); }

@media (orientation: portrait) {
    .project-grid { --project-columns: 1; }
    .project-metrobeat-content { grid-template-columns: minmax(0, 1fr); }
    .project-metrobeat-preview { grid-row: 1; }
    .project-divider { --teeth: 19; }
}
