/* =========================================================
   FLIPBOOK · trình đọc lật trang cho Cẩm nang
   Nạp sau handbook.css. Không ảnh hưởng phần còn lại của site.
   ========================================================= */

#hbReader {
  scroll-margin-top: 84px;
}

.hb-reader {
  --hb-paper: #f8f2e7;
  --hb-accent: #f28b5c;
  --hb-line: rgba(251, 247, 239, 0.16);
  margin-top: 20px;
  padding: 14px clamp(12px, 2vw, 22px) 12px;
  border-radius: 26px;
  border: 1px solid rgba(20, 20, 46, 0.55);
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(96, 96, 170, 0.32), transparent 62%),
    linear-gradient(160deg, #1b1c40 0%, #0f1024 100%);
  box-shadow: 0 40px 80px -50px rgba(20, 20, 46, 0.85);
  color: var(--paper);
}

.hb-reader-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 4px 12px;
}

.hb-reader-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-family: var(--label);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(251, 247, 239, 0.72);
  white-space: nowrap;
}

.hb-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hb-accent);
  box-shadow: 0 0 0 4px rgba(242, 139, 92, 0.18);
}

.hb-reader-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hb-counter {
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(251, 247, 239, 0.08);
  font-family: var(--label);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: rgba(251, 247, 239, 0.92);
  white-space: nowrap;
}

.hb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid rgba(251, 247, 239, 0.22);
  background: rgba(251, 247, 239, 0.06);
  color: var(--paper);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.hb-btn:hover {
  background: rgba(251, 247, 239, 0.14);
}

.hb-btn:focus-visible {
  outline: 2px solid var(--hb-accent);
  outline-offset: 2px;
}

.hb-btn .icon {
  width: 15px;
  height: 15px;
}

.hb-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0 4px;
  outline: none;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.hb-reader.is-turning .hb-stage {
  overflow: hidden;
}

.hb-stage:focus-visible {
  outline: 2px solid rgba(242, 139, 92, 0.85);
  outline-offset: 6px;
  border-radius: 12px;
}

.hb-book {
  position: relative;
  width: 100%;
  max-width: 820px;
  aspect-ratio: 1.5248;
  -webkit-perspective: 2400px;
  perspective: 2400px;
  box-shadow: 0 30px 55px -24px rgba(0, 0, 0, 0.7);
}

.hb-page {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  overflow: hidden;
  background: var(--hb-paper);
}

.hb-page-left {
  left: 0;
  border-radius: 6px 0 0 6px;
}

.hb-page-right {
  right: 0;
  border-radius: 0 6px 6px 0;
}

.hb-page.is-blank::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 100% at 30% 0%, rgba(255, 255, 255, 0.6), transparent 55%),
    linear-gradient(135deg, #fbf6ec, #eee4d3);
}

.hb-page img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.28s ease;
}

.hb-page.is-ready img {
  opacity: 1;
}

.hb-spine {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 3;
  width: 42px;
  height: 100%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(20, 20, 46, 0.18), transparent);
  pointer-events: none;
}

.hb-sheet {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 4;
  width: 50%;
  height: 100%;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transform-origin: left center;
  pointer-events: none;
  will-change: transform;
}

.hb-sheet[hidden] {
  display: none;
}

.hb-sheet.is-anim {
  animation: hb-turn var(--hb-dur, 680ms) cubic-bezier(0.42, 0.05, 0.18, 1) forwards;
}

@keyframes hb-turn {
  to {
    transform: rotateY(var(--hb-to, -180deg));
  }
}

.hb-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--hb-paper);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.hb-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hb-front {
  border-radius: 0 6px 6px 0;
}

.hb-back {
  transform: rotateY(180deg);
  border-radius: 6px 0 0 6px;
}

.hb-face.is-blank img {
  visibility: hidden;
}

.hb-front::after,
.hb-back::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hb-front::after {
  background: linear-gradient(90deg, rgba(20, 20, 46, 0.24), transparent 16%);
}

