/**
 * CSS for Turn Your PDF Files like Real Book Plugin
 * Author: P Adhil Khan
 * Version: 1.0.2
 */

/* --- Global & Reset --- */
.typf-flip-book-container *,
.typf-flip-book-container *::before,
.typf-flip-book-container *::after { /* Apply box-sizing to all elements including pseudo-elements */
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; /* Consistent font stack */
}

body.typf-fullscreen-active {
    overflow: hidden !important; /* Prevent body scroll when flipbook is fullscreen */
}

/* --- Main Plugin Container --- */
.typf-flip-book-container {
    background-color: #2c3e50; /* Dark slate blue - main background */
    color: #ecf0f1; /* Light grey/off-white - primary text */
    padding: 20px;
    border-radius: 12px; /* Softer, modern radius */
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25), 0 5px 15px rgba(0,0,0,0.2); /* Enhanced shadow for depth */
    overflow: hidden; /* Contains child elements and shadows */
    max-width: 1000px; /* Max width for comfortable viewing on large screens */
    margin: 30px auto; /* Centering on page with some vertical margin */
    display: flex; /* Use flexbox for main layout */
    flex-direction: column; /* Stack header and UI vertically */
    gap: 20px; /* Space between header and the main UI block */
    line-height: 1.5; /* Improved text readability */
}

/* --- Header Section --- */
.typf-header-section {
    text-align: center;
    padding-bottom: 20px; /* Increased padding */
    border-bottom: 1px solid rgba(236, 240, 241, 0.15); /* Slightly more visible border */
    flex-shrink: 0; /* Prevent header from shrinking if content below grows */
}
.typf-header-section h1 {
    font-size: clamp(1.6em, 4vw, 2.3em); /* Responsive font size: min, preferred, max */
    color: #ffffff; /* Pure white for main title */
    margin-bottom: 10px; /* More space below title */
    font-weight: 600; /* Semi-bold */
    letter-spacing: 0.5px; /* Slight letter spacing for modern feel */
}
.typf-header-section h4 {
    font-size: clamp(0.85em, 2.5vw, 1em); /* Responsive subtitle */
    color: #bdc3c7; /* Lighter grey for subtitle */
    font-weight: 400; /* Normal weight */
}
.typf-header-section h4 a {
    color: #1abc9c; /* Teal accent - eye-catching and clean */
    text-decoration: none;
    transition: color 0.25s ease-in-out, text-shadow 0.25s ease-in-out;
}
.typf-header-section h4 a:hover {
    color: #2ecc71; /* Brighter green on hover for clear feedback */
    text-shadow: 0 0 8px rgba(46, 204, 113, 0.6); /* Subtle glow on hover */
}

/* --- Flip-book UI Area (wrapper for controls, viewport, nav, thumbs) --- */
.typf-flip-book-ui {
    display: flex;
    flex-direction: column;
    gap: 15px; /* Consistent spacing between UI sections */
    flex-grow: 1; /* Allows this area to expand and fill available space */
    min-height: 0; /* Important for flex-grow to work correctly in some flexbox scenarios */
}

/* --- Controls Area (Upload, Reset, Zoom, Fullscreen) --- */
.typf-controls-area {
    display: flex;
    justify-content: space-between; /* Pushes upload controls to left, view controls to right */
    align-items: center;
    flex-wrap: wrap; /* Allows controls to stack on smaller screens */
    gap: 15px; /* Increased gap between control groups when they wrap */
    padding: 12px 15px;
    background-color: rgba(52, 73, 94, 0.75); /* Semi-transparent darker slate blue for a modern frosted glass effect */
    border-radius: 8px;
    flex-shrink: 0; /* Prevent this area from shrinking */
}
.typf-upload-controls,
.typf-view-controls {
    display: flex;
    align-items: center;
    gap: 10px; /* Space between individual buttons within a group */
}

