/* WordPress用縦書き電子書籍スタイル - v07 シンプル＆温かみデザイン */

/* ========================================
   ベースカラー設定
   温かみのある色調を使用
======================================== */
:root {
    --book-primary-color: #8B7355; /* ブラウン系の温かい色 */
    --book-secondary-color: #F5F2E8; /* ベージュ系の背景色 */
    --book-text-color: #4A4A4A; /* ソフトな黒 */
    --book-border-color: #D4C5B9; /* 優しいボーダー色 */
    --book-shadow-color: rgba(139, 115, 85, 0.1); /* 温かい影 */
    --book-accent-color: #C9A876; /* アクセントカラー */
    --book-paper-color: #FFFEF9; /* 紙のような背景色 */
}

/* ========================================
   書籍一覧用スタイル（シンプル版）
======================================== */
.digital-book-list-wrapper {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    font-family: 'Yu Gothic', 'Hiragino Kaku Gothic ProN', 'メイリオ', sans-serif;
}

.book-list-container {
    /* 背景を透明にして、親要素の背景を使用 */
}

.book-list-item {
    border-bottom: 1px solid #e5e5e5;
    padding-bottom: 20px;
    margin-bottom: 20px;
}

.book-list-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.book-list-header {
    display: flex;
    align-items: center; /* flex-start -> center に変更してボタンを天地中央に */
    justify-content: space-between;
}

.book-basic-info {
    flex: 1;
    margin-right: 20px;
}

.book-title-line {
    display: flex;
    align-items: center; /* baseline -> center に変更して天地中心を揃える */
    margin-bottom: 10px; /* 書籍名と著者の間隔を10pxに */
}

.book-title {
    margin: 0;
    font-size: 20px;
    font-weight: bold;
    color: #333;
}

/* 書籍一覧ページの書籍タイトルのマージン調整 */
.digital-book-list-wrapper .book-title {
    margin: 0;
}

.book-meta {
    font-size: 14px;
    color: #666;
}

.book-meta-item {
    margin-top: 4px; /* 各項目を改行で表示 */
}

.book-meta-item:first-child {
    margin-top: 0;
}

.book-author {
    font-weight: 500;
}

.chapter-count {
    margin-left: 15px;
    background-color: #f0f0f0;
    padding: 4px 10px; /* padding調整: 2px -> 4px (上下), 8px -> 10px (左右) */
    border-radius: 12px;
    font-size: 12px;
    display: inline-block;
    white-space: nowrap;
}

.book-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    align-items: center; /* flex-start -> center に変更 */
}

.read-btn {
    display: inline-block;
    padding: 8px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.read-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    color: white;
    text-decoration: none;
}

.book-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background-color: var(--book-secondary-color);
}

.book-list-item.expanded .book-details {
    max-height: 500px;
    transition: max-height 0.5s ease-in;
}

.book-details-content {
    padding: 0 24px 24px 59px;
}

.book-description {
    margin-bottom: 20px;
    line-height: 1.8;
    color: var(--book-text-color);
    font-size: 15px;
}

.book-chapters-list {
    margin-top: 15px;
}

.chapters-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--book-primary-color);
    display: flex;
    align-items: center;
}

.chapters-title::before {
    content: '📖';
    margin-right: 6px;
}

.chapter-item {
    padding: 8px 0;
    border-bottom: 1px dotted var(--book-border-color);
    font-size: 14px;
    line-height: 1.6;
    color: var(--book-text-color);
}

.chapter-item:last-child {
    border-bottom: none;
}

/* ========================================
   メインの書籍表示スタイル
======================================== */

/* 書籍ページのpost_content余白を削除 */
.post_content:has(.digital-book-wrapper) {
    margin: 0 !important;
    padding: 0 !important;
}

.digital-book-wrapper {
    font-family: 'Noto Serif JP', 'Yu Mincho', '游明朝', serif;
}

/* タイトルヘッダー（縦書き表示ページ・目次ページ） */
.book-title-header {
    text-align: center;
    padding: 45px 20px 10px;
    margin-bottom: 0;
}

.book-main-title {
    font-size: clamp(28px, 4vw, 42px);
    font-weight: 400;
    color: var(--book-primary-color);
    letter-spacing: 0.1em;
    line-height: 1.6;
    margin: 0;
}

/* ナビゲーション（タイトル直下に配置） */
.book-navigation {
    text-align: center;
    margin: 20px auto;
}

