/**
 * Sahaj eReader — reading surface.
 *
 * Typography is tuned for Devanagari first. Matras sit above and below the
 * baseline, so the leading is looser than a Latin-only reader would need, and
 * letter-spacing is pinned to normal everywhere because adjusting it shatters
 * conjuncts like क्ष and ज्ञ.
 */

.ser-reader {
	--ser-paper: #f5f4f0;
	--ser-paper-raised: #ffffff;
	--ser-ink: #1a1d29;
	--ser-ink-soft: #5b6072;
	--ser-rule: #d8d6cf;
	--ser-accent: #2d3a8c;
	--ser-measure: 34rem;
	--ser-size: 1.18rem;
	--ser-lead: 1.85;

	position: relative;
	display: flex;
	flex-direction: column;
	min-height: 70vh;
	margin: 0 auto;
	background: var(--ser-paper);
	color: var(--ser-ink);
	border: 1px solid var(--ser-rule);
	border-radius: 2px;
	overflow: hidden;
}

.ser-reader[data-theme="sepia"] {
	--ser-paper: #f2e8d5;
	--ser-paper-raised: #f8f1e3;
	--ser-ink: #3d3226;
	--ser-ink-soft: #6f6152;
	--ser-rule: #ddcdb0;
	--ser-accent: #7a4a1e;
}

.ser-reader[data-theme="night"] {
	--ser-paper: #14161f;
	--ser-paper-raised: #1c1f2b;
	--ser-ink: #c8ccd8;
	--ser-ink-soft: #7f8598;
	--ser-rule: #2a2e3d;
	--ser-accent: #8f9dde;
}

/* ---------- Chrome ---------- */

.ser-bar {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 14px;
	background: var(--ser-paper-raised);
	border-bottom: 1px solid var(--ser-rule);
}

.ser-bar-title {
	flex: 1 1 auto;
	min-width: 0;
	text-align: center;
	line-height: 1.3;
}

.ser-book-title {
	display: block;
	font-size: 0.92rem;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ser-book-author {
	display: block;
	font-size: 0.76rem;
	color: var(--ser-ink-soft);
}

.ser-bar-tools {
	display: flex;
	gap: 4px;
	flex: 0 0 auto;
}

.ser-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 10px;
	font: inherit;
	font-size: 0.84rem;
	color: var(--ser-ink);
	background: transparent;
	border: 1px solid transparent;
	border-radius: 2px;
	cursor: pointer;
}

.ser-btn:hover {
	background: var(--ser-paper);
	border-color: var(--ser-rule);
}

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

.ser-btn[disabled] {
	opacity: 0.4;
	cursor: default;
}

.ser-icon-lines,
.ser-icon-lines::before,
.ser-icon-lines::after {
	display: block;
	width: 15px;
	height: 1.5px;
	background: currentColor;
}

.ser-icon-lines {
	position: relative;
}

.ser-icon-lines::before,
.ser-icon-lines::after {
	content: "";
	position: absolute;
	left: 0;
}

.ser-icon-lines::before { top: -5px; }
.ser-icon-lines::after  { top: 5px; }

.ser-minus,
.ser-plus {
	font-size: 0.7em;
	vertical-align: super;
}

.ser-theme-dot {
	width: 13px;
	height: 13px;
	border-radius: 50%;
	border: 1.5px solid currentColor;
	background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}

/* ---------- Contents ---------- */

.ser-body {
	position: relative;
	display: flex;
	align-items: stretch;
	flex: 1 1 auto;
	min-height: 0;
}

/*
 * Hidden by default and forced with !important: themes commonly set a display
 * value on nav elements, which silently beats the [hidden] attribute and
 * leaves the panel stuck open above the text.
 */
.ser-toc {
	display: none !important;
	flex: 0 0 262px;
	max-height: 78vh;
	overflow-y: auto;
	background: var(--ser-paper-raised);
	border-inline-end: 1px solid var(--ser-rule);
}

.ser-reader.ser-toc-open .ser-toc {
	display: block !important;
}

.ser-scrim {
	display: none;
}

.ser-toc-list {
	margin: 0;
	padding: 8px 0;
	list-style: none;
}

