/* ملف CSS للبازل - النسخة النهائية مع تأثيرات الفيد والزوم */
/* assets/puzzle-contest.css */

/* منع التمرير عند فتح البوب أب */
body.puzzle-no-scroll {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* زر تشغيل المسابقة */
.puzzle-contest-trigger {
    background: rgb(50,84,172);
    color: white;
    padding: 15px 30px;
    border: none;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    margin: 10px 0;
    touch-action: manipulation;
}

.puzzle-contest-trigger:hover,
.puzzle-contest-trigger:active {
    background: rgb(16,141,205);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

/* البوب أب الرئيسي - z-index عالي جداً */
.puzzle-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999999;
    backdrop-filter: blur(5px);
    padding: 10px;
}

.puzzle-popup-container {
    background: white;
    border-radius: 20px;
    padding: 20px;
    width: 100%;
    max-width: 400px;
    max-height: 95vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: popupSlideIn 0.3s ease;
}

@keyframes popupSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* زر الإغلاق - في الزاوية بالضبط مع الألوان الجديدة */
.puzzle-close-btn {
    position: absolute !important;
    top: 0 !important;
    right: 0 !important;
    background: rgb(50,84,172) !important;
    background-color: rgb(50,84,172) !important;
    border: none !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 0 20px 0 15px !important;
    cursor: pointer !important;
    color: white !important;
    transition: all 0.3s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 10 !important;
    touch-action: manipulation !important;
    font-size: 24px !important;
    font-weight: bold !important;
    font-family: Arial, sans-serif !important;
}

.puzzle-popup-container .puzzle-close-btn {
    background: rgb(50,84,172) !important;
    background-color: rgb(50,84,172) !important;
    color: white !important;
    border: none !important;
}

.puzzle-close-btn:hover,
.puzzle-close-btn:active,
.puzzle-close-btn:focus {
    background: rgb(16,141,205) !important;
    background-color: rgb(16,141,205) !important;
    color: white !important;
    transform: scale(1.05) !important;
    border: none !important;
}

/* عنوان المسابقة */
.puzzle-title {
    text-align: center;
    color: rgb(50,84,172);
    margin-bottom: 10px;
    font-size: 20px;
    font-weight: bold;
    padding-right: 40px;
}

/* نص الإرشادات البسيط */
.puzzle-instructions-text {
    text-align: center;
    color: #666;
    font-size: 16px;
    margin-bottom: 20px;
    padding: 0 20px;
    line-height: 1.4;
}

/* للكمبيوتر */
@media (min-width: 768px) {
    .puzzle-instructions-text {
        font-size: 18px;
        margin-bottom: 25px;
    }
}

/* منطقة اللعبة */
.puzzle-game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* إطار البازل - محسن للموبايل */
.puzzle-container {
    position: relative;
    width: 100%;
    max-width: 300px;
    height: 300px;
    border: 3px solid #ddd;
    border-radius: 15px;
    background: #f8f9fa;
    overflow: hidden;
    transition: all 0.5s ease;
    margin: 0 auto;
}

.puzzle-content {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* wrapper للصورة الأصلية */
.original-image-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* الصورة الكاملة داخل الإطار */
.full-frame-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    transition: all 0.5s ease;
    will-change: transform, opacity;
    transform: translateZ(0);
}

.full-frame-image.success-image {
    animation: successZoom 0.8s ease;
}

/* تأثير الفيد للصورة الثانية (الوسط) */
.middle-image.fade-in {
    animation: fadeInMiddle 0.6s ease-in-out;
}

@keyframes fadeInMiddle {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* تنسيق الصورة الثانية */
.middle-image {
    transition: all 0.4s ease;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    border: 2px solid #e0e0e0;
}

/* تأثير الزوم للصورة الثالثة (النهائية) */
.success-image.zoom-in {
    animation: zoomInSuccess 1s ease-out;
}

@keyframes zoomInSuccess {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* تأثير إضافي للصورة النهائية */
.success-image {
    transition: all 0.3s ease;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

/* تأثير خفيف مستمر بعد الظهور */
.success-image.zoom-in {
    animation: zoomInSuccess 1s ease-out, successGlow 3s ease-in-out infinite;
}

@keyframes successGlow {
    0%, 100% {
        box-shadow: 0 8px 25px rgba(0,0,0,0.2);
    }
    50% {
        box-shadow: 0 8px 35px rgba(78, 205, 196, 0.4);
    }
}

@keyframes successZoom {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.7;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.full-frame-image.animate-success {
    animation: successPulse 2s ease infinite;
}

@keyframes successPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 20px rgba(78, 205, 196, 0.3);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 0 30px rgba(78, 205, 196, 0.6);
    }
}

/* عدم وجود صورة */
.no-image-placeholder {
    width: 100%;
    height: 100%;
    background: #f0f0f0;
    border: 2px dashed #ccc;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 16px;
    text-align: center;
}

/* شبكة البازل داخل الإطار */
.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2px;
    width: 100%;
    height: 100%;
    padding: 5px;
    transition: all 0.3s ease;
    will-change: transform;
    transform: translateZ(0);
}

.puzzle-grid.fade-out {
    opacity: 0;
    transform: scale(0.95);
}

/* قطعة البازل - محسنة للموبايل */
.puzzle-piece {
    background-size: cover;
    background-repeat: no-repeat;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    min-height: 80px;
    will-change: transform;
    transform: translateZ(0);
}

.puzzle-piece:hover,
.puzzle-piece:active {
    transform: scale(1.05);
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    z-index: 10;
    border-color: #4ecdc4;
}

.puzzle-piece.selected {
    border: 3px solid #ff6b6b;
    transform: scale(1.08);
    box-shadow: 0 0 15px rgba(255, 107, 107, 0.6);
    z-index: 20;
}

.puzzle-piece.swapping {
    animation: swapAnimation 0.3s ease;
}

@keyframes swapAnimation {
    50% {
        transform: scale(1.15);
        box-shadow: 0 6px 15px rgba(0,0,0,0.3);
    }
}

.puzzle-piece.solved {
    border: 3px solid #4ecdc4;
    animation: solvedPulse 0.6s ease;
}

@keyframes solvedPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(78, 205, 196, 0.5);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(78, 205, 196, 0.8);
    }
}

