/*
 * Liseuse
 * The flipbook is the only thing that matters: the interface floats in frosted glass,
 * fades away while reading, and the background glows with the colors of the open pages.
 */

@property --lsp-amb-a { syntax: "<color>"; inherits: true; initial-value: #3b4a63; }
@property --lsp-amb-b { syntax: "<color>"; inherits: true; initial-value: #5a4a3b; }

.lsp {
	--lsp-glass: rgba(20, 22, 27, .58);
	--lsp-glass-line: rgba(255, 255, 255, .09);
	--lsp-ink: #f5f5f7;
	--lsp-ink-soft: rgba(245, 245, 247, .58);
	--lsp-hover: rgba(255, 255, 255, .1);
	--lsp-track: rgba(255, 255, 255, .18);
	--lsp-ease: cubic-bezier(.2, .8, .2, 1);

	position: relative;
	isolation: isolate;
	display: block;
	width: 100%;
	height: var(--lsp-h, 640px);
	max-height: 88vh;
	margin: 1.5em 0;
	background: var(--lsp-bg, #1d2026);
	color: var(--lsp-ink);
	border-radius: 20px;
	overflow: hidden;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	font-size: 14px;
	line-height: 1.4;
	-webkit-font-smoothing: antialiased;
	outline: none;
	box-sizing: border-box;
	transition: --lsp-amb-a 1.2s ease, --lsp-amb-b 1.2s ease;
}
.lsp *, .lsp *::before, .lsp *::after { box-sizing: border-box; }
.lsp:focus-visible { box-shadow: 0 0 0 2px var(--lsp-ink); }

.lsp.is-light {
	--lsp-glass: rgba(255, 255, 255, .72);
	--lsp-glass-line: rgba(0, 0, 0, .07);
	--lsp-ink: #16181d;
	--lsp-ink-soft: rgba(22, 24, 29, .55);
	--lsp-hover: rgba(0, 0, 0, .06);
	--lsp-track: rgba(0, 0, 0, .14);
}

/* ---------- Ambient light ---------- */

.lsp-ambient {
	position: absolute;
	inset: -15%;
	z-index: -1;
	pointer-events: none;
	background:
		radial-gradient(42% 55% at 32% 46%, color-mix(in oklab, var(--lsp-amb-a) 80%, transparent), transparent 72%),
		radial-gradient(42% 55% at 68% 46%, color-mix(in oklab, var(--lsp-amb-b) 80%, transparent), transparent 72%);
	filter: blur(70px) saturate(1.35);
	opacity: 0;
	transition: opacity 1s ease;
}
.lsp.has-ambient.is-ready .lsp-ambient { opacity: .7; }
.lsp.is-light.has-ambient.is-ready .lsp-ambient { opacity: .35; }

/* ---------- Livre ---------- */

.lsp-book {
	position: absolute !important;
	inset: 32px 76px 108px;
	min-width: 0 !important;
	opacity: 0;
	transform: scale(.97);
	transition: opacity .6s var(--lsp-ease), transform .6s var(--lsp-ease);
}
.lsp.is-ready .lsp-book { opacity: 1; transform: none; }
.lsp-book .stf__wrapper { height: 100%; }
.lsp-book .stf__block { filter: drop-shadow(0 24px 40px rgba(0, 0, 0, .45)) drop-shadow(0 2px 4px rgba(0, 0, 0, .25)); }
.lsp.is-light .lsp-book .stf__block { filter: drop-shadow(0 24px 40px rgba(0, 0, 0, .18)) drop-shadow(0 2px 4px rgba(0, 0, 0, .12)); }

.lsp-page { background: #fff; overflow: hidden; }
.lsp-page canvas { display: block; width: 100%; height: 100%; }
.lsp-page:not(.is-rendered) {
	background: linear-gradient(100deg, #efede9 40%, #f8f7f4 50%, #efede9 60%) 0 0 / 300% 100%;
	animation: lsp-shimmer 1.4s linear infinite;
}
@keyframes lsp-shimmer { to { background-position: -150% 0; } }

/* Binding fold */
.lsp-page::after {
	content: "";
	position: absolute;
	top: 0; bottom: 0;
	width: 8%;
	pointer-events: none;
}
.lsp-page.--left::after  { right: 0; background: linear-gradient(to left, rgba(0, 0, 0, .18), rgba(0, 0, 0, .04) 35%, transparent); }
.lsp-page.--right::after { left: 0;  background: linear-gradient(to right, rgba(0, 0, 0, .18), rgba(0, 0, 0, .04) 35%, transparent); }
.lsp-page[data-density="hard"]::after { display: none; }

/* ---------- Chargement ---------- */

.lsp-loader {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 16px;
	padding: 24px;
	text-align: center;
	color: var(--lsp-ink-soft);
}
.lsp.is-ready .lsp-loader { display: none; }
.lsp-loader p { margin: 0; max-width: 46ch; font-variant-numeric: tabular-nums; }
.lsp-loader a { color: var(--lsp-ink); }
.lsp-ring { width: 44px; height: 44px; transform: rotate(-90deg); }
.lsp-ring circle { fill: none; stroke-width: 3; stroke: var(--lsp-track); }
.lsp-ring .lsp-ring-val {
	stroke: var(--lsp-ink);
	stroke-linecap: round;
	stroke-dasharray: 125.7;
	stroke-dashoffset: 120;
	transition: stroke-dashoffset .25s ease;
}
.lsp.has-error .lsp-ring { display: none; }
.lsp.has-error .lsp-error { color: var(--lsp-ink); }

/* ---------- Shared frosted glass ---------- */

.lsp-dock, .lsp-side, .lsp-strip, .lsp-zoom-ctrl, .lsp-toast, .lsp-peek {
	background: var(--lsp-glass);
	-webkit-backdrop-filter: blur(20px) saturate(1.6);
	backdrop-filter: blur(20px) saturate(1.6);
	border: 1px solid var(--lsp-glass-line);
	box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .45);
}

/* ---------- Side arrows ---------- */

.lsp-side {
	position: absolute;
	top: calc(50% - 38px);
	z-index: 3;
	width: 48px;
	height: 48px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border-radius: 50%;
	color: var(--lsp-ink);
	cursor: pointer;
	transition: opacity .35s var(--lsp-ease), transform .35s var(--lsp-ease), background-color .2s;
}
.lsp-side svg { width: 22px; height: 22px; }
.lsp-side-prev { left: 14px; }
.lsp-side-next { right: 14px; }
.lsp-side:hover { transform: scale(1.06); }
.lsp-side:disabled { opacity: 0 !important; pointer-events: none; }
.lsp:not(.is-ready) .lsp-side { display: none; }

/* ---------- Dock ---------- */

.lsp-dock {
	position: absolute;
	left: 50%;
	bottom: 16px;
	z-index: 4;
	width: min(620px, calc(100% - 24px));
	padding: 10px 10px 6px;
	border-radius: 18px;
	transform: translateX(-50%);
	transition: opacity .35s var(--lsp-ease), transform .35s var(--lsp-ease);
}
.lsp:not(.is-ready) .lsp-dock { opacity: 0; pointer-events: none; }

.lsp.is-idle .lsp-dock { opacity: 0; transform: translate(-50%, 14px); pointer-events: none; }
.lsp.is-idle .lsp-side { opacity: 0; transform: scale(.9); pointer-events: none; }
.lsp.is-idle { cursor: none; }

.lsp-dock-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
}
.lsp-group { display: flex; align-items: center; gap: 2px; }

.lsp-btn {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	padding: 0;
	margin: 0;
	border: 0;
	border-radius: 11px;
	background: transparent;
	color: var(--lsp-ink);
	cursor: pointer;
	text-decoration: none;
	box-shadow: none;
	transition: background-color .15s, transform .15s;
}
.lsp-btn:hover { background: var(--lsp-hover); color: var(--lsp-ink); }
.lsp-btn:active { transform: scale(.92); }
.lsp-btn.is-active { background: var(--lsp-ink); color: var(--lsp-bg); }
.lsp-btn:disabled { opacity: .28; cursor: default; background: transparent; transform: none; }
.lsp-btn:focus-visible, .lsp-side:focus-visible, .lsp-thumb:focus-visible, .lsp-range:focus-visible {
	outline: 2px solid var(--lsp-ink);
	outline-offset: 2px;
}

/* Infobulles */
.lsp:not(.is-touch) .lsp-btn[data-tip]:hover::after {
	content: attr(data-tip);
	position: absolute;
	bottom: calc(100% + 12px);
	left: 50%;
	transform: translateX(-50%);
	padding: 5px 9px;
	border-radius: 7px;
	background: var(--lsp-ink);
	color: var(--lsp-bg);
	font-size: 12px;
	font-weight: 500;
	white-space: nowrap;
	pointer-events: none;
	animation: lsp-tip .15s .35s both;
}
@keyframes lsp-tip { from { opacity: 0; transform: translate(-50%, 4px); } }

.lsp-counter {
	display: inline-flex;
	align-items: baseline;
	gap: 6px;
	margin: 0 6px;
	color: var(--lsp-ink-soft);
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}
.lsp .lsp-page-input {
	width: 6ch;
	height: 30px;
	margin: 0;
	padding: 0 4px;
	border: 1px solid transparent;
	border-radius: 9px;
	background: var(--lsp-hover);
	color: var(--lsp-ink);
	font: inherit;
	font-weight: 600;
	text-align: center;
	box-shadow: none;
}
.lsp .lsp-page-input:focus { outline: none; border-color: var(--lsp-ink-soft); }

.lsp .lsp-sr {
	position: absolute !important;
	width: 1px; height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
}

/* ---------- Progress bar / navigation ---------- */

.lsp-scrub { position: relative; padding: 0 6px 6px; }

.lsp .lsp-range {
	-webkit-appearance: none;
	appearance: none;
	display: block;
	width: 100%;
	height: 18px;
	margin: 0;
	padding: 0;
	background: transparent;
	border: 0;
	cursor: pointer;
	--p: 0%;
}
.lsp-range::-webkit-slider-runnable-track {
	height: 4px;
	border-radius: 4px;
	background: linear-gradient(to right, var(--lsp-ink) var(--p), var(--lsp-track) var(--p));
	transition: height .15s;
}
.lsp-range::-moz-range-track { height: 4px; border-radius: 4px; background: var(--lsp-track); }
.lsp-range::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--lsp-ink); }
.lsp-range::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 14px;
	height: 14px;
	margin-top: -5px;
	border-radius: 50%;
	background: var(--lsp-ink);
	box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
	transform: scale(.75);
	transition: transform .15s;
}
.lsp-range::-moz-range-thumb {
	width: 14px; height: 14px; border: 0; border-radius: 50%;
	background: var(--lsp-ink);
	transform: scale(.75);
	transition: transform .15s;
}
.lsp-range:hover::-webkit-slider-thumb, .lsp-range:active::-webkit-slider-thumb { transform: scale(1.1); }
.lsp-range:hover::-moz-range-thumb, .lsp-range:active::-moz-range-thumb { transform: scale(1.1); }

