/* hero scene - hand-painted home hero with a stop-motion boil: each .boil is a one-frame window, the 3-frame strip moves with transform + steps(3) */

.hero-scene {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    /* warmer near the ground, cool clouds (#b8c2cf) */
    background: linear-gradient(to bottom,
        var(--sky)      0%,
        var(--sky)     25%,
        var(--sky-warm) 80%);
    pointer-events: none;

    /* ── the knobs you will want to turn ── */
    /* sky tones: --neutral (#D6CBAE) at 32% and 50% over white */


    /* one 3-frame cycle: 375ms = 8fps · 500 = 6 · 600 = 5 · 750 = 4 (now); everything scales with it */
    --boil-dur: 750ms;
    /* min scene height ≥ 100vh so no bare sky shows above the clouds */
    --stage-min-h: 100vh;

    /* stage point centred in the window (shifted to catch two trunks in tight frames) */
    --stage-focus: 50%;

    /* how much lower the land sits (% of stage height) - reveals more sky */
    --land-drop: 7%;
}

/* the frame dimensions come from static/img/hero/manifest.json. */
.hero-scene {
    --f-clouds: 1185 / 439;
    --f-ground: 1184 / 183;
    --f-tree:    478 / 609;
    --art-aspect: 1.437;     /* the drawing canvas, 1180 × 821 */
}

/* ── palette tokens on <body> so the hero text (a sibling of the scene) inherits them too ── */
body {
    --sky:      #f2eee5;            /* sky above */
    --sky-warm: #eae5d6;            /* sky at the horizon */

    --scrim-rgb:    234, 229, 214;  /* veil colour behind the text */
    --scrim-a:      0.62;
    --ink-title:    #3d3028;
    --ink-sub:      #353821;   /* see the golden-hour contrast note */
    --cloud-filter: none;           /* on a blue sky the clouds need lifting */
    --dusk:         0;              /* 0 = day, 1 = darkness over the land */
    --star-opacity: 0;
}

/* ── stage: anchored at the bottom, lifted with max() on tall screens ── */
.hero-scene .stage {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: max(100%, calc(var(--stage-min-h) * var(--art-aspect)));
    aspect-ratio: var(--art-aspect);
    transform: translateX(calc(-1 * var(--stage-focus)));
}

/* ── parallax: two depth planes (sky, land); trees stand on the hill and move with it ── */
.hero-scene .depth { position: absolute; inset: 0; }

/* ── the boil mechanism ── */
.boil {
    position: absolute;
    overflow: hidden;
}

/* hide a layer while its <img> has no src (sprites live on static.igem.wiki) */
.boil:not(:has(> img[src])) { display: none; }
.boil > img {
    /* strip out of flow so Safari does not grow the window to all three frames */
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    /* height:auto overrides the width/height attribute hints (kept for zero layout shift) */
    height: auto;
    /* one shared beat; set --rate per element to desynchronise (defaults to 1) */
    animation: boil calc(var(--boil-dur) * var(--rate, 1)) steps(3) infinite;
    /* phase offsets in whole frames: same beat, different drawing */
    animation-delay: calc(var(--phase, 0) * var(--boil-dur) * var(--rate, 1) / -3);
}
/* ── boil paused until hero-scene.js takes over with .js-boil and playbackRate ── */
.hero-scene .boil > img          { animation-play-state: paused; }
.hero-scene.js-boil .boil > img  { animation-play-state: running; }

@keyframes boil {
    /* -100% = full strip, steps(3) = three frames; no fill-mode so reduce-motion resets to frame 1 */
    to { transform: translateY(-100%); }
}

/* ── clouds ── */
.hero-scene .clouds > img { filter: var(--cloud-filter); }
.hero-scene .clouds {
    top: 0;
    left: 0;
    width: 100%;
    aspect-ratio: var(--f-clouds);
}
/* 8% wider than the stage: the frame the removed cloud drift left behind */
.hero-scene .drift {
    position: absolute;
    inset: 0 -8% 0 0;
}

