/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  overflow: hidden;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: transparent;
}

main {
  display: flex;
  flex-direction: column;   /* stack vertically */
  gap: 24px;                /* space between carousels */
  align-items: center;      /* center horizontally */
  justify-content: flex-start;
  padding: 1rem;
}

/* Carousel container */
.mimo-carousel.carousel-container {
  position: relative;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  background: white;
  border-radius: var(--mc-radius, 12px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

/* Carousel track with scroll-snap */
.mimo-carousel .carousel-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: auto;       /* پیش‌فرض: بدون انیمیشن */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  touch-action: pan-y;              /* allow vertical scroll; we manage horizontal */
  overscroll-behavior-inline: contain;
}

.mimo-carousel .carousel-track::-webkit-scrollbar {
  display: none;
}

/* Individual slides */
.mimo-carousel .carousel-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  position: relative;
}

.mimo-carousel .carousel-slide picture { display:block; }
.mimo-carousel .carousel-slide a.carousel-link { display:block; text-decoration:none; color:inherit; }
.mimo-carousel .carousel-slide img {
  width: 100%;
  height: auto;
  display: block;
  /* Keep natural aspect ratio; no cropping/forcing */
  object-fit: unset;
  min-height: 0;
  max-height: none;
}

/* Navigation buttons */
.mimo-carousel .carousel-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, var(--mc-btn-alpha));
  border: none;
  border-radius: 50%;
  width: var(--mc-btn);
  height: var(--mc-btn);
  font-size: var(--mc-btn-font);
  font-weight: bold;
  color: #333;
  cursor: pointer;
  z-index: 10;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.mimo-carousel .carousel-btn:hover {
  background: rgba(255, 255, 255, 1);
  transform: translateY(-50%) scale(1.1);
}

