*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/*==============================================================
VARIÁVEIS GLOBAIS
==============================================================*/
:root {
    /* Perspectiva */
    --book-perspective: 2400px;

    /* Tempo */
    --flip-duration: 900ms;
    --flip-easing: cubic-bezier(.22, .61, .36, 1);

    /* Página */
    --page-radius: 0px;
    --page-background: #ffffff;
    --page-text: #222222;

    /* Sombras */
    --shadow-light: rgba(255, 255, 255, .15);
    --shadow-medium: rgba(0, 0, 0, .18);
    --shadow-strong: rgba(0, 0, 0, .35);

    /* Overlay */
    --overlay-dark: rgba(0, 0, 0, .22);

    /* Z-index */
    --z-page: 10;
    --z-header: 5000;
    --z-indicators: 6000;
    --z-floating: 7000;
    --z-loader: 99999;
}

/*==============================================================
BODY
==============================================================*/
html, body {
    width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100vh;
    margin: 0;


}

body {
    background: #111;
    font-family: 'Poppins', sans-serif;
    color: var(--page-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/*==============================================================
LIVRO
==============================================================*/
#bookflip-engine {
    position: fixed;
    top: 85px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    perspective: var(--book-perspective);
    transform-style: preserve-3d;
    isolation: isolate;
    perspective-origin: center center;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/*==============================================================
PÁGINAS
==============================================================*/
.bookflip-page {

    position: absolute;
    inset: 0;
    width: 100%;
    flex-grow: 1;
    height: 100%;
    right: 0; /* As páginas nascem fixadas no lado direito da tela */
    overflow: hidden;
    background: var(--page-background);
    border-radius: var(--page-radius);

    /* CORREÇÃO 1: Origem de rotação mudada de 'bottom center' para a lateral (dobradiça do livro) */
    transform-origin: left center;

    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    will-change: transform, opacity, filter, box-shadow;
    transform: translate3d(0, 0, 0) rotateY(0deg);

    transition:
        transform var(--flip-duration) var(--flip-easing),
        opacity var(--flip-duration) ease,
        filter calc(var(--flip-duration) * .8) ease,
        box-shadow var(--flip-duration) ease,
        visibility 0s linear var(--flip-duration);
    z-index: var(--z-page);
    perspective: inherit;
    contain: layout style paint;
    box-shadow:
        0 10px 30px rgba(0, 0, 0, .10),
        0 25px 70px rgba(0, 0, 0, .18);

}







/*==============================================================
CAMADA DE FUNDO
==============================================================*/
.bookflip-page-background {
    position: absolute;
    inset: 0;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    transform: translateZ(-1px) scale(1.02);
    z-index: 1;
}

/*==============================================================
OVERLAY
==============================================================*/
.bookflip-page-overlay {
    position: absolute;
    inset: 0;
    background: var(--overlay-dark);
    pointer-events: none;
    z-index: 2;
}

/*==============================================================
CONTEÚDO
==============================================================*/
.bgt3-content {

    flex-grow: 1;
    position: relative;
    z-index: 5;
    width: 100%;
/*     height: 100%;  */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: clamp(30px, 5vw, 80px);
}

/*==============================================================
TIPOGRAFIA PADRÃO
==============================================================*/
.bgt3-content h1 {
    font-size: clamp(2.5rem, 3vw, 5rem);
    font-weight: 700;
    margin-bottom: 5px;
}

.bgt3-content h2 {
    font-size: clamp(2rem, 2vw, 3rem);
    margin-bottom: 5px;
}

.bgt3-content p {
    max-width: 900px;
    font-size: clamp(1rem, 1.6vw, 1.25rem);
    line-height: 1.8;
}


/*==============================================================
ANIMAÇÕES AUXILIARES (Corrigidas: Sem saltos verticais)
==============================================================*/
@keyframes pageAppear {
    from {
        opacity: 0;
        /* Mudado de translate3d(0, 80px, ...) para manter o alinhamento vertical zerado (0) */
        transform: translate3d(20px, 0, -50px) scale(.98);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

/*==============================================================
ESTADOS DINÂMICOS DAS PÁGINAS (Alinhamento Vertical Travado em 0)
==============================================================*/

.bookflip-page-current {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    /* Forçado translate3d rígido em 0 no eixo vertical */
    transform: translate3d(0, 0, 0) rotateY(0deg);
    z-index: 40;
    transform-origin: left center;
}

.bookflip-page-left {
    opacity: 1;
    visibility: visible;
    pointer-events: none;
    transform: translate3d(0, 0, -10px) rotateY(-180deg);
    z-index: 10;
}

.bookflip-page-right {
    opacity: 1;
    visibility: visible;
    pointer-events: none;
    transform: translate3d(0, 0, -20px) rotateY(180deg);
    z-index: 20;
}

/*
.bookflip-page-left {
    opacity: 1;
    visibility: visible;
    pointer-events: none;
    /* Alinhamento vertical travado em 0
    transform: translate3d(0, 0, -10px) rotateY(-180deg);
    z-index: 10;
}

.bookflip-page-right {
    opacity: 1;
    visibility: visible;
    pointer-events: none;
    Alinhamento vertical travado em 0
    transform: translate3d(0, 0, -20px) rotateY(0deg);
    z-index: 20;
}
 */

/* CLASSE CRÍTICA: Força a página em movimento a ficar por cima de tudo para a rotação ser visível */
.bookflip-page.flipping {
    z-index: 50 !important;
    visibility: visible !important;
    opacity: 1 !important;
}


/*==============================================================
FACE DA PÁGINA
==============================================================*/
.bookflip-page::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 12;
    opacity: 1;
    transition: opacity var(--flip-duration) ease;
    border: 1px solid rgba(255, 255, 255, .05);
    box-shadow:
        inset 0 0 1px rgba(255, 255, 255, .35),
        inset 0 0 60px rgba(255, 255, 255, .06);
}

/*==============================================================
VERSO DA FOLHA & REFLEXO SUPERIOR (Unificados e Corrigidos)
==============================================================*/
.bookflip-page::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 9; /* Mantido abaixo do conteúdo principal */

    /* CORREÇÃO: Mudado de rotateX(180deg) para rotateY(180deg) para o verso espelhar na horizontal */
    transform: rotateY(180deg);

    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, .16),
        rgba(255, 255, 255, .05) 20%,
        rgba(255, 255, 255, 0) 45%
    );
    mix-blend-mode: screen;
    opacity: .85;
}

