/**
 * Reader (1.41.0): a PDF read over the page.
 *
 * The dialog fills the viewport -- the page is what is being read, and on a
 * phone there is no room to spare around it -- with a bar above (the title,
 * the original file, Close) and a bar below (the pages and the zoom). Every
 * control is at least 44px square. The page is centred while it fits and
 * scrolls from its edge once it does not (`margin: auto` in a scrolling
 * flex box, never `place-items: center`, which would put the overflow out of
 * reach). Browser pinch-zoom is off inside the page area: the reader's own
 * zoom redraws the page sharp, where a pinch would enlarge its pixels.
 *
 * See `ILM\Components\Support\Reader`.
 *
 * @package ILM\Components
 * @since 1.41.0
 */

.ilm-reader-open {
	overflow: hidden;
}

.ilm-reader {
	box-sizing: border-box;
	inline-size: 100%;
	max-inline-size: 100vw;
	block-size: 100%;
	max-block-size: 100vh;
	max-block-size: 100dvh;
	margin: 0;
	padding: 0;
	border: 0;
	background: #16161a;
	color: #fff;
	overflow: hidden;
}

.ilm-reader::backdrop {
	background-color: rgb(0 0 0 / 0.86);
}

.ilm-reader__panel {
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
	inline-size: 100%;
	block-size: 100%;
	padding-block-start: env(safe-area-inset-top, 0);
	padding-block-end: env(safe-area-inset-bottom, 0);
	padding-inline-start: env(safe-area-inset-left, 0);
	padding-inline-end: env(safe-area-inset-right, 0);
}

/* Full screen is the panel's (the standard refuses a dialog itself). */
.ilm-reader__panel:fullscreen {
	background: #16161a;
	color: #fff;
}

.ilm-reader__bar {
	box-sizing: border-box;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	flex: none;
	padding: 0.5rem;
	background: #0d0d10;
}

.ilm-reader__bar--top {
	border-block-end: 1px solid rgb(255 255 255 / 0.12);
	flex-wrap: nowrap;
}

.ilm-reader__bar--bottom {
	justify-content: center;
	column-gap: 1.5rem;
	border-block-start: 1px solid rgb(255 255 255 / 0.12);
}

.ilm-reader__title {
	flex: 1 1 auto;
	min-inline-size: 0;
	margin: 0;
	padding-inline-start: 0.5rem;
	color: inherit;
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.3;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ilm-reader__group {
	display: flex;
	align-items: center;
	gap: 0.25rem;
}

.ilm-reader__button,
.ilm-reader__original {
	appearance: none;
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.375rem;
	min-inline-size: 2.75rem;
	min-block-size: 2.75rem;
	padding: 0 0.625rem;
	border: 1px solid rgb(255 255 255 / 0.28);
	border-radius: var(--ilm-radius-md, 0.375rem);
	background: transparent;
	color: #fff;
	font: inherit;
	font-size: 0.9375rem;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
}

.ilm-reader__button {
	padding: 0;
}

.ilm-reader__button .ilm-icon,
.ilm-reader__original .ilm-icon {
	inline-size: 1.25rem;
	block-size: 1.25rem;
	flex: none;
}

.ilm-reader__button:hover:not(:disabled),
.ilm-reader__original:hover {
	background: rgb(255 255 255 / 0.12);
	border-color: #fff;
}

.ilm-reader__button[aria-pressed="true"] {
	background: #fff;
	border-color: #fff;
	color: #0d0d10;
}

.ilm-reader__button:disabled {
	opacity: 0.4;
	cursor: default;
}

.ilm-reader__button[hidden],
.ilm-reader__original[hidden] {
	display: none;
}

.ilm-reader__button:focus-visible,
.ilm-reader__original:focus-visible,
.ilm-reader__page:focus-visible,
.ilm-reader__fallback:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
}

.ilm-reader__original {
	flex: none;
	padding-inline: 0.75rem;
	white-space: nowrap;
}

