/**
 * Eduplayify Game Mode: Mystery Chests / Box Opener (mystery_chests)
 * طور صناديق الحظ والمفاجآت — تنسيقات خفيفة وعالية الأداء بألوان الخزنة الملكية
 * المتوافق مع §10 (الأجهزة الضعيفة والمتصفحات القديمة).
 */

.mchest-stage {
    position: relative;
    width: 100%;
    border-radius: 16px;
    background: #131129;
    background: linear-gradient(155deg, #0f172a 0%, #1e1b4b 52%, #2e1065 100%);
    padding: 12px 14px 16px;
    box-sizing: border-box;
    color: #f8fafc;
    overflow: hidden;
    border: 1.5px solid rgba(251, 191, 36, 0.28);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* HUD الشريط العلوي */
.mchest-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    padding: 8px 10px;
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 12px;
}

.mchest-hud-stats {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.mchest-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1.3;
    white-space: nowrap;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mchest-pill-coins {
    background: rgba(245, 158, 11, 0.18);
    border: 1.5px solid #f59e0b;
    color: #fde68a;
}

.mchest-pill-coins.is-bumped {
    transform: scale(1.12);
    box-shadow: 0 0 14px rgba(251, 191, 36, 0.65);
}

.mchest-pill-shield {
    background: rgba(148, 163, 184, 0.14);
    border: 1.5px solid rgba(148, 163, 184, 0.35);
    color: #94a3b8;
}

.mchest-pill-shield.is-active {
    background: rgba(6, 182, 212, 0.22);
    border-color: #22d3ee;
    color: #cffafe;
    box-shadow: 0 0 10px rgba(34, 211, 238, 0.4);
}

.mchest-pill-streak {
    background: rgba(249, 115, 22, 0.22);
    border: 1.5px solid #fb923c;
    color: #fed7aa;
}

.mchest-freeze-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #e2e8f0;
    border-radius: 9999px;
    padding: 4px 10px;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.mchest-freeze-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.mchest-freeze-btn.is-on {
    background: rgba(16, 185, 129, 0.24);
    border-color: #34d399;
    color: #a7f3d0;
}

/* لوحة المنافسة الوهمية المصغّرة */
.mchest-rivals {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.mchest-rival-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 0.74rem;
    font-weight: 700;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #cbd5e1;
    transition: transform 0.25s ease, border-color 0.25s ease;
}

.mchest-rival-chip.is-player {
    background: rgba(79, 70, 229, 0.32);
    border-color: #818cf8;
    color: #ffffff;
}

.mchest-rival-chip.is-stolen {
    border-color: #f87171;
    transform: scale(0.95);
}

.mchest-rival-score {
    color: #fbbf24;
    font-weight: 800;
}

/* حاوية السؤال داخل الطور (تترك قوالب الأسئلة الـ25 واضحة ومقروءة) */
.mchest-q-host {
    background: #ffffff;
    color: #1e293b;
    border-radius: 14px;
    padding: 14px 14px 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    min-height: 220px;
    position: relative;
}

/* إشعار درع الحماية / الأحداث */
.mchest-toast {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0 auto 10px;
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 800;
    text-align: center;
    animation: mchestPop 0.28s ease-out;
}

.mchest-toast.is-visible {
    display: flex;
}

.mchest-toast.is-shield {
    background: rgba(6, 182, 212, 0.22);
    border: 1.5px solid #22d3ee;
    color: #ecfeff;
}

.mchest-toast.is-steal {
    background: rgba(245, 158, 11, 0.22);
    border: 1.5px solid #fbbf24;
    color: #fef3c7;
}

.mchest-toast.is-warn {
    background: rgba(239, 68, 68, 0.22);
    border: 1.5px solid #f87171;
    color: #fee2e2;
}

/* ساحة صناديق الحظ الـ4 */
.mchest-arena {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 12px 6px 8px;
}

.mchest-arena-header {
    margin-bottom: 12px;
    width: 100%;
    max-width: 560px;
}

.mchest-arena-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 0.78rem;
    font-weight: 800;
    background: rgba(251, 191, 36, 0.18);
    border: 1px solid rgba(251, 191, 36, 0.5);
    color: #fde68a;
    margin-bottom: 6px;
}

.mchest-arena-title {
    margin: 0 0 4px;
    font-size: clamp(1.1rem, 2.5vw, 1.4rem);
    font-weight: 800;
    color: #ffffff;
}

.mchest-arena-sub {
    margin: 0;
    font-size: 0.86rem;
    color: #cbd5e1;
    line-height: 1.5;
}

/* شريط العد التنازلي قبل الخلط */
.mchest-countdown-wrap {
    width: 100%;
    max-width: 360px;
    height: 7px;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 9999px;
    overflow: hidden;
    margin: 10px auto 0;
}

.mchest-countdown-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #fbbf24, #f97316);
    border-radius: 9999px;
    transform-origin: left center;
    transition: width 2s linear;
}

