/* Protected reader and «کتابخانهٔ من» (phase 5). */

.kf-library {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 16px;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.kf-library__item {
	display: flex;
	gap: 12px;
	align-items: flex-start;
	border: 1px solid rgba(0, 0, 0, 0.08);
	border-radius: 10px;
	padding: 12px;
}

.kf-library .kf-library__cover img,
.woocommerce-account .kf-library__cover img {
	/* The theme stretches account images to full width; the shelf needs a thumbnail. */
	width: 84px;
	max-width: 84px;
	height: auto;
	border-radius: 6px;
	display: block;
}

.kf-library__title {
	margin: 0 0 6px;
	font-size: 1rem;
	line-height: 1.5;
}

.kf-library__meta {
	margin: 0 0 10px;
	font-size: 0.85rem;
	opacity: 0.75;
}

.kf-reader {
	direction: rtl;
	margin: 16px 0;
	background: #f6f6f8;
	border-radius: 12px;
	padding: 12px;
}

.kf-reader__bar {
	/* Forced LTR so the DOM order is the visual order regardless of the theme: «بعدی» on the
	   left, «قبلی» on the right, the way a Persian book is turned. */
	direction: ltr;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 10px;
	flex-wrap: wrap;
}

.kf-reader__center {
	direction: rtl;
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
	justify-content: center;
}

.kf-reader__goto {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.kf-reader__goto-input {
	width: 4.5rem;
	padding: 5px 8px;
	border: 1px solid #d7dbe2;
	border-radius: 6px;
	font: inherit;
	text-align: center;
}

.kf-reader__goto-button {
	border: 0;
	background: #fff;
	border-radius: 6px;
	padding: 6px 14px;
	font: inherit;
	cursor: pointer;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.kf-reader__nav {
	direction: rtl;
	border: 0;
	background: #fff;
	border-radius: 999px;
	min-height: 40px;
	padding: 8px 14px;
	font-size: 15px;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
	font-family: inherit;
}

.kf-reader__nav span {
	font-size: 14px;
}

.kf-reader__nav:hover {
	background: #efefef;
}

.kf-reader__status {
	font-size: 0.9rem;
	opacity: 0.8;
}

.kf-reader__stage {
	position: relative;
	background: #fff;
	border-radius: 8px;
	min-height: 240px;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
}

.kf-reader__canvas {
	max-width: 100%;
	height: auto;
	display: block;
	/* Deterrence only: dragging the canvas out or long-pressing it should not offer a save. */
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
	pointer-events: none;
}

/* The `hidden` attribute loses to the class rule above, so the second canvas has to be hidden
   explicitly — otherwise leaving the two-page spread left the second page on screen for good
   (owner report 2026-09-16). */
.kf-reader__canvas[hidden] {
	display: none;
}

/* «ابتدا» / «انتها» sit next to the page-turn buttons but must not compete with them. */
.kf-reader__edge {
	padding: 8px 12px;
	opacity: 0.85;
}

.kf-reader__notice {
	position: absolute;
	inset: auto 16px 16px;
	margin: 0;
	padding: 12px 14px;
	background: rgba(255, 255, 255, 0.94);
	border-radius: 8px;
	font-size: 0.9rem;
	text-align: center;
}

.kf-reader__notice:empty {
	display: none;
}

.kf-reader__hint {
	margin: 10px 0 0;
	font-size: 0.8rem;
	opacity: 0.65;
	text-align: center;
}

.kf-preview {
	margin: 12px 0;
}

@media print {
	.kf-reader {
		display: none !important;
	}
}

/* ── Wave 1 of the reading experience: tools row, bookmarks, zoom, night, spread ── */

.kf-reader__tools {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	margin-bottom: 10px;
}

.kf-reader__tool {
	border: 0;
	background: #fff;
	border-radius: 999px;
	min-height: 36px;
	padding: 7px 13px;
	font: inherit;
	font-size: 0.85rem;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.kf-reader__tool:hover {
	background: #efefef;
}

.kf-reader__tool.is-on,
.kf-reader__tool[aria-pressed="true"] {
	background: #123a6b;
	color: #fff;
}

.kf-reader__toc-select {
	max-width: 15rem;
	padding: 6px 8px;
	border: 1px solid #d7dbe2;
	border-radius: 6px;
	font: inherit;
	font-size: 0.85rem;
	background: #fff;
}

.kf-reader__zoom {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.kf-reader__zoom-level {
	font-size: 0.8rem;
	min-width: 3.2rem;
	text-align: center;
	opacity: 0.75;
}

.kf-reader__marks {
	background: #fff;
	border-radius: 8px;
	padding: 10px 12px;
	margin-bottom: 10px;
	font-size: 0.85rem;
}

.kf-reader__marks-empty {
	margin: 0;
	opacity: 0.7;
}

.kf-reader__marks-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 6px;
}

.kf-reader__marks-list li {
	display: flex;
	align-items: center;
	gap: 8px;
	justify-content: space-between;
	border-bottom: 1px dashed rgba(0, 0, 0, 0.08);
	padding-bottom: 5px;
}

.kf-reader__mark-open {
	border: 0;
	background: none;
	font: inherit;
	color: #123a6b;
	cursor: pointer;
	text-align: right;
	padding: 2px 0;
	flex: 1;
}

.kf-reader__mark-drop {
	border: 0;
	background: #f2f3f5;
	border-radius: 6px;
	font: inherit;
	font-size: 0.75rem;
	padding: 4px 9px;
	cursor: pointer;
}

.kf-reader__marks-form {
	display: flex;
	gap: 6px;
	margin: 10px 0 0;
}

.kf-reader__note-input {
	flex: 1;
	padding: 6px 9px;
	border: 1px solid #d7dbe2;
	border-radius: 6px;
	font: inherit;
	font-size: 0.85rem;
}

.kf-reader__progress {
	height: 5px;
	background: rgba(0, 0, 0, 0.08);
	border-radius: 999px;
	margin-top: 10px;
	overflow: hidden;
}

.kf-reader__progress-bar {
	display: block;
	height: 100%;
	width: 0;
	background: #1c7f6b;
	transition: width 0.25s ease;
}

/* A zoomed page is scrolled inside the stage instead of stretching the whole layout. */
.kf-reader__stage.is-zoomed {
	overflow: auto;
	align-items: flex-start;
	justify-content: flex-start;
	-webkit-overflow-scrolling: touch;
}

.kf-reader.is-spread .kf-reader__stage {
	gap: 10px;
	align-items: flex-start;
}

/* Night mode: the page image is inverted, which keeps the text light on a dark page. */
.kf-reader.is-night {
	background: #10131a;
	color: #e7e9ee;
}

.kf-reader.is-night .kf-reader__stage {
	background: #171a22;
}

.kf-reader.is-night .kf-reader__canvas {
	filter: invert(1) hue-rotate(180deg) brightness(0.92);
}

.kf-reader.is-night .kf-reader__nav,
.kf-reader.is-night .kf-reader__tool,
.kf-reader.is-night .kf-reader__goto-button {
	background: #232837;
	color: #e7e9ee;
	box-shadow: none;
}

.kf-reader.is-night .kf-reader__marks,
.kf-reader.is-night .kf-reader__goto-input,
.kf-reader.is-night .kf-reader__note-input,
.kf-reader.is-night .kf-reader__toc-select {
	background: #1c2130;
	color: #e7e9ee;
	border-color: #2c3346;
}

.kf-reader.is-night .kf-reader__mark-open {
	color: #8ab4f8;
}

.kf-reader:fullscreen,
.kf-reader.is-pseudo-fullscreen {
	position: fixed;
	inset: 0;
	z-index: 99999;
	margin: 0;
	border-radius: 0;
	overflow: auto;
	padding: 12px 14px;
}

.kf-reader:fullscreen .kf-reader__stage,
.kf-reader.is-pseudo-fullscreen .kf-reader__stage {
	min-height: 70vh;
}

@media (max-width: 640px) {
	.kf-reader {
		padding: 8px;
	}

	/* On a phone the bar becomes two rows: page indicator on top, the two page-turn buttons
	   below it side by side — otherwise every button gets a line of its own. */
	.kf-reader__center {
		flex: 1 1 100%;
		order: -1;
	}

	.kf-reader__nav {
		flex: 1 1 30%;
		text-align: center;
	}

	/* On a phone the two end buttons keep only their arrow, so all four fit on one row. */
	.kf-reader__edge {
		flex: 0 1 auto;
		padding: 8px 10px;
	}

	.kf-reader__edge span {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip-path: inset(50%);
	}

	/* A spread needs a wide screen; the switch would do nothing here. */
	.kf-reader__spread {
		display: none;
	}

	.kf-reader__tools {
		gap: 6px;
	}

	.kf-reader__tool {
		font-size: 0.8rem;
		padding: 7px 10px;
	}

	.kf-reader__toc-select {
		max-width: 100%;
		flex: 1 1 100%;
	}

	.kf-reader__nav span {
		font-size: 13px;
	}
}

/* Install card on «کتابخانهٔ من» (ADR-037). Hidden until pwa.js knows the device can install. */
.kf-pwa-card {
	display: flex;
	align-items: center;
	gap: 14px;
	margin: 0 0 20px;
	padding: 14px 16px;
	border: 1px solid #e6e6ea;
	border-radius: 14px;
	background: #f6f7fa;
}

.kf-pwa-card__icon {
	flex: 0 0 auto;
	width: 48px;
	height: 48px;
	border-radius: 12px;
}

.kf-pwa-card__body {
	flex: 1 1 auto;
	min-width: 0;
}

.kf-pwa-card__text,
.kf-pwa-card__hint {
	margin: 4px 0 0;
	font-size: 0.88rem;
	line-height: 1.8;
	color: #555;
}

.kf-pwa-card__install {
	flex: 0 0 auto;
	white-space: nowrap;
}

.kf-pwa-card.is-installed {
	background: #eef8f1;
	border-color: #cfe9d8;
}

@media (max-width: 600px) {
	.kf-pwa-card {
		flex-wrap: wrap;
	}

	.kf-pwa-card__install {
		flex-basis: 100%;
	}
}

/* In-book search (ADR-038). */
.kf-reader__search {
	display: inline-flex;
	align-items: center;
	gap: 4px;
}

.kf-reader__search-input {
	width: 12rem;
	max-width: 40vw;
	padding: 4px 8px;
	border: 1px solid rgba(0, 0, 0, 0.18);
	border-radius: 6px;
	font: inherit;
	font-size: 0.85rem;
}

.kf-reader__results {
	background: #fff;
	border-radius: 8px;
	padding: 10px 12px;
	margin-bottom: 10px;
	font-size: 0.85rem;
	max-height: 40vh;
	overflow: auto;
}

.kf-reader__results-status {
	margin: 0 0 6px;
	opacity: 0.75;
}

.kf-reader__results-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 4px;
}

.kf-reader__result {
	display: flex;
	gap: 10px;
	align-items: baseline;
	width: 100%;
	padding: 6px 4px;
	border: 0;
	border-bottom: 1px dashed rgba(0, 0, 0, 0.08);
	background: none;
	font: inherit;
	text-align: right;
	cursor: pointer;
	color: inherit;
}

.kf-reader__result:hover,
.kf-reader__result:focus {
	background: rgba(0, 0, 0, 0.04);
}

.kf-reader__result-page {
	flex: 0 0 auto;
	min-width: 4.5rem;
	font-weight: 700;
	color: var(--kf-mega-strong, #123a6b);
}

.kf-reader__result mark {
	background: #ffe9a8;
	color: inherit;
	padding: 0 2px;
	border-radius: 3px;
}

.kf-reader.is-night .kf-reader__results {
	background: #1f1f24;
	color: #e8e8e8;
}

.kf-reader.is-night .kf-reader__result mark {
	background: #6b5a1e;
}