.hero-scene .sway {
    position: absolute;
    inset: 0;
}

/* ── ground ── */
.hero-scene .ground {
    bottom: calc(-1 * var(--land-drop));
    left: 0;
    width: 100%;
    aspect-ratio: var(--f-ground);
}
/* hill frozen on frame 1 (too noisy); delete to restore - ground.webp still holds 3 frames */
.hero-scene .ground > img { animation: none; }

/* fill the gap under the hill on very wide screens */
.hero-scene .ground::after {
    content: "";
    position: absolute;
    top: 99%;
    left: 0;
    width: 100%;
    height: 100vh;
    background: #8b9a88;
}

/* ── trees: one sprite at five positions, varied by scale and flip ── */
.hero-scene .tree {
    height: var(--h);
    aspect-ratio: var(--f-tree);
    left: var(--x);
    bottom: calc(100% - var(--base) - var(--land-drop));
    transform: translateX(-50%) scaleX(var(--flip, 1));
}

/* ── reduce motion: native fallback in case accessibility.js is late ── */
@media (prefers-reduced-motion: reduce) {
    .boil > img {
        animation: none;
    }
}
/* low-end devices (class set by hero-scene.js) */
.hero-scene.is-static .boil > img {
    animation: none;
}

/* ── hero text: scrim under the title so it reads over sky, hill and tree alike ── */

.hero .text-container { position: absolute; }

.hero .text-container::before {
    content: "";
    position: absolute;
    inset: -3rem -8rem -4rem -7rem;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(
        ellipse 72% 62% at 32% 55%,
        rgba(var(--scrim-rgb), var(--scrim-a))                     0%,
        rgba(var(--scrim-rgb), calc(var(--scrim-a) * 0.89))        42%,
        rgba(var(--scrim-rgb), 0)                                  80%
    );
}

/* scrim 0.62 + darker ink passes AA (worst background #b5b296) */
.hero h1 {
    color: var(--ink-title);
    text-shadow: 0 2px 28px rgba(var(--scrim-rgb), 0.9);
}
.hero .hero-sub,
.hero .tagline { color: var(--ink-sub); }

/* ── sky presets via <body data-sky="terracotta|aegean|sunset">; tokens only ── */

/* ── terracotta ── */
body[data-sky="terracotta"] {
    --sky:        #f4ede0;
    --sky-warm:   #ecdcc2;
    --scrim-rgb:  236, 220, 194;
}

/* ── aegean: brighten the clouds so they read on the blue sky ── */
body[data-sky="aegean"] {
    --sky:          #cfdcea;
    --sky-warm:     #eee7d8;
    --scrim-rgb:    238, 231, 216;
    --cloud-filter: brightness(1.2) saturate(0.7);
}

/* ── sunset: starting values; hero-scene.js repaints them on scroll ── */
body[data-sky="sunset"] {
    --sky:      #eee4cb;     /* golden hour - never a white sky */
    --sky-warm: #f0cf95;
}

/* land darkened with an alpha overlay (compositor-only) */
.hero-scene .nightfall {
    position: absolute;
    inset: 0;
    background: #241d33;
    opacity: var(--dusk);
    pointer-events: none;
}

/* ── stars: sunset preset only, top half of the stage ── */
.hero-scene .stars {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 56%;
    opacity: var(--star-opacity);
    pointer-events: none;
}
.hero-scene .stars i {
    position: absolute;
    display: block;
    width: var(--s, 2px);
    height: var(--s, 2px);
    border-radius: 50%;
    background: #fdf6e3;
    animation: twinkle var(--tw, 4s) ease-in-out infinite alternate;
    animation-delay: var(--twd, 0s);
}
@keyframes twinkle {
    from { opacity: 0.35; }
    to   { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .hero-scene .stars i { animation: none; }
}
.hero-scene.is-static .stars i { animation: none; }

/* ── scroll lock indicator: progress ring + skip button on dark glass, same layout as the Explore More nav ── */
.hero-lock {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding-bottom: 1.1rem;
    pointer-events: none;      /* .is-s3 on the button unlocks it */
    opacity: 0;
    transition: opacity 0.38s ease, transform 0.38s var(--apple-ease);
}

/* shared glass for the two pieces. */
.hero-lock-paddle,
.hero-lock-skip {
    height: 3rem;
    background: rgba(20, 15, 32, 0.74);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(244, 234, 216, 0.20);
    box-shadow: 0 6px 26px rgba(10, 8, 20, 0.30);
    color: #F4EAD8;
}

/* ring + chevron in the paddle: indicator next to a button */
.hero-lock-paddle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.95rem;
    border-radius: 50px;
}

