/**
 * Eduplayify Game Template: missing_letters (إكمال الحروف الناقصة)
 * تصميم جمالي حديث وعالي التباين، متجاوب، ويدعم اتجاه الكلمة بدقة (RTL/LTR)
 */

/* الحاوية الرئيسية */
.ml-wrap {
    width: 100%;
    max-width: 820px;
    margin: 0 auto;
    text-align: center;
    padding: 10px 12px 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
}

/* صينية أحرف الكلمة (Word Row) — px قبل clamp كمصيدة متصفحات بلا clamp */
.ml-word-row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    gap: clamp(8px, 1.8vw, 14px);
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f6 100%);
    border: 2px dashed #cbd5e1;
    border-radius: 20px;
    padding: 18px;
    padding: clamp(14px, 3vw, 24px);
    margin: 0 auto 20px;
    max-width: 96%;
    box-sizing: border-box;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.04);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

/* فرض اتجاه الكلمة قطعيًا وفق لغتها وليس لغة الموقع */
.ml-word-row[dir="ltr"],
.ml-word-row.dir-ltr {
    direction: ltr !important;
}
.ml-word-row[dir="rtl"],
.ml-word-row.dir-rtl {
    direction: rtl !important;
}

.ml-word-row.is-correct {
    border-color: #10b981;
    border-style: solid;
    background: #ecfdf5;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

.ml-word-row.shake {
    animation: mlShake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
    border-color: #ef4444;
}

/* بطاقة الحرف المكشوف (Known Letter Tile) — ثابت قبل clamp كي لا يصغر على الشاشات الضعيفة */
.ml-letter-box {
    width: 56px;
    width: clamp(48px, 11vw, 68px);
    height: 62px;
    height: clamp(54px, 12vw, 76px);
    min-width: 48px;
    min-height: 54px;
    border-radius: 14px;
    background: linear-gradient(145deg, #ffffff 0%, #f1f5f9 100%);
    border: 2px solid #cbd5e1;
    box-shadow: 0 4px 0 #94a3b8, 0 6px 12px rgba(0, 0, 0, 0.08);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-size: clamp(1.6rem, 5vw, 2.3rem);
    font-weight: 900;
    color: #1e293b;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    line-height: 1;
}

.ml-letter-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 38%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-radius: 14px 14px 0 0;
    pointer-events: none;
}

/* خانة الحرف الناقص (Missing Slot) */
.ml-slot {
    width: 56px;
    width: clamp(48px, 11vw, 68px);
    height: 62px;
    height: clamp(54px, 12vw, 76px);
    min-width: 48px;
    min-height: 54px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-sizing: border-box;
}

/* حقل إدخال الحرف */
.ml-letter-input {
    width: 100%;
    height: 100%;
    border-radius: 14px;
    border: 2px dashed #6366f1;
    background: #ffffff;
    font-size: 1.8rem;
    font-size: clamp(1.6rem, 5vw, 2.3rem);
    font-weight: 900;
    text-align: center;
    color: #4338ca;
    box-shadow: inset 0 2px 4px rgba(99, 102, 241, 0.08), 0 4px 0 rgba(99, 102, 241, 0.25);
    outline: none;
    box-sizing: border-box;
    cursor: text;
    transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    line-height: 1;
}

.ml-letter-input:focus {
    border: 2.5px solid #4f46e5;
    background: #eef2ff;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.22), 0 4px 0 #3730a3;
    transform: translateY(-2px);
}

.ml-letter-input.is-filled {
    border-style: solid;
    border-color: #4f46e5;
    background: #faf5ff;
}

.ml-letter-input.correct {
    border-color: #10b981 !important;
    background: #ecfdf5 !important;
    color: #047857 !important;
    box-shadow: 0 4px 0 #059669 !important;
    animation: mlPopIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ml-letter-input.incorrect {
    border-color: #ef4444 !important;
    background: #fef2f2 !important;
    color: #b91c1c !important;
    box-shadow: 0 4px 0 #dc2626 !important;
}

/* تخصيص الخطوط بناء على لغة الكلمة */
.ml-word-row[dir="ltr"] .ml-letter-char,
.ml-word-row[dir="ltr"] .ml-letter-input {
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif !important;
}

.ml-word-row[dir="rtl"] .ml-letter-char,
.ml-word-row[dir="rtl"] .ml-letter-input {
    font-family: 'Cairo', system-ui, -apple-system, sans-serif !important;
}

/* شريط أزرار العمليات */
.ml-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.ml-btn-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 28px;
    font-size: 1.05rem;
    font-weight: 800;
    border-radius: 9999px;
    background: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.ml-btn-check:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.45);
}

.ml-btn-check:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.ml-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 22px;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: 9999px;
    background: #ffffff;
    color: #475569;
    border: 1.5px solid #cbd5e1;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.ml-btn-secondary:hover:not(:disabled) {
    background: #f1f5f9;
    color: #1e293b;
    border-color: #94a3b8;
}

.ml-btn-secondary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* حركات التفاعل (Animations) */
@keyframes mlShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@keyframes mlPopIn {
    0% { transform: scale(0.85); opacity: 0.7; }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); opacity: 1; }
}

/* مصيدة غير بديهية: flex gap غير مدعوم في Safari<14.1 — الهوامش أدناه
   بديل فقط عند غياب gap */
@supports not (gap: 8px) {
    .ml-word-row > *, .ml-actions > * { margin: 4px 5px; }
}