/* =============================================================================
   PDF Book Reader — Estilos
   Design: sem fundo, controles abaixo do PDF, visual neutro.
   ============================================================================= */

/* ── Reset de box-sizing ────────────────────────────────────────────────── */
.pbr-container *,
.pbr-container *::before,
.pbr-container *::after {
	box-sizing: border-box;
}

/* ── Variáveis ──────────────────────────────────────────────────────────── */
.pbr-container {
	--pbr-accent:       #4a7fd4;
	--pbr-accent2:      #8b65d9;
	--pbr-page-bg:      #fff;
	--pbr-shadow:       0 8px 32px rgba(0 0 0 / .18), 0 2px 8px rgba(0 0 0 / .10);
	--pbr-btn-color:    #444;
	--pbr-btn-border:   rgba(0 0 0 / .18);
	--pbr-btn-hover-bg: rgba(0 0 0 / .06);
	--pbr-muted:        #888;
	--pbr-radius-ctrl:  7px;
}

/* ── Container — sem fundo ──────────────────────────────────────────────── */
.pbr-container {
	position: relative;
	display: block;
	/* sem background — herda a página */
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
	font-size: 14px;
	color: var(--pbr-btn-color);
	user-select: none;
	-webkit-user-select: none;
	outline: none;
	/* Margens verticais padrão (respiro no fluxo do artigo) */
	margin-top:    2.5rem;
	margin-bottom: 2.5rem;
}

/* ── Breakout do container do tema (720px → 1200px) ─────────────────────────
 *
 * Quando o leitor está dentro do .article-container (max-width:720px) do tema,
 * ele precisa "escapar" para uma largura maior sem quebrar a estrutura HTML.
 *
 * Técnica: margens negativas simétricas.
 *
 *   largura desejada  = min(1200px, 100vw)
 *   margem cada lado  = (largura-do-pai − largura-desejada) ÷ 2
 *
 * Exemplos:
 *   viewport 1440px → pai=720px  → margin = (720−1080)/2 = −180px  ✓  (90vw de 1440=1296 → cap 1200)
 *   viewport  900px → pai=720px  → margin = (720− 810)/2 =  −45px  ✓  (90vw de 900=810)
 *   viewport  600px → pai=600px  → margin = (600− 540)/2 =  +30px  ✓  (90vw de 600=540, centra)
 *
 * O limite de 90vw garante 5% de respiro lateral em cada lado da tela.
 * Como `.article-container` é centrado com margin:auto, a fórmula garante
 * que o leitor também fique centrado no viewport.
 * ─────────────────────────────────────────────────────────────────────────── */
.article-container    .pbr-container,
.entry-content        .pbr-container,
.reading-experience   .pbr-container {
	--pbr-breakout-max: 1200px;
	--pbr-breakout-w:   min(var(--pbr-breakout-max), 90vw);

	width:         var(--pbr-breakout-w) !important; /* derrota o style="width:100%" inline */
	margin-left:   calc( ( 100% - var(--pbr-breakout-w) ) / 2 );
	margin-right:  calc( ( 100% - var(--pbr-breakout-w) ) / 2 );
	margin-top:    3rem;
	margin-bottom: 3rem;
}

/* Fix: atributo HTML "hidden" não pode ser sobreposto por display:flex */
.pbr-container [hidden] {
	display: none !important;
}

/* ── Tela cheia ─────────────────────────────────────────────────────────── */
.pbr-container.pbr-fullscreen {
	position: fixed !important;
	inset: 0 !important;
	width: 100vw !important;
	height: 100vh !important;
	z-index: 999999;
	background: #111 !important;
	/* Cadeia flex: container → viewer → stage */
	display: flex;
	flex-direction: column;
}

/* 1. Viewer ocupa todo o espaço restante do container */
.pbr-container.pbr-fullscreen .pbr-viewer {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-height: 0; /* permite que filhos flex encolham abaixo do content-size */
	overflow: hidden;
}

/* 2. Stage cresce para preencher o viewer (sobrepõe a altura inline "600px") */
.pbr-container.pbr-fullscreen .pbr-stage {
	flex: 1;
	min-height: 0;
	height: auto !important;   /* !important derrota o style="height:Xpx" inline */
	background: #111;
	padding: 20px;
}

/* ── Estado: carregando ─────────────────────────────────────────────────── */
/* Position absolute sobre o viewer para não colapsar o layout */
.pbr-loading {
	position: absolute;
	inset: 0;
	z-index: 50;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	background: rgba(255 255 255 / .92);
	color: var(--pbr-muted);
	font-size: 13px;
	border-radius: 4px;
	/* Altura mínima para quando o viewer ainda não tem dimensões */
	min-height: 120px;
}

.pbr-loading p { margin: 0; }

.pbr-spinner {
	width: 36px;
	height: 36px;
	border: 3px solid rgba(0 0 0 / .08);
	border-top-color: var(--pbr-accent);
	border-radius: 50%;
	animation: pbr-spin 0.8s linear infinite;
}

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

/* ── Estado: erro ───────────────────────────────────────────────────────── */
.pbr-error-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 10px;
	padding: 40px 24px;
	color: #c0392b;
	text-align: center;
	font-size: 14px;
}

