/**
 * Mobile-First Enhancements for AITutorials.site
 * Comprehensive responsive improvements for mobile, tablet, and desktop
 */

/* ===================================
   GLOBAL MOBILE OPTIMIZATIONS
   =================================== */

/* Better touch targets for mobile (minimum 44x44px) */
@media (max-width: 768px) {
    button, 
    .btn, 
    a.btn, 
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 0.75rem 1.25rem;
    }
    
    /* Links in text should have more padding for easier tapping */
    .tutorial-content a,
    .content-section a {
        padding: 0.125rem 0.25rem;
        margin: -0.125rem -0.25rem;
    }
}

/* Prevent horizontal scroll on small screens */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Better text sizing for mobile readability */
@media (max-width: 768px) {
    body {
        font-size: 16px; /* Minimum 16px to prevent iOS zoom on focus */
        line-height: 1.6;
    }
    
    h1 {
        font-size: 2rem;
        line-height: 1.2;
    }
    
    h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 1.25rem;
        line-height: 1.4;
    }
    
    p {
        font-size: 1rem;
        line-height: 1.6;
    }
}

/* ===================================
   IMPROVED CONTAINER PADDING
   =================================== */

@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 0.75rem;
    }
}

/* ===================================
   HERO SECTION MOBILE IMPROVEMENTS
   =================================== */

@media (max-width: 768px) {
    .hero {
        padding: 2.5rem 0 3rem 0;
        text-align: center;
    }
    
    .hero-title {
        font-size: 2rem;
        line-height: 1.2;
        margin-bottom: 1rem;
    }
    
    .hero-subtitle {
        font-size: 1rem;
        line-height: 1.6;
        margin-bottom: 1.5rem;
    }
    
    .hero-buttons {
        flex-direction: column;
        gap: 0.75rem;
        width: 100%;
    }
    
    .hero-buttons .btn {
        width: 100%;
        max-width: 300px;
        margin: 0 auto;
    }
    
    .hero-stats {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 1rem;
        justify-content: center;
        margin-top: 2rem;
    }
    
    .stat-item {
        flex: 0 1 auto;
        min-width: 80px;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: 1.75rem;
    }
    
    .hero-badge {
        font-size: 0.875rem;
        padding: 0.375rem 0.75rem;
    }
}

/* ===================================
   COURSE CARDS - MOBILE GRID
   =================================== */

@media (max-width: 768px) {
    .topics-grid,
    .course-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .topic-card,
    .course-card {
        padding: 1.25rem;
    }
    
    .topic-icon {
        font-size: 2rem;
        width: 48px;
        height: 48px;
    }
    
    .course-meta {
        flex-wrap: wrap;
        gap: 0.5rem;
        font-size: 0.875rem;
    }
}

/* ===================================
   NAVIGATION - IMPROVED MOBILE MENU
   =================================== */

@media (max-width: 768px) {
    .nav-container {
        padding: 0 1rem;
        height: 64px;
    }
    
    .nav-menu {
        top: 64px;
        height: calc(100vh - 64px);
        padding: 1.5rem 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Better touch targets in mobile menu */
    .nav-link {
        font-size: 1.0625rem;
        padding: 1rem;
        border-radius: 8px;
    }
    
    /* Dark mode toggle in mobile menu */
    .theme-toggle-mobile {
        margin-top: auto;
        padding-top: 2rem;
        border-top: 1px solid var(--border-color);
    }
}

/* ===================================
   TUTORIAL PAGES - MOBILE OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    .tutorial-header {
        padding: 1.5rem 0;
    }
    
    .tutorial-breadcrumb {
        font-size: 0.875rem;
        flex-wrap: wrap;
    }
    
    .tutorial-title {
        font-size: 1.75rem;
        line-height: 1.3;
        margin: 1rem 0;
    }
    
    .tutorial-content {
        padding: 1.5rem 1rem;
        font-size: 1rem;
        line-height: 1.7;
    }
    
    /* Better code block display on mobile */
    .tutorial-content pre {
        margin: 1.5rem -1rem;
        padding: 1rem;
        border-radius: 0;
        font-size: 0.875rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .tutorial-content pre code {
        font-size: 0.8125rem;
    }
    
    /* Info boxes should be more prominent on mobile */
    .info-box,
    .warning-box,
    .success-box {
        margin: 1.5rem -1rem;
        padding: 1rem;
        border-radius: 0;
        font-size: 0.9375rem;
    }
    
    /* Images should be responsive */
    .tutorial-content img {
        max-width: 100%;
        height: auto;
        margin: 1.5rem 0;
        border-radius: 8px;
    }
}

/* ===================================
   TABLES - MOBILE SCROLL
   =================================== */

@media (max-width: 768px) {
    .tutorial-content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        margin: 1.5rem -1rem;
        width: calc(100% + 2rem);
    }
    
    .tutorial-content table th,
    .tutorial-content table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.875rem;
    }
}

/* ===================================
   BUTTONS - MOBILE FRIENDLY
   =================================== */

@media (max-width: 768px) {
    .btn-primary,
    .btn-outline,
    .btn-secondary {
        font-size: 1rem;
        padding: 0.875rem 1.5rem;
        width: 100%;
        text-align: center;
    }
    
    /* Side-by-side buttons on mobile */
    .tutorial-navigation {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .tutorial-navigation .btn {
        width: 100%;
    }
}

/* ===================================
   FORMS - MOBILE OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px; /* Prevent iOS zoom */
        padding: 0.75rem 1rem;
        width: 100%;
    }
    
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    label {
        font-size: 0.9375rem;
        margin-bottom: 0.5rem;
        display: block;
    }
}

