/*
 * style.css
 * ----------------------------------------
 * Auto Battle Dungeon 全体のUIを管理する。
 *
 * 主な役割：
 * ・ゲーム画面の基本レイアウト
 * ・ステージ選択画面
 * ・戦闘画面
 * ・HP / 攻撃ゲージ
 * ・敵表示
 * ・戦闘ログ
 * ・勝利 / 敗北表示
 * ・エラー画面
 *
 * JavaScript側ではクラス名を指定するだけにして、
 * 見た目の処理はこのファイルにまとめる。
 * ----------------------------------------
 */


/* ==================================================
   基本設定
   ================================================== */

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;

    width: 100%;
    height: 100%;

    /*
     * ページそのものは縦スクロールさせない。
     *
     * 縦スクロールが必要な場合は、
     * NavigationSystemが作成する各画面Pane側で行う。
     */
    overflow: hidden;
}

body {
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Helvetica Neue",
        Arial,
        sans-serif;

    background: #111827;
    color: #f9fafb;

    /*
     * 横方向のページスクロールも禁止。
     */
    overflow-x: hidden;
    overflow-y: hidden;
}


/*
 * ボタンはiPadなどのタッチ操作でも
 * 押しやすいサイズを確保する。
 */
button {
    min-height: 48px;
    padding: 10px 20px;
    border: 0;
    border-radius: 12px;

    background: #2563eb;
    color: #ffffff;

    font-size: 16px;
    font-weight: 700;

    cursor: pointer;
    touch-action: manipulation;
}


/*
 * ボタンを押せない状態。
 */
button:disabled {
    opacity: 0.5;
    cursor: default;
}


/*
 * キーボード操作などでフォーカスされた場合。
 */
button:focus-visible {
    outline: 3px solid #facc15;
    outline-offset: 3px;
}


/* ==================================================
   ゲーム全体
   ================================================== */

/*
 * ゲーム全体の表示領域。
 *
 * 重要:
 * - 画面全体を100vhに固定する
 * - #game-root自身を縦スクロールさせない
 * - 各画面Pane側で縦スクロールする
 *
 * これにより、
 *
 * ステージ選択を下へスクロール
 * ↓
 * 戦闘画面へ移動
 *
 * した際に、ステージ選択側のスクロール位置が
 * 戦闘画面へ引き継がれることを防ぐ。
 */
#game-root {
    width: 100%;
    height: 100vh;
    min-height: 100vh;

    padding:
        max(16px, env(safe-area-inset-top))
        max(16px, env(safe-area-inset-right))
        max(16px, env(safe-area-inset-bottom))
        max(16px, env(safe-area-inset-left));

    /*
     * NavigationSystemが内部に作る
     * 6画面のトラックだけを表示する。
     *
     * 縦スクロールは各Paneに任せる。
     */
    overflow: hidden;
}


/*
 * 各画面の共通設定。
 */
.screen {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}


/* ==================================================
   ローディング
   ================================================== */

#loading-screen {
    min-height: 70vh;

    display: flex;
    align-items: center;
    justify-content: center;

    text-align: center;
    font-size: 18px;
    color: #d1d5db;
}


/* ==================================================
   共通ヘッダー
   ================================================== */

.screen-header,
.battle-header {
    padding: 16px 0 24px;
    text-align: center;
}

.screen-header h1,
.battle-header h1 {
    margin: 0 0 8px;
    font-size: clamp(24px, 6vw, 36px);
}

.screen-header p,
.battle-header p {
    margin: 0;
    color: #9ca3af;
}


/* ==================================================
   ステージ選択
   ================================================== */

.stage-list {
    display: grid;

    grid-template-columns:
        repeat(
            auto-fit,
            minmax(240px, 1fr)
        );

    gap: 16px;
}

.stage-card {
    padding: 20px;

    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 16px;
}

.stage-card h2 {
    margin: 0 0 12px;
    font-size: 22px;
}

.stage-card p {
    margin: 0 0 20px;
    line-height: 1.6;
    color: #d1d5db;
}

.stage-card button {
    width: 100%;
}


/* ==================================================
   戦闘画面
   ================================================== */