.pbr-error-state svg { width: 36px; height: 36px; opacity: .7; }
.pbr-error-state p   { margin: 0; }
.pbr-error           { color: #c0392b; padding: 8px 0; margin: 0; }

/* ── Palco — sem fundo, só centraliza o livro ───────────────────────────── */
.pbr-stage {
	position: relative;
	display: flex;
	align-items: flex-start;  /* sem gap no topo — livro cola no início */
	justify-content: center;
	overflow: hidden;
	padding: 0;
	width: 100%;
	box-sizing: border-box;
	/* sem background */

	/* Altura controlada por JS após renderização — sem max-height fixo. */
}

/* ── Book wrap (perspectiva 3-D) ──────────────────────────────────────────── */
.pbr-book-wrap {
	perspective: 2600px;
	perspective-origin: center 38%;
	max-width: 100%;
	flex-shrink: 1;
}

/* ── Livro ──────────────────────────────────────────────────────────────── */
.pbr-book {
	position: relative;
	display: flex;
	align-items: stretch;
	transform-style: preserve-3d;
	box-shadow: var(--pbr-shadow);
	border-radius: 1px 3px 3px 1px;
	max-width: 100%;
}

/* ── Páginas ────────────────────────────────────────────────────────────── */
.pbr-page {
	position: relative;
	display: flex;
	align-items: flex-start;
	justify-content: flex-start;
	background: var(--pbr-page-bg);
	overflow: hidden;
	max-width: 100%;
	flex-shrink: 1;
}

.pbr-page-left  { border-radius: 2px 0 0 2px; }
.pbr-page-right { border-radius: 0 2px 2px 0; }

.pbr-page canvas {
	display: block;
	max-width: 100%;
}

/* ── Lombada ────────────────────────────────────────────────────────────── */
.pbr-spine {
	width: 6px;
	align-self: stretch;
	flex-shrink: 0;
	display: none;
	background: linear-gradient(to bottom,
		#d4c09e 0%, #b09060 25%,
		#8a6840 50%, #b09060 75%,
		#d4c09e 100%
	);
	box-shadow:
		inset 1px 0 2px rgba(255 255 255 / .25),
		inset -1px 0 2px rgba(0 0 0 / .30),
		0 0 10px rgba(0 0 0 / .40);
}

.pbr-book--double .pbr-spine { display: block; }

/* ── Sombra interna nas páginas (efeito de lombada) ─────────────────────── */
.pbr-shadow {
	position: absolute;
	top: 0;
	bottom: 0;
	width: 36px;
	pointer-events: none;
	z-index: 2;
}

.pbr-shadow-left {
	right: 0;
	background: linear-gradient(to left,
		rgba(0 0 0 / .14) 0%,
		transparent 100%
	);
}

.pbr-shadow-right {
	left: 0;
	background: linear-gradient(to right,
		rgba(0 0 0 / .14) 0%,
		transparent 100%
	);
}

/* ── Flippers (animação 3-D) ────────────────────────────────────────────── */
.pbr-flipper {
	position: absolute;
	transform-style: preserve-3d;
	z-index: 30;
}

.pbr-flipper-fwd { transform-origin: left  center; }
.pbr-flipper-bwd { transform-origin: right center; }

.pbr-face {
	position: absolute;
	inset: 0;
	overflow: hidden;
	background: var(--pbr-page-bg);
	backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
}

.pbr-face-back { transform: rotateY(180deg); }

.pbr-canvas-flip {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: fill;
}

/* Sombra na borda de dobra */
.pbr-flipper-fwd .pbr-face-front::after,
.pbr-flipper-bwd .pbr-face-front::after {
	content: '';
	position: absolute;
	inset: 0;
	pointer-events: none;
	backface-visibility: hidden;
	z-index: 1;
}

.pbr-flipper-fwd .pbr-face-front::after {
	background: linear-gradient(to left,
		rgba(0 0 0 / .22) 0%, rgba(0 0 0 / .06) 16%, transparent 40%
	);
}

.pbr-flipper-bwd .pbr-face-front::after {
	background: linear-gradient(to right,
		rgba(0 0 0 / .22) 0%, rgba(0 0 0 / .06) 16%, transparent 40%
	);
}

/* ── Botões sobrepostos ao stage (aparecem ao passar o mouse) ────────────── */
.pbr-stage-btn {
	position: absolute;
	top: 50%;
	transform: translateY(-50%) scale(0.85);
	width: 40px;
	height: 40px;
	border: none;
	border-radius: 50%;
	background: rgba(0 0 0 / .38);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: opacity 0.2s, transform 0.18s, background 0.15s;
	z-index: 10;
}

.pbr-stage:hover .pbr-stage-btn:not(:disabled) {
	opacity: 1;
	transform: translateY(-50%) scale(1);
}

.pbr-stage-btn:hover:not(:disabled) { background: rgba(0 0 0 / .58); }
.pbr-stage-btn:active:not(:disabled) { transform: translateY(-50%) scale(0.92) !important; }
.pbr-stage-btn:disabled { display: none; }
.pbr-stage-btn svg { width: 20px; height: 20px; pointer-events: none; }
.pbr-stage-btn-prev { left: 8px; }
.pbr-stage-btn-next { right: 8px; }

/* ── Barra de progresso ─────────────────────────────────────────────────── */
.pbr-progress {
	height: 3px;
	background: rgba(0 0 0 / .08);
	margin: 0;
}

.pbr-progress-fill {
	height: 100%;
	background: linear-gradient(90deg, var(--pbr-accent) 0%, var(--pbr-accent2) 100%);
	transition: width 0.4s ease;
	will-change: width;
}

/* ── Controles abaixo do PDF ────────────────────────────────────────────── */
.pbr-controls {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 8px 4px 2px;
	gap: 8px;
}

.pbr-controls-nav,
.pbr-controls-extra {
	display: flex;
	align-items: center;
	gap: 4px;
}

/* Divisor vertical entre zoom e fullscreen */
.pbr-controls-divider {
	width: 1px;
	height: 18px;
	background: var(--pbr-btn-border);
	margin: 0 4px;
}

/* ── Botões dos controles ────────────────────────────────────────────────── */
.pbr-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	padding: 0;
	border: 1px solid var(--pbr-btn-border);
	border-radius: var(--pbr-radius-ctrl);
	background: transparent;
	color: var(--pbr-btn-color);
	cursor: pointer;
	transition: background 0.14s, border-color 0.14s, transform 0.1s;
	flex-shrink: 0;
}