.mimo-carousel .carousel-btn:focus-visible {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

.mimo-carousel .carousel-btn:active {
  transform: translateY(-50%) scale(0.95);
}

.mimo-carousel .carousel-btn--prev {
  left: var(--mc-offset);
}

.mimo-carousel .carousel-btn--next {
  right: var(--mc-offset);
}

/* RTL support */
[dir="rtl"] .mimo-carousel .carousel-btn--prev {
  right: var(--mc-offset);
  left: auto;
}

[dir="rtl"] .mimo-carousel .carousel-btn--next {
  left: var(--mc-offset);
  right: auto;
}

/* Responsive design */

/* Mobile (320px - 767px) */
@media (min-width: 320px) and (max-width: 767px) {
  .mimo-carousel.carousel-container {
    margin: 0.5rem;
    border-radius: 8px;
  }
  
  /* use tokens computed by ResizeObserver */
  .mimo-carousel .carousel-btn {
    width: var(--mc-btn);
    height: var(--mc-btn);
    font-size: var(--mc-btn-font);
  }
  
  .mimo-carousel .carousel-btn--prev {
    left: var(--mc-offset);
  }
  
  .mimo-carousel .carousel-btn--next {
    right: var(--mc-offset);
  }
  
  [dir="rtl"] .mimo-carousel .carousel-btn--prev {
    right: var(--mc-offset);
  }
  
  [dir="rtl"] .mimo-carousel .carousel-btn--next {
    left: var(--mc-offset);
  }
  
  /* Prevent white space on initial load by setting aspect ratio for track */
  /* Dynamic aspect ratio set via JS from first loaded image */
  .mimo-carousel .carousel-track {
    min-height: 0;
    aspect-ratio: var(--mc-ar, 3 / 2); /* Fallback to 3/2 if JS not loaded yet */
  }
  
  .mimo-carousel .carousel-slide img {
    aspect-ratio: var(--mc-ar, 3 / 2);
    object-fit: cover;
  }
}

/* Tablet (768px+) */
@media (min-width: 768px) {
  .mimo-carousel.carousel-container {
    margin: 1rem;
    border-radius: 12px;
  }
  
  .mimo-carousel .carousel-btn {
    width: var(--mc-btn);
    height: var(--mc-btn);
    font-size: var(--mc-btn-font);
  }
  
  .mimo-carousel .carousel-btn--prev {
    left: var(--mc-offset);
  }
  
  .mimo-carousel .carousel-btn--next {
    right: var(--mc-offset);
  }
  
  [dir="rtl"] .mimo-carousel .carousel-btn--prev {
    right: var(--mc-offset);
  }
  
  [dir="rtl"] .mimo-carousel .carousel-btn--next {
    left: var(--mc-offset);
  }
  
  /* Reset aspect-ratio for tablet/desktop - let images determine natural height */
  .mimo-carousel .carousel-track {
    aspect-ratio: unset;
  }
  
  .mimo-carousel .carousel-slide img {
    aspect-ratio: unset;
    object-fit: unset;
  }
}

/* Desktop (1440px+) */
@media (min-width: 1440px) {
  .mimo-carousel.carousel-container {
    margin: 2rem auto;
    border-radius: 16px;
  }
  
  .mimo-carousel .carousel-btn {
    width: var(--mc-btn);
    height: var(--mc-btn);
    font-size: var(--mc-btn-font);
  }
  
  .mimo-carousel .carousel-btn--prev {
    left: var(--mc-offset);
  }
  
  .mimo-carousel .carousel-btn--next {
    right: var(--mc-offset);
  }
  
  [dir="rtl"] .mimo-carousel .carousel-btn--prev {
    right: var(--mc-offset);
  }
  
  [dir="rtl"] .mimo-carousel .carousel-btn--next {
    left: var(--mc-offset);
  }
  
  /* no min/max height on desktop */
}

/* Loading state */
.mimo-carousel .carousel-slide img[data-loading="true"] {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Focus management for accessibility */
.mimo-carousel.carousel-container:focus-within {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .mimo-carousel .carousel-track {
    scroll-behavior: auto;
  }
  
  .mimo-carousel .carousel-btn {
    transition: none;
  }
  
  .mimo-carousel .carousel-slide img[data-loading="true"] {
    animation: none;
  }
}

/* Pagination dots */
.mimo-carousel .carousel-pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding-top: 10px;
  margin-top: 16px;
}

.mimo-carousel .carousel-dot {
  width: var(--mc-dot);
  height: var(--mc-dot);
  border: 0;
  border-radius: 9999px;
  background: rgba(20, 20, 20, 0.3);
  cursor: pointer;
  transition: 0.2s;
}

.mimo-carousel .carousel-dot:hover,
.mimo-carousel .carousel-dot:focus-visible {
  transform: scale(1.1);
  background: rgba(20, 20, 20, 0.6);
}

.mimo-carousel .carousel-dot.is-active,
.mimo-carousel [role="tab"][aria-selected="true"] {
  width: var(--mc-dot-active);
  background: rgba(20, 20, 20, 0.9);
}

.mimo-carousel.carousel-container.has-overlay-dots {
  position: relative;
}

.mimo-carousel.carousel-container.has-overlay-dots .carousel-pagination {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  margin: 0;
  padding: 0;
  z-index: 3;
}

/* Temporary snap disabling for teleport */
.mimo-carousel .carousel-track.no-snap {
  scroll-snap-type: none;
}

/* Smooth scroll only when JS explicitly enables it */
.mimo-carousel .carousel-track.smooth {
  scroll-behavior: smooth;
}

/* CSS variables base */
.mimo-carousel {
  /* scalable UI tokens (base designed ~1200px) */
  --mc-scale: 1;
  --mc-btn: 56px;         /* button size */
  --mc-btn-font: 24px;    /* icon/font size */
  --mc-offset: 16px;      /* side offset */
  --mc-dot: 8px;          /* dot diameter */
  --mc-dot-active: 22px;  /* active dot length */
  --mc-btn-alpha: 0.7;    /* 30% transparent background */
  --mc-height: 420px;
  --mc-gap: 8px;
  --mc-radius: 12px;
  --mc-speed: 300ms;
}