/* メインコンテンツ */
.main-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 10px 0 30px 0; /* 上10px、下30pxのパディング */
    writing-mode: vertical-rl;
    text-orientation: upright;
    height: calc(100vh - 280px); /* 高さを調整（300px→280px） */
    min-height: 400px; /* 最小高さを設定 */
    overflow-x: auto;
    overflow-y: hidden;
    font-size: 18px; /* 16px → 18px に変更 */
    line-height: 2.2;
    color: var(--book-text-color);
    letter-spacing: 0.05em;
}

/* スクロールバーのカスタマイズ */
.main-content::-webkit-scrollbar {
    height: 8px;
}

.main-content::-webkit-scrollbar-track {
    background: var(--book-secondary-color);
    border-radius: 4px;
}

.main-content::-webkit-scrollbar-thumb {
    background: var(--book-primary-color);
    border-radius: 4px;
}

.main-content::-webkit-scrollbar-thumb:hover {
    background: var(--book-accent-color);
}

/* 章セクション */
.chapter-section {
    margin-left: 0; /* margin削除 */
    padding-right: 0; /* padding削除 */
}

.chapter-section:first-child {
    margin-left: 0;
}

/* 章タイトル */
.chapter-title {
    font-size: 24px;
    font-weight: 400;
    margin: 0 0 30px 0;
    padding-left: 50px; /* 左パディング50px追加 */
    color: var(--book-text-color); /* 本文と同じ色に変更 */
    letter-spacing: 0.15em;
    position: relative;
}

.chapter-number-vertical {
    display: inline-block;
    font-size: 28px;
    font-weight: 600;
    color: var(--book-text-color); /* 本文と同じ色に変更 */
}

/* 章コンテンツ */
.chapter-content {
    font-size: 18px; /* 16px → 18px に統一 */
    line-height: 2.4;
    text-align: justify;
}

.chapter-content p {
    margin: 0 0 1.5em 0;
    text-indent: 1em;
}

/* 最後の段落にも確実にmarginを適用 */
.chapter-content p:last-child {
    margin: 0 0 1.5em 0 !important;
}

/* ルビ */
.chapter-content ruby {
    ruby-align: center;
}

.chapter-content rt {
    font-size: 0.5em;
    color: var(--book-text-color);
    opacity: 0.8;
}

/* 縦中横（二桁数字を横組み表示） */
.tcy-number {
    text-combine-upright: all;
    -webkit-text-combine: horizontal;
    -ms-text-combine-horizontal: all;
    font-feature-settings: normal;
    letter-spacing: 0 !important;
    margin: 0;
    padding: 0;
}

/* 縦書きコンテンツ内の画像スタイル */
.chapter-content img {
    max-width: 300px;
    max-height: 300px;
    width: auto;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

    /* 縦書きでの画像配置 */
    writing-mode: horizontal-tb;
    text-orientation: mixed;

    /* 画像を適切にセンタリング */
    object-fit: contain;
    order: 1; /* 画像を先に配置 */
}

/* 画像のキャプション */
.chapter-content .wp-caption {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    max-width: none !important;
    margin: auto 3em;
    text-align: center;
}

.chapter-content .wp-caption-text {
    font-size: 14px;
    color: #666;
    margin-top: 8px;
    line-height: 1.4;
    text-align: center;
}

/* WordPress画像ブロック */
.chapter-content .wp-block-image {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    margin: auto 3em;
    text-align: center;
}

.chapter-content .wp-block-image img {
    margin: 0 auto;
}

/* 画像の配置クラス */
.chapter-content .aligncenter {
    display: block;
    margin: auto 3em;
}

.chapter-content .alignleft,
.chapter-content .alignright {
    /* 縦書きでは左右配置を無効にして中央配置 */
    display: block;
    margin: auto 3em;
    float: none;
}

/* ギャラリー */
.chapter-content .wp-block-gallery,
.chapter-content .gallery {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    margin: auto 3em;
    text-align: center;
}

.chapter-content .gallery-item {
    display: inline-block;
    margin: 0 10px 10px 0;
    vertical-align: top;
}

/* 図表 */
.chapter-content figure {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 300px;
    height: 100%;
    margin: 0 auto;
    position: relative;
}

.chapter-content figcaption {
    display: block !important; /* 明示的に表示 */
    font-size: 14px;
    color: #666;
    margin-top: 8px;
    text-align: center;
    writing-mode: horizontal-tb; /* 横書きで表示 */
    text-orientation: mixed;
    order: 2; /* 画像の下に配置 */
}

/* 目次に戻るボタン（フローティング） */
.toc-icon-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--book-primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.toc-icon-btn:hover {
    background-color: var(--book-accent-color);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    transform: translateY(-2px);
}

.toc-icon-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.toc-icon-btn svg {
    filter: none;
}

/* アイキャッチ画像ページ */
.featured-image-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
}

