/* Reference Carousel (Level 2) */
.reference-carousel {
    position: relative;
    height: 100vh;
    overflow: hidden;
    background: var(--background-primary);
    display: none;
    align-items: center;
    justify-content: center;
}

.reference-carousel.active {
    display: flex;
}

/* Reference List Container (for horizontal carousel) - FIX 1: Container Background */
.reference-carousel .reference-list {
    position: relative;
    width: 100vw; /* Full viewport width to prevent shadow clipping */
    height: 100vh; /* Full viewport height for mobile consistency */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--background-primary); /* Match page background for invisible container */
    margin-left: calc(-50vw + 50%); /* Center full-width container within page */
}

/* Reference Cards - 3D Design with Enhanced Shadow Space */
.reference-carousel .reference-list .reference-item {
    position: absolute;
    width: var(--reference-card-width);
    height: var(--reference-card-height);
    aspect-ratio: 2.5 / 3.5; /* Correct playing card aspect ratio */
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3); /* Enhanced shadow for better visibility */
    background: var(--card-bg);
    border: none;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* FIX 3: Reduced for total 0.5s sequence */
    cursor: pointer;
    transform-style: preserve-3d;
    backface-visibility: hidden;
    perspective: 1000px;
    min-width: 0; /* Prevent flex/grid expansion */
    max-width: 100vw; /* Absolute maximum to prevent viewport overflow */
}

/* Reference Card Content Structure - FoundContext 3-Section Layout */
.reference-card-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    border-radius: 20px;
    min-height: 0; /* Allow flex items to shrink */
}

.reference-card-content .reference-header {
    flex-shrink: 0;
    padding: 1.5rem;
    background: var(--theater-burgundy);
    color: var(--header-text);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    margin: 0;
}

.reference-card-content .reference-title {
    font-family: var(--card-deck-font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--header-text);
    margin: 0;
    line-height: 1.3;
}

.reference-card-content .reference-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--card-bg);
    scrollbar-width: thin;
    scrollbar-color: var(--neutral-400) transparent;
    min-height: 0; /* Allow body to shrink and keep footer visible */
}

.reference-card-content .reference-section {
    margin-bottom: 1rem;
}

.reference-card-content .reference-section h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--section-heading);
    margin: 0 0 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.reference-card-content .reference-section p {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-secondary);
    margin: 0;
}

.reference-card-content .reference-footer {
    flex-shrink: 0;
    padding: 1.5rem;
    background: var(--footer-bg);
    color: var(--footer-text);
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    margin: 0;
}

.reference-card-content .reference-footer h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--footer-text);
    margin: 0 0 0.75rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Horizontal Reference Positioning - HORIZONTAL ONLY */
.reference-carousel .reference-list .reference-item:nth-child(1) {
    transform: translateX(-120%);
    opacity: 0; /* Hide adjacent cards to prevent visibility when container is full width */
    pointer-events: none;
    z-index: 3;
    filter: blur(2px);
}

.reference-carousel .reference-list .reference-item:nth-child(2) {
    transform: translateX(0%);
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
    filter: blur(0px);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3);
}

.reference-carousel .reference-list .reference-item:nth-child(3) {
    transform: translateX(120%);
    opacity: 0; /* Hide adjacent cards to prevent visibility when container is full width */
    pointer-events: none;
    z-index: 3;
    filter: blur(2px);
}

/* Hide items beyond 3rd position for horizontal carousel */
.reference-carousel .reference-list .reference-item:nth-child(n + 4) {
    opacity: 0;
    pointer-events: none;
    transform: translateX(200%) scale(0.5);
    z-index: 1;
}

/* Card Content */
.item-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Poster Background */
.item-poster {
    flex: 1;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
}

/* Card Overlay Information */
.item-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.9));
    color: white;
    padding: 1.5rem;
    transform: translateY(0);
    transition: all 0.3s ease;
}

.item:hover .item-overlay {
    background: linear-gradient(transparent, rgba(0,0,0,0.95));
}

.item-title {
    font-family: var(--card-deck-font-display);
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    line-height: 1.2;
}

