* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* body {
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    background: linear-gradient(135deg, #d9f99d, #4ade80, #166534);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
} */

/* تعديل العنصر الرئيسي ليأخذ الارتفاع الصحيح دائمًا */
html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

body {
    height: 100vh;
    margin: 0;
    background: linear-gradient(135deg, #2193b0, #6dd5ed, #b2f0f7);
    background-size: 400% 400%;
    animation: gradientDirection 60s ease-in-out infinite;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

@keyframes gradientDirection {
    0% {
        background: linear-gradient(135deg, #2193b0, #6dd5ed, #b2f0f7);
        background-size: 400% 400%;
        background-position: 0% 0%;
    }
    50% {
        background: linear-gradient(315deg, #2193b0, #6dd5ed, #b2f0f7);
        background-size: 400% 400%;
        background-position: 100% 100%;
    }
    100% {
        background: linear-gradient(135deg, #2193b0, #6dd5ed, #b2f0f7);
        background-size: 400% 400%;
        background-position: 0% 0%;
    }
}


.game-container {
    width: 100%;
    max-width: 500px;
    text-align: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
    border: 3px solid #ffcc00;
}

.game-container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect width="100" height="100" fill="none" stroke="%23333" stroke-width="2"/></svg>');
    opacity: 0.2;
    z-index: -1;
}

h1 {
    color: #ffcc00;
    margin-bottom: 15px;
    font-size: 2.5rem;
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
    letter-spacing: 2px;
}

.game-info {
    display: flex;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.6);
    padding: 10px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    border: 2px solid #ff6600;
}

.score-container, .high-score-container {
    color: #fff;
    font-size: 1.2rem;
}

.score-value, .high-score-value {
    color: #ffcc00;
    font-weight: bold;
    font-size: 1.4rem;
}

.game-board {
    width: 100%;
    aspect-ratio: 1/1;
    background: rgba(20, 30, 50, 0.8); /* أزرق داكن شفاف */
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    border: 3px solid #2193b0; /* نفس الأزرق المستخدم في h2 */
    box-shadow: inset 0 0 20px rgba(0, 0, 50, 0.8); /* ظل داخلي أزرق داكن */
    display: grid;
    grid-template-columns: repeat(20, 1fr);
    grid-template-rows: repeat(20, 1fr);
}

.snake-head {
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="%2300cc66"/><circle cx="35" cy="40" r="8" fill="%23fff"/><circle cx="65" cy="40" r="8" fill="%23fff"/><circle cx="35" cy="40" r="4" fill="%23000"/><circle cx="65" cy="40" r="4" fill="%23000"/><path d="M40,70 Q50,85 60,70" stroke="%23cc0066" stroke-width="4" fill="none"/></svg>') center/cover;
    border-radius: 30%;
    z-index: 2;
}


.snake-body {
    background: #2193b0; /* أزرق سماوي */
    border-radius: 40%;
    border: 1px solid #17627c; /* أزرق داكن للتحديد */
    z-index: 1;
}

.snake-tail {
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" fill="%2317627c"/></svg>') center/cover;
    border-radius: 40%;
}

.food {
    background: url('../images/food.svg') center/cover;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.controls {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    gap: 15px;
}

button {
    background: linear-gradient(to bottom, #ffcc00, #ff6600);
    color: #000;
    border: none;
    padding: 12px 25px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

button:active {
    transform: translateY(1px);
}

.direction-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 5px;
    margin-top: 20px;
    display: none;
}

.dir-btn {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid #ffcc00;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    color: white;
}

#up-btn { grid-column: 2; grid-row: 1; }
#left-btn { grid-column: 1; grid-row: 2; }
#right-btn { grid-column: 3; grid-row: 2; }
#down-btn { grid-column: 2; grid-row: 3; }

/* مودل الخسارة والفوز */
.game-over, .game-win {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    z-index: 10;
    display: none;
    padding: 20px;
}

.game-over h2 {
    color: #ff3300;
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(255, 51, 0, 0.8);
    animation: shake 0.5s ease-in-out;
}

.game-win h2 {
    color: #ffcc00;
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(255, 204, 0, 0.8);
    animation: bounce 0.8s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.game-win p, .game-over p {
    color: #fff;
    font-size: 1.3rem;
    margin-top: 15px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.final-score, .win-score {
    background: rgba(255, 255, 255, 0.1);
    padding: 15px 30px;
    border-radius: 15px;
    margin-top: 20px;
    font-size: 1.5rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.final-score span, .win-score-value {
    color: #ffcc00;
    font-weight: bold;
    font-size: 2rem;
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
}

.instructions {
    color: #fff;
    margin-top: 15px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.instructions p {
    margin: 5px 0;
}

/* مودل الإرشادات */
.instructions-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    z-index: 15;
    display: none;
    padding: 20px;
    overflow-y: auto;
}

.instructions-modal.show {
    display: flex !important;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
}

.instructions-content {
    background: linear-gradient(135deg, rgba(33, 147, 176, 0.2), rgba(109, 213, 237, 0.2));
    border-radius: 20px;
    padding: 25px;
    max-width: 500px;
    width: 100%;
    border: 3px solid #2193b0;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    margin-top: 20px;
}

.instructions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 15px;
}

.instructions-header h2 {
    color: #ffcc00;
    font-size: 1.8rem;
    margin: 0;
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
}

.close-instructions {
    background: rgba(255, 51, 51, 0.8);
    color: white;
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-instructions:hover {
    background: rgba(255, 51, 51, 1);
    transform: rotate(90deg);
}

.instructions-body {
    margin-bottom: 20px;
}

.instruction-item {
    display: flex;
    align-items: flex-start;
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s;
}

.instruction-item:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: #2193b0;
    transform: translateX(5px);
}

.instruction-icon {
    font-size: 2.5rem;
    margin-left: 15px;
    min-width: 50px;
    text-align: center;
}

.instruction-text h3 {
    color: #ffcc00;
    font-size: 1.2rem;
    margin: 0 0 8px 0;
    text-shadow: 0 0 5px rgba(255, 204, 0, 0.3);
}

.instruction-text p {
    color: #fff;
    font-size: 1rem;
    margin: 0;
    line-height: 1.5;
}

.instructions-footer {
    text-align: center;
    padding-top: 15px;
    border-top: 2px solid rgba(255, 255, 255, 0.2);
}

.start-playing-btn {
    background: linear-gradient(to bottom, #ffcc00, #ff6600);
    color: #000;
    border: none;
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 5px 20px rgba(255, 102, 0, 0.4);
    width: 100%;
}

.start-playing-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(255, 102, 0, 0.6);
}

.instructions-btn {
    background: linear-gradient(to bottom, #2193b0, #17627c);
    color: white;
    font-size: 1rem;
}

/* تصميم متجاوب للهواتف */
@media (max-width: 600px) {
    .game-container {
        width: 95%;
        padding: 15px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .direction-controls {
        display: grid;
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
    }
    
    button {
        width: 100%;
        margin-bottom: 10px;
    }
}

#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #007bff, #00c6ff); 
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 16px;
    color: #fff;
  }
  
  .loader-box {
    text-align: center;
  }
  
  .logo svg {
    margin-bottom: 15px;
  }
  
  #progress-text {
    font-size: 18px;
    margin-bottom: 10px;
    color: #333;
  }
  
  .progress-bar {
    width: 200px;
    height: 10px;
    background: #eee;
    border-radius: 5px;
    overflow: hidden;
    margin: 0 auto;
  }
  
  .progress-fill {
    height: 100%;
    background: #007bff;
    transition: width 0.1s linear;
  }


.rotate-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #fff;
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    text-align: center;
  }
  
  .rotate-warning .rotate-icon {
    width: 100px;
    height: 100px;
    margin-bottom: 20px;
    animation: rotate 2s infinite ease-in-out;
  }
  
  @keyframes rotate {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
  }
  
  @media screen and (orientation: landscape) and (max-width: 1024px) {
    .rotate-warning {
      display: flex;
    }
  
    .game-container {
      display: none;
    }
  }


  .joystick-container {
    position: fixed;
    bottom: 5%;
    left: 5%;
    width: 25vw;
    max-width: 150px;
    aspect-ratio: 1 / 1;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    touch-action: none;
  }

  .joystick-stick {
    position: absolute;
    width: 40%;
    height: 40%;
    left: 30%;
    top: 30%;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    pointer-events: none;
    transition: 0.05s ease;
  }