/**
 * MOBILE OPTIMIZATIONS
 * Comprehensive mobile-first responsive design
 * Breakpoints: 320px, 375px, 414px, 768px, 1024px, 1200px
 */

/* ============================================
   MOBILE-FIRST BASE STYLES
   ============================================ */

/* Default (Mobile First - 320px and up) */
* {
    -webkit-tap-highlight-color: rgba(255, 107, 107, 0.3);
    -webkit-touch-callout: none;
}

/* Prevent text size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* ============================================
   MOBILE: 320px - 767px (Phones)
   ============================================ */

@media (max-width: 767px) {
    /* Typography adjustments */
    body {
        font-size: 16px; /* Minimum recommended for mobile */
        line-height: 1.6;
    }

    /* Header - More compact on mobile */
    .header-text {
        font-size: 8vw !important; /* Responsive but readable */
        padding: 0.4em 0.6em !important;
        word-wrap: break-word;
        hyphens: auto;
    }

    .header-subtext {
        font-size: 4vw !important;
        padding: 0.3em 0.5em !important;
        margin-top: 0.5rem;
    }

    #above-menu-background {
        padding: 1rem 0.5rem;
    }

    /* Navigation - Mobile friendly */
    nav {
        width: 100% !important;
        font-size: 16px !important; /* Fixed size for readability */
    }

    nav li {
        padding: 1rem 0.5rem !important; /* Larger touch targets */
        min-height: 44px; /* WCAG minimum */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    nav li a {
        padding: 0.5rem;
        display: block;
        width: 100%;
    }

    /* Main container - Full width on mobile */
    .main-container {
        width: 100% !important;
        padding: 1rem 0 !important;
    }

    /* Animal page content - Reduced padding */
    .animal-page-content {
        padding: 1.5rem 1rem !important;
        border-radius: 8px !important;
        margin: 0.5rem !important;
    }

    /* Page titles - Responsive sizing */
    .page-title {
        font-size: 6vw !important;
        width: 100% !important;
        padding: 1rem 0.5rem !important;
        border-radius: 8px !important;
        margin-bottom: 1rem !important;
    }

    .page-sub-titles {
        font-size: 5.5vw !important;
        width: 100% !important;
        padding: 0.8rem 0.5rem !important;
        border-radius: 8px !important;
        margin-top: 2rem !important;
        margin-bottom: 1rem !important;
    }

    /* Page introduction - Mobile optimized */
    .page-introduction {
        font-size: 1.05em !important;
        padding: 1rem !important;
        margin: 1rem 0 !important;
        border-left-width: 4px !important;
    }

    /* Paragraphs - Better mobile spacing */
    .animal-page-content p {
        font-size: 1em !important;
        line-height: 1.7 !important;
        margin-bottom: 1.2rem !important;
    }

    /* Quick facts box - Mobile friendly */
    .quick-facts-box {
        padding: 1.5rem 1rem !important;
        margin: 1.5rem 0 !important;
        max-width: 100% !important;
    }

    .quick-facts-box h2 {
        font-size: 1.3em !important;
    }

    .quick-facts-table {
        font-size: 0.95em;
    }

    .quick-facts-table td {
        padding: 0.6rem 0.4rem !important;
        display: block;
        width: 100% !important;
    }

    .quick-facts-table tr {
        display: block;
        margin-bottom: 0.8rem;
        border-bottom: 1px solid rgba(0,0,0,0.1);
        padding-bottom: 0.8rem;
    }

    .quick-facts-table td:first-child {
        font-weight: bold;
        color: #FF6B6B;
        margin-bottom: 0.3rem;
    }

    /* Feature list (Cool Facts) - Mobile optimized */
    .feature-list li {
        padding: 1rem 0.8rem !important;
        margin-bottom: 1.2rem !important;
        border-left-width: 4px !important;
        font-size: 0.95em;
    }

    .feature-list li strong {
        display: block;
        margin-bottom: 0.5rem;
        font-size: 1.05em;
    }

    /* Main box - Mobile friendly */
    .main-box {
        width: 95% !important;
        padding: 1.5rem 1rem !important;
        border-radius: 8px !important;
    }

    /* Images - Responsive */
    img {
        max-width: 100% !important;
        height: auto !important;
        border-radius: 8px;
    }

    /* Tables - Responsive */
    table {
        font-size: 0.9em;
    }

    /* Ads - Mobile optimized */
    .ad-container {
        margin: 1.5rem 0 !important;
        padding: 1rem 0.5rem !important;
        border-radius: 8px !important;
    }

    .ad-label {
        font-size: 0.7em;
        margin-bottom: 0.8rem;
    }

    .ad-slot {
        min-height: 250px;
    }

    /* Hide sidebar ads on mobile */
    .ad-sidebar {
        display: none;
    }

    /* Back to top button - Mobile positioned */
    #back-to-top {
        width: 50px !important;
        height: 50px !important;
        font-size: 24px !important;
        bottom: 20px !important;
        right: 20px !important;
    }
}

