/**
 * Funky.Morph Component Styles
 * 
 * FLIP-based animation engine for smooth element transitions,
 * shared element morphs, and list animations.
 */

/* ==========================================================================
   CSS Custom Properties
   ========================================================================== */

.funky-morph,
[data-morph-active],
[data-morph-list-active] {
	/* Timing */
	--morph-duration: 300ms;
	--morph-easing: cubic-bezier(0.4, 0, 0.2, 1);
	--morph-stagger: 50ms;

	/* Clone styling */
	--morph-clone-shadow: var(--pro-shadow-lg, 0 10px 25px rgba(0, 0, 0, 0.15));
	--morph-clone-radius: var(--pro-radius-md, 0.5rem);

	/* Overlay */
	--morph-overlay-bg: var(--pro-bg-overlay, rgba(0, 0, 0, 0.5));
	--morph-overlay-blur: 4px;

	/* Z-index layers */
	--morph-z-overlay: 9998;
	--morph-z-clone: 10000;
	--morph-z-target: 10001;
}

/* ==========================================================================
   Morph State Classes
   ========================================================================== */

/* Element currently involved in a morph */
[data-morph-active] {
	will-change: transform, opacity;
}

/* Source element during morph (hidden) */
[data-morph-source-active] {
	visibility: hidden;
	pointer-events: none;
}

/* Target element during morph */
[data-morph-target-active] {
	z-index: var(--morph-z-target);
}

/* Reversible morph target */
[data-morph-reverse] {
	cursor: pointer;
}

/* ==========================================================================
   Clone Elements
   ========================================================================== */

.funky-morph-clone {
	position: fixed;
	pointer-events: none;
	z-index: var(--morph-z-clone);
	will-change: transform, opacity;
	box-shadow: var(--morph-clone-shadow);
	border-radius: var(--morph-clone-radius);
	overflow: hidden;
}

.funky-morph-clone--animating {
	transition: transform var(--morph-duration) var(--morph-easing),
	            opacity var(--morph-duration) var(--morph-easing);
}

/* Child clones for shared element transitions */
.funky-morph-clone--child {
	box-shadow: none;
	border-radius: 0;
}

/* Image clones */
.funky-morph-clone img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
}

/* ==========================================================================
   Overlay/Backdrop
   ========================================================================== */

.funky-morph-overlay {
	position: fixed;
	inset: 0;
	background: var(--morph-overlay-bg);
	backdrop-filter: blur(var(--morph-overlay-blur));
	-webkit-backdrop-filter: blur(var(--morph-overlay-blur));
	z-index: var(--morph-z-overlay);
	opacity: 0;
	transition: opacity var(--morph-duration) var(--morph-easing);
}

.funky-morph-overlay--visible {
	opacity: 1;
}

/* ==========================================================================
   List Animations
   ========================================================================== */

[data-morph-list-active] {
	position: relative;
}

/* List item base */
[data-morph-item] {
	will-change: transform, opacity;
}

/* Item entering */
[data-morph-item-entering] {
	opacity: 0;
}

/* Item exiting */
[data-morph-item-exiting] {
	opacity: 0;
	pointer-events: none;
}

/* Item moving */
[data-morph-item-moving] {
	z-index: 1;
}

/* ==========================================================================
   Screen Reader Only
   ========================================================================== */

.funky-morph-sr-only,
#funky-morph-live {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
	.funky-morph-clone,
	.funky-morph-clone--animating,
	[data-morph-active],
	[data-morph-item] {
		transition: none !important;
		animation: none !important;
	}

	.funky-morph-overlay {
		backdrop-filter: none;
		-webkit-backdrop-filter: none;
	}
}

/* Also respect data attribute */
[data-animations="off"] .funky-morph-clone,
[data-animations="off"] .funky-morph-clone--animating,
[data-animations="off"] [data-morph-active],
[data-animations="off"] [data-morph-item] {
	transition: none !important;
	animation: none !important;
}

/* ==========================================================================
   Theme: Light
   ========================================================================== */

