/**
 * Eduplayify Game Mode: Flip & Reveal (cards)
 * طور اقلب واكتشف — تنسيقات شبكة البطاقات والانقلاب ثلاثي الأبعاد
 */

.q-cards-stage {
    position: relative;
    width: 100%;
    max-width: 860px;
    min-height: 100%;
    margin: auto;
    padding: 1.5rem 0.75rem 2rem;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.q-cards-header {
    text-align: center;
    margin-bottom: 1.5rem;
    width: 100%;
}

.q-cards-title {
    font-size: clamp(1.25rem, 3vw, 1.75rem);
    font-weight: 800;
    color: var(--text, #1e293b);
    margin: 0 0 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.q-cards-sub {
    font-size: 0.95rem;
    color: var(--text-muted, #64748b);
    margin: 0 0 0.75rem;
}

.q-cards-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 9999px;
    font-size: 0.88rem;
    font-weight: 700;
    background: rgba(99, 102, 241, 0.1);
    color: #4f46e5;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

[data-theme="dark"] .q-cards-status-pill,
.dark .q-cards-status-pill {
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
    border-color: rgba(99, 102, 241, 0.4);
}

/* شبكة البطاقات المتجاوبة الممركزة في وسط الساحة */
.q-cards-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 820px;
    margin: 1.25rem auto;
    box-sizing: border-box;
    perspective: 1000px;
}

@media (max-width: 480px) {
    .q-cards-grid {
        gap: 10px;
    }
}

/* هيكل البطاقة ثلاثية الأبعاد */
.q-card-item {
    position: relative;
    flex: 0 1 138px;
    width: 138px;
    max-width: 155px;
    aspect-ratio: 3 / 4;
    min-height: 145px;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    perspective: 1000px;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (max-width: 480px) {
    .q-card-item {
        flex: 0 1 102px;
        width: 102px;
        min-height: 122px;
    }
}

.q-card-item:focus-visible {
    outline: 3px solid #6366f1;
    outline-offset: 4px;
    border-radius: 16px;
}

.q-card-item:hover:not(.is-solved):not(.is-revealing) {
    transform: translateY(-6px) scale(1.02);
}

.q-card-item:active:not(.is-solved):not(.is-revealing) {
    transform: translateY(-2px) scale(0.98);
}

.q-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 16px;
    box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.15), 0 4px 8px -2px rgba(0, 0, 0, 0.08);
}

.q-card-item.is-flipped .q-card-inner,
.q-card-item.is-solved .q-card-inner {
    transform: rotateY(180deg);
}

/* وجه البطاقة الأمامي (قبل الكشف) */
.q-card-front,
.q-card-back {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 12px 8px;
    overflow: hidden;
}

.q-card-front {
    background: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%);
    color: #ffffff;
    border: 2px solid rgba(255, 255, 255, 0.22);
}

/* نقوش هندسية جمالية لخلفية البطاقة */
.q-card-front::before {
    content: '';
    position: absolute;
    inset: 6px;
    border: 1px dashed rgba(255, 255, 255, 0.35);
    border-radius: 11px;
    pointer-events: none;
}

.q-card-front::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 65%);
    pointer-events: none;
}

/* ألوان مميزة لكل بطاقة بناءً على موقعها */
.q-card-item:nth-child(8n + 1) .q-card-front { background: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%); }
.q-card-item:nth-child(8n + 2) .q-card-front { background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%); }
.q-card-item:nth-child(8n + 3) .q-card-front { background: linear-gradient(135deg, #059669 0%, #047857 100%); }
.q-card-item:nth-child(8n + 4) .q-card-front { background: linear-gradient(135deg, #d97706 0%, #b45309 100%); }
.q-card-item:nth-child(8n + 5) .q-card-front { background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%); }
.q-card-item:nth-child(8n + 6) .q-card-front { background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%); }
.q-card-item:nth-child(8n + 7) .q-card-front { background: linear-gradient(135deg, #db2777 0%, #9d174d 100%); }
.q-card-item:nth-child(8n + 8) .q-card-front { background: linear-gradient(135deg, #0d9488 0%, #115e59 100%); }

.q-card-icon {
    font-size: 1.8rem;
    line-height: 1;
    margin-bottom: 4px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
    transition: transform 0.3s ease;
}

.q-card-item:hover:not(.is-solved) .q-card-icon {
    transform: scale(1.15) rotate(5deg);
}

.q-card-num {
    font-size: 1.15rem;
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
    z-index: 1;
}

.q-card-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    z-index: 1;
}

/* وجه البطاقة الخلفي (بعد الانقلاب / الحل) */
.q-card-back {
    transform: rotateY(180deg);
    background: #ffffff;
    color: #1e293b;
    border: 2px solid #cbd5e1;
}

[data-theme="dark"] .q-card-back,
.dark .q-card-back {
    background: #1e293b;
    color: #f8fafc;
    border-color: #334155;
}

/* البطاقة المكتملة */
.q-card-item.is-solved {
    cursor: default;
    opacity: 0.72;
}

.q-card-item.is-solved .q-card-inner {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.q-card-solved-badge {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    font-weight: 800;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    margin-bottom: 6px;
}

.q-card-solved-text {
    font-size: 0.78rem;
    font-weight: 800;
    color: #059669;
}

[data-theme="dark"] .q-card-solved-text,
.dark .q-card-solved-text {
    color: #34d399;
}

/* شريط زر العودة للبطاقات */
.q-cards-back-bar {
    display: flex;
    justify-content: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border, #e2e8f0);
}

.q-cards-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 24px;
    font-size: 1rem;
    font-weight: 800;
    border-radius: 9999px;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.q-cards-back-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.35);
}
