/* ==========================================================================
   BOOTSTRAP BAZAAR: GILDED GROVE THEME
   Sprite-mapped version based on uploaded assets
   ========================================================================== */

:root {
    --bazaar-gold: #eeae47;
    --bazaar-gold-glow: rgba(238, 174, 71, 0.6);
    --bazaar-wood-dark: #3e2723;
    --bazaar-wood-medium: #5d4037;
    --bazaar-cream: #f5e6d3;
    --bazaar-text-light: #f7fafc;
    --asset-path: '/static/images/bazaar';
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
    background: #1a1a1a;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* --- 1. The Stage (Background) --- */
.gilded-grove-stage {
    background-image: url('/static/images/bazaar/pantry_scene.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    padding: 60px 0 100px;
    min-height: 100vh;
    color: var(--bazaar-text-light);
}

.gilded-grove-stage::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, rgba(45,27,14,0.3) 0%, rgba(74,55,40,0.2) 50%, rgba(45,27,14,0.3) 100%);
    z-index: 0;
    pointer-events: none;
}

.bazaar-header {
    position: relative;
    z-index: 1;
    text-align: center;
    margin-bottom: 40px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.bazaar-header h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.5rem;
    color: var(--bazaar-gold);
    display: inline-flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
}

.bazaar-header p {
    font-size: 1.1rem;
    opacity: 0.9;
    margin: 0;
}

/* Monarch Butterfly Decorations - from agent_sprites.png row 2 */
.monarch-icon {
    display: inline-block;
    background-image: url('/static/images/bazaar/agent_sprites.png');
    background-repeat: no-repeat;
    image-rendering: pixelated;
}

.monarch-icon.flying {
    width: 40px; 
    height: 40px; 
    background-position: -5px -105px;
    background-size: 200px 200px;
    animation: float 3s ease-in-out infinite;
}

.monarch-icon.resting {
    width: 35px; 
    height: 35px; 
    background-position: -55px -108px;
    background-size: 200px 200px;
}

@keyframes float { 
    0%, 100% { transform: translateY(0) rotate(-5deg); } 
    50% { transform: translateY(-10px) rotate(5deg); } 
}


/* --- 2. Category Navigation --- */
.bazaar-categories {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 40px;
}

