/* ============================================================
   FLIPBOOK — stilovi
   Boje se podešavaju u config.php (accent, background)
   ============================================================ */
:root {
  --fb-accent: #079A3C;
  --fb-bg: #1F2326;
  --fb-fg: #F2F4F3;
  --fb-muted: rgba(242, 244, 243, .62);
  --fb-line: rgba(255, 255, 255, .10);
  --fb-glass: rgba(20, 23, 25, .72);
  --fb-radius: 12px;
  --fb-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--fb-bg); }
body { font-family: var(--fb-font); color: var(--fb-fg); -webkit-font-smoothing: antialiased; overflow: hidden; }

.fb {
  position: relative;
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  grid-template-columns: minmax(0, 1fr);
  background:
    radial-gradient(ellipse 70% 60% at 50% 45%, rgba(255,255,255,.075), transparent 70%),
    var(--fb-bg);
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- gornja traka ---------- */
.fb-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--fb-line);
  z-index: 5;
}
.fb-brand { min-width: 0; flex: 1 1 auto; display: flex; align-items: center; }
.fb-brand img { height: 30px; width: auto; display: block; }
.fb-brand span { min-width: 0; font-weight: 650; font-size: 15px; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fb-tools { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- dugmad ---------- */
.fb-btn {
  appearance: none; border: 1px solid var(--fb-line); background: rgba(255,255,255,.04);
  color: var(--fb-fg); height: 40px; min-width: 40px; padding: 0 10px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 13px var(--fb-font); cursor: pointer;
  transition: background .18s, border-color .18s, transform .12s, opacity .18s;
  -webkit-tap-highlight-color: transparent;
}
.fb-btn:hover { background: rgba(255,255,255,.10); border-color: rgba(255,255,255,.18); }
.fb-btn:active { transform: scale(.95); }
.fb-btn:focus-visible, .fb-nav:focus-visible { outline: 2px solid var(--fb-accent); outline-offset: 2px; }
.fb-btn[disabled] { opacity: .35; pointer-events: none; }
.fb-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.fb-btn--ghost { border-color: transparent; background: transparent; }
.fb-btn--accent { background: var(--fb-accent); border-color: var(--fb-accent); color: #fff; }
.fb-btn--accent:hover { background: var(--fb-accent); filter: brightness(1.1); border-color: var(--fb-accent); }
.fb-btn[aria-pressed="true"] { color: #fff; }

/* zvuk on/off, fullscreen in/out */
.fb-btn .fb-mute { display: none; }
.fb-btn[aria-pressed="false"] .fb-wave { display: none; }
.fb-btn[aria-pressed="false"] .fb-mute { display: inline; }
.fb-btn .fb-exit { display: none; }
.fb.is-fullscreen .fb-btn .fb-enter { display: none; }
.fb.is-fullscreen .fb-btn .fb-exit { display: inline; }

/* ---------- pozornica i knjiga ---------- */
.fb-stage { position: relative; min-height: 0; overflow: hidden; touch-action: pan-y; }
.fb-book {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%) translateX(var(--fb-shift, 0px));
  transition: transform .55s cubic-bezier(.22, .8, .25, 1), opacity .4s;
  filter: drop-shadow(0 22px 38px rgba(0,0,0,.45)) drop-shadow(0 4px 10px rgba(0,0,0,.25));
  opacity: 0;
}
.fb.is-ready .fb-book { opacity: 1; }
.fb-book > div { width: 100%; height: 100%; }

.fb-page { background: #fff; overflow: hidden; user-select: none; -webkit-user-select: none; }
.fb-page img {
  width: 100%; height: 100%; display: block; object-fit: fill;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
  position: relative; z-index: 1;
  opacity: 0; transition: opacity .35s;
}
.fb-page img.is-loaded { opacity: 1; }
.fb-page::before { /* skeleton dok se stranica renderuje */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, #eef0ef 30%, #f8f9f8 50%, #eef0ef 70%) 0 0 / 300% 100%;
  animation: fb-shimmer 1.4s linear infinite;
}
.fb-page.is-loaded::before { display: none; }
/* sjena hrbata (pregib u sredini) — samo u prikazu dvije stranice */
.fb-page::after { content: ""; position: absolute; top: 0; bottom: 0; width: 9%; pointer-events: none; z-index: 2; }
.fb.is-double .fb-page.--left::after  { right: 0; background: linear-gradient(to left,  rgba(0,0,0,.20), rgba(0,0,0,.05) 35%, transparent); }
.fb.is-double .fb-page.--right::after { left: 0;  background: linear-gradient(to right, rgba(0,0,0,.20), rgba(0,0,0,.05) 35%, transparent); }
.fb-page[data-density="hard"]::after { display: none; }

@keyframes fb-shimmer { to { background-position: -300% 0; } }

/* bočne strelice */
.fb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 3;
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--fb-line); background: var(--fb-glass); color: var(--fb-fg);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: grid; place-items: center; cursor: pointer;
  transition: background .2s, opacity .25s, transform .15s;
}
.fb-nav:hover { background: var(--fb-accent); border-color: var(--fb-accent); }
.fb-nav:active { transform: translateY(-50%) scale(.93); }
.fb-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fb-nav--prev { left: clamp(10px, 2vw, 28px); }
.fb-nav--next { right: clamp(10px, 2vw, 28px); }
.fb-nav[disabled] { opacity: 0; pointer-events: none; }

/* loader */
.fb-loader {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 16px;
  transition: opacity .4s; z-index: 4;
}
.fb.is-ready .fb-loader { opacity: 0; pointer-events: none; }
.fb-loader__book { position: relative; width: 56px; height: 40px; perspective: 200px; }
.fb-loader__book i {
  position: absolute; right: 0; top: 0; width: 50%; height: 100%;
  background: var(--fb-fg); border-radius: 0 3px 3px 0; transform-origin: left center;
  animation: fb-flip 1.5s ease-in-out infinite;
}
.fb-loader__book::before { content: ""; position: absolute; left: 0; top: 0; width: 50%; height: 100%; background: rgba(255,255,255,.35); border-radius: 3px 0 0 3px; }
.fb-loader__book i:nth-child(2) { animation-delay: .18s; opacity: .8; }
.fb-loader__book i:nth-child(3) { animation-delay: .36s; opacity: .6; background: var(--fb-accent); }
@keyframes fb-flip { 0%, 15% { transform: rotateY(0); } 60%, 100% { transform: rotateY(-180deg); } }
.fb-loader__txt { font-size: 13px; color: var(--fb-muted); }
.fb-loader__bar { width: 180px; height: 3px; border-radius: 3px; background: var(--fb-line); overflow: hidden; }
.fb-loader__bar b { display: block; height: 100%; width: 0; background: var(--fb-accent); transition: width .25s; }

.fb-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  padding: 7px 14px; border-radius: 99px; background: var(--fb-glass); border: 1px solid var(--fb-line);
  font-size: 12px; color: var(--fb-muted); white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity .5s; z-index: 3;
}
.fb-hint.is-on { opacity: 1; }

/* ---------- donja navigacija ---------- */
.fb-bar {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 8px clamp(10px, 3vw, 28px);
  border-top: 1px solid var(--fb-line);
}
.fb-pager { display: flex; align-items: center; gap: 14px; flex: 0 1 460px; min-width: 0; margin: 0 8px; }
.fb-count { font-size: 13px; color: var(--fb-muted); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 62px; text-align: right; }
.fb-count b { color: var(--fb-fg); font-weight: 650; }
.fb-pager input[type=range] {
  flex: 1; min-width: 60px; appearance: none; -webkit-appearance: none; height: 4px; border-radius: 4px; cursor: pointer;
  background: linear-gradient(var(--fb-accent), var(--fb-accent)) 0 / var(--fb-prog, 0%) 100% no-repeat, rgba(255,255,255,.14);
}
.fb-pager input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 3px solid var(--fb-accent); }
.fb-pager input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--fb-accent); }

