/* ===========================================================================
   Modern HTML5 flipbook reader — brand-accented, fliphtml5-style immersive UI.
   Theme is driven by CSS variables so the navy/accent can be tuned in one place.
   =========================================================================== */
:root {
  --fb-bg-1: #20264a;
  --fb-bg-2: #0d1024;
  --fb-accent: #635BFF;
  --fb-accent-soft: rgba(99, 91, 255, 0.35);
  --fb-fg: #e7eaf6;
  --fb-fg-dim: #97a0c2;
  --fb-bar-bg: rgba(13, 16, 36, 0.72);
  --fb-panel-bg: #161a35;
  --fb-page-bg: #ffffff;
  --fb-skel-page: rgba(255, 255, 255, 0.05);
  --fb-skel-border: rgba(255, 255, 255, 0.08);
  --fb-skel-shape: rgba(255, 255, 255, 0.10);
  --fb-skel-sheen: rgba(255, 255, 255, 0.08);
  --fb-skel-track: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, var(--fb-bg-1) 0%, var(--fb-bg-2) 78%);
  color: var(--fb-fg);
  -webkit-user-select: none;
  user-select: none;
}

#fb-app { position: fixed; inset: 0; }

/* ── Stage (book area) ───────────────────────────────────────────────────── */
#fb-stage {
  position: absolute;
  inset: 0 0 64px 0;            /* leave room for the bottom bar */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 64px;
  transition: transform .2s ease;
}
#fb-book { margin: 0 auto; transition: transform .45s ease; }

/* StPageFlip page surface */
.fb-page {
  background: var(--fb-page-bg);
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}
.fb-page .fb-canvas { display: block; width: 100%; height: 100%; }
.fb-page-loading {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: #f3f4f8;
}

/* ── Side arrows ─────────────────────────────────────────────────────────── */
.fb-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
  background: rgba(255, 255, 255, 0.06);
  color: var(--fb-fg);
  border-radius: 50%;
  z-index: 30;
  transition: background .15s, color .15s, opacity .15s;
}
.fb-arrow:hover { background: var(--fb-accent); color: #fff; }
.fb-arrow:disabled { opacity: 0.25; cursor: default; }
.fb-arrow svg { width: 26px; height: 26px; }
.fb-arrow-left { left: 14px; }
.fb-arrow-right { right: 14px; }

/* ── Bottom bar ──────────────────────────────────────────────────────────── */
.fb-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--fb-bar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 40;
}
.fb-bar-left, .fb-bar-right { display: flex; align-items: center; gap: 2px; }
.fb-bar-center {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.fb-btn {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--fb-fg-dim);
  border-radius: 8px;
  transition: color .15s, background .15s;
}
.fb-btn:hover { color: var(--fb-fg); background: rgba(255, 255, 255, 0.07); }
.fb-btn.is-active { color: #fff; background: var(--fb-accent); }
.fb-btn svg { width: 19px; height: 19px; }

/* Page seek slider */
.fb-slider {
  -webkit-appearance: none; appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  cursor: pointer;
  outline: none;
}
.fb-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--fb-accent);
  box-shadow: 0 0 0 4px var(--fb-accent-soft);
  cursor: grab;
}
.fb-slider::-moz-range-thumb {
  width: 15px; height: 15px; border: none; border-radius: 50%;
  background: var(--fb-accent);
  box-shadow: 0 0 0 4px var(--fb-accent-soft);
  cursor: grab;
}
.fb-pageinfo {
  font-size: 12.5px; font-weight: 600; color: var(--fb-fg);
  min-width: 64px; text-align: center; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.fb-logo {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--fb-accent); color: #fff;
  font-weight: 800; font-size: 15px; margin-left: 4px;
  box-shadow: 0 4px 14px var(--fb-accent-soft);
}

/* ── Side panel (thumbnails / contents / search) ───────────────────────────── */
.fb-panel {
  position: fixed;
  top: 0; left: 0; bottom: 56px;
  width: 250px;
  background: var(--fb-panel-bg);
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  z-index: 35;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .25s ease;
}
.fb-panel.is-open { transform: translateX(0); }
.fb-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid rgba(255, 255, 255, 0.07); flex-shrink: 0;
}
.fb-panel-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--fb-fg-dim); font-weight: 700; }
.fb-panel-close { background: none; border: none; color: var(--fb-fg-dim); cursor: pointer; display: flex; padding: 3px; border-radius: 6px; }
.fb-panel-close:hover { color: var(--fb-fg); background: rgba(255, 255, 255, 0.08); }
.fb-panel-close svg { width: 18px; height: 18px; }
.fb-panel-search { padding: 10px 12px; flex-shrink: 0; }
#fb-search-input {
  width: 100%; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--fb-fg); outline: none;
}
#fb-search-input:focus { border-color: var(--fb-accent); }
#fb-search-input::placeholder { color: var(--fb-fg-dim); }
.fb-panel-body { flex: 1; overflow-y: auto; padding: 12px; }
.fb-panel-hint { color: var(--fb-fg-dim); font-size: 12.5px; padding: 8px 4px; }

