/* =====================================
   子供向けプログラミングゲーム - メインスタイル
   ===================================== */

/* リセット & ベース設定 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Nunito', 'Comic Neue', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
}

/* メインコンテナ */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* =====================================
   ヘッダー
   ===================================== */
.game-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border-bottom: 3px solid #ff6b9d;
}

.game-title {
    font-size: 2rem;
    font-weight: 800;
    color: #667eea;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.title-icon {
    color: #ff6b9d;
    animation: bounce 2s infinite;
}

.level-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.level-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: #667eea;
}

.progress-bar {
    width: 200px;
    height: 8px;
    background: #e1e8f4;
    border-radius: 20px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff6b9d, #ffa726);
    border-radius: 20px;
    transition: width 0.5s ease;
    width: 30%;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.score-display {
    background: linear-gradient(135deg, #ffa726, #ff6b9d);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.1rem;
    box-shadow: 0 3px 10px rgba(255, 107, 157, 0.3);
}

.help-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 0.8rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}

.help-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

/* =====================================
   メインゲーム画面
   ===================================== */
.game-main {
    flex: 1;
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 1rem;
    padding: 1rem;
    min-height: calc(100vh - 200px);
    margin-bottom: 100px; /* フッターのスペースを確保 */
}

/* サイドパネル共通スタイル */
.code-blocks-panel,
.program-panel {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    overflow-y: auto;
}

.panel-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 2px solid #e1e8f4;
    padding-bottom: 0.5rem;
}

/* =====================================
   コードブロック
   ===================================== */
.block-category {
    margin-bottom: 1.5rem;
}