.ser-toc-list li {
	margin: 0;
	padding: 0;
	list-style: none;
}

.ser-toc-item {
	display: block;
	width: 100%;
	padding: 9px 18px;
	font: inherit;
	font-size: 0.88rem;
	line-height: 1.45;
	text-align: start;
	color: var(--ser-ink);
	background: none;
	border: 0;
	border-inline-start: 2px solid transparent;
	cursor: pointer;
}

.ser-toc-item:hover {
	background: var(--ser-paper);
	border-inline-start-color: var(--ser-accent);
}

.ser-toc-item[aria-current="true"] {
	font-weight: 600;
	border-inline-start-color: var(--ser-accent);
}

/* Narrow screens: float the panel over the text rather than beside it. */
@media (max-width: 900px) {
	.ser-toc {
		position: absolute;
		inset-block: 0;
		inset-inline-start: 0;
		z-index: 6;
		flex: none;
		width: min(84%, 320px);
		max-height: none;
		box-shadow: 0 0 24px rgba(0, 0, 0, 0.18);
	}

	.ser-reader.ser-toc-open .ser-scrim {
		display: block;
		position: absolute;
		inset: 0;
		z-index: 5;
		background: rgba(0, 0, 0, 0.3);
	}
}

/* ---------- Reading surface ---------- */

.ser-surface {
	position: relative;
	flex: 1 1 auto;
	min-width: 0;
	overflow-y: auto;
	max-height: 78vh;
	padding: clamp(28px, 4vw, 64px) clamp(22px, 5vw, 72px);
}

.ser-chapter {
	position: relative;
	max-width: var(--ser-measure);
	margin: 0 auto;
	padding: 0 4px;
	font-size: var(--ser-size);
	line-height: var(--ser-lead);
	color: var(--ser-ink);

	/* Never adjust letter-spacing on Devanagari — it breaks conjuncts. */
	letter-spacing: normal;
	hyphens: none;
	-webkit-hyphens: none;
	word-break: normal;
	overflow-wrap: break-word;
}

.ser-reader[data-font="noto-serif-devanagari"] .ser-chapter {
	font-family: "Noto Serif Devanagari", "Noto Serif", Georgia, serif;
}

.ser-reader[data-font="noto-sans-devanagari"] .ser-chapter {
	font-family: "Noto Sans Devanagari", "Noto Sans", system-ui, sans-serif;
}

.ser-chapter p {
	margin: 0 0 1.05em;
	text-align: start;
	font-size: inherit;
	line-height: inherit;
	color: inherit;
}

.ser-chapter p + p {
	text-indent: 1.5em;
}

.ser-chapter h1,
.ser-chapter h2,
.ser-chapter h3,
.ser-chapter h4 {
	margin: 1.8em 0 0.9em;
	font-family: inherit;
	font-weight: 600;
	line-height: 1.45;
	letter-spacing: normal;
	color: inherit;
}

.ser-chapter > h1:first-child,
.ser-chapter > h2:first-child,
.ser-chapter > h3:first-child {
	margin-top: 0;
}

.ser-chapter h1 { font-size: 1.45em; }
.ser-chapter h2 { font-size: 1.26em; }
.ser-chapter h3 { font-size: 1.1em; }
.ser-chapter h4 { font-size: 1em; }

.ser-chapter hr {
	width: 28%;
	margin: 2.2em auto;
	border: 0;
	border-top: 1px solid var(--ser-rule);
}

.ser-chapter blockquote {
	margin: 1.4em 0;
	padding-inline-start: 1.2em;
	border-inline-start: 2px solid var(--ser-rule);
	color: var(--ser-ink-soft);
}

.ser-chapter img {
	max-width: 100%;
	height: auto;
	display: block;
	margin: 1.6em auto;
}

.ser-chapter table {
	width: 100%;
	margin: 1.4em 0;
	border-collapse: collapse;
	font-size: 0.94em;
}

.ser-chapter td,
.ser-chapter th {
	padding: 6px 10px;
	border: 1px solid var(--ser-rule);
}

.ser-status {
	color: var(--ser-ink-soft);
	text-align: center;
}

