/* História "Cómo funciona" (home #como-funciona). Sem dependências externas.
   Linha do tempo em scroll normal: três passos empilhados, sem sticky e sem prender o scroll.
   Sem JS e com reduced-motion: tudo no estado final. Com .fx-tl-on (js/fx-timeline.js): a linha
   acompanha o scroll da secção e cada passo toca a sua cena uma vez ao ficar ativo (.is-seen). */
/* ref: @motion-primitives/text-effect -> reveals com clip-path, opacity e transform. */

.story-track {
    max-width: 1200px;
    margin-inline: auto;
    padding: var(--section-y) var(--gutter);
}

.story-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-8);
    margin-bottom: clamp(2rem, 4vw, 3rem);
}

.story-scenes {
    --tl-pad: clamp(2rem, 4vw, 3.5rem);
    position: relative;
    display: grid;
    gap: clamp(3rem, 6vw, 4.5rem);
    padding-left: var(--tl-pad);
}

.story-step {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    align-items: center;
    gap: clamp(2rem, 5vw, 4rem);
}

.story-copy {
    max-width: 30rem;
}

.story-step-number {
    margin-bottom: var(--space-3);
    color: var(--primary);
    font-size: var(--fs-caption);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: .08em;
}

.story-copy h3 {
    margin-bottom: var(--space-3);
    color: var(--on-night);
    font-size: var(--fs-h3);
    font-weight: 600;
    letter-spacing: -.02em;
    line-height: 1.1;
}

.story-copy p:not(.story-step-number) {
    color: var(--on-night-muted);
    font-size: var(--fs-lead);
    line-height: 1.55;
}

.story-illustration {
    justify-self: center;
    width: min(100%, 30rem);
    margin: 0;
    color: var(--on-night);
}

.story-illustration svg {
    display: block;
    width: 100%;
    height: auto;
    filter: drop-shadow(0 0 20px rgb(255 195 0 / .12));
}

.story-progress {
    display: none;
}

