/**
 * Eduplayify Game Template: word_search (البحث عن الكلمات في الشبكة)
 * تصميم متجاوب فائق الجمال والدقة، متوافق مع وضع ملء الشاشة والشاشات العادية والهواتف
 */

/* الحاوية الرئيسية للعبة */
.ws-search-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 6px 12px 14px;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    max-height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
}

/* شريط العنوان والتوجيه */
.ws-header {
    font-size: clamp(0.95rem, 2.2vw, 1.15rem);
    font-weight: 800;
    color: #1e293b;
    text-align: center;
    line-height: 1.3;
    padding: 6px 16px;
    margin: 0 auto 8px;
    max-width: 95%;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(79, 70, 229, 0.04) 100%);
    border-radius: 12px;
    border: 1.5px solid #e0e7ff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.04);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-shrink: 0;
}
.ws-header::before {
    content: '🔍';
    font-size: 1.1em;
}

/* صورة السؤال إن وجدت */
.ws-search-wrap .ws-image-box {
    margin-bottom: 8px;
    text-align: center;
    max-width: 100%;
    flex-shrink: 0;
}
.ws-search-wrap .ws-image {
    max-width: 220px;
    max-height: 130px;
    border-radius: 10px;
    border: 1.5px solid #e2e8f0;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
    object-fit: contain;
    background: #fff;
}

/* حاوية المحتوى: اللوحة + الشبكة */
.ws-search-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* العرض الأفقي المتجاور في الشاشات العريضة (Desktop & Tablets):
   يضع قائمة الكلمات إلى الجانب والشبكة إلى جانبها لتقليل الارتفاع الرأسي ومنع أي انقطاع في وضع ملء الشاشة */
@media (min-width: 768px) {
    .ws-search-content {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 18px;
    }
}

/* بطاقة الكلمات المستهدفة ومؤشر التقدم */
.ws-targets-panel {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    max-width: 600px;
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    padding: 8px 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    box-sizing: border-box;
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .ws-targets-panel {
        width: 210px;
        max-width: 230px;
        align-self: flex-start;
        padding: 10px 12px;
        gap: 8px;
    }
}

/* شريط معلومات التقدم داخل البطاقة */
.ws-targets-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
    flex-wrap: wrap;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 6px;
}

@media (min-width: 768px) {
    .ws-targets-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
}

.ws-targets-title {
    font-size: clamp(0.82rem, 1.8vw, 0.92rem);
    font-weight: 800;
    color: #475569;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.ws-targets-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ws-counter {
    display: inline-flex;
    align-items: center;
    font-weight: 800;
    font-size: 0.82rem;
    color: #4338ca;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 9999px;
    padding: 2px 10px;
    white-space: nowrap;
}
.ws-counter-num {
    margin-inline-start: 4px;
}

.ws-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.ws-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #e2e8f0;
    border: 1px solid #cbd5e1;
    transition: all 0.25s ease;
}
.ws-dot.found {
    background: #10b981;
    border-color: #059669;
    transform: scale(1.25);
    box-shadow: 0 0 5px rgba(16, 185, 129, 0.5);
}

/* شريط شارات الكلمات المطلوب إيجادها */
.ws-words-badge-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 2px 0;
}

@media (min-width: 768px) {
    .ws-words-badge-list {
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }
}

.ws-word-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    background: #f8fafc;
    border: 1.5px solid #cbd5e1;
    border-radius: 9999px;
    font-size: clamp(0.82rem, 1.8vw, 0.94rem);
    font-weight: 700;
    color: #334155;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1.2;
    box-sizing: border-box;
}

@media (min-width: 768px) {
    .ws-word-badge {
        width: 100%;
        justify-content: space-between;
        padding: 5px 12px;
    }
}

.ws-word-badge.is-found {
    border-style: solid;
    text-decoration: line-through;
    opacity: 0.92;
    transform: scale(0.98);
    font-weight: 800;
}
.ws-word-badge.is-found::after {
    content: ' ✓';
    font-weight: 900;
    text-decoration: none;
    display: inline-block;
}

/* شارات التلميحات (وضع إظهار التلميحات) */
.ws-word-badge.ws-badge-hint {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
    font-size: clamp(0.8rem, 1.7vw, 0.9rem);
    word-break: break-word;
}
.ws-word-badge.ws-badge-hint:hover {
    background: #fef3c7;
    border-color: #f59e0b;
}

/* شارات الكلمات المخفية (وضع إخفاء الاثنين) */
.ws-word-badge.ws-badge-mystery {
    background: #f8fafc;
    border: 1.5px dashed #94a3b8;
    color: #64748b;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.ws-word-badge.ws-badge-mystery:hover {
    background: #f1f5f9;
    border-color: #64748b;
    color: #334155;
}

/* كشف الكلمة المخفية بعد إيجادها */
.ws-word-badge.ws-badge-revealed {
    border-style: solid;
    animation: wsBadgeReveal 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes wsBadgeReveal {
    0% { transform: scale(0.85); opacity: 0.4; }
    50% { transform: scale(1.08); }
    100% { transform: scale(0.98); opacity: 1; }
}

/* شبكة الحروف التفاعلية (Grid) - حجم مدروس وأنيق ومضبوط لمنع الكبر المفرط */
.ws-grid {
    --cell-size: 32px;
    --cell-size: clamp(26px, min(calc((70vh - 60px) / var(--grid-size, 10)), 38px), 40px);
    --gap: 2px;
    --gap: clamp(1.5px, 0.3vmin, 3px);
    display: inline-grid;
    gap: 2px;
    gap: var(--gap);
    padding: 8px;
    padding: clamp(6px, 1vmin, 10px);
    background: #ffffff;
    border-radius: 16px;
    border: 2px solid #cbd5e1;
    box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.07), 0 3px 8px -2px rgba(0, 0, 0, 0.03);
    position: relative;
    margin: 0 auto;
    touch-action: none;
    cursor: pointer;
    box-sizing: border-box;
    flex-shrink: 0;
}

