/* モバイル以外では非表示 */
#toc-floating-btn,
#toc-popup-overlay {
    display: none;
}

@media screen and (max-width: 768px) {
    /* フローティングボタン */
    #toc-floating-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        position: fixed;
        bottom: 11%;
        right: 3%;
        width: 44px;
        height: 44px;
        background-color: #fff;
        border: 1px solid #ddd;
        border-radius: 8px; /* 角丸 */
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        z-index: 9990;
        cursor: pointer;
        color: #333;
        transition: opacity 0.3s;
        padding: 3px; /* 内側の余白を少し縮小 */
    }
    
    #toc-floating-btn .toc-icon {
        width: 20px; /* 45pxに収めるため少し縮小 */
        height: 20px;
        fill: currentColor; /* 文字色に合わせる */
        margin-bottom: 2px; /* 間隔も縮小 */
    }
    
    #toc-floating-btn .toc-label {
        font-size: 9px; /* フォントサイズも微調整 */
        line-height: 1;
        font-weight: bold;
    }

    #toc-floating-btn:hover {
        opacity: 0.9;
    }

    /* ポップアップオーバーレイ */
    #toc-popup-overlay {
        display: none; /* 初期状態はJSで制御 */
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.5);
        z-index: 9999;
        justify-content: center;
        align-items: center;
    }
    
    /* bodyがスクロールしないように */
    body.toc-popup-open {
        overflow: hidden;
    }

    /* ポップアップコンテンツ */
    #toc-popup-content {
        position: absolute; /* 中央配置のため */
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 90%;
        max-width: 400px;
        /* デフォルト (投稿ページ等) は中身に合わせて自動伸縮、最大90% */
        height: auto;
        max-height: 90vh;
        background-color: #fff;
        border-radius: 8px;
        box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        display: flex;
        flex-direction: column;
    }

    /* WooCommerceタブモード時は高さ固定 (JSでクラス付与) */
    #toc-popup-overlay.toc-mode-tabs #toc-popup-content {
        height: 50vh;
        max-height: none;
    }

    /* ポップアップヘッダー */
    .toc-popup-header {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 15px;
        border-bottom: 1px solid #eee;
        position: relative;
        font-weight: bold;
        font-size: 16px;
        flex-shrink: 0; /* 縮まないように */
    }
    
    /* 閉じるボタン */
    #toc-popup-close {
        position: absolute;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
        background: none;
        border: none;
        font-size: 24px;
        line-height: 1;
        cursor: pointer;
        color: #999;
        padding: 0 10px;
    }
    
    /* ポップアップボディ（スクロールエリア） */
    .toc-popup-body {
        padding: 15px 20px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex-grow: 1; /* 残りの高さを埋める */
    }

    /* Arkhe Block TOC のスタイル調整 (ポップアップ内) */
    .toc-popup-body .ark-block-toc__list {
        margin: 0;
        padding: 0;
        list-style: none; /* Arkhe側で設定されているかもしれないが念のため */
    }

    .toc-popup-body .ark-block-toc__list li {
        margin-bottom: 8px;
    }
    
    .toc-popup-body .ark-block-toc__list li a {
        text-decoration: none;
        color: #333;
        font-size: 14px;
        display: block;
        line-height: 1.5;
    }

    /* 階層インデント */
    .toc-popup-body .ark-block-toc__list .ark-block-toc__list {
        margin-top: 8px;
        margin-left: 15px;
        padding-left: 10px;
        border-left: 1px solid #eee;
    }
    

}

/* Arkhe目次ブロックの見出し2（H2）カスタマイズ */
.ark-block-toc__list[data-level="2"] > li > .ark-block-toc__link {
    font-weight: 700; /* 太字 */
    background: var(--arkb-marker-style, linear-gradient(transparent 60%, rgba(255, 255, 100, 0.6) 0)); /* マーカー */
    padding: 1px;
    display: inline; /* マーカーを行全体でなく文字幅にする */
    box-decoration-break: clone; /* 改行時もマーカースタイルを維持 */
    -webkit-box-decoration-break: clone;
}

/* 省略表示機能（Show More） - 共通スタイル */
.toc-hidden {
    display: none !important;
}

/* ルート要素（H2）用のもっと見るボタン */
.toc-show-more-root {
    display: block;
    width: 140px;
    margin: 20px auto 10px;
    padding: 8px 0;
    text-align: center;
    background-color: #f1f1f1;
    border-radius: 20px;
    font-size: 12px;
    color: #666;
    cursor: pointer;
    border: 1px solid #ddd;
    line-height: 1;
    transition: background-color 0.2s;
}

.toc-show-more-root:hover {
    background-color: #e5e5e5;
}

/* 3点リーダー装飾 (参考画像風) */
.toc-show-more-root::before,
.toc-show-more-root::after {
    content: "....";
    color: #ccc;
    margin: 0 8px;
    letter-spacing: 2px;
}

/* ネスト要素（H3以降）用のもっと見るボタン */
.toc-show-more-sub {
    display: block; /* slideUpアニメーションを滑らかにするためblockに変更 */
    width: fit-content; /* 全幅にならないように */
    font-size: 11px;
    color: #999;
    cursor: pointer;
    padding: 4px 8px;
    background: #f9f9f9;
    border-radius: 4px;
    margin-top: 4px;
    border: 1px solid #eee;
}

.toc-show-more-sub:hover {
    background-color: #f0f0f0;
    color: #666;
}


.toc-show-more-sub::after {
    content: " ▼";
    font-size: 0.8em;
}

/* -------------------------------------------
   WooCommerce タブ目次用スタイル
------------------------------------------- */
/* ページ内挿入目次 */
.custom-tab-toc {
    margin-bottom: 2em;
    padding-bottom: 1.5em;
    border-bottom: 1px dotted #ccc;
}

/* ポップアップ内タブナビゲーション */
.toc-popup-tabs {
    display: flex;
    overflow-x: auto;
    border-bottom: 1px solid #eee;
    background: #fdfdfd;
    padding: 0 10px;
}

.toc-tab-nav-item {
    background: none;
    border: none;
    padding: 12px 15px;
    font-size: 13px;
    font-weight: bold;
    color: #888;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.toc-tab-nav-item.active {
    color: #333;
    border-bottom-color: #333; /* アクセントカラーがあるならvarの使用検討 */
}

.toc-tab-nav-item:hover {
    color: #555;
}

/* タブコンテンツエリア */
.toc-tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.toc-tab-pane.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}
