/* CSS Custom Variables for Clay Theme */
:root {
    --clay-bg-pastel: #fcefe3;
    --clay-card-bg: #fffbf7;
    --clay-primary: #ff85a2; /* Mimi pink */
    --clay-secondary: #ffb57a; /* Toto orange */
    --clay-accent: #6db3f2; /* Sky blue */
    --clay-border: #80614d;
    --clay-shadow-soft: 0 10px 20px rgba(128, 97, 77, 0.12);
    --clay-shadow-heavy: 0 15px 30px rgba(128, 97, 77, 0.22);
    --clay-highlight: inset 0 4px 0 rgba(255, 255, 255, 0.5);
    
    --font-heading: 'Jua', sans-serif;
    --font-body: 'Gaegu', sans-serif;
}

/* Reset & Basic Setup */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-body);
    background: radial-gradient(circle, #ffe9d6 0%, #ffd4b8 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
    user-select: none;
}

/* Clouds Background Animation */
.clouds-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}

.cloud {
    position: absolute;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 100px;
    filter: blur(4px);
    animation: floatClouds 30s linear infinite;
}

.cloud::before, .cloud::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
}

.cloud-1 {
    width: 150px;
    height: 60px;
    top: 10%;
    left: -200px;
    animation-duration: 45s;
}
.cloud-1::before { width: 70px; height: 70px; top: -30px; left: 20px; }
.cloud-1::after { width: 50px; height: 50px; top: -20px; right: 20px; }

.cloud-2 {
    width: 200px;
    height: 80px;
    top: 30%;
    left: -250px;
    animation-duration: 60s;
    animation-delay: -20s;
}
.cloud-2::before { width: 100px; height: 100px; top: -45px; left: 30px; }
.cloud-2::after { width: 70px; height: 70px; top: -30px; right: 30px; }

.cloud-3 {
    width: 120px;
    height: 50px;
    top: 60%;
    left: -150px;
    animation-duration: 35s;
    animation-delay: -10s;
}
.cloud-3::before { width: 55px; height: 55px; top: -25px; left: 15px; }
.cloud-3::after { width: 40px; height: 40px; top: -15px; right: 15px; }

@keyframes floatClouds {
    0% { transform: translateX(-100px); }
    100% { transform: translateX(calc(100vw + 250px)); }
}

/* Floating Bubbles Container */
#bubble-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 1;
    pointer-events: none;
}

.bubble {
    position: absolute;
    bottom: -100px;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.4) 0%, rgba(109, 179, 242, 0.2) 60%, rgba(255, 133, 162, 0.2) 100%);
    border-radius: 50%;
    box-shadow: inset -5px -5px 15px rgba(0,0,0,0.05), inset 5px 5px 10px rgba(255,255,255,0.6), 0 5px 15px rgba(0,0,0,0.05);
    animation: riseUp 8s ease-in infinite;
}

@keyframes riseUp {
    0% {
        transform: translateY(0) scale(1) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 0.8;
    }
    90% {
        opacity: 0.8;
    }
    100% {
        transform: translateY(-110vh) scale(1.2) rotate(360deg);
        opacity: 0;
    }
}

/* Header styling */
.app-header {
    width: 100%;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    position: relative;
}

.main-title {
    font-family: var(--font-heading);
    color: #6a4f3d;
    font-size: 2.2rem;
    text-shadow: 2px 2px 0px #fff, 4px 4px 0px rgba(128, 97, 77, 0.1);
}

.controls-panel {
    display: flex;
    gap: 12px;
}

.btn-round {
    background: var(--clay-card-bg);
    border: 3px solid var(--clay-border);
    border-radius: 30px;
    padding: 8px 16px;
    font-family: var(--font-heading);
    font-size: 1rem;
    color: #6a4f3d;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--clay-border), var(--clay-shadow-soft);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease-out;
}

.btn-round:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 var(--clay-border), var(--clay-shadow-heavy);
}

.btn-round:active {
    transform: translateY(4px);
    box-shadow: 0 0px 0 var(--clay-border), var(--clay-shadow-soft);
}

.btn-round.active {
    background: #e2f7e3;
    border-color: #3b8e40;
    color: #27622b;
    box-shadow: 0 4px 0 #3b8e40, var(--clay-shadow-soft);
}
.btn-round.active:hover {
    box-shadow: 0 6px 0 #3b8e40, var(--clay-shadow-heavy);
}
.btn-round.active:active {
    transform: translateY(4px);
    box-shadow: 0 0px 0 #3b8e40;
}

