* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', '微軟正黑體', sans-serif;
    background: #0d7377;
    height: 100vh;
    width: 100vw;
    overflow: hidden; /* 防止滾動 */
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.container {
    background: #f5f5f5;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 10px;
    box-sizing: border-box;
}

.header {
    text-align: center;
    flex-shrink: 0;
    padding-bottom: 5px;
}

.header h1 {
    color: #0d7377;
    margin: 0;
    font-size: 1.2rem;
}

.instruction {
    color: #555;
    font-size: 0.8rem;
    margin: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.main-layout {
    display: flex;
    flex: 1; /* 佔據剩餘空間 */
    gap: 10px;
    min-height: 0; /* 允許縮小 */
    overflow: hidden;
}

.game-viewport {
    flex: 1;
    position: relative;
    background: #111;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    touch-action: none; /* 防止畫布上的觸控滾動 */
}

#canvas-container {
    width: 100%;
    height: 100%;
}

.hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
}

.health-bar-container {
    pointer-events: auto;
}

.status-label {
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    display: block;
    margin-bottom: 2px;
}

.health-bar {
    width: 120px;
    height: 15px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #14919b;
    border-radius: 8px;
    overflow: hidden;
}

.health-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff4444 0%, #ff8844 30%, #ffdd44 60%, #88ff44 100%);
    width: 100%;
    transition: width 0.2s;
}

.status-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
}

#food-count, #danger-indicator {
    background: rgba(0,0,0,0.5);
    padding: 4px 8px;
    border-radius: 4px;
    color: #fff;
    font-size: 0.9rem;
}

#danger-indicator.danger {
    background: rgba(255, 0, 0, 0.8);
    animation: pulse-danger 0.5s infinite;
}

.control-panel {
    width: 250px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
    overflow-y: auto;
}

.controls {
    background: white;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.control-info {
    font-size: 0.8rem;
    color: #666;
    text-align: center;
    margin-bottom: 8px;
}

.virtual-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.btn-row {
    display: flex;
    gap: 5px;
}

.btn-arrow {
    width: 55px;
    height: 55px;
    background: linear-gradient(135deg, #14919b, #0d7377);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 0 #064e56;
    touch-action: none; /* 防止按鈕觸控延遲與滾動 */
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-arrow:active {
    transform: translateY(4px);
    box-shadow: none;
}

.btn-new-game {
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    background: #4ba85c;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
}

.stats-panel {
    background: white;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
}

.stats-panel h2 {
    margin-top: 0;
    font-size: 1rem;
    color: #0d7377;
}

/* Full-screen Settlement Modal (R2) */
.game-over-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: modalBackdropFadeIn 0.25s ease-out;
}

.game-over-card {
    background: linear-gradient(160deg, #16363c 0%, #0c2024 100%);
    border: 2px solid #14919b;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.7), 0 0 24px rgba(20, 145, 155, 0.35);
    border-radius: 18px;
    max-width: 420px;
    width: 100%;
    padding: 28px 24px;
    text-align: center;
    color: #ffffff;
    animation: modalPopIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalBackdropFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalPopIn {
    from { transform: scale(0.88); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.game-over-icon {
    font-size: 3rem;
    margin-bottom: 8px;
    animation: iconBounce 1s ease infinite alternate;
}

@keyframes iconBounce {
    from { transform: translateY(0); }
    to { transform: translateY(-6px); }
}

.game-over-card h2 {
    margin: 0 0 6px 0;
    font-size: 1.6rem;
    color: #00ff88;
    letter-spacing: 1px;
}

.game-over-cause-badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: bold;
    margin-bottom: 10px;
}

.cause-predator {
    background: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
    border: 1px solid #ef4444;
}

.cause-starvation {
    background: rgba(245, 158, 11, 0.25);
    color: #fcd34d;
    border: 1px solid #f59e0b;
}

.game-over-desc {
    margin: 0 0 16px 0;
    font-size: 0.95rem;
    color: #e2e8f0;
}

.final-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.final-stat-box {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.final-stat-box.full-width {
    grid-column: span 2;
}

.stat-box-label {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-bottom: 4px;
}

.stat-box-val {
    font-size: 1.15rem;
    font-weight: bold;
    color: #ffffff;
}

.title-badge {
    color: #fde047;
    font-size: 1.05rem;
}

.game-over-tip {
    background: rgba(13, 115, 119, 0.35);
    border-left: 3px solid #00dd88;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    color: #cbd5e1;
    text-align: left;
    margin-bottom: 20px;
    line-height: 1.4;
}

.btn-restart {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #00dd88 0%, #14919b 100%);
    color: #0b2529;
    border: none;
    border-radius: 10px;
    font-size: 1.05rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 221, 136, 0.4);
    transition: transform 0.15s, box-shadow 0.15s;
}

.btn-restart:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 221, 136, 0.6);
}

.btn-restart:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(0, 221, 136, 0.3);
}

@keyframes pulse-danger {
    0%, 100% { transform: scale(1); box-shadow: 0 0 5px red; }
    50% { transform: scale(1.1); box-shadow: 0 0 15px red; }
}

/* RWD mobile optimization */
@media (max-width: 800px) {
    .container {
        padding: 5px;
    }
    
    .instruction {
        display: none; /* 手機隱藏說明 */
    }

    .main-layout {
        flex-direction: column;
    }

    .game-viewport {
        flex: 1; /* 遊戲畫面占滿剩餘空間 */
    }

    .control-panel {
        width: 100%;
        height: auto;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        background: transparent;
        padding-top: 5px;
        overflow: visible;
    }

    .controls {
        flex: 1;
        background: transparent;
        padding: 0;
        align-items: center;
        justify-content: center;
    }

    .control-info, .stats-panel, .header h1 {
        display: none; /* 極簡模式 */
    }
    
    .header {
        display: none; /* 隱藏標題欄，全屏遊戲體驗 */
    }

    .virtual-controls {
        transform: scale(1.1); /* 稍微放大按紐 */
    }
    
    /* 將重新開始按鈕變小放在角落 */
    .btn-new-game {
        position: absolute;
        top: 10px;
        right: 10px;
        width: auto;
        margin: 0;
        padding: 5px 10px;
        font-size: 0.7rem;
        z-index: 10;
        background: rgba(255,255,255,0.8);
        color: #333;
    }
}
