/* Mobile Support - Portrait Overlay and Landscape Scaling */

/* Lock viewport on mobile - no scrolling allowed */
@media screen and (max-width: 1100px) {
    html {
        overflow: hidden !important;
        position: fixed !important;
        width: 100vw !important;
        height: 100vh !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body {
        overflow: hidden !important;
        position: fixed !important;
        width: 100vw !important;
        height: 100vh !important;
        margin: 0 !important;
        padding: 0 !important;
        /* Use a dark color that blends with game edges */
        background-color: #2a2a2a !important;
    }
}

/* Portrait mode overlay - fills entire viewport, centered */
#portrait-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #4e8656;
    z-index: 10000;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.portrait-message {
    text-align: center;
    color: white;
    font-family: Arial, Helvetica, sans-serif;
    padding: 20px;
    max-width: 90%;
}

.portrait-logo {
    width: 60px;
    height: 60px;
    margin-bottom: 15px;
}

.portrait-message h2 {
    font-size: 20px;
    margin-bottom: 8px;
    margin-top: 0;
}

.portrait-message p {
    font-size: 14px;
    opacity: 0.9;
    margin: 0;
}

.rotate-icon {
    font-size: 36px;
    margin-top: 20px;
    animation: rotate-hint 2s ease-in-out infinite;
}

@keyframes rotate-hint {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

/* Mobile portrait - show overlay, hide content */
@media screen and (max-width: 1100px) and (orientation: portrait) {
    #portrait-overlay {
        display: flex !important;
    }
    .website {
        display: none !important;
    }
}

/* Mobile landscape - fill screen with game content */
@media screen and (max-width: 1100px) and (orientation: landscape) {
    #portrait-overlay {
        display: none !important;
    }

    .website {
        display: block !important;
        position: fixed !important;
        margin: 0 !important;
        padding: 0 !important;
        /* Dimensions and position set by JavaScript */
    }

    /* Hide regular navBar on mobile - use hamburger menu instead */
    .navBar {
        display: none !important;
    }

    .gameContainer {
        border-radius: 0 !important;
        touch-action: none;
    }

    /* Smooth chat bar repositioning when iOS keyboard opens */
    .chat-bar {
        transition: bottom 0.15s ease-out, width 0.15s ease-out;
    }

    /* Hamburger menu button */
    .mobile-menu-btn {
        display: flex !important;
        position: fixed;
        bottom: 10px;
        left: 10px;
        width: 40px;
        height: 40px;
        background-color: rgba(0, 0, 0, 0.6);
        border: none;
        border-radius: 8px;
        cursor: pointer;
        z-index: 9999;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        padding: 8px;
    }

    .mobile-menu-btn span {
        display: block;
        width: 24px;
        height: 3px;
        background-color: white;
        border-radius: 2px;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    /* Hamburger animation when open */
    .mobile-menu-btn.open span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }

    .mobile-menu-btn.open span:nth-child(2) {
        opacity: 0;
    }

    .mobile-menu-btn.open span:nth-child(3) {
        transform: rotate(-45deg) translate(6px, -6px);
    }

    /* Mobile dropdown menu - opens upward from bottom */
    .mobile-menu {
        display: none;
        position: fixed;
        bottom: 55px;
        left: 10px;
        background-color: rgba(0, 0, 0, 0.85);
        border-radius: 8px;
        z-index: 9998;
        min-width: 150px;
        overflow: hidden;
    }

    .mobile-menu.open {
        display: block !important;
    }

    .mobile-menu a {
        display: block;
        padding: 12px 20px;
        color: white;
        text-decoration: none;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 14px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        transition: background-color 0.2s ease;
    }

    .mobile-menu a:last-child {
        border-bottom: none;
    }

    .mobile-menu a:hover,
    .mobile-menu a:active {
        background-color: rgba(255, 255, 255, 0.1);
    }

    .mobile-menu a.active {
        background-color: rgba(78, 134, 86, 0.8);
    }
}

/* Hide hamburger menu on desktop and portrait */
.mobile-menu-btn,
.mobile-menu {
    display: none;
}

/* Desktop - normal behavior, no overlay */
@media screen and (min-width: 1101px) {
    #portrait-overlay {
        display: none !important;
    }

    html, body {
        overflow: auto !important;
        position: static !important;
        width: auto !important;
        height: auto !important;
    }

    .website {
        position: relative !important;
        transform: none !important;
        top: auto !important;
        left: auto !important;
        width: 1100px !important;
    }
}

/* ============================================================
   Touch device overrides (iPads and tablets wider than 1100px)
   The .touch-device class is added by mobile-controls.js
   ============================================================ */

/* Portrait mode on touch devices - show rotate overlay */
.touch-device #portrait-overlay {
    display: none;
}

@media screen and (orientation: portrait) {
    .touch-device #portrait-overlay {
        display: flex !important;
    }
    .touch-device .website {
        display: none !important;
    }
}

/* Landscape touch devices - mobile-friendly UI */
@media screen and (orientation: landscape) {
    .touch-device #portrait-overlay {
        display: none !important;
    }

    .touch-device .navBar {
        display: none !important;
    }

    .touch-device .gameContainer {
        touch-action: none;
    }

    .touch-device .chat-bar {
        transition: bottom 0.15s ease-out, width 0.15s ease-out;
    }

    /* Hamburger menu on touch devices */
    .touch-device .mobile-menu-btn {
        display: flex !important;
        position: fixed;
        bottom: 10px;
        left: 10px;
        width: 40px;
        height: 40px;
        background-color: rgba(0, 0, 0, 0.6);
        border: none;
        border-radius: 8px;
        cursor: pointer;
        z-index: 9999;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        padding: 8px;
    }

    .touch-device .mobile-menu-btn span {
        display: block;
        width: 24px;
        height: 3px;
        background-color: white;
        border-radius: 2px;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    .touch-device .mobile-menu-btn.open span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }

    .touch-device .mobile-menu-btn.open span:nth-child(2) {
        opacity: 0;
    }

    .touch-device .mobile-menu-btn.open span:nth-child(3) {
        transform: rotate(-45deg) translate(6px, -6px);
    }

    .touch-device .mobile-menu {
        display: none;
        position: fixed;
        bottom: 55px;
        left: 10px;
        background-color: rgba(0, 0, 0, 0.85);
        border-radius: 8px;
        z-index: 9998;
        min-width: 150px;
        overflow: hidden;
    }

    .touch-device .mobile-menu.open {
        display: block !important;
    }

    .touch-device .mobile-menu a {
        display: block;
        padding: 12px 20px;
        color: white;
        text-decoration: none;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 14px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        transition: background-color 0.2s ease;
    }

    .touch-device .mobile-menu a:last-child {
        border-bottom: none;
    }

    .touch-device .mobile-menu a:hover,
    .touch-device .mobile-menu a:active {
        background-color: rgba(255, 255, 255, 0.1);
    }

    .touch-device .mobile-menu a.active {
        background-color: rgba(78, 134, 86, 0.8);
    }
}
