/* =================================================================
   AETHER CHRONICLES - MOBILE RESPONSIVE CSS
   Consolidated mobile/tablet responsive overrides.
   Breakpoints:
     - Tablet:          max-width 1024px
     - Phone landscape:  max-width 768px
     - Phone portrait:   max-width 480px
   ================================================================= */

/* -----------------------------------------------------------------
   GLOBAL / SHARED RULES
   ----------------------------------------------------------------- */

/* Viewport meta hint (actual tag must be in HTML) */
@viewport { width: device-width; }

/* Prevent horizontal overflow site-wide on small screens */
@media (max-width: 1024px) {
    html, body {
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
}

/* =================================================================
   1. MAIN MENU - premium-header, sidebar, hero area
   ================================================================= */

/* --- Tablet (max-width 1024px) --- */
@media (max-width: 1024px) {
    /* Slightly compact header */
    .premium-header {
        height: 50px;
        padding: 0 14px;
    }

    /* Adjust screen top to match smaller header */
    #screen-main-menu.active {
        top: 50px !important;
    }

    /* Narrower sidebar */
    .main-menu-sidebar {
        width: 220px;
        min-width: 220px;
        max-width: 220px;
        padding: 14px;
    }

    /* Shift hero / news to match sidebar */
    .news-carousel-container,
    .hero-artwork-area {
        left: 220px;
    }

    /* Smaller currency pills */
    .currency-pill {
        padding: 3px 8px;
    }

    .currency-amount {
        font-size: 12px;
    }

    /* Touch-friendly nav buttons in PLAY grid */
    .nav-section:first-child .nav-btn {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    /* Touch-friendly compact nav links */
    .nav-section:not(:first-child) .nav-btn {
        min-height: 44px !important;
        padding: 10px 12px !important;
    }
}

/* --- Phone landscape (max-width 768px) --- */
@media (max-width: 768px) {
    .premium-header {
        height: 46px;
        padding: 0 10px;
    }

    #screen-main-menu.active {
        top: 46px !important;
        flex-direction: column;
    }

    /* Collapse sidebar to bottom drawer style */
    .main-menu-sidebar {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        height: auto;
        max-height: 45vh;
        order: 2;
        border-right: none;
        border-top: 1px solid rgba(212, 168, 87, 0.2);
        overflow-y: auto;
        padding: 12px 16px;
    }

    /* Play buttons: 2-column grid, touch-friendly */
    .nav-section:first-child .nav-buttons {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .nav-section:first-child .nav-btn {
        aspect-ratio: unset !important;
        padding: 14px 8px !important;
        min-height: 56px !important;
        font-size: 13px !important;
    }

    /* Other nav sections: horizontal scrollable row */
    .nav-section:not(:first-child) .nav-buttons {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 6px !important;
        padding-bottom: 4px;
    }

    .nav-section:not(:first-child) .nav-buttons::-webkit-scrollbar {
        display: none;
    }

    .nav-section:not(:first-child) .nav-btn {
        min-height: 44px !important;
        white-space: nowrap;
        flex-shrink: 0;
        font-size: 14px !important;
    }

    /* Hero area sits above the sidebar */
    .hero-artwork-area {
        left: 0 !important;
        position: relative;
        order: 1;
        flex: 1;
        min-height: 200px;
    }

    .news-carousel-container {
        left: 0 !important;
        padding: 10px 12px;
    }

    /* News banner: stack vertically */
    .hero-news-banner {
        flex-direction: column !important;
        gap: 10px;
        padding: 12px 16px;
    }

    .duel-live-btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    /* Logo still visible on landscape phones */
    .header-center {
        display: flex;
    }

    .logo-aether {
        font-size: 14px;
        letter-spacing: 4px;
    }

    .logo-chronicles {
        font-size: 7px;
        letter-spacing: 3px;
    }

    /* Hide add-currency button to save space */
    .currency-add {
        display: none;
    }
}

/* --- Phone portrait (max-width 480px) --- */
@media (max-width: 480px) {
    .premium-header {
        height: 44px;
        padding: 0 8px;
    }

    #screen-main-menu.active {
        top: 44px !important;
    }

    /* Hide center logo on small phones */
    .header-center {
        display: none !important;
    }

    /* Stack header into left+right only */
    .header-right {
        gap: 6px;
    }

    .header-icon-btn {
        width: 34px;
        height: 34px;
    }

    /* Currency pills compact */
    .currency-pill {
        padding: 2px 6px;
        border-radius: 12px;
    }

    .currency-pill .currency-icon {
        font-size: 13px;
    }

    .currency-amount {
        font-size: 11px;
    }

    /* Single column play grid on tiny phones */
    .nav-section:first-child .nav-buttons {
        grid-template-columns: 1fr 1fr !important;
    }

    .nav-section:first-child .nav-btn {
        min-height: 50px !important;
        font-size: 12px !important;
    }

    .nav-section:first-child .nav-icon svg {
        width: 24px;
        height: 24px;
    }

    /* News cards smaller */
    .news-card {
        width: 140px;
    }

    .news-card-image {
        height: 50px;
    }

    .news-card-content h4 {
        font-size: 11px;
    }

    .news-card-content p {
        font-size: 9px;
    }

    /* Hero banner text */
    .news-banner-text h3 {
        font-size: 14px;
    }

    .news-banner-text p {
        font-size: 11px;
    }

    .duel-live-btn {
        font-size: 13px;
        padding: 10px 16px;
    }

    /* Ensure readable text */
    .player-name {
        font-size: 13px;
    }
}

