/*
 * Icon Carousel System - CSS Styling
 * Based on Implementation Plan from UX agents
 *
 * REFACTORED ARCHITECTURE (Dec 2024):
 * - This file contains SHARED base styles for BOTH NPC and Item carousels
 * - Both carousels use the same revolving door effect and positioning
 * - Item-specific additions (tabs, stats) are in inventory-carousel.css
 *
 * KEY PRINCIPLES:
 * 1. Overflow must be visible on .carousel-track for revolving door effect
 * 2. All carousel items position absolutely from center (left: 50%, margin-left: -40px)
 * 3. Transform translations create the 3D carousel positions
 * 4. Item carousel adds header/stats WITHOUT breaking core mechanics
 */

/* CSS Variables for theming */
:root {
    --carousel-bg: transparent; /* Glass morphism - transparent by default */
    --carousel-bg-hover: rgba(255, 255, 255, 0.08); /* Subtle white on hover */
    --carousel-border: rgba(255, 255, 255, 0.05); /* Very subtle border */
    --carousel-border-hover: rgba(123, 68, 193, 0.3); /* Purple border on hover */
    --carousel-text: #e0e0e0;
    --carousel-accent: #7B44C1; /* Purple accent matching website */
    --carousel-hover: #9966D4; /* Lighter purple for hover states */
    --carousel-shadow: 0 10px 30px rgba(123, 68, 193, 0.2); /* Purple shadow */
    --carousel-radius: 16px;
    --carousel-transition: all 0.3s ease;
    --carousel-gradient: linear-gradient(135deg, rgba(123, 68, 193, 0.1) 0%, transparent 50%, rgba(123, 68, 193, 0.05) 100%);
}

/* Interactive icon pane - container for carousels */
.interactive-icon-pane {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    z-index: 1000;
    pointer-events: none;
}

/* Main carousel container */
#carousel-container,
.carousel-overlay {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    padding: 0;
    width: 100%;
    height: auto;
}

/* Ensure vertical-image-pane is positioned for overlays */
#vertical-image-pane {
    position: relative !important;
    width: 100%;
    height: 100%;
}

/* Individual carousels - Base styles for BOTH carousels */
.carousel {
    background: var(--carousel-bg);
    border: 1px solid var(--carousel-border);
    border-radius: var(--carousel-radius);
    backdrop-filter: none; /* No blur by default */
    -webkit-backdrop-filter: none;
    box-shadow: none; /* No shadow by default */
    flex: 0 1 400px; /* Don't grow, can shrink, base width 400px */
    max-width: 400px;
    min-height: 120px;
    transition: var(--carousel-transition);
    overflow: hidden; /* Hide content outside carousel bounds */
    pointer-events: auto; /* Re-enable clicks on the carousels themselves */
    position: relative;
    cursor: default;
    /* Ensure proper layout context */
    display: block; /* Not flex by default */
}

/* Gradient overlay (hidden by default) */
.carousel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--carousel-gradient);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

/* Glass morphism on hover */
.carousel:hover {
    background: var(--carousel-bg-hover);
    border-color: var(--carousel-border-hover);
    box-shadow: var(--carousel-shadow);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transform: translateY(-2px);
}

.carousel:hover::before {
    opacity: 1;
}

/* Carousel positioning */
.carousel.npc-carousel {
    align-self: flex-end;
    margin-right: auto; /* Keep on left */
}

.carousel.item-carousel {
    align-self: flex-end;
    margin-left: auto; /* Keep on right */
    /* Item carousel specific: handle additional elements */
    display: flex;
    flex-direction: column;
}

/* Item carousel specific layout adjustments */
.item-carousel .carousel-viewport {
    /* Viewport should not shrink below its height */
    flex-shrink: 0;
}

/* Collapsed state */
.carousel.empty {
    display: none;
}

/* Header styles removed - no longer using header */

.carousel-count-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid var(--carousel-accent);
    color: var(--carousel-accent);
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    transition: var(--carousel-transition);
    z-index: 3;
}

.carousel:hover .carousel-count-badge {
    background: var(--carousel-accent);
    color: white;
    box-shadow: 0 0 10px rgba(123, 68, 193, 0.3);
}

/* Viewport - Shared for both carousels */
.carousel-viewport {
    display: flex;
    align-items: center;
    padding: 1rem;
    position: relative;
    z-index: 2; /* Above gradient overlay */
    height: 120px; /* Fixed height for consistency */
    overflow: visible; /* CRITICAL: Allow revolving door effect */
}

