* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none; /* لمنع السحب وتحديث الصفحة بالخطأ على الموبايل */
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#game-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0; left: 0;
}

/* واجهة المستخدم (HUD) */
#hud {
    position: absolute;
    top: 15px; left: 15px; right: 15px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 10;
    pointer-events: none;
    flex-wrap: wrap;
    gap: 10px;
}

.hud-box {
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    border: 2px solid #555;
}

#book-counter { color: #ffd700; border-color: #ffd700; }
#stamina-container { display: flex; align-items: center; gap: 10px; }
#stamina-bar { width: 100px; height: 12px; background: #333; border-radius: 6px; overflow: hidden; border: 1px solid #aaa; }
#stamina-fill { width: 100%; height: 100%; background: #00ffcc; transition: width 0.1s linear; }
#item-icon { color: #00e1ff; }

/* المؤشر */
#crosshair {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.8);
    font-size: 28px;
    pointer-events: none;
    z-index: 5;
}

/* الرسائل */
#game-message {
    position: absolute;
    top: 20%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    color: #ff3333;
    padding: 10px 20px;
    font-size: 18px;
    font-weight: bold;
    border-radius: 8px;
    border: 2px solid #ff3333;
    z-index: 20;
    pointer-events: none;
    text-align: center;
}

/* النوافذ المنبثقة */
.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: 100;
}
.hidden { display: none !important; }
.modal {
    background: #1a1a1a; color: #fff; padding: 25px; border-radius: 12px;
    text-align: center; max-width: 400px; width: 90%;
    border: 3px solid #ff4444; box-shadow: 0 0 20px rgba(255, 68, 68, 0.4);
}
.start-modal { border-color: #00cc66; box-shadow: 0 0 20px rgba(0, 204, 102, 0.4); line-height: 1.6; }
.modal button {
    margin-top: 15px; padding: 10px 20px; background: #00cc66; color: #fff;
    font-size: 16px; font-weight: bold; border: none; border-radius: 6px; cursor: pointer;
}

/* 📱 تحكم الموبايل (معدّل كلياً) */
#touch-controls {
    position: absolute;
    bottom: 20px; left: 20px; right: 20px;
    display: none; /* يظهر فقط في الشاشات الصغيرة */
    justify-content: space-between;
    align-items: flex-end;
    z-index: 10;
    pointer-events: none; /* للسماح بلمس الكاميرا خلفه */
}

/* عصا التحكم على اليسار */
#joystick-base {
    width: 120px; height: 120px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    position: relative;
    pointer-events: auto;
}
#joystick-stick {
    width: 50px; height: 50px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    position: absolute; top: 35px; left: 35px;
}

/* ترتيب الأزرار بشكل عمودي على اليمين */
#action-buttons-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: auto;
}

.touch-btn {
    background: rgba(0, 153, 255, 0.8);
    color: white; border: 2px solid #fff;
    padding: 15px; border-radius: 12px;
    font-weight: bold; font-size: 16px;
    width: 130px; text-align: center;
}
.interact-btn { background: rgba(0, 204, 102, 0.8); }

@media (max-width: 768px) {
    #touch-controls { display: flex; }
    /* تصغير النصوص للموبايل */
    .hud-box { font-size: 14px; padding: 6px 10px; }
}