:root {
    --primary-color: #1AAFFF;
    --background-color: #1a1a1a;
    --surface-color: #2c2c2c;
    --text-color: #f0f0f0;
    --error-color: #ff4d4d;
}

/* --- 基础样式重置 --- */
body {
    background-color: var(--background-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    min-height: 100vh;
}

a { color: var(--primary-color); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

/* --- 修复：登录/注册页面专用居中容器 --- */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center; /* 子元素水平居中 */
    justify-content: flex-start;
    padding-top: 80px; /* 距离顶部留出空间 */
    text-align: center; /* 文本内容居中 */
}

.login-container h1 {
    margin-bottom: 10px;
}

/* --- 游戏模式专用样式 (核心布局) --- */
/* 
   修复说明：
   原代码 "html, body.game-mode" 导致所有页面的 html 标签都被禁止滚动。
   现改为 "html.game-mode, body.game-mode"，限制仅在游戏页面生效。
*/
html.game-mode, body.game-mode {
    width: 100%;
    height: 100%;
    overflow: hidden; /* 禁止滚动 */
    background-color: #000;
    position: fixed; /* 强制固定，防止移动端回弹 */
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    touch-action: none;
}

body.game-mode {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- 游戏容器 --- */
#game-container {
    width: 100%;
    height: 100%; 
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom) !important;
    box-sizing: border-box;
    margin: 0 !important;
    border: none !important;
}

#game-container .ejs_parent, 
#game-container .ejs_canvas_parent {
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
}

.ejs_canvas {
    display: block !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important; 
    width: 100% !important;
    height: 100% !important;
}

.ejs_canvas.stretch-mode {
    object-fit: fill !important;
    max-width: none !important;
    max-height: none !important;
    width: 100vw !important;
    height: 100vh !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    margin: 0 !important;
    z-index: 0 !important; 
    border-radius: 0 !important;
}

/* --- 虚拟按键动态高度 (由用户配置控制) --- */
.ejs_virtualGamepad_parent {
    bottom: 22vh !important; /* 默认值，会被 JS 动态覆盖 */
}

/* --- 大厅组件样式 --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 10px;
    border-bottom: 1px solid #444;
}

.system-section { margin-bottom: 40px; }
.system-section h2 { color: var(--primary-color); border-left: 4px solid var(--primary-color); padding-left: 10px; margin-bottom: 15px; }

.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
}

.game-card {
    background-color: var(--surface-color);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    transition: transform 0.2s, background-color 0.2s;
    border: 1px solid transparent;
}

.game-card:hover { transform: translateY(-3px); background-color: #383838; border-color: var(--primary-color); }
.game-card a { display: block; color: #fff; font-weight: 500; text-decoration: none; word-wrap: break-word; }

button {
    cursor: pointer;
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    background-color: var(--primary-color);
    color: white;
    font-size: 14px;
    transition: opacity 0.2s;
}
button:hover { opacity: 0.9; }

/* 登录表单样式微调 */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%; /* 占满容器 */
    max-width: 350px; /* 限制最大宽度 */
    margin: 20px 0; /* 上下间距 */
    padding: 30px;
    background-color: var(--surface-color);
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    text-align: left; /* 表单内部文字靠左 */
}
.login-form input {
    padding: 12px;
    border-radius: 4px;
    border: 1px solid #444;
    background-color: #222;
    color: #fff;
}

/* --- 菜单栏样式 --- */
#ejs-bottom-bar,
.ejs--bottom-bar,
.ejs_menu_bar {
    display: flex !important;
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    bottom: auto !important;
    right: auto !important;
    width: auto !important;
    min-width: 320px !important;
    max-width: 90vw !important;
    max-height: 85vh !important;
    background-color: rgba(30, 30, 30, 0.95) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 20px !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-content: flex-start !important;
    gap: 15px !important; 
    padding: 0 20px 20px 20px !important;
    z-index: 9000 !important; 
    box-shadow: 0 20px 50px rgba(0,0,0,0.8) !important;
    transform: translate(-50%, -50%) scale(0.9);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.19, 1, 0.22, 1) !important;
    overflow-y: auto !important;
    scrollbar-width: none; 
}

#ejs-bottom-bar::-webkit-scrollbar,
.ejs--bottom-bar::-webkit-scrollbar,
.ejs_menu_bar::-webkit-scrollbar {
    display: none; 
}

