/**
 * Eduplayify Game Template: Classification (التصنيف والمجموعات)
 * تصميم حديث، تفاعلي وأنيق مع دعم كامل للغة العربية والشاشات المختلفة
 */

.cls-stage {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 8px 12px 20px;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

/* =========================================
   1. سلال التصنيف (Classification Buckets)
   ========================================= */
.cls-buckets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
    align-items: stretch;
}

.cls-bucket {
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    padding: 14px;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
    transition: all 0.25s cubic-bezier(0.2, 0, 0.2, 1);
    position: relative;
    cursor: pointer;
}

.cls-bucket:hover {
    border-color: #cbd5e1;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.06);
}

/* حالة الاستعداد عند تحديد بطاقة بالنقر */
.cls-buckets.has-selection .cls-bucket {
    border-style: dashed;
    border-color: #6366f1;
    background: #faf5ff;
    animation: clsPulseReady 1.5s infinite ease-in-out;
}

@keyframes clsPulseReady {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.12); }
}

/* حالة مرور البطاقة المسحوبة فوق السلة */
.cls-bucket.drag-over {
    border-color: #4f46e5 !important;
    background: #eef2ff !important;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.2), 0 10px 24px rgba(79, 70, 229, 0.15) !important;
    transform: scale(1.02);
}

.cls-bucket.drag-over .cls-bucket-inner {
    border-color: #818cf8 !important;
    background: rgba(255, 255, 255, 0.85) !important;
}

/* حالة اكتمال السلة */
.cls-bucket.is-completed {
    border-color: #10b981;
    background: #f0fdf4;
}

.cls-bucket.is-completed .cls-bucket-count {
    background: #10b981;
    color: #ffffff;
}

/* تنوع ألوان السلال لإعطاء هوية بصرية ممتعة */
.cls-bucket-0 {
    --cat-accent: #4f46e5;
    --cat-bg-soft: #eef2ff;
    border-top: 4px solid #4f46e5;
}
.cls-bucket-1 {
    --cat-accent: #d97706;
    --cat-bg-soft: #fffbeb;
    border-top: 4px solid #d97706;
}
.cls-bucket-2 {
    --cat-accent: #059669;
    --cat-bg-soft: #ecfdf5;
    border-top: 4px solid #059669;
}
.cls-bucket-3 {
    --cat-accent: #7c3aed;
    --cat-bg-soft: #f5f3ff;
    border-top: 4px solid #7c3aed;
}

/* رأس السلة */
.cls-bucket-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f5f9;
}

.cls-bucket-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.cls-bucket-icon {
    font-size: 1.25rem;
    line-height: 1;
    flex-shrink: 0;
}

.cls-bucket-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--dark, #1e293b);
    margin: 0;
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 4px;
    word-break: break-word;
}

.cls-bucket-count {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 9999px;
    background: #f1f5f9;
    color: #64748b;
    white-space: nowrap;
    transition: all 0.25s ease;
    flex-shrink: 0;
}

/* الحاوية الداخلية للسلة (منطقة وضع البطاقات) */
.cls-bucket-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    align-content: flex-start;
    justify-content: flex-start;
    gap: 8px;
    min-height: 95px;
    padding: 10px;
    background: #f8fafc;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    box-sizing: border-box;
    flex-grow: 1;
    transition: all 0.2s ease;
    position: relative;
}

/* تلميح السلة الفارغة (يختفي فوراً عند وضع أي بطاقة) */
.cls-bucket-inner:empty::before {
    content: attr(data-placeholder);
    color: #94a3b8;
    font-size: 0.84rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 75px;
    text-align: center;
    pointer-events: none;
}

/* =========================================
   2. بنك العناصر المتاحة (Pool Box)
   ========================================= */
.cls-pool-box {
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    padding: 14px 18px 18px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.03);
}

.cls-pool-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px dashed #e2e8f0;
}

.cls-pool-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #475569;
    display: flex;
    align-items: center;
    gap: 6px;
}

.cls-pool-count {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 9999px;
    background: #eef2ff;
    color: #4f46e5;
    white-space: nowrap;
}

.cls-pool {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    align-items: center;
    min-height: 80px;
    padding: 4px 0;
    box-sizing: border-box;
}

.cls-pool:empty::before {
    content: attr(data-empty-text);
    color: #10b981;
    font-weight: 700;
    font-size: 1rem;
    padding: 16px;
    text-align: center;
}

/* =========================================
   3. البطاقات (Cards)
   ========================================= */
