/* 全体設定 */
* {
    box-sizing: border-box; /* すべての要素にborder-boxを適用 */
}

body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* 垂直方向も中央揃え */
    min-height: 100vh; /* ビューポートの高さ全体を使用 */
    background-color: #f0f0f0;
    margin: 0;
    padding-top: 20px;
    padding-left: 20px; /* 左側に20pxの余白を追加 */
    padding-right: 20px; /* 右側にも20pxの余白を追加 */
}

h1 {
    color: #333;
}

.controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap; /* ボタンが多すぎる場合に折り返す */
    justify-content: center; /* ボタンを中央揃え */
}

.game-info {
    display: flex;
    justify-content: space-around; /* 均等に配置 */
    max-width: 600px; /* 最大幅を設定 */
    width: 90%; /* 小さい画面では90%の幅を使用 */
    margin-bottom: 20px;
    flex-wrap: wrap; /* 要素が多すぎる場合に折り返す */
}

.score-container, .turns-container, .bonus-score-container {
    font-size: 1.2em;
    font-weight: bold;
    flex: 1; /* 各要素が利用可能なスペースを均等に占める */
    text-align: center; /* 中央揃え */
    min-width: 100px; /* 小さい画面でも潰れないように最小幅を設定 */
    margin: 5px; /* 要素間の余白 */
}

#settingsPanel {
    background-color: #fff;
    border: 1px solid #ccc;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center; /* パネル内のコンテンツを中央揃えにする（ブロック要素は影響を受けない） */
    max-width: 600px; /* 設定パネルも最大幅を設定 */
    width: 90%; /* 小さい画面では90%の幅を使用 */
}

.hidden {
    display: none;
}

.difficulty-selection {
    margin-bottom: 15px;
    text-align: left; /* ラジオボタンとラベルのテキストを左揃えに変更 */
    max-width: 250px; /* 難易度選択ブロックの最大幅を設定（適宜調整） */
    margin-left: auto; /* 難易度選択ブロック自体を中央揃え */
    margin-right: auto; /* 難易度選択ブロック自体を中央揃え */
}

/* その他の設定パネル内の要素のセンタリングを維持したい場合は、必要に応じて個別にtext-align: center;を適用します */
#settingsPanel label[for="volumeSlider"] {
    text-align: center; /* 音量調節ラベルを中央揃えに戻す */
    display: block; /* ブロック要素にしてmargin:autoを効かせる場合はこれが必要 */
}


/* ゲームコンテナ */
.game-container {
    display: grid;
    /* 画面幅に合わせて列数を自動調整し、各カードは最低150pxの幅を維持。
       利用可能なスペースがあれば、それ以上にも柔軟に拡大します。 */
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); /* minmaxの最小値を150pxに変更 */
    grid-gap: 10px;
    perspective: 1000px;
    width: 100%; /* 親要素の幅に合わせて可変 */
    max-width: 640px; /* コンテナの最大幅を制限 */
    margin: 0 auto; /* ゲームコンテナ自体を中央揃え */
}

/* カードのスタイル */
.card {
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative; /* 子要素のabsolute基準 */
    transform-style: preserve-3d;
    /* transition: transform 0.6s; <-- この行は削除またはコメントアウト */

    /* 正方形のアスペクト比を維持（推奨される新しい方法） */
    aspect-ratio: 1 / 1;

    /* --- 揺れ防止とパフォーマンス最適化のための追加 --- */
    will-change: transform, box-shadow; /* ブラウザにアニメーションの準備を促す */
    box-shadow: 0 0px 0px rgba(0, 0, 0, 0); /* デフォルトで透明な影を設定し、レイアウトシフトを防ぐ */
    transform: translateZ(0); /* ハードウェアアクセラレーションを有効にする */
    transition: transform 0.3s ease, box-shadow 0.3s ease; /* すべてのトランジションをここで管理 */
}

/* ホバー時の浮き上がる効果 */
.card:hover {
    transform: translateY(-5px) scale(1.05) translateZ(0); /* ハードウェアアクセラレーションを一貫して適用 */
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); /* ホバー時に影を可視化 */
    /* transition: transform 0.3s ease, box-shadow 0.3s ease; <-- この行は削除またはコメントアウト (親に移動したため) */
}

/* front-faceとback-faceの共通スタイル */
.front-face, .back-face {
    width: 100%;
    height: 100%;
    position: absolute; /* .card内にぴったり収まるように */
    top: 0;
    left: 0;
    backface-visibility: hidden; /* 各面の裏側を非表示にする */
    border-radius: 8px;
}

