/* ===================================================
   adhoc.quest - Creamy Pastel Bubble Storybook
   =================================================== */

/* --- Custom Properties / Palette --- */
:root {
    --vanilla-cloud: #FFF8F0;
    --peach-whisper: #FDF0E0;
    --dream-haze: #F0E6F6;
    --petal-blush: #E8A0B4;
    --sunset-melon: #F4A89A;
    --spearmint-foam: #B8E6D0;
    --honey-drop: #F5D78E;
    --cocoa-ink: #3D2B1F;
    --warm-umber: #6B5044;
    --soap-shimmer: #E6D4F0;

    --spring-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
    --font-display: 'Baloo 2', cursive;
    --font-body: 'Nunito', sans-serif;
    --font-accent: 'Caveat', cursive;
}

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

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

body {
    font-family: var(--font-body);
    color: var(--cocoa-ink);
    background-color: var(--vanilla-cloud);
    overflow-x: hidden;
    line-height: 1.7;
}

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

/* --- Bubble Canvas (cursor-spawned bubbles) --- */
#bubble-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.cursor-bubble {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.7), rgba(232,160,180,0.15));
    box-shadow: inset -2px -2px 6px rgba(255,255,255,0.5);
    animation: bubbleRise 1.5s ease-out forwards;
}

.cursor-bubble::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 20%;
    width: 30%;
    height: 20%;
    border-radius: 50%;
    background: rgba(255,255,255,0.6);
}

@keyframes bubbleRise {
    0% {
        opacity: 0.8;
        transform: translateY(0) translateX(0) scale(1);
    }
    80% {
        opacity: 0.4;
    }
    100% {
        opacity: 0;
        transform: translateY(var(--rise-y, -150px)) translateX(var(--drift-x, 20px)) scale(0);
    }
}

/* --- Chapters / Sections --- */
.chapter {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
}

/* --- Hero Section --- */
#hero {
    background: radial-gradient(ellipse at 50% 40%, var(--vanilla-cloud), var(--peach-whisper));
    overflow: hidden;
}

#hero-bubbles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.bg-bubble {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.6), rgba(240,230,246,0.15));
    box-shadow: inset -4px -4px 12px rgba(255,255,255,0.6);
    pointer-events: none;
}

.bg-bubble::before {
    content: '';
    position: absolute;
    top: 12%;
    left: 18%;
    width: 28%;
    height: 18%;
    border-radius: 50%;
    background: rgba(255,255,255,0.7);
}

#hero-content {
    position: relative;
    z-index: 2;
    text-align: center;
}

/* --- Hero Title (letter bubbles) --- */
#hero-title {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 8vw, 6rem);
    font-weight: 800;
    color: var(--cocoa-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.05em;
    margin-bottom: 1rem;
}

.letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(80px) scale(0.5);
    animation: letterBubbleIn 0.7s var(--spring-bounce) forwards;
    animation-delay: var(--delay, 0s);
    padding: 0 0.02em;
    position: relative;
}

.letter.dot {
    color: var(--petal-blush);
}

@keyframes letterBubbleIn {
    0% {
        opacity: 0;
        transform: translateY(80px) scale(0.5);
    }
    100% {
        opacity: 1;
        transform: translateY(var(--bob-offset, 0px)) rotate(var(--rotation, 0deg)) scale(1);
    }
}

/* Bobbing animation applied after entrance */
.letter.bobbing {
    animation: letterBob var(--bob-duration, 3s) ease-in-out infinite alternate;
    opacity: 1;
    transform: rotate(var(--rotation, 0deg));
}

@keyframes letterBob {
    0% {
        transform: translateY(calc(var(--bob-offset, 0px) - 4px)) rotate(var(--rotation, 0deg));
    }
    100% {
        transform: translateY(calc(var(--bob-offset, 0px) + 4px)) rotate(var(--rotation, 0deg));
    }
}

/* --- Subtitle SVG --- */
#subtitle-container {
    position: relative;
    z-index: 2;
    margin-top: 0.5rem;
}

#subtitle-svg {
    width: clamp(280px, 50vw, 500px);
    height: 50px;
    overflow: visible;
}

#subtitle-text {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    fill-opacity: 0;
    animation: handwrite 1.5s ease-out 2.5s forwards;
}

@keyframes handwrite {
    0% {
        stroke-dashoffset: 1000;
        fill-opacity: 0;
    }
    70% {
        fill-opacity: 0;
    }
    100% {
        stroke-dashoffset: 0;
        fill-opacity: 1;
    }
}

/* --- Scroll Hint --- */
#scroll-hint {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 5;
    animation: scrollHintPulse 2s ease-in-out infinite;
}