.battle-screen {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.battle-field {
    display: grid;

    grid-template-columns:
        minmax(0, 1fr)
        minmax(0, 1.4fr);

    gap: 16px;
}


/* ==================================================
   主人公 / 敵 共通パネル
   ================================================== */

.player-panel,
.enemy-panel {
    padding: 16px;

    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 16px;
}

.player-panel h2,
.enemy-panel h2 {
    margin: 0 0 16px;
    font-size: 20px;
}


/* ==================================================
   HP表示
   ================================================== */

.hp-text {
    margin-bottom: 12px;
    font-size: 18px;
    font-weight: 700;
}


/* ==================================================
   ゲージ
   ================================================== */

.gauge-label {
    margin-bottom: 6px;
    font-size: 13px;
    color: #9ca3af;
}

.gauge {
    width: 100%;
    height: 14px;

    overflow: hidden;

    background: #111827;
    border-radius: 999px;
}

.gauge-fill {
    width: 0%;
    height: 100%;

    background: #22c55e;
    border-radius: inherit;

    transition:
        width 0.08s linear;
}


/*
 * 敵側のゲージ。
 */
.enemy-gauge {
    background: #ef4444;
}


/* ==================================================
   敵一覧
   ================================================== */

#enemy-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.enemy-card {
    padding: 14px;

    background: #111827;
    border: 1px solid #374151;
    border-radius: 12px;

    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
}

.enemy-card h3 {
    margin: 0 0 8px;
    font-size: 17px;
}

.enemy-card .gauge-label {
    margin-top: 10px;
}

.enemy-status {
    margin-top: 8px;
    font-size: 13px;
    color: #9ca3af;
}


/*
 * 撃破された敵。
 */
.enemy-card.defeated {
    opacity: 0.45;
    transform: scale(0.98);
}

.enemy-card.defeated .enemy-status {
    color: #f87171;
    font-weight: 700;
}


/* ==================================================
   戦闘ログ
   ================================================== */

.battle-log-panel {
    padding: 16px;

    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 16px;
}

.battle-log-panel h2 {
    margin: 0 0 10px;
    font-size: 18px;
}

.battle-log {
    height: 180px;

    overflow-y: auto;

    padding: 10px;

    background: #111827;
    border-radius: 10px;

    -webkit-overflow-scrolling: touch;
}

.battle-log-entry {
    padding: 5px 0;

    font-size: 14px;
    line-height: 1.5;

    color: #d1d5db;

    border-bottom: 1px solid #1f2937;
}

.battle-log-entry:last-child {
    color: #ffffff;
    font-weight: 700;
}


/* ==================================================
   勝利 / 敗北
   ================================================== */

.battle-result-panel {
    padding: 20px;

    background: #1f2937;
    border: 2px solid #4b5563;
    border-radius: 16px;

    text-align: center;
}

.battle-result h2 {
    margin: 0 0 10px;
    font-size: 30px;
}

.battle-result p {
    margin: 0 0 20px;
    color: #d1d5db;
}

.battle-result-actions {
    display: flex;
    flex-wrap: wrap;

    justify-content: center;
    gap: 12px;
}


/* ==================================================
   エラー画面
   ================================================== */

#error-screen {
    position: fixed;
    inset: 0;

    z-index: 9999;

    padding: 20px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: rgba(0, 0, 0, 0.8);

    overflow-y: auto;
}

#error-screen[hidden] {
    display: none;
}

#error-panel {
    width: 100%;
    max-width: 700px;

    padding: 24px;

    background: #1f2937;

    border: 2px solid #ef4444;
    border-radius: 16px;

    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.5);
}

#error-panel h1 {
    margin: 0 0 12px;

    color: #f87171;
    font-size: 26px;
}

#error-message {
    margin: 0 0 16px;
    line-height: 1.6;
}

#error-detail {
    max-height: 280px;

    overflow: auto;

    margin: 0 0 16px;
    padding: 12px;

    background: #111827;
    border-radius: 10px;

    white-space: pre-wrap;
    word-break: break-word;

    font-size: 12px;
    line-height: 1.5;

    color: #d1d5db;
}

#error-panel button {
    margin-right: 8px;
    margin-bottom: 8px;
}


/* ==================================================
   iPad / スマートフォン向け
   ================================================== */

@media (max-width: 700px) {

    #game-root {
        padding:
            max(12px, env(safe-area-inset-top))
            max(12px, env(safe-area-inset-right))
            max(12px, env(safe-area-inset-bottom))
            max(12px, env(safe-area-inset-left));
    }

    .battle-field {
        grid-template-columns: 1fr;
    }

    .battle-log {
        height: 160px;
    }

    .battle-result-actions {
        flex-direction: column;
    }

    .battle-result-actions button {
        width: 100%;
    }
}


