/**
 * TGM Wood Factory - コア機能拡張CSS
 * アニメーション、通知システム、パフォーマンス最適化、配送PR機能を統合
 */

/* =============== ヒーローセクション修正 =============== */

/* 画像の表示問題を修正（PC・モバイル共通） */
.hero .hero-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    object-fit: cover;
}

.hero .hero-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

/* オーバーレイの修正 */
.hero .hero-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1;
}

/* スクロールヒントの修正 */
.hero .scroll-hint {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
}

/* =============== アニメーション・エフェクト =============== */

/* フェードインのみのシンプルなアニメーション */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* 元のfadeInUpアニメーションを上書き - 縦移動を小さくする */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ヒーロータイトルとサブタイトルのアニメーション */
.hero-title {
    animation: fadeIn 1s ease;
}

.hero-subtitle {
    animation: fadeIn 1.2s ease;
}

/* ボタンもフェードインのみに変更 */
.hero-buttons {
    animation: fadeIn 1.3s ease;
}

/* カスタムページのヒーローセクションもフェードインのみ */
.custom-hero .hero-title,
.yndesign-hero-title,
.page-hero-title {
    animation: fadeIn 1s ease;
}

.custom-hero .hero-subtitle,
.yndesign-hero-subtitle,
.page-hero-subtitle {
    animation: fadeIn 1.2s ease;
}

/* カスタムページのスクロールヒントもフェードイン */
.custom-hero .scroll-hint {
    animation: fadeIn 1.3s ease;
}

/* モバイルでの調整 */
@media (max-width: 768px) {
    /* モバイルではアニメーションを少し速く */
    .hero-title,
    .custom-hero .hero-title {
        animation: fadeIn 0.8s ease;
    }
    
    .hero-subtitle,
    .custom-hero .hero-subtitle {
        animation: fadeIn 1s ease;
    }
}

/* フォント読み込み完了時のスムーズな表示 */
.fonts-loaded .hero-title,
.fonts-loaded .hero-subtitle {
    /* フォントが読み込まれたらすぐに表示 */
    transition: opacity 0.3s ease;
}

/* パフォーマンス最適化 */
.hero-title,
.hero-subtitle,
.hero-buttons,
.scroll-hint {
    will-change: opacity;
}

/* アニメーション完了後のwill-changeをリセット */
.hero-title.animated,
.hero-subtitle.animated,
.hero-buttons.animated,
.scroll-hint.animated {
    will-change: auto;
}

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

/* 画像遅延読み込み */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* 読み込み完了時のフェードイン */
img.lazy-loaded {
    opacity: 1;
}

/* プレースホルダー画像のぼかしエフェクト */
.lazy-placeholder {
    filter: blur(5px);
    transform: scale(1.05);
    transition: filter 0.3s, transform 0.3s;
}

.lazy-placeholder.lazy-loaded {
    filter: blur(0);
    transform: scale(1);
}

/* 画像コンテナのアスペクト比保持 - 特定のクラスのみに適用 */
.image-container.lazy-aspect-ratio {
    position: relative;
    background-color: #f5f5f5;
    overflow: hidden;
}

.image-container.lazy-aspect-ratio img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 一般的なアスペクト比 */
.aspect-ratio-16-9 {
    padding-bottom: 56.25%; /* 16:9 */
}

.aspect-ratio-4-3 {
    padding-bottom: 75%; /* 4:3 */
}

.aspect-ratio-1-1 {
    padding-bottom: 100%; /* 1:1 */
}

