/*
 * Card Flip Effect Styles
 * Flip a container like a playing card (rotateY) to reveal back content
 * Structure: Parent has class from admin (e.g., flip-card) and receives .ccws-card-flip-container
 *            First child becomes .flip-front, second child becomes .flip-back
 */

.ccws-card-flip-container {
	/* Layout */
	display: block;             /* Keep in normal flow */
	position: relative;         /* Positioning context for faces */
	overflow: hidden;           /* Clip faces when rotated */
	/* Fixed size (override with --ccws-card-flip-height if needed) */
	height: var(--ccws-card-flip-height, 350px);
	/* 3D */
	perspective: 1000px;
	transform-style: preserve-3d;
	/* Interaction */
	cursor: pointer;
}

/* Inner wrapper that actually rotates (W3Schools-like structure) */
.ccws-card-flip-container .ccws-flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s ease;
    transform-style: preserve-3d;
}

/* On hover show back (desktop). Persistent toggle is handled by .ccws-flipped class */
.ccws-card-flip-container:hover .ccws-flip-inner {
    transform: rotateY(180deg);
}

/* Persistent flipped state (click/tap/keyboard) */
.ccws-card-flip-container.ccws-flipped .ccws-flip-inner {
    transform: rotateY(180deg);
}

/* Face elements (first and second direct children) */
.ccws-card-flip-container .ccws-flip-inner > * {
    /* Take faces out of document flow and stack them */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
}

/* Front face: default orientation */
.ccws-card-flip-container .ccws-flip-inner > .flip-front {
    transform: rotateY(0deg);
    z-index: 2;
}

/* Back face: rotated 180deg so it faces forward when parent flips */
.ccws-card-flip-container .ccws-flip-inner > .flip-back {
    transform: rotateY(180deg);
    z-index: 1;
}

/* Center content on both faces without overriding site typography */
.ccws-card-flip-container .ccws-flip-inner > .flip-front,
.ccws-card-flip-container .ccws-flip-inner > .flip-back {
    /* Fill the card area */
    align-self: stretch;
    justify-self: stretch;
    width: 100%;
    height: 100%;
    box-sizing: border-box;

    /* Center inner content */
    display: flex;
    flex-direction: column;
    justify-content: center;  /* Vertical center */
    align-items: center;       /* Horizontal center */
}

/* Close button on the back face */
.ccws-card-flip-container .ccws-card-flip-close {
	position: absolute;
	top: 12px;
	right: 12px;
	width: 32px;
	height: 32px;
	border: none;
	border-radius: 50%;
	background: rgba(0,0,0,0.08);
	cursor: pointer;
	z-index: 5;
}

.ccws-card-flip-container .ccws-card-flip-close:hover {
	background: rgba(0,0,0,0.15);
}

.ccws-card-flip-container .ccws-card-flip-close::before,
.ccws-card-flip-container .ccws-card-flip-close::after {
	content: '';
	position: absolute;
	left: 50%;
	top: 50%;
	width: 16px;
	height: 2px;
	background: currentColor;
	border-radius: 2px;
	transform-origin: center;
}

.ccws-card-flip-container .ccws-card-flip-close::before { transform: translate(-50%, -50%) rotate(45deg); }
.ccws-card-flip-container .ccws-card-flip-close::after  { transform: translate(-50%, -50%) rotate(-45deg); }

/* Focus styles for accessibility */
.ccws-card-flip-container:focus {
	outline: 2px solid #2271b1;
	outline-offset: 2px;
}

/* Reduced motion support: disable 3D rotation, use simple show/hide */
@media (prefers-reduced-motion: reduce) {
	.ccws-card-flip-container,
	.ccws-card-flip-container > * {
		transition: none !important;
	}
	.ccws-card-flip-container { transform: none !important; }
	.ccws-card-flip-container:hover { transform: none !important; }

	/* Hide back by default, show only when flipped */
	.ccws-card-flip-container > .flip-back { display: none; transform: none !important; }
	.ccws-card-flip-container.ccws-flipped > .flip-front { display: none; }
	.ccws-card-flip-container.ccws-flipped > .flip-back { display: block; }
}
