/* ===================================================
   bability.pro — Blobitecture Tutorial Experience
   Terracotta-warm palette / Broken-grid / Organic blobs
   =================================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-surface: #C1694F;
    --secondary-surface: #D4A574;
    --background: #F5E6D0;
    --dark-accent: #3D2B1F;
    --text-body: #5C3D2E;
    --highlight-code: #8B6914;
    --intersection: #7A3B2E;
    --sage-mist: #A8B5A0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Fira Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    line-height: 1.65;
    color: var(--text-body);
    background-color: var(--background);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* --- Floating Navigation Blob --- */
#nav-blob {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    background: var(--primary-surface);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: default;
    box-shadow: 0 4px 20px rgba(61, 43, 31, 0.2);
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

#nav-blob:hover {
    transform: scale(1.1);
}

#nav-blob-text {
    font-family: 'Fira Code', monospace;
    font-size: 0.5rem;
    color: var(--background);
    text-transform: lowercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* --- Particle Canvas --- */
#particle-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 998;
}

/* --- SVG Annotation Lines --- */
#annotation-lines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 5;
}

/* --- Stages --- */
.stage {
    position: relative;
    min-height: 120vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stage-inner {
    position: relative;
    width: 100%;
    max-width: 1400px;
    min-height: 100vh;
    margin: 0 auto;
    padding: 5vh 40px;
}

/* --- Typography --- */
.stage-heading {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4.5rem);
    letter-spacing: -0.02em;
    line-height: 1.05;
    color: var(--dark-accent);
    margin-bottom: 0.5em;
}

.blob-text {
    font-family: 'Fira Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    line-height: 1.65;
    color: var(--text-body);
}

.blob-text strong {
    font-weight: 500;
    color: var(--dark-accent);
}

.blob-text code {
    font-family: 'Fira Code', monospace;
    font-size: 0.85em;
    color: var(--highlight-code);
    background: rgba(245, 230, 208, 0.5);
    padding: 0.1em 0.3em;
    border-radius: 3px;
}

.blob-code {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--highlight-code);
    display: block;
}

/* --- Blob Base --- */
.blob {
    position: relative;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    mix-blend-mode: multiply;
}

.blob.visible {
    opacity: 1;
    transform: scale(1);
}

.blob-inner {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.blob-content {
    padding: 10%;
    position: relative;
    z-index: 2;
}

/* --- Annotations --- */
.annotation {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.6s ease 0.3s, transform 0.6s ease 0.3s;
}

.annotation.visible {
    opacity: 1;
    transform: translateY(0);
}

.annotation-panel {
    background: rgba(245, 230, 208, 0.85);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid rgba(212, 165, 116, 0.3);
    backdrop-filter: blur(4px);
    max-width: 320px;
}

.annotation-code {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--highlight-code);
    display: block;
    white-space: pre-wrap;
}

.code-prop {
    color: var(--text-body);
}

.code-val {
    color: var(--highlight-code);
}

/* ===================================================
   STAGE 1: SEED
   =================================================== */
#stage-seed {
    min-height: 120vh;
}

#stage-seed .stage-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120vh;
}

.seed-blob {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: radial-gradient(ellipse at 30% 40%, #D4A574, #C1694F);
    animation: seedPulse 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    mix-blend-mode: normal;
    transition: border-radius 1.2s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.8s ease, transform 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.seed-blob.morphed {
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
}

@keyframes seedPulse {
    0%, 100% { transform: scale(0.95); }
    50% { transform: scale(1.05); }
}

.seed-heading {
    margin-top: 30px;
    text-align: center;
}

.annotation-seed {
    position: absolute;
    right: 15%;
    top: 50%;
    transform: translateY(-50%);
}

.annotation-seed.visible {
    transform: translateY(-50%);
}

/* ===================================================
   STAGE 2: BUDDING
   =================================================== */
#stage-budding {
    min-height: 120vh;
}

.budding-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(12, 1fr);
    min-height: 100vh;
    gap: 0;
}