/* front-faceのスタイル（画像面） */
.front-face {
    background-size: cover;       /* 画像サイズをカバーに */
    background-position: center;  /* 画像位置を中央に */
    transform: rotateY(180deg);   /* 最初は裏を向ける（見えない状態） */
}

/* back-faceのスタイル（?マークの面） */
.back-face {
    background-color: #333; /* 裏面の背景色 */
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em;
    transform: rotateY(0deg); /* 最初は表を向ける（見える状態） */
}

/* カードがめくれた時のスタイル */
.card.flipped {
    transform: rotateY(180deg); /* カード全体を回転させる */
}

/* マッチしたカードが消えるアニメーションを無効化 */
.card.matched {
    /* opacity: 0; */
    /* transform: scale(0.5); */
    /* transition: opacity 0.5s ease, transform 0.5s ease; */
}

/* ヒント表示時のスタイル */
.card.show-hint {
    transform: rotateY(180deg); /* !important を削除し、滑らかなトランジションを有効にする */
}

/* --- 花火アニメーションのスタイル --- */
#fireworks-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* クリックイベントを透過させる */
    overflow: hidden; /* 花火がコンテナ外にはみ出さないように */
    z-index: 1000; /* 他の要素の上に表示 */
}

.firework {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: white; /* デフォルトの色 */
    border-radius: 50%;
    opacity: 0;
    animation: explode 1s forwards; /* 爆発アニメーション */
}

@keyframes explode {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    10% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.5); /* 爆発後少し小さく */
    }
}

/* --- カスタムアラートモーダルのスタイル --- */
#customAlertModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7); /* 半透明のオーバーレイ */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000; /* 最前面に表示 */
}

.modal-hidden {
    display: none !important; /* JavaScriptで非表示にするクラス */
}

.modal-content {
    background-color: #fff;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    max-width: 80%; /* 幅を画面の80%に制限 */
    transform: scale(0.8); /* 最初は少し小さく */
    animation: modal-appear 0.3s forwards; /* アニメーションで表示 */
}

@keyframes modal-appear {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

#alertMessage {
    font-size: 1.5em;
    margin-bottom: 20px;
    color: #333;
    text-align: left; /* 左寄せに変更 */
    padding-left: 0; /* padding-leftをリセット */
    /* 必要に応じてメッセージボックス内の余白を調整する場合は、modal-contentのpaddingを調整してください */
}

#alertOkButton {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 10px 25px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
}

#alertOkButton:hover {
    background-color: #45a049;
}

/* スコアがマイナスになった場合に赤色で表示 */
.negative-score {
    color: red;
}

/* ボタンの共通スタイル */
.game-button { /* 新しい共通スタイルクラス */
    background-color: #4CAF50; /* 例として緑色 */
    color: white;
    padding: 10px 20px;
    border: 2px solid;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
    margin: 5px; /* ボタン間の余白 */
}

.game-button:hover {
    transform: translateY(-2px); /* ホバーで少し浮き上がる */
}

#startButton {
    background-color: #4CAF50; /* ゲームスタートはグリーン */
    border-color: #ffffff; /* 白色の枠線 */
}

#startButton:hover {
    border-color: #483d8b; /* ホバーでdarkslateblue */
}

#settingsButton {
    background-color: #a0522d; /* 設定は茶色 */
    border-color: #ffffff; /* 白色の枠線 */
}

#settingsButton:hover {
    border-color: #483d8b; /* ホバーでdarkslateblue */
}

#hintButton, #bottomHintButton { /* ヒントボタンのスタイルを両方に適用 */
    background-color: #0000ff; /* ヒントは青 */
    border-color: #ffffff; /* 白色の枠線 */
}

#hintButton:hover, #bottomHintButton:hover {
    border-color: #483d8b; /* ホバーでdarkslateblue */
}

/* スマートフォン向けの調整 */
@media (max-width: 768px) {
    h1 {
        font-size: 1.8em;
    }

    /* controls, game-info, settingsPanelはbodyのpaddingとwidth:90%で対応 */
    .controls, .game-info, #settingsPanel {
        width: 100%; /* 小さい画面では親要素の幅を最大限に利用 */
        padding: 0; /* bodyのpaddingで余白を確保するため、ここでリセット */
        box-sizing: border-box;
    }

    .game-info {
        flex-direction: column; /* 縦に並べる */
        align-items: center;
    }
    .score-container, .turns-container, .bonus-score-container {
        width: 100%; /* 折り返した際に幅いっぱいに */
        margin: 5px 0; /* 縦方向の余白 */
    }
}
