/**
 * Sorting Game Responsive Styles
 * Additional CSS to enhance mobile responsiveness
 */

/* Base game container styles */
.sarah-loz-game-container {
    max-width: 100% !important;
    box-sizing: border-box;
    transition: width 0.3s ease, height 0.3s ease;
}

/* Game layout container */
.sorting-game-layout {
    overscroll-behavior: contain; /* Prevent scrolling parent when scrolling container */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Categories section */
.sorting-categories-section {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    transition: gap 0.3s ease, margin 0.3s ease;
}

/* Category containers */
.category-container {
    overflow: auto; /* Enable scrolling inside categories */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    transition: all 0.3s ease;
    margin: 0 auto;
    /* Prevent text selection inside categories */
    user-select: none;
    -webkit-user-select: none;
}

/* Sequence containers */
.sequence-container {
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

/* Category title */
.category-title {
    position: sticky;
    top: 0;
    width: 100%;
    z-index: 10;
    text-align: center;
    transition: font-size 0.3s ease, padding 0.3s ease;
}

/* Items section */
.sorting-items-section {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    transition: all 0.3s ease;
}

/* Individual sorting items */
.sorting-item {
    touch-action: none; /* Prevents scrolling during drag on touch devices */
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    will-change: transform; /* Optimize for animation */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: grab;
}

.sorting-item:active {
    cursor: grabbing;
}

/* Progress container */
.sorting-progress-container {
    transition: height 0.3s ease;
}

/* Progress bar */
.sorting-progress-bar {
    transition: width 0.3s ease;
}

/* Droppable highlight state */
.ui-state-hover {
    background-color: #e0f2f1 !important;
    border-color: #80cbc4 !important;
    box-shadow: 0 0 10px rgba(128, 203, 196, 0.4) !important;
}

/* Correct placement highlight */
.correct-placement {
    border: 2px solid #4caf50 !important;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.6) !important;
    animation: pulseGreen 1s ease;
}

/* Incorrect placement highlight */
.incorrect-placement {
    border: 2px solid #f44336 !important;
    box-shadow: 0 0 8px rgba(244, 67, 54, 0.6) !important;
}

@keyframes pulseGreen {
    0% { box-shadow: 0 0 0 rgba(76, 175, 80, 0.6); }
    50% { box-shadow: 0 0 15px rgba(76, 175, 80, 0.8); }
    100% { box-shadow: 0 0 8px rgba(76, 175, 80, 0.6); }
}

/* Game instructions */
.sorting-instructions {
    text-align: center;
    transition: font-size 0.3s ease;
}

/* Media queries for different device sizes */
@media (max-width: 480px) {
    /* Extra small devices */
    .sorting-game-layout {
        padding: 8px !important;
    }
    
    .sorting-instructions {
        font-size: 13px !important;
        padding: 6px !important;
    }
    
    .sorting-categories-section {
        gap: 6px !important;
        margin-bottom: 10px !important;
    }
    
    .category-container {
        padding: 4px !important;
    }
    
    .category-title {
        padding: 3px 6px !important;
        font-size: 11px !important;
    }
    
    .sequence-container {
        width: 65px !important;
        height: 65px !important;
    }
    
    .sequence-number {
        width: 18px !important;
        height: 18px !important;
        font-size: 10px !important;
    }
    
    .sorting-items-section {
        gap: 5px !important;
        padding: 6px !important;
    }
    
    .sorting-progress-text {
        font-size: 11px !important;
        margin: 5px 0 !important;
    }
    
    .sarah-loz-game-ui {
        flex-direction: column;
        align-items: center;
        gap: 5px;
    }
    
    .sarah-loz-game-score, .sarah-loz-game-timer {
        font-size: 14px;
        padding: 3px 6px;
    }
}

@media (min-width: 481px) and (max-width: 767px) {
    /* Small devices */
    .sorting-game-layout {
        padding: 12px !important;
    }
    
    .sorting-categories-section {
        gap: 8px !important;
    }
    
    .sorting-items-section {
        gap: 8px !important;
    }
}

/* Portrait orientation on mobile */
@media (max-width: 767px) and (orientation: portrait) {
    .sarah-loz-game-container {
        margin-top: 15px;
        margin-bottom: 15px;
    }
    
    .sarah-loz-game-ui {
        top: 5px;
        left: 5px;
        right: 5px;
    }
    
    /* Make categories larger in portrait mode for single column layout */
    .category-container {
        min-width: 85% !important;
        margin-bottom: 10px !important;
    }
}

/* Landscape orientation on small screens */
@media (max-height: 500px) and (orientation: landscape) {
    .sorting-game-layout {
        padding: 5px !important;
    }
    
    .sorting-categories-section {
        min-height: 100px !important;
        margin-bottom: 5px !important;
    }
    
    .sorting-items-section {
        min-height: 80px !important;
        max-height: 150px !important;
    }
    
    .sorting-instructions {
        margin-bottom: 5px !important;
    }
    
    .sorting-divider {
        margin: 5px 0 !important;
    }
}

/* High contrast mode for accessibility */
@media (prefers-contrast: high) {
    .category-container, .sequence-container {
        border: 3px dashed #000 !important;
        background-color: #f5f5f5 !important;
    }
    
    .category-title {
        background-color: #000 !important;
        color: #fff !important;
    }
    
    .sequence-number {
        background-color: #000 !important;
    }
    
    .sorting-item {
        border: 2px solid #000 !important;
        background-color: #fff !important;
    }
    
    .correct-placement {
        border: 3px solid #006400 !important;
    }
    
    .incorrect-placement {
        border: 3px solid #8b0000 !important;
    }
    
    .sarah-loz-game-score, .sarah-loz-game-timer {
        background-color: rgba(255, 255, 255, 0.9) !important;
        color: #000 !important;
        border: 1px solid #000;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .sarah-loz-game-container {
        background-color: #2c2c2c !important;
    }
    
    .sorting-instructions {
        background-color: #3c3c3c !important;
        color: #f0f0f0 !important;
        border-color: #555 !important;
    }
    
    .category-container, .sequence-container {
        background-color: #3c3c3c !important;
        border-color: #555 !important;
    }
    
    .sorting-item {
        background-color: #4c4c4c !important;
        border-color: #666 !important;
        color: #f0f0f0 !important;
    }
    
    .sorting-divider {
        background-color: #555 !important;
    }
    
    .sarah-loz-game-score, .sarah-loz-game-timer {
        background-color: rgba(50, 50, 50, 0.8) !important;
        color: #fff !important;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .sorting-item, .category-container, .sequence-container, .correct-placement, .incorrect-placement {
        transition: none !important;
        animation: none !important;
    }
    
    @keyframes pulseGreen {
        0%, 50%, 100% { box-shadow: 0 0 8px rgba(76, 175, 80, 0.6); }
    }
}

/* RTL language support (for Arabic) */
[dir="rtl"] .sorting-instructions,
[dir="rtl"] .category-title,
[dir="rtl"] .sorting-progress-text {
    text-align: right !important;
}

/* Helper classes for dragging state */
.gu-mirror {
    position: fixed !important;
    margin: 0 !important;
    z-index: 9999 !important;
    opacity: 0.8;
    transform: rotate(2deg);
}

.gu-hide {
    display: none !important;
}

.gu-unselectable {
    user-select: none !important;
}

.gu-transit {
    opacity: 0.2;
} 