@use "sass:math";
@use "@automattic/jetpack-base-styles/gutenberg-base-styles" as gb;
@use "../../../shared/styles/jetpack-variables";
@use "variables";

.wp-story-display-contents {
	display: contents;
}

.wp-story-app {
	padding: 10px;
}

.wp-story-container {
	display: block;
	height: 320px;
	width: 180px;
	margin-left: auto;
	margin-right: auto;
	margin-bottom: 24px;
	position: relative;
	list-style: none;
	padding: 0;
	z-index: 1;
	border-radius: 15px;
	overflow: hidden;
	-webkit-tap-highlight-color: transparent;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
	transition: box-shadow 0.3s ease-in-out, transform 0.3s cubic-bezier(0.18, 0.14, 0.25, 1);
	break-inside: avoid;
	page-break-inside: avoid;

	figure {
		transition: transform 0.3s cubic-bezier(0.18, 0.14, 0.25, 1);
	}

	&:hover {
		box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
		transform: scale3d(1.03, 1.03, 1);

		figure {
			transform: scale3d(1.07, 1.07, 1);
		}
	}

	button {
		box-shadow: none;
		text-shadow: none;
		background-color: transparent;
		border: 0;
		outline-width: 0;
		cursor: pointer;
	}

	&.wp-story-initialized {
		opacity: 1;
	}

	&.wp-story-clickable {
		cursor: pointer;
	}

	.wp-story-wrapper,
	.wp-story-slide {
		padding: 0;
		margin: 0;
		line-height: normal;
		list-style-type: none;
	}

	.wp-story-wrapper {
		display: block;
		position: absolute;
		height: 100%;
		bottom: 0;
		top: 0;
		left: 0;
		right: 0;
		z-index: -1;
		border-radius: 15px;
		background-color: variables.$wp-story-background-color;
	}

	.wp-story-slide {
		display: flex;
		height: 100%;
		width: 100%;

		figure {
			align-items: center;
			display: flex;
			height: 100%;
			width: 100%;
			justify-content: center;
			margin: 0;
			position: relative;
			overflow: hidden;
			object-fit: contain;
		}

		&.is-loading {
			position: absolute;
			z-index: 1;
			background-color: #484542;
			align-items: center;
			justify-content: center;

			&.semi-transparent {
				background-color: #4845427f;
			}

			&.transparent {
				background-color: transparent;
			}

			@keyframes rotate-spinner {

				100% {
					transform: rotate(360deg);
				}
			}

			.wp-story-loading-spinner {
				display: flex;
				align-items: center;
			}

			.wp-story-loading-spinner__outer,
			.wp-story-loading-spinner__inner {
				margin: auto;
				box-sizing: border-box;
				border: 0.1em solid transparent;
				border-radius: 50%;
				animation: 3s linear infinite;
				animation-name: rotate-spinner;
			}

			.wp-story-loading-spinner__outer {
				width: 40px;
				height: 40px;
				font-size: 40px;
				border-top-color: #fff;
			}

			.wp-story-loading-spinner__inner {
				width: 100%;
				height: 100%;
				border-top-color: #c4c4c4;
				border-right-color: #c4c4c4;
				opacity: 0.4;
			}
		}
	}

	.wp-story-image,
	.wp-story-video {
		display: block;
		height: auto;
		width: auto;
		max-height: 100%;
		max-width: 100%;
		margin: 0;
		border: 0;

		&.wp-story-crop-wide {
			max-width: revert;
		}

		&.wp-story-crop-narrow {
			max-height: revert;
		}
	}

	.wp-story-meta,
	.wp-story-controls {
		display: none;
	}

	.wp-story-overlay {
		width: 100%;
		position: absolute;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 1;
		top: 0;
		bottom: 0;
		right: 0;
		left: 0;

		.wp-story-button-play,
		.wp-story-button-replay {
			cursor: pointer;
		}

		.wp-story-embed-icon,
		.wp-story-embed-icon-expand {
			position: absolute;
			top: 0;
			right: 0;
			margin: 15px;
			padding: 5px 3px;
			display: flex;
			align-items: center;
			background-color: rgba(0, 0, 0, 0.5);
			border-radius: 5px;
			color: #fff;

			* {
				margin: 0 2px;
			}

			svg {
				fill: #fff;
				width: 20px;
				height: 20px;
			}

			span {
				color: #fff;
				line-height: 20px;
				font-size: 16px;
				font-weight: 600;
				font-family: sans-serif;
			}
		}

		.wp-story-embed-icon-expand {
			background-color: transparent;

			svg {
				filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.6));
			}
		}
	}

	&.wp-story-ended,
	&.wp-story-disabled {

		.wp-story-overlay {
			background-color: rgba(255, 255, 255, 0.4);
		}
	}

	.wp-story-prev-slide,
	.wp-story-next-slide {
		display: none;
		position: absolute;

		button {
			border-width: 0;

			&:hover {
				border-width: 2px;
			}
		}
	}

	.wp-story-prev-slide {
		margin: auto;
		left: -84px;
	}

	.wp-story-next-slide {
		margin: auto;
		right: -84px;
	}

	.wp-story-pagination {
		position: absolute;
		text-align: center;
		z-index: 2;
	}

	.wp-story-pagination-bullets {
		display: flex;
		position: absolute;
		margin: 7px 10px;
		top: auto;
		right: 0;
		left: 0;
		bottom: 0;
		overflow: hidden;
		transition: flex-basis 1000ms ease-in-out;

		.wp-story-pagination-bullet {
			flex: 1;
			justify-content: space-between;
			opacity: 1;
			margin: 0 2px;
			padding: 6px 0;
			vertical-align: top;

			.wp-story-pagination-bullet-bar {
				min-width: 12px;
				width: 100%;
				height: 4px;
				background: variables.$wp-story-pagination-bullet-color;
			}

			.wp-story-pagination-bullet-bar-progress {
				width: 0;
				opacity: 1;
				height: 4px;
				background-color: variables.$wp-story-pagination-bullet-progress-color;
				transition: width 0.1s ease;
			}
		}

		.wp-story-pagination-ellipsis {
			flex: 0 0 4px;

			.wp-story-pagination-bullet-bar {
				min-width: 6px;
			}
		}
	}

	.wp-story-controls {
		display: none;
		width: 64px;
		flex-direction: row;
		justify-content: space-between;
		margin: 0 10px;
		position: absolute;
		bottom: 30px;
		z-index: 3;

		@media ( max-width: gb.$break-medium ) {
			bottom: 50px;
			margin: 0 16px;
		}
	}

	&.wp-story-with-controls {
		overflow: visible;
		border-radius: 0;
		box-shadow: none !important;
		transition: none !important;

		.wp-story-wrapper {
			border-radius: 15px;
			box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
			overflow: hidden;
		}

		figure {
			transform: none !important;
			transition: none !important;
		}

		&:hover {
			transform: none !important;
			box-shadow: none !important;

			figure {
				transform: none;
			}
		}

		.wp-story-prev-slide,
		.wp-story-next-slide {
			display: block;
		}

		.wp-story-prev-slide {
			margin: auto;
			left: -48px;
		}

		.wp-story-next-slide {
			margin: auto;
			right: -48px;
		}

		.wp-story-controls {
			display: flex;

			// reapply initial styles
			@media ( max-width: gb.$break-medium ) {
				bottom: 30px;
				margin: 0 10px;
			}
		}
	}
}