/* GPU加速を使用したアニメーション */
.gpu-accelerated {
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* 軽量なホバーエフェクト */
.light-hover {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.light-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* アニメーションの最適化 */
@media (prefers-reduced-motion: no-preference) {
    .smooth-scroll {
        scroll-behavior: smooth;
    }
}

/* モバイルでのアニメーション簡素化 */
@media (max-width: 768px) {
    .animate, .animated {
        animation-duration: 0.15s !important;
        transition-duration: 0.15s !important;
    }

    .light-hover:hover {
        transform: none;
    }
}

/* フォントの表示最適化 */
.font-display-swap {
    font-display: swap;
}

/* レイアウトシフトの防止 - 遅延読み込み画像のみ */
img[loading="lazy"] {
    max-width: 100%;
    height: auto;
}

/* アイコンフォントの事前読み込み */
.preload-icons {
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    content: '\f015'; /* 事前読み込み用の文字 */
    position: absolute;
    left: -9999px;
}

/* Critical CSS */
.critical-hero {
    min-height: 100vh;
    background-color: #f9f4ef;
}

/* .critical-header を無効化 - ヘッダーの透明効果を妨げるため */
/*
.critical-header {
    position: fixed;
    top: 0;
    width: 100%;
    background-color: white;
    z-index: 1000;
}
*/

/* ローディングスピナー */
.loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    display: none;
}

.loading-spinner::after {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid #f3f3f3;
    border-top-color: #9b7653;
    animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
    to { transform: rotate(360deg); }
}

/* ページ読み込み中の表示 */
body.loading {
    overflow: hidden;
}

body.loading .loading-spinner {
    display: block;
}

/* キャッシュ可能なアセット */
.cacheable {
    /* ブラウザキャッシュヒント */
}

/* 動的コンテンツ（キャッシュしない） */
.no-cache {
    /* キャッシュ無効化ヒント */
}

/* =============== 通知システム =============== */

/* 通知コンテナ */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    max-width: 400px;
    padding: 15px 20px;
    margin-bottom: 10px;
    border-radius: 5px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    animation: slideIn 0.3s ease;
    font-family: var(--font-primary);
    font-size: 14px;
    line-height: 1.5;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* 通知タイプ別スタイル */
.notification-error {
    background-color: #fee;
    border-left: 4px solid #f44336;
    color: #721c24;
}

.notification-warning {
    background-color: #fff3cd;
    border-left: 4px solid #ffc107;
    color: #856404;
}

.notification-success {
    background-color: #d4edda;
    border-left: 4px solid #28a745;
    color: #155724;
}

.notification-info {
    background-color: #d1ecf1;
    border-left: 4px solid #17a2b8;
    color: #0c5460;
}

/* 通知コンテンツ */
.notification-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.notification-content p {
    margin: 0;
    flex: 1;
}

/* 閉じるボタン */
.notification-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    margin-left: 15px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.notification-close:hover {
    opacity: 1;
}

/* モバイル対応 */
@media (max-width: 768px) {
    .notification {
        left: 10px;
        right: 10px;
        max-width: none;
    }
}

/* フォームエラー表示 */
.form-error {
    color: #721c24;
    font-size: 12px;
    margin-top: 5px;
    display: block;
}

.form-group.has-error input,
.form-group.has-error textarea,
.form-group.has-error select {
    border-color: #f44336;
}

/* エラーサマリー */
.error-summary {
    background-color: #fee;
    border: 1px solid #fcc;
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 20px;
}

.error-summary h3 {
    color: #721c24;
    margin: 0 0 10px 0;
    font-size: 16px;
}

.error-summary ul {
    margin: 0;
    padding-left: 20px;
}

.error-summary li {
    color: #721c24;
    margin-bottom: 5px;
}

/* 成功メッセージ */
.success-message {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 20px;
    color: #155724;
}

/* ローディング表示 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    display: none;
}

.loading-overlay.active {
    display: flex;
}

.loading-overlay .loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: static;
    transform: none;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =============== 配送・プロモーション =============== */

/* 配送情報バナー */
.shipping-banner {
    background: linear-gradient(135deg, #9b7653 0%, #cda67f 100%);
    color: white;
    text-align: center;
    padding: 0.3rem 1rem;
    font-weight: 500;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1001; /* ヘッダーより高く */
    min-height: auto;
    line-height: 1.1;
    font-size: 0.85rem;
    height: auto;
}

/* ヘッダーを配送バナーの下に配置 */
.header {
    top: 32px !important; /* 配送バナーの高さ分下げる */
}

/* モバイル用の短縮テキスト（デフォルトは非表示） */
.shipping-banner-mobile {
    display: none;
}

.shipping-banner::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    100% {
        left: 100%;
    }
}

.shipping-banner-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    position: relative;
    z-index: 1;
    line-height: 1.1;
    padding: 0;
}

