/*
 * Homepage request journey (partials/home/features.leaf: nav.fk-jr), between
 * the "How it works" intro and chapter 01. Four linked stops (Collect, Vote,
 * Triage, Notify), each with a small Trailmate mockup, joined by a track.
 *
 * Two ways it renders, and both are complete:
 *   1. No script, reduced motion, or motion.js absent: the markup as written,
 *      which is the FINISHED state. Track full, every node lit, the title
 *      typed, TestFlight on the chip, the email in the inbox. Elements that
 *      exist mid-sequence (data-jr-until) are hidden.
 *   2. html.fk-motion (motion.js) + .fk-jr.is-live (home-journey.js): stops
 *      ahead of the current one show their opening state, the current one
 *      plays (.is-on, beats 0-3), stops behind it hold the finished state.
 *      --jr-p (0 to 1) drives the fill and the travelling marker.
 * Only transform and opacity animate. Colours are --fk-* tokens; status chips
 * reuse .fk-chip--* from story.css. --jr-* names are component internals.
 */

.fk-jr {
    --jr-gap: clamp(0.85rem, 1.6vw, 1.5rem);
    --jr-node: 1.05rem;
    --jr-node-x: 1.1rem;
    --jr-p: 1;
    margin: clamp(0.5rem, 2vw, 1.5rem) auto 0;
    padding-bottom: clamp(2.5rem, 5vw, 4.5rem);
}

.fk-jr__body {
    position: relative;
}

.fk-jr__list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--jr-gap);
    margin: 0;
    padding: 0;
    list-style: none;
}

.fk-jr__stop {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ---------- Track, fill, marker, nodes ---------- */

/* The track runs from the first node to the fourth. Nodes sit at the same
   offset in every column, so the span is three column pitches:
   3 * (column + gap) = 75% of the row + 0.75 gap. */
.fk-jr__track {
    position: absolute;
    top: calc(var(--jr-node) / 2 - 1px);
    left: calc(var(--jr-node-x) + var(--jr-node) / 2);
    width: calc(75% + var(--jr-gap) * 0.75);
    height: 2px;
    border-radius: var(--fk-radius-pill);
    background: var(--fk-hairline);
    container-type: size;
}

.fk-jr__fill {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--fk-accent-gradient);
    transform: scaleX(var(--jr-p));
    transform-origin: left center;
}

.fk-jr__marker {
    position: absolute;
    top: 50%;
    left: 0;
    width: 0.7rem;
    height: 0.7rem;
    margin: -0.35rem 0 0 -0.35rem;
    border-radius: var(--fk-radius-pill);
    background: var(--fk-primary-text);
    box-shadow: 0 0 0 4px var(--fk-primary-soft);
    opacity: 0;
    transform: translateX(calc(var(--jr-p) * 100cqi));
}

.fk-jr__node {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    width: var(--jr-node);
    height: var(--jr-node);
    margin: 0 0 0.85rem var(--jr-node-x);
    border: 2px solid var(--fk-primary-text);
    border-radius: var(--fk-radius-pill);
    background: var(--fk-surface-alt);
}

.fk-jr__node::after {
    content: "";
    position: absolute;
    inset: 2px;
    border-radius: inherit;
    background: var(--fk-primary-text);
}

/* ---------- Stop card ---------- */

.fk-jr__link {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    box-sizing: border-box;
    min-width: 0;
    padding: 1rem 1.1rem 1.1rem;
    border: 1px solid var(--fk-hairline);
    border-radius: var(--fk-radius-lg);
    background: var(--fk-surface-raised);
    color: var(--fk-ink);
    text-decoration: none;
    transition: transform var(--fk-duration-base) var(--fk-ease-out);
}

.fk-jr__link:hover {
    transform: translateY(-3px);
}

.fk-jr__link:focus-visible {
    outline: 2px solid var(--fk-focus);
    outline-offset: 3px;
}

