/* Trình đọc trực tuyến (mlib/reader.php, assets/js/reader.js). Màu, phông theo hệ thống; vùng chạm 44px; tương phản ≥ 4.5:1. */
:root { --navy: #132a4f; --blue: #1560bd; --orange: #f7931e; --muted: #475569; --line: #e2e8f0; --bg: #e9eef5; --head: "Baloo 2", "Be Vietnam Pro", system-ui, sans-serif; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
/* 100dvh: iPad/iPhone Safari tính đúng chiều cao khi thanh địa chỉ co giãn; trình duyệt cũ dùng 100%. */
body.rd { height: 100dvh; overflow: hidden; -webkit-text-size-adjust: 100%; display: flex; flex-direction: column; background: var(--bg); font: 400 15px/1.5 "Be Vietnam Pro", system-ui, sans-serif; color: var(--navy); }
button, input, select { font: inherit; color: inherit; }
.screen-reader-text { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rd-ic { width: 20px; height: 20px; flex: none; }
.rd-btn { flex: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; display: inline-grid; place-items: center; min-width: 44px; height: 44px; padding: 0 10px; border: 0; border-radius: 12px; background: none; color: var(--navy); text-decoration: none; cursor: pointer; transition: background-color .15s; }
@media (hover: hover) { .rd-btn:hover { background: #eef3fb; } .rd-cta:hover { background: #ffa53d; } }
.rd-btn[hidden] { display: none; }
.rd-btn[aria-pressed="true"] { background: #e3eefc; color: var(--blue); }
:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }

.rd-top { position: relative; z-index: 5; display: flex; align-items: center; gap: 6px; min-height: 60px; padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); background: #fff; border-bottom: 1px solid var(--line); box-shadow: 0 6px 18px -14px rgba(19, 42, 79, .5); }
.rd-title { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.rd-title b { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 800 1rem var(--head); }
.rd-title small { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; color: var(--muted); font-size: .8125rem; }
.rd-kind { padding: 0 8px; border-radius: 999px; border: 1px solid var(--k); color: var(--k); font-weight: 700; font-size: .75rem; }
.rd-trial { display: inline-flex; align-items: center; gap: 3px; color: #9a4a0b; font-weight: 700; }
.rd-trial .rd-ic { width: 13px; height: 13px; }
.rd-switch { flex: none; }
.rd-switch select { height: 44px; max-width: 260px; padding: 0 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.rd-pager { flex: none; display: flex; align-items: center; gap: 2px; }
.rd-pager input { width: 52px; height: 36px; border: 1px solid var(--line); border-radius: 10px; text-align: center; font-weight: 700; }
.rd-pager span { color: var(--muted); white-space: nowrap; }
.rd-zoom { flex: none; display: flex; align-items: center; }
.rd-zoom output { min-width: 54px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.rd-cta { flex: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 0; border-radius: 12px; background: var(--orange); color: #1f1300; font-weight: 800; text-decoration: none; box-shadow: 0 3px 0 #c2410c; cursor: pointer; white-space: nowrap; }
.rd-progress { position: absolute; left: 0; bottom: -1px; height: 3px; width: 0; max-width: 100%; background: linear-gradient(90deg, var(--blue), var(--orange)); transition: width .2s, opacity .4s; }

.rd-find { display: none; align-items: center; gap: 8px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); }
.rd-find.is-open { display: flex; }
.rd-find input { flex: 1; max-width: 360px; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; }
.rd-count { min-width: 110px; color: var(--muted); font-size: .875rem; }

.rd-body { flex: 1; min-height: 0; display: flex; }
.rd-thumbs { width: 176px; flex: none; overflow-y: auto; padding: 14px 18px; background: #f8fafc; border-right: 1px solid var(--line); }
.rd-thumbs[hidden] { display: none; }
.rd-thumb { display: block; width: 100%; margin: 0 0 14px; padding: 0; border: 0; background: none; text-align: center; cursor: pointer; }
.rd-thumb canvas, .rd-thumb img, .rd-thumb .rd-ph { display: block; width: 100%; aspect-ratio: 210 / 297; object-fit: cover; border-radius: 4px; background: #fff; box-shadow: 0 1px 3px rgba(19, 42, 79, .2); outline: 3px solid transparent; outline-offset: 2px; }
.rd-thumb.is-current canvas, .rd-thumb.is-current img, .rd-thumb.is-current .rd-ph { outline-color: var(--blue); }
.rd-thumb.is-locked .rd-ph { background: repeating-linear-gradient(-45deg, #eef2f7 0 8px, #e5eaf2 8px 16px); }
.rd-thumb > span:last-child { display: block; margin-top: 4px; color: var(--muted); font-size: .75rem; font-weight: 600; }
.rd-scroller { flex: 1; min-width: 0; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 24px 16px 80px; scroll-behavior: smooth; }
.rd-page { position: relative; margin: 0 auto 18px; background: #fff; box-shadow: 0 2px 4px rgba(19, 42, 79, .12), 0 20px 36px -24px rgba(19, 42, 79, .5); }
.rd-page canvas, .rd-page img { display: block; width: 100%; height: 100%; }
/* Khung đo chữ PDF.js gắn vào body; CSS gốc của PDF.js ẩn nó. PDF toàn ảnh không tự thu về 0 nên phải ẩn, nếu không nó thành dải đen ép mất vùng đọc. */
.hiddenCanvasElement { display: none; }
.rd-num { position: absolute; right: 10px; bottom: -22px; color: var(--muted); font-size: .75rem; }
.rd-page.is-loading::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, #f1f5f9 30%, #f8fafc 50%, #f1f5f9 70%) 0 0 / 200% 100%; animation: rd-shim 1.2s linear infinite; }
@keyframes rd-shim { to { background-position: -200% 0; } }
.rd-page.is-broken::after { content: "Không tải được ảnh trang này"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
/* Trang khóa: không có dữ liệu thật, chỉ khung giả (dòng kẻ mờ) */
.rd-page.is-locked { background: #fff repeating-linear-gradient(180deg, transparent 0 34px, #eef2f7 34px 40px); background-clip: content-box; padding: 60px 56px; }
.rd-lockcard { position: absolute; inset: 0; display: grid; place-items: center; background: linear-gradient(180deg, rgba(233, 238, 245, .2), rgba(233, 238, 245, .85)); }
.rd-lockcard > div { width: min(340px, 86%); padding: 24px; border-radius: 20px; background: #fff; text-align: center; box-shadow: 0 30px 60px -24px rgba(19, 42, 79, .55), 0 0 0 1px var(--line); }
.rd-lockicon { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: #ffeed6; color: #9a4a0b; }
.rd-lockicon .rd-ic { width: 26px; height: 26px; }
.rd-lockcard h2 { margin: 10px 0 4px; font: 800 1.125rem var(--head); }
.rd-lockcard p { margin: 0 0 14px; color: var(--muted); font-size: .875rem; }
.rd-lockcard .rd-cta { width: 100%; }
/* Lớp chữ PDF.js: chọn / sao chép / tô kết quả tìm */
.textLayer { position: absolute; inset: 0; overflow: hidden; line-height: 1; }
.textLayer span, .textLayer br { position: absolute; color: transparent; white-space: pre; cursor: text; transform-origin: 0 0; }
.textLayer ::selection { background: rgba(21, 96, 189, .28); }
.textLayer mark.hit { color: transparent; background: rgba(255, 209, 102, .7); border-radius: 2px; }
.textLayer mark.hit.is-cur { background: rgba(247, 147, 30, .85); box-shadow: 0 0 0 2px rgba(247, 147, 30, .4); }
.rd-error { display: none; max-width: 420px; margin: 60px auto; padding: 24px; border-radius: 20px; background: #fff; text-align: center; box-shadow: 0 0 0 1px var(--line); }
.rd-error.is-on { display: block; }

.rd-bottom { display: none; }
.rd-bottom span { min-width: 64px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
/* Ô nhập < 16px làm Safari iOS tự phóng to cả trang khi chạm vào. */
@media (pointer: coarse) { .rd-pager input, .rd-find input, .rd-switch select { font-size: 16px; } }

/* Máy tính bảng (iPad dọc/ngang ≤ 1024px): thanh trên chỉ giữ việc chính; trang + thu phóng xuống thanh nổi phía dưới. */
@media (max-width: 1024px) {
  .rd-hide-md { display: none !important; }
  .rd-switch select { max-width: 200px; }
  .rd-thumbs { position: fixed; z-index: 6; top: 60px; bottom: 0; left: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom)); box-shadow: 10px 0 24px -12px rgba(19, 42, 79, .4); }
  .rd-scroller { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  .rd-bottom { position: fixed; z-index: 5; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 4px; padding: 6px; border-radius: 18px; background: rgba(255, 255, 255, .96); box-shadow: 0 12px 32px -12px rgba(19, 42, 79, .45), 0 0 0 1px var(--line); }
}
@media (max-width: 760px) {
  .rd-hide-sm { display: none !important; }
  .rd-title b { font-size: .9375rem; }
  .rd-title small .rd-kind { display: none; }
  .rd-cta span { display: none; }
  .rd-scroller { padding: 12px 8px calc(96px + env(safe-area-inset-bottom)); }
  .rd-page.is-locked { padding: 30px 20px; }
  .rd-find { gap: 4px; padding: 8px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left)); }
  .rd-find > .rd-ic { display: none; }
  .rd-find input { min-width: 0; }
  .rd-count { min-width: 0; white-space: nowrap; font-size: .8125rem; }
  .rd-bottom { left: 0; right: 0; bottom: 0; transform: none; justify-content: space-between; gap: 2px; padding: 8px max(10px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); border-radius: 0; background: #fff; box-shadow: none; border-top: 1px solid var(--line); }
}
/* Màn thấp (điện thoại nằm ngang): thanh trên gọn hơn; cuộn xuống thì ẩn hai thanh để đọc, cuộn lên hiện lại (reader.js). */
@media (max-height: 500px) and (max-width: 1024px) {
  .rd-top { min-height: 52px; transition: margin-top .2s ease; }
  .rd-title small { display: none; }
  .rd-thumbs { top: 52px; }
  .rd-scroller { padding-top: 10px; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .rd-bottom { bottom: calc(8px + env(safe-area-inset-bottom)); transition: transform .2s ease, opacity .2s; }
  body.is-immersive .rd-top { margin-top: -53px; }
  body.is-immersive .rd-bottom { transform: translate(-50%, 140%); opacity: 0; pointer-events: none; }
}
@media (max-height: 500px) and (max-width: 760px) {
  .rd-bottom { bottom: 0; }
  body.is-immersive .rd-bottom { transform: translateY(110%); }
}
@media (prefers-reduced-motion: reduce) { .rd-scroller { scroll-behavior: auto; } .rd-page.is-loading::after { animation: none; } .rd-top, .rd-bottom { transition: none !important; } }
