/* ============================================================
 ↓右側に目次表示するやつ（PC画面用)
 ============================================================*/

/* グローバル設定：現在地ハイライト（赤） */
#toc-target a.active-section {
    color: #ff0000 !important;
    font-weight: bold !important;
    border-left: 3px solid #ff0000;
    padding-left: 5px;
    background-color: #fff5f5;
}

/* PC表示時（px以上）のレイアウト最適化 */
@media (min-width: 1230px) {
  
    /* 5. 画面右側に浮く目次の設定 */
    #floating-toc {
        position: fixed !important;
        top: 120px;
        right: 5px; /* 右端からの距離 */
        width: calc(50vw - 475px - 20px); /* 画面中央からコンテナ半分を引いた余白分 */
        min-width: 80px; /* 狭くなりすぎないよう最小幅を設定 */
        max-width: 300px; /* 広くなりすぎないよう最大幅を設定 */
        max-height: 80vh;
        
        /* ▼▼▼ 修正箇所：ここから ▼▼▼ */
        display: flex;          /* 中身を縦並びのボックスにする */
        flex-direction: column; /* 縦方向に並べる */
        overflow: hidden;       /* 全体はスクロールさせない */
        padding: 0;             /* 余白は内部の要素に個別に設定するため0にする */
        /* ▲▲▲ 修正箇所：ここまで ▲▲▲ */

        background: #fff;
        border: 1px solid #ddd;
        box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        z-index: 1000;
        border-radius: 4px;
        box-sizing: border-box;
    }
  
    /* 目次のタイトルと最小化ボタン（固定エリア） */
    .toc-title {
        font-size: 16px;
        font-weight: bold;
        border-bottom: 2px solid #eee;
        color: #333;
        display: flex;
        justify-content: space-between;
        align-items: center;
        
        /* ▼▼▼ 追加・調整箇所 ▼▼▼ */
        flex-shrink: 0;               /* タイトルエリアが潰れないように固定 */
        padding: 15px 15px 5px 15px;  /* 上・左右・下の余白（親のpaddingを移植） */
        margin-bottom: 0;             /* 下のマージンをゼロにしてリストと詰める */
        background: #fff;             /* 背景色を明示（重なった時用） */
        /* ▲▲▲ 追加・調整箇所 ▲▲▲ */
    }

    #toc-toggle {
        font-size: 11px;
        color: #888;
        cursor: pointer;
        font-weight: normal;
    }
    #toc-toggle:hover { color: #333; }

    /* 目次リストエリア（ここだけスクロールさせる） */
    #toc-target {
        /* ▼▼▼ 追加・調整箇所 ▼▼▼ */
        overflow-y: auto;           /* 縦スクロールをここに適用 */
        flex-grow: 1;               /* 残りの高さを全て使う */
        padding: 5px 15px 15px 15px; /* 上・左右・下の余白（親のpaddingを移植） */
        /* ▲▲▲ 追加・調整箇所 ▲▲▲ */
      
       /* ▼▼▼ 追加推奨 ▼▼▼ */
        position: relative; /* スクロール位置計算の基準点にする */
        scroll-behavior: smooth; /* 手動スクロールも滑らかに */
        /* ▲▲▲ 追加推奨 ▲▲▲ */
    }

    /* 目次内の各項目の区切り線 */
    #toc-target div {
        border-bottom: 3px solid #eee;
        padding: 4px 0;
    }
    #toc-target div:last-child { border-bottom: none; }

    /* 目次内のリンク文字（文字溢れ対策込み） */
    #toc-target a {
        font-size: 13px;
        color: #0077bb;
        text-decoration: none;
        display: block;
        line-height: 1.4;
        /* --- 文字溢れ対策 --- */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* 2. マウスをのせた時（ホバー時）の設定 */
    #toc-target a:hover {
        color: #005588 !important;   /* 少し濃い青色に */
        font-weight: bold !important; /* 太字にする */
        background-color: #f0f8ff;    /* ほんのり薄い水色背景 */
        text-decoration: none;        /* 下線は不要 */
    }

    /* 現在地ハイライト（PC内設定：オレンジ優先の場合） */
    /* ※もし冒頭の赤色(#ff0000)を優先したい場合は、以下のブロックを削除してください */
    #toc-target a.active-section {
        color: #ff6600 !important; /* 目立つオレンジ */
        font-weight: bold !important;
        border-left: 2px solid #ff6600;
        padding-left: 4px;
        background-color: transparent; /* 背景色はホバーやグローバル設定に任せる場合 */
    }

    /* --- 字下げ設定 --- */
    .toc-page-name { padding-left: 0px !important; font-weight: bold; }
    .toc-h1 { padding-left: 8px !important; }
    .toc-h2 { padding-left: 18px !important; font-size: 0.95em !important; }
    .toc-h3 { padding-left: 28px !important; font-size: 0.9em !important; color: #666; }
}
/* ============================================================
 ↑右側に目次表示するやつ（PC画面用)
 ============================================================*/




