/* =========================================================
   5. ストーリー表示用オーバーレイ
   ========================================================= */
#story-typing-container {
    display: none;    /* 初期状態は非表示 */
    opacity: 0;        /* 初期状態は透明 */
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    z-index: 2000;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    box-sizing: border-box;
    transition: opacity 0.5s ease-in-out;
}

#story-typing-msg {
    position: absolute;
    text-align: left;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    color: #0f8;
    text-shadow: 0 0 5px #0f8;
    white-space: pre-wrap;
    pointer-events: none;
    overflow-y: visible;
    box-sizing: border-box;
}

/* ---------- エンディング専用 ---------- */
#story-typing-container.ending-mode {
    justify-content: flex-start;
    align-items: center;
    padding-right: 0;
    padding-left: 0;
    box-sizing: border-box;
    overflow: hidden;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.10) 0%,
        rgba(0, 0, 0, 0.04) 18%,
        rgba(0, 0, 0, 0.04) 82%,
        rgba(0, 0, 0, 0.12) 100%
    );
}

#story-typing-container.ending-mode #story-typing-msg {
    position: relative;
    margin: 0;
    pointer-events: auto;
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    color: #eafcff;
    text-align: left;
    font-family: 'Courier New', Courier, monospace;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-shadow:
        0 0 4px rgba(255, 255, 255, 0.35),
        0 0 10px rgba(0, 255, 200, 0.18),
        0 0 22px rgba(0, 180, 255, 0.10);
    background: linear-gradient(
        to bottom,
        rgba(8, 18, 24, 0.28) 0%,
        rgba(8, 18, 24, 0.14) 100%
    );
    border: 1px solid rgba(120, 255, 230, 0.18);
    border-radius: 14px;
    box-shadow:
        inset 0 0 24px rgba(120, 255, 230, 0.05),
        0 0 18px rgba(0, 255, 200, 0.05);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    -webkit-mask-image: linear-gradient(
        to bottom,
        transparent 0%,
        #000 6%,
        #000 94%,
        transparent 100%
    );
    mask-image: linear-gradient(
        to bottom,
        transparent 0%,
        #000 6%,
        #000 94%,
        transparent 100%
    );
    scrollbar-width: thin;
    scrollbar-color: rgba(80, 255, 220, 0.55) rgba(255, 255, 255, 0.06);
}

#story-typing-container.ending-mode #story-typing-msg::-webkit-scrollbar {
    width: 10px;
}

#story-typing-container.ending-mode #story-typing-msg::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 999px;
}

#story-typing-container.ending-mode #story-typing-msg::-webkit-scrollbar-thumb {
    background: linear-gradient(
        to bottom,
        rgba(120, 255, 240, 0.70),
        rgba(0, 210, 255, 0.55)
    );
    border-radius: 999px;
    border: 2px solid rgba(0, 0, 0, 0.12);
}

#story-typing-container.ending-mode #story-typing-msg > div {
    min-height: 1.6em;
    margin-bottom: 0.38em;
}

/* ---------- スキップ / NEXT ボタン ---------- */
#skip-button {
    /* 位置の固定（ここは維持） */
    position: fixed;
    bottom: 18px; /* portrait基準 */
    left: 50%;
    transform: translateX(-50%);
    z-index: 2001;

    /* サイズ調整（menu-btnの最小幅を上書きして少しコンパクトに） */
    min-width: 140px;
    height: 40px;
    padding: 0 20px;

    /* ★文字の完全なセンター配置（共通設定の補強） */
    display: flex;
    justify-content: center;
    align-items: center;
    text-indent: 0.16em; /* letter-spacing分のズレを補正 */
    
    /* 角丸を他のボタンと合わせる (4px) */
    border-radius: 4px; 
    
    pointer-events: auto;
    transition: all 0.2s ease;
}

/* ホバー時の挙動を調整（translateXを維持しつつ浮き上がらせる） */
#skip-button:hover {
    transform: translateX(-50%) translateY(-2px);
}

#skip-button:active {
    transform: translateX(-50%) scale(0.96);
}



.cursor-blink {
    animation: blink-anim 0.8s infinite;
    display: inline-block;
    vertical-align: bottom;
    color: #fff;
}

/* =========================================================
   レスポンシブ
   ========================================================= */
@media (orientation: portrait) {
    #story-typing-msg {
        width: 90%;
        max-width: 1100px;
        margin: 0 0 88px 0;
        font-size: calc(17px * var(--ui-scale, 1));
        line-height: 1.75;
    }

    #story-typing-container.ending-mode {
        padding-top: 18px;
        padding-bottom: 88px;
    }

    #story-typing-container.ending-mode #story-typing-msg {
        width: 92vw;
        max-width: 92vw;
        height: calc(100vh - 18px - 88px);
        max-height: calc(100vh - 18px - 88px);
        padding: 14px 14px 16px;
        font-size: calc(16px * var(--ui-scale, 1));
        line-height: 1.78;
    }

    #skip-button {
        bottom: 18px;
        min-width: 124px;
        height: 40px;
        padding: 0 18px;
        font-size: calc(16px * var(--ui-scale, 1));
    }
}

@media (orientation: landscape) {
    #story-typing-msg {
        width: min(75vw, 900px);
        max-width: 900px;
        font-size: calc(17px * var(--ui-scale, 1));
        margin-bottom: 60px;
        line-height: 1.70;
    }

    #story-typing-container.ending-mode {
        padding-top: 17px;
        padding-bottom: 72px;
    }

    #story-typing-container.ending-mode #story-typing-msg {
        /* ★修正：表示幅を狭くする（88vw → 75vw, 1200px → 900px） */
        width: min(75vw, 900px);
        max-width: 900px;
        
        height: calc(100vh - 14px - 72px);
        max-height: calc(100vh - 14px - 72px);
        
        /* ★修正：横の余白を少し増やして読みやすく調整 */
        padding: 12px 24px; 
        
        /* ★修正：文字を少し大きくする（12px → 15px） */
        font-size: calc(16px * var(--ui-scale, 1));
        
        /* 文字が大きくなった分、行間もわずかに広げる */
        line-height: 1.75; 
    }

    #skip-button {
        bottom: 12px;
        min-width: 118px;
        height: 36px;
        padding: 0 16px;
        font-size: calc(16px * var(--ui-scale, 1));
    }
}