/* Touch-first layout adjustments shared by the game pages. */
.mobile-nav-toggle { display: none; }

@media (max-width: 760px), (orientation: landscape) and (max-height: 520px) and (max-width: 1024px) {
    *, *::before, *::after { box-sizing: border-box; }
    html { -webkit-text-size-adjust: 100%; scroll-padding-top: 12px; }
    body { min-width: 320px; overflow-x: hidden; }

    nav {
        display: grid !important;
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-areas: "menu status" "links links";
        align-items: center;
        gap: 8px 10px;
        padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)) !important;
    }
    .mobile-nav-toggle {
        grid-area: menu;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 7px;
        min-width: 82px;
        min-height: 42px;
        padding: 8px 12px;
        border: 1px solid #555;
        border-radius: 10px;
        background: #252525;
        color: #fff;
        font: inherit;
        font-size: 14px;
        cursor: pointer;
        touch-action: manipulation;
    }
    .mobile-nav-toggle span:first-child { font-size: 19px; line-height: 1; }
    .user-status-top {
        grid-area: status;
        justify-self: end;
        min-width: 0;
        max-width: 100%;
        gap: 6px !important;
        padding: 5px 9px !important;
        font-size: 13px;
    }
    .username-display {
        display: inline-block;
        max-width: 28vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .coins-display, .coin-icon { font-size: 15px !important; }
    .notification-bell { width: 36px !important; min-width: 36px !important; min-height: 0 !important; padding: 0 !important; }
    .notification-badge { top: -6px; right: -6px; min-width: 17px; height: 17px; font-size: 10px; }
    .nav-links {
        grid-area: links;
        display: grid !important;
        width: 100%;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px !important;
        padding-top: 4px;
    }
    nav.has-mobile-toggle:not(.mobile-open) .nav-links { display: none !important; }
    nav.has-mobile-toggle.mobile-open .nav-links { display: grid !important; }
    .nav-links a {
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 0;
        min-height: 42px;
        padding: 8px 5px;
        border: 1px solid #ffffff14;
        border-radius: 9px;
        background: #ffffff08;
        font-size: 13px !important;
        line-height: 1.25;
        text-align: center;
        overflow-wrap: anywhere;
        touch-action: manipulation;
    }
    .notifications-page { padding: 18px 12px !important; }
    .notifications-header { margin-bottom: 18px; }
    .notification-item { gap: 10px; padding: 11px; }
    .notification-card-image { width: 48px; height: 68px; }
    .notification-title-row { align-items: flex-start; flex-direction: column; gap: 2px; }
    .notification-title-row h2 { font-size: .98rem; }

    .main-content {
        width: 100%;
        max-width: 100%;
        margin: 18px auto !important;
        padding: 10px !important;
    }
    .auth-container { box-sizing: border-box; width: min(calc(100% - 24px), 420px) !important; padding: 24px 18px !important; border-radius: 22px !important; }
    .main-content h1 { font-size: clamp(1.35rem, 6vw, 2rem); line-height: 1.25; }
    .pack-group { margin-top: 18px !important; padding: 14px 10px !important; border-radius: 14px !important; }
    .pack-group h2 { max-width: 100%; font-size: 17px !important; letter-spacing: .04em !important; margin-bottom: 15px !important; }
    .pack-list {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px !important;
    }
    .pack-option {
        box-sizing: border-box;
        width: auto !important;
        min-width: 0;
        padding: 8px !important;
        border-width: 2px !important;
        border-radius: 12px !important;
    }
    .pack-option img { width: min(100%, 135px) !important; max-width: 100%; }
    .pack-option p { margin: 7px 0 2px !important; font-size: 13px; }
    .pack-option:hover { transform: none !important; }
    .btn-open-inner { width: min(145px, 100%); max-width: 100%; padding: 0 !important; font-size: inherit !important; }

    .daily-bonus-card { margin-bottom: 20px !important; padding: 15px 10px !important; }
    .energy-cards { gap: 12px !important; margin-top: 15px !important; }
    .energy-card { width: min(27vw, 100px) !important; height: auto !important; aspect-ratio: 5 / 7; }
    .filter-container { gap: 7px !important; margin: 16px 0 !important; }
    .filter-btn { min-height: 42px; padding: 8px 13px !important; }
    .filter-series-select { min-height: 42px; min-width: min(190px, 100%); }
    .inventory-search-input { min-height: 42px; width: 100%; min-width: 0; border-radius: 12px; }
    .inventory-sort-control { width: 100%; justify-content: space-between; }
    .inventory-sort-control .filter-series-select { flex: 1; min-width: 0; }

    .inventory-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
        padding: 8px !important;
    }
    .inventory-item {
        box-sizing: border-box;
        min-width: 0;
        min-height: 0 !important;
        padding: 8px !important;
        border-radius: 12px !important;
        overflow: hidden !important;
    }
    .inventory-item:hover { transform: none !important; }
    .inventory-item img { width: 100%; max-width: 100%; height: auto; }
    .inventory-item .card-display-name, .inventory-item p { overflow-wrap: anywhere; }
    .action-container { flex-wrap: wrap; gap: 6px !important; }
    .btn-action { min-height: 42px; padding: 8px 4px !important; font-size: 11px !important; }
    .rarity-tag { max-width: 100%; }
    .card-count-badge { top: 42% !important; right: 2px !important; width: 25px !important; height: 25px !important; }

    .collection-container { width: 100%; box-sizing: border-box; padding: 10px !important; }
    .col-control-panel {
        position: static !important;
        top: auto !important;
        display: grid !important;
        grid-template-columns: minmax(0, 1fr);
        gap: 10px !important;
        padding: 12px !important;
        margin-bottom: 16px !important;
    }
    .col-filter-group { width: 100%; min-width: 0; }
    .col-input, .col-select { width: 100%; min-width: 0; min-height: 44px; box-sizing: border-box; }
    .col-set-section { padding: 12px !important; margin-bottom: 18px !important; border-radius: 14px !important; scroll-margin-top: 12px !important; }
    .col-set-info { align-items: flex-start !important; gap: 8px; }
    .col-set-info > div:last-child { width: 100%; text-align: left !important; }
    .col-progress-bar { width: 100% !important; }
    .col-card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 6px !important; }
    .col-card-label { padding: 3px 2px !important; font-size: 9px !important; }

    .upgrade-container { width: auto !important; max-width: 100%; margin: 10px !important; padding: 12px !important; border-radius: 15px !important; }
    .slot-container { gap: 7px !important; margin-bottom: 18px !important; }
    .card-slot { width: min(39vw, 150px) !important; height: auto !important; aspect-ratio: 5 / 7; }
    .plus-sign { font-size: clamp(24px, 8vw, 40px) !important; }
    .stat-row { gap: 8px; font-size: .95rem !important; }
    .btn-upgrade.image-button { width: min(100%, 250px) !important; min-height: 0 !important; padding: 0 !important; }
    .card-list-modal {
        inset: 8px !important;
        top: 8px !important;
        left: 8px !important;
        width: auto !important;
        height: auto !important;
        max-height: calc(100dvh - 16px);
        transform: none !important;
        padding: 10px !important;
        border-radius: 14px !important;
    }
    .modal-header { margin-bottom: 10px !important; }
    .modal-header h2 { margin: 4px 0 10px !important; font-size: 1.1rem; }
    .modal-controls { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 7px !important; }
    .modal-search-input { grid-column: 1 / -1 !important; width: 100%; box-sizing: border-box; min-width: 0; }
    .modal-filter-select { width: 100%; min-width: 0; font-size: 14px; }
    .modal-body-scroll { min-height: 0; padding-right: 0 !important; }
    .grid-cards { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
    .selectable-card:hover { transform: none !important; }
    .upgrade-card-name { font-size: 12px; }

    .market-controls { margin: 12px 8px !important; text-align: left !important; }
    .market-controls select { width: 100%; min-height: 44px; }
    .leaderboard-page { border-radius: 7px !important; }
    .leaderboard-wrapper { width: 100%; box-sizing: border-box; margin: 16px auto !important; padding: 8px !important; overflow-x: hidden; border-radius: 7px !important; }
    .leaderboard-header { margin-bottom: 18px !important; }
    .leaderboard-header h1 { font-size: 1.65rem !important; letter-spacing: .05em !important; }
    .leaderboard-table { width: 100%; min-width: 0; table-layout: fixed; }
    .leaderboard-table { border-radius: 7px; }
    .leaderboard-table th, .leaderboard-table td { box-sizing: border-box; padding: 9px 4px !important; font-size: .72rem !important; overflow-wrap: anywhere; }
    .leaderboard-table th:nth-child(1), .leaderboard-table td:nth-child(1) { width: 13%; }
    .leaderboard-table th:nth-child(2), .leaderboard-table td:nth-child(2) { width: 34%; }
    .leaderboard-table th:nth-child(3), .leaderboard-table td:nth-child(3) { width: 20%; }
    .leaderboard-table th:nth-child(4), .leaderboard-table td:nth-child(4) { width: 33%; }
    .leaderboard-table th { font-size: .61rem !important; letter-spacing: 0 !important; line-height: 1.2; }
    .rank-badge { width: 27px; height: 27px; line-height: 27px; font-size: .8rem; }
    .username-cell { gap: 4px !important; min-width: 0; flex-wrap: wrap; overflow-wrap: anywhere; }
    .my-label { margin-left: 0; }
    .wealth-cell { font-size: .85rem !important; }

    .guide-container { width: 100%; box-sizing: border-box; margin: 24px auto !important; padding: 0 12px !important; }
    .guide-header { margin-bottom: 28px !important; }
    .guide-header h1 { font-size: clamp(1.8rem, 9vw, 2.5rem) !important; }
    .step-card, .step-card:nth-child(even) { gap: 12px !important; margin-bottom: 16px !important; padding: 18px 14px !important; border-radius: 18px !important; }
    .step-content h2 { margin-bottom: 10px !important; font-size: 1.35rem !important; }
    .step-content p { font-size: 1rem !important; }
    .visual-aid { width: 130px !important; height: 130px !important; }
    .pack-anim { width: 105px !important; height: 140px !important; }
    .btn-start { display: block !important; padding: 14px 20px !important; }

    .slot-page { padding: 8px !important; }
    .game-card { margin: 12px auto 25px !important; padding: 18px 12px !important; }
    .machine-heading h1 { font-size: clamp(1.4rem, 7vw, 2rem) !important; }
    .machine-subtitle { margin: 8px 0 16px !important; font-size: .95rem; }
    .slot-display { width: 100% !important; padding: 9px !important; gap: 7px !important; }
    .slot-reel { padding: 5px !important; }
    .reel-label { font-size: .55rem !important; letter-spacing: .04em !important; }
    .machine-info { gap: 7px !important; }

    .modal-content, .alert-box { box-sizing: border-box; width: calc(100% - 24px) !important; max-width: 420px; max-height: calc(100dvh - 24px); overflow-y: auto; padding: 18px !important; border-radius: 18px !important; }
    .modal-overlay, .game-alert-mask, .game-alert { padding: 12px; }
    button, input, select, textarea { font-size: 16px; }
    button, a, select { touch-action: manipulation; }
}

