/* Responsive Design for Learning Difficulties Application */
/* التصميم المتجاوب لتطبيق صعوبات التعلم */

/* Base responsive breakpoints */
/* نقاط التوقف الأساسية للتصميم المتجاوب */

/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {
    
    /* Base font size adjustments */
    html {
        font-size: 14px;
    }
    
    /* Header adjustments */
    .app-header {
        padding: 12px;
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .logo {
        order: 1;
        justify-content: center;
    }
    
    .logo h1 {
        font-size: 1.3rem;
    }
    
    .logo i {
        font-size: 1.8rem;
    }
    
    .user-info {
        font-size: 0.85rem;
        order: 2;
        justify-content: center;
    }
    
    .settings-btn {
        order: 3;
        align-self: center;
    }
    
    /* Welcome section */
    .welcome-section {
        padding: 15px 10px;
    }
    
    .welcome-card {
        padding: 18px;
        margin: 10px;
        border-radius: 20px;
    }
    
    .welcome-card h2 {
        font-size: 1.4rem;
        margin-bottom: 15px;
    }
    
    .welcome-card p {
        font-size: 0.95rem;
        line-height: 1.5;
    }
    
    .progress-overview {
        flex-direction: column;
        gap: 12px;
        align-items: center;
    }
    
    .level-display, .points-display {
        padding: 10px 18px;
        font-size: 0.95rem;
        min-width: 120px;
        text-align: center;
    }
    
    /* Activities section */
    .activities-section {
        padding: 18px 12px;
    }
    
    .activities-section h2 {
        font-size: 1.4rem;
        margin-bottom: 25px;
    }
    
    .activity-category {
        margin-bottom: 30px;
    }
    
    .activity-category h3 {
        font-size: 1.1rem;
        padding: 8px 12px;
        margin-bottom: 15px;
    }
    
    .activities-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .activity-card {
        padding: 18px;
        margin-bottom: 12px;
        border-radius: 18px;
    }
    
    .activity-icon {
        width: 65px;
        height: 65px;
        font-size: 1.8rem;
        margin-bottom: 15px;
    }
    
    .activity-card h4 {
        font-size: 1.05rem;
        margin-bottom: 8px;
    }
    
    .activity-card p {
        font-size: 0.85rem;
        line-height: 1.4;
        margin-bottom: 12px;
    }
    
    .level-badge {
        padding: 4px 12px;
        font-size: 0.8rem;
    }
    
    /* Progress section */
    .progress-section {
        padding: 20px 15px;
    }
    
    .progress-card {
        padding: 20px;
    }
    
    .progress-stats {
        flex-direction: column;
        gap: 15px;
    }
    
    .stat i {
        font-size: 1.5rem;
    }
    
    .stat span {
        font-size: 1.2rem;
    }
    
    /* Game interface */
    .game-header {
        padding: 15px;
    }
    
    .game-nav h1 {
        font-size: 1.4rem;
    }
    
    .game-stats {
        gap: 15px;
    }
    
    .game-stats .stat {
        padding: 10px 15px;
        min-width: 70px;
    }
    
    .game-stats .stat i {
        font-size: 1.2rem;
    }
    
    .game-stats .stat span {
        font-size: 1rem;
    }
    
    .game-stats .stat small {
        font-size: 0.7rem;
    }
    
    .game-board {
        padding: 20px 15px;
    }
    
    .level-info h2 {
        font-size: 1.4rem;
    }
    
    .level-info p {
        font-size: 1rem;
    }
    
    /* Modal adjustments */
    .modal-content {
        width: 95%;
        margin: 10% auto;
    }
    
    .modal-header {
        padding: 15px;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .success-stats {
        flex-direction: column;
        gap: 10px;
    }
    
    .success-actions {
        flex-direction: column;
        gap: 10px;
    }
    
    .success-btn {
        width: 100%;
    }
    
    /* Control buttons */
    .game-controls {
        gap: 10px;
    }
    
    .control-btn {
        min-width: 90px;
        padding: 10px 15px;
        font-size: 0.9rem;
    }
    
    /* Cards grid for mobile */
    .cards-container.level-1 {
        grid-template-columns: repeat(2, 80px);
        grid-template-rows: repeat(2, 80px);
        gap: 10px;
    }
    
    .cards-container.level-2 {
        grid-template-columns: repeat(3, 70px);
        grid-template-rows: repeat(2, 70px);
        gap: 8px;
    }
    
    .cards-container.level-3 {
        grid-template-columns: repeat(4, 65px);
        grid-template-rows: repeat(2, 65px);
        gap: 8px;
    }
    
    .card-face {
        font-size: 1.8rem;
    }
    
    /* Visual discrimination grid */
    .visual-grid {
        max-width: 300px;
        gap: 8px;
    }
    
    .visual-item {
        width: 45px;
        height: 45px;
        font-size: 1.5rem;
    }
    
    /* Color sequence */
    .color-button {
        width: 50px;
        height: 50px;
    }
}

/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) and (max-width: 768px) {
    
    .activities-row {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .progress-stats {
        flex-direction: row;
        justify-content: space-around;
    }
    
    .game-stats {
        gap: 20px;
    }
    
    .cards-container.level-1 {
        grid-template-columns: repeat(2, 100px);
        grid-template-rows: repeat(2, 100px);
    }
    
    .cards-container.level-2 {
        grid-template-columns: repeat(3, 90px);
        grid-template-rows: repeat(2, 90px);
    }
    
    .cards-container.level-3 {
        grid-template-columns: repeat(4, 80px);
        grid-template-rows: repeat(2, 80px);
    }
    
    .visual-item {
        width: 55px;
        height: 55px;
        font-size: 1.8rem;
    }
    
    .color-button {
        width: 65px;
        height: 65px;
    }
}

/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) and (max-width: 992px) {
    
    .activities-row {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .app-container {
        max-width: 100%;
    }
    
    .welcome-card {
        margin: 20px;
    }
    
    .modal-content {
        width: 80%;
    }
}

/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {
    
    .activities-row {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .app-container {
        max-width: 1200px;
    }
    
    .modal-content {
        width: 60%;
        max-width: 600px;
    }
}

/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px) {
    
    .activities-row {
        grid-template-columns: repeat(3, 1fr);
        max-width: 1000px;
        margin: 0 auto;
    }
    
    .game-board {
        max-width: 1200px;
    }
}

/* Orientation-specific styles */
/* تنسيقات خاصة بالاتجاه */

/* Portrait orientation */
@media screen and (orientation: portrait) and (max-width: 768px) {
    
    .game-stats {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .game-stats .stat {
        flex: 0 0 45%;
        margin-bottom: 10px;
    }
    
    .cards-container {
        justify-content: center;
        margin: 20px auto;
    }
    
    .visual-grid {
        margin: 20px auto;
    }
}

/* Landscape orientation */
@media screen and (orientation: landscape) and (max-height: 600px) {
    
    .app-header {
        padding: 10px 20px;
    }
    
    .game-header {
        padding: 10px 20px;
    }
    
    .welcome-section {
        padding: 20px;
    }
    
    .welcome-card {
        padding: 20px;
    }
    
    .game-board {
        padding: 20px;
    }
    
    .level-info h2 {
        font-size: 1.4rem;
        margin-bottom: 5px;
    }
    
    .progress-bar {
        margin: 15px auto;
    }
    
    .game-controls {
        margin-top: 20px;
    }
}

/* Touch device optimizations */
/* تحسينات للأجهزة اللمسية */

@media (hover: none) and (pointer: coarse) {
    
    /* Larger touch targets */
    .activity-card {
        padding: 25px;
        margin-bottom: 20px;
        min-height: 120px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        position: relative;
        overflow: hidden;
    }
    
    .control-btn {
        padding: 15px 25px;
        min-height: 50px;
        min-width: 120px;
        position: relative;
        overflow: hidden;
    }
    
    .memory-card {
        min-width: 80px;
        min-height: 80px;
    }
    
    .visual-item {
        min-width: 50px;
        min-height: 50px;
    }
    
    .color-button {
        min-width: 60px;
        min-height: 60px;
    }
    
    .back-btn, .help-btn, .settings-btn {
        min-width: 48px;
        min-height: 48px;
        padding: 14px;
    }
    
    /* Remove hover effects and replace with tap effects */
    .activity-card:hover {
        transform: none;
    }
    
    .control-btn:hover:not(:disabled) {
        transform: none;
    }
    
    /* Enhanced active states for better touch feedback */
    .activity-card:active {
        transform: scale(0.96);
        opacity: 0.9;
        background: linear-gradient(135deg, #FFE066 10%, white 90%);
        transition: all 0.15s ease;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }
    
    .control-btn:active {
        transform: scale(0.95);
        opacity: 0.85;
        transition: all 0.1s ease;
        box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
    }
    
    .memory-card:active {
        transform: scale(0.95);
        transition: all 0.1s ease;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    }
    
    .visual-item:active {
        transform: scale(0.9);
        transition: all 0.1s ease;
        box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2);
    }
    
    .color-button:active {
        transform: scale(0.9);
        transition: all 0.1s ease;
        box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.25);
    }
    
    .settings-btn:active,
    .back-btn:active,
    .help-btn:active {
        transform: scale(0.9);
        opacity: 0.8;
        transition: all 0.1s ease;
    }
    
    /* Add ripple effect for buttons */
    .control-btn, .success-btn, .back-btn, .help-btn, .activity-card {
        position: relative;
        overflow: hidden;
    }
    
    .control-btn:active::after,
    .success-btn:active::after,
    .back-btn:active::after,
    .help-btn:active::after,
    .activity-card:active::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.6);
        transform: translate(-50%, -50%);
        animation: mobileRipple 0.8s ease-out;
        pointer-events: none;
        z-index: 1;
    }
    
    @keyframes mobileRipple {
        0% {
            width: 0;
            height: 0;
            opacity: 1;
        }
        50% {
            width: 100px;
            height: 100px;
            opacity: 0.8;
        }
        100% {
            width: 200px;
            height: 200px;
            opacity: 0;
        }
    }
    
    /* Enhanced bounce animation for mobile success */
    @keyframes mobileBounceIn {
        0% {
            transform: scale(0.3) rotate(-15deg);
            opacity: 0;
        }
        50% {
            transform: scale(1.05) rotate(5deg);
            opacity: 1;
        }
        70% {
            transform: scale(0.95) rotate(-2deg);
        }
        100% {
            transform: scale(1) rotate(0deg);
            opacity: 1;
        }
    }
    
    .mobile-success-bounce {
        animation: mobileBounceIn 0.8s ease-out;
    }
}

