/* 全局基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #121212;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

/* =========================================
   游戏库界面样式
   ========================================= */
#library-container {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #1e1e1e;
    padding-bottom: 60px;
}

.library-header {
    width: 100%;
    max-width: 800px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    color: #eee;
}

.library-title {
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    border-left: 4px solid #d32f2f;
    padding-left: 10px;
}

.library-tools button {
    padding: 8px 16px;
    background-color: #333;
    border: 1px solid #555;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 800px;
    padding-bottom: 40px;
}

.game-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s;
}

.game-card:active {
    transform: scale(0.95);
}

.game-cover {
    width: 120px;
    height: 160px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    background-color: #333;
    border: 2px solid #444;
}

.game-title {
    margin-top: 8px;
    color: #ccc;
    font-size: 14px;
    text-align: center;
    word-break: break-all;
    max-width: 120px;
    line-height: 1.2;
}

/* 上下文菜单 */
.context-menu {
    display: none;
    position: fixed;
    background-color: #333;
    border: 1px solid #555;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    z-index: 2000;
    min-width: 200px;
    flex-direction: column;
    padding: 5px 0;
}

.context-menu-item {
    padding: 12px 15px;
    color: white;
    cursor: pointer;
    font-size: 14px;
    text-align: left;
    background: none;
    border: none;
    width: 100%;
    display: block;
    border-bottom: 1px solid #444;
}
.context-menu-item:last-child { border-bottom: none; }
.context-menu-item:hover { background-color: #555; }
.context-menu-item.danger { color: #ff6b6b; }

/* =========================================
   游戏运行界面样式
   ========================================= */
#game-container {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

#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; }

#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;

    will-change: transform; /* 强制提升为独立的 GPU 合成层 */
    backface-visibility: hidden; /* 减少 iOS 闪烁并优化重绘 */

    /* --- 新增：解决长按选中和画面变蓝的问题 --- */
    -webkit-user-select: none;    /* 禁用 Safari/iOS 的文本选中 */
    user-select: none;            /* 禁用标准文本选中 */
    -webkit-touch-callout: none;  /* 禁用 iOS 长按弹出的系统菜单/气泡 */
    touch-action: none;           /* 彻底禁用浏览器的默认手势（如双击放大、滑动）交由游戏处理 */
}

body.fullscreen #controls { display: none !important; }
body.body-extended #controls { 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);
    color: rgba(255, 255, 255, 0.5);
    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;
    padding: 8px;
    margin: -8px;
}

.exit-extended-btn:hover {
    background-color: rgba(220, 50, 50, 0.9);
    color: rgba(255, 255, 255, 1);
}
.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; }
}

/* =========================================
   输出日志 / 进度条
   ========================================= */
#output {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 8px 15px;
    background-color: rgba(30, 30, 30, 0.95);
    color: #90ee90;
    font-family: monospace;
    font-size: 13px;
    white-space: pre-wrap;
    border-top: 1px solid #444;
    z-index: 3000;
    display: none;
    max-height: 150px;
    overflow-y: auto;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.5);
}

/* =========================================
   文件管理器样式
   ========================================= */
.fm-breadcrumb {
    padding: 10px;
    background-color: #222;
    border-bottom: 1px solid #444;
    color: #aaa;
    font-family: monospace;
    word-break: break-all;
    font-size: 14px;
}

.fm-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.fm-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #444;
    transition: background-color 0.2s;
}

.fm-item:hover { background-color: #3e3e3e; }

.fm-item-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    flex-grow: 1;
    cursor: pointer;
}

.fm-icon { font-size: 18px; min-width: 20px; text-align: center; }
.fm-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #eee; font-size: 15px; }
.fm-item-dir .fm-name { font-weight: bold; color: #fff; }

.fm-actions {
    display: flex;
    gap: 5px;
}

.fm-actions button {
    padding: 5px 10px;
    font-size: 12px;
    background-color: #555;
    border: none;
    color: white;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
}
.fm-actions button:hover { background-color: #777; }
.fm-actions button.edit-btn { background-color: #f0ad4e; }
.fm-actions button.edit-btn:hover { background-color: #ec971f; }

/* 红色删除小按钮 */
.fm-actions button.delete-btn { 
    background-color: #d9534f; 
    margin-right: 0;
}
.fm-actions button.delete-btn:hover { background-color: #c9302c; }

/* 底部按钮区域布局 */
.fm-footer {
    padding: 15px;
    border-top: 1px solid #444;
    background-color: #222;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 按钮组：横向排列 */
.fm-btn-group { 
    display: flex; 
    gap: 12px; 
    width: 100%;
}

.fm-btn {
    flex: 1; /* 平分宽度，实现半宽效果 */
    padding: 12px;
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    text-align: center;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}