/* Hide mobile UI elements on large desktop screens */
.mobile-menu-btn,
.sidebar-overlay,
.close-sidebar-btn {
    display: none;
}

/* Tablet & Mobile Breakpoint */
@media (max-width: 1024px) {
    body {
        overflow-y: auto;
        overflow-x: hidden;
    }

    .app-shell {
        padding: 0;
        display: block;
        min-height: 100vh;
        height: auto;
        overflow: hidden; /* Prevent horizontal scrolling */
    }

    /* Floating Action Button (FAB) */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        top: 20px;
        left: 20px;
        z-index: 100;
        background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
        color: white;
        border: none;
        padding: 10px 18px;
        border-radius: 999px;
        font-weight: 700;
        font-size: 14px;
        box-shadow: 0 4px 15px rgba(139, 124, 246, 0.4);
        cursor: pointer;
        transition: transform 0.2s ease;
    }

    .mobile-menu-btn:active {
        transform: scale(0.95);
    }

    /* Sidebar Dark Overlay */
    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(10, 15, 25, 0.6);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 140;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .sidebar-overlay.show {
        opacity: 1;
        visibility: visible;
    }

    /* Sidebar Off-canvas Animation */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85vw;
        max-width: 380px;
        z-index: 150;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        border-radius: 0 24px 24px 0;
        margin: 0;
        padding: 24px 20px;
        border-left: none;
        box-shadow: 20px 0 40px rgba(0, 0, 0, 0.4);
    }

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

    .close-sidebar-btn {
        display: flex;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.1);
        color: #e7edf7;
        width: 34px;
        height: 34px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        cursor: pointer;
        flex-shrink: 0;
    }

    /* Main Content Layout Engine Overrides */
    .main-content {
        border-radius: 0;
        min-height: 100vh;
        padding: 80px 16px 120px 16px; /* Top space for FAB, Bottom space for controls */
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        border: none;
        background: transparent;
        box-shadow: none;
    }

    .demo-progress-wrapper {
        position: relative;
        top: 0;
        left: 0;
        transform: none;
        width: 100%;
        margin-bottom: 24px;
        z-index: 10;
    }

    .canvas {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 24px;
        perspective: none;
    }

    /* Transcript (Nexus) drops naturally in flow */
    /* Transcript (Nexus) drops naturally in flow */
    .nexus-container {
        width: 100%;
        order: 1; /* Keep transcript at the top */
    }

    .subtitles-shell {
        width: 100%;
        padding: 16px;
    }

    /* NEW: Expand transcript area and shrink font to fit wrapped intro text on mobile */
    .subtitles {
        min-height: 260px;
        max-height: 260px;
        /* Reduce the top/bottom fade so text doesn't get hidden as easily */
        mask-image: linear-gradient(to bottom, transparent 0%, black 5%, black 95%, transparent 100%);
        -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 5%, black 95%, transparent 100%);
    }

    .subtitles .log-entry[data-role="system"]:not(.system) {
        font-size: 15px !important;
        line-height: 1.5 !important;
    }

    /* Data Cards Grid (replaces absolute positioning) */

    /* Data Cards Grid (replaces absolute positioning) */
    .cards-container {
        position: relative;
        inset: auto;
        pointer-events: auto;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        width: 100%;
        order: 2; /* Drops cards below the transcript */
    }

    .data-card {
        position: relative;
        width: 100%;
        min-height: 110px;
        padding: 14px;
        /* Strip absolute positioning hooks */
        top: auto !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        transform: translateY(4px) scale(0.98);
    }

    .data-card.active {
        transform: translateY(0) scale(1);
    }

    .card-header {
        margin-bottom: 8px;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .card-title { font-size: 10px; }
    .card-content { font-size: 13px; }
    .placeholder-name { font-size: 14px; }

    /* Outcomes Grid Override */
    .subtitles-shell.outcomes-mode .subtitles {
        max-height: none;
    }

    .outcomes-grid {
        grid-template-columns: 1fr; /* Force 1 column on mobile */
        gap: 10px;
    }

    .outcome-item[style*="grid-column"] {
        grid-column: span 1 !important; /* Disables span 2 inline styling */
    }

    /* Bottom Fixed Controls */
    .controls {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 32px);
        max-width: 400px;
        display: flex;
        justify-content: space-between;
        padding: 8px;
        background: rgba(20, 30, 45, 0.85);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border: 1px solid rgba(148, 163, 184, 0.2);
        box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.4);
        z-index: 120;
    }

    .controls .btn {
        flex: 1;
        padding: 14px;
    }
}

/* Extra small screens (Small Phones) */
@media (max-width: 480px) {
    .cards-container {
        grid-template-columns: 1fr; /* Snaps cards to 1 column */
    }

    .card-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}