/**
 * Yu-Gi-Oh! Center — mobile layout layer
 * Load after style.css (and after duel-2player.css on duel page).
 * Breakpoints: tablet/phone ≤767.98px, small phone ≤479.98px
 */

@media (max-width: 767.98px) {
    :root {
        --m-header-bar: 56px;
        --m-header-offset: calc(var(--m-header-bar) + env(safe-area-inset-top, 0px));
    }

    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
        scroll-padding-top: var(--m-header-offset);
    }

    /* Base layout: iOS hates background-attachment: fixed */
    body {
        background-attachment: scroll !important;
        padding-top: var(--m-header-offset) !important;
        overflow-x: clip;
        touch-action: manipulation;
    }

    /* style.css applied scroll-margin to every div[id] — causes jumpy mobile scroll */
    div[id] {
        scroll-margin-top: 0 !important;
    }

    section[id],
    main[id] {
        scroll-margin-top: var(--m-header-offset) !important;
    }

    h1 {
        font-size: clamp(1.65rem, 6.5vw, 2.15rem) !important;
    }

    h2 {
        font-size: clamp(1.35rem, 5.2vw, 1.85rem) !important;
    }

    h3 {
        font-size: clamp(1.15rem, 4.2vw, 1.45rem) !important;
    }

    h4 {
        font-size: 1.15rem !important;
    }

    h5,
    h6 {
        font-size: 1.05rem !important;
    }

    .container {
        padding-left: max(0.85rem, env(safe-area-inset-left, 0px)) !important;
        padding-right: max(0.85rem, env(safe-area-inset-right, 0px)) !important;
    }

    .section {
        padding: 2.25rem 0 !important;
    }

    .section-header {
        margin-bottom: 1.5rem !important;
    }

    /* ----- Fixed header (safe area) ----- */
    .header {
        height: auto !important;
        min-height: var(--m-header-offset) !important;
        padding-top: env(safe-area-inset-top, 0px) !important;
        padding-bottom: 0 !important;
    }

    .navbar,
    .nav-container {
        min-height: var(--m-header-bar);
    }

    .nav-container {
        padding-left: max(0.65rem, env(safe-area-inset-left, 0px)) !important;
        padding-right: max(0.65rem, env(safe-area-inset-right, 0px)) !important;
    }

    .nav-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem !important;
        z-index: calc(var(--z-fixed) + 2) !important;
    }

    /* Nav sheet: no invisible overlay blocking taps when “closed” */
    .nav-menu {
        position: fixed !important;
        top: var(--m-header-offset) !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-height: min(72dvh, calc(100dvh - var(--m-header-offset) - 12px)) !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        margin: 0 !important;
        padding: 0.75rem 1rem max(1rem, env(safe-area-inset-bottom, 0px)) !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0 !important;
        background: rgba(8, 5, 16, 0.97) !important;
        backdrop-filter: blur(16px) saturate(1.1);
        -webkit-backdrop-filter: blur(16px) saturate(1.1);
        border-bottom: 1px solid var(--border-primary) !important;
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55) !important;
        z-index: calc(var(--z-fixed) + 1) !important;
        transform: translate3d(0, -100%, 0) !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
        transition:
            transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
            opacity 0.25s ease,
            visibility 0s linear 0.3s !important;
    }

    .nav-menu.active {
        transform: translate3d(0, 0, 0) !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        transition:
            transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
            opacity 0.25s ease,
            visibility 0s linear 0s !important;
    }

    .nav-list {
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.35rem !important;
    }

    .nav-item {
        width: 100% !important;
    }

    .nav-link {
        white-space: normal !important;
        text-align: center !important;
        padding: 0.85rem 1rem !important;
        min-height: 48px;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    body:has(.nav-menu.active),
    body.nav-drawer-open {
        overflow: hidden !important;
        overscroll-behavior: none;
    }

    /* ----- Heroes (offset matches header) ----- */
    .hero {
        margin-top: calc(-1 * var(--m-header-offset)) !important;
        padding-top: var(--m-header-offset) !important;
        min-height: 0 !important;
    }

    .hero.hero--modern.hero--chase {
        margin-top: calc(-1 * var(--m-header-offset)) !important;
        padding: calc(0.75rem + var(--m-header-offset)) 0 1.25rem !important;
        min-height: 0 !important;
    }

    .hero.hero--modern.hero--chase .hero-container.hero--chase__container {
        grid-template-columns: 1fr !important;
        text-align: center;
        gap: 1rem !important;
    }

    .hero-chase-visual {
        order: -1;
        width: 100%;
        max-width: min(100%, 400px);
        margin-inline: auto;
    }

    .hero-video-frame {
        margin-inline: auto;
    }

    .hero-chase-btns {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        max-width: 22rem;
        margin-inline: auto;
    }

    .hero-chase-btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    .hero-container {
        grid-template-columns: 1fr !important;
        gap: 1.25rem !important;
    }

    .hero-title {
        font-size: clamp(1.65rem, 6vw, 2.25rem) !important;
    }

    .hero-visual {
        height: auto !important;
        min-height: 220px;
        max-height: 42dvh;
    }

    .cards-hero,
    .sets-hero {
        padding-top: calc(var(--m-header-offset) + 2rem) !important;
        padding-left: max(0.85rem, env(safe-area-inset-left, 0px)) !important;
        padding-right: max(0.85rem, env(safe-area-inset-right, 0px)) !important;
    }

    .duel-hero {
        padding: calc(var(--m-header-offset) + 1rem) 1rem 1.5rem !important;
    }

    /* ----- Grids & cards ----- */
    .cards-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .ra05-bento {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.65rem !important;
    }

    .tcg-hub-grid {
        grid-template-columns: 1fr !important;
    }

    .community-grid,
    .footer-content,
    .resources-grid,
    .features-grid,
    .tips-grid {
        grid-template-columns: 1fr !important;
    }

    .card-item {
        will-change: auto !important;
    }

    .hero-image {
        will-change: auto !important;
    }

    /* Reduce hover motion on touch devices */
    @media (hover: none) {
        .resource-card:hover,
        .feature-card:hover,
        .tip-card:hover,
        .community-card:hover {
            transform: none !important;
        }

        .hero-image:hover {
            transform: none !important;
        }
    }

    /* ----- Modals ----- */
    .modal-overlay {
        align-items: flex-start !important;
        justify-content: center !important;
        padding: max(0.5rem, env(safe-area-inset-top, 0px))
            max(0.5rem, env(safe-area-inset-right, 0px))
            max(0.5rem, env(safe-area-inset-bottom, 0px))
            max(0.5rem, env(safe-area-inset-left, 0px)) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .card-details-modal,
    .modal-content {
        width: 100% !important;
        max-width: min(36rem, 100%) !important;
        max-height: min(88dvh, calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 1rem)) !important;
        margin: 0.5rem auto !important;
    }

    .modal-header {
        padding: 1rem 1rem !important;
        position: sticky;
        top: 0;
        z-index: 2;
        background: var(--bg-card);
    }

    .modal-body {
        padding: 1rem !important;
    }

    .close-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .news-status {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .btn {
        min-height: 46px;
    }
}

@media (max-width: 479.98px) {
    :root {
        --m-header-bar: 52px;
    }

    .ra05-bento {
        grid-template-columns: 1fr !important;
    }

    .hero-chase-title {
        font-size: clamp(1.2rem, 7vw, 1.65rem) !important;
    }

    .section {
        padding: 1.85rem 0 !important;
    }

    .container {
        padding-left: max(0.65rem, env(safe-area-inset-left, 0px)) !important;
        padding-right: max(0.65rem, env(safe-area-inset-right, 0px)) !important;
    }
}

/* ----- Duel page (nav.js only; same header tokens) ----- */
@media (max-width: 767.98px) {
    body.duel-page {
        min-height: 100dvh;
    }

    .duel-page .duel-settings-panel,
    .duel-page .duel-board,
    .duel-page .duel-extras-panel,
    .duel-page .duel-log-panel {
        padding-left: max(0.75rem, env(safe-area-inset-left, 0px)) !important;
        padding-right: max(0.75rem, env(safe-area-inset-right, 0px)) !important;
    }

    .duel-player-card {
        padding: 1rem !important;
    }

    .duel-lp-grid button {
        min-height: 44px;
        padding-top: 0.65rem !important;
        padding-bottom: 0.65rem !important;
    }

    .duel-turn-inline {
        flex: 1 1 100% !important;
        min-width: 0 !important;
    }

    .duel-custom-row input[type='number'] {
        flex: 1 1 auto;
        min-width: 0;
        max-width: 100%;
    }
}

/*
 * Homepage chase hero — remove the “tall empty band” on mobile.
 * Base .hero uses flex + align-items:center + large min-height; chase must
 * stack from the top with content-sized height (loads after style.css).
 */
@media (max-width: 767.98px) {
    .hero.hero--modern.hero--chase {
        min-height: 0 !important;
        height: auto !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        align-items: stretch !important;
        align-content: flex-start !important;
    }

    .hero.hero--modern.hero--chase .hero-container.hero--chase__container {
        align-items: stretch !important;
        align-content: start !important;
        justify-items: stretch !important;
        min-height: 0 !important;
        flex: 0 1 auto !important;
        width: 100%;
    }

    .hero-chase-visual {
        flex: 0 0 auto !important;
    }
}
