/* ══════════════════════════════════════════════════════════════
   VRINDAVAN SCENES — Docs/IMPLEMENTATION_PLAN_vrindavan.md, Phase 3.
   One signature moment per page. Flat pigment, hairline ink,
   scroll-bound where the plan says so. With reduced motion every
   scene rests in its finished state: tail open, wheel still.
   ══════════════════════════════════════════════════════════════ */

:root { --ease: cubic-bezier(0.25, 0.1, 0.25, 1); }

/* ─── 1 · HOME — the Yamuna at the page edge ───────────────── */
.v-yamuna {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: clamp(110px, 19vh, 180px);
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}
.v-yamuna-art { display: block; height: 100%; width: 100%; }
/* Fish rest under the front row; with reduced motion one stays frozen mid-leap. */
.yf { transform: translate(0, 60px); }
@media (prefers-reduced-motion: reduce) {
    .yf-1 { transform: translate(40px, -62px) rotate(-6deg); }
}

/* ─── 2 · ABOUT — the implied flute ────────────────────────── */
.v-scene-flute {
    margin: 64px calc(50% - min(50vw - 22px, 560px)) 72px;
}
.v-scene-flute svg { display: block; width: 100%; height: auto; }

/* ─── 3 · HOME WORK SECTION — the unfurling peacock ────────────
   Planned for /build/ (retired Nov 2026); it now opens its tail as
   the reader scrolls through the work cards. */
#work { position: relative; view-timeline-name: --work; }
.v-peacock {
    position: absolute;
    top: 24px;
    right: max(16px, calc((100vw - 1240px) / 2 - 24px));
    width: clamp(160px, 14vw, 220px);
    pointer-events: none;
    z-index: 0;
}
.v-peacock svg { display: block; width: 100%; height: auto; overflow: visible; }
.pk-f { transform: rotate(var(--a)); }          /* the OPEN tail is the default */
@media (max-width: 1099px) { .v-peacock { display: none; } }

