/**
 * Team Section Slider
 * Inspired by provided carousel reference, adapted to KennelDAO branding.
 */

:root {
  --team-card-bg: rgba(15, 22, 30, 0.92);
  --team-card-border: rgba(63, 224, 249, 0.35);
  --team-card-glow: 0 25px 60px rgba(0, 0, 0, 0.6);
  --team-arrow-bg: rgba(19, 26, 34, 0.9);
  --team-arrow-border: rgba(63, 224, 249, 0.35);
}

.team {
  margin-top: clamp(60px, 8vw, 100px);
  margin-bottom: 0;
  padding: clamp(30px, 4vw, 50px) 0; /* Reduced padding to fit in one screen */
  position: relative;
  min-height: fit-content;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  /* Allow overflow to preserve rounded corners on carousel cards */
  overflow-x: hidden; /* Prevent horizontal overflow */
  overflow-y: visible; /* Allow vertical overflow for carousel effects */
}

/* Desktop: Reduce section title spacing */
.team .section-title {
  margin-bottom: clamp(20px, 3vw, 35px); /* Reduced spacing to bring content closer */
}

.team-shell {
  display: flex;
  gap: clamp(20px, 3vw, 40px);
  align-items: flex-start;
  justify-content: center;
  flex-wrap: nowrap;
  max-width: 1200px;
  width: 100%;
  margin: clamp(30px, 4vw, 50px) auto 0;
  padding: 0 clamp(12px, 2vw, 20px);
  box-sizing: border-box;
  overflow-x: hidden;
  position: relative;
}

.team-carousel {
  flex: 1 1 auto;
  min-width: 350px;
  max-width: 500px;
  width: clamp(350px, 45vw, 500px);
  height: clamp(500px, 70vh, 650px);
  position: relative;
  perspective: 1200px;
  -webkit-perspective: 1200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(40px, 5vw, 60px) clamp(30px, 4vw, 40px);
  margin: 0 auto;
  overflow: visible;
  contain: layout style;
  box-sizing: border-box;
}

/* Desktop navigation arrows - positioned on the right */
.team-nav-desktop {
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 2vw, 20px);
  align-items: center;
  justify-content: center;
  padding-left: clamp(12px, 2vw, 20px);
  align-self: center;
  flex-shrink: 0;
}

/* Mobile navigation arrows - hidden on desktop */
.team-nav-mobile {
  display: none;
}

.team-track {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  overflow: visible;
  /* Ensure rounded corners are fully visible */
  padding: 0;
  /* Contain transforms but allow rounded corners to show */
  contain: layout style;
}

.team-card {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100%, 500px);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 28px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border: 1px solid var(--team-card-border);
  overflow: hidden;
  box-shadow: var(--team-card-glow);
  transition:
    transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    opacity 0.6s ease,
    box-shadow 0.6s ease;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  will-change: transform;
  isolation: isolate;
  cursor: pointer;
}

.team-card__overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.7) 0%,
    rgba(0, 0, 0, 0.5) 30%,
    rgba(0, 0, 0, 0.3) 60%,
    rgba(0, 0, 0, 0.6) 100%
  );
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.team-card:hover .team-card__overlay {
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.8) 0%,
    rgba(0, 0, 0, 0.6) 30%,
    rgba(0, 0, 0, 0.4) 60%,
    rgba(0, 0, 0, 0.7) 100%
  );
}

.team-card__content {
  position: absolute;
  top: clamp(15px, 2.5vw, 20px);
  left: clamp(15px, 2.5vw, 20px);
  z-index: 2;
  text-align: left;
  width: calc(100% - clamp(30px, 5vw, 40px));
}

.team-card__name {
  color: var(--accent);
  font-size: clamp(1.5em, 3.5vw, 2em);
  font-weight: bold;
  margin: 0 0 clamp(8px, 1.5vw, 12px) 0;
  text-shadow: 
    0 0 15px rgba(63, 224, 249, 0.9),
    0 2px 6px rgba(0, 0, 0, 0.95),
    0 4px 12px rgba(0, 0, 0, 0.8),
    0 0 25px rgba(0, 0, 0, 0.7);
  line-height: 1.2;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
}

