/* ==========================================================================
   Projects page
   The gallery rows scroll continuously and can be dragged; the item width
   and gutter below are mirrored by the marquee keyframes and by the drag
   handlers in the page template, so keep them in step.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Hero
   -------------------------------------------------------------------------- */

.projects-hero {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: clamp(360px, 48vh, 480px);
    padding-block: calc(var(--header-h) + var(--space-16)) var(--space-16);
    overflow: hidden;
    background-color: var(--ink);
}

.projects-banner {
    position: absolute;
    inset: 0;
}

.projects-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.projects-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, rgba(10, 12, 16, 0.68) 0%, rgba(10, 12, 16, 0.82) 100%);
}

.projects-title {
    max-width: 780px;
    margin-inline: auto;
    padding-inline: var(--gutter);
    text-align: center;
    color: #fff;
}

.projects-title h1 {
    margin-bottom: var(--space-4);
    color: #fff;
}

.projects-title p {
    margin-bottom: 0;
    color: rgba(255, 255, 255, 0.78);
    font-size: var(--text-md);
}

/* --------------------------------------------------------------------------
   Stats
   -------------------------------------------------------------------------- */

.stats-section {
    position: relative;
    padding-block: var(--section-y);
    background-color: var(--surface-subtle);
    background-size: cover;
    background-position: center;
    border-bottom: 1px solid var(--line);
}

/* The section carries a photograph; this wash keeps the figures readable
   without fading the text itself. */
.bg-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(249, 250, 251, 0.94);
    pointer-events: none;
}

.stats-section > .container {
    position: relative;
    z-index: 1;
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-5);
    max-width: var(--container-max);
    margin-inline: auto;
}

.stats-section .stat-item {
    padding: var(--space-8) var(--space-5);
    text-align: center;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.stats-section .stat-item:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: 0 auto var(--space-5);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius);
    background-color: var(--primary-tint);
    color: var(--primary-color);
    font-size: 0.9375rem;
}

.stats-section .stat-number {
    display: block;
    margin-bottom: var(--space-2);
    font-size: clamp(2rem, 1.5rem + 1.8vw, 2.75rem);
    font-weight: 700;
    line-height: 1;
    color: var(--ink);
    letter-spacing: var(--tracking-tight);
}

.stats-section .stat-label {
    margin-top: 0;
    color: var(--muted);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   Gallery
   -------------------------------------------------------------------------- */

.projects-content {
    position: relative;
    padding-block: var(--section-y);
    background-color: var(--surface);
    background-size: cover;
    background-position: center;
}

.projects-content::before {
    content: '';
    position: absolute;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.95);
    pointer-events: none;
}

.projects-content > .container {
    position: relative;
    z-index: 1;
}

.collage-container {
    max-width: var(--container-wide);
    margin-inline: auto;
}

.collage-header {
    max-width: 62ch;
    margin: 0 auto var(--space-12);
    text-align: center;
}

.collage-header h2 {
    margin-bottom: var(--space-4);
    font-size: var(--h2);
    color: var(--ink);
}

.collage-header h2::after {
    content: '';
    display: block;
    width: 40px;
    height: 2px;
    margin: var(--space-4) auto 0;
    background-color: var(--primary-color);
}

.collage-header p {
    color: var(--muted);
    font-size: var(--text-md);
    line-height: var(--leading-normal);
}

.projects-gallery {
    margin-bottom: var(--space-16);
}

.projects-row {
    position: relative;
    margin-bottom: var(--space-5);
    overflow: hidden;
    touch-action: none;
}

.projects-grid {
    display: flex;
    width: fit-content;
    white-space: nowrap;
    user-select: none;
    cursor: grab;
    will-change: transform;
    backface-visibility: hidden;
    transform: translateZ(0);
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

.projects-row:nth-child(odd) .projects-grid {
    animation-name: projectScrollLeft;
    animation-duration: 60s;
}

.projects-row:nth-child(even) .projects-grid {
    animation-name: projectScrollRight;
    animation-duration: 68s;
}

/* Item width (300) + gutter (25) x 6 items — keep in step with .project-item. */
@keyframes projectScrollLeft {
    from { transform: translateX(0); }
    to { transform: translateX(calc(-325px * 6)); }
}

@keyframes projectScrollRight {
    from { transform: translateX(calc(-325px * 6)); }
    to { transform: translateX(0); }
}

.project-item {
    position: relative;
    flex: 0 0 300px;
    min-width: 300px;
    height: 260px;
    margin-right: 25px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background-color: var(--surface-sunken);
    transition: border-color var(--dur) var(--ease);
    /* The fade-in is driven by CSS rather than the observer so that cloned
       items and rows below the fold never sit at zero opacity. The script
       still adds .animated; it simply no longer gates visibility. */
    animation: projectItemIn 500ms var(--ease) 200ms both;
}

@keyframes projectItemIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
}

.project-item:hover {
    border-color: var(--line-strong);
}

.project-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--dur-slow) var(--ease);
}

.project-item:hover img {
    transform: scale(1.03);
}

/* Placeholder when a project row has fewer images than the layout expects. */
.project-item-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    background-color: var(--surface-sunken);
    color: var(--faint);
    font-size: var(--text-sm);
}

/* Toggled by the page script on hover. */
.project-overlay {
    position: absolute;
    inset: auto 0 0 0;
    height: 45%;
    background: linear-gradient(to top, rgba(10, 12, 16, 0.6) 0%, rgba(10, 12, 16, 0) 100%);
    opacity: 0;
    transition: opacity var(--dur-slow) var(--ease);
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Closing call to action
   -------------------------------------------------------------------------- */

.projects-content .cta-section {
    margin: 0 0 var(--space-8);
    padding: clamp(32px, 5vw, 56px) var(--space-8);
    text-align: center;
    background-color: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    color: var(--body);
}

.cta-content {
    max-width: 640px;
    margin-inline: auto;
}

.cta-content h3 {
    margin-bottom: var(--space-3);
    font-size: var(--h2);
    color: var(--ink);
}

.cta-content p {
    margin-bottom: var(--space-8);
    font-size: var(--text-md);
    line-height: var(--leading-normal);
}

.cta-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.cta-section .cta-button.primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.cta-section .cta-button.primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

/* Outlined against a light ground now, so the border and label take the
   neutral tokens rather than translucent white. */
.cta-section .cta-button.secondary {
    background-color: transparent;
    border-color: var(--line-strong);
    color: var(--ink);
}

.cta-section .cta-button.secondary:hover {
    background-color: var(--surface);
    border-color: var(--ink);
    color: var(--ink);
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 991px) {
    .stats-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .projects-hero {
        min-height: 260px;
        padding-block: var(--space-12);
    }

    .project-item {
        flex-basis: 220px;
        min-width: 220px;
        height: 190px;
        margin-right: 15px;
    }

    @keyframes projectScrollLeft {
        from { transform: translateX(0); }
        to { transform: translateX(calc(-235px * 6)); }
    }

    @keyframes projectScrollRight {
        from { transform: translateX(calc(-235px * 6)); }
        to { transform: translateX(0); }
    }

    .projects-content .cta-section {
        padding: var(--space-8) var(--space-5);
    }

    .cta-buttons .cta-button {
        width: 100%;
    }
}

@media (max-width: 560px) {
    .stats-container {
        grid-template-columns: 1fr;
    }
}

/* Continuous motion is disabled when the visitor asks for reduced motion;
   the rows stay draggable. */
@media (prefers-reduced-motion: reduce) {
    .projects-grid {
        animation: none !important;
    }

    .project-item {
        animation: none;
    }
}
