/* Mezn Game Style */

.mezn-game-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background-color: transparent; 
    color: #1f2937;
}

html.dark .mezn-game-wrapper {
    color: #e5e5e5;
}

.mezn-game-container {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    height: 75vh;
    min-height: 600px;
    background: #f8f9fa;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

html.dark .mezn-game-container {
    background: #171717;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* =========================================
   修复部分：手机端/窄屏适配优化
   ========================================= */
@media (max-width: 768px) {
    .mezn-game-container {
        grid-template-columns: 1fr;
        /* 调整上下比例：上方列表占30%，下方操作区占70% */
        grid-template-rows: 30% 70%;
        /* 优先使用动态视口高度适配移动端浏览器 */
        height: 85vh;
        height: 85dvh;
    }

    /* 1. 隐藏按键说明，释放空间 */
    .key-map-section {
        display: none !important;
    }

    /* 2. 确保导入按钮不被挤压，且适配全面屏底部 */
    .import-area {
        flex-shrink: 0;
        padding-bottom: constant(safe-area-inset-bottom);
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* 3. 确保中间列表能滚动 */
    .panel-saves ul {
        min-height: 0;
    }

    /* 4. 稍微缩小封面图节省空间 */
    .game-cover-img {
        max-width: 100px;
        max-height: 100px;
        margin-bottom: 10px;
    }
}
/* ========================================= */

/* Panels */
.panel-list, .panel-saves {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border-right: 1px solid #eee;
}

html.dark .panel-list, 
html.dark .panel-saves {
    background: #262626;
    border-right-color: #404040;
}

.panel-header {
    padding: 15px;
    background: #2d3436;
    color: #fff;
}

html.dark .panel-header {
    background: #1f2937;
}

.panel-header h3 { margin: 0; font-size: 1rem; font-weight: 500; letter-spacing: 0.5px; }

ul {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
}

ul::-webkit-scrollbar { width: 6px; }
ul::-webkit-scrollbar-thumb { background-color: #d1d5db; border-radius: 3px; }
html.dark ul::-webkit-scrollbar-thumb { background-color: #525252; }

/* Game List */
#game-list-ul li {
    padding: 12px 15px;
    border-bottom: 1px solid #f1f1f1;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
    color: #2d3436;
}

html.dark #game-list-ul li {
    border-bottom-color: #404040;
    color: #d4d4d4;
}

#game-list-ul li:hover {
    background: #f0f8ff;
    color: #0984e3;
}
html.dark #game-list-ul li:hover {
    background: #404040;
    color: #60a5fa;
}

#game-list-ul li.active {
    background: #0984e3;
    color: white !important;
}

/* Game Info */
.game-info-area {
    padding: 20px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
    text-align: center;
    flex-shrink: 0;
}
html.dark .game-info-area {
    background: #1f2937;
    border-bottom-color: #374151;
}

.game-cover-img {
    max-width: 140px;
    max-height: 140px;
    width: auto; height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    margin-bottom: 15px;
    object-fit: contain;
    display: none;
    margin-left: auto; margin-right: auto;
}