/* ==================================================
   動きを減らす設定への対応
   ================================================== */

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;

        transition-duration:
            0.01ms !important;

        animation-duration:
            0.01ms !important;

        animation-iteration-count:
            1 !important;
    }
}


/* ==================================================
   設定画面
   ================================================== */

/*
 * 設定画面全体。
 * iPadで見やすいように、カードを縦に並べる。
 */
.settings-screen {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}


/*
 * 設定画面ヘッダー。
 */
.settings-header {
    padding: 16px 0 20px;
    text-align: center;
}

.settings-title-icon {
    margin-right: 8px;
    font-size: 28px;
}

.settings-header h1 {
    margin: 0;
    font-size: clamp(26px, 6vw, 36px);
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}


/*
 * 各設定カテゴリのカード。
 */
.settings-section {
    padding: 18px;

    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 18px;

    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.18);
}

.settings-section h2 {
    margin: 0 0 16px;
    font-size: 20px;
}


/*
 * 設定項目。
 */
.settings-row {
    display: flex;

    align-items: center;
    justify-content: space-between;

    gap: 16px;

    min-height: 58px;
    padding: 10px 0;

    border-bottom: 1px solid #374151;
}

.settings-row:last-child {
    border-bottom: 0;
}

.settings-label {
    min-width: 0;
    font-size: 16px;
    font-weight: 700;
}


/*
 * ON / OFF ボタン。
 */
.settings-toggle-button {
    flex-shrink: 0;

    min-width: 90px;
    min-height: 48px;

    border-radius: 999px;

    font-size: 15px;

    transition:
        transform 0.12s ease,
        background 0.12s ease;
}

.settings-toggle-button.is-on {
    background: #22c55e;
    color: #ffffff;
}

.settings-toggle-button.is-off {
    background: #4b5563;
    color: #d1d5db;
}

.settings-toggle-button:active {
    transform: scale(0.96);
}


/*
 * 音量設定。
 */
.settings-volume-row {
    display: flex;

    align-items: center;

    gap: 12px;

    padding-top: 14px;
}

.settings-volume-control {
    flex: 1;
    min-width: 0;
}

.settings-volume-slider {
    width: 100%;
    height: 8px;

    accent-color: #2563eb;

    cursor: pointer;
}

.settings-value {
    flex-shrink: 0;

    min-width: 52px;

    text-align: right;

    font-weight: 700;
}


/*
 * 戦闘速度設定。
 */
.settings-speed-block {
    padding-top: 6px;
}

.settings-speed-list {
    display: grid;

    grid-template-columns:
        repeat(4, minmax(0, 1fr));

    gap: 10px;

    margin-top: 12px;
}

.settings-speed-button {
    min-height: 54px;
    padding: 8px;

    background: #374151;

    border: 2px solid transparent;
    border-radius: 14px;

    color: #ffffff;

    font-size: 16px;
    font-weight: 700;
}

.settings-speed-button.is-selected {
    background: #2563eb;

    border-color: #93c5fd;

    box-shadow:
        0 0 0 2px rgba(37, 99, 235, 0.25);
}

.settings-speed-button.is-locked {
    background: #111827;

    color: #6b7280;

    border-color: #374151;

    cursor: not-allowed;
}


/*
 * 設定画面の説明文。
 */
.settings-description {
    margin: 8px 0 0;

    color: #9ca3af;

    font-size: 13px;
    line-height: 1.5;
}


/*
 * データリセットなどの危険操作。
 */
.settings-danger-section {
    border-color: #7f1d1d;
}

.settings-reset-button {
    width: 100%;
    margin-top: 8px;

    background: #b91c1c;
    color: #ffffff;
}

.settings-reset-button:active {
    transform: scale(0.98);
}


/* ==================================================
   設定画面 iPad / スマートフォン対応
   ================================================== */

@media (max-width: 700px) {

    .settings-section {
        padding: 16px;
        border-radius: 16px;
    }

    .settings-row {
        align-items: flex-start;
    }

    .settings-speed-list {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }

    .settings-toggle-button {
        min-width: 84px;
    }
}


/*
 * 横幅がかなり狭い場合。
 */
@media (max-width: 420px) {

    .settings-row {
        flex-direction: column;
        align-items: stretch;
    }

    .settings-toggle-button {
        width: 100%;
    }

    .settings-value {
        text-align: left;
    }
}