/* استيراد خط عربي جميل */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;900&display=swap');

/* إعادة تعيين وإعدادات عامة */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', sans-serif;
    direction: rtl;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

/* Canvas اللعبة */
#gameCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* الشاشات */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    animation: fadeIn 0.5s ease;
}

.screen.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* القائمة الرئيسية */
.menu-container {
    text-align: center;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    animation: slideUp 0.6s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.game-title {
    font-size: 3rem;
    font-weight: 900;
    margin-bottom: 0.5rem;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3);
    background: linear-gradient(45deg, #fff, #ffd700);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-subtitle {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.menu-btn {
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-family: 'Cairo', sans-serif;
    font-weight: 600;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
}

.menu-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    background: rgba(255, 255, 255, 0.3);
}

.menu-btn.primary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;
    font-size: 1.4rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.menu-btn.primary:hover {
    background: linear-gradient(135deg, #f5576c 0%, #f093fb 100%);
}

.credits {
    font-size: 0.9rem;
    opacity: 0.7;
}

/* شاشة التعليمات */
.instructions-container {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    padding: 2rem;
    border-radius: 20px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.instructions-container h2 {
    color: #667eea;
    margin-bottom: 1.5rem;
    font-size: 2rem;
}

.instruction-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 10px;
    border-right: 4px solid #667eea;
}

.instruction-section h3 {
    color: #764ba2;
    margin-bottom: 0.7rem;
}

.instruction-section ul {
    list-style: none;
    padding-right: 1rem;
}

.instruction-section li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

/* شاشة المستويات */
.levels-container {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    padding: 2rem;
    border-radius: 20px;
    max-width: 700px;
    max-height: 85vh;
    /* السماح بالتمرير إذا كان المحتوى طويلاً */
    overflow-y: auto;
    /* تفعيل شريط التمرير */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.levels-container h2 {
    color: #667eea;
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 2rem;
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
    width: 100%;
    /* ضمان العرض الكامل */
}

.level-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 1.5rem;
    border-radius: 15px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.level-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.level-card.locked {
    background: #999;
    cursor: not-allowed;
    opacity: 0.6;
}

.level-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.level-card h3 {
    margin-bottom: 0.5rem;
}

.level-btn {
    margin-top: 1rem;
    padding: 0.5rem 1.5rem;
    background: rgba(255, 255, 255, 0.3);
    border: none;
    border-radius: 20px;
    color: #fff;
    font-family: 'Cairo', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
}

.level-card:not(.locked) .level-btn:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* واجهة اللعب */
#gameUI {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

#gameUI.hidden {
    display: none;
}

#gameUI>* {
    pointer-events: auto;
}