.team-card__role {
  color: var(--credit);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: clamp(0.85em, 2vw, 0.95em);
  margin: 0 0 clamp(12px, 2vw, 16px) 0;
  text-shadow: 
    0 1px 3px rgba(0, 0, 0, 0.95),
    0 2px 6px rgba(0, 0, 0, 0.8),
    0 0 12px rgba(0, 0, 0, 0.7);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.9));
}

.team-card__bio {
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.5;
  margin: 0 0 clamp(16px, 2.5vw, 20px) 0;
  font-size: clamp(0.9em, 2vw, 1em);
  text-shadow: 
    0 1px 4px rgba(0, 0, 0, 0.95),
    0 2px 8px rgba(0, 0, 0, 0.8),
    0 0 10px rgba(0, 0, 0, 0.7);
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.9));
}

.team-card__link {
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: clamp(8px, 1.5vw, 10px) clamp(14px, 2.5vw, 18px);
  border-radius: 999px;
  border: 1px solid rgba(63, 224, 249, 0.4);
  text-transform: uppercase;
  font-size: clamp(0.8em, 1.8vw, 0.9em);
  letter-spacing: 0.15em;
  transition: background 0.3s ease, border 0.3s ease, box-shadow 0.3s ease;
  text-decoration: none;
  background: rgba(19, 26, 34, 0.6);
  backdrop-filter: blur(5px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.team-card__link svg {
  width: 16px;
  height: 16px;
}

.team-card__link:hover,
.team-card__link:focus-visible {
  background: rgba(19, 26, 34, 0.85);
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(63, 224, 249, 0.3);
  outline: none;
}

.team-card.center {
  z-index: 5;
  transform: translateZ(100px) scale(1);
}

.team-card.up-1 {
  z-index: 4;
  transform: translateY(-100px) translateZ(15px) scale(0.94); /* Reduced spacing */
  opacity: 0.85;
}

.team-card.up-2 {
  z-index: 3;
  transform: translateY(-190px) translateZ(-60px) scale(0.86); /* Reduced spacing */
  opacity: 0.6;
}

.team-card.down-1 {
  z-index: 4;
  transform: translateY(100px) translateZ(15px) scale(0.94); /* Reduced spacing */
  opacity: 0.85;
}

.team-card.down-2 {
  z-index: 3;
  transform: translateY(190px) translateZ(-60px) scale(0.86); /* Reduced spacing */
  opacity: 0.6;
}

.team-card.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(0) translateZ(-200px) scale(0.7);
}

.team-arrow {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--team-arrow-border);
  background: var(--team-arrow-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, color 0.25s ease, background 0.25s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0.85;
}

.team-arrow svg {
  width: 24px;
  height: 24px;
}

.team-arrow:hover,
.team-arrow:focus-visible {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(63, 224, 249, 0.3);
  background: rgba(19, 26, 34, 0.95);
  opacity: 1;
  outline: none;
}

@media (max-width: 1024px) {
  .team-shell {
    flex-direction: column;
    align-items: center;
  }
  .team-carousel {
    max-width: min(500px, 100%);
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 768px) {
  /* Team carousel CSS variables - improved for better visibility */
  :root {
    --team-carousel-gap: 0.5rem; /* Reduced gap between inactive cards */
    --team-carousel-speed: 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* Faster, more responsive transition */
    --team-carousel-closed: min(120px, 28vw); /* Smaller inactive cards for tighter spacing, responsive */
    --team-carousel-open: min(300px, 85vw); /* Ensure active card fits in viewport */
  }

  .team .section-title {
    margin-bottom: clamp(30px, 5vw, 50px); /* Slightly reduced for mobile too */
  }

  .team-shell {
    align-items: center;
    margin-top: clamp(40px, 6vw, 60px);
    flex-direction: column;
    gap: clamp(12px, 2vw, 20px);
  }

  /* Hide desktop navigation on mobile */
  .team-nav-desktop {
    display: none;
  }

  /* Show mobile navigation below carousel */
  .team-nav-mobile {
    display: flex;
    flex-direction: row;
    gap: clamp(20px, 4vw, 30px);
    align-items: center;
    justify-content: center;
    margin-top: clamp(20px, 3vw, 30px);
    width: 100%;
  }

  /* Mobile: Switch to horizontal carousel using fractions carousel system */
  .team-carousel {
    max-width: 100%;
    width: 100%;
    height: auto;
    min-height: auto;
    padding: 0 clamp(8px, 2vw, 12px); /* Add padding to prevent edge clipping */
    margin: 0;
    perspective: none;
    -webkit-perspective: none;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
  }

  .team-track {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: auto;
    min-height: auto;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scroll-padding: 0 clamp(8px, 2vw, 12px); /* Add padding for better centering */
    cursor: grab;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pinch-zoom;
    overscroll-behavior-x: contain;
    overscroll-behavior-y: none;
    gap: var(--team-carousel-gap);
    padding: 0;
    box-sizing: border-box;
  }

  .team-track::-webkit-scrollbar {
    display: none;
  }

  .team-track:active {
    cursor: grabbing;
  }

  /* Mobile: Cards in horizontal layout - improved visibility */
  .team-card {
    position: relative;
    flex: 0 0 var(--team-carousel-closed);
    min-width: var(--team-carousel-closed);
    max-width: var(--team-carousel-closed);
    width: var(--team-carousel-closed);
    height: min(300px, 85vw);
    aspect-ratio: 1 / 1;
    margin: 0;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    inset: auto;
    border-radius: 28px;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    transition: flex-basis var(--team-carousel-speed), 
                transform var(--team-carousel-speed), 
                box-shadow var(--team-carousel-speed), 
                min-width var(--team-carousel-speed), 
                max-width var(--team-carousel-speed), 
                width var(--team-carousel-speed),
                opacity var(--team-carousel-speed);
    transform-style: flat;
    -webkit-transform-style: flat;
    flex-shrink: 0;
    box-sizing: border-box;
    opacity: 0.6;
    cursor: pointer;
  }

  /* Active card expands and becomes fully visible */
  .team-card[active] {
    flex-basis: var(--team-carousel-open) !important;
    min-width: var(--team-carousel-open) !important;
    max-width: var(--team-carousel-open) !important;
    width: var(--team-carousel-open) !important;
    height: min(300px, 85vw);
    transform: translateY(-4px);
    box-shadow: 0 18px 55px rgba(0, 0, 0, 0.45);
    opacity: 1;
    z-index: 2;
  }

  /* Non-active cards - reduced opacity and spacing */
  .team-card:not([active]) {
    opacity: 0.5;
    z-index: 1;
  }

  /* Mobile navigation arrows styling */
  .team-nav-mobile .team-arrow {
    width: clamp(44px, 10vw, 52px);
    height: clamp(44px, 10vw, 52px);
    min-width: 44px;
    min-height: 44px;
  }

  .team-nav-mobile .team-arrow svg {
    width: clamp(20px, 5vw, 24px);
    height: clamp(20px, 5vw, 24px);
  }

  /* Rotate mobile arrows to point left/right instead of up/down */
  .team-nav-mobile .team-arrow--up {
    transform: rotate(-90deg); /* Points left (previous) */
  }

  .team-nav-mobile .team-arrow--down {
    transform: rotate(-90deg) scaleX(-1); /* Points right (next) - rotate to left then flip horizontally */
  }

  .team-nav-mobile .team-arrow--up:hover,
  .team-nav-mobile .team-arrow--up:focus-visible {
    transform: rotate(-90deg) scale(1.1);
  }

  .team-nav-mobile .team-arrow--down:hover,
  .team-nav-mobile .team-arrow--down:focus-visible {
    transform: rotate(-90deg) scaleX(-1) scale(1.1);
  }


  /* Ensure card and description are visible together */
  .team-shell {
    max-height: none;
    overflow-y: visible;
  }

  /* Smooth scroll behavior */
  .team-track {
    scroll-padding: 0 20px;
  }

  /* Improve card visibility during scroll */
  .team-card {
    will-change: transform, opacity;
  }
  
  /* Ensure smooth scrolling */
  .team-track {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
}
