/* ============================================================
   Eduplayify — Mode: edu_worm (الدودة التعليمية)
   نمط العرض مطابق لبقية الأطوار: مسرح عمودي داخل بطاقة المحرك،
   ترويسة سؤال + تلميح + صندوق كانفس متجاوب + شريط سفلي متناسق.
   - لا dvh (القاعدة 10) ولا CDN ولا ألوان تكشف الإجابة.
   - تحكم باللمس الانسيابي على الساحة مباشرة مع دعم لوحة المفاتيح.
   ============================================================ */

.ew-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 1050px;
    padding: 10px 4px;
    box-sizing: border-box;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    /* توسيط أفقي قاطع: العنصر فلكس له عرض محدَّد فيُحاذى لليسار ما لم تُكتب الهوامش
       (كان ينزاح داخل ملء الشاشة على الشاشات العريضة) */
    margin-inline: auto;
    align-self: center;
}

/* ---------- الترويسة ---------- */
.ew-header {
    text-align: center;
    margin-bottom: 8px;
    max-width: 1020px;
    width: 100%;
}

.ew-title {
    margin: 0 0 3px;
    font-size: clamp(1.05rem, 2.4vw, 1.35rem);
    font-weight: 800;
    color: var(--ink, #1e293b);
    line-height: 1.35;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ew-hint {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--ink-soft, #64748b);
    letter-spacing: -0.01em;
}

/* ---------- صندوق الكانفس ---------- */
.ew-canvas-box {
    position: relative;
    margin: 0 auto;
    border-radius: 20px;
    padding: 6px;
    background: linear-gradient(135deg, #e0e7ff 0%, #ede9fe 50%, #fce7f3 100%);
    box-shadow: 0 16px 36px -10px rgba(99, 102, 241, 0.25), 0 4px 18px rgba(15, 23, 42, 0.08);
    border: 2px solid rgba(165, 180, 252, 0.55);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 1020px;
    box-sizing: border-box;
}

.ew-canvas {
    display: block;
    border-radius: 14px;
    background: #FCFDFF;
    touch-action: none;
    max-width: 100%;
    box-shadow: inset 0 2px 8px rgba(15, 23, 42, 0.04);
}

/* ---------- نافذة الانطلاق ---------- */
.ew-start-overlay {
    position: absolute;
    inset: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(15, 23, 42, 0.36);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: 14px;
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s ease;
    padding: 12px;
    z-index: 5;
}

.ew-start-overlay.is-gone {
    opacity: 0;
    transform: scale(0.96);
    pointer-events: none;
}

.ew-start-icon {
    font-size: 2.3rem;
    animation: ewPulse 1.4s ease-in-out infinite alternate;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.25));
}

.ew-start-text {
    background: rgba(255, 255, 255, 0.96);
    border-radius: 14px;
    padding: 8px 18px;
    font-size: 0.88rem;
    font-weight: 800;
    color: #1e293b;
    text-align: center;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
    border: 1px solid rgba(226, 232, 240, 0.8);
}

@keyframes ewPulse {
    from { transform: translateY(-4px) scale(0.98); }
    to { transform: translateY(4px) scale(1.05); }
}

/* ---------- رسالة التغذية الراجعة ---------- */
.ew-toast {
    position: absolute;
    top: 14px;
    inset-inline: 0;
    margin: 0 auto;
    width: fit-content;
    max-width: 90%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    border-radius: 16px;
    background: #ffffff;
    border: 2px solid;
    box-shadow: 0 10px 25px -4px rgba(15, 23, 42, 0.18);
    font-weight: 800;
    font-size: 0.82rem;
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
    transition: opacity 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    z-index: 6;
}

.ew-toast.is-on {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.ew-toast-ok {
    border-color: #10b981;
    background: #ecfdf5;
    color: #064e3b;
}

.ew-toast-no {
    border-color: #f59e0b;
    background: #fffbeb;
    color: #78350f;
}

.ew-toast-emoji {
    font-size: 1.15rem;
    line-height: 1;
}

/* ---------- صورة السؤال (نفس صنف وقواعد بقية القوالب) ---------- */
/* في ملء الشاشة تُخفى: الساحة تحتاج الارتفاع كلّه، ويُقتطع العمود بلا فائدة.
   الإخفاء بـ CSS يخفض ارتفاع الترويسة تلقائيًا فيكبر الكانفس من جديد. */
#gamePlayArea:fullscreen .ew-stage .ws-image,
.gpa-fullscreen .ew-stage .ws-image {
    display: none !important;
}

/* ---------- لوحة الأسهم (D-pad) ---------- */
.ew-dpad {
    display: grid;
    grid-template-columns: repeat(3, auto);
    grid-template-rows: repeat(2, auto);
    gap: 7px;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
    direction: ltr;
}

.ew-dpad-btn {
    width: 46px;
    height: 46px;
    border: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    color: #ffffff;
    background: linear-gradient(160deg, #818cf8 0%, #6366f1 55%, #7c3aed 100%);
    box-shadow: 0 6px 14px -4px rgba(79, 70, 229, 0.55), 0 2px 4px rgba(15, 23, 42, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.45);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.ew-dpad-btn svg {
    width: 22px;
    height: 22px;
    display: block;
    fill: currentColor;
    filter: drop-shadow(0 1px 1px rgba(15, 23, 42, 0.28));
    pointer-events: none;
}

.ew-dpad-btn:hover {
    filter: brightness(1.07);
}

.ew-dpad-btn:active,
.ew-dpad-btn.is-pressed {
    transform: translateY(2px) scale(0.94);
    box-shadow: 0 2px 6px -2px rgba(79, 70, 229, 0.5), inset 0 2px 5px rgba(15, 23, 42, 0.22);
}

.ew-dpad-btn:focus-visible {
    outline: 3px solid #a5b4fc;
    outline-offset: 2px;
}

.ew-dpad-up { grid-area: 1 / 2 / 2 / 3; }
.ew-dpad-left { grid-area: 2 / 1 / 3 / 2; }
.ew-dpad-down { grid-area: 2 / 2 / 3 / 3; }
.ew-dpad-right { grid-area: 2 / 3 / 3 / 4; }

/* ---------- الشريط السفلي الصغير ---------- */
.ew-foot {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 10px;
    width: 100%;
    max-width: 1020px;
}

.ew-score-line {
    font-size: 0.88rem;
    font-weight: 800;
    color: var(--ink-soft, #475569);
    background: #f8fafc;
    padding: 6px 14px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ew-pause {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 6px 13px;
    border-radius: 12px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.ew-speed {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px;
    border-radius: 12px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
}

.ew-speed-btn {
    border: 0;
    background: transparent;
    border-radius: 9px;
    padding: 4px 9px;
    font-size: 0.72rem;
    font-weight: 700;
    color: #64748b;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.18s ease;
}

.ew-speed-btn.is-on {
    background: #ffffff;
    color: #4338ca;
    font-weight: 800;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
}

/* ---------- شاشات صغيرة والتحسين المتجاوب ---------- */
@media (max-width: 560px) {
    .ew-stage {
        padding: 4px 2px;
    }
    .ew-header {
        margin-bottom: 6px;
    }
    .ew-title {
        font-size: 0.98rem;
    }
    .ew-hint {
        font-size: 0.74rem;
    }
    .ew-canvas-box {
        padding: 4px;
        border-radius: 16px;
    }
    .ew-canvas {
        border-radius: 12px;
    }
    .ew-dpad {
        gap: 6px;
        margin-top: 8px;
    }
    .ew-dpad-btn {
        width: 42px;
        height: 42px;
    }
    .ew-dpad-btn svg {
        width: 19px;
        height: 19px;
    }
    .ew-foot {
        gap: 8px;
        margin-top: 8px;
    }
    .ew-speed-btn {
        font-size: 0.65rem;
        padding: 3px 7px;
    }
    .ew-score-line {
        font-size: 0.78rem;
        padding: 5px 10px;
    }
    .ew-pause {
        font-size: 0.74rem;
        padding: 5px 9px;
    }
    .ew-toast {
        font-size: 0.76rem;
        padding: 6px 12px;
    }
}