/* =================================================================
   2. BATTLE SCREEN - battlefield, field zones, hand, stats bars
   ================================================================= */

/* --- Tablet (max-width 1024px) --- */
@media (max-width: 1024px) {
    /* Compact stats bars */
    #opponent-stats-bar,
    #player-stats-bar {
        height: 30px !important;
        font-size: 10px !important;
        padding: 2px 10px !important;
    }

    .battle-stat {
        padding: 2px 8px;
        font-size: 9px;
    }

    .next-phase-prompt {
        padding: 6px 16px !important;
        font-size: 11px !important;
    }

    #surrender-button {
        padding: 6px 14px !important;
        font-size: 10px !important;
    }
}

/* --- Phone landscape (max-width 768px) --- */
@media (max-width: 768px) {
    /* Stats bars thinner */
    #opponent-stats-bar,
    #player-stats-bar {
        height: 28px !important;
        font-size: 9px !important;
        padding: 2px 8px !important;
    }

    /* Battlefield: single column stacked layout */
    .battlefield-container {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto auto auto auto auto !important;
        grid-template-areas:
            "opponent-field"
            "center-area"
            "player-field"
            "hand-area"
            "side-panel" !important;
        gap: 6px !important;
        padding: 6px !important;
        height: auto !important;
        overflow-y: auto !important;
    }

    /* Hide battle log on phone to save space (accessible via toggle) */
    .battle-log {
        display: none !important;
    }

    /* Field zones: scrollable row */
    .field-container,
    #player-field,
    #opponent-field {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 8px !important;
        padding: 6px !important;
        justify-content: flex-start !important;
    }

    .field-container::-webkit-scrollbar,
    #player-field::-webkit-scrollbar,
    #opponent-field::-webkit-scrollbar {
        display: none;
    }

    /* Smaller field zones */
    .field-zone {
        width: 140px !important;
        height: 110px !important;
        min-width: 140px !important;
        max-width: 140px !important;
        min-height: 110px !important;
        max-height: 110px !important;
        flex-shrink: 0 !important;
        margin: 2px !important;
        padding: 4px !important;
        border-width: 2px !important;
        border-radius: 10px !important;
    }

    #player-field .field-zone,
    #opponent-field .field-zone {
        border-width: 3px !important;
    }

    /* Cards on field scale down */
    .card-on-field,
    .field-zone .card {
        width: 120px !important;
        height: 96px !important;
    }

    /* Stat badges smaller */
    .field-zone .battlefield-stat {
        width: 24px !important;
        height: 24px !important;
        font-size: 11px !important;
    }

    /* Player hand: fixed bottom, horizontal scroll */
    #player-hand {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        min-height: 110px !important;
        max-height: 120px !important;
        height: 115px !important;
        padding: 8px 12px !important;
        z-index: 100 !important;
        border-radius: 12px 12px 0 0 / 12px 12px 0 0 !important;
        border-top-width: 4px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start !important;
        flex-wrap: nowrap !important;
        gap: 0 !important;
    }

    #player-hand::-webkit-scrollbar {
        display: none;
    }

    /* Hand cards: remove fan rotation for scrollable layout */
    .card-in-hand,
    .card-in-hand:nth-child(n) {
        transform: none !important;
        flex-shrink: 0 !important;
        margin-right: -10px !important;
    }

    .card-in-hand:last-child {
        margin-right: 0 !important;
    }

    #player-hand .card {
        width: 85px !important;
        height: 119px !important;
        margin-right: -10px !important;
        border-radius: 10px !important;
    }

    #player-hand .card:last-child {
        margin-right: 0 !important;
    }

    /* Smaller hover effect on phone */
    .card-in-hand:hover {
        transform: translateY(-30px) scale(1.2) !important;
        margin-left: 20px !important;
        margin-right: 20px !important;
    }

    /* Center area compact */
    .center-area {
        min-height: 40px;
        padding: 4px 8px;
    }

    .vs-display {
        font-size: 22px;
    }

    /* Side panel horizontal */
    .side-panel {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 6px !important;
        padding: 6px !important;
    }

    .deck-zone,
    .discard-zone {
        min-width: 60px;
        min-height: 36px;
    }

    /* Account for fixed hand at bottom */
    .battlefield-container {
        padding-bottom: 125px !important;
    }

    /* Touch-friendly phase/action buttons */
    .next-phase-prompt {
        padding: 10px 20px !important;
        font-size: 12px !important;
        min-height: 44px !important;
    }

    #surrender-button {
        min-height: 44px !important;
        min-width: 44px !important;
    }
}