/* General Button Styling (applied to upload label, reset, zoom, fullscreen buttons) */
.typf-control-button {
    background-color: #1abc9c; /* Teal - primary action color */
    color: #ffffff; /* White text for contrast */
    border: none;
    padding: 10px 20px; /* Comfortable padding */
    border-radius: 6px; /* Modern rounded corners */
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500; /* Medium weight for button text */
    text-align: center;
    transition: background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    display: inline-flex; /* For aligning text/icons if icons are added later */
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); /* Subtle shadow for depth */
    white-space: nowrap; /* Prevent button text from wrapping */
}
.typf-control-button:hover {
    background-color: #16a085; /* Darker teal on hover */
    box-shadow: 0 3px 6px rgba(0,0,0,0.15);
    transform: translateY(-1px); /* Slight lift effect */
}
.typf-control-button:active {
    background-color: #14997a; /* Even darker teal for pressed state */
    transform: translateY(0px); /* Settle back down */
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.typf-control-button:disabled,
.typf-nav-arrow:disabled { /* Combined disabled styles for controls and nav arrows */
    background-color: #7f8c8d !important; /* Muted grey */
    color: #bdc3c7 !important; /* Lighter text for disabled state */
    cursor: not-allowed !important;
    box-shadow: none !important;
    transform: none !important;
    opacity: 0.7; /* Slightly transparent */
}
.typf-pdf-upload-input { display: none; /* Actual file input is visually hidden */ }

/* --- Loading Popup --- */
.typf-loading-popup {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.85); /* Darker overlay for more focus */
    display: flex; align-items: center; justify-content: center;
    z-index: 10000; /* Highest z-index to be on top of everything */
    opacity: 0; /* Initially hidden */
    visibility: hidden; /* Initially hidden and not interactive */
    transition: opacity 0.25s ease, visibility 0s linear 0.25s; /* Fade transition, visibility change after opacity */
}
.typf-loading-popup.typf-active { /* Class added by JS to show the popup */
    opacity: 1;
    visibility: visible;
    transition-delay: 0s; /* Remove delay when showing */
}
.typf-loading-content {
    background-color: #34495e; /* Dark slate blue, consistent with other UI elements */
    padding: 35px 45px; /* More padding */
    border-radius: 10px; /* Softer radius */
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    color: #ecf0f1;
}
.typf-loading-content p { font-size: 1.15em; }

/* --- Flipbook Viewport & Flipbook Element --- */
.typf-flipbook-viewport {
    width: 100%;
    margin: 0 auto; /* Center the viewport */
    background-color: #222a33; /* Very dark blue, for contrast with pages */
    border-radius: 6px;
    overflow: hidden; /* Essential for turn.js page clipping */
    position: relative; /* For absolute positioning of internal elements if needed */
    flex-grow: 1; /* Allows viewport to expand and fill available vertical space */
    display: flex; /* To center the turn.js book instance if it's smaller than viewport */
    align-items: center;
    justify-content: center;
    min-height: 300px; /* Minimum height to ensure it's visible even before content loads */
    box-shadow: inset 0 0 15px rgba(0,0,0,0.25); /* Inner shadow for a subtle depth effect */
}
.typf-flipbook { /* The element turn.js transforms */
    /* turn.js will set width and height. Optional shadow for the book itself. */
     box-shadow: 0 5px 25px rgba(0,0,0,0.3);
    /* transition: opacity 0.4s ease-in-out; /* Optional fade-in for the book */
}
.typf-flipbook .page { /* Individual pages within the flipbook */
    background-color: #ffffff; /* Default page background (white) */
    overflow: hidden; /* Crucial: ensure canvas does not overflow its page div */
    position: relative; /* Establishes positioning context for the canvas */
}
.typf-flipbook .page canvas { /* The canvas where PDF pages are rendered */
    display: block; /* Removes any extra space below the canvas element */
    position: absolute; /* Allows precise centering within the .page div */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Centers the canvas */
    /* JS will set the actual width/height attributes of the canvas for rendering.
       CSS max-width/height ensures the displayed canvas scales down if the .page div is smaller,
       while maintaining aspect ratio if width/height are 'auto'. */
    max-width: 100%;
    max-height: 100%;
    width: auto !important; /* Important: allows aspect ratio to be maintained by browser if only one dimension is constrained by JS/page div */
    height: auto !important;
}

/* --- Fullscreen Mode Styling --- */
.typf-flip-book-container.typf-fullscreen {
    position: fixed !important; /* Override any relative positioning */
    top: 0 !important; left: 0 !important;
    width: 100vw !important; height: 100vh !important; /* Full viewport dimensions */
    max-width: none !important; /* Override max-width from normal mode */
    z-index: 9999; /* High z-index, but potentially below loading popup */
    padding: 10px; /* Minimal padding in fullscreen */
    border-radius: 0; /* No rounded corners in fullscreen */
    gap: 10px; /* Reduced gap between main UI elements in fullscreen */
}
.typf-flip-book-container.typf-fullscreen .typf-header-section { display: none; /* Hide plugin header in fullscreen */ }
.typf-flip-book-container.typf-fullscreen .typf-controls-area { padding: 8px 10px; /* Smaller padding for controls */ }
.typf-flip-book-container.typf-fullscreen .typf-control-button { padding: 8px 15px; font-size: 0.85em; /* Smaller buttons */ }


