/* ============================================================
   NUT KINH LUP "TIM KINH KHAC" — HIEN CA KHI DANG DOC SACH
   Mau theo he mau san co: nau #8b5a2b, vang #b08434, nen giay #fdfaf4.

   VI TRI: GIUA CANH DUOI man hinh.
   Ly do (so do tren site that, xem tools/reader-search/):
     - >=768px: hai mui ten lat trang nam o GIUA CHIEU CAO hai mep (top:50%),
       canh duoi trong hoan toan.
     - <=767px: mui ten lat trang xuong canh duoi nhung nam o 10% trai / 10% phai
       (master.css: .bb-custom-wrapper nav span { bottom:20px; left:10% } ,
        <=480px thi bottom:30px) -> khoang giua canh duoi van trong.
     - Thanh cuon .ps__scrollbar-y-rail bam mep PHAI, nut mep duoi GIUA nen khong dinh.
     - Nut "XEM MUC LUC" va dau X deu nam o thanh TREN -> khong lien quan.
   ============================================================ */

.ksp-rs {
	position: fixed;
	left: 50%;
	bottom: calc(18px + env(safe-area-inset-bottom));
	transform: translateX(-50%);
	/* duoi hop giai thich AI (99999) va hop tim kinh (100000),
	   duoi banner cai app PWA (99998), tren khung doc sach (2000) */
	z-index: 99996;
	display: none;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	pointer-events: none;      /* khung bao khong chan cham vao trang sach */
}
.ksp-rs > * { pointer-events: auto; }

/* Chi hien khi DANG DOC SACH (theme them .body--disabled luc mo trinh doc) */
body.body--disabled .ksp-rs,
body:has(.book-container.showBook) .ksp-rs { display: flex; }

/* Hop giai thich AI truot len tu canh duoi -> tranh de len nhau */
body.ksp-ai-sheet-open .ksp-rs,
body:has(.ksp-ai-box.is-sheet:not([hidden])) .ksp-rs { display: none !important; }

/* Che do du phong: khi KHONG tim thay nut "Tim kinh" cua ksp-ai-assistant tren trang
   (JS tu gan lop nay) thi hien nut nay o goc duoi phai nhu nut cu, de "trang nao cung co kinh lup".
   Binh thuong lop nay khong bao gio duoc gan -> khong co chuyen hai nut cung hien. */
.ksp-rs.ksp-rs--page {
	display: flex;
	left: auto;
	right: 16px;
	bottom: calc(16px + env(safe-area-inset-bottom));
	transform: none;
	align-items: flex-end;
}
body.body--disabled .ksp-rs.ksp-rs--page {
	left: 50%;
	right: auto;
	transform: translateX(-50%);
	align-items: center;
}

/* ---------- nut ---------- */
.ksp-rs-fab {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	box-sizing: border-box;
	min-height: 48px;          /* >= 44px de cham duoc tren dien thoai */
	min-width: 48px;
	padding: 0 18px;
	border-radius: 999px;
	background: #8b5a2b;
	color: #fff;               /* tuong phan 5,84 : 1 */
	border: 1px solid rgba(60, 40, 10, .2);
	box-shadow: 0 6px 20px rgba(60, 40, 10, .32);
	font: inherit;
	font-size: 15px;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}
.ksp-rs-fab:hover,
.ksp-rs-fab:focus-visible { background: #76491f; color: #fff; text-decoration: none; }
.ksp-rs-fab:focus-visible { outline: 3px solid #b08434; outline-offset: 2px; }
.ksp-rs-fab svg { flex: none; }
.ksp-rs-fab .ksp-rs-t { white-space: nowrap; }

/* ---------- goi y "Tim kinh khac" ---------- */
.ksp-rs-hint {
	background: #fdfaf4;
	color: #8b5a2b;            /* tuong phan 5,54 : 1 */
	border: 1px solid #ddd0b6;
	border-radius: 999px;
	padding: 7px 14px;
	font: inherit;
	font-size: 13.5px;
	font-weight: 600;
	line-height: 1.2;
	white-space: nowrap;
	box-shadow: 0 4px 14px rgba(60, 40, 10, .2);
	animation: ksp-rs-in .25s ease-out;
}
@keyframes ksp-rs-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .ksp-rs-hint { animation: none; } }

/* ---------- man hinh hep: chi con bieu tuong, chu thanh goi y ngan ---------- */
@media (max-width: 480px) {
	.ksp-rs-fab { padding: 0; width: 48px; height: 48px; }
	.ksp-rs-fab .ksp-rs-t { display: none; }    /* van con aria-label="Tim kinh khac" */
}
/* Man hinh rong thi chu hien thang canh kinh lup, khong can goi y noi */
@media (min-width: 481px) {
	.ksp-rs-hint { display: none !important; }
}

/* ============================================================
   CHE DO TOI KHI DOC SACH
   Bat khi <html data-ksp-theme="dark"> + body.body--disabled
   (bang mau trong ksp-ai-assistant/assets/ksp-dark.css).
   Dung pill toi + chu/bieu tuong vang kem cho do choi mat ban dem.
   ============================================================ */
:root[data-ksp-theme="dark"] body.body--disabled .ksp-rs-fab {
	background: #272118;
	color: #d8b071;            /* tuong phan 7,87 : 1 tren #272118 */
	border-color: #5a4a30;
	box-shadow: 0 6px 20px rgba(0, 0, 0, .55);
}
:root[data-ksp-theme="dark"] body.body--disabled .ksp-rs-fab:hover,
:root[data-ksp-theme="dark"] body.body--disabled .ksp-rs-fab:focus-visible {
	background: #332b1f;
	color: #f0cd8a;
}
:root[data-ksp-theme="dark"] body.body--disabled .ksp-rs-hint {
	background: #272118;
	color: #d8b071;            /* tuong phan 7,87 : 1 */
	border-color: #5a4a30;
	box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
}
/* ksp-dark.css co quy tac .book-container *:not(.ksp-rl-spin){border-color:...}
   — nut nay nam NGOAI .book-container nen khong dinh, nhung van ep ro rang cho chac. */
:root[data-ksp-theme="dark"] body.body--disabled .ksp-rs-fab svg,
:root[data-ksp-theme="dark"] body.body--disabled .ksp-rs-hint { opacity: 1; }