.category-btn {
    background: linear-gradient(180deg, var(--bazaar-wood-medium) 0%, var(--bazaar-wood-dark) 100%);
    border: 2px solid var(--bazaar-gold);
    color: var(--bazaar-cream);
    padding: 12px 24px;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.category-btn:hover {
    background: linear-gradient(180deg, #6d4c41 0%, var(--bazaar-wood-medium) 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(238, 174, 71, 0.3);
}

.category-btn.active {
    background: var(--bazaar-gold);
    color: var(--bazaar-wood-dark);
    box-shadow: 0 0 20px var(--bazaar-gold-glow);
}


/* --- 3. The Product Grid & Items --- */
.bazaar-grid {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 40px 30px;
    padding-top: 30px;
}

.bazaar-grid.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.loading-spinner {
    font-family: 'Orbitron', sans-serif;
    color: var(--bazaar-gold);
    font-size: 1.2rem;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.bazaar-item {
    position: relative;
    cursor: pointer;
    text-align: center;
    transition: transform 0.3s ease;
    z-index: 1;
    padding: 20px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    border: 1px solid rgba(238, 174, 71, 0.2);
}

.bazaar-item:hover {
    transform: translateY(-10px) scale(1.02);
    z-index: 10;
    border-color: var(--bazaar-gold);
    box-shadow: 0 10px 40px rgba(238, 174, 71, 0.3);
}

/* Layer 1: Contact Shadow */
.item-shadow {
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 30px;
    background: radial-gradient(ellipse, rgba(0,0,0,0.5) 0%, transparent 70%);
    z-index: -2;
}

/* Layer 2: Hover Glow - using golden ring from ui_sprites.png */
.item-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    width: 180px;
    height: 180px;
    background-image: url('/static/images/bazaar/ui_sprites.png');
    background-position: -35px -145px;
    background-size: 200px 200px;
    background-repeat: no-repeat;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: -1;
    pointer-events: none;
}

.bazaar-item:hover .item-glow {
    opacity: 0.8;
    transform: translate(-50%, -50%) scale(1.2);
    animation: pulseGlow 2s infinite;
}

@keyframes pulseGlow { 
    0%, 100% { opacity: 0.6; } 
    50% { opacity: 1; } 
}

/* Layer 3: Product Image & Info */
.item-img-container {
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    filter: sepia(0.15) contrast(1.05);
    transition: filter 0.3s;
}

.bazaar-item:hover .item-img-container {
    filter: sepia(0) contrast(1);
}

.item-img-container img {
    max-width: 90%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 5px 10px rgba(0,0,0,0.3));
    transition: transform 0.3s ease;
}

.bazaar-item:hover .item-img-container img {
    transform: scale(1.05);
}

.item-info h3 {
    font-size: 1rem;
    margin: 0 0 8px 0;
    color: var(--bazaar-cream);
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    line-height: 1.3;
    min-height: 2.6em;
}

.item-info .price {
    color: var(--bazaar-gold);
    font-weight: 700;
    font-size: 1.3rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.item-info .rating {
    font-size: 0.85rem;
    color: var(--bazaar-cream);
    opacity: 0.8;
    margin-top: 5px;
}

.item-info .rating .stars {
    color: var(--bazaar-gold);
}


/* ================= THE HUBB DISPLAY MODAL ================= */

.hubb-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.hubb-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.hubb-overlay.hidden {
    display: none;
}

.hubb-container {
    position: relative;
    width: 90%;
    max-width: 700px;
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn { 
    from { transform: scale(0.5); opacity: 0; } 
    to { opacity: 1; } 
}

/* --- The Rustic Frame Background --- */
.hubb-frame-bg {
    position: relative;
    background: linear-gradient(145deg, #4a3728 0%, #2d1b0e 50%, #3e2723 100%);
    border: 4px solid var(--bazaar-gold);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 
        0 0 0 8px var(--bazaar-wood-dark),
        0 0 40px rgba(238, 174, 71, 0.4),
        inset 0 0 60px rgba(0,0,0,0.5);
    display: grid;
    grid-template-columns: 1fr 150px;
    grid-template-rows: auto auto auto auto;
    gap: 20px;
}

/* --- Close Button --- */
.hubb-close-btn {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 45px;
    height: 45px;
    background: var(--bazaar-wood-dark);
    color: var(--bazaar-gold);
    border: 3px solid var(--bazaar-gold);
    border-radius: 50%;
    font-size: 1.8rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    transition: all 0.2s;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.hubb-close-btn:hover {
    background: var(--bazaar-gold);
    color: var(--bazaar-wood-dark);
    transform: scale(1.1);
}

/* --- 1. Title & Price --- */
.hubb-title-bar {
    grid-column: 1 / -1;
    text-align: center;
    padding: 15px 20px;
    background: linear-gradient(90deg, transparent, rgba(238, 174, 71, 0.2), transparent);
    border-bottom: 2px solid var(--bazaar-gold);
}

.hubb-title-bar h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.3rem;
    color: var(--bazaar-cream);
    margin: 0 0 5px 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.hubb-price {
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--bazaar-gold);
}

/* --- 2. Product Display Window --- */
.hubb-window-area {
    grid-column: 1;
    grid-row: 2;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(238, 174, 71, 0.3);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 250px;
}

.hubb-window-area img {
    max-width: 100%;
    max-height: 220px;
    object-fit: contain;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.4));
}

/* --- 3. Agent Corner - using sprite for frame --- */
.hubb-agent-corner {
    grid-column: 2;
    grid-row: 2;
    text-align: center;
    padding: 10px;
}

.agent-frame {
    width: 120px;
    height: 120px;
    margin: 0 auto 10px;
    border: 3px solid var(--bazaar-gold);
    border-radius: 50%;
    overflow: hidden;
    background: var(--bazaar-wood-dark);
    box-shadow: 0 0 20px var(--bazaar-gold-glow);
    position: relative;
}

/* Agent sprite from agent_sprites.png - bottom row has agent portraits */
.agent-sprite {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Using existing individual agent images for better quality */
.agent-sprite.resi { background-image: url('/static/resi_1.png'); }
.agent-sprite.charles { background-image: url('/static/charles_1.png'); }
.agent-sprite.becky { background-image: url('/static/becky_1.png'); }
.agent-sprite.hawk { background-image: url('/static/hawk_1.png'); }
.agent-sprite.tally { background-image: url('/static/tally_1.png'); }
.agent-sprite.spike { background-image: url('/static/spike_1.png'); }

/* Fallback using sprite sheet portraits */
.agent-sprite.resi-sprite { 
    background-image: url('/static/images/bazaar/agent_sprites.png');
    background-position: -150px -150px;
    background-size: 200px 200px;
}
.agent-sprite.charles-sprite { 
    background-image: url('/static/images/bazaar/agent_sprites.png');
    background-position: 0px -150px;
    background-size: 200px 200px;
}
.agent-sprite.becky-sprite { 
    background-image: url('/static/images/bazaar/agent_sprites.png');
    background-position: -50px -150px;
    background-size: 200px 200px;
}
.agent-sprite.hawk-sprite { 
    background-image: url('/static/images/bazaar/agent_sprites.png');
    background-position: -100px -150px;
    background-size: 200px 200px;
}

.agent-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.agent-label span {
    display: block;
}

#hubb-agent-name {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    color: var(--bazaar-gold);
    font-weight: 700;
}

#hubb-agent-role {
    font-size: 0.8rem;
    color: var(--bazaar-cream);
    opacity: 0.8;
}

/* --- 4. Speech Bubble - using parchment from ui_sprites.png --- */
.hubb-speech-bubble {
    grid-column: 1 / -1;
    grid-row: 3;
    background: var(--bazaar-cream);
    color: var(--bazaar-wood-dark);
    padding: 20px 25px;
    border-radius: 15px;
    position: relative;
    font-family: 'Poppins', serif;
    font-weight: 500;
    font-style: italic;
    font-size: 1rem;
    line-height: 1.5;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    /* Optional: use sprite parchment as background
    background-image: url('/static/images/bazaar/ui_sprites.png');
    background-position: 0px -85px;
    background-size: 200px 200px;
    */
}

.hubb-speech-bubble::before {
    content: '';
    position: absolute;
    top: -15px;
    right: 80px;
    border: 10px solid transparent;
    border-bottom-color: var(--bazaar-cream);
}

#hubb-agent-advice {
    margin: 0;
}