/* --- Phone portrait (max-width 480px) --- */
@media (max-width: 480px) {
    /* Even smaller stats bars */
    #opponent-stats-bar,
    #player-stats-bar {
        height: 26px !important;
        font-size: 8px !important;
        padding: 1px 6px !important;
    }

    .battle-stat {
        padding: 1px 5px;
        font-size: 8px;
        gap: 3px;
    }

    /* Smaller field zones for portrait phones */
    .field-zone {
        width: 110px !important;
        height: 90px !important;
        min-width: 110px !important;
        max-width: 110px !important;
        min-height: 90px !important;
        max-height: 90px !important;
        border-radius: 8px !important;
    }

    .card-on-field,
    .field-zone .card {
        width: 95px !important;
        height: 76px !important;
    }

    .field-zone .battlefield-stat {
        width: 20px !important;
        height: 20px !important;
        font-size: 9px !important;
    }

    /* Player hand smaller */
    #player-hand {
        height: 100px !important;
        min-height: 95px !important;
        max-height: 105px !important;
        padding: 6px 8px !important;
    }

    #player-hand .card {
        width: 68px !important;
        height: 95px !important;
        margin-right: -8px !important;
        border-radius: 8px !important;
    }

    .card-in-hand:hover {
        transform: translateY(-25px) scale(1.15) !important;
        margin-left: 15px !important;
        margin-right: 15px !important;
    }

    /* Center area minimal */
    .center-area {
        min-height: 30px;
        border-width: 2px !important;
    }

    .vs-display {
        font-size: 18px;
    }

    /* Pad bottom for smaller hand */
    .battlefield-container {
        padding-bottom: 110px !important;
    }

    /* Phase button touch-friendly */
    .next-phase-prompt {
        min-height: 44px !important;
        font-size: 11px !important;
        padding: 8px 16px !important;
    }

    #surrender-button {
        min-height: 44px !important;
        padding: 8px 12px !important;
        font-size: 10px !important;
    }
}


/* =================================================================
   3. SHOP SCREEN - shop grid, items, navigation, featured banner
   ================================================================= */