/* ---------- napomena na dnu ---------- */
.fb-note {
  padding: 10px clamp(14px, 3vw, 28px);
  font-size: 13px; line-height: 1.5; color: var(--fb-muted); text-align: center;
  background: rgba(0,0,0,.22); border-top: 1px solid var(--fb-line);
}
.fb-note strong, .fb-note b { color: var(--fb-fg); font-weight: 600; }
.fb-note a { color: #fff; }

/* ---------- panel sa svim stranicama ---------- */
.fb-thumbs {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(380px, 88vw); z-index: 20;
  background: #171a1c; border-left: 1px solid var(--fb-line);
  transform: translateX(100%); transition: transform .35s cubic-bezier(.22, .8, .25, 1);
  display: flex; flex-direction: column;
}
.fb.thumbs-open .fb-thumbs { transform: none; }
.fb-thumbs__head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--fb-line); font-weight: 650; font-size: 14px; }
.fb-thumbs__grid { overflow-y: auto; padding: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; overscroll-behavior: contain; }
.fb-thumb { appearance: none; border: 0; background: none; padding: 0; cursor: pointer; color: var(--fb-muted); font: 500 12px var(--fb-font); text-align: center; }
.fb-thumb__img { display: block; width: 100%; background: #e9ecea; border-radius: 4px; overflow: hidden; outline: 2px solid transparent; outline-offset: 3px; transition: outline-color .2s, transform .2s; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.fb-thumb__img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.fb-thumb span { display: block; margin-top: 7px; }
.fb-thumb:hover .fb-thumb__img { transform: translateY(-2px); }
.fb-thumb.is-active .fb-thumb__img { outline-color: var(--fb-accent); }
.fb-thumb.is-active span { color: var(--fb-fg); }

.fb-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 15; }
.fb.thumbs-open .fb-scrim { opacity: 1; pointer-events: auto; }