.item-meta {
    font-size: 0.9rem;
    opacity: 0.9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.item-year {
    font-weight: 500;
}

.item-count {
    background: rgba(255,255,255,0.2);
    padding: 0.2rem 0.8rem;
    border-radius: 12px;
    font-size: 0.8rem;
}

/* Footer Navigation */
.reference-navigation {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    z-index: 1000;
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.1);
    transform: translateY(100%);
    transition: all 0.4s ease;
}

.nav-visible .reference-navigation {
    transform: translateY(0);
}

.nav-btn {
    min-width: 120px;
    height: 40px;
    border-radius: 20px;
    border: none;
    background: var(--footer-bg);
    color: var(--footer-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: var(--card-deck-font-body);
    padding: 0 1rem;
    white-space: nowrap;
    transition: all 200ms ease;
    user-select: none; /* Prevent text selection */
}

.nav-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: scale(1.02);
}

.nav-btn:disabled {
    background: var(--neutral-400);
    cursor: not-allowed;
    opacity: 0.5;
}

.reference-counter {
    font-size: 1rem;
    font-weight: 600;
    color: var(--section-heading);
    font-family: var(--card-deck-font-display);
    min-width: 80px;
    text-align: center;
    user-select: none; /* Prevent text selection */
}

/* 3D Card Sliding Animation Classes - FIX 3: Consistent Animation Parameters */
.reference-carousel.next .reference-item,
.reference-carousel.prev .reference-item {
    transition: all 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* Identical timing for both directions */
}

/* Hover effects removed - horizontal-only carousel */
.reference-carousel .reference-list .reference-item:hover {
    /* No hover transformations for horizontal-only movement */
    cursor: pointer;
}

.reference-carousel .reference-list .reference-item:nth-child(2):hover {
    /* Active card maintains position, only cursor changes */
    cursor: pointer;
}

/* 3D Card Sliding Effect - Enhanced Visual Motion */
/* FIX 3: Consistent Animation Classes with Identical Parameters */
.reference-carousel .reference-list .reference-item.sliding-in-left,
.reference-carousel .reference-list .reference-item.sliding-in-right,
.reference-carousel .reference-list .reference-item.sliding-out-left,
.reference-carousel .reference-list .reference-item.sliding-out-right {
    animation-duration: 0.25s; /* Half duration for total 0.5s sequence */
    animation-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94); /* Standardized easing */
    animation-fill-mode: forwards;
}

.reference-carousel .reference-list .reference-item.sliding-in-left {
    animation-name: slideInFromLeft;
}

.reference-carousel .reference-list .reference-item.sliding-in-right {
    animation-name: slideInFromRight;
}

.reference-carousel .reference-list .reference-item.sliding-out-left {
    animation-name: slideOutToLeft;
}

.reference-carousel .reference-list .reference-item.sliding-out-right {
    animation-name: slideOutToRight;
}

@keyframes slideInFromLeft {
    from {
        transform: translateX(-200%); /* -150% + -50% centering */
        opacity: 0;
        filter: blur(4px);
    }
    to {
        transform: translateX(-50%); /* Centered position */
        opacity: 1;
        filter: blur(0px);
    }
}

@keyframes slideInFromRight {
    from {
        transform: translateX(100%); /* 150% - 50% centering */
        opacity: 0;
        filter: blur(4px);
    }
    to {
        transform: translateX(-50%); /* Centered position */
        opacity: 1;
        filter: blur(0px);
    }
}

@keyframes slideOutToLeft {
    from {
        transform: translateX(-50%); /* Centered position */
        opacity: 1;
        filter: blur(0px);
    }
    to {
        transform: translateX(-200%); /* -150% + -50% centering */
        opacity: 0;
        filter: blur(4px);
    }
}

@keyframes slideOutToRight {
    from {
        transform: translateX(-50%); /* Centered position */
        opacity: 1;
        filter: blur(0px);
    }
    to {
        transform: translateX(100%); /* 150% - 50% centering */
        opacity: 0;
        filter: blur(4px);
    }
}

/* Mobile Landscape Optimizations - FoundContext v4 */