/* Page preview while dragging */
.lsp-peek {
	--x: 0;
	position: absolute;
	bottom: calc(100% + 14px);
	left: calc(6px + var(--x) * (100% - 12px));
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	padding: 6px 6px 5px;
	border-radius: 12px;
	transform: translateX(-50%) translateY(6px);
	opacity: 0;
	pointer-events: none;
	transition: opacity .15s, transform .15s;
}
.lsp-peek.is-on { opacity: 1; transform: translateX(-50%); }
.lsp-peek canvas { display: block; width: 96px; border-radius: 4px; background: #fff; }
.lsp-peek span { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Thumbnail strip ---------- */

.lsp-strip {
	position: absolute;
	left: 50%;
	bottom: 112px;
	z-index: 4;
	width: min(900px, calc(100% - 24px));
	padding: 14px 16px 10px;
	border-radius: 18px;
	overflow-x: auto;
	overflow-y: hidden;
	overscroll-behavior: contain;
	scrollbar-width: none;
	transform: translateX(-50%);
	animation: lsp-rise .3s var(--lsp-ease);
	-webkit-mask-image: linear-gradient(to right, transparent, #000 28px, #000 calc(100% - 28px), transparent);
	mask-image: linear-gradient(to right, transparent, #000 28px, #000 calc(100% - 28px), transparent);
}
.lsp-strip::-webkit-scrollbar { display: none; }
.lsp-strip[hidden] { display: none; }
@keyframes lsp-rise { from { opacity: 0; transform: translate(-50%, 12px); } }

.lsp-strip-track { display: flex; gap: 10px; width: max-content; padding: 0 12px; }

.lsp-thumb {
	flex: none;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	width: 68px;
	padding: 0;
	margin: 0;
	border: 0;
	background: transparent;
	color: var(--lsp-ink-soft);
	font: inherit;
	font-size: 12px;
	font-variant-numeric: tabular-nums;
	cursor: pointer;
}
.lsp-thumb-img {
	display: block;
	width: 100%;
	border-radius: 5px;
	overflow: hidden;
	background: #efede9;
	box-shadow: 0 4px 10px rgba(0, 0, 0, .3);
	transition: transform .2s var(--lsp-ease), box-shadow .2s;
}
.lsp-thumb canvas { display: block; width: 100%; height: 100%; }
.lsp-thumb:hover .lsp-thumb-img { transform: translateY(-3px); }
.lsp-thumb.is-current .lsp-thumb-img { box-shadow: 0 0 0 2px var(--lsp-ink), 0 8px 18px rgba(0, 0, 0, .35); transform: translateY(-3px); }
.lsp-thumb.is-current .lsp-thumb-n { color: var(--lsp-ink); font-weight: 600; }

/* ---------- Loupe ---------- */

.lsp-zoom {
	position: absolute;
	inset: 0;
	z-index: 6;
	display: flex;
	background: color-mix(in srgb, var(--lsp-bg) 88%, transparent);
	-webkit-backdrop-filter: blur(24px);
	backdrop-filter: blur(24px);
	animation: lsp-fade .25s ease;
}
.lsp-zoom[hidden] { display: none; }
@keyframes lsp-fade { from { opacity: 0; } }

.lsp-zoom-scroll {
	flex: 1;
	overflow: auto;
	display: flex;
	cursor: grab;
	overscroll-behavior: contain;
}
.lsp-zoom-scroll.is-dragging { cursor: grabbing; user-select: none; }
.lsp-zoom-sheet { display: flex; margin: auto; padding: 24px; }
.lsp-zoom-sheet canvas { display: block; background: #fff; box-shadow: 0 20px 50px rgba(0, 0, 0, .4); }

.lsp-zoom-ctrl {
	position: absolute;
	left: 50%;
	bottom: 16px;
	display: flex;
	align-items: center;
	gap: 2px;
	padding: 5px;
	border-radius: 16px;
	transform: translateX(-50%);
}
.lsp-zoom-val {
	min-width: 4.4em;
	text-align: center;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}
.lsp-sep { width: 1px; height: 20px; margin: 0 4px; background: var(--lsp-glass-line); }

/* ---------- Toast ---------- */

.lsp-toast {
	position: absolute;
	top: 16px;
	left: 50%;
	z-index: 7;
	padding: 9px 16px;
	border-radius: 999px;
	font-weight: 600;
	opacity: 0;
	transform: translate(-50%, -8px);
	transition: opacity .25s, transform .25s var(--lsp-ease);
	pointer-events: none;
}
.lsp-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

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

.lsp.is-fullscreen, .lsp.is-pseudo-fs {
	margin: 0;
	border-radius: 0;
	width: 100%;
	height: 100%;
	max-height: none;
}
.lsp.is-pseudo-fs { position: fixed; inset: 0; z-index: 999999; height: 100dvh; }
.lsp.is-fullscreen .lsp-book, .lsp.is-pseudo-fs .lsp-book { inset: 40px 96px 112px; }
html.lsp-lock, html.lsp-lock body { overflow: hidden; }

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
	.lsp { border-radius: 14px; max-height: 82vh; }
}
/* The viewer's actual width matters, not the screen's (theme columns, sidebars…). */
.lsp { container-type: inline-size; container-name: lsp; }
@container lsp (max-width: 640px) {
	.lsp-book, .lsp.is-fullscreen .lsp-book, .lsp.is-pseudo-fs .lsp-book { inset: 16px 12px 112px; }
	.lsp-side { display: none; }
	.lsp-dock { bottom: 10px; width: calc(100% - 16px); padding: 8px 6px 4px; }
	.lsp-btn { width: 32px; height: 36px; }
	.lsp-group { gap: 0; }
	.lsp-counter { margin: 0 2px; }
	.lsp .lsp-page-input { padding: 0 2px; }
	.lsp-strip { bottom: 108px; width: calc(100% - 16px); }
}
@container lsp (max-width: 380px) {
	.lsp-share, .lsp-total { display: none; }
	.lsp-btn { width: 30px; }
}
.lsp.is-touch .lsp-side { display: none; }

@media (prefers-reduced-motion: reduce) {
	.lsp, .lsp * { animation: none !important; transition-duration: .01s !important; }
}

.lsp-notice { padding: 12px 16px; border-left: 3px solid #d63638; background: #fcf0f1; }
