/* ==========================================
   WATERCOLOR-CRAYON CHIBI STORY STYLES
   Optimized for mobile & Messenger
   ========================================== */

/* --- Custom Properties --- */
:root {
    --pastel-cream: #faf5f0;
    --pastel-pink: #f4c2c2;
    --pastel-pink-light: #fce4ec;
    --pastel-blue: #b3d9ff;
    --pastel-blue-light: #e3f2fd;
    --pastel-lavender: #d4b8e8;
    --pastel-mint: #b8e6d4;
    --pastel-yellow: #ffeaa7;
    --pastel-yellow-light: #fff9e6;
    --pastel-green: #a8e6cf;
    --pastel-green-light: #e8f5e9;
    --crayon-black: #4a4a4a;
    --crayon-black-soft: rgba(74, 74, 74, 0.7);
    --watercolor-white: rgba(255, 255, 255, 0.85);
    --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.12);
    --transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    overflow: hidden;
    height: 100%;
}

body {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Segoe Print', cursive, sans-serif;
    background: linear-gradient(180deg, var(--pastel-cream) 0%, #f0e8e0 100%);
    color: var(--crayon-black);
    overflow: hidden;
    height: 100%;
    position: relative;
    /* Crayon texture overlay */
    background-image: 
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
}

/* --- Main Container --- */
#story-container {
    width: 100%;
    max-width: 540px;
    margin: 0 auto;
    height: 100%;
    overflow-y: scroll;
    overflow-x: hidden;
    scroll-snap-type: y mandatory;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* Hide scrollbar */
#story-container::-webkit-scrollbar {
    display: none;
}
#story-container {
    scrollbar-width: none;
}

/* --- Scene Base --- */
.scene {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Scene Image --- */
.scene-image {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.scene-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    /* Watercolor-crayon filter effect */
    filter: saturate(1.05) contrast(0.98) brightness(1.02);
    transition: transform 0.6s var(--transition-smooth);
}

/* --- Scene Overlay --- */
.scene-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 40%;
    justify-content: flex-end;
}

/* --- Speech Bubbles --- */
.speech-bubble {
    position: relative;
    max-width: 85%;
    padding: 14px 18px;
    background: var(--watercolor-white);
    /* Hand-drawn border effect */
    border: 2.5px solid var(--crayon-black-soft);
    border-radius: 22px;
    /* Slightly irregular border */
    box-shadow: 
        2px 3px 0 rgba(74, 74, 74, 0.15),
        inset 0 0 20px rgba(255, 255, 255, 0.5);
    opacity: 0;
    transform: translateY(15px) scale(0.92);
    transition: all 0.5s var(--transition-smooth);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    /* Watercolor texture */
    background-image: 
        radial-gradient(ellipse at 20% 50%, rgba(255, 255, 255, 0.6) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(255, 255, 255, 0.4) 0%, transparent 40%);
}

.speech-bubble.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -12px;
    width: 24px;
    height: 12px;
    background: var(--watercolor-white);
    border-left: 2.5px solid var(--crayon-black-soft);
    border-bottom: 2.5px solid var(--crayon-black-soft);
}

.speech-bubble.right {
    align-self: flex-end;
    margin-right: 8px;
}

.speech-bubble.right::after {
    right: 28px;
    border-right: none;
    border-left: 2.5px solid var(--crayon-black-soft);
    border-bottom: 2.5px solid var(--crayon-black-soft);
    border-radius: 0 0 0 12px;
}

.speech-bubble.left {
    align-self: flex-start;
    margin-left: 8px;
}

.speech-bubble.left::after {
    left: 28px;
    border-right: 2.5px solid var(--crayon-black-soft);
    border-bottom: 2.5px solid var(--crayon-black-soft);
    border-left: none;
    border-radius: 0 0 12px 0;
}

/* Speech text with typing effect */
.speech-text {
    font-size: 1rem;
    line-height: 1.5;
    color: var(--crayon-black);
    font-weight: 500;
    letter-spacing: 0.3px;
    /* Crayon-like text */
    text-shadow: 0.5px 0.5px 0 rgba(74, 74, 74, 0.1);
    overflow: hidden;
    border-right: 2px solid transparent;
}

.speech-text.typing {
    border-right-color: var(--pastel-pink);
    animation: blink-caret 0.75s step-end infinite;
}

@keyframes blink-caret {
    from, to { border-right-color: transparent; }
    50% { border-right-color: var(--pastel-pink); }
}