/* 中型デスクトップ（800px-1400px） - テキストとアイコンの被りを防ぐ */
@media (min-width: 800px) and (max-width: 1400px) {
    body .shipping-banner .container .shipping-banner-content {
        justify-content: space-between;
        gap: 0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        padding-top: 0;
        padding-bottom: 0;
    }

    body .shipping-banner .container .shipping-banner-content .shipping-info-block {
        position: static;
        transform: none;
        flex: 1 1 auto;
        min-width: 0;
    }

    body .shipping-banner .container .shipping-banner-content .shipping-info-block .shipping-info {
        font-size: 0.8rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    body .shipping-banner .container .shipping-banner-content .shipping-info-block .shipping-info span {
        display: inline;
    }

    /* SNSブロックを縮小 */
    body .shipping-banner .container .shipping-banner-content .sns-block {
        flex: 0 0 auto;
    }

    body .shipping-banner .container .shipping-banner-content .sns-block .header-sns {
        gap: 0.3rem;
    }

    body .shipping-banner .container .shipping-banner-content .sns-block .sns-icon {
        font-size: 0.9rem;
        width: 28px;
        height: 28px;
    }

    /* カートとユーザーブロックも縮小 */
    body .shipping-banner .container .shipping-banner-content .user-block,
    body .shipping-banner .container .shipping-banner-content .cart-block {
        flex: 0 0 auto;
    }
}

/* 大型デスクトップ（1401px以上） */
@media (min-width: 1401px) {
    body .shipping-banner .container .shipping-banner-content {
        justify-content: flex-end;
    }

    body .shipping-banner .container .shipping-banner-content .shipping-info-block {
        position: absolute;
        left: 45%;
        transform: translateX(-50%);
    }

    body .shipping-banner .container .shipping-banner-content .shipping-info-block .shipping-info {
        white-space: nowrap;
    }

    /* 右側要素を右に配置するために左パディングを追加 */
    body .shipping-banner .container .shipping-banner-content {
        padding-left: 200px;
        padding-right: 20px;
    }
}

/* モバイルでは左寄せ - 詳細度を上げて確実に適用 */
@media (max-width: 768px) {
    body.mobile-view .shipping-banner .container .shipping-banner-content,
    body .shipping-banner .container .shipping-banner-content {
        justify-content: flex-start;
        gap: 0.5rem;
        flex-wrap: nowrap;
    }

    body.mobile-view .shipping-banner .container .shipping-banner-content .shipping-info-block,
    body .shipping-banner .container .shipping-banner-content .shipping-info-block {
        position: static;
        transform: none;
        left: auto;
        margin-right: auto;
        flex-shrink: 1;
        min-width: 0;
        max-width: calc(100% - 140px);
    }

    body.mobile-view .shipping-banner .container .shipping-banner-content .shipping-info-block .shipping-info,
    body .shipping-banner .container .shipping-banner-content .shipping-info-block .shipping-info {
        font-size: 0.65rem;
        line-height: 1.3;
        word-break: break-word;
        white-space: nowrap;
        overflow: visible;
        text-overflow: clip;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 0.3rem;
    }

    /* 左右の順序を変更: アイコン → 配送情報 → 詳細はこちら */
    body .shipping-banner .container .shipping-banner-content .shipping-info-block .shipping-info i {
        order: 0;
        flex-shrink: 0;
    }

    body .shipping-banner .container .shipping-banner-content .shipping-info-block .shipping-info span {
        order: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    body .shipping-banner .container .shipping-banner-content .shipping-info-block .shipping-info a {
        order: 2;
        white-space: nowrap;
        flex-shrink: 0;
    }
}

.shipping-banner i {
    font-size: 1.2rem;
}

/* 配送情報ボックス */
.shipping-info-box {
    background: #f9f4ef;
    border: 2px solid #cda67f;
    border-radius: 8px;
    padding: 2rem;
    margin: 2rem 0;
    position: relative;
}

.shipping-info-box::before {
    content: '🚚';
    position: absolute;
    top: -20px;
    left: 30px;
    background: white;
    padding: 0 10px;
    font-size: 2rem;
}

.shipping-info-title {
    color: #9b7653;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    padding-top: 0.5rem;
}

.shipping-info-content {
    display: grid;
    gap: 1rem;
}

.shipping-info-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.shipping-info-item i {
    color: #9b7653;
    margin-top: 0.2rem;
    flex-shrink: 0;
}

.shipping-info-item-text {
    flex: 1;
}

.shipping-info-item-text strong {
    color: #9b7653;
    display: block;
    margin-bottom: 0.25rem;
}

.shipping-price {
    background: white;
    padding: 1rem;
    border-radius: 5px;
    border-left: 4px solid #9b7653;
    margin-top: 1rem;
}

.shipping-price-highlight {
    color: #d9534f;
    font-size: 1.2rem;
    font-weight: 700;
}

/* インラインバナー */
.shipping-inline-banner {
    background: #fff;
    border: 1px solid #cda67f;
    border-radius: 5px;
    padding: 1rem 1.5rem;
    margin: 1rem 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.shipping-inline-banner i {
    color: #9b7653;
    font-size: 1.5rem;
}

.shipping-inline-banner-text {
    flex: 1;
}

.shipping-inline-banner-text strong {
    color: #9b7653;
    display: block;
    margin-bottom: 0.25rem;
}

/* 配送CTAボタン */
.shipping-cta {
    text-align: center;
    margin: 2rem 0;
}

.shipping-cta-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #9b7653;
    color: white;
    padding: 1rem 2rem;
    border-radius: 5px;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
}

.shipping-cta-button:hover {
    background: #7a5c42;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

/* フローティングバナー（スクロール時に表示） */
.shipping-floating-banner {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #9b7653;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 50px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: none;
    align-items: center;
    gap: 0.75rem;
    z-index: 1000;
    cursor: pointer;
    transition: all 0.3s ease;
}

.shipping-floating-banner:hover {
    transform: scale(1.05);
    background: #7a5c42;
}

.shipping-floating-banner.show {
    display: flex;
}

/* モバイルレスポンシブ対応 */
@media (max-width: 768px) {
    .shipping-banner {
        padding: 0.25rem 0;
        font-size: 0.75rem;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 1001;
        min-height: auto;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1.1;
        height: auto;
    }

    .shipping-banner i {
        font-size: 0.85rem;
        flex-shrink: 0;
    }

    .shipping-banner-content {
        gap: 0.4rem;
        padding: 0 0.5rem;
        width: 100%;
        max-width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1.1;
    }

    /* モバイルでもヘッダーを配送バナーの下に配置 */
    .header {
        top: 28px !important; /* モバイル版配送バナーの高さ分 */
    }
    
    .shipping-banner-content span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .shipping-banner-content a {
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .shipping-banner .container {
        max-width: none;
        width: 100%;
        padding: 0;
    }
    
    .shipping-info-box {
        padding: 1.5rem 1rem;
    }
    
    .shipping-info-title {
        font-size: 1.25rem;
    }
    
    .shipping-inline-banner {
        flex-direction: column;
        text-align: center;
    }
    
    .shipping-cta-button {
        font-size: 0.9rem;
        padding: 0.75rem 1.5rem;
    }
    
    .shipping-floating-banner {
        bottom: 10px;
        right: 10px;
        padding: 0.75rem 1rem;
        font-size: 0.85rem;
    }
}

/* =============== iOS Safari Fallback =============== */
/* If GSAP ScrollTrigger fails to animate elements, they will become visible after 2 seconds */
/* Uses @supports to target only iOS Safari (and other WebKit browsers on iOS) */

@supports (-webkit-touch-callout: none) {
    /* iOS-only CSS fallback */
    .animate-fade-up,
    .reveal-text,
    .reveal-line,
    .reveal-para,
    .stagger-item,
    .scroll-trigger {
        animation: iosFallbackShow 0.5s ease forwards;
        animation-delay: 2s;
    }
    
    @keyframes iosFallbackShow {
        to {
            opacity: 1 !important;
            transform: none !important;
        }
    }
}