/* style.css - تنسيقات المشروع كاملة */

/* ===== الإعدادات العامة ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    margin: 0;
    overflow: hidden;
    background: #000;
    touch-action: none;
    font-family: 'Arial', sans-serif;
    -webkit-user-select: none;
    user-select: none;
}

/* ===== Canvas الخاص بـ Babylon.js ===== */
#renderCanvas {
    width: 100vw;
    height: 100vh;
    display: block;
    touch-action: none;
    outline: none;
}

/* ===== شاشة التحميل ===== */
#loading-screen {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1a2e;
    z-index: 3000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    transition: opacity 0.8s ease-out;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #333;
    border-top: 4px solid #ffd700;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.loading-text {
    color: #ffd700;
    font-size: 20px;
    letter-spacing: 2px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== زر VR ===== */
#vr-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #ffd700;
    color: #000;
    border: none;
    padding: 16px 28px;
    border-radius: 30px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    z-index: 500;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

#vr-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.6);
}

#vr-button:active {
    transform: scale(0.98);
}

/* ===== الرسائل (الموظف والكمسري) ===== */
.message {
    display: none;
    position: fixed;
    bottom: 30%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    font-size: 20px;
    padding: 16px 28px;
    border-radius: 12px;
    text-align: center;
    z-index: 1000;
    animation: fadeIn 0.5s;
    max-width: 80%;
}

.employee-msg {
    color: #ffd700;
    border: 2px solid #ffd700;
}

.conductor-msg {
    color: #ff6b6b;
    border: 2px solid #ff6b6b;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ===== شاشة النهاية ===== */
#end-screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: black;
    z-index: 2000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    transition: opacity 3s ease-in;
}

.end-content {
    text-align: center;
    animation: fadeInUp 2s ease-out;
}

.end-title {
    color: #ffd700;
    font-size: 36px;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

.end-subtitle {
    color: #ccc;
    font-size: 18px;
    opacity: 0.8;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== أزرار الحركة المؤقتة (Desktop + Mobile) ===== */
/* ⚠️ مؤقتة للاختبار - بتختفي تلقائياً في VR */

#movement-controls {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 100;
    display: flex;
    gap: 15px;
    align-items: flex-end;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    /* مهم للموبايل: منع scroll أو zoom عند اللمس */
    touch-action: none;
}

/* الـ D-Pad (قدام/ورا/يمين/شمال) */
.dpad {
    display: grid;
    grid-template-columns: repeat(3, 65px);
    grid-template-rows: repeat(3, 65px);
    gap: 5px;
}

.dpad .move-btn:nth-child(1) { grid-column: 2; grid-row: 1; } /* قدام */
.dpad .move-btn:nth-child(2) { grid-column: 1; grid-row: 2; } /* شمال */
.dpad .move-btn:nth-child(3) { grid-column: 2; grid-row: 2; } /* ورا */
.dpad .move-btn:nth-child(4) { grid-column: 3; grid-row: 2; } /* يمين */

/* أزرار فوق/تحت */
.vertical-pad {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.move-btn {
    width: 65px;
    height: 65px;
    background: rgba(255, 255, 255, 0.25);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
    border-radius: 14px;
    font-size: 26px;
    font-weight: bold;
    cursor: pointer;
    /* مهم: instant response بدون transitions على الـ background للضغط السريع */
    transition: transform 0.1s, box-shadow 0.1s, border-color 0.1s;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    /* ⚡ مهم جداً للموبايل */
    touch-action: none;          /* منع scroll/zoom */
    -webkit-touch-callout: none; /* منع context menu على iOS */
    -webkit-user-select: none;
    user-select: none;
    /* تجنب تأخير الـ tap على الموبايل */
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    /* عشان الإيموجي يبان كويس */
    line-height: 1;
}

.move-btn:hover {
    background: rgba(255, 215, 0, 0.3);
    border-color: #ffd700;
}

/* لما الزرار يكون مضغوط (نشط) */
.move-btn.active {
    background: rgba(255, 215, 0, 0.7) !important;
    border-color: #ffd700;
    transform: scale(0.92);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.7);
}

/* تمييز أزرار فوق/تحت بلون مختلف */
.move-btn.height-btn {
    background: rgba(0, 123, 255, 0.35);
    border-color: rgba(0, 123, 255, 0.7);
}

.move-btn.height-btn:hover {
    background: rgba(0, 123, 255, 0.5);
    border-color: #4dabff;
}

.move-btn.height-btn.active {
    background: rgba(0, 123, 255, 0.8) !important;
    box-shadow: 0 0 20px rgba(0, 123, 255, 0.7);
}

/* ===== أزرار التفاعل المؤقتة (التذكرة + الباب) ===== */

#action-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
    /* بنشيله من فوق زرار VR */
    margin-bottom: 90px;
    touch-action: manipulation;
}

