/*
 * GRIHA flipbook viewer (Shashwat magazine).
 * Page-turn effect: StPageFlip (MIT), see page-flip.LICENSE.txt.
 * Copied into each issue folder (sites/default/files/shashwat/<slug>/viewer/)
 * by scripts/shashwat-flipbook/build.sh; each folder is self-contained.
 */

:root {
  --fb-navy: #112d4e;
  --fb-slate: #3f5874;
  --fb-slate-2: #5a7a94;
  --fb-mist: #bcccdc;
  --fb-ink: #ffffff;
  --fb-bar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #16263a;
  color: var(--fb-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#fb-app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at center, #2c4561 0%, #16263a 70%);
}

/* ---------- Top bar ---------- */
.fb-top {
  flex: 0 0 auto;
  height: var(--fb-bar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--fb-navy);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.fb-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-family: Merriweather, Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fb-title small {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-weight: 400;
  color: var(--fb-mist);
  margin-left: 8px;
  font-size: 13px;
}

/* ---------- Stage ---------- */
.fb-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: 20px 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fb-book-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}
.fb-book { width: 100%; height: 100%; }
/* The library sets min-width/height inline from its settings; flipbook.js
   uses a huge minWidth only to force one-page mode, so neutralise it. */
.fb-book.stf__parent { min-width: 0 !important; min-height: 0 !important; }
.fb-book .stf__wrapper { width: 100%; height: 100%; }

.fb-page {
  background: #fff;
  overflow: hidden;
}
.fb-page img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.25s ease;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.fb-page.is-loaded img,
.fb-page.has-preview img.fb-preview { opacity: 1; }
/* The thumbnail, stretched to the page: a soft preview until the page loads. */
.fb-page img.fb-preview { transition: none; }
.fb-page.is-loaded img.fb-preview { display: none; }
.fb-page::before {
  /* Spinner, only until either the preview or the full page is there. */
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid #d6e0ea;
  border-top-color: var(--fb-slate);
  border-radius: 50%;
  animation: fb-spin 0.8s linear infinite;
}
.fb-page.is-loaded::before,
.fb-page.has-preview::before { display: none; }
@keyframes fb-spin { to { transform: rotate(360deg); } }

.fb-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, opacity 0.2s;
  z-index: 5;
}
.fb-arrow:hover { background: rgba(255, 255, 255, 0.25); }
.fb-arrow[disabled] { opacity: 0.25; cursor: default; }
.fb-arrow--prev { left: 10px; }
.fb-arrow--next { right: 10px; }

.fb-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fb-mist);
  font-size: 14px;
}

/* ---------- Thumbnails drawer ---------- */
.fb-thumbs {
  flex: 0 0 auto;
  display: none;
  gap: 10px;
  padding: 12px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  background: rgba(17, 45, 78, 0.92);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  scrollbar-width: thin;
  scrollbar-color: var(--fb-slate-2) transparent;
}
.fb-thumbs.is-open { display: flex; }
.fb-thumb {
  flex: 0 0 auto;
  width: 76px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 3px;
  background: none;
  color: var(--fb-mist);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  text-align: center;
}
.fb-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: var(--fb-ratio, 0.762);
  object-fit: cover;
  background: #2c4561;
}
.fb-thumb span { display: block; padding-top: 3px; }
.fb-thumb:hover { border-color: rgba(255, 255, 255, 0.35); }
.fb-thumb.is-current { border-color: #fff; color: #fff; }

/* ---------- Bottom toolbar ---------- */
.fb-bar {
  flex: 0 0 auto;
  min-height: var(--fb-bar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--fb-navy);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.fb-sep {
  width: 1px;
  height: 24px;
  margin: 0 8px;
  background: rgba(255, 255, 255, 0.18);
}

.fb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 40px;
  height: 40px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}
.fb-btn:hover { background: rgba(255, 255, 255, 0.12); }
.fb-btn[disabled] { opacity: 0.35; cursor: default; background: transparent; }
.fb-btn.is-active { background: rgba(255, 255, 255, 0.18); }
.fb-btn svg { width: 20px; height: 20px; flex: 0 0 auto; }
.fb-btn:focus-visible, .fb-arrow:focus-visible, .fb-thumb:focus-visible, .fb-pageinput:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.fb-btn--primary {
  padding: 0 14px;
  background: linear-gradient(135deg, var(--fb-slate), var(--fb-slate-2));
}
.fb-btn--primary:hover { background: linear-gradient(135deg, #2f4660, var(--fb-slate)); }

.fb-pager {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 6px;
  font-size: 14px;
  color: var(--fb-mist);
  white-space: nowrap;
}
.fb-pageinput {
  width: 84px;
  height: 32px;
  padding: 0 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: inherit;
  text-align: center;
}

/* ---------- Zoom overlay ---------- */
.fb-zoom {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  flex-direction: column;
  background: rgba(10, 20, 32, 0.97);
}
.fb-zoom.is-open { display: flex; }
.fb-zoom-bar {
  flex: 0 0 auto;
  height: var(--fb-bar-h);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 0 12px;
  background: var(--fb-navy);
}
.fb-zoom-bar .fb-zoom-label {
  margin-right: auto;
  padding-left: 4px;
  color: var(--fb-mist);
  font-size: 14px;
}
.fb-zoom-scroll {
  flex: 1 1 auto;
  overflow: auto;
  cursor: grab;
  -webkit-overflow-scrolling: touch;
}
.fb-zoom-scroll.is-dragging { cursor: grabbing; }
.fb-zoom-inner {
  display: flex;
  justify-content: center;
  gap: 0;
  width: max-content;
  min-width: 100%;
  padding: 16px;
  margin: 0 auto;
}
.fb-zoom-inner img {
  display: block;
  height: calc((100vh - var(--fb-bar-h) - 32px) * var(--fb-z, 1));
  width: auto;
  background: #fff;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- Small screens ---------- */
.fb-hide-sm { }
@media (max-width: 720px) {
  .fb-stage { padding: 10px 8px; }
  .fb-arrow { display: none; }
  .fb-title { font-size: 14px; }
  .fb-title small { display: none; }
  .fb-hide-sm { display: none !important; }
  .fb-sep { margin: 0 2px; }
  .fb-btn { min-width: 36px; padding: 0 6px; }
  .fb-btn--primary .fb-btn-text { display: none; }
  .fb-pageinput { width: 54px; }
  .fb-bar { gap: 0; padding: 6px 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .fb-page::before { animation-duration: 2s; }
}