.game-title-h4 { margin: 0 0 15px 0; color: #333; font-size: 1.1rem; }
html.dark .game-title-h4 { color: #fff; }

.start-game-btn {
    width: 100%;
    max-width: 280px;
    padding: 12px;
    background: #00b894;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    box-shadow: 0 4px 6px rgba(0,184,148,0.2);
    transition: transform 0.1s;
}
.start-game-btn:active { transform: translateY(1px); }
.empty-state { color: #888; margin-top: 20px; }
html.dark .empty-state { color: #a3a3a3; }

/* Save List */
.save-item {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    transition: background 0.2s;
}
html.dark .save-item {
    background: #262626;
    border-bottom-color: #404040;
}
.save-item:hover { background: #f9f9f9; }
html.dark .save-item:hover { background: #333; }

.save-info {
    flex: 1;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.save-meta { display: flex; align-items: center; gap: 8px; }
.save-date { font-size: 0.85rem; color: #999; }
html.dark .save-date { color: #a3a3a3; }

.save-tag { font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; }
.tag-auto { background: #dfe6e9; color: #636e72; }
.tag-manual { background: #ffeaa7; color: #d63031; }
.tag-exit { background: #55efc4; color: #00b894; }

html.dark .tag-auto { background: #374151; color: #9ca3af; }
html.dark .tag-manual { background: #713f12; color: #fde047; }
html.dark .tag-exit { background: #064e3b; color: #34d399; }

.save-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-icon-play {
    font-size: 1.2rem;
    color: #00b894;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
}
.btn-icon-play:hover { background: #e0fbf6; }
html.dark .btn-icon-play:hover { background: #064e3b; }

.btn-icon-download {
    font-size: 1.1rem;
    color: #74b9ff;
    cursor: pointer;
    padding: 6px;
    border-left: 1px solid #f1f1f1;
    margin-left: 4px;
    padding-left: 10px;
}
html.dark .btn-icon-download { border-left-color: #404040; color: #60a5fa; }
.btn-icon-download:hover { color: #0984e3; }

/* Import Area */
.import-area {
    padding: 15px;
    border-top: 1px solid #eee;
    background: #fdfdfd;
    margin-top: auto;
}
html.dark .import-area {
    background: #262626;
    border-top-color: #404040;
}

.btn-import {
    width: 100%;
    padding: 10px;
    background: #fff;
    border: 1px dashed #b2bec3;
    color: #636e72;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}
html.dark .btn-import {
    background: #1f2937;
    border-color: #525252;
    color: #a3a3a3;
}

.btn-import:hover {
    border-color: #0984e3;
    color: #0984e3;
    background: #f0f8ff;
}
html.dark .btn-import:hover {
    background: #374151;
    color: #fff;
}

/* Key Map */
.key-map-section {
    padding: 10px 15px;
    background-color: #fafafa;
    border-top: 1px solid #eee;
}
html.dark .key-map-section {
    background-color: #1f2937;
    border-top-color: #374151;
}

.key-map-title {
    font-size: 0.75rem;
    font-weight: bold;
    color: #b2bec3;
    margin: 0 0 8px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
html.dark .key-map-title { color: #6b7280; }

.key-map-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.key-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #ffffff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    border: 1px solid #e5e7eb;
    color: #636e72;
}
html.dark .key-item {
    background: #374151;
    border-color: #4b5563;
    color: #d1d5db;
}

.key-badge {
    background: #f1f2f6;
    color: #2f3542;
    font-family: monospace;
    font-weight: bold;
    padding: 1px 5px;
    border-radius: 3px;
    border-bottom: 2px solid #ced6e0;
    line-height: 1;
}
html.dark .key-badge {
    background: #1f2937;
    color: #f3f4f6;
    border-bottom: 2px solid #000;
}

.action-a { color: #e74c3c; font-weight: bold; }
.action-b { color: #f1c40f; font-weight: bold; }

/* Overlay & Controls */
#game-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #1a1a1a;
    z-index: 10000;
    display: flex;
    flex-direction: column;
}

.screen-area {
    flex: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    position: relative;
    overflow: hidden;
    min-height: 200px;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain; 
    image-rendering: pixelated; 
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.controls-area {
    height: auto;
    min-height: 240px;
    background: #222;
    padding: 10px 15px 30px 15px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.meta-row {
    display: flex;
    justify-content: center;
    gap: 20px;
}
.btn-pill {
    background: #444;
    color: #ccc;
    border: 1px solid #555;
    border-radius: 20px;
    padding: 8px 18px;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.5px;
}
.btn-save {
    background: #e67e22;
    border-color: #d35400;
    color: white;
}
.btn-pill:active { transform: scale(0.95); opacity: 0.8; }

.main-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    width: 100%;
    max-width: 480px; 
    margin: 0 auto; 
}

.d-pad {
    position: relative;
    width: 140px; height: 140px;
}
.d-btn {
    position: absolute;
    width: 46px; height: 46px;
    background: #3a3a3a;
    border: none;
    display: flex; justify-content: center; align-items: center;
    box-shadow: 0 4px 0 #111;
    border-radius: 4px;
}
.d-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #111; background: #555; }

.d-up    { top: 0; left: 47px; }
.d-down  { bottom: 0; left: 47px; }
.d-left  { top: 47px; left: 0; }
.d-right { top: 47px; right: 0; }
.d-center {
    position: absolute; top: 47px; left: 47px;
    width: 46px; height: 46px; background: #3a3a3a; z-index: 1;
}

.arrow { width: 0; height: 0; border-style: solid; opacity: 0.8; }
.arrow-up    { border-width: 0 7px 12px 7px; border-color: transparent transparent #ccc transparent; }
.arrow-down  { border-width: 12px 7px 0 7px; border-color: #ccc transparent transparent transparent; }
.arrow-left  { border-width: 7px 12px 7px 0; border-color: transparent #ccc transparent transparent; }
.arrow-right { border-width: 7px 0 7px 12px; border-color: transparent transparent transparent #ccc; }

.action-btns {
    width: 130px; height: 130px;
    position: relative;
}
.btn-wrapper { position: absolute; }
.b-pos { bottom: 10px; left: 0; }
.a-pos { top: 20px; right: 0; }

.btn-round {
    width: 65px; height: 65px;
    border-radius: 50%;
    border: none;
    font-size: 20px; font-weight: bold;
    color: rgba(255,255,255,0.9);
    box-shadow: 0 4px 0 rgba(0,0,0,0.4);
}
.btn-round:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.4); }
.btn-a { background: #e74c3c; } 
.btn-b { background: #f1c40f; color: #333; } 

#exit-area {
    height: 44px;
    background: #111;
    color: #666;
    display: flex; justify-content: center; align-items: center;
    font-size: 13px;
    border-top: 1px solid #333;
    cursor: pointer;
    transition: background 0.3s;
}
#exit-area:hover { background: #222; }