/* Mobile Specific Styles - classroom edition */

/* Standardize footer across all screens */
@media (max-width: 1150px) {
    .footer-privacy {
        padding: 10px 0;
    }

    .current-turn {
        display: none !important;
    }
}

/* Error message popup for mobile */
@media (max-width: 600px) {
    .error-message {
        width: 90vw;
        font-size: 1rem;
        padding: 12px 10px;
    }
}

/* Responsive Design Overrides */
@media (max-width: 1150px), (max-height: 499px) {
    html,
    body {
        width: 100%;
        height: var(--app-viewport-height, 100vh);
        min-height: var(--app-viewport-height, 100vh);
        overflow: hidden !important;
        overscroll-behavior-y: none;
    }

    #gameScreen,
    #gameScreen.mobile-view {
        height: var(--app-viewport-height, 100vh) !important;
        overflow: hidden !important;
    }

    .screen {
        overscroll-behavior-y: contain;
    }

    .no-scroll-screen.active {
        height: var(--app-viewport-height, 100vh) !important;
        overflow: hidden !important;
    }

    .no-scroll-screen.active>.home-container,
    .no-scroll-screen.active>.setup-container,
    .no-scroll-screen.active>.room-container,
    .no-scroll-screen.active>.join-container,
    .no-scroll-screen.active>.quickmatch-container {
        height: 100%;
        min-height: 100%;
        max-height: 100%;
        overflow-y: auto !important;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-ui {
        display: flex !important;
        flex-direction: column !important;
        min-height: var(--app-viewport-height, 100vh) !important;
        height: var(--app-viewport-height, 100vh) !important;
        max-height: var(--app-viewport-height, 100vh) !important;
        width: 100vw !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        background: transparent !important;
        z-index: 500 !important;
        overflow: hidden !important;
    }

    .desktop-ui {
        display: none !important;
    }

    .mobile-header {
        position: relative !important;
        padding: 10px 15px !important;
        display: flex !important;
        justify-content: flex-end !important;
        z-index: 10 !important;
    }

    .mobile-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 70px !important;
        background: var(--surface-bg, white) !important;
        justify-content: space-around !important;
        align-items: center !important;
        border-top: 2px solid var(--border-color, #34495e) !important;
        z-index: 1000 !important;
        padding-bottom: env(safe-area-inset-bottom, 0);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1) !important;
    }

    .current-turn-mobile {
        margin: 10px auto !important;
        position: relative !important;
        z-index: 5 !important;
        display: block !important;
        flex-shrink: 0 !important;
    }

    .mobile-game-area {
        flex: 1 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 10px !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
        /* Reserve nav space without adding extra scrollable area */
        min-height: 0 !important;
        overflow: hidden !important;
    }

    #mobileGameBoard {
        max-width: 95vw !important;
        max-height: calc(var(--app-viewport-height, 100vh) - 200px) !important;
        object-fit: contain !important;
        margin: 0 auto !important;
    }

    .support-float {
        display: none;
    }

    .home-container {
        padding: 10px 15px;
        min-height: 100vh;
        box-sizing: border-box;
    }

    .game-title {
        font-size: 1.8rem;
        margin-top: 2rem;
        margin-bottom: 0.2rem;
    }

    .name-input-container {
        margin-bottom: 1.5rem;
    }

    .name-input-container label {
        font-size: 1rem;
        margin-bottom: 0.3rem;
    }

    .name-input-container input {
        padding: 10px 15px;
        font-size: 1rem;
        width: 100%;
        max-width: 300px;
        box-sizing: border-box;
    }

    .game-modes {
        grid-template-columns: repeat(2, 1fr);
        max-width: 600px;
        gap: 0.8rem;
        width: 100%;
    }

    .mode-btn {
        min-height: 90px;
        padding: 0.8rem;
    }

    .btn-icon {
        font-size: 1.5rem;
        margin-bottom: 0.3rem;
    }

    .btn-text {
        font-size: 1rem;
        margin-bottom: 0.2rem;
    }

    .btn-desc {
        font-size: 0.8rem;
    }

    .theme-toggle-home {
        margin-top: 1rem;
    }

    .theme-btn {
        padding: 8px 16px;
        font-size: 0.9rem;
    }

    .setup-container,
    .room-container,
    .join-container,
    .quickmatch-container {
        padding: 12px;
        overflow-y: auto;
        min-height: 100%;
        box-sizing: border-box;
        padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .room-info {
        padding: 1rem;
        margin-top: 1rem;
    }

    .code-display,
    .link-display {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .code-display span,
    .link-display span {
        word-break: break-all;
        font-size: 0.9rem;
    }
}

@media (max-width: 500px) {
    .game-modes {
        grid-template-columns: 1fr;
        max-width: 350px;
    }
}

/* --- Mobile Home Screen Optimizations --- */
@media (max-width: 600px) {
    .home-container {
        padding: 0 2vw;
        gap: 0.7rem;
        min-height: 100vh;
    }

    .game-title {
        font-size: 2.2rem;
        color: #2c3e50;
        margin-top: 3rem;
        margin-bottom: 0.2rem;
        text-align: center;
        font-weight: 800;
    }

    .name-input-container {
        margin-bottom: 1rem;
    }

    .name-input-container input {
        padding: 10px 10px;
        font-size: 1rem;
        max-width: 95vw;
    }

    .game-modes {
        grid-template-columns: 1fr;
        width: 100%;
        max-width: 350px;
        gap: 0.5rem;
        margin: 0 auto;
    }

    .mode-btn {
        min-width: 90px;
        max-width: 100vw;
        min-height: 50px;
        max-height: 70px;
        font-size: 0.9rem;
        padding: 0.5em 0.3em 0.3em 0.3em;
        border-radius: 10px;
    }

    .btn-icon {
        font-size: 1.3rem;
    }

    .btn-text {
        font-size: 1rem;
    }

    .btn-desc {
        font-size: 0.8rem;
    }

    .theme-toggle-home {
        margin-top: 0;
    }

    .theme-btn {
        padding: 7px 12px;
        font-size: 0.9rem;
    }
}

/* Smaller devices */
@media (max-width: 400px) {
    .home-container {
        padding: 0 1vw;
        gap: 0.5rem;
    }

    .game-title {
        font-size: 1.1rem;
    }

    .mode-btn {
        min-height: 40px;
        font-size: 0.8rem;
        padding: 0.3em;
    }
}

/* --- Improved Mobile Home Screen Icon Handling --- */
@media (max-width: 600px) {
    .home-container {
        box-sizing: border-box;
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .game-modes {
        grid-template-columns: 1fr;
        max-width: 100%;
        width: 100%;
        padding: 0;
        margin: 0 auto;
    }

    .mode-btn {
        min-width: 0;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        overflow: hidden;
        word-break: break-word;
        white-space: normal;
    }

    .btn-icon {
        font-size: 1.5rem;
        width: 2.2rem;
        height: 2.2rem;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 0.2rem;
        overflow: hidden;
    }
}

/* Game board sizing for mobile */
@media (max-width: 1150px) {
    #mobileGameBoard {
        max-width: 92vw !important;
        max-height: 82vh !important;
        display: block !important;
        margin: 0 auto !important;
        touch-action: none !important;
        pointer-events: auto !important;
        box-sizing: border-box !important;
    }
}

/* Mobile global chat overrides */
@media (max-width: 1250px) {
    .desktop-global-chat-panel {
        display: none !important;
    }

    .mobile-global-chat-key {
        display: block !important;
        position: fixed;
        right: 0;
        top: 20%;
        z-index: 1000;
    }
}

@media (min-width: 1251px) {
    .mobile-global-chat-key {
        display: none !important;
    }

    .mobile-global-chat-drawer {
        display: none !important;
    }
}



/* Mobile Global Chat Styles (Drawer, Toggle) */
.mobile-global-chat-toggle {
    display: none;
    transition: all 0.3s ease;
}

.mobile-global-chat-toggle button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.mobile-global-chat-drawer {
    backdrop-filter: blur(4px);
}

.mobile-global-chat-messages {
    scroll-behavior: smooth;
}

.mobile-global-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.mobile-global-chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

#globalChatMessagesMobile {
    scroll-behavior: smooth;
    overflow-y: auto;
    padding: 12px;
}