/* --- Navigation Controls (Prev/Next Arrows, Page Counter) --- */
.typf-navigation-controls {
    display: flex;
    justify-content: center; /* Center the entire control bar */
    align-items: center;
    padding: 12px 0; /* Increased padding */
    gap: 20px; /* More space around the page counter */
    background-color: rgba(52, 73, 94, 0.75); /* Matches controls area */
    border-radius: 8px;
    margin-top: 10px; /* Space from viewport or thumbnail strip */
    flex-shrink: 0; /* Prevent this area from shrinking */
}
.typf-nav-arrow { /* Base style for prev/next buttons */
    background-color: #1abc9c; /* Teal */
    color: white;
    border: none;
    padding: 10px 22px; /* Slightly wider for better tap area */
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.15s ease;
    line-height: 1; /* Ensures text is vertically centered */
}
.typf-nav-arrow:hover { background-color: #16a085; transform: scale(1.03); }
.typf-nav-arrow:active { background-color: #14997a; transform: scale(1); }
/* Disabled state is handled by .typf-control-button:disabled */

.typf-page-counter-bar { display: flex; align-items: center; color: #ecf0f1; }
.typf-current-page-input {
    width: 60px; /* Wider for up to 3-4 digit page numbers */
    padding: 9px 10px; /* Increased padding */
    border: 1px solid rgba(236, 240, 241, 0.25); /* Subtle border */
    background-color: rgba(236, 240, 241, 0.95); /* Very light input background for contrast */
    color: #2c3e50; /* Dark text for input */
    border-radius: 5px;
    text-align: center;
    font-size: 0.95em;
    font-weight: 500; /* Make page numbers stand out */
    margin: 0 6px; /* Space around the '/' separator */
    -moz-appearance: textfield; /* Remove number input spinners in Firefox */
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.typf-current-page-input:focus {
    outline: none;
    border-color: #1abc9c; /* Teal focus border */
    box-shadow: 0 0 0 3px rgba(26, 188, 156, 0.25); /* Soft glow on focus */
}
.typf-current-page-input::-webkit-outer-spin-button,
.typf-current-page-input::-webkit-inner-spin-button {
    -webkit-appearance: none; margin: 0; /* Remove spinners in WebKit browsers */
}
.typf-total-pages { font-size: 0.95em; font-weight: 500; }

/* --- Thumbnail Strip --- */
.typf-thumbnail-strip { /* Class targeting is generally safer for elements dynamically populated by JS */
    display: flex;
    overflow-x: auto; /* Enable horizontal scrolling for thumbnails */
    overflow-y: hidden; /* Hide vertical scrollbar */
    padding: 12px; /* More padding around thumbnails */
    background-color: rgba(34, 42, 51, 0.85); /* Darker, semi-transparent background */
    border-radius: 8px;
    margin-top: 10px;
    gap: 12px; /* Space between thumbnails */
    height: 135px; /* Slightly taller strip */
    flex-shrink: 0; /* Prevent strip from shrinking */
    /* Custom scrollbar styling for WebKit browsers (Chrome, Safari, Edge) */
    scrollbar-width: thin; /* For Firefox */
    scrollbar-color: #1abc9c #34495e; /* Thumb and track color for Firefox */
}
.typf-thumbnail-strip::-webkit-scrollbar { height: 8px; /* Height of horizontal scrollbar */ }
.typf-thumbnail-strip::-webkit-scrollbar-track { background: #34495e; border-radius: 4px;}
.typf-thumbnail-strip::-webkit-scrollbar-thumb { background-color: #1abc9c; border-radius: 4px; border: 2px solid #34495e;}

.typf-thumbnail {
    flex: 0 0 auto; /* Prevent thumbnails from shrinking/growing; maintain their defined width */
    width: 85px; /* Base width for thumbnails */
    height: 100%; /* Make thumbnails fill the height of the strip */
    border: 2px solid transparent; /* Transparent border for smooth transition on hover/active */
    border-radius: 6px;
    cursor: pointer;
    overflow: hidden; /* Clip the image/canvas if it's larger than the thumbnail div */
    position: relative; /* For positioning the title/author overlay */
    transition: border-color 0.2s ease, transform 0.2s ease-out, box-shadow 0.2s ease;
    background-color: #34495e; /* Placeholder background for the image area before image loads */
    box-shadow: 0 2px 5px rgba(0,0,0,0.15); /* Subtle shadow for thumbnails */
}
.typf-thumbnail:hover {
    border-color: #1abc9c; /* Teal border on hover */
    transform: translateY(-2px) scale(1.03); /* Slight lift and scale effect */
    box-shadow: 0 4px 10px rgba(0,0,0,0.2); /* Enhanced shadow on hover */
}
.typf-thumbnail.typf-active-thumbnail {
    border-color: #e67e22; /* Orange border for the currently active/selected page thumbnail */
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 4px 12px rgba(230, 126, 34, 0.35); /* More prominent shadow for active thumbnail */
}
.typf-thumbnail img,
.typf-thumbnail canvas { /* Styling for the image or canvas element inside the thumbnail */
    width: 100%;
    height: 100%;
    object-fit: contain; /* Scales the image to fit within the thumbnail while maintaining aspect ratio */
    display: block;
    background-color: #fff; /* White background for the image/canvas itself, helps with transparent PDFs */
}
.typf-thumbnail-info { /* Overlay for title/author on cover thumbnail */
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0) 100%); /* Gradient for better text readability */
    color: white;
    padding: 10px 6px 6px 6px; /* Adjusted padding */
    font-size: 0.75em; /* Slightly larger text */
    text-align: center;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.25s ease-in-out;
    pointer-events: none; /* So the overlay doesn't interfere with clicking the thumbnail */
}
.typf-thumbnail:hover .typf-thumbnail-info { opacity: 1; /* Show info on hover */ }
.typf-thumbnail-title {
    display: block; font-weight: bold; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; margin-bottom: 3px; /* Space between title and author */
}
.typf-thumbnail-author {
    display: block; font-size: 0.9em; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) { /* Tablet and large phone landscape */
    .typf-flip-book-container { padding: 15px; gap: 15px; margin: 20px auto; }
    .typf-header-section h1 { font-size: clamp(1.4em, 3.5vw, 1.9em); }
    .typf-header-section h4 { font-size: clamp(0.8em, 2vw, 0.95em); }
    .typf-controls-area { flex-direction: column; align-items: stretch; padding: 10px; }
    .typf-upload-controls, .typf-view-controls { justify-content: center; width: 100%; }
    .typf-control-button { flex-grow: 1; padding: 10px 15px; } /* Allow buttons to grow */
    .typf-view-controls .typf-control-button { min-width: 90px; flex-grow: 0; } /* Prevent zoom/FS from taking full width */
    .typf-navigation-controls { gap: 10px; padding: 10px 0; }
    .typf-nav-arrow { padding: 9px 18px; }
    .typf-current-page-input { width: 50px; padding: 7px 9px; }
    .typf-thumbnail-strip { height: 120px; gap: 10px; }
    .typf-thumbnail { width: 75px; }
}

@media (max-width: 480px) { /* Smaller phones */
    .typf-flip-book-container { padding: 10px; gap: 10px; margin: 15px auto; }
    .typf-header-section { padding-bottom: 15px; margin-bottom: 10px; }
    .typf-header-section h1 { font-size: clamp(1.2em, 4vw, 1.7em); }
    .typf-upload-controls, .typf-view-controls { flex-direction: column; /* Stack buttons vertically */ }
    .typf-control-button { width: 100%; margin-bottom: 8px; } /* Make buttons full width */
    .typf-control-button:last-child { margin-bottom: 0; }
    .typf-view-controls .typf-control-button { min-width: unset; } /* Allow full width when stacked */
    .typf-navigation-controls { flex-wrap: wrap; } /* Allow page counter to wrap if needed */
    .typf-page-counter-bar { order: -1; width: 100%; justify-content: center; margin-bottom: 10px; } /* Move counter above arrows if wrapped */
    .typf-thumbnail-strip { height: 100px; gap: 8px; }
    .typf-thumbnail { width: 65px; }
    .typf-thumbnail-info { font-size: 0.7em; padding: 8px 4px 4px 4px; }
    .typf-control-button { padding: 12px 15px; } /* Ensure good tap targets */
}

/* Utility class for elements initially hidden by JS logic or for forced hiding */
.typf-hidden {
    display: none !important;
}