/* ─── AT Developers — Flipbook Viewer · Tema claro ─── */

.atfb-viewer {
  position: relative;
  background: #F5F0E8;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(123,158,171,0.12), 0 0 0 1px rgba(123,158,171,0.12);
  max-width: 1120px;
  margin: 40px auto 0;
  user-select: none;
}

/* ── Top controls bar — oculta por defecto ── */
.atfb-controls-top {
  display: none;
}

.atfb-controls-left,
.atfb-controls-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.atfb-btn {
  background: rgba(28,43,53,0.05);
  border: 1px solid rgba(123,158,171,0.2);
  border-radius: 6px;
  color: rgba(28,43,53,0.55);
  padding: 7px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: Inter, sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.atfb-btn:hover {
  background: rgba(123,158,171,0.12);
  color: #5C7E8C;
  border-color: rgba(123,158,171,0.35);
}

.atfb-btn svg { flex-shrink: 0; stroke: currentColor; }

.atfb-zoom-level {
  font-family: Inter, sans-serif;
  font-size: 11px;
  color: rgba(28,43,53,0.35);
  min-width: 34px;
  text-align: center;
  padding: 0 2px;
}

/* ── Canvas wrap ── */
.atfb-canvas-wrap {
  position: relative;
  background: #FDFCF8;
  min-height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: default;
  padding: 28px 56px;
}

.atfb-canvas-wrap.is-zoomed   { cursor: grab; }
.atfb-canvas-wrap.is-dragging { cursor: grabbing; }

/* ── Book wrap — aspect-ratio set by JS from first image; fallback = Zapiola A4 ── */
.atfb-book-wrap {
  position: relative;
  width: 100%;
  max-width: 1060px;
  aspect-ratio: var(--atfb-aspect-ratio, 1985 / 1404);
  border-radius: 2px;
  box-shadow:
    0 4px 32px rgba(0,0,0,0.13),
    0 1px 4px  rgba(0,0,0,0.08),
    0 0 0 1px  rgba(0,0,0,0.05);
  overflow: hidden;
  transform-origin: center center;
  transition: transform 0.2s ease;
}

/* ── Flip stack — parent of all pages ── */
.atfb-flipstack {
  position: absolute;
  inset: 0;
  /* perspective here creates 3D depth for all rotateY children */
  perspective: 1800px;
  perspective-origin: center center;
}

/* ── Individual pages ── */
.atfb-page {
  position: absolute;
  inset: 0;
  display: none;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.atfb-page.is-active {
  display: block;
  z-index: 1;
}

.atfb-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill; /* ratio set dynamically by JS — fills without distortion */
  pointer-events: none;
  -webkit-user-drag: none;
  image-rendering: -webkit-optimize-contrast; /* sharpens text on WebKit/Safari */
}

/* ── Page transitions — crossfade limpio ── */

.atfb-page.atfb-flip-out-next,
.atfb-page.atfb-flip-out-prev {
  display: block;
  z-index: 3;
  animation: atfb-fade-out 0.22s ease-out forwards;
}

.atfb-page.atfb-flip-in-next,
.atfb-page.atfb-flip-in-prev {
  display: block;
  z-index: 4;
  animation: atfb-fade-in 0.22s ease-in forwards;
}

@keyframes atfb-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

@keyframes atfb-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Navigation arrows ── */
.atfb-nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(245,240,232,0.92);
  border: 1px solid rgba(123,158,171,0.2);
  color: rgba(28,43,53,0.7);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  transition: background 0.2s, border-color 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.atfb-nav-arrow:hover {
  background: rgba(123,158,171,0.18);
  border-color: rgba(123,158,171,0.4);
  color: #1C2B35;
}

.atfb-nav-arrow.prev { left: 8px; }
.atfb-nav-arrow.next { right: 8px; }

/* Pan overlay (blocks flip events when zoomed) */
.atfb-pan-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  cursor: grab;
}

.atfb-pan-overlay.active   { display: block; }
.atfb-pan-overlay.dragging { cursor: grabbing; }

/* ── Loading state ── */
.atfb-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #FDFCF8;
  z-index: 20;
  gap: 16px;
  transition: opacity 0.3s;
}

.atfb-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.atfb-loading-text {
  font-family: Inter, sans-serif;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: rgba(28,43,53,0.4);
  text-transform: uppercase;
}

