/*
 * Reading mode for stories and blog posts: book view (turn pages, two
 * side by side on wide screens) and scroll view, three paper colours,
 * adjustable text size and full screen. Logical properties for Urdu.
 */

body.sh-reader-open { overflow: hidden; }

.sh-reader {
	--sh-reader-size: 20px;
	--sh-r-bg: #fbf7ee;
	--sh-r-text: #2a2119;
	--sh-r-muted: #7b6a55;
	--sh-r-line: rgb(42 33 25 / 12%);
	--sh-r-accent: #a67c2d;
	--sh-r-button: rgb(42 33 25 / 6%);

	position: fixed;
	inset: 0;
	z-index: 100001;
	display: flex;
	flex-direction: column;
	background: var(--sh-r-bg);
	color: var(--sh-r-text);
	font-family: var(--sh-font-ui);
}

.sh-reader[hidden] { display: none; }

.sh-reader[data-tone="sepia"] {
	--sh-r-bg: #f1e3c4;
	--sh-r-text: #3b2c1a;
	--sh-r-muted: #85704f;
	--sh-r-line: rgb(59 44 26 / 15%);
	--sh-r-accent: #8c6420;
	--sh-r-button: rgb(59 44 26 / 7%);
}

.sh-reader[data-tone="night"] {
	--sh-r-bg: #12100d;
	--sh-r-text: #e6dccb;
	--sh-r-muted: #a29480;
	--sh-r-line: rgb(230 220 203 / 12%);
	--sh-r-accent: #e2b85c;
	--sh-r-button: rgb(230 220 203 / 8%);
}

/* Top bar */

.sh-reader__bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 10px clamp(12px, 3vw, 28px);
	border-block-end: 1px solid var(--sh-r-line);
}

.sh-reader__heading {
	display: flex;
	flex-direction: column;
	min-width: 0;
	line-height: 1.4;
}

