/* Complete Reset & Core Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: #1E1B18; /* Deep warm charcoal/espresso */
    color: #D4B886; /* Soft amber nightlight glow */
    font-family: 'Quicksand', sans-serif;
    font-weight: 500;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    overflow-x: hidden;
}

header {
    width: 100%;
    max-width: 900px;
    text-align: center;
    margin-bottom: 25px;
}

h1 {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

p#site-subtitle {
    font-size: 1.2rem;
    font-weight: 600;
    opacity: 0.8;
    margin-bottom: 20px;
    color: #C2A678;
}

/* Language Toggles */
.toggle-container {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.lang-toggle {
    font-family: 'Fredoka', sans-serif;
    background-color: #2D2722;
    color: #D4B886;
    border: 2px solid #3A322B;
    padding: 12px 26px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lang-toggle.active {
    background-color: #D4B886;
    color: #1E1B18;
    border-color: #D4B886;
    box-shadow: 0 0 12px rgba(212, 184, 134, 0.4);
}

/* Main Layout Structure */
main {
    width: 100%;
    max-width: 1200px; /* Expanded grid container to comfortably hold the larger book frame */
    display: flex;
    flex-direction: column;
    gap: 40px;
}

/* Book Frame Wrapper Container */
#player-wrapper {
    position: relative;
    width: 100%;
    max-width: 850px; /* SCALED UP: Expanded from 950px to make the overall book graphics noticeably larger */
    margin: 2rem auto 5.5rem auto; 
    background-image: url('book.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    aspect-ratio: 2 / 1; 
}

/* Presentation Window Layer - Directly handles fitting video inside pages */
.video-screen-clip {
    position: absolute;
    /* ADJUST THESE VALUES to nudge/align your video viewport exactly with your asset pages */
    top: 6%;       /* Decreased from 10% to push video closer to top edges of the open book pages */
    bottom: 6%;    /* Decreased from 10% to drop video lower into the bottom edges of the pages */
    left: 15%;      /* Pushes the margins wider outwards onto the left page */
    right: 15%;     /* Pushes the margins wider outwards onto the right page */
    border-radius: 10px; 
    overflow: hidden; 
    background-color: #1C1008; 
    transform: translateZ(0); 
    
    display: flex;
    justify-content: center;
    align-items: center;
}

/* HTML5 Video Element */
#story-player {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Changed from 'cover' to 'contain' to prevent cropping your asset artwork inside pages */
    display: block;
    border-radius: 12px;
}

/* Standardized fluid typography with a strong halo effect and custom orange color */
::cue, video::cue {
    background: transparent !important;
    background-color: transparent !important;
    color: #FF8A3D !important;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    
    text-shadow: 
        -2px -2px 4px #1E1B18,  2px -2px 4px #1E1B18, 
        -2px  2px 4px #1E1B18,  2px  2px 4px #1E1B18,
        -3px  0px 6px #1E1B18,  3px  0px 6px #1E1B18,
         0px -3px 6px #1E1B18,  0px  3px 6px #1E1B18,
         0px  0px 12px rgba(0, 0, 0, 0.9);

    font-size: clamp(1.1rem, 3.8vw, 2.2rem) !important;
}

video::-webkit-media-text-track-display {
    background: transparent !important;
}

video::-webkit-media-text-track-display-backdrop {
    background: transparent !important;
}

/* Mute Notification Toast UI */
.mute-banner {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(45, 39, 34, 0.9);
    color: #D4B886;
    font-family: 'Fredoka', sans-serif;
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: 20px;
    border: 1px solid #4A3F35;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
    z-index: 10;
    pointer-events: none;
    white-space: nowrap;
}

.mute-banner.visible {
    opacity: 1;
    visibility: visible;
    top: 25px;
}

/* Cast Button Setup */
.cast-button-container {
    position: absolute;
    bottom: -55px; 
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
}

.cast-btn {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    background-color: #8C6D47; 
    color: #FFFFFF;
    border: none;
    padding: 10px 22px;
    font-size: 1rem;
    border-radius: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease-in-out;
}

.cast-btn:hover {
    background-color: #705535;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

/* Library Grid Selection UI */
.library-section {
    width: 100%;
}

.library-section h2 {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 20px;
    text-align: center;
    opacity: 0.9;
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.book-card {
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    background-color: #2D2722;
    border: 2px solid #3A322B;
    color: #D4B886;
    padding: 20px;
    border-radius: 18px;
    font-size: 1.25rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.book-card:hover {
    border-color: #D4B886;
    background-color: #3A322B;
    transform: translateY(-2px);
}

.book-card.playing {
    border-color: #D4B886;
    background-color: #4A3F35;
    box-shadow: 0 0 15px rgba(212, 184, 134, 0.2);
}

footer {
    margin-top: 50px;
    padding: 20px;
    font-size: 0.9rem;
    opacity: 0.4;
}

@media (max-width: 600px) {
    h1 { font-size: 2rem; }
    .library-grid { grid-template-columns: 1fr; }
    .book-card { padding: 25px; text-align: center; }
}

/* Transcript Toggle Container */
.transcript-section {
    width: 100%;
    max-width: 900px;
    margin: -10px auto 40px auto; /* Pulls it up slightly closer to the book */
    text-align: center;
}

/* The Toggle Button */
.transcript-btn {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    background: transparent;
    color: #C2A678;
    border: 2px solid #4A3F35;
    padding: 10px 24px;
    font-size: 1.1rem;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.transcript-btn:hover {
    background-color: #3A322B;
    border-color: #C2A678;
}

/* The Expanding Text Box */
.transcript-box {
    margin-top: 15px;
    background-color: #2D2722;
    border: 1px solid #4A3F35;
    border-radius: 12px;
    padding: 25px;
    max-height: 400px; /* Sets how tall it gets before requiring a scrollbar */
    overflow-y: auto;
    text-align: left;
    transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.4s ease;
    opacity: 1;
}

/* The Hidden State */
.transcript-box.hidden {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    overflow: hidden;
    border-color: transparent;
}

/* The Text Itself */
#transcript-text {
    font-family: 'Quicksand', sans-serif;
    font-size: 1.2rem;
    line-height: 1.7;
    color: #E6D5B8;
    white-space: pre-wrap; /* Crucial: respects the line breaks in your .txt files */
}

/* Custom Scrollbar for the text box */
.transcript-box::-webkit-scrollbar {
    width: 8px;
}
.transcript-box::-webkit-scrollbar-track {
    background: #1E1B18; 
    border-radius: 10px;
}
.transcript-box::-webkit-scrollbar-thumb {
    background: #8C6D47; 
    border-radius: 10px;
}