/* ===================================
   CERTIFICATE FORMS - MOBILE
   =================================== */

@media (max-width: 768px) {
    .certificate-section {
        padding: 2rem 1.25rem;
        margin: 2rem 0;
        border-radius: 12px;
    }
    
    .certificate-icon {
        font-size: 3rem;
    }
    
    .certificate-section h2 {
        font-size: 1.5rem;
    }
    
    .certificate-form {
        padding: 1.25rem;
    }
    
    .submit-button {
        width: 100%;
        padding: 1rem;
        font-size: 1.0625rem;
    }
}

/* ===================================
   QUIZ CONTAINERS - MOBILE
   =================================== */

@media (max-width: 768px) {
    .quiz-container {
        padding: 1.25rem;
        margin: 1.5rem 0;
    }
    
    .quiz-question {
        font-size: 1rem;
        margin-bottom: 1rem;
    }
    
    .quiz-option {
        padding: 0.875rem 1rem;
        font-size: 0.9375rem;
        margin-bottom: 0.75rem;
    }
}

/* ===================================
   FOOTER - MOBILE STACK
   =================================== */

@media (max-width: 768px) {
    .footer {
        padding: 2.5rem 0 2rem;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 2rem;
        text-align: center;
    }
    
    .footer-section {
        width: 100%;
        max-width: 100%;
    }
    
    .footer-links {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
    }
    
    .social-links {
        justify-content: center;
    }
}

/* ===================================
   SEARCH BAR - MOBILE
   =================================== */

@media (max-width: 768px) {
    .search-container {
        width: 100%;
        margin: 1rem 0;
    }
    
    .search-input {
        font-size: 16px;
        padding: 0.875rem 1rem;
        width: 100%;
    }
}

/* ===================================
   MODALS - MOBILE FULL SCREEN
   =================================== */

@media (max-width: 768px) {
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        padding: 1.5rem 1rem;
    }
    
    .modal-header {
        margin-bottom: 1.5rem;
    }
    
    .modal-close {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
    }
}

/* ===================================
   TOOLTIPS - MOBILE HIDDEN
   =================================== */

@media (max-width: 768px) {
    .tooltip {
        display: none; /* Tooltips don't work well on touch devices */
    }
}

/* ===================================
   SPACING - MOBILE REDUCTIONS
   =================================== */

@media (max-width: 768px) {
    section {
        padding: 2.5rem 0;
    }
    
    .section-title {
        font-size: 1.75rem;
        margin-bottom: 1rem;
    }
    
    .section-subtitle {
        font-size: 1rem;
        margin-bottom: 2rem;
    }
}

@media (max-width: 480px) {
    section {
        padding: 2rem 0;
    }
    
    .section-title {
        font-size: 1.5rem;
    }
}

/* ===================================
   LANDSCAPE MODE FIXES
   =================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .hero {
        padding: 2rem 0;
    }
    
    .hero-title {
        font-size: 1.75rem;
    }
    
    .nav-menu {
        height: 100vh;
    }
}

/* ===================================
   SMALL PHONE OPTIMIZATIONS (iPhone SE)
   =================================== */

@media (max-width: 375px) {
    body {
        font-size: 15px;
    }
    
    .container {
        padding: 0 0.875rem;
    }
    
    .hero-title {
        font-size: 1.625rem;
    }
    
    .btn {
        font-size: 0.9375rem;
        padding: 0.75rem 1.25rem;
    }
    
    .topic-card,
    .course-card {
        padding: 1rem;
    }
    
    .tutorial-content {
        padding: 1rem 0.875rem;
    }
}

/* ===================================
   TABLET LANDSCAPE OPTIMIZATIONS
   =================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 720px;
    }
    
    .topics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.25rem;
    }
    
    .hero-title {
        font-size: 2.5rem;
    }
}

/* ===================================
   LARGE SCREENS - CONSTRAIN WIDTH
   =================================== */

@media (min-width: 1400px) {
    .container {
        max-width: 1280px;
    }
    
    .tutorial-content {
        max-width: 820px;
        margin: 0 auto;
    }
}

/* ===================================
   PERFORMANCE - REDUCE MOTION
   =================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===================================
   PRINT STYLES
   =================================== */

@media print {
    .navbar,
    .hamburger,
    .hero-buttons,
    .footer,
    .tutorial-navigation,
    .social-share,
    .emoji-reactions,
    .certificate-section,
    .aitutor-widget {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.6;
        color: #000;
        background: #fff;
    }
    
    .tutorial-content {
        max-width: 100%;
        padding: 0;
    }
    
    pre, code {
        border: 1px solid #000;
        page-break-inside: avoid;
    }
    
    h1, h2, h3 {
        page-break-after: avoid;
    }
}

/* ===================================
   ACCESSIBILITY - FOCUS STATES
   =================================== */

@media (max-width: 768px) {
    *:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
    
    button:focus,
    a:focus,
    input:focus,
    textarea:focus,
    select:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
}

/* ===================================
   SAFE AREAS - iOS NOTCH SUPPORT
   =================================== */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .navbar {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .nav-menu {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}
