/* --- START OF FILE style.css --- */

/* =========================================
   1. VARIABLES & BASE SETUP (Aurora Effect)
   ========================================= */
:root {
    /* Dynamic Aurora Colors (Updated by JS based on Genre) */
    --aurora-color: rgba(60, 20, 100, 0.4);
    --aurora-color-secondary: rgba(20, 20, 60, 0.2);
    --mouse-x: 50%;
    --mouse-y: 50%;
}

body {
    background-color: #050505;
    color: white;
    overflow-x: hidden;
    position: relative;
    /* Aurora Background Effect */
    background-image: 
        radial-gradient(circle at 10% 20%, var(--aurora-color) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, var(--aurora-color-secondary) 0%, transparent 40%);
    background-attachment: fixed;
    transition: background-image 1s ease-in-out;
}

/* Premium Noise Texture Overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1; /* Lowest layer */
    pointer-events: none;
    opacity: 0.07;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    mix-blend-mode: overlay;
}

/* Subtle Paper Grain */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='turbulence' baseFrequency='0.65' numOctaves='3' seed='2'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23grain)' opacity='0.5'/%3E%3C/svg%3E");
    background-size: 150px 150px;
    animation: grain-shift 8s steps(10) infinite;
}

@keyframes grain-shift {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-5%, -10%); }
    20% { transform: translate(-15%, 5%); }
    30% { transform: translate(7%, -25%); }
    40% { transform: translate(-5%, 25%); }
    50% { transform: translate(-15%, 10%); }
    60% { transform: translate(15%, 0%); }
    70% { transform: translate(0%, 15%); }
    80% { transform: translate(3%, 25%); }
    90% { transform: translate(-10%, 10%); }
}

/* =========================================
   2. WEBGL & FALLBACK
   ========================================= */
#webgl-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0; /* Behind content, above aurora bg */
}

/* Fallback for WebGL failure */
.fallback-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: radial-gradient(circle at center, #1a1a1a 0%, #000000 100%);
    display: none;
}
.fallback-active .fallback-bg {
    display: block;
}

/* =========================================
   3. LAYOUT & CARDS (Shiny Border)
   ========================================= */
.perspective-container {
    perspective: 1000px;
    position: relative;
    z-index: 10;
}

#tilt-wrapper {
    transform-style: preserve-3d;
    transition: transform 0.1s ease-out; /* Parallax speed */
}

.split-card-container {
    height: 75vh;
    max-height: 750px;
    border-radius: 2.5rem;
    overflow: hidden;
    position: relative;
    z-index: 20;
    
    /* Glassmorphism */
    background: rgba(26, 26, 26, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 
        0 8px 32px 0 rgba(0, 0, 0, 0.37),
        inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
        
    transition: height 0.3s ease, width 0.3s ease;
    
    /* Float Animation */
    animation: float-card 6s ease-in-out infinite;
}

@keyframes float-card {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

/* Shiny Border Effect (Category A) */
.split-card-container::after {
    content: '';
    position: absolute;
    inset: -1px;
    z-index: -1;
    border-radius: inherit;
    background: radial-gradient(
        400px circle at var(--mouse-x) var(--mouse-y),
        rgba(255, 255, 255, 0.3),
        transparent 40%
    );
    opacity: 0.7;
    pointer-events: none;
}

.split-card-container.desktop-mode {
    height: 300px;
    width: 100%;
    border-radius: 1.5rem;
}

/* Center Connector */
.plus-connector {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
    background: rgba(26, 26, 26, 0.6);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.15);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5), inset 0 1px 0 0 rgba(255, 255, 255, 0.1);
    transition: transform 0.2s ease;
}

.plus-connector:hover {
    transform: translate(-50%, -50%) scale(1.1);
}

/* =========================================
   4. CAROUSEL (Transitions)
   ========================================= */
.carousel-track {
    display: flex;
    transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
}

