:root {
    --bg-main: #0c0c0c;
    --surface: rgba(22, 22, 22, 0.92);
    --surface-hover: rgba(45, 45, 45, 0.95);
    --text-primary: #ffffff;
    --text-secondary: #aaaaaa;
    --border: rgba(255, 255, 255, 0.15);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    background-color: var(--bg-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-primary);
    overflow: hidden;
    /* Usa a altura dinâmica real da tela (sem barras de navegação do Android/iOS) */
    height: 100vh;
    height: 100dvh;
    height: calc(var(--vh, 1vh) * 100);
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
}

#loader {
    position: fixed; inset: 0; background: #000; z-index: 999999;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}
.spinner {
    width: 40px; height: 40px; border: 3px solid rgba(255,255,255,0.1);
    border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite;
    margin-bottom: 15px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#app-container { 
    position: relative; 
    width: 100%; 
    height: 100vh;
    height: 100dvh;
    height: calc(var(--vh, 1vh) * 100);
    display: flex; 
    justify-content: center; 
    align-items: center; 
}

#zoom-viewport {
    width: 100%; height: 100%; overflow: hidden; display: flex;
    justify-content: center; align-items: center; cursor: default;
    touch-action: none;
}
#zoom-viewport.is-zoomed { cursor: grab; }
#zoom-viewport.is-zoomed:active { cursor: grabbing; }

#flipbook-wrapper {
    transition: transform 0.2s cubic-bezier(0.2, 0, 0.2, 1);
    will-change: transform;
    transform-origin: center center;
    display: flex; justify-content: center; align-items: center;
}

#zoom-viewport.is-zoomed #flipbook { pointer-events: none !important; }

.page {
    background-color: #ffffff; overflow: hidden; will-change: transform;
    margin: 0 !important; border: 0 !important;
}
.page canvas { width: 100%; height: 100%; object-fit: fill; display: block; }
.page.--left { box-shadow: inset -10px 0 20px -10px rgba(0,0,0,0.6); }
.page.--right { box-shadow: inset 10px 0 20px -10px rgba(0,0,0,0.6); }

.page-skeleton {
    width: 100%; height: 100%; background: #1a1a1a;
    display: flex; justify-content: center; align-items: center; color: #555; font-size: 1rem;
}
.page-ghost { box-shadow: none !important; background-color: #ffffff !important; pointer-events: none; }

.side-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    background: var(--surface); color: var(--text-primary); border: 1px solid var(--border);
    width: 44px; height: 60px; border-radius: 8px; cursor: pointer; z-index: 1000;
    display: flex; justify-content: center; align-items: center; font-size: 1.1rem;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    transition: var(--transition);
}
.side-nav.left { left: 15px; }
.side-nav.right { right: 15px; }
.side-nav:hover:not(:disabled) { background: var(--surface-hover); transform: translateY(-50%) scale(1.05); }
.side-nav:disabled { opacity: 0; pointer-events: none; }

/* ==========================================================================
   BARRA DE FERRAMENTAS INFERIOR (BLINDADA PARA MOBILE E SAMSUNG GALAXY)
   ========================================================================== */
.bottom-toolbar {
    position: fixed !important; /* Fixa na tela física, ignorando os scrolls do contêiner */
    bottom: max(15px, env(safe-area-inset-bottom)) !important; /* Respeita a barra do Android/iOS */
    left: 50% !important;
    transform: translateX(-50%) !important; /* Centralização perfeita independente da tela */
    z-index: 99999 !important; /* Sobrescreve absolutamente qualquer canvas do PDF */
    background: var(--surface); 
    border: 1px solid var(--border);
    padding: 8px 16px; 
    border-radius: 35px; 
    display: flex; 
    align-items: center; 
    gap: 12px;
    backdrop-filter: blur(16px); 
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.85);
    width: max-content;
    max-width: 94vw;
}

.page-info { font-size: 0.85rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; padding: 0 6px; border-right: 1px solid var(--border); }
.tools-group { display: flex; align-items: center; gap: 2px; }

.tool-btn {
    background: transparent; color: var(--text-secondary); border: none;
    padding: 8px 10px; border-radius: 20px; cursor: pointer; font-size: 0.95rem;
    display: flex; align-items: center; gap: 6px; transition: var(--transition);
}
.tool-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.1); }
.tool-btn .label { font-size: 0.8rem; }

.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; bottom: 135%; right: -10px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 12px; padding: 6px;
    display: flex; flex-direction: column; gap: 2px; min-width: 170px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.9); opacity: 0; visibility: hidden;
    transform: translateY(10px); transition: var(--transition); z-index: 100000;
}
.dropdown.active .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-menu button, .dropdown-menu a {
    background: transparent; color: var(--text-primary); border: none; padding: 10px 12px;
    border-radius: 8px; text-align: left; font-size: 0.85rem; cursor: pointer;
    display: flex; align-items: center; gap: 10px; text-decoration: none; transition: var(--transition);
}
.dropdown-menu button:hover, .dropdown-menu a:hover { background: rgba(255,255,255,0.1); }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 100000;
    display: flex; justify-content: center; align-items: center; opacity: 0; visibility: hidden;
    backdrop-filter: blur(5px); transition: var(--transition);
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-content {
    background: #141414; border: 1px solid var(--border); width: 90%; max-width: 450px;
    max-height: 75vh; border-radius: 16px; display: flex; flex-direction: column; overflow: hidden;
}
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 1rem; }
.modal-header button { background: none; border: none; color: var(--text-secondary); font-size: 1.2rem; cursor: pointer; }
.toc-list { list-style: none; overflow-y: auto; padding: 10px; }
.toc-list li {
    padding: 12px 14px; border-radius: 8px; cursor: pointer; display: flex;
    justify-content: space-between; font-size: 0.9rem; border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: var(--transition);
}
.toc-list li:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* Adaptações Mobile Extremas */
@media (max-width: 768px) {
    .side-nav { display: none !important; } 
    .tool-btn .label { display: none; } 
    .bottom-toolbar { padding: 6px 14px; gap: 8px; }
    .tool-btn { padding: 8px 12px; font-size: 1.15rem; }
}

/* Celular na Horizontal (Landscape) - Garante que a barra não seja engolida pela tela baixa */
@media (max-height: 500px) {
    .bottom-toolbar { bottom: max(8px, env(safe-area-inset-bottom)) !important; padding: 4px 12px; }
    .tool-btn { padding: 6px 10px; font-size: 1rem; }
}