#ejs-bottom-bar.show-controls,
.ejs--bottom-bar.show-controls,
.ejs_menu_bar.show-controls {
    transform: translate(-50%, -50%) scale(1) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

.ejs_menu_bar_hidden {
    display: flex !important; 
    opacity: 0 !important;
    pointer-events: none !important;
}

.ejs-button,
.ejs_menu_button {
    flex: 1 0 auto !important; 
    width: auto !important;    
    min-width: 80px !important; 
    height: auto !important;   
    min-height: 70px !important;
    border-radius: 12px !important;
    background-color: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
    padding: 10px 8px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 0 !important; 
    color: #ddd !important;
    transition: transform 0.1s, background-color 0.2s !important;
    text-transform: none !important;
    box-sizing: border-box !important;
}

.ejs-button:active,
.ejs_menu_button:active {
    background-color: var(--primary-color) !important;
    color: #fff !important;
    transform: scale(0.96);
}

.ejs-button svg,
.ejs_menu_button svg {
    width: 28px !important;
    height: 28px !important;
    fill: currentColor !important;
    margin-bottom: 8px !important;
    pointer-events: none;
    flex-shrink: 0 !important;
}

.ejs-button span,
.ejs_menu_button span {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    font-size: 13px !important;
    line-height: 1.2 !important;
    text-align: center !important;
    white-space: nowrap !important;
    font-weight: 500 !important;
}

/* --- 修复：防止音量控件图标重叠 --- */
.ejs-button > *,
.ejs_menu_button > * {
    position: relative !important;
    display: block !important;
}

.ejs-button > svg:not(:first-child),
.ejs_menu_button > svg:not(:first-child) {
    display: none !important; /* 隐藏多余的SVG图标 */
}

/* --- 强制隐藏退出模拟器按钮 --- */
.ejs-button[data-action="exitEmulation"],
.ejs_menu_button[data-action="exitEmulation"],
button[onclick*="exitEmulation"] {
    display: none !important;
}

#ejs-custom-close-btn {
    position: -webkit-sticky !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important; 
    background-color: #2a2a2a !important; 
    border-bottom: 1px solid rgba(255, 59, 48, 0.3) !important;
    color: #ff453a !important;
    flex-basis: 100% !important; 
    min-height: 45px !important;
    margin: 0 !important; 
    margin-bottom: 10px !important;
    padding: 10px 0 !important;
    flex-direction: row !important;
    border-radius: 0 0 10px 10px !important; 
    box-shadow: 0 5px 15px rgba(0,0,0,0.5) !important;
}

#ejs-bottom-bar {
    padding-top: 0 !important; 
}

#ejs-custom-close-btn svg {
    fill: #ff453a !important;
    width: 24px !important;
    height: 24px !important;
    margin-bottom: 0 !important;
}

#ejs-custom-close-btn:hover {
    background-color: #333 !important;
}

/* --- 新增：返回大厅按钮的醒目样式 --- */
.ejs-button[data-action="exitLobby"],
.ejs_menu_button[data-action="exitLobby"] {
    background-color: rgba(255, 69, 58, 0.2) !important;
    border: 2px solid #ff453a !important;
    color: #ff453a !important;
    font-weight: 600 !important;
}

.ejs-button[data-action="exitLobby"]:active,
.ejs_menu_button[data-action="exitLobby"]:active {
    background-color: #ff453a !important;
    color: #fff !important;
}

.ejs-button[data-action="exitLobby"] svg,
.ejs_menu_button[data-action="exitLobby"] svg {
    fill: #ff453a !important;
}

.ejs-button[data-action="exitLobby"]:active svg,
.ejs_menu_button[data-action="exitLobby"]:active svg {
    fill: #fff !important;
}

.ejs_virtualGamepad_open {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

#ejs-menu-trigger {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 28px;
    height: 28px;
    background-color: rgba(30, 30, 30, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    z-index: 99999 !important; 
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    color: #fff;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

#ejs-menu-trigger:hover {
    background-color: rgba(26, 175, 255, 0.8);
    transform: scale(1.05);
}

#ejs-menu-trigger:active {
    transform: scale(0.95);
}

#ejs-menu-trigger svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* --- 确认弹窗 (层级极高) --- */
#custom-confirm-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 2147483647 !important; /* 确保在全屏元素之上 */
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
.confirm-box {
    background: #222;
    border: 1px solid #444;
    border-radius: 15px;
    padding: 25px;
    width: 80%;
    max-width: 350px;
    text-align: center;
    color: white;
}
.confirm-buttons { display: flex; gap: 15px; margin-top: 20px; }
.modal-btn { padding: 10px 20px; border-radius: 8px; flex: 1; border: none; font-weight: bold; cursor: pointer; }
.btn-yes { background: var(--primary-color); color: white; }
.btn-no { background: #444; color: white; }