/**
 * Primo Piano PDF Reader - Magazine Style
 * Clean PDF viewer with PDF.js
 */

/* ============================================
   CONTAINER & LAYOUT
   ============================================ */

.pp-magazine-container {
    width: 100%;
    max-width: 1400px;
    margin: 30px auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    min-height: 600px;
}

/* ============================================
   LOADING STATE
   ============================================ */

.pp-magazine-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 500px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 12px;
    color: #fff;
}

.pp-loader {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #4facfe;
    border-radius: 50%;
    animation: pp-spin 1s linear infinite;
}

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

.pp-magazine-loading p {
    margin-top: 20px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

/* ============================================
   MAGAZINE WRAPPER
   ============================================ */

.pp-magazine-wrapper {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 12px;
    overflow: visible;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    min-height: 600px;
}

/* ============================================
   TOOLBAR
   ============================================ */

.pp-magazine-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.pp-toolbar-left,
.pp-toolbar-right {
    display: flex;
    gap: 8px;
}

.pp-toolbar-center {
    flex: 1;
    text-align: center;
}

.pp-tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    padding: 5px;
}

.pp-tool-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.pp-tool-btn:active {
    transform: translateY(0);
}

.pp-tool-btn svg {
    width: 40px;
    height: 40px;
}

.pp-page-indicator {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 500;
}

#pp-page-num {
    font-weight: 700;
    color: #4facfe;
}

/* ============================================
   FLIPBOOK VIEWPORT
   ============================================ */

.pp-flipbook-viewport {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 75vh;
    max-height: 900px;
    min-height: 400px;
    padding: 20px;
    background: linear-gradient(180deg, #0f0f1a 0%, #1a1a2e 100%);
    overflow: hidden; /* Default hidden, auto when zoomed */
    transition: all 0.3s ease;
}

/* When zoomed, enable scrolling */
.pp-flipbook-viewport.is-zoomed {
    overflow: auto;
    align-items: flex-start;
    justify-content: flex-start;
    cursor: grab;
    padding-bottom: 100px;
}

.pp-flipbook-viewport.is-zoomed:active {
    cursor: grabbing;
}

/* Flipbook transform transition */
.pp-flipbook {
    transition: transform 0.3s ease;
}

/* Scrollbar styling for zoomed viewport */
.pp-flipbook-viewport.is-zoomed::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.pp-flipbook-viewport.is-zoomed::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

.pp-flipbook-viewport.is-zoomed::-webkit-scrollbar-thumb {
    background: rgba(79, 172, 254, 0.6);
    border-radius: 6px;
}

.pp-flipbook-viewport.is-zoomed::-webkit-scrollbar-thumb:hover {
    background: rgba(79, 172, 254, 0.8);
}

/* Firefox scrollbar */
.pp-flipbook-viewport.is-zoomed {
    scrollbar-width: auto;
    scrollbar-color: rgba(79, 172, 254, 0.6) rgba(255, 255, 255, 0.1);
}

/* Navigation Arrows */
.pp-nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pp-nav-prev {
    left: 15px;
}

.pp-nav-next {
    right: 15px;
}

.pp-nav-arrow:hover {
    background: rgba(79, 172, 254, 0.3);
    transform: translateY(-50%) scale(1.1);
}

.pp-nav-arrow:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pp-nav-arrow:disabled:hover {
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
}

/* ============================================
   FLIPBOOK (Turn.js)
   ============================================ */

.pp-flipbook {
    position: relative;
    /* Dimensions controlled by Turn.js */
    /* Book shadow */
    box-shadow:
        0 0 30px rgba(0, 0, 0, 0.5),
        0 0 100px rgba(0, 0, 0, 0.3);
}

.pp-flipbook .pp-page {
    background: #fff;
    overflow: hidden;
}

.pp-flipbook .pp-page canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Page shadow effect */
.pp-flipbook .turn-page-wrapper {
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.1);
}

/* Gradient overlay for realism */
.pp-flipbook .pp-page::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 50px;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.08), transparent);
    pointer-events: none;
}

.pp-flipbook .pp-page.odd::after {
    right: auto;
    left: 0;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.08), transparent);
}

/* Hard cover effect for first/last pages */
.pp-flipbook .pp-page.pp-hard {
    background: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%);
}

/* ============================================
   THUMBNAILS STRIP
   ============================================ */

.pp-page-thumbnails {
    display: flex;
    gap: 8px;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.4);
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.pp-page-thumbnails::-webkit-scrollbar {
    height: 6px;
}

.pp-page-thumbnails::-webkit-scrollbar-track {
    background: transparent;
}

.pp-page-thumbnails::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.pp-thumb {
    flex-shrink: 0;
    width: 60px;
    height: 85px;
    background: #fff;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.pp-thumb:hover {
    opacity: 1;
    transform: translateY(-2px);
}

.pp-thumb.active {
    border-color: #4facfe;
    opacity: 1;
    box-shadow: 0 0 15px rgba(79, 172, 254, 0.5);
}

