/* ==========================================================================
   Flipbook viewer — layout, chrome a page-turn vizuál
   Farby sa dajú prepísať cez ?theme= alebo data-* atribúty na <html>.
   ========================================================================== */

:root {
  --fb-bg-1: #2b2f36;
  --fb-bg-2: #15171b;
  --fb-accent: #c8a456;
  --fb-toolbar-bg: rgba(16, 18, 21, .92);
  --fb-toolbar-fg: #e8e8ea;
  --fb-toolbar-fg-dim: #9aa0a8;
  --fb-toolbar-h: 56px;
  --fb-radius: 10px;
  --fb-panel-bg: rgba(20, 22, 26, .97);
  --fb-shadow-book: 0 30px 70px -12px rgba(0, 0, 0, .75), 0 10px 24px -8px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--fb-bg-2);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--fb-toolbar-fg);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

.fb-app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--fb-bg-1) 0%, var(--fb-bg-2) 70%);
}

/* --- plocha knihy ------------------------------------------------------- */

.fb-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  padding: 26px;
}

/* Obal, ktorý sa posúva a zoomuje.
   Transformácia ide SEM, nie na .stf__parent: page-flip číta offsetWidth
   kontejnera .stf__block a CSS transformácia offsetWidth neovplyvňuje,
   takže sa jeho prepočet geometrie nerozbije. */
.fb-zoom {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
  will-change: transform;
  transition: transform .22s cubic-bezier(.22, .61, .36, 1);
}
.fb-zoom.is-dragging { transition: none; }

/* page-flip si vytvorí vnútri .fb-book štruktúru
   .stf__parent > .stf__wrapper > .stf__block  a z .stf__block číta rozmery,
   do ktorých vpasuje dvojstranu. Preto musia vyplniť celú scénu. */
.fb-book,
.fb-book .stf__wrapper,
.fb-book .stf__block {
  position: relative;
  width: 100%;
  height: 100%;
}

/* --- jedna strana ------------------------------------------------------- */

.fb-page {
  position: relative;
  overflow: hidden;
  background: #fff;
  background-size: cover;
  background-position: center;
  box-shadow: var(--fb-shadow-book);
}

.fb-page canvas,
.fb-page img {
  display: block;
  width: 100%;
  height: 100%;
  /* contain, nie cover: dokument môže obsahovať stranu s iným pomerom strán
     (napr. jednu rozkladaciu na šírku) a cover by jej odrezal obsah. */
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

/* Tieň v hrbe knihy — na ľavej strane sprava, na pravej zľava. */
.fb-page::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 34px;
  pointer-events: none;
  z-index: 2;
}
.fb-page--left::before {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, .22) 0%, rgba(0, 0, 0, .06) 40%, rgba(0, 0, 0, 0) 100%);
}
.fb-page--right::before {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, .22) 0%, rgba(0, 0, 0, .06) 40%, rgba(0, 0, 0, 0) 100%);
}
/* V portrait režime (mobil) hrb neexistuje. */
.fb-is-portrait .fb-page::before { display: none; }

/* Placeholder, kým sa strana nedorenderuje. */
.fb-page__skeleton {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(100deg, #f4f4f5 30%, #eaeaec 50%, #f4f4f5 70%);
  background-size: 220% 100%;
  animation: fb-shimmer 1.3s linear infinite;
  color: #b9b9bf;
  font-size: 12px;
  letter-spacing: .08em;
}
@keyframes fb-shimmer {
  from { background-position: 180% 0; }
  to   { background-position: -80% 0; }
}

/* Obálka dostane o kúsok hlbší tieň a jemný lesk. */
.fb-page--cover::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, rgba(255, 255, 255, .14) 0%, rgba(255, 255, 255, 0) 38%);
  z-index: 3;
}

/* --- bočné strelky ----------------------------------------------------- */

.fb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(18, 20, 24, .62);
  color: #fff;
  cursor: pointer;
  z-index: 20;
  opacity: 0;
  transition: opacity .2s, background .2s, transform .2s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.fb-stage:hover .fb-nav,
.fb-nav:focus-visible { opacity: 1; }
.fb-nav:hover { background: rgba(18, 20, 24, .85); }
.fb-nav[disabled] { opacity: 0 !important; pointer-events: none; }
.fb-nav--prev { left: 14px; }
.fb-nav--next { right: 14px; }
.fb-nav svg { width: 20px; height: 20px; }

/* Na dotykových zariadeniach strelky nechávame viditeľné (nie je hover). */
@media (hover: none) {
  .fb-nav { opacity: .75; width: 40px; height: 40px; }
}

/* --- toolbar ------------------------------------------------------------ */

