/* ============================================================
 * AiTone 見守りライブラリ 専用スタイル
 * ============================================================
 * 「ライブラリ＝本棚」であることが一目で伝わるように、
 * 記事カードを1冊の本（背表紙＋小口）、カテゴリを1段の棚として表現する。
 *
 * 使用箇所: /library/ 配下のすべてのページ
 * 依存: Tailwind のカラー変数には依存せず、ここで完結させる
 * ============================================================ */

:root {
    --paper: #fdfbf7;          /* 紙の色 */
    --paper-edge: #efe7db;     /* 小口（紙の重なり）の色 */
    --ink: #292524;
    --ink-soft: #57534e;
    --wood: #c8b6a0;           /* 棚板 */
    --wood-dark: #a1866b;

    /* ライブラリ配下ページのヒーロー高さ。
     * faq ページのヒーロー（py-12 + 見出し + リード文 = 164px）に揃えている。
     * 配下の全ページでこの高さに固定することで、
     *   ・ページ間を移動してもヒーローの高さが変わらない
     *   ・JavaScript がヒーローを組み立てる前後で高さが変わらない（＝ちらつかない）
     * の2点を満たす。 */
    --lib-hero-h: 164px;
}

/* ============================================================
 * パンくずバー（ヒーローの上に置く細い帯）
 * パンくず・カテゴリ・更新日をここに逃がすことで、
 * ヒーロー本体は「見出し＋リード文」だけになり、高さを固定できる。
 * ============================================================ */
/* 高さは 47px に固定する。JavaScript で差し込む前後、および画面幅によって
 * 高さが変わらないようにして、ちらつき（レイアウトシフト）を防ぐ。 */
div[data-layout="crumbs"],
.lib-crumbbar {
    display: flex;
    align-items: center;
    height: 47px;
    background: #fff;
    border-bottom: 1px solid #f0eae0;
    overflow: hidden;
}
.lib-crumbbar__inner {
    width: 100%;
    max-width: 64rem;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}
@media (min-width: 768px) {
    .lib-crumbbar__inner { padding: 0 2.5rem 0 4rem; }
}

/* ============================================================
 * ヒーロー（ライブラリ配下ページ共通）
 * 見開きの扉ページに見立て、左端に背表紙の帯を置く。
 * 高さは --lib-hero-h に固定する（faq ページと同じ高さ）。
 * ============================================================ */

/* JavaScript が組み立てる前の素の状態にも同じ寸法を効かせ、
 * 描画前後で高さが変わらないようにしている。 */