/*==============================================================
PÁGINA EM MOVIMENTO
==============================================================*/
.bookflip-page.flipping {
    will-change: transform, opacity, filter, box-shadow;
}

/*==============================================================
ANTI-SELEÇÃO DURANTE A ANIMAÇÃO
==============================================================*/
.bookflip-page.flipping * {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
}

/*==============================================================
ANIMAÇÕES AUXILIARES (Corrigida para não usar saltos no eixo X/Z)
==============================================================*/
@keyframes pageAppear {
    from {
        opacity: 0;
        transform: translate3d(20px, 0, -50px) scale(.98); /* Suave aproximação lateral */
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

@keyframes pageDisappear {
    from { opacity: 1; }
    to { opacity: 0; }
}

/*==============================================================
PÁGINA ATUAL (Todas as propriedades repetidas foram unificadas aqui)
==============================================================*/
.bookflip-page-current {
    box-shadow:
        0 20px 60px rgba(0, 0, 0, .18),
        0 40px 90px rgba(0, 0, 0, .22);
    outline: 1px solid rgba(255, 255, 255, .05);
    filter: drop-shadow(0 12px 30px rgba(0, 0, 0, .15));
    backdrop-filter: saturate(110%);
}

.bookflip-page-current .bgt3-content {
    animation: pageAppear calc(var(--flip-duration) * .6) ease;
}

/* TEXTURA DA PÁGINA ATUAL */
.bookflip-page-current::before {
    background-image: radial-gradient(
        rgba(255, 255, 255, .02),
        transparent 65%
    );
}

/*==============================================================
PÁGINA VIRADA (ESQUERDA)
==============================================================*/
.bookflip-page-left {
    box-shadow:
        inset 0 0 45px rgba(0, 0, 0, .25),
        0 15px 45px rgba(0, 0, 0, .12);
}

/*==============================================================
ILUMINAÇÃO E OVERLAYS DAS PÁGINAS (Com transições limpas)
==============================================================*/
.bookflip-page-current .bookflip-page-overlay {
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, .08),
        rgba(0, 0, 0, .10),
        rgba(0, 0, 0, .18)
    );
    transition: background var(--flip-duration) ease;
}

