/* =========================================================
   Tutorial Studio
   编辑画布与视口样式

   文件：stage.css

   主要功能：
   1. 中间编辑区域布局
   2. 编辑画布面板
   3. 编辑区顶部工具栏
   4. 画布视口区域
   5. 画布外框
   6. Preview iframe
   7. 元素选中框
   8. 八方向缩放控制点
   9. 旋转控制点
   10. 底部状态栏
   11. 画布缩放工具栏

   说明：
   画布的设计尺寸、缩放比例和位置由
   ViewportController 统一管理。
========================================================= */


/* =========================================================
   一、中间编辑区域
========================================================= */

.center-column {
    position: relative;
    min-width: 0;
    min-height: 0;
    width: 100%;

    /* 不再限制为浏览器可视高度 */
    height: auto;
    min-height: calc(100vh - 160px);

    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    gap: 10px;
    align-self: start;

    overflow: visible;
}

/* =========================================================
   二、编辑画布面板
========================================================= */

.stage-panel {
    position: relative;
    min-width: 0;
    width: 100%;

    /* 允许面板根据内容增高 */
    height: auto;
    min-height: 0;
    flex: 0 0 auto;

    display: flex;
    flex-direction: column;

    overflow: visible;
}

/* =========================================================
   三、编辑区顶部工具栏
========================================================= */

.stage-toolbar {
    position: relative;

    width: 100%;
    height: 54px;
    min-height: 54px;

    flex: 0 0 54px;

    background: #ffffff;

    border-bottom: 1px solid var(--line);

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

    padding: 0 17px;

    box-sizing: border-box;

    font-size: 12px;

    z-index: 30;
}


/* 工具栏辅助文字 */

.muted {
    color: #9ba4b2;

    font-weight: 400;
}


/* 工具栏操作区域 */

.stage-actions {
    display: flex;

    align-items: center;

    gap: 7px;

    min-width: 0;
}


/* 普通工具栏按钮 */

.icon-btn {
    width: 29px;
    height: 29px;

    flex: 0 0 auto;

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

    padding: 0;

    border: 1px solid var(--line);

    background: #ffffff;

    border-radius: 7px;

    cursor: pointer;

    font-size: 19px;

    color: #344054;

    box-sizing: border-box;

    transition:
        background-color 0.15s ease,
        border-color 0.15s ease;
}


.icon-btn:hover {
    background: #f3f5f9;

    border-color: #c5cddd;
}


/* =========================================================
   四、编辑画布区域
========================================================= */

.stage-wrap {
    position: relative;
    min-width: 0;
    width: 100%;

    /* 给画布更大的显示空间 */
    height: 500px;
    min-height: 500px;
    flex: 0 0 500px;

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

    padding: 8px;
    box-sizing: border-box;

    overflow: hidden;
}

/* =========================================================
   五、编辑画布外框
========================================================= */

/*
 * 注意：
 *
 * 画布实际尺寸由 ViewportController 设置。
 *
 * 例如：
 *
 * 1280 × 720
 * 750 × 1950
 * 1080 × 1920
 *
 * 不再使用固定的 16:9 比例限制。
 */

.stage-frame {
    position: absolute;

    left: 0;
    top: 0;

    /*
     * 初始设计尺寸。
     * 初始化视口控制器后会更新。
     */
    width: 1280px;
    height: 720px;

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

    max-width: none;
    max-height: none;

    /*
     * 实际显示尺寸由视口控制器负责。
     */
    aspect-ratio: auto;

    flex: none;

    margin: 0;
    padding: 0;

    border: 0;

    box-sizing: border-box;

    transform: none;

    transform-origin: top left;

    /*
     * 不在这里设置 overflow: hidden，
     * 避免干扰选中框和控制点的显示。
     */
}


/* =========================================================
   六、Preview iframe
========================================================= */

.stage-frame iframe {
    position: absolute;

    left: 0;
    top: 0;

    /*
     * 默认设计尺寸。
     * preview.js 和 ViewportController 会同步更新。
     */
    width: 1280px;
    height: 720px;

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

    max-width: none;
    max-height: none;

    display: block;

    margin: 0;
    padding: 0;

    border: 0;

    background: #ffffff;

    border-radius: 5px;

    box-sizing: border-box;

    /*
     * 缩放从左上角开始。
     */
    transform-origin: top left;

    /*
     * iframe 的缩放由 ViewportController 控制。
     */

    box-shadow:
        0 20px 60px rgba(32, 42, 64, 0.16);
}


/* =========================================================
   七、元素选中框
========================================================= */

.selection-box {
    position: absolute;

    border: 1px solid #6171e8;

    box-shadow:
        0 0 0 1px rgba(97, 113, 232, 0.16);

    box-sizing: border-box;

    /*
     * 选中框主体不拦截鼠标事件。
     */
    pointer-events: none;

    z-index: 20;
}


/* 隐藏选中框 */

.selection-box.hidden {
    display: none;
}


