/* ==========================================================================
   result.css - iPhone SE / 縦短画面 / スマホキーボード完全対応版
   ========================================================================== */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    
    /* 中央寄せにし、はみ出た場合はスクロールできるようにする */
    justify-content: center;
    align-items: center; 
    
    z-index: 100000 !important; 
    font-family: sans-serif;
    box-sizing: border-box; 
    padding: 10px; /* 画面端の最低限のクッション */
}

.overlay * {
    box-sizing: border-box;
}

/* アクティブ時の表示切り替え */
.overlay.show {
    display: flex;
}

/* --- リザルトメイン枠組み（赤枠） --- */
.result-box {
    background: #1a1a2e;
    border: 3px solid #e60012;
    border-radius: 12px;
    padding: 20px; 
    
    width: 92%;
    max-width: 340px;
    text-align: center;
    color: #fff;
    box-shadow: 0 0 20px rgba(230, 0, 18, 0.5);
    
    /* 一律で absolute や bottom を廃止し、画面上部に突き抜ける現象を根本から防ぐ */
    position: relative;
    transform: none;
    left: auto;
    bottom: auto;

    /* 縦が狭い画面でも操作パッドに被らないよう上限を制限し、枠内スクロールを保証 */
    max-height: 85vh; 
    overflow-y: auto;
    
    height: auto !important;
}

/* タイトル（CLEAR / TIME UP） */
.result-box h2 {
    font-size: 24px;
    margin: 0 0 12px 0;
    color: #ff3333;
    text-shadow: 0 0 10px rgba(255, 51, 51, 0.6);
    letter-spacing: 2px;
}

/* --- スコア明細エリア --- */
.result-details {
    background: #0f0f1b;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 6px 0;
    font-size: 14px;
}

.bonus-row {
    color: #ffcc00;
}

.result-divider {
    border: none;
    border-top: 1px dashed #444;
    margin: 6px 0;
}

.total-row {
    font-size: 18px;
    font-weight: bold;
    color: #00ffcc;
    text-shadow: 0 0 8px rgba(0, 255, 204, 0.5);
}

/* --- 数字カウントアップ中の輝きエフェクト --- */
.counting {
    animation: pulse 0.1s infinite alternate;
    color: #fff !important;
    text-shadow: 0 0 12px #ffcc00;
}

@keyframes pulse {
    from { transform: scale(1.0); }
    to { transform: scale(1.05); }
}

/* --- ハイスコア・ランキング表示用の箱（スクロール対応） --- */
.ranking-preview {
    background: #000000; /* 引き締まるように真っ黒に変更 */
    border-radius: 8px;
    padding: 10px;
    margin-top: 10px;
    margin-bottom: 15px; 
    border: 2px solid #333;
    
    /* 💡 縦幅を固定し、これを超えたらこの箱の中だけをスクロールさせる（Retryボタンの押し出し防止） */
    max-height: 180px; 
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* スマホの慣性スクロール用 */
}

/* 💡 ネオンピンクの極細スクロールバーデザイン */
.ranking-preview::-webkit-scrollbar {
    width: 6px;
}
.ranking-preview::-webkit-scrollbar-track {
    background: #0f0f1b;
    border-radius: 3px;
}
.ranking-preview::-webkit-scrollbar-thumb {
    background: #ff00ff; /* 世界観に合わせたネオンピンク */
    border-radius: 3px;
}

.ranking-title {
    margin: 0 0 5px 0;
    font-size: 12px;
    color: #aaa;
    font-weight: bold;
}

.high-score-val {
    font-size: 16px;
    font-weight: bold;
    color: #fff;
}

/* --- オレンジのリトライボタン --- */
#retry-btn.retry-button {
    background: #f0a04b;
    color: #fff;
    border: none;
    padding: 12px 30px;
    font-size: 18px;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(240, 160, 75, 0.4);
    width: 100%;
    
    position: relative;
    margin-top: 5px;
    margin-bottom: 5px;
}

/* ==========================================================================
   📱 スマホのキーボード表示（入力欄フォーカス時）の隠れ・ズレ対策
   ========================================================================== */
@media screen and (max-width: 480px) {
    
    /* 名前入力欄（input）にフォーカスが当たっている時だけ緊急発動 */
    .overlay:has(input:focus) {
        /* 中央寄せ（center）をやめ、強制的に画面の「一番上」に配置する */
        align-items: flex-start !important;
        padding-top: env(safe-area-inset-top, 10px) !important; /* iPhoneのノッチ対策 */
        overflow-y: auto !important;
    }

    .overlay:has(input:focus) .result-box {
        /* キーボードが下から生えてきても潰されないよう、上部にピタッと張り付ける */
        margin-top: 10px !important;
        max-height: calc(100vh - 60px) !important; /* キーボード領域を考慮した高さ制限 */
        box-shadow: 0 0 15px rgba(230, 0, 18, 0.7);
    }
}