.ilm-reader__where {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
	padding-inline: 0.25rem;
	font-size: 0.9375rem;
	white-space: nowrap;
}

/*
 * The theme styles every text field; the reader's page number must stay
 * readable on the dark bar, hence the weight of the selector.
 */
.ilm-reader .ilm-reader__page {
	box-sizing: border-box;
	inline-size: 3.75rem;
	min-block-size: 2.75rem;
	margin: 0;
	padding: 0 0.375rem;
	border: 1px solid rgb(255 255 255 / 0.28);
	border-radius: var(--ilm-radius-md, 0.375rem);
	background: #0d0d10;
	color: #fff;
	font: inherit;
	font-size: 1rem;
	text-align: center;
	-moz-appearance: textfield;
}

.ilm-reader .ilm-reader__page::-webkit-inner-spin-button,
.ilm-reader .ilm-reader__page::-webkit-outer-spin-button {
	margin: 0;
	-webkit-appearance: none;
}

.ilm-reader__page:disabled {
	opacity: 0.6;
}

.ilm-reader__zoom {
	min-inline-size: 3.25rem;
	font-size: 0.875rem;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

.ilm-reader__stage {
	box-sizing: border-box;
	position: relative;
	display: flex;
	flex: 1 1 auto;
	min-block-size: 0;
	padding: 1rem;
	overflow: auto;
	overscroll-behavior: contain;
	touch-action: pan-x pan-y;
	-webkit-overflow-scrolling: touch;
}

.ilm-reader__canvas {
	display: block;
	flex: none;
	margin: auto;
	background: #fff;
	box-shadow: 0 0.25rem 1.5rem rgb(0 0 0 / 0.5);
	transition: opacity 0.15s ease;
}

.ilm-reader__canvas[hidden],
.ilm-reader__loading[hidden],
.ilm-reader__error[hidden] {
	display: none;
}

.ilm-reader__stage.is-busy .ilm-reader__canvas {
	opacity: 0.6;
}

.ilm-reader__loading,
.ilm-reader__error {
	margin: auto;
	max-inline-size: 28rem;
	text-align: center;
	line-height: 1.5;
}

.ilm-reader__loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.75rem;
}

.ilm-reader__spinner {
	display: block;
	inline-size: 2.5rem;
	block-size: 2.5rem;
	border: 3px solid rgb(255 255 255 / 0.25);
	border-block-start-color: #fff;
	border-radius: 50%;
	animation: ilm-reader-spin 0.9s linear infinite;
}

.ilm-reader__error p {
	margin: 0 0 1rem;
}

.ilm-reader__fallback {
	display: inline-flex;
	align-items: center;
	min-block-size: 2.75rem;
	padding: 0 1.25rem;
	border-radius: var(--ilm-radius-md, 0.375rem);
	background: #fff;
	color: #0d0d10;
	font-weight: 600;
	text-decoration: none;
}

@keyframes ilm-reader-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.ilm-reader__spinner {
		animation-duration: 3s;
	}

	.ilm-reader__canvas {
		transition: none;
	}
}

/* A phone: the bars tighten, the original keeps its icon and its name. */
@media (max-width: 37.4375rem) {
	.ilm-reader__bar--bottom {
		column-gap: 0.75rem;
		row-gap: 0.25rem;
		padding-block: 0.375rem;
	}

	.ilm-reader__stage {
		padding: 0.5rem;
	}

	.ilm-reader__zoom {
		display: none;
	}

	.ilm-reader__original {
		padding-inline: 0.5rem;
	}

	.ilm-reader__original-label {
		position: absolute;
		inline-size: 1px;
		block-size: 1px;
		margin: -1px;
		padding: 0;
		overflow: hidden;
		clip: rect(0 0 0 0);
		white-space: nowrap;
		border: 0;
	}
}

/* The trigger a card's cover is: a hint that it opens. */
.ilm-reader-trigger {
	display: block;
	color: inherit;
}
