/*
 * Timeline layout, shared by the Tools page and Understanding STES. Loaded
 * only where the "tools-timeline" class appears.
 *
 * Applies to the Group with the "tools-timeline" class (Block → Advanced →
 * Additional CSS class). Each direct child of the Group is one step. Inside
 * a step, the first block is the text and the second block is the media.
 * Colours, type and
 * spacing of the content stay block settings; this file only draws the
 * line, the points and the alternating layout. The points cycle through the
 * Interreg accent colours used for the Home steps (green, navy, teal, coral);
 * a page may override them with --storm-timeline-point. Steps fade in while
 * scrolling and points get a halo on hover (motion only without
 * prefers-reduced-motion).
 */

.tools-timeline {
    position: relative;
}

/* Continuous vertical line */
.tools-timeline::before {
    content: "";

    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;

    width: 1px;

    background: var(--wp--preset--color--palette-color-6);

    transform: translateX(-50%);
}

/* Desktop: text and media alternate either side of the line */
.tools-timeline > * {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 7rem minmax(0, 1fr);
    align-items: center;

    margin: 0;
    padding-block: var(--wp--preset--spacing--70);
}

/* Timeline point */
.tools-timeline > *::before {
    content: "";

    z-index: 1;
    grid-column: 2;
    grid-row: 1;
    justify-self: center;

    box-sizing: border-box;
    width: 16px;
    height: 16px;

    border: 2px solid var(--storm-timeline-point, var(--wp--preset--color--palette-color-1));
    border-radius: 50%;

    background: radial-gradient(
            circle,
            var(--storm-timeline-point, var(--wp--preset--color--palette-color-1)) 0 3px,
            var(--wp--preset--color--palette-color-8) 3.5px
    );
}

/* Point colours; :where() keeps them easy to override */
:where(.tools-timeline > :nth-child(4n + 1)) {
    --storm-timeline-point: var(--wp--preset--color--palette-color-3);
}

:where(.tools-timeline > :nth-child(4n + 2)) {
    --storm-timeline-point: var(--wp--preset--color--palette-color-1);
}

:where(.tools-timeline > :nth-child(4n + 3)) {
    --storm-timeline-point: var(--storm-accent-teal, #00b7a5);
}

:where(.tools-timeline > :nth-child(4n)) {
    --storm-timeline-point: var(--storm-accent-coral, #ec5152);
}

/* Hover or keyboard focus on a step: its point gets a soft halo */
.tools-timeline > :is(:hover, :focus-within)::before {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--storm-timeline-point, var(--wp--preset--color--palette-color-1)) 18%, transparent);
}

@media (prefers-reduced-motion: no-preference) {
    .tools-timeline > *::before {
        transition: transform 0.25s ease, box-shadow 0.25s ease;
    }

    .tools-timeline > :is(:hover, :focus-within)::before {
        transform: scale(1.2);
    }

    /* While scrolling: each step fades in and its point grows into place.
       Only in browsers with scroll-driven animations; others show the
       timeline as it is. */
    @supports (animation-timeline: view()) {
        .tools-timeline > * {
            view-timeline-name: --storm-timeline-step;

            animation: storm-timeline-step linear both;
            animation-timeline: --storm-timeline-step;
            animation-range: entry 10% cover 30%;
        }

        .tools-timeline > *::before {
            animation: storm-timeline-point linear both;
            animation-timeline: --storm-timeline-step;
            animation-range: entry 30% cover 40%;
        }
    }
}

@keyframes storm-timeline-step {
    from {
        opacity: 0;
        translate: 0 1.5rem;
    }

    to {
        opacity: 1;
        translate: 0 0;
    }
}

@keyframes storm-timeline-point {
    from {
        scale: 0.3;
    }

    to {
        scale: 1;
    }
}

.tools-timeline > * > :first-child {
    grid-column: 1;
    grid-row: 1;
    justify-self: end;

    max-width: 28rem;
    margin: 0;

    text-align: right;
}

.tools-timeline > * > :nth-child(2) {
    grid-column: 3;
    grid-row: 1;
    justify-self: start;

    margin: 0;
}

.tools-timeline > :nth-child(even) > :first-child {
    grid-column: 3;
    justify-self: start;

    text-align: left;
}

.tools-timeline > :nth-child(even) > :nth-child(2) {
    grid-column: 1;
    justify-self: end;
}


/* Tablet and mobile: one column, line on the left, media hidden */
@media (max-width: 781px) {
    .tools-timeline::before {
        left: 8px;
    }

    .tools-timeline > * {
        grid-template-columns: 16px minmax(0, 1fr);
        column-gap: var(--wp--preset--spacing--40);
        align-items: start;

        padding-block: var(--wp--preset--spacing--60);
    }

    .tools-timeline > *::before {
        grid-column: 1;
    }

    .tools-timeline > * > :first-child,
    .tools-timeline > :nth-child(even) > :first-child {
        grid-column: 2;
        justify-self: stretch;

        max-width: none;

        text-align: left;
    }

    .tools-timeline > * > :nth-child(2) {
        display: none;
    }
}