.carousel-item {
    min-width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background-size: cover;
    background-position: center;
    
    /* Category B: Scale/Fade Transitions */
    transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.6s ease, filter 0.6s ease;
    transform: scale(0.9);
    opacity: 0.3;
    filter: grayscale(100%) blur(2px);
}

.carousel-item.is-active {
    transform: scale(1);
    opacity: 1;
    filter: grayscale(0%) blur(0px);
}

.carousel-overlay {
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.7));
    backdrop-filter: blur(2px);
    pointer-events: none;
}

/* =========================================
   5. CONTROLS (Magnetic & Navigation)
   ========================================= */
.btn-haptic {
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease;
    will-change: transform;
    cursor: pointer;
}

.btn-haptic:active {
    transform: scale(0.95); /* Adjusted for JS magnetic effect */
}

/* Navigation Arrows */
.group button[onclick*="Slide"] {
    position: absolute;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    opacity: 0; /* Hidden by default until hover */
}

.group:hover button[onclick*="Slide"] {
    opacity: 1;
}

.group button[onclick*="Slide"]:hover {
    background-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.split-card-container.generating-active button[onclick*="Slide"] {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* =========================================
   6. GENERATION & EFFECTS (Confetti)
   ========================================= */
#generation-overlay {
    border-radius: 2.5rem;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(16px);
}

#generation-overlay.desktop-mode {
    border-radius: 1.5rem;
}

#webgl-generation-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.pulse-glow {
    animation: pulse-glow 2s ease-in-out infinite;
}

/* Confetti Particle */
.confetti {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
}

/* =========================================
   History Catalog Styles 
   ========================================= */

#history-list {
    display: grid;
    /* Responsive Columns: At least 150px wide, filling space */
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); 
    gap: 1rem;
    padding: 1.5rem;
    padding-bottom: 150px;
    width: 100%;
    /* Ensure grid respects box model */
    box-sizing: border-box;
    /* Align items to start to prevent stretching weirdness */
    align-items: start;
}

.history-card {
    position: relative;
    width: 100%;
    /* THE FIX: Force 9:16 Aspect Ratio using Padding Hack */
    /* 16 / 9 = 1.777... -> 177.77% */
    padding-bottom: 177.77%; 
    height: 0; /* Collapse actual height, rely on padding */
    
    background: #1a1a1a;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    
    /* Animation */
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.history-card.reveal {
    opacity: 1;
    transform: scale(1);
}

/* Image is absolute to fit the padding box */
.history-card-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s ease;
    z-index: 1;
}

.history-card:hover .history-card-img {
    transform: scale(1.05);
}

/* --- OVERLAY & BUTTONS --- */
.history-actions-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    /* Stronger gradient for readability */
    background: linear-gradient(to top, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.3) 40%, transparent 100%);
    
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0.75rem;
    
    /* Interaction */
    opacity: 0;
    transition: opacity 0.2s ease;
}

.history-card:hover .history-actions-overlay {
    opacity: 1;
}

/* Genre Label (Top Left of Card) */
.overlay-info {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 20;
    pointer-events: none;
}
.overlay-title {
    font-size: 0.65rem;
    font-weight: 800;
    color: rgba(255,255,255,0.9);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(0,0,0,0.5);
    padding: 2px 6px;
    border-radius: 4px;
    backdrop-filter: blur(4px);
}

/* Buttons */
.history-btn-group {
    display: flex;
    gap: 0.4rem;
    width: 100%;
}

.catalog-btn {
    flex: 1;
    height: 32px; /* Compact buttons */
    border-radius: 0.4rem;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    cursor: pointer;
}

.catalog-btn:hover {
    background: white;
    color: black;
    transform: translateY(-2px);
}

.catalog-btn svg {
    width: 14px;
    height: 14px;
}

/* Delete specific hover */
.btn-delete:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

/* Favorite Star */
.history-fav-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 20;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(4px);
    border-radius: 50%;
    padding: 6px;
    color: white;
    opacity: 0;
    transition: opacity 0.2s;
}

