/* UI Component styles - joystick, minimap, modals, banners, HUD */

/* Menu Grid Button - compact square buttons for 3x3 menu grid */
.menu-grid-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.75rem;
    aspect-ratio: 1;
    background: rgb(30 41 59); /* slate-800 */
    border: 1px solid rgb(51 65 85); /* slate-700 */
    border-radius: 0.75rem;
    transition: all 0.15s;
}

.menu-grid-btn:hover {
    background: rgb(51 65 85); /* slate-700 */
}

.menu-grid-btn:active {
    transform: scale(0.95);
}

/* Loading bar */
#loading-bar {
    background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 50%, #3b82f6 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* Dynamic Joystick - hidden by default, appears on touch/click */
#joystick-area {
    position: fixed;
    left: 0;
    top: 180px; /* Below header UI */
    width: 100%; /* Full width - joystick works anywhere */
    height: calc(100% - 180px);
    z-index: 15;
    touch-action: none;
    /* Desktop: show crosshair cursor to indicate clickable area */
    cursor: crosshair;
}

/* Desktop: Show subtle hint on hover */
@media (hover: hover) and (pointer: fine) {
    #joystick-area::before {
        content: 'Click & drag to move';
        position: fixed;
        bottom: 100px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.7);
        color: rgba(255, 255, 255, 0.8);
        padding: 8px 16px;
        border-radius: 20px;
        font-size: 12px;
        opacity: 0;
        transition: opacity 0.3s;
        pointer-events: none;
    }

    #joystick-area:hover::before {
        opacity: 1;
    }

    /* Hide hint once joystick is active */
    #joystick-area:has(.joystick-zone.active)::before {
        display: none;
    }
}

/* Hide joystick area when any modal is visible (not hidden) */
body:has(.ui-overlay.fixed:not(.hidden)) #joystick-area {
    pointer-events: none;
    visibility: hidden;
}

/* Hide minimap when any modal is visible (not hidden) */
body:has(.ui-overlay.fixed:not(.hidden)) #minimap-container {
    visibility: hidden;
    pointer-events: none;
}

.joystick-zone {
    position: absolute;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255, 255, 255, 0.15);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease-out;
    transform: translate(-50%, -50%);
}

.joystick-zone.active {
    opacity: 1;
}

.joystick-handle {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* HUD Container - positioned opposite to minimap (default: left) */
#hud-container {
    left: max(16px, env(safe-area-inset-left));
}

/* Minimap Container - Top Right (natural position, below HUD) */
#minimap-container {
    position: fixed;
    top: max(70px, calc(env(safe-area-inset-top) + 60px));
    right: max(16px, env(safe-area-inset-right));
    width: 100px;
    height: 100px; /* Slightly smaller for mobile */
    background: rgba(15, 23, 42, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    overflow: hidden;
    backdrop-filter: blur(4px);
    z-index: 20;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: all 0.3s ease-out;
}

#minimap-container.expanded {
    width: min(360px, 90vw);
    height: min(360px, 90vw); /* ~4x size, but max 90% of screen */
    border-radius: 16px;
    /* Position is set dynamically via JS based on data-position attribute */
}

#minimap-canvas {
    width: 100%;
    height: 100%; /* distinct from attribute width/height */
}

/* Animation classes */
.animate-slide-up {
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.animate-pulse-ring::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse-ring 1.5s infinite;
}

.coin-bounce {
    animation: coinBounce 0.3s ease-out;
}

/* Floating reward text */
.floating-reward {
    position: fixed;
    font-weight: bold;
    font-size: 18px;
    color: #10b981;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    animation: floatUp 1s ease-out forwards;
    z-index: 100;
}

