@charset "UTF-8";

/*!
Theme Name: Cocoon Child
Description: Cocoon専用の子テーマ
Theme URI: https://wp-cocoon.com/
Author: わいひら
Author URI: https://nelog.jp/
Template:   cocoon-master
Version:    1.1.3
*/

/************************************
** 子テーマ用のスタイルを書く
************************************/
/*必要ならばここにコードを書く*/

/************************************
** レスポンシブデザイン用のメディアクエリ
************************************/
/*1023px以下*/
@media screen and (max-width: 1023px){
  /*必要ならばここにコードを書く*/
}

/*834px以下*/
@media screen and (max-width: 834px){
  /*必要ならばここにコードを書く*/
}

/*480px以下*/
@media screen and (max-width: 480px){
  /*必要ならばここにコードを書く*/
}

// ==========================================
// 会員ページ向け中央ダイアログ制御（9月／10月切り替え版）
// ==========================================
function custom_member_page_restriction() {
    $is_logged_in = (function_exists('swpm_is_member_logged_in') && swpm_is_member_logged_in());

    // 2026年10月1日 00:00:00 （日本時間）のタイムスタンプ
    $target_date = 1759244400; 
    $current_time = time();
    $is_after_october = ($current_time >= $target_date);

    // 例外ページ（ログイン画面など）は除外
    $current_url = $_SERVER['REQUEST_URI'];
    if (strpos($current_url, 'wp-login.php') !== false || strpos($current_url, 'lock.php') !== false) {
        return;
    }

    if (!$is_logged_in) {
        add_action('wp_footer', function() use ($is_after_october) {
            ?>
            <style>
                #swpm-restriction-overlay {
                    position: fixed;
                    top: 0; left: 0; width: 100%; height: 100%;
                    background: rgba(0, 0, 0, 0.6);
                    z-index: 999999; display: flex; align-items: center; justify-content: center;
                }
                .swpm-restriction-box {
                    background: #ffffff; padding: 30px; border-radius: 8px; text-align: center; max-width: 500px; width: 90%;
                    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
                }
                .swpm-restriction-box h3 { margin-top: 0; color: #333; font-size: 20px; }
                .swpm-restriction-box p { color: #666; font-size: 14px; line-height: 1.6; }
                .swpm-restriction-btn {
                    display: inline-block; margin-top: 15px; padding: 10px 20px; background: #0073aa; color: #fff;
                    text-decoration: none; border-radius: 4px; font-weight: bold;
                }
                .swpm-restriction-btn:hover { background: #005177; }
                .swpm-close-btn {
                    display: inline-block; margin-top: 15px; padding: 10px 20px; background: #6c757d; color: #fff;
                    text-decoration: none; border-radius: 4px; font-weight: bold; cursor: pointer; border: none;
                }
                .swpm-close-btn:hover { background: #5a6268; }
            </style>

            <div id="swpm-restriction-overlay">
                <div class="swpm-restriction-box">
                    <?php if ($is_after_october): ?>
                        <!-- 10月以降（非会員は完全ブロック） -->
                        <h3>会員限定コンテンツ</h3>
                        <p>このページは会員専用です。ご入会の上ご利用ください。</p>
                        <a href="<?php echo home_url('/membership-login'); ?>" class="swpm-restriction-btn">ログイン / 入会案内はこちら</a>
                    <?php else: ?>
                        <!-- 今月中（9月中・お知らせのみ、閉じれば操作可能） -->
                        <h3>お知らせ</h3>
                        <p>このページは10月から会員専用になります。</p>
                        <button type="button" id="swpm-dismiss-modal" class="swpm-close-btn">閉じる</button>
                    <?php endif; ?>
                </div>
            </div>

            <script>
                document.addEventListener('DOMContentLoaded', function() {
                    const overlay = document.getElementById('swpm-restriction-overlay');
                    const dismissBtn = document.getElementById('swpm-dismiss-modal');
                    
                    if (dismissBtn) {
                        // 9月中は「閉じる」ボタンでダイアログを消せるようにする
                        dismissBtn.addEventListener('click', function() {
                            overlay.style.display = 'none';
                        });
                    }

                    if (overlay) {
                        overlay.addEventListener('contextmenu', function(e) { 
                            <?php if ($is_after_october): ?>e.preventDefault();<?php endif; ?>
                        });
                    }
                });
            </script>
            <?php
        });
    }
}
add_action('template_redirect', 'custom_member_page_restriction');