[data-layout="hero"],
.lib-hero {
    position: relative;
    display: flex;
    align-items: center;
    height: var(--lib-hero-h);
    overflow: hidden;
    background: linear-gradient(180deg, var(--paper) 0%, #f6f1e9 100%);
    border-bottom: 1px solid #e7ded0;
}
/* 幅が狭いときは、見出しの折り返しで文字が切れないよう伸びることを許す */
@media (max-width: 767px) {
    [data-layout="hero"],
    .lib-hero {
        height: auto;
        min-height: var(--lib-hero-h);
    }
}
.lib-hero::before {
    /* 左端の背表紙 */
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 12px;
    background: linear-gradient(180deg, var(--spine, #0d9488), color-mix(in srgb, var(--spine, #0d9488) 70%, #000));
}
.lib-hero::after {
    /* 背表紙の隣に走る小口の縞 */
    content: '';
    position: absolute;
    inset: 0 auto 0 12px;
    width: 7px;
    background: repeating-linear-gradient(90deg, #fff 0 1px, var(--paper-edge) 1px 3px);
    opacity: .85;
}
.lib-hero__paper {
    /* 紙の繊維感をごく薄く乗せる */
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(0, 0, 0, .022) 0 1px, transparent 1px),
        radial-gradient(circle at 70% 60%, rgba(0, 0, 0, .018) 0 1px, transparent 1px);
    background-size: 13px 13px, 19px 19px;
}
.lib-hero__inner {
    position: relative;
    width: 100%;
    max-width: 64rem;
    margin: 0 auto;
    padding: 1.1rem 1.5rem 1.1rem 3rem;
}
@media (min-width: 768px) {
    .lib-hero__inner { padding: 1.1rem 2.5rem 1.1rem 4rem; }
}

/* パンくず（バー内） */
.hero-crumbs {
    font-size: .8125rem;
    color: #8a8078;
    min-width: 0;
    /* 1行に収め、長いタイトルは省略記号で切る（高さを固定するため） */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hero-crumbs a { color: #8a8078; text-decoration: none; }
.hero-crumbs a:hover { color: #0d9488; text-decoration: underline; }
.hero-crumbs span[aria-hidden] { margin: 0 .5rem; color: #cfc6ba; }
.hero-crumbs .is-current { color: var(--ink); font-weight: 700; }

/* カテゴリ・更新日（バー内の右側） */
.hero-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .6rem;
}
.hero-cat {
    display: inline-block;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .04em;
    padding: .22rem .7rem;
    border-radius: 9999px;
    text-decoration: none;
    color: #fff;
    background: var(--spine, #0d9488);
    white-space: nowrap;
}
.hero-cat:hover { filter: brightness(1.08); }
.hero-updated { font-size: .7rem; color: #8a8078; white-space: nowrap; }
/* 幅が狭いときは更新日を省き、パンくずの表示領域を確保する */
@media (max-width: 639px) { .hero-updated { display: none; } }

.lib-hero__title {
    font-size: clamp(1.4rem, 3.1vw, 1.95rem);
    font-weight: 900;
    line-height: 1.35;
    color: var(--ink);
    letter-spacing: -.01em;
    margin: 0;
    /* 高さ固定のため、長いタイトルは2行で打ち止める */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}
.lib-hero__lead {
    margin: .5rem 0 0;
    max-width: 48rem;
    font-size: .875rem;
    line-height: 1.75;
    color: var(--ink-soft);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

/* 索引ページのヒーローは、見出しをひとまわり大きくする */
.lib-hero--index .lib-hero__title { -webkit-line-clamp: 1; font-size: clamp(1.7rem, 4vw, 2.4rem); }
.lib-hero--index .lib-hero__lead { -webkit-line-clamp: 2; }
/* 右下の書架（装飾）と文章が重ならないよう、右に余白を取る */
@media (min-width: 1024px) {
    .lib-hero--index .lib-hero__inner { padding-right: 24rem; }
}

/* JavaScript が動く前の素の h1 / p も、同じ位置・同じ大きさで見えるようにしておく */
[data-layout="hero"]:not(.lib-hero) > h1 {
    font-size: clamp(1.4rem, 3.1vw, 1.95rem);
    font-weight: 900;
    line-height: 1.35;
    color: var(--ink);
    margin: 0 1.5rem 0 3rem;
}
[data-layout="hero"]:not(.lib-hero) > p {
    display: none;
}
[data-layout="hero"]:not(.lib-hero) > [data-hero-extra] { display: none; }

/* ============================================================
 * 絞り込み（カテゴリチップ＋キーワード）
 * ============================================================ */
.lib-toolbar {
    position: sticky;
    top: 5rem;
    z-index: 30;
    background: rgba(253, 251, 247, .93);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #e7ded0;
}
.lib-toolbar__inner {
    max-width: 72rem;
    margin: 0 auto;
    padding: .9rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
}
.lib-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.lib-chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .8125rem;
    font-weight: 700;
    color: var(--ink-soft);
    background: #fff;
    border: 1px solid #e0d7c9;
    border-radius: 9999px;
    padding: .4rem .9rem;
    cursor: pointer;
    transition: color .15s, border-color .15s, background-color .15s;
}
.lib-chip:hover { border-color: var(--chip, #0d9488); color: var(--chip, #0d9488); }
.lib-chip.is-active {
    color: #fff;
    background: var(--chip, #1c1917);
    border-color: var(--chip, #1c1917);
}
.lib-chip__n {
    font-size: .6875rem;
    font-weight: 700;
    opacity: .7;
    font-variant-numeric: tabular-nums;
}

.lib-search {
    flex: 1 1 14rem;
    min-width: 12rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    background: #fff;
    border: 1px solid #e0d7c9;
    border-radius: 9999px;
    padding: .4rem .95rem;
}
.lib-search:focus-within { border-color: #0d9488; box-shadow: 0 0 0 3px rgba(13, 148, 136, .12); }
.lib-search input {
    flex: 1;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: .875rem;
    color: var(--ink);
    min-width: 0;
}
.lib-search svg { flex: none; width: 1rem; height: 1rem; color: #a8a29e; }
.lib-count { font-size: .75rem; color: #8a8078; white-space: nowrap; }

/* ============================================================
 * 本（記事カード）
 * ============================================================ */
.book {
    position: relative;
    display: block;
    padding-left: 1.55rem;          /* 背表紙＋小口の幅ぶん空ける */
    background: var(--paper);
    border: 1px solid #e7ded0;
    border-radius: 3px 12px 12px 3px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 12px 20px -18px rgba(60, 40, 20, .55);
    text-decoration: none;
    color: inherit;
    overflow: hidden;
    transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
}
.book:hover {
    /* 棚から少し引き出したような動き */
    transform: translateY(-5px) rotate(-.35deg);
    box-shadow: 0 2px 0 rgba(0, 0, 0, .04), 0 26px 34px -22px rgba(60, 40, 20, .6);
    border-color: #dccfba;
}
.book:focus-visible { outline: 3px solid #0d9488; outline-offset: 3px; }

.book-spine {
    position: absolute;
    inset: 0 auto 0 0;
    width: .95rem;
    background: linear-gradient(180deg, var(--spine), var(--spine-dark));
}
.book-spine::after {
    /* 背表紙の箔押し風の細線 */
    content: '';
    position: absolute;
    inset: .7rem .22rem auto .22rem;
    height: 2px;
    background: rgba(255, 255, 255, .55);
    border-radius: 2px;
    box-shadow: 0 3px 0 rgba(255, 255, 255, .3);
}
.book-edge {
    position: absolute;
    inset: 0 auto 0 .95rem;
    width: .6rem;
    background: repeating-linear-gradient(90deg, #fff 0 1px, var(--paper-edge) 1px 3px);
}

.book-body { display: block; padding: 1.4rem 1.4rem 1.25rem; }
.book-tag {
    display: inline-block;
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .02em;
    padding: .2rem .6rem;
    border-radius: 9999px;
    border: 1px solid #e0d7c9;
    background: #f5efe5;
    color: #8a8078;
    margin-bottom: .7rem;
}
.book-title {
    display: block;
    font-size: 1.0625rem;
    font-weight: 900;
    line-height: 1.55;
    color: var(--ink);
    margin-bottom: .55rem;
}
.book-desc {
    display: block;
    font-size: .8125rem;
    line-height: 1.85;
    color: var(--ink-soft);
}
.book-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    margin-top: .9rem;
    font-size: .6875rem;
    color: #a8a29e;
    font-variant-numeric: tabular-nums;
}

/* 準備中の本 */
.book--soon {
    background: #f7f4ee;
    border-style: dashed;
    box-shadow: none;
    cursor: default;
}
.book--soon:hover { transform: none; box-shadow: none; border-color: #e7ded0; }
.book--soon .book-title { color: #8a8078; }
.book--soon .book-desc { color: #a8a29e; }
.book--soon .book-edge { opacity: .5; }
.book-soon {
    font-weight: 700;
    color: #a8a29e;
}

/* ============================================================
 * 棚（カテゴリ）
 * ============================================================ */
.shelf { margin-bottom: 4.5rem; scroll-margin-top: 9rem; }
.shelf[hidden] { display: none; }

.shelf__head {
    position: relative;
    padding-left: 1.1rem;
    margin-bottom: 1.75rem;
}
.shelf__head::before {
    content: '';
    position: absolute;
    inset: .15rem auto .15rem 0;
    width: 5px;
    border-radius: 3px;
    background: var(--spine, #0d9488);
}
.shelf__eyebrow {
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .18em;
    color: var(--spine, #0d9488);
    margin: 0 0 .4rem;
}
.shelf__title {
    display: flex;
    align-items: baseline;
    gap: .75rem;
    font-size: clamp(1.35rem, 2.6vw, 1.75rem);
    font-weight: 900;
    color: var(--ink);
    margin: 0 0 .6rem;
}
.shelf__count {
    font-size: .75rem;
    font-weight: 700;
    color: #a8a29e;
    font-variant-numeric: tabular-nums;
}
.shelf__summary {
    max-width: 48rem;
    font-size: .875rem;
    line-height: 1.9;
    color: var(--ink-soft);
    margin: 0;
}

.shelf__books {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    align-items: stretch;
}
@media (min-width: 640px) { .shelf__books { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .shelf__books { grid-template-columns: repeat(3, 1fr); } }

.shelf__board {
    height: 12px;
    margin-top: 1.1rem;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--wood), var(--wood-dark));
    box-shadow: 0 10px 18px -12px rgba(60, 40, 20, .75);
}
.shelf__empty {
    margin-top: 1rem;
    font-size: .875rem;
    color: #a8a29e;
}

/* 新着・関連記事のグリッド（棚板なし） */
.book-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}
@media (min-width: 640px) { .book-row { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .book-row { grid-template-columns: repeat(3, 1fr); } }

/* ============================================================
 * 索引ページのヒーローに置く、装飾用の本棚
 * ============================================================ */
/* 索引ヒーローの右下に置く。絶対配置にして、ヒーローの高さに影響させない。 */
.bookshelf-deco {
    position: absolute;
    right: 2.5rem;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    gap: .2rem;
    height: 5.4rem;
    max-width: 22rem;
    padding: 0 .75rem;
    border-bottom: 11px solid var(--wood);
    border-radius: 0 0 3px 3px;
    box-shadow: 0 11px 16px -12px rgba(60, 40, 20, .8);
}
.bookshelf-deco span {
    display: block;
    width: var(--w, 1.05rem);
    border-radius: 2px 2px 0 0;
    background: linear-gradient(180deg, var(--c), color-mix(in srgb, var(--c) 62%, #000));
    /* 背表紙の箔押し風の線 */
    box-shadow:
        inset -1px 0 0 rgba(255, 255, 255, .28),
        inset 0 12px 0 -10px rgba(255, 255, 255, .5),
        inset 0 20px 0 -18px rgba(255, 255, 255, .35);
}
/* 数冊だけ斜めに立てかけて、書架らしさを出す */
.bookshelf-deco span.is-tilted {
    transform: rotate(9deg);
    transform-origin: bottom left;
    margin-right: .35rem;
}
/* 幅が足りないときは見出しと重なるので隠す */
@media (max-width: 1023px) {
    .bookshelf-deco { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .book, .book:hover { transition: none; transform: none; }
}

/* ============================================================
 * フローティング目次（js/toc.js が生成）
 * ============================================================
 * 長い記事で、本文の上のレイヤーに常時表示する目次。
 * 1400px 以上では左に固定表示、それ未満では「目次」ボタンから開く
 * オーバーレイとして振る舞う。
 * ============================================================ */

.lib-toc {
    position: fixed;
    right: 1.25rem;
    left: auto;
    bottom: 1.5rem;
    z-index: 40;
    width: 15.5rem;
    max-height: min(70vh, calc(100vh - 9rem));
    display: none;
    flex-direction: column;
    background: rgba(253, 251, 247, .97);
    backdrop-filter: blur(10px);
    border: 1px solid #e7ded0;
    border-radius: 14px;
    box-shadow: 0 18px 40px -22px rgba(60, 40, 20, .55);
    overflow: hidden;
}
.lib-toc.is-open { display: flex; }

.lib-toc__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .7rem .5rem .7rem .95rem;
    border-bottom: 1px solid #eee4d6;
    background: #fff;
}
.lib-toc__label {
    font-size: .75rem;
    font-weight: 900;
    letter-spacing: .12em;
    color: var(--ink);
}
.lib-toc__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.85rem;
    height: 1.85rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #8a8078;
    cursor: pointer;
}
.lib-toc__close:hover { background: #f2ece1; color: var(--ink); }
.lib-toc__close svg { width: 1rem; height: 1rem; }

.lib-toc__nav { overflow-y: auto; padding: .5rem .45rem; }
.lib-toc__nav ol { list-style: none; margin: 0; padding: 0; }
.lib-toc__nav a {
    display: flex;
    gap: .55rem;
    align-items: baseline;
    padding: .45rem .6rem;
    border-radius: 8px;
    font-size: .8125rem;
    line-height: 1.5;
    color: var(--ink-soft);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background-color .15s, color .15s, border-color .15s;
}
.lib-toc__nav a:hover { background: #f4eee3; color: var(--ink); }
.lib-toc__nav a.is-current {
    background: #fff;
    color: var(--ink);
    font-weight: 700;
    border-left-color: var(--spine, #0d9488);
}
.lib-toc__num {
    flex: none;
    font-size: .6875rem;
    font-weight: 700;
    color: #b3a99c;
    font-variant-numeric: tabular-nums;
    min-width: 1.1em;
}
.lib-toc__nav a.is-current .lib-toc__num { color: var(--spine, #0d9488); }
.lib-toc__text { min-width: 0; }

.lib-toc__foot { padding: .55rem .65rem .7rem; border-top: 1px solid #eee4d6; background: #fff; }
.lib-toc__top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    width: 100%;
    padding: .5rem;
    border: 1px solid #e0d7c9;
    border-radius: 9999px;
    background: #fff;
    font-size: .75rem;
    font-weight: 700;
    color: var(--ink-soft);
    cursor: pointer;
    transition: background-color .15s, color .15s, border-color .15s;
}
.lib-toc__top:hover { background: #0d9488; border-color: #0d9488; color: #fff; }
.lib-toc__top svg { width: .85rem; height: .85rem; }

/* 開くボタン */
.lib-toc-open {
    position: fixed;
    right: 1.25rem;
    left: auto;
    bottom: 1.5rem;
    z-index: 41;
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .6rem 1.1rem;
    border: 1px solid #e0d7c9;
    border-radius: 9999px;
    background: rgba(253, 251, 247, .97);
    backdrop-filter: blur(10px);
    box-shadow: 0 12px 26px -16px rgba(60, 40, 20, .7);
    font-size: .8125rem;
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
}
.lib-toc-open:hover { border-color: #0d9488; color: #0d9488; }
.lib-toc-open svg { width: 1rem; height: 1rem; }
.lib-toc-open.is-hidden { display: none; }

.lib-toc-backdrop {
    position: fixed;
    inset: 0;
    z-index: 39;
    background: rgba(28, 25, 23, .35);
}
.lib-toc-backdrop[hidden] { display: none; }

/* 目次が常時開いているときは、本文と重ならないよう右に余白を確保する */
@media (min-width: 1400px) {
    .has-toc main { padding-right: 17rem; }
}

/* 狭い画面では、右下から立ち上がるオーバーレイにする */
@media (max-width: 1399px) {
    .lib-toc {
        left: 1rem;
        right: 1rem;
        width: auto;
        max-width: 26rem;
        margin-left: auto;
        max-height: 65vh;
    }
}

/* 見出しへ飛んだときに、固定ヘッダーの下に隠れないようにする */
main section[id] { scroll-margin-top: 5.5rem; }

@media print {
    .lib-toc, .lib-toc-open, .lib-toc-backdrop { display: none !important; }
}
