/* 既存スタイルはそのまま */
#content-wrapper {
    position: relative;
    width: 100%;
}

#simple-sticky-toc {
    position: absolute;
    top: 0;
    left: -50%;
    width: 220px;
    z-index: 10;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    margin: 0;
    padding: 15px;
    max-height: 100vh; /* 画面の高さの100%まで */
    overflow-y: auto;  /* 縦スクロール */
    padding-right: 10px; /* スクロールバーが重ならないよう余白 */
}

.simple-sticky-toc-wrapper  {
    position: sticky;
    top: 20px;
}

.sstoc-toggle {
    background-color: transparent;
    border: none;
    outline: none;
    padding: 0;
    font-size: 18px;
}

.sstoc-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* h2（上位階層） */
.sstoc-list > li > a {
    color: #333 !important;
    font-size: 1em !important;
    font-weight: 450 !important;
    line-height: 1.2em !important; /* 行間を詰める */
    text-decoration: none;
    position: relative;
}

/* h3（サブ階層） */
.sstoc-list ul li a {
    color: #666 !important;
    font-size: 0.85em !important;
    font-weight: normal !important;
    line-height: 1.2em !important; /* 行間を詰める */
    text-decoration: none;
    position: relative;
}


/* リンクホバー */
.sstoc-list li a:hover {
    text-decoration: underline;
}

/* サブリスト調整 */
.sstoc-list ul {
    padding-left: 1em;
    margin: 0;
}

.sstoc-list ul li ul {
    margin: 0;
    padding: 0;
}

.sstoc-list li {
    list-style: none;
}

/* 見出しの色・サイズ指定（h2とh3） */
h2[id^="toc-"] {
    color: #333;
}

h3[id^="toc-"] {
    color: #666;
    font-size: 0.85em;
}

/* RTL support */
body.rtl #simple-sticky-toc {
    direction: rtl;
    text-align: right;
}

body.rtl .sstoc-list {
    flex-direction: row-reverse;
}

body.rtl .sstoc-list ul {
    padding-right: 1em;
    padding-left: 0;
}

/* Mobile styles */
@media (max-width: 767px) {
    #simple-sticky-toc {
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        width: 100%;
    }

    .sstoc-toggle {
        display: block;
        width: 100%;
        padding: 10px;
        background: transparent;
        color: #fff;
        border: none;
        font-size: 16px;
        cursor: pointer;
    }

    .sstoc-list {
        display: none;
        margin-top: 10px;
    }

    .sstoc-list.open {
        display: block;
    }

    #sstoc-wrapper {
        display: block;
    }

    #sstoc-content {
        padding: 0;
    }

    h1[id^="toc-"],
    h2[id^="toc-"],
    h3[id^="toc-"],
    h4[id^="toc-"],
    h5[id^="toc-"],
    h6[id^="toc-"] {
        scroll-margin-top: 60px;
    }
}
/* h2相当 */
.sstoc-list > li > a,
.sstoc-list > li > a span {
    line-height: 0.8em !important;
}

/* h3相当 */
.sstoc-list ul li a,
.sstoc-list ul li a span {
    line-height: 0.8em !important;
}



/* h2カウンター初期化 */
.sstoc-list {
    counter-reset: toc-h2;
    position: relative;
}

/* h2リンクの親位置を相対に */
.sstoc-list > li > a {
    position: relative;
}

/* 背景数字（縦一列揃え ） */
.sstoc-list > li > a::before {
    counter-increment: toc-h2;
    content: counter(toc-h2);
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%); /* 垂直中央に揃える */
    font-family: "Ultra", serif;
    font-weight: 400;
    font-style: normal;
    font-size: 4em; /* サイズはお好みで調整 */
    z-index: -1; /* 背景扱い */
    pointer-events: none;
}

/* 奇数番号の背景色 */
.sstoc-list > li:nth-child(odd) > a::before {
    color: #FCF4D9; /* 透明度100% */
}

/* 偶数番号の背景色（薄め 2/3くらい） */
.sstoc-list > li:nth-child(even) > a::before {
    color: rgba(255, 122, 90, 0.17); /* 透明度約17% */
}

/* 現在地リンクにアンダーライン */
.sstoc-list li a.active {
    text-decoration: underline;
}

/* モバイルではh2の背景数字を非表示 */
@media (max-width: 767px) {
    .sstoc-list > li > a::before {
        display: none !important;
    }
}


/* モバイル時のh2リンクのフォントウェイト調整 */
@media (max-width: 767px) {
    .sstoc-list > li > a {
        font-weight: 500 !important; /* 通常400～太字700の中間 */
    }
}

/* さらに偶数番目のh3リンクの文字色も調整（元の85%グレーを維持） */
.sstoc-list > li > ul > li:nth-child(even) > a {
    color: #888 !important;
}

/* h3全体の左線を太く＆色を交互に変更 */
.sstoc-list > li > ul > li {
    position: relative;
    left: -1em; /* 元の位置 */
    border-left: 3px solid #FFD1C6; /* 線の太さと初期色を変更 */
    padding-left: 1em; /* 線とテキストの間隔 */
}

/* 偶数番目のh3リンクの左線を薄め色に */
.sstoc-list > li > ul > li:nth-child(even) {
    border-left-color: #FCF4D9;
}



@media (max-width: 767px) {
    /* h3 サブ階層を完全に非表示 */
    .sstoc-list ul,
    .sstoc-list ul.sstoc-list.open {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        overflow: hidden !important;
    }
}

/* モバイル専用スタイル */
@media (max-width: 767px) {
    /* 目次内の文字をやや小さく */
    .sstoc-list > li > a,
    .sstoc-list.open > li > a {
        font-size: 0.9em !important;
    }

    /* 偶数番目のh2をやや薄く */
    .sstoc-list > li:nth-child(even) > a,
    .sstoc-list.open > li:nth-child(even) > a {
        color: rgba(51, 51, 51, 0.7) !important;
    }
}

/* h3デフォルト */
#simple-sticky-toc .sstoc-list > li > ul > li > a,
#simple-sticky-toc .sstoc-list > li > ul > li > a span {
    color: #666 !important;
}

/* h3偶数だけ薄く */
#simple-sticky-toc .sstoc-list > li > ul > li:nth-child(even) > a,
#simple-sticky-toc .sstoc-list > li > ul > li:nth-child(even) > a span {
    color: #888 !important;
}
}

/* h4のliを非表示 */
#simple-sticky-toc .sstoc-list > li > ul > li > ul > li {
    display: none !important;
}

#simple-sticky-toc .sstoc-list > li > ul > li > ul > li,
#simple-sticky-toc .sstoc-list > li > ul > li > ul > li a {
    display: none !important;
}


@media (max-width: 767px) {
    /* TOC全体は右上固定 */
    #simple-sticky-toc {
        position: fixed !important;
        top: 10px;
        right: 10px;
        z-index: 9999;
        background: transparent;
        width: auto !important;
        padding: 0;
        box-shadow: none;
    }

    /* ボタン画像（スマホ用） */
    .sstoc-toggle {
        width: 95px !important;   
        height: 95px !important;
        background-image: url('https://otokureka.com/wp-content/uploads/目次（スマホ）.png');
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        cursor: pointer;
        border: none;
        outline: none;
        font-size: 0;
        padding: 0;
    }

    /* 目次リスト（初期非表示、JSで開閉） */
    .sstoc-list {
        display: none;
        position: fixed;
        top: 110px;           
        right: 10px;
        width: 90vw;           
        max-height: 70vh;      
        overflow-y: auto;      
        background: #fff;
        border-radius: 8px;
        padding: 15px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        z-index: 9998;
    }
}