/* خلية الحرف في الشبكة — px ثابت قبل var() كي لا تنهار لمتصفح بلا متغيرات CSS */
.ws-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    width: var(--cell-size);
    height: 32px;
    height: var(--cell-size);
    min-width: 26px;
    min-height: 26px;
    font-family: 'Cairo', 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    font-size: clamp(13px, calc(var(--cell-size) * 0.54), 20px);
    font-weight: 800;
    line-height: 1;
    border-radius: 6px;
    border-radius: clamp(5px, 0.8vmin, 8px);
    background: #f8fafc;
    color: #1e293b;
    border: 1.5px solid #e2e8f0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    box-sizing: border-box;
}

.ws-cell:hover:not(.found):not(.selected) {
    background: #e0e7ff;
    color: #3730a3;
    border-color: #c7d2fe;
    transform: scale(1.05);
    z-index: 2;
}

/* نبض الخلية الأولى عند بدء التحديد بالنقر */
.ws-cell.start-cell {
    background: #4f46e5 !important;
    color: #ffffff !important;
    border-color: #3730a3 !important;
    animation: wsStartPulse 0.9s infinite alternate ease-in-out;
    z-index: 5;
}
@keyframes wsStartPulse {
    0% { transform: scale(1.03); box-shadow: 0 0 0 2px #4f46e5; }
    100% { transform: scale(1.07); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.4); }
}

/* الخلايا المحددة أثناء السحب */
.ws-cell.selecting,
.ws-cell.selected {
    background: #4f46e5 !important;
    color: #ffffff !important;
    border-color: #3730a3 !important;
    font-weight: 900;
    transform: scale(1.05);
    box-shadow: 0 3px 8px rgba(79, 70, 229, 0.3);
    z-index: 4;
}

/* الخلايا المكتشفة بنجاح */
.ws-cell.found {
    font-weight: 900;
    animation: wsFoundPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1;
}

@keyframes wsFoundPop {
    0% { transform: scale(0.92); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* طبقة خط التوصيل التفاعلي اللحظي أثناء السحب */
.ws-line-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    z-index: 6;
}

.ws-active-line {
    stroke: #4f46e5;
    stroke-opacity: 0.45;
    stroke-linecap: round;
    mix-blend-mode: multiply;
}

/* دعم الاتجاهين RTL و LTR */
[dir="rtl"] .ws-grid { direction: rtl; }
[dir="rtl"] .ws-cell { direction: rtl; }
[dir="ltr"] .ws-grid { direction: ltr; }
[dir="ltr"] .ws-cell { direction: ltr; }

/* قواعد وضع ملء الشاشة لمنع الانقطاع نهائياً */
#gamePlayArea:fullscreen .ws-search-wrap,
.gpa-fullscreen .ws-search-wrap {
    padding: 4px 8px 8px;
    height: 100%;
    max-height: 100%;
    justify-content: flex-start;
}

#gamePlayArea:fullscreen .ws-search-content,
.gpa-fullscreen .ws-search-content {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex: 1 1 auto;
    min-height: 0;
}

#gamePlayArea:fullscreen .ws-targets-panel,
.gpa-fullscreen .ws-targets-panel {
    width: 200px;
    max-width: 220px;
    align-self: center;
    padding: 8px 10px;
}

#gamePlayArea:fullscreen .ws-grid,
.gpa-fullscreen .ws-grid {
    --cell-size: clamp(24px, min(calc((76vh - 80px) / var(--grid-size, 10)), 38px), 40px);
    align-self: center;
}

/* شاشات الجوال والأجهزة اللوحية الصغيرة */
@media (max-width: 767px) {
    .ws-search-wrap {
        padding: 4px 6px 10px;
    }
    .ws-header {
        padding: 5px 12px;
        margin-bottom: 6px;
    }
    .ws-targets-panel {
        padding: 6px 10px;
        gap: 5px;
    }
    .ws-targets-header {
        padding-bottom: 4px;
    }
    .ws-words-badge-list {
        gap: 5px;
    }
    .ws-word-badge {
        padding: 3px 10px;
        font-size: 0.82rem;
    }
    .ws-grid {
        border-radius: 12px;
        padding: 6px;
        --cell-size: clamp(24px, min(calc((56vh - 50px) / var(--grid-size, 10)), calc((92vw - 24px) / var(--grid-size, 10))), 34px);
    }
    #gamePlayArea:fullscreen .ws-search-content,
    .gpa-fullscreen .ws-search-content {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }
    #gamePlayArea:fullscreen .ws-targets-panel,
    .gpa-fullscreen .ws-targets-panel {
        width: 100%;
        max-width: 100%;
    }
}

/* مصيدة غير بديهية: grid/clamp/min() غائبة في القديم — الشبكة تسقط لأعمدة
   مرنة، وحجم الخلية الثابت 30px يمنع شبكة بحجم صفر على شاشة ضعيفة */
.ws-grid {
    min-width: 240px;
    min-height: 240px;
}
@supports not (display: grid) {
    .ws-grid { display: flex; flex-wrap: wrap; }
    .ws-cell { flex: 0 0 30px; width: 30px; height: 30px; margin: 1px; }
}
@supports not (gap: 6px) {
    .ws-search-content > *, .ws-words-badge-list > *, .ws-targets-panel > * { margin: 3px; }
}