.pp-thumb canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pp-thumb-number {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 2px;
}

/* ============================================
   ACCESS MESSAGES
   ============================================ */

.pp-access-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    padding: 60px 40px;
    text-align: center;
    border-radius: 12px;
}

.pp-access-message.pp-validating {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
}

.pp-access-message.pp-denied {
    background: linear-gradient(135deg, #2c1810 0%, #1a0f0a 100%);
    color: #fff;
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.pp-access-message.pp-error {
    background: linear-gradient(135deg, #2c2810 0%, #1a170a 100%);
    color: #fff;
}

.pp-access-message.pp-view-only {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
}

.pp-message-icon {
    margin-bottom: 20px;
    opacity: 0.8;
}

.pp-message-icon svg {
    stroke: currentColor;
}

.pp-access-message.pp-validating .pp-message-icon svg {
    animation: pp-spin 2s linear infinite;
}

.pp-access-message h3 {
    margin: 0 0 10px;
    font-size: 24px;
    font-weight: 600;
}

.pp-access-message p {
    margin: 0 0 25px;
    opacity: 0.7;
    font-size: 15px;
    max-width: 400px;
}

.pp-btn-subscribe,
.pp-btn-download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 28px;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
}

.pp-btn-subscribe:hover,
.pp-btn-download:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 172, 254, 0.4);
    color: #fff;
}

/* ============================================
   FULLSCREEN MODE
   ============================================ */

.pp-magazine-container.pp-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    margin: 0;
    z-index: 99999;
    border-radius: 0;
}

.pp-magazine-container.pp-fullscreen .pp-magazine-wrapper {
    height: 100%;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.pp-magazine-container.pp-fullscreen .pp-flipbook-viewport {
    flex: 1;
    min-height: auto;
}

/* Dimensions controlled by Turn.js dynamically */

/* ============================================
   TEXT LAYER (Accessibility/Selection)
   ============================================ */

.pp-page .textLayer {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    opacity: 0;
    line-height: 1.0;
    pointer-events: auto;
}

.pp-page .textLayer > span {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}

.pp-page .textLayer ::selection {
    background: rgba(79, 172, 254, 0.3);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 900px) {
    .pp-flipbook-viewport {
        padding: 15px 5px;
        min-height: auto;
    }

    /* Hide navigation arrows on mobile - users can swipe */
    .pp-nav-arrow {
        display: none;
    }

    .pp-magazine-toolbar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 15px;
    }

    .pp-toolbar-center {
        order: -1;
        flex-basis: 100%;
    }

    .pp-tool-btn {
        width: 36px;
        height: 36px;
    }

    .pp-tool-btn svg {
        width: 20px;
        height: 20px;
    }

    .pp-page-thumbnails {
        padding: 8px;
    }

    .pp-thumb {
        width: 40px;
        height: 57px;
    }

    .pp-magazine-container {
        margin: 10px auto;
        min-height: auto;
    }

    .pp-magazine-wrapper {
        min-height: auto;
    }
}

@media (max-width: 600px) {
    .pp-magazine-container {
        margin: 5px auto;
    }

    .pp-flipbook-viewport {
        min-height: auto;
        padding: 10px 2px;
    }

    .pp-magazine-toolbar {
        padding: 8px 10px;
    }

    .pp-access-message {
        padding: 30px 15px;
        min-height: 250px;
    }

    .pp-access-message h3 {
        font-size: 18px;
    }

    .pp-tool-btn {
        width: 32px;
        height: 32px;
    }

    .pp-tool-btn svg {
        width: 18px;
        height: 18px;
    }

    .pp-page-thumbnails {
        padding: 5px;
        gap: 5px;
    }

    .pp-thumb {
        width: 35px;
        height: 50px;
    }
}

/* ============================================
   PRINT PROTECTION
   ============================================ */

@media print {
    .pp-magazine-container {
        display: none !important;
    }

    body::before {
        content: "Stampa non consentita";
        display: block;
        font-size: 24px;
        text-align: center;
        padding: 50px;
    }
}

/* ============================================
   SCREENSHOT & COPY DETERRENTS
   ============================================ */

/* Disable text selection */
.pp-magazine-container {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Disable touch callout (iOS long-press) */
.pp-magazine-container * {
    -webkit-touch-callout: none;
}

/* Disable image dragging */
.pp-magazine-container img,
.pp-magazine-container canvas {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

/* Re-enable pointer events for navigation */
.pp-magazine-container .pp-nav-arrow,
.pp-magazine-container .pp-tool-btn,
.pp-magazine-container .pp-thumb,
.pp-magazine-container button {
    pointer-events: auto;
}

/* Blur content when window loses focus (screenshot deterrent) */
.pp-magazine-container.pp-blur-content .pp-flipbook-viewport {
    filter: blur(20px);
    transition: filter 0.1s ease;
}

.pp-magazine-container.pp-blur-content::after {
    content: "Contenuto protetto";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 20px 40px;
    border-radius: 8px;
    font-size: 18px;
    z-index: 9999;
}
