/*
 * Article reader: photos beside the text on wide screens, photos in the text everywhere else.
 * Wide layout is decided by the same media query in article-reader.js (WIDE_QUERY).
 */

/* ---------- Photos inside the text (narrow screens, reduced motion, no JavaScript, print) ---------- */

.single-shell .wp-block-post-content > .wp-block-image,
.single-shell .wp-block-post-content > .wp-block-gallery {
	margin-block: var(--wp--preset--spacing--md);
}
.single-shell .wp-block-post-content > .wp-block-image + .wp-block-image,
.single-shell .wp-block-post-content > .wp-block-image + .wp-block-gallery,
.single-shell .wp-block-post-content > .wp-block-gallery + .wp-block-image {
	margin-top: calc(var(--wp--preset--spacing--md) * 0.75);
}
/*
 * Photos keep the size WordPress writes in width/height, so space is reserved before lazy images load.
 * Portrait photos are capped at one screen and centred inside that box instead of being stretched.
 */
.single-shell .wp-block-post-content > .wp-block-image img {
	display: block;
	max-width: 100%;
	height: auto;
	max-height: 82svh;
	margin-inline: auto;
	object-fit: contain;
}
.single-shell .wp-block-post-content .wp-block-image figcaption,
.single-shell .wp-block-post-content .wp-block-gallery > figcaption {
	margin: 0.5rem 0 0;
	text-align: center;
	font-family: var(--wp--preset--font-family--sans);
	font-size: 0.78rem;
	line-height: 1.6;
	color: var(--wp--preset--color--muted);
}

.article-reader__panel { display: none; }

/* ---------- Photo panel parts, shared by the wide and stacked layouts ---------- */

