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

.hidden { display: none !important; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #ffcce6, #cce5ff);
    min-height: 100vh;
    overflow-x: hidden;
    color: #333;
}

/* モーダル類（変更なし） */
.modal { display: flex; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.7); z-index: 1000; justify-content: center; align-items: center; }
.modal.hidden { display: none; }
.modal-content { background: white; padding: 30px; border-radius: 15px; text-align: center; box-shadow: 0 5px 15px rgba(0,0,0,0.3); max-width: 400px; width: 90%; }
.modal-content h2 { margin-bottom: 20px; color: #ff66b2; }
#playerName { width: 100%; padding: 12px; margin-bottom: 20px; border: 2px solid #ff66b2; border-radius: 8px; font-size: 16px; }
#startButton, #closeRulesButton, #restartButton {
    background: #ff66b2; color: white; border: none; padding: 12px 25px; border-radius: 8px; font-size: 16px; cursor: pointer; transition: background 0.3s; width: 100%; margin-top: 10px;
}
#startButton:hover, #closeRulesButton:hover, #restartButton:hover { background: #ff3399; }
.rules-button { background: #66ccff; color: white; border: none; padding: 12px 25px; border-radius: 8px; font-size: 16px; cursor: pointer; transition: background 0.3s; width: 100%; }
.rules-button:hover { background: #3399cc; }
/* ルール説明モーダルのスタイル修正 */
.rules-modal {
    max-width: 500px; /* 横幅を少し広げる */
    width: 90%;
    max-height: 80vh; /* 画面からはみ出さないように */
    display: flex;
    flex-direction: column;
    padding: 0; /* 内側の余白は中身で調整 */
    overflow: hidden; /* はみ出し防止 */
    border: 3px solid #ff99cc; /* ピンクの枠線 */
    background: #fff0f5; /* 薄いピンクの背景 */
}

.rules-modal h2 {
    margin: 0;
    padding: 15px;
    background: #ff66b2;
    color: white;
    font-size: 20px;
    border-radius: 12px 12px 0 0; /* 上だけ丸く */
    flex-shrink: 0;
}

.rules-content {
    padding: 20px;
    overflow-y: auto; /* 縦スクロールを許可 */
    text-align: left; /* 左揃えにして読みやすく！ */
    line-height: 1.6; /* 行間を空ける */
    font-size: 15px;
    color: #555;
    flex-grow: 1; /* 余ったスペースを使う */
}

/* スクロールバーも可愛くする */
.rules-content::-webkit-scrollbar {
    width: 8px;
}
.rules-content::-webkit-scrollbar-track {
    background: #ffe6f0;
}
.rules-content::-webkit-scrollbar-thumb {
    background: #ff99cc;
    border-radius: 4px;
}

.rules-content h3 {
    color: #ff3399;
    border-bottom: 2px dashed #ff99cc;
    padding-bottom: 5px;
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 16px;
}

.rules-content p, .rules-content ul {
    margin-bottom: 10px;
}

.rules-content ul {
    padding-left: 20px;
}

/* 閉じるボタン */
#closeRulesButton {
    margin: 15px;
    width: calc(100% - 30px);
    background: #ff66b2;
    flex-shrink: 0;
}

/* 右上の×ボタン */
.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    color: white;
    cursor: pointer;
    z-index: 10;
}

/* Game Container */
.game-container { 
    display: flex; 
    justify-content: center; 
    padding: 20px; 
    gap: 20px; 
}

.player-side, .mirintea-side {
    flex: 1; max-width: 520px;
    background: rgba(255,255,255,0.9);
    border-radius: 20px; padding: 20px;
    box-shadow: 0 10px 30px rgba(255,102,178,0.3);
    border: 4px solid #ff99cc;
    
    display: flex;
    flex-direction: column;
    height: auto; 
    min-height: 90vh; 
}

.player-side h2, .mirintea-side h2 {
    text-align: center; margin-bottom: 10px; color: #ff3399;
    font-size: 24px; text-shadow: 2px 2px 4px rgba(255,255,255,0.8);
    flex-shrink: 0;
}

/* === レイアウトエリア === */

/* 上段：組札 */
.top-row {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
    height: 110px;
    flex-shrink: 0;
}

.foundations {
    display: flex;
    gap: 10px;
}

.foundation {
    width: 70px; height: 100px;
    background: rgba(255,182,193,0.25);
    border: 3px dashed #ff66b2;
    border-radius: 12px;
    box-shadow: inset 0 0 15px rgba(255,255,255,0.5);
    position: relative;
}
.foundation:empty::after { display: none; }

/* 中段：場札（Tableau） */
.tableau {
    display: flex;
    justify-content: space-between;
    gap: 5px;
    flex-grow: 1; 
    margin-bottom: 20px; 
    position: relative;
    min-height: 60vh; 
}