.fb-toolbar {
  flex: 0 0 auto;
  height: var(--fb-toolbar-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px;
  background: var(--fb-toolbar-bg);
  border-top: 1px solid rgba(255, 255, 255, .07);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 30;
  user-select: none;
}

.fb-toolbar__spacer { flex: 1 1 auto; }

/* Poistka: ak sa toolbar aj tak nezmestí (úzky iframe, veľké systémové písmo),
   nech sa dá posunúť, namiesto aby tlačidlá vypadli mimo obraz. */
.fb-toolbar { overflow-x: auto; scrollbar-width: none; }
.fb-toolbar::-webkit-scrollbar { display: none; }

.fb-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--fb-toolbar-fg);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, color .15s, opacity .15s;
}
.fb-btn:hover { background: rgba(255, 255, 255, .09); }
.fb-btn:active { background: rgba(255, 255, 255, .14); }
.fb-btn[disabled] { opacity: .32; pointer-events: none; }
.fb-btn.is-active { background: rgba(255, 255, 255, .14); color: var(--fb-accent); }
.fb-btn svg { width: 19px; height: 19px; }

.fb-counter {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  font-variant-numeric: tabular-nums;
  color: var(--fb-toolbar-fg-dim);
  white-space: nowrap;
}
.fb-counter input {
  width: 46px;
  height: 30px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 6px;
  background: rgba(255, 255, 255, .06);
  color: var(--fb-toolbar-fg);
  text-align: center;
  font: inherit;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.fb-counter input::-webkit-outer-spin-button,
.fb-counter input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.fb-counter input:focus {
  outline: none;
  border-color: var(--fb-accent);
  background: rgba(255, 255, 255, .1);
}

.fb-title {
  flex: 0 1 auto;
  min-width: 0;
  padding: 0 10px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--fb-toolbar-fg);
}

/* --- panel s náhľadmi --------------------------------------------------- */

.fb-thumbs {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 186px;
  padding: 14px 14px 16px;
  background: var(--fb-panel-bg);
  border-top: 1px solid rgba(255, 255, 255, .08);
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  z-index: 25;
  transform: translateY(102%);
  transition: transform .26s cubic-bezier(.22, .61, .36, 1);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  scrollbar-width: thin;
}
.fb-thumbs.is-open { transform: translateY(0); }

.fb-thumb {
  display: inline-block;
  width: 96px;
  margin-right: 10px;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  vertical-align: top;
  text-align: center;
}
.fb-thumb__frame {
  position: relative;
  width: 100%;
  background: #fff;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color .15s, transform .15s;
}
.fb-thumb:hover .fb-thumb__frame { transform: translateY(-2px); }
.fb-thumb.is-current .fb-thumb__frame { outline-color: var(--fb-accent); }
.fb-thumb__frame img,
.fb-thumb__frame canvas { display: block; width: 100%; height: auto; }
.fb-thumb__n {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--fb-toolbar-fg-dim);
  font-variant-numeric: tabular-nums;
}
.fb-thumb.is-current .fb-thumb__n { color: var(--fb-accent); }

/* --- loader ------------------------------------------------------------- */

.fb-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 16px;
  grid-auto-flow: row;
  background: var(--fb-bg-2);
  z-index: 60;
  transition: opacity .3s;
}
.fb-loader.is-hidden { opacity: 0; pointer-events: none; }
.fb-loader__ring {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, .16);
  border-top-color: var(--fb-accent);
  border-radius: 50%;
  animation: fb-spin .8s linear infinite;
}
@keyframes fb-spin { to { transform: rotate(360deg); } }
.fb-loader__text {
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--fb-toolbar-fg-dim);
  font-variant-numeric: tabular-nums;
}

/* --- chybový stav ------------------------------------------------------- */

.fb-error {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 32px;
  text-align: center;
  background: var(--fb-bg-2);
  z-index: 70;
}
.fb-error.is-shown { display: grid; }
.fb-error__box { max-width: 380px; }
.fb-error h2 { margin: 0 0 8px; font-size: 16px; }
.fb-error p { margin: 0; color: var(--fb-toolbar-fg-dim); font-size: 13px; word-break: break-word; }

/* --- mobil -------------------------------------------------------------- */

@media (max-width: 640px) {
  :root { --fb-toolbar-h: 52px; }
  .fb-stage { padding: 10px; }

  /* Na mobile necháme len to, čo sa prstom naozaj používa.
     Skok na prvú/poslednú stranu nahrádza pás náhľadov,
     priblíženie sa robí štipcom alebo dvojklikom. */
  #fb-tb-first,
  #fb-tb-last,
  #fb-tb-zoomin,
  #fb-tb-zoomout,
  #fb-tb-share { display: none; }
  .fb-title { display: none; }
  .fb-btn { width: 36px; height: 36px; }
  .fb-thumbs { max-height: 150px; padding: 10px 10px 12px; }
  .fb-thumb { width: 74px; }
  .fb-nav--prev { left: 6px; }
  .fb-nav--next { right: 6px; }
}

/* Veľmi nízke okná (napr. iframe 320px vysoký) — toolbar zoštíhlime. */
@media (max-height: 420px) {
  :root { --fb-toolbar-h: 46px; }
  .fb-stage { padding: 8px; }
  .fb-btn { width: 34px; height: 34px; }
}

/* Skrytie prvkov podľa konfigurácie (?download=0 atď.) */
.fb-hidden { display: none !important; }

/* Rešpektuj redukované animácie. */
@media (prefers-reduced-motion: reduce) {
  .fb-zoom, .fb-thumbs { transition: none; }
  .fb-page__skeleton { animation: none; }
}
