/**
 * Flip Card with Background Component
 *
 * A component that displays cards with front and back sides that can be flipped.
 * Includes responsive design and special effects.
 * Flip functionality is disabled on mobile devices.
 */

/* --------------------------------
 * 1. Component Base Styles
 * -------------------------------- */
.flip-card-with-background {
  /* Component container */
  margin: 80px auto;
}

/* Component header */
.flip-card-with-background__title {
  font-size: 38px;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  color: #222222;
}

.flip-card-with-background__description {
  font-size: 22px;
  font-weight: 400;
  text-align: center;
  color: #222222;
  margin-bottom: 80px;
}

/* --------------------------------
 * 2. Card Grid Layout
 * -------------------------------- */
.flip-card-with-background__grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: 20px;
}

.flip-card-with-background__item {
  display: flex;
  flex-direction: column;
  perspective: 1000px; /* 3D effect for flip animation */
}

/* --------------------------------
 * 3. Card Structure
 * -------------------------------- */
.flip-card-with-background__card {
  position: relative;
  display: flex;
  height: 100%;
  background: #fcfaff;
  border-radius: 20px;
  overflow: visible; /* Allows ::before to overflow container */
  z-index: 1;
}

/* Card inner container - handles the flip */
.flip-card-with-background__card-inner {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.6s;
  transform-style: preserve-3d;
  will-change: transform; /* Improve animation performance */
}

/* Common styles for front and back */
.flip-card-with-background__card-front,
.flip-card-with-background__card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  overflow: hidden !important; /* Prevent scroll bars */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  z-index: 11;
}

/* --------------------------------
 * 4. Card Front Styles
 * -------------------------------- */
.flip-card-with-background__card-front {
  position: relative;
  z-index: 2;
}

.flip-card-with-background__image-wrapper {
  height: auto;
  line-height: 0; /* Remove extra space below image */
}

.flip-card-with-background__image {
  display: block;
  width: 100%;
  max-height: 200px; /* Limit image height */
  object-fit: cover;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
}

.flip-card-with-background__content {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  padding: 30px 20px;
  box-sizing: border-box;
  background-color: #fcfaff;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
  overflow: hidden !important; /* Prevent scroll bars */
}

.flip-card-with-background__card-title {
  margin-bottom: 15px;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  color: #6800ff;
  flex-shrink: 0; /* Don't shrink titles */
}

.flip-card-with-background__card-description {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.4; /* Improve readability */
  color: #222222;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}

/* Remove any default margins that might cause overflow */
.flip-card-with-background__card-description p,
.flip-card-with-background__card-back-description p {
  margin: 0 0 10px 0;
}

.flip-card-with-background__card-description p:last-child,
.flip-card-with-background__card-back-description p:last-child {
  margin-bottom: 0;
}

/* --------------------------------
 * 5. Card Back Styles
 * -------------------------------- */
.flip-card-with-background__card-back {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform: rotateY(180deg);
  background-size: cover;
  background-position: center;
  border-radius: 20px;
  overflow: hidden;
}

.flip-card-with-background__card-back-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: rgba(0, 0, 0, 0.51);
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px); /* Safari support */
  overflow: hidden !important; /* Prevent scroll bars */
}

.flip-card-with-background__card-back-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between; /* Distribute content evenly */
  flex-grow: 1;
  padding: 30px 20px;
  box-sizing: border-box;
  overflow: hidden !important; /* Prevent scroll bars */
}

.flip-card-with-background__card-back-title {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  color: #fffffa;
  flex-shrink: 0; /* Don't shrink titles */
}

