/* ==========================================================================
   The Library — design tokens
   ========================================================================== */
:root {
	--lib-cream: #FAF3E1;
	--lib-cream-deep: #F1E3C3;
	--lib-ink: #12211D;
	--lib-emerald: #0B4F45;
	--lib-emerald-light: #146B5C;
	--lib-teal-deep: #0A3B3D;
	--lib-turquoise: #1E9E92;
	--lib-gold: #C9A227;
	--lib-gold-soft: #E7C766;
	--lib-shadow: rgba(11, 30, 26, 0.35);
	--lib-font-display: 'Amiri', 'Traditional Arabic', Georgia, serif;
	--lib-font-body: 'Noto Naskh Arabic', 'Noto Sans', 'Segoe UI', sans-serif;
	--lib-font-label: 'Reem Kufi', 'Noto Kufi Arabic', Georgia, serif;
}

/* Let Arabic titles/text flow right-to-left automatically within the
   surrounding layout, without forcing the whole page into RTL mode */
.lib-brand, .lib-book-title, .lib-toc-title, .lib-chapter-title,
h1, h2, h3, h4, h5, p, .lib-empty-state {
	unicode-bidi: plaintext;
}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
	}
}

html, body {
	background-color: var(--lib-cream);
	color: var(--lib-ink);
	font-family: var(--lib-font-body);
	min-height: 100%;
	-webkit-tap-highlight-color: transparent;
	overscroll-behavior-y: contain;
}

a, button, .btn, .lib-chapter-row, .lib-book-link {
	touch-action: manipulation;
}

/* Comfortable tap targets for a WebView-wrapped app */
.btn, .form-control, .nav-link, .lib-chapter-row {
	min-height: 44px;
}

/* Subtle top edge strip with a geometric star-tile texture */
.lib-shelf-edge {
	height: 6px;
	background: linear-gradient(90deg, var(--lib-emerald) 0%, var(--lib-gold) 50%, var(--lib-emerald) 100%);
}

/* ==========================================================================
   Navbar
   ========================================================================== */
.lib-navbar {
	background-color: var(--lib-emerald);
	padding-top: .9rem;
	padding-bottom: .9rem;
	box-shadow: 0 3px 12px var(--lib-shadow);
}

.lib-admin-nav-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: .75rem;
}

.lib-admin-nav-actions {
	display: flex;
	align-items: center;
	gap: .6rem;
	flex-wrap: wrap;
}

.btn-lib-outline {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 44px;
	padding: 0 1.1rem;
	border-radius: 24px;
	border: 1.5px solid rgba(250, 243, 225, 0.55);
	color: var(--lib-cream);
	background: transparent;
	font-family: var(--lib-font-body);
	font-weight: 600;
	font-size: .92rem;
	line-height: 1;
	text-decoration: none;
	transition: background-color .25s ease, border-color .25s ease, color .25s ease, transform .2s ease;
}

.btn-lib-outline:hover {
	background-color: rgba(250, 243, 225, 0.12);
	border-color: var(--lib-gold-soft);
	color: var(--lib-gold-soft);
	transform: translateY(-1px);
}

.lib-admin-nav-actions .btn-lib {
	height: 44px;
	display: inline-flex;
	align-items: center;
	line-height: 1;
	padding: 0 1.1rem;
}

.lib-brand {
	font-family: var(--lib-font-display);
	font-weight: 700;
	font-size: 1.5rem;
	color: var(--lib-cream) !important;
	letter-spacing: .02em;
}

.lib-brand-mark {
	color: var(--lib-gold);
	margin-right: .35rem;
}

.lib-navbar .nav-link {
	color: var(--lib-cream-deep) !important;
	font-family: var(--lib-font-body);
	font-weight: 600;
	position: relative;
	transition: color .25s ease;
}

.lib-navbar .nav-link::after {
	content: '';
	position: absolute;
	left: 0; bottom: -2px;
	width: 0%;
	height: 2px;
	background: var(--lib-gold);
	transition: width .3s ease;
}

.lib-navbar .nav-link:hover {
	color: var(--lib-gold-soft) !important;
}

.lib-navbar .nav-link:hover::after {
	width: 100%;
}

.lib-navbar .navbar-toggler {
	border-color: rgba(255,255,255,0.6);
}

.lib-navbar .navbar-toggler-icon {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3E%3Cpath stroke='%23FFFFFF' stroke-width='2.5' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E");
}

