/* ===========================================
   🌟 ヘッダー制御（改善版）
   =========================================== */

.header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 8000 !important;
    
    /* 🔥 スムーズトランジション */
    transition: 
        transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.3s ease !important;
    
    /* 🚀 GPU アクセラレーション */
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    
    /* 初期状態：表示 */
    transform: translateY(0) translateZ(0);
    opacity: 1;
}

/* 🎯 ヘッダー表示状態（明示的） */
.header.header-visible {
    transform: translateY(0) translateZ(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* 🎯 ヘッダー非表示状態 */
.header.header-hidden {
    transform: translateY(-100%) translateZ(0) !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ===========================================
   🌟 タブバー制御（改善版）
   =========================================== */

.native-tab-bar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 7000 !important;
    
    /* 🔥 スムーズトランジション */
    transition: 
        transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.3s ease !important;
    
    /* 🚀 GPU アクセラレーション */
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    
    /* 初期状態：表示 */
    transform: translateY(0) translateZ(0);
    opacity: 1;
}

/* 🎯 タブバー表示状態（明示的） */
.native-tab-bar.tab-bar-visible {
    transform: translateY(0) translateZ(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* 🎯 タブバー非表示状態 */
.native-tab-bar.tab-bar-hidden {
    transform: translateY(100%) translateZ(0) !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ===========================================
   🌟 スクロール中の視覚効果
   =========================================== */

/* ヘッダー：スクロール中は影を追加 */
body.scrolling .header {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
}

/* タブバー：スクロール中は影を追加 */
body.scrolling .native-tab-bar {
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15) !important;
}

/* ===========================================
   🌟 トップ付近での特別処理
   =========================================== */

/* トップ100px以内では常に表示 */
body.at-top .header,
body.at-top .native-tab-bar {
    transform: translateY(0) translateZ(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* ===========================================
   📱 モバイル専用最適化
   =========================================== */

@media (max-width: 768px) {
    /* モバイルではより滑らかに */
    .header {
        transition: 
            transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
            opacity 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
    }
    
    .native-tab-bar {
        transition: 
            transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
            opacity 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
    }
    
    /* 🔥 Safari対策：バウンススクロール無効化 */
    body {
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }
}

/* ===========================================
   🌟 パフォーマンス最適化
   =========================================== */

/* スクロール時のリペイント最小化 */
.header *,
.native-tab-bar * {
    will-change: auto; /* 子要素は最適化しない */
}

/* トランジション中のちらつき防止 */
.header,
.native-tab-bar {
    -webkit-transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    -webkit-perspective: 1000;
}

/* ===========================================
   🎯 アクセシビリティ対応
   =========================================== */

/* フォーカス時は常に表示 */
.header:focus-within,
.native-tab-bar:focus-within {
    transform: translateY(0) translateZ(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* キーボードナビゲーション時 */
body.user-is-tabbing .header,
body.user-is-tabbing .native-tab-bar {
    transition: none !important; /* 即座に表示 */
}

/* ===========================================
   🌟 ダークモード対応
   =========================================== */

.dark-mode .header {
    background: linear-gradient(135deg, 
        rgba(26, 26, 26, 0.98) 0%, 
        rgba(30, 30, 40, 0.98) 100%) !important;
    backdrop-filter: blur(20px);
}

.dark-mode .native-tab-bar {
    background: rgba(26, 26, 26, 0.98) !important;
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===========================================
   🔧 デバッグモード（開発時のみ）
   =========================================== */

body.debug-scroll .header::before,
body.debug-scroll .native-tab-bar::before {
    content: attr(data-state);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    z-index: 10000;
    pointer-events: none;
}

/* ===========================================
   🎨 追加のスムーズ効果
   =========================================== */

/* ヘッダー出現時の微妙な拡大効果 */
.header.header-visible {
    animation: headerSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes headerSlideIn {
    0% {
        transform: translateY(-100%) translateZ(0);
        opacity: 0;
    }
    50% {
        transform: translateY(-5%) translateZ(0);
        opacity: 0.7;
    }
    100% {
        transform: translateY(0) translateZ(0);
        opacity: 1;
    }
}

/* タブバー出現時の微妙な拡大効果 */
.native-tab-bar.tab-bar-visible {
    animation: tabBarSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes tabBarSlideIn {
    0% {
        transform: translateY(100%) translateZ(0);
        opacity: 0;
    }
    50% {
        transform: translateY(5%) translateZ(0);
        opacity: 0.7;
    }
    100% {
        transform: translateY(0) translateZ(0);
        opacity: 1;
    }
}

/* ===========================================
   🌟 レスポンシブブレークポイント
   =========================================== */

/* タブレット */
@media (min-width: 769px) and (max-width: 1024px) {
    .header {
        transition: 
            transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
            opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
}

/* デスクトップ */
@media (min-width: 1025px) {
    .native-tab-bar {
        display: none !important; /* デスクトップでは非表示 */
    }
    
    .header {
        transition: 
            transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
            opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
}

/* ===========================================
   🔥 重要：既存のscroll-header-tabbar-complete.cssを上書き
   =========================================== */

/* 既存の定義があればこちらを優先 */
.header.header-visible,
.header.header-hidden,
.native-tab-bar.tab-bar-visible,
.native-tab-bar.tab-bar-hidden {
    all: unset; /* リセット */
}