.featured-image-container {
    max-width: 100%;
    max-height: 80%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-featured-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 6px 20px var(--book-shadow-color);
}

/* 目次 */
.toc-container {
    padding: 20px 0;
}

.toc-item {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px dotted var(--book-border-color);
}

.toc-item:last-child {
    border-bottom: none;
}

.toc-chapter-number {
    font-size: 18px;
    font-weight: 600;
    color: var(--book-accent-color);
    margin-bottom: 5px;
}

.toc-chapter-title {
    font-size: 16px;
    color: var(--book-text-color);
    line-height: 1.8;
}

.toc-chapter-title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.3s ease;
}

.toc-chapter-title a:hover {
    color: var(--book-primary-color);
}

.toc-page-number {
    font-size: 14px;
    color: var(--book-text-color);
    opacity: 0.7;
    margin-top: 5px;
}

.nav-controls {
    display: inline-flex;
    align-items: center;
    gap: 15px;
}

.nav-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    color: var(--book-text-color);
}

.nav-btn:hover:not(:disabled) {
    opacity: 0.7;
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-info {
    font-size: 16px;
    color: var(--book-text-color);
    min-width: 50px;
    text-align: center;
}

.loading-indicator {
    text-align: center;
    padding: 10px;
    color: var(--book-text-color);
    font-size: 14px;
}

/* プレビューページ用スタイル */
.book-preview-wrapper {
    max-width: 900px;
    margin: 40px auto;
    padding: 20px;
}

.preview-header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--book-secondary-color);
    border-radius: 8px;
}

.preview-title {
    font-size: 28px;
    color: var(--book-primary-color);
    margin: 0;
    font-weight: 400;
}

.preview-content {
    background: var(--book-paper-color);
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 6px 20px var(--book-shadow-color);
    border: 1px solid var(--book-border-color);
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    /* モバイルでは書籍タイトルヘッダーを非表示（デフォルト） */
    .book-title-header {
        display: none;
    }

    /* 表紙ページ（featured-image-page）がある時だけタイトルを表示 */
    .digital-book-wrapper:has(.featured-image-page) .book-title-header {
        display: block;
        padding: 15px 20px 5px; /* コンパクトに */
    }

    /* 表紙ページの時のナビゲーションのマージンを狭める */
    .digital-book-wrapper:has(.featured-image-page) .book-navigation {
        margin: 10px auto;
    }

    /* 表紙ページの時の本文エリアの高さ（フッター分を確保） */
    .digital-book-wrapper:has(.featured-image-page) .main-content {
        height: calc(100vh - 320px);
        padding-top: 0;
        padding-bottom: 0;
    }

    .main-content {
        height: calc(100vh - 240px);
        min-height: 300px; /* モバイルの最小高さ */
        padding: 10px 15px 30px 15px; /* 左右15pxのパディング追加 */
        max-width: calc(100% - 30px); /* 左右のマージン確保 */
    }

    .chapter-section {
        margin-left: 0; /* margin削除 */
        padding-right: 0; /* padding削除 */
    }

    .chapter-title {
        padding-left: 30px; /* モバイルでは左パディングを30pxに */
    }

    .chapter-number-vertical {
        font-size: 24px; /* 章タイトルサイズに合わせる */
    }

    .nav-btn {
        font-size: 14px;
    }

    .toc-icon-btn {
        width: 48px;
        height: 48px;
    }

    .book-list-header {
        padding: 20px 15px;
    }

    .book-title {
        font-size: 18px;
    }

    .read-btn {
        padding: 8px 18px;
        font-size: 13px;
    }

    .featured-image-page {
        padding: 10px;
    }

    .featured-image-container {
        max-height: 85%;
        max-width: calc(100vw / 1.5); /* ビューポート幅の66% */
        width: 100%;
    }

    .book-featured-image {
        max-height: 100%;
        max-width: calc(100vw / 1.5); /* コンテナと同じ計算で画像幅を制限 */
        object-fit: contain;
    }

    /* モバイルでの本文内画像調整 */
    .chapter-content img {
        max-height: 200px;
        margin: auto 2.5em;
    }
}

/* アニメーション */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chapter-section {
    animation: fadeIn 0.6s ease-out;
}

/* エラーメッセージ */
.digital-book-error {
    background: #FFF3E0;
    color: #E65100;
    padding: 15px 20px;
    border-radius: 8px;
    border-left: 4px solid #E65100;
    margin: 20px 0;
    font-size: 14px;
}

/* 印刷用スタイル */
@media print {
    .book-navigation,
    .book-list-header .book-actions {
        display: none;
    }

    .main-content {
        height: auto;
        overflow: visible;
        writing-mode: initial;
        box-shadow: none;
        border: none;
    }
}