/* Book Viewport & Animation */
.book-viewport {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 20px 40px;
    z-index: 5;
}

.book-wrapper {
    position: relative;
    width: 1020px;
    height: 600px;
}

.book-container {
    width: 100%;
    height: 100%;
    background: #8c6a51; /* Wood book shelf background */
    border: 12px solid #5a4231;
    border-radius: 24px;
    position: relative;
    box-shadow: 0 25px 50px rgba(0,0,0,0.3);
    overflow: hidden;
}

.book-page {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: var(--clay-card-bg);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.23, 1, 0.32, 1);
    transform: translateX(100px) rotate(2deg);
}

.book-page.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0) rotate(0deg);
}

/* Page transitions */
.book-page.exit-left {
    transform: translateX(-100px) rotate(-2deg);
    opacity: 0;
}

.page-spread {
    display: flex;
    width: 100%;
    height: 100%;
}

.page-left, .page-right {
    flex: 1;
    height: 100%;
    padding: 20px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.page-left {
    border-right: 2px dashed rgba(128, 97, 77, 0.15); /* Book spine mark */
}

/* Cover styles */
.cover-design {
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, #fff 0%, #fff0e0 100%);
}

.cover-img-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cover-title-page {
    background: radial-gradient(circle at center, #fffbf2 0%, #ffdca8 100%);
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 20px;
}

.badge {
    background: #ff7396;
    color: white;
    font-family: var(--font-heading);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 1.1rem;
    border: 3px solid var(--clay-border);
    box-shadow: 0 4px 0 var(--clay-border);
}

.book-title {
    font-family: var(--font-heading);
    font-size: 3.2rem;
    color: #553e30;
    line-height: 1.2;
    text-shadow: 2px 2px 0px #fff;
}

.book-title .highlight {
    color: #ff688e;
    font-size: 3.6rem;
    display: inline-block;
    animation: wiggle 2s ease-in-out infinite;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg) scale(1.05); }
}

.author {
    font-size: 1.3rem;
    color: #8c6e5a;
    font-weight: bold;
}

.start-btn {
    background: var(--clay-secondary);
    border: 4px solid var(--clay-border);
    border-radius: 50px;
    padding: 12px 28px;
    font-family: var(--font-heading);
    font-size: 1.4rem;
    color: white;
    text-shadow: 2px 2px 0 var(--clay-border);
    cursor: pointer;
    box-shadow: 0 6px 0 var(--clay-border), var(--clay-shadow-soft);
    transition: all 0.15s ease-out;
    margin-top: 10px;
}

.start-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 9px 0 var(--clay-border), var(--clay-shadow-heavy);
}

.start-btn:active {
    transform: translateY(6px);
    box-shadow: 0 0px 0 var(--clay-border);
}

/* Illustration Styles */
.illustration-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 18px;
}

.illustration-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 18px;
    border: 6px solid var(--clay-border);
    transition: transform 0.3s ease;
}

.illustration-img:hover {
    transform: scale(1.03);
}

.clay-shadow {
    box-shadow: 0 12px 24px rgba(128, 97, 77, 0.25);
}

/* Text Page Styles */
.text-layout {
    display: flex;
    flex-direction: column;
    background: #fffdfb;
    padding: 25px 30px;
    height: 100%;
}

.page-top-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.page-number {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: #b0917c;
}

.tts-btn {
    background: #e6f3ff;
    border: 2px solid #5a94cc;
    color: #2b5680;
    border-radius: 20px;
    padding: 6px 14px;
    font-family: var(--font-heading);
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 3px 0 #5a94cc;
    transition: all 0.1s ease;
}

.tts-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 #5a94cc;
}

.tts-btn:active {
    transform: translateY(3px);
    box-shadow: 0 0px 0 #5a94cc;
}

.story-text {
    font-size: 1.45rem; /* Balanced size for 6-7 year olds */
    color: #4a382b;
    line-height: 1.7;
    text-align: center;
    word-break: keep-all;
    margin: auto 0; /* Vertically center inside the remaining space */
    font-weight: 700;
    width: 100%;
    display: block; /* Removed flex column to prevent inline elements from stretching */
}

.story-text .char-mimi {
    color: #ff547d;
    font-weight: bold;
    border-bottom: 3px dashed #ff547d;
    display: inline-block;
    padding-bottom: 1px;
}

