/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Georgia', serif;
    background: linear-gradient(to bottom, #f5e9d0, #e8d4aa);
    color: #5d4037;
    line-height: 1.6;
    font-size: 18px;
}

.book-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    background: linear-gradient(to bottom, #fdf6e3, #f0e6d2);
    box-shadow: 0 0 30px rgba(139, 69, 19, 0.3);
    min-height: 100vh;
    position: relative;
}

/* Header Styles */
.book-header {
    text-align: center;
    padding: 30px 0;
    border-bottom: 3px double #8b4513;
    margin-bottom: 30px;
    padding-top: 30px;
}

.book-header h1 {
    font-size: 2.8rem;
    color: #8b4513;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    font-family: 'Times New Roman', serif;
    letter-spacing: 2px;
    margin-bottom: 10px;
}

.book-header h2 {
    font-size: 1.5rem;
    color: #a0522d;
    font-style: italic;
    font-weight: normal;
}

/* Story Content Styles */
.story-content {
    padding: 0 20px;
}

.story-section {
    margin-bottom: 40px;
    padding: 20px;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(139, 69, 19, 0.1);
    position: relative;
}

.story-section::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(to right, transparent, #d2b48c, transparent);
}

.story-section:first-child {
    margin-top: 20px;
}

.story-section p {
    margin-bottom: 15px;
    text-indent: 20px;
}

.story-section.postscript {
    font-size: 0.9rem;
    background-color: rgba(245, 235, 220, 0.8);
    border-top: 1px dashed #d2b48c;
    border-bottom: 1px dashed #d2b48c;
}

.story-section.postscript p {
    text-indent: 0;
    font-style: italic;
}

.story-section blockquote {
    margin: 20px 0;
    padding: 15px 20px;
    background-color: #f9f1e7;
    border-left: 5px solid #d2b48c;
    font-style: italic;
    color: #6b4c3d;
    position: relative;
    clear: both; /* Prevent blockquotes from wrapping around images */
}

.story-section blockquote::before {
    content: """;
    font-size: 3rem;
    position: absolute;
    top: -10px;
    left: 5px;
    color: #d2b48c;
    font-family: Georgia, serif;
}

.story-section blockquote::after {
    content: """;
    font-size: 3rem;
    position: absolute;
    bottom: -20px;
    right: 5px;
    color: #d2b48c;
    font-family: Georgia, serif;
}

.character {
    font-weight: bold;
    color: #8b4513;
}

.closing {
    text-align: center;
    font-style: italic;
    margin-top: 20px;
    color: #a0522d;
    font-size: 1.2rem;
}

/* Image Styles */
.story-figure {
    margin: 20px 0;
    text-align: center;
    background: #fff8eb;
    padding: 15px;
    border: 1px solid #d2b48c;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(139, 69, 19, 0.1);
    display: flow-root; /* Prevents text overlap issues */
}

.story-figure.left {
    float: left;
    width: 40%;
    margin: 10px 20px 15px 0;
    shape-outside: margin-box;
}

.story-figure.right {
    float: right;
    width: 40%;
    margin: 10px 0 15px 20px;
    shape-outside: margin-box;
}

.story-figure.center {
    width: 80%;
    margin: 20px auto;
    clear: both;
}

.story-figure.left {
    float: left;
    width: 40%;
    margin: 10px 20px 15px 0;
    shape-outside: margin-box;
}

.story-figure.right {
    float: right;
    width: 40%;
    margin: 10px 0 15px 20px;
    shape-outside: margin-box;
}

.story-figure.center {
    width: 80%;
    margin: 20px auto;
    clear: both;
}

.story-figure img {
    max-width: 100%;
    height: auto;
    border-radius: 5px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.story-figure figcaption {
    font-size: 0.9rem;
    color: #8b4513;
    margin-top: 10px;
    font-style: italic;
}

/* Clear floats */
.story-section::before,
.story-section::after {
    content: "";
    display: table;
}

.story-section::after {
    clear: both;
}

/* Ensure proper spacing after floated elements */
.story-section {
    overflow: hidden; /* Creates a new block formatting context */
    padding: 10px 0; /* Add some breathing room */
}

/* Footer Styles */
.book-footer {
    text-align: center;
    padding: 30px 0;
    border-top: 3px double #8b4513;
    margin-top: 30px;
    color: #a0522d;
    font-style: italic;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        font-size: 16px;
    }
    
    .book-container {
        padding: 10px;
    }
    
    .book-header h1 {
        font-size: 2.2rem;
    }
    
    .story-figure.left,
    .story-figure.right {
        float: none;
        width: 100%;
        margin: 20px 0;
    }
    
    .story-figure.center {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .book-header h1 {
        font-size: 1.8rem;
    }
    
    .book-header h2 {
        font-size: 1.2rem;
    }
    
    .story-section {
        padding: 15px;
    }
}

/* Audio Element Styling */
#background-audio {
    display: none; /* Hide the default audio controls */
}

.audio-control-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    padding: 10px 15px;
    background-color: #8b4513;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    font-size: 18px;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Ensure button stays visible on all devices */
    touch-action: manipulation;
}

/* Ensure button remains visible on small screens */
@media (max-width: 480px) {
    .audio-control-btn {
        bottom: 10px;
        right: 10px;
        width: 45px;
        height: 45px;
    }
}

.audio-control-btn:hover {
    background-color: #a0522d;
    transform: scale(1.1);
}

.audio-control-btn.muted {
    opacity: 0.6;
}

/* Storyteller button styling */
.storyteller-btn {
    position: fixed;
    bottom: 140px;
    right: 20px;
    z-index: 1000;
    padding: 10px 15px;
    background-color: #5d4037;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    font-size: 16px;
    width: auto;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Ensure button stays visible on all devices */
    touch-action: manipulation;
}

.storyteller-btn:hover {
    background-color: #8b4513;
    transform: scale(1.05);
}

.storyteller-btn:active {
    transform: scale(0.98);
}

/* Scroll button styling */
.scroll-btn {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 1000;
    padding: 10px 15px;
    background-color: #2c5a8c;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    font-size: 16px;
    width: auto;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Ensure button stays visible on all devices */
    touch-action: manipulation;
}

.scroll-btn:hover {
    background-color: #4a90e2;
    transform: scale(1.05);
}

.scroll-btn:active {
    transform: scale(0.98);
}

/* Back button styling */
.back-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    padding: 10px 15px;
    background-color: #8b4513;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    font-size: 16px;
    width: auto;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Ensure button stays visible on all devices */
    touch-action: manipulation;
}

.back-btn:hover {
    background-color: #a0522d;
    transform: scale(1.05);
}

.back-btn:active {
    transform: scale(0.98);
}

/* Firefox-specific fixes for text overlapping images */
.story-figure.left,
.story-figure.right {
    min-height: 100px; /* Prevent text overlap in Firefox */
}

.story-section blockquote {
    clear: both; /* Prevent blockquotes from wrapping around images in Firefox */
    /* Additional Firefox fix for text-image overlap */
    overflow: hidden;
    margin-top: 15px;
    margin-bottom: 15px;
}