/* ═══════════════════════════════════════════════════════════
   BookChoix PDF Flipbook — flipbook.css
   Layout, viewer, 3D flip animation, page spread
═══════════════════════════════════════════════════════════ */

/* ── Design Tokens (inherit BookChoix) ── */
:root {
  --coral:        #E07D5B;
  --coral-dark:   #C95E38;
  --coral-light:  #FEF0EC;
  --navy:         #1C2B4A;
  --navy-mid:     #2A3B5E;
  --navy-dark:    #131929;
  --teal:         #00B5A3;
  --white:        #FFFFFF;
  --warm-bg:      #F8F5F2;
  --body-text:    #444B5A;
  --muted:        #8A8F9D;
  --border:       rgba(28,43,74,0.10);

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'Jost', system-ui, sans-serif;

  --ease-slide:   cubic-bezier(0.4, 0, 0.2, 1); /* material standard — smooth & snappy */
  --ease-out:     cubic-bezier(0.0, 0, 0.2, 1);
  --ease-inout:   cubic-bezier(0.4, 0, 0.2, 1);

  --toolbar-h:    58px;
  --sidebar-w:    288px;
  --flip-dur:     380ms; /* slide lebih cepat dari flip 3D */
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  background: var(--navy-dark);
  color: var(--body-text);
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: var(--font-body); border: none; background: none; }
svg { display: block; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════════════════════ */
#bc-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════
   LOADING SCREEN
═══════════════════════════════════════════════════════════ */
#bc-loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--navy-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  transition: opacity 400ms var(--ease-out), visibility 400ms;
}

#bc-loader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.bc-loader__logo {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
}
.bc-loader__logo em { font-style: italic; color: var(--coral); }

.bc-loader__bar-wrap {
  width: 200px;
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}
.bc-loader__bar {
  height: 100%;
  background: var(--coral);
  border-radius: 2px;
  width: 0%;
  transition: width 200ms var(--ease-out);
}

.bc-loader__text {
  font-size: 13px;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.05em;
}

/* ═══════════════════════════════════════════════════════════
   MAIN LAYOUT (sidebar + content)
═══════════════════════════════════════════════════════════ */
#bc-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ═══════════════════════════════════════════════════════════
   VIEWER STAGE
═══════════════════════════════════════════════════════════ */
#bc-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #1a1f2e;
  /* Subtle dot grid — bookish texture */
  background-image: radial-gradient(circle, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 28px 28px;
  overflow: hidden;
  position: relative;
  transition: background 300ms;
}

/* Stage in grid view mode */
#bc-stage.view-grid {
  align-items: flex-start;
  justify-content: flex-start;
  overflow-y: auto;
}

/* ── Progress bar (bottom of stage) ── */
#bc-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255,255,255,0.06);
  z-index: 10;
}
#bc-progress-fill {
  height: 100%;
  background: var(--coral);
  transition: width 400ms var(--ease-out);
  border-radius: 0 2px 2px 0;
}

/* ═══════════════════════════════════════════════════════════
   FLIPBOOK CONTAINER
═══════════════════════════════════════════════════════════ */
#bc-book-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Ground shadow */
#bc-book-wrap::after {
  content: '';
  position: absolute;
  bottom: -24px;
  left: 8%;
  right: 8%;
  height: 40px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.50) 0%, transparent 70%);
  filter: blur(12px);
  border-radius: 50%;
  pointer-events: none;
}

/* ── The actual book (two-page spread container) ── */
#bc-book {
  position: relative;
  display: flex;
  user-select: none;
  /* Clip overflow so outgoing/incoming pages slide cleanly */
  overflow: hidden;
  border-radius: 4px;
}


/* ═══════════════════════════════════════════════════════════
   PAGE ELEMENTS
   Each "page" is a half — left or right
═══════════════════════════════════════════════════════════ */
.bc-page-slot {
  position: relative;
  overflow: hidden;
  background: #fff;
  /* Shared page dimensions — set by JS */
  flex-shrink: 0;
}

