@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@500;700&family=Zen+Kaku+Gothic+New:wght@400;500;700&family=Zen+Old+Mincho:wght@400;500;600;700&display=swap');

/* ==========================================
   オープニングシネマ（短い自動詩）
========================================== */

/* 動画・シネマ中：ヘッダーと装飾を隠して没入 */
body.video-phase .header,
body.video-phase .site-scene,
body.video-phase .site-bg,
body.video-phase .overlay,
body.journey-immersive .header,
body.journey-immersive .site-scene,
body.journey-immersive .site-bg,
body.journey-immersive .overlay {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.45s ease;
}

/* 動画フェード中：黒レイヤーの下に宇宙背景を出して真っ黒フレームを防ぐ */
body.opening-active.hub-ready .header,
body.opening-active.hub-ready .site-scene,
body.opening-active.hub-ready .site-bg,
body.opening-active.hub-ready .overlay {
    opacity: 1;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

body.opening-active.hub-ready .header {
    pointer-events: auto;
}

body.journey-immersive {
    overflow: hidden;
}

/* オープニング・スキップ：映像の上に置く小さな映画クレジット調 */
.opening-skip {
    position: fixed;
    top: auto;
    right: max(22px, env(safe-area-inset-right));
    bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px));
    z-index: 100000;
    appearance: none;
    border: none;
    background: transparent;
    color: rgba(236, 220, 168, 0.9);
    font-family: "Orbitron", sans-serif;
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.32em;
    line-height: 1;
    padding: 0.85rem 0.15rem 0.55rem;
    min-height: 44px;
    min-width: 44px;
    cursor: pointer;
    text-shadow: 0 1px 10px rgba(0, 0, 0, 0.7);
    animation: opening-skip-in 0.85s ease 0.55s both;
    transition: color 0.25s ease, opacity 0.3s ease;
}

.opening-skip::after {
    content: "";
    display: block;
    width: 100%;
    height: 1px;
    margin: 0.55rem auto 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(212, 181, 106, 0.85) 22%,
        rgba(212, 181, 106, 0.85) 78%,
        transparent
    );
    transform: scaleX(0.42);
    transform-origin: center;
    transition: transform 0.35s ease;
}

.opening-skip:hover,
.opening-skip:focus-visible {
    color: #f6e7b6;
    background: transparent;
    border: none;
    outline: none;
}

.opening-skip:hover::after,
.opening-skip:focus-visible::after {
    transform: scaleX(1);
}

.opening-skip[hidden] {
    display: none !important;
}

@keyframes opening-skip-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .opening-skip {
        animation: none;
    }
}

/* シネマ退出中：下層の宇宙背景を先に見せ、白フラッシュを防ぐ */
body.journey-exiting .site-bg,
body.journey-exiting .site-scene,
body.journey-exiting .overlay {
    opacity: 1 !important;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

body.journey-exiting .header {
    opacity: 1 !important;
    pointer-events: auto;
    transition: opacity 0.45s ease;
}

#mugenJourney.is-fading-out {
    transition: opacity 0.65s ease;
    opacity: 0;
    /* fade中も下地は黒（透過で白が出ない） */
    background: #060a12 !important;
}

#mugenJourney.is-dismissed {
    display: none !important;
}

body.has-mugen-journey .header,
body.has-mugen-journey .site-scene,
body.has-mugen-journey .site-bg {
    transition: opacity 0.45s ease;
}

body.has-mugen-journey {
    background-color: #060a12;
}

/* =========================
   固定フルビューステージ
========================= */

#mugenJourney.mugen-cinema {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    z-index: 90000;
    pointer-events: none;
    background: #071018;
}

body.journey-phase #mugenJourney.mugen-cinema,
body.journey-immersive #mugenJourney.mugen-cinema,
body.cinema-beat-4 #mugenJourney.mugen-cinema {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    transform: none !important;
    pointer-events: auto;
    z-index: 90000;
}

/* =========================
   背景レイヤー
========================= */

.journey-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.48) saturate(0.9) contrast(1.02);
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.9s ease;
}

body.journey-immersive .journey-bg {
    opacity: 1;
}

