/* EPUB Book Reader – reader page styles */

:root {
	--bar-h: 52px;
	--foot-h: 48px;
	--desk: #e9e5dd;
	--desk-2: #d9d3c8;
	--chrome: rgba(255, 255, 255, .92);
	--chrome-ink: #2b2b2b;
	--muted: #6b6b6b;
	--line: rgba(0, 0, 0, .1);
	--paper: #fdfbf7;
	--paper-edge: #ece7dc;
	--ink: #1f1f1f;
	--accent: #0a6e8a;
	--shadow: 0 24px 50px -18px rgba(40, 30, 10, .45), 0 4px 12px rgba(40, 30, 10, .15);
	--radius: 6px;
	--book-max-w: 1280px;
}
[data-theme="sepia"] {
	--desk: #d8ccb4;
	--desk-2: #c9bb9f;
	--paper: #f4ecd8;
	--paper-edge: #e3d6b8;
	--ink: #3b2f20;
	--chrome: rgba(250, 243, 228, .94);
	--chrome-ink: #3b2f20;
	--muted: #7a6a52;
	--accent: #8a5a12;
}
[data-theme="dark"] {
	--desk: #121212;
	--desk-2: #1b1b1b;
	--paper: #232323;
	--paper-edge: #2d2d2d;
	--ink: #d9d9d9;
	--chrome: rgba(28, 28, 28, .94);
	--chrome-ink: #e6e6e6;
	--muted: #9a9a9a;
	--line: rgba(255, 255, 255, .1);
	--accent: #7cc4dc;
	--shadow: 0 24px 50px -18px rgba(0, 0, 0, .8), 0 4px 12px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body.epr {
	font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	color: var(--chrome-ink);
	background: radial-gradient(ellipse at 50% 40%, var(--desk) 0%, var(--desk-2) 100%);
	overflow: hidden;
	transition: background .3s;
}
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Top bar ---------- */
.epr-bar {
	position: fixed; inset: 0 0 auto 0; height: var(--bar-h); z-index: 20;
	display: flex; align-items: center; gap: 8px; padding: 0 10px;
	background: var(--chrome); border-bottom: 1px solid var(--line);
	backdrop-filter: blur(8px);
}
.epr-bar__group { display: flex; align-items: center; gap: 2px; flex: none; }
.epr-bar__title { flex: 1; min-width: 0; text-align: center; line-height: 1.2; }
.epr-bar__book, .epr-bar__chapter { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.epr-bar__book { font-weight: 600; font-size: 14px; }
.epr-bar__chapter { font-size: 12px; color: var(--muted); }

.epr-btn {
	display: inline-flex; align-items: center; justify-content: center;
	min-width: 40px; height: 40px; padding: 0 8px; border: 0; border-radius: 8px;
	background: transparent; color: inherit; cursor: pointer; text-decoration: none; font: inherit;
}
.epr-btn:hover { background: var(--line); }
.epr-btn:focus-visible, .epr-nav:focus-visible, .epr-seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.epr-btn[aria-pressed="true"] { background: var(--line); color: var(--accent); }
.epr-btn--solid { background: var(--accent); color: #fff; font-weight: 600; }
.epr-btn--solid:hover { background: var(--accent); filter: brightness(1.1); }

/* ---------- Stage & book ---------- */
.epr-stage {
	position: fixed; top: var(--bar-h); bottom: var(--foot-h); left: 0; right: 0;
	display: flex; align-items: center; justify-content: center; gap: 12px;
	padding: 22px 12px 26px;
}
.epr-book {
	position: relative; flex: 1; height: 100%; max-width: var(--book-max-w);
	background: var(--paper); color: var(--ink);
	border-radius: var(--radius);
	/* stacked-pages edge effect */
	box-shadow:
		0 1px 0 var(--paper-edge),
		0 3px 0 -1px var(--paper),
		0 4px 0 -1px var(--paper-edge),
		0 6px 0 -2px var(--paper),
		0 7px 0 -2px var(--paper-edge),
		var(--shadow);
	transition: background .3s, max-width .3s;
	perspective: 2200px;
}
.epr-book__pages { position: absolute; inset: 28px 36px; }
.epr-book__spine {
	position: absolute; top: 0; bottom: 0; left: 50%; width: 90px; margin-left: -45px;
	pointer-events: none; opacity: 0; transition: opacity .3s;
	background: linear-gradient(to right,
		rgba(0,0,0,0) 0%, rgba(0,0,0,.035) 30%, rgba(0,0,0,.16) 49%,
		rgba(255,255,255,.06) 50%, rgba(0,0,0,.08) 51%, rgba(0,0,0,.03) 70%, rgba(0,0,0,0) 100%);
}
[data-theme="dark"] .epr-book__spine { mix-blend-mode: normal; filter: brightness(.6); }
body.is-spread .epr-book__spine { opacity: 1; }
body.is-single .epr-book { max-width: 760px; }
body.is-scroll .epr-book { max-width: 820px; }
body.is-scroll .epr-book__pages { inset: 0 0 0 16px; }
body.is-scroll .epr-nav { display: none; }

/* Page-turn overlay */
.epr-flip {
	position: absolute; top: 0; bottom: 0; width: 50%; right: 0;
	transform-origin: left center; pointer-events: none; opacity: 0;
	background: linear-gradient(to left, var(--paper) 0%, var(--paper) 70%, var(--paper-edge) 100%);
	box-shadow: -10px 0 30px rgba(0,0,0,.12);
	border-radius: 0 var(--radius) var(--radius) 0;
	backface-visibility: hidden;
}
body.is-single .epr-flip { width: 100%; border-radius: var(--radius); }
.epr-flip.go-next { animation: epr-turn-next .55s cubic-bezier(.45,.05,.3,1) forwards; }
.epr-flip.go-prev { animation: epr-turn-prev .55s cubic-bezier(.45,.05,.3,1) forwards; }
@keyframes epr-turn-next {
	0%   { opacity: 1; transform: rotateY(0deg); box-shadow: -4px 0 12px rgba(0,0,0,.1); }
	60%  { opacity: .9; }
	100% { opacity: 0; transform: rotateY(-100deg); box-shadow: -30px 0 40px rgba(0,0,0,.25); }
}
@keyframes epr-turn-prev {
	0%   { opacity: 1; transform: rotateY(0deg); }
	100% { opacity: 0; transform: rotateY(100deg); }
}
.epr-flip.go-prev { left: 0; right: auto; transform-origin: right center; border-radius: var(--radius) 0 0 var(--radius);
	background: linear-gradient(to right, var(--paper) 0%, var(--paper) 70%, var(--paper-edge) 100%); }
body.is-single .epr-flip.go-prev { width: 100%; }
@media (prefers-reduced-motion: reduce) { .epr-flip { display: none; } }

/* Side nav arrows */
.epr-nav {
	flex: none; width: 44px; height: 88px; border: 0; border-radius: 22px; cursor: pointer;
	background: transparent; color: var(--chrome-ink); opacity: .55; transition: opacity .2s, background .2s;
}
.epr-nav:hover { opacity: 1; background: var(--chrome); }
.epr-nav svg { width: 28px; height: 28px; }
.epr-nav:disabled { opacity: .15; cursor: default; background: transparent; }

/* ---------- Footer ---------- */
.epr-foot {
	position: fixed; inset: auto 0 0 0; height: var(--foot-h); z-index: 20;
	display: flex; align-items: center; gap: 14px; padding: 0 18px;
	background: var(--chrome); border-top: 1px solid var(--line);
}
.epr-foot__info { flex: none; min-width: 150px; text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
#epr-slider { flex: 1; accent-color: var(--accent); }

/* ---------- Loader ---------- */
.epr-loader {
	position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
	color: var(--chrome-ink); background: inherit; z-index: 5; text-align: center; padding: 20px;
}
.epr-loader p { margin: 6px 0 0; }
.epr-loader__bar { width: 220px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.epr-loader__bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.epr-loader__book { position: relative; width: 60px; height: 40px; perspective: 200px; }
.epr-loader__book span {
	position: absolute; left: 30px; top: 0; width: 28px; height: 40px; background: var(--paper);
	border: 1px solid var(--paper-edge); transform-origin: left center; border-radius: 0 3px 3px 0;
	animation: epr-loader-flip 1.5s infinite ease-in-out;
}
.epr-loader__book span:nth-child(2) { animation-delay: .25s; }
.epr-loader__book span:nth-child(3) { animation-delay: .5s; }
@keyframes epr-loader-flip { 0%, 20% { transform: rotateY(0); } 60%, 100% { transform: rotateY(-180deg); } }
.epr-loader.is-error .epr-loader__book, .epr-loader.is-error .epr-loader__bar { display: none; }
.epr-loader a { color: var(--accent); }

/* ---------- Panels ---------- */
.epr-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 29; }
.epr-panel {
	position: fixed; top: 0; bottom: 0; width: min(360px, 88vw); z-index: 30;
	display: flex; flex-direction: column;
	background: var(--chrome); color: var(--chrome-ink); box-shadow: 0 0 40px rgba(0,0,0,.25);
	animation: epr-slide-in .2s ease-out;
}
.epr-panel--left { left: 0; }
.epr-panel--right { right: 0; }
@keyframes epr-slide-in { from { opacity: 0; transform: translateX(var(--from, -20px)); } }
.epr-panel--right { --from: 20px; }
.epr-panel__head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 18px; border-bottom: 1px solid var(--line); }
.epr-panel__head h2 { margin: 0; font-size: 16px; }
.epr-panel__body { flex: 1; overflow-y: auto; padding: 8px 0 24px; }
#epr-toc-list ul { list-style: none; margin: 0; padding: 0; }
#epr-toc-list ul ul { padding-left: 16px; }
#epr-toc-list a {
	display: block; padding: 9px 18px; color: inherit; text-decoration: none; border-left: 3px solid transparent; font-size: 14px;
}
#epr-toc-list a:hover { background: var(--line); }
#epr-toc-list a.is-current { border-left-color: var(--accent); color: var(--accent); font-weight: 600; background: var(--line); }

.epr-search__form { display: flex; gap: 6px; padding: 12px 14px 4px; }
.epr-search__form input {
	flex: 1; min-width: 0; height: 40px; padding: 0 12px; font: inherit; color: inherit;
	border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
}
.epr-search__status { margin: 4px 16px; font-size: 13px; color: var(--muted); min-height: 1.2em; }
.epr-search__results { list-style: none; margin: 0; padding-left: 0; }
.epr-search__results button {
	display: block; width: 100%; text-align: left; border: 0; background: transparent; color: inherit; font: inherit;
	padding: 10px 16px; font-size: 13.5px; cursor: pointer; border-bottom: 1px solid var(--line);
}
.epr-search__results button:hover { background: var(--line); }
.epr-search__results small { display: block; color: var(--muted); margin-bottom: 3px; }
.epr-search__results mark { background: rgba(255, 200, 0, .45); color: inherit; border-radius: 2px; }

/* ---------- Settings popover ---------- */
.epr-pop {
	position: fixed; top: calc(var(--bar-h) + 6px); right: 10px; z-index: 30; width: min(340px, calc(100vw - 20px));
	padding: 12px 14px; border-radius: 12px; background: var(--chrome); color: var(--chrome-ink);
	box-shadow: 0 12px 40px rgba(0,0,0,.25); border: 1px solid var(--line);
}
.epr-pop__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; }
.epr-pop__label { font-size: 13px; color: var(--muted); }
.epr-seg { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.epr-seg button { border: 0; background: transparent; color: inherit; font: inherit; font-size: 13px; padding: 7px 10px; cursor: pointer; }
.epr-seg button + button, .epr-seg output + button { border-left: 1px solid var(--line); }
.epr-seg button:hover { background: var(--line); }
.epr-seg button.is-active { background: var(--accent); color: #fff; }
.epr-seg output { padding: 0 10px; font-size: 13px; min-width: 52px; text-align: center; border-left: 1px solid var(--line); }
.epr-serif { font-family: Georgia, "Times New Roman", serif; }
.epr-swatch--light { background: #fdfbf7 !important; color: #222 !important; }
.epr-swatch--sepia { background: #f4ecd8 !important; color: #3b2f20 !important; }
.epr-swatch--dark { background: #232323 !important; color: #ddd !important; }
.epr-swatch.is-active { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- Lightbox ---------- */
.epr-lightbox {
	position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
	background: rgba(10,10,10,.9); cursor: zoom-out; padding: 30px;
}
.epr-lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; box-shadow: 0 10px 40px rgba(0,0,0,.6); border-radius: 4px; }
.epr-lightbox__close { position: absolute; top: 10px; right: 10px; color: #fff; }

/* ---------- Small screens ---------- */
@media (max-width: 700px) {
	:root { --bar-h: 48px; --foot-h: 44px; }
	.epr-hide-sm { display: none; }
	.epr-stage { padding: 10px 6px 14px; gap: 0; }
	.epr-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; width: 34px; height: 64px; opacity: .35; }
	.epr-nav--prev { left: 0; }
	.epr-nav--next { right: 0; }
	.epr-book__pages { inset: 18px 20px; }
	.epr-foot__info { min-width: 0; }
}

/* ---------- Fixed-layout (page-by-page) EPUBs ---------- */
/* The book is sized in JS to the exact shape of the pages; no inner margins. */
body.is-fixed .epr-book__pages { inset: 0; }
body.is-fixed .epr-book { overflow: hidden; }
body.is-fixed .epr-stage { padding: 14px 12px 18px; }
@media (max-width: 700px) { body.is-fixed .epr-stage { padding: 6px 4px 8px; } }
