/* =========================================================
   FLIPBOOK — cartilla digital
   Se carga DESPUÉS de estilo-2.css.

   Nota: estilo-2.css pone color y fuente en `*`, así que aquí
   se reinician dentro de .flipbook y cada clase define el suyo.
   ========================================================= */

.flipbook {
    --papel: #FFF9F0;
    --tinta: #2B2118;
    --tenue: #7A6A58;
    --acento: #F97316;
    --acento-fuerte: #C2410C;   /* texto naranja sobre papel (contraste suficiente) */
    --duracion: 800ms;

    /* Tamaño de UNA página; el libro abierto mide el doble */
    --pw: min(44vw, 420px);
    --ph: calc(var(--pw) * 1.38);

    color: #EDE3D3;
    font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

.flipbook * {
    color: inherit;
    font-family: inherit;
}

/* Debe coincidir con el min-width: 760px de flipbook.js */
@media (max-width: 759px) {
    .flipbook {
        --pw: min(88vw, 400px);
        --ph: calc(var(--pw) * 1.32);
    }
}

.menu-estado {
    text-align: center;
    padding: 48px 20px;
    line-height: 1.5;
}


/* =========================
   ESCENA Y LIBRO
   ========================= */

.libro-escena {
    display: flex;
    justify-content: center;
    padding: 40px 0 8px;

    perspective: 3400px;
    overflow-x: clip;
    touch-action: pan-y;
}

.libro {
    position: relative;
    width: calc(var(--pw) * 2);
    height: var(--ph);

    transform-style: preserve-3d;
    transition: transform var(--duracion) cubic-bezier(0.5, 0.1, 0.25, 1);
}

.libro--simple {
    width: var(--pw);
}

/* Cerrado: la portada (mitad derecha) se centra. Al final: la contraportada. */
.libro--cerrado {
    transform: translateX(calc(var(--pw) * -0.5));
}

.libro--final {
    transform: translateX(calc(var(--pw) * 0.5));
}


/* =========================
   HOJAS
   ========================= */

.hoja {
    position: absolute;
    top: 0;
    left: 50%;
    width: 50%;
    height: 100%;

    transform-origin: left center;
    transform-style: preserve-3d;
    transition: transform var(--duracion) cubic-bezier(0.5, 0.1, 0.25, 1);
}

.hoja.volteada {
    transform: rotateY(-180deg);
}

.libro--simple .hoja {
    left: 0;
    width: 100%;
}

.libro--simple .hoja.volteada {
    pointer-events: none;
}


/* =========================
   CARAS (frente y dorso)
   ========================= */

.cara {
    position: absolute;
    inset: 0;
    overflow: hidden;

    background: var(--papel);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;

    /* Borde fino: sin esto una portada negra desaparece sobre el fondo negro */
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.cara--frente {
    border-radius: 2px 8px 8px 2px;
}

.cara--dorso {
    border-radius: 8px 2px 2px 8px;
    transform: rotateY(180deg);
}

/* Sombra del lomo */
.cara::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}

.cara--frente::before {
    background: linear-gradient(to right, rgba(60, 35, 10, 0.24), rgba(60, 35, 10, 0) 9%);
}

.cara--dorso::before {
    background: linear-gradient(to left, rgba(60, 35, 10, 0.24), rgba(60, 35, 10, 0) 9%);
}

/* Sombra que cruza la página mientras gira */
.cara::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    opacity: 0;
    background: linear-gradient(to right, rgba(20, 10, 0, 0.55), rgba(20, 10, 0, 0) 75%);
}

.hoja.girando .cara::after {
    animation: sombraGiro var(--duracion) ease-in-out;
}

@keyframes sombraGiro {
    0%, 100% { opacity: 0; }
    50%      { opacity: 0.6; }
}


/* =========================
   PORTADA Y CONTRAPORTADA
   ========================= */

.portada {
    position: absolute;
    inset: 0;
    width: 100%;
    padding: 0;
    border: 0;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    cursor: pointer;
}