.journey-deep-space {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    background: radial-gradient(
        ellipse 80% 70% at 50% 45%,
        rgba(28, 48, 90, 0.22) 0%,
        rgba(8, 14, 28, 0.5) 55%,
        rgba(3, 6, 14, 0.82) 100%
    );
    transition: opacity 0.9s ease;
}

body.journey-immersive .journey-deep-space {
    opacity: 1;
}

.journey-deep-space::before {
    content: "";
    position: absolute;
    inset: -20%;
    background: linear-gradient(
        115deg,
        transparent 34%,
        rgba(140, 160, 210, 0.05) 44%,
        rgba(200, 210, 240, 0.1) 50%,
        rgba(140, 160, 210, 0.05) 56%,
        transparent 66%
    );
    filter: blur(8px);
    animation: cinema-sweep 14s ease-in-out infinite;
}

@keyframes cinema-sweep {
    0%, 100% { transform: translateX(-8%); opacity: 0.35; }
    50% { transform: translateX(8%); opacity: 0.55; }
}

.journey-galaxy {
    position: absolute;
    left: 62%;
    top: 40%;
    width: 70vw;
    height: 26vw;
    z-index: 2;
    border-radius: 50%;
    background: radial-gradient(
        ellipse 50% 50% at 50% 50%,
        rgba(255, 245, 225, 0.22) 0%,
        rgba(180, 200, 240, 0.12) 22%,
        rgba(100, 130, 200, 0.06) 42%,
        transparent 70%
    );
    mix-blend-mode: screen;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.9s ease;
}

/* =========================
   詩ステージ（縦書き・左右に散らす）
========================= */

.cinema-stage {
    position: absolute;
    inset: 0;
    z-index: 30;
    pointer-events: none;
}