@media (min-width: 1024px) and (min-height: 600px) and (prefers-reduced-motion: no-preference),
	(orientation: landscape) and (min-width: 600px) and (max-height: 599.98px) and (prefers-reduced-motion: no-preference),
	(max-width: 1023.98px) and (orientation: portrait) and (min-height: 560px) and (prefers-reduced-motion: no-preference) {
	/* Source photos stay in the text for screen readers' order but are drawn in the panel. */
	.single-shell.reader-enabled .reader-source-media {
		position: absolute !important;
		width: 1px !important;
		height: 1px !important;
		margin: 0 !important;
		overflow: hidden !important;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	.article-reader__panel {
		min-width: 0;
		max-width: none;
		display: flex;
		flex-direction: column;
		font-family: var(--wp--preset--font-family--sans);
		color: var(--wp--preset--color--muted);
	}

	/* Photo, caption and buttons. JS sets the photo box so the buttons sit on the real photo edges. */
	.article-reader__stage { position: relative; min-height: 0; }
	.article-reader__slide {
		position: absolute;
		margin: 0;
		opacity: 0;
		transition: opacity 1200ms cubic-bezier(.22, .61, .36, 1);
		cursor: pointer;
	}
	.article-reader__slide.is-active { opacity: 1; }
	/* A slide fading out takes no presses: a video's link there would leave the article for YouTube. */
	.article-reader__slide:not(.is-active) { pointer-events: none; }
	.article-reader__slide:focus-visible { outline: 2px solid var(--wp--preset--color--accent); outline-offset: 3px; }
	.article-reader__slide img {
		display: block;
		width: 100%;
		height: 100%;
		max-width: none;
		max-height: none;
		margin: 0;
		object-fit: contain;
	}
	.article-reader__slide a { display: contents; }

	.article-reader__slide figcaption { display: none; }

	/* YouTube (#34): the thumbnail and play button fill the player-shaped box JS sets (16:9, or 9:16 for Shorts).
	   (0,4,0) outranks youtube.css's .nk-youtube.is-short .nk-youtube__play (0,3,0) whatever the stylesheet order. */
	.article-reader__slide.nk-youtube { margin: 0; background: var(--wp--preset--color--ink); }
	.article-reader__panel .article-reader__slide.nk-youtube .nk-youtube__play,
	.article-reader__panel .article-reader__slide.nk-youtube .nk-youtube__player {
		display: block;
		width: 100%;
		height: 100%;
		max-width: none;
		max-height: none;
		margin: 0;
		aspect-ratio: auto;
	}

	.article-reader__meta {
		position: absolute;
		display: grid;
		grid-template-columns: 2.5rem minmax(0, 1fr) 2.5rem;
		grid-template-rows: auto 2.75rem;
		align-items: start;
		padding-top: 0.25rem;
	}
	.article-reader__caption {
		grid-column: 2;
		grid-row: 1;
		min-height: 2.5rem;
		margin: 0;
		padding-top: 0.45rem;
		text-align: center;
		font-size: 0.78rem;
		line-height: 1.6;
	}
	.article-reader__button {
		display: grid;
		place-items: center;
		width: 2.5rem;
		height: 2.5rem;
		padding: 0;
		border: 0;
		border-radius: 50%;
		background: transparent;
		color: var(--wp--preset--color--accent);
		cursor: pointer;
		-webkit-tap-highlight-color: transparent;
	}
	.article-reader__button svg { width: 1.15rem; height: 1.15rem; }
	.article-reader__button:focus-visible { outline: 2px solid var(--wp--preset--color--accent); outline-offset: 1px; }
	.article-reader__button:disabled { opacity: .25; cursor: default; background: transparent; }
	.article-reader__button[data-action="previous"] { grid-column: 1; grid-row: 1; justify-self: start; margin-left: -0.7rem; }
	.article-reader__button[data-action="next"] { grid-column: 3; grid-row: 1; justify-self: end; margin-right: -0.7rem; }
	.article-reader__button[data-action="toggle"] { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
	.article-reader__button[data-action="toggle"][hidden] { display: grid; visibility: hidden; }
	/* No full screen on a video (YouTube's player has its own); the space stays so nothing shifts. */
	.article-reader__button[data-action="expand"][hidden] { display: grid; visibility: hidden; }
	/* Expand sits under the next arrow, off the photo. */
	.article-reader__button[data-action="expand"] { grid-column: 3; grid-row: 2; justify-self: end; margin-right: -0.7rem; }

	/* Every body photo, in article order. A grey bar marks photos that play automatically. */
	.article-reader__count {
		margin: 0;
		font-size: 0.78rem;
		font-variant-numeric: tabular-nums;
	}
	.article-reader__thumbnails {
		position: relative;
		display: flex;
		align-items: flex-start;
		gap: 0.5rem 0.6rem;
		padding: 2px;
	}
	.article-reader__run {
		display: flex;
		flex: none;
		gap: 0.3rem;
		padding-bottom: 0.45rem;
		position: relative;
	}
	.article-reader__run.is-autoplay::after {
		content: '';
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		height: 2px;
		border-radius: 1px;
		background: #c9ccca;
	}
	.article-reader__thumb {
		flex: none;
		width: 2.85rem;
		height: 2.15rem;
		padding: 0;
		border: 1px solid transparent;
		background: none;
		opacity: 0.55;
		cursor: pointer;
	}
	.article-reader__thumb.is-active { border-color: var(--wp--preset--color--accent); opacity: 1; }
	.article-reader__thumb:focus-visible { outline: 2px solid var(--wp--preset--color--accent); outline-offset: 1px; }
	.article-reader__thumb img { display: block; width: 100%; height: 100%; max-height: none; object-fit: cover; }
	/* A small play mark on a video's tile. */
	.article-reader__thumb.is-video { position: relative; }
	.article-reader__thumb.is-video::after {
		content: '';
		position: absolute;
		inset: 50% auto auto 50%;
		margin: -0.4rem 0 0 -0.25rem;
		border-style: solid;
		border-width: 0.4rem 0 0.4rem 0.65rem;
		border-color: transparent transparent transparent #fff;
		filter: drop-shadow(0 0 2px rgba(0, 0, 0, .6));
	}
}

@media (hover: hover) {
	.article-reader__button:hover { background: rgba(89, 106, 115, .08); }
	.article-reader__thumb:hover { opacity: 0.85; }
}

/* ---------- Photos beside the text: wide screens and phones held sideways ---------- */

@media (min-width: 1024px) and (min-height: 600px) and (prefers-reduced-motion: no-preference),
	(orientation: landscape) and (min-width: 600px) and (max-height: 599.98px) and (prefers-reduced-motion: no-preference) {
	.single-shell.reader-enabled {
		--reader-gap: clamp(2rem, 3.5vw, 5rem);
		width: min(100% - clamp(2rem, 4vw, 7rem), 112rem);
		max-width: none;
		margin-inline: auto !important;
		box-sizing: border-box;
		display: grid;
		grid-template-columns: minmax(0, 1.85fr) minmax(20rem, 1fr);
		column-gap: var(--reader-gap);
		align-items: start;
		padding-top: var(--wp--preset--spacing--md);
	}

	.single-shell.reader-enabled > :not(.article-reader__panel) {
		grid-column: 2;
		width: 100%;
		max-width: none;
		margin-inline: 0 !important;
	}
	.single-shell.reader-enabled > .wp-block-post-date { grid-row: 1; }
	.single-shell.reader-enabled > .wp-block-post-title { grid-row: 2; }
	.single-shell.reader-enabled > .wp-block-post-featured-image { grid-row: 3; }
	.single-shell.reader-enabled > .wp-block-post-content { grid-row: 4; }
	.single-shell.reader-enabled > .wp-block-post-terms { grid-row: 5; }
	.single-shell.reader-enabled > .post-navigation { grid-row: 6; }
	.single-shell.reader-enabled > .wp-block-post-content > * { max-width: none; }

	.article-reader__panel {
		grid-column: 1;
		grid-row: 1 / span 6;
		position: sticky;
		top: 1rem;
		height: calc(100dvh - 2rem);
		margin: 0 !important;
		gap: 1rem;
	}
	.article-reader__stage { flex: 1 1 auto; }
	.article-reader__index { flex: none; }
	.article-reader__panel:not(.is-compact) .article-reader__count { margin-bottom: 0.4rem; }
	.article-reader__panel:not(.is-compact) .article-reader__thumbnails {
		flex-wrap: wrap;
		max-height: min(30dvh, 12rem);
		overflow-y: auto;
	}
}

/* Phones held sideways: little height, so a narrower text column and tighter margins. */
@media (orientation: landscape) and (min-width: 600px) and (max-height: 599.98px) and (prefers-reduced-motion: no-preference) {
	.single-shell.reader-enabled {
		--reader-gap: 1.75rem;
		width: calc(100% - 2rem - env(safe-area-inset-left) - env(safe-area-inset-right));
		grid-template-columns: minmax(0, 1.6fr) minmax(16rem, 1fr);
		padding-top: 0.5rem;
	}
	.article-reader__panel {
		top: 0.5rem;
		height: calc(100dvh - 1rem);
		gap: 0.4rem;
	}
}

/* ---------- Small portrait screens: photo pinned on top, text scrolling below ---------- */

@media (max-width: 1023.98px) and (orientation: portrait) and (min-height: 560px) and (prefers-reduced-motion: no-preference) {
	.article-reader__panel {
		position: sticky;
		top: 0;
		z-index: 10;
		/* Reach the screen edges so the text never shows beside the photo while it scrolls under. */
		margin-inline: calc(var(--wp--preset--spacing--md) * -1) !important;
		padding: 0.5rem var(--wp--preset--spacing--md) 0.3rem;
		background: var(--wp--preset--color--paper);
		border-bottom: 1px solid var(--wp--preset--color--line);
	}
	.single-shell.reader-enabled { padding-top: 0; }
	.single-shell.reader-enabled > .wp-block-post-date { margin-top: var(--wp--preset--spacing--md); }
	.article-reader__stage { flex: none; }
}

/* ---------- Compact panel (phones, upright or sideways): one caption row, one thumbnail row ---------- */

.article-reader__panel.is-compact .article-reader__meta { grid-template-rows: auto; padding-top: 0; }
.article-reader__panel.is-compact .article-reader__caption { min-height: 2.25rem; padding-top: 0.45rem; }
.article-reader__panel.is-compact .article-reader__button { width: 2.25rem; height: 2.25rem; }
.article-reader__panel.is-compact .article-reader__button[data-action="previous"] { margin-left: -0.55rem; }
.article-reader__panel.is-compact .article-reader__button[data-action="next"] { margin-right: -0.55rem; }
.article-reader__panel.is-compact .article-reader__index {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	min-width: 0;
}
.article-reader__panel.is-compact .article-reader__count { flex: none; min-width: 3.2em; }
.article-reader__panel.is-compact .article-reader__thumbnails {
	flex: 1 1 auto;
	min-width: 0;
	flex-wrap: nowrap;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scrollbar-width: none;
	padding-bottom: 0;
}
.article-reader__panel.is-compact .article-reader__thumbnails::-webkit-scrollbar { display: none; }
.article-reader__panel.is-compact .article-reader__run { padding-bottom: 0.35rem; }
.article-reader__panel.is-compact .article-reader__thumb { width: 2.4rem; height: 2.4rem; }
/* Play/stop and expand move to the end of the thumbnail row. */
.article-reader__panel.is-compact .article-reader__index > [data-action="toggle"] { flex: none; }
.article-reader__panel.is-compact .article-reader__index > [data-action="expand"] { flex: none; margin: 0 -0.4rem 0 -0.5rem; }

@media print {
	.article-reader__panel { display: none !important; }
}

/* ---------- Full-screen photo ---------- */

html.has-lightbox { overflow: hidden; }
.article-lightbox {
	width: 100vw;
	max-width: none;
	height: 100dvh;
	max-height: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: #141515;
	color: #e9e9e6;
	overscroll-behavior: contain;
}
.article-lightbox::backdrop { background: #141515; }
.article-lightbox[open] {
	display: flex;
	flex-direction: column;
	animation: article-lightbox-in 280ms cubic-bezier(.22, .61, .36, 1);
}
@keyframes article-lightbox-in { from { opacity: 0; } to { opacity: 1; } }
.article-lightbox__figure {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	box-sizing: border-box;
	flex: 1 1 auto;
	min-height: 0;
	width: 100%;
	margin: 0;
	padding: calc(env(safe-area-inset-top) + 3.5rem) calc(env(safe-area-inset-right) + 1rem) 0.75rem calc(env(safe-area-inset-left) + 1rem);
}
.article-lightbox__figure img {
	display: block;
	min-height: 0;
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
}
.article-lightbox__figure figcaption {
	flex: none;
	font-family: var(--wp--preset--font-family--sans);
	font-size: 0.8rem;
	line-height: 1.6;
	text-align: center;
}
/* Every body photo as small tiles, scrolling sideways. */
.article-lightbox__index {
	flex: none;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.5rem calc(env(safe-area-inset-right) + 1rem) calc(env(safe-area-inset-bottom) + 0.75rem) calc(env(safe-area-inset-left) + 1rem);
	font-family: var(--wp--preset--font-family--sans);
}
.article-lightbox__count {
	flex: none;
	min-width: 3.2em;
	margin: 0;
	font-size: 0.75rem;
	font-variant-numeric: tabular-nums;
	color: #a9aba8;
}
.article-lightbox__thumbnails {
	display: flex;
	flex: 1 1 auto;
	gap: 0.3rem;
	min-width: 0;
	padding: 2px;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scrollbar-width: none;
}
.article-lightbox__thumbnails::-webkit-scrollbar { display: none; }
.article-lightbox__thumb {
	flex: none;
	width: 3rem;
	height: 2.25rem;
	padding: 0;
	border: 1px solid transparent;
	background: none;
	opacity: 0.45;
	cursor: pointer;
}
.article-lightbox__thumb.is-active { border-color: #e9e9e6; opacity: 1; }
.article-lightbox__thumb:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.article-lightbox__thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
@media (hover: hover) { .article-lightbox__thumb:hover { opacity: 0.8; } }

.article-lightbox__close {
	position: absolute;
	top: calc(env(safe-area-inset-top) + 0.5rem);
	right: calc(env(safe-area-inset-right) + 0.5rem);
	display: grid;
	place-items: center;
	width: 2.75rem;
	height: 2.75rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .1);
	color: #fff;
	cursor: pointer;
}
.article-lightbox__close svg { width: 1.3rem; height: 1.3rem; }
.article-lightbox__close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
@media (hover: hover) { .article-lightbox__close:hover { background: rgba(255, 255, 255, .2); } }
@media (prefers-reduced-motion: reduce) { .article-lightbox[open] { animation: none; } }

/* ---------- Cover: featured image and title, shown on every visit ---------- */

.article-intro {
	position: fixed;
	inset: 0;
	z-index: 100000;
	margin: 0;
	background: #222;
	color: #fff;
	transition: opacity 2500ms cubic-bezier(.22, .61, .36, 1);
	/*
	 * Safety net. article-reader.js takes the cover over (data-reader-managed) and
	 * lifts it after 6 seconds; if the module never runs — blocked, failed to load,
	 * threw, or unsupported — the cover would otherwise hide the article for good.
	 */
	animation: nk-article-intro-failsafe 1200ms ease 6s forwards;
}
.article-intro[data-reader-managed] { animation: none; }
@keyframes nk-article-intro-failsafe {
	to {
		opacity: 0;
		visibility: hidden;
	}
}
.article-intro.is-leaving { opacity: 0; pointer-events: none; }
.article-intro img { display: block; width: 100%; height: 100%; object-fit: cover; }
.article-intro::after {
	content: '';
	position: absolute;
	inset: 0;
	background: linear-gradient(transparent 35%, rgba(0, 0, 0, .55));
	pointer-events: none;
}
.article-intro__title {
	position: absolute;
	z-index: 1;
	left: max(1.5rem, 7vw);
	right: max(1.5rem, 7vw);
	bottom: calc(env(safe-area-inset-bottom) + max(5.5rem, 14vh));
	margin: 0;
	max-width: 24em;
	text-wrap: balance;
	font-size: clamp(1.6rem, 3.5vw, 4rem);
	font-weight: 400;
	line-height: 1.5;
	text-shadow: 0 2px 24px rgba(0, 0, 0, .3);
}
.article-intro__skip {
	position: absolute;
	z-index: 1;
	left: max(1.5rem, 7vw);
	bottom: calc(env(safe-area-inset-bottom) + max(1.5rem, 5vh));
	min-height: 2.75rem;
	padding: 0;
	border: 0;
	border-bottom: 1px solid rgba(255, 255, 255, .55);
	background: transparent;
	color: #fff;
	font: inherit;
	font-family: var(--wp--preset--font-family--sans);
	font-size: .8rem;
	cursor: pointer;
}
@media (orientation: landscape) and (max-height: 500px) {
	.article-intro__title { bottom: calc(env(safe-area-inset-bottom) + 4.5rem); font-size: clamp(1.4rem, 3vw, 2rem); }
	.article-intro__skip { bottom: calc(env(safe-area-inset-bottom) + 1rem); }
}

/* The title only receives focus from script (tabindex="-1") when the cover closes; it is not a control. */
.single-shell > .wp-block-post-title[tabindex="-1"]:focus { outline: none; }

.single-shell .wp-block-post-date:has(.article-reader__reopen) {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 1rem;
}
.article-reader__reopen {
	min-height: 2.75rem;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--wp--preset--color--muted);
	font: inherit;
	cursor: pointer;
	text-decoration: underline;
	text-decoration-color: var(--wp--preset--color--line);
	text-underline-offset: 0.3em;
}

@media (prefers-reduced-motion: reduce) {
	.article-intro { transition: none; animation-duration: 1ms; }
}
@media print {
	.article-intro, .article-reader__reopen { display: none !important; }
}
