/* Mobile Layout Fix CSS v2.2
 * Scoped to real mobile devices only. Never affects desktop.
 * Guarded by: body.is-mobile + media queries.
 */

/* Core mobile layout (phones/tablets) */
@media (max-width: 768px) {
    body.is-mobile main.poki-main {
        padding: 16px 12px 60px;
    }

    body.is-mobile .game-grid {
        /* Stable 3-column grid on most phones */
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px;
    }

    body.is-mobile .game-grid .post {
        border-radius: 16px;
    }

    body.is-mobile .game-grid .game-item {
        padding: 8px;
        gap: 8px;
    }

    body.is-mobile .game-grid .game-item img {
        width: 100%;
        /* Keep thumbnails square and consistent to avoid layout jumps */
        aspect-ratio: 1 / 1;
        height: auto;
        object-fit: cover;
        border-radius: 12px;
        background: #eef4ff;
    }

    body.is-mobile .game-grid .post-name {
        font-size: 12px;
        line-height: 1.3;
        min-height: 32px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* Hero on mobile */
    body.is-mobile .poki-hero {
        padding: 20px;
        grid-template-columns: 1fr;
        gap: 20px;
    }

    body.is-mobile .poki-hero h1 {
        font-size: 1.5rem;
    }

    /* Mobile navigation drawer */
    body.is-mobile .menu-mobile {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    body.is-mobile .menu {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        background: var(--poki-card-bg);
        z-index: 9999;
        transition: left 0.3s ease;
        overflow-y: auto;
        padding: 80px 20px 20px;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }

    body.is-mobile .menu.open {
        left: 0;
    }

    body.is-mobile.nav-open {
        overflow: hidden;
    }

    body.is-mobile.nav-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0,0,0,0.5);
        z-index: 9998;
    }

    /* Mobile search panel */
    body.is-mobile #search-left {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: var(--poki-card-bg);
        z-index: 99999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
    }

    body.is-mobile #search-left.active {
        transform: translateX(0);
    }

    body.is-mobile .search-container {
        padding: 20px;
    }

    /* Game page on mobile */
    body.is-mobile .play-hero-grid {
        display: block !important;
    }

    body.is-mobile .mobile-game-shell {
        width: 100%;
        overflow: hidden;
        margin-bottom: 32px;
    }

    /* Keep meta content below the game frame on mobile */
    body.is-mobile .play-stage {
        margin-bottom: 40px !important;
    }

    body.is-mobile .play-meta-desktop {
        display: none !important;
    }

    body.is-mobile .play-meta {
        margin-top: 0 !important;
        position: relative;
        z-index: 1;
    }

    body.is-mobile .play-meta-mobile {
        display: block !important;
        margin-top: 0 !important;
        position: relative;
        z-index: 1;
        background: transparent;
    }

    body.is-mobile .mobile-game-frame {
        position: relative;
        width: 100%;
        /* 默认高度，防止 JS 未执行时出现 0 高度或黑屏 */
        height: var(--dynamic-frame-height, 70vh);
        max-height: 90vh;
        min-height: 60vh;
        background: #000;
        border-radius: 16px;
        overflow: hidden;
    }

    body.is-mobile .mobile-game-frame iframe {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        border: none;
        background: #000;
    }

    body.is-mobile .controller-toggle {
        margin-top: 12px;
        padding: 10px 14px;
        border-radius: 12px;
        border: 1px solid var(--grey-5, #bac9de);
        background: var(--poki-card-bg, #fff);
        color: var(--poki-ink);
        font-weight: 600;
        width: 100%;
        box-shadow: 0 6px 18px rgba(0,0,0,.08);
    }

    /* Hide controller when toggled off (mobile only) */
    body.is-mobile .controller-hidden {
        display: none !important;
    }

    /* Lightweight skeletons for cards */
    body.is-mobile .skeleton-card {
        background: var(--poki-card-bg, #fff);
        border-radius: 16px;
        overflow: hidden;
        box-shadow: 0 6px 18px rgba(0,0,0,.06);
        height: 180px;
        position: relative;
    }
    body.is-mobile .skeleton-shimmer {
        position: absolute;
        inset: 0;
        background: linear-gradient(90deg, rgba(0,0,0,0.04) 25%, rgba(0,0,0,0.08) 37%, rgba(0,0,0,0.04) 63%);
        transform: translateX(-100%);
        animation: mobileShimmer 1.25s infinite;
    }
    @keyframes mobileShimmer {
        100% { transform: translateX(100%); }
    }
}

/* Small phones */
@media (max-width: 480px) {
    body.is-mobile main.poki-main {
        padding: 12px 8px 50px;
    }

    body.is-mobile .game-grid {
        /* On very small phones, switch to 2 columns */
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    body.is-mobile .game-grid .game-item img {
        aspect-ratio: 1 / 1;
        height: auto;
    }

    body.is-mobile .game-grid .post-name {
        font-size: 11px;
    }
}

/* Landscape on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    body.is-mobile .game-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 10px;
    }

    body.is-mobile .game-grid .game-item img {
        height: 80px;
    }
}

/* Touch target sizing for mobile devices only */
@media (hover: none) and (pointer: coarse) {
    body.is-mobile button,
    body.is-mobile a,
    body.is-mobile input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }

    body.is-mobile .game-grid .post:active {
        transform: scale(0.98);
    }
}

/* iOS Safari viewport height fix */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        body.is-mobile .menu,
        body.is-mobile #search-left {
            height: -webkit-fill-available;
        }
    }
}

