/* Mobile-specific responsive design */
@media screen and (max-width: 768px) {
    /* Root Container - Prevent SPA Layout Shifts */
    body {
        font-size: 16px;
        min-height: 100vh;
    }

    /* Header Mobile Layout with height reservation */
    .site-header {
        padding: 0.5rem 0;
        min-height: 60px;
        contain: layout style;
    }

    .main-nav {
        flex-direction: column;
        align-items: center;
        padding: 0.5rem;
        gap: 0.5rem;
        min-height: 120px; /* Reserve space for navigation */
    }

    .logo {
        font-size: 1.3rem;
        margin-bottom: 0.5rem;
    }

    .nav-links {
        display: flex;
        flex-direction: column;
        width: 100%;
        align-items: center;
        gap: 1rem;
        margin-bottom: 0.5rem;
    }

    .nav-links > a {
        display: inline-block;
        width: auto;
        text-align: center;
        padding: 0.5rem;
        font-size: 0.9rem;
    }

    .nav-links > .nav-row {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 1rem;
        width: 100%;
    }

    .search-box {
        display: flex;
        flex-direction: row;
        width: 100%;
        justify-content: center;
        align-items: center;
        gap: 0.5rem;
    }

    .search-box input {
        flex-grow: 1;
        width: auto;
        min-width: 150px;
        padding: 0.5rem;
        font-size: 0.9rem;
    }

    .search-box button {
        width: auto;
        padding: 0.5rem;
        font-size: 0.9rem;
        min-width: 44px;
        min-height: 44px;
    }

    /* Navigation */
    .nav-links {
        flex-direction: column;
        width: 100%;
        align-items: center;
        gap: 1rem;
        margin-top: 1rem;
    }

    /* Main Content Layout with height reservations */
    .container {
        width: 100%;
        padding: 0 10px;
        min-height: 500px; /* Increased minimum height for content */
        contain: layout paint;
    }

    .main-content {
        width: 100%;
        padding: 0 10px;
        contain: layout style;
        min-height: 400px; /* Reserve space for dynamic content */
    }

    .main-content:not(.home) {
        display: flex;
        flex-direction: column;
        width: 100%;
        margin: 1rem 0;
        gap: 1rem;
        padding: 0 10px;
    }

    .content-area {
        width: 100%;
        padding: 0;
    }

    .sidebar {
        position: static;
        width: 100%;
        flex: 1 1 100%;
        order: 1; /* Ensure sidebar comes before content on mobile */
    }

    /* AdSense Optimization */
    ins.adsbygoogle {
        display: block !important;
        min-height: 250px; /* Reserve minimum space for ads */
        margin: 1rem 0;
        background: #f8f8f8; /* Light background while loading */
    }

    ins.adsbygoogle.adsbygoogle-noablate {
        position: relative !important;
        transform: none !important;
        height: auto !important;
        max-height: none !important;
    }

    /* Homepage Specific Mobile Layout */
    .main-content.home {
        display: flex;
        flex-direction: column;
        width: 95%;
        margin: 1rem auto;
        gap: 1rem;
    }

    .main-content.home .sidebar {
        order: 2; /* Move sidebar to the bottom */
        width: 100%;
    }

    .main-content.home .content-area {
        order: 1; /* Move content area to the top */
        width: 100%;
    }

    .main-content.home .greetings-list {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        width: 100%;
    }

    .main-content.home .greeting-card {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Individual Greetings Page Layout */
    .main-content:not(.home) {
        display: flex;
        flex-direction: column;
        width: 100%;
        margin: 1rem auto;
        gap: 1rem;
    }

    .main-content:not(.home) .sidebar {
        order: 2; /* Move sidebar to the bottom */
        width: 100%;
    }

    .main-content:not(.home) .content-area {
        order: 1; /* Keep main content at the top */
        width: 100%;
    }

    /* Categories Widget */
    .categories-widget {
        padding: 10px;
    }

    .categories-list .collapsible {
        padding: 12px 0;
        font-size: 16px;
        min-height: 44px;
        min-width: 44px;
    }

    /* Greetings and Cards */
    .greetings-list,
    .single-greeting-content {
        display: flex;
        flex-direction: column;
    }

    /* Greetings Cards with aspect ratio */
    .home .greetings-list {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .greeting-card {
        aspect-ratio: 16/9;
        contain: layout style;
        min-height: 200px;
        width: 100%;
        margin-bottom: 1rem;
        padding: 1rem;
        background-color: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .greeting-header {
        margin-bottom: 0.75rem;
    }

    .greeting-title {
        font-size: 1.2rem;
        margin-bottom: 0.5rem;
    }

    .greeting-meta {
        display: flex;
        justify-content: space-between;
        font-size: 0.9rem;
        color: #666;
        margin-bottom: 0.5rem;
    }

    .greeting-content {
        font-size: 1rem;
        line-height: 1.5;
        margin-bottom: 0.75rem;
        overflow-wrap: break-word;
    }

    .tags {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .tag {
        font-size: 0.8rem;
        background-color: #f0f0f0;
        padding: 0.25rem 0.5rem;
        border-radius: 15px;
        text-decoration: none;
        color: #333;
    }

    /* Image containers with aspect ratio */
    .image-container {
        position: relative;
        width: 100%;
        aspect-ratio: 16/9;
        background: #f8f8f8;
        overflow: hidden;
    }

    .image-container img {
        position: absolute;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    /* Font Loading Optimization */
    @font-face {
        font-family: 'Nunito';
        font-display: optional;
        src: local('Nunito');
    }

    /* Prevent text layout shifts */
    h1, h2, h3, h4, h5, h6, p {
        line-height: 1.5;
        overflow-wrap: break-word;
    }

    /* Responsive Typography */
    .logo {
        font-size: 1.3rem;
    }

    h1 {
        font-size: 1.8rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    /* Ensure no horizontal scrolling */
    * {
        max-width: 100%;
        overflow-x: hidden;
    }
}

/* Mobile Touch Improvements */
@media (pointer: coarse) {
    .nav-links a,
    .search-box button,
    .categories-list .collapsible {
        min-height: 44px;
        min-width: 44px;
    }
}