.cinema-line {
    position: absolute;
    margin: 0;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
    font-size: clamp(1.35rem, 3.8vw, 2.15rem);
    font-weight: 400;
    line-height: 1.9;
    letter-spacing: 0.42em;
    color: var(--hub-ink, #e8eef8);
    text-shadow:
        0 0 48px rgba(140, 180, 255, 0.28),
        0 0 2px rgba(255, 255, 255, 0.12);
    opacity: 0;
    pointer-events: none;
    padding-left: 1.1rem;
    /* filter: blur は GPU で黒画面化しやすいので使わない */
    transition:
        opacity 1.1s cubic-bezier(0.22, 1, 0.36, 1),
        transform 1.1s cubic-bezier(0.22, 1, 0.36, 1),
        letter-spacing 1.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.cinema-line::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 2.8em;
    transform: scaleY(0.2);
    transform-origin: top center;
    background: linear-gradient(
        180deg,
        var(--hub-gold, #d4b56a),
        transparent
    );
    opacity: 0;
    transition:
        opacity 1.15s cubic-bezier(0.22, 1, 0.36, 1) 0.12s,
        transform 1.3s cubic-bezier(0.22, 1, 0.36, 1) 0.12s;
}

.cinema-line--a {
    left: 14%;
    top: 18%;
    transform: translate(-8px, 16px) scale(0.97);
}

.cinema-line--b {
    right: 12%;
    top: 26%;
    left: auto;
    padding-left: 0;
    padding-right: 1.1rem;
    transform: translate(8px, 16px) scale(0.97);
}

.cinema-line--b::before {
    left: auto;
    right: 0;
}

.cinema-line--c {
    left: 58%;
    top: 14%;
    transform: translate(-4px, 18px) scale(0.97);
}

/* フィナーレ：黒地に金字・中央大きく */
.cinema-finale {
    position: absolute;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 1s ease, visibility 1s ease;
}

body.cinema-beat-4 .cinema-finale {
    opacity: 1 !important;
    visibility: visible !important;
}

.cinema-closing {
    position: relative;
    margin: 0;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
    font-size: clamp(2.05rem, 6.2vw, 3.55rem);
    font-weight: 500;
    line-height: 1.95;
    letter-spacing: 0.52em;
    color: var(--hub-gold, #d4b56a);
    text-shadow:
        0 0 1px rgba(255, 236, 200, 0.45),
        0 0 28px rgba(212, 181, 106, 0.22);
}

.cinema-closing::before {
    content: "";
    position: absolute;
    top: 0.15em;
    bottom: 0.15em;
    left: -0.85em;
    width: 1px;
    background: linear-gradient(
        180deg,
        transparent,
        rgba(212, 181, 106, 0.75),
        transparent
    );
}

body.cinema-beat-1 .cinema-line--a,
body.cinema-beat-2 .cinema-line--b,
body.cinema-beat-3 .cinema-line--c {
    opacity: 1;
    letter-spacing: 0.22em;
}

body.cinema-beat-1 .cinema-line--a {
    transform: translate(0, 0) scale(1);
}

body.cinema-beat-2 .cinema-line--b {
    transform: translate(0, 0) scale(1);
}

body.cinema-beat-3 .cinema-line--c {
    transform: translate(0, 0) scale(1);
}

body.cinema-beat-1 .cinema-line--a::before,
body.cinema-beat-2 .cinema-line--b::before,
body.cinema-beat-3 .cinema-line--c::before {
    opacity: 0.85;
    transform: scaleY(1);
}

/* 前の詩はゆっくり消す */
body.cinema-beat-4 .cinema-line {
    opacity: 0;
    pointer-events: none;
}

/* フィナーレ：宇宙をフェードアウトして黒地へ */
body.cinema-beat-4 .journey-bg,
body.cinema-beat-4 .journey-deep-space,
body.cinema-beat-4 .journey-stars,
body.cinema-beat-4 .journey-stars-far,
body.cinema-beat-4 .journey-nebula-field,
body.cinema-beat-4 .journey-galaxy,
body.cinema-beat-4 .journey-vignette {
    opacity: 0 !important;
    transition: opacity 1.1s ease !important;
}

body.cinema-beat-4 #mugenJourney.mugen-cinema {
    background: #000;
}

/* ビートごとの宇宙トーン（中央グローは控えめ） */
body.cinema-beat-1 .journey-deep-space {
    background: radial-gradient(
        ellipse 80% 70% at 50% 45%,
        rgba(30, 48, 90, 0.22) 0%,
        rgba(8, 14, 28, 0.55) 60%,
        rgba(2, 5, 12, 0.88) 100%
    );
}

body.cinema-beat-2 .journey-deep-space {
    background: radial-gradient(
        ellipse 75% 65% at 50% 42%,
        rgba(40, 70, 130, 0.2) 0%,
        rgba(8, 14, 30, 0.55) 55%,
        rgba(2, 5, 12, 0.88) 100%
    );
}

body.cinema-beat-3 .journey-deep-space {
    background: radial-gradient(
        ellipse 70% 60% at 50% 50%,
        rgba(60, 100, 180, 0.16) 0%,
        rgba(10, 18, 40, 0.55) 50%,
        rgba(2, 5, 12, 0.9) 100%
    );
}

/* =========================
   星・星雲・ビネット
========================= */

.journey-stars {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    background:
        radial-gradient(
            ellipse 55% 45% at 50% 50%,
            rgba(90, 140, 255, 0.035) 0%,
            transparent 55%
        );
    transition: opacity 0.9s ease;
}

body.journey-immersive .journey-stars {
    opacity: 1;
}

.journey-stars span {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 2px;
    height: 2px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(200, 220, 255, 0.25) 45%,
        rgba(255, 255, 255, 0.92) 100%
    );
    border-radius: 999px;
    transform-origin: left center;
}

.journey-stars-far {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    background-image:
        radial-gradient(1px 1px at 12% 18%, rgba(255, 255, 255, 0.85), transparent),
        radial-gradient(1px 1px at 28% 72%, rgba(200, 220, 255, 0.7), transparent),
        radial-gradient(1.5px 1.5px at 44% 32%, rgba(255, 255, 255, 0.9), transparent),
        radial-gradient(1px 1px at 61% 58%, rgba(180, 210, 255, 0.65), transparent),
        radial-gradient(1px 1px at 76% 22%, rgba(255, 255, 255, 0.75), transparent),
        radial-gradient(1.5px 1.5px at 88% 80%, rgba(200, 230, 255, 0.7), transparent),
        radial-gradient(1px 1px at 8% 88%, rgba(255, 255, 255, 0.6), transparent),
        radial-gradient(1px 1px at 52% 8%, rgba(220, 235, 255, 0.8), transparent),
        radial-gradient(1px 1px at 33% 48%, rgba(255, 255, 255, 0.55), transparent),
        radial-gradient(1.5px 1.5px at 70% 40%, rgba(190, 215, 255, 0.7), transparent),
        radial-gradient(1px 1px at 18% 42%, rgba(255, 255, 255, 0.7), transparent),
        radial-gradient(1px 1px at 39% 84%, rgba(210, 225, 255, 0.6), transparent),
        radial-gradient(1.5px 1.5px at 57% 14%, rgba(255, 255, 255, 0.8), transparent),
        radial-gradient(1px 1px at 66% 76%, rgba(185, 210, 255, 0.6), transparent),
        radial-gradient(1px 1px at 83% 46%, rgba(255, 255, 255, 0.7), transparent),
        radial-gradient(1px 1px at 95% 30%, rgba(210, 230, 255, 0.65), transparent),
        radial-gradient(1px 1px at 4% 54%, rgba(255, 255, 255, 0.6), transparent),
        radial-gradient(1.5px 1.5px at 48% 62%, rgba(230, 240, 255, 0.75), transparent),
        radial-gradient(1px 1px at 24% 6%, rgba(255, 255, 255, 0.65), transparent),
        radial-gradient(1px 1px at 72% 92%, rgba(200, 220, 255, 0.6), transparent);
    background-size: 100% 100%;
    transform-origin: center center;
    transition: opacity 0.25s ease;
}

body.journey-immersive .journey-stars-far {
    opacity: 0.6;
}

.journey-nebula-field {
    position: absolute;
    inset: 0;
    z-index: 2;
    overflow: hidden;
    pointer-events: none;
}

.journey-nebula-field .nebula {
    position: absolute;
    width: 70vw;
    height: 70vw;
    border-radius: 50%;
    background: radial-gradient(
        circle at 50% 50%,
        var(--core, rgba(150, 120, 255, 0.22)) 0%,
        var(--edge, rgba(90, 70, 200, 0.08)) 42%,
        transparent 72%
    );
    opacity: 0;
    mix-blend-mode: screen;
    transition: opacity 0.9s ease;
}

body.journey-warp .journey-stars {
    background:
        radial-gradient(
            ellipse 60% 50% at 50% 50%,
            rgba(140, 180, 255, 0.06) 0%,
            transparent 60%
        );
}

body.journey-warp .journey-vignette {
    background: radial-gradient(
        ellipse 72% 62% at 50% 50%,
        transparent 40%,
        rgba(0, 0, 0, 0.35) 100%
    );
}

.journey-vignette {
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
    opacity: 0;
    background: radial-gradient(
        ellipse 75% 65% at 50% 50%,
        transparent 45%,
        rgba(0, 0, 0, 0.28) 100%
    );
    transition: opacity 0.35s ease;
}

body.journey-immersive .journey-vignette {
    opacity: 1;
}

/* 完了後は固定レイヤーを隠す */
body.journey-done .journey-bg,
body.journey-done .journey-deep-space,
body.journey-done .journey-stars,
body.journey-done .journey-stars-far,
body.journey-done .journey-nebula-field,
body.journey-done .journey-galaxy,
body.journey-done .journey-vignette,
body.journey-done .cinema-stage {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden;
}

@media (max-width: 768px) {
    .cinema-line {
        font-size: clamp(1.15rem, 5.2vw, 1.55rem);
        letter-spacing: 0.32em;
    }

    body.cinema-beat-1 .cinema-line--a,
    body.cinema-beat-2 .cinema-line--b,
    body.cinema-beat-3 .cinema-line--c {
        letter-spacing: 0.16em;
    }

    .cinema-line--a {
        left: 10%;
        top: 16%;
    }

    .cinema-line--b {
        right: 8%;
        top: 24%;
    }

    .cinema-line--c {
        left: 52%;
        top: 12%;
    }

    .cinema-closing {
        letter-spacing: 0.4em;
        font-size: clamp(1.8rem, 7.8vw, 2.7rem);
        font-weight: 500;
    }

    .cinema-finale {
        padding: 1rem;
    }
}