.bookflip-page-left .bookflip-page-overlay {
    background: linear-gradient(
        180deg,
        rgba(0, 0, 0, .30),
        rgba(0, 0, 0, .18),
        rgba(0, 0, 0, .08)
    );
}

.bookflip-page-right .bookflip-page-overlay {
    background: rgba(0, 0, 0, .30);
}

/*==============================================================
CONTEÚDO DA PÁGINA (Efeito Parallax 3D)
==============================================================*/
.bgt3-content {
    transform: translateZ(40px);
}

.bgt3-content h1,
.bgt3-content h2 {
    text-shadow: 0 2px 12px rgba(0, 0, 0, .20);
}

.bgt3-content p {
    text-shadow: 0 1px 8px rgba(0, 0, 0, .10);
}

/*==============================================================
HEADER DA ENGINE
==============================================================*/
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    flex-shrink: 0;   /* lixo */
    padding: 0 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: var(--z-header);
    backdrop-filter: blur(18px);
    background: rgba(15, 15, 15, .25);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

header h1 {
    color: #ffffff;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 2px;
}

header nav {
    display: flex;
    gap: 35px;
}

header nav a {
    color: white;
    text-decoration: none;
    font-size: .95rem;
    transition: .35s;
    position: relative;
}

header nav a:hover {
    color: #6fb5ff;
}

header nav a::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -8px;
    width: 0;
    height: 2px;
    background: #6fb5ff;
    transition: .35s;
}

header nav a:hover::after {
    width: 100%;
}

/*==============================================================
INDICADORES
==============================================================*/
#bookflip-indicators {
    position: fixed;
    right: 35px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 14px;
    z-index: var(--z-indicators);
    transition: opacity .35s;
}

.bookflip-page-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: rgba(255, 255, 255, .30);
    transition: .35s;
}

.bookflip-page-dot:hover {
    transform: scale(1.3);
    background: white;
}

.bookflip-page-dot.active {
    background: white;
    transform: scale(1.5);
    box-shadow: 0 0 18px rgba(255, 255, 255, .60);
}

/*==============================================================
LOADER (Corrigido para respeitar a transição suave de opacidade)
==============================================================*/
#bookflip-loader {
    position: fixed;
    inset: 0;
    display: flex;
    flex-shrink: 0;   /* Lixo */
    justify-content: center;
    align-items: center;
    background: #111;
    z-index: var(--z-loader);
    transition: opacity .6s ease, visibility .6s ease; /* Adicionado visibility para evitar cliques fantasmas */
}

#bookflip-loader.bookflip-hidden-fade {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.bookflip-loader-circle {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, .15);
    border-top-color: #ffffff;
    animation: bookSpin 1s linear infinite;
}

@keyframes bookSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/*==============================================================
SCROLLBAR
==============================================================*/
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #161616;
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 20px;
}

::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/*==============================================================
UTILITÁRIOS
==============================================================*/
.bookflip-hidden {
    display: none !important;
}

.bookflip-invisible {
    visibility: hidden;
}

.bookflip-fade-in {
    animation: fadeIn .8s ease forwards;
}

.bookflip-fade-out {
    animation: fadeOut .5s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/*==============================================================
RESPONSIVO - TABLET (1024px)
==============================================================*/
@media (max-width: 1024px) {
    header {
        padding: 0 25px;
        height: 70px;
    }
    header nav {
        gap: 20px;
    }
    #bookflip-indicators {
        right: 20px;
    }
}

/*==============================================================
RESPONSIVO - CELULAR (768px)
==============================================================*/
@media (max-width: 992px) {
    header {
        height: 65px;
        padding: 0 20px;
    }
    header h1 {
        font-size: 1.2rem;
    }
    header nav {
        display: none;
    }
    #bookflip-indicators {
        right: 15px;
        gap: 10px;
    }
    .bookflip-page-dot {
        width: 10px;
        height: 10px;
    }
    .bgt3-content {
        padding: 25px;
    }
}

/*==============================================================
TELAS MUITO PEQUENAS (480px)
==============================================================*/
@media (max-width: 480px) {
    .bgt3-content h1 {
        font-size: 2rem;
    }
    .bgt3-content h2 {
        font-size: 1.5rem;
    }
    .bgt3-content p {
        font-size: .95rem;
        line-height: 1.7;
    }
}
/*==============================================================
FIM DA BOOKFLIP ENGINE
==============================================================*/