.sh-reader__heading strong,
.sh-reader__heading span {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sh-reader__heading strong { font-family: var(--sh-font-heading); font-size: 1rem; }
.sh-reader__heading span { color: var(--sh-r-muted); font-size: 0.8rem; }

.sh-reader__controls {
	display: flex;
	flex: none;
	align-items: center;
	gap: 8px;
}

.sh-reader__group {
	display: inline-flex;
	padding: 3px;
	border-radius: 999px;
	background: var(--sh-r-button);
}

.sh-reader__btn,
.sh-reader__icon,
.sh-reader__tone {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	height: 36px;
	min-width: 36px;
	margin: 0;
	padding: 0 12px;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: 600 0.85rem/1 var(--sh-font-ui);
	cursor: pointer;
}

.sh-reader__btn:hover,
.sh-reader__icon:hover { background: var(--sh-r-button); color: inherit; }
.sh-reader__btn[aria-pressed="true"] { background: var(--sh-r-accent); color: var(--sh-r-bg); }
.sh-reader__btn:disabled { opacity: 0.35; cursor: default; }
.sh-reader__icon { padding: 0; width: 40px; }

.sh-reader__a { font-family: Georgia, serif; font-size: 1.15rem; font-weight: 700; }
.sh-reader__a--small { font-size: 0.85rem; }

.sh-reader__tone {
	width: 28px;
	height: 28px;
	min-width: 28px;
	margin: 4px;
	padding: 0;
	border: 1px solid rgb(127 127 127 / 45%);
}

.sh-reader__tone[data-tone="paper"] { background: #fbf7ee; }
.sh-reader__tone[data-tone="sepia"] { background: #f1e3c4; }
.sh-reader__tone[data-tone="night"] { background: #12100d; }
.sh-reader__tone[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--sh-r-bg), 0 0 0 4px var(--sh-r-accent); }

@media (max-width: 960px) {
	.sh-reader__btn span:not(.sh-reader__a) { display: none; }
	.sh-reader__btn { padding: 0 9px; }
}

@media (max-width: 640px) {
	.sh-reader__bar { flex-wrap: wrap; gap: 8px; }
	.sh-reader__heading { flex: 1 1 100%; order: 2; }
	.sh-reader__controls { flex: 1 1 100%; justify-content: space-between; gap: 4px; }
	.sh-reader__tone { margin: 4px 2px; }
}

/* Stage and pages */

.sh-reader__stage {
	position: relative;
	display: flex;
	flex: 1;
	min-height: 0;
	padding-block: clamp(20px, 4vh, 40px);
}

.sh-reader__viewport {
	flex: 1;
	width: 100%;
	max-width: 1180px;
	height: 100%;
	margin-inline: auto;
	padding-inline: clamp(20px, 6vw, 80px);
	overflow: hidden;
	outline: none;
	box-sizing: border-box;
}

.sh-reader__text {
	box-sizing: border-box;
	font-family: var(--sh-font-body);
	font-size: var(--sh-reader-size);
	line-height: 1.8;
	color: var(--sh-r-text);
}

.sh-reader[data-mode="book"] .sh-reader__viewport { padding-inline: 0; width: calc(100% - 2 * clamp(56px, 8vw, 120px)); flex: none; }

.sh-reader[data-mode="book"] .sh-reader__text {
	height: 100%;
	columns: 2;
	column-gap: clamp(48px, 6vw, 96px);
	column-fill: auto;
	column-rule: 1px solid var(--sh-r-line);
	transition: transform 0.45s var(--sh-ease, ease);
}

@media (max-width: 900px), (orientation: portrait) {
	.sh-reader[data-mode="book"] .sh-reader__text { columns: 1; column-gap: 48px; column-rule: 0; }
}

@media (max-width: 640px) {
	.sh-reader[data-mode="book"] .sh-reader__viewport { width: calc(100% - 40px); }
}

.sh-reader[data-mode="scroll"] .sh-reader__viewport { overflow-y: auto; }
.sh-reader[data-mode="scroll"] .sh-reader__text { max-width: 38em; margin-inline: auto; padding-block-end: 4em; }

.sh-reader__text p { margin: 0 0 1em; orphans: 2; widows: 2; }
.sh-reader[data-mode="book"] .sh-reader__text p { text-align: justify; hyphens: auto; }

.sh-reader__text h2,
.sh-reader__text h3,
.sh-reader__text h4 {
	margin: 1.4em 0 0.5em;
	color: inherit;
	font-family: var(--sh-font-heading);
	font-size: 1.3em;
	line-height: 1.3;
	break-after: avoid;
}

.sh-reader__text blockquote {
	margin: 1.2em 0;
	padding-inline-start: 1em;
	border: 0;
	border-inline-start: 3px solid var(--sh-r-accent);
	font-style: italic;
}

.sh-reader__text figure { margin: 1em 0; break-inside: avoid; }
.sh-reader__text img { display: block; max-width: 100%; max-height: 55vh; width: auto; height: auto; margin-inline: auto; border-radius: 6px; object-fit: contain; }
.sh-reader__text figcaption { color: var(--sh-r-muted); font-family: var(--sh-font-ui); font-size: 0.7em; text-align: center; }
.sh-reader__text a { color: var(--sh-r-accent); }
.sh-reader__text .alignwide,
.sh-reader__text .alignfull { width: auto; max-width: 100%; margin-inline: 0; }

.sh-reader__body > p:first-of-type::first-letter {
	float: inline-start;
	margin-inline-end: 0.1em;
	color: var(--sh-r-accent);
	font-family: var(--sh-font-heading);
	font-size: 3.6em;
	font-weight: 800;
	line-height: 0.85;
}

/* Title page: its own page in book view */

.sh-reader__titlepage {
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding-block: 1em 2em;
	text-align: center;
}

.sh-reader[data-mode="book"] .sh-reader__titlepage { height: 100%; padding: 0; break-after: column; box-sizing: border-box; }

.sh-reader__titlepage p {
	margin: 0 0 0.8em;
	color: var(--sh-r-accent);
	font-family: var(--sh-font-ui);
	font-size: 0.7em;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
}

.sh-reader__titlepage h1 {
	margin: 0;
	color: inherit;
	font-family: var(--sh-font-heading);
	font-size: clamp(1.8em, 4vw, 2.6em);
	line-height: 1.15;
}

.sh-reader__titlepage::after {
	content: "";
	display: block;
	width: 64px;
	height: 2px;
	margin: 1.2em auto 0;
	background: var(--sh-r-accent);
}

.sh-reader__next {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin-block-start: 2em;
	padding: 1em 1.2em;
	border: 1px solid var(--sh-r-line);
	border-radius: 10px;
	color: inherit;
	font-family: var(--sh-font-ui);
	text-decoration: none;
	break-inside: avoid;
}

.sh-reader__next small { color: var(--sh-r-accent); font-size: 0.65em; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.sh-reader__next strong { font-family: var(--sh-font-heading); font-size: 1em; }
.sh-reader__next:hover { border-color: var(--sh-r-accent); color: inherit; }

/* Page turn buttons */

.sh-reader__turn {
	position: absolute;
	inset-block-start: 50%;
	z-index: 1;
	display: grid;
	place-items: center;
	width: 48px;
	height: 48px;
	padding: 0;
	border: 1px solid var(--sh-r-line);
	border-radius: 50%;
	background: var(--sh-r-bg);
	color: inherit;
	transform: translateY(-50%);
	cursor: pointer;
	transition: background-color 0.2s, opacity 0.2s;
}

.sh-reader__turn--prev { inset-inline-start: clamp(4px, 2vw, 32px); }
.sh-reader__turn--next { inset-inline-end: clamp(4px, 2vw, 32px); }
.sh-reader__turn:hover { background: var(--sh-r-button); color: inherit; }
.sh-reader__turn:disabled { opacity: 0.2; cursor: default; }
.sh-reader[dir="rtl"] .sh-reader__turn svg { transform: scaleX(-1); }
.sh-reader[data-mode="scroll"] .sh-reader__turn { display: none; }

@media (max-width: 640px) {
	.sh-reader__turn { display: none; }
	.sh-reader[data-mode="book"] .sh-reader__text p { text-align: start; hyphens: manual; }
}

/* Footer: progress and page number */

.sh-reader__foot {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	padding: 0 20px 14px;
	color: var(--sh-r-muted);
	font-size: 0.8rem;
}

.sh-reader__progress {
	display: block;
	width: min(420px, 100%);
	height: 3px;
	border-radius: 3px;
	background: var(--sh-r-line);
	overflow: hidden;
}

.sh-reader__progress span { display: block; width: 0; height: 100%; background: var(--sh-r-accent); transition: width 0.3s; }
.sh-reader[dir="rtl"] .sh-reader__progress { transform: scaleX(-1); }

/* Urdu */

html[lang|="ur"] .sh-reader__text { line-height: 2.3; }
html[lang|="ur"] .sh-reader__titlepage h1 { line-height: 1.9; }
html[lang|="ur"] .sh-reader__titlepage p,
html[lang|="ur"] .sh-reader__next small { letter-spacing: 0; text-transform: none; font-size: 0.8em; }
html[lang|="ur"] .sh-reader__text blockquote { font-style: normal; }
html[lang|="ur"] .sh-reader__body > p:first-of-type::first-letter { float: none; margin: 0; color: inherit; font: inherit; }
html[lang|="ur"] .sh-reader__heading strong,
html[lang|="ur"] .sh-reader__heading span { line-height: 2.1; padding-block: 0.2em; }
html[lang|="ur"] .sh-reader__btn { line-height: 2; }

/* Floating "Reading mode" button */

.sh-reader-fab {
	position: fixed;
	inset-block-end: 20px;
	inset-inline-end: 20px;
	z-index: 800;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	height: 48px;
	padding: 0 20px 0 16px;
	padding-inline: 16px 20px;
	border: 0;
	border-radius: 999px;
	background: var(--sh-gold);
	color: #1a1208;
	box-shadow: 0 10px 30px rgb(0 0 0 / 30%);
	font: 600 0.95rem/1 var(--sh-font-ui);
	cursor: pointer;
	opacity: 0;
	pointer-events: none;
	transform: translateY(16px);
	transition: opacity 0.3s, transform 0.3s var(--sh-ease);
}

.sh-reader-fab.is-visible { opacity: 1; pointer-events: auto; transform: none; }
.sh-reader-fab:hover { background: #f0cd7c; color: #1a1208; }
html[lang|="ur"] .sh-reader-fab { line-height: 2; }

@media (max-width: 640px) {
	.sh-reader-fab span { display: none; }
	.sh-reader-fab { width: 52px; height: 52px; padding: 0; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
	.sh-reader-fab,
	.sh-reader__progress span { transition: none; }
}
