/* UI sans — English */
@font-face {
	font-family: 'Inter';
	src: url('../fonts/inter/inter-400.woff2') format('woff2');
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: 'Inter';
	src: url('../fonts/inter/inter-500.woff2') format('woff2');
	font-weight: 500;
	font-style: normal;
	font-display: swap;
}

/* Farsi stack — matches site primary-font */
@font-face {
	font-family: 'primary-font';
	src: url('../fonts/farsi-fonts/iran-yekan-400.woff2') format('woff2');
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: 'primary-font';
	src: url('../fonts/farsi-fonts/iran-yekan-500.woff2') format('woff2');
	font-weight: 500;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: 'primary-font';
	src: url('../fonts/farsi-fonts/iran-yekan-700.woff2') format('woff2');
	font-weight: 700;
	font-style: normal;
	font-display: swap;
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
	-webkit-tap-highlight-color: transparent;
}

:root {
	--bg: #dedee1;
	--surface: #ffffff;
	--ink: #18181b;
	--muted: #71717a;
	--line: #e4e4e7;
	--accent: #3f3f46;
	--book-shadow:
		0 1px 0 rgba(255, 255, 255, 0.5),
		0 36px 72px -20px rgba(24, 24, 27, 0.28),
		0 12px 24px -12px rgba(24, 24, 27, 0.14);
	--depth-z: 13;
	--font-ui: 'Inter', system-ui, -apple-system, sans-serif;
	--font-body: Georgia, 'Times New Roman', serif;
}

html[lang="fa"] {
	--font-ui: 'primary-font', 'Vazir', Tahoma, sans-serif;
	--font-body: 'primary-font', 'Vazir', Tahoma, sans-serif;
}

body {
	font-family: var(--font-ui);
	background: var(--bg);
	color: var(--ink);
	min-height: 100vh;
	min-height: 100dvh;
	overflow: hidden;
	position: fixed;
	width: 100%;
	height: 100%;
	height: 100dvh;
}

.scene {
	position: fixed;
	inset: 0;
	background: var(--bg);
}

