/*
   The story page (Views/Home/Story.cshtml): the character tells Cocorra's story in speech bubbles.
   Motion, all CSS:
   - on load: the opening rises in and she pops up, then floats;
   - small loops: hearts, rain cloud, thought bubbles, voice wave, room rings, typing dots, pointing sway;
   - scroll-driven (only where animation-timeline is supported): each scene's face pops in, "typing…" shows, then
     the bubble grows from its tail; the born sentence lights up word by word; tiles flip; lines draw.
   Base styles are the final state, so without support (or with reduced motion) every scene simply shows.
*/

/* ---------- layout ---------- */
.story-opening { display: flex; flex-wrap: wrap; align-items: center; gap: 40px; padding-block: 48px 80px; }
.story-opening > div:first-child { flex: 1 1 460px; min-width: 0; }
.story-opening h1 { font-size: clamp(2.6rem, 3.5vw + 1rem, 4rem); line-height: 1.2; margin-block-end: 20px; }
.story-opening-art { flex: 0 1 360px; position: relative; margin-inline: auto; }

.scene { padding-block: 88px; }
.scene-white { background: var(--white); }
.scene-sage { background: var(--sage); color: var(--forest-deep); text-align: center; padding-block: 104px; }
.scene-forest { background: var(--forest); color: var(--on-forest); padding-block: 96px; }
.scene-row { display: flex; flex-wrap: wrap; align-items: center; gap: 32px 56px; max-width: 1000px; }
.scene-row-reverse { flex-direction: row-reverse; }
.scene-face { flex: 0 0 260px; position: relative; margin-inline: auto; }
.scene-face-wide { flex-basis: 320px; display: flex; justify-content: center; }
.face-scene { width: 260px; height: 260px; }
.scene-text { flex: 1 1 420px; min-width: 0; }
.scene-label { font-size: 0.95rem; font-weight: 600; color: var(--muted); margin-block-end: 12px; }
.scene-sage .scene-label { color: var(--forest-deep); }
.scene-forest .scene-label { color: var(--on-forest-soft); }

/* bubbles: the tail (the small corner) points at her face */
.bubble-wrap { position: relative; }
.bubble { margin: 0; padding: 28px 32px; background: var(--cream); border-radius: 32px; font-size: 1.35rem; line-height: 1.9; }
.bubble.on-cream { background: var(--white); }
.bubble-start { border-end-start-radius: 8px; }
.bubble-end { border-end-end-radius: 8px; }
.typing {
    position: absolute; bottom: 0; display: flex; gap: 6px; padding: 14px 18px; border-radius: 20px;
    background: var(--cream); opacity: 0;
}
.typing.on-cream { background: var(--white); }
.typing-start { inset-inline-start: 0; border-end-start-radius: 4px; }
.typing-end { inset-inline-end: 0; border-end-end-radius: 4px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--sage-deep); }

.scene-tag { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; margin: 18px 8px 0; font-size: 1rem; font-weight: 600; color: var(--muted); }