/* --- Emotion Indicators --- */
.emotion-indicator {
    position: absolute;
    width: 36px;
    height: 36px;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.scene.active .emotion-indicator {
    opacity: 1;
}

.emotion-indicator.nervous {
    top: 15%;
    right: 15%;
    background: radial-gradient(circle, var(--pastel-blue) 0%, transparent 70%);
    animation: nervous-pulse 1.5s ease-in-out infinite;
}

.emotion-indicator.very-nervous {
    top: 12%;
    right: 12%;
    background: radial-gradient(circle, var(--pastel-blue) 0%, transparent 70%);
    animation: nervous-shake 0.5s ease-in-out infinite;
}

.emotion-indicator.confident {
    top: 15%;
    right: 15%;
    background: radial-gradient(circle, var(--pastel-yellow) 0%, transparent 70%);
    animation: confident-glow 2s ease-in-out infinite;
}

@keyframes nervous-pulse {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.2); opacity: 0.9; }
}

@keyframes nervous-shake {
    0%, 100% { transform: translateX(0) scale(1); }
    25% { transform: translateX(-3px) scale(1.1); }
    75% { transform: translateX(3px) scale(1.1); }
}

@keyframes confident-glow {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.3); opacity: 1; }
}

/* --- Action Effects --- */
.action-effect {
    position: absolute;
    pointer-events: none;
}

.gentle-glow {
    top: 40%;
    left: 30%;
    width: 80px;
    height: 80px;
    background: radial-gradient(circle, rgba(255, 234, 167, 0.5) 0%, transparent 70%);
    animation: gentle-pulse 2s ease-in-out infinite;
}

@keyframes gentle-pulse {
    0%, 100% { transform: scale(1); opacity: 0.4; }
    50% { transform: scale(1.4); opacity: 0.8; }
}

.star-burst {
    top: 10%;
    left: 20%;
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, var(--pastel-yellow) 0%, transparent 60%);
    animation: star-burst-anim 1.5s ease-out infinite;
}

@keyframes star-burst-anim {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.5); opacity: 1; }
    100% { transform: scale(2); opacity: 0; }
}

.warm-glow {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at center, rgba(255, 234, 167, 0.15) 0%, transparent 60%);
    animation: warm-fade 3s ease-in-out infinite;
}