/* Product reveal and glow */
.product-reveal {
    animation: productReveal 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.product-glow {
    animation: productGlow 2s ease-in-out infinite;
    border-radius: 16px;
}

/* Shop button pulse */
.shop-button-pulse {
    animation: shopPulse 2s ease-in-out infinite;
}

/* Achievement popup */
.achievement-popup {
    position: fixed;
    top: max(140px, calc(env(safe-area-inset-top) + 120px));
    right: max(16px, env(safe-area-inset-right));
    background: linear-gradient(135deg, #1e293b, #334155);
    border: 2px solid #fbbf24;
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(251, 191, 36, 0.3);
    animation: achievementSlide 3s ease-in-out forwards;
    z-index: 200;
    max-width: calc(100vw - 32px);
}

.achievement-icon {
    font-size: 32px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Level up popup */
.level-up-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    border: 3px solid #fbbf24;
    border-radius: 24px;
    padding: 32px 48px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(168, 85, 247, 0.4);
    animation: levelUpPop 0.5s ease-out forwards;
    z-index: 250;
}

/* XP bar glow */
.xp-bar-fill {
    background: linear-gradient(90deg, #8b5cf6, #a855f7);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
    transition: width 0.5s ease-out;
}

/* Tutorial overlay - more translucent to show game */
.tutorial-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.tutorial-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 28px;
    padding: 36px 32px;
    max-width: 340px;
    text-align: center;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
    animation: tutorialPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Rush Hour Banner */
.rush-hour-banner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #dc2626, #f97316);
    padding: 16px 32px;
    border-radius: 16px;
    text-align: center;
    z-index: 200;
    animation: rushPulse 0.5s ease-out;
    box-shadow: 0 10px 40px rgba(220, 38, 38, 0.5);
}

/* Rush Hour Active Indicator */
.rush-hour-indicator {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    top: max(130px, calc(env(safe-area-inset-top) + 110px));
    background: linear-gradient(135deg, #dc2626, #f97316);
    padding: 8px 20px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 20;
    animation: rushGlow 1s ease-in-out infinite alternate;
    box-shadow: 0 4px 20px rgba(220, 38, 38, 0.4);
    pointer-events: none;
}

.rush-hour-indicator.hidden {
    display: none;
}

/* Weather Banner */
.weather-banner {
    position: fixed;
    top: 35%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(51, 65, 85, 0.95));
    padding: 16px 32px;
    border-radius: 16px;
    text-align: center;
    z-index: 100;
    animation: weatherSlide 0.4s ease-out, weatherFade 2.5s ease-in-out;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

/* Fuel Warning Animations */
.fuel-warning {
    animation: fuelPulse 0.5s ease-in-out infinite;
}

.fuel-critical {
    animation: fuelPulse 0.25s ease-in-out infinite;
    background: linear-gradient(to right, #dc2626, #f97316) !important;
}

.low-fuel-banner {
    position: fixed;
    top: max(180px, calc(env(safe-area-inset-top) + 160px));
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #f97316, #ea580c);
    padding: 8px 16px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 25;
    animation: slideDown 0.3s ease-out, fuelBannerFade 3s ease-in-out;
    box-shadow: 0 4px 20px rgba(249, 115, 22, 0.4);
}

/* District Unlock Banner */
.district-banner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #059669, #10b981);
    padding: 20px 40px;
    border-radius: 20px;
    text-align: center;
    z-index: 200;
    animation: districtPop 0.5s ease-out;
    box-shadow: 0 10px 50px rgba(5, 150, 105, 0.5);
}

/* ========================================
   Interactive Tutorial Styles
   ======================================== */

/* Highlighted element during tutorial */
.tutorial-highlight {
    position: relative;
    z-index: 400 !important;
    animation: tutorialPulse 1.5s ease-in-out infinite;
    box-shadow:
        0 0 0 4px rgba(59, 130, 246, 0.7),
        0 0 20px rgba(59, 130, 246, 0.4),
        0 0 40px rgba(59, 130, 246, 0.2) !important;
    border-radius: 12px;
}

@keyframes tutorialPulse {
    0%, 100% {
        box-shadow:
            0 0 0 4px rgba(59, 130, 246, 0.7),
            0 0 20px rgba(59, 130, 246, 0.4);
    }
    50% {
        box-shadow:
            0 0 0 8px rgba(59, 130, 246, 0.5),
            0 0 30px rgba(59, 130, 246, 0.6),
            0 0 50px rgba(59, 130, 246, 0.3);
    }
}

/* Tooltip arrow positioning */
.tutorial-arrow {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #0f172a;
    border: 1px solid #3b82f6;
    transform: rotate(45deg);
}

.tutorial-arrow.arrow-top {
    top: -7px;
    left: 50%;
    margin-left: -6px;
    border-right: none;
    border-bottom: none;
}

.tutorial-arrow.arrow-bottom {
    bottom: -7px;
    left: 50%;
    margin-left: -6px;
    border-left: none;
    border-top: none;
}

.tutorial-arrow.arrow-left {
    left: -7px;
    top: 20px;
    border-right: none;
    border-top: none;
}

.tutorial-arrow.arrow-right {
    right: -7px;
    top: 20px;
    border-left: none;
    border-bottom: none;
}

/* Slide up animation for modal */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-slide-up {
    animation: slideUp 0.3s ease-out forwards;
}
