/**
 * ChiffTown Mobile Map Enhancements
 * Makes the isometric town map work beautifully on mobile
 */

/* === Mobile Map Container === */
@media (max-width: 768px) {
    .interactive-map-container {
        /* Use image's natural aspect ratio — eliminates blank space below the image
           where NPCs, petals, lanterns were clustering and causing visual chaos.
           Map image is 3168×1344 = 2.357:1 aspect ratio */
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        aspect-ratio: 3168 / 1344;
        touch-action: none;
        position: relative;
        overflow: hidden;
        cursor: grab;
    }
    
    .interactive-map-container.panning {
        cursor: grabbing;
    }
    
    /* Make the map image transformable */
    .city-map-image {
        transform-origin: center center;
        transition: none; /* Remove hover transition for smooth touch control */
        will-change: transform;
        max-width: 100%;
        width: 100%;
        height: auto;
    }
    
    /* FULLSCREEN MODE FIX FOR MOBILE */
    .interactive-map-container.fullscreen-map {
        background: #0a0a1a !important;
        overflow: auto !important;
        display: flex;
        align-items: center;
        justify-content: center;
        /* Override auto-height for fullscreen: fill the viewport */
        height: 100vh !important;
        aspect-ratio: unset !important;
    }
    
    .interactive-map-container.fullscreen-map .city-map-image {
        max-width: 100vw !important;
        max-height: 100vh !important;
        width: auto !important;
        height: auto !important;
        object-fit: contain;
        transform: none !important;
    }
    
    .interactive-map-container.fullscreen-map .map-wrapper {
        width: 100vw;
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Zoom controls for mobile */
    .mobile-map-controls {
        position: absolute;
        bottom: 20px;
        right: 20px;
        z-index: 100;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .mobile-zoom-btn {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: rgba(10, 10, 26, 0.9);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(244, 197, 66, 0.3);
        color: #f4c542;
        font-size: 1.2rem;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    }
    
    .mobile-zoom-btn:active {
        transform: scale(0.9);
        background: rgba(244, 197, 66, 0.15);
    }
    
    /* Reset button */
    .mobile-reset-btn {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: rgba(10, 10, 26, 0.9);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(100, 150, 200, 0.3);
        color: #5ac8fa;
        font-size: 0.9rem;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    }
    
    .mobile-reset-btn:active {
        transform: scale(0.9);
        background: rgba(100, 150, 200, 0.15);
    }
    
    /* Enhanced hotspot tooltips for mobile */
    .map-hotspot {
        /* Bigger touch targets */
        min-width: 60px;
        min-height: 60px;
        z-index: 50;
    }
    
    /* Show tooltip on tap, not hover */
    .map-hotspot .hotspot-label {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
        transition: all 0.3s ease;
        pointer-events: none;
        background: rgba(10, 10, 26, 0.95);
        backdrop-filter: blur(15px);
        border: 1px solid rgba(244, 197, 66, 0.4);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
        padding: 0.75rem 1.25rem;
        font-size: 0.85rem;
        font-weight: 600;
        white-space: nowrap;
        z-index: 1000;
    }
    
    .map-hotspot.active-tap .hotspot-label {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    
    /* Pulsing glow for active venues */
    .map-hotspot.active .hotspot-glow {
        animation: mobilePulse 2s ease-in-out infinite;
    }
    
    @keyframes mobilePulse {
        0%, 100% {
            transform: scale(1);
            opacity: 0.4;
        }
        50% {
            transform: scale(1.15);
            opacity: 0.7;
        }
    }
    
    /* Tap indicator */
    .map-hotspot::after {
        content: '';
        position: absolute;
        inset: -5px;
        border-radius: inherit;
        border: 2px solid rgba(244, 197, 66, 0);
        transition: all 0.3s ease;
        pointer-events: none;
    }
    
    .map-hotspot.active-tap::after {
        border-color: rgba(244, 197, 66, 0.6);
        animation: tapRing 0.6s ease-out;
    }
    
    @keyframes tapRing {
        0% {
            transform: scale(0.8);
            opacity: 1;
        }
        100% {
            transform: scale(1.3);
            opacity: 0;
        }
    }
    
    /* VENUE LIST - PROPER GRID ON MOBILE */
    .venue-list {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
        margin-top: 1.5rem !important;
        padding: 0 !important;
    }
    
    .venue-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        padding: 1rem 0.5rem !important;
        background: rgba(255, 255, 255, 0.03) !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        border-radius: 12px !important;
        text-decoration: none !important;
        transition: all 0.3s ease !important;
        min-height: 140px !important;
    }
    
    .venue-item:active {
        background: rgba(244, 197, 66, 0.1) !important;
        transform: scale(0.97) !important;
    }
    
    .venue-icon {
        font-size: 1.5rem !important;
        margin-bottom: 0.5rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        height: 60px !important;
    }
    
    .venue-icon img {
        width: 70px !important;
        height: auto !important;
        max-height: 60px !important;
        object-fit: contain !important;
    }
    
    .venue-name {
        font-size: 0.9rem !important;
        font-weight: 600 !important;
        color: #f4c542 !important;
        margin-bottom: 0.25rem !important;
        text-align: center !important;
    }
    
    .venue-desc {
        font-size: 0.75rem !important;
        color: rgba(255, 255, 255, 0.5) !important;
        text-align: center !important;
    }
    
    /* Hide toggle button - showing list by default */
    .venue-list-toggle {
        display: none !important;
    }
    
    /* Map instruction hint */
    .map-hint {
        position: absolute;
        top: 20px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(10, 10, 26, 0.9);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(244, 197, 66, 0.3);
        padding: 0.5rem 1rem;
        border-radius: 20px;
        color: #f4c542;
        font-size: 0.75rem;
        font-weight: 500;
        z-index: 99;
        pointer-events: none;
        opacity: 1;
        transition: opacity 0.3s ease;
    }
    
    .map-hint.hidden {
        opacity: 0;
    }
    
    /* Map wrapper for transform — height: auto so it matches the image, not the old 70vh */
    .map-wrapper {
        width: 100%;
        height: auto;
        position: relative;
        transform-origin: center center;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .map-wrapper.smooth-transition {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* Fullscreen button adjustment for mobile */
    .map-controls {
        margin-bottom: 0.5rem;
    }
    
    .fullscreen-btn {
        width: 100%;
        padding: 0.75rem 1.25rem;
        font-size: 0.9rem;
    }
}

/* === Small mobile devices (iPhone SE, etc.) === */
@media (max-width: 480px) {
    .interactive-map-container {
        /* Keep auto height — image aspect ratio handles sizing */
        height: auto !important;
        min-height: 0 !important;
    }
    
    .map-hint {
        font-size: 0.7rem;
        padding: 0.4rem 0.8rem;
    }
    
    .mobile-zoom-btn,
    .mobile-reset-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .hotspot-label {
        font-size: 0.8rem !important;
        padding: 0.6rem 1rem !important;
    }
    
    .venue-list {
        gap: 0.5rem !important;
    }
    
    .venue-item {
        padding: 0.75rem 0.4rem !important;
        min-height: 120px !important;
    }
    
    .venue-icon img {
        width: 60px !important;
        max-height: 50px !important;
    }
    
    .venue-name {
        font-size: 0.85rem !important;
    }
    
    .venue-desc {
        font-size: 0.7rem !important;
    }
}

/* === Extra small screens (iPhone SE 1st gen: 320px) === */
@media (max-width: 375px) {
    .venue-list {
        gap: 0.4rem !important;
    }
    
    .venue-item {
        padding: 0.6rem 0.3rem !important;
        min-height: 110px !important;
    }
    
    .venue-icon {
        height: 50px !important;
    }
    
    .venue-icon img {
        width: 55px !important;
        max-height: 45px !important;
    }
    
    .venue-name {
        font-size: 0.8rem !important;
    }
    
    .venue-desc {
        font-size: 0.65rem !important;
    }
    
    .mobile-zoom-btn,
    .mobile-reset-btn {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }
    
    .mobile-map-controls {
        bottom: 15px;
        right: 15px;
        gap: 8px;
    }
}

/* === Mobile: Hotspot sizing fix — no forced min-width that breaks layout === */
@media (max-width: 768px) {
    /* The default mobile rule sets min-width:80px/min-height:80px which
       can overflow the now-correctly-sized map container. Let percentage
       widths/heights from the desktop layout rule, just ensure touch targets. */
    .map-hotspot {
        min-width: 0 !important;
        min-height: 0 !important;
    }

    /* Hotspot labels: hidden by default on mobile to avoid clutter,
       shown only on active tap (via .active-tap class from mobile-map.js) */
    .map-hotspot .hotspot-label {
        opacity: 0 !important;
        transform: translateX(-50%) translateY(10px) !important;
        font-size: 0.7rem !important;
        padding: 0.3rem 0.6rem !important;
    }

    .map-hotspot.active-tap .hotspot-label {
        opacity: 1 !important;
        transform: translateX(-50%) translateY(0) !important;
    }
}

/* === Mobile: Hide floating UI clutter that creates visual noise below the map === */
@media (max-width: 768px) {
    /* Town Chat toggle button */
    #townChatToggle,
    .tc-toggle {
        display: none !important;
    }

    /* Activity Feed button */
    .activity-feed-btn,
    #activity-feed-btn {
        display: none !important;
    }

    /* Spring Festival wheel button */
    .festival-wheel-btn {
        display: none !important;
    }

    /* Hide the invite FAB on mobile — it overlaps the map area */
    .fab-invite {
        display: none !important;
    }

    /* Ensure map image is block-level with no gaps */
    .interactive-map-container .city-map-image {
        display: block;
        width: 100%;
        height: auto;
        min-height: 0;
    }

    /* Zoom controls: sit neatly at bottom-right of the (now correctly-sized) map */
    .mobile-map-controls {
        position: absolute;
        bottom: 8px;
        right: 8px;
        z-index: 100;
    }

    /* Town clock: stay within map boundaries */
    #townClock,
    .town-clock {
        position: absolute;
        top: 8px;
        left: 8px;
        z-index: 20;
        font-size: 0.65rem;
    }

    /* Festival banner: above page (fixed), not inside map — OK to keep */
    .festival-banner {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }
}

/* === Desktop: Hide mobile controls === */
@media (min-width: 769px) {
    .mobile-map-controls,
    .mobile-zoom-btn,
    .mobile-reset-btn,
    .map-hint,
    .venue-list-toggle {
        display: none !important;
    }
    
    .venue-list {
        display: grid !important;
    }
}