.history-card:hover .history-fav-btn, 
.history-fav-btn.active {
    opacity: 1;
}

.history-fav-btn.active {
    color: #fbbf24;
    fill: #fbbf24;
}

/* --- MOBILE FIXES --- */
@media (max-width: 640px) {
    #history-list {
        grid-template-columns: repeat(2, 1fr); /* 2 Columns */
        gap: 0.5rem;
        padding: 0.75rem;
    }

    /* Always show buttons on mobile */
    .history-actions-overlay {
        opacity: 1 !important;
        background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, transparent 50%);
    }
    
    .history-fav-btn {
        opacity: 1 !important;
    }
}
/* =========================================
   8. UTILITIES & MODALS
   ========================================= */
/* Color Dots */
.color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
    border: 2px solid transparent;
}
.color-dot:hover { transform: scale(1.2); }
.color-dot.selected { 
    transform: scale(1.3); 
    border-color: white; 
    box-shadow: 0 0 10px rgba(255,255,255,0.3);
}

/* Advanced Controls Panel */
.advanced-controls {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0, 1, 0, 1), opacity 0.4s ease;
    opacity: 0;
}
.advanced-controls.expanded {
    max-height: 400px;
    opacity: 1;
    margin-top: 1rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translate(-50%, 100px);
    background: rgba(20, 20, 20, 0.9);
    border: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(10px);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.success i { color: #10b981; }
.toast.error i { color: #ef4444; }

/* =========================================
   FIXED SHARE MENU (Center Popup)
   ========================================= */

.share-menu {
    position: fixed; /* Breaks out of the button container */
    top: 50%;
    left: 50%;
    /* Start slightly smaller for pop-in animation */
    transform: translate(-50%, -50%) scale(0.9);
    
    /* Visuals */
    background: rgba(20, 20, 20, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border-radius: 1.5rem;
    padding: 1.5rem;
    
    /* Layout */
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    z-index: 100; /* Ensure it's above the image */
    
    /* Animation State: Hidden */
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.share-menu::before {
    content: 'SHARE';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: #fbbf24;
    color: black;
    font-size: 0.6rem;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 1px;
}

.share-menu.active {
    opacity: 1;
    pointer-events: auto;
    /* End State: Centered and full size */
    transform: translate(-50%, -50%) scale(1);
}

/* Make the buttons inside larger for the popup */
.share-btn {
    width: 56px;
    height: 56px;
    padding: 0;
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.share-btn:hover {
    background: white;
    color: black;
    transform: translateY(-3px);
}

.share-btn svg {
    width: 24px;
    height: 24px;
}

/* =========================================
   9. RESPONSIVE ADJUSTMENTS
   ========================================= */
@media (max-width: 640px) {
    .split-card-container {
        height: 65vh;
        max-height: 650px;
    }

    #history-drawer {
        width: 100%;
    }
    
    #history-list {
        grid-template-columns: repeat(2, 1fr); /* 2 Columns on Mobile */
        gap: 0.5rem;
        padding: 0.5rem;
    }
    
    .history-card-image-wrapper {
        aspect-ratio: 1/1.5; /* Slightly taller aspect ratio on mobile */
    }
    
    /* Force Overlay Visible on Mobile so buttons are clickable */
    .history-actions-overlay {
        opacity: 1 !important;
        background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 40%);
        padding-bottom: 0.5rem;
    }
    
    /* Hide the text info on mobile to save space (Pinterest style) */
    .history-info {
        display: none; 
    }
    
    /* Make buttons slightly smaller on mobile to fit */
    .catalog-btn {
        height: 32px;
    }
    .catalog-btn i {
        width: 14px;
        height: 14px;
    }
    
    .history-fav-btn {
        opacity: 1 !important;
        transform: scale(1) !important;
        top: 5px;
        right: 5px;
        padding: 5px;
    }
}