/* ===================================
   لعبة الغذاء الصحي - التصميم الرئيسي
   =================================== */

/* استيراد خطوط Google */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;700&family=Changa:wght@700&display=swap');

/* المتغيرات */
:root {
    /* الألوان الرئيسية */
    --primary: #4CAF50;
    --primary-light: #81C784;
    --primary-dark: #388E3C;

    --secondary: #FF9800;
    --secondary-light: #FFB74D;
    --secondary-dark: #F57C00;

    --accent: #E91E63;
    --accent-light: #F48FB1;

    /* ألوان النجوم والنقاط */
    --gold: #FFD700;
    --silver: #C0C0C0;
    --bronze: #CD7F32;

    /* ألوان الخلفية */
    --bg-gradient-start: #E8F5E9;
    --bg-gradient-end: #C8E6C9;
    --bg-game: #87CEEB;

    /* ألوان النصوص */
    --text-primary: #1B5E20;
    --text-secondary: #4E7350;
    --text-light: #FFFFFF;

    /* ألوان الحالات */
    --success: #4CAF50;
    --error: #F44336;
    --warning: #FF9800;

    /* الظلال */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.2);

    /* الانحناءات */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 50%;

    /* المسافات */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* الحركات */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

/* إعادة التعيين */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    min-height: 100vh;
    color: var(--text-primary);
    overflow-x: hidden;
    direction: rtl;
}

/* ===================================
   الشاشات
   =================================== */

.screen {
    display: none;
    min-height: 100vh;
    padding: var(--space-md);
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
}

/* ===================================
   شاشة البداية
   =================================== */

.logo-wrapper {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.food-icons {
    display: flex;
    justify-content: center;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.bounce-icon {
    font-size: 2.5rem;
    animation: bounce 1s infinite;
    animation-delay: var(--delay);
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-15px);
    }
}

.game-title {
    font-family: 'Changa', 'Cairo', sans-serif;
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: var(--space-sm);
}

.game-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* نموذج اللاعب */
.player-form {
    background: white;
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--space-lg);
}

.player-form label {
    display: block;
    font-weight: 700;
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}

.player-form input {
    width: 100%;
    padding: var(--space-md);
    font-size: 1.1rem;
    font-family: inherit;
    border: 2px solid var(--primary-light);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    text-align: center;
    transition: var(--transition-fast);
}

.player-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

/* الإحصائيات */
.stats-preview {
    display: flex;
    justify-content: center;
    gap: var(--space-xl);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: white;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    font-size: 1.5rem;
    margin-bottom: var(--space-xs);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ===================================
   الأزرار
   =================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 700;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--secondary), var(--secondary-dark));
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: white;
}

.btn-back {
    background: white;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    padding: 0;
    font-size: 1.5rem;
    box-shadow: var(--shadow-sm);
}

/* ===================================
   شاشة المراحل
   =================================== */

.screen-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    width: 100%;
}

.screen-header h2 {
    flex: 1;
    text-align: center;
    font-family: 'Changa', sans-serif;
    font-size: 1.5rem;
}

.player-info {
    font-weight: 700;
    color: var(--primary-dark);
}

/* Levels Grid */
.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: var(--space-md);
    padding: var(--space-md);
    max-height: 60vh;
    overflow-y: auto;
    /* Scrollable for 100 levels */
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius-lg);
}

.level-btn {
    width: 70px;
    height: 70px;
    border-radius: var(--radius-lg);
    border: none;
    background: white;
    box-shadow: var(--shadow-sm);
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-dark);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.level-btn.locked {
    cursor: not-allowed;
}

.level-btn.locked::after {
    content: '🔒';
    position: absolute;
    font-size: 1.5rem;
}

.level-btn.completed {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    border-color: var(--primary-dark);
    color: white;
}

.level-btn:not(.locked):hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.level-number {
    font-size: 1.5rem;
    font-weight: 700;
}

.level-stars {
    font-size: 0.8rem;
    margin-top: var(--space-xs);
}

.level-stars .star {
    opacity: 0.3;
}

.level-stars .star.earned {
    opacity: 1;
}

/* التنقل السفلي */
.bottom-nav {
    display: flex;
    gap: var(--space-md);
    justify-content: center;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: white;
    border: 2px solid var(--primary-light);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.nav-btn:hover {
    background: var(--primary-light);
    color: white;
}

/* ===================================
   شاشة اللعب
   =================================== */

#game-screen {
    padding: 0;
    background: linear-gradient(180deg, #87CEEB 0%, #98D8C8 50%, #8FBC8F 100%);
}

.game-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
}

.btn-pause {
    background: white;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    padding: 0;
    font-size: 1.2rem;
    border: 2px solid var(--primary-light);
}

.game-stats {
    display: flex;
    gap: var(--space-lg);
    flex: 1;
    justify-content: center;
}

.game-stats .stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-stats .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.game-stats .value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.health-bar {
    width: 80px;
    height: 12px;
    background: #e0e0e0;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.health-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--success), var(--primary-light));
    transition: width 0.3s ease;
}

