/* Mobile Responsive Enhancement for OA-Dynasty Book Website */

/* Base styles for all screen sizes */
:root {
    --mobile-padding: 15px;
    --small-phone-width: 360px;
    --phone-width: 480px;
    --content-width: min(100% - 30px, 1200px);
}

/* Global mobile fixes - Multiple media queries for better device compatibility */
@media screen and (max-width: 768px), 
       screen and (max-device-width: 768px),
       only screen and (max-device-width: 768px) and (-webkit-min-device-pixel-ratio: 1) {
    .container {
        padding-left: var(--mobile-padding);
        padding-right: var(--mobile-padding);
        width: var(--content-width);
        margin: 0 auto;
    }

    /* Improve typography for mobile */
    body {
        font-size: 16px;
        line-height: 1.6;
        position: relative; /* Ensure proper stacking context */
    }

    h1 {
        font-size: 1.8rem;
        line-height: 1.3;
    }

    h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    h3 {
        font-size: 1.3rem;
        line-height: 1.3;
    }

    /* Book detail page specific mobile enhancements */
    .book-detail-cover {
        width: 100%;
        max-width: 300px;
        margin: 0 auto 20px;
    }

    .book-purchase {
        text-align: center;
        margin-top: 15px;
    }

    .book-purchase .btn {
        width: 100%;
        max-width: 220px;
    }

    .book-description {
        font-size: 0.95rem;
        line-height: 1.5;
        text-align: left;
    }

    .book-quote {
        font-size: 1rem;
        padding: 15px;
        margin: 15px 0;
    }

    /* Author section mobile improvements */
    .author-info {
        flex-direction: column;
    }

    .author-photo {
        width: 150px;
        height: 150px;
        margin: 0 auto 15px;
    }

    .author-bio {
        padding-left: 0;
        text-align: center;
    }

    /* Reviews mobile improvements */
    .review {
        padding: 15px;
        margin-bottom: 15px;
    }

    /* Image optimization for mobile */
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Mobile book card styling - important overrides for real devices */
    .book-card {
        display: flex !important;
        flex-direction: row !important;
        background: white !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
        margin-bottom: 20px !important;
        overflow: hidden !important;
        min-height: 200px !important;
        max-height: 220px !important; /* Limit height to keep button visible */
        transform: none !important; /* Override hover effects */
    }
    
    .book-card:hover {
        transform: none !important; /* Disable desktop hover effects on mobile */
    }
    
    .book-card .book-cover {
        width: 40% !important;
        min-width: 120px !important;
        max-width: 150px !important;
        flex-shrink: 0 !important;
        height: auto !important; /* Override desktop fixed height */
    }
    
    .book-card .book-cover img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        min-height: 200px !important;
        max-height: 220px !important; /* Match card height */
        transform: none !important; /* Override desktop hover scale */
    }
    
    .book-card .book-info {
        width: 60% !important;
        padding: 15px !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
    }
    
    .book-card .book-info h3 {
        font-size: 1.1rem;
        margin-bottom: 8px;
        line-height: 1.2;
        color: var(--primary-color, #800020);
    }
    
    .book-card .book-info .author {
        font-size: 0.9rem;
        color: #666;
        margin-bottom: 5px;
        font-style: italic;
    }
    
    .book-card .book-info .genre {
        font-size: 0.8rem;
        color: #800020;
        background-color: rgba(128, 0, 32, 0.1);
        padding: 2px 6px;
        border-radius: 12px;
        display: inline-block;
        margin-bottom: 8px;
        width: fit-content;
    }
    
    .book-card .book-info p {
        font-size: 0.85rem !important;
        line-height: 1.3 !important;
        margin-bottom: 8px !important;
        color: #333 !important;
        flex-grow: 1 !important;
        overflow: hidden !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 3 !important;
        line-clamp: 3 !important;
        -webkit-box-orient: vertical !important;
        max-height: 60px !important; /* Limit description height */
    }
    
    .book-card .book-info .btn {
        align-self: flex-start !important;
        font-size: 0.8rem !important;
        padding: 6px 12px !important;
        margin-top: 8px !important; /* Fixed margin instead of auto */
        text-decoration: none !important;
        background-color: var(--primary-color, #800020) !important;
        color: white !important;
        border-radius: 4px !important;
        transition: background-color 0.3s ease !important;
        display: inline-block !important; /* Ensure button is visible */
        visibility: visible !important; /* Force visibility */
        flex-shrink: 0 !important; /* Prevent button from shrinking */
        white-space: nowrap !important; /* Keep button text on one line */
    }
    
    .book-card .book-info .btn:hover {
        background-color: #a00030 !important;
    }

    /* Content spacing for better readability */
    p {
        margin-bottom: 1rem;
    }

    section {
        padding: 2rem 0;
    }

    /* Small phone specific adjustments */
    @media screen and (max-width: 480px) {
        .book-meta {
            flex-direction: column;
            align-items: flex-start;
        }

        .book-meta-item {
            margin-bottom: 8px;
        }

        .page-banner h1 {
            font-size: 1.6rem;
        }

        .page-banner h2 {
            font-size: 1.3rem;
        }
        
        /* Adjust book card layout for small phones */
        .book-card {
            min-height: 180px !important;
            max-height: 200px !important;
        }
        
        .book-card .book-cover {
            min-width: 100px !important;
            max-width: 120px !important;
        }
        
        .book-card .book-cover img {
            min-height: 180px !important;
            max-height: 200px !important;
        }
        
        .book-card .book-info {
            padding: 10px !important;
        }
        
        .book-card .book-info h3 {
            font-size: 0.95rem !important;
            margin-bottom: 6px !important;
        }
        
        .book-card .book-info .author {
            font-size: 0.8rem !important;
            margin-bottom: 4px !important;
        }
        
        .book-card .book-info .genre {
            font-size: 0.7rem !important;
            padding: 1px 4px !important;
            margin-bottom: 6px !important;
        }
        
        .book-card .book-info p {
            font-size: 0.75rem !important;
            line-height: 1.2 !important;
            -webkit-line-clamp: 2 !important;
            line-clamp: 2 !important;
            max-height: 36px !important;
            margin-bottom: 6px !important;
        }
        
        .book-card .book-info .btn {
            font-size: 0.75rem !important;
            padding: 5px 10px !important;
            margin-top: 6px !important;
        }
        
        /* Improve spacing in small screens */
        section {
            padding: 1.5rem 0;
        }
        
        /* Content prioritization for tiny screens */
        .book-meta-item:not(:first-child) {
            display: none;
        }
    }

    /* Extra small devices */
    @media screen and (max-width: 360px) {
        .book-detail-cover {
            max-width: 240px;
        }

        .book-quote p {
            font-size: 0.9rem;
        }

        .author-photo {
            width: 120px;
            height: 120px;
        }
        
        /* Simplify UI for very small screens */
        .book-reviews .review:nth-child(n+3) {
            display: none;
        }
        
        .related-books h2::after {
            content: " (Swipe to view more)";
            font-size: 0.8rem;
            font-weight: normal;
            display: block;
        }
    }
}

/* Header improvements */
@media screen and (max-width: 768px) {
    header .container {
        padding: 10px 15px;
    }

    .logo h1 {
        font-size: 1.2rem;
    }

    /* Improved footer for mobile */
    .footer-content {
        text-align: center;
    }

    .footer-content .social-links {
        justify-content: center;
        margin-top: 20px;
    }
    
    /* Book grid enhancements for mobile */
    .book-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
        width: 100% !important;
        grid-template-columns: none !important; /* Override desktop grid */
    }
    
    /* Make sure book cards are full width on mobile */
    .book-grid .book-card {
        width: 100% !important;
        max-width: 100% !important;
        min-width: auto !important; /* Override desktop min-width */
    }
    
    /* Additional mobile-specific styles for real devices */
    body {
        -webkit-text-size-adjust: 100% !important;
        -ms-text-size-adjust: 100% !important;
    }
    
    /* Force mobile layout for real devices */
    .featured .book-grid .book-card,
    .books-container .book-grid .book-card {
        display: flex !important;
        flex-direction: row !important;
    }
    
    .featured .book-grid .book-card .book-info,
    .books-container .book-grid .book-card .book-info {
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Ensure buttons are always visible */
    .book-info .btn {
        opacity: 1 !important;
        visibility: visible !important;
        display: inline-block !important;
        pointer-events: auto !important;
    }
    
    /* Filtered out cards - completely remove from layout */
    .book-card[data-filtered-out="true"] {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        min-height: 0 !important;
        max-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        opacity: 0 !important;
        overflow: hidden !important;
        position: absolute !important;
        left: -9999px !important;
    }
    
    .book-card[data-filtered-out="true"] * {
        display: none !important;
        visibility: hidden !important;
    }
}

/* Fix for the newsletter form */
@media screen and (max-width: 768px) {
    .newsletter form {
        width: 100%;
        display: flex;
        flex-direction: column;
    }

    .newsletter input,
    .newsletter .btn {
        width: 100%;
        margin: 5px 0;
    }
}

/* Forms improvements for mobile */
@media screen and (max-width: 768px) {
    .form-group {
        margin-bottom: 15px;
    }

    .form-group label {
        margin-bottom: 5px;
    }

    .form-group input,
    .form-group textarea,
    .form-group select {
        padding: 10px;
    }

    .contact-grid form {
        padding: 15px;
    }
    
    /* Contact page mobile responsiveness */
    .contact-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }
    
    .contact-item {
        margin-bottom: 15px !important;
    }
    
    .contact-item i {
        font-size: 1.2rem !important;
        min-width: 24px !important;
    }
    
    .contact-form {
        padding: 20px !important;
        margin-bottom: 30px !important;
    }
    
    .map-container {
        height: 300px !important;
        overflow: hidden !important;
    }
    
    .map-container iframe {
        height: 300px !important;
    }
    
    /* Notification style fix for mobile */
    .download-notification {
        width: 90% !important;
        left: 5% !important;
    }
}

/* Improved animations for mobile (reduce motion) */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Performance optimizations for mobile */
@media screen and (max-width: 768px) {
    /* Add will-change for smoother animations */
    .book-card,
    .btn,
    nav {
        will-change: transform;
    }
    
    /* Use hardware acceleration for smoother transitions */
    .menu-toggle,
    nav,
    .book-card:hover {
        transform: translateZ(0);
    }
}