.lib-page-wrap {
	min-height: 70vh;
	padding-bottom: 3rem;
}

.lib-footer {
	background-color: var(--lib-ink);
	color: var(--lib-cream-deep);
	padding: 1.25rem 0;
	font-family: var(--lib-font-label);
	font-size: 1.05rem;
	letter-spacing: .03em;
}

/* ==========================================================================
   Hero
   ========================================================================== */
.lib-hero {
	background: radial-gradient(ellipse at top, var(--lib-teal-deep) 0%, var(--lib-ink) 75%);
	color: var(--lib-cream);
	padding: 2.25rem 0 3rem;
	margin-bottom: -2.5rem;
	position: relative;
	overflow: hidden;
}

@media (min-width: 768px) {
	.lib-hero {
		padding: 3.5rem 0 4.5rem;
	}
}

.lib-hero::before {
	content: '';
	position: absolute;
	inset: 0;
	background-image: repeating-linear-gradient(90deg, rgba(255,255,255,0.02) 0 2px, transparent 2px 40px);
	pointer-events: none;
}

.lib-hero::after {
	content: '';
	position: absolute;
	left: 0; right: 0; bottom: 0;
	height: 34px;
	background-color: var(--lib-ink);
	-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='60' viewBox='0 0 100 60'%3E%3Cpath d='M0,60 L0,32 C0,16 14,6 25,6 C34,6 38,16 50,0 C62,16 66,6 75,6 C86,6 100,16 100,32 L100,60 Z'/%3E%3C/svg%3E");
	mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='60' viewBox='0 0 100 60'%3E%3Cpath d='M0,60 L0,32 C0,16 14,6 25,6 C34,6 38,16 50,0 C62,16 66,6 75,6 C86,6 100,16 100,32 L100,60 Z'/%3E%3C/svg%3E");
	-webkit-mask-repeat: repeat-x;
	mask-repeat: repeat-x;
	-webkit-mask-size: 84px 34px;
	mask-size: 84px 34px;
}

.lib-hero h1 {
	font-family: var(--lib-font-display);
	font-weight: 800;
	font-size: 1.85rem;
	animation: lib-fade-up .7s ease both;
}

.lib-hero p {
	font-family: var(--lib-font-label);
	font-size: 1.05rem;
	color: var(--lib-gold-soft);
	animation: lib-fade-up .7s ease .15s both;
}

@media (min-width: 768px) {
	.lib-hero h1 { font-size: 2.75rem; }
	.lib-hero p { font-size: 1.25rem; }
}

/* ==========================================================================
   Book shelf grid + "pull off the shelf" cards
   ========================================================================== */
.lib-shelf {
	background: linear-gradient(180deg, transparent 0%, transparent 88%, var(--lib-emerald-light) 88%, var(--lib-emerald) 100%);
	padding: 2.25rem 0 2.5rem;
	position: relative;
	z-index: 1;
}

@media (min-width: 768px) {
	.lib-shelf {
		padding: 3.5rem 0 3.5rem;
	}
}

.lib-book-card {
	perspective: 900px;
	opacity: 0;
	animation: lib-fade-up .6s ease forwards;
	padding: .5rem .5rem 1rem;
	text-align: center;
}

@media (min-width: 768px) {
	.lib-book-card {
		padding: .75rem .75rem 1.25rem;
	}
}

.lib-book-link {
	display: block;
	text-decoration: none;
	color: inherit;
}

.lib-book-cover-frame {
	position: relative;
	max-width: 220px;
	margin: 10px auto 0;
	border-radius: 50% 50% 6px 6px / 32% 32% 6px 6px;
	box-shadow: -6px 6px 14px var(--lib-shadow), inset 4px 0 0 rgba(0,0,0,0.2);
	transform: rotateY(0deg) translateY(0) scale(1);
	transition: transform .45s cubic-bezier(.2,.8,.2,1), box-shadow .45s ease;
	transform-style: preserve-3d;
	overflow: hidden;
	background: var(--lib-emerald-light);
}

.lib-book-cover-frame::before {
	content: '';
	position: absolute;
	top: -9px;
	left: 50%;
	width: 9px;
	height: 9px;
	background: var(--lib-gold);
	border-radius: 50%;
	transform: translateX(-50%);
	box-shadow: 0 -8px 0 -3px var(--lib-gold);
	z-index: 2;
}