.category-title {
    font-size: 1rem;
    font-weight: 600;
    color: #764ba2;
    margin-bottom: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.code-block {
    background: white;
    border-radius: 15px;
    padding: 1rem;
    margin-bottom: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    cursor: grab;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    font-weight: 600;
    user-select: none;
}

.code-block:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.code-block:active {
    cursor: grabbing;
    transform: scale(1.05);
}

/* ブロック種類別の色分け */
.action-block {
    border-left: 5px solid #4caf50;
    background: linear-gradient(135deg, #e8f5e8, #ffffff);
}

.action-block:hover {
    border-color: #4caf50;
    background: linear-gradient(135deg, #c8e6c9, #e8f5e8);
}

.loop-block {
    border-left: 5px solid #ff9800;
    background: linear-gradient(135deg, #fff3e0, #ffffff);
}

.loop-block:hover {
    border-color: #ff9800;
    background: linear-gradient(135deg, #ffe0b2, #fff3e0);
}

.condition-block {
    border-left: 5px solid #2196f3;
    background: linear-gradient(135deg, #e3f2fd, #ffffff);
}

.condition-block:hover {
    border-color: #2196f3;
    background: linear-gradient(135deg, #bbdefb, #e3f2fd);
}

.block-icon {
    font-size: 1.2rem;
    color: inherit;
}

.repeat-input {
    width: 40px;
    border: none;
    background: rgba(255, 152, 0, 0.1);
    border-radius: 8px;
    padding: 0.2rem 0.5rem;
    font-weight: 600;
    text-align: center;
    color: #ff9800;
}

/* =====================================
   ゲームエリア
   ===================================== */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem;
}

.game-canvas-container {
    position: relative;
    background: white;
    border-radius: 20px;
    padding: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 3px solid #ff6b9d;
}

#game-canvas {
    display: block;
    border-radius: 15px;
    background: linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
                linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.canvas-overlay {
    position: absolute;
    top: 1rem;
    left: 1rem;
    width: 400px;
    height: 400px;
    pointer-events: none;
}

.character {
    position: absolute;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    transition: all 0.5s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    z-index: 10;
}

.goal {
    position: absolute;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #ffa726, #ff6b9d);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    animation: pulse 2s infinite;
    box-shadow: 0 4px 15px rgba(255, 167, 38, 0.3);
}

/* ゲームコントロール */
.game-controls {
    display: flex;
    gap: 1rem;
}

.control-btn {
    background: white;
    border: 3px solid;
    border-radius: 15px;
    padding: 1rem 1.5rem;
    font-family: inherit;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 120px;
    justify-content: center;
}

.run-btn {
    border-color: #4caf50;
    color: #4caf50;
}

.run-btn:hover {
    background: #4caf50;
    color: white;
    transform: translateY(-2px);
}

.reset-btn {
    border-color: #ff9800;
    color: #ff9800;
}

.reset-btn:hover {
    background: #ff9800;
    color: white;
    transform: translateY(-2px);
}

.clear-btn {
    border-color: #f44336;
    color: #f44336;
}

.clear-btn:hover {
    background: #f44336;
    color: white;
    transform: translateY(-2px);
}

/* =====================================
   プログラムエリア
   ===================================== */
.program-area {
    margin-bottom: 1.5rem;
}

.drop-zone {
    min-height: 300px;
    border: 3px dashed #ccc;
    border-radius: 15px;
    padding: 1rem;
    background: rgba(102, 126, 234, 0.05);
    transition: all 0.3s ease;
}

.drop-zone.drag-over {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    transform: scale(1.02);
}

.drop-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: #999;
    text-align: center;
}

.drop-placeholder i {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: #ccc;
}

.program-block {
    background: white;
    border-radius: 12px;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
    border-left: 4px solid;
    animation: slideInRight 0.3s ease;
}

.program-block .block-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.program-block .remove-btn {
    background: #f44336;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.3s ease;
}

.program-block .remove-btn:hover {
    background: #d32f2f;
    transform: scale(1.1);
}

/* ミッションパネル */
.mission-panel {
    background: linear-gradient(135deg, #ff6b9d, #ffa726);
    color: white;
    border-radius: 15px;
    padding: 1rem;
    margin-top: 1rem;
}

.mission-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mission-text {
    font-size: 0.95rem;
    line-height: 1.4;
}

/* =====================================
   フッター
   ===================================== */
.game-footer {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    border-top: 3px solid #ff6b9d;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 25px;
    padding: 0.8rem 1.5rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.footer-btn:hover {
    background: #5a67d8;
    transform: translateY(-2px);
}

.footer-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.level-selector {
    display: flex;
    gap: 0.5rem;
}

.level-numbers {
    display: flex;
    gap: 0.3rem;
}

.level-number {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #e1e8f4;
    color: #667eea;
}

.level-number.active {
    background: #667eea;
    color: white;
}

.level-number:hover {
    transform: scale(1.1);
}

/* =====================================
   モーダル
   ===================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    animation: slideInUp 0.3s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #e1e8f4;
    padding-bottom: 1rem;
}

.modal-header h3 {
    color: #667eea;
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-close {
    background: #f44336;
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: #d32f2f;
    transform: scale(1.1);
}

/* ヘルプモーダル */
.help-section {
    margin-bottom: 1.5rem;
}

.help-section h4 {
    color: #667eea;
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.help-section p {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.block-help {
    margin-bottom: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 10px;
}

.help-block {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    padding: 0.5rem;
    border-radius: 8px;
}

/* レベルクリアモーダル */
.celebration-modal .modal-content {
    text-align: center;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.celebration-icon {
    font-size: 4rem;
    color: #ffa726;
    margin-bottom: 1rem;
    animation: bounce 1s infinite;
}

.celebration-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 1rem;
}

.celebration-message {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

.celebration-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.celebration-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.celebration-btn {
    background: white;
    color: #667eea;
    border: none;
    border-radius: 25px;
    padding: 1rem 2rem;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.celebration-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.next-btn {
    background: #ffa726;
    color: white;
}

.next-btn:hover {
    background: #ff9800;
}

/* =====================================
   レスポンシブ対応
   ===================================== */
@media (max-width: 1200px) {
    .game-main {
        grid-template-columns: 250px 1fr 250px;
        margin-bottom: 100px;
    }
}

@media (max-width: 1024px) {
    .game-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        gap: 1rem;
        min-height: calc(100vh - 220px);
        margin-bottom: 120px;
    }
    
    .code-blocks-panel,
    .program-panel {
        max-height: 300px;
    }
    
    .game-header {
        padding: 1rem;
        flex-wrap: wrap;
        gap: 1rem;
    }
    
    .game-title {
        font-size: 1.5rem;
    }
    
    .progress-bar {
        width: 150px;
    }
    
    .game-footer {
        padding: 0.8rem 1rem;
    }
}

@media (max-width: 768px) {
    .game-header {
        flex-direction: column;
        text-align: center;
    }
    
    .header-right {
        order: -1;
        margin-bottom: 1rem;
    }
    
    .game-main {
        padding: 0.5rem;
        margin-bottom: 140px;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 0.8rem;
    }
    
    .game-footer {
        padding: 0.8rem;
    }
    
    .modal-content {
        margin: 1rem;
        padding: 1.5rem;
    }
    
    .celebration-stats {
        flex-direction: column;
        gap: 1rem;
    }
    
    .celebration-buttons {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .game-canvas-container {
        padding: 0.5rem;
    }
    
    #game-canvas {
        width: 300px;
        height: 300px;
    }
    
    .canvas-overlay {
        width: 300px;
        height: 300px;
    }
    
    .character,
    .goal {
        width: 30px;
        height: 30px;
        font-size: 1.2rem;
    }
    
    .game-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .control-btn {
        min-width: 100px;
        padding: 0.8rem 1rem;
    }
    
    .game-main {
        margin-bottom: 160px;
    }
    
    .footer-btn {
        font-size: 0.9rem;
        padding: 0.6rem 1rem;
    }
    
    .level-number {
        width: 30px;
        height: 30px;
        font-size: 0.9rem;
    }
}