/* ============================================
   SMALL PHONES: 320px - 374px
   ============================================ */

@media (max-width: 374px) {
    /* Extra small screens adjustments */
    .header-text {
        font-size: 9vw !important;
    }

    .header-subtext {
        font-size: 4.5vw !important;
    }

    .animal-page-content {
        padding: 1rem 0.8rem !important;
    }

    .page-title {
        font-size: 7vw !important;
    }

    .page-sub-titles {
        font-size: 6vw !important;
    }

    .feature-list li {
        padding: 0.8rem 0.6rem !important;
    }

    .quick-facts-box {
        padding: 1rem 0.8rem !important;
    }
}

/* ============================================
   STANDARD PHONES: 375px - 413px (iPhone, standard Android)
   ============================================ */

@media (min-width: 375px) and (max-width: 413px) {
    /* Optimized for iPhone 6/7/8, iPhone X, etc. */
    .header-text {
        font-size: 7.5vw !important;
    }

    .header-subtext {
        font-size: 4vw !important;
    }

    .animal-page-content {
        padding: 1.5rem 1rem !important;
    }
}

/* ============================================
   LARGE PHONES: 414px - 767px (iPhone Plus, large Android)
   ============================================ */

@media (min-width: 414px) and (max-width: 767px) {
    /* Optimized for larger phones */
    .header-text {
        font-size: 7vw !important;
    }

    .header-subtext {
        font-size: 3.5vw !important;
    }

    .animal-page-content {
        padding: 2rem 1.5rem !important;
    }

    .page-title {
        font-size: 5.5vw !important;
    }

    .page-sub-titles {
        font-size: 5vw !important;
    }
}

/* ============================================
   TABLETS: 768px - 1023px (iPad, Android tablets)
   ============================================ */

@media (min-width: 768px) and (max-width: 1023px) {
    /* Tablet optimization */
    .header-text {
        font-size: 5.5vw !important;
    }

    .header-subtext {
        font-size: 2.5vw !important;
    }

    .main-container {
        width: 95% !important;
        padding: 1.5rem 0 !important;
    }

    .animal-page-content {
        padding: 2rem !important;
        border-radius: 12px !important;
    }

    .page-title {
        font-size: 4vw !important;
        padding: 0.8rem !important;
    }

    .page-sub-titles {
        font-size: 3.5vw !important;
        padding: 0.7rem !important;
    }

    .quick-facts-box {
        max-width: 600px !important;
        margin: 2rem auto !important;
    }

    /* Two-column layout for tablets (landscape) */
    @media (orientation: landscape) {
        .feature-list {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1rem;
        }

        .feature-list li {
            margin-bottom: 0 !important;
        }
    }
}

/* ============================================
   SMALL LAPTOPS: 1024px - 1199px
   ============================================ */

@media (min-width: 1024px) and (max-width: 1199px) {
    .main-container {
        width: 90%;
    }

    .animal-page-content {
        padding: 2.5rem 2rem;
    }

    .header-text {
        font-size: 4.5vw !important;
    }

    .header-subtext {
        font-size: 2vw !important;
    }
}

/* ============================================
   DESKTOP: 1200px and up
   ============================================ */

@media (min-width: 1200px) {
    .main-container {
        width: 85%;
        max-width: 1200px;
    }

    .animal-page-content {
        padding: 3rem 2.5rem;
    }

    .header-text {
        font-size: 4vw !important;
        max-font-size: 3rem;
    }

    .header-subtext {
        font-size: 1.8vw !important;
        max-font-size: 1.3rem;
    }

    /* Grid layout for cool facts on large screens */
    .feature-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
    }

    .feature-list li {
        margin-bottom: 0 !important;
    }
}

/* ============================================
   MOBILE NAVIGATION ENHANCEMENTS
   ============================================ */

