/* =========================================================
CHARACTER OVERLAY & EXPANDABLE SECTIONS
(Complete Updated Version with Responsive Details Buttons)
   ========================================================= */

/* ================== Full-Page Overlay ================== */
.character-overlay {
    position: fixed; /* CHANGED from absolute to fixed */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none; /* Ensures it does not appear by default */
    flex-direction: column; /* ADDED */
    align-items: center;    /* ADDED */
    justify-content: center; /* CHANGED from flex-start to center */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    overflow-y: auto; /* Allow scrolling */
    pointer-events: auto; /* ADDED: Ensures clicks/taps register on entire overlay */
    overscroll-behavior: contain; /* ADDED: Prevents scrolling outside overlay */
   z-index: 10000; /* now it’s above the main chat but below Sophie’s chat */
}

/* Show Overlay When Active */
.character-overlay.visible {
    display: flex;
    opacity: 1;
    z-index: 10002; /* CHANGED from 1000 to ensure it's above other elements */
    visibility: visible;
    overflow-y: auto;
    pointer-events: auto; /* Keep overlay clickable */
}

/* ================== Overlay Content Box ================== */
.overlay-content {
    background: rgba(20, 20, 20, 0.95);
    padding: 40px;
    max-width: 90vw;
    width: 95%;
    border-radius: 10px;
    text-align: center;
    border: 2px solid #7b0202;
    box-shadow: 0px 0px 20px rgba(139, 0, 0, 0.7);
    /* Removed duplicate overflow-y to avoid confusion */
    overflow-y: auto;
    max-height: 90vh;
    position: relative;
    /* We keep only one overflow-y: auto; above */
}

/* Centered Header Above Image & Traits */
.overlay-header {
    text-align: center;
    font-size: 2em;
    color: #c5c5c5;
    margin-bottom: 10px;
}

/* ================== Overlay Intro (Image & Traits) ================== */
.overlay-intro {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
    text-align: center;
    margin-bottom: 20px;
}

/* Character Image Inside Overlay */
.overlay-intro img {
    width: 180px;
    height: 180px;
    object-fit: cover;
    border-radius: 5px;
    border: 2px solid #7b0202;
}

/* ================== Character Traits ================== */
.character-traits {
    list-style: none;
    padding: 0;
    text-align: left; /* Default to left-aligned on larger screens */
    margin: 0;
}

.character-traits li {
    font-size: 1em;
    color: #c5c5c5;
    margin-bottom: 5px;
}

/* Trait Bullet Points */
.character-traits li::before {
    content: "❖";
    color: #7b0202;
    font-size: 1.2em;
    margin-right: 8px;
}

/* ================== Section Title Styling ================== */
.section-title {
    width: 100%;
    text-align: center;
    font-size: 2em;
    font-weight: bold;
    text-transform: uppercase;
    color: #c5c5c5;
    margin: 30px 0;
    border-bottom: 2px solid #7b0202;
    padding-bottom: 10px;
}

/* ================== Close Button ================== */
.close-overlay {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2em;
    color: #d62727;
    cursor: pointer;
}

/* ================== Expandable Sections Grid ================== */
.expandable-sections {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: 800px;
    margin: 20px auto;
}

/* Two-column grid for main sections (larger screens) */
.expandable-sections-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    justify-content: center;
    justify-items: center; /* Centers the "buttons" */
    width: 100%;
}

/* Ensuring odd button is centered below the others */
.expandable-sections-container details:nth-child(odd):last-child {
    grid-column: span 2;
    justify-self: center;
}

/* ================== <details> "Button" Base Styles ================== */
/* These rules style each <details> element (and its corresponding <summary>) to look like a uniform button */
.expandable-sections details,
.spoiler-sections details {
    display: block; /* Treat each detail as a block-level button */
    background: rgba(30, 30, 30, 0.9);
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #7b0202;
    cursor: pointer;
    text-align: center;
    min-width: 250px;
    max-width: 350px;
    margin: 0 auto 20px; /* Center and add spacing below each "button" */
    transition: all 0.3s ease-in-out;
    pointer-events: auto; /* Ensures touch events are captured */
    user-select: none; /* Prevents accidental text selection */
    -webkit-overflow-scrolling: touch; /* Ensures smooth scrolling */
    overflow-anchor: none; /* Prevents accidental focus jumps */
}

