/* ─── Responsive Design ─── */

/* ─── Workspace Toggle: tray controls (mobile-only) ─── */
#tray-controls { display: none; }

/* Utility class: show only on mobile */
.mobile-only { display: none !important; }

/* ═══ Tablet (769px - 1024px) ═══ */
@media (max-width: 1024px) {
    #app {
        grid-template-columns: var(--toolbar-width) 1fr 200px;
    }
    #panel {
        width: 200px;
    }
}

/* ═══ Mobile (≤768px): Distraction-free, canvas-centric overlay layout ═══ */
@media (max-width: 768px) {
    .mobile-only { display: inline-flex !important; }
    .desktop-only { display: none !important; }

    /* ─── App container: revert to block; all panels are fixed overlays ─── */
    #app {
        display: block;
        position: relative;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    /* ─── Tool Settings Bar: hidden on mobile ─── */
    #tool-settings-bar {
        display: none !important;
    }

    /* ═══ CANVAS HERO LAYER ═══
     * Workspace fills the full viewport by default, then smoothly shrinks
     * via CSS transitions when overlay panels open — no canvas clipping.
     * bottom: 36px always reserves space for the timeline peek tab.
     ════════════════════════════════════════════════════════════════════ */
    #workspace {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 36px; /* reserve room for the timeline drag-handle peek */
        z-index: 1;
        overflow: hidden;
        background: var(--bg-canvas);
        transition: top    0.3s  cubic-bezier(0.4, 0, 0.2, 1),
                    bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }
    /* Canvas shrinks down when topbar opens so nothing is hidden behind it */
    #workspace.topbar-active {
        top: var(--topbar-height);
    }
    /* Canvas shrinks up when timeline is fully open (matches timeline max-height) */
    #workspace.timeline-active {
        bottom: min(55vh, 280px);
    }

    /* ═══ TOPBAR DRAWER ═══
     * Collapsed by default (slid fully above viewport).
     * The #topbar-peek pill tab is always visible at top-centre.
     ════════════════════════════════════════════════════════════════════ */
    #topbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--topbar-height);
        z-index: 300;
        display: flex;
        align-items: center;
        padding: 0 12px;
        gap: 6px;
        background: rgba(22, 33, 62, 0.97);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
        /* hidden above viewport by default */
        transform: translateY(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    #topbar.open {
        transform: translateY(0);
    }
    #topbar .spacer { flex: 1; }
    #topbar .logo   { font-size: 11px; letter-spacing: 1.5px; }
    #topbar .menu-group { gap: 4px; }
    #topbar .btn.sm {
        min-height: 32px;
        padding: 4px 10px;
        font-size: 11px;
    }

    /* ─── Topbar peek pill: always visible at top-centre ─── */
    #topbar-peek {
        position: fixed;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        z-index: 310;           /* sits above topbar */
        width: 56px;
        height: 24px;
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: rgba(22, 33, 62, 0.82);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-radius: 0 0 12px 12px;
        border: 1px solid rgba(58, 58, 90, 0.6);
        border-top: none;
        color: var(--text-secondary);
        cursor: pointer;
        /* follows the topbar down when it opens */
        transition: top var(--transition-normal), background var(--transition-fast);
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
    }
    #topbar-peek.topbar-open {
        top: var(--topbar-height);
    }
    #topbar-peek:active {
        background: rgba(42, 42, 74, 0.95);
    }
    .topbar-peek-chevron {
        transition: transform 0.3s ease;
    }
    #topbar-peek.topbar-open .topbar-peek-chevron {
        transform: rotate(180deg);
    }

    /* ═══ TOOLBAR FLOATING PILL ═══
     * Converted from a horizontal bottom bar to a compact floating sidebar
     * docked to the left edge, vertically centred — always accessible.
     ════════════════════════════════════════════════════════════════════ */
    #toolbar {
        position: fixed;
        left: 8px;
        top: 50%;
        transform: translateY(-50%);
        width: 44px;
        height: auto;
        max-height: 80vh;
        flex-direction: column;
        align-items: center;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 8px 0;
        gap: 2px;
        background: rgba(22, 33, 62, 0.88);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border: 1px solid rgba(58, 58, 90, 0.65);
        border-radius: 12px;
        box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
        z-index: 150;
        scrollbar-width: none;
        -ms-overflow-style: none;
        /* re-enable flex since main.css uses display:flex */
        display: flex !important;
    }
    #toolbar::-webkit-scrollbar { display: none; }
    #toolbar .tool-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        flex-shrink: 0;
        border-radius: 8px;
    }
    #toolbar .tool-divider {
        width: 24px;
        height: 1px;
        min-height: 1px;
        min-width: unset;
        background: var(--border);
        margin: 2px 0;
    }

    /* ═══ RIGHT PANEL — bottom sheet (existing behaviour, kept) ═══ */
    #panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 70vh;
        z-index: 260;
        background: var(--bg-panel);
        border-top: 2px solid var(--border);
        border-radius: 12px 12px 0 0;
        box-shadow: var(--shadow-lg);
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    #panel.open {
        transform: translateY(0);
    }
    .panel-drag-handle {
        display: block !important;
        width: 40px;
        height: 4px;
        background: var(--border-light);
        border-radius: 2px;
        margin: 8px auto 4px;
    }

    /* ═══ TIMELINE BOTTOM-SHEET DRAWER ═══
     * Collapsed by default: translateY(calc(100% − 36px)) so the drag-handle
     * peeks 36 px above the viewport bottom.
     * On .open it slides fully into view (translateY(0)).
     ════════════════════════════════════════════════════════════════════ */
    #timeline {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 200;
        max-height: min(55vh, 280px);
        height: auto;
        display: flex;
        flex-direction: column;
        background: rgba(22, 33, 62, 0.97);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--border);
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
        /* collapsed: show only the 36px drag handle */
        transform: translateY(calc(100% - 36px));
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
    }
    #timeline.open {
        transform: translateY(0);
        overflow-y: auto;
    }

    /* ─── Timeline drag handle: the 36px peek tab ─── */
    #timeline-drag-handle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        gap: 8px;
        height: 36px;
        min-height: 36px;
        flex-shrink: 0;
        padding: 0 16px;
        cursor: pointer;
        color: var(--text-secondary);
        border-bottom: 1px solid transparent;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
        transition: color var(--transition-fast),
                    border-color var(--transition-fast);
    }
    #timeline-drag-handle:active { color: var(--text-primary); }
    #timeline.open #timeline-drag-handle {
        border-bottom-color: var(--border);
        color: var(--accent);
    }
    .timeline-drag-bar {
        width: 32px;
        height: 3px;
        background: var(--border-light);
        border-radius: 2px;
        flex-shrink: 0;
    }
    .timeline-handle-label {
        font-size: 11px;
        font-weight: 500;
        font-family: var(--font-sans);
        letter-spacing: 0.5px;
        text-transform: uppercase;
    }
    .timeline-handle-chevron {
        flex-shrink: 0;
        transition: transform 0.3s ease;
        /* default: points UP → "tap to expand" */
    }
    #timeline.open .timeline-handle-chevron {
        transform: rotate(180deg); /* points DOWN → "tap to collapse" */
    }

    /* ─── Timeline playback controls (inside open timeline) ─── */
    #timeline-controls {
        flex-wrap: wrap;
        height: auto;
        min-height: 36px;
        padding: 4px 8px;
        gap: 4px;
        flex-shrink: 0;
    }
    #timeline-controls .onion-controls,
    #timeline-controls .fps-control {
        display: none;
    }
    #timeline-controls .icon-btn {
        min-width: 36px;
        min-height: 36px;
    }

    /* ─── Tray toggle bar ─── */
    #tray-controls {
        display: flex;
        align-items: stretch;
        flex-shrink: 0;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
    }
    .tray-toggle-btn {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 0 10px;
        min-height: 44px;
        border: none;
        background: transparent;
        color: var(--text-secondary);
        font-family: var(--font-sans);
        font-size: 12px;
        font-weight: 500;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: background var(--transition-fast), color var(--transition-fast);
    }
    .tray-toggle-btn:active  { background: var(--bg-panel-hover); }
    .tray-toggle-btn.tray-open { color: var(--accent); }
    .tray-toggle-icon    { flex-shrink: 0; }
    .tray-toggle-label   { flex: 1; text-align: left; }
    .tray-toggle-chevron {
        flex-shrink: 0;
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .tray-toggle-btn.tray-open .tray-toggle-chevron { transform: rotate(180deg); }
    .tray-divider {
        width: 1px;
        flex-shrink: 0;
        background: var(--border);
        align-self: stretch;
    }

    /* ─── Collapsible trays: collapsed by default ─── */
    #frame-strip,
    #audio-track {
        flex: 0 0 auto;
        max-height: 0;
        overflow: hidden;
        opacity: 0;
        transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity    0.25s ease;
    }
    #frame-strip.tray-open {
        max-height: 84px;
        opacity: 1;
        padding: 4px 8px;
        gap: 6px;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }
    #audio-track.tray-open {
        max-height: 80px;
        opacity: 1;
    }

    /* ─── Frame thumbs ─── */
    .frame-thumb {
        width: 80px;
        min-width: 80px;
        height: 64px;
        scroll-snap-align: center;
    }
    .frame-thumb canvas { width: 100%; height: auto; }
    .frame-connector    { width: 16px; font-size: 12px; }

    /* ─── File menu modal (mobile-only) ─── */
    .file-menu-modal {
        min-width: unset !important;
        width: calc(100vw - 48px) !important;
        max-width: 320px !important;
    }
    .file-menu-item {
        display: flex;
        align-items: center;
        gap: 14px;
        width: 100%;
        padding: 14px 20px;
        background: none;
        border: none;
        border-bottom: 1px solid var(--border);
        color: var(--text-primary);
        font-family: var(--font-sans);
        font-size: 15px;
        font-weight: 500;
        text-align: left;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: background var(--transition-fast);
    }
    .file-menu-item:last-child { border-bottom: none; }
    .file-menu-item:active { background: var(--bg-panel-hover); }
    .file-menu-item svg { flex-shrink: 0; color: var(--accent); }

    .modal-overlay .modal {
        min-width: unset !important;
        width: calc(100vw - 32px);
        max-width: 400px;
        max-height: 80vh;
        overflow-y: auto;
    }

    /* ─── Context menus ─── */
    .context-menu { min-width: 160px; }
    .context-menu div { min-height: 36px; padding: 8px 12px; }
}

/* ═══ Small mobile (≤480px) ═══ */
@media (max-width: 480px) {
    #topbar .logo {
        display: none;
    }
    #topbar .menu-group {
        flex: 1;
        justify-content: center;
    }
}