/* scene extras */
.cloud { position: absolute; top: -46px; inset-inline-start: 50%; width: 100px; margin-inline-start: -50px; }
.cloud svg { width: 100px; height: 50px; fill: #B9BFB4; }
.cloud { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 18px; }
.drop { width: 3px; height: 10px; border-radius: 2px; background: #8FA3B0; margin-top: -4px; }

.thought { position: absolute; border-radius: 50%; background: var(--white); border: 2px solid var(--sand); }
.thought-1 { top: 10px; inset-inline-start: -6px; width: 12px; height: 12px; }
.thought-2 { top: -16px; inset-inline-start: -28px; width: 20px; height: 20px; }
.thought-3 { top: -58px; inset-inline-start: -64px; width: 44px; height: 34px; display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--forest); }

.born-line { font-family: var(--font-head); font-weight: 500; font-size: clamp(1.9rem, 2.5vw + 1rem, 3rem); line-height: 1.4; color: var(--forest-deep); }
.born-heart { width: 44px; height: 44px; fill: var(--forest); margin: 24px auto 0; }

.wave { display: inline-flex; align-items: center; gap: 4px; height: 30px; }
.wave span { width: 5px; height: 30px; border-radius: 3px; background: var(--sage-deep); }
.check { width: 30px; height: 30px; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.check circle { stroke: var(--blush); }
.check path { stroke: var(--clay-deep); }

.ring { position: absolute; top: 50%; left: 50%; width: 300px; height: 300px; margin: -150px 0 0 -150px; border-radius: 50%; border: 3px solid var(--sage); }
.ring-late { border-color: var(--clay); }
.sitting { position: relative; width: 300px; }

.tiles { display: inline-flex; gap: 6px; perspective: 400px; }
.tiles span {
    width: 40px; height: 48px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
    font-family: var(--font-head); font-weight: 700; font-size: 1.5rem; background: var(--forest); color: var(--on-forest);
}
.tiles span:nth-child(2) { background: var(--sage-deep); color: var(--white); }
.tiles span:nth-child(3) { background: var(--clay-deep); color: var(--white); }

.team-line { font-family: var(--font-head); font-weight: 500; font-size: clamp(1.6rem, 1.6vw + 1rem, 2.5rem); line-height: 1.45; margin-block-end: 40px; color: var(--on-forest); }
.story-roles { display: flex; flex-wrap: wrap; gap: 32px 64px; }
.story-roles li { flex: 1 1 320px; min-width: 0; }
.story-roles h2 { font-size: 1.6rem; margin-block-end: 6px; color: var(--on-forest); }
.story-roles p { color: var(--on-forest-soft); }
.draw { display: block; height: 2px; background: var(--sage); margin-block-end: 16px; }

.scene-next p:last-child { font-size: 1.35rem; line-height: 1.9; }

.story-ending { display: flex; flex-wrap: wrap; align-items: center; gap: 40px; }
.story-ending > div:last-child { flex: 1 1 480px; min-width: 0; }
.story-ending h2 { font-size: clamp(2.2rem, 2.5vw + 1rem, 3.5rem); line-height: 1.3; margin-block-end: 16px; }
.story-ending .lead { margin-block-end: 32px; }
.slide { flex: 0 1 340px; margin-inline: auto; }
.pointing { width: 340px; }
/* The art points right; on RTL pages the text sits to her left, so mirror her. */
[dir="rtl"] .pointing { transform: scaleX(-1); }

.heart-up { position: absolute; width: 24px; height: 24px; fill: var(--clay); }
.heart-a { top: 30%; inset-inline-end: 4%; }
.heart-b { top: 40%; inset-inline-start: 6%; width: 18px; height: 18px; fill: var(--sage); }
.heart-c { top: 18%; inset-inline-start: 22%; width: 22px; height: 22px; }
.heart-d { top: 20px; inset-inline-end: 6px; }
.heart-e { top: 40px; inset-inline-start: 0; width: 18px; height: 18px; fill: var(--sage-deep); }

.story-progress { position: sticky; top: 0; z-index: 30; height: 4px; margin-block-end: -4px; display: none; }
.story-progress div { height: 4px; background: var(--clay-deep); }

/* ---------- keyframes ---------- */
@keyframes rise { from { opacity: 0; translate: 0 28px; } to { opacity: 1; translate: 0 0; } }
@keyframes popin { 0% { opacity: 0; scale: .6; } 70% { opacity: 1; scale: 1.06; } 100% { opacity: 1; scale: 1; } }
@keyframes bubble { 0% { opacity: 0; scale: .5; } 70% { opacity: 1; scale: 1.03; } 100% { opacity: 1; scale: 1; } }
@keyframes typing { 0% { opacity: 0; } 15% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes dot { 0%, 60%, 100% { translate: 0 0; opacity: .45; } 30% { translate: 0 -6px; opacity: 1; } }
@keyframes float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -12px; } }
@keyframes heartup { 0% { opacity: 0; translate: 0 0; scale: .5; } 20% { opacity: 1; } 100% { opacity: 0; translate: 0 -130px; scale: 1.1; } }
@keyframes drift { 0%, 100% { translate: -8px 0; } 50% { translate: 8px 0; } }
@keyframes rain { 0% { opacity: 0; translate: 0 -4px; } 30% { opacity: 1; } 100% { opacity: 0; translate: 0 26px; } }
@keyframes thought { 0% { opacity: 0; scale: .3; } 30% { opacity: 1; scale: 1; } 80% { opacity: 1; scale: 1; } 100% { opacity: 0; scale: 1; } }
@keyframes wave { 0%, 100% { scale: 1 .3; } 50% { scale: 1 1; } }
@keyframes ring { 0% { opacity: .7; scale: .7; } 100% { opacity: 0; scale: 1.3; } }
@keyframes lit { from { opacity: .2; } to { opacity: 1; } }
@keyframes draw { from { scale: 0 1; } to { scale: 1 1; } }
@keyframes flip { from { opacity: 0; rotate: y 90deg; } to { opacity: 1; rotate: y 0deg; } }
@keyframes slidein { 0% { opacity: 0; translate: var(--slide-from) 0; } 70% { opacity: 1; translate: calc(var(--slide-from) * -0.09) 0; } 100% { opacity: 1; translate: 0 0; } }
@keyframes wiggle { 0%, 100% { rotate: 0deg; } 50% { rotate: -3deg; } }
@keyframes check { from { stroke-dashoffset: 30; } to { stroke-dashoffset: 0; } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(163, 94, 72, .4); } 50% { box-shadow: 0 0 0 12px rgba(163, 94, 72, 0); } }
@keyframes progress { from { scale: 0 1; } to { scale: 1 1; } }

