/* Community Collage Styles - Optimized for Performance */

:root {
  --card-min: 180px;
  --card-max: 240px;
  --card-fluid: 15vw;
  --cellW: clamp(var(--card-min), var(--card-fluid), var(--card-max));
  --cellH: calc(var(--cellW) * 4 / 5);
  --unitH: calc(var(--cellH) / 2);
  --cc-gap: clamp(.25rem, 0.5vw, 1rem);
  --cc-duration: 120s;
}

/* Container performance optimizations */
.community-collage {
  contain: layout style;
  transform: translateZ(0); /* Create compositing layer */
}

.cc-outer { 
  width: 100%; 
  position: relative;
  contain: layout style;
}

.cc-wrapper { 
  position: relative; 
  width: 100%;
  isolation: isolate; /* Create new stacking context */
}

.cc-vp {
  width: 100vw;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  will-change: scroll-position; /* Optimize for scrolling */
}

.cc-vp::-webkit-scrollbar { 
  display: none; 
}

/* Gradient overlays - optimized rendering */
.cc-gradient {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 60px;
  z-index: 100;
  pointer-events: none;
  will-change: auto; /* Don't animate these */
  contain: paint;
}

.cc-gradient--left {
  left: 0;
  background: linear-gradient(90deg, 
    rgba(255,255,255,0.95) 0%,
    rgba(255,255,255,0.7) 30%,
    rgba(255,255,255,0.3) 60%,
    rgba(255,255,255,0) 100%);
}

.cc-gradient--right {
  right: 0;
  background: linear-gradient(270deg, 
    rgba(255,255,255,0.95) 0%,
    rgba(255,255,255,0.7) 30%,
    rgba(255,255,255,0.3) 60%,
    rgba(255,255,255,0) 100%);
}

/* Error message */
.cc-error {
  background: #fee;
  border: 2px solid #c00;
  color: #800;
  padding: 1rem;
  margin: 1rem 0;
  border-radius: 8px;
  contain: layout style paint;
}

/* Track - optimized for animation */
.cc-track {
  display: flex;
  width: max-content;
  will-change: transform;
  transform: translateZ(0); /* Force GPU acceleration */
  backface-visibility: hidden; /* Prevent flickering */
}

/* Optimized animation */
@keyframes marquee {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(calc(-100% / 6), 0, 0);
  }
}

.cc-track--animated {
  animation: marquee var(--cc-duration) linear infinite;
  animation-fill-mode: both;
}

.cc-vp:hover .cc-track--animated,
.cc-track--paused {
  animation-play-state: paused !important;
}

/* Grid - optimized layout */
.cc-grid {
  display: grid;
  grid-template-rows: repeat(6, var(--unitH));
  grid-auto-flow: column dense;
  grid-auto-columns: var(--cellW);
  gap: var(--cc-gap);
  margin: 0;
  padding: 0;
  list-style: none;
  width: max-content;
  contain: layout style;
}

/* Tile sizes with containment */
.cc-tile { 
  min-width: 0; 
  position: relative;
  contain: layout style paint;
  isolation: isolate;
}

.cc-s { grid-column: span 1; grid-row: span 2; }
.cc-m { grid-column: span 2; grid-row: span 2; }
.cc-l { grid-column: span 2; grid-row: span 4; }

/* Cards - optimized for hover effects */
.cc-card {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: #e9eff5;
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(2,41,64,.04), 0 10px 24px rgba(2,41,64,.06);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
  will-change: transform, box-shadow;
  backface-visibility: hidden;
  contain: layout style paint;
}

/* Optimized hover states */
.cc-s .cc-card:hover {
  transform: scale3d(1.08, 1.08, 1) translateZ(0);
  box-shadow: 0 4px 8px rgba(2,41,64,.12), 0 24px 48px rgba(2,41,64,.2);
  z-index: 20;
}

.cc-m .cc-card:hover {
  transform: scale3d(1.05, 1.05, 1) translateZ(0);
  box-shadow: 0 3px 6px rgba(2,41,64,.1), 0 20px 40px rgba(2,41,64,.18);
  z-index: 20;
}

.cc-l .cc-card:hover {
  transform: scale3d(1.03, 1.03, 1) translateZ(0);
  box-shadow: 0 2px 4px rgba(2,41,64,.08), 0 20px 40px rgba(2,41,64,.15);
  z-index: 20;
}

/* Images - optimized rendering */
.cc-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Overlay gradient - optimized */
.cc-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 50%, rgba(0,0,0,.55) 100%);
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  will-change: opacity;
}

.cc-card:hover::after { 
  opacity: 0.8; 
}

.cc-card--placeholder { 
  background: #9CA3AF; 
}

.cc-card--placeholder::after { 
  display: none; 
}

/* Stacking context optimization */
.cc-tile:has(.cc-card:hover) { 
  z-index: 15; 
}

/* Label - optimized */
.cc-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 1;
  background: rgba(2,41,64,.9);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  contain: layout style paint;
}

.cc-card:hover .cc-label { 
  transform: translate3d(0, -5px, 0); 
}

/* Prevent text selection */
.cc-track {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .cc-track--animated {
    animation: none !important;
  }
  
  .cc-card,
  .cc-label,
  .cc-card::after {
    transition: none !important;
  }
  
  .cc-vp {
    scrollbar-width: thin;
  }
  
  .cc-vp::-webkit-scrollbar {
    display: block;
    height: 8px;
  }
  
  .cc-vp::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
  }
  
  .cc-vp::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.3);
    border-radius: 4px;
  }
  
  .cc-vp::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.5);
  }
}

/* Loading state optimization */
.cc-grid:not(.cc-initialized) .cc-tile {
  opacity: 0;
  transform: translateY(20px);
}

.cc-grid.cc-initialized .cc-tile {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

/* Stagger animation for initial load */
.cc-grid.cc-initialized .cc-tile:nth-child(n) {
  transition-delay: calc(0.02s * var(--index, 1));
}
        