/* --- Tablet (max-width 1024px) --- */
@media (max-width: 1024px) {
    /* Shop header compact */
    .shop-header {
        padding: 1.25rem;
    }

    .shop-title {
        font-size: 2.2rem;
    }

    .shop-subtitle {
        font-size: 1rem;
    }

    /* Grid: 2 columns on tablet */
    .shop-grid,
    .bundles-grid,
    .cosmetics-grid,
    .secret-items-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
        padding: 1.5rem;
    }

    body #screen-shop.active .shop-items-container {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.2rem !important;
    }

    body #screen-shop.active .shop-item {
        max-width: 100% !important;
        min-height: 280px !important;
    }

    /* Tabs: wrap */
    body #screen-shop.active .shop-nav-tabs {
        flex-wrap: wrap !important;
        gap: 4px !important;
        padding: 0.75rem 1rem 0 !important;
    }

    body #screen-shop.active .shop-tab {
        flex: 1 !important;
        min-width: 100px !important;
        padding: 0.7rem 1rem !important;
        font-size: 0.9rem !important;
        min-height: 44px !important;
    }

    /* Featured banner stacked */
    body #screen-shop.active .featured-pack-banner {
        flex-direction: column !important;
        height: auto !important;
        min-height: 200px !important;
    }

    /* Currency display compact */
    .player-currency {
        gap: 0.75rem;
    }

    .currency-display {
        padding: 0.5rem 0.75rem;
    }

    .currency-amount {
        font-size: 1.1rem;
    }

    /* Shop navigation touch targets */
    .shop-nav-btn {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }
}

/* --- Phone landscape (max-width 768px) --- */
@media (max-width: 768px) {
    .shop-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
        text-align: center;
    }

    .shop-title {
        font-size: 1.8rem;
    }

    .shop-subtitle {
        font-size: 0.95rem;
    }

    .player-currency {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Single column grid on phones */
    .shop-grid,
    .bundles-grid,
    .cosmetics-grid,
    .secret-items-grid {
        grid-template-columns: 1fr !important;
        gap: 1.25rem;
        padding: 1rem;
    }

    body #screen-shop.active .shop-items-container {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
        padding: 0.5rem !important;
    }

    body #screen-shop.active .shop-item {
        max-width: 100% !important;
        min-height: 260px !important;
    }

    /* Tabs: stack vertically */
    body #screen-shop.active .shop-nav-tabs {
        flex-direction: column !important;
        padding: 0.5rem !important;
    }

    body #screen-shop.active .shop-tab {
        width: 100% !important;
        text-align: center !important;
        border-radius: 8px !important;
        margin-bottom: 4px !important;
        min-height: 44px !important;
        font-size: 14px !important;
    }

    .shop-section {
        padding: 1rem;
    }

    .section-header {
        margin-bottom: 1.5rem;
    }

    .section-header h2 {
        font-size: 1.6rem;
    }

    .section-header p {
        font-size: 1rem;
    }

    /* Featured banner */
    body #screen-shop.active .featured-pack-banner {
        margin: 0 0.5rem 1rem !important;
        height: auto !important;
    }

    body #screen-shop.active .featured-pack-info {
        padding: 1rem !important;
    }

    body #screen-shop.active .featured-pack-title {
        font-size: 1.3rem !important;
    }

    /* Shop navigation scrollable */
    .shop-navigation {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }

    .shop-navigation::-webkit-scrollbar {
        display: none;
    }

    .shop-nav-btn {
        flex-shrink: 0;
        min-height: 44px;
        min-width: 44px;
    }

    /* Item content readable */
    .item-content {
        padding: 1rem;
    }

    .item-content h3 {
        font-size: 1.1rem;
    }

    .buy-button {
        width: 100%;
        min-height: 44px;
        font-size: 14px;
    }

    .purchase-controls {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* --- Phone portrait (max-width 480px) --- */
@media (max-width: 480px) {
    .shop-title {
        font-size: 1.5rem;
    }

    .shop-subtitle {
        font-size: 0.85rem;
    }

    .currency-display {
        padding: 0.4rem 0.6rem;
        border-radius: 18px;
    }

    .currency-icon {
        font-size: 1.2rem;
    }

    .currency-amount {
        font-size: 1rem;
    }

    .currency-label {
        font-size: 0.75rem;
    }

    body #screen-shop.active .shop-item {
        min-height: 240px !important;
        padding: 1rem !important;
    }

    body #screen-shop.active .shop-item h3 {
        font-size: 1rem !important;
    }

    body #screen-shop.active .shop-item-icon {
        width: 60px !important;
        height: 60px !important;
    }

    .item-image-container {
        height: 140px;
    }

    /* Quantity selector touch targets */
    .pack-quantity-btn,
    body #screen-shop.active .pack-quantity-btn {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    /* Ensure readable text */
    body #screen-shop.active .shop-item-description,
    body #screen-shop.active .shop-item p {
        font-size: 14px !important;
    }
}