/* Style the <summary> portion to appear uniform */
.expandable-sections details summary,
.spoiler-sections details summary {
    display: block;            /* Force block-level for consistent shape */
    background: transparent;   /* Use parent's background */
    margin: 0;
    padding: 10px 0;
    font-size: 1em;
    font-weight: bold;
    color: #c5c5c5;
    outline: none;             /* Remove focus outline */
    text-align: center;
    list-style: none;          /* Remove default marker if any */
    touch-action: manipulation; /* Ensures taps work */
    -webkit-touch-callout: none;
    -webkit-user-select: none; 
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    pointer-events: auto; /* Allow touch interaction */
}

.expandable-sections details summary {
    touch-action: manipulation; /* Ensures mobile taps register */
    cursor: pointer;
}

/* Remove the default disclosure arrow in WebKit/Blink browsers */
.expandable-sections details summary::-webkit-details-marker,
.spoiler-sections details summary::-webkit-details-marker {
    display: none;
}



/* ================== When <details> is Open (Modal Behavior) ================== */
.expandable-sections details[open],
.spoiler-sections details[open] {
    /* [CHANGED] from absolute to fixed for true viewport centering */
    position: fixed; 
    
    background: rgba(20, 20, 20, 0.98);
    width: 600px;
    max-width: 90vw;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(1);
    box-shadow: 0px 0px 15px rgba(139, 0, 0, 0.6);
    padding: 20px;
    border-radius: 10px;
    transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
    opacity: 1;
    z-index: 2000;
    max-height: 80vh; /* ADDED to ensure content inside is scrollable */
    overflow-y: auto; /* ADDED to allow scrolling if content is long */
}

/* Ensure bullet points in expandable and spoiler sections use ❖ */
.expandable-sections details[open] ul li::before,
.spoiler-sections details[open] ul li::before {
    content: "❖";
    color: #7b0202;
    font-size: 1.2em;
    margin-right: 8px;
}

/* ================== Spoiler Section Heading ================== */
.spoiler-heading {
    width: 100%;
    text-align: center;
    font-size: 1.2em;
    color: #ff4444;
    margin-top: 20px; /* Space from last details section */
    margin-bottom: 10px;
}

/* Two-column grid for Spoilers section (larger screens) */
.spoiler-sections {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    justify-content: center;
    justify-items: center; /* Centers the "buttons" */
    width: 100%;
}

/* Ensuring odd Spoiler button is centered below the others */
.spoiler-sections details:nth-child(odd):last-child {
    grid-column: span 2;
    justify-self: center;
}

/* =========================================================
   RESPONSIVE QUERIES
   ========================================================= */

/* For screens 768px and below, switch the layout to flex and reduce text size */
@media (max-width: 768px) {
    .expandable-sections-container,
    .spoiler-sections {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .expandable-sections details,
    .spoiler-sections details {
        width: 100%;
        max-width: 350px;
        flex: 1 0 auto;
    }
    
    .expandable-sections details summary,
    .spoiler-sections details summary {
        font-size: 0.9em;
        padding: 8px 0;
    }

    /* Center the character traits on mobile */
    .character-traits {
        text-align: center;
    }
    .character-traits li {
        text-align: center;
    }
    .character-traits li::before {
        position: static;   /* Inline bullet */
        margin-right: 5px;
    }
}

/* Extra adjustments for very small screens (≤ 480px) */
@media (max-width: 480px) {
    .overlay-content {
        padding: 20px;
    }
    .overlay-header {
        font-size: 1.5em;
    }
    .overlay-intro img {
        width: 120px;
        height: 120px;
    }
    .character-traits li {
        font-size: 0.9em; /* Slightly smaller text on very narrow screens */
    }
    .expandable-sections details,
    .spoiler-sections details {
        padding: 8px;
        font-size: 0.9em;
    }
}
