:root {
    --primary-color: #FF6B6B;
    --secondary-color: #4ECDC4;
    --accent-color: #FFE66D;
    --text-color: #2D3436;
    --bg-color: #F7FFF7;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Comic Neue', cursive;
    background-color: var(--secondary-color);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

h1,
h2,
h3,
h4 {
    font-family: 'Fredoka One', cursive;
    color: var(--primary-color);
    text-shadow: 2px 2px 0px #fff;
    margin-top: 0;
}

.book-container {
    width: 90vw;
    height: 90vh;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 8px solid var(--accent-color);
}

.page {
    position: absolute;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
    animation: fadeIn 0.5s ease-in-out;
    background-image: radial-gradient(circle at center, #fff 0%, #f0f8ff 100%);
}

.page.active {
    display: flex;
}

/* Cover Page */
.page.cover {
    justify-content: center;
    align-items: center;
    text-align: center;
    background: radial-gradient(circle, #FFE66D 0%, #FF6B6B 100%);
}

.page.cover h1 {
    font-size: 3rem;
    color: white;
    text-shadow: 4px 4px 0px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.5rem;
    color: white;
    margin-top: 10px;
    font-weight: bold;
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
}

.start-btn {
    padding: 20px 40px;
    font-size: 1.5rem;
    background: white;
    color: var(--primary-color);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'Fredoka One', cursive;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    margin-top: 30px;
}

.start-btn:hover {
    transform: scale(1.1) rotate(-3deg);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
}

/* Content Layout */
.content {
    flex: 2;
    display: flex;
    gap: 20px;
    align-items: flex-start;
    /* Changed from center to allow better text flow */
    justify-content: center;
    width: 95%;
    margin: 0 auto;
    height: 65vh;
    /* Fixed height for content area */
}

.text-area {
    flex: 1;
    font-size: 1.1rem;
    line-height: 1.6;
    background: rgba(255, 255, 255, 0.95);
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    overflow-y: auto;
    max-height: 100%;
    /* Fill the content area */
    font-family: 'Comic Neue', cursive;
    text-align: left;
    border: 2px dashed #eee;
}

/* Custom Scrollbar for Webkit */
.text-area::-webkit-scrollbar {
    width: 10px;
}

.text-area::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 5px;
}

.text-area::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 5px;
}

.text-area::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

.image-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.image-area img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 15px;
    border: 5px solid white;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    transform: rotate(2deg);
    transition: transform 0.3s;
    object-fit: contain;
}

.image-area img:hover {
    transform: scale(1.02) rotate(0deg);
}

/* Interactive Area */
.interactive-area {
    flex: 0 0 auto;
    background: transparent;
    padding: 10px;
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 5px 0;
}

.draw-btn {
    background: #FF9800;
    /* Orange */
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 1.3rem;
    font-family: 'Fredoka One', cursive;
    cursor: pointer;
    box-shadow: 0 5px 0 #F57C00;
    transition: transform 0.1s;
}

.draw-btn:hover {
    transform: translateY(-2px);
}

.draw-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #F57C00;
}

/* Nav Buttons */
.nav-buttons {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 10px 20px;
    margin-top: auto;
    /* Push to bottom */
}

.nav-buttons button {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 1.2rem;
    font-family: 'Fredoka One', cursive;
    cursor: pointer;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.nav-buttons button:hover {
    transform: translateY(-3px);
}

/* Fun Facts & Quiz */
.fun-fact {
    background: #E1F5FE;
    border-left: 5px solid #03A9F4;
    padding: 15px;
    margin: 20px 0;
    border-radius: 0 10px 10px 0;
    font-size: 0.95rem;
}

.quiz-section {
    background: #FFF3E0;
    border: 2px dashed #FFB74D;
    padding: 15px;
    border-radius: 15px;
    margin-top: 20px;
    text-align: center;
}

.quiz-btn {
    background: white;
    border: 2px solid #FFB74D;
    color: #E65100;
    padding: 8px 15px;
    margin: 5px;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Comic Neue', cursive;
    font-weight: bold;
    font-size: 1rem;
    transition: 0.2s;
}

.quiz-btn:hover {
    background: #FFB74D;
    color: white;
}

.quiz-feedback {
    margin-top: 10px;
    font-weight: bold;
    min-height: 1.2em;
}

.quiz-feedback.correct {
    color: #2E7D32;
}

.quiz-feedback.incorrect {
    color: #D84315;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #fefefe;
    margin: 2% auto;
    /* 2% from top and centered */
    padding: 20px;
    border: 8px solid var(--accent-color);
    width: 90%;
    height: 90%;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    align-self: flex-end;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

.header-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

/* Canvas in Modal */
.canvas-container {
    flex: 1;
    background: white;
    border: 2px solid #ccc;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
}

#drawingCanvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.tools-panel {
    height: 120px;
    /* Fixed height for tools */
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding-top: 10px;
}

.colors {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.color-swatch {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.2s;
}

.color-swatch:hover {
    transform: scale(1.2);
    z-index: 1;
}

.templates-panel,
.templates-list {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.templates-list p {
    margin: 0;
    font-weight: bold;
    color: var(--text-color);
}

.template-btn {
    background: #E1F5FE;
    border: 1px solid #039BE5;
    color: #0277BD;
    padding: 5px 10px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 0.9rem;
}

.template-btn:hover {
    background: #039BE5;
    color: white;
}

.tool-btn {
    background: #ff4757;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .book-container {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        border: none;
    }

    .page {
        padding: 10px;
        height: 100vh;
        /* Force full height */
        /* display: flex; REMOVED */
        flex-direction: column;
        justify-content: space-between;
        /* Space out elements */
        overflow: hidden;
        /* Prevent page scroll, rely on inner scroll */
    }

    .content {
        flex-direction: column;
        height: auto;
        flex: 1;
        /* Take all available space */
        min-height: 0;
        /* Allow shrinking */
        width: 100%;
        margin: 0;
        gap: 10px;
    }

    .text-area {
        order: 2;
        /* Text below image on mobile for better flow? Or keep text top? User didn't specify, keeping text top as per code */
        flex: 1;
        /* Grow to fill space */
        max-height: none;
        /* Remove fixed limit */
        overflow-y: auto;
        /* Scrollable text */
        padding: 15px;
        font-size: 1rem;
    }

    .image-area {
        order: 1;
        /* Image top */
        height: 30vh;
        /* Fixed height for image */
        flex-shrink: 0;
        /* Don't shrink image */
        min-height: 150px;
    }

    .interactive-area {
        flex-shrink: 0;
        padding: 5px;
        margin: 0;
    }

    .nav-buttons {
        flex-shrink: 0;
        /* Never shrink buttons */
        padding: 10px;
        background: rgba(255, 255, 255, 0.9);
        /* Readable background */
        border-top: 1px solid #eee;
        z-index: 10;
        margin-top: 0;
        /* Remove auto margin as we use flex-col */
    }

    .nav-buttons button {
        padding: 8px 16px;
        font-size: 1rem;
    }

    .modal-content {
        width: 100%;
        height: 100%;
        margin: 0;
        border-radius: 0;
        border: none;
    }

    .color-swatch {
        width: 35px;
        height: 35px;
    }
}