:root {
    --primary-color: #6a4c3a;
    --secondary-color: #f5f0e8;
    --text-color: #3e3e3e;
    --accent-color: #a47e69;
    --white-color: #ffffff;
    --bg-main: var(--secondary-color);
    --bg-content: var(--white-color);
    --text-main: var(--text-color);
    --text-heading: var(--primary-color);
    --border-color: #e0d8cc;
}

body.dark-theme {
    --primary-color: #d3bda6;
    --secondary-color: #1a1a1a;
    --text-color: #c7c7c7;
    --accent-color: #a47e69;
    --white-color: #2c2c2c;
    --bg-main: #1a1a1a;
    --bg-content: #2c2c2c;
    --text-main: #c7c7c7;
    --text-heading: #d3bda6;
    --border-color: #444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    overflow-x: hidden; /* 追加: html要素での横スクロール防止 */
}

body {
    font-family: "Noto Serif JP", "游明朝 Medium", "Yu Mincho Medium", "YuMincho Medium", "ヒラギノ明朝 ProN", "Hiragino Mincho ProN", serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.8;
    overflow-x: hidden;
    transition: background-color 0.3s, color 0.3s;
    -webkit-text-size-adjust: 100%;
    width: 100%; /* 追加 */
    min-height: 100vh; /* 追加 */
    padding-top: 60px; /* ヘッダー分の余白を追加 */
}

/* --- リーダーページ専用ヘッダー --- */
.reader-header {
    background-color: rgba(245, 240, 232, 0.95);
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    transition: background-color 0.3s, border-color 0.3s;
    width: 100%;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
body.dark-theme .reader-header {
    background-color: rgba(44, 44, 44, 0.95);
}
.reader-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 100%;
    padding: 0 20px;
    width: 100%; /* 追加 */
}
.logo a {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-heading);
    text-decoration: none; /* 追加 */
    white-space: nowrap; /* 追加: ロゴの改行を防ぐ */
}
.reader-controls {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-shrink: 0; /* 追加: 縮小を防ぐ */
}
.display-settings-btn, .menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-heading);
    flex-shrink: 0; /* 追加 */
}
.menu-toggle {
    width: 25px;
    height: 25px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}
.menu-toggle .bar {
    display: block;
    width: 100%;
    height: 3px;
    background-color: var(--text-heading);
}

/* --- メインレイアウト --- */
.reader-container {
    display: flex;
    gap: 30px;
    padding: 30px 20px;
    align-items: flex-start;
    max-width: 100%; /* 追加 */
    width: 100%; /* 追加 */
}

/* --- サイドバー（著者情報・関連小説） --- */
.sidebar-left, .sidebar-right {
    flex-shrink: 0;
    width: 260px;
    position: sticky;
    top: 80px; /* ヘッダー分の余白を増やす */
    height: calc(100vh - 90px);
    overflow-y: auto;
    max-width: 100%; /* 追加 */
}

.sidebar-card {
    background: var(--bg-content);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    transition: background-color 0.3s;
    max-width: 100%; /* 追加 */
    overflow: hidden; /* 追加 */
}
body.dark-theme .sidebar-card {
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.sidebar-card h3 {
    font-size: 18px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-heading);
    transition: border-color 0.3s, color 0.3s;
    word-wrap: break-word; /* 追加 */
    overflow-wrap: break-word; /* 追加 */
}

.author-card .author-image {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background-color: #eee;
    margin: 0 auto 15px auto;
    background-size: cover;
}

.author-card .author-name {
    font-size: 20px;
    text-align: center;
    margin-bottom: 5px;
    word-wrap: break-word; /* 追加 */
    overflow-wrap: break-word; /* 追加 */
}
.author-card .author-bio {
    font-size: 14px;
    text-align: center;
    color: #777;
    word-wrap: break-word; /* 追加 */
    overflow-wrap: break-word; /* 追加 */
}
body.dark-theme .author-card .author-bio {
    color: #aaa;
}

.related-novel-list {
    list-style: none;
}
.related-novel-item a {
    display: block;
    padding: 10px;
    border-radius: 5px;
    transition: background-color 0.3s;
    text-decoration: none;
    word-wrap: break-word; /* 追加 */
    overflow-wrap: break-word; /* 追加 */
}
.related-novel-item a:hover {
    background-color: var(--bg-main);
}
.related-novel-item .title {
    font-weight: bold;
    color: var(--text-main);
    font-size: 15px;
    word-wrap: break-word; /* 追加 */
    overflow-wrap: break-word; /* 追加 */
}
.related-novel-item .author {
    font-size: 13px;
    color: var(--accent-color);
    word-wrap: break-word; /* 追加 */
    overflow-wrap: break-word; /* 追加 */
}