/* ─── 4 · MEANING — the chariot wheel ──────────────────────── */
.v-wheel {
    position: fixed;
    top: 50%;
    left: 0;
    width: min(92vh, 860px);
    aspect-ratio: 1;
    transform: translate(-70%, -50%);
    color: var(--marigold-on-night, #987A4F);
    pointer-events: none;
    z-index: 0;
}
.v-wheel-art { display: block; width: 100%; height: 100%; }
@media (max-width: 767px) { .v-wheel { width: 110vw; transform: translate(-78%, -50%); } }

/* ─── 6 · CASE STUDIES — footprints along a rule ───────────── */
.v-footprints {
    max-width: 520px;
    margin: 56px auto;
    view-timeline-name: --steps;
}
.v-footprints svg { display: block; width: 100%; height: auto; }

/* ─── 8 · 404 — the hidden butter pot ──────────────────────── */
.v-pot { width: min(240px, 70vw); margin: 0 auto 28px; }
.v-pot svg { display: block; width: 100%; height: auto; transform-origin: 30% 92%; }

/* ─── 10 · FOOTER — fireflies (the one time-based loop) ────── */
footer.footer-night { position: relative; z-index: 5; }   /* above the setting sun */
.scene-fireflies {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}
.firefly {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--marigold, #E8A33D);
}
.firefly:nth-child(1) { left: 12%; top: 30%; }
.firefly:nth-child(2) { left: 31%; top: 62%; }
.firefly:nth-child(3) { left: 54%; top: 22%; }
.firefly:nth-child(4) { left: 72%; top: 55%; }
.firefly:nth-child(5) { left: 88%; top: 34%; }

/* ─── FOOTER WAVES in flat pigment ─────────────────────────── */
.footer-wave-3d .wave-svg-root { filter: none; }
.footer-wave-3d .w-layer-deep,
.footer-wave-3d .w-layer-mid { opacity: 1; }
.footer-wave-3d .w-layer-deep  path:first-child { fill: #5B9792; }
.footer-wave-3d .w-layer-mid   path:first-child { fill: #1B3A6B; }
.footer-wave-3d .w-layer-front path:first-child { fill: #0E2244; }
.footer-wave-3d .w-layer-deep  path:last-child  { stroke: #1F1A17; stroke-width: 1; vector-effect: non-scaling-stroke; }
.footer-wave-3d .w-layer-mid   path:last-child  { stroke: #2A9D9D; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.footer-wave-3d .w-layer-front path:last-child  { stroke: #E8A33D; stroke-width: 1.5; vector-effect: non-scaling-stroke; }

/* ─── MOTION — only when the reader allows it ──────────────── */
@media (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: scroll()) {
        .v-wheel-art  { animation: vTurn  linear both; animation-timeline: scroll(root); }

        .pk-f {
            animation: pkOpen linear both;
            animation-timeline: --work;
            animation-range: entry 5% cover 40%;
        }
        .v-scene-flute svg {
            animation: vRise linear both;
            animation-timeline: view();
            animation-range: entry 10% cover 50%;
        }
        .fp { animation: fpIn linear both; animation-timeline: --steps; }
        .fp:nth-of-type(1) { animation-range: entry 40% entry 60%; }
        .fp:nth-of-type(2) { animation-range: entry 55% entry 75%; }
        .fp:nth-of-type(3) { animation-range: entry 70% entry 90%; }
        .fp:nth-of-type(4) { animation-range: entry 85% cover 55%; }
        .fp:nth-of-type(5) { animation-range: cover 50% cover 60%; }
        .fp:nth-of-type(6) { animation-range: cover 55% cover 65%; }
        .fp:nth-of-type(7) { animation-range: cover 60% cover 70%; }
    }

    /* The Yamuna flows: each row slides one scallop (60 units) and loops seamlessly,
       back and front rows one way, the middle row the other. Fish leap in turn. */
    .yw-1 { animation: ywLeft 9s linear infinite; }
    .yw-2 { animation: ywRight 7s linear infinite; }
    .yw-3 { animation: ywLeft 5.5s linear infinite; }
    .yf   { animation: leap 6s var(--ease) infinite; }
    .yf-2 { animation-duration: 7s;   animation-delay: -2.4s; }
    .yf-3 { animation-duration: 5.4s; animation-delay: -3.1s; }
    .yf-4 { animation-duration: 6.5s; animation-delay: -1.3s; }
    .yf-5 { animation-duration: 7.5s; animation-delay: -5.2s; }
    .yf-6 { animation-duration: 6.8s; animation-delay: -3.4s; }

    .firefly { animation: ffDrift 20s var(--ease) infinite alternate; }
    .firefly:nth-child(2) { animation-duration: 23s; animation-delay: -6s; }
    .firefly:nth-child(3) { animation-duration: 19s; animation-delay: -11s; }
    .firefly:nth-child(4) { animation-duration: 25s; animation-delay: -3s; }
    .firefly:nth-child(5) { animation-duration: 21s; animation-delay: -15s; }

    .v-pot svg:hover { animation: potRock 900ms var(--ease); }
}

@keyframes ywLeft  { 0% { transform: translate(0, 0); } 50% { transform: translate(-30px, 2.5px); } 100% { transform: translate(-60px, 0); } }
@keyframes ywRight { 0% { transform: translate(0, 0); } 50% { transform: translate(30px, -2.5px); } 100% { transform: translate(60px, 0); } }
@keyframes leap {
    0%   { transform: translate(0, 70px)     rotate(-55deg); }
    6%   { transform: translate(16px, -4px)  rotate(-42deg); }
    12%  { transform: translate(40px, -62px) rotate(-14deg); }
    17%  { transform: translate(60px, -76px) rotate(8deg); }
    23%  { transform: translate(82px, -40px) rotate(35deg); }
    30%, 100% { transform: translate(100px, 60px) rotate(62deg); }
}
@keyframes vTurn  { to { transform: rotate(360deg); } }
@keyframes pkOpen { from { transform: rotate(calc(var(--a) * 0.04)); } }   /* folded upright, fans out to both sides */
@keyframes vRise  { from { opacity: 0; transform: translateY(24px); } }
@keyframes fpIn   { from { opacity: 0; } }
@keyframes ffDrift {
    0%   { transform: translate(0, 0);       opacity: .35; }
    30%  { transform: translate(28px, -18px); opacity: 1; }
    60%  { transform: translate(-14px, -34px); opacity: .6; }
    100% { transform: translate(22px, 10px);  opacity: 1; }
}
@keyframes potRock {
    0%, 100% { transform: rotate(0); }
    30% { transform: rotate(-4deg); }
    65% { transform: rotate(2.5deg); }
}

@media print {
    .v-yamuna, .v-wheel, .v-peacock, .scene-fireflies { display: none; }
}

/* ─── 5 · CASE STUDIES — the monsoon clearing ──────────────────
   Moved here from the retired /writing/: these are the reading
   pages. Flat indigo clouds hang over the header and part as you
   read; one fine line of rain falls. Finished state: parted. */
.v-monsoon {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: clamp(112px, 15vh, 160px);
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}
.v-monsoon ~ main .cs-header { padding-top: clamp(36px, 6vh, 72px); }
.v-cloud { position: absolute; top: 0; height: 100%; width: auto; }
.v-cloud-l { left: 0;  transform: translateX(-62%); }
.v-cloud-r { right: 0; transform: translateX(62%); }
.v-rain { position: absolute; left: 50%; top: 40%; width: 2px; height: 0; }
main#main { position: relative; z-index: 1; }

@media (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: scroll()) {
        .v-cloud-l { animation: cloudL linear both; animation-timeline: scroll(root); animation-range: 0 420px; }
        .v-cloud-r { animation: cloudR linear both; animation-timeline: scroll(root); animation-range: 0 420px; }
        .v-rain    { height: 60%; animation: rain linear both; animation-timeline: scroll(root); animation-range: 40px 380px; }
    }
}
@keyframes cloudL { from { transform: translateX(8%); }  to { transform: translateX(-62%); } }
@keyframes cloudR { from { transform: translateX(-8%); } to { transform: translateX(62%); } }
@keyframes rain   { 0% { transform: scaleY(0); transform-origin: top; } 60% { transform: scaleY(1); opacity: 1; } 100% { transform: scaleY(1); opacity: 0; } }

/* ─── WORK CARDS — a deck being dealt ───────────────────────────
   The grid pins in place; as you scroll, each card flies in from the
   right and lands on the pile, the ones beneath settle back a little.
   Scroll up and the cards lift off to the right again (js/motion.js).
   Without JS, or with reduced motion, the cards stay a plain list. */
#work { overflow-x: clip; }
#work .work-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    max-width: 780px;
    margin-inline: auto;
}
#work-grid.deck { display: block; height: calc(var(--n, 6) * 62svh + 100svh); }
#work-grid.deck .deck-stage {
    position: sticky;
    top: 84px;
    height: calc(100svh - 104px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
/* Every card shares one cell (so all are the height of the tallest); the ones
   beneath step up and narrow, so each layer shows its top edge — a real pile. */
#work-grid.deck .deck-pile { display: grid; width: 100%; padding-top: 64px; }
#work-grid.deck .work-card {
    grid-area: 1 / 1;
    width: 100%;
    background: #FAF4EA;
    will-change: transform;
    transform-origin: 50% 0;
    box-shadow: 0 1px 0 rgba(31, 26, 23, 0.05), 0 14px 28px -18px rgba(31, 26, 23, 0.35);
}
/* The peacock stands above the pile on every screen and opens its tail as
   the cards are dealt (--open from js/motion.js). */
#work-grid.deck .v-peacock {
    position: relative;
    top: auto;
    right: auto;
    display: block;
    width: clamp(280px, 80vw, 440px);
    max-width: min(90vw, 58svh);
    margin-bottom: 0;
    z-index: 0;
}
#work-grid.deck .pk-f {
    animation: none !important;
    transform: rotate(calc(var(--a) * (0.04 + 0.96 * var(--open, 1))));
}
#work-grid.deck .work-card:hover { transform: none; }
@media (max-width: 640px) {
    #work-grid.deck .deck-stage { top: 76px; height: calc(100svh - 88px); }
    #work-grid.deck .deck-pile { padding-top: 52px; }
}

.work-case-links {
    max-width: 780px;
    margin: 40px auto 0;
    font-family: var(--ui);
    font-size: 13px;
    letter-spacing: 0.06em;
    color: var(--text-soft, #5A4E44);
}
.work-case-links a { color: var(--art-a, #B33A2B); text-decoration: none; border-bottom: 1px solid currentColor; }

/* ─── THE SUN ON THE HORIZON — rises above the river as you reach the end ───
   --rise (0 → 1) comes from js/horizon.js: 0 = set behind the wave, 1 = clear
   of it. Without JS, or with reduced motion, the sun simply stands risen. */
.marigold-bloom.v-horizon {
    --rise: 1;
    position: relative;
    z-index: 4;                       /* the wave (z 5) hides the sun while it is down */
    display: flex;
    justify-content: center;
    padding: 32px 0 0;
    margin-bottom: 2px;
}
.marigold-bloom.v-horizon svg {
    width: 56px;
    height: 56px;
    opacity: 1;
    animation: none;
    transition: none;
    transform: translateY(calc((1 - var(--rise)) * 118px)) rotate(calc((1 - var(--rise)) * -60deg));
}
@media (max-width: 640px) {
    .marigold-bloom.v-horizon { padding-top: 24px; margin-bottom: 0; }
    .marigold-bloom.v-horizon svg { width: 44px; height: 44px; transform: translateY(calc((1 - var(--rise)) * 96px)) rotate(calc((1 - var(--rise)) * -60deg)); }
}


/* Leave room for the full card beneath the larger bird on short laptops. */
@media (min-width: 769px) and (max-height: 800px) {
    #work-grid.deck .deck-pile { padding-top: 40px; }
}
@media (min-width: 769px) and (max-height: 740px) {
    #work-grid.deck .v-peacock { max-width: 50svh; }
}
