/**
 * ============================================
 * MOBILE & TABLET EXAM RESPONSIVE STYLES
 * Optimized for touch interactions
 * ============================================
 */

/* iPad Landscape (1024x768) - OPTIMIZED for Image Matching */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .exam-container {
        max-width: 100%;
        padding: 8px 12px;
    }
    
    .question-card {
        padding: 24px;
    }
    
    .question-text {
        font-size: 1.2rem;
        margin-bottom: 16px;
    }
    
    /* Image Matching - Compact for iPad */
    .image-slot {
        padding: 10px !important;
    }
    
    .image-slot img {
        max-width: 340px !important;
        max-height: 260px !important;
    }
    
    .drag-item {
        padding: 10px 18px !important;
        font-size: 14px !important;
        min-height: 42px !important;
        min-width: 100px !important;
        cursor: pointer !important;
        touch-action: none !important;
        transition: all 0.2s ease !important;
        user-select: none !important;
        -webkit-user-select: none !important;
    }
    
    .drag-item:active {
        transform: scale(1.05) !important;
    }
    
    .drop-zone {
        min-height: 56px !important;
        border-width: 3px !important;
        border-style: dashed !important;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        padding: 8px !important;
        font-size: 14px;
    }
    
    .pool {
        min-height: 80px !important;
        padding: 16px !important;
        gap: 10px !important;
    }
    
    .drop-zone:empty::after {
        content: '👆 Buraya sürükle';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: rgba(100, 116, 139, 0.5);
        font-size: 17px;
        font-weight: 600;
        text-align: center;
        pointer-events: none;
    }
    
    .drop-zone.drag-over {
        background: rgba(99, 102, 241, 0.15) !important;
        border-color: #6366f1 !important;
        border-style: solid !important;
        transform: scale(1.02) !important;
    }
    
    .image-slot img {
        width: 220px !important;
        height: 190px !important;
        object-fit: contain !important;
    }
    
    .pool {
        padding: 24px;
        gap: 16px;
    }
    
    #dragSlots {
        grid-template-columns: repeat(3, minmax(320px, 1fr)) !important;
        gap: 22px !important;
    }
}

/* Tablet Portrait & Mobile - Below 768px */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }
    
    .exam-container {
        padding: 12px;
    }
    
    .progress-header {
        padding: 16px 20px;
        margin-bottom: 16px;
    }
    
    .question-number {
        font-size: 1rem;
    }
    
    .question-card {
        padding: 24px;
        border-radius: 16px;
    }
    
    .question-text {
        font-size: 1.2rem;
        margin-bottom: 24px;
    }
    
    .reading-container {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }
    
    .reading-passage {
        max-height: 400px;
        padding: 20px;
    }
    
    /* Drag & Drop Items - Larger for touch */
    .drag-item {
        padding: 16px 24px !important;
        font-size: 16px !important;
        min-height: 60px !important;
        min-width: 140px !important;
        touch-action: none !important;
        cursor: pointer !important;
        user-select: none !important;
        transition: all 0.2s ease !important;
        position: relative !important;
        overflow: hidden !important;
        -webkit-user-select: none !important;
        -webkit-tap-highlight-color: transparent !important;
    }
    
    .pool {
        gap: 14px !important;
        padding: 20px !important;
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .drop-zone {
        min-height: 280px !important;
        border-width: 3px !important;
        position: relative;
        touch-action: none !important;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        border-style: dashed !important;
    }
    
    .drop-zone:empty::after {
        content: '👆 Buraya sürükle';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: rgba(100, 116, 139, 0.5);
        font-size: 16px;
        font-weight: 600;
        text-align: center;
        pointer-events: none;
    }
    
    .drop-zone.drag-over {
        background: rgba(99, 102, 241, 0.15) !important;
        border-color: #6366f1 !important;
        border-style: solid !important;
        transform: scale(1.02) !important;
        box-shadow: 0 0 20px rgba(99, 102, 241, 0.4) !important;
    }
    
    .drag-item:active {
        transform: scale(1.05) !important;
    }
    
    #dragSlots {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
        gap: 20px !important;
    }
    
    /* Image Matching */
    .image-slot {
        margin-bottom: 16px;
    }
    
    .image-slot img {
        width: 100%;
        max-width: 280px;
        height: auto;
        max-height: 200px;
        object-fit: contain;
    }
    
    .image-slot .drop-zone {
        min-height: 100px !important;
        padding: 16px;
    }
    
    /* Options */
    .option-item {
        padding: 16px 20px;
        font-size: 16px;
        margin-bottom: 12px;
        min-height: 60px;
        display: flex;
        align-items: center;
    }
    
    /* Buttons */
    .btn-submit {
        width: 100%;
        justify-content: center;
        min-height: 56px;
        font-size: 17px;
    }
    
    .controls {
        flex-direction: column;
        gap: 12px;
    }
}