/* رقم القطعة */
.piece-number {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0,0,0,0.7);
    color: white;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    opacity: 0.8;
}

/* معلومات اللعبة */
.puzzle-info {
    width: 100%;
    max-width: 300px;
}

.puzzle-stats {
    background: linear-gradient(135deg, rgb(50,84,172), rgb(16,141,205));
    color: white;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    text-align: center;
    border: 1px solid rgb(50,84,172);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.puzzle-stats span {
    font-weight: bold;
    color: white;
    font-size: 14px;
}

#moveCount, #timeCounter {
    color: white;
    font-size: 16px;
    font-weight: bold;
}

/* أزرار التحكم - محسنة للموبايل */
.puzzle-controls {
    display: flex;
    gap: 10px;
    width: 100%;
}

.puzzle-btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    touch-action: manipulation;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.puzzle-btn:hover,
.puzzle-btn:active {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.2);
}

.puzzle-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
    background: #ccc !important;
}

.puzzle-btn.disabled:hover,
.puzzle-btn.disabled:active {
    transform: none !important;
    box-shadow: none !important;
    background: #ccc !important;
}

.puzzle-btn-primary {
    background: rgb(50,84,172);
    color: white;
}

.puzzle-btn-primary:hover,
.puzzle-btn-primary:active {
    background: rgb(16,141,205);
}

.puzzle-btn-secondary {
    background: rgb(16,141,205);
    color: white;
}

.puzzle-btn-secondary:hover,
.puzzle-btn-secondary:active {
    background: rgb(50,84,172);
}

.puzzle-btn-secondary.disabled {
    background: #ccc;
}

.puzzle-btn-success {
    background: rgb(50,84,172);
    color: white;
}

.puzzle-btn-success:hover,
.puzzle-btn-success:active {
    background: rgb(16,141,205);
}

.puzzle-btn i {
    color: white;
    font-size: 14px;
}