.nav {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 100;
	background: rgba(222, 222, 225, 0.9);
	backdrop-filter: blur(12px);
	padding: 14px 20px;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.brand {
	color: var(--muted);
	text-decoration: none;
	font-size: 0.875rem;
	font-weight: 500;
	display: flex;
	align-items: center;
	gap: 8px;
	transition: color 0.2s ease;
}

.brand:hover {
	color: var(--ink);
}

.back-btn {
	padding: 6px 14px;
	background: transparent;
	border: 1px solid var(--line);
	border-radius: 999px;
	color: var(--muted);
	text-decoration: none;
	font-size: 0.8125rem;
	font-weight: 500;
	display: flex;
	align-items: center;
	gap: 6px;
	transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.back-btn:hover {
	color: var(--ink);
	border-color: var(--accent);
	background: var(--surface);
}

.main {
	position: relative;
	z-index: 1;
	height: 100vh;
	height: 100dvh;
	display: flex;
	flex-direction: column;
	padding-top: 56px;
	opacity: 0;
	transition: opacity 0.45s ease;
}

.main.is-ready {
	opacity: 1;
}

.book-wrap {
	position: relative;
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px 16px 12px;
}

.book-wrap::after {
	content: '';
	position: absolute;
	left: 50%;
	bottom: 9%;
	width: min(72vw, 880px);
	height: 36px;
	transform: translateX(-50%);
	background: radial-gradient(ellipse at center, rgba(24, 24, 27, 0.2) 0%, transparent 72%);
	pointer-events: none;
	z-index: 0;
}

#book {
	position: relative;
	z-index: 1;
	border-radius: 2px;
	box-shadow: var(--book-shadow);
}

/* Injected into .stf__block after PageFlip init — above resting .stf__item, below flip shadows */
.book-depth-layer {
	position: absolute;
	top: 0;
	bottom: 0;
	pointer-events: none;
	z-index: var(--depth-z);
}

html[dir="ltr"] .book-depth-spine {
	left: 0;
	width: 20px;
	background: linear-gradient(
		to right,
		rgba(24, 24, 27, 0.32) 0%,
		rgba(24, 24, 27, 0.14) 45%,
		transparent 100%
	);
}

html[dir="rtl"] .book-depth-spine {
	right: 0;
	width: 20px;
	background: linear-gradient(
		to left,
		rgba(24, 24, 27, 0.32) 0%,
		rgba(24, 24, 27, 0.14) 45%,
		transparent 100%
	);
}

html[dir="ltr"] .book-depth-fore {
	right: 0;
	width: 14px;
	background:
		linear-gradient(to left, rgba(24, 24, 27, 0.26), transparent 85%),
		repeating-linear-gradient(
			to bottom,
			rgba(24, 24, 27, 0.2) 0,
			rgba(24, 24, 27, 0.2) 1px,
			transparent 1px,
			transparent 4px
		);
}

html[dir="rtl"] .book-depth-fore {
	left: 0;
	width: 14px;
	background:
		linear-gradient(to right, rgba(24, 24, 27, 0.26), transparent 85%),
		repeating-linear-gradient(
			to bottom,
			rgba(24, 24, 27, 0.2) 0,
			rgba(24, 24, 27, 0.2) 1px,
			transparent 1px,
			transparent 4px
		);
}

.page {
	background: var(--surface);
}

/* Cover & back */
.cover-page {
	background: linear-gradient(165deg, #52525b 0%, #27272a 100%);
	position: relative;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	box-shadow:
		inset 0 -5px 10px rgba(0, 0, 0, 0.32),
		inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.cover-page::after {
	content: '';
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 3px;
	background: linear-gradient(to bottom, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.38));
	pointer-events: none;
	z-index: 2;
}

.cover-inner {
	position: relative;
	z-index: 1;
	height: 100%;
	display: flex;
	flex-direction: column;
	padding: 40px 32px;
}

.cover-inner--center {
	justify-content: center;
	text-align: center;
}

.cover-top {
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.cover-label {
	font-size: 0.6875rem;
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.12em;
	color: rgba(255, 255, 255, 0.55);
	margin-bottom: 16px;
}

.cover-title {
	font-family: var(--font-ui);
	font-size: 1.75rem;
	font-weight: 500;
	color: #fff;
	line-height: 1.35;
	margin-bottom: 12px;
}

.cover-subtitle {
	font-size: 0.875rem;
	color: rgba(255, 255, 255, 0.65);
	line-height: 1.7;
	font-weight: 400;
}

.cover-bottom {
	display: flex;
	justify-content: space-between;
	align-items: flex-end;
	padding-top: 24px;
}

.cover-meta {
	font-size: 0.75rem;
	color: rgba(255, 255, 255, 0.55);
}

.cover-rating {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 6px;
}

.cover-rating-label {
	font-size: 0.625rem;
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	color: rgba(255, 255, 255, 0.5);
}

.cover-stars {
	display: flex;
	gap: 4px;
}

.star-btn {
	background: none;
	border: none;
	padding: 0;
	min-width: 44px;
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	color: rgba(255, 255, 255, 0.35);
	font-size: 0.875rem;
	line-height: 1;
	transition: color 0.15s ease, transform 0.15s ease;
}

.star-btn:hover,
.star-btn:focus-visible {
	color: rgba(255, 255, 255, 0.85);
	outline: none;
	transform: scale(1.08);
}

.star-btn.is-filled,
.star-btn.is-user {
	color: rgba(255, 255, 255, 0.85);
}

.star-btn.is-user {
	color: #fff;
}

.cover-rating.is-busy {
	opacity: 0.6;
	pointer-events: none;
}

.cover-rating-meta {
	font-size: 0.75rem;
	color: rgba(255, 255, 255, 0.65);
	font-variant-numeric: tabular-nums;
}

.cover-rating-sep {
	margin: 0 4px;
	opacity: 0.5;
}

.cover-end-icon {
	font-size: 2rem;
	color: rgba(255, 255, 255, 0.75);
	margin-bottom: 20px;
}

.cover-end-title {
	font-family: var(--font-ui);
	font-size: 1.5rem;
	font-weight: 500;
	color: #fff;
	margin-bottom: 12px;
}

.cover-end-meta {
	color: rgba(255, 255, 255, 0.55);
	font-size: 0.8125rem;
}

/* Content pages */
.content-page {
	padding: 36px 32px;
	background: var(--surface);
	display: flex;
	flex-direction: column;
	height: 100%;
	position: relative;
}

.content-page.portfolio-measure .page-body {
	overflow: hidden;
}

.page-head {
	margin-bottom: 28px;
}

.page-number {
	font-size: 0.6875rem;
	font-weight: 500;
	color: var(--muted);
	margin-bottom: 10px;
}

.page-title {
	font-family: var(--font-ui);
	font-size: 1.125rem;
	font-weight: 500;
	color: var(--ink);
	line-height: 1.4;
	margin-bottom: 8px;
}

.page-cat {
	display: inline-block;
	color: var(--muted);
	font-size: 0.6875rem;
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.08em;
}

.page-body {
	flex: 1;
	color: #3f3f46;
	font-family: var(--font-body);
	font-size: 0.9375rem;
	line-height: 1.85;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	touch-action: pan-y;
	overscroll-behavior: contain;
	font-weight: 400;
	position: relative;
}

html[lang="fa"] .page-body {
	line-height: 2;
}

.page-body::-webkit-scrollbar {
	width: 3px;
}

.page-body::-webkit-scrollbar-thumb {
	background: var(--line);
	border-radius: 3px;
}

.page-body h1,
.page-body h2,
.page-body h3 {
	font-family: var(--font-ui);
	color: var(--ink);
	font-weight: 500;
	margin: 24px 0 12px;
	line-height: 1.4;
}

.page-body h1 { font-size: 1.25rem; }
.page-body h2 { font-size: 1.125rem; }
.page-body h3 { font-size: 1rem; }

.page-body p {
	margin-bottom: 1em;
}

html[dir="ltr"] .page-body p {
	text-align: left;
}

.page-body img {
	max-width: 100%;
	height: auto;
	border-radius: 2px;
	margin: 20px 0;
}

.page-body ul,
.page-body ol {
	margin: 16px 0;
	padding-inline-start: 1.25rem;
}

.page-body li {
	margin-bottom: 6px;
}

.page-footer {
	margin-top: 20px;
	padding-top: 16px;
	border-top: 1px solid var(--line);
	text-align: end;
	font-size: 0.6875rem;
	font-weight: 500;
	color: var(--muted);
}

/* Controls */
.controls {
	padding: 12px 20px 28px;
	padding-bottom: max(28px, env(safe-area-inset-bottom, 0px));
}

.controls-grid {
	display: grid;
	grid-template-columns: 44px 1fr auto 44px;
	gap: 12px;
	align-items: center;
	max-width: 380px;
	margin: 0 auto;
}

.like-btn {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	min-height: 44px;
	padding: 6px 10px;
	background: transparent;
	border: 1px solid transparent;
	border-radius: 999px;
	color: var(--muted);
	font-size: 0.8125rem;
	font-weight: 500;
	cursor: pointer;
	font-family: var(--font-ui);
	transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.like-btn:hover,
.like-btn:focus-visible {
	color: var(--ink);
	border-color: var(--line);
	background: var(--surface);
	outline: none;
}

.like-btn.is-liked {
	color: #be123c;
}

.like-btn.is-liked:hover {
	color: #9f1239;
}

.like-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.like-btn i {
	font-size: 0.875rem;
}

#like-count {
	font-variant-numeric: tabular-nums;
	min-width: 1ch;
}

.nav-btn {
	width: 44px;
	height: 44px;
	background: transparent;
	border: 1px solid transparent;
	border-radius: 50%;
	color: var(--muted);
	font-size: 0.875rem;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.nav-btn:hover:not(:disabled),
.nav-btn:focus-visible:not(:disabled) {
	color: var(--ink);
	border-color: var(--line);
	background: var(--surface);
	outline: none;
}

.nav-btn:active:not(:disabled) {
	transform: scale(0.96);
}

.nav-btn:disabled {
	color: #d4d4d8;
	cursor: not-allowed;
}

.page-display {
	text-align: center;
}

.current-page {
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--ink);
	font-variant-numeric: tabular-nums;
}

.total-page {
	font-size: 0.75rem;
	color: var(--muted);
	font-weight: 400;
	margin-top: 2px;
}

.loader {
	position: fixed;
	inset: 0;
	background: var(--bg);
	display: flex;
	justify-content: center;
	align-items: center;
	z-index: 1000;
	flex-direction: column;
	gap: 16px;
	transition: opacity 0.35s ease, visibility 0.35s ease;
}

.loader.is-hidden {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
}

.spinner {
	width: 28px;
	height: 28px;
	border: 2px solid var(--line);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: rotate 0.7s linear infinite;
}

@keyframes rotate {
	to { transform: rotate(360deg); }
}

.loader-text {
	color: var(--muted);
	font-size: 0.8125rem;
	font-weight: 400;
}

@media (min-width: 769px) {
	.nav {
		padding: 16px 40px;
	}

	.brand {
		font-size: 0.9375rem;
	}

	.back-btn {
		padding: 7px 16px;
		font-size: 0.875rem;
	}

	.book-wrap {
		padding: 32px 24px 16px;
	}

	.content-page {
		padding: 44px 40px;
	}

	.cover-inner {
		padding: 48px 40px;
	}

	.cover-title {
		font-size: 2rem;
	}

	.page-title {
		font-size: 1.25rem;
	}

	.controls {
		padding: 16px 40px 32px;
	}

	.controls-grid {
		grid-template-columns: 48px 1fr auto 48px;
		max-width: 420px;
		gap: 14px;
	}

	.nav-btn {
		width: 48px;
		height: 48px;
	}
}

@media (max-width: 480px) {
	.nav {
		padding: 12px 16px;
	}

	.book-wrap {
		padding: 20px 14px 10px;
	}

	.cover-title {
		font-size: 1.625rem;
	}

	.content-page,
	.cover-inner {
		padding: 32px 26px;
	}

	.controls {
		padding-left: 16px;
		padding-right: 16px;
	}

	.controls-grid {
		max-width: 100%;
		gap: 10px;
	}
}

@media (max-width: 380px) {
	.cover-title {
		font-size: 1.5rem;
	}

	.content-page,
	.cover-inner {
		padding: 28px 22px;
	}
}
