/**
 * Mobile-Specific Styles for Shadowspire Interactive Map
 * Optimizes UI and interaction for touch devices
 */

/* =====================================================
   HIDE ZOOM CONTROLS & HOME LINK ON MOBILE
   ===================================================== */

@media (pointer: coarse) and (hover: none) {
    /* Hide zoom in/out buttons on touch devices */
    .controlHolder,
    .zoomIn,
    .zoomOut {
        display: none !important;
    }

    /* Hide home.php link on mobile */
    .logotype {
        display: none;
    }
}

@media screen and (max-width: 768px) {
    /* Hide zoom in/out buttons on mobile screens */
    .controlHolder,
    .zoomIn,
    .zoomOut {
        display: none !important;
    }

    /* Hide home.php link on mobile screens */
    .logotype {
        display: none;
    }

    /* Mobile menu improvements */
    nav.menuhide {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
    }

    nav.menuhide.active {
        display: block;
    }

    .navigate_bg {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        z-index: 1000;
        position: relative;
    }

    .navigate_close {
        position: fixed;
        top: 15px;
        right: 15px;
        width: 45px;
        height: 45px;
        cursor: pointer;
        z-index: 1001;
        background: #c41e3a;
        border-radius: 50%;
        border: 2px solid #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    .navigate_close::before,
    .navigate_close::after {
        content: '';
        position: absolute;
        width: 22px;
        height: 3px;
        background: #fff;
        border-radius: 2px;
    }

    .navigate_close::before {
        transform: rotate(45deg);
    }

    .navigate_close::after {
        transform: rotate(-45deg);
    }

    .navigate_l {
        position: absolute;
        top: 70px;
        left: 20px;
        z-index: 1001;
    }

    .navigate_content {
        width: auto;
        padding: 0;
    }

    .menu_items {
        display: contents;
    }

    .menu_item {
        padding: 15px;
        text-align: center;
        background: rgba(76, 49, 30, 0.8);
        border-radius: 8px;
        text-decoration: none;
        color: #beb9a2;
        transition: all 0.2s ease;
        white-space: nowrap;
    }

    .menu_item:active {
        background: rgba(76, 49, 30, 1);
        transform: scale(0.98);
    }

    .menu_item_title {
        font-size: 16px;
        font-weight: bold;
        margin-bottom: 5px;
    }

    .menu_item_desc {
        font-size: 12px;
        opacity: 0.8;
    }
}

/* =====================================================
   MOBILE VIEWPORT OPTIMIZATION
   ===================================================== */

@media (pointer: coarse) and (hover: none) {
    /* Disable hover effects on touch devices */
    .map-content .marker:hover,
    .map-stages li:hover,
    .map-closepage:hover {
        filter: none !important;
        background-color: inherit;
        cursor: auto;
    }

    /* Increase touch target sizes */
    .map-content .marker {
        min-width: 60px;
        min-height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .map-content .marker p {
        font-size: 12px;
        margin: -10px 0 0 0;
    }

    .map-stages li {
        min-width: 50px;
        min-height: 50px;
        padding: 10px 16px !important;
        font-size: 14px;
    }

    .map-closepage {
        width: 60px;
        height: 60px;
        border-radius: 8px;
    }

    /* Touch feedback state */
    .map-content .marker.touch-active,
    .map-content .marker.mobile-active {
        filter: brightness(1.3) drop-shadow(0px 4px 8px rgba(0, 0, 0, 0.8));
        transform: scale(1.05);
        transition: all 0.15s ease-out;
    }

    .map-stages li.touch-active {
        background: #6c4f2a !important;
        transform: scale(1.05);
        transition: all 0.15s ease-out;
    }

    .close-sidebar.touch-active {
        opacity: 0.8;
        transform: scale(1.05);
        transition: all 0.15s ease-out;
    }

    .map-closepage.touch-active {
        background-color: #6c4f2a;
        transform: scale(1.05);
        transition: all 0.15s ease-out;
    }
}

/* =====================================================
   MOBILE LAYOUT & SIDEBAR
   ===================================================== */

@media screen and (max-width: 768px) {
    /* Hide map-stages on small screens, show mobile controls later */
    .map-stages {
        display: none;
    }

    .map-closepage {
        display: none;
    }

    /* Mobile sidebar - slide up from bottom on very small screens */
    .map-sidebar {
        width: 100vw;
        max-width: 100vw;
        height: 65vh;
        max-height: calc(100vh - 40px);
        left: 0 !important;
        right: 0 !important;
        bottom: calc(-100vh + 40px);
        top: auto;
        border-radius: 16px 16px 0 0;
        z-index: 100;
        -webkit-transition: bottom 0.3s ease-in-out 0s;
        -moz-transition: bottom 0.3s ease-in-out 0s;
        -o-transition: bottom 0.3s ease-in-out 0s;
        transition: bottom 0.3s ease-in-out 0s;
        padding: 15px 15px 20px 15px;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        overflow: hidden;
    }

    .map-sidebar.active {
        bottom: 0;
        -webkit-transition: bottom 0.3s ease-in-out 0s;
        -moz-transition: bottom 0.3s ease-in-out 0s;
        -o-transition: bottom 0.3s ease-in-out 0s;
        transition: bottom 0.3s ease-in-out 0s;
    }

    /* Close sidebar button - visible on mobile */
    .close-sidebar {
        display: block;
        position: absolute;
        top: 15px;
        right: 15px;
        width: 30px;
        height: 30px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 50%;
        cursor: pointer;
        z-index: 10;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }

    .close-sidebar::before,
    .close-sidebar::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 16px;
        height: 2px;
        background: #beb9a2;
        border-radius: 2px;
    }

    .close-sidebar::before {
        transform: translate(-50%, -50%) rotate(45deg);
    }

    .close-sidebar::after {
        transform: translate(-50%, -50%) rotate(-45deg);
    }

    /* Sidebar border adjustments */
    .map-sidebar-border {
        display: none;
    }

    .map-sidebar-border-bot {
        display: none;
    }

    .map-sidebar-image {
        height: 140px !important;
        width: 100%;
        flex-shrink: 0;
        border-radius: 8px;
        margin-bottom: 12px;
        background-size: cover !important;
        background-position: center !important;
    }

    .map-sidebar-content {
        flex: 1;
        overflow-y: auto;
        padding: 0 2px;
        min-height: 0;
    }

    .map-sidebar-location-title {
        font-size: 11px;
        margin-bottom: 20px;
        opacity: 0.6;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: #383838;
        top: 70px;
    }

    .map-sidebar-location-name {
        font-size: 16px;
        font-weight: bold;
        margin-bottom: 10px;
        color: #e5e0d3;
        line-height: 1.2;
    }

    .map-sidebar-text {
        font-size: 13px;
        line-height: 1.5;
        color: #615e5b;
    }

    /* Handle scroll within sidebar on mobile */
    .map-sidebar-content::-webkit-scrollbar {
        width: 4px;
    }

    .map-sidebar-content::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 4px;
    }

    .map-sidebar-content::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.2);
        border-radius: 4px;
    }

    .map-sidebar-content::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.3);
    }

    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
    }
}

