/* ==========================================================================
   GGIGGL.com - The Physics of Joy
   Colors: #0d0221, #f72585, #ff6d00, #c5f015, #7b2ff7, #fef9ef, #b8b8d1, #00f5d4
   Fonts: Baloo 2, Space Grotesk, Caveat
   ========================================================================== */

/* --- CSS Custom Properties --- */
:root {
    --midnight-giggle: #0d0221;
    --electric-fuchsia: #f72585;
    --neon-tangerine: #ff6d00;
    --acid-lemon: #c5f015;
    --hot-violet: #7b2ff7;
    --cream-fizz: #fef9ef;
    --giggle-gray: #b8b8d1;
    --mint-burst: #00f5d4;

    --font-primary: 'Baloo 2', cursive;
    --font-secondary: 'Space Grotesk', sans-serif;
    --font-accent: 'Caveat', cursive;

    --spring-ease: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --smooth-ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);

    --laugh-intensity: 0;
    --wobble-amplitude: 1;
    --bg-color-r: 13;
    --bg-color-g: 2;
    --bg-color-b: 33;
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--midnight-giggle);
    color: var(--cream-fizz);
    font-family: var(--font-secondary);
    overflow-x: hidden;
    cursor: default;
}

::selection {
    background: var(--electric-fuchsia);
    color: var(--cream-fizz);
}

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

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

/* --- Ripple Container --- */
#ripple-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    overflow: hidden;
}

.ripple {
    position: absolute;
    border-radius: 50%;
    border: 2px solid var(--neon-tangerine);
    opacity: 0.7;
    transform: scale(0);
    animation: ripple-expand 1.5s var(--spring-ease) forwards;
}