#game-canvas {
    display: block;
    width: 100%;
    flex: 1;
    touch-action: none;
}

/* أزرار التحكم للجوال */
.game-controls {
    display: none;
    padding: var(--space-md);
    gap: var(--space-lg);
    justify-content: center;
    background: rgba(255, 255, 255, 0.8);
}

.control-btn {
    width: 80px;
    height: 80px;
    font-size: 2rem;
    background: white;
    border: 3px solid var(--primary);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: var(--transition-fast);
}

.control-btn:active {
    background: var(--primary);
    color: white;
    transform: scale(0.95);
}

@media (max-width: 768px) {
    .game-controls.mobile-only {
        display: flex;
    }
}

/* ===================================
   شاشة النتيجة
   =================================== */

.result-container {
    text-align: center;
}

.result-header {
    margin-bottom: var(--space-lg);
}

.result-header h2 {
    font-family: 'Changa', sans-serif;
    font-size: 2rem;
    color: var(--primary-dark);
}

.stars-display {
    display: flex;
    justify-content: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.stars-display .star {
    font-size: 3rem;
    opacity: 0.3;
    transition: var(--transition-normal);
}

.stars-display .star.earned {
    opacity: 1;
    animation: starPop 0.5s ease;
}

@keyframes starPop {
    0% {
        transform: scale(0);
    }

    50% {
        transform: scale(1.3);
    }

    100% {
        transform: scale(1);
    }
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: var(--space-xl);
    margin-bottom: var(--space-lg);
}

.result-stat {
    background: white;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.result-stat .label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.result-stat .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.food-tip {
    background: linear-gradient(135deg, #FFF9C4, #FFECB3);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.tip-icon {
    font-size: 2rem;
}

.food-tip p {
    text-align: right;
    color: var(--text-primary);
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* ===================================
   لوحة الصدارة
   =================================== */

.leaderboard-list {
    background: white;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: var(--space-md);
    border-bottom: 1px solid #eee;
    transition: var(--transition-fast);
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-item:hover {
    background: var(--bg-gradient-start);
}

.rank {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    border-radius: var(--radius-full);
    margin-left: var(--space-md);
}

.rank.gold {
    background: var(--gold);
    color: #333;
}

.rank.silver {
    background: var(--silver);
    color: #333;
}

.rank.bronze {
    background: var(--bronze);
    color: white;
}

.rank.normal {
    background: #e0e0e0;
}

.leaderboard-name {
    flex: 1;
    font-weight: 600;
}

.leaderboard-score {
    font-weight: 700;
    color: var(--primary-dark);
}

/* ===================================
   الشارات
   =================================== */

.badges-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.badge-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-md);
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: var(--transition-fast);
}

.badge-item.locked {
    opacity: 0.5;
    filter: grayscale(1);
}

.badge-item:not(.locked) {
    cursor: pointer;
}

.badge-item:not(.locked):hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.badge-icon {
    font-size: 2.5rem;
    margin-bottom: var(--space-sm);
}

.badge-name {
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}

/* ===================================
   النافذة المنبثقة
   =================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    text-align: center;
    min-width: 280px;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    margin-bottom: var(--space-lg);
    font-size: 1.5rem;
}

.modal-content .btn {
    width: 100%;
    margin-bottom: var(--space-md);
}

.modal-content .btn:last-child {
    margin-bottom: 0;
}

/* ===================================
   تجاوب الشاشات
   =================================== */

@media (max-width: 480px) {
    .game-title {
        font-size: 2rem;
    }

    .bounce-icon {
        font-size: 2rem;
    }

    .levels-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-sm);
    }

    .level-number {
        font-size: 1.2rem;
    }

    .stats-preview {
        gap: var(--space-md);
    }

    .result-stats {
        flex-direction: column;
        align-items: center;
    }
}

/* ===================================
   تأثيرات إضافية
   =================================== */

/* تأثير النقاط المضافة */
.points-popup {
    position: fixed;
    font-size: 1.5rem;
    font-weight: 700;
    pointer-events: none;
    animation: floatUp 1s ease forwards;
    z-index: 100;
}

.points-popup.positive {
    color: var(--success);
}

.points-popup.negative {
    color: var(--error);
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(-50px) scale(1.5);
    }
}

/* تأثير اهتزاز عند الخطأ */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.shake {
    animation: shake 0.3s ease;
}

/* Mission Modal Specifics */
.mission-content {
    background: linear-gradient(to bottom, #ffffff, #f0f7ff);
    border: 4px solid var(--primary);
    max-width: 400px;
}

.mission-icon {
    font-size: 5rem;
    margin: var(--space-md) 0;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
    animation: bounce 2s infinite;
}

#mission-text {
    font-size: 1.1rem;
    color: var(--text-color);
    margin-bottom: var(--space-lg);
    line-height: 1.6;
    background: rgba(255, 255, 255, 0.9);
    padding: 15px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.mission-actions {
    display: flex;
    gap: var(--space-md);
    justify-content: center;
}