/* ============================================================
   Home page flying-image hero
   Thumbnail images fly in from random points and settle into a
   "rugby ball" ellipse around the static centre content. A subtle
   animated network (canvas) sits behind everything. Layout is
   declarative here; the random origins + reveal + network animation
   are driven by /assets/js/homepage-flying-grid.js.
   ============================================================ */
.homepage-flying-grid {
    background: linear-gradient(180deg, #0f1012 0%, #111317 100%);
    overflow: hidden;
    padding: 0;
    position: relative;
    /* network node/line colours (overridden for light mode in light-mode.css) */
    --net-line: 150, 172, 205;
    --net-dot: 184, 199, 222;
}

/* --- animated network background --- */
.homepage-flying-grid__network {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 0;
    pointer-events: none;
}

.homepage-flying-grid__stage {
    position: relative;
    z-index: 1;
    min-height: clamp(600px, 90vh, 860px);
    margin: 0 auto;
    width: 100%;
    display: grid;
    place-items: center;
}

/* --- centre content (static) --- */
.homepage-flying-grid__content {
    position: relative;
    z-index: 3;
    padding: clamp(24px, 3vw, 40px);
    width: 100%;
    /* The content band spans the full width and overlaps the outer cards. Let
       pointer events pass through to the image cards beneath; only the buttons
       below re-enable interaction. */
    pointer-events: none;
}

.homepage-flying-grid__content-inner {
    align-items: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 0 auto;
    max-width: 50rem;
    text-align: center;
    width: 100%;
}

.homepage-flying-grid__eyebrow {
    color: #a9b5c4;
    font-size: 0.875rem;
    letter-spacing: 0.18em;
    margin: 0 0 10px;
    text-transform: uppercase;
}

.homepage-flying-grid__content h1 {
    color: #ffffff;
    font-size: clamp(2rem, 3.6vw, 4.1rem);
    line-height: 1.04;
    margin: 0;
}

.homepage-flying-grid__lead {
    color: #c8d1dc;
    font-size: clamp(0.98rem, 1.2vw, 1.08rem);
    line-height: 1.6;
    margin: 16px 0 0;
    max-width: 34rem;
}

.homepage-flying-grid__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px;
    margin-top: 28px;
    /* re-enable interaction for the buttons (the content layer disables it) */
    pointer-events: auto;
}

.homepage-flying-grid__secondary {
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    color: #ffffff;
    display: inline-flex;
    min-height: 54px;
    padding: 0 22px;
    text-decoration: none;
    transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}

.homepage-flying-grid__secondary:hover,
.homepage-flying-grid__secondary:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.22);
    color: #ffffff;
    text-decoration: none;
}

/* --- image layer (ellipse around the content) --- */
.homepage-flying-grid__images {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.homepage-flying-grid__card {
    position: absolute;
    /* Sized so the eight-image ellipse (the denser layout) still clears the
       section edges and the centre text. Safe for both the 6- and 8-image views. */
    width: clamp(120px, 14vw, 200px);
    aspect-ratio: 4 / 3;
    opacity: 0;
    /* base (pre-reveal) state: displaced to a random origin + shrunk.
       --fly-x / --fly-y / --fly-s are set per-card by the script. */
    transform: translate(-50%, -50%)
               translate(var(--fly-x, 0px), var(--fly-y, 0px))
               scale(var(--fly-s, 0.16));
    transition: transform 1700ms cubic-bezier(0.2, 0.8, 0.2, 1) var(--fly-delay, 0ms),
                opacity 900ms ease var(--fly-delay, 0ms);
    will-change: transform, opacity;
    /* re-enable interaction (the .__images layer disables it) so cards can be
       hovered and, when they carry a link, clicked. */
    pointer-events: auto;
}

/* The script adds .is-in to one card at a time, in a random order. */
.homepage-flying-grid__card.is-in {
    opacity: 1;
    transform: translate(-50%, -50%) translate(0px, 0px) scale(1);
}

/* Wrapping anchor (present only when the image directory defines a link). */
.homepage-flying-grid__card-anchor {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
}

.homepage-flying-grid__card--link {
    cursor: pointer;
}

.homepage-flying-grid__card-inner {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 10px;
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.34);
    height: 100%;
    overflow: hidden;
    width: 100%;
    transition: transform 320ms ease, box-shadow 320ms ease;
}

.homepage-flying-grid__card-inner img {
    display: block;
    height: 100%;
    object-fit: cover;
    width: 100%;
    /* Darker / dulled by default; comes to life on hover or focus. */
    filter: brightness(0.58) saturate(0.72);
    transition: filter 320ms ease;
}