@keyframes warm-fade {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.sparkle-burst {
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 100px;
    background: 
        radial-gradient(circle at 30% 30%, var(--pastel-yellow) 2px, transparent 2px),
        radial-gradient(circle at 70% 20%, var(--pastel-pink) 2px, transparent 2px),
        radial-gradient(circle at 50% 60%, var(--pastel-yellow) 1.5px, transparent 1.5px),
        radial-gradient(circle at 20% 70%, var(--pastel-green) 2px, transparent 2px),
        radial-gradient(circle at 80% 70%, var(--pastel-yellow) 1.5px, transparent 1.5px);
    animation: sparkle-rotate 3s linear infinite;
}

@keyframes sparkle-rotate {
    from { transform: translateX(-50%) rotate(0deg); }
    to { transform: translateX(-50%) rotate(360deg); }
}

.sunshine {
    top: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(180deg, rgba(255, 249, 230, 0.6) 0%, transparent 100%);
    animation: sunshine-breathe 4s ease-in-out infinite;
}

@keyframes sunshine-breathe {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.final-sparkle {
    bottom: 30%;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 120px;
    background: 
        radial-gradient(circle at 25% 25%, var(--pastel-yellow) 3px, transparent 3px),
        radial-gradient(circle at 75% 25%, var(--pastel-pink) 2.5px, transparent 2.5px),
        radial-gradient(circle at 50% 50%, var(--pastel-yellow) 2px, transparent 2px),
        radial-gradient(circle at 25% 75%, var(--pastel-green) 2.5px, transparent 2.5px),
        radial-gradient(circle at 75% 75%, var(--pastel-yellow) 3px, transparent 3px),
        radial-gradient(circle at 50% 15%, var(--pastel-pink) 2px, transparent 2px),
        radial-gradient(circle at 50% 85%, var(--pastel-green) 2px, transparent 2px);
    animation: final-sparkle-anim 2s ease-in-out infinite;
}

@keyframes final-sparkle-anim {
    0%, 100% { transform: translateX(-50%) scale(1) rotate(0deg); opacity: 0.8; }
    50% { transform: translateX(-50%) scale(1.3) rotate(180deg); opacity: 1; }
}

.double-glow {
    top: 30%;
    left: 50%;
    transform: translateX(-50%);
    width: 150px;
    height: 80px;
    background: radial-gradient(ellipse, rgba(168, 230, 207, 0.4) 0%, transparent 60%);
    animation: double-glow-anim 2.5s ease-in-out infinite;
}

@keyframes double-glow-anim {
    0%, 100% { transform: translateX(-50%) scale(1); opacity: 0.5; }
    50% { transform: translateX(-50%) scale(1.2); opacity: 0.9; }
}

.hesitant-pause {
    top: 50%;
    right: 10%;
    width: 40px;
    height: 40px;
    background: radial-gradient(circle, var(--pastel-lavender) 0%, transparent 60%);
    animation: hesitant-anim 1.8s ease-in-out infinite;
}

@keyframes hesitant-anim {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    33% { transform: scale(0.8); opacity: 0.3; }
    66% { transform: scale(1.1); opacity: 0.7; }
}

.confetti {
    top: 15%;
    left: 0;
    right: 0;
    height: 30%;
    background-image: 
        radial-gradient(circle at 10% 20%, var(--pastel-pink) 3px, transparent 3px),
        radial-gradient(circle at 30% 40%, var(--pastel-yellow) 2.5px, transparent 2.5px),
        radial-gradient(circle at 50% 15%, var(--pastel-green) 3px, transparent 3px),
        radial-gradient(circle at 70% 50%, var(--pastel-lavender) 2px, transparent 2px),
        radial-gradient(circle at 90% 30%, var(--pastel-pink) 2.5px, transparent 2.5px),
        radial-gradient(circle at 20% 70%, var(--pastel-yellow) 2px, transparent 2px),
        radial-gradient(circle at 80% 80%, var(--pastel-green) 3px, transparent 3px);
    animation: confetti-fall 4s linear infinite;
}

@keyframes confetti-fall {
    0% { transform: translateY(-20px); opacity: 1; }
    100% { transform: translateY(30px); opacity: 0.7; }
}

.floating-books {
    top: 25%;
    left: 10%;
    width: 50px;
    height: 50px;
    background: radial-gradient(circle, var(--pastel-blue) 0%, transparent 60%);
    animation: float-anim 3s ease-in-out infinite;
}

@keyframes float-anim {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-10px) rotate(5deg); }
}

.happy-bounce {
    bottom: 40%;
    right: 20%;
    width: 50px;
    height: 50px;
    background: radial-gradient(circle, var(--pastel-yellow) 0%, transparent 60%);
    animation: bounce-anim 1s ease-in-out infinite;
}

@keyframes bounce-anim {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-15px) scale(1.2); }
}

.tremble {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    animation: tremble-anim 0.15s linear infinite;
}

@keyframes tremble-anim {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-1px, 1px); }
    50% { transform: translate(1px, -1px); }
    75% { transform: translate(-1px, -1px); }
    100% { transform: translate(1px, 1px); }
}

/* --- Cover Scene --- */
.cover {
    background: linear-gradient(180deg, var(--pastel-yellow-light) 0%, var(--pastel-cream) 50%, var(--pastel-pink-light) 100%);
}

.cover-content {
    text-align: center;
    padding: 40px 30px;
    position: relative;
    z-index: 10;
}

.cover-decoration {
    position: relative;
    height: 120px;
    margin-bottom: 20px;
}

.star {
    position: absolute;
    font-size: 2rem;
    animation: star-twinkle 2s ease-in-out infinite;
    filter: drop-shadow(0 0 8px rgba(255, 234, 167, 0.8));
}

.star-2 {
    left: 25%;
    top: 20%;
    animation-delay: 0.5s;
    font-size: 1.5rem;
}

.star-3 {
    right: 20%;
    top: 30%;
    animation-delay: 1s;
    font-size: 1.8rem;
}

@keyframes star-twinkle {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.8; }
    50% { transform: scale(1.3) rotate(15deg); opacity: 1; }
}

.cover-title {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--crayon-black);
    line-height: 1.2;
    margin-bottom: 15px;
    /* Crayon text effect */
    text-shadow: 
        1px 1px 0 var(--pastel-pink),
        2px 2px 0 rgba(244, 194, 194, 0.5);
    letter-spacing: 1px;
}

