/* ゲームの描画面をウィンドウに合わせ、縮尺と安全領域はUnity側で統一する。 */
html,
body,
.game-shell {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #0a1426;
    color: #fff5df;
    font-family: system-ui, sans-serif;
}

.game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.game-canvas:focus-visible {
    outline: 2px solid #95dfef;
    outline-offset: -2px;
}

/* ロゴ・進捗・右下のヒントを別の領域へ配置し、低い画面は全体をスクロールできるようにする。 */
.loading-panel {
    --loading-hero: url('Loading/loading-hero.en.webp');
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    box-sizing: border-box;
    overflow: auto;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    background: #0a1426;
    isolation: isolate;
}

.loading-panel [hidden],
.loading-panel[hidden] {
    display: none;
}

html:lang(ja) .loading-panel {
    --loading-hero: url('Loading/loading-hero.ja.webp');
}

html:lang(zh-Hans) .loading-panel {
    --loading-hero: url('Loading/loading-hero.zh-Hans.webp');
}

html:lang(zh-Hant) .loading-panel {
    --loading-hero: url('Loading/loading-hero.zh-Hant.webp');
}

/* 原画のぼかしを画面全体へ敷き、中央の原画を縮小しても周囲の世界観を維持する。 */
.loading-backdrop {
    position: fixed;
    inset: -1rem;
    z-index: -1;
    pointer-events: none;
    background-image: linear-gradient(180deg, rgb(7 16 33 / 40%), #071021), var(--loading-hero);
    background-position: center;
    background-size: cover;
    filter: blur(10px);
}

/* ロゴ専用の画像領域を確保し、進捗パネルが大きいロゴへ重ならないようにする。 */
.loading-art {
    position: relative;
    flex: 1 0 10rem;
    align-self: stretch;
    min-height: 10rem;
}

.loading-hero {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 35%;
}

/* 視覚上の題名を重複させず、画像取得失敗時にも見出しの意味を保つ。 */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* 高い不透明度の面と枠で、明暗の激しい原画から進捗を独立させる。 */
.loading-card {
    flex: 0 0 auto;
    box-sizing: border-box;
    width: min(100%, 38rem);
    padding: 0.5rem 1.25rem 1rem;
    border: 1px solid #8c7447;
    border-radius: 1.25rem;
    background: rgb(10 20 38 / 96%);
    box-shadow: 0 0.5rem 2rem rgb(0 0 0 / 35%);
    text-align: center;
}

/* スプライト全体は動かさず、元ゲームの足・腕・胴体の歩行だけをループする。 */
.loading-boss {
    width: 88px;
    height: 88px;
    margin: 0 auto;
    background: url('Loading/boss-walk.png') left center / 1200% 100% no-repeat;
    animation: loading-boss-walk 1s steps(12) infinite;
    filter: drop-shadow(0 5px 5px rgb(0 0 0 / 35%));
}

@keyframes loading-boss-walk {
    to { background-position: 109.090909% center; }
}

.loading-status-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.625rem;
    text-align: left;
}

/* 翻訳内の意味単位の改行を保ち、狭い画面でも長い案内を折り返す。 */
.loading-label {
    min-width: 0;
    margin: 0;
    white-space: pre-line;
    overflow-wrap: anywhere;
    line-height: 1.6;
}

.loading-percent {
    flex: 0 0 auto;
    color: #ffcf78;
    font-size: 1.125rem;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}

/* ブラウザー既定色に依存せず、バーの輪郭・背景・到達部分を十分に区別する。 */
.loading-progress {
    display: block;
    box-sizing: border-box;
    width: 100%;
    height: 0.875rem;
    overflow: hidden;
    appearance: none;
    border: 1px solid #9a8764;
    border-radius: 999px;
    background: #263247;
    accent-color: #ffcb6c;
}

.loading-progress::-webkit-progress-bar {
    border-radius: 999px;
    background: #263247;
}

.loading-progress::-webkit-progress-value {
    border-radius: 999px;
    background: linear-gradient(90deg, #f5a83f, #ffe2a0);
}

.loading-progress::-moz-progress-bar {
    border-radius: 999px;
    background: linear-gradient(90deg, #f5a83f, #ffe2a0);
}

/* ヒントは右下、戻る導線は左下へ置き、狭幅では下段の右端へヒントを保つ。 */
.loading-footer {
    display: flex;
    flex: 0 0 auto;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    width: 100%;
}

.loading-tips {
    box-sizing: border-box;
    width: min(100%, 29rem);
    margin-left: auto;
    padding: 0.75rem 1rem;
    border: 1px solid #3c5067;
    border-radius: 0.875rem;
    background: #14243a;
    box-shadow: 0 0.5rem 2rem rgb(0 0 0 / 25%);
}

.loading-tip-label {
    color: #ffcf78;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

/* 一文のヒントは通常幅で一行、狭幅では省略せず自然に折り返す。 */
.loading-tip {
    min-height: 3.3em;
    margin: 0.375rem 0 0;
    font-size: 0.9375rem;
    line-height: 1.65;
    overflow-wrap: anywhere;
    text-wrap: pretty;
}

.loading-delay {
    margin: 0.875rem 0 0;
    color: #e3d2b4;
    font-size: 0.875rem;
    white-space: pre-line;
    overflow-wrap: anywhere;
    line-height: 1.6;
}

.reload-button {
    min-height: 44px;
    margin-top: 1rem;
    padding: 0.75rem 2rem;
    border: 0;
    border-radius: 0.75rem;
    background: #ffc25b;
    color: #342421;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

/* 読み込みパネル内だけに戻る導線を置き、プレイ中のCanvasへ重ねない。 */
.loading-links {
    display: flex;
    align-items: center;
    gap: 0.125rem 1.5rem;
    flex-wrap: wrap;
}

.loading-links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: #b4e6f2;
    font-size: 0.8125rem;
    overflow-wrap: anywhere;
    text-underline-offset: 0.2em;
}

.loading-links a:focus-visible,
.reload-button:focus-visible {
    outline: 2px solid #95dfef;
    outline-offset: 3px;
    border-radius: 0.25rem;
}

.loading-panel[data-state='error'] .loading-status-line {
    justify-content: center;
    margin-top: 0.75rem;
    text-align: center;
}

@media (max-width: 480px) {
    .loading-card {
        padding-inline: 1rem;
        border-radius: 1rem;
    }

    .loading-tip {
        min-height: 4.95em;
    }
}

/* 低い横画面では装飾と余白を縮め、ロゴを完全表示する領域を確保する。 */
@media (max-height: 540px) and (min-width: 481px) {
    .loading-panel {
        gap: 0.5rem;
        padding-block: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-bottom));
    }

    .loading-art {
        flex-basis: 5rem;
        min-height: 5rem;
    }

    /* 低い横画面は原画全体を縮小して、ロゴが上下で欠けるのを防ぐ。 */
    .loading-hero {
        object-fit: contain;
        object-position: center;
    }

    .loading-card {
        padding-block: 0.25rem 0.625rem;
    }

    .loading-boss {
        width: 48px;
        height: 48px;
    }

    .loading-tips {
        padding-block: 0.5rem;
    }

    .loading-tip {
        min-height: 1.65em;
    }
}

/* OSの動き軽減設定では歩行を静止し、ヒントの自動切替もJS側で停止する。 */
@media (prefers-reduced-motion: reduce) {
    .loading-boss {
        animation: none;
    }
}

@media (forced-colors: active) {
    .loading-card,
    .loading-tips {
        background: Canvas;
        border-color: CanvasText;
    }

    .loading-progress {
        appearance: auto;
    }
}