@media (max-width: 767px) {
    /* Mobile menu toggle - Always visible on mobile */
    .mobile-menu-toggle {
        display: block !important;
        margin: 1rem auto !important;
        width: 60px;
        height: 60px;
        font-size: 28px;
    }

    /* Hide desktop navigation on mobile */
    #top-menu-background nav:not(.mobile-menu-active) {
        display: none !important;
    }

    /* Mobile menu styling */
    #top-menu-background nav.mobile-menu-active {
        display: block !important;
        position: fixed;
        top: 0;
        left: 0;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        background: linear-gradient(135deg, #FF6B6B 0%, #4ECDC4 100%);
        z-index: 10000;
        overflow-y: auto;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
        padding: 2rem 1rem;
    }

    #top-menu-background nav.mobile-menu-active ul {
        display: flex !important;
        flex-direction: column;
        list-style: none;
        padding: 0;
        margin: 0;
    }

    #top-menu-background nav.mobile-menu-active li {
        width: 100% !important;
        float: none !important;
        margin: 0.5rem 0;
        border: none !important;
    }

    #top-menu-background nav.mobile-menu-active li a {
        display: block;
        padding: 1rem;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 8px;
        text-align: center;
        font-size: 18px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #top-menu-background nav.mobile-menu-active li a:hover,
    #top-menu-background nav.mobile-menu-active li a:active {
        background: rgba(255, 255, 255, 0.35);
        transform: translateX(8px);
    }

    /* Close button for mobile menu */
    #top-menu-background nav.mobile-menu-active::before {
        content: '✕';
        position: absolute;
        top: 1rem;
        right: 1rem;
        color: white;
        font-size: 32px;
        cursor: pointer;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 50%;
    }
}

/* ============================================
   TOUCH INTERACTIONS
   ============================================ */

/* Larger touch targets for mobile */
@media (max-width: 767px) {
    a, button, input, select, textarea {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects on touch devices */
    @media (hover: none) {
        .feature-list li:hover {
            transform: none;
        }

        nav li:hover {
            background: transparent;
        }
    }
}

/* ============================================
   MOBILE IMAGE OPTIMIZATION
   ============================================ */

@media (max-width: 767px) {
    img {
        /* Lazy loading optimization */
        loading: lazy;
        /* Prevent layout shift */
        aspect-ratio: attr(width) / attr(height);
    }

    /* Responsive images */
    img[width] {
        width: 100%;
        height: auto;
    }
}

/* ============================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ============================================ */

@media (max-width: 767px) {
    /* Reduce animations on mobile for better performance */
    * {
        animation-duration: 0.3s !important;
        transition-duration: 0.2s !important;
    }

    /* Disable parallax effects on mobile */
    body, html {
        background-attachment: scroll !important;
    }

    /* Reduce shadows on mobile for performance */
    .animal-page-content {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    }

    .main-box {
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12) !important;
    }
}

/* ============================================
   LANDSCAPE ORIENTATION FIXES
   ============================================ */

@media (max-width: 767px) and (orientation: landscape) {
    /* Reduce header size in landscape */
    .header-text {
        font-size: 5vh !important;
        padding: 0.3em 0.5em !important;
    }

    .header-subtext {
        font-size: 2.5vh !important;
    }

    #above-menu-background {
        padding: 0.5rem;
    }

    /* More compact spacing in landscape */
    .animal-page-content {
        padding: 1rem !important;
    }

    .page-title {
        padding: 0.6rem !important;
        margin-bottom: 0.8rem !important;
    }

    .page-sub-titles {
        padding: 0.5rem !important;
        margin-top: 1.5rem !important;
        margin-bottom: 0.8rem !important;
    }
}

/* ============================================
   SAFE AREAS (iPhone X+, Android with notches)
   ============================================ */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .mobile-menu-toggle {
        margin-left: max(1rem, env(safe-area-inset-left));
        margin-right: max(1rem, env(safe-area-inset-right));
    }

    #back-to-top {
        right: max(20px, calc(env(safe-area-inset-right) + 20px)) !important;
        bottom: max(20px, calc(env(safe-area-inset-bottom) + 20px)) !important;
    }
}

/* ============================================
   ACCESSIBILITY - MOBILE
   ============================================ */

@media (max-width: 767px) {
    /* Focus states for keyboard navigation on mobile */
    *:focus-visible {
        outline: 3px solid #FFE66D;
        outline-offset: 3px;
    }

    /* Skip to content link - Mobile positioned */
    .skip-to-content:focus {
        top: 10px;
        left: 10px;
        z-index: 100000;
    }
}

/* ============================================
   PRINT STYLES (Mobile-friendly)
   ============================================ */

@media print {
    @page {
        margin: 1cm;
    }

    body {
        font-size: 12pt;
        background: white !important;
    }

    .header-text,
    .header-subtext {
        background: none !important;
        text-shadow: none !important;
        color: black !important;
    }

    nav,
    .mobile-menu-toggle,
    .ad-container,
    #back-to-top {
        display: none !important;
    }

    .animal-page-content {
        box-shadow: none !important;
        background: white !important;
        padding: 0 !important;
    }
}
