/* =====================================================
   RESPONSIVE LAYOUT (Mobile Portrait ≤ 768px)
   Author: Antigravity
   Description: Mobile-first adaptations for DDDungeon
   ===================================================== */

@media (max-width: 768px) {

/* === Header Height Variable Fix === */
/* Mobile header is 50px; update variable so calc() rules in main.css work correctly */
:root {
    --header-height: 50px;
}

/* === Global Layout Fixes === */
body {
        overflow-x: hidden;
        /* Prevent horizontal scroll */
        /* padding-bottom: 60px; removed for mobile scroll fix */
        /* Safe area for bottom nav */
    }

    .app-content {
        padding: var(--space-unit);
        /* Remove margin-bottom since footer is hidden, or adapt it */
        margin-top: 0; /* handled by app-container */
        height: 100%;
        /* padding-bottom: 60px; removed for mobile scroll fix */
    }

/* === Compact Header === */
/* height removed - now uses var(--header-height) from main.css */
.app-header {
padding: 0 var(--space-unit);
        justify-content: space-between;
        flex-direction: row;
        /* Force row direction even on small screens */
        flex-wrap: nowrap;
        /* No wrapping */
        background-color: var(--clr-surface);
        z-index: 101;
        /* Above content */
    }



    .app-header .user-stats {
        gap: var(--space-unit);
        font-size: 0.9rem;
    }

    /* Hard-enforce only 2 currency tiers on mobile to prevent overflow */
    #money-display .value .currency-tier:nth-child(n+3) {
        display: none;
    }

    .app-header .stat-item .icon {
        width: 16px;
        height: 16px;
    }

#mobile-menu-toggle {
display: block;
}

/* #app-container removed - main.css uses var(--header-height) with 100dvh, which is correct for mobile */

#sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 80%;
        max-width: 200px;
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: var(--clr-overlay);
        z-index: 999;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    #sidebar-overlay.visible {
        display: block;
        opacity: 1;
    }

    /* === Show Scrollable Footer === */
    .app-footer {
        display: flex;
        /* Now scrollable, so it can be visible at the bottom */
    }

    /* === Tab Content Stacking === */
    .tab-content {
        display: none;
        /* Base state */
        flex-direction: column;
        /* Stack children vertically */
        gap: var(--space-unit);
    }

    .tab-content.active {
        display: flex;
        /* Use flex for active content */
    }

    /* Grid containers should become single column */
    .grid-container,
    .dungeon-container,
    .party-container,
    .tavern-container,
    .armory-container {
        display: flex;
        flex-direction: column;
        grid-template-columns: 1fr;
        /* Force single column if grid is used */
        gap: var(--space-unit);
        margin-top: var(--space-unit);
        width: 100%;
    }

    /* === Specific Tab Adjustments === */

    /* Dungeon Tab Adjustments */
    .dungeon-view .dungeon-container {
        display: flex;
        flex-direction: column;
    }

  /* Mobile combatant card - fills slot width */
  .dungeon-view .hero-tile {
    width: 100%;
    height: auto;
  }

  .dungeon-view .combatant {
    font-size: 0.7rem;
    padding: 0;
  }

  /* Scale down effects for mobile */
  .dungeon-view .combatant .effects-row {
    top: 2px;
    left: 2px;
    right: 2px;
    gap: 2px;
  }

  .dungeon-view .combatant .effect-badge {
    width: 12px;
    height: 12px;
    font-size: 8px;
    border-width: 1px;
  }

  .dungeon-view .combatant .effect-duration {
    width: 10px;
    height: 10px;
    font-size: 7px;
  }

    .dungeon-viz {
        min-height: 200px;
        order: 1;
    }


    /* Armory Tab - Moved to armory.css as Phase 5 Component 5 */

    
    /* System Tab */
    /* Component 2 of Phase 5 moved to system.css */

    /* === General Touch Targets === */

    /* Card Padding reduction */

    /* === V2 Scaling Overrides === */
    /* When ScalingManager is active, we disable the vertical reflow for the combat arena */
    .dungeon-view .dungeon-stage {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        min-height: 250px;
        /* Lock font-size to prevent double-scaling from rem zoom */
        font-size: 16px;
        padding-top: 0;
    }

    .dungeon-view .dungeon-header {
        padding: 0.25rem 0.5rem;
        margin-bottom: 0.25rem;
    }

    /* Dashboard adjustments */
    .combat-dashboard {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .dashboard-left {
        display: flex;
        gap: 0.25rem;
        font-size: 0.85rem;
    }

    .combat-pulse-group {
        padding: 2px 4px;
        gap: 0.2rem;
    }

    .pulse-icon {
        font-size: 1rem;
    }

    .tactical-briefing {
        left: auto;
        right: 0;
        width: calc(100vw - 20px);
        max-width: 320px;
    }

    .gear-btn {
        font-size: 1.5rem;
    }

    /* Side drawer mobile width */
    .dungeon-settings-menu {
        width: 50%;
        min-width: 280px; /* Ensure it's usable on very small screens */
    }

    .dungeon-view .exploration-view {
        padding: 0.5rem;
    }

    .dungeon-view .side-container {
        /* flex-direction: row; */
        width: auto;
        gap: 0;
    }

    .dungeon-view .combat-column {
        display: flex;
        flex-direction: column;
        /* min-width: 90px; */
    }

    .dungeon-view .combatant {
        /* width: 90px; */
        font-size: 1rem;
    }

    /* =====================================================
       MOBILE VERTICAL STACK EXPERIMENT (Combat UI)
       ===================================================== */
       
    .dungeon-view .combat-layout {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

.dungeon-view .speed-rail-container {
    width: 100%;
    height: auto; /* Allow it to grow for portraits */
    min-height: 24px; /* Minimum for dots */
    overflow-x: auto;
    overflow-y: visible;
    padding: 0.25rem 0.5rem;
    border-right: none;
    border-bottom: 2px solid var(--clr-border);
    order: 2;
    background: var(--clr-surface-dark);
    display: flex;
    align-items: center;
}

.dungeon-view .speed-rail-container.collapsed {
    height: 24px;
    min-height: 24px;
}

.dungeon-view .speed-rail-list {
    margin: 0; /* Remove the 20px top margin from dungeon.css */
    display: flex;
    align-items: center;
    gap: 4px;
}

    
    .dungeon-view .speed-rail-container.collapsed {
        min-height: 24px;
        height: 24px;
        width: 100%;
    }

    .dungeon-view .speed-rail-list {
        display: flex;
        flex-direction: row;
        gap: 0.5rem;
        width: max-content;
        height: 100%;
        align-items: center;
    }

.dungeon-view .speed-rail-item {
    margin: 0;
    flex-shrink: 0;
    min-height: 44px;
}

    .dungeon-view .combat-main-content {
        order: 1;
        width: 100%;
        padding: 0.5rem 0;
    }



    /* Adjust vs-indicator for the stack */
    .dungeon-view .vs-indicator {
        margin: 0.5rem 0;
        transform: rotate(0deg); /* Keep it vertical visually */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Action Banner Center Ribbon */
    .dungeon-view .skill-banner-container {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 100%;
        max-width: 100%;
    }

/* Combat Log Slide-Up Overlay */
.dungeon-view .combat-log {
    position: fixed;
    bottom: var(--safe-bottom);
    left: 0;
    right: 0;
    width: 100vw;
    box-sizing: border-box;
    /* Progressive enhancement: vh fallback then dvh */
    height: calc(100vh - 120px);
    height: calc(100dvh - 120px);
    /* Only set max-height on expanded state */
    margin: 0;
    z-index: 3000;
    background: var(--clr-surface-dark);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    border-radius: 16px 16px 0 0;
    border: 1px solid var(--clr-border);
    border-bottom: none;
    order: 99;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Performance optimization - NOT strict (would break child scrolling) */
    contain: layout paint;
}

.dungeon-view .combat-log.expanded {
    transform: translateY(0);
    /* Cap the expanded height with progressive enhancement */
    height: min(60vh, 500px);
    height: min(60dvh, 500px);
    max-height: min(60vh, 500px);
    max-height: min(60dvh, 500px);
    /* Floor to prevent collapse on very small viewports */
    min-height: 200px;
}

.dungeon-view .combat-log.hidden {
    display: flex; /* Override display: none from desktop */
    transform: translateY(100%);
    visibility: hidden; /* Prevent scroll contribution */
    pointer-events: none; /* Prevent interaction when hidden */
}

/* Add visual affordance for mobile close gesture */
.dungeon-view .combat-log .log-grabber {
    display: block;
    width: 40px;
    min-height: 12px;
    background: var(--clr-text-dim);
    border-radius: 2px;
    margin: 8px auto;
    opacity: 0.5;
    flex-shrink: 0;
    touch-action: none;
}

/* Ensure log header stays visible */
.dungeon-view .combat-log .log-header {
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

/* Make log entries scrollable */
.dungeon-view .combat-log .log-entries {
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* Required for flex scrolling */
}
    

    
    /* End Mobile Vertical Stack Experiment */

    /* Typography Adjustments */
    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    h3 {
        font-size: 1.1rem;
    }

    /* === VS-Centered Dual Row Layout Mobile Overrides === */
    .combat-stat-headers {
        display: none;
    }
}