.cover-subtitle {
    font-size: 1.2rem;
    color: var(--crayon-black-soft);
    margin-bottom: 40px;
    opacity: 0.85;
}

.tap-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--crayon-black-soft);
    font-size: 0.9rem;
    opacity: 0.7;
    animation: hint-bounce 2s ease-in-out infinite;
}

.tap-arrow {
    font-size: 1.5rem;
}

@keyframes hint-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(8px); }
}

/* --- Ending Scene --- */
.ending {
    background: linear-gradient(180deg, var(--pastel-yellow-light) 0%, var(--pastel-cream) 40%, var(--pastel-pink-light) 100%);
}

.ending-content {
    text-align: center;
    padding: 40px 30px;
    position: relative;
    z-index: 10;
}

.ending-stars {
    margin-bottom: 30px;
    display: flex;
    justify-content: center;
    gap: 12px;
}

.ending-stars .star {
    position: relative;
    font-size: 2rem;
    display: inline-block;
}

.ending-stars .star:nth-child(1) { animation-delay: 0s; }
.ending-stars .star:nth-child(2) { animation-delay: 0.2s; }
.ending-stars .star:nth-child(3) { animation-delay: 0.4s; }
.ending-stars .star:nth-child(4) { animation-delay: 0.6s; }
.ending-stars .star:nth-child(5) { animation-delay: 0.8s; }

.ending-message {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--crayon-black);
    margin-bottom: 12px;
    text-shadow: 1px 1px 0 var(--pastel-yellow);
}

.ending-sub {
    font-size: 1rem;
    color: var(--crayon-black-soft);
    margin-bottom: 30px;
    opacity: 0.8;
}

.share-hint {
    font-size: 0.85rem;
    color: var(--crayon-black-soft);
    opacity: 0.6;
    margin-bottom: 15px;
}

.share-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 32px;
    background: linear-gradient(135deg, var(--pastel-pink) 0%, var(--pastel-lavender) 100%);
    border: 2.5px solid var(--crayon-black-soft);
    border-radius: 28px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--crayon-black);
    cursor: pointer;
    box-shadow: var(--shadow-medium);
    transition: all 0.3s var(--transition-smooth);
    font-family: inherit;
}

.share-btn:active {
    transform: scale(0.95);
    box-shadow: var(--shadow-soft);
}

.share-icon {
    font-size: 1.3rem;
}

/* --- Progress Bar --- */
.progress-bar {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 540px;
    padding: 12px 20px;
    padding-top: max(12px, env(safe-area-inset-top));
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(250, 245, 240, 0.95) 0%, transparent 100%);
}

.progress-fill {
    height: 4px;
    background: var(--pastel-pink-light);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--pastel-pink), var(--pastel-lavender));
    border-radius: 2px;
    transition: width 0.4s var(--transition-smooth);
}

.progress-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
}

.progress-dots .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pastel-pink-light);
    border: 1.5px solid var(--crayon-black-soft);
    transition: all 0.3s ease;
}

.progress-dots .dot.active {
    background: var(--pastel-pink);
    transform: scale(1.2);
}

/* --- Navigation Hints --- */
.nav-hint {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    background: var(--watercolor-white);
    border: 2px solid var(--crayon-black-soft);
    border-radius: 16px;
    font-size: 0.8rem;
    color: var(--crayon-black-soft);
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    z-index: 50;
    backdrop-filter: blur(4px);
}

.top-hint {
    top: 60px;
}

.bottom-hint {
    bottom: max(20px, env(safe-area-inset-bottom));
}

.nav-hint.visible {
    opacity: 0.7;
}

/* --- Responsive --- */
@media (max-width: 360px) {
    :root {
        font-size: 14px;
    }
    
    .speech-bubble {
        padding: 12px 14px;
    }
    
    .cover-title {
        font-size: 1.8rem;
    }
    
    .ending-message {
        font-size: 1.3rem;
    }
}

@media (min-width: 541px) {
    #story-container {
        border-left: 1px solid rgba(0, 0, 0, 0.05);
        border-right: 1px solid rgba(0, 0, 0, 0.05);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
    }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* --- Print --- */
@media print {
    #story-container {
        overflow: visible;
        height: auto;
    }
    
    .scene {
        height: auto;
        page-break-after: always;
    }
    
    .scene-overlay,
    .progress-bar,
    .nav-hint {
        display: none;
    }
}