/* ---------- Chapter navigation, above and below the text ---------- */

.ser-nav {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	max-width: var(--ser-measure);
	margin: 0 auto;
}

.ser-nav-top {
	padding-bottom: 18px;
	margin-bottom: 22px;
	border-bottom: 1px solid var(--ser-rule);
}

.ser-nav-bottom {
	padding-top: 22px;
	margin-top: 30px;
	border-top: 1px solid var(--ser-rule);
}

.ser-nav .ser-btn {
	border-color: var(--ser-rule);
	padding: 7px 14px;
}

.ser-nav-count {
	font-size: 0.78rem;
	color: var(--ser-ink-soft);
	white-space: nowrap;
}

/* ---------- Watermark ---------- */

.ser-watermark {
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 1;
	opacity: 0.075;
	overflow: hidden;
}

.ser-watermark::before {
	content: attr(data-mark);
	position: absolute;
	inset: 0;
	display: block;
	font-size: 0.8rem;
	line-height: 4.2;
	letter-spacing: 0.35em;
	white-space: nowrap;
	color: var(--ser-ink);
	transform: rotate(-30deg) scale(1.6);
	transform-origin: center;
	text-align: center;
	word-spacing: 3em;
}

.ser-reader[data-theme="night"] .ser-watermark {
	opacity: 0.11;
}

/* ---------- Footer and progress ---------- */

.ser-foot {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 14px;
	background: var(--ser-paper-raised);
	border-top: 1px solid var(--ser-rule);
}

.ser-position {
	font-size: 0.78rem;
	color: var(--ser-ink-soft);
	text-align: center;
}

.ser-progress-rail {
	height: 2px;
	background: var(--ser-rule);
}

.ser-progress-fill {
	height: 100%;
	width: 0;
	background: var(--ser-accent);
	transition: width 220ms ease;
}

/* ---------- Copy protection ---------- */

.ser-protect-standard .ser-chapter,
.ser-protect-strict .ser-chapter {
	-webkit-user-select: none;
	-moz-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
}

.ser-blurred .ser-chapter {
	filter: blur(7px);
	transition: filter 90ms linear;
}

@media print {
	.ser-protect-standard,
	.ser-protect-strict {
		display: none !important;
	}
}

/* ---------- Shelf ---------- */

.ser-shelf {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
	gap: 22px;
	margin: 24px 0;
}

.ser-shelf-item {
	display: flex;
	gap: 14px;
	padding: 14px;
	background: #fff;
	border: 1px solid #e3e1da;
	border-radius: 2px;
}

.ser-shelf-cover {
	flex: 0 0 74px;
	display: flex;
	align-items: center;
	justify-content: center;
	aspect-ratio: 2 / 3;
	background: #eceae3;
	overflow: hidden;
}

.ser-shelf-cover img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.ser-cover-fallback {
	font-size: 1.7rem;
	font-weight: 600;
	color: #2d3a8c;
}

.ser-shelf-meta {
	flex: 1 1 auto;
	min-width: 0;
}

.ser-shelf-meta h3 {
	margin: 0 0 3px;
	font-size: 0.98rem;
	line-height: 1.35;
}

.ser-shelf-author {
	margin: 0 0 8px;
	font-size: 0.82rem;
	color: #6b6f7d;
}

.ser-tag {
	display: inline-block;
	margin: 0 0 8px;
	padding: 2px 7px;
	font-size: 0.7rem;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	border-radius: 2px;
}

.ser-tag-borrow {
	color: #2d3a8c;
	background: #e7eaf7;
}

.ser-shelf-progress {
	height: 3px;
	margin: 0 0 10px;
	background: #e3e1da;
}

.ser-shelf-progress span {
	display: block;
	height: 100%;
	background: #2d3a8c;
}

.ser-open,
.ser-borrow,
.ser-return {
	display: inline-block;
	margin-inline-end: 6px;
	padding: 6px 12px;
	font-size: 0.84rem;
	color: #fff;
	background: #2d3a8c;
	border: 1px solid #2d3a8c;
	border-radius: 2px;
	text-decoration: none;
	cursor: pointer;
}