/* Hover / keyboard-focus: brighten the image and lift the thumbnail. */
.homepage-flying-grid__card:hover .homepage-flying-grid__card-inner img,
.homepage-flying-grid__card:focus-within .homepage-flying-grid__card-inner img {
    filter: brightness(1.03) saturate(1.06);
}

.homepage-flying-grid__card:hover .homepage-flying-grid__card-inner,
.homepage-flying-grid__card:focus-within .homepage-flying-grid__card-inner {
    transform: scale(1.06);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

/* --- per-image title (heading shown ABOVE the thumbnail) and caption
   (short description shown BELOW). Both are plain, centred text that fades in
   once the image has flown into place. --- */
.homepage-flying-grid__title,
.homepage-flying-grid__caption {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    white-space: nowrap;
    line-height: 1.15;
    pointer-events: none;
    opacity: 0;
    transition: opacity 450ms ease;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
}

.homepage-flying-grid__title {
    bottom: calc(100% + 7px);
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.01em;
    color: #ffffff;
}

.homepage-flying-grid__title-accent {
    color: var(--sudo-red2, #d20007);
}

.homepage-flying-grid__caption {
    top: calc(100% + 7px);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #e7edf5;
}

/* Title + caption fade in shortly after the image has flown into place. */
.homepage-flying-grid__card.is-in .homepage-flying-grid__title,
.homepage-flying-grid__card.is-in .homepage-flying-grid__caption {
    opacity: 1;
    transition-delay: 700ms;
}

/* Six-image layout (.--six): keep the eight-image ellipse but drop the two side
   images (the far-left and far-right middle ones, positions 7 and 3), leaving a
   balanced six-point shape. The remaining cards keep their positions below.
   Switching back to eight simply drops this class. */
.homepage-flying-grid--six .homepage-flying-grid__card:nth-of-type(3),
.homepage-flying-grid--six .homepage-flying-grid__card:nth-of-type(7) {
    display: none;
}

/* Eight final positions on a rugby-ball ellipse (card centres). The top and
   bottom centre cards are clamped so their centre never comes within 105px of the
   section edge — enough that even the largest card's title (above) / caption
   (below) keeps at least a 5px gap. The clamp only engages on short/wide
   viewports; at normal heights the 14%/86% percentages win and the shape is
   unchanged. */
.homepage-flying-grid__card:nth-of-type(1) { left: 50%; top: max(14%, 105px); }
.homepage-flying-grid__card:nth-of-type(2) { left: 76%; top: 25%; }
.homepage-flying-grid__card:nth-of-type(3) { left: 91%; top: 50%; }
.homepage-flying-grid__card:nth-of-type(4) { left: 76%; top: 75%; }
.homepage-flying-grid__card:nth-of-type(5) { left: 50%; top: min(86%, calc(100% - 105px)); }
.homepage-flying-grid__card:nth-of-type(6) { left: 24%; top: 75%; }
.homepage-flying-grid__card:nth-of-type(7) { left: 9%;  top: 50%; }
.homepage-flying-grid__card:nth-of-type(8) { left: 24%; top: 25%; }

/* --- tablet / mobile: drop the ellipse, show a compact static strip --- */
@media (max-width: 860px) {
    .homepage-flying-grid__stage {
        min-height: auto;
        display: block;
        padding: 64px 0 48px;
    }

    .homepage-flying-grid__images {
        position: static;
        inset: auto;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 8px;
        width: min(100%, 560px);
        margin: 26px auto 0;
        padding: 0 16px;
    }

    .homepage-flying-grid__card,
    .homepage-flying-grid__card.is-in {
        position: static;
        left: auto;
        top: auto;
        width: auto;
        opacity: 1;
        transform: none;
        transition: none;
    }

    /* Titles/captions would crowd the compact thumbnail grid on small screens. */
    .homepage-flying-grid__title,
    .homepage-flying-grid__caption {
        display: none;
    }
}

@media (max-width: 480px) {
    .homepage-flying-grid__images {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* --- reduced motion: settle everything immediately, no fly, no drift --- */
@media (prefers-reduced-motion: reduce) {
    .homepage-flying-grid__card,
    .homepage-flying-grid__secondary {
        transition: none;
    }

    .homepage-flying-grid__card {
        opacity: 1 !important;
        transform: translate(-50%, -50%) scale(1) !important;
    }

    .homepage-flying-grid__title,
    .homepage-flying-grid__caption {
        opacity: 1 !important;
        transition: none !important;
    }
}