/* Left page slot */
.bc-page-slot--left {
  border-radius: 4px 0 0 4px;
  box-shadow:
    inset -12px 0 28px rgba(0,0,0,0.12),
    inset -2px  0  6px rgba(0,0,0,0.06),
    -6px 0 18px rgba(0,0,0,0.30);
  /* Subtle paper texture via gradient */
  background: linear-gradient(to right, #f9f7f5 0%, #ffffff 100%);
}

/* Right page slot */
.bc-page-slot--right {
  border-radius: 0 4px 4px 0;
  box-shadow:
    inset 12px 0 28px rgba(0,0,0,0.12),
    inset  2px 0  6px rgba(0,0,0,0.06),
    6px 0 18px rgba(0,0,0,0.30);
  background: linear-gradient(to left, #f9f7f5 0%, #ffffff 100%);
}

/* Single page (mobile) */
.bc-page-slot--single {
  border-radius: 4px;
  box-shadow:
    0 10px 40px rgba(0,0,0,0.45),
    0  2px  8px rgba(0,0,0,0.20);
  background: #fff;
}

/* Page canvas / image inside slot */
.bc-page-slot canvas,
.bc-page-slot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Page number label */
.bc-page-label {
  position: absolute;
  bottom: 10px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 2;
  opacity: 0.7;
}
.bc-page-slot--left  .bc-page-label { left: 14px; }
.bc-page-slot--right .bc-page-label { right: 14px; }

/* Spine center line */
#bc-spine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,0.06),
    rgba(0,0,0,0.22) 20%,
    rgba(0,0,0,0.28) 50%,
    rgba(0,0,0,0.22) 80%,
    rgba(0,0,0,0.06)
  );
  pointer-events: none;
  z-index: 5;
}

/* ═══════════════════════════════════════════════════════════
   SLIDE + FADE TRANSITION
   Two layers stacked in #bc-book (overflow:hidden):
   — .bc-page-layer  : the currently VISIBLE spread (underneath)
   — .bc-page-transit: the INCOMING spread (animates on top)
   Direction classes drive translateX + opacity keyframes.
═══════════════════════════════════════════════════════════ */

/* Base layer — always present, holds current pages */
.bc-page-layer {
  position: absolute;
  inset: 0;
  display: flex;
  will-change: opacity, transform;
}

/* Transit layer — injected by JS, removed after animation */
.bc-page-transit {
  position: absolute;
  inset: 0;
  display: flex;
  z-index: 10;
  will-change: opacity, transform;
  pointer-events: none;
}

/* ── Forward (next page): slides in from right ── */
.bc-page-transit.anim-forward {
  animation: transitForward var(--flip-dur) var(--ease-slide) forwards;
}
.bc-page-layer.anim-forward-out {
  animation: layerForwardOut var(--flip-dur) var(--ease-slide) forwards;
}

/* ── Backward (prev page): slides in from left ── */
.bc-page-transit.anim-backward {
  animation: transitBackward var(--flip-dur) var(--ease-slide) forwards;
}
.bc-page-layer.anim-backward-out {
  animation: layerBackwardOut var(--flip-dur) var(--ease-slide) forwards;
}

/* ── Keyframes ── */

/* Incoming spread — forward: enter from right */
@keyframes transitForward {
  0%   { transform: translateX(4%);  opacity: 0; }
  18%  { opacity: 1; }
  100% { transform: translateX(0%);  opacity: 1; }
}

/* Current spread — forward: exit to left */
@keyframes layerForwardOut {
  0%   { transform: translateX(0%);  opacity: 1; }
  30%  { opacity: 0; }
  100% { transform: translateX(-3%); opacity: 0; }
}

/* Incoming spread — backward: enter from left */
@keyframes transitBackward {
  0%   { transform: translateX(-4%); opacity: 0; }
  18%  { opacity: 1; }
  100% { transform: translateX(0%);  opacity: 1; }
}

/* Current spread — backward: exit to right */
@keyframes layerBackwardOut {
  0%   { transform: translateX(0%);  opacity: 1; }
  30%  { opacity: 0; }
  100% { transform: translateX(3%);  opacity: 0; }
}

/* ── Spine overlay on transit layer ── */
.bc-transit-spine {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,0.06),
    rgba(0,0,0,0.22) 20%,
    rgba(0,0,0,0.28) 50%,
    rgba(0,0,0,0.22) 80%,
    rgba(0,0,0,0.06)
  );
  pointer-events: none;
  z-index: 5;
}



/* ═══════════════════════════════════════════════════════════
   CLICK HOTSPOTS (prev/next hit areas on book)
═══════════════════════════════════════════════════════════ */
.bc-hotspot {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22%;
  z-index: 15;
  cursor: pointer;
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity 200ms;
}

#bc-book-wrap:hover .bc-hotspot { opacity: 1; }

.bc-hotspot--prev { left: 0; justify-content: flex-start; padding-left: 12px; }
.bc-hotspot--next { right: 0; justify-content: flex-end; padding-right: 12px; }

.bc-hotspot__btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--navy);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  transition: background 150ms, transform 150ms;
}
.bc-hotspot:hover .bc-hotspot__btn {
  background: var(--coral);
  color: #fff;
  transform: scale(1.08);
}
.bc-hotspot__btn svg { width: 18px; height: 18px; stroke-width: 2.2; }