@media (max-width: 380px) {
    .inventory-grid { gap: 7px !important; padding: 5px !important; }
    .inventory-item { padding: 6px !important; }
    .col-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .user-status-top { padding: 4px 7px !important; }
}

/* Keep the pack reveal cards within the narrow phone viewport. */
@media (max-width: 760px), (orientation: landscape) and (max-height: 520px) and (max-width: 1024px) {
    #gacha-overlay {
        box-sizing: border-box;
        justify-content: flex-start;
        overflow-x: hidden;
        overflow-y: auto;
        padding: max(14px, env(safe-area-inset-top)) 10px max(18px, env(safe-area-inset-bottom));
    }
    #pack-total-value {
        flex: 0 0 auto;
        max-width: 100%;
        margin: 0 0 10px;
        padding: 10px 20px;
    }
    #reveal-status {
        flex: 0 0 auto;
        max-width: 100%;
        margin: 8px 0 12px;
        font-size: clamp(18px, 5.5vw, 25px);
        line-height: 1.35;
    }
    .card-stack {
        flex: 0 0 auto;
        width: 100%;
        height: clamp(300px, 44dvh, 380px);
        overflow: visible;
        perspective: 1200px;
    }
    .card-container {
        width: min(26vw, 118px);
        height: auto;
        aspect-ratio: 5 / 7;
    }
    #close-reveal {
        flex: 0 0 auto;
        margin-top: 12px !important;
    }
}