/* =================================================================
   4. DECK MANAGER - three-column layout, panels, controls
   ================================================================= */

/* --- Tablet (max-width 1024px) --- */
@media (max-width: 1024px) {
    /* Already handled by deck-manager-layout.css (goes single column below 1024px) */
    /* Add touch-friendly overrides */

    .deck-builder-layout {
        height: auto !important;
        overflow: visible !important;
        padding: 10px !important;
        gap: 10px !important;
    }

    .deck-builder-collection-panel .card-list,
    .deck-builder-deck-panel .card-list {
        max-height: 50vh !important;
    }

    /* Touch-friendly filter buttons */
    .card-type-filter-btn {
        min-height: 36px;
        padding: 6px 12px;
        font-size: 12px;
    }

    .quick-filter-btn {
        min-height: 40px;
        padding: 8px 14px;
    }

    /* Larger touch targets for view buttons */
    .view-button {
        min-width: 44px;
        min-height: 44px;
        padding: 8px 12px;
    }

    .secondary-button {
        min-height: 36px;
        padding: 6px 12px;
        font-size: 0.8em;
    }

    /* Compact card grid */
    .deck-builder-collection-panel .card-list,
    .deck-builder-deck-panel .card-list {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 3px;
    }
}

/* --- Phone landscape (max-width 768px) --- */
@media (max-width: 768px) {
    #screen-deck-manager {
        padding-top: 50px;
    }

    .deck-builder-layout {
        grid-template-columns: 1fr !important;
        padding: 8px !important;
        gap: 8px !important;
    }

    /* Panels stack and scroll */
    .deck-builder-collection-panel,
    .deck-builder-deck-panel,
    .deck-builder-info-panel {
        padding: 8px;
        border-radius: 8px;
    }

    .deck-builder-collection-panel .card-list,
    .deck-builder-deck-panel .card-list {
        max-height: 40vh !important;
        grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
    }

    /* Panel headers compact */
    .panel-header {
        margin-bottom: 8px;
        padding-bottom: 6px;
    }

    .panel-header h3 {
        font-size: 1.1em;
    }

    /* Collection controls compact */
    .collection-controls {
        padding: 6px;
    }

    #collection-search {
        font-size: 14px;
        padding: 8px 36px 8px 12px;
    }

    /* Filter rows stack */
    .filter-row {
        flex-direction: column;
        gap: 4px;
    }

    .filter-row select,
    .filter-row input {
        width: 100%;
        min-height: 40px;
        font-size: 14px;
    }

    .sort-and-view {
        flex-direction: column;
        gap: 8px;
    }

    .sort-and-view select {
        width: 100%;
        min-height: 40px;
    }

    /* Deck details stack */
    .deck-details-row {
        flex-direction: column;
        gap: 8px;
    }

    /* Touch-friendly card type filters */
    .quick-filters {
        flex-wrap: wrap;
    }

    .card-type-filter-btn {
        min-height: 40px;
        padding: 8px 12px;
        font-size: 13px;
    }

    /* Deck actions wrap */
    .deck-actions {
        gap: 4px;
    }

    .secondary-button {
        min-height: 40px;
        min-width: 44px;
        padding: 6px 10px;
        font-size: 0.8em;
    }

    /* Aether curve display smaller */
    #aether-curve-display {
        min-height: 60px;
        padding: 8px 6px 14px;
    }

    .aether-bar {
        min-width: 16px;
    }

    /* Deck overview compact */
    .deck-overview {
        grid-template-columns: 1fr 1fr;
        gap: 4px;
        padding: 4px;
    }

    /* Customization collapsed by default hint */
    .deck-customization input,
    .deck-customization textarea {
        font-size: 14px;
        padding: 8px;
    }
}