.atfb-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(123,158,171,0.2);
  border-top-color: #7B9EAB;
  border-radius: 50%;
  animation: atfb-spin 0.75s linear infinite;
}

@keyframes atfb-spin { to { transform: rotate(360deg); } }

/* ── Bottom controls bar ── */
.atfb-controls-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(245,240,232,0.85);
  border-top: 1px solid rgba(123,158,171,0.12);
}

.atfb-progress-btn {
  background: none;
  border: none;
  color: rgba(28,43,53,0.4);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s;
  flex-shrink: 0;
}

.atfb-progress-btn:hover { color: #5C7E8C; }

.atfb-progress-track {
  flex: 1;
  position: relative;
  height: 3px;
  background: rgba(123,158,171,0.15);
  border-radius: 2px;
  cursor: pointer;
}

.atfb-progress-fill {
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  background: #7B9EAB;
  border-radius: 2px;
  pointer-events: none;
  transition: width 0.25s ease;
}

.atfb-progress-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  background: #7B9EAB;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 3px rgba(123,158,171,0.18);
  transition: left 0.25s ease;
}

.atfb-page-counter {
  font-family: Inter, sans-serif;
  font-size: 11px;
  color: rgba(28,43,53,0.35);
  white-space: nowrap;
  min-width: 44px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Mobile CTA ── */
.atfb-mobile-cta { display: none; }

/* ── Close button — only visible in fullscreen ── */
.atfb-close-fs-btn {
  display: none;
}

.atfb-viewer.is-fullscreen .atfb-close-fs-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 10001;
  width: 48px;
  height: 48px;
  background: rgba(28,43,53,0.72);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 50%;
  color: rgba(255,255,255,0.95);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.2s;
}

.atfb-viewer.is-fullscreen .atfb-close-fs-btn:hover,
.atfb-viewer.is-fullscreen .atfb-close-fs-btn:active {
  background: rgba(92,126,140,0.85);
}

/* ── Fullscreen mode ── */
body.atfb-fs-open { overflow: hidden; }

.atfb-viewer.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  border-radius: 0;
  max-width: none;
  margin: 0;
  display: flex;
  flex-direction: column;
  box-shadow: none;
  background: #FDFCF8;
}

.atfb-viewer.is-fullscreen .atfb-canvas-wrap {
  flex: 1;
  min-height: 0;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .atfb-viewer { margin: 24px 0 0; border-radius: 8px; }

  .atfb-canvas-wrap {
    padding: 14px 44px;
    min-height: 240px;
  }

  .atfb-nav-arrow { width: 36px; height: 36px; font-size: 18px; }
  .atfb-nav-arrow.prev { left: 4px; }
  .atfb-nav-arrow.next { right: 4px; }

  .atfb-controls-bottom { gap: 8px; }

  .atfb-mobile-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 24px;
    background: #7B9EAB;
    color: white;
    font-family: Inter, sans-serif;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    border: none;
    border-top: 1px solid rgba(123,158,171,0.2);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s;
  }

  .atfb-mobile-cta:hover,
  .atfb-mobile-cta:active { background: #5C7E8C; }

  .atfb-mobile-cta svg { flex-shrink: 0; stroke: currentColor; }

  .atfb-viewer.is-fullscreen .atfb-mobile-cta { display: none; }

  /* Fullscreen: use safe areas for iOS notch/home bar */
  .atfb-viewer.is-fullscreen {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .atfb-viewer.is-fullscreen .atfb-canvas-wrap {
    padding: 10px 40px;
  }
}

@media (max-width: 480px) {
  .atfb-zoom-level { display: none; }

  .atfb-canvas-wrap { padding: 12px 36px; }
  .atfb-nav-arrow { width: 32px; height: 32px; font-size: 16px; }
  .atfb-nav-arrow.prev { left: 2px; }
  .atfb-nav-arrow.next { right: 2px; }
}

/* ── Rotate hint (iOS portrait fullscreen) ── */
.atfb-rotate-hint {
  display: none;
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 43, 53, 0.88);
  color: rgba(255, 255, 255, 0.92);
  padding: 10px 18px;
  border-radius: 20px;
  font-family: Inter, sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
  z-index: 10002;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  gap: 8px;
  align-items: center;
}

.atfb-viewer.is-fullscreen .atfb-rotate-hint.is-visible {
  display: flex;
}