.lib-book-cover-frame img {
	display: block;
	width: 100%;
	aspect-ratio: 2 / 3;
	object-fit: cover;
	transition: filter .45s ease;
}

.lib-book-card:hover .lib-book-cover-frame,
.lib-book-card:active .lib-book-cover-frame {
	transform: rotateY(-14deg) translateY(-10px) scale(1.04);
	box-shadow: -16px 20px 28px var(--lib-shadow), inset 4px 0 0 rgba(0,0,0,0.25);
}

.lib-book-card:hover .lib-book-cover-frame img,
.lib-book-card:active .lib-book-cover-frame img {
	filter: brightness(1.05);
}

.lib-book-title-wrap {
	padding: 0 .25rem;
}

.lib-book-title {
	font-family: var(--lib-font-display);
	font-weight: 700;
	font-size: 1.05rem;
	line-height: 1.3;
	margin-top: 1.1rem;
	color: var(--lib-ink);
	transition: color .25s ease;
}

.lib-book-card:hover .lib-book-title,
.lib-book-card:active .lib-book-title {
	color: var(--lib-emerald-light);
}

.lib-book-author {
	font-family: var(--lib-font-label);
	font-size: .95rem;
	color: var(--lib-emerald-light);
	margin-top: .2rem;
}

/* Stagger the shelf reveal */
.lib-book-card:nth-child(1) { animation-delay: .05s; }
.lib-book-card:nth-child(2) { animation-delay: .12s; }
.lib-book-card:nth-child(3) { animation-delay: .19s; }
.lib-book-card:nth-child(4) { animation-delay: .26s; }
.lib-book-card:nth-child(5) { animation-delay: .33s; }
.lib-book-card:nth-child(6) { animation-delay: .40s; }
.lib-book-card:nth-child(7) { animation-delay: .47s; }
.lib-book-card:nth-child(8) { animation-delay: .54s; }