.budding-parent-blob {
    grid-column: 2 / 8;
    grid-row: 2 / 10;
    clip-path: ellipse(48% 44% at 50% 50%);
    background: radial-gradient(ellipse at 30% 40%, #D4A574, #C1694F);
    min-height: 400px;
    mix-blend-mode: normal;
}

.budding-child-blob {
    grid-column: 6 / 11;
    grid-row: 5 / 11;
    clip-path: ellipse(45% 42% at 52% 48%);
    background: radial-gradient(ellipse at 35% 35%, #D4A574, #C1694F);
    min-height: 300px;
    z-index: 2;
    mix-blend-mode: multiply;
}

.annotation-budding-1 {
    grid-column: 9 / 12;
    grid-row: 2 / 4;
    align-self: center;
}

.annotation-budding-2 {
    grid-column: 9 / 12;
    grid-row: 6 / 8;
    align-self: center;
}

.annotation-budding-3 {
    grid-column: 1 / 3;
    grid-row: 8 / 10;
    align-self: center;
}

/* Warm background bloom for budding stage */
#stage-budding::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80vw;
    height: 80vh;
    background: radial-gradient(ellipse at center, rgba(212, 165, 116, 0.05) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* ===================================================
   STAGE 3: BRANCHING
   =================================================== */
#stage-branching {
    min-height: 140vh;
}

.branching-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(14, 1fr);
    min-height: 120vh;
    gap: 0;
}

.branch-blob {
    mix-blend-mode: normal;
    min-height: 200px;
}

.branch-blob-1 {
    grid-column: 1 / 7;
    grid-row: 1 / 6;
    clip-path: polygon(5% 15%, 25% 2%, 65% 0%, 90% 20%, 95% 60%, 78% 95%, 40% 100%, 8% 80%);
    background: radial-gradient(ellipse at 30% 40%, #D4A574, #C1694F);
    z-index: 3;
}

.branch-blob-2 {
    grid-column: 5 / 11;
    grid-row: 3 / 8;
    clip-path: ellipse(46% 44% at 55% 48%);
    background: radial-gradient(ellipse at 40% 35%, #D4A574, #C1694F);
    z-index: 2;
    mix-blend-mode: multiply;
}

.branch-blob-3 {
    grid-column: 2 / 7;
    grid-row: 6 / 11;
    clip-path: ellipse(48% 46% at 45% 52%);
    background: radial-gradient(ellipse at 35% 40%, #D4A574, #C1694F);
    z-index: 4;
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
}

.branch-blob-4 {
    grid-column: 7 / 12;
    grid-row: 7 / 12;
    clip-path: polygon(10% 5%, 55% 0%, 95% 15%, 100% 55%, 85% 90%, 45% 100%, 5% 85%, 0% 40%);
    background: radial-gradient(ellipse at 50% 45%, #D4A574, #C1694F);
    z-index: 3;
    mix-blend-mode: multiply;
}

.branch-blob-5 {
    grid-column: 4 / 10;
    grid-row: 10 / 15;
    clip-path: ellipse(44% 40% at 48% 50%);
    background: radial-gradient(ellipse at 30% 30%, #D4A574, #C1694F);
    z-index: 5;
}

.annotation-branch-1 {
    grid-column: 8 / 12;
    grid-row: 1 / 3;
    align-self: center;
    z-index: 10;
}

.annotation-branch-2 {
    grid-column: 9 / 12;
    grid-row: 8 / 10;
    align-self: center;
    z-index: 10;
}

.annotation-branch-3 {
    grid-column: 1 / 4;
    grid-row: 12 / 14;
    align-self: center;
    z-index: 10;
}

/* ===================================================
   CROSS-SECTION TRANSITION
   =================================================== */
.cross-section-stage {
    min-height: 40vh;
    overflow: hidden;
}

.cross-section-container {
    position: relative;
    width: 100%;
    height: 40vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cross-ring {
    position: absolute;
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.5s ease, transform 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.cross-ring.visible {
    opacity: 1;
    transform: scale(1);
}

.cross-ring-1 {
    width: 500px; height: 280px;
    background: #C1694F;
    border-radius: 50%;
    transition-delay: 0ms;
}
.cross-ring-2 {
    width: 440px; height: 245px;
    background: #D4A574;
    border-radius: 50%;
    transition-delay: 50ms;
}
.cross-ring-3 {
    width: 380px; height: 210px;
    background: #C1694F;
    border-radius: 50%;
    transition-delay: 100ms;
}
.cross-ring-4 {
    width: 320px; height: 175px;
    background: #D4A574;
    border-radius: 50%;
    transition-delay: 150ms;
}
.cross-ring-5 {
    width: 260px; height: 140px;
    background: #C1694F;
    border-radius: 50%;
    transition-delay: 200ms;
}
.cross-ring-6 {
    width: 200px; height: 108px;
    background: #D4A574;
    border-radius: 50%;
    transition-delay: 250ms;
}
.cross-ring-7 {
    width: 140px; height: 76px;
    background: #C1694F;
    border-radius: 50%;
    transition-delay: 300ms;
}
.cross-ring-8 {
    width: 80px; height: 44px;
    background: #D4A574;
    border-radius: 50%;
    transition-delay: 350ms;
}

/* ===================================================
   STAGE 4: MATURATION
   =================================================== */
#stage-maturation {
    min-height: 130vh;
}

.maturation-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(12, 1fr);
    min-height: 110vh;
    gap: 0;
}

.mature-compound-blob {
    grid-column: 1 / 8;
    grid-row: 1 / 7;
    clip-path: path('M 10 80 Q 30 10 120 20 Q 250 0 350 50 Q 420 100 380 200 Q 340 280 220 290 Q 100 300 40 240 Q 0 180 10 80 Z');
    background: radial-gradient(ellipse at 35% 40%, #D4A574, #C1694F);
    min-height: 350px;
    z-index: 3;
    mix-blend-mode: normal;
}

.mature-merge-blob-1 {
    grid-column: 3 / 7;
    grid-row: 4 / 8;
    clip-path: ellipse(48% 46% at 50% 50%);
    background: radial-gradient(ellipse at 40% 35%, #D4A574, #C1694F);
    min-height: 200px;
    z-index: 2;
    mix-blend-mode: normal;
}

.mature-merge-blob-2 {
    grid-column: 5 / 9;
    grid-row: 5 / 9;
    clip-path: ellipse(44% 48% at 48% 52%);
    background: radial-gradient(ellipse at 35% 40%, #D4A574, #C1694F);
    min-height: 200px;
    z-index: 2;
    mix-blend-mode: multiply;
}

.mature-math-blob {
    grid-column: 6 / 12;
    grid-row: 2 / 7;
    clip-path: polygon(8% 10%, 40% 0%, 85% 5%, 100% 35%, 95% 75%, 60% 100%, 15% 90%, 0% 50%);
    background: radial-gradient(ellipse at 30% 40%, #D4A574, #C1694F);
    min-height: 300px;
    z-index: 4;
    mix-blend-mode: normal;
}

.mature-code-blob {
    grid-column: 2 / 8;
    grid-row: 8 / 13;
    clip-path: ellipse(46% 44% at 52% 50%);
    background: radial-gradient(ellipse at 35% 35%, #D4A574, #C1694F);
    min-height: 300px;
    z-index: 3;
    mix-blend-mode: normal;
}

.annotation-mature-1 {
    grid-column: 9 / 12;
    grid-row: 7 / 9;
    align-self: center;
    z-index: 10;
}

.annotation-mature-2 {
    grid-column: 9 / 12;
    grid-row: 10 / 12;
    align-self: center;
    z-index: 10;
}

/* ===================================================
   STAGE 5: ECOSYSTEM
   =================================================== */
#stage-ecosystem {
    min-height: 140vh;
}

.ecosystem-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(16, 1fr);
    min-height: 130vh;
    gap: 0;
}

.eco-blob {
    min-height: 120px;
    mix-blend-mode: normal;
}

.eco-blob-1 {
    grid-column: 1 / 6;
    grid-row: 1 / 4;
    clip-path: ellipse(48% 44% at 50% 50%);
    background: radial-gradient(ellipse at 30% 40%, #D4A574, #C1694F);
    z-index: 3;
}

.eco-blob-2 {
    grid-column: 4 / 10;
    grid-row: 2 / 6;
    clip-path: polygon(5% 12%, 30% 0%, 75% 3%, 95% 22%, 100% 60%, 82% 95%, 35% 100%, 8% 78%);
    background: radial-gradient(ellipse at 35% 35%, #D4A574, #C1694F);
    z-index: 4;
    min-height: 200px;
}

.eco-blob-3 {
    grid-column: 8 / 12;
    grid-row: 1 / 4;
    clip-path: ellipse(44% 46% at 52% 48%);
    background: radial-gradient(ellipse at 40% 30%, #D4A574, #C1694F);
    z-index: 2;
}

.eco-blob-4 {
    grid-column: 1 / 4;
    grid-row: 4 / 7;
    clip-path: ellipse(46% 44% at 48% 52%);
    background: radial-gradient(ellipse at 35% 40%, var(--secondary-surface), var(--primary-surface));
    z-index: 2;
}

.eco-blob-5 {
    grid-column: 3 / 8;
    grid-row: 5 / 9;
    clip-path: polygon(10% 8%, 50% 0%, 92% 12%, 100% 48%, 88% 88%, 45% 100%, 5% 82%, 0% 40%);
    background: radial-gradient(ellipse at 30% 40%, #D4A574, #C1694F);
    z-index: 5;
    min-height: 180px;
    mix-blend-mode: multiply;
}

.eco-blob-6 {
    grid-column: 9 / 13;
    grid-row: 4 / 8;
    clip-path: ellipse(44% 42% at 50% 50%);
    background: radial-gradient(ellipse at 40% 35%, var(--secondary-surface), var(--primary-surface));
    z-index: 3;
}

.eco-blob-7 {
    grid-column: 6 / 11;
    grid-row: 7 / 11;
    clip-path: polygon(8% 5%, 45% 0%, 90% 8%, 100% 42%, 92% 82%, 50% 100%, 10% 88%, 0% 45%);
    background: radial-gradient(ellipse at 35% 40%, #D4A574, #C1694F);
    z-index: 4;
    min-height: 200px;
}

.eco-blob-8 {
    grid-column: 1 / 5;
    grid-row: 8 / 11;
    clip-path: ellipse(46% 48% at 48% 50%);
    background: radial-gradient(ellipse at 30% 35%, var(--secondary-surface), var(--primary-surface));
    z-index: 2;
}

.eco-blob-9 {
    grid-column: 3 / 9;
    grid-row: 10 / 14;
    clip-path: ellipse(48% 44% at 52% 48%);
    background: radial-gradient(ellipse at 35% 40%, #D4A574, #C1694F);
    z-index: 5;
    min-height: 180px;
}

.eco-blob-10 {
    grid-column: 9 / 13;
    grid-row: 9 / 12;
    clip-path: polygon(12% 8%, 55% 0%, 95% 15%, 100% 50%, 85% 90%, 40% 100%, 5% 80%, 0% 35%);
    background: radial-gradient(ellipse at 40% 40%, var(--secondary-surface), var(--primary-surface));
    z-index: 3;
}

.eco-blob-11 {
    grid-column: 2 / 8;
    grid-row: 13 / 17;
    clip-path: polygon(5% 10%, 35% 0%, 80% 5%, 100% 30%, 95% 70%, 65% 100%, 15% 95%, 0% 55%);
    background: radial-gradient(ellipse at 30% 40%, #D4A574, #C1694F);
    z-index: 4;
    min-height: 250px;
}

.eco-blob-12 {
    grid-column: 8 / 12;
    grid-row: 12 / 16;
    clip-path: ellipse(44% 46% at 50% 48%);
    background: radial-gradient(ellipse at 35% 35%, var(--sage-mist), rgba(168, 181, 160, 0.6));
    z-index: 2;
}

.eco-final-text {
    font-size: clamp(1rem, 1.3vw, 1.15rem);
    font-weight: 500;
    line-height: 1.7;
    color: var(--dark-accent);
}

.annotation-eco-1 {
    grid-column: 10 / 13;
    grid-row: 5 / 7;
    align-self: center;
    z-index: 10;
}

.annotation-eco-2 {
    grid-column: 1 / 4;
    grid-row: 7 / 9;
    align-self: center;
    z-index: 10;
}

.annotation-eco-3 {
    grid-column: 9 / 12;
    grid-row: 13 / 15;
    align-self: center;
    z-index: 10;
}

/* ===================================================
   ANIMATIONS
   =================================================== */
@keyframes elasticEnter {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    60% {
        opacity: 1;
        transform: scale(1.03);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* SVG annotation line draw animation */
.annotation-line {
    stroke: #D4A574;
    stroke-opacity: 0.5;
    stroke-width: 1.5;
    fill: none;
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 0.8s ease;
}

.annotation-line.drawn {
    stroke-dashoffset: 0;
}

/* ===================================================
   RESPONSIVE
   =================================================== */
@media (max-width: 768px) {
    .stage-inner {
        padding: 5vh 20px;
    }

    .budding-grid,
    .branching-grid,
    .maturation-grid,
    .ecosystem-grid {
        display: flex;
        flex-direction: column;
        gap: 20px;
    }

    .blob {
        min-height: 200px !important;
    }

    .annotation {
        position: relative !important;
        right: auto !important;
        top: auto !important;
        margin: 10px auto;
    }

    .annotation-panel {
        max-width: 100%;
    }

    .annotation-seed {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        margin-top: 20px;
    }

    .annotation-seed.visible {
        transform: none;
    }

    .cross-ring-1 { width: 300px; height: 170px; }
    .cross-ring-2 { width: 264px; height: 148px; }
    .cross-ring-3 { width: 228px; height: 126px; }
    .cross-ring-4 { width: 192px; height: 106px; }
    .cross-ring-5 { width: 156px; height: 84px; }
    .cross-ring-6 { width: 120px; height: 65px; }
    .cross-ring-7 { width: 84px; height: 46px; }
    .cross-ring-8 { width: 48px; height: 26px; }
}