/* ── ring: r 15.5 in a 36 viewBox → circumference 97.39 = dasharray ── */
.hero-lock-ring {
    width: 2.1rem;
    height: 2.1rem;
    flex: none;
}
/* rotate the counter only (start at 12 o'clock) */
.hero-lock-gauge {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    overflow: visible;         /* the stroke lands on the viewBox edge */
}
.hero-lock-ring circle {
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
}
.hero-lock-track { stroke: rgba(244, 234, 216, 0.22); }
/* 6.4:1 over the track (SC 1.4.11) */
.hero-lock-arc {
    stroke: #F4EAD8;
    stroke-dasharray: 97.39;
    stroke-dashoffset: calc(97.39 * (1 - var(--lock-p, 0)));
}

/* chevron beside the ring says what to do */
.hero-lock-chevron {
    width: 1.15rem;
    height: 1.15rem;
    flex: none;
    fill: none;
    stroke: #F4EAD8;
    stroke-width: 2.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    animation: hero-lock-nudge 2.1s ease-in-out infinite;
}
/* transform only - opacity belongs to birth step 3 */
@keyframes hero-lock-nudge {
    0%, 62%, 100% { transform: translateY(-14%); }
    82%           { transform: translateY( 20%); }
}

/* ── skip: double chevron; name in aria-label + title ── */
.hero-lock-skip {
    display: grid;
    place-items: center;
    width: 3rem;
    flex: none;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
}
.hero-lock-skip svg {
    width: 45%;
    height: 45%;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.hero-lock-skip:focus-visible {
    outline: 3px solid #F4EAD8;
    outline-offset: 3px;
}
@media (hover: hover) {
    .hero-lock.is-s3 .hero-lock-skip:hover {
        background: rgba(38, 30, 56, 0.86);
    }
}

/* ── birth (same as the Explore More nav): s1 seed pops, s2 paddle grows left, s3 content appears ── */

/* step 1 - the seed */
.hero-lock-skip {
    transform: scale(0);
    transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1),
                background 0.25s ease;
}
.hero-lock.is-s1 { opacity: 1; }
.hero-lock.is-s1 .hero-lock-skip { transform: scale(1); }

/* step 2: paddle grows from its right edge */
.hero-lock-paddle {
    transform: scaleX(0);
    transform-origin: right center;
    opacity: 0;
    transition: transform 0.62s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity   0.12s ease;
}
.hero-lock.is-s2 .hero-lock-paddle { transform: scaleX(1); opacity: 1; }

/* step 3 - the content */
.hero-lock-ring,
.hero-lock-chevron,
.hero-lock-skip svg {
    opacity: 0;
    transition: opacity 0.4s ease;
}
.hero-lock.is-s3 .hero-lock-ring,
.hero-lock.is-s3 .hero-lock-chevron,
.hero-lock.is-s3 .hero-lock-skip svg { opacity: 1; }
.hero-lock.is-s3 .hero-lock-skip { pointer-events: auto; }

/* press-in on :active after birth */
.hero-lock.is-s3 .hero-lock-skip:active {
    transform: scale(0.9);
    transition: transform 0.09s ease;
}

/* ── exit: .is-done merges paddle and seed (0–400ms), .is-gone condenses them (440–760ms); order after birth matters ── */

