/**
 * Mobile Landing Page Fixes
 * Comprehensive mobile responsiveness for Matrix Board Game Manager
 */

/* === MOBILE CONTAINER FIXES === */
@media (max-width: 768px) {
    /* Force proper container sizing on mobile */
    .container-matrix,
    .max-w-6xl,
    .max-w-4xl {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 auto !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    
    /* Fix text overflow issues */
    * {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        box-sizing: border-box !important;
    }
    
    /* Hero section mobile fixes */
    .min-h-screen {
        min-height: auto !important;
        padding: 2rem 0 !important;
    }
    
    /* Grid system mobile fixes */
    .grid {
        display: block !important;
        width: 100% !important;
    }
    
    .grid > * {
        margin-bottom: 1.5rem !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .grid > *:last-child {
        margin-bottom: 0 !important;
    }
    
    /* Terminal window mobile fixes */
    .terminal-window {
        width: 100% !important;
        max-width: 100% !important;
        margin: 1rem 0 !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }
    
    .terminal-body {
        padding: 1rem !important;
        font-size: 0.875rem !important;
        line-height: 1.4 !important;
        word-break: break-word !important;
    }
    
    .terminal-header {
        padding: 0.5rem !important;
        font-size: 0.75rem !important;
        text-align: center !important;
    }
    
    /* Typography mobile fixes */
    h1, .text-4xl, .text-5xl {
        font-size: 1.875rem !important;
        line-height: 1.2 !important;
        margin-bottom: 1rem !important;
        word-break: break-word !important;
    }
    
    h2, .text-3xl {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0.875rem !important;
        word-break: break-word !important;
    }
    
    h3, .text-2xl {
        font-size: 1.25rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0.75rem !important;
        word-break: break-word !important;
    }
    
    p, .text-lg, .text-base {
        font-size: 0.9375rem !important;
        line-height: 1.5 !important;
        margin-bottom: 1rem !important;
        word-break: break-word !important;
    }
    
    .text-sm {
        font-size: 0.8125rem !important;
        line-height: 1.4 !important;
    }
    
    .text-xs {
        font-size: 0.75rem !important;
        line-height: 1.3 !important;
    }
    
    /* Button mobile fixes */
    .btn-matrix-primary,
    .btn-matrix-secondary {
        width: 100% !important;
        padding: 1rem 1.5rem !important;
        font-size: 0.9375rem !important;
        margin-bottom: 0.75rem !important;
        min-height: 48px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-sizing: border-box !important;
    }
    
    .btn-group,
    .flex.space-x-6,
    .flex.gap-6 {
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.75rem !important;
        align-items: stretch !important;
    }
    
    /* Section spacing mobile fixes */
    .py-20 {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
    }
    
    .py-16 {
        padding-top: 2.5rem !important;
        padding-bottom: 2.5rem !important;
    }
    
    .py-12 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
    
    .px-4,
    .px-6,
    .px-8 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    /* Card mobile fixes */
    .card-matrix,
    .card-matrix-glow {
        margin: 1rem 0 !important;
        padding: 1.5rem 1rem !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Stats grid mobile fixes */
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4,
    .lg\\:grid-cols-2,
    .lg\\:grid-cols-3,
    .lg\\:grid-cols-4 {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    .card-stats-matrix {
        padding: 1.25rem !important;
        text-align: center !important;
        width: 100% !important;
        margin-bottom: 1rem !important;
    }
    
    .card-stats-matrix-value {
        font-size: 1.5rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    .card-stats-matrix-label {
        font-size: 0.75rem !important;
        line-height: 1.3 !important;
    }
    
    /* Feature cards mobile fixes */
    .feature-card {
        padding: 1.5rem 1rem !important;
        margin-bottom: 1rem !important;
        width: 100% !important;
        text-align: center !important;
    }
    
    .feature-title {
        font-size: 1.125rem !important;
        margin-bottom: 0.75rem !important;
    }
    
    .feature-description {
        font-size: 0.875rem !important;
        line-height: 1.5 !important;
    }
    
    /* Space utilities mobile override */
    .space-y-8 > * + * {
        margin-top: 1.5rem !important;
    }
    
    .space-y-12 > * + * {
        margin-top: 2rem !important;
    }
    
    .space-y-16 > * + * {
        margin-top: 2.5rem !important;
    }
    
    /* Prevent horizontal scrolling and fix footer positioning */
    body, html {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        height: 100% !important;
        min-height: 100vh !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Force navigation to absolute top */
    header.nav-matrix-unified {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1000 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Adjust body to account for fixed header and flex layout */
    body {
        padding-top: 40px !important;
        display: flex !important;
        flex-direction: column !important;
        min-height: 100vh !important;
    }
    
    main {
        padding-top: 0 !important;
        margin-top: 0 !important;
        flex: 1 !important;
        min-height: 0 !important;
    }
    
    footer {
        flex-shrink: 0 !important;
        margin-top: auto !important;
        position: relative !important;
        z-index: 100 !important;
        background: rgba(0, 0, 0, 0.95) !important;
        width: 100% !important;
        bottom: 0 !important;
        margin-bottom: 0 !important;
        padding-bottom: 0 !important;
    }
    
    /* Ensure footer touches the very bottom */
    footer .container-matrix {
        margin-bottom: 0 !important;
        padding-bottom: 0.5rem !important;
    }
    
    /* Fix Matrix background canvas positioning */
    #matrix-canvas,
    .matrix-bg-animation,
    canvas {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        z-index: -10 !important;
        pointer-events: none !important;
        overflow: hidden !important;
    }
    
    /* Prevent Matrix canvas from extending beyond viewport */
    body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    html {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        height: 100% !important;
    }
    
    /* Ensure content doesn't extend below viewport */
    .min-h-screen {
        min-height: auto !important;
        height: auto !important;
        max-height: none !important;
        padding: 2rem 0 !important;
    }
    
    .overflow-hidden {
        overflow: hidden !important;
    }
    
    /* Image mobile fixes */
    img {
        max-width: 100% !important;
        height: auto !important;
        display: block !important;
    }
    
    /* Table mobile fixes */
    .table-matrix {
        font-size: 0.75rem !important;
        overflow-x: auto !important;
        display: block !important;
        white-space: nowrap !important;
    }
    
    .table-matrix th,
    .table-matrix td {
        padding: 0.5rem 0.25rem !important;
        font-size: 0.75rem !important;
    }
}

/* === EXTRA SMALL MOBILE (320px and below) === */
@media (max-width: 480px) {
    .container-matrix,
    .max-w-6xl,
    .max-w-4xl {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
    
    h1, .text-4xl, .text-5xl {
        font-size: 1.625rem !important;
    }
    
    h2, .text-3xl {
        font-size: 1.375rem !important;
    }
    
    .terminal-body {
        padding: 0.75rem !important;
        font-size: 0.8125rem !important;
    }
    
    .btn-matrix-primary,
    .btn-matrix-secondary {
        padding: 0.875rem 1rem !important;
        font-size: 0.875rem !important;
    }
    
    .card-matrix,
    .card-matrix-glow {
        padding: 1rem 0.75rem !important;
    }
    
    .py-20 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
}

/* === LANDSCAPE PHONE FIXES === */
@media (max-height: 500px) and (orientation: landscape) {
    .min-h-screen {
        min-height: auto !important;
        height: auto !important;
        padding: 1rem 0 !important;
    }
    
    .py-20,
    .py-16,
    .py-12 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
}

/* === TOUCH TARGET IMPROVEMENTS === */
@media (max-width: 768px) {
    /* Ensure touch targets are at least 44px */
    a, button, input, select, textarea {
        min-height: 44px !important;
        min-width: 44px !important;
        touch-action: manipulation !important;
    }
    
    /* Prevent zoom on form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Mobile checkbox styling fixes */
    input[type="checkbox"] {
        width: 20px !important;
        height: 20px !important;
        min-width: 20px !important;
        min-height: 20px !important;
        border: 2px solid rgba(0, 255, 65, 0.4) !important;
        border-radius: 4px !important;
        background: rgba(0, 0, 0, 0.9) !important;
        appearance: none !important;
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        position: relative !important;
        cursor: pointer !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    input[type="checkbox"]:checked {
        background: rgba(0, 255, 65, 0.2) !important;
        border-color: var(--matrix-green) !important;
    }
    
    input[type="checkbox"]:checked::after {
        content: '✓' !important;
        color: var(--matrix-green) !important;
        font-size: 14px !important;
        font-weight: bold !important;
        line-height: 1 !important;
    }
    
    input[type="checkbox"]:focus {
        outline: 2px solid rgba(0, 255, 65, 0.5) !important;
        outline-offset: 2px !important;
        box-shadow: 0 0 8px rgba(0, 255, 65, 0.3) !important;
    }
    
    /* Checkbox label spacing on mobile */
    .flex.items-center.space-x-3 {
        gap: 0.75rem !important;
        align-items: center !important;
        margin: 1rem 0 !important;
    }
    
    /* Remember me label styling for mobile */
    label[for="id_remember_me"] {
        font-size: 0.9375rem !important;
        line-height: 1.4 !important;
        cursor: pointer !important;
        user-select: none !important;
        touch-action: manipulation !important;
    }
    
    /* Contact form checkbox styling - mobile */
    /* Target all checkboxes in contact forms */
    #demoSchedulerForm input[type="checkbox"],
    .checkbox-matrix-group input[type="checkbox"] {
        width: 18px !important;
        height: 18px !important;
        min-width: 18px !important;
        min-height: 18px !important;
        margin-right: 0.5rem !important;
        border: 2px solid rgba(0, 255, 65, 0.4) !important;
        border-radius: 3px !important;
        background: rgba(0, 0, 0, 0.9) !important;
        appearance: none !important;
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        position: relative !important;
        cursor: pointer !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }
    
    #demoSchedulerForm input[type="checkbox"]:checked,
    .checkbox-matrix-group input[type="checkbox"]:checked {
        background: rgba(0, 255, 65, 0.2) !important;
        border-color: var(--matrix-green) !important;
    }
    
    #demoSchedulerForm input[type="checkbox"]:checked::after,
    .checkbox-matrix-group input[type="checkbox"]:checked::after {
        content: '✓' !important;
        color: var(--matrix-green) !important;
        font-size: 12px !important;
        font-weight: bold !important;
        line-height: 1 !important;
    }
    
    #demoSchedulerForm input[type="checkbox"]:focus,
    .checkbox-matrix-group input[type="checkbox"]:focus {
        outline: 2px solid rgba(0, 255, 65, 0.5) !important;
        outline-offset: 2px !important;
        box-shadow: 0 0 8px rgba(0, 255, 65, 0.3) !important;
    }
    
    /* Contact form checkbox labels - mobile */
    #demoSchedulerForm label,
    .checkbox-matrix-group label {
        font-size: 0.875rem !important;
        line-height: 1.4 !important;
        cursor: pointer !important;
        user-select: none !important;
        display: flex !important;
        align-items: center !important;
        margin-bottom: 0.5rem !important;
        padding: 0.25rem 0 !important;
        color: rgba(0, 255, 65, 0.9) !important;
        font-family: 'Courier New', monospace !important;
    }
}