.pbr-btn:hover:not(:disabled) {
	background: var(--pbr-btn-hover-bg);
	border-color: rgba(0 0 0 / .30);
}

.pbr-btn:active:not(:disabled) {
	transform: scale(0.91);
}

.pbr-btn:disabled {
	opacity: 0.28;
	cursor: not-allowed;
}

.pbr-btn svg {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
	pointer-events: none;
}

/* ── Info de página ─────────────────────────────────────────────────────── */
.pbr-page-info {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 0 4px;
	font-size: 13px;
	color: var(--pbr-muted);
}

.pbr-page-input {
	width: 42px;
	padding: 3px 5px;
	background: transparent;
	border: 1px solid var(--pbr-btn-border);
	border-radius: 5px;
	color: inherit;
	font-size: 13px;
	text-align: center;
	-moz-appearance: textfield;
	transition: border-color 0.14s;
}

.pbr-page-input:focus {
	outline: none;
	border-color: var(--pbr-accent);
}

.pbr-page-input::-webkit-inner-spin-button,
.pbr-page-input::-webkit-outer-spin-button {
	-webkit-appearance: none;
}

.pbr-page-sep,
.pbr-page-total { color: var(--pbr-muted); }

/* ── Nível de zoom ──────────────────────────────────────────────────────── */
.pbr-zoom-value {
	min-width: 36px;
	text-align: center;
	font-size: 12px;
	color: var(--pbr-muted);
}

/* ── Fullscreen: ajuste de stage ────────────────────────────────────────── */
.pbr-container.pbr-fullscreen .pbr-controls {
	padding: 10px 16px;
	background: rgba(255 255 255 / .06);
	flex-shrink: 0;
	/* Inverte cores para fundo escuro em tela cheia */
	--pbr-btn-color:    #ddd;
	--pbr-btn-border:   rgba(255 255 255 / .18);
	--pbr-btn-hover-bg: rgba(255 255 255 / .10);
	--pbr-muted:        #999;
}

.pbr-container.pbr-fullscreen .pbr-progress {
	background: rgba(255 255 255 / .10);
}

.pbr-container.pbr-fullscreen .pbr-loading {
	background: rgba(17 17 17 / .92);
	color: #aaa;
}

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
	/* Margens verticais menores em telas pequenas */
	.pbr-container {
		margin-top:    1.5rem;
		margin-bottom: 1.5rem;
	}

	/* Em breakout, usa 94vw para ter 3% de respiro por lado */
	.article-container  .pbr-container,
	.entry-content      .pbr-container,
	.reading-experience .pbr-container {
		--pbr-breakout-w: 94vw;
		margin-top:    1.5rem;
		margin-bottom: 1.5rem;
	}

	.pbr-stage {
		padding: 0;
	}

	/* Setas sempre visíveis em touch (não há hover) */
	.pbr-stage-btn {
		opacity: 0.7;
		transform: translateY(-50%) scale(1);
	}

	.pbr-stage-btn-prev { left: 4px; }
	.pbr-stage-btn-next { right: 4px; }

	/* Esconde zoom no mobile — só navegação e fullscreen */
	.pbr-controls-extra .pbr-btn-zoom-in,
	.pbr-controls-extra .pbr-btn-zoom-out,
	.pbr-controls-extra .pbr-zoom-value {
		display: none;
	}

	/* Esconde divisor se zoom está oculto */
	.pbr-controls-divider { display: none; }
}

/* ── Acessibilidade: movimento reduzido ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
	.pbr-flipper    { transition: none !important; }
	.pbr-spinner    { animation: none; border-top-color: var(--pbr-muted); }
	.pbr-progress-fill,
	.pbr-stage-btn  { transition: none !important; }
}