.ser-return {
	color: #2d3a8c;
	background: transparent;
}

.ser-open:hover,
.ser-borrow:hover { background: #232e70; }

.ser-library-status {
	font-size: 0.85rem;
	color: #6b6f7d;
}

.ser-notice {
	max-width: 34rem;
	margin: 40px auto;
	padding: 28px;
	text-align: center;
	background: #fff;
	border: 1px solid #e3e1da;
	border-radius: 2px;
}

.ser-notice h2 {
	margin: 0 0 8px;
	font-size: 1.2rem;
}

.ser-toast {
	position: fixed;
	left: 50%;
	bottom: 26px;
	z-index: 9999;
	transform: translateX(-50%);
	max-width: 90vw;
	padding: 11px 18px;
	font-size: 0.88rem;
	color: #fff;
	background: #1a1d29;
	border-radius: 2px;
}

@media (max-width: 640px) {
	.ser-reader { --ser-size: 1.06rem; }
	.ser-surface { padding: 22px 18px; }
	.ser-nav .ser-btn { padding: 7px 10px; font-size: 0.8rem; }
	.ser-btn-label { display: none; }
	.ser-surface { max-height: none; }
	.ser-shelf { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
	.ser-progress-fill { transition: none; }
}

/* ---------- Product page ---------- */

.ser-product-actions {
	margin: 0 0 18px;
}

.ser-owned {
	margin: 0 0 8px;
	font-size: 0.92rem;
	font-weight: 600;
	color: #2d3a8c;
}

.ser-read-note {
	margin: 0 0 4px;
	font-size: 0.85rem;
	color: #6b6f7d;
}

/* ---------- Ebook promo on a print product page ---------- */

.ser-ebook-promo {
	margin: 22px 0;
	padding: 16px 18px;
	background: #f6f6f9;
	border: 1px solid #e0e0e8;
	border-inline-start: 3px solid #2d3a8c;
	border-radius: 2px;
}

.ser-promo-head {
	margin: 0 0 8px;
	font-size: 0.95rem;
	font-weight: 600;
	letter-spacing: 0.01em;
}

.ser-promo-line {
	margin: 0 0 10px;
	font-size: 0.88rem;
	color: #4a4e5c;
}

.ser-promo-line strong { color: #1a1d29; }

.ser-promo-link {
	font-size: 0.86rem;
	color: #2d3a8c;
}

.ser-promo-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px;
	margin: 0;
}

.ser-promo-price {
	font-size: 1.02rem;
	font-weight: 600;
	color: #1a1d29;
}

.ser-promo-price del { font-weight: 400; opacity: 0.6; }

.ser-ebook-promo .button {
	margin: 0;
}

.ser-subscribe {
	background: transparent !important;
	color: #2d3a8c !important;
	box-shadow: inset 0 0 0 1px #2d3a8c;
}

/* ---------- Alignment carried over from DOCX ---------- */

.ser-chapter .ser-center {
	text-align: center;
	text-indent: 0;
}

.ser-chapter .ser-right {
	text-align: end;
	text-indent: 0;
}

.ser-chapter p.ser-center + p,
.ser-chapter p.ser-right + p {
	text-indent: 0;
}

.ser-promo-warn {
	margin: 10px 0 0;
	padding: 8px 10px;
	font-size: 0.82rem;
	color: #8a5300;
	background: #fcf5e6;
	border-inline-start: 3px solid #dba617;
}

.ser-sub-status {
	margin: 0 0 18px;
	padding: 10px 14px;
	font-size: 0.88rem;
	color: #2d3a8c;
	background: #eef1fa;
	border-inline-start: 3px solid #2d3a8c;
	border-radius: 2px;
}

.ser-sub-ending {
	color: #8a5300;
	background: #fcf5e6;
	border-inline-start-color: #dba617;
}

/* ---------- Ebook page actions ---------- */

.ser-product-actions {
	margin: 0 0 20px;
}

.ser-product-actions .ser-promo-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px;
	margin: 10px 0 0;
}

.ser-product-actions .ser-promo-price {
	font-size: 1.1rem;
	font-weight: 600;
}
