/**
 * Eduplayify Crossword Game Template (قالب الكلمات المتقاطعة)
 * تصميم فخم، عالي الوضوح والتباين، متجاوب بالكامل مع كافة الشاشات والمتصفحات القديمة والحديثة
 */

/* الحاوية الرئيسية للعبة */
.cw-player-wrap {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    padding: clamp(6px, 1.5vw, 16px);
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

/* بطاقة العنوان والتعليمات */
.cw-header-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: clamp(10px, 1.8vh, 16px) clamp(14px, 2.5vw, 24px);
    margin-bottom: clamp(12px, 2vh, 20px);
    text-align: center;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
}

.cw-title {
    font-size: clamp(1.2rem, 2.2vw, 1.65rem);
    font-weight: 900;
    color: #1e1b4b;
    margin: 0 0 4px 0;
}

.cw-subtitle {
    font-size: clamp(0.85rem, 1.4vw, 0.98rem);
    color: #64748b;
    margin: 0;
    font-weight: 600;
}

/* الحاوية المنقسمة: شبكة الكلمات + قائمة الدلالات */
.cw-layout-container {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(14px, 2.5vw, 24px);
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
}

/* حاوية شبكة الكلمات المتقاطعة */
.cw-grid-container {
    flex: 1 1 340px;
    max-width: 100%;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1.5px solid #cbd5e1;
    border-radius: 18px;
    padding: clamp(10px, 2vw, 20px);
    box-shadow: inset 0 2px 6px rgba(15, 23, 42, 0.06), 0 8px 24px -6px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* شريط تمرير ناعم عند الحاجة على الشاشات الضيقة جداً */
.cw-grid-container::-webkit-scrollbar {
    height: 6px;
}
.cw-grid-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 9999px;
}

/* شبكة الكلمات بنظام Grid مع دعم التجاوب */
.cw-grid-el {
    display: -ms-grid;
    display: grid;
    gap: 3px;
    gap: clamp(2px, 0.5vw, 4px);
    margin: 0 auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* خلايا الشبكة — px ثابت قبل var() كي لا تنهار لمتصفح بلا متغيرات CSS */
.cw-cell {
    position: relative;
    width: 40px;
    width: var(--cw-cell-size, 42px);
    height: 40px;
    height: var(--cw-cell-size, 42px);
    min-width: 26px;
    min-height: 26px;
    border-radius: clamp(4px, 1vw, 8px);
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

/* الخلية الفارغة غير المستخدمة (شفافة وخفيفة) */
.cw-cell.is-empty {
    background: transparent;
    border: none;
    pointer-events: none;
}

/* خلية الحرف المتاحة للكتابة */
.cw-cell.is-letter {
    background: #ffffff;
    border: 2px solid #cbd5e1;
    box-shadow: 0 2px 5px rgba(15, 23, 42, 0.08);
    cursor: pointer;
}

.cw-cell.is-letter:hover:not(.is-locked) {
    border-color: #94a3b8;
    transform: translateY(-1px);
    -webkit-transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(15, 23, 42, 0.12);
}

/* الخلية ضمن الكلمة النشطة حالياً */
.cw-cell.is-word-active {
    background: #f0fdf4;
    border-color: #86efac;
}

/* الخلية المركّز عليها حالياً للكتابة */
.cw-cell.is-focused {
    background: #ffffff !important;
    border-color: #4f46e5 !important;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.28), 0 4px 12px rgba(79, 70, 229, 0.18) !important;
    transform: scale(1.06);
    -webkit-transform: scale(1.06);
    z-index: 10;
}

/* حالات التحقق */
.cw-cell.is-correct {
    background: #ecfdf5 !important;
    border-color: #10b981 !important;
    color: #047857 !important;
}

.cw-cell.is-incorrect {
    background: #fff1f2 !important;
    border-color: #f43f5e !important;
    color: #be123c !important;
    animation: cwShake 0.4s ease-in-out;
    -webkit-animation: cwShake 0.4s ease-in-out;
}

/* رقم الكلمة في زاوية الخلية */
.cw-num-badge {
    position: absolute;
    top: 2px;
    inset-inline-start: 3px;
    font-size: clamp(0.6rem, 1.1vw, 0.72rem);
    font-weight: 900;
    line-height: 1;
    color: #475569;
    pointer-events: none;
    z-index: 4;
}

/* حقل إدخال الحرف */
.cw-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-family: "Baloo Bhaijaan 2", Tajawal, system-ui, -apple-system, sans-serif;
    font-weight: 900;
    font-size: clamp(1.1rem, 2.2vw, 1.55rem);
    line-height: 1;
    color: #0f172a;
    outline: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -webkit-appearance: none;
}

.cw-cell.is-correct .cw-input {
    color: #047857 !important;
}

.cw-cell.is-incorrect .cw-input {
    color: #be123c !important;
}

.cw-input:focus {
    cursor: text;
}

.cw-input:disabled {
    cursor: default;
}

/* حاوية دلالات الكلمات (Clues Container) */
.cw-clues-container {
    flex: 1 1 300px;
    max-width: 100%;
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-radius: 18px;
    padding: clamp(14px, 2vw, 22px);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
}

.cw-clues-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 10px;
}