.scroll-bubble {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--petal-blush);
    opacity: 0.5;
}

.scroll-bubble:nth-child(2) { opacity: 0.7; width: 10px; height: 10px; }
.scroll-bubble:nth-child(3) { opacity: 0.9; width: 12px; height: 12px; }

@keyframes scrollHintPulse {
    0%, 100% { transform: translateX(-50%) translateY(0); opacity: 1; }
    50% { transform: translateX(-50%) translateY(8px); opacity: 0.6; }
}

/* --- Chapter Islands --- */
.chapter-island {
    position: relative;
    max-width: 700px;
    width: 90%;
    background: linear-gradient(135deg, var(--vanilla-cloud), var(--peach-whisper));
    border: 1px solid rgba(232, 160, 180, 0.4);
    border-radius: 60% 40% 50% 45% / 45% 55% 40% 60%;
    box-shadow: 0 8px 32px rgba(61, 43, 31, 0.08);
    padding: 3rem 2.5rem;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.6s ease-out, transform 0.6s var(--spring-bounce), border-radius 0.6s var(--spring-bounce);
    z-index: 2;
}

.chapter-island.visible {
    opacity: 1;
    transform: scale(1);
}

.chapter-island:hover {
    border-radius: 50% 55% 45% 50% / 55% 45% 55% 45%;
}

.chapter-island.island-alt {
    border-radius: 45% 55% 40% 60% / 55% 40% 60% 45%;
    background: linear-gradient(135deg, var(--peach-whisper), var(--dream-haze));
}

.chapter-island.island-alt:hover {
    border-radius: 55% 45% 55% 45% / 45% 55% 45% 55%;
}

.island-content {
    position: relative;
}

/* --- Chapter Headings --- */
.chapter-heading {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 700;
    color: var(--cocoa-ink);
    margin-bottom: 1.2rem;
    position: relative;
    display: inline-block;
}

.chapter-heading::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 100%;
    height: 8px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='8' viewBox='0 0 120 8'%3E%3Cpath d='M0 4 Q10 0 20 4 Q30 8 40 4 Q50 0 60 4 Q70 8 80 4 Q90 0 100 4 Q110 8 120 4' stroke='%23E8A0B4' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-size: 120px 8px;
    animation: squiggleScroll 3s linear infinite;
}

@keyframes squiggleScroll {
    0% { background-position: 0 0; }
    100% { background-position: 120px 0; }
}

/* --- Chapter Text --- */
.chapter-text {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    font-weight: 400;
    color: var(--warm-umber);
    margin-bottom: 1rem;
    line-height: 1.8;
}

.chapter-text:last-of-type {
    margin-bottom: 0;
}

/* --- Annotations --- */
.annotation {
    display: block;
    font-family: var(--font-accent);
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    font-weight: 400;
    color: var(--petal-blush);
    margin-top: 1.5rem;
    position: relative;
    padding-left: 3rem;
    transform: rotate(var(--annotation-rot, -3deg));
    opacity: 0;
    transition: opacity 0.5s ease-out, transform 0.5s var(--spring-bounce);
}

.annotation.visible {
    opacity: 1;
}

.annotation .dotted-trail {
    position: absolute;
    left: 0;
    top: -10px;
    width: 30px;
    height: 50px;
}

/* --- Interstitial Decorations --- */
.interstitial-deco {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2rem 0;
    z-index: 1;
}

.paper-airplane {
    width: 40px;
    height: 30px;
    animation: airplaneDrift 8s ease-in-out infinite;
}

@keyframes airplaneDrift {
    0% { transform: translateX(-30px) translateY(0) rotate(-5deg); }
    25% { transform: translateX(30px) translateY(-15px) rotate(5deg); }
    50% { transform: translateX(50px) translateY(5px) rotate(-3deg); }
    75% { transform: translateX(-10px) translateY(-10px) rotate(3deg); }
    100% { transform: translateX(-30px) translateY(0) rotate(-5deg); }
}

.spiral-doodle {
    width: 50px;
    height: 50px;
    animation: spiralSpin 20s linear infinite;
}

@keyframes spiralSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.star-burst {
    width: 40px;
    height: 40px;
    animation: starTwinkle 3s ease-in-out infinite;
}

@keyframes starTwinkle {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.7; }
    50% { transform: scale(1.15) rotate(10deg); opacity: 1; }
}

.dotted-path-vertical {
    width: 4px;
    height: 60px;
    background-image: radial-gradient(circle, var(--petal-blush) 1.5px, transparent 1.5px);
    background-size: 4px 12px;
    background-repeat: repeat-y;
}

