/* ==========================================================================
   Flip Card Component
   Prefix: .fc
   ========================================================================== */

/* --- Custom properties --------------------------------------------------- */
.fc {
  --fc-corner-offset: var(--space-m, 1.25rem);
  --fc-radius: 0;
  --fc-aspect: 2 / 3;
  --fc-transition: 0.55s cubic-bezier(0.45, 0, 0.25, 1);
  --fc-back-bg: #ffd100;
  --fc-back-color: #111;
  --fc-cta-border: #111;
  --fc-gradient: linear-gradient(to top, rgba(0,0,0,0.65) 0%, rgba(0,0,0,0) 55%);
}

/* --- Themes (back face) --------------------------------------------------- */
.fc--yellow {
  --fc-back-bg: #ffd100;
  --fc-back-color: #111;
  --fc-cta-border: #111;
}

.fc--black {
  --fc-back-bg: #111111;
  --fc-back-color: #fff;
  --fc-cta-border: #fff;
  --fc-cta-color: #fff;
}

.fc--white {
  --fc-back-bg: #ffffff;
  --fc-back-color: #111;
  --fc-cta-border: #111;
}

/* --- Base container ------------------------------------------------------- */
.fc {
  display: block;
  perspective: 1200px;
  border-radius: var(--fc-radius);
  aspect-ratio: var(--fc-aspect);
  position: relative;
  isolation: isolate;
}

/* --- Inner (flip stage) --------------------------------------------------- */
.fc__inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform var(--fc-transition);
  border-radius: inherit;
  border: 1px solid var(--neutral-light);
}

.fc__inner[data-flipped] {
  transform: rotateY(180deg);
}

/* --- Pointer-event gating ------------------------------------------------
 * backface-visibility: hidden hides elements visually but NOT for pointer
 * events. The front face, even when rotated away, would capture all clicks
 * (including the close button). Toggle pointer-events with flip state.
 * ----------------------------------------------------------------------- */
.fc__front { pointer-events: auto; }
.fc__back  { pointer-events: none; }

.fc__inner[data-flipped] .fc__front { pointer-events: none; }
.fc__inner[data-flipped] .fc__back  { pointer-events: auto; }

/* --- Front face ----------------------------------------------------------- */
.fc__front {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  border-radius: inherit;
  cursor: pointer;
  user-select: none;
}

.fc__image {
  display: block;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

.fc__image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

/* Dark gradient overlay (default) */
.fc__front::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--fc-gradient);
  pointer-events: none;
  border-radius: inherit;
}

/* Light front variant: no overlay */
.fc--front-light .fc__front::after {
  display: none;
}

/* Front footer: title left, + icon right */
.fc__front-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: var(--fc-corner-offset);
  gap: var(--space-s, 0.75rem);
}

.fc__front-text {
  flex: 1;
  min-width: 0;
  padding-right: 0.5rem;
}

.fc__front-title {
  margin: 0;
  font-size: var(--text-m);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--white, #fff);
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Light front: dark text */
.fc--front-light .fc__front-title {
  color: var(--text-dark, #111);
}

.fc__open-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  color: var(--white, #fff);
  margin-bottom: 0.1rem;
}

/* Light front: dark icon */
.fc--front-light .fc__open-icon {
  color: var(--text-dark, #111);
}

.fc__open-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* --- Back face ------------------------------------------------------------ */
.fc__back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: rotateY(180deg);
  overflow: hidden;
  border-radius: inherit;
  background-color: var(--fc-back-bg);
  color: var(--fc-back-color);
  display: flex;
  flex-direction: column;
  /* Reserve space so content never overlaps the close button */
  padding-bottom: calc(var(--space-m, 1.25rem) * 2 + 1.5rem);
}

/* Scrollable content */
.fc__back-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-m, 1.25rem) var(--space-m, 1.25rem) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-s, 0.75rem);
  scrollbar-width: none;
}

.fc__back-content::-webkit-scrollbar {
  display: none;
}

.fc__back-title {
  margin: 0;
  font-size: var(--text-m, 1.125rem);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.2;
  color: inherit;
}

.fc__excerpt {
  margin: 0;
  font-size: var(--text-s, 0.9rem);
  line-height: 1.6;
  color: inherit;
  opacity: 0.9;
}

.fc__cta {
  display: inline-block;
  align-self: flex-start;
  margin-top: auto;
  padding: 0.6em 1.5em;
  font-size: var(--text-xs, 0.8rem);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fc-cta-color, var(--fc-back-color));
  border: 1.5px solid var(--fc-cta-border);
  text-decoration: none;
  transition: background-color 0.2s, color 0.2s;
}

.fc--yellow .fc__cta:hover,
.fc--white .fc__cta:hover {
  background-color: #111;
  color: #fff;
  border-color: #111;
}

.fc--black .fc__cta:hover {
  background-color: #fff;
  color: #111;
  border-color: #fff;
}

/* --- Close button --------------------------------------------------------- */
/* Positioned in the exact same corner as .fc__open-icon on the front */
.fc__close {
  position: absolute;
  bottom: var(--fc-corner-offset);
  right: var(--fc-corner-offset);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--fc-back-color);
  transition: opacity 0.2s;
  z-index: 2;
}

.fc__close:hover {
  opacity: 0.6;
}

.fc__close svg {
  display: block;
  width: 100%;
  height: 100%;
}