.global-chat-container {
    height: 160px;
}

.global-chat-messages {
    padding: 8px;
}

.global-chat-message {
    font-size: 0.85rem;
    padding: 6px 8px;
    margin-bottom: 6px;
    border-radius: 12px;
}

.global-chat-message.own-message {
    margin-left: 15%;
}

.global-chat-message-avatar {
    width: 20px;
    height: 20px;
}

.global-chat-input-row {
    padding: 6px 8px;
}

.global-chat-input-row input {
    font-size: 0.85rem;
    padding: 6px 10px;
}

.global-chat-input-row button {
    font-size: 0.85rem;
    padding: 6px 12px;
    min-width: 50px;
}

.online-users-indicator {
    padding: 2px 6px;
}

#mobileOnlineUsersCount {
    font-size: 0.8rem;
}

@media (max-width: 480px) {
    .global-chat-container {
        height: 140px;
        border-radius: 8px;
    }

    .global-chat-message {
        font-size: 0.8rem;
        padding: 4px 6px;
        border-radius: 10px;
    }

    .global-chat-message-avatar {
        width: 18px;
        height: 18px;
    }
}

/* Mobile Global Chat Styles */
.mobile-global-chat-toggle {
    transition: all 0.3s ease;
}

.mobile-global-chat-toggle button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.mobile-global-chat-drawer {
    backdrop-filter: blur(4px);
}

.mobile-global-chat-messages {
    scroll-behavior: smooth;
}

#globalChatMessagesMobile {
    scroll-behavior: smooth;
    overflow-y: auto;
    padding: 12px;
}

/* Keep small phones/tablets in portrait mode during gameplay */
@media (max-width: 1150px) and (orientation: landscape) and (pointer: coarse), (max-height: 499px) and (orientation: landscape) and (pointer: coarse) {
    #gameScreen.mobile-view .mobile-ui {
        visibility: hidden !important;
        pointer-events: none !important;
    }

    #gameScreen.mobile-view::after {
        content: 'Please rotate your device to portrait to continue.';
        position: fixed;
        inset: 0;
        z-index: 2500;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 24px;
        background: var(--board-bg, #2d5016);
        color: #ffffff;
        font-size: 1.15rem;
        font-weight: 700;
        line-height: 1.4;
    }
}

/* Prevent auto-zoom on mobile inputs */
@media (max-width: 1150px) {

    input,
    textarea,
    select {
        font-size: 16px !important;
    }

    body {
        position: relative;
        width: 100%;
        min-height: var(--app-viewport-height, 100vh);
        height: var(--app-viewport-height, 100vh);
        overflow-y: hidden;
        overflow-x: hidden;
    }
}