@keyframes ripple-expand {
    0% {
        transform: scale(0);
        opacity: 0.7;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* --- Navigation Pill --- */
.nav-pill {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    background: rgba(13, 2, 33, 0.6);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    padding: 8px 12px;
    opacity: 0.5;
    transition: opacity 0.4s var(--smooth-ease), transform 0.4s var(--spring-ease);
    cursor: pointer;
}

.nav-pill:hover {
    opacity: 1;
    transform: scale(1.05);
}

.nav-pill-inner {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

.nav-indicator {
    width: 30px;
    height: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--giggle-gray);
    transition: color 0.4s var(--smooth-ease), transform 0.3s var(--spring-ease);
    cursor: pointer;
}

.nav-indicator.active {
    color: var(--neon-tangerine);
    transform: scale(1.3);
}

.nav-indicator .squiggle {
    width: 100%;
    height: 100%;
}

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

.stage-bg-pattern {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.05;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Ctext x='10' y='30' font-size='12' fill='%23fef9ef' opacity='0.5' transform='rotate(-15 30 30)' font-family='sans-serif'%3Eha%3C/text%3E%3Ctext x='35' y='50' font-size='8' fill='%23fef9ef' opacity='0.3' transform='rotate(25 45 45)' font-family='sans-serif'%3Eha%3C/text%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* --- Stage 1: The Setup --- */
.stage-1 {
    background-color: var(--midnight-giggle);
}

.stage-1-content {
    text-align: center;
    z-index: 2;
}

.logotype {
    font-family: var(--font-primary);
    font-size: clamp(5rem, 15vw, 14rem);
    font-weight: 800;
    color: var(--cream-fizz);
    letter-spacing: 0.05em;
    line-height: 1;
    animation: logotype-breathe 3s ease-in-out infinite;
    text-shadow: 0 0 40px rgba(255, 109, 0, 0.3);
    transition: color 0.5s, text-shadow 0.5s;
}

.logotype:hover {
    color: var(--neon-tangerine);
    text-shadow: 0 0 80px rgba(255, 109, 0, 0.6), 0 0 120px rgba(247, 37, 133, 0.3);
}

@keyframes logotype-breathe {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

.tagline {
    font-family: var(--font-accent);
    font-size: clamp(1.2rem, 3vw, 2rem);
    color: var(--giggle-gray);
    margin-top: 1rem;
    opacity: 0;
    animation: tagline-fade 1.5s 0.5s var(--smooth-ease) forwards;
}

@keyframes tagline-fade {
    to {
        opacity: 1;
    }
}

/* --- Stage 2: The Tremor --- */
.stage-2 {
    background-color: var(--midnight-giggle);
}

.stage-2-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
    padding: 2rem;
    z-index: 2;
    width: 100%;
    max-width: 900px;
}

.tremor-block {
    padding: 2rem 3rem;
    border-radius: 30px;
    background: rgba(123, 47, 247, 0.08);
    border: 1px solid rgba(123, 47, 247, 0.15);
    transition: transform 0.5s var(--spring-ease), border-radius 0.5s var(--spring-ease);
    opacity: 0;
    transform: translateY(40px);
}

.tremor-block.visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.8s var(--smooth-ease), transform 0.8s var(--spring-ease);
}

.tremor-block-1 {
    align-self: flex-start;
    animation: wobble-gentle 3s ease-in-out infinite;
}

.tremor-block-2 {
    align-self: flex-end;
    transform: rotate(-2deg);
    animation: wobble-gentle 3.5s 0.5s ease-in-out infinite;
}

.tremor-block-3 {
    align-self: center;
    transform: rotate(1.5deg);
    animation: wobble-gentle 2.8s 1s ease-in-out infinite;
}

.tremor-block-2.visible {
    transform: translateY(0) rotate(-2deg);
}

.tremor-block-3.visible {
    transform: translateY(0) rotate(1.5deg);
}

@keyframes wobble-gentle {
    0%, 100% {
        transform: rotate(calc(-1deg * var(--wobble-amplitude, 1)));
    }
    50% {
        transform: rotate(calc(1deg * var(--wobble-amplitude, 1)));
    }
}

.tremor-headline {
    font-family: var(--font-primary);
    font-size: clamp(2rem, 5vw, 4rem);
    font-weight: 700;
    color: var(--neon-tangerine);
    line-height: 1.1;
}

.tremor-text {
    font-family: var(--font-secondary);
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--giggle-gray);
    margin-top: 0.5rem;
}

/* --- Stage 3: The Build --- */
.stage-3 {
    background-color: var(--midnight-giggle);
}

.stage-3-content {
    position: relative;
    width: 100%;
    height: 100vh;
    z-index: 2;
    overflow: hidden;
}

.build-fragment {
    position: absolute;
    opacity: 0;
    transition: opacity 0.6s, transform 0.8s var(--spring-ease);
}

.build-fragment.visible {
    opacity: 1;
}

.build-word {
    font-family: var(--font-primary);
    font-weight: 800;
    line-height: 1;
    display: block;
}

.build-fragment-1 {
    top: 10%;
    left: 15%;
    transform: rotate(-7deg) scale(0.5);
}
.build-fragment-1 .build-word {
    font-size: clamp(4rem, 10vw, 8rem);
    color: var(--electric-fuchsia);
}
.build-fragment-1.visible {
    transform: rotate(-7deg) scale(1);
}

.build-fragment-2 {
    top: 25%;
    right: 10%;
    transform: rotate(5deg) scale(0.5);
}
.build-fragment-2 .build-word {
    font-size: clamp(3rem, 7vw, 6rem);
    color: var(--hot-violet);
}
.build-fragment-2.visible {
    transform: rotate(5deg) scale(1);
}

.build-fragment-3 {
    top: 50%;
    left: 5%;
    transform: rotate(-12deg) scale(0.5);
}
.build-fragment-3 .build-word {
    font-size: clamp(5rem, 12vw, 10rem);
    color: var(--neon-tangerine);
    text-shadow: 0 0 40px rgba(255, 109, 0, 0.5);
}
.build-fragment-3.visible {
    transform: rotate(-12deg) scale(1);
}

.build-fragment-4 {
    top: 45%;
    right: 15%;
    transform: rotate(3deg);
}
.build-fragment-4 .build-annotation {
    font-family: var(--font-accent);
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: var(--acid-lemon);
}

.build-fragment-5 {
    bottom: 20%;
    left: 40%;
    transform: rotate(8deg) scale(0.5);
}
.build-fragment-5 .build-word {
    font-size: clamp(3.5rem, 8vw, 7rem);
    color: var(--mint-burst);
}
.build-fragment-5.visible {
    transform: rotate(8deg) scale(1);
}

.build-fragment-6 {
    bottom: 10%;
    right: 8%;
    transform: rotate(-4deg) scale(0.5);
}
.build-fragment-6 .build-word {
    font-size: clamp(6rem, 14vw, 12rem);
    color: var(--electric-fuchsia);
    text-shadow: 0 0 60px rgba(247, 37, 133, 0.6);
}
.build-fragment-6.visible {
    transform: rotate(-4deg) scale(1);
}

.diagonal-slice {
    position: absolute;
    top: 0;
    left: -10%;
    width: 120%;
    height: 100%;
    background: linear-gradient(7deg, transparent 48%, rgba(123, 47, 247, 0.1) 48%, rgba(123, 47, 247, 0.1) 52%, transparent 52%);
    pointer-events: none;
}

/* --- Stage 4: The Eruption --- */
.stage-4 {
    background: var(--midnight-giggle);
    transition: background-color 0.1s;
}

.stage-4.erupting {
    animation: eruption-bg-cycle 0.5s steps(1) infinite;
}

@keyframes eruption-bg-cycle {
    0% { background-color: var(--midnight-giggle); }
    20% { background-color: #1a0533; }
    40% { background-color: #2a0845; }
    60% { background-color: #1a0533; }
    80% { background-color: var(--midnight-giggle); }
    100% { background-color: var(--midnight-giggle); }
}

.stage-4-content {
    text-align: center;
    z-index: 2;
}

.eruption-text-container {
    display: flex;
    justify-content: center;
    gap: 0;
    flex-wrap: wrap;
}

.eruption-letter {
    font-family: var(--font-primary);
    font-size: clamp(5rem, 15vw, 14rem);
    font-weight: 800;
    line-height: 1;
    display: inline-block;
    background: linear-gradient(135deg, var(--electric-fuchsia), var(--hot-violet), var(--mint-burst));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    opacity: 0;
    transform: translateY(100px) scale(0.3) rotate(0deg);
    transition: transform 0.8s var(--spring-ease), opacity 0.6s var(--smooth-ease);
}

.eruption-letter.exploded {
    opacity: 1;
    transform: translateY(0) scale(1);
    animation: letter-bounce 1s var(--spring-ease) infinite alternate;
}

@keyframes letter-bounce {
    0% {
        transform: translateY(0) scale(1) rotate(0deg);
    }
    100% {
        transform: translateY(-15px) scale(1.08) rotate(var(--letter-rotate, 3deg));
    }
}

.eruption-letter[data-index="0"] { --letter-rotate: -5deg; animation-delay: 0s; }
.eruption-letter[data-index="1"] { --letter-rotate: 4deg; animation-delay: 0.1s; }
.eruption-letter[data-index="2"] { --letter-rotate: -3deg; animation-delay: 0.2s; }
.eruption-letter[data-index="3"] { --letter-rotate: 6deg; animation-delay: 0.3s; }
.eruption-letter[data-index="4"] { --letter-rotate: -4deg; animation-delay: 0.4s; }
.eruption-letter[data-index="5"] { --letter-rotate: 5deg; animation-delay: 0.5s; }

.eruption-subtitle {
    margin-top: 2rem;
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.eruption-sub-word {
    font-family: var(--font-secondary);
    font-size: clamp(1rem, 2.5vw, 2rem);
    font-weight: 600;
    letter-spacing: 0.3em;
    color: var(--acid-lemon);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.5s, transform 0.6s var(--spring-ease);
}

.eruption-sub-word.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Stage 5: The Afterglow --- */
.stage-5 {
    background-color: var(--midnight-giggle);
}

.stage-5-content {
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.afterglow-circle {
    width: clamp(150px, 30vw, 300px);
    height: clamp(150px, 30vw, 300px);
    border-radius: 50%;
    background: radial-gradient(circle at center, var(--mint-burst), rgba(0, 245, 212, 0.2));
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    animation: afterglow-pulse 3s ease-in-out infinite;
    transition: transform 0.5s var(--spring-ease), box-shadow 0.5s;
    box-shadow: 0 0 60px rgba(0, 245, 212, 0.3), 0 0 120px rgba(0, 245, 212, 0.1);
}

.afterglow-circle:hover {
    transform: scale(1.1);
    box-shadow: 0 0 80px rgba(0, 245, 212, 0.5), 0 0 160px rgba(0, 245, 212, 0.2);
}

@keyframes afterglow-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 60px rgba(0, 245, 212, 0.3), 0 0 120px rgba(0, 245, 212, 0.1);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 80px rgba(0, 245, 212, 0.4), 0 0 150px rgba(0, 245, 212, 0.15);
    }
}

.afterglow-text {
    font-family: var(--font-accent);
    font-size: clamp(2rem, 5vw, 3.5rem);
    color: var(--midnight-giggle);
    font-weight: 600;
}

/* --- Floating Glyphs --- */
#floating-glyphs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 90;
    overflow: hidden;
}

.floating-glyph {
    position: absolute;
    font-family: var(--font-primary);
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    will-change: transform;
    animation: glyph-float 4s var(--smooth-ease) forwards;
}

@keyframes glyph-float {
    0% {
        opacity: 0;
        transform: translateY(0) scale(0.5) rotate(0deg);
    }
    20% {
        opacity: 0.7;
    }
    100% {
        opacity: 0;
        transform: translateY(-200px) scale(1.2) rotate(var(--glyph-rotate, 45deg));
    }
}

/* --- Scroll Transition Clip Paths --- */
.stage {
    clip-path: inset(0 0 0 0);
}

.stage-1.transitioning {
    clip-path: circle(0% at 50% 50%);
    animation: clip-circle-out 1s var(--smooth-ease) forwards;
}

@keyframes clip-circle-out {
    from {
        clip-path: circle(100% at 50% 50%);
    }
    to {
        clip-path: circle(0% at 50% 50%);
    }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .stage-2-content {
        gap: 2rem;
        padding: 1.5rem;
    }

    .tremor-block {
        padding: 1.5rem 2rem;
    }

    .build-fragment-1 { top: 8%; left: 5%; }
    .build-fragment-2 { top: 22%; right: 5%; }
    .build-fragment-3 { top: 40%; left: 3%; }
    .build-fragment-4 { top: 55%; right: 5%; }
    .build-fragment-5 { bottom: 25%; left: 20%; }
    .build-fragment-6 { bottom: 8%; right: 3%; }

    .eruption-subtitle {
        gap: 0.8rem;
    }

    .nav-pill {
        top: 10px;
        right: 10px;
        padding: 6px 8px;
    }
}

@media (max-width: 480px) {
    .logotype {
        font-size: clamp(3.5rem, 18vw, 6rem);
    }

    .eruption-letter {
        font-size: clamp(3.5rem, 18vw, 6rem);
    }

    .tremor-block-1,
    .tremor-block-2,
    .tremor-block-3 {
        align-self: center;
    }
}
