/* Digital Card Component Styles */

.digital-card {
  position: relative;
  width: 100%;
  max-width: 350px;
  aspect-ratio: var(--card-ar, 3 / 4);
  margin: 0 auto;
  cursor: pointer;
  user-select: none;
  border-radius: 12px;
  /* allow drop-shadow to render outside card bounds */
  overflow: visible;
  transition: transform 0.2s ease;
  box-shadow: none;
  background: transparent; /* no underlay to avoid white flash during flip */
  perspective: 1000px; /* improve 3D rendering and reduce iOS artifacts */
}

/* Elevation effect only for multi-view; suppressed in single-view */
.multi-view .digital-card:hover { transform: translateY(-2px); }

/* Card flip container - only for overlays */
.media-flip-inner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.8s;
  pointer-events: none; /* Let clicks pass through to base media, but images handle their own */
  will-change: transform;
  z-index: 3;
}

.media-flip-inner.transition-off {
  transition: none !important;
}
.media-container {
  position: relative;
  width: 100%;
  height: 100%;
}
.media-flip-inner.repaint { outline: 0 solid transparent; }

.media-flip-inner.flipped { transform: rotateY(180deg); }

/* Overlay faces - front and back */
.media-front,
.media-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform;
  border-radius: 12px;
  /* allow drop-shadow outside face */
  overflow: visible;
  transition: none;
}

.media-front { transform: rotateY(0deg); background: transparent; }
.media-back  { transform: rotateY(180deg); background: transparent; }

/* Prevent image mirroring artifacts on iOS during 3D flips */
.media-front img,
.media-back img,
.overlay {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  /* avoid forcing a 3D layer; allows drop-shadow to render */
  transform: none;
  /* Enable iOS native image callout menu (Save Image, Copy Image, etc.) */
  -webkit-touch-callout: default;
  /* Allow images to receive their own touch events for native iOS menu */
  pointer-events: auto;
}

/* Suppress native image menu in static decks */
.static-deck-mode .media-front img,
.static-deck-mode .media-back img,
.static-deck-mode .overlay {
  -webkit-touch-callout: none;
}

/* Default face visibility */
.media-front { z-index: 2; }
.media-back  { z-index: 1; }
/* 3D flip via container rotation (no opacity swap) */

/* Base media */
.card-base-media {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
}

/* Skeleton placeholder (initial render before media) */
.card-skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #f4f6f9, #e9edf3);
  color: #b9c2d0;
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-transform: none;
}
.card-skeleton-title {
  font-size: clamp(14px, 3.2vw, 24px);
  text-align: center;
  opacity: 0.45;
}

/* Legacy overlay class - keep for compatibility */
.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  z-index: 2;
  pointer-events: none;
}

/* Match main cards.css overlay class */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain; /* respect product-specific aspect ratio */
  pointer-events: none;
  z-index: 2; /* match site behavior */
  border-radius: 12px; /* keep rounded corners on the image itself */
  /* no base shadow to avoid rectangle; apply drop-shadow per view below */
  filter: none;
}

/* Alpha-respecting shadow (no rectangle)
   Apply a single, softer shadow directly to the face images.
   iOS Safari can visually "stack" multiple drop-shadows on scroll, so keep this simple. */
.single-view .media-front .overlay,
.single-view .media-back .overlay {
  filter: drop-shadow(8px 12px 10px rgba(0,0,0,0.22));
}
.multi-view .media-front .overlay,
.multi-view .media-back .overlay {
  filter: drop-shadow(5px 9px 8px rgba(0,0,0,0.20));
}

/* Flip icon - hint, centered at bottom of card */
.flip-help {
  position: absolute;
  /* Sit just below the card edge rather than overlapping it */
  bottom: -18px;
  left: 0;
  right: 0;
  transform: none;
  background: none;
  padding: 4px;
  border-radius: 0;
  font-size: 1rem;
  color: white;
  text-align: center;
  z-index: 10;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: auto; /* Ensure flip icon is clickable */
  opacity: 0; /* hidden by default, shown via JS */
  transition: opacity 0.3s ease;
}