.flip-card-with-background__card-back-description {
  flex: 1;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.4; /* Improve readability */
  color: #fffffa;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}

/* --------------------------------
 * 6. Link Styles
 * -------------------------------- */
.flip-card-with-background__link-wrapper {
  position: relative;
  z-index: 3;
  padding-top: 15px;
  text-align: right;
  flex-shrink: 0; /* Don't shrink link area */
}

.flip-card-with-background__link {
  font-size: 24px;
  font-weight: 700;
  color: #fffffa;
  text-decoration: none;
}

/* --------------------------------
 * 7. Decorative Elements
 * -------------------------------- */
/* Gradient background effect for desktop */
.flip-card-with-background__card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: conic-gradient(from -90deg at 50% 50%, #3e0099 0deg, #e92651 161.25deg, #3e0099 360deg);
  opacity: 0.5;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
  z-index: -1;
  display: none; /* Hidden by default, enabled in desktop media query */
}

/* --------------------------------
 * 8. Responsive Styles
 * -------------------------------- */
/* Desktop styles */
@media screen and (min-width: 992px) {

  /* Card item */
  .flip-card-with-background__item {
    max-width: 540px;
    min-width: 400px;
  }

  /* Card content */
  .flip-card-with-background__card-description {
    flex: 1;
  }

  /* Link positioning */
  .flip-card-with-background__link-wrapper {
    margin-top: auto; /* Push to bottom */
  }

  /* Card interaction */
  .flip-card-with-background__card-inner {
    cursor: pointer; /* Indicate clickable only on desktop */
  }

  .flip-card-with-background__card-inner.is-flipped {
    transform: rotateY(180deg);
  }

  /* Card hover effects */
  .flip-card-with-background__card-inner:hover {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  }

  /* Focus styles for accessibility */
  .flip-card-with-background__card-inner:focus {
    outline: 2px solid #6800ff;
    outline-offset: 2px;
  }

  /* Show gradient background on desktop */
  .flip-card-with-background__card::before {
    display: block;
  }

  /* Position variations for gradient background */
  .flip-card-with-background__card--1::before {
    transform: translate(-20px, 20px);
  }

  /* Default positioning for card--2 (when there are more than 2 children) */
  .flip-card-with-background__card--2::before {
    transform: translate(0px, 20px);
  }

  /* Special positioning for card--2 when there are exactly 2 children */
  .flip-card-with-background__grid:has(.flip-card-with-background__item:nth-child(2):last-child)
    .flip-card-with-background__card--2::before {
    transform: translate(-20px, 20px);
  }

  .flip-card-with-background__card--3::before {
    transform: translate(20px, 20px);
  }

  /* Hide mobile-only elements */
  .flip-card-hiden-desktop {
    display: none;
  }
}

/* Mobile styles */
@media screen and (max-width: 991px) {
  .flip-card-with-background {
    margin: 10px auto;  /* Reduce margin on mobile */
  }

  /* Component header */
  .flip-card-with-background__title {
    font-size: 16px;
  }

  .flip-card-with-background__description {
    font-size: 16px;
    margin-bottom: 20px; /* Reduce margin on mobile */
  }

  /* Card item */
  .flip-card-with-background__item {
    max-width: 400px;
    min-width: 340px;
  }

  /* Hide back side completely on mobile */
  .flip-card-with-background__card-back {
    display: none;
  }

  /* Card title */
  .flip-card-with-background__card-title {
    font-size: 16px;
    color: #222222;
    margin-bottom: 0;
  }

  /* Card description */
  .flip-card-with-background__card-description {
    font-size: 16px;
    text-align: center;
  }

  /* Link wrapper */
  .flip-card-with-background__link-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
  }

  /* Link */
  .flip-card-with-background__link {
    font-size: 20px;
    font-weight: 700;
    color: #6800ff;
    text-decoration: none;
  }

  /* Hide desktop-only elements */
  .flip-card-hiden-mobile {
    display: none;
  }
}

/* --------------------------------
 * 9. Browser Compatibility
 * -------------------------------- */
/* Safari fix for backface-visibility */
@supports (-webkit-backdrop-filter: none) or (backdrop-filter: none) {
  .flip-card-with-background__card-front,
  .flip-card-with-background__card-back {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }

  .flip-card-with-background__card-back-overlay {
    -webkit-overflow-scrolling: touch;
  }
}

/* --------------------------------
 * 10. Print Styles
 * -------------------------------- */
@media print {
  .flip-card-with-background__card-inner {
    transform: none !important;
    box-shadow: none !important;
  }

  .flip-card-with-background__card-back {
    display: none !important;
  }

  .flip-card-with-background__card::before {
    display: none !important;
  }
}
