/* =========================================================
   Tutorial Studio · Responsive
   响应式布局
========================================================= */


/* =========================================================
   中小屏幕
========================================================= */

@media (max-width: 1150px) {

    .workspace {
        grid-template-columns:
            190px
            minmax(460px, 1fr)
            350px;
    }

    .menu-bar {
        display: none;
    }

}


/* =========================================================
   手机与窄屏设备
========================================================= */

@media (max-width: 900px) {

    /*
     * 编辑器改为单列。
     */
    .workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    /*
     * 手机上隐藏左右侧栏。
     *
     * AI 助手会在需要时被移动到独立弹窗中。
     */
    .sidebar,
    .inspector {
        display: none;
    }

    /*
     * 避免工作区超出屏幕。
     */
    .workspace,
    .center-column,
    .stage-panel {
        min-width: 0;
        max-width: 100%;
    }

    /*
     * 手机端浮动 AI 按钮。
     */
    .mobile-ai-launcher {
        position: fixed;

        right: 18px;
        bottom: calc(22px + env(safe-area-inset-bottom, 0px));

        z-index: 10000;

        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;

        min-width: 112px;
        min-height: 48px;

        padding: 0 18px;

        border: none;
        border-radius: 999px;

        color: #ffffff;
        background: linear-gradient(
            135deg,
            #5667e8,
            #7556d9
        );

        box-shadow:
            0 8px 24px rgba(86, 103, 232, 0.3);

        font-size: 15px;
        font-weight: 650;

        cursor: pointer;

        -webkit-tap-highlight-color: transparent;

        transition:
            transform 0.18s ease,
            box-shadow 0.18s ease;
    }

    .mobile-ai-launcher:active {
        transform: scale(0.96);
    }

    .mobile-ai-launcher:focus-visible {
        outline: 3px solid rgba(86, 103, 232, 0.35);
        outline-offset: 3px;
    }

    .mobile-ai-launcher[hidden] {
        display: none !important;
    }

    .mobile-ai-launcher-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;

        width: 23px;
        height: 23px;

        border-radius: 50%;

        background: rgba(255, 255, 255, 0.18);

        font-size: 19px;
        line-height: 1;
    }

    .mobile-ai-launcher-text {
        white-space: nowrap;
    }


    /* =====================================================
       AI 助手弹窗遮罩
    ===================================================== */

    .mobile-ai-overlay {
        position: fixed;
        inset: 0;

        z-index: 10001;

        display: flex;
        align-items: flex-end;
        justify-content: center;

        padding: 0;

        background: rgba(15, 23, 42, 0.48);

        opacity: 0;
        visibility: hidden;
        pointer-events: none;

        transition:
            opacity 0.22s ease,
            visibility 0.22s ease;

        overscroll-behavior: contain;
    }

    .mobile-ai-overlay.is-open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }


    /* =====================================================
       AI 助手聊天窗口
    ===================================================== */

    .mobile-ai-sheet {
        display: flex;
        flex-direction: column;

        width: 100%;
        height: 88vh;
        height: 88dvh;

        max-height: 900px;
        min-height: 0;

        overflow: hidden;

        background: #ffffff;

        border-radius: 22px 22px 0 0;

        box-shadow:
            0 -10px 40px rgba(15, 23, 42, 0.16);

        transform: translateY(28px);

        transition: transform 0.22s ease;
    }

    .mobile-ai-overlay.is-open .mobile-ai-sheet {
        transform: translateY(0);
    }


    /* =====================================================
       弹窗顶部标题栏
    ===================================================== */

    .mobile-ai-header {
        position: relative;

        display: flex;
        align-items: center;
        justify-content: space-between;

        flex-shrink: 0;

        min-height: 58px;

        padding:
            8px
            16px
            8px;

        background: #ffffff;

        border-bottom: 1px solid #e6eaf0;
    }

    .mobile-ai-header-title {
        display: flex;
        align-items: center;
        gap: 9px;

        color: #172033;

        font-size: 16px;
        font-weight: 700;
    }

    .mobile-ai-header-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;

        width: 32px;
        height: 32px;

        color: #ffffff;

        border-radius: 10px;

        background: linear-gradient(
            135deg,
            #5667e8,
            #7556d9
        );

        font-size: 19px;
    }

    .mobile-ai-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;

        width: 42px;
        height: 42px;

        padding: 0;

        border: none;
        border-radius: 50%;

        color: #475467;
        background: #f2f4f7;

        font-size: 28px;
        line-height: 1;

        cursor: pointer;

        -webkit-tap-highlight-color: transparent;
    }

    .mobile-ai-close:active {
        background: #e4e7ec;
    }


    /* =====================================================
       AI 面板容器
    ===================================================== */

    .mobile-ai-panel-host {
        display: flex;
        flex: 1;
        flex-direction: column;

        min-width: 0;
        min-height: 0;

        overflow: hidden;
    }

    /*
     * 由 JavaScript 移动进来的原始 #aiPanel。
     */
    #mobileAiSheet .ai-panel {
        display: flex;
        flex: 1;
        flex-direction: column;

        width: 100%;
        max-width: none;
        min-width: 0;

        height: 100%;
        max-height: none;
        min-height: 0;

        margin: 0;
        padding: 0;

        overflow: hidden;

        border: none;
        border-radius: 0;

        box-shadow: none;

        background: #ffffff;
    }

    /*
     * 原面板的标题已经在弹窗顶部显示，
     * 隐藏重复标题栏。
     */
    #mobileAiSheet .ai-panel-head {
        display: none;
    }

    /*
     * 展开聊天内容。
     */
    #mobileAiSheet .ai-panel-body {
        display: flex;

        flex: 1;
        flex-direction: column;

        width: 100%;
        min-width: 0;
        min-height: 0;

        overflow: hidden;
    }

    /*
     * 消息列表。
     */
    #mobileAiSheet .ai-messages {
        flex: 1;

        min-height: 100px;
        max-height: none;

        overflow-x: hidden;
        overflow-y: auto;

        overscroll-behavior: contain;

        -webkit-overflow-scrolling: touch;
    }

    /*
     * 输入框。
     */
    #mobileAiSheet .ai-input-wrap {
        flex-shrink: 0;

        padding: 12px 14px;

        background: #ffffff;

        border-top: 1px solid #e6eaf0;
    }

    #mobileAiSheet .ai-input {
        width: 100%;
        min-height: 76px;

        font-size: 16px;
        line-height: 1.6;
    }

    #mobileAiSheet .ai-send-btn {
        min-height: 42px;
        min-width: 64px;

        padding: 0 18px;
    }

    #mobileAiSheet .ai-message-content {
        overflow-wrap: anywhere;
        word-break: break-word;

        line-height: 1.7;
    }

    /*
     * 手机上强制显示消息区。
     */
    #mobileAiSheet .ai-panel.collapsed .ai-panel-body {
        display: flex;
    }

}


/* =========================================================
   矮屏手机或横屏设备
========================================================= */

@media (max-width: 900px) and (max-height: 560px) {

    .mobile-ai-sheet {
        height: 96vh;
        height: 96dvh;

        border-radius: 14px 14px 0 0;
    }

    .mobile-ai-header {
        min-height: 48px;

        padding: 4px 12px;
    }

    .mobile-ai-header-icon {
        width: 28px;
        height: 28px;
    }

    .mobile-ai-close {
        width: 36px;
        height: 36px;
    }

    #mobileAiSheet .ai-input-wrap {
        padding: 7px 10px;
    }

    #mobileAiSheet .ai-input {
        min-height: 52px;
    }

}