/* Phone landscape has desktop-like width but very little vertical room. Keep
   the touch layout while tightening the header and fitting overlays to height. */
@media screen and (orientation: landscape) and (max-height: 520px) and (max-width: 1024px) {
    nav { gap: 5px 8px; padding-top: 5px !important; padding-bottom: 5px !important; }
    .mobile-nav-toggle { min-height: 36px; padding: 5px 10px; }
    .user-status-top { padding: 3px 8px !important; }
    .nav-links { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 5px !important; }
    .nav-links a { min-width: 0; padding: 7px 5px !important; font-size: 12px !important; }
    .main-content { margin-top: 8px !important; margin-bottom: 8px !important; padding: 8px !important; }
    #gacha-overlay { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    #reveal-status { margin: 4px 0 6px; font-size: clamp(16px, 3.5vw, 21px); }
    .card-stack { height: min(52dvh, 250px); }
    .card-container { width: min(15vw, 95px); }
    .new-card-badge {
        top: 3px !important;
        right: 1px !important;
        left: auto !important;
        width: 38px !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }
    #pack-total-value { margin-bottom: 5px; padding: 6px 14px; }
    .modal-content, .alert-box { max-height: calc(100dvh - 12px) !important; padding: 12px !important; }
    .card-list-modal { max-height: calc(100dvh - 16px) !important; }

    /* The pack summary must fit above the phone's browser/system controls. */
    #gacha-overlay {
        inset: 0;
        width: 100%;
        height: 100dvh;
        justify-content: flex-start;
        gap: 4px;
        overflow-x: hidden;
        overflow-y: auto;
        padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }
    #pack-total-value { margin: 0 0 2px; padding: 5px 14px; }
    .total-value-title { margin-bottom: 0; font-size: .68rem; letter-spacing: 1px; }
    .total-value-amount { font-size: 1.35rem; line-height: 1.2; }
    #reveal-status { margin: 2px 0 4px; font-size: clamp(15px, 3.5vh, 20px); line-height: 1.15; }
    .card-stack { flex: 0 0 auto; width: 100%; height: min(34dvh, 145px); min-height: 76px; overflow: visible; }
    .card-container { width: min(22dvh, 90px); height: auto; aspect-ratio: 5 / 7; }
    #close-reveal { flex: 0 0 auto; min-height: 40px; margin: 4px 0 0 !important; padding: 7px 22px; font-size: 15px; }
}