/* High DPI displays */
/* الشاشات عالية الدقة */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    
    /* Ensure crisp text and icons */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    /* Optimize icon rendering */
    .fas, .far, .fab {
        -webkit-font-smoothing: antialiased;
    }
    
    /* Enhance gradients for high DPI */
    .activity-card,
    .welcome-card,
    .control-btn {
        background-size: 200% 200%;
    }
}

/* Performance optimizations for mobile */
@media (max-width: 768px) {
    
    /* Use hardware acceleration for smooth animations */
    .activity-card,
    .memory-card,
    .control-btn,
    .modal-content {
        transform: translateZ(0);
        backface-visibility: hidden;
        perspective: 1000px;
    }
    
    /* Optimize heavy animations for mobile */
    .activity-card:hover,
    .memory-card.flipped .card-inner,
    .control-btn:hover {
        will-change: transform;
    }
    
    /* Reduce complex animations on slower devices */
    @media (max-width: 480px) {
        .rainbow-border {
            animation-duration: 5s;
        }
        
        .float {
            animation-duration: 4s;
        }
        
        .sparkle::before {
            animation-duration: 3s;
        }
    }
    
    /* Optimize images and backgrounds */
    .activity-icon,
    .card-face {
        background-attachment: scroll;
    }
    
    /* Smooth momentum scrolling */
    .activities-section,
    .modal-body,
    .game-board {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* Reduced motion preferences */
/* تفضيلات تقليل الحركة */

@media (prefers-reduced-motion: reduce) {
    
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .bounce, .pulse, .fade-in {
        animation: none !important;
    }
    
    .card-inner {
        transition: none !important;
    }
}

/* Dark mode support (if needed) */
/* دعم الوضع المظلم */

@media (prefers-color-scheme: dark) {
    
    /* This can be implemented if dark mode is desired */
    /* يمكن تطبيق هذا إذا كان الوضع المظلم مطلوباً */
    
    /*
    body {
        background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
    }
    
    .app-container {
        background: rgba(17, 24, 39, 0.95);
        color: #f9fafb;
    }
    */
}

/* Print styles (for progress reports) */
/* تنسيقات الطباعة */

@media print {
    
    body {
        background: white !important;
        color: black !important;
    }
    
    .app-header,
    .game-controls,
    .control-btn,
    .modal {
        display: none !important;
    }
    
    .app-container {
        box-shadow: none !important;
        background: white !important;
    }
    
    .activity-card {
        break-inside: avoid;
        border: 1px solid #ccc;
    }
    
    .progress-card {
        break-inside: avoid;
    }
    
    h1, h2, h3 {
        color: black !important;
    }
}

/* Accessibility improvements */
/* تحسينات إمكانية الوصول */

@media (prefers-contrast: high) {
    
    .activity-card {
        border: 2px solid #000;
    }
    
    .control-btn {
        border: 2px solid #000;
    }
    
    .memory-card .card-face {
        border: 2px solid #000;
    }
}

/* Focus indicators for keyboard navigation */
/* مؤشرات التركيز للتنقل بالكيبورد */

.activity-card:focus,
.control-btn:focus,
.memory-card:focus,
.visual-item:focus,
.color-button:focus {
    outline: 3px solid #4facfe;
    outline-offset: 2px;
}

/* Ensure minimum tap target size (44px) */
/* ضمان حد أدنى لحجم هدف اللمس */

@media (max-width: 768px) {
    
    .control-btn,
    .back-btn,
    .help-btn,
    .settings-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .memory-card,
    .visual-item,
    .color-button {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Mobile viewport and safe area handling */
@media (max-width: 768px) {
    
    /* Handle notches and safe areas on modern phones */
    .app-container {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    /* Prevent horizontal scroll */
    body {
        overflow-x: hidden;
        width: 100%;
    }
    
    /* Improve touch scrolling */
    .activities-section,
    .game-board,
    .modal-body {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Optimize for mobile keyboards */
    .modal-content {
        max-height: calc(100vh - 20px);
        margin: 10px auto;
        overflow-y: auto;
    }
    
    /* Better spacing for mobile */
    .app-container {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    /* Prevent zoom on form inputs */
    input, select, textarea {
        font-size: 16px;
    }
    
    /* Improve button accessibility on mobile */
    button, .btn, .control-btn {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
}

/* Landscape mobile optimizations */
@media (max-width: 896px) and (orientation: landscape) {
    
    .app-header {
        padding: 8px 15px;
    }
    
    .welcome-section {
        padding: 15px;
    }
    
    .welcome-card {
        padding: 15px;
    }
    
    .activities-section {
        padding: 15px;
    }
    
    .game-board {
        padding: 15px;
    }
    
    /* Compact layout for landscape */
    .game-stats {
        gap: 8px;
    }
    
    .game-stats .stat {
        padding: 8px 12px;
        min-width: 50px;
    }
    
    .game-stats .stat i {
        font-size: 1rem;
    }
    
    .game-stats .stat span {
        font-size: 0.9rem;
    }
}