.story-text .char-toto {
    color: #ff852e;
    font-weight: bold;
    border-bottom: 3px dashed #ff852e;
    display: inline-block;
    padding-bottom: 1px;
}

.story-text .keyword {
    color: #3b8c4c;
    background: #ebf9ed;
    padding: 2px 6px;
    border-radius: 8px;
    border: 2px solid #a3dfae;
}

.story-text .sound-effect {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    color: #a453f6;
    text-shadow: 2px 2px 0px #fff;
    display: inline-block;
    animation: bounce 0.6s ease infinite alternate;
}

.story-text .speech {
    color: #1a6cb0;
    font-style: italic;
    background: #f0f7fc;
    border-left: 5px solid #6db3f2;
    padding: 6px 12px;
    border-radius: 0 8px 8px 0;
    display: inline-block;
    margin: 6px 0;
}

.story-text .highlight {
    background: linear-gradient(180deg, rgba(255,255,255,0) 50%, #fff275 50%);
    padding: 0 4px;
    color: #8c6400;
}

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

/* Custom Navigation Buttons (Paws) */
.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: #ffecd1;
    border: 4px solid var(--clay-border);
    border-radius: 50%;
    width: 70px;
    height: 70px;
    cursor: pointer;
    box-shadow: 0 6px 0 var(--clay-border), var(--clay-shadow-soft);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 100;
}

.nav-btn:hover {
    background: #ffe3bd;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 8px 0 var(--clay-border), var(--clay-shadow-heavy);
}

.nav-btn:active {
    transform: translateY(-50%) scale(0.95);
    box-shadow: 0 1px 0 var(--clay-border);
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: translateY(-50%) scale(1);
    box-shadow: 0 4px 0 var(--clay-border);
}

.prev-btn {
    left: -35px;
}

.next-btn {
    right: -35px;
}

.nav-icon {
    font-size: 1.6rem;
}

.nav-text {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: #6a4f3d;
    margin-top: -2px;
}

/* Footer & Progress Bar */
.app-footer {
    width: 100%;
    padding: 20px 40px;
    display: flex;
    justify-content: center;
    z-index: 10;
    position: relative;
}

.progress-bar-container {
    width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.progress-line {
    width: 100%;
    height: 12px;
    background: #e0cab8;
    border: 3px solid var(--clay-border);
    border-radius: 10px;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.mascot-slider {
    position: absolute;
    top: -16px;
    left: 0%;
    font-size: 1.8rem;
    transform: translateX(-50%);
    transition: left 0.5s cubic-bezier(0.23, 1, 0.32, 1);
    text-shadow: 0 3px 5px rgba(0,0,0,0.15);
}

.progress-text {
    font-family: var(--font-heading);
    color: #6a4f3d;
    font-size: 1.1rem;
}

/* Particle clicks */
.particle {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 9999;
    animation: explode 0.8s ease-out forwards;
}

@keyframes explode {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--mx), var(--my)) scale(0);
        opacity: 0;
    }
}

/* Responsive Scaling for Book */
@media (max-width: 1000px) {
    .book-viewport {
        padding: 10px;
    }
    .book-wrapper {
        width: 100%;
        max-width: 700px;
        height: 480px;
    }
    .nav-btn {
        width: 60px;
        height: 60px;
    }
    .prev-btn { left: -15px; }
    .next-btn { right: -15px; }
    .story-text { font-size: 1.3rem; }
}

@media (max-width: 720px) {
    .app-header {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }
    .main-title { font-size: 1.8rem; }
    .book-wrapper {
        width: 100%;
        height: 600px;
    }
    .page-spread {
        flex-direction: column;
    }
    .page-left {
        flex: 1.1;
        border-right: none;
        border-bottom: 2px dashed rgba(128, 97, 77, 0.15);
        padding: 15px;
    }
    .page-right {
        flex: 1.2;
        padding: 15px;
    }
    .illustration-wrapper {
        border-radius: 12px;
    }
    .story-text {
        font-size: 1.2rem;
        line-height: 1.5;
    }
    .progress-bar-container {
        width: 80%;
    }
    .cover-title-page {
        padding: 20px;
    }
    .book-title {
        font-size: 2.2rem;
    }
    .book-title .highlight {
        font-size: 2.5rem;
    }
    .nav-btn {
        width: 50px;
        height: 50px;
    }
    .prev-btn { left: -10px; }
    .next-btn { right: -10px; }
}
