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

body {
    font-family: 'Microsoft JhengHei', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
    max-width: 1200px;
    width: 95%;
}

header {
    text-align: center;
    margin-bottom: 20px;
}

header h1 {
    color: #333;
    margin-bottom: 10px;
    font-size: 2.5em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

#game-info {
    display: flex;
    justify-content: center;
    gap: 30px;
    font-size: 1.2em;
    color: #555;
    font-weight: bold;
}

#game-area {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    position: relative;
}

#game-canvas {
    border: 3px solid #333;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

#minimap-container {
    position: relative;
}

#minimap {
    border: 2px solid #666;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.1);
}

#controls {
    text-align: center;
}

#instructions {
    margin-bottom: 15px;
    color: #555;
}

#instructions p {
    margin-bottom: 5px;
}

#game-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

button {
    padding: 12px 24px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
    font-family: inherit;
}

#start-btn, #next-level-btn {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
}

#reset-btn {
    background: linear-gradient(45deg, #f44336, #da190b);
    color: white;
}

#toggle-minimap-btn {
    background: linear-gradient(45deg, #2196F3, #0b7dda);
    color: white;
}

#restart-game-btn {
    background: linear-gradient(45deg, #FF9800, #e68900);
    color: white;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#level-selection {
    text-align: center;
    margin-top: 20px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}

#level-selection h3 {
    margin-bottom: 15px;
    color: #333;
}

#level-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    max-width: 400px;
    margin: 0 auto;
}

.level-btn {
    padding: 10px;
    background: linear-gradient(45deg, #9C27B0, #673AB7);
    color: white;
    border-radius: 5px;
    font-size: 14px;
}

.level-btn.completed {
    background: linear-gradient(45deg, #4CAF50, #45a049);
}

.level-btn.locked {
    background: #ccc;
    color: #666;
    cursor: not-allowed;
}

#game-over {
    text-align: center;
    padding: 30px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    margin-top: 20px;
}

#game-over h2 {
    color: #333;
    margin-bottom: 15px;
    font-size: 2em;
}

#final-message {
    font-size: 1.2em;
    color: #555;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    #game-container {
        width: 98%;
        padding: 15px;
    }
    
    header h1 {
        font-size: 2em;
    }
    
    #game-info {
        flex-direction: column;
        gap: 10px;
        font-size: 1em;
    }
    
    #game-area {
        flex-direction: column;
        align-items: center;
    }
    
    #game-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    button {
        width: 200px;
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

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

/* 美化對話框樣式 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: modalFadeIn 0.3s ease-out;
}

.modal-dialog {
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease-out;
}

.modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.4em;
    font-weight: bold;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: none;
    box-shadow: none;
}

.modal-body {
    padding: 30px;
    text-align: center;
    flex: 1;
    overflow-y: auto;
    max-height: calc(90vh - 140px); /* 減去 header 和 footer 的高度 */
}

.modal-icon {
    font-size: 4em;
    margin-bottom: 20px;
}

.modal-icon.success::before { content: "🎉"; }
.modal-icon.warning::before { content: "⚠️"; }
.modal-icon.error::before { content: "❌"; }
.modal-icon.info::before { content: "ℹ️"; }
.modal-icon.question::before { content: "❓"; }

.modal-content {
    font-size: 1.1em;
    color: #333;
    line-height: 1.6;
}

.modal-content .stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin: 20px 0;
    text-align: left;
}

.modal-content .stat-item {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.modal-content .stat-label {
    font-weight: bold;
    color: #555;
    font-size: 0.9em;
}

.modal-content .stat-value {
    font-size: 1.2em;
    color: #333;
    margin-top: 5px;
}

.modal-footer {
    padding: 20px 30px;
    background: #f8f9fa;
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-shrink: 0; /* 防止 footer 被壓縮 */
}

.modal-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 100px;
}

.modal-btn-primary {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
}