/* Prevent iOS auto-zoom on inputs */
@media (max-width: 768px) {
    body.is-mobile input[type="text"],
    body.is-mobile input[type="search"],
    body.is-mobile textarea,
    body.is-mobile select {
        font-size: 16px;
    }
}

/* ==========================
   Landscape play tweaks (mobile only)
   ========================== */
@media (max-width: 1024px) and (orientation: landscape) {
    /* Hide meta info when the phone is rotated even if JS landscape mode isn't active yet */
    body.is-mobile .play-meta,
    body.is-mobile .tag-list-scroll,
    body.is-mobile .poki-section {
        display: none;
    }

    /* 强制全屏显示游戏，去掉所有外层滚动/留白 */
    body.is-mobile.landscape-mode-active {
        overflow: hidden !important;
        overscroll-behavior: none;
        touch-action: none;
        margin: 0 !important;
        padding: 0 !important;
        background: #000 !important;
    }
    body.is-mobile.landscape-mode-active main,
    body.is-mobile.landscape-mode-active .poki-main {
        padding: 0 !important;
        margin: 0 !important;
        background: #000 !important;
    }

    /* 游戏容器/iframe 固定全屏，内容居中且不裁切（contain） */
    body.is-mobile.landscape-mode-active header,
    body.is-mobile.landscape-mode-active nav,
    body.is-mobile.landscape-mode-active footer,
    body.is-mobile.landscape-mode-active .play-meta,
    body.is-mobile.landscape-mode-active .tag-list-scroll,
    body.is-mobile.landscape-mode-active .poki-section,
    body.is-mobile.landscape-mode-active .poki-hero {
        display: none !important;
    }

    body.is-mobile.landscape-mode-active,
    body.is-mobile.landscape-mode-active main {
        background: #000 !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    body.is-mobile.landscape-mode-active #gamePlayer,
    body.is-mobile.landscape-mode-active object,
    body.is-mobile.landscape-mode-active .game-container iframe,
    body.is-mobile.landscape-mode-active .play-stage iframe {
        position: fixed !important;
        inset: 0 !important;
        width: auto !important;
        height: auto !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        z-index: 99996 !important;
        background: #000 !important;
        display: block !important;
        margin: auto !important;
        object-fit: contain !important;
        touch-action: none;
    }

    body.is-mobile.landscape-mode-active .play-stage {
        position: fixed !important;
        inset: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #000 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}