/* =========================================================
   八、八方向缩放控制点
========================================================= */

.selection-box .transform-handle {
    position: absolute;

    width: 10px;
    height: 10px;

    background: #ffffff;

    border: 2px solid #6171e8;

    border-radius: 50%;

    box-sizing: border-box;

    /*
     * 控制点允许接收鼠标事件。
     */
    pointer-events: auto;

    z-index: 2;
}


/* 左上 */

.transform-handle-nw {
    left: -5px;
    top: -5px;

    cursor: nwse-resize;
}


/* 上 */

.transform-handle-n {
    left: 50%;
    top: -5px;

    transform: translateX(-50%);

    cursor: ns-resize;
}


/* 右上 */

.transform-handle-ne {
    right: -5px;
    top: -5px;

    cursor: nesw-resize;
}


/* 右 */

.transform-handle-e {
    right: -5px;
    top: 50%;

    transform: translateY(-50%);

    cursor: ew-resize;
}


/* 右下 */

.transform-handle-se {
    right: -5px;
    bottom: -5px;

    cursor: nwse-resize;
}


/* 下 */

.transform-handle-s {
    left: 50%;
    bottom: -5px;

    transform: translateX(-50%);

    cursor: ns-resize;
}


/* 左下 */

.transform-handle-sw {
    left: -5px;
    bottom: -5px;

    cursor: nesw-resize;
}


/* 左 */

.transform-handle-w {
    left: -5px;
    top: 50%;

    transform: translateY(-50%);

    cursor: ew-resize;
}


/* =========================================================
   九、旋转控制点
========================================================= */

.selection-box .transform-rotate-handle {
    position: absolute;

    left: 50%;
    top: -28px;

    width: 12px;
    height: 12px;

    transform: translateX(-50%);

    background: #ffffff;

    border: 2px solid #6171e8;

    border-radius: 50%;

    box-sizing: border-box;

    pointer-events: auto;

    cursor: grab;

    z-index: 3;
}


/* 旋转时的鼠标状态 */

.selection-box .transform-rotate-handle:active {
    cursor: grabbing;
}


/* 旋转控制点连接线 */

.selection-box .transform-rotate-handle::before {
    content: "";

    position: absolute;

    left: 50%;
    top: 10px;

    width: 1px;
    height: 15px;

    background: #6171e8;

    transform: translateX(-50%);

    pointer-events: none;
}


/* =========================================================
   十、编辑区底部状态栏
========================================================= */

.stage-footer {
    position: relative;

    width: 100%;
    height: 40px;
    min-height: 40px;

    flex: 0 0 40px;

    background: #ffffff;

    border-top: 1px solid var(--line);

    display: flex;

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

    padding: 0 17px;

    box-sizing: border-box;

    color: #9aa3b0;

    font-size: 10px;

    z-index: 30;
}


/* =========================================================
   十一、画布视口工具栏
========================================================= */

.viewport-toolbar {
    display: flex;

    align-items: center;

    gap: 7px;

    flex-shrink: 0;

    min-width: 0;
}


/* 视口按钮 */

.viewport-toolbar .icon-btn {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    width: 30px;
    height: 30px;

    flex: 0 0 30px;

    padding: 0;

    font-size: 20px;

    color: #344054;

    background: #ffffff;

    border: 1px solid var(--line);

    border-radius: 7px;

    cursor: pointer;

    box-sizing: border-box;

    transition:
        background-color 0.15s ease,
        border-color 0.15s ease;
}


.viewport-toolbar .icon-btn:hover {
    background: #f3f5f9;

    border-color: #c5cddd;
}


/* 缩放百分比 */

.viewport-zoom-value {
    min-width: 48px;

    text-align: center;

    color: #344054;

    font-size: 12px;

    font-weight: 600;

    font-variant-numeric: tabular-nums;

    white-space: nowrap;
}


/* 适应画布、实际大小等操作按钮 */

.viewport-action-btn {
    height: 30px;

    flex: 0 0 auto;

    padding: 0 11px;

    border: 1px solid var(--line);

    border-radius: 7px;

    background: #ffffff;

    color: #344054;

    font-size: 12px;

    white-space: nowrap;

    cursor: pointer;

    box-sizing: border-box;

    transition:
        background-color 0.15s ease,
        border-color 0.15s ease;
}


.viewport-action-btn:hover {
    background: #f3f5f9;

    border-color: #c5cddd;
}


/* =========================================================
   十二、窄屏布局
========================================================= */

@media (max-width: 900px) {
    .stage-toolbar {
        padding: 0 10px;
    }

    .stage-wrap {
        padding: 6px;
    }

    .stage-footer {
        padding: 0 10px;
    }

    .viewport-toolbar {
        gap: 4px;
    }

    .viewport-toolbar .icon-btn {
        width: 28px;
        height: 28px;

        flex-basis: 28px;
    }

    .viewport-zoom-value {
        min-width: 42px;
    }

    .viewport-action-btn {
        padding: 0 7px;

        font-size: 11px;
    }
}