/* ═══════════════════════════════════════════════════════════
   CONTINUOUS SCROLL MODE
═══════════════════════════════════════════════════════════ */
#bc-continuous {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 32px 24px 80px;
  gap: 0;
  scroll-behavior: smooth;
}

/* Scrollbar */
#bc-continuous::-webkit-scrollbar { width: 6px; }
#bc-continuous::-webkit-scrollbar-track { background: transparent; }
#bc-continuous::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
#bc-continuous::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* Show continuous, hide spread */
#bc-stage.view-continuous #bc-book-wrap  { display: none; }
#bc-stage.view-continuous #bc-progress   { display: none; }
#bc-stage.view-continuous #bc-continuous { display: flex; }

/* Each page item */
.bc-cont-item {
  position: relative;
  flex-shrink: 0;
  background: #fff;
  border-radius: 3px;
  box-shadow:
    0 4px 20px rgba(0,0,0,0.35),
    0 1px  4px rgba(0,0,0,0.20);
  /* page gap — breathing room between pages */
  margin-bottom: 20px;
  overflow: hidden;
  transition: box-shadow 200ms;
}

.bc-cont-item:last-child { margin-bottom: 0; }

/* Subtle highlight on active/visible page */
.bc-cont-item.is-visible {
  box-shadow:
    0 6px 28px rgba(0,0,0,0.40),
    0 0 0 2px rgba(224,125,91,0.35);
}

.bc-cont-item img {
  display: block;
  width: 100%;
  height: auto;
}

/* Page number chip floating bottom-right of each page */
.bc-cont-item__num {
  position: absolute;
  bottom: 10px;
  right: 12px;
  background: rgba(28,43,74,0.65);
  backdrop-filter: blur(4px);
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 10px;
  pointer-events: none;
  font-family: var(--font-body);
}

/* Skeleton placeholder saat page belum dirender */
.bc-cont-item__skeleton {
  width: 100%;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 25%,
    rgba(255,255,255,0.08) 50%,
    rgba(255,255,255,0.04) 75%
  );
  background-size: 200% 100%;
  animation: skelShimmer 1.4s infinite;
}

@keyframes skelShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Back-to-top button */
#bc-cont-top {
  position: fixed;
  bottom: 40px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  border: none;
  z-index: 50;
  transition: background 150ms, transform 150ms, opacity 200ms;
}
#bc-cont-top:hover { background: var(--coral-dark); transform: scale(1.08); }
#bc-cont-top svg { width: 18px; height: 18px; stroke-width: 2.2; }
#bc-stage.view-continuous #bc-cont-top { display: flex; }

#bc-grid {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 20px;
  padding: 32px;
  width: 100%;
  align-content: start;
}

#bc-stage.view-grid #bc-book-wrap { display: none; }
#bc-stage.view-grid #bc-grid     { display: grid; }
#bc-stage.view-grid #bc-progress { display: none; }

.bc-grid-item {
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255,255,255,0.05);
  border: 2px solid transparent;
  transition: border-color 150ms, transform 150ms, box-shadow 150ms;
  display: flex;
  flex-direction: column;
}

.bc-grid-item:hover {
  border-color: var(--coral);
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.35);
}

.bc-grid-item.is-active {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(224,125,91,0.3);
}

.bc-grid-item__canvas {
  width: 100%;
  /* aspect-ratio set dynamically per page via inline style */
  object-fit: cover;
  display: block;
  background: #fff;
}

.bc-grid-item canvas {
  width: 100% !important;
  height: auto !important;
}

.bc-grid-item__label {
  padding: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  text-align: center;
  font-weight: 400;
  letter-spacing: 0.03em;
}

.bc-grid-item.is-active .bc-grid-item__label {
  color: var(--coral);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════
   EMPTY / ERROR STATES
═══════════════════════════════════════════════════════════ */
.bc-state-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: rgba(255,255,255,0.3);
  text-align: center;
  padding: 40px;
}
.bc-state-empty svg { width: 48px; height: 48px; opacity: 0.4; }
.bc-state-empty h3  { font-family: var(--font-display); font-size: 20px; color: rgba(255,255,255,0.5); }
.bc-state-empty p   { font-size: 14px; max-width: 320px; line-height: 1.6; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 100%;
    --toolbar-h: 52px;
  }

  #bc-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    padding: 16px;
  }

  .bc-hotspot { width: 30%; }
  .bc-hotspot__btn { width: 36px; height: 36px; }
}
