/* ==============================================
   FLIP CARDS - CSS
   Desktop: 3D flip with configurable speed
   Mobile (<768px): Accordion layout

   DOM structure (wrapper injected by JS):
     .flip-card-container
       .flip-card           ← stable hover target (flat, never rotates)
         .flip-card-inner   ← rotates in 3D
           .flip-card-front
           .flip-card-back
   ============================================== */

/* ---- DESKTOP FLIP CARDS ---- */

/* Container - basic grid/flex parent, no perspective needed here */
.flip-card-container {
  /* perspective now lives on each .flip-card for better per-card vanishing point */
}

/* Stable wrapper — this is the hover/click target.
   It stays perfectly flat while the inner rotates. */
.flip-card {
  position: relative;
  width: 100%;
  height: 220px;
  perspective: 1000px;
  cursor: pointer;
}

/* Inner — the element that actually flips.
   Speed is set via CSS custom property --flip-speed.
   Add data-flip-speed="0.3s" (or any value) to the
   GP container to override the default 0.4s. */
.flip-card-inner {
  position: absolute;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--flip-speed, 0.4s) cubic-bezier(0.4, 0, 0.2, 1);
}

/* Flip on hover (via stable wrapper) or tap (.is-flipped) */
.flip-card:hover .flip-card-inner,
.flip-card-inner.is-flipped {
  transform: rotateY(180deg);
}

/* Front and back shared styles */
.flip-card-front,
.flip-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1.5em;
  box-sizing: border-box;
  overflow: hidden;
  /* Prevent children from intercepting hover */
  pointer-events: none;
}

/* Re-enable pointer events on the wrapper (hover target) */
.flip-card {
  pointer-events: auto;
}

/* Ensure inner + all children don't intercept hover */
.flip-card-inner {
  pointer-events: none;
}

.flip-card-front *,
.flip-card-back * {
  pointer-events: none;
}

/* Back face styling */
.flip-card-back {
  background: var(--global-color-10);
  transform: rotateY(180deg);
}

.flip-card-back p,
.flip-card-back .gb-text {
  color: var(--base);
  font-size: 18px;
  line-height: 22px;
  text-align: left;
  margin: 0;
  font-weight: 400;
}

/* Hover enhancement on front — triggered via stable wrapper */
.flip-card:hover .flip-card-front {
  box-shadow: 0 8px 30px rgba(0, 195, 208, 0.25);
}

/* Focus state for accessibility (on wrapper) */
.flip-card:focus-visible {
  outline: 3px solid var(--accent-2);
  outline-offset: 4px;
}

/* ==============================================
   RESPONSIVE - TABLET
   ============================================== */

@media (max-width: 1024px) {
  .flip-card {
    height: 260px;
  }
}

/* ==============================================
   MOBILE ACCORDION (<768px)
   Converts flip cards to expandable accordions.
   JS handles click toggling with .accordion-open class.
   ============================================== */

@media (max-width: 767px) {
  /* Reset 3D / flip behavior */
  .flip-card-container {
    perspective: none;
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .flip-card {
    height: auto;
    perspective: none;
    cursor: pointer;
    margin-bottom: 8px;
  }

  .flip-card-inner {
    position: relative;
    height: auto;
    transform-style: flat;
    transition: none;
    border-radius: 16px;
    overflow: hidden;
    background: transparent;
    /* Re-enable pointer events on mobile since wrapper handles clicks */
    pointer-events: none;
  }

  /* Disable hover flip on mobile */
  .flip-card:hover .flip-card-inner,
  .flip-card-inner.is-flipped {
    transform: none;
  }

  /* ---- FRONT = Accordion Header ---- */
  .flip-card-front {
    position: relative;
    width: 100%;
    height: auto;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    transform: none;
    border-radius: inherit;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    padding: 14px 44px 14px 16px;
    gap: 12px;
    pointer-events: none;
    border-radius: 16px !important;
  }

  /* Title row: icon left, text right */
  .flip-card-front .flip-card-title {
    display: flex !important;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    width: 100%;
    text-align: left;
    margin: 0;
  }

  /* Shrink the SVG icon to 40px */
  .flip-card-front .gb-shape {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .flip-card-front .gb-shape svg {
    width: 100%;
    height: 100%;
  }

  /* Title text */
  .flip-card-front .flip-card-title > .gb-text {
    flex: 1;
    font-size: 15px;
    line-height: 1.3;
  }

  /* Accordion chevron indicator */
  .flip-card-inner::after {
    content: "";
    position: absolute;
    top: 20px;
    right: 16px;
    width: 10px;
    height: 10px;
    border-right: 1px solid var(--global-color-9);
    border-bottom: 1px solid var(--global-color-9);
    transform: rotate(45deg);
    transition:
      transform 0.3s ease,
      top 0.3s ease;
    pointer-events: none;
    z-index: 2;
  }

  .flip-card-inner.accordion-open::after {
    transform: rotate(-135deg);
    top: 24px;
  }

  /* ---- BACK = Accordion Tray ---- */
  .flip-card-back {
    position: absolute;
    width: 100%;
    height: auto;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    transform: none;
    border-radius: 0;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    padding: 0 16px;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition:
      max-height 0.35s ease,
      opacity 0.25s ease,
      padding 0.35s ease;
    background: transparent !important;
  }

  .flip-card-inner.accordion-open .flip-card-back {
    position: relative;
    max-height: 300px;
    opacity: 1;
    padding: 16px;
    background: var(--global-color-10) !important;
    border-radius: 16px;
  }

  /* Hide the repeated bold title paragraph in the back on mobile */
  .flip-card-back > p:first-child {
    display: none;
  }

  .flip-card-back p,
  .flip-card-back .gb-text {
    font-size: 14px;
    line-height: 1.5;
  }

  /* Remove desktop hover effects */
  .flip-card:hover .flip-card-front {
    box-shadow: none;
  }
}


/* ==============================================
   ACCESSIBILITY & PRINT
   ============================================== */

@media (prefers-reduced-motion: reduce) {
  .flip-card-inner {
    transition: none !important;
    height: auto;
  }

  .flip-card-front,
  .flip-card-back {
    position: relative;
    transform: none !important;
    backface-visibility: visible;
  }

  .flip-card-back {
    margin-top: 0.5em;
  }
}

@media print {
  .flip-card-inner {
    height: auto;
    page-break-inside: avoid;
    margin-bottom: 1em;
  }

  .flip-card-front,
  .flip-card-back {
    position: relative;
    transform: none !important;
    backface-visibility: visible;
  }
}