.fb-thumb {
  position: relative; width: 100%; margin-bottom: 12px; border-radius: 6px;
  overflow: hidden; cursor: pointer; border: 2px solid transparent; background: #fff; line-height: 0;
}
.fb-thumb canvas, .fb-thumb img { width: 100%; display: block; }
.fb-thumb:hover { border-color: var(--fb-accent-soft); }
.fb-thumb.is-current { border-color: var(--fb-accent); }
.fb-thumb-num {
  position: absolute; bottom: 0; right: 0;
  background: rgba(13, 16, 36, 0.85); color: #fff;
  font-size: 10px; font-weight: 600; padding: 1px 6px; border-top-left-radius: 6px; line-height: 1.4;
}

.fb-toc-item { padding: 8px 12px; font-size: 13px; color: var(--fb-fg); cursor: pointer; border-radius: 6px; line-height: 1.35; }
.fb-toc-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.fb-result { padding: 9px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 2px; }
.fb-result:hover { background: rgba(255, 255, 255, 0.08); }
.fb-result-page { display: block; font-size: 11px; font-weight: 700; color: var(--fb-accent); margin-bottom: 2px; }
.fb-result-snip { display: block; font-size: 12px; color: var(--fb-fg-dim); line-height: 1.4; }

/* ── Loading overlay ─────────────────────────────────────────────────────── */
.fb-loading {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0; color: var(--fb-fg-dim);
  background: radial-gradient(ellipse at 50% 30%, var(--fb-bg-1) 0%, var(--fb-bg-2) 78%);
  transition: opacity .5s ease, visibility 0s linear .5s;
}
.fb-loading.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.fb-spin {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--fb-accent);
  animation: fb-spin 0.8s linear infinite;
}
.fb-page-loading .fb-spin { border-top-color: var(--fb-accent); }
@keyframes fb-spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #fb-stage { padding: 14px 10px; inset: 0 0 52px 0; }
  .fb-arrow { width: 38px; height: 38px; }
  .fb-arrow-left { left: 6px; } .fb-arrow-right { right: 6px; }
  .fb-bar { height: 52px; gap: 6px; padding: 0 8px; }
  .fb-btn { width: 34px; height: 34px; }
  /* keep the essentials on small screens */
  .fb-bar-left .fb-hide-sm, .fb-bar-right .fb-hide-sm { display: none; }
  .fb-panel { width: 200px; bottom: 52px; }
}

/* ── Fullscreen ──────────────────────────────────────────────────────────── */
/* Fullscreen targets #fb-app; give it the same backdrop so the area around the
   book isn't a blank void. */
#fb-app:fullscreen,
#fb-app:-webkit-full-screen {
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at 50% 30%, var(--fb-bg-1) 0%, var(--fb-bg-2) 78%);
}