/* --- 本文コンテンツ --- */
.main-content {
    min-width: 0; /* これは重要: flexboxで幅が縮小できるようにする */
    flex-grow: 1;
    background: var(--bg-content);
    padding: 50px;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.07);
    transition: background-color 0.3s;
    max-width: 100%; /* 追加 */
    overflow-x: hidden; /* 追加: 横スクロール防止 */
}
body.dark-theme .main-content {
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.novel-title {
    text-align: center;
    font-size: 32px;
    margin-bottom: 50px;
    color: var(--text-heading);
    word-wrap: break-word; /* 追加 */
    overflow-wrap: break-word; /* 追加 */
}
.novel-text {
    max-width: 100%; /* ★修正: セミコロンを追加 */
    font-size: 17px;
    line-height: 2.2;
    white-space: pre-wrap;
    transition: font-size 0.3s;
    word-wrap: break-word; /* 変更: break-allからbreak-wordへ */
    overflow-wrap: break-word;
    /* word-break: break-all; を削除 */
    hyphens: auto; /* 追加: 自動ハイフネーション */
    -webkit-hyphens: auto; /* 追加: Safari対応 */
    -ms-hyphens: auto; /* 追加: IE対応 */
}
.novel-text.font-size-small { font-size: 14px; }
.novel-text.font-size-large { font-size: 21px; }

/* --- ポップアップ共通 --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1999;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* --- 表示設定ポップアップ --- */
.settings-modal, .resume-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -60%);
    background: var(--bg-content);
    border-radius: 18px;
    padding: 20px;
    width: 90%;
    max-width: 340px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    z-index: 2001;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}
.settings-modal.visible, .resume-modal.visible {
    opacity: 1;
    transform: translate(-50%, -50%);
    pointer-events: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h4 {
    font-size: 22px;
    color: var(--text-heading);
}
.close-modal-btn {
    background: none;
    border: none;
    font-size: 25px;
    cursor: pointer;
    color: #888;
}
.setting-group {
    margin-bottom: 20px;
}
.setting-group label {
    display: block;
    margin-bottom: 10px;
    font-size: 15px;
    color: var(--text-main);
}
.control-buttons {
    display: flex;
}
.control-buttons button {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-main);
    color: var(--text-main);
    cursor: pointer;
}
.control-buttons button:first-child { border-radius: 5px 0 0 5px; }
.control-buttons button:last-child { border-radius: 0 5px 5px 0; }
.control-buttons button.active {
    background: var(--primary-color);
    color: var(--white-color);
    border-color: var(--primary-color);
}
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 28px;
}
.slider:before {
    position: absolute; content: ""; height: 20px; width: 20px;
    left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(22px); }

/* --- 履歴再開ポップアップ --- */
.resume-modal {
    padding: 30px;
    text-align: center;
}
.resume-modal p {
    font-size: 20px;
    margin-bottom: 20px;
    color: var(--text-main);
}
.resume-modal button {
    background-color: var(--primary-color);
    color: var(--white-color);
    border: none;
    padding: 10px 30px;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}
.resume-modal button:hover {
    background-color: var(--accent-color);
}

/* --- 三本線メニューポップアップ --- */
.actions-modal {
    position: fixed;
    bottom: -100%;
    left: 0;
    width: 100%;
    background: var(--bg-content);
    border-top: 1px solid var(--border-color);
    z-index: 2000;
    transition: bottom 0.3s ease-in-out;
    padding: 10px 0;
}
.actions-modal.visible {
    bottom: 0;
}
.actions-list {
    display: flex;
    justify-content: space-around;
    list-style: none;
}
.action-item button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-radius: 8px;
    width: 100px;
}
.action-item button:hover {
    background-color: var(--bg-main);
}
.action-item svg {
    width: 24px;
    height: 24px;
    fill: var(--text-heading);
}

/* --- Toast Notification --- */
.toast-notification {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0,0,0,0.8);
    color: white;
    padding: 12px 25px;
    border-radius: 25px;
    font-size: 14px;
    z-index: 3000;
    transition: bottom 0.5s ease-in-out, opacity 0.5s ease-in-out;
    opacity: 0;
}
.toast-notification.show {
    bottom: 30px;
    opacity: 1;
}

/* --- レスポンシブ対応 --- */
@media (max-width: 1080px) {
    .reader-container {
        flex-direction: column;
    }
    .sidebar-left, .sidebar-right {
        position: static;
        width: 100%;
        height: auto;
        overflow-y: visible;
    }
    .main-content {
        order: -1;
    }
}
@media (max-width: 768px) {
    .reader-container {
        padding: 0px 0;
        width: 100%; /* 追加 */
    }
    .main-content {
        padding: 30px 18px;
        border-radius: 0;
        width: 100%; /* 追加 */
    }
    .novel-title {
        font-size: 28px;
    }
    .logo a {
        font-size: 20px;
    }
    .display-settings-btn {
        font-size: 14px;
    }
    .reader-header .container {
        padding: 0 10px;
    }
    .reader-controls {
        gap: 10px;
    }
    
    /* スマホ専用の追加修正 */
    .novel-text {
        /* スマホで特に重要 */
        overflow-wrap: anywhere; /* より強力な改行 */
    }
}