.modal-btn-secondary {
    background: linear-gradient(45deg, #6c757d, #5a6268);
    color: white;
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* 開始選單樣式 */
.start-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 900;
}

.start-menu-content {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 50px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    animation: slideInUp 0.6s ease-out;
}

.start-menu-content h2 {
    color: #333;
    font-size: 3em;
    margin-bottom: 40px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.start-menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

.start-btn {
    padding: 15px 40px;
    font-size: 18px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    min-width: 200px;
}

.start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

/* 關卡選擇面板樣式 */
.level-select-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 950;
}

.level-select-content {
    background: white;
    border-radius: 20px;
    padding: 40px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalSlideIn 0.4s ease-out;
}

.level-select-content h3 {
    text-align: center;
    color: #333;
    font-size: 2em;
    margin-bottom: 30px;
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.level-card {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.level-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.level-card.unlocked {
    border-color: #4CAF50;
    background: linear-gradient(135deg, #e8f5e8 0%, #f0f8f0 100%);
}

.level-card.completed {
    border-color: #2196F3;
    background: linear-gradient(135deg, #e3f2fd 0%, #f1f8ff 100%);
}

.level-card.locked {
    background: #f5f5f5;
    color: #999;
    cursor: not-allowed;
    border-color: #ccc;
}

.level-card.locked:hover {
    transform: none;
    box-shadow: none;
}

.level-number {
    font-size: 2em;
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
}

.level-card.locked .level-number {
    color: #999;
}

.level-stars {
    font-size: 1.2em;
    margin: 10px 0;
    min-height: 1.5em;
}

.level-stats {
    font-size: 0.8em;
    color: #666;
    margin-top: 8px;
}

.level-select-footer {
    text-align: center;
}

.level-actions {
    margin-top: 10px;
    text-align: center;
}

.level-info-btn {
    background: linear-gradient(45deg, #2196F3, #1976D2);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.level-info-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

.level-card.locked .level-info-btn {
    background: #ccc;
    cursor: default;
}

.level-card.locked .level-info-btn:hover {
    transform: none;
    box-shadow: none;
}

/* 關卡說明內容樣式 */
.level-info-content {
    text-align: left;
    /* 移除高度限制，讓內容自然展開，滾動由 modal-body 處理 */
}

.level-info-content h4 {
    color: #333;
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.1em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 5px;
}

.level-info-content h4:first-child {
    margin-top: 0;
}

.level-info-content p {
    margin-bottom: 8px;
    line-height: 1.5;
}

.level-info-content ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.level-info-content li {
    margin-bottom: 5px;
    line-height: 1.4;
}

.level-basic-info {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.level-tutorial {
    background: #e3f2fd;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #2196F3;
}

.level-objective {
    background: #e8f5e9;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #4CAF50;
}

.level-mechanics {
    background: #fff3e0;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #FF9800;
}

.level-tips {
    background: #f3e5f5;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #9C27B0;
}

.level-stars {
    background: #fffde7;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #FFC107;
}

.star-conditions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.star-condition {
    background: white;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    font-size: 0.95em;
}

/* 關卡簡介樣式 */
.level-brief {
    text-align: left;
    /* 讓內容自然展開，滾動由 modal-body 處理 */
}

.brief-intro {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.brief-intro h4 {
    margin: 0 0 10px 0;
    font-size: 1.4em;
    color: white;
    border: none;
}

.brief-intro p {
    margin-bottom: 8px;
    line-height: 1.5;
}

.brief-tutorial {
    background: #e3f2fd;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    border-left: 4px solid #2196F3;
}

.brief-controls {
    background: #f5f5f5;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #666;
}

.brief-controls p {
    margin-bottom: 8px;
    font-size: 0.95em;
}

/* 動畫效果 */
@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideIn {
    from { 
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to { 
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 響應式設計 */
@media (max-width: 768px) {
    .modal-dialog {
        width: 95%;
        margin: 20px;
        max-height: 95vh;
    }
    
    .modal-body {
        padding: 20px;
        max-height: calc(95vh - 120px);
    }
    
    .start-menu-content {
        padding: 30px;
        margin: 20px;
    }
    
    .start-menu-content h2 {
        font-size: 2em;
    }
    
    .level-select-content {
        padding: 20px;
        margin: 20px;
    }
    
    .levels-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 10px;
    }
    
    .level-card {
        padding: 15px;
    }
}