/* ========================================= */
/* --- UNIVERSAL APP CORE STYLES --- */
/* ========================================= */

/* --- UNIVERSAL FIX FOR WIDTH MATH --- */
* {
    box-sizing: border-box; /* THE CRUCIAL FIX for Title Overflow! */
}

/* --- GENERAL RESET --- */
.content-body {
    margin: 0;
    padding: 0;
    /* background-color: var(--brand-white); */
    font-family: 'Courier New', Courier, monospace;
    overflow-y: auto;
    height: 100vh;
}

.content-container {
    padding: 20px;
    margin: 0 auto;
}

/* --- THE UNIVERSAL TETRIS GRID --- */
.masonry-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); 
    grid-auto-flow: dense; /* The magic rule that fills empty holes! */
    gap: 20px; 
    align-items: stretch; /* BUG FIX: Stretch all cells to the full row height */
}

/* Prevent normal cards from vertically stretching to fill newly tall rows */
.masonry-item:not(.expanded) {
    height: fit-content;
}

@media (max-width: 600px) {
    .masonry-grid { grid-template-columns: 1fr; }
}

/* --- THE PROJECT CARD --- */
.masonry-item {
    display: flex;
    flex-direction: column;
    /* border: 3px solid var(--brand-dark);  */
    background-color: var(--brand-dark); 
    cursor: pointer; 
}

/* --- FLEX ORDERING (Thumb is top, Name is middle, Desc is bottom) --- */
.media-thumb { order: 1; width: 100%; height: auto; display: block; }
.expanded-media { order: 2; display: none; }
.project-name { order: 3; }
.project-desc { order: 4; display: none; }

/* --- TEXT & BUTTONS --- */
.project-name {
    font-family: 'PixelFont', monospace; 
    font-size: 14px; 
    font-weight: normal; 
    color: var(--brand-white);             
    background-color: var(--brand-dark);  
    width: 100%;             
    margin: 0;               
    padding: 10px;     
    border-top: 2px solid var(--brand-dark);
    transition: background-color 0.2s, color 0.2s;
}

.project-desc {
    background-color: var(--brand-dark);
    color: var(--brand-white);
    padding: 0 15px 15px 15px; 
    font-family: 'Courier New', Courier, monospace; 
    font-size: 13px;
    line-height: 1.5;
    margin: 0;
}

.masonry-item:hover .project-name {
    background-color: var(--brand-white); 
    color: var(--brand-dark);            
}

.gallery-btn {
    width: 100%;
    background-color: var(--brand-black);
    color: var(--brand-white);
    font-family: 'PixelFont', monospace;
    font-size: 14px;
    padding: 12px;
    margin-top: 20px;
    border: 1px dashed var(--brand-white); 
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s, color 0.2s;
    display: block; 
}

.gallery-btn:hover {
    background-color: var(--brand-white);
    color: var(--brand-black);
}

/* ========================================= */
/* --- EXPANDED STATE (THE ACCORDION) --- */
/* ========================================= */

.masonry-item.expanded {
    grid-column: 1 / -1; /* By default, stretch across all columns */
    margin-top: 10px; 
    margin-bottom: 30px; 

    background-color: var(--brand-black)000;
    transition: background-color 0.3s ease, grid-row-end 0.3s ease;
}

/* 1. Hide thumb, reveal media */
.masonry-item.expanded .media-thumb { display: none; }
.masonry-item.expanded .expanded-media { display: flex; width: 100%; }

/* 2. Reveal text */
.masonry-item.expanded .project-desc { display: block; }

/* 3. FLIP THE TITLE TO THE TOP! */
.masonry-item.expanded .project-name {
    order: 1; /* Swaps position to the top! */
    font-size: 18px; 
    padding: 15px;
    /* background-color: var(--brand-black)000 !important; Locks dark mode */
    color: var(--brand-white) !important;            
    border-bottom: 1px dashed var(--brand-white); 
    border-top: none; 

    background-color: transparent; /* Lets the new card color show through! */
}

.masonry-item.expanded .expanded-media { order: 2; }
.masonry-item.expanded .project-desc { 
order: 3; 
background-color: transparent;}


/* ======================================================= */
/* --- LARGE SCREEN TETRIS LAYOUT (> 1300px) --- */
/* ======================================================= */
@media (min-width: 1300px) {
    
    .masonry-grid {
        grid-template-columns: repeat(3, 1fr); 
    }

    /* 1. Expanded cards take up 2 columns AND 2 rows */
    .masonry-item.expanded {
        grid-column: span 2; 
        grid-row: span 2; 
        margin-top: 0;
        margin-bottom: 0;
        height: fit-content; 
    }
    
    /* 2. Format the video area to a cinematic ultra-wide shape! */
    .masonry-item.expanded .expanded-media {
        background-color: var(--brand-darker);
        position: relative; 
        width: 100%;
        aspect-ratio: 2.3 / 1; /* Creates perfect space for text below */
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
    }

    /* 3. THE MAGIC SHIELD: Use ">" so this ONLY affects standard single videos! */
    .masonry-item.expanded .expanded-media > iframe {
        position: absolute;
        height: 100%;        
        width: auto;         
        max-width: 100%;
        aspect-ratio: 16 / 9;
        border: none;
    }

    /* 4. Ensure the Anthro Machine split-media fills this new box perfectly */
    .masonry-item.expanded .split-media {
        height: 100%;
        width: 100%;
        position: relative;
        z-index: 2;
    }
}
