.meg-reader {
	--meg-ink: #1a1a1a;
	--meg-muted: #6d6d6d;
	--meg-panel: #1a1a1a;
	--meg-accent: #00a651;
	--meg-border: #e4e7e5;
	position: relative;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
	width: 100%;
	max-width: 1200px;
	height: min(82vh, 860px);
	height: min(82svh, 860px);
	min-height: min(420px, calc(100vh - 20px));
	min-height: min(420px, calc(100svh - 20px));
	max-height: calc(100vh - 20px);
	max-height: calc(100svh - 20px);
	margin: 12px auto;
	padding: 10px;
	overflow: hidden;
	border: 1px solid var(--meg-border);
	border-radius: 12px;
	background: #fff;
	box-shadow: 0 8px 28px rgba(0, 0, 0, .09);
	color: var(--meg-ink);
	font-family: Montserrat, "Helvetica Neue", Arial, sans-serif;
	line-height: 1.35;
	isolation: isolate;
}

.meg-reader *,
.meg-reader *::before,
.meg-reader *::after {
	box-sizing: border-box;
}

.meg-share-page {
	width: min(1240px, calc(100% - 2rem));
	margin: clamp(1rem, 4vw, 3rem) auto;
}

.meg-share-heading {
	margin: 0 auto 1rem;
	text-align: center;
}

.meg-share-heading h1 {
	margin: 0 0 .4rem;
	color: #1a1a1a;
	font-family: Montserrat, "Helvetica Neue", Arial, sans-serif;
	font-weight: 800;
}

.meg-toolbar {
	position: relative;
	z-index: 2;
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	min-height: 42px;
	margin-bottom: 6px;
	padding: 4px 6px;
	border-radius: 8px;
	background: var(--meg-panel);
	color: #fff;
}

.meg-page-controls,
.meg-view-controls {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	gap: 3px;
}

.meg-view-controls {
	flex-wrap: wrap;
	margin-left: auto;
}

.meg-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-width: 34px;
	min-height: 34px;
	padding: 5px 8px;
	border: 1px solid transparent;
	border-radius: 6px;
	background: transparent;
	color: #fff;
	font: inherit;
	font-size: 11px;
	font-weight: 650;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
	transition: background .14s ease, color .14s ease, border-color .14s ease;
	-webkit-tap-highlight-color: transparent;
}

.meg-page-controls .meg-btn {
	font-size: 18px;
	font-weight: 400;
}

.meg-btn:hover:not(:disabled) {
	border-color: rgba(255, 255, 255, .2);
	background: rgba(255, 255, 255, .1);
	color: #fff;
}

.meg-btn:active:not(:disabled) {
	background: rgba(0, 166, 81, .32);
}

.meg-btn:focus-visible {
	outline: 2px solid var(--meg-accent);
	outline-offset: 2px;
}

.meg-btn:disabled {
	opacity: .36;
	cursor: not-allowed;
}

