/* --- RESET E BASE --- */
body, html { 
    margin: 0; padding: 0; background: #222; 
    width: 100%; height: 100%;
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center;
    font-family: sans-serif; overflow: hidden; 
}

/* --- HEADER --- */
header {
    width: 100%; padding: 15px 0; text-align: center;
    background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
    position: fixed; top: 0; left: 0; z-index: 1000;
}
header h1 { color: #ddd; font-size: 18px; font-weight: 300; margin: 0; letter-spacing: 1px; }

/* --- LOADER --- */
#loader {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #1a1a1a; color: white; display: flex; flex-direction: column;
    justify-content: center; align-items: center; z-index: 2000;
    transition: opacity 0.5s ease;
}
.spinner {
    width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.1);
    border-top: 4px solid #3498db; border-radius: 50%;
    animation: spin 1s linear infinite; margin-bottom: 10px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- AREA VISIVA --- */
#view-area {
    width: 100%; height: 100vh;
    display: flex; justify-content: center; align-items: center;
    overflow: hidden; position: relative;
}
.zoom-wrap {
    transition: transform 0.3s ease-out;
    transform-origin: center center;
    display: flex; justify-content: center; align-items: center;
    will-change: transform;
}
.flipbook-container {
    width: 95vw; max-width: 1474px; height: 80vh;
    display: flex; justify-content: center; align-items: center;
}
.page { background-color: white; overflow: hidden; box-shadow: inset 0 0 10px rgba(0,0,0,0.1); }
.page img { width: 100%; height: 100%; object-fit: contain; }

/* --- CONTROLLI (DESKTOP) --- */
#controls {
    background: rgba(0, 0, 0, 0.9);
    padding: 10px 20px;
    border-radius: 40px;
    position: fixed;
    bottom: 25px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.8);
    border: 1px solid rgba(255,255,255,0.1);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Separatore visivo tra i gruppi solo su Desktop */
.control-group:first-child {
    /*border-right: 1px solid rgba(255,255,255,0.2);*/
    padding-right: 20px;
}

/* --- BOTTONI --- */
.btn-control {
    background: #111;
    border: 1px solid #444;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
}

.btn-control:hover:not(:disabled) {
    background: #333;
    border-color: #666;
    transform: translateY(-2px);
}

.btn-control:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(1);
}

.btn-download { background: #0047bb; border-color: #0047bb; text-decoration: none; display: inline-flex; align-items: center; }
.btn-download:hover:not(:disabled) { background: #28a745; box-shadow: 0 0 12px rgba(40, 167, 69, 0.4); }

.btn-zoom { background: #0056b3; border-color: #004a9b; }
.btn-zoom:hover:not(:disabled) { background: #007bff; box-shadow: 0 0 12px rgba(0, 123, 255, 0.4); }

#page-number { font-size: 15px; font-weight: bold; min-width: 90px; text-align: center; color: #fff; }

/* --- RESPONSIVE (MOBILE) --- */
@media (max-width: 768px) {
    #controls {
        flex-direction: column;
        width: 92%;
        max-width: 360px;
        bottom: 15px;
        border-radius: 20px;
        padding: 15px;
        gap: 12px;
    }

    .control-group {
        width: 100%;
        justify-content: center;
        border: none !important;
        padding: 0 !important;
        gap: 8px;
    }

    /* Riga 2: Zoom e Reset mantengono una buona area di tocco */
    .control-group:last-child .btn-zoom {
        flex: 1; /* Questi due si dividono lo spazio */
        max-width: 100px; /* Ma non troppo larghi */
        font-size: 11px;
    }

    /* Bottone PDF: centrato e non troppo largo */
    .btn-download {
        flex: 0 1 auto; /* Non forza l'espansione */
        min-width: 80px; 
        max-width: 120px;
        justify-content: center;
        font-size: 11px;
        padding: 12px 15px;
    }

    .flipbook-container {
        height: 65vh;
    }
}