/* ==================== 基础重置 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation;
}

/* ==================== 全局电脑端间距 ==================== */
@media (min-width: 769px) {
    body {
        padding: 0 20px;
    }
}

/* ==================== 主容器 ==================== */
.game-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;              /* ✅ 修改：取消居中（原为 margin: 0 auto） */
    height: calc(100vh - 80px);
    min-height: 0;
    overflow: hidden;
}

/* ==================== 左侧容器 ==================== */
.left-container {
    width: 100%;
    position: relative;
    margin-top: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

/* ==================== 任务地图容器 ==================== */
.task-map-container {
    text-align: center;
    margin-bottom: 0;
    margin-top: auto;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 0;
}

/* ==================== 地图容器 ==================== */
.game-board {
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin: 0 auto;
    margin-top: auto !important;
    margin-bottom: 10px !important;
    border: 0px solid #333;
    transition: margin-top 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    overflow: hidden;
}

/* ==================== 大正方形（地图网格） ==================== */
.big-square {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    background: transparent;
    border: 0px solid #90caf9;
    display: grid;
    grid-gap: 0;
    box-sizing: border-box;
}

/* 不同网格尺寸 */
.big-square.grid-3x3 { grid-template-columns: repeat(3, 1fr); }
.big-square.grid-4x4 { grid-template-columns: repeat(4, 1fr); }
.big-square.grid-5x5 { grid-template-columns: repeat(5, 1fr); }
.big-square.grid-6x6 { grid-template-columns: repeat(6, 1fr); }

/* ==================== 小正方形 ==================== */
.small-square {
    aspect-ratio: 1/1;
    background: transparent;
    border: 0px solid #1f1f402d;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 20;
}

/* 小鸟图片 */
.bird-square {
    background-position: center;
    background-repeat: no-repeat;
}

.small-square .bird-image {
    width: 85%;
    height: 85%;
    object-fit: contain;
}

/* ==================== 代码面板 ==================== */
.code-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 0px;
    background: #f5f5f5;
    border-radius: 8px;
    height: 100%;
}

/* ==================== 通道容器 ==================== */
.channel-container {
    position: relative;
    min-width: 300px;
    z-index: 2;
    display: none;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: auto auto;
    row-gap: 20px;
    column-gap: 8px;
    padding: 0px;
    padding-bottom: 15px;
    background: #e9ecef;
    border-radius: 8px;
    margin-bottom: -5px !important;
}