.fk-jr__head {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--fk-primary-text);
    font-size: var(--fk-font-eyebrow);
    font-weight: 600;
    letter-spacing: var(--fk-tracking-eyebrow);
    text-transform: uppercase;
}

.fk-jr__num {
    display: inline-grid;
    place-items: center;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: var(--fk-radius-pill);
    background: var(--fk-accent-gradient);
    color: var(--fk-primary-contrast);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0;
}

.fk-jr__cap {
    color: var(--fk-ink-soft);
    font-size: var(--fk-font-small);
    line-height: var(--fk-leading-snug);
    text-wrap: pretty;
}

.fk-jr__link:hover .fk-jr__name,
.fk-jr__link:focus-visible .fk-jr__name {
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

/* ---------- Mini mockups ---------- */

.fk-jr__card {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.55rem;
    box-sizing: border-box;
    min-height: 7.5rem;
    padding: 0.85rem;
    border: 1px solid var(--fk-hairline);
    border-radius: var(--fk-radius-md);
    background: var(--fk-surface-alt);
    font-size: 0.8rem;
    line-height: 1.3;
    overflow: hidden;
}

.fk-jr__k {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--fk-ink-soft);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* 01 Collect: the title types into the field. */
.fk-jr__field {
    display: flex;
    align-items: center;
    min-height: 2rem;
    padding: 0 0.6rem;
    border: 1px solid var(--fk-hairline);
    border-radius: var(--fk-radius-sm);
    background: var(--fk-surface-raised);
    color: var(--fk-ink);
    font-weight: 600;
    white-space: nowrap;
}

.fk-jr__type {
    display: inline-flex;
    white-space: pre;
}

.fk-jr__caret {
    display: inline-block;
    width: 2px;
    height: 1.05em;
    margin-left: 1px;
    background: var(--fk-primary-text);
    opacity: 0;
}

.fk-jr__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.fk-jr__tag {
    overflow: hidden;
    color: var(--fk-ink-soft);
    font-size: 0.72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fk-jr__btn {
    flex: none;
    padding: 0.25rem 0.65rem;
    border-radius: var(--fk-radius-pill);
    background: var(--fk-accent-gradient);
    color: var(--fk-primary-contrast);
    font-size: 0.72rem;
    font-weight: 700;
}

.fk-jr__sent {
    color: var(--fk-primary-text);
    font-size: 0.72rem;
    font-weight: 600;
}

/* 02 Vote: the counter rolls (story.js odometer) and the revenue appears. */
.fk-jr__vrow {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.fk-jr__vbtn {
    flex: none;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    min-width: 2.6rem;
    padding: 0.35rem 0.4rem;
    border: 1px solid var(--fk-primary-text);
    border-radius: var(--fk-radius-sm);
    background: var(--fk-primary-soft);
    color: var(--fk-primary-text);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.fk-jr__vbtn svg {
    width: 0.75rem;
    height: 0.75rem;
}

.fk-jr__vtext {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.fk-jr__vtext b,
.fk-jr__t {
    overflow: hidden;
    color: var(--fk-ink);
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fk-jr__mrr {
    color: var(--fk-ink-soft);
    font-size: 0.74rem;
    font-weight: 600;
}

.fk-jr__voters {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--fk-ink-soft);
    font-size: 0.7rem;
}

.fk-jr__voters i {
    display: inline-grid;
    place-items: center;
    width: 1.45rem;
    height: 1.45rem;
    border: 1px solid var(--fk-hairline);
    border-radius: var(--fk-radius-pill);
    background: var(--fk-surface-raised);
    color: var(--fk-ink);
    font-size: 0.56rem;
    font-style: normal;
    font-weight: 700;
    --jr-hide: scale(0.5);
}

.fk-jr__voters span {
    margin-left: 0.2rem;
}

/* 03 Triage: the chip steps Pending, Approved, In Progress, TestFlight. */
.fk-jr__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.fk-jr__chips {
    font-size: 0.9rem;
}

.fk-jr__votes {
    color: var(--fk-ink-soft);
    font-size: 0.72rem;
    white-space: nowrap;
}

.fk-jr__seg {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.25rem;
}

.fk-jr__seg i {
    display: block;
    height: 4px;
    border-radius: var(--fk-radius-pill);
    background: var(--fk-accent-gradient);
    transform-origin: left center;
    --jr-hide: scaleX(0);
}

/* 04 Notify: the status email lands in the inbox of the person who asked. */
.fk-jr__card--notify {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    justify-content: stretch;
    align-content: stretch;
}

.fk-jr__badge {
    padding: 0.1rem 0.45rem;
    border-radius: var(--fk-radius-pill);
    background: var(--fk-accent-gradient);
    color: var(--fk-primary-contrast);
    font-size: 0.62rem;
    letter-spacing: 0;
    text-transform: none;
    --jr-hide: scale(0.6);
}

.fk-jr__wait,
.fk-jr__mail {
    grid-area: 2 / 1;
    align-self: center;
}

.fk-jr__wait {
    color: var(--fk-ink-soft);
    font-size: 0.74rem;
    text-align: center;
}

.fk-jr__mail {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.6rem 0.65rem;
    border: 1px solid var(--fk-hairline);
    border-left: 3px solid var(--fk-primary-text);
    border-radius: var(--fk-radius-sm);
    background: var(--fk-surface-raised);
    --jr-hide: translateY(-0.6rem);
}

.fk-jr__subj {
    color: var(--fk-ink);
    font-size: 0.74rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.fk-jr__move {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    color: var(--fk-ink-soft);
    font-size: 0.72rem;
}

.fk-jr__move b {
    color: var(--fk-ink);
}

/* Static (finished) state: mid-sequence elements are hidden. */
.fk-jr [data-jr-until] {
    opacity: 0;
}

/* ---------- Motion: the live loop ---------- */

html.fk-motion .fk-jr.is-live {
    --jr-p: 0;
}

html.fk-motion .fk-jr.is-live .fk-jr__fill {
    transition: transform 0.7s var(--fk-ease-out);
}

html.fk-motion .fk-jr.is-live .fk-jr__marker {
    opacity: 1;
    transition: transform 0.7s var(--fk-ease-out);
}

html.fk-motion .fk-jr.is-live .fk-jr__marker::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--fk-primary-text);
    animation: fk-jr-ping 1.6s var(--fk-ease-out) infinite;
}

html.fk-motion .fk-jr.is-live .fk-jr__node::after {
    transition: transform var(--fk-duration-base) var(--fk-ease-spring);
}

html.fk-motion .fk-jr.is-live .is-ahead .fk-jr__node::after {
    transform: scale(0);
}

/* Only the mockup dims on a stop that is ahead; the caption keeps its
   contrast. */
html.fk-motion .fk-jr.is-live .fk-jr__card {
    transition: opacity var(--fk-duration-slow) var(--fk-ease-out);
}

html.fk-motion .fk-jr.is-live .is-ahead .fk-jr__card {
    opacity: 0.55;
}

html.fk-motion .fk-jr.is-live .is-on .fk-jr__link {
    border-color: var(--fk-primary-text);
}

/* Mid-sequence pieces: home-journey.js adds .is-in when each should show. */
html.fk-motion .fk-jr.is-live [data-jr-from],
html.fk-motion .fk-jr.is-live [data-jr-until] {
    opacity: 0;
    transform: var(--jr-hide, translateY(0.3rem));
    transition: opacity var(--fk-duration-base) var(--fk-ease-out), transform var(--fk-duration-base) var(--fk-ease-out);
}

html.fk-motion .fk-jr.is-live .is-in {
    opacity: 1;
    transform: none;
}

/* Typing: each character appears on its own delay while the stop is on. */
html.fk-motion .fk-jr.is-live .is-ahead .fk-jr__ch {
    opacity: 0;
}

html.fk-motion .fk-jr.is-live .is-on .fk-jr__ch {
    transition: opacity 0s linear calc(var(--jr-i, 0) * 85ms + 150ms);
}

html.fk-motion .fk-jr.is-live .is-on .fk-jr__caret {
    opacity: 1;
    animation: fk-jr-caret 0.9s steps(1) infinite;
}

/* The vote counter starts from data-odo-from on a stop that is ahead, and
   rolls up (story.css transition) once the stop is on. */
html.fk-motion .fk-jr.is-live .is-ahead .fk-odo__reel {
    transform: translate3d(0, calc(var(--from, 0) * -1em), 0);
    transition: none;
}

@keyframes fk-jr-ping {
    0% { opacity: 0.55; transform: scale(1); }
    100% { opacity: 0; transform: scale(2.6); }
}

@keyframes fk-jr-caret {
    0% { opacity: 1; }
    50% { opacity: 0; }
}

/* The stops link to the chapters (#how-*). Clear the fixed navbar, except on
   a pinned chapter, whose pin already pads below it. */
.fk-features .fk-ch[id] {
    scroll-margin-top: 5rem;
}

@media (min-width: 1024px) and (min-height: 640px) {
    html.fk-motion .fk-features .fk-ch[id] {
        scroll-margin-top: 0;
    }
}

/* ---------- Large screens: fill the run-in to chapter 01 ---------- */

@media (min-width: 1024px) {
    .fk-jr__list {
        min-height: clamp(18rem, 30svh, 26rem);
    }
}

/* ---------- Tablets: 2 x 2, no connecting track ---------- */

@media (max-width: 1023px) {
    .fk-jr__list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .fk-jr__track {
        display: none;
    }
}

/* ---------- Phones: a vertical list with the track down the left ---------- */

@media (max-width: 639px) {
    .fk-jr {
        --jr-gap: 0.75rem;
        --jr-node-x: 0px;
    }

    .fk-jr__list {
        grid-template-columns: minmax(0, 1fr);
        grid-auto-rows: 1fr;
    }

    .fk-jr__stop {
        flex-direction: row;
        align-items: flex-start;
        gap: 0.7rem;
    }

    .fk-jr__node {
        flex: none;
        margin: 1.1rem 0 0;
    }

    .fk-jr__link {
        height: 100%;
        padding: 0.85rem;
        gap: 0.6rem;
    }

    /* Compact mockups: the field, counter, chip and email stay; the
       secondary rows go, so four stops fit in a short scroll. */
    .fk-jr__card {
        min-height: 0;
        padding: 0.6rem 0.7rem;
        gap: 0.45rem;
    }

    .fk-jr__card > .fk-jr__k,
    .fk-jr__voters,
    .fk-jr__sent,
    .fk-jr__seg,
    .fk-jr__tag {
        display: none;
    }

    .fk-jr__card--notify {
        grid-template-rows: 1fr;
    }

    .fk-jr__wait,
    .fk-jr__mail {
        grid-area: 1 / 1;
    }

    .fk-jr__row {
        justify-content: flex-end;
    }

    /* Rows are equal height, so the four nodes are three row pitches apart. */
    .fk-jr__track {
        display: block;
        top: calc(1.1rem + var(--jr-node) / 2);
        left: calc(var(--jr-node) / 2 - 1px);
        width: 2px;
        height: calc(75% + var(--jr-gap) * 0.75);
    }

    .fk-jr__fill {
        transform: scaleY(var(--jr-p));
        transform-origin: center top;
    }

    .fk-jr__marker {
        top: 0;
        left: 50%;
        transform: translateY(calc(var(--jr-p) * 100cqb));
    }

    .fk-jr__link:hover {
        transform: none;
    }
}

/* ---------- Reduced motion ---------- */

/* home-journey.js never adds .is-live under reduce, so the strip already
   renders its finished state. This covers the hover lift. */
@media (prefers-reduced-motion: reduce) {
    .fk-jr *,
    .fk-jr *::before,
    .fk-jr *::after {
        animation: none !important;
        transition: none !important;
    }

    .fk-jr__link:hover {
        transform: none;
    }
}