/* Wiggle animation for flip icon */
@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  15% { transform: rotate(10deg); }
  30% { transform: rotate(-10deg); }
  45% { transform: rotate(8deg); }
  60% { transform: rotate(-8deg); }
  75% { transform: rotate(4deg); }
  90% { transform: rotate(-4deg); }
}

.flip-help.wiggle-once {
  animation: wiggle 1.5s ease-in-out 1;
}

/* Pickup helper: same style as flip, positioned under the selector */
.action-help {
  position: absolute;
  top: 46px; /* under the 32px circle with spacing */
  right: 12px; /* align exactly under the 32px selection indicator at right:12px */
  width: 32px; /* same width as the circle so text is centered beneath it */
  background: none;
  padding: 2px 4px;
  border-radius: 0;
  font-size: 0.9rem;
  color: white;
  text-align: center;
  z-index: 9;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.action-help.wiggle-once { animation: wiggle 1.2s ease-in-out 1; }

/* Selection indicator */
.card-selection-indicator {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid #dee2e6;
  display: grid;            /* ensures perfect centering when stacking icons */
  place-items: center;
  z-index: 10;
  /* slower, delayed fade-in for opacity; instant for others */
  transition:
    opacity 0.36s ease 0.12s,
    transform 0.15s ease,
    background 0.15s ease,
    border-color 0.15s ease;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.card-selection-indicator:hover {
  background: #ffffff;
  border-color: #007acc;
  transform: scale(1.04);
}

.card-selection-indicator.mode-take {
  background: var(--accent-color, #2db36f);
  border-color: var(--accent-color, #2db36f);
  color: #ffffff;
}

/* Hand semantics: green when in hand; neutral when available */
.digital-card.selected .card-selection-indicator {
  background: var(--accent-color, #2db36f);
  border-color: var(--accent-color, #2db36f);
  color: white;
  transform: scale(1.06);
}

/* Facilitator count badge variant: inherits size/position/scale, but is Brand 4 (pink) and non-interactive */
.card-selection-indicator.is-count-badge {
  background: var(--brand4, #ec4899);
  border-color: var(--brand4, #ec4899);
  cursor: default;
}

/* Ensure Brand 4 overrides selected-state Brand 2 for count badge */
.digital-card.selected .card-selection-indicator.is-count-badge {
  background: var(--brand4, #ec4899);
  border-color: var(--brand4, #ec4899);
}

/* Variant to show discard indicator as Brand 4 when participants have the card */
.card-selection-indicator.mode-discard.has-participants,
.digital-card.selected .card-selection-indicator.mode-discard.has-participants {
  background: var(--brand4, #ec4899);
  border-color: var(--brand4, #ec4899);
}

/* Card +/- icons inside indicator */
.card-selection-indicator .indicator-take-icon svg,
.card-selection-indicator .indicator-discard-icon svg {
  display: block;
  width: 24px;   /* larger icon within 32px circle */
  height: 24px;
}
/* stack both icons in same center cell; hide one via opacity without shifting layout */
.card-selection-indicator .indicator-take-icon,
.card-selection-indicator .indicator-discard-icon {
  grid-area: 1 / 1;
}

/* Toggle visibility by mode */
.card-selection-indicator .indicator-take-icon { opacity: 1; transition: opacity 0.15s ease; }
.card-selection-indicator .indicator-discard-icon { opacity: 0; transition: opacity 0.15s ease; }
.card-selection-indicator.mode-discard .indicator-take-icon { opacity: 0; }
.card-selection-indicator.mode-discard .indicator-discard-icon { opacity: 1; }

/* Selected state: green pill, white stroke */
.digital-card.selected .card-selection-indicator .indicator-take-icon svg rect,
.digital-card.selected .card-selection-indicator .indicator-take-icon svg path,
.digital-card.selected .card-selection-indicator .indicator-discard-icon svg rect,
.digital-card.selected .card-selection-indicator .indicator-discard-icon svg path {
  stroke: #ffffff;
}

/* Hide indicator while the card is animating (flip or swipe) */
.digital-card.is-flipping .card-selection-indicator { opacity: 0; pointer-events: none; transition: opacity 90ms ease 0s; }
.current-card-slot .digital-card.swipe-enter-left .card-selection-indicator,
.current-card-slot .digital-card.swipe-enter-right .card-selection-indicator,
.current-card-slot .digital-card.swipe-leave-left .card-selection-indicator,
.current-card-slot .digital-card.swipe-leave-right .card-selection-indicator { opacity: 0; pointer-events: none; transition: opacity 90ms ease 0s; }

/* Fade flip/pickup tooltips during animation with quick out and slower in */
.flip-help, .action-help { transition: opacity 0.36s ease 0.12s; }
.digital-card.is-flipping .flip-help,
.digital-card.is-flipping .action-help { opacity: 0; transition: opacity 90ms ease 0s; }
.current-card-slot .digital-card.swipe-enter-left .flip-help,
.current-card-slot .digital-card.swipe-enter-left .action-help,
.current-card-slot .digital-card.swipe-enter-right .flip-help,
.current-card-slot .digital-card.swipe-enter-right .action-help,
.current-card-slot .digital-card.swipe-leave-left .flip-help,
.current-card-slot .digital-card.swipe-leave-left .action-help,
.current-card-slot .digital-card.swipe-leave-right .flip-help,
.current-card-slot .digital-card.swipe-leave-right .action-help { opacity: 0; transition: opacity 90ms ease 0s; }

/* Ensure white icon when take-mode also uses green background in main list */
.card-selection-indicator.mode-take .indicator-take-icon svg rect,
.card-selection-indicator.mode-take .indicator-take-icon svg path {
  stroke: #ffffff;
}

/* Hover overlay removed - using flip icon instead */

/* Loading state for individual cards */
.card-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  color: #6c757d;
  font-size: 0.9rem;
}

.card-loading::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid #dee2e6;
  border-top: 2px solid #007acc;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 0.5rem;
}

/* Error state */
.card-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f8d7da;
  color: #721c24;
  padding: 1rem;
  text-align: center;
  font-size: 0.9rem;
}

.card-error-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

/* Touch-friendly interactions for mobile */
@media (max-width: 768px) {
  .digital-card {
    max-width: 100%;
    touch-action: manipulation;
  }
  
  .digital-card:hover {
    transform: none; /* Disable hover transform on mobile */
  }
  
  .digital-card:active {
    transform: scale(0.98);
  }
  
  .card-selection-indicator {
    width: 26px;
    height: 26px;
    top: 10px;
    right: 10px;
  }
  .card-selection-indicator .indicator-take-icon svg,
  .card-selection-indicator .indicator-discard-icon svg {
    width: 22px;  /* scale appropriately for smaller circle */
    height: 22px;
  }
  
  .selection-checkmark {
    font-size: 14px;
  }
  
  /* Always show card info on mobile */
  .card-info {
    opacity: 1;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  }
}

/* Single view specific styles */
.single-view .digital-card {
  max-width: none; /* width controlled inline based on container/gap calc */
  width: 100%;
  margin: 0 auto;
  display: block;
}

/* Remove hover elevation in single-view completely */
.single-view .digital-card:hover { transform: none; }

/* Suppress hover/press elevation in single-card view for smoother swipe UX */
.single-view .digital-card:hover,
.single-view .digital-card:active {
  transform: none !important;
}

/* Ensure card holder is properly hidden */
.current-card-slot .digital-card { background: transparent; border-radius: 16px; box-shadow: none; }

/* Remove any container-based shadow to avoid rectangle; rely on image drop-shadow */

/* Multi view specific styles */
.multi-view .digital-card { max-width: 100%; margin-top: 4px; }

/* Animation for card entrance only in multi view; disable in single view */
.multi-view .digital-card { animation: cardEnter 0.4s ease-out; }
.single-view .digital-card { animation: none !important; }

/* (moved to multi-view block above) */

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Flip animation enhancement */
.card-flip-container {
  perspective: 1000px;
}


/* Selected cards filter styling */
.filtered-view .digital-card:not(.selected) {
  opacity: 0.3;
  transform: scale(0.95);
  pointer-events: none;
}

.filtered-view .digital-card.selected {
  opacity: 1;
  transform: scale(1);
}

/* Flip helper: subtle and fade-capable */
.flip-help {
  opacity: 0; /* default hidden; shown briefly via JS */
  pointer-events: auto;
  transition: opacity 0.3s ease;
}