.cw-clues-title {
    font-size: clamp(1.05rem, 1.8vw, 1.25rem);
    font-weight: 800;
    color: #1e1b4b;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cw-clues-sections {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cw-section-title {
    font-size: clamp(0.9rem, 1.4vw, 1.02rem);
    font-weight: 800;
    color: #4338ca;
    margin: 0 0 8px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.cw-clues-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cw-clue-item {
    padding: 8px 12px;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: clamp(0.85rem, 1.35vw, 0.96rem);
    color: #334155;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-transition: all 0.2s ease;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    line-height: 1.45;
}

.cw-clue-item:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    transform: translateX(-2px);
    -webkit-transform: translateX(-2px);
}

.cw-clue-item.is-active {
    background: #eef2ff;
    border-color: #6366f1;
    color: #312e81;
    box-shadow: 0 3px 10px rgba(99, 102, 241, 0.14);
    font-weight: 700;
}

.cw-clue-item.is-solved {
    opacity: 0.65;
    background: #f1f5f9;
}

.cw-clue-num {
    background: #4f46e5;
    color: #ffffff;
    font-size: 0.78rem;
    font-weight: 900;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}

.cw-clue-item.is-active .cw-clue-num {
    background: #4338ca;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.35);
}

.cw-clue-item.is-solved .cw-clue-num {
    background: #10b981;
}

/* شريط الإجراءات والتحقق */
.cw-actions-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: clamp(16px, 3vh, 26px);
    flex-wrap: wrap;
}

.cw-check-btn {
    min-width: 190px;
    padding: clamp(11px, 1.8vh, 15px) clamp(24px, 3vw, 36px);
    font-size: clamp(1.05rem, 1.8vw, 1.25rem);
    font-weight: 800;
    border-radius: 9999px;
    background: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.38);
    cursor: pointer;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.cw-check-btn:hover {
    transform: translateY(-2px);
    -webkit-transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.48);
}

.cw-retry-btn {
    padding: clamp(10px, 1.6vh, 14px) clamp(20px, 2.5vw, 28px);
    font-size: clamp(0.98rem, 1.6vw, 1.15rem);
    font-weight: 800;
    border-radius: 9999px;
    background: #f8fafc;
    color: #334155;
    border: 2px solid #cbd5e1;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-transition: all 0.2s;
}

.cw-retry-btn:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

/* شريط التغذية الراجعة والنتيجة */
.cw-feedback-banner {
    margin-top: 16px;
    padding: 12px 20px;
    border-radius: 12px;
    text-align: center;
    font-weight: 800;
    font-size: clamp(0.95rem, 1.6vw, 1.15rem);
    animation: cwBannerSlide 0.35s ease-out;
    -webkit-animation: cwBannerSlide 0.35s ease-out;
}

.cw-feedback-banner.is-success {
    background: #ecfdf5;
    color: #065f46;
    border: 1.5px solid #a7f3d0;
}

.cw-feedback-banner.is-partial {
    background: #fffbeb;
    color: #92400e;
    border: 1.5px solid #fde68a;
}

@keyframes cwBannerSlide {
    from { opacity: 0; transform: translateY(-8px); -webkit-transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); -webkit-transform: translateY(0); }
}

@-webkit-keyframes cwBannerSlide {
    from { opacity: 0; -webkit-transform: translateY(-8px); }
    to { opacity: 1; -webkit-transform: translateY(0); }
}

@keyframes cwShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@-webkit-keyframes cwShake {
    0%, 100% { -webkit-transform: translateX(0); }
    25% { -webkit-transform: translateX(-4px); }
    75% { -webkit-transform: translateX(4px); }
}

/* ========================================================
   وضع ملء الشاشة والشاشات الكبيرة (Fullscreen / Smartboards)
   ======================================================== */
.gpa-fullscreen .cw-player-wrap {
    max-width: 1280px;
}

.gpa-fullscreen .cw-cell {
    --cw-cell-size: clamp(38px, 4.5vw, 56px);
}

.gpa-fullscreen .cw-input {
    font-size: clamp(1.4rem, 2.5vw, 2rem);
}

.gpa-fullscreen .cw-num-badge {
    font-size: 0.85rem;
}

.gpa-fullscreen .cw-clue-item {
    font-size: 1.12rem;
    padding: 10px 16px;
}

.gpa-fullscreen .cw-clue-num {
    width: 26px;
    height: 26px;
    font-size: 0.95rem;
}

/* مصيدة غير بديهية: flex-gap غائب في Safari<14.1 — هوامش بديلة فقط عند الغياب */
@supports not (gap: 14px) {
    .cw-layout-container > * { margin: 7px; }
    .cw-clues-list > *, .cw-actions-bar > * { margin: 4px; }
}