/* ============================================================
 ↓右側に目次表示するやつ（スマホ画面用)
 ============================================================*/

@media (max-width: 1229px) {
    #floating-toc {
        display: block !important;
        position: fixed !important;
        top: 0 !important;
        right: -100% !important; 
        width: 250px !important; 
        height: 100vh !important;
        max-height: 100vh !important;
        background: #fff !important;
        z-index: 100000 !important;
        transition: right 0.3s ease-in-out !important;
        box-shadow: -5px 0 15px rgba(0,0,0,0.2) !important;
        padding: 0 !important; 
        overflow-y: auto !important;
        border: none !important;
        border-radius: 0 !important;
    }

    #floating-toc.is-open {
        right: 0 !important;
    }

    /* 目次内のヘッダー */
    .toc-title {
        background: #f8f8f8;
        padding: 20px;
        font-size: 18px !important; 
        border-bottom: 1px solid #eee;
        margin-bottom: 0 !important;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: sticky !important; /* スクロールしても上部に張り付く */
        top: 0;                      /* 張り付く位置 */
        z-index: 10;                 /* 項目より上に表示 */
    }

    /* ×ボタン */
    #toc-toggle {
        font-size: 24px !important;
        color: #333 !important;
        width: 40px;
        height: 40px;
        display: flex;
        justify-content: center;
        align-items: center;
        background: #eee;
        border-radius: 50%;
        cursor: pointer;
    }

    /* 項目全体のリスト：左右のパディングを0にしてaタグを端まで届かせる */
    #toc-target {
        padding: 10px 0 !important;
    }

    /* 項目ごとの枠：ここもパディングを0にする */
    #toc-target div {
        border-bottom: 1px solid #f0f0f0 !important;
        padding: 0 !important; 
        margin: 0 !important;
    }

    /* 【重要】当たり判定を横いっぱいに広げる設定 */
    #toc-target a {
        display: block !important;    /* 1行まるごとボタン化 */
        width: 100% !important;
        padding: 10px 20px !important; /* リンクの内側に余白を作る（タップしやすさUP） */
        font-size: 16px !important; 
        line-height: 1.4 !important;
        white-space: normal !important; 
        text-overflow: clip !important;
        overflow: visible !important;
        box-sizing: border-box !important; /* paddingを幅に含める */
        text-decoration: none !important;
        color: #0077bb;
    }

    /* タップした瞬間に背景色を変えてフィードバックを出す */
    #toc-target a:active {
        background-color: #f0f0f0 !important;
    }

    /* JSで付与されるクラスに基づいた字下げ調整 */
    #toc-target .toc-page-name a { padding-left: 20px !important; }
    #toc-target .toc-h1 a { padding-left: 20px !important; }
    #toc-target .toc-h2 a { padding-left: 35px !important; } /* 字下げをaのpaddingで制御 */
    #toc-target .toc-h3 a { padding-left: 50px !important; }

    /* 三本線ボタン */
    #sp-toc-open-btn {
        position: fixed !important;
        right: 0 !important;
        top: 50% !important;
        width: 50px !important;
        height: 60px !important;
        background: rgba(0, 0, 0, 0.7) !important;
        color: #fff !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 10px 0 0 10px !important;
        z-index: 99999 !important;
        cursor: pointer !important;
        font-size: 30px !important;
    }

    #sp-toc-overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        background: rgba(0, 0, 0, 0.5) !important;
        display: none;
        z-index: 99999 !important;
    }
}
/* ============================================================
 ↑右側に目次表示するやつ（スマホ画面用)
 ============================================================*/