.wp-story-fullscreen {

	&.wp-story-app {
		position: fixed;
		// can force redraw on mobile safari
		transform: translate3d(0, 0, 0);
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		margin: 0;
		padding: 0;
		z-index: 9999999999;
		width: 100% !important;
		max-width: 100% !important;
		height: 100%;
		user-select: none;
		-webkit-touch-callout: none;
	}

	&.wp-story-container {
		margin: auto;
		height: 100%;
		width: 100%;
		max-width: 100%;
		max-height: 100%;
		border-radius: 0;
		box-shadow: none;
		transform: none;
		transition: none !important;
		overflow: initial;

		figure {
			transform: none;
			transition: none !important;
		}

		&:focus {
			outline: none;
		}

		&::before {
			box-shadow: none;

			&:hover {
				opacity: 0;
				transition: none !important;
			}
		}

		.wp-story-wrapper {
			height: auto;
			margin-top: 84px;
			margin-bottom: 84px;
			border-radius: 0;
			overflow: initial;

			@media ( max-width: gb.$break-medium ) {
				margin-top: 0;
				margin-bottom: 0;
			}
		}

		.wp-story-slide {
			height: 100%;
			width: auto;

			&.is-loading {
				width: 100%;
			}
		}

		.wp-story-meta {
			padding: 20px 0;
			display: flex;
			flex-direction: row;
			color: #fff;
			font-family: sans-serif;
			line-height: 20px;
			align-items: center;

			@media ( max-width: gb.$break-medium ) {
				padding: 16px;
				background: rgb(0, 0, 0);
				background: linear-gradient(180deg, rgba(0, 0, 0, 0.63) 0%, rgba(0, 0, 0, 0) 100%);
			}

			.wp-story-icon {
				background-color: #fff;
				width: 40px;
				height: 40px;
				flex-shrink: 0;
				margin: 0 16px 0 0;
				border: 2px solid #fff;
				border-radius: 4px;

				img {
					text-align: center;
					width: 100%;
					height: 100%;
				}

				@media ( max-width: gb.$break-medium ) {
					width: 24px;
					height: 24px;
					margin: 0 12px 0 0;
				}
			}

			.wp-story-title {
				font-size: 14px;
				font-weight: 600;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;

				@media ( max-width: gb.$break-medium ) {
					font-size: 12px;
				}
			}

			.wp-story-exit-fullscreen {
				margin-left: auto;
				order: 3;
				min-width: 24px;
				min-height: 24px;
			}
		}

		.wp-story-overlay {
			margin-top: 84px;
			margin-bottom: 84px;

			.wp-story-embed-icon,
			.wp-story-embed-icon-expand {
				display: none;
			}

			@media ( max-width: gb.$break-medium ) {
				margin-top: 0;
				margin-bottom: 0;
				top: 76px;
				bottom: 76px;
			}
		}

		&.wp-story-ended,
		&.wp-story-disabled {

			.wp-story-overlay {

				@media ( max-width: gb.$break-medium ) {
					top: 0;
					bottom: 0;
				}
			}
		}

		.wp-story-prev-slide,
		.wp-story-next-slide {
			display: block;

			@media ( max-width: gb.$break-medium ) {
				display: block;
				position: absolute;
				top: 0;
				bottom: 0;
				height: 100%;

				button {
					display: none;
				}
			}
		}

		.wp-story-prev-slide {

			@media ( max-width: gb.$break-medium ) {
				left: 0;
				width: 33.33%;
			}
		}

		.wp-story-next-slide {

			@media ( max-width: gb.$break-medium ) {
				right: 0;
				width: 66.66%;
			}
		}

		.wp-story-controls {
			width: 88px;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			position: absolute;
			bottom: 20px;
			margin: 0;

			@media ( max-width: gb.$break-medium ) {
				bottom: 36px;
				margin: 0 16px;
			}
		}

		.wp-story-pagination-bullets {
			display: flex;
			position: absolute;
			bottom: 42px;
			top: auto;
			padding: 14px 0;
			margin: 0;

			.wp-story-pagination-bullet {
				justify-content: space-between;

				&:first-child {
					margin-left: 0;
				}

				&:last-child {
					margin-right: 0;
				}
			}

			@media ( max-width: gb.$break-medium ) {
				bottom: 0;
				padding: 10px 16px;
			}
		}
	}
}

.wp-story-background {
	display: block;
	position: absolute;
	left: 0;
	right: 0;
	top: 0;
	bottom: 0;
	z-index: -2;
	background-color: variables.$wp-story-background-color;

	svg {
		width: 0;
		height: 0;
	}

	img {
		width: 100%;
		height: 100%;
	}

	.wp-story-background-dark {
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		opacity: 0.12;

		@supports (backdrop-filter: none) {
			backdrop-filter: blur(18px);
		}
	}

	.wp-story-background-image {
		width: 100%;
		height: 100%;
		background-repeat: no-repeat;
		background-position: left center;
		background-size: 100% auto;
		display: none;

		@supports not (backdrop-filter: none) {
			filter: blur(18px);
			filter: url(#gaussian-blur-18);
			filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius="18");
		}
	}

	.wp-story-background-blur {
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		background-color: #0e1112e0;

		@supports (backdrop-filter: none) {
			backdrop-filter: blur(18px);
		}
	}
}

html.wp-story-in-fullscreen {
	overflow: hidden;
	scroll-behavior: auto;
}

body.wp-story-in-fullscreen {
	overflow: hidden;
	padding-right: 15px; /* Avoid width reflow */
	position: fixed;
	width: 100%;
	height: 100%;
}