/* ---------- Linha do tempo: SVG com pathLength=1; só stroke-dashoffset muda (pintura, não layout) ---------- */
.story-line {
    position: absolute;
    top: 0;
    left: calc(var(--tl-pad) / 2 - 1px);
    width: 2px;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.story-line path {
    fill: none;
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

.story-line__track {
    stroke: var(--line-night);
}

/* Sem JS e com reduced-motion: --tl-p ausente = linha inteira. */
.story-line__fill {
    stroke: var(--primary);
    stroke-dasharray: 1;
    stroke-dashoffset: calc(1 - var(--tl-p, 1));
}

/* Marco de cada passo sobre a linha. */
.story-step::before {
    position: absolute;
    top: 50%;
    left: calc(var(--tl-pad) / -2 - 6px);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 4px var(--night), 0 0 16px rgb(255 195 0 / .45);
    content: "";
    transform: translateY(-50%);
}

.fx-tl-on .story-step::before {
    transition: opacity var(--motion-base, .26s) var(--ease), transform var(--motion-base, .26s) var(--ease);
}

.fx-tl-on .story-step:not(.is-seen)::before {
    opacity: .35;
}

.fx-tl-on .story-step.is-active::before {
    transform: translateY(-50%) scale(1.35);
}

/* Passo 2: PIN viaja do telemóvel para o teclado (aprovado pelo utilizador — manter). */
.fx-tl-on .story-pin-transfer .pin-digit {
    transition: opacity .3s var(--ease), transform .45s var(--ease);
}

.fx-tl-on .story-step:not(.is-seen) .story-pin-transfer .pin-digit {
    opacity: 0;
    transform: translate3d(-3rem, 0, 0);
}

.fx-tl-on .story-pin-transfer .pin-digit:nth-of-type(2) { transition-delay: .08s; }
.fx-tl-on .story-pin-transfer .pin-digit:nth-of-type(3) { transition-delay: .16s; }
.fx-tl-on .story-pin-transfer .pin-digit:nth-of-type(4) { transition-delay: .24s; }

/* Cena 3: a porta do Ilustrador sobe (recorte já no SVG); estado final = porta aberta o bastante para ver as caixas. */
.story-storage-reveal .shutter-slats {
    transform: translateY(-150px);
}

.fx-tl-on .story-storage-reveal .shutter-slats {
    transition: transform 1.1s var(--ease) .2s;
}

.fx-tl-on .story-step:not(.is-seen) .story-storage-reveal .shutter-slats {
    transform: none;
}


@media (max-width: 768px) {
    .story-head {
        display: block;
    }

    .story-scenes {
        --tl-pad: 1.75rem;
    }

    .story-step {
        grid-template-columns: 1fr;
        gap: var(--space-6);
    }

    /* Uma coluna: o marco fica no topo do passo (desenho em cima). */
    .story-step::before {
        top: .5rem;
    }

    .story-illustration {
        justify-self: start;
        width: min(100%, 26rem);
    }
}

/* ---------- Cena 1: telemóvel (arte do Ilustrador) + texto HTML sobre #bubble-slot ---------- */
.phone-stage {
    position: relative;
    width: min(100%, 260px);
    container-type: inline-size;
}

.phone-stage svg {
    display: block;
    width: 100%;
    height: auto;
}

/* #bubble-slot: x68 y160 w130 h68 no viewBox 260x480 */
.bubble-text {
    position: absolute;
    top: 33.3%;
    left: 26.2%;
    display: grid;
    align-content: center;
    gap: .15em;
    width: 50%;
    height: 14.2%;
    color: var(--ink);
    font-size: 5.6cqi;
    line-height: 1.2;
}

.bubble-text strong {
    font-weight: 650;
}

.bubble-text span {
    color: var(--primary-ink);
    font-size: 1.3em;
    letter-spacing: .1em;
}

/* Estado final (sem JS, reduced-motion, passo já visto): a mensagem já chegou. */
.story-phone .typing {
    opacity: 0;
}

.fx-tl-on .story-phone :is(.bubble, .bubble-text) {
    transition: opacity .45s var(--ease) .55s, transform .55s var(--ease) .55s;
}

.fx-tl-on .story-phone .typing {
    transition: opacity .3s var(--ease) .45s;
}

.fx-tl-on .story-step:not(.is-seen) .story-phone :is(.bubble, .bubble-text) {
    opacity: 0;
    transform: translate3d(0, .75rem, 0);
}

.fx-tl-on .story-step:not(.is-seen) .story-phone .typing {
    opacity: 1;
}

/* Cena 3: caixas do Ilustrador no interior; a de cima assenta depois de a porta subir. */
.fx-tl-on .story-storage-reveal .scene-boxes g[class^="box-"] {
    transform-box: fill-box;
    transform-origin: 50% 100%;
}

.fx-tl-on .story-storage-reveal .box-3 {
    transition: opacity .3s var(--ease) .9s, transform .6s cubic-bezier(.34, 1.4, .64, 1) .9s;
}

.fx-tl-on .story-step:not(.is-seen) .story-storage-reveal .box-3 {
    opacity: 0;
    transform: translateY(-18px);
}

@media (max-width: 768px) {
    .phone-stage {
        width: min(62vw, 220px);
    }
}

/* Desktop: a narrativa mantém o meio visual à esquerda e a explicação à direita
   nos três passos. A ordem no HTML continua texto -> arte para preservar o mobile. */
@media (min-width: 769px) {
    .story-step {
        grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
        align-items: center;
    }

    .story-step .story-illustration {
        grid-column: 1;
        grid-row: 1;
        justify-self: center;
    }

    .story-step .story-copy {
        grid-column: 2;
        grid-row: 1;
        justify-self: stretch;
    }
}

/* C3 (FX.md): aurora + grelha sob o cursor atrás do conteúdo; fundo da secção intacto; grelha só ponteiro fino. */
.sk-ambient-host { --mx: 50%; --my: 40%; }
.sk-ambient.fx-aurora { position: absolute; inset: 0; z-index: -1; background: none; opacity: .7; pointer-events: none; }
.sk-ambient.fx-cursor-grid { --mx: inherit; --my: inherit; }
.sk-ambient.fx-cursor-grid::after { opacity: 0; }
.fx-lit:hover > .sk-ambient.fx-cursor-grid::after { opacity: .8; }
@media not all and (hover: hover) and (pointer: fine) { .sk-ambient.fx-cursor-grid::after { display: none; } }

@media (prefers-reduced-motion: reduce) {
    .story-line__fill {
        stroke-dashoffset: 0;
    }
}