.bubble-chain {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.chain-bubble {
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.6), rgba(184,230,208,0.2));
    box-shadow: inset -2px -2px 6px rgba(255,255,255,0.4);
}

.chain-bubble:nth-child(1) { width: 8px; height: 8px; }
.chain-bubble:nth-child(2) { width: 12px; height: 12px; }
.chain-bubble:nth-child(3) { width: 16px; height: 16px; }
.chain-bubble:nth-child(4) { width: 12px; height: 12px; }
.chain-bubble:nth-child(5) { width: 8px; height: 8px; }

/* --- Bubble Navigation --- */
#bubble-nav {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    animation: navBreathe 4s ease-in-out infinite;
}

@keyframes navBreathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

.nav-bubble {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1.5px solid rgba(232, 160, 180, 0.5);
    background: radial-gradient(circle at 30% 30%, rgba(255,248,240,0.95), rgba(253,240,224,0.9));
    box-shadow: 0 4px 16px rgba(61, 43, 31, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--warm-umber);
    transition: transform 0.4s var(--spring-bounce), box-shadow 0.3s ease, background 0.3s ease;
    position: relative;
}

.nav-bubble svg {
    width: 20px;
    height: 20px;
}

.nav-bubble:hover {
    transform: scale(1.2);
    box-shadow: 0 6px 24px rgba(61, 43, 31, 0.15);
    background: radial-gradient(circle at 30% 30%, rgba(255,248,240,1), rgba(232,160,180,0.2));
}

.nav-bubble.active {
    border-color: var(--petal-blush);
    background: radial-gradient(circle at 30% 30%, rgba(232,160,180,0.2), rgba(240,230,246,0.3));
    color: var(--petal-blush);
}

.nav-bubble:hover::after {
    content: attr(title);
    position: absolute;
    right: 54px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-accent);
    font-size: 1rem;
    color: var(--warm-umber);
    background: var(--vanilla-cloud);
    padding: 4px 12px;
    border-radius: 20px;
    white-space: nowrap;
    box-shadow: 0 2px 12px rgba(61, 43, 31, 0.1);
    border: 1px solid rgba(232, 160, 180, 0.3);
    animation: labelPop 0.3s var(--spring-bounce);
}

@keyframes labelPop {
    0% { opacity: 0; transform: translateY(-50%) scale(0.8) translateX(10px); }
    100% { opacity: 1; transform: translateY(-50%) scale(1) translateX(0); }
}

/* --- Background color transition zones --- */
#chapter-spark {
    background: linear-gradient(to bottom, var(--vanilla-cloud), rgba(240, 230, 246, 0.3));
}

#chapter-wander {
    background: linear-gradient(to bottom, rgba(240, 230, 246, 0.3), var(--dream-haze));
}

#chapter-discovery {
    background: linear-gradient(to bottom, var(--dream-haze), rgba(230, 212, 240, 0.4));
}

#chapter-return {
    background: linear-gradient(to bottom, rgba(230, 212, 240, 0.4), var(--soap-shimmer));
}

/* --- Micro bubble fizz (spawned on hover) --- */
.fizz-bubble {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.8), rgba(184,230,208,0.3));
    pointer-events: none;
    animation: fizzUp 1.5s ease-out forwards;
    z-index: 10;
}

@keyframes fizzUp {
    0% {
        opacity: 0.8;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-60px) scale(0);
    }
}

/* --- Background bubble float animation --- */
@keyframes bgBubbleFloat {
    0% {
        transform: translateY(0) translateX(0);
    }
    100% {
        transform: translateY(var(--float-distance, -110vh)) translateX(var(--drift, 30px));
    }
}

.bg-bubble.floating {
    animation: bgBubbleFloat var(--float-speed, 15s) linear infinite;
}

/* --- Pop animation for bubbles reaching top --- */
@keyframes bubblePop {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(0); opacity: 0; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .chapter-island {
        padding: 2rem 1.5rem;
        width: 95%;
        border-radius: 50% 45% 48% 52% / 48% 52% 46% 50%;
    }

    .chapter-island:hover {
        border-radius: 48% 52% 46% 50% / 50% 48% 52% 46%;
    }

    .annotation {
        position: relative;
        padding-left: 2rem;
        margin-top: 1.2rem;
    }

    #bubble-nav {
        bottom: 1rem;
        right: 1rem;
        gap: 8px;
    }

    .nav-bubble {
        width: 38px;
        height: 38px;
    }

    .nav-bubble:hover::after {
        display: none;
    }

    #hero-title {
        gap: 0.02em;
    }
}

@media (max-width: 480px) {
    .chapter {
        padding: 3rem 1rem;
    }

    .chapter-island {
        padding: 1.5rem 1.2rem;
    }
}