html[dir="rtl"] .mchest-countdown-fill {
    transform-origin: right center;
}

/* شبكة الصناديق الـ4 */
.mchest-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    width: 100%;
    max-width: 720px;
    margin: 10px auto 14px;
    position: relative;
}

@media (max-width: 680px) {
    .mchest-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        max-width: 420px;
    }
}

.mchest-card {
    position: relative;
    background: rgba(30, 27, 75, 0.9);
    background: linear-gradient(170deg, rgba(49, 46, 129, 0.92) 0%, rgba(15, 23, 42, 0.96) 100%);
    border: 2px solid rgba(251, 191, 36, 0.38);
    border-radius: 16px;
    padding: 12px 8px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    min-height: 146px;
    color: #ffffff;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.25s ease;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.32);
    will-change: transform;
}

.mchest-card.is-pickable {
    cursor: pointer;
    border-color: rgba(251, 191, 36, 0.72);
    animation: mchestPulse 1.6s ease-in-out infinite;
}

.mchest-card.is-pickable:hover,
.mchest-card.is-pickable:focus-visible {
    transform: translateY(-5px) scale(1.03);
    border-color: #fde047;
    box-shadow: 0 14px 28px rgba(245, 158, 11, 0.35);
    outline: none;
}

.mchest-card.is-pickable:active {
    transform: translateY(-1px) scale(0.98);
}

.mchest-card.is-shuffling {
    transition: transform 0.26s cubic-bezier(0.45, 0.05, 0.55, 0.95);
    z-index: 5;
    border-color: #38bdf8;
    box-shadow: 0 10px 24px rgba(56, 189, 248, 0.35);
}

.mchest-card.is-chosen {
    border-color: #fde047;
    background: linear-gradient(170deg, rgba(120, 53, 15, 0.85) 0%, rgba(49, 46, 129, 0.96) 100%);
    box-shadow: 0 0 26px rgba(251, 191, 36, 0.55);
    transform: scale(1.04);
    z-index: 4;
}

.mchest-card.is-peek {
    opacity: 0.6;
    border-color: rgba(255, 255, 255, 0.22);
}

/* رقم الصندوق */
.mchest-num {
    position: absolute;
    top: 7px;
    inset-inline-start: 8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.82);
    border: 1px solid rgba(251, 191, 36, 0.55);
    color: #fde68a;
    font-size: 0.72rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* غلاف الصندوق SVG */
.mchest-svg-wrap {
    position: relative;
    width: 78px;
    height: 68px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 6px;
}

.mchest-svg {
    width: 74px;
    height: 64px;
    overflow: visible;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.45));
}