@keyframes lib-fade-up {
	from { opacity: 0; transform: translateY(24px); }
	to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Chapters / Table of contents page
   ========================================================================== */
.lib-toc-header {
	border-bottom: 2px solid var(--lib-gold);
	padding-bottom: 1rem;
	margin-bottom: 1.5rem;
}

.lib-toc-eyebrow {
	font-family: var(--lib-font-label);
	letter-spacing: .12em;
	text-transform: uppercase;
	color: var(--lib-emerald-light);
	font-size: .9rem;
}

.lib-toc-title {
	font-family: var(--lib-font-display);
	font-weight: 800;
	font-size: 2.1rem;
	color: var(--lib-ink);
}

.lib-chapter-row {
	display: flex;
	align-items: center;
	gap: .85rem;
	padding: .9rem 1rem;
	border-radius: 10px;
	text-decoration: none;
	color: var(--lib-ink);
	background: #fff;
	border: 1px solid rgba(11, 79, 69, 0.12);
	margin-bottom: .8rem;
	opacity: 0;
	animation: lib-fade-up .5s ease forwards;
	transition: transform .3s cubic-bezier(.2,.8,.2,1), box-shadow .3s ease, background-color .3s ease;
	position: relative;
	overflow: hidden;
}

.lib-chapter-row:nth-child(1) { animation-delay: .04s; }
.lib-chapter-row:nth-child(2) { animation-delay: .10s; }
.lib-chapter-row:nth-child(3) { animation-delay: .16s; }
.lib-chapter-row:nth-child(4) { animation-delay: .22s; }
.lib-chapter-row:nth-child(5) { animation-delay: .28s; }
.lib-chapter-row:nth-child(6) { animation-delay: .34s; }
.lib-chapter-row:nth-child(7) { animation-delay: .40s; }
.lib-chapter-row:nth-child(8) { animation-delay: .46s; }
.lib-chapter-row:nth-child(9) { animation-delay: .52s; }
.lib-chapter-row:nth-child(10) { animation-delay: .58s; }

.lib-chapter-row::before {
	content: '';
	position: absolute;
	left: 0; top: 0; bottom: 0;
	width: 4px;
	background: var(--lib-gold);
	transform: scaleY(0);
	transform-origin: bottom;
	transition: transform .3s ease;
}

.lib-chapter-row:hover,
.lib-chapter-row:active {
	transform: translateX(10px);
	box-shadow: 0 10px 24px var(--lib-shadow);
	background: var(--lib-cream-deep);
}

.lib-chapter-row:hover::before,
.lib-chapter-row:active::before {
	transform: scaleY(1);
}

.lib-chapter-number {
	font-family: var(--lib-font-label);
	font-weight: 600;
	font-size: 1.6rem;
	color: var(--lib-gold);
	min-width: 2.4rem;
	text-align: center;
}

.lib-chapter-title {
	font-family: var(--lib-font-display);
	font-weight: 700;
	font-size: 1.15rem;
	flex: 1;
}

.lib-chapter-open-icon {
	color: var(--lib-emerald-light);
	transition: transform .3s ease;
	white-space: nowrap;
	font-size: .9rem;
}

@media (max-width: 420px) {
	.lib-chapter-open-icon span.lib-open-label {
		display: none;
	}
}

.lib-chapter-row:hover .lib-chapter-open-icon {
	transform: translateX(6px);
	color: var(--lib-gold);
}

/* ==========================================================================
   Buttons — gold-leaf accent style
   ========================================================================== */
.btn-lib {
	background-color: var(--lib-emerald);
	border-color: var(--lib-emerald);
	color: var(--lib-cream);
	font-family: var(--lib-font-body);
	font-weight: 600;
	border-radius: 24px;
	padding-left: 1.25rem;
	padding-right: 1.25rem;
	transition: transform .2s ease, background-color .25s ease, box-shadow .25s ease;
}

.btn-lib:hover {
	background-color: var(--lib-turquoise);
	border-color: var(--lib-turquoise);
	color: var(--lib-ink);
	transform: translateY(-2px);
	box-shadow: 0 8px 16px var(--lib-shadow);
}

.btn-lib-gold {
	background-color: var(--lib-gold);
	border-color: var(--lib-gold);
	color: var(--lib-ink);
	font-weight: 700;
	border-radius: 24px;
}

.btn-lib-gold:hover {
	background-color: var(--lib-gold-soft);
	border-color: var(--lib-gold-soft);
	color: var(--lib-ink);
	transform: translateY(-2px);
}

/* Empty state */
.lib-empty-state {
	text-align: center;
	padding: 4rem 1rem;
	font-family: var(--lib-font-label);
	font-size: 1.3rem;
	color: var(--lib-emerald-light);
	animation: lib-fade-up .6s ease both;
}

/* Small pill-shaped action chips used in admin tables (Edit / Delete / Manage Chapters) */
.btn-lib-chip {
	display: inline-flex;
	align-items: center;
	gap: .3rem;
	height: 32px;
	padding: 0 .85rem;
	border-radius: 18px;
	font-family: var(--lib-font-body);
	font-weight: 600;
	font-size: .82rem;
	line-height: 1;
	text-decoration: none;
	border: 1.5px solid transparent;
	white-space: nowrap;
	transition: transform .18s ease, background-color .2s ease, border-color .2s ease, color .2s ease;
	margin: 2px;
}

.btn-lib-chip:hover {
	transform: translateY(-1px);
}

.btn-lib-chip svg {
	flex-shrink: 0;
}

.btn-lib-chip-teal {
	background: rgba(11, 79, 69, 0.08);
	border-color: var(--lib-emerald-light);
	color: var(--lib-emerald);
}
.btn-lib-chip-teal:hover {
	background: var(--lib-emerald-light);
	color: #fff;
}

.btn-lib-chip-gold {
	background: rgba(201, 162, 39, 0.12);
	border-color: var(--lib-gold);
	color: #7a5f13;
}
.btn-lib-chip-gold:hover {
	background: var(--lib-gold);
	color: var(--lib-ink);
}

.btn-lib-chip-danger {
	background: #FBEAEA;
	border-color: #D64545;
	color: #B23A3A;
	font-weight: 700;
}
.btn-lib-chip-danger:hover {
	background: #D64545;
	border-color: #D64545;
	color: #fff;
}

/* Admin login page reuses the hero look, kept distinct from public font scale */
.lib-admin-card {
	max-width: 420px;
	width: 100%;
	background: #fff;
	border-radius: 14px;
	border-top: 4px solid var(--lib-gold);
	padding: 2.25rem;
	box-shadow: 0 12px 32px var(--lib-shadow);
	animation: lib-fade-up .5s ease both;
}

.lib-admin-center {
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1.25rem;
}
