:root {
    --bg-color: #f4f7f6;
    --panel-bg: #ffffff;
    --text-main: #333333;
    --plant-color: #4cd137;
    --herb-color: #00a8ff;
    --carn-color: #e84118;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    --border-radius: 12px;
}

body {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
}

.container {
    max-width: 1040px; /* 少し広くした */
    width: 100%;
}

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

h1 {
    color: #2f3640;
    margin-bottom: 5px;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 20px;
}

.visuals-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap; /* スマホ用 */
}

/* シミュレーション部分を画面の25%程度、あるいは固定で小さく */
.simulation-section {
    flex: 0 0 auto;
    background: #7bd02d;
    border-radius: var(--border-radius);
    padding: 10px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: center;
    align-items: center;
}

#simCanvas {
    background: #88d44e;
    border-radius: 8px;
    border: 2px solid #6ab04c;
    width: 300px; /* 固定幅 */
    height: 300px;
}

/* グラフ部分を大きく長く */
.graph-section {
    flex: 1; /* 残りのスペースを全て埋める */
    background: var(--panel-bg);
    padding: 10px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 300px;
}

#graphCanvas {
    background: #fafafa;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 100%; /* 親要素に合わせて伸びる */
    height: 300px; /* 高さを指定 */
}


.controls-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.stats-panel {
    flex: 1;
    min-width: 250px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-box {
    background: var(--panel-bg);
    padding: 15px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
    font-weight: bold;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stat-box.plant { border-left: 6px solid var(--plant-color); }
.stat-box.herbivore { border-left: 6px solid var(--herb-color); }
.stat-box.carnivore { border-left: 6px solid var(--carn-color); }
.stat-box .icon { font-size: 1.5em; margin-right: 10px; }

.controls-panel {
    flex: 2;
    background: var(--panel-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.control-inputs {
    flex: 1;
    min-width: 200px;
}

.control-actions {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.control-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    font-weight: bold;
}

.control-group input[type="number"] {
    width: 70px;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1em;
}

.slider-group {
    flex-direction: column;
    align-items: flex-start;
    margin-top: 10px;
}

.slider-group input {
    width: 100%;
    margin-top: 5px;
}

.buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
}

.btn {
    flex: 1 1 calc(50% - 10px); /* ボタンが増えたため、スマホ等では2列で綺麗に並ぶようにする */
    min-width: 140px;
    padding: 12px 8px; /* スマホでも押しやすい大きさに */
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}

.btn:active {
    transform: scale(0.95);
}

.btn:hover {
    opacity: 0.9;
}

.btn.primary { background: #fbc531; color: #333; }
.btn.success { background: #44bd32; color: white; }
.btn.danger { background: #e84118; color: white; }

.explanation {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    line-height: 1.6;
}

.explanation h3 {
    margin-top: 0;
    color: #273c75;
}

@media (max-width: 768px) {
    body {
        padding: 10px; /* スマホ画面の余白を少し減らす */
    }
    
    .visuals-row { flex-direction: column; }
    
    .simulation-section { 
        width: 100%; 
        box-sizing: border-box;
    }
    
    #simCanvas { 
        width: 100%; 
        max-width: 300px; 
    }
    
    .graph-section {
        width: 100%;
        box-sizing: border-box;
        padding: 5px; /* グラフを画面いっぱいに広げる */
    }
    
    #graphCanvas {
        height: 220px; /* スマホだと縦に長すぎるとスクロールが大変なので少し高さを抑える */
    }

    .btn { 
        font-size: 0.9rem; /* 文字を少し小さくして4つのボタンでも収まりやすく */
        padding: 10px 5px;
    }
    
    .stats-panel {
        flex-direction: row; /* スマホでは数値を横並びにして高さを節約 */
        flex-wrap: wrap;
    }
    
    .stat-box {
        flex: 1 1 30%; /* 3つ並べる */
        font-size: 0.9rem;
        padding: 10px;
        justify-content: center;
        flex-direction: column; /* アイコンの上に数値を並べるなど */
    }
    
    .stat-box .icon {
        margin-right: 0;
        margin-bottom: 5px;
    }
}
