[hidden] { display: none !important; }

* { box-sizing: border-box; }

:root {
  --toolbar-height: 58px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --cover-shift: 0px;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #202124;
  font-family: Arial, Helvetica, sans-serif;
}

body {
  position: relative;
}

/*
 * IMPORTANTE PARA IFRAME:
 * usamos 100% da altura real do documento/iframe, e não 100dvh.
 * Isso evita diferenças de viewport em navegadores mobile e iframes.
 */
.viewer-shell,
.viewer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.book-stage {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--toolbar-height);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overscroll-behavior: none;
}

.book-positioner,
.book-zoom {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-positioner {
  transition: transform .22s ease;
}

/* Com showCover=true a capa ocupa metade do spread desktop. */
.book-positioner.cover-centered {
  transform: translateX(var(--cover-shift));
}

.book-zoom {
  transform-origin: center center;
  transition: transform .18s ease;
  will-change: transform;
}

.book-zoom.is-zoomed {
  transition: none;
  touch-action: none;
}

.book-zoom.is-zoomed .book { cursor: grab; }
.book-zoom.is-dragging .book { cursor: grabbing; }
.book-zoom.is-dragging { user-select: none; }

.book {
  margin: 0 auto;
}

.page {
  background: #fff;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.page canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.page-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #777;
  font-size: 14px;
  background: #f4f4f4;
}

.page.rendered .page-placeholder { display: none; }

.status {
  position: absolute;
  z-index: 10000;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  padding: 24px;
  text-align: center;
  line-height: 1.45;
}

.status.error { background: #7d1f1f; }

/* Barra presa ao fundo REAL do iframe. */
.toolbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  min-height: 58px;
  padding: 9px 12px calc(9px + var(--safe-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 8px;
  color: #fff;
  background: rgba(24, 25, 27, .98);
  border-top: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 -4px 18px rgba(0,0,0,.28);
  user-select: none;
  overflow: hidden;
}

.toolbar button {
  flex: 0 0 auto;
  border: 0;
  border-radius: 7px;
  background: #fff;
  color: #222;
  min-width: 42px;
  height: 38px;
  cursor: pointer;
  font-size: 22px;
  padding: 0 12px;
  touch-action: manipulation;
}

.toolbar button:hover:not(:disabled) { filter: brightness(.92); }
.toolbar button:disabled { opacity: .45; cursor: default; }
.toolbar .fullscreen-btn,
.toolbar .embed-btn,
.toolbar .icon-btn {
  min-width: 42px;
  width: 42px;
  padding: 0;
  display: grid;
  place-items: center;
}
.toolbar .zoom-reset { font-size: 13px; min-width: 62px; }
.toolbar-icon {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.toolbar-separator {
  flex: 0 0 auto;
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,.25);
  margin: 0 2px;
}
#pageInfo {
  flex: 0 0 auto;
  min-width: 76px;
  text-align: center;
  font-size: 14px;
}

@media (max-width: 700px) {
  :root { --toolbar-height: 52px; }

  .book-stage { padding: 6px 5px; }

  /* Uma página por vez no mobile; sem deslocamento da capa. */
  .book-positioner.cover-centered { transform: none; }

  .toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: 52px;
    height: calc(52px + var(--safe-bottom));
    padding: 7px 6px calc(7px + var(--safe-bottom));
    display: grid;
    grid-template-columns: 32px minmax(44px, 1fr) 32px 32px 46px 32px 38px 36px;
    align-items: center;
    justify-content: stretch;
    gap: 4px;
    width: 100%;
    max-width: 100%;
  }

  .toolbar button {
    width: 100%;
    min-width: 0;
    height: 34px;
    padding: 0 4px;
    border-radius: 6px;
    font-size: 20px;
  }

  #pageInfo {
    min-width: 0;
    width: 100%;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .toolbar .zoom-reset {
    min-width: 0;
    width: 100%;
    font-size: 11px;
    padding: 0 2px;
  }

  .toolbar .embed-btn,
  .toolbar .fullscreen-btn,
  .toolbar .icon-btn {
    min-width: 0;
    width: 100%;
    padding: 0;
  }

  .toolbar-icon {
    width: 18px;
    height: 18px;
  }

  .toolbar-separator { display: none; }
}

@media (max-width: 360px) {
  .toolbar {
    grid-template-columns: 30px minmax(40px, 1fr) 30px 30px 43px 30px 35px 34px;
    gap: 3px;
    padding-left: 4px;
    padding-right: 4px;
  }

  .toolbar button { height: 32px; }
  #pageInfo { font-size: 11px; }
}


/* Modal do código de incorporação */
.embed-modal {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0,0,0,.68);
}

.embed-box {
  width: min(680px, 100%);
  max-height: calc(100% - 20px);
  overflow: auto;
  border-radius: 10px;
  padding: 18px;
  color: #202124;
  background: #fff;
  box-shadow: 0 14px 50px rgba(0,0,0,.45);
}

.embed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.embed-header strong { font-size: 18px; }
.embed-box p { margin: 12px 0; font-size: 14px; line-height: 1.4; }

.embed-close {
  border: 0;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

#embedCode {
  display: block;
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid #c9cdd2;
  border-radius: 7px;
  padding: 10px;
  font: 13px/1.45 Consolas, Monaco, monospace;
  color: #202124;
  background: #f7f8f9;
}

.embed-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

#embedCopy {
  border: 0;
  border-radius: 7px;
  padding: 10px 16px;
  cursor: pointer;
  background: #202124;
  color: #fff;
  font-weight: 700;
}

#embedFeedback {
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 420px) {
  .embed-modal { padding: 10px; }
  .embed-box { padding: 14px; }
  #embedCode { min-height: 150px; font-size: 12px; }
}