/* Phone specific - Below 480px */
@media (max-width: 480px) {
    .exam-container {
        padding: 8px;
    }
    
    .progress-header {
        padding: 14px 16px;
        border-radius: 12px;
    }
    
    .question-card {
        padding: 20px;
        border-radius: 12px;
    }
    
    .question-text {
        font-size: 1.1rem;
        line-height: 1.5;
    }
    
    .question-type-badge {
        font-size: 0.8rem;
        padding: 6px 16px;
    }
    
    .drag-item {
        padding: 14px 20px !important;
        font-size: 15px !important;
        min-width: 120px !important;
        min-height: 56px !important;
        touch-action: none !important;
        transition: all 0.2s ease !important;
    }
    
    .drag-item:active {
        transform: scale(1.05) !important;
    }
    
    .pool {
        padding: 16px !important;
        gap: 12px !important;
    }
    
    .drop-zone {
        min-height: 260px !important;
        padding: 16px;
    }
    
    #dragSlots {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    .image-slot img {
        max-width: 240px;
        max-height: 180px;
    }
    
    .option-item {
        padding: 14px 18px;
        font-size: 15px;
        min-height: 56px;
    }
    
    .tf-table {
        font-size: 14px;
    }
    
    .tf-table thead th,
    .tf-table tbody td {
        padding: 12px 8px;
    }
    
    .instruction-text {
        font-size: 14px;
        padding: 12px 16px;
    }
    
    .audio-container {
        padding: 20px;
    }
}

/* Extra small devices - Below 360px */
@media (max-width: 360px) {
    .question-text {
        font-size: 1rem;
    }
    
    .drag-item {
        padding: 12px 16px !important;
        font-size: 14px !important;
        min-width: 100px !important;
        min-height: 52px !important;
    }
    
    .drop-zone {
        min-height: 240px !important;
    }
    
    .image-slot img {
        max-width: 200px;
        max-height: 160px;
    }
    
    .pool {
        padding: 12px !important;
    }
}

/* Touch device specific optimizations */
@media (hover: none) and (pointer: coarse) {
    /* All draggable items */
    .drag-item {
        touch-action: none !important;
        -webkit-tap-highlight-color: transparent !important;
        cursor: pointer !important;
    }
    
    .drop-zone {
        touch-action: none !important;
    }
    
    /* Options and radio buttons */
    .option-item {
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.1) !important;
        cursor: pointer;
    }
    
    /* Larger tap targets for radio buttons */
    input[type="radio"] {
        width: 28px !important;
        height: 28px !important;
        margin: 8px !important;
        cursor: pointer;
    }
    
    input[type="checkbox"] {
        width: 28px !important;
        height: 28px !important;
        margin: 8px !important;
        cursor: pointer;
    }
    
    /* Buttons */
    .btn-submit {
        min-height: 56px !important;
        font-size: 18px !important;
        padding: 16px 32px !important;
        touch-action: manipulation !important;
    }
    
    /* Text inputs */
    input[type="text"],
    textarea {
        min-height: 48px;
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 12px 16px;
    }
}

/* Landscape mode on small devices */
@media (max-height: 500px) and (orientation: landscape) {
    .question-card {
        padding: 20px;
    }
    
    .progress-header {
        padding: 12px 20px;
        margin-bottom: 12px;
    }
    
    .question-text {
        font-size: 1.1rem;
        margin-bottom: 16px;
    }
    
    .drop-zone {
        min-height: 180px !important;
    }
    
    .image-slot img {
        max-height: 140px !important;
    }
    
    .drag-item {
        padding: 10px 18px !important;
        min-height: 48px !important;
    }
    
    .pool {
        padding: 16px !important;
    }
}

/* High DPI displays (Retina) */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .image-slot img,
    .drop-zone img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Prevent zoom on iOS when focusing inputs */
@supports (-webkit-touch-callout: none) {
    input[type="text"],
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* Dark mode support (if device prefers dark) */
@media (prefers-color-scheme: dark) {
    /* Optional: Can be enabled if needed */
    /* body {
        filter: invert(0.9) hue-rotate(180deg);
    }
    img, video {
        filter: invert(1) hue-rotate(180deg);
    } */
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