.hb-back::after {
  background: linear-gradient(270deg, rgba(20, 20, 46, 0.24), transparent 16%);
}

.hb-nav {
  position: absolute;
  top: 50%;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(251, 247, 239, 0.22);
  background: rgba(16, 16, 36, 0.72);
  color: var(--paper);
  cursor: pointer;
  transform: translateY(-50%);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.hb-nav:hover {
  background: rgba(242, 139, 92, 0.9);
  border-color: transparent;
}

.hb-nav:focus-visible {
  outline: 2px solid var(--hb-accent);
  outline-offset: 2px;
}

.hb-nav:disabled {
  opacity: 0.28;
  cursor: default;
}

.hb-nav .icon {
  width: 18px;
  height: 18px;
}

.hb-prev {
  left: 8px;
}

.hb-prev .icon {
  transform: rotate(180deg);
}

.hb-next {
  right: 8px;
}

.hb-reader-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 6px 2px;
}

.hb-range {
  flex: 1;
  height: 28px;
  accent-color: var(--hb-accent);
  cursor: pointer;
}

.hb-hint {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: rgba(251, 247, 239, 0.5);
  white-space: nowrap;
}

/* ---------- chế độ một trang (điện thoại) ---------- */
.hb-reader.is-single .hb-book {
  max-width: 440px;
  aspect-ratio: 0.7624;
}

.hb-reader.is-single .hb-page-left {
  display: none;
}

.hb-reader.is-single .hb-page-right {
  width: 100%;
  border-radius: 6px;
}

.hb-reader.is-single .hb-spine {
  display: none;
}

.hb-reader.is-single .hb-sheet {
  left: 0;
  width: 100%;
}

.hb-reader.is-single .hb-front,
.hb-reader.is-single .hb-back {
  border-radius: 6px;
}

@media (min-width: 1100px) {
  .hb-prev {
    left: -54px;
  }
  .hb-next {
    right: -54px;
  }
}

/* ---------- toàn màn hình (khung nổi) ---------- */
.hb-reader.is-expanded {
  position: fixed;
  inset: 0;
  z-index: 300;
  margin: 0;
  border: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  padding: 12px clamp(12px, 3vw, 26px);
  overflow: hidden;
}

.hb-reader.is-expanded .hb-stage {
  flex: 1;
  min-height: 0;
}

.hb-reader.is-expanded .hb-book {
  width: 100%;
  max-width: 96vw;
  max-width: min(96vw, calc((100dvh - 168px) * 1.5248));
}

.hb-reader.is-expanded.is-single .hb-book {
  max-width: 92vw;
  max-width: min(92vw, calc((100dvh - 168px) * 0.7624));
}

body.hb-lock {
  overflow: hidden;
}

@media (max-width: 760px) {
  .hb-reader {
    margin-top: 16px;
    margin-left: calc(-1 * clamp(20px, 5vw, 56px));
    margin-right: calc(-1 * clamp(20px, 5vw, 56px));
    padding: 12px 10px 10px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .hb-reader.is-expanded {
    margin: 0;
    padding: 12px 10px;
    border-radius: 0;
  }
  .hb-reader-head {
    padding-bottom: 10px;
  }
  .hb-reader-title {
    font-size: 10px;
    letter-spacing: 0.1em;
  }
  .hb-counter {
    font-size: 10.5px;
    padding: 5px 9px;
  }
  .hb-btn {
    min-height: 40px;
    padding: 0 11px;
    font-size: 11px;
  }
  .hb-nav {
    width: 40px;
    height: 40px;
  }
  .hb-prev {
    left: 6px;
  }
  .hb-next {
    right: 6px;
  }
  .hb-reader-foot {
    padding-top: 8px;
  }
  .hb-hint {
    display: none;
  }
}

@media (max-width: 520px) {
  .hb-btn-label {
    display: none;
  }
  .hb-btn {
    width: 40px;
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hb-sheet.is-anim {
    animation-duration: 1ms;
  }
  .hb-page img {
    transition: none;
  }
}