.portada--atras {
    cursor: default;
}

.portada-logo {
    display: block;
    width: 100%;
    height: auto;
}

.portada--atras .portada-logo {
    width: 55%;
    opacity: 0.9;
}

.portada-abrir {
    position: absolute;
    bottom: 6%;
    font-size: 15px;
    letter-spacing: 0.02em;
    opacity: 0.75;
    transition: opacity 0.2s ease;
}

.portada:hover .portada-abrir {
    opacity: 1;
}


/* =========================
   PÁGINA DE CONTENIDO
   ========================= */

.pagina {
    position: absolute;
    inset: 0;

    display: flex;
    flex-direction: column;
    padding: 8% 8% 4%;

    color: var(--tinta);
}

/* Más margen del lado del lomo */
.cara--frente .pagina {
    padding-left: 11%;
}

.cara--dorso .pagina {
    padding-right: 11%;
}

.pagina-cuerpo {
    flex: 1;
    min-height: 0;
    overflow-y: auto;

    scrollbar-width: thin;
    scrollbar-color: #D9C9B0 transparent;
}

.pagina-pie {
    padding-top: 8px;
    text-align: center;
    font-size: 14px;
    color: var(--tenue);
    font-variant-numeric: lining-nums;
}


/* =========================
   CATEGORÍAS
   ========================= */

.categoria {
    position: relative;
    margin: 22px 0 6px;
    padding-bottom: 12px;

    font-size: 24px;
    font-weight: 700;
    line-height: 1.15;
}

.categoria:first-child {
    margin-top: 0;
}

.categoria::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 40px;
    height: 3px;
    background: var(--acento);
}

.categoria--continua {
    font-size: 18px;
    font-weight: 600;
    color: var(--tenue);
}


/* =========================
   PRODUCTOS
   ========================= */

.item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px dotted rgba(43, 33, 24, 0.28);
}

.item-foto {
    flex: none;
    width: 56px;
    height: 56px;
    border-radius: 6px;
    object-fit: cover;
}

.item-texto {
    flex: 1 1 auto;
    min-width: 0;
}

.item-nombre {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.25;
}

.item-desc {
    margin-top: 2px;
    font-size: 14px;
    line-height: 1.35;
    color: var(--tenue);
}

.item-precio {
    flex: none;
    font-size: 17px;
    font-weight: 700;
    font-variant-numeric: lining-nums tabular-nums;
    white-space: nowrap;
    color: var(--acento-fuerte);
}

.item-agregar {
    flex: none;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;

    background: var(--acento);
    color: #1F1308;
    font-family: Arial, sans-serif;
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;

    transition: transform 0.15s ease, background-color 0.15s ease;
}

.item-agregar:hover {
    background: #FB923C;
}

.item-agregar.agregado {
    transform: scale(1.2);
    background: #86EFAC;
}


/* =========================
   CONTROLES
   ========================= */

.libro-controles {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 18px 0 8px;
}

.libro-indicador {
    min-width: 150px;
    text-align: center;
    font-size: 15px;
    font-variant-numeric: lining-nums;
}

.libro-btn {
    padding: 10px 18px;
    border: 0;
    border-radius: 6px;

    background: var(--acento);
    color: #1F1308;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;

    transition: background-color 0.2s ease;
}

.libro-btn:hover:not(:disabled) {
    background: #FB923C;
}

.libro-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.flipbook button:focus-visible {
    outline: 3px solid #FDBA74;
    outline-offset: 3px;
}

.pagina .item-agregar:focus-visible {
    outline-color: var(--tinta);
}

@media (max-width: 759px) {
    .libro-indicador {
        min-width: 120px;
    }
}


/* =========================
   MOVIMIENTO REDUCIDO
   ========================= */

@media (prefers-reduced-motion: reduce) {
    .flipbook {
        --duracion: 1ms;
    }

    .hoja.girando .cara::after {
        animation: none;
    }
}