.meg-icon {
	display: block;
	flex: 0 0 18px;
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.meg-page-controls .meg-icon {
	width: 21px;
	height: 21px;
}

.meg-page-status {
	min-width: 76px;
	padding: 5px 8px;
	border-radius: 5px;
	background: rgba(255, 255, 255, .1);
	color: #fff;
	text-align: center;
	font-size: 11px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.meg-progress {
	flex: 0 0 3px;
	height: 3px;
	margin: 0 3px 6px;
	overflow: hidden;
	border-radius: 3px;
	background: #e7e9e8;
}

.meg-progress span {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: inherit;
	background: var(--meg-accent);
	transform: scaleX(0);
	transform-origin: left center;
	transition: transform .18s ease;
}

.meg-stage {
	position: relative;
	box-sizing: border-box;
	display: flex;
	flex: 1 1 auto;
	align-items: flex-start;
	justify-content: flex-start;
	min-width: 0;
	min-height: 0;
	padding: 10px;
	overflow: auto;
	overscroll-behavior: contain;
	touch-action: pan-y;
	border: 1px solid #e3e6e4;
	border-radius: 8px;
	background: #f5f6f5;
	-webkit-overflow-scrolling: touch;
}

.meg-stage:focus-visible {
	outline: 2px solid var(--meg-accent);
	outline-offset: 2px;
}

.meg-page-surface {
	position: relative;
	flex: 0 0 auto;
	margin: auto;
	background: #fff;
	box-shadow: 0 7px 22px rgba(0, 0, 0, .18), 0 1px 4px rgba(0, 0, 0, .1);
	transform-origin: center center;
	will-change: transform;
}

.meg-page-surface .meg-canvas,
.meg-page-surface canvas {
	display: block;
	width: 100%;
	height: auto;
	max-width: none;
	background: #fff;
}

.meg-pdf-links {
	position: absolute;
	inset: 0;
	pointer-events: none;
}

.meg-pdf-links a {
	position: absolute;
	display: block;
	background: rgba(0, 166, 81, .015);
	pointer-events: auto;
}

.meg-pdf-links a:hover,
.meg-pdf-links a:focus-visible {
	outline: 2px solid rgba(0, 166, 81, .85);
	background: rgba(0, 166, 81, .1);
}

.meg-pdf-links a.is-internal {
	cursor: pointer;
}

.meg-loader {
	position: absolute;
	z-index: 5;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 1.5rem;
	background: rgba(245, 246, 245, .92);
	color: #333;
	font-size: 12px;
	font-weight: 550;
	text-align: center;
}

.meg-reader.is-loading .meg-loader,
.meg-reader.is-rendering .meg-loader {
	display: flex;
}

.meg-reader.is-loading .meg-page-surface {
	visibility: hidden;
}

.meg-reader.is-rendering .meg-loader {
	background: rgba(245, 246, 245, .7);
}

.meg-spinner {
	width: 22px;
	height: 22px;
	border: 2px solid rgba(26, 26, 26, .12);
	border-top-color: var(--meg-accent);
	border-radius: 50%;
	animation: meg-spin .75s linear infinite;
}

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

.meg-error {
	display: none;
	flex: 0 0 auto;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin: 8px 0 0;
	padding: 9px 11px;
	border: 1px solid #f0cbcf;
	border-radius: 7px;
	background: #fff5f5;
	color: #702c31;
	font-size: 11px;
}

.meg-error[hidden] {
	display: none !important;
}

.meg-reader.has-error .meg-error,
.meg-reader.has-page-error .meg-error {
	display: flex;
}

.meg-reader.has-error .meg-stage {
	min-height: 160px;
}

.meg-error button {
	flex: 0 0 auto;
	padding: 6px 9px;
	border: 1px solid #00a651;
	border-radius: 5px;
	background: #00a651;
	color: #fff;
	font: inherit;
	font-weight: 650;
	cursor: pointer;
}

.meg-message {
	padding: .8rem 1rem;
	border-left: 4px solid var(--meg-accent);
	border-radius: 6px;
	background: #f4faf6;
	color: #1a1a1a;
}

.meg-gesture-hint {
	display: none;
	flex: 0 0 auto;
	margin: 6px 0 0;
	color: #5d665f;
	text-align: center;
	font-size: 10px;
	font-weight: 500;
	line-height: 1.35;
}

.meg-page-surface.meg-turn-next {
	animation: meg-turn-in-next .26s ease-out both;
}

.meg-page-surface.meg-turn-prev {
	animation: meg-turn-in-prev .26s ease-out both;
}

@keyframes meg-turn-in-next {
	0% { opacity: .3; transform: perspective(1200px) rotateY(-62deg) translateX(12px); }
	72% { opacity: 1; transform: perspective(1200px) rotateY(7deg) translateX(-2px); }
	100% { opacity: 1; transform: perspective(1200px) rotateY(0) translateX(0); }
}

@keyframes meg-turn-in-prev {
	0% { opacity: .3; transform: perspective(1200px) rotateY(62deg) translateX(-12px); }
	72% { opacity: 1; transform: perspective(1200px) rotateY(-7deg) translateX(2px); }
	100% { opacity: 1; transform: perspective(1200px) rotateY(0) translateX(0); }
}

.meg-reader.is-dragging,
.meg-reader.is-dragging * {
	cursor: grabbing !important;
	user-select: none !important;
}

.meg-reader.is-fullscreen {
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
	border: 0;
	border-radius: 0;
	background: #fff;
}

.meg-reader.is-fullscreen .meg-stage {
	flex: 1 1 auto;
	min-height: 0;
}

.meg-reader.meg-fallback-fullscreen {
	position: fixed !important;
	z-index: 999999;
	inset: 0;
	width: 100vw;
	max-width: none;
	height: 100vh;
	height: 100dvh;
	min-height: 0;
	max-height: none;
	margin: 0;
	padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
	border: 0;
	border-radius: 0;
	background: #fff;
}

.meg-reader.meg-fallback-fullscreen .meg-stage {
	flex: 1 1 auto;
	min-height: 0;
}

html.meg-fullscreen-open {
	overflow: hidden !important;
}

html.meg-fullscreen-open body > :not(.meg-reader) {
	visibility: hidden !important;
}

@media (max-width: 700px) {
	.meg-reader .meg-toolbar,
	.meg-reader .meg-progress,
	.meg-reader .meg-gesture-hint {
		display: none !important;
	}

	.meg-reader {
		height: min(88vh, 860px);
		height: min(88svh, 860px);
		min-height: min(420px, calc(100vh - 16px));
		min-height: min(420px, calc(100svh - 16px));
		max-height: calc(100vh - 16px);
		max-height: calc(100svh - 16px);
		margin: 8px auto;
		padding: 7px;
		border-radius: 9px;
	}

	.meg-toolbar {
		flex-direction: row;
		flex-wrap: wrap;
		gap: 4px;
		min-height: 40px;
		margin-bottom: 4px;
		padding: 3px;
		border-radius: 6px;
	}

	.meg-page-controls {
		flex: 0 0 auto;
		gap: 2px;
	}

	.meg-view-controls {
		flex: 1 1 auto;
		justify-content: flex-end;
		gap: 2px;
	}

	.meg-btn {
		min-width: 36px;
		min-height: 36px;
		padding: 4px 6px;
	}

	.meg-btn-label {
		display: none;
	}

	.meg-icon {
		width: 17px;
		height: 17px;
	}

	.meg-page-controls .meg-icon {
		width: 19px;
		height: 19px;
	}

	.meg-page-status {
		min-width: 70px;
		padding: 4px 5px;
		font-size: 10px;
	}

	.meg-progress {
		margin: 0 2px 4px;
	}

	.meg-stage {
		padding: 6px;
		border-radius: 6px;
	}

	.meg-gesture-hint {
		display: block;
	}

	.meg-reader.is-fullscreen .meg-gesture-hint,
	.meg-reader.meg-fallback-fullscreen .meg-gesture-hint {
		display: none;
	}
}

@media (max-height: 500px) {
	.meg-reader {
		height: calc(100vh - 12px);
		height: calc(100svh - 12px);
		min-height: min(360px, calc(100vh - 12px));
		min-height: min(360px, calc(100svh - 12px));
		max-height: calc(100vh - 12px);
		max-height: calc(100svh - 12px);
		margin: 6px auto;
		padding: 6px;
	}

	.meg-reader.is-fullscreen,
	.meg-reader.meg-fallback-fullscreen {
		height: 100vh;
		height: 100dvh;
		min-height: 0;
		max-height: none;
		margin: 0;
	}

	.meg-toolbar {
		min-height: 34px;
		margin-bottom: 3px;
		padding: 2px 4px;
	}

	.meg-btn {
		min-height: 28px;
	}

	.meg-progress {
		height: 2px;
		margin-bottom: 3px;
	}
}

.meg-scroll-stack[hidden] {
	display: none !important;
}

.meg-reader.meg-mobile-scroll .meg-toolbar,
.meg-reader.meg-mobile-scroll .meg-progress,
.meg-reader.meg-mobile-scroll .meg-gesture-hint {
	display: none !important;
}

.meg-reader.meg-mobile-scroll .meg-page-surface {
	display: none !important;
}

.meg-reader.meg-mobile-scroll .meg-stage {
	position: relative;
	display: block;
	flex: 1 1 auto;
	width: 100%;
	min-width: 0;
	min-height: 0;
	padding: 0;
	overflow-x: hidden;
	overflow-y: auto;
	overscroll-behavior-y: contain;
	touch-action: pan-y;
	border: 0;
	border-radius: 0;
	background: #e2e4e3;
	-webkit-overflow-scrolling: touch;
	scroll-snap-type: y proximity;
}

.meg-reader.meg-mobile-scroll .meg-scroll-stack {
	display: block;
	width: 100%;
	background: #e2e4e3;
}

.meg-scroll-page {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 100%;
	min-height: 0;
	padding-bottom: 10px;
	background: #e2e4e3;
	scroll-snap-align: start;
}

.meg-scroll-content {
	position: relative;
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	width: 100%;
	min-height: 0;
	padding: 0;
}

.meg-scroll-surface {
	position: relative;
	flex: 0 0 auto;
	margin: auto;
	background: #fff;
	box-shadow: 0 2px 9px rgba(0, 0, 0, .18);
}

.meg-scroll-surface canvas {
	display: block;
	width: 100%;
	height: auto;
}

.meg-scroll-placeholder {
	position: absolute;
	z-index: 1;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	gap: 8px;
	background: #e2e4e3;
	color: #5d665f;
	font: 500 12px Montserrat, "Helvetica Neue", Arial, sans-serif;
}

.meg-scroll-placeholder[hidden] {
	display: none !important;
}

.meg-scroll-page.is-loading .meg-scroll-placeholder {
	display: flex;
}

.meg-scroll-page.has-error .meg-scroll-placeholder {
	display: flex;
	padding: 20px;
	color: #702c31;
	text-align: center;
}

.meg-reader.meg-mobile-scroll .meg-error button {
	display: none;
}

.meg-reader.meg-mobile-scroll.meg-fallback-fullscreen,
.meg-reader.meg-mobile-scroll.is-fullscreen {
	padding: max(0px, env(safe-area-inset-top)) max(0px, env(safe-area-inset-right)) max(0px, env(safe-area-inset-bottom)) max(0px, env(safe-area-inset-left));
	border-radius: 0;
	background: #fff;
}

@media (prefers-reduced-motion: reduce) {
	.meg-spinner {
		animation-duration: 1.5s;
	}

	.meg-page-surface {
		animation-duration: .01ms !important;
	}
}