.mchest-lid {
    transform-origin: 40px 28px;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mchest-card.is-open .mchest-lid {
    transform: translateY(-9px) rotate(-18deg);
}

.mchest-glow-beam {
    opacity: 0;
    transition: opacity 0.28s ease;
}

.mchest-card.is-open .mchest-glow-beam {
    opacity: 1;
}

/* شارة المكافأة المنبثقة من الصندوق */
.mchest-reward-box {
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    margin-top: 4px;
    transition: opacity 0.22s ease, transform 0.25s ease;
}

.mchest-card.is-closed .mchest-reward-box {
    opacity: 0;
    transform: scale(0.7);
}

.mchest-card.is-open .mchest-reward-box {
    opacity: 1;
    transform: scale(1);
}

.mchest-reward-ico {
    font-size: 1.25rem;
    line-height: 1.1;
}

.mchest-reward-lbl {
    font-size: 0.78rem;
    font-weight: 800;
    color: #fef3c7;
    line-height: 1.25;
}

.mchest-closed-hint {
    position: absolute;
    bottom: 11px;
    left: 6px;
    right: 6px;
    font-size: 0.74rem;
    font-weight: 800;
    color: #fde68a;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.mchest-card.is-closed.is-pickable .mchest-closed-hint {
    opacity: 1;
}

/* كونفيتي CSS خفيف على الصندوق المختار (8 عناصر فقط) */
.mchest-burst {
    position: absolute;
    top: 32%;
    left: 50%;
    width: 4px;
    height: 4px;
    pointer-events: none;
}

.mchest-spark {
    position: absolute;
    width: 7px;
    height: 7px;
    border-radius: 2px;
    animation: mchestSparkOut 0.65s ease-out forwards;
}

@keyframes mchestSparkOut {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--tx, 0px), var(--ty, -30px)) scale(0.3) rotate(160deg); opacity: 0; }
}

@keyframes mchestPulse {
    0%, 100% { box-shadow: 0 8px 18px rgba(0, 0, 0, 0.32), 0 0 0 0 rgba(251, 191, 36, 0.25); }
    50% { box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32), 0 0 0 5px rgba(251, 191, 36, 0.14); }
}

@keyframes mchestPop {
    from { opacity: 0; transform: scale(0.92) translateY(6px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* أزرار التحكم أسفل الصناديق */
.mchest-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 6px;
}

.mchest-btn-primary {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #ffffff;
    border: none;
    border-radius: 9999px;
    padding: 9px 22px;
    font-size: 0.94rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(245, 158, 11, 0.38);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.mchest-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(245, 158, 11, 0.5);
}

.mchest-result-banner {
    background: rgba(15, 23, 42, 0.85);
    border: 1.5px solid #fbbf24;
    border-radius: 12px;
    padding: 10px 16px;
    margin: 4px auto 10px;
    max-width: 480px;
    animation: mchestPop 0.28s ease-out;
}

.mchest-result-banner h4 {
    margin: 0 0 3px;
    font-size: 1.02rem;
    font-weight: 800;
    color: #fde047;
}

.mchest-result-banner p {
    margin: 0;
    font-size: 0.84rem;
    color: #e2e8f0;
}

/* شاشة البداية داخل الطور */
.mchest-start-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px 14px;
    min-height: 290px;
}

.mchest-start-features {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    max-width: 480px;
    width: 100%;
    margin: 14px 0 18px;
}

@media (max-width: 480px) {
    .mchest-start-features {
        grid-template-columns: 1fr;
    }
}

.mchest-feat-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    font-size: 0.82rem;
    font-weight: 700;
    color: #f1f5f9;
    text-align: start;
}

/* بطاقة ملخص الكنز المدمجة في شاشة النهاية */
.mchest-finish-summary {
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
    color: #ffffff;
    border: 1.5px solid rgba(251, 191, 36, 0.55);
    border-radius: 14px;
    padding: 12px 18px;
    margin: 10px auto 6px;
    max-width: 440px;
    width: 100%;
    box-sizing: border-box;
    box-shadow: 0 8px 22px rgba(30, 27, 75, 0.25);
}

.mchest-finish-summary-grid {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 8px;
}

.mchest-finish-stat {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 0.84rem;
    font-weight: 800;
    color: #fde68a;
}

@media (prefers-reduced-motion: reduce) {
    .mchest-card,
    .mchest-lid,
    .mchest-countdown-fill,
    .mchest-spark {
        animation: none !important;
        transition: none !important;
    }
}