/* =====================================================
   SMALL MOBILE DEVICES (< 480px)
   ===================================================== */

@media screen and (max-width: 480px) {
    .map-sidebar {
        height: 55vh;
        padding: 15px 12px;
    }

    .map-sidebar-image {
        height: 120px !important;
    }

    .map-sidebar-location-name {
        font-size: 16px;
    }

    .map-sidebar-text {
        font-size: 12px;
    }

    .close-sidebar {
        width: 28px;
        height: 28px;
        top: 12px;
        right: 12px;
    }
}

/* =====================================================
   TABLET DEVICES (768px - 1024px)
   ===================================================== */

@media screen and (min-width: 769px) and (max-width: 1024px) {
    .map-stages {
        position: fixed;
        right: 15px;
        top: 155px;
        z-index: 100;
        font-size: 0;
        background: rgba(0, 0, 0, 0.5);
        border-radius: 6px;
        display: flex;
        flex-direction: column;
    }

    .map-stages li {
        padding: 8px 12px;
        font-size: 12px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .map-sidebar {
        width: 350px;
        height: calc(100vh - 250px);
    }

    .map-closepage {
        width: 50px;
        height: 50px;
        right: 15px;
        top: 290px;
    }
}

/* =====================================================
   LANDSCAPE MODE ADJUSTMENTS
   ===================================================== */

@media screen and (orientation: landscape) and (max-height: 600px) {
    .map-sidebar {
        height: 50vh;
    }

    .map-sidebar-image {
        height: 100px !important;
    }

    .map-sidebar-content {
        height: calc(100% - 110px) !important;
    }

    .map-stages {
        display: flex;
        flex-direction: row;
        position: fixed;
        right: auto;
        bottom: 10px;
        left: 10px;
        top: auto;
        max-width: calc(100% - 20px);
        overflow-x: auto;
    }

    .map-stages li {
        margin: 0 5px;
        flex-shrink: 0;
    }
}

/* =====================================================
   IMPROVED HEADER/FOOTER FOR MOBILE
   ===================================================== */

@media screen and (max-width: 768px) {
    /* Adjust map area to account for mobile header */
    section.map {
        top: 0;
        bottom: 0;
    }

    .map-content {
        width: 100vw;
        height: 100vh;
    }
}

/* =====================================================
   ACCESSIBILITY & KEYBOARD NAVIGATION
   ===================================================== */

.map-content .marker:focus,
.map-stages li:focus,
.close-sidebar:focus {
    outline: 2px solid #d4af37;
    outline-offset: 2px;
}

/* Prevent text selection during touch interactions */
.map-content .marker,
.map-stages li,
.close-sidebar,
.map-closepage {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* =====================================================
   SMOOTH ANIMATIONS FOR MOBILE
   ===================================================== */

@media (pointer: coarse) {
    * {
        -webkit-tap-highlight-color: transparent;
    }

    .map-content .marker,
    .map-stages li,
    .close-sidebar,
    .map-closepage {
        transition: all 0.15s cubic-bezier(0.4, 0.0, 0.2, 1);
    }
}

/* =====================================================
   HIGH DPI DEVICE OPTIMIZATION
   ===================================================== */

@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    .map-content .marker p {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* =====================================================
   NOTCH & SAFE AREA SUPPORT (iPhone X+)
   ===================================================== */

@supports (padding: max(0px)) {
    .map-sidebar {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }

    .close-sidebar {
        right: max(15px, env(safe-area-inset-right));
        top: max(15px, env(safe-area-inset-top));
    }
}
