/* ============================================
   Mobile CSS - TacticsMaker
   モバイル専用（デスクトップには影響なし）
   ============================================ */

/* デスクトップではモバイル要素非表示 */
.mobile-bottom-nav {
    display: none;
}

.mobile-overlay {
    display: none;
}

.show-on-mobile {
    display: none;
}

.mobile-status-tab {
    display: none;
}

.mobile-buff-btn {
    display: none;
}

/* === 縦画面モバイル === */
@media (max-width: 768px) {

    /* show/hide切替 */
    .hide-on-mobile {
        display: none !important;
    }

    .show-on-mobile {
        display: inline !important;
    }

    .mobile-buff-btn {
        display: inline-block !important;
    }

    /* サイドバー非表示 */
    .sidebar {
        display: none !important;
    }

    /* 右パネル: スライドオーバーレイ */
    .right-panel {
        position: fixed !important;
        right: -100%;
        top: 0;
        width: 85% !important;
        max-width: 320px;
        min-width: auto !important;
        height: 100vh !important;
        z-index: 2000;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
    }

    .right-panel.mobile-open {
        right: 0 !important;
    }

    /* オーバーレイ背景（ブラーなし・薄暗く） */
    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 1999;
    }

    .mobile-overlay.active {
        display: block;
    }

    /* メインコンテンツ: フル幅 */
    .main-content {
        width: 100% !important;
        padding: 8px 10px 70px !important;
        height: auto !important;
    }

    /* ダッシュボードレイアウト */
    .dashboard-layout {
        flex-direction: column !important;
        height: auto !important;
        overflow: auto !important;
    }

    /* body: dashboard-layoutのoverflow:hidden上書き */
    /* html:root body.antigravity-scroll-lock の !important を打ち負かすため同等以上の特異度 */
    html:root body,
    html:root body.antigravity-scroll-lock {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        height: auto !important;
        min-height: 100vh !important;
    }

    /* === 栞タブ（右端に常時表示） === */
    .mobile-status-tab {
        display: flex !important;
        position: fixed;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        z-index: 1998;
        writing-mode: vertical-rl;
        background: rgba(255, 0, 51, 0.15);
        border: 1px solid rgba(255, 0, 51, 0.3);
        border-right: none;
        border-radius: 8px 0 0 8px;
        color: #ff4d6d;
        font-size: 0.65rem;
        font-weight: 700;
        padding: 12px 6px;
        cursor: pointer;
        letter-spacing: 2px;
        align-items: center;
        gap: 4px;
        transition: all 0.25s;
        backdrop-filter: blur(12px);
        -webkit-tap-highlight-color: transparent;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
    }

    .mobile-status-tab:active {
        background: rgba(255, 0, 51, 0.3);
        transform: translateY(-50%) scale(0.95);
    }

    .mobile-status-tab .tab-icon {
        writing-mode: horizontal-tb;
        font-size: 0.9rem;
    }

    /* === 下部ナビバー === */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: rgba(8, 8, 18, 0.97);
        border-top: 1px solid rgba(255, 0, 51, 0.2);
        z-index: 1500;
        backdrop-filter: blur(20px);
        padding: 0 4px;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .mobile-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        border: none;
        background: transparent;
        color: rgba(255, 255, 255, 0.45);
        font-size: 0.55rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-nav-btn:active {
        transform: scale(0.9);
    }

    .mobile-nav-btn.active {
        color: #ff0033;
    }

    .mobile-nav-icon {
        font-size: 1.15rem;
        line-height: 1;
    }

    /* ヘルプFAB非表示 */
    .help-fab {
        display: none !important;
    }

    /* モーダル調整 */
    .dashboard-modal-content {
        width: 96% !important;
        max-width: none !important;
        max-height: 88vh !important;
        border-radius: 12px !important;
    }

    .dashboard-modal-content.modal-large {
        width: 98% !important;
    }

    /* ヘッダーコンパクト化 */
    .dashboard-header {
        padding: 6px 10px !important;
        gap: 8px !important;
        border-radius: 6px !important;
        margin-bottom: 6px !important;
    }

    .header-logo-text {
        font-size: 0.85rem !important;
        letter-spacing: 2px !important;
    }

    .header-subtitle {
        display: none !important;
    }

    .header-animation-bar {
        display: none !important;
    }

    /* ステージタイトル */
    .stage-title-bar {
        padding: 4px 10px !important;
        margin-bottom: 8px !important;
    }

    /* セクションコンパクト化 */
    .main-content>section {
        margin-bottom: 8px !important;
        padding: 10px !important;
    }

    .main-content>section>h2 {
        font-size: 0.85rem !important;
        gap: 4px !important;
        flex-wrap: wrap !important;
    }

    /* ターンタブ */
    .turn-tabs {
        gap: 2px !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px !important;
    }

    .turn-tab {
        min-width: 42px !important;
        padding: 5px 8px !important;
        font-size: 0.7rem !important;
        white-space: nowrap;
    }

    /* === アクションカードグリッド（モバイル） === */
    /* 5視覚列: 並び|キャラ(固定)|スキル(可変)|対象+バフ(固定)|ダメージ(固定) */
    .char-action {
        grid-template-columns: 24px 85px 1fr 75px 90px !important;
        grid-template-rows: auto auto !important;
        grid-template-areas:
            "order charinfo skills target damage"
            "order charinfo skills buffs  damage" !important;
        min-height: 40px !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
        width: 100% !important;
        max-width: 100% !important;
        align-items: center !important;
    }

    .action-grid-header {
        grid-template-columns: 24px 85px 1fr 75px 90px !important;
        box-sizing: border-box !important;
        max-width: 100% !important;
    }

    /* ヘッダーのバフ列非表示（統合済み） */
    .action-grid-header>div:nth-child(5) {
        display: none !important;
    }

    /* 対象ゾーン: 上半分 */
    .action-zone-target {
        padding: 2px !important;
        border-right: none !important;
        overflow: hidden !important;
        align-self: end !important;
    }

    /* バフゾーン: 下半分（テキストボタン） */
    .action-zone-buffs {
        padding: 2px !important;
        overflow: hidden !important;
        border-right: none !important;
        justify-content: center !important;
        align-items: center !important;
        align-self: start !important;
    }

    .action-zone-buffs .buff-active {
        display: none !important;
    }

    .action-zone-buffs .buff-display {
        display: none !important;
    }

    /* 元々のバフ詳細ボタン非表示（mobile-buff-btnだけ残す） */
    .action-zone-buffs>button:not(.mobile-buff-btn) {
        display: none !important;
    }

    /* 解明キャラのバフゾーン内容: CSSで即時非表示（JSタイミング待ちによるチラつき防止） */
    [id^="navi-row-"] .action-zone-buffs>*:not(.mobile-buff-btn) {
        display: none !important;
    }

    /* スキルゾーン: 1fr可変（残りスペースを使う） */
    .action-zone-skills {
        padding: 3px 4px !important;
        overflow: hidden !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* ナビ行スキル: 左寄せ */
    .navi-skill-row {
        justify-content: flex-start !important;
        align-items: center !important;
        gap: 4px !important;
        width: 100% !important;
    }

    .navi-skill-buttons {
        gap: 2px !important;
    }

    /* ナビ パッシブ情報（モバイル挿入） */
    .mobile-navi-info {
        width: 100% !important;
        text-align: left !important;
    }

    /* スキルボタン縦並び */
    .action-buttons {
        flex-direction: column !important;
        gap: 2px !important;
    }

    /* キャラ名ゾーン: 85px固定 */
    .action-zone-charinfo {
        padding: 3px 4px !important;
        overflow: hidden !important;
        word-break: break-all !important;
        align-items: center !important;
    }

    .char-name {
        font-size: 0.68rem !important;
        letter-spacing: 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .char-name img {
        width: 20px !important;
        height: 20px !important;
    }

    /* パッシブ情報（銃撃OFF, 強化OFF等）折り返し */
    .char-passive-info {
        font-size: 0.55rem !important;
        word-break: break-all !important;
        line-height: 1.2 !important;
    }

    .action-zone-damage {
        padding: 2px 3px !important;
        overflow: hidden !important;
        justify-content: flex-end !important;
        text-align: right !important;
    }

    .action-zone-order {
        padding: 2px !important;
    }

    /* (char-name は上で定義済み) */

    /* ダメージ表示: 収まる・右寄せ */
    .action-damage {
        font-size: 0.65em !important;
        text-align: right !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    /* ダメージボックス内: min-width・サイズ制約 */
    .action-zone-damage div[style] {
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* statsRow: クリ率/防御を縦並びに（CSS即時適用でチラつき防止） */
    .action-zone-damage div[style*="gap:6px"][style*="font-size"] {
        flex-direction: column !important;
        gap: 1px !important;
        align-items: flex-end !important;
    }

    /* statsRow内の "/"セパレーター非表示 */
    .action-zone-damage div[style*="gap:6px"][style*="font-size"]>span[style*="color:#555"],
    .action-zone-damage div[style*="gap: 6px"][style*="font-size"]>span[style*="color:#555"] {
        display: none !important;
    }

    /* バフゾーン: 最小高さで消失防止 */
    .action-zone-buffs {
        min-height: 22px !important;
    }

    /* スキルボタン: さらにコンパクト */
    .action-btn {
        padding: 3px 6px !important;
        font-size: 0.62rem !important;
        min-width: 28px !important;
    }

    /* ターゲットセレクト: コンパクト */
    .target-select {
        width: 60px !important;
        max-width: 60px !important;
        font-size: 0.62em !important;
        padding: 2px !important;
    }

    /* ナビのターゲットセレクトも同様 */
    .navi-target-select {
        margin-left: 4px !important;
    }

    .navi-target-select select {
        max-width: 60px !important;
        font-size: 0.62em !important;
        padding: 2px !important;
    }

    /* ドラッグハンドル縮小 */
    .drag-handle {
        width: 12px !important;
        min-width: 12px !important;
        font-size: 8px !important;
    }

    /* 上下ボタン縮小 */
    .action-zone-order button {
        width: 14px !important;
        height: 12px !important;
        font-size: 6px !important;
    }

    /* (バフ列ヘッダーは上で処理済み) */

    /* 結果表示 */
    .total-damage {
        font-size: 1.2rem !important;
    }

    .turn-breakdown {
        font-size: 0.75rem !important;
    }

    /* セクションh2内のボタン群 */
    #refreshCalcBtn,
    #resetActionsBtn {
        font-size: 0.55em !important;
        padding: 3px 8px !important;
    }
}

/* === 横画面モバイル === */
@media (max-width: 1024px) and (max-height: 500px) and (orientation: landscape) {

    .hide-on-mobile {
        display: none !important;
    }

    .show-on-mobile {
        display: inline !important;
    }

    /* サイドバー: 縮小表示 */
    .sidebar {
        width: 40px !important;
        min-width: 40px !important;
        padding: 6px 0 !important;
        gap: 2px !important;
    }

    .sidebar-logo {
        font-size: 0.6rem !important;
        margin-bottom: 8px !important;
        padding: 4px 2px !important;
    }

    .sidebar-label {
        display: none !important;
    }

    .sidebar-icon {
        font-size: 1rem !important;
    }

    .sidebar-btn {
        padding: 6px 2px !important;
        border-radius: 6px !important;
    }

    /* 右パネル非表示 (スライドオーバーレイ) */
    .right-panel {
        position: fixed !important;
        right: -100%;
        top: 0;
        width: 280px !important;
        min-width: auto !important;
        height: 100vh !important;
        z-index: 2000;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
    }

    .right-panel.mobile-open {
        right: 0 !important;
    }

    /* メインコンテンツ */
    .main-content {
        padding: 8px 12px !important;
    }

    /* ヘッダーコンパクト */
    .dashboard-header {
        padding: 4px 10px !important;
        margin-bottom: 6px !important;
    }

    /* 下部ナビ非表示(横画面ではサイドバー使用) */
    .mobile-bottom-nav {
        display: none !important;
    }

    /* 栞タブ表示 */
    .mobile-status-tab {
        display: flex !important;
        position: fixed;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        z-index: 1998;
        writing-mode: vertical-rl;
        background: rgba(255, 0, 51, 0.15);
        border: 1px solid rgba(255, 0, 51, 0.3);
        border-right: none;
        border-radius: 8px 0 0 8px;
        color: #ff4d6d;
        font-size: 0.6rem;
        font-weight: 700;
        padding: 10px 5px;
        cursor: pointer;
        letter-spacing: 2px;
        align-items: center;
        gap: 4px;
        transition: all 0.25s;
        backdrop-filter: blur(12px);
        -webkit-tap-highlight-color: transparent;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
    }

    .mobile-status-tab .tab-icon {
        writing-mode: horizontal-tb;
        font-size: 0.8rem;
    }

    /* セクション */
    .main-content>section {
        margin-bottom: 6px !important;
        padding: 8px !important;
    }
}

/* === 横画面スマホ: バフをモーダル式に === */
@media (orientation: landscape) and (max-height: 500px) {
    .mobile-buff-btn {
        display: inline-block !important;
    }

    .action-zone-buffs .buff-active {
        display: none !important;
    }

    .action-zone-buffs .buff-display {
        display: none !important;
    }

    .action-zone-buffs>button:not(.mobile-buff-btn) {
        display: none !important;
    }

    [id^="navi-row-"] .action-zone-buffs>*:not(.mobile-buff-btn) {
        display: none !important;
    }
}