/* ---------- motion (only for people who have not asked for less) ---------- */
@media (prefers-reduced-motion: no-preference) {
    .intro-1 { animation: rise .7s ease-out .1s both; }
    .intro-2 { animation: rise .7s ease-out .3s both; }
    .intro-3 { animation: rise .7s ease-out .5s both; }
    .intro-img { animation: popin .9s cubic-bezier(.2, .9, .3, 1.2) .3s both, float 5s ease-in-out 1.3s infinite; }

    .heart-up { animation: heartup 4s ease-out infinite; }
    .heart-b, .heart-e { animation-delay: 1.4s; }
    .heart-c { animation-delay: 2.7s; }
    .cloud { animation: drift 6s ease-in-out infinite; }
    .drop { animation: rain 1.4s linear infinite; }
    .drop:nth-of-type(2) { animation-delay: .45s; }
    .drop:nth-of-type(3) { animation-delay: .9s; }
    .thought { animation: thought 3.2s ease-out infinite; }
    .thought-2 { animation-delay: .35s; }
    .thought-3 { animation-delay: .7s; }
    .wave span { animation: wave 1.1s ease-in-out infinite; }
    .wave span:nth-child(2) { animation-delay: .15s; }
    .wave span:nth-child(3) { animation-delay: .3s; }
    .wave span:nth-child(4) { animation-delay: .45s; }
    .wave span:nth-child(5) { animation-delay: .6s; }
    .wave span:nth-child(6) { animation-delay: .75s; }
    .ring { animation: ring 2.6s ease-out infinite; }
    .ring-late { animation-delay: 1.3s; }
    .typing span { animation: dot 1s ease-in-out infinite; }
    .typing span:nth-child(2) { animation-delay: .15s; }
    .typing span:nth-child(3) { animation-delay: .3s; }
    .wiggle { animation: wiggle 2.8s ease-in-out infinite; transform-origin: 50% 90%; }
    .story-ending .btn-store-primary { animation: glow 3s ease-in-out infinite; }

    @supports (animation-timeline: view()) {
        .scene { view-timeline: --scene block; }
        .face-in { animation: popin linear both; animation-timeline: --scene; animation-range: entry 15% cover 35%; }
        .typing { animation: typing linear both; animation-timeline: --scene; animation-range: cover 28% cover 42%; }
        .bubble { animation: bubble linear both; animation-timeline: --scene; animation-range: cover 38% cover 50%; }
        .bubble-start { transform-origin: 0 100%; }
        .bubble-end { transform-origin: 100% 100%; }
        [dir="rtl"] .bubble-start { transform-origin: 100% 100%; }
        [dir="rtl"] .bubble-end { transform-origin: 0 100%; }
        .tag-in { animation: rise linear both; animation-timeline: --scene; animation-range: cover 46% cover 56%; }
        .rise-s { animation: rise linear both; animation-timeline: --scene; animation-range: entry 20% cover 40%; }
        .pop-s { animation: popin linear both; animation-timeline: --scene; animation-range: cover 56% cover 64%; }
        .draw { transform-origin: 0 50%; animation: draw linear both; animation-timeline: --scene; animation-range: cover 30% cover 50%; }
        [dir="rtl"] .draw { transform-origin: 100% 50%; }
        .draw-late { animation-range: cover 38% cover 58%; }
        .check path { stroke-dasharray: 30; animation: check linear both; animation-timeline: --scene; animation-range: cover 48% cover 58%; }
        .slide { --slide-from: -90px; animation: slidein linear both; animation-timeline: --scene; animation-range: entry 10% cover 40%; }
        [dir="rtl"] .slide { --slide-from: 90px; }

        .w { animation: lit linear both; animation-timeline: --scene; }
        .w:nth-child(1) { animation-range: cover 20% cover 24%; }
        .w:nth-child(2) { animation-range: cover 23% cover 27%; }
        .w:nth-child(3) { animation-range: cover 26% cover 30%; }
        .w:nth-child(4) { animation-range: cover 29% cover 33%; }
        .w:nth-child(5) { animation-range: cover 32% cover 36%; }
        .w:nth-child(6) { animation-range: cover 35% cover 39%; }
        .w:nth-child(7) { animation-range: cover 38% cover 42%; }
        .w:nth-child(8) { animation-range: cover 41% cover 45%; }
        .w:nth-child(9) { animation-range: cover 44% cover 48%; }
        .w:nth-child(10) { animation-range: cover 47% cover 51%; }
        .w:nth-child(11) { animation-range: cover 50% cover 54%; }
        .w:nth-child(12) { animation-range: cover 53% cover 57%; }
        .w:nth-child(13) { animation-range: cover 55% cover 59%; }
        .w:nth-child(14) { animation-range: cover 57% cover 61%; }
        .w:nth-child(n+15) { animation-range: cover 59% cover 63%; }

        .flip { animation: flip linear both; animation-timeline: --scene; }
        .flip:nth-child(1) { animation-range: cover 46% cover 52%; }
        .flip:nth-child(2) { animation-range: cover 49% cover 55%; }
        .flip:nth-child(3) { animation-range: cover 52% cover 58%; }
        .flip:nth-child(4) { animation-range: cover 55% cover 61%; }

        .story-progress { display: block; }
        .story-progress div { transform-origin: 0 50%; animation: progress linear both; animation-timeline: scroll(root block); }
        [dir="rtl"] .story-progress div { transform-origin: 100% 50%; }
    }
}

@media (max-width: 599px) {
    .scene { padding-block: 64px; }
    .bubble { padding: 22px 24px; font-size: 1.2rem; }
    .thought-3 { inset-inline-start: -40px; }
}
