/* 全局基础样式 - 修复移动设备溢出问题 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    width: 100%; /* 替换100vw，避免移动设备视口计算问题 */
    height: 100%; /* 替换100vh，兼容更多移动浏览器 */
    overflow: hidden; /* 移除!important，允许必要时调整 */
}

body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* 顶部控制栏 - 确保移动设备可滚动 */
#controls {
    padding: 10px;
    background-color: #282c34;
    color: #eee;
    flex-shrink: 0; /* 防止被挤压消失 */
    border-bottom: 1px solid #444;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    min-height: 50px;
    display: flex;
    align-items: center;
    z-index: 10;
    gap: 8px;
    overflow-x: auto; /* 允许横向滚动 */
    white-space: nowrap; /* 按钮不换行 */
    -webkit-overflow-scrolling: touch; /* 优化移动设备滚动体验 */
    scrollbar-width: thin; /* 细滚动条 */
}

/* 修复按钮在移动设备上的点击区域 */
#controls button {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    background-color: #555;
    color: white;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
    min-width: auto; /* 避免按钮被强制拉伸 */
    display: inline-flex; /* 确保按钮内容正确显示 */
    align-items: center;
    justify-content: center;
}

#controls button:hover:not(:disabled) {
    background-color: #777;
}

#controls button:disabled {
    background-color: #3e3e3e;
    cursor: not-allowed;
}

#controls button[style*="red"] {
    background-color: #c0392b !important;
}

#controls button[style*="red"]:hover:not(:disabled) {
    background-color: #e74c3c !important;
}

/* 输出区域 */
#output {
    padding: 5px 10px;
    background-color: #1e1e1e;
    color: #90ee90;
    font-family: monospace;
    white-space: pre-wrap;
    min-height: 20px;
    flex-shrink: 0;
    border-bottom: 1px solid #444;
    width: 100%;
    box-sizing: border-box;
}

/* Canvas 容器 - 适配移动设备 */
#canvas {
    flex-grow: 1;
    width: 100% !important;
    height: 100% !important;
    background-color: black;
    outline: none;
    border: none;
    display: block;
    overflow: hidden;
    box-sizing: border-box;
    z-index: 1;
}

/* 扩展显示模式样式 */
body.body-extended #controls,
body.body-extended #output {
    display: none !important;
}
body.body-extended #canvas {
    height: 100vh !important;
    margin-top: 0 !important;
}

/* 悬浮退出按钮 */
.exit-extended-btn {
    position: fixed;
    width: 50px; /* 增大触摸区域 */
    height: 50px; /* 增大触摸区域 */
    border-radius: 50%;
    background-color: rgba(200, 50, 50, 0.3); /* 背景透明度 0.3 */
    color: rgba(255, 255, 255, 0.5); /* 文字透明度 0.9，与背景协调 */
    border: none;
    font-size: 24px; /* 增大图标 */
    cursor: move !important;
    user-select: none;
    -webkit-user-select: none;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999 !important;
    pointer-events: auto;
    transition: background-color 0.2s;
    clip-path: none !important;
    overflow: visible !important;
    /* 增加触摸热区 */
    padding: 8px;
    margin: -8px;
}

.exit-extended-btn:hover {
    background-color: rgba(220, 50, 50, 0.9); /* hover 背景透明度 0.9 */
    color: rgba(255, 255, 255, 1); /* hover 文字完全不透明，确保清晰 */
}
.exit-extended-btn:active {
    cursor: grabbing !important;
}

body.body-extended .exit-extended-btn {
    display: flex;
}

/* 移动设备适配补充 */
@media (max-width: 768px) {
    #controls {
        padding: 8px 5px; /* 减少内边距，节省空间 */
        gap: 5px; /* 减少按钮间距 */
    }
    
    #controls button {
        padding: 6px 10px; /* 缩小按钮尺寸 */
        font-size: 12px; /* 缩小字体 */
    }
}