.carousel-track {
    flex: 1;
    overflow: visible; /* CRITICAL: Must be visible for revolving door */
    position: relative;
    height: 100px; /* Fixed height for items */
    margin: 0 60px; /* Space for side items */
}

.carousel-items {
    position: relative;
    height: 100%;
    width: 100%;
}

/* Navigation buttons */
.carousel-nav {
    background: rgba(0, 0, 0, 0.5); /* Semi-transparent background for visibility */
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    color: var(--carousel-text);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--carousel-transition);
    flex-shrink: 0;
    position: relative;
    z-index: 10; /* Higher than carousel items (max z-index: 5) */
}

.carousel-nav:hover:not(:disabled) {
    background: rgba(123, 68, 193, 0.2);
    border-color: var(--carousel-accent);
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(123, 68, 193, 0.3);
}

.carousel-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.carousel-prev {
    margin-right: 0.5rem;
}

.carousel-next {
    margin-left: 0.5rem;
}

/* Carousel items - Revolving door effect */
.carousel-item {
    position: absolute;
    display: flex;
    align-items: stretch; /* Allow items to stretch full height */
    height: 100%; /* Use full height */
    justify-content: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    transform: translateX(150%) scale(0.5);
    z-index: 1;
    pointer-events: none;
}

/* Center position - largest */
.carousel-item.active {
    opacity: 1;
    transform: translateX(0) scale(1);
    z-index: 5;
    pointer-events: auto;
    left: 50%;
    margin-left: -40px; /* Half of 80px icon size */
}

/* Side positions - slightly smaller */
.carousel-item.side-left {
    opacity: 0.7;
    transform: translateX(-80px) scale(0.75);
    z-index: 3;
    pointer-events: auto;
    left: 50%;
    margin-left: -40px;
}

.carousel-item.side-left:hover {
    opacity: 0.9;
    transform: translateX(-80px) scale(0.85);
    z-index: 4;
}

.carousel-item.side-right {
    opacity: 0.7;
    transform: translateX(80px) scale(0.75);
    z-index: 3;
    pointer-events: auto;
    left: 50%;
    margin-left: -40px;
}

.carousel-item.side-right:hover {
    opacity: 0.9;
    transform: translateX(80px) scale(0.85);
    z-index: 4;
}

/* Far positions - smallest */
.carousel-item.far-left {
    opacity: 0.4;
    transform: translateX(-140px) scale(0.5);
    z-index: 2;
    pointer-events: none;
    left: 50%;
    margin-left: -40px;
}

.carousel-item.far-right {
    opacity: 0.4;
    transform: translateX(140px) scale(0.5);
    z-index: 2;
    pointer-events: none;
    left: 50%;
    margin-left: -40px;
}

.carousel-item:hover {
    background: rgba(123, 68, 193, 0.1);
    border-radius: 8px;
}

/* Item icon */
.carousel-item .carousel-icon {
    width: 80px;
    height: 100%; /* Fill entire height */
    min-height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.1);
    position: relative;
    flex-shrink: 0;
    transition: var(--carousel-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.carousel-item:hover .carousel-icon {
    border-color: var(--carousel-accent);
    box-shadow: 0 0 15px rgba(123, 68, 193, 0.2);
}

.carousel-item .carousel-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Fill entire container */
}

/* Placeholder icon when no image available */
.carousel-icon-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: rgba(255,255,255,0.05);
}

/* Dialogue indicator */
.dialogue-indicator {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--carousel-accent);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    animation: pulse 2s infinite;
    box-shadow: 0 0 10px rgba(123, 68, 193, 0.5);
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
}

/* Item info */
.carousel-info {
    flex: 1;
    min-width: 0;
}

