/* ---------- 9.5 ランキング画面 : OST風 ---------- */

#ranking-overlay {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;

    position: absolute;
    inset: 0;
    z-index: 140;

    flex-direction: column;
    align-items: center;

    /* コンテンツを上から並べる（余白はパネル側で自動調整する） */
    justify-content: flex-start; 
}

/* panel */

/* panel */
#ranking-panel {
    position: relative;
    z-index: 2;
    width: min(92vw, 560px);
    padding: 18px 16px 16px;
    border-radius: 3px;
    border: 1px solid rgba(120,255,255,0.18);
    background: rgba(0,0,0,0.5);
    box-shadow:
        0 0 30px rgba(0,255,255,0.08),
        inset 0 0 24px rgba(120,255,255,0.04);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    
    /* 上下中央寄せ */
    margin-top: auto;
    margin-bottom: auto;

    /* ★修正：高さを自動計算にし、はみ出しを完全に防ぐ最強の設定 */
    display: flex;
    flex-direction: column;
    box-sizing: border-box; /* 内側の余白（padding）を高さに含める */
    flex: 0 1 auto;         /* 画面が狭いときは自動的に縮む */
    min-height: 0;          /* 縮んだ状態でスクロールさせるためのおまじない */
    
    /* ※ max-height: calc(...); は削除します */
}

/* loading */

#loading-ranking {
    color: #9fefff;
    font-family: 'Orbitron', monospace;
    font-size: calc(13px * var(--ui-scale, 1));
    letter-spacing: 0.32em;
    margin-bottom: 12px;
    text-align: center;
    text-shadow: 0 0 8px rgba(0,255,255,0.18);
    animation: rankingBlink 0.8s ease-in-out infinite;
}

/* scroll */

#ranking-scroll-container {
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    margin: 0;
    padding-right: 4px;
    -webkit-overflow-scrolling: touch;

    scrollbar-width: thin;
    scrollbar-color: rgba(0, 255, 255, 0.6) rgba(0, 255, 255, 0.05);

    /* 親(ranking-panel)の空きスペースをすべて埋める */
    flex: 1;
    min-height: 0;
    height: 100%;
}

#ranking-scroll-container::-webkit-scrollbar {
    width: 6px;
}

#ranking-scroll-container::-webkit-scrollbar-track {
    background: rgba(0, 255, 255, 0.05);
    border-radius: 3px;
}

#ranking-scroll-container::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 255, 0.5);
    border-radius: 3px;
}

#ranking-scroll-container::-webkit-scrollbar-thumb:hover {
    background: #0ff;
}

/* table */

#ranking-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: calc(16px * var(--ui-scale, 1));
}

#ranking-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    /* グラデーションを適用（透過度 0.9 の黒から 1.0 の黒へ） */
    background: linear-gradient(to bottom, rgba(0, 40, 40, 0.9), rgba(0, 0, 0, 1));
    
    color: #9fefff;
    padding: 12px 10px;
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.16);
}

#ranking-table td {
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding: 10px 10px;
    color: #d7e6ee;
}

#ranking-table tbody tr {
    transition:
        background 0.18s ease,
        transform 0.16s ease;
}

#ranking-table tbody tr:hover {
    background: rgba(0,255,255,0.04);
}

/* columns */

#ranking-table th.col-rank,
#ranking-table td.col-rank {
    width: 64px;
    text-align: center;
}

#ranking-table th.col-name,
#ranking-table td.col-name {
    text-align: left;
}

#ranking-table th.col-stage,
#ranking-table td.col-stage {
    width: 78px;
    text-align: center;
}

#ranking-table th.col-score,
#ranking-table td.col-score {
    width: 118px;
    text-align: right;
}

/* top ranks */

#ranking-table td.rank-1 {
    color: #ffd700;
    text-shadow:
        0 0 8px rgba(255,215,0,0.8),
        0 0 18px rgba(255,215,0,0.35);
    font-weight: bold;
    font-size: 1.12em;
}

#ranking-table td.rank-2 {
    color: #d8dde2;
    text-shadow: 0 0 10px rgba(216,221,226,0.65);
    font-weight: bold;
}

#ranking-table td.rank-3 {
    color: #cd7f32;
    text-shadow: 0 0 10px rgba(205,127,50,0.7);
    font-weight: bold;
}

#ranking-table td.stage-all-clear {
    color: #ffd700;
    font-weight: bold;
    text-shadow: 0 0 8px rgba(255,215,0,0.45);
}

/* --- ランキング画面のボタン行 --- */
#ranking-overlay .btn-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    width: 100%;
    
    /* 上下の余白を設定 */
    margin-top: 20px;
    margin-bottom: 20px;

    /* ★追加：画面が狭くてもボタン自体は押し潰されないように保護する */
    flex-shrink: 0; 
}


/* ---------- portrait ---------- */
@media (orientation: portrait) {
    #ranking-overlay {
        padding-top: 5vh;
    }

    #ranking-shell {
        min-width: 92vw;
        padding: 10px 10px 8px;
    }

    #ranking-panel {
        width: 90vw;
        padding: 14px 12px 12px;
        border-radius: 3px;
    }

    #loading-ranking {
        font-size: calc(12px * var(--ui-scale, 1));
        margin-bottom: 10px;
        letter-spacing: 0.24em;
    }

    #ranking-table {
        font-size: calc(16px * var(--ui-scale, 1));
    }

    #ranking-table th,
    #ranking-table td {
        padding: 9px 6px;
    }

    #ranking-table th.col-rank,
    #ranking-table td.col-rank {
        width: 52px;
    }

    #ranking-table th.col-stage,
    #ranking-table td.col-stage {
        width: 64px;
    }

    #ranking-table th.col-score,
    #ranking-table td.col-score {
        width: 94px;
    }
}

/* ---------- landscape ---------- */
@media (orientation: landscape) {
    #ranking-overlay {
        padding-top: 4vh;
    }

    #ranking-shell {
        margin-bottom: 10px;
        padding: 6px 14px 6px;
        min-width: min(86vw, 680px);
    }

    #ranking-panel {
        width: min(70vw, 480px);
        padding: 10px 10px 10px;
        border-radius: 3px;
    }

    #loading-ranking {
        margin-bottom: 8px;
        font-size: calc(11px * var(--ui-scale, 1));
        letter-spacing: 0.20em;
    }

    #ranking-table {
        font-size: calc(14px * var(--ui-scale, 1));
    }

    #ranking-table th {
        padding: 8px 8px;
    }

    #ranking-table td {
        padding: 7px 8px;
    }

    #ranking-table th.col-rank,
    #ranking-table td.col-rank {
        width: 50px;
    }

    #ranking-table th.col-stage,
    #ranking-table td.col-stage {
        width: 62px;
    }

    #ranking-table th.col-score,
    #ranking-table td.col-score {
        width: 92px;
    }
}