/* --- 5. Action Button - styled like wood button sprite --- */
#hubb-add-to-cart-btn {
    grid-column: 1 / -1;
    grid-row: 4;
    justify-self: center;
    background: linear-gradient(180deg, var(--bazaar-gold) 0%, #d49a3a 100%);
    border: 3px solid var(--bazaar-wood-dark);
    color: var(--bazaar-wood-dark);
    padding: 15px 50px;
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s;
    box-shadow: 0 5px 20px rgba(0,0,0,0.4);
}

#hubb-add-to-cart-btn:hover {
    background: linear-gradient(180deg, #f5c565 0%, var(--bazaar-gold) 100%);
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(238, 174, 71, 0.5);
}

#hubb-add-to-cart-btn:active {
    transform: translateY(1px);
    box-shadow: 0 3px 10px rgba(0,0,0,0.4);
}


/* ================= RESPONSIVE ADJUSTMENTS ================= */

@media (max-width: 768px) {
    .bazaar-header h2 {
        font-size: 1.8rem;
    }
    
    .bazaar-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
    
    .hubb-frame-bg {
        grid-template-columns: 1fr;
        padding: 20px;
    }
    
    .hubb-agent-corner {
        grid-column: 1;
        grid-row: 2;
        display: flex;
        align-items: center;
        gap: 15px;
    }
    
    .agent-frame {
        width: 80px;
        height: 80px;
        margin: 0;
    }
    
    .hubb-window-area {
        grid-row: 3;
        min-height: 200px;
    }
    
    .hubb-speech-bubble {
        grid-row: 4;
    }
    
    #hubb-add-to-cart-btn {
        grid-row: 5;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .bazaar-grid {
        grid-template-columns: 1fr;
    }
    
    .category-btn {
        padding: 10px 16px;
        font-size: 0.75rem;
    }
    
    .monarch-icon {
        display: none;
    }
}


/* ==========================================================================
   GILDED GROVE ENHANCEMENTS - Global polish
   ========================================================================== */

/* Smooth transitions for all interactive elements */
a, button, .bazaar-item, .product-card, .category-btn, .cat-pill {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Gold glow effect on focus for accessibility */
*:focus-visible {
    outline: 2px solid var(--bazaar-gold);
    outline-offset: 2px;
}

/* Custom scrollbar for Gilded Grove theme */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bazaar-wood-dark);
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--bazaar-gold) 0%, #d49a3a 100%);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #f5c565 0%, var(--bazaar-gold) 100%);
}

/* Selection color matching theme */
::selection {
    background: var(--bazaar-gold);
    color: var(--bazaar-wood-dark);
}

/* Subtle wood grain texture overlay for cards */
.bazaar-item::after,
.product-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.8" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23n)" opacity="0.03"/></svg>');
    pointer-events: none;
    border-radius: inherit;
    z-index: -1;
}