[data-theme="light"] {
	--morph-overlay-bg: rgba(255, 255, 255, 0.8);
	--morph-clone-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   Theme: Even Funkyer
   ========================================================================== */

[data-theme="even-funkyer"] {
	--morph-overlay-bg: rgba(32, 0, 64, 0.9);
	--morph-clone-shadow: 
		0 0 30px rgba(255, 0, 255, 0.4),
		0 0 60px rgba(0, 255, 255, 0.2);
	--morph-overlay-blur: 8px;
}

[data-theme="even-funkyer"] .funky-morph-clone {
	border: 1px solid rgba(255, 0, 255, 0.5);
}

[data-theme="even-funkyer"] .funky-morph-overlay {
	background: 
		linear-gradient(135deg, 
			rgba(32, 0, 64, 0.95) 0%, 
			rgba(64, 0, 128, 0.9) 100%);
}

/* ==========================================================================
   Theme: High Contrast
   ========================================================================== */

[data-theme="high-contrast"] {
	--morph-overlay-bg: rgba(0, 0, 0, 0.85);
	--morph-clone-shadow: none;
}

[data-theme="high-contrast"] .funky-morph-clone {
	border: 2px solid currentColor;
}

/* ==========================================================================
   High Contrast Mode (System)
   ========================================================================== */

@media (prefers-contrast: high) {
	.funky-morph-clone {
		border: 2px solid currentColor;
		box-shadow: none;
	}

	.funky-morph-overlay {
		background: rgba(0, 0, 0, 0.9);
		backdrop-filter: none;
	}
}

@media (forced-colors: active) {
	.funky-morph-clone {
		border: 2px solid CanvasText;
		forced-color-adjust: none;
	}

	.funky-morph-overlay {
		background: Canvas;
		opacity: 0.9;
	}
}

/* ==========================================================================
   Density: Compact
   ========================================================================== */

[data-density="compact"] {
	--morph-duration: 200ms;
	--morph-stagger: 30ms;
}

/* ==========================================================================
   Density: Comfortable (Default)
   ========================================================================== */

[data-density="comfortable"] {
	--morph-duration: 300ms;
	--morph-stagger: 50ms;
}

/* ==========================================================================
   Density: Spacious
   ========================================================================== */

[data-density="spacious"] {
	--morph-duration: 400ms;
	--morph-stagger: 70ms;
}

/* ==========================================================================
   High Contrast Mode
   ========================================================================== */

@media (prefers-contrast: high) {
	[data-morph-active] {
		/* Ensure visibility during transition */
		outline: 2px solid currentColor !important;
	}

	.funky-morph-clone {
		/* Make clones visible in high contrast */
		outline: 2px dashed currentColor;
	}

	[data-morph-target-active] {
		outline: 3px solid currentColor;
	}
}

/* ==========================================================================
   Forced Colors Mode
   ========================================================================== */

@media (forced-colors: active) {
	[data-morph-active],
	.funky-morph-clone {
		forced-color-adjust: none;
	}

	.funky-morph-overlay {
		background: Canvas;
		opacity: 0.8;
	}
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
	.funky-morph-clone,
	.funky-morph-overlay,
	[data-morph-source-active] {
		display: none !important;
	}

	[data-morph-target-active] {
		position: static !important;
		z-index: auto !important;
	}
}

/* ==========================================================================
   Playground Demo Styles
   ========================================================================== */

.morph-demo__state-display {
	display: flex;
	flex-wrap: wrap;
	gap: 1rem;
	padding: 1rem;
	background: var(--pro-bg-secondary);
	border-radius: var(--pro-radius-md, 0.5rem);
}

.morph-demo__state-item {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.morph-demo__log {
	background: var(--pro-bg-secondary);
	padding: 1rem;
	border-radius: var(--pro-radius-sm, 0.25rem);
	max-height: 150px;
	overflow: auto;
	font-size: 0.875rem;
	margin: 0;
}

/* Card to Modal Demo */
.morph-demo__cards {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap: 1rem;
}

.morph-demo__card {
	background: var(--pro-bg-secondary);
	border: 1px solid var(--pro-border);
	border-radius: var(--pro-radius-md, 0.5rem);
	padding: 1.5rem;
	cursor: pointer;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.morph-demo__card:hover {
	transform: translateY(-2px);
	box-shadow: var(--pro-shadow-md);
}

.morph-demo__card:focus {
	outline: 2px solid var(--pro-primary);
	outline-offset: 2px;
}

.morph-demo__card-image {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 80px;
	margin-bottom: 1rem;
	color: var(--pro-primary);
}

.morph-demo__card-content {
	text-align: center;
}

.morph-demo__card-title {
	margin: 0 0 0.5rem;
	font-size: 1.125rem;
}

.morph-demo__card-text {
	margin: 0;
	font-size: 0.875rem;
}

/* Overlay */
.morph-demo__overlay {
	position: fixed;
	inset: 0;
	background: var(--morph-overlay-bg, rgba(0, 0, 0, 0.5));
	backdrop-filter: blur(var(--morph-overlay-blur, 4px));
	-webkit-backdrop-filter: blur(var(--morph-overlay-blur, 4px));
	z-index: 10000;
	cursor: pointer;
}

/* Modal */
.morph-demo__modal {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 90%;
	max-width: 500px;
	max-height: 80vh;
	overflow: auto;
	background: var(--pro-bg-primary);
	border: 1px solid var(--pro-border);
	border-radius: var(--pro-radius-lg, 0.75rem);
	box-shadow: var(--pro-shadow-xl);
	z-index: 10001;
	padding: 2rem;
}

.morph-demo__modal-image {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 120px;
	margin-bottom: 1.5rem;
	color: var(--pro-primary);
}

.morph-demo__modal-content {
	text-align: center;
}

.morph-demo__modal-title {
	margin: 0 0 0.5rem;
}

.morph-demo__modal-desc {
	margin: 0 0 1.5rem;
}

.morph-demo__modal-details {
	text-align: left;
	margin-bottom: 1.5rem;
	padding: 1rem;
	background: var(--pro-bg-secondary);
	border-radius: var(--pro-radius-sm, 0.25rem);
}

.morph-demo__modal-details ul {
	margin: 0.5rem 0 0;
	padding-left: 1.5rem;
}

/* List Animations Demo */
.morph-demo__list-controls {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-bottom: 1rem;
}

.morph-demo__list {
	list-style: none;
	padding: 0;
	margin: 0;
}

.morph-demo__list-item {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem 1rem;
	background: var(--pro-bg-secondary);
	border: 1px solid var(--pro-border);
	border-radius: var(--pro-radius-sm, 0.25rem);
	margin-bottom: 0.5rem;
}

.morph-demo__list-icon {
	color: var(--pro-primary);
	width: 24px;
	text-align: center;
}

.morph-demo__list-text {
	flex: 1;
}

.morph-demo__list-remove {
	color: var(--pro-text-muted);
	background: transparent;
	border: none;
	padding: 0.25rem 0.5rem;
	cursor: pointer;
	opacity: 0.6;
	transition: opacity 0.2s ease;
}

.morph-demo__list-remove:hover {
	opacity: 1;
	color: var(--pro-danger);
}

/* Shared Element Transitions Demo */
.morph-demo__shared-container {
	position: relative;
	min-height: 200px;
}

.morph-demo__shared-source {
	display: flex;
	align-items: center;
	gap: 1rem;
	padding: 1rem;
	background: var(--pro-bg-secondary, var(--pro-surface-bg, #f6f8fa));
	border: 1px solid var(--pro-border, var(--pro-border-color, #e1e4e8));
	border-radius: var(--pro-radius-md, 0.5rem);
}

.morph-demo__shared-thumb {
	width: 60px;
	height: 60px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--pro-bg-tertiary, #e9ecef);
	border-radius: var(--pro-radius-sm, 0.25rem);
	color: var(--pro-primary, #0366d6);
}

.morph-demo__shared-info {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
}

.morph-demo__shared-title {
	font-weight: 600;
}

.morph-demo__shared-subtitle {
	font-size: 0.875rem;
}

.morph-demo__shared-target {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	background: var(--pro-bg-primary, var(--pro-surface-bg, #ffffff));
	border: 1px solid var(--pro-border, var(--pro-border-color, #e1e4e8));
	border-radius: var(--pro-radius-lg, 0.75rem);
	box-shadow: var(--pro-shadow-lg, 0 10px 25px rgba(0, 0, 0, 0.15));
	padding: 1.5rem;
	z-index: 10;
}

.morph-demo__shared-hero {
	height: 150px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--pro-bg-tertiary, #e9ecef);
	border-radius: var(--pro-radius-md, 0.5rem);
	margin-bottom: 1rem;
	color: var(--pro-primary, #0366d6);
}

.morph-demo__shared-details {
	color: var(--pro-text-primary, #24292e);
}

.morph-demo__shared-details h4 {
	margin: 0 0 0.25rem;
	color: var(--pro-text-primary, #24292e);
}

.morph-demo__shared-body {
	margin: 1rem 0;
	line-height: 1.6;
	color: var(--pro-text-secondary, #586069);
}

/* Responsive */
@media (max-width: 576px) {
	.morph-demo__state-display {
		flex-direction: column;
		gap: 0.5rem;
	}

	.morph-demo__cards {
		grid-template-columns: 1fr;
	}

	.morph-demo__modal {
		width: 95%;
		padding: 1.5rem;
	}

	.morph-demo__shared-source {
		flex-direction: column;
		text-align: center;
	}
}