/* Apply landscape layout to any card with landscape-enabled class (for testing) */
.reference-carousel .reference-list .reference-item.landscape-enabled .landscape-card-layout {
  display: flex !important;
  height: 100vh !important;
  width: 100vw !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 1000 !important;
  background: white !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Hide bottom navigation when landscape is enabled */
.reference-carousel:has(.reference-item.landscape-enabled) .reference-navigation {
  display: none !important;
}

.reference-carousel .reference-list .reference-item.landscape-enabled .card-meta-column {
  width: 220px !important;
  flex-shrink: 0 !important;
  padding: 16px !important;
  background: var(--footer-bg) !important;
  color: var(--footer-text) !important;
  border-right: 1px solid var(--card-border) !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: space-between !important;
}

.reference-carousel .reference-list .reference-item.landscape-enabled .card-content-column {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  background: white !important;
  padding: 16px !important;
}

.reference-carousel .reference-list .reference-item.landscape-enabled .card-content-scrollable {
  flex: 1 !important;
  overflow-y: auto !important;
  padding: 16px !important;
  background: #fafafa !important;
  border-radius: 8px !important;
}


@media screen and (min-width: 480px) and (max-width: 1024px) 
       and (orientation: landscape) and (max-height: 500px) {
  
  /* MOBILE-LANDSCAPE-PLAN.md Implementation: Remove parent constraints for fixed positioning */
  .reference-carousel .reference-list .reference-item.landscape-enabled {
    aspect-ratio: none !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    transform: none !important;
    position: static !important;
    top: auto !important;
    left: auto !important;
  }
  
  /* MOBILE-LANDSCAPE-PLAN.md wireframe structure */
  .reference-carousel .reference-list .reference-item.landscape-enabled .landscape-card-layout {
    display: flex;
    height: 100%;
    width: 100%;
  }
  
  /* Left column: Fixed header + navigation (220px) */
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-meta-column {
    width: 220px;
    flex-shrink: 0;
    padding: 16px;
    background: var(--footer-bg);
    color: var(--footer-text);
    border-right: 1px solid var(--card-border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  
  /* Right column: Scrollable content area */
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-content-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--card-bg, white);
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-content-scrollable {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color, #e9ecef) transparent;
  }
  
  /* Left column header section styling */
  .reference-carousel .reference-list .reference-item.landscape-enabled .fixed-header-section {
    margin-bottom: 16px;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .reference-title-landscape {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary, #1f2937);
    line-height: 1.3;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .show-info,
  .reference-carousel .reference-list .reference-item.landscape-enabled .year-info {
    font-size: 0.875rem;
    margin-bottom: 4px;
    color: var(--text-secondary, #6b7280);
  }
  
  /* Left column navigation section */
  .reference-carousel .reference-list .reference-item.landscape-enabled .fixed-nav-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .nav-buttons {
    display: flex;
    gap: 8px;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .nav-btn-left {
    flex: 1;
    padding: 8px 12px;
    background: var(--footer-bg, #8B1538);
    color: var(--footer-text, white);
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
  }

  .reference-carousel .reference-list .reference-item.landscape-enabled .nav-btn-left:hover {
    filter: brightness(0.9);
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-order {
    font-size: 0.875rem;
    color: var(--text-secondary, #6b7280);
    text-align: center;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .tag {
    padding: 2px 8px;
    background: var(--tag-bg);
    color: var(--tag-text);
    font-size: 0.75rem;
    border-radius: 12px;
    border: 1px solid var(--tag-border);
  }
  
  /* Right column content styling */
  .reference-carousel .reference-list .reference-item.landscape-enabled .content-block {
    margin-bottom: 20px;
  }

  .reference-carousel .reference-list .reference-item.landscape-enabled .content-block h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--section-heading, #8B1538);
    margin-bottom: 8px;
  }

  .reference-carousel .reference-list .reference-item.landscape-enabled .content-block p {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary, #1f2937);
  }

  /* Landscape-specific component styles using database theme variables */
  /* Target mobile-landscape-overlay (fixed position overlay created by JavaScript) */
  #mobile-landscape-overlay .card-meta-column {
    background: var(--footer-bg) !important;
    color: var(--footer-text) !important;
  }

  #mobile-landscape-overlay .landscape-back-button-container {
    border-bottom: 1px solid rgba(255,255,255,0.2);
  }

  #mobile-landscape-overlay .landscape-back-button {
    background: rgba(255, 255, 255, 0.15);
    color: var(--footer-text);
    border: 1px solid rgba(255, 255, 255, 0.3);
  }

  #mobile-landscape-overlay .landscape-back-button:hover {
    background: rgba(255, 255, 255, 0.25);
  }

  #mobile-landscape-overlay .landscape-title {
    color: var(--footer-text) !important;
  }

  #mobile-landscape-overlay .landscape-subtitle {
    color: var(--footer-text) !important;
    opacity: 0.8;
  }

  #mobile-landscape-overlay .landscape-card-position {
    color: var(--footer-text) !important;
    opacity: 0.7;
  }

  #mobile-landscape-overlay .landscape-tags-label {
    color: var(--footer-text) !important;
    opacity: 0.6;
  }

  #mobile-landscape-overlay .landscape-tags-grid {
    scrollbar-color: rgba(255,255,255,0.3) transparent;
  }

  #mobile-landscape-overlay .landscape-tags-grid .tag {
    background: rgba(255,255,255,0.2) !important;
    color: var(--footer-text) !important;
    border-color: rgba(255,255,255,0.3) !important;
  }

  #mobile-landscape-overlay .landscape-nav-button {
    background: rgba(255, 255, 255, 0.15);
    color: var(--footer-text);
    border: 2px solid rgba(255, 255, 255, 0.3);
  }

  #mobile-landscape-overlay .landscape-nav-button:hover {
    background: rgba(255, 255, 255, 0.25);
  }

  #mobile-landscape-overlay .landscape-section-heading {
    color: var(--section-heading) !important;
  }

  .reference-carousel .reference-list .reference-item.landscape-enabled .content-expandable {
    margin-bottom: 16px;
  }

  .reference-carousel .reference-list .reference-item.landscape-enabled .content-expandable h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--section-heading, #8B1538);
    cursor: pointer;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color, #e9ecef);
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .expanded-content {
    margin-top: 12px;
    padding-left: 16px;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .expanded-content p {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary, #1f2937);
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-content-scrollable::-webkit-scrollbar {
    width: 6px;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-content-scrollable::-webkit-scrollbar-track {
    background: transparent;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-content-scrollable::-webkit-scrollbar-thumb {
    background-color: var(--border-color, #e9ecef);
    border-radius: 3px;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-content-scrollable::-webkit-scrollbar-thumb:hover {
    background-color: var(--section-heading, #8B1538);
  }
  
  /* Meta column layout */
  .reference-carousel .reference-list .reference-item.landscape-enabled .card-meta-header {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color, #e9ecef);
  }
  
  /* Adjust reference title and meta for landscape */
  .reference-carousel .reference-list .reference-item.landscape-enabled .reference-title {
    font-size: 1.125rem;
    line-height: 1.25;
    margin-bottom: 8px;
  }
  
  .reference-carousel .reference-list .reference-item.landscape-enabled .reference-meta {
    font-size: 0.75rem;
    margin-bottom: 8px;
  }
  
  /* Enhanced content area for landscape reading */
  .reference-carousel .reference-list .reference-item.landscape-enabled .quick-context,
  .reference-carousel .reference-list .reference-item.landscape-enabled .cultural-background {
    font-size: 1rem;
    line-height: 1.75;
    margin-bottom: 16px;
  }
  
  /* Preserve animations with landscape dimensions */
  @keyframes slideInFromLeft {
    from {
      transform: translateX(-200%);
      opacity: 0;
      filter: blur(4px);
    }
    to {
      transform: translateX(-50%);
      opacity: 1;
      filter: blur(0px);
    }
  }
  
  @keyframes slideInFromRight {
    from {
      transform: translateX(100%);
      opacity: 0;
      filter: blur(4px);
    }
    to {
      transform: translateX(-50%);
      opacity: 1;
      filter: blur(0px);
    }
  }
}