.top-bar {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1rem;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    border-radius: 50px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.stat-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-label {
    font-weight: 600;
    font-size: 1rem;
}

.stat-value {
    font-weight: 900;
    font-size: 1.3rem;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.energy-bar {
    width: 150px;
    height: 20px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.energy-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #00ff88, #00ddff);
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.bottom-left {
    position: absolute;
    bottom: 20px;
    right: 20px;
}

.germs-counter {
    background: rgba(0, 0, 0, 0.6);
    padding: 1rem 1.5rem;
    border-radius: 20px;
    font-size: 1.2rem;
    font-weight: 600;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.counter-value {
    color: #ff6b6b;
    font-weight: 900;
    font-size: 1.5rem;
}

.game-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 2rem 3rem;
    border-radius: 20px;
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    animation: messageAppear 0.5s ease;
    transition: opacity 0.5s ease;
}

.game-message.hidden {
    opacity: 0;
    pointer-events: none;
}

@keyframes messageAppear {
    from {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

/* الشاشات المنبثقة */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    animation: fadeIn 0.3s ease;
}

.overlay.hidden {
    display: none;
}

.pause-container,
.result-container {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    padding: 2rem;
    border-radius: 20px;
    text-align: center;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.4s ease;
}

.pause-container h2,
.result-container h2 {
    color: #667eea;
    margin-bottom: 1.5rem;
    font-size: 2.5rem;
}

.pause-buttons,
.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.5rem;
}

.result-message {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: #666;
}

.stats-summary {
    background: rgba(102, 126, 234, 0.1);
    padding: 1rem;
    border-radius: 10px;
    margin: 1rem 0;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    font-size: 1.1rem;
}

.stat-item span:last-child {
    font-weight: 700;
    color: #667eea;
}

.educational-box {
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    padding: 1.5rem;
    border-radius: 15px;
    margin: 1.5rem 0;
    color: #2d3436;
    border: 3px solid #fdcb6e;
}

.educational-box h3 {
    margin-bottom: 0.8rem;
    font-size: 1.5rem;
}

.educational-box p {
    line-height: 1.6;
    font-size: 1.1rem;
}

.result-container.win h2 {
    color: #00b894;
}

.result-container.lose h2 {
    color: #d63031;
}

/* تأثيرات متحركة */
@keyframes float {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }
}

.game-title {
    animation: float 3s ease-in-out infinite;
}

/* استجابة للشاشات الصغيرة والمتوسطة */
@media (max-width: 768px) {
    .game-title {
        font-size: 2rem;
    }

    .top-bar {
        width: 95%;
        padding: 0.5rem;
        gap: 0.5rem;
        justify-content: center;
        flex-wrap: wrap;
    }

    .stat-box {
        background: rgba(0, 0, 0, 0.3);
        padding: 4px 8px;
        border-radius: 10px;
    }

    .stat-label {
        font-size: 0.8rem;
    }

    .stat-value {
        font-size: 1rem;
    }

    .energy-bar {
        width: 80px;
        height: 15px;
    }

    .levels-grid {
        grid-template-columns: 1fr;
    }

    .menu-container,
    .instructions-container,
    .levels-container,
    .pause-container,
    .result-container {
        width: 90%;
        max-width: 90%;
        max-height: 85vh;
        /* تقليل الارتفاع قليلاً لضمان عدم خروجه من الشاشة */
        overflow-y: auto;
        /* ضمان التمرير في الموبايل */
        padding: 1rem;
        margin: auto;
    }

    /* تحسين الأزرار للمس */
    .menu-btn,
    .icon-btn {
        min-height: 44px;
        /* الحد الأدنى الموصى به للمس */
        min-width: 44px;
    }

    .bottom-left {
        bottom: 10px;
        right: 10px;
        left: 10px;
        /* توسيط على الموبايل */
        text-align: center;
    }

    .germs-counter {
        display: inline-block;
        font-size: 1rem;
        padding: 0.5rem 1rem;
    }
}

/* استجابة للشاشات الصغيرة جداً (موبايل) */
@media (max-width: 480px) {
    .game-title {
        font-size: 1.5rem;
    }

    .top-bar {
        top: 10px;
        border-radius: 20px;
        flex-direction: row;
        /* الحفاظ على الأزرار في صف واحد قدر الإمكان أو السماح بالالتفاف */
    }

    .stat-box {
        font-size: 0.7rem;
    }

    .icon-btn {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }

    .menu-btn {
        width: 100%;
        /* أزرار كاملة العرض */
        font-size: 1rem;
        padding: 0.8rem;
    }
}

/* شريط التمرير المخصص */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.8);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 1);
}

/* عناصر التحكم باللمس */
.touch-controls {
    display: none;
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    justify-content: center;
    gap: 20px;
    z-index: 100;
    pointer-events: none;
    /* السماح بالنقر من خلال الحاوية */
}

.touch-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: white;
    font-size: 1.5rem;
    backdrop-filter: blur(5px);
    cursor: pointer;
    pointer-events: auto;
    /* إعادة تفعيل النقر للأزرار */
    transition: transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

.touch-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.4);
}

.touch-btn.power {
    background: rgba(255, 215, 0, 0.3);
    border-color: rgba(255, 215, 0, 0.6);
    transform: translateY(-20px);
    /* رفع زر الطاقة قليلاً */
}

/* إظهار التحكم باللمس فقط على الشاشات الصغيرة */
@media (max-width: 768px) {
    .touch-controls {
        display: flex;
    }
}