.cls-card {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    background: #ffffff;
    border: 2px solid #cbd5e1;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    box-shadow: 0 3px 0 #cbd5e1, 0 4px 10px rgba(0, 0, 0, 0.04);
    transition: transform 0.18s cubic-bezier(0.2, 0, 0.2, 1),
                box-shadow 0.18s cubic-bezier(0.2, 0, 0.2, 1),
                border-color 0.18s ease;
    align-self: flex-start;
    max-width: 100%;
    box-sizing: border-box;
}

.cls-card:hover {
    transform: translateY(-2px);
    border-color: #94a3b8;
    box-shadow: 0 5px 0 #cbd5e1, 0 8px 16px rgba(0, 0, 0, 0.08);
}

.cls-card:active {
    cursor: grabbing;
    transform: translateY(1px);
    box-shadow: 0 1px 0 #cbd5e1, 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* صورة البطاقة */
.cls-card img {
    max-width: 52px;
    max-height: 44px;
    border-radius: 6px;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* بطاقة تحتوي على صورة فقط بدون نص */
.cls-card.image-only {
    padding: 8px 14px;
    min-width: 72px;
    min-height: 64px;
}

.cls-card.image-only img {
    max-width: 76px;
    max-height: 56px;
    border-radius: 8px;
}

.cls-card span {
    pointer-events: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* حالة السحب */
.cls-card.is-dragging {
    opacity: 0.92;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.2), 0 0 0 2px #4f46e5;
    z-index: 1000;
    cursor: grabbing;
}

/* حالة التحديد بالنقرة (Tap-to-place) */
.cls-card.is-selected {
    border-color: #4f46e5;
    background: #eef2ff;
    color: #4338ca;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.3), 0 6px 14px rgba(79, 70, 229, 0.15);
    transform: translateY(-3px) scale(1.02);
}

/* حالة البطاقة بعد وضعها بنجاح داخل السلة */
.cls-card.in-bucket {
    cursor: default;
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border: 1.5px solid #86efac;
    color: #15803d;
    box-shadow: 0 1px 3px rgba(22, 101, 52, 0.08);
    padding: 6px 12px;
    font-size: 0.9rem;
    font-weight: 700;
    border-radius: 8px;
    align-self: flex-start;
    flex-shrink: 0;
    transform: none;
    animation: clsPopIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cls-card.in-bucket:hover {
    transform: none;
    border-color: #86efac;
    box-shadow: 0 1px 3px rgba(22, 101, 52, 0.08);
}

.cls-card.in-bucket img {
    max-width: 32px;
    max-height: 26px;
    border-radius: 4px;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

.cls-card.in-bucket.image-only {
    padding: 4px 8px;
    min-width: unset;
    min-height: unset;
}

.cls-card.in-bucket.image-only img {
    max-width: 36px;
    max-height: 30px;
}

/* شارة علامة الصح داخل البطاقة المسقطة */
.cls-card-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #16a34a;
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 900;
    margin-inline-end: 4px;
    flex-shrink: 0;
}

/* حركة الانبثاق عند إسقاط البطاقة في السلة */
@keyframes clsPopIn {
    0% {
        opacity: 0;
        transform: scale(0.7) translateY(-4px);
    }
    70% {
        transform: scale(1.06) translateY(1px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* حركة الاهتزاز عند الإجابة الخاطئة */
@keyframes clsShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-7px); }
    40%, 80% { transform: translateX(7px); }
}

.cls-card.shake {
    animation: clsShake 0.4s ease-in-out both;
    border-color: #ef4444 !important;
    background: #fef2f2 !important;
    color: #b91c1c !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25) !important;
}

/* =========================================
   4. التجاوب مع الشاشات الصغيرة (Responsive)
   ========================================= */
@media (max-width: 640px) {
    .cls-buckets {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 18px;
    }
    .cls-bucket {
        min-height: 130px;
        padding: 10px;
    }
    .cls-bucket-inner {
        min-height: 80px;
        padding: 8px;
        gap: 6px;
    }
    .cls-card {
        padding: 8px 14px;
        font-size: 0.95rem;
    }
    .cls-card.in-bucket {
        padding: 5px 10px;
        font-size: 0.85rem;
    }
    .cls-pool-box {
        padding: 12px;
    }
}

/* مصيدة غير بديهية: grid/flex-gap غائبان في IE11/Safari<14.1 —
   البديل flex + هوامش يعمل فقط عند غياب grid، والحديث يتجاهله */
@supports not (display: grid) {
    .cls-buckets { display: flex; flex-wrap: wrap; }
    .cls-bucket { flex: 1 1 240px; margin: 8px; }
}
@supports not (gap: 8px) {
    .cls-bucket-header > *, .cls-pool > *, .cls-bucket-inner > * { margin: 4px; }
}