/* ==================== 指令库容器 ==================== */
.code-blocks {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    row-gap: 4px;
    column-gap: 10px;
    margin: 15px 0;
    background: #e9ecef;
    border-radius: 8px;
    padding: 15px;
    height: calc(100% - 20px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    min-width: 300px;
    z-index: 1;
}

/* ==================== 标题栏 ==================== */
.game-header {
    position: sticky;
    top: 0;
    background-color: rgb(255, 255, 255);
    z-index: 200;
    padding: 5px 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ==================== 任务需求面板 ==================== */
.task-requirement-container {
    position: fixed;
    width: 100%;
    background: rgba(240, 248, 255, 0.95);
    border-radius: 0 0 8px 8px;
    padding: 5px 15px 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    z-index: 99;
    transition: transform 0.4s ease-out;
    transform: translateY(-100%);
}

.task-requirement-container.slide-out {
    transform: translateY(0);
}

.task-handle {
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    height: 35px;
    padding: 0 10px;
    background: rgba(240, 248, 255, 0.8);
    border-radius: 0 0 8px 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
    transition: background-color 0.3s;
}

.task-handle:hover {
    background-color: rgba(224, 240, 255, 0.8);
}

/* ================================================================
   📱 手机端 (宽度 ≤ 768px)
   ================================================================ */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .game-container {
        height: calc(100vh - 65px);
        max-width: 100%;
        padding: 0 2px;
        overflow: visible;
    }

    .left-container {
        align-items: center;
    }

    .game-header {
        width: 100%;
        max-width: calc(100vw - 20px);
    }

    .game-board {
        margin-bottom: 5px !important;
        overflow: hidden;
    }

    .game-board .big-square {
        box-sizing: border-box;
    }

    .small-square .bird-image {
        width: 85%;
        height: 85%;
        object-fit: contain;
    }

    .game-alert {
        font-size: 1rem;
        padding: 8px 16px;
    }

    .task-requirement-popup h3 {
        font-size: 1rem !important;
    }

    .task-requirement-popup .popup-content {
        font-size: 0.9rem !important;
    }
}

/* ================================================================
   💻 电脑端 (宽度 ≥ 769px) — 横向双栏布局（左对齐）
   ================================================================ */
@media (min-width: 769px) {
    .game-container {
        flex-direction: row;
        align-items: flex-end;
        justify-content: flex-start;    /* ✅ 修改：改为左对齐（原为 center） */
        max-width: 100%;
        width: 100%;
        margin: 0;                      /* ✅ 修改：取消居中 */
        gap: 10px;
        padding: 0 40px 0 10px;         /* ✅ 修改：右侧留更大间距（左10px，右40px） */
        height: calc(100vh - 80px);
    }

    /* 左侧：地图区域 — 用 flex 撑满 */
    .left-container {
        flex: 1 1 0;
        min-width: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;
        padding: 0 0 10px 0;
    }

    /* 地图容器 — 正方形，靠底部 */
    .game-board {
        width: min(100%, 100%);
        height: min(100%, 100%);
        max-width: 100%;
        max-height: 100%;
        aspect-ratio: 1 / 1;
        flex-shrink: 0;
        margin: 0 !important;
        margin-bottom: 0 !important;
    }

    .big-square {
        width: 100%;
        height: 100%;
        aspect-ratio: 1 / 1;
    }

    /* 右侧：指令库 — 也靠底部对齐 */
    .right-container {
        width: 30%;
        min-width: 220px;
        max-width: 400px;
        flex-shrink: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        padding-bottom: 0;
    }

    .code-panel {
        height: 100%;
    }

    .code-blocks {
        height: calc(100% - 20px);
    }
}

/* ================================================================
   🖥️ 大屏幕 (≥ 1200px) — 右侧间距更大
   ================================================================ */
@media (min-width: 1200px) {
    .game-container {
        gap: 10px;
        padding: 0 60px 0 20px;         /* ✅ 修改：右侧留更大间距（左20px，右60px） */
    }

    .right-container {
        width: 400px;
        max-width: 400px;
    }
}

/* ================================================================
   🖥️ 超大屏幕 (≥ 1600px) — 右侧间距进一步加大
   ================================================================ */
@media (min-width: 1600px) {
    .game-container {
        gap: 10px;
        padding: 0 80px 0 30px;         /* ✅ 修改：右侧留更大间距（左30px，右80px） */
    }

    .right-container {
        width: 400px;
        max-width: 400px;
    }
}

/* ================================================================
   📱 超小屏保护 (≤ 480px)
   ================================================================ */
@media (max-width: 480px) {
    .game-alert {
        font-size: 1rem;
        padding: 8px 16px;
    }

    .task-requirement-popup h3 {
        font-size: 1rem !important;
    }

    .task-requirement-popup .popup-content {
        font-size: 0.9rem !important;
    }
}

/* ========= body 覆盖 ========= */
body {
    padding-top: 80px !important;
    min-height: 100vh !important;
    margin: 0 !important;
}
@media (max-width: 768px) {
    body { padding-top: 65px !important; }
}

/* ========= 地图尺寸 ========= */
.big-square {
    width: var(--map-width-ratio, 90%);
    height: auto;
    aspect-ratio: var(--big-square-aspect-ratio, 1 / 1);
}
.small-square { aspect-ratio: 1 / 1; }