/* iPad portrait sits just beyond the phone breakpoint. Fold the crowded
   desktop navigation and keep the five reveal cards inside the screen. */
@media screen and (orientation: portrait) and (min-width: 761px) and (max-width: 1100px) {
    nav {
        display: grid !important;
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-areas: "menu status" "links links";
        align-items: center;
        gap: 8px 12px;
        padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)) !important;
    }
    .mobile-nav-toggle { grid-area: menu; display: inline-flex !important; }
    .user-status-top { grid-area: status; justify-self: end; min-width: 0; max-width: 100%; }
    .username-display { max-width: 24vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .nav-links {
        grid-area: links;
        display: grid !important;
        width: 100%;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 7px !important;
        padding-top: 4px;
    }
    nav.has-mobile-toggle:not(.mobile-open) .nav-links { display: none !important; }
    nav.has-mobile-toggle.mobile-open .nav-links { display: grid !important; }
    .nav-links a { min-width: 0; padding: 8px 6px !important; text-align: center; }

    #gacha-overlay {
        box-sizing: border-box;
        justify-content: flex-start;
        overflow-x: hidden;
        overflow-y: auto;
        padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    }
    #pack-total-value { flex: 0 0 auto; margin: 0 0 10px; }
    #reveal-status { flex: 0 0 auto; margin: 8px 0 12px; font-size: clamp(20px, 3vw, 28px); }
    .card-stack { flex: 0 0 auto; width: 100%; height: 370px; overflow: visible; }
    .card-container { width: min(26vw, 118px); height: auto; aspect-ratio: 5 / 7; }
    #close-reveal { flex: 0 0 auto; margin-top: 12px !important; }
}