/* ---------- uvećanje ---------- */
.fb-zoom { position: absolute; inset: 0; z-index: 30; background: rgba(14,16,17,.97); display: none; flex-direction: column; }
.fb.zoom-open .fb-zoom { display: flex; }
.fb-zoom__bar { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--fb-line); font-size: 13px; font-variant-numeric: tabular-nums; }
.fb-zoom__bar span { min-width: 52px; text-align: center; color: var(--fb-muted); }
.fb-zoom__bar .fb-btn:last-child { margin-left: 16px; }
.fb-zoom__scroll { flex: 1; overflow: auto; cursor: grab; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.fb-zoom__scroll.is-drag { cursor: grabbing; }
.fb-zoom__pages { display: flex; justify-content: center; gap: 2px; padding: 24px; width: max-content; min-width: 100%; margin: 0 auto; }
.fb-zoom__pages img { display: block; background: #fff; box-shadow: 0 10px 40px rgba(0,0,0,.5); user-select: none; -webkit-user-drag: none; }

/* ---------- prilagođavanje ---------- */
@media (max-width: 760px) {
  .fb-lbl { display: none; }
  .fb-nav { display: none; }
  .fb-btn { height: 38px; min-width: 38px; padding: 0 8px; }
  .fb-tools { gap: 4px; }
  .fb-note { font-size: 12px; padding: 8px 14px; }
  .fb-pager { gap: 10px; margin: 0 4px; }
  .fb-zoom__pages { padding: 12px; flex-direction: column; align-items: center; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .fb-note { display: none; }
  .fb-top, .fb-bar { padding-top: 6px; padding-bottom: 6px; }
}
@media (hover: none) { .fb-btn:hover { background: rgba(255,255,255,.04); } .fb-btn--accent:hover { background: var(--fb-accent); } }
@media (prefers-reduced-motion: reduce) { .fb-book, .fb-thumbs { transition: none; } }
