body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #a8dadc 0%, #457b9d 100%);
    font-family: 'Arial', sans-serif;
    margin: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    box-sizing: border-box;
}

.container {
    text-align: center;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 30px 20px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-width: 600px;
    width: 100%;
    box-sizing: border-box;
}

h1 {
    font-family: 'Comic Sans MS', cursive, sans-serif;
    color: #2c3e50;
    margin-bottom: 30px;
    font-size: 2.8em;
    text-shadow: 3px 3px 5px rgba(0, 0, 0, 0.2);
    letter-spacing: 1px;
    word-break: keep-all;
}

.controls {
    margin-bottom: 20px;
    font-size: 1.1em;
    color: #333;
}

.controls label {
    margin-right: 8px;
}

.controls select {
    padding: 6px 10px;
    font-size: 0.95em;
    border-radius: 8px;
    border: 1px solid #a8dadc;
    background-color: #f1faee;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.controls select:hover {
    border-color: #457b9d;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

.dice-container {
    /* ここをFlexboxに戻す */
    display: flex;
    flex-wrap: wrap; /* 画面幅に応じて折り返す */
    justify-content: center; /* 中央揃え */
    align-items: flex-start; /* 上揃え */
    gap: 15px; /* サイコロ間の隙間 */
    margin-bottom: 30px;
    min-height: auto; /* 動的な高さ調整は不要に */
    border: none; /* 仮の枠線は削除 */
    overflow: visible; /* はみ出しも通常に */
    /* 以前のランダム配置用のposition:relativeやmin-height設定を削除/変更 */
}

.dice {
    /* position:absoluteを削除 */
    width: 70px;
    height: 70px;
    background-color: white;
    border: none;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3em;
    font-weight: bold;
    color: black;
    box-shadow:
        0 6px 12px rgba(0, 0, 0, 0.25),
        0 0 0 4px rgba(255, 255, 255, 0.6) inset;
    transform: perspective(500px) rotateX(7deg) rotateY(-7deg);
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out; /* left, topのアニメーションを削除 */
    flex-shrink: 0;
    cursor: default;
    /* top, leftプロパティはJavaScriptで設定しないのでCSSから削除 */
}

/* サイコロの目ごとの色 */
.yellow { color: #FFD700; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); }
.lightblue { color: #87CEEB; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); }
.purple { color: #800080; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); }
.red { color: #FF0000; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); }
.green { color: #008000; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); }
.brown { color: #A52A2A; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); }

button {
    padding: 12px 30px;
    font-size: 1.3em;
    background: linear-gradient(45deg, #e63946, #f4a261);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(230, 57, 70, 0.4);
    transition: all 0.3s ease-in-out;
    letter-spacing: 1px;
    font-weight: bold;
}

button:hover {
    background: linear-gradient(45deg, #f4a261, #e63946);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(230, 57, 70, 0.6);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(230, 57, 70, 0.3);
}

/* ------------------------------------------------ */
/* スマホ向け調整 (メディアクエリ) */
@media (max-width: 768px) {
    .container {
        padding: 20px 15px;
        border-radius: 10px;
    }

    h1 {
        font-size: 2.2em;
        margin-bottom: 25px;
    }

    .controls {
        font-size: 1em;
        margin-bottom: 15px;
    }

    .controls select {
        padding: 5px 8px;
        font-size: 0.9em;
    }

    .dice-container {
        gap: 10px;
        margin-bottom: 25px;
        min-height: auto; /* ここも元に戻す */
    }

    .dice {
        width: 60px;
        height: 60px;
        font-size: 2.5em;
        border-radius: 10px;
        box-shadow:
            0 5px 10px rgba(0, 0, 0, 0.2),
            0 0 0 3px rgba(255, 255, 255, 0.5) inset;
    }

    button {
        padding: 10px 25px;
        font-size: 1.1em;
    }
}

@media (max-width: 480px) {
    .dice {
        width: 50px;
        height: 50px;
        font-size: 2em;
        gap: 8px;
    }
    .dice-container {
        gap: 8px;
        min-height: auto; /* ここも元に戻す */
    }
    h1 {
        font-size: 1.8em;
    }
}