/* نموذج التسجيل */
.contest-form-container {
    margin-top: 20px;
    width: 100%;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.puzzle-success-message h3 {
    color: #ffffff !important; /* أبيض */
    /* أو جرب هذه الألوان: */
    /* color: #ffd700 !important; */ /* ذهبي */
    /* color: #ffeb3b !important; */ /* أصفر فاتح */
    /* color: #4caf50 !important; */ /* أخضر */
    /* color: #ff9800 !important; */ /* برتقالي */
}

.puzzle-success-message {
    background: #d60000;
    color: white;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    text-align: center;
}

.puzzle-success-message h3 {
    margin-bottom: 10px;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.puzzle-success-message h3 i {
    color: white;
    font-size: 24px;
}

.puzzle-success-message p {
    margin-bottom: 5px;
    opacity: 0.9;
    font-size: 14px;
}

.contest-form {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 15px;
    border: 1px solid #e0e0e0;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group label i {
    color: rgb(50,84,172);
    font-size: 16px;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus {
    outline: none;
    border-color: rgb(50,84,172);
    box-shadow: 0 0 5px rgba(50,84,172,0.3);
}

.puzzle-btn-success {
    background: rgb(50,84,172);
    color: white;
    padding: 15px 30px;
    border: none;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    transition: all 0.3s ease;
    touch-action: manipulation;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.puzzle-btn-success:hover,
.puzzle-btn-success:active {
    background: rgb(16,141,205);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.2);
}

.puzzle-btn-success i {
    color: white;
    font-size: 16px;
}

/* رسالة النجاح النهائية */
.puzzle-final-success {
    text-align: center;
    background: rgb(16,141,205);
    color: white;
    padding: 25px;
    border-radius: 15px;
    margin-top: 20px;
    animation: finalSuccessAppear 0.5s ease;
}

@keyframes finalSuccessAppear {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.puzzle-final-success h2 {
    margin-bottom: 15px;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.puzzle-final-success h2 i {
    color: white;
    font-size: 28px;
}

.puzzle-final-success p {
    margin-bottom: 10px;
    opacity: 0.9;
    font-size: 14px;
}

/* تنبيه محسن للموبايل */
.mobile-alert {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999999;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.mobile-alert.show {
    opacity: 1;
}

.mobile-alert-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 300px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.mobile-alert-content p {
    margin-bottom: 20px;
    font-size: 16px;
    color: #333;
}

.mobile-alert-btn {
    background: rgb(50,84,172);
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    touch-action: manipulation;
}

.mobile-alert-btn:hover,
.mobile-alert-btn:active {
    background: rgb(16,141,205);
    transform: translateY(-2px);
}

/* تأثير الاهتزاز للأخطاء */
.shake {
    animation: shake 0.6s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* تأثيرات إضافية للقطع */
.puzzle-piece::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, 
        rgba(255,255,255,0.1) 25%, 
        transparent 25%, 
        transparent 50%, 
        rgba(255,255,255,0.1) 50%, 
        rgba(255,255,255,0.1) 75%, 
        transparent 75%
    );
    background-size: 15px 15px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.puzzle-piece:hover::before,
.puzzle-piece:active::before {
    opacity: 1;
}

/* تأثيرات الانتقال */
.puzzle-popup-overlay.closing {
    animation: fadeOut 0.3s ease;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* تنسيق خاص للوحة الإدارة */
.puzzle-contest-container {
    display: inline-block;
    margin: 10px 0;
}

/* تحسينات للشاشات الصغيرة جداً */
@media (max-width: 360px) {
    .puzzle-popup-container {
        padding: 15px;
        max-width: 340px;
    }
    
    .puzzle-container {
        max-width: 280px;
        height: 280px;
    }
    
    .puzzle-title {
        font-size: 18px;
    }
    
    .puzzle-btn {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    .puzzle-stats {
        padding: 12px;
    }
    
    .puzzle-stats span {
        font-size: 13px;
    }
}

/* تحسينات للشاشات الأكبر (تابلت) */
@media (min-width: 768px) {
    .puzzle-popup-container {
        max-width: 700px;
        padding: 30px;
    }
    
    .puzzle-game-area {
        flex-direction: row;
        align-items: flex-start;
    }
    
    .puzzle-info {
        max-width: 200px;
        margin-right: 20px;
    }
    
    .puzzle-controls {
        flex-direction: column;
    }
    
    .puzzle-btn {
        flex: none;
    }
}

/* تحسينات اللمس */
@media (hover: none) and (pointer: coarse) {
    .puzzle-piece:hover::before {
        opacity: 0;
    }
    
    .puzzle-piece:active::before {
        opacity: 1;
    }
    
    .puzzle-btn:hover {
        transform: none;
    }
    
    .puzzle-btn:active {
        transform: scale(0.98);
    }
}

/* منع التحديد والسحب */
.puzzle-popup-container * {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.puzzle-popup-container input {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}