/* --- Phone portrait (max-width 480px) --- */
@media (max-width: 480px) {
    .deck-builder-layout {
        padding: 4px !important;
        gap: 6px !important;
    }

    .deck-builder-collection-panel .card-list,
    .deck-builder-deck-panel .card-list {
        max-height: 35vh !important;
        grid-template-columns: repeat(auto-fill, minmax(65px, 1fr));
        gap: 2px;
        padding: 2px;
    }

    /* Cards scale down */
    .deck-builder-collection-panel .card,
    .deck-builder-deck-panel .card {
        width: 65px;
        height: 91px;
        margin: 1px;
    }

    .panel-header h3 {
        font-size: 1em;
    }

    .collection-stats {
        font-size: 0.75em;
    }

    /* Deck count compact */
    .deck-count-text {
        font-size: 0.9em;
        padding: 4px 8px;
    }

    /* Search bar */
    #collection-search {
        font-size: 14px;
        padding: 8px 30px 8px 10px;
        border-radius: 18px;
    }

    /* Advanced filters */
    .advanced-filters {
        padding: 6px;
    }

    .filter-row select,
    .filter-row input {
        font-size: 14px;
        min-height: 44px;
    }

    /* Quick filter buttons */
    .quick-filter-btn {
        min-height: 44px;
        font-size: 13px;
    }

    .card-type-filter-btn {
        min-height: 44px;
        font-size: 12px;
    }
}


/* =================================================================
   5. COLLECTION SCREEN - card grid, sidebar, filters
   ================================================================= */

/* --- Tablet (max-width 1024px) --- */
@media (max-width: 1024px) {
    /* Already handled in enhanced-collection-view.css:
       layout goes column, sidebar goes full-width */

    /* Collection grid: 3 columns */
    .collection-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
        padding: 12px;
    }

    .collection-card {
        width: 140px;
        height: 196px;
    }

    /* Sidebar touch targets */
    .collection-sidebar {
        padding: 16px;
    }

    .search-input {
        font-size: 14px;
        min-height: 44px;
    }

    .search-clear-btn {
        width: 28px;
        height: 28px;
    }
}

/* --- Phone landscape (max-width 768px) --- */
@media (max-width: 768px) {
    .collection-layout {
        padding: 8px !important;
        gap: 8px !important;
    }

    .collection-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
        padding: 8px;
    }

    .collection-card {
        width: 120px;
        height: 168px;
    }

    /* Card set heading smaller */
    .card-set-heading {
        font-size: 1.2rem;
    }

    /* Filters compact */
    .collection-filters-row,
    .collection-display-options {
        padding: 12px;
        gap: 8px;
    }

    .filter-group,
    .display-group {
        min-width: 100%;
    }

    .filter-group label,
    .display-group label {
        font-size: 12px;
    }

    .filter-group select,
    .display-group select {
        min-height: 40px;
        font-size: 14px;
    }

    /* Collection sidebar compact */
    .collection-sidebar {
        padding: 12px;
        gap: 12px;
    }

    /* Card owned count readable */
    .card-owned-count {
        font-size: 0.8rem;
        padding: 2px 5px;
    }

    /* Quick filters scrollable */
    .collection-quick-filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .collection-quick-filters::-webkit-scrollbar {
        display: none;
    }
}

/* --- Phone portrait (max-width 480px) --- */
@media (max-width: 480px) {
    .collection-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        padding: 6px;
    }

    .collection-card {
        width: 100%;
        height: auto;
        aspect-ratio: 5 / 7;
    }

    .card-set-heading {
        font-size: 1rem;
        margin: 8px 0;
    }

    .card-set-group {
        margin-bottom: 12px;
        padding-bottom: 8px;
    }

    /* Card grid sizes forced to 2-col */
    .card-list.view-grid.grid-small,
    .card-list.view-grid.grid-medium,
    .card-list.view-grid.grid-large {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px;
    }

    /* Search bar */
    .search-input {
        padding: 12px 40px 12px 14px;
        font-size: 14px;
        border-radius: 10px;
    }

    /* Filters */
    .collection-filters-row,
    .collection-display-options {
        padding: 8px;
        gap: 6px;
    }

    .filter-group select,
    .display-group select {
        min-height: 44px;
        font-size: 14px;
    }

    /* Sidebar stat cards */
    .collection-sidebar {
        padding: 10px;
        gap: 10px;
    }

    /* Card detail popup / modal should be full-screen on phones */
    .card-detail-modal,
    .card-detail-popup {
        width: 95vw !important;
        max-width: 95vw !important;
        height: auto !important;
        max-height: 90vh !important;
        border-radius: 12px !important;
    }

    /* Ensure no text goes below 14px */
    .card-owned-count {
        font-size: 14px;
    }
}


/* =================================================================
   6. GENERAL TOUCH & ACCESSIBILITY IMPROVEMENTS
   ================================================================= */

/* All interactive elements get minimum touch target on mobile */
@media (max-width: 768px) {
    button,
    [role="button"],
    .nav-btn,
    .shop-nav-btn,
    .buy-button,
    .quick-buy-button,
    .view-button,
    .secondary-button,
    .card-type-filter-btn,
    .quick-filter-btn,
    .clear-filters-btn,
    .clear-btn,
    .filter-toggle-btn,
    .carousel-nav,
    .header-icon-btn,
    .home-btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Prevent double-tap zoom on interactive elements */
    button,
    [role="button"],
    a,
    select,
    input {
        touch-action: manipulation;
    }

    /* Smoother scrolling everywhere */
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent text selection on game elements */
    .card,
    .field-zone,
    .nav-btn,
    .shop-item {
        -webkit-user-select: none;
        user-select: none;
    }

    /* Ensure minimum readable font size */
    body {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
}

/* =================================================================
   7. MODAL & OVERLAY MOBILE OVERRIDES
   ================================================================= */

@media (max-width: 768px) {
    /* Generic modals fill most of the screen */
    .modal,
    .modal-overlay .modal-content,
    .popup-modal,
    .overlay-panel {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 90vh !important;
        margin: auto !important;
        border-radius: 12px !important;
        overflow-y: auto !important;
    }

    /* Confirmation dialogs */
    .confirm-dialog,
    .confirmation-modal {
        width: 90vw !important;
        max-width: 400px !important;
        padding: 20px !important;
    }

    .confirm-btn,
    .cancel-btn {
        min-height: 44px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .modal,
    .modal-overlay .modal-content,
    .popup-modal {
        width: 100vw !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
}

/* =================================================================
   8. AUTH / LOGIN SCREEN MOBILE
   ================================================================= */

@media (max-width: 768px) {
    .auth-container,
    .login-container,
    .password-protection-container {
        width: 90vw !important;
        max-width: 400px;
        padding: 24px 20px;
    }

    .auth-container input,
    .login-container input,
    .password-protection-container input {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 10px 14px;
    }

    .auth-container button,
    .login-container button,
    .password-protection-container button {
        min-height: 48px;
        font-size: 16px;
    }
}


/* =================================================================
   9. SAFE AREA INSETS (notch/home indicator)
   ================================================================= */

@supports (padding: env(safe-area-inset-top)) {
    @media (max-width: 768px) {
        .premium-header {
            padding-top: env(safe-area-inset-top);
        }

        #player-hand {
            padding-bottom: calc(8px + env(safe-area-inset-bottom)) !important;
        }

        body {
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
        }
    }
}