/* 列の区切り */
.tableau-column {
    width: 13%; 
    background: rgba(255, 255, 255, 0.4);
    border: 2px solid rgba(255, 102, 178, 0.5); 
    position: relative;
    border-radius: 12px;
    height: 100%; 
}
.tableau-column:empty::after { display: none; }

/* 下段：ストックと廃棄札 */
.bottom-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    height: 110px;
    margin-top: auto;
    padding-top: 10px;
    border-top: 2px dashed rgba(255,102,178,0.3);
    flex-shrink: 0;
}

.stock, .waste {
    width: 70px; height: 100px;
    background: rgba(255,182,193,0.25);
    border: 3px dashed #ff66b2;
    border-radius: 12px;
    box-shadow: inset 0 0 15px rgba(255,255,255,0.5);
    position: relative;
}
.stock:empty::after, .waste:empty::after { display: none; }

/* Card Styles */
.card {
    width: 70px; height: 100px;
    background: white;
    border: 2px solid #ff66b2;
    border-radius: 10px;
    position: absolute;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255,102,178,0.4);
    transition: transform 0.1s ease;
    background-size: cover;
    z-index: 1;
}

/* ★スマホ用レイアウト */
@media (max-width: 768px) {
    /* 縦並び：columnで上がプレイヤー、下がみりんてゃ */
    .game-container {
        flex-direction: column; 
        align-items: center;
        padding: 10px;
    }

    .player-side, .mirintea-side {
        width: 100%;
        max-width: none;
        margin-bottom: 30px;
        min-height: 80vh; 
    }

    /* カードサイズ調整 */
    .card, .foundation, .stock, .waste {
        width: 11vw;  
        height: 15.5vw; 
        max-width: 70px; 
        max-height: 100px;
    }

    .top-row, .bottom-controls {
        height: auto;
        padding-bottom: 10px;
    }

    /* ★修正：スマホ用みりんてゃウィンドウ */
    /* !importantを削除して、ドラッグ操作（top/leftの変更）を受け付けるようにしたよ！ */
    .character-window {
        width: 160px; /* 少し大きく */
        height: 220px !important; /* 縦長にして文字が入るように！ */
        
        /* 初期位置：右下 */
        left: auto;
        top: auto;
        bottom: 10px;
        right: 10px;
    }
    
    #mirinteaImage { width: 90px; height: 90px; }
    /* 文字エリアをスクロール可能に */
    .dialogue-box { 
        font-size: 12px; 
        padding: 8px;
        flex-grow: 1; /* 余ったスペースを全部使う */
        overflow-y: auto; /* 文字が多いときはスクロール */
    }
}

/* オーバーレイ */
.overlay {
    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: 2000;
}
.overlay-content {
    background: white; padding: 40px; border-radius: 20px; text-align: center;
    border: 5px solid #ff66b2;
    max-width: 90%;
}
.overlay-content img { width: 200px; height: 200px; border-radius: 50%; object-fit: cover; margin-bottom: 20px; }
.overlay-content p { font-size: 20px; color: #ff3399; margin-bottom: 20px; font-weight: bold; }

/* ★キャラクターウィンドウ（共通設定） */
.character-window {
    position: fixed; 
    
    /* PCでの初期位置（ドラッグで上書きされる） */
    top: calc(100vh - 250px); 
    left: calc(100vw - 250px);
    right: auto;

    width: 220px; 
    height: 250px; 
    
    background: linear-gradient(135deg, #fff0f5, #ffe4f0);
    border: 4px solid #ff66b2;
    border-radius: 20px;
    box-shadow: 0 12px 40px rgba(255,102,178,0.5);
    z-index: 9999;
    
    /* フレックスボックスにして中身を整理 */
    display: flex; 
    flex-direction: column;
}

.character-header {
    background: #ff66b2; color: white; padding: 10px;
    border-radius: 15px 15px 0 0; display: flex; justify-content: space-between;
    cursor: move; /* ドラッグできるマーク */
    flex-shrink: 0;
}

.character-content { 
    padding: 10px; 
    text-align: center; 
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

#mirinteaImage { 
    width: 100px; height: 100px; 
    border-radius: 50%; 
    object-fit: cover; 
    border: 3px solid #ff99cc; 
    margin: 0 auto 10px;
    flex-shrink: 0;
}

.dialogue-box { 
    background: white; 
    padding: 10px; 
    border-radius: 10px; 
    font-size: 14px; 
    color: #d63384; 
    
    /* 縦に並ぶように設定 */
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* 文字が見えるように高さを確保 */
    flex-grow: 1;
    overflow-y: auto;
    min-height: 0; /* Flexboxの子要素でスクロールさせるコツ */
}