/* ── act A: they become one ── */

/* content leaves first */
.hero-lock.is-done .hero-lock-ring,
.hero-lock.is-done .hero-lock-chevron,
.hero-lock.is-done .hero-lock-skip svg {
    opacity: 0;
    transition: opacity 0.16s ease;
}
.hero-lock.is-done .hero-lock-chevron { animation: none; }

/* paddle and seed meet in sync; --lock-merge-x set by hero-scene.js */
.hero-lock.is-done .hero-lock-paddle,
.hero-lock.is-done .hero-lock-skip {
    transition: transform 0.30s cubic-bezier(0.65, 0, 0.35, 1) 0.10s;
}
.hero-lock.is-done .hero-lock-paddle { transform: scaleX(0); }
.hero-lock.is-done .hero-lock-skip {
    transform: translateX(var(--lock-merge-x, 0px));
    pointer-events: none;
}

/* ── act B: they condense ── */

/* keep translateX, add scale */
.hero-lock.is-gone .hero-lock-skip {
    transform: translateX(var(--lock-merge-x, 0px)) scale(0);
    transition: transform 0.28s cubic-bezier(0.55, 0, 1, 0.45);
}
.hero-lock.is-gone {
    opacity: 0;
    transform: scale(0.2);
    transition: transform 0.30s cubic-bezier(0.55, 0, 1, 0.45),
                opacity   0.22s ease 0.10s;
}

/* lift the title by --lock-lift only when the indicator would overlap it */
.hero .text-container {
    transition: transform 0.45s var(--apple-ease);
}
.hero.is-locked .text-container {
    transform: translateY(calc(-1 * var(--hero-lock-h, 0px)));
}

/* reduce-motion switched on mid-birth: finish instantly */
@media (prefers-reduced-motion: reduce) {
    .hero-lock,
    .hero-lock-paddle,
    .hero-lock-skip,
    .hero-lock-ring,
    .hero-lock-skip svg,
    .hero .text-container { transition: none; }
    .hero-lock.is-done,
    .hero-lock.is-done .hero-lock-paddle,
    .hero-lock.is-done .hero-lock-skip,
    .hero-lock.is-gone,
    .hero-lock.is-gone .hero-lock-skip { transform: none; }
    .hero-lock-chevron { animation: none; transform: none; }
}


/* ── typography & mobile ── */

/* words do not break; spaces between them do */
.hero h1 .word {
    display: inline-block;
    white-space: nowrap;
}

/* Quicksand: rounded, suits the painting; the whole site uses it */
.hero h1 {
    font-family: 'Quicksand', sans-serif;
}
.hero h1 { font-weight: 400; letter-spacing: -1px; }

/* ── mobile: smaller title floor so it fits in two lines ── */
/* ── tight framing on mobile: bigger scene, focus on two trees ── */
@media (max-width: 600px) {
    .hero-scene {
        /* 140vh: trees fit whole */
        --stage-min-h: 140vh;
        /* 65.8% = midpoint of the trees at 54.1% and 77.5% */
        --stage-focus: 65.8%;
    }
}

@media (max-width: 600px) {
    .hero h1 {
        font-size: clamp(1.9rem, calc(8.6vw * var(--fs-scale, 1)), 3.2rem);
        letter-spacing: -0.3px;
        line-height: 1.05;
    }
    .hero .text-container { bottom: 14%; }
}

/* dvh follows the visible height on iOS Safari */
@supports (height: 100dvh) {
    .hero { height: 100dvh; }
}

/* ── animated title: padding + negative margin so blur does not clip descenders ── */
.hero h1 .char {
    padding-block: 0.16em;
    margin-block: -0.16em;
}

/* exit uses the entrance curve, slightly longer, with explicit properties */
.hero h1 .char.hidden {
    transition: opacity   0.55s var(--apple-ease),
                filter    0.55s var(--apple-ease),
                transform 0.55s var(--apple-ease);
    transform: translateY(-14px) scale(0.97);
}
