* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: 'Noto Sans Lao', 'Noto Sans Thai', system-ui, sans-serif; color: #eee;
  background: radial-gradient(circle at 50% 40%, #3b4a42 0%, #1b2420 70%);
  display: flex; flex-direction: column; user-select: none;
}
.rd-bar, .rd-footer { display: flex; align-items: center; gap: .4rem; padding: .35rem .6rem; background: rgba(0,0,0,.45); flex: none; z-index: 5; }
.rd-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .95rem; }
.rd-tools { display: flex; gap: .2rem; }
.rd-btn {
  background: transparent; border: 0; color: #eee; font-size: 1.15rem; width: 38px; height: 38px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; text-decoration: none;
}
.rd-btn:hover, .rd-btn.on { background: rgba(255,255,255,.15); color: #ffd666; }
.rd-stage { position: relative; flex: 1; overflow: auto; display: flex; perspective: 2400px; }
.rd-book { margin: auto; display: flex; position: relative; padding: 14px; }
.rd-page {
  position: relative; background: #fff; overflow: hidden; flex: none;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.rd-page img, .rd-page canvas { display: block; width: 100%; height: 100%; }
.rd-page.left { box-shadow: -6px 10px 30px rgba(0,0,0,.5); }
.rd-page.left::after, .rd-page.right::after { content: ""; position: absolute; top: 0; bottom: 0; width: 40px; pointer-events: none; }
.rd-page.left::after { right: 0; background: linear-gradient(90deg, transparent, rgba(0,0,0,.18)); }
.rd-page.right::after { left: 0; background: linear-gradient(270deg, transparent, rgba(0,0,0,.2)); }
.rd-page.blank { background: transparent; box-shadow: none; }
.rd-page .pno { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; color: #999; font-size: 11px; }

/* ໜ້າທີ່ກຳລັງພິກ */
.rd-flip { position: absolute; inset: 14px; display: flex; pointer-events: none; z-index: 4; transform-style: preserve-3d; }
.rd-flip .rd-page { transition: transform .5s cubic-bezier(.45,.05,.35,1), filter .5s; backface-visibility: hidden; }
.rd-flip .rd-page.turn-next { transform-origin: left center; }
.rd-flip .rd-page.turn-prev { transform-origin: right center; }
.rd-flip.go .rd-page.turn-next { transform: rotateY(-90deg); filter: brightness(.6); }
.rd-flip.go .rd-page.turn-prev { transform: rotateY(90deg); filter: brightness(.6); }

.rd-nav {
  position: fixed; top: 50%; transform: translateY(-50%); z-index: 6; border: 0; cursor: pointer;
  width: 46px; height: 80px; background: rgba(0,0,0,.35); color: #fff; font-size: 1.6rem; border-radius: 10px;
}
.rd-nav:hover { background: rgba(0,0,0,.6); color: #ffd666; }
.rd-nav.prev { left: 8px; } .rd-nav.next { right: 8px; }
.rd-nav:disabled { opacity: .2; cursor: default; }

.rd-footer input[type=range] { flex: 1; accent-color: #ffd666; }
.rd-pageinfo { white-space: nowrap; font-size: .9rem; }
.rd-pageinfo input { width: 64px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 6px; padding: 2px 4px; text-align: center; }

.rd-loading { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; z-index: 3; }
.rd-loading.hide { display: none; }
.spinner { width: 46px; height: 46px; border: 4px solid rgba(255,255,255,.2); border-top-color: #ffd666; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.rd-panel {
  position: fixed; top: 0; bottom: 0; left: 0; width: 340px; max-width: 88vw; z-index: 20; background: #1f2925;
  transform: translateX(-100%); transition: transform .25s; display: flex; flex-direction: column; box-shadow: 4px 0 20px rgba(0,0,0,.5);
}
.rd-panel.open { transform: none; }
.rd-panel-head { display: flex; align-items: center; justify-content: space-between; padding: .5rem .75rem; border-bottom: 1px solid rgba(255,255,255,.1); font-weight: 600; }
.rd-panel-body { flex: 1; overflow: auto; padding: .5rem; }
.toc-item { display: flex; gap: .5rem; padding: .45rem .5rem; border-radius: 6px; color: #ddd; cursor: pointer; font-size: .9rem; }
.toc-item:hover { background: rgba(255,255,255,.08); color: #ffd666; }
.toc-item span:last-child { margin-left: auto; color: #999; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { cursor: pointer; text-align: center; font-size: 11px; color: #aaa; }
.thumb .tbox { aspect-ratio: 3/4; background: #fff1; display: flex; align-items: center; justify-content: center; overflow: hidden; border: 2px solid transparent; border-radius: 3px; }
.thumb.cur .tbox { border-color: #ffd666; }
.thumb img, .thumb canvas { width: 100%; height: 100%; object-fit: contain; background: #fff; }

.rd-video { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.rd-video iframe, .rd-video video { width: min(100%, 1280px); aspect-ratio: 16/9; border: 0; background: #000; max-height: 100%; }

@media (max-width: 700px) {
  .d-none-sm { display: none !important; }
  .rd-nav { width: 34px; height: 60px; font-size: 1.2rem; }
  .rd-tools .rd-btn { width: 32px; }
}