/* ── Light theme ─────────────────────────────────────────────────────────── */
:root.fb-light {
  --fb-bg-1: #eef1f8;
  --fb-bg-2: #d6dcec;
  --fb-fg: #1d2238;
  --fb-fg-dim: #5c688a;
  --fb-bar-bg: rgba(255, 255, 255, 0.82);
  --fb-panel-bg: #ffffff;
  --fb-skel-page: rgba(20, 26, 60, 0.045);
  --fb-skel-border: rgba(20, 26, 60, 0.10);
  --fb-skel-shape: rgba(20, 26, 60, 0.10);
  --fb-skel-sheen: rgba(255, 255, 255, 0.6);
  --fb-skel-track: rgba(20, 26, 60, 0.12);
}
.fb-light .fb-arrow { background: rgba(20, 26, 60, 0.06); }
.fb-light .fb-arrow:hover { background: var(--fb-accent); color: #fff; }
.fb-light .fb-bar { border-top-color: rgba(20, 26, 60, 0.10); }
.fb-light .fb-btn:hover { background: rgba(20, 26, 60, 0.06); }
.fb-light .fb-slider { background: rgba(20, 26, 60, 0.16); }
.fb-light .fb-page { box-shadow: 0 10px 40px rgba(20, 26, 60, 0.18); }
.fb-light .fb-panel { border-right-color: rgba(20, 26, 60, 0.10); }
.fb-light .fb-panel-head { border-bottom-color: rgba(20, 26, 60, 0.10); }
.fb-light #fb-search-input { background: rgba(20, 26, 60, 0.05); border-color: rgba(20, 26, 60, 0.16); }
.fb-light .fb-panel-close:hover,
.fb-light .fb-toc-item:hover,
.fb-light .fb-result:hover { background: rgba(20, 26, 60, 0.06); color: var(--fb-fg); }
.fb-light .fb-spin { border-color: rgba(20, 26, 60, 0.15); border-top-color: var(--fb-accent); }
.fb-light .fb-page-loading { background: #eef1f8; }

/* ── Skeleton loader + progress ──────────────────────────────────────────────── */
.fb-skel {
  display: flex;
  height: clamp(240px, 60vh, 520px);
  filter: drop-shadow(0 26px 60px rgba(0, 0, 0, 0.42));
  animation: fb-skel-in .55s cubic-bezier(.2, .75, .2, 1) both;
}
.fb-skel-page {
  position: relative;
  aspect-ratio: 1 / 1.414;
  height: 100%;
  padding: clamp(14px, 2.6vh, 24px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(8px, 1.4vh, 13px);
  background: var(--fb-skel-page);
  border: 1px solid var(--fb-skel-border);
  overflow: hidden;
}
.fb-skel-page:first-child {
  border-radius: 5px 0 0 5px; border-right: none;
  box-shadow: inset -14px 0 22px -14px rgba(0, 0, 0, 0.3);
}
.fb-skel-page-right {
  border-radius: 0 5px 5px 0;
  box-shadow: inset 14px 0 22px -14px rgba(0, 0, 0, 0.3);
}
/* soft light sweep travelling across each page */
.fb-skel-page::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 38%, var(--fb-skel-sheen) 50%, transparent 62%);
  transform: translateX(-100%);
  animation: fb-sheen 1.7s ease-in-out infinite;
}
.fb-skel-page-right::after { animation-delay: .22s; }

.fb-skel-line { height: 9px; border-radius: 5px; background: var(--fb-skel-shape); }
.fb-skel-line.short { width: 58%; }
.fb-skel-title { height: 16px; width: 66%; margin-bottom: 8px; }
.fb-skel-img {
  height: 26%; min-height: 48px; border-radius: 8px;
  background: var(--fb-skel-shape); margin: 6px 0;
}

.fb-loader-meta {
  margin-top: 34px;
  width: min(280px, 72vw);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  animation: fb-skel-in .55s .08s cubic-bezier(.2, .75, .2, 1) both;
}
.fb-progress-track {
  position: relative; width: 100%; height: 4px;
  border-radius: 999px; background: var(--fb-skel-track); overflow: hidden;
}
.fb-progress-bar {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--fb-accent), #9d97ff);
  box-shadow: 0 0 12px var(--fb-accent-soft);
}
.fb-loader-status {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px; color: var(--fb-fg-dim);
}
#fb-progress-pct {
  font-size: 16px; font-weight: 700; color: var(--fb-fg);
  font-variant-numeric: tabular-nums; min-width: 44px; text-align: right;
}
.fb-loader-label { letter-spacing: .01em; }

/* indeterminate fallback when the server sends no Content-Length */
.fb-loading.fb-indeterminate .fb-progress-bar,
.fb-loading.fb-indeterminate #fb-progress-pct { display: none; }
.fb-loading.fb-indeterminate .fb-progress-track::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--fb-accent), transparent);
  animation: fb-indet 1.2s ease-in-out infinite;
}

@keyframes fb-sheen { to { transform: translateX(100%); } }
@keyframes fb-skel-in { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes fb-indet { 0% { left: -40%; } 100% { left: 100%; } }

@media (max-width: 768px) {
  .fb-skel { height: clamp(220px, 56vh, 460px); }
  .fb-skel-page-right { display: none; }
  .fb-skel-page:first-child {
    border-radius: 5px; border-right: 1px solid var(--fb-skel-border); box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fb-skel, .fb-loader-meta { animation: none; }
  .fb-skel-page::after, .fb-loading.fb-indeterminate .fb-progress-track::after { animation: none; }
}
