/**
 * Full-screen story viewer (Instagram/WhatsApp-style) and its no-JS
 * fallback list (taxonomy-story_category.php). Loaded only where used —
 * see mgglobalmed_enqueue_assets() in functions.php.
 */

/* ---------- Viewer overlay ---------- */
.story-viewer {
	position: fixed;
	inset: 0;
	z-index: 400;
	background-color: var(--color-viewer-bg);
	display: grid;
	grid-template-rows: 1fr;
}

.story-viewer[hidden] {
	display: none;
}

body.story-viewer-open {
	overflow: hidden;
}

.story-viewer__progress {
	position: absolute;
	inset-block-start: var(--space-3);
	inset-inline: var(--space-3);
	z-index: 3;
	display: flex;
	gap: var(--space-1);
}

.story-viewer__segment {
	flex: 1 1 0;
	height: 3px;
	border-radius: var(--radius-tag);
	background-color: rgba(var(--color-cream-rgb), 0.3);
	overflow: hidden;
}

.story-viewer__segment-fill {
	width: 0%;
	height: 100%;
	background-color: var(--color-cream);
}

.story-viewer__segment-fill--filled {
	width: 100%;
}

.story-viewer__segment-fill--running {
	animation-name: story-viewer-fill;
	animation-timing-function: linear;
	animation-fill-mode: forwards;
}

.story-viewer__segment-fill--paused {
	animation-play-state: paused;
}

@keyframes story-viewer-fill {
	from {
		width: 0%;
	}
	to {
		width: 100%;
	}
}

.story-viewer__close {
	position: absolute;
	inset-block-start: var(--space-5);
	inset-inline-end: var(--space-4);
	z-index: 3;
	background: none;
	border: none;
	color: var(--color-cream);
	font-size: var(--text-xl);
	padding: var(--space-2);
	cursor: pointer;
}

.story-viewer__close:focus-visible {
	outline: 2px solid var(--color-gold);
	outline-offset: 2px;
}

.story-viewer__stage {
	grid-area: 1 / 1;
	position: relative;
	overflow: hidden;
	touch-action: pan-y;
}

.story-viewer__media {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
}

.story-viewer__image {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
}

.story-viewer__video {
	width: 100%;
	height: 100%;
	border: none;
}

.story-viewer__zone {
	position: absolute;
	inset-block: 0;
	width: 33.333%;
	background: none;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	z-index: 2;
}

.story-viewer__zone--prev {
	inset-inline-start: 0;
	justify-content: flex-start;
	padding-inline-start: var(--space-4);
}

.story-viewer__zone--next {
	inset-inline-end: 0;
	justify-content: flex-end;
	padding-inline-end: var(--space-4);
}

.story-viewer__zone-icon {
	opacity: 0;
	color: var(--color-cream);
	font-size: var(--text-2xl);
	background-color: rgba(var(--color-viewer-bg-rgb), 0.35);
	border-radius: 50%;
	padding: var(--space-2);
}

.story-viewer__zone:focus-visible .story-viewer__zone-icon {
	opacity: 1;
	outline: 2px solid var(--color-gold);
}

/* Reduced motion: the tap zones become explicit, always-visible buttons
   instead of invisible regions, since there's no auto-advance countdown
   to lean on instead — see also story-viewer.js, which also skips
   autoplay/auto-advance entirely in this mode. */
@media (prefers-reduced-motion: reduce) {
	.story-viewer__zone-icon {
		opacity: 1;
	}
}

/* Stage and caption share the same grid cell so the caption's gradient
   naturally overlaps the bottom of the media, regardless of how tall the
   caption's own content is — no guessed pixel offset needed. */
.story-viewer__caption {
	grid-area: 1 / 1;
	align-self: end;
	z-index: 3;
	padding: var(--space-8) var(--space-5) var(--space-6);
	background: linear-gradient(to top, rgba(var(--color-viewer-bg-rgb), 0.85), rgba(var(--color-viewer-bg-rgb), 0));
	pointer-events: none;
}

.story-viewer__caption > * {
	pointer-events: auto;
}

.story-viewer__tag {
	margin: 0 0 var(--space-2);
	font-family: var(--font-mono);
	font-size: var(--text-xs);
	letter-spacing: var(--tracking-label);
	text-transform: uppercase;
	color: var(--color-gold);
}

.story-viewer__heading {
	margin: 0 0 var(--space-2);
	font-family: var(--font-display);
	font-size: var(--text-xl);
	color: var(--color-cream);
}

.story-viewer__description {
	margin: 0 0 var(--space-4);
	color: rgba(var(--color-cream-rgb), 0.85);
	font-size: var(--text-sm);
	max-width: 60ch;
}

.story-viewer__link {
	display: inline-flex;
}

/* The default .btn--secondary is dark-on-transparent, unreadable against
   the viewer's black background. */
.story-viewer .btn--secondary {
	color: var(--color-cream);
	border-color: var(--color-cream);
}

.story-viewer .btn--secondary:hover,
.story-viewer .btn--secondary:focus-visible {
	background-color: var(--color-cream);
	color: var(--color-ink);
}

/* ---------- No-JS story list (taxonomy-story_category.php) ---------- */
.story-list-page {
	padding-block: var(--space-8); /* 64px mobile */
}

@media (min-width: 640px) {
	.story-list-page {
		padding-block: var(--space-9); /* 96px tablet */
	}
}

@media (min-width: 1024px) {
	.story-list-page {
		padding-block: var(--space-10); /* 128px desktop */
	}
}

.story-list {
	display: flex;
	flex-direction: column;
	gap: var(--space-8);
	margin-block-start: var(--space-6);
}

.story-list-item {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	padding-block-end: var(--space-8);
	border-bottom: var(--border-hairline);
}

.story-list-item:last-child {
	border-bottom: none;
	padding-block-end: 0;
}

.story-list-item__media {
	width: 100%;
	max-height: 480px;
	object-fit: cover;
	border-radius: var(--radius-lg);
}

.story-list-item__video {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 9;
	border-radius: var(--radius-lg);
	overflow: hidden;
}

.story-list-item__video iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: none;
}

.story-list-item__heading {
	margin: 0;
}