.action-btn {
    background: rgba(255, 255, 255, 0.25);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    font-family: 'Arial', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    min-width: 150px;
    text-align: center;
}

.action-btn:hover {
    background: rgba(255, 215, 0, 0.4);
    border-color: #ffd700;
    transform: scale(1.03);
}

.action-btn:active {
    transform: scale(0.95);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

/* زرار التذكرة بلون ذهبي */
#grab-ticket-btn {
    background: rgba(255, 215, 0, 0.3);
    border-color: rgba(255, 215, 0, 0.6);
}

/* زرار الباب بلون مختلف */
.action-btn.door-btn {
    background: rgba(139, 69, 19, 0.4);
    border-color: rgba(160, 82, 45, 0.7);
}

.action-btn.door-btn:hover {
    background: rgba(160, 82, 45, 0.6);
    border-color: #cd853f;
}

/* لما يكون الباب مفتوح */
.action-btn.door-btn.open-state {
    background: rgba(34, 139, 34, 0.4);
    border-color: rgba(50, 205, 50, 0.7);
}

/* ===== زرار سحب الإحداثيات ===== */
#log-pos-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    background: rgba(40, 167, 69, 0.85);
    color: white;
    border: 2px solid rgba(50, 205, 50, 0.8);
    padding: 10px 18px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: bold;
    font-family: 'Arial', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
}

#log-pos-btn:hover {
    background: rgba(50, 205, 50, 0.9);
    transform: scale(1.05);
}

#log-pos-btn:active {
    transform: scale(0.95);
}

/* عرض الإحداثيات الحالية */
#coords-display {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 100;
    background: rgba(0, 0, 0, 0.75);
    color: #00ff00;
    padding: 8px 14px;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: bold;
    border: 1px solid #00ff00;
    pointer-events: none;
    line-height: 1.5;
    min-width: 140px;
    text-align: right;
}

/* إخفاء كل الأزرار في وضع VR */
body.in-vr #movement-controls,
body.in-vr #action-controls,
body.in-vr #log-pos-btn,
body.in-vr #coords-display {
    display: none;
}

/* ===== تحسينات للـ Mobile و VR ===== */
@media (max-width: 768px) {
    #vr-button {
        bottom: 20px;
        right: 20px;
        padding: 14px 22px;
        font-size: 16px;
    }

    .message {
        font-size: 16px;
        padding: 12px 20px;
    }

    .end-title {
        font-size: 28px;
    }

    /* أزرار حركة على الموبايل - أكبر شوية للأصابع */
    .dpad {
        grid-template-columns: repeat(3, 60px);
        grid-template-rows: repeat(3, 60px);
        gap: 4px;
    }

    .move-btn {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }

    .action-btn {
        font-size: 14px;
        padding: 10px 16px;
        min-width: 130px;
    }
}

/* للشاشات الصغيرة جداً */
@media (max-width: 400px) {
    #movement-controls {
        bottom: 10px;
        left: 10px;
        gap: 10px;
    }

    .dpad {
        grid-template-columns: repeat(3, 55px);
        grid-template-rows: repeat(3, 55px);
    }

    .move-btn {
        width: 55px;
        height: 55px;
        font-size: 22px;
    }

    #action-controls {
        bottom: 10px;
        right: 10px;
        margin-bottom: 80px;
    }
}
