/* Mobile Enhancements and Touch Interactions */

/* Touch-friendly button sizes */
@media (max-width: 768px) {
    button,
    .btn,
    a[role="button"],
    input[type="submit"],
    input[type="button"] {
        min-height: 48px;
        min-width: 48px;
        padding: 12px 16px;
    }

    /* Larger touch targets for important actions */
    .btn-primary,
    .btn-success,
    .btn-danger {
        min-height: 56px;
        padding: 16px 24px;
    }
}

/* Mobile-friendly form inputs */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 16px !important;
        min-height: 48px;
        border-radius: 8px;
    }

    /* Better mobile form spacing */
    .form-group {
        margin-bottom: 20px;
    }

    .form-label {
        margin-bottom: 8px;
        font-size: 16px;
        font-weight: 600;
    }
}

/* Mobile Dropdown Menu Enhancements */
@media (max-width: 768px) {
    #mobileUserMenu {
        position: fixed;
        top: 60px;
        right: 16px;
        left: 16px;
        width: auto;
        max-width: 300px;
        margin-left: auto;
        margin-right: 0;
        border-radius: 12px;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
        border: 1px solid rgba(0, 0, 0, 0.1);
        background: white;
        z-index: 1001;
    }

    #mobileUserMenu a,
    #mobileUserMenu button {
        padding: 16px 20px;
        font-size: 16px;
        border-bottom: 1px solid #f3f4f6;
    }

    #mobileUserMenu a:last-child,
    #mobileUserMenu button:last-child {
        border-bottom: none;
    }

    #mobileUserMenu a:hover,
    #mobileUserMenu button:hover {
        background-color: #f9fafb;
    }

    /* Mobile menu button */
    #mobileUserMenuBtn {
        min-height: 48px;
        min-width: 48px;
        padding: 12px;
        border-radius: 8px;
    }

    #mobileUserMenuBtn:active {
        background-color: rgba(255, 255, 255, 0.2);
        transform: scale(0.95);
    }
}

/* Mobile-optimized tables */
@media (max-width: 768px) {
    .table-responsive {
        margin: 0 -16px;
        border-radius: 0;
    }

    .table-responsive table {
        font-size: 14px;
    }

    .table-responsive th,
    .table-responsive td {
        padding: 12px 8px;
        white-space: nowrap;
    }

    /* Stack table data on very small screens */
    @media (max-width: 480px) {
        .table-responsive table,
        .table-responsive thead,
        .table-responsive tbody,
        .table-responsive th,
        .table-responsive td,
        .table-responsive tr {
            display: block;
        }

        .table-responsive thead tr {
            position: absolute;
            top: -9999px;
            left: -9999px;
        }

        .table-responsive tr {
            border: 1px solid #e5e7eb;
            margin-bottom: 16px;
            border-radius: 8px;
            padding: 16px;
            background: white;
        }

        .table-responsive td {
            border: none;
            position: relative;
            padding-left: 50%;
            text-align: left;
            margin-bottom: 8px;
        }

        .table-responsive td:before {
            content: attr(data-label) ": ";
            position: absolute;
            left: 16px;
            width: 45%;
            font-weight: 600;
            color: #374151;
        }
    }
}

/* Mobile-optimized cards */
@media (max-width: 768px) {
    .card {
        margin: 8px 0;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .card-header {
        padding: 20px 20px 16px;
    }

    .card-body {
        padding: 16px 20px;
    }

    .card-footer {
        padding: 16px 20px 20px;
    }
}

/* Mobile-optimized modals */
@media (max-width: 768px) {
    .modal {
        padding: 16px;
    }

    .modal-content {
        width: 100%;
        max-height: calc(100vh - 32px);
        border-radius: 16px;
        padding: 24px 20px;
    }

    .modal-header {
        padding-bottom: 16px;
        margin-bottom: 20px;
        border-bottom: 1px solid #e5e7eb;
    }

    .modal-body {
        padding: 0;
        margin-bottom: 24px;
    }

    .modal-footer {
        padding-top: 16px;
        border-top: 1px solid #e5e7eb;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
}

/* Mobile-optimized navigation */
@media (max-width: 768px) {
    /* Mobile header */
    .mobile-header {
        padding: 16px;
        background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    }

    /* Mobile menu */
    .mobile-menu {
        position: fixed;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100vh;
        background: white;
        z-index: 1000;
        transition: left 0.3s ease;
        overflow-y: auto;
        padding-top: env(safe-area-inset-top);
    }

    .mobile-menu.open {
        left: 0;
    }

    .mobile-menu-header {
        padding: 20px;
        border-bottom: 1px solid #e5e7eb;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .mobile-menu-close {
        background: none;
        border: none;
        font-size: 24px;
        color: #6b7280;
        padding: 8px;
        border-radius: 8px;
        cursor: pointer;
    }

    .mobile-menu-nav {
        padding: 20px;
    }

    .mobile-menu-nav a {
        display: block;
        padding: 16px 20px;
        color: #374151;
        text-decoration: none;
        border-radius: 12px;
        margin-bottom: 8px;
        transition: all 0.2s ease;
    }

    .mobile-menu-nav a:hover,
    .mobile-menu-nav a.active {
        background: rgba(59, 130, 246, 0.1);
        color: #2563eb;
    }
}

/* Mobile-optimized game elements */
@media (max-width: 768px) {
    .game-container {
        padding: 16px;
    }

    .game-header {
        text-align: center;
        margin-bottom: 24px;
    }

    .game-title {
        font-size: 24px;
        font-weight: 700;
        margin-bottom: 8px;
    }

    .game-description {
        font-size: 16px;
        color: #6b7280;
        line-height: 1.5;
    }

    .game-controls {
        display: flex;
        flex-direction: column;
        gap: 16px;
        margin-bottom: 24px;
    }

    .game-controls .btn {
        width: 100%;
        justify-content: center;
    }

    .game-content {
        background: white;
        border-radius: 16px;
        padding: 24px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        margin-bottom: 24px;
    }
}

/* Mobile-optimized flash cards */
@media (max-width: 768px) {
    .flash-card-container {
        padding: 16px;
    }

    .flash-card {
        width: 100%;
        max-width: 100%;
        aspect-ratio: 4/5;
        margin: 0 auto 24px;
    }

    .flash-card-front,
    .flash-card-back {
        border-radius: 16px;
        padding: 32px 24px;
        font-size: 18px;
        line-height: 1.6;
    }

    .flash-card-controls {
        display: flex;
        gap: 16px;
        justify-content: center;
        margin-top: 24px;
    }

    .flash-card-controls .btn {
        min-width: 120px;
        padding: 16px 24px;
    }
}

/* Mobile-optimized quiz elements */
@media (max-width: 768px) {
    .quiz-container {
        padding: 16px;
    }

    .quiz-question {
        background: white;
        border-radius: 16px;
        padding: 24px;
        margin-bottom: 24px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    .quiz-question-text {
        font-size: 18px;
        font-weight: 600;
        margin-bottom: 20px;
        line-height: 1.5;
    }

    .quiz-options {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .quiz-option {
        padding: 16px 20px;
        border: 2px solid #e5e7eb;
        border-radius: 12px;
        background: white;
        cursor: pointer;
        transition: all 0.2s ease;
        text-align: left;
        font-size: 16px;
        line-height: 1.4;
    }

    .quiz-option:hover {
        border-color: #3b82f6;
        background: rgba(59, 130, 246, 0.05);
    }

    .quiz-option.selected {
        border-color: #3b82f6;
        background: rgba(59, 130, 246, 0.1);
        color: #2563eb;
    }

    .quiz-option.correct {
        border-color: #10b981;
        background: rgba(16, 185, 129, 0.1);
        color: #065f46;
    }

    .quiz-option.incorrect {
        border-color: #ef4444;
        background: rgba(239, 68, 68, 0.1);
        color: #991b1b;
    }
}

/* Mobile-optimized progress indicators */
@media (max-width: 768px) {
    .progress-bar {
        width: 100%;
        height: 8px;
        background: #e5e7eb;
        border-radius: 4px;
        overflow: hidden;
        margin: 16px 0;
    }

    .progress-fill {
        height: 100%;
        background: linear-gradient(90deg, #3b82f6, #1d4ed8);
        border-radius: 4px;
        transition: width 0.3s ease;
    }

    .progress-text {
        text-align: center;
        font-size: 14px;
        color: #6b7280;
        margin-bottom: 8px;
    }
}

/* Mobile-optimized notifications */
@media (max-width: 768px) {
    .notification {
        position: fixed;
        top: 16px;
        left: 16px;
        right: 16px;
        background: white;
        border-radius: 12px;
        padding: 20px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
        z-index: 1001;
        transform: translateY(-100%);
        transition: transform 0.3s ease;
    }

    .notification.show {
        transform: translateY(0);
    }

    .notification.success {
        border-left: 4px solid #10b981;
    }

    .notification.error {
        border-left: 4px solid #ef4444;
    }

    .notification.warning {
        border-left: 4px solid #f59e0b;
    }

    .notification.info {
        border-left: 4px solid #3b82f6;
    }
}

/* Mobile-optimized loading states */
@media (max-width: 768px) {
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(255, 255, 255, 0.9);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1002;
    }

    .loading-spinner {
        width: 48px;
        height: 48px;
        border: 4px solid #e5e7eb;
        border-top: 4px solid #3b82f6;
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }

    .loading-text {
        margin-top: 16px;
        font-size: 16px;
        color: #6b7280;
        text-align: center;
    }
}

/* Mobile-optimized animations */
@media (max-width: 768px) {
    @keyframes slideInFromBottom {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    @keyframes slideInFromRight {
        from {
            transform: translateX(100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }

    .slide-in-bottom {
        animation: slideInFromBottom 0.3s ease-out;
    }

    .slide-in-right {
        animation: slideInFromRight 0.3s ease-out;
    }
}

/* Mobile-optimized accessibility */
@media (max-width: 768px) {
    /* Focus indicators for touch devices */
    .btn:focus,
    a:focus,
    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid #3b82f6;
        outline-offset: 2px;
    }

    /* Skip links for screen readers */
    .skip-link {
        position: absolute;
        top: -40px;
        left: 6px;
        background: #3b82f6;
        color: white;
        padding: 8px;
        text-decoration: none;
        border-radius: 4px;
        z-index: 1003;
    }

    .skip-link:focus {
        top: 6px;
    }
}

/* Mobile-optimized performance */
@media (max-width: 768px) {
    /* Reduce animations on low-end devices */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }

    /* Optimize for touch scrolling */
    .scroll-container {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Reduce repaints */
    .transform-layer {
        transform: translateZ(0);
        will-change: transform;
    }
}
