/* ======================================
   Storybook - Responsive Layout
   ====================================== */

#storybook-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100vh;
    background: black;
    overflow: hidden;
    position: relative;
    font-family: "Cardo", serif;
    color: #3b2f23;
}

/* Desktop: Side-by-side layout */
@media (min-width: 768px) {
    /* Interactive pane becomes a flex row container on desktop ONLY when storybook is open */
    body.storybook-open .interactive-pane {
        display: flex;
        flex-direction: row;
        gap: 20px;
        align-items: flex-start;
        justify-content: flex-start;
        max-height: calc(100vh - 150px); /* Limit height to prevent overlap with input */
        overflow: visible; /* Ensure content isn't clipped */
    }

    /* Vertical image pane takes up available space when storybook is open */
    body.storybook-open #vertical-image-pane {
        flex: 1;
        display: block !important;
    }

    /* Storybook container has fixed width when visible */
    body.storybook-open #storybook-container {
        width: 400px;  /* Mobile-like width */
        height: calc(100vh - 150px); /* Account for header and input area */
        position: relative;
        border-radius: 12px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
        flex-shrink: 0;
        display: flex !important;
        flex-direction: column;
        margin-bottom: 0; /* Add some bottom margin */
    }

    /* No margin adjustment needed since it's inside interactive pane */
    body.storybook-open #cool-content-container {
        /* Remove the margin adjustment */
    }

    /* Keep other panes visible on desktop */
    body.storybook-open #vertical-image-pane,
    body.storybook-open #image-pane {
        display: block !important;
    }
}

#storybook-container * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Ensure reader takes up available space in flex container */
#storybook-container #reader {
    flex: 1;
    min-height: 0; /* Important for flex children */
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.6);
    background: linear-gradient(to bottom,#ffffff 0%,#ffffff 100%) padding-box,
    linear-gradient(135deg,#f7e6b5 0%,#d9b25c 30%,#f7e6b5 55%,#b88a2d 80%,#d9b25c 100%) border-box;
}

/* Desktop adjustments for reader */
@media (min-width: 768px) {
    #storybook-container #reader {
        height: calc(100% - 60px); /* Account for controls */
    }
}

#storybook-container .page-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.85);
    z-index: 0;
}

#storybook-container .page-overlay {
    position: relative;
    z-index: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow-y: auto;
    padding: 1.2rem;
    font-size: 1.1rem;
    line-height: 1.7;
    color: #fffbe9;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent 50%);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

#storybook-container .page-overlay h1,
#storybook-container .page-overlay h2,
#storybook-container .page-overlay h3 {
    font-family: "Cinzel", serif;
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1.4rem;
}

#storybook-container .page-overlay #page > p:first-of-type::first-letter {
    font-family: "Cinzel", serif;
    font-size: 3rem;
    float: left;
    padding-right: 0.25rem;
    line-height: 1;
    color: #e3c48a;
}

#storybook-container .gloss {
    border-bottom: 1px dotted #ffd;
    cursor: help;
    position: relative;
    outline: none;
}

#storybook-container .gloss:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,.8);
    color: white;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    white-space: pre-wrap;
    max-width: 80vw;
    font-size: 0.85rem;
    text-align: center;
    z-index: 10;
}

#storybook-container #controls {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.65);
    z-index: 2;
    flex-shrink: 0; /* Prevent controls from shrinking */
    margin-top: auto; /* Push to bottom of flex container */
}

#storybook-container button {
    flex: 1;
    margin: 0 0.5rem;
    padding: 0.6rem 1rem;
    font-size: 1.1rem;
    font-family: "Cinzel", serif;
    background: #333;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease;
}

#storybook-container button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#storybook-container .voice {
    background: #1c304b;
}

#storybook-container #toggleTextBtn {
    background: #2c3e50;
    min-width: auto;
    padding: 0.6rem 0.8rem;
}

#storybook-container #progress {
    min-width: 3rem;
    text-align: center;
    font-size: 1rem;
}

#storybook-container #exit-storybook {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    color: white;
    font-size: 0.95rem;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    z-index: 9999;
    cursor: pointer;
}

#storybook-container #exit-storybook:hover {
    background: rgba(0, 0, 0, 0.9);
}