.carousel-name {
    font-weight: 600;
    color: var(--carousel-text);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.carousel-desc {
    font-size: 0.75rem;
    color: rgba(224,224,224,0.7);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Element badges for Fae */
.element-badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    color: white;
    margin: 0.25rem 0;
}

/* Fae progress bar */
.fae-progress {
    position: relative;
    height: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    margin-top: 0.25rem;
    overflow: hidden;
}

.fae-progress-bar {
    position: absolute;
    height: 100%;
    background: linear-gradient(to right, #6366f1, #818cf8);
    border-radius: 2px;
    transition: width 0.5s ease;
}

.fae-progress-text {
    position: absolute;
    right: 0;
    top: -18px;
    font-size: 0.65rem;
    color: rgba(224,224,224,0.7);
}

/* Item badges */
.item-badges {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    margin-top: 0.25rem;
}

.item-badge {
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
}

.item-badge.takeable {
    background: #3b82f6;
    color: white;
}

.item-badge.holdable {
    background: #10b981;
    color: white;
}

.item-badge.interact {
    background: #f59e0b;
    color: white;
}

/* Item quantity */
.item-quantity {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

/* Carousel indicators */
.carousel-indicators {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.5rem;
    padding-top: 0;
}

.carousel-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    cursor: pointer;
    transition: var(--carousel-transition);
    position: relative;
    z-index: 2;
}

.carousel-indicator.active {
    background: var(--carousel-accent);
    transform: scale(1.5);
    box-shadow: 0 0 5px rgba(123, 68, 193, 0.5);
}

.carousel-indicator:hover {
    background: var(--carousel-hover);
    transform: scale(1.2);
}

/* Empty state */
.carousel-empty {
    text-align: center;
    color: rgba(224,224,224,0.5);
    font-size: 0.85rem;
    padding: 2rem;
}

/* Mobile responsive */
@media (max-width: 768px) {
    #carousel-container,
    .carousel-overlay {
        flex-direction: row; /* Keep side-by-side on mobile */
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .carousel {
        flex: 1;
        max-width: none;
        min-height: 100px;
    }

    .carousel.npc-carousel,
    .carousel.item-carousel {
        margin: 0;
    }

    .carousel-header {
        padding: 0.5rem 0.75rem;
    }

    .carousel-label {
        display: none; /* Hide labels on mobile to save space */
    }

    .carousel-nav {
        width: 28px;
        height: 28px;
    }

    .carousel-item .carousel-icon {
        width: 48px;
        height: 48px;
    }

    .carousel-track {
        height: 60px;
    }
}

/* Tablet responsive */
@media (min-width: 769px) and (max-width: 1024px) {
    .carousel {
        max-width: 350px;
    }
}

/* Accessibility - Focus states */
.carousel-nav:focus-visible,
.carousel-item:focus-visible {
    outline: 2px solid var(--carousel-accent);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .carousel {
        border-width: 2px;
    }

    .carousel-nav {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .carousel-item,
    .carousel-nav,
    .carousel-indicator {
        transition: none;
    }

    @keyframes pulse {
        0%, 100% {
            transform: none;
            opacity: 1;
        }
    }
}

/* Action Menu for NPCs */
.action-menu {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
    background: rgba(0, 0, 0, 0.85);
    padding: 0.5rem;
    border-radius: 8px;
    backdrop-filter: blur(4px);
}

.carousel-icon:hover .action-menu {
    opacity: 1;
    pointer-events: auto;
}

.action-btn {
    width: 32px;
    height: 32px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: rgba(123, 68, 193, 0.3);
    border-color: var(--carousel-accent);
    transform: scale(1.1);
}

.action-btn:active {
    transform: scale(0.95);
}

.action-btn img {
    width: 100%;
    height: 100%;
    filter: brightness(0) invert(1);
    opacity: 0.8;
}

.action-btn:hover img {
    opacity: 1;
}

/* Make sure the carousel icon is positioned relative for the menu */
.carousel-icon {
    position: relative;
    overflow: visible;
}

/* Allow overflow on carousel items to show the menu */
.carousel-item {
    overflow: visible;
}

/* CRITICAL: Ensure track overflow is visible for revolving door effect */
/* This MUST NOT be overridden by any other styles */
.carousel-track,
.npc-carousel .carousel-track,
.item-carousel .carousel-track {
    overflow: visible !important;
}

/* Darken the NPC icon slightly on hover for better menu visibility */
.carousel-icon:hover > img:first-child,
.carousel-icon:hover > .carousel-icon-placeholder {
    filter: brightness(0.7);
}

/* ==========================================================================
   Revolving Door Effect Protection
   These rules ensure the 3D carousel effect works for BOTH carousels
   ========================================================================== */

/* Ensure all carousel items can be positioned properly */
.carousel-items {
    position: relative;
    height: 100%;
    width: 100%;
    /* No display or overflow rules - let items position absolutely */
}

/* Protect the revolving door positioning */
.carousel-item {
    /* Base hidden state is defined earlier */
    /* Active and side states are defined earlier */
    /* This section just ensures no overrides break it */
}

/* Item carousel specific: ensure items align properly despite extra header */
.item-carousel .carousel-item {
    /* Items should be vertically centered in their track */
    top: 50%;
    margin-top: -40px; /* Half of 80px height */
}

/* Both carousels must have consistent track sizing */
.carousel .carousel-track {
    height: 100px; /* Must match item heights */
    position: relative;
    margin: 0 60px; /* Space for side items to peek in */
}