/* =========================================================
   スライドショーマニュアル
   z-index: 9500（既存モーダルより上、tourFloatBtn より上）
   グローバル CSS の `body * { font-size: ...!important; }` を
   上書きするため、必要箇所に !important を付与する。
   ========================================================= */

#manualSlidesOverlay {
    position: fixed;
    inset: 0;
    z-index: 9500;
    background: rgba(15, 23, 42, 0.88);
    display: none;
    flex-direction: column;
    color: #1f2937;
    font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
}
#manualSlidesOverlay.is-open { display: flex; }

/* ダイアログモード: 右クリックヘルプ起動時。画面90%サイズで浮遊表示 */
#manualSlidesOverlay.is-dialog {
    inset: 5vh 5vw;
    border-radius: 12px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}
#manualSlidesOverlay.is-dialog::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
    pointer-events: none;
}

#manualSlidesOverlay * { box-sizing: border-box; }

/* ── ヘッダー（タイトル＋編集トグル＋閉じる） ── */
.ms-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #f59e0b 0%, #b45309 100%);
    color: #fff;
}
.ms-header .ms-title {
    flex: 0 1 auto;
    min-width: 0;
    font-size: 18px !important;
    font-weight: 700;
    letter-spacing: 0.02em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius: 4px;
    padding: 2px 6px;
    margin-left: -6px;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}
.ms-header .ms-title.is-editable {
    cursor: text;
}
/* 編集アクション群 (編集/undo/redo/保存/閉じる) をヘッダー右端へまとめて寄せる wrapper。
   editToggle 等が非表示のときも closeBtn(×) が確実に一番右に配置される。 */
.ms-header .ms-header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}
.ms-header .ms-title.is-editable:hover {
    background: rgba(255, 255, 255, 0.18);
    text-decoration: underline;
    text-decoration-color: rgba(255, 255, 255, 0.6);
    text-underline-offset: 3px;
}
.ms-header .ms-title.is-editable:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.28);
    color: #fff;
    text-decoration: underline;
    text-decoration-color: #fff;
    text-underline-offset: 3px;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.55);
    white-space: nowrap;
}

/* ── サイドバー最上部の検索（章・スライド・本文） ── */
.ms-sidebar .ms-search-wrap {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    padding: 8px 12px;
}
.ms-sidebar .ms-search-icon {
    flex: 0 0 auto;
    font-size: 12px !important;
    color: #6b7280;
}
.ms-sidebar .ms-search-input {
    flex: 1 1 auto;
    min-width: 0;
    background: #fff;
    border: 1px solid #d1d5db;
    outline: none;
    color: #1f2937;
    font-size: 12px !important;
    padding: 6px 8px;
    border-radius: 5px;
}
.ms-sidebar .ms-search-input:focus { border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2); }
.ms-sidebar .ms-search-input::placeholder { color: #9ca3af; }
.ms-sidebar .ms-search-input::-webkit-search-cancel-button { display: none; }
.ms-sidebar .ms-search-clear {
    flex: 0 0 auto;
    display: none;
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    font-size: 12px !important;
    padding: 2px 4px;
}
.ms-sidebar .ms-search-clear:hover { color: #1f2937; }
.ms-search-results {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 8px;
    right: 8px;
    min-width: 0;
    max-height: 60vh;
    overflow-y: auto;
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
    z-index: 9520;
    padding: 4px;
}
.ms-search-results.is-open { display: block; }
.ms-search-group { border-bottom: 1px solid #f3f4f6; }
.ms-search-group:last-child { border-bottom: none; }
.ms-search-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
    padding: 7px 10px;
    cursor: pointer;
    border-radius: 5px;
    font-size: 13px !important;
}
.ms-search-item:hover,
.ms-search-item.is-active { background: #fff7ed; }
.ms-search-item.is-header {
    font-weight: 700;
    color: #b45309;
    background: #fafafa;
}
.ms-search-item.is-header:hover,
.ms-search-item.is-header.is-active { background: #fff1e0; }
.ms-search-item-icon {
    font-size: 11px !important;
    color: #d97706;
}
.ms-search-item-num {
    flex: 0 0 auto;
    font-size: 11px !important;
    color: #9ca3af;
}
.ms-search-item-title {
    flex: 1 1 auto;
    min-width: 0;
}
.ms-search-item-desc {
    flex: 1 1 100%;
    font-size: 11px !important;
    color: #6b7280;
    padding-left: 2px;
}
.ms-search-hl {
    background: #fde68a;
    color: #7c2d12;
    border-radius: 2px;
    padding: 0 1px;
}
.ms-search-empty {
    padding: 16px;
    text-align: center;
    color: #6b7280;
    font-size: 13px !important;
}

.ms-header .ms-btn {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px !important;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s ease;
}
.ms-header .ms-btn:hover { background: rgba(255, 255, 255, 0.3); }
.ms-header .ms-btn.is-active { background: #fff; color: #b45309; }
.ms-header .ms-history-btn {
    padding: 6px 10px;
    min-width: 32px;
    justify-content: center;
}
.ms-header .ms-history-btn:disabled,
.ms-header .ms-history-btn.is-disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.05);
    pointer-events: none;
}
/* 閲覧履歴「戻る」ボタン (headerActions 内, closeBtn の直前)。
   navStack が空なら .is-disabled でグレーアウト。 */
.ms-header .ms-nav-back-btn {
    padding: 6px 10px;
    min-width: 32px;
    justify-content: center;
}
.ms-header .ms-nav-back-btn:disabled,
.ms-header .ms-nav-back-btn.is-disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.05);
    pointer-events: none;
}
.ms-header .ms-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 24px !important;
    cursor: pointer;
    padding: 0 6px;
    line-height: 1;
}

/* ── 本体 2 カラム ── */
.ms-body {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
    background: #f9fafb;
}

/* ── サイドバー（章リスト） ── */
.ms-sidebar {
    flex: 0 0 260px;
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
    transition: flex-basis 0.25s ease, padding 0.25s ease, border-color 0.25s ease, opacity 0.2s ease;
}
/* デスクトップ: サイドバー折りたたみ（目次ボタン/ハンバーガーでトグル。スマホは専用の off-canvas 表示に別途対応） */
@media (min-width: 769px) {
    .ms-body:not(.is-sidebar-open) .ms-sidebar {
        flex: 0 0 0;
        min-width: 0;
        padding: 0;
        border-right-color: transparent;
        opacity: 0;
        overflow: hidden;
        pointer-events: none;
    }
}
.ms-sidebar .ms-sidebar-actions {
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    display: none;
    gap: 6px;
}
.ms-sidebar .ms-sidebar-actions.is-edit { display: flex; }
.ms-sidebar .ms-sidebar-actions .ms-btn {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    padding: 6px 10px;
    font-size: 12px !important;
    cursor: pointer;
}
.ms-sidebar .ms-sidebar-actions .ms-btn:hover { background: #e5e7eb; }
.ms-sidebar .ms-sidebar-actions .ms-sidebar-add-chapter {
    flex: 1 1 auto;
    width: auto;
}
.ms-sidebar .ms-sidebar-actions .ms-sidebar-toggle-all {
    flex: 0 0 auto;
    width: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
}

/* サイドバー: カテゴリ見出し（章を6分類にグルーピング）。編集/表示どちらのモードでも表示する */
.ms-category-group {
    border-bottom: 1px solid #e5e7eb;
}
.ms-category-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    cursor: pointer;
    background: #eef2ff;
    font-weight: 700;
    color: #3730a3;
    font-size: 12px !important;
    position: sticky;
    top: 0;
    z-index: 1;
}
.ms-category-head:hover { background: #e0e7ff; }
.ms-category-caret {
    font-size: 12px !important;
    transition: transform 0.15s ease;
}
.ms-category-head.is-collapsed .ms-category-caret { transform: rotate(-90deg); }
.ms-category-label { flex: 1 1 auto; }
.ms-category-count {
    color: #6366f1;
    font-weight: 400;
    font-size: 11px !important;
}
/* カテゴリ並べ替え ▲▼ (編集モードのみ DOM 生成される) */
.ms-category-move {
    flex: 0 0 auto;
    display: flex;
    gap: 2px;
}
.ms-category-move .ms-category-move-btn {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid #c7d2fe;
    color: #3730a3;
    border-radius: 4px;
    width: 22px;
    height: 22px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 11px !important;
    line-height: 1;
}
.ms-category-move .ms-category-move-btn:hover { background: #fff; border-color: #6366f1; }
/* 名称変更は ▲▼ と別操作なので色で区別 (誤爆防止) */
.ms-category-move .ms-category-rename-btn {
    color: #b45309;
    border-color: #fcd34d;
}
.ms-category-move .ms-category-rename-btn:hover { border-color: #d97706; }
.ms-category-move .ms-category-move-btn.is-disabled,
.ms-category-move .ms-category-move-btn:disabled {
    opacity: 0.35;
    pointer-events: none;
}
.ms-category-group.is-collapsed .ms-category-chapters { display: none; }

.ms-chapter {
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
}
.ms-chapter .ms-chapter-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-weight: 700;
    color: #111827;
    font-size: 14px !important;
}
.ms-chapter .ms-chapter-head:hover { background: #f3f4f6; }
.ms-chapter .ms-chapter-handle {
    color: #9ca3af;
    cursor: grab;
    display: none;
}
.ms-chapter .ms-chapter-handle:active { cursor: grabbing; }
.ms-chapter.is-edit .ms-chapter-handle { display: inline; }
.ms-chapter .ms-chapter-title {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius: 4px;
    padding: 1px 4px;
}
.ms-chapter .ms-chapter-title.is-editable {
    cursor: text;
}
.ms-chapter .ms-chapter-title.is-editable:hover {
    background: #fff7ed;
    text-decoration: underline;
    text-decoration-color: #f59e0b;
    text-underline-offset: 2px;
}
.ms-chapter .ms-chapter-title.is-editable:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 2px #f59e0b;
    color: #111827;
}
.ms-chapter .ms-chapter-del {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 14px !important;
    display: none;
    padding: 0 4px;
}
.ms-chapter.is-edit .ms-chapter-del { display: inline; }

/* 章タイトル横のリンク設定ボタン（編集モードのみ表示） */
.ms-chapter .ms-chapter-links-btn {
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    font-size: 13px !important;
    display: none;
    padding: 0 4px;
    position: relative;
}
.ms-chapter.is-edit .ms-chapter-links-btn { display: inline; }
.ms-chapter .ms-chapter-links-btn:hover { color: #1d4ed8; }
.ms-chapter .ms-chapter-links-btn.has-links { color: #1d4ed8; }
.ms-chapter .ms-chapter-links-count {
    display: inline-block;
    background: #1d4ed8;
    color: #fff;
    border-radius: 999px;
    padding: 0 5px;
    font-size: 10px !important;
    margin-left: 2px;
    vertical-align: text-top;
    line-height: 14px;
    min-width: 14px;
    text-align: center;
    font-weight: 700;
}

/* 対象ボタンキー選択（右クリックヘルプ用）。編集モード（.ms-chapter.is-edit）のみ表示。fix76 のCSSスコープ規則を踏襲。 */
.ms-chapter .ms-chapter-target-row {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 2px 12px 6px 34px;
}
.ms-chapter.is-edit .ms-chapter-target-row { display: flex; }
.ms-chapter .ms-chapter-target-label {
    flex: 0 0 auto;
    color: #9ca3af;
    font-size: 11px !important;
}

/* 対象ボタンキー共通フィールド（select + カスタム入力トグル）。サイドバー(.is-compact)とリンク設定モーダルで共用。fix281 */
.ms-chtarget-field {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.ms-chtarget-row {
    display: flex;
    align-items: center;
    gap: 4px;
}
.ms-chtarget-select {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px !important;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    color: #374151;
    background: #fff;
}
.ms-chtarget-field.is-compact .ms-chtarget-select { font-size: 11px !important; padding: 3px 4px; }
.ms-chtarget-select:focus {
    outline: none;
    border-color: #f59e0b;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}
.ms-chtarget-custom-toggle {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #f9fafb;
    color: #6b7280;
    font-size: 11px !important;
    cursor: pointer;
}
.ms-chtarget-custom-toggle:hover { background: #eef2ff; color: #4338ca; }
.ms-chtarget-custom-input {
    font-size: 12px !important;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    color: #374151;
    background: #fff;
}
.ms-chtarget-custom-input:focus {
    outline: none;
    border-color: #f59e0b;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}
.ms-chtarget-custom-input.is-invalid {
    border-color: #ef4444;
    background: #fef2f2;
}
.ms-chtarget-key-hint {
    color: #9ca3af;
    font-size: 10px !important;
    line-height: 1.3;
    min-height: 1.3em;
}
.ms-chtarget-key-hint:empty { min-height: 0; }

/* 右サイド リンクリストパネル（表示モード時のみ） */
.ms-links-panel {
    display: none;
    flex: 0 0 200px;
    background: #ffffff;
    border-left: 1px solid #e5e7eb;
    padding: 8px 0;
    overflow-y: auto;
}
.ms-links-panel.is-visible { display: block; }
.ms-links-panel .ms-links-panel-head {
    padding: 6px 12px;
    color: #374151;
    font-weight: 700;
    font-size: 13px !important;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 6px;
}
.ms-links-panel .ms-links-panel-head i { color: #1d4ed8; }
.ms-links-panel .ms-links-panel-list {
    display: flex;
    flex-direction: column;
    padding: 6px 0;
}
.ms-links-panel .ms-links-panel-item {
    background: transparent;
    border: none;
    text-align: left;
    padding: 8px 12px;
    cursor: pointer;
    color: #1d4ed8;
    font-size: 13px !important;
    display: flex;
    align-items: center;
    gap: 6px;
    border-left: 3px solid transparent;
}
.ms-links-panel .ms-links-panel-item:hover {
    background: #eff6ff;
    border-left-color: #1d4ed8;
}
.ms-links-panel .ms-links-panel-item-arrow {
    color: #9ca3af;
    font-size: 10px !important;
}
.ms-links-panel .ms-links-panel-item:hover .ms-links-panel-item-arrow { color: #1d4ed8; }
.ms-links-panel .ms-links-panel-item-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* リンク設定モーダル */
.ms-links-editor-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.ms-links-editor {
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
    width: 100%;
    max-width: 640px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ms-links-editor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}
.ms-links-editor-title {
    font-weight: 700;
    color: #111827;
    font-size: 14px !important;
}
.ms-links-editor-close {
    background: transparent;
    border: none;
    font-size: 20px !important;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 0 8px;
}
.ms-links-editor-close:hover { color: #111827; }
.ms-links-editor-body {
    padding: 12px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ms-links-editor-hint {
    color: #6b7280;
    font-size: 12px !important;
}
.ms-links-editor-empty {
    color: #9ca3af;
    font-size: 13px !important;
    padding: 12px 4px;
    text-align: center;
}
.ms-links-editor-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ms-links-editor-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
}
.ms-links-editor-row-num {
    color: #9ca3af;
    font-size: 12px !important;
    width: 20px;
}
.ms-links-editor-row-title {
    flex: 1 1 40%;
    padding: 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px !important;
}
.ms-links-editor-row-arrow {
    color: #9ca3af;
}
.ms-links-editor-row-target {
    flex: 1 1 45%;
    padding: 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px !important;
    background: #fff;
}
.ms-links-editor-row-del {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 13px !important;
}
.ms-links-editor-row-del:hover { color: #b91c1c; }
.ms-links-editor-addrow {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px dashed #e5e7eb;
}
.ms-links-editor-addrow-label {
    color: #374151;
    font-size: 12px !important;
    font-weight: 700;
    width: 40px;
}
.ms-links-editor-target,
.ms-links-editor-title-input {
    padding: 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px !important;
}
.ms-links-editor-target { flex: 1 1 40%; background: #fff; }
.ms-links-editor-title-input { flex: 1 1 35%; }
.ms-links-editor-url-input,
.ms-links-editor-row-url {
    flex: 1 1 45%;
    padding: 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 12px !important;
    background: #fffbeb;
    color: #1f2937;
    font-family: ui-monospace, "SFMono-Regular", "Consolas", monospace;
}
.ms-links-editor-url-input:focus,
.ms-links-editor-row-url:focus {
    outline: none;
    border-color: #f59e0b;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}
.ms-links-editor-add {
    background: #1d4ed8;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px !important;
    font-weight: 600;
}
.ms-links-editor-add:hover { background: #1e40af; }

/* リンク設定モーダル内 対象ボタンキー選択（サイドバーの .ms-chtarget-field と STATE.data.chapters[ci].target を共有） */
.ms-links-editor-chtarget-section {
    padding: 12px 16px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ms-links-editor-chtarget-label {
    color: #374151;
    font-size: 12px !important;
    font-weight: 700;
}
.ms-links-editor-chtarget-hint {
    color: #9ca3af;
    font-size: 11px !important;
}
.ms-links-editor-chtarget-section .ms-chtarget-select { font-size: 13px !important; padding: 6px 8px; }
/* リンク設定モーダル内 カテゴリ選択（サイドバーの分類先） */
.ms-links-editor-category-select {
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px !important;
    background: #fff;
    color: #374151;
}
.ms-links-editor-divider {
    margin: 12px 16px 0;
    border-top: 1px solid #eee;
}

/* 章の折りたたみ三角ボタン */
.ms-chapter .ms-chapter-toggle {
    flex: 0 0 auto;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #6b7280;
    width: 20px;
    height: 20px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    line-height: 1;
}
.ms-chapter .ms-chapter-toggle i {
    font-size: 14px !important;
    transition: transform 0.15s ease;
    transform: rotate(0deg);
    display: block;
}
.ms-chapter .ms-chapter-toggle:hover {
    background: #e5e7eb;
    color: #111827;
}
.ms-chapter .ms-chapter-toggle.is-collapsed i {
    transform: rotate(-90deg);
}
.ms-chapter.is-collapsed > .ms-slide-list,
.ms-chapter.is-collapsed > .ms-chapter-target-row {
    display: none;
}

/* 表示モード（非編集）ではサイドバーの折りたたみボタンとスライド一覧を隠す */
.ms-chapter:not(.is-edit) .ms-chapter-toggle,
.ms-chapter:not(.is-edit) > .ms-slide-list {
    display: none;
}
/* 表示モードでは現在章のヘッダーをハイライト */
.ms-chapter:not(.is-edit).is-current > .ms-chapter-head {
    background: #fef3c7;
    color: #92400e;
    border-left: 3px solid #f59e0b;
    padding-left: 9px;
}

.ms-slide-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.ms-slide-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px 5px 28px;
    cursor: pointer;
    color: #4b5563;
    font-size: 13px !important;
    border-left: 3px solid transparent;
}
.ms-slide-item:hover { background: #f3f4f6; }
.ms-slide-item.is-current {
    background: #fef3c7;
    color: #92400e;
    border-left-color: #f59e0b;
    font-weight: 600;
}
.ms-slide-item .ms-slide-handle {
    color: #9ca3af;
    cursor: grab;
    display: none;
}
.ms-slide-item.is-edit .ms-slide-handle { display: inline; }
.ms-slide-item .ms-slide-num {
    flex: 0 0 28px;
    color: #9ca3af;
    font-size: 11px !important;
}
.ms-slide-item .ms-slide-name {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ms-slide-item .ms-slide-del {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 12px !important;
    display: none;
    padding: 0 4px;
}
.ms-slide-item.is-edit .ms-slide-del { display: inline; }

/* サイドバー スライド右クリックのコンテキストメニュー */
.ms-context-menu {
    position: fixed;
    z-index: 99999;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    padding: 4px;
    min-width: 180px;
    font-size: 13px !important;
    color: #111827;
}
.ms-context-menu .ms-context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    border: none;
    text-align: left;
    padding: 8px 12px;
    cursor: pointer;
    color: inherit;
    font-size: 13px !important;
    border-radius: 4px;
}
.ms-context-menu .ms-context-menu-item:hover,
.ms-context-menu .ms-context-menu-item:focus {
    background: #eff6ff;
    color: #1d4ed8;
    outline: none;
}
.ms-context-menu .ms-context-menu-item i {
    width: 14px;
    color: #6b7280;
    font-size: 13px !important;
}
.ms-context-menu .ms-context-menu-item:hover i { color: #1d4ed8; }
.ms-context-menu .ms-context-menu-item.is-danger { color: #b91c1c; }
.ms-context-menu .ms-context-menu-item.is-danger i { color: #b91c1c; }
.ms-context-menu .ms-context-menu-item.is-danger:hover,
.ms-context-menu .ms-context-menu-item.is-danger:focus {
    background: #fee2e2;
    color: #991b1b;
}
.ms-context-menu .ms-context-menu-item.is-danger:hover i { color: #991b1b; }
.ms-context-menu .ms-context-menu-sep {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 4px 2px;
}

/* サイドバー 章ドラッグハンドル右クリック/長押しの「カテゴリ変更」メニュー */
.ms-category-ctxmenu { min-width: 220px; }
.ms-context-menu-header {
    padding: 6px 12px 8px;
    font-size: 12px !important;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ms-category-ctxmenu-item {
    justify-content: flex-start;
}
.ms-category-ctxmenu-item.is-current {
    cursor: default;
    font-weight: 700;
    color: #0a91d9;
}
.ms-category-ctxmenu-item.is-current:hover,
.ms-category-ctxmenu-item.is-current:focus {
    background: transparent;
    color: #0a91d9;
    outline: none;
}
.ms-category-ctxmenu-check {
    width: 14px;
    display: inline-flex;
    justify-content: center;
    color: #0a91d9;
    font-size: 12px !important;
}
.ms-category-ctxmenu-label {
    flex: 1 1 auto;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ms-category-ctxmenu-count {
    flex: 0 0 auto;
    color: #9ca3af;
    font-size: 12px !important;
}
.ms-category-ctxmenu-item.is-current .ms-category-ctxmenu-count { color: #0a91d9; }

/* ── メイン（大画像 + テキスト） ── */
.ms-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}
.ms-stage {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: #1f2937;
    min-height: 0;
    position: relative;
}
/* 画像 + SVG オーバーレイのラッパー。JS で aspect-ratio を natural 比に合わせる →
   max-width/max-height:100% でステージ内にフィットしつつ縦横比が保たれる */
.ms-stage-inner {
    position: relative;
    display: block;
    max-width: 100%;
    max-height: 100%;
    line-height: 0;
    margin: 0 auto;
    /* スワイプ時の縦スクロール阻害を最小化（横方向のみ扱う） */
    touch-action: pan-y;
    will-change: transform;
}
/* 表示モード時のみスワイプ用カーソル */
.ms-stage:not(.is-edit) .ms-stage-inner { cursor: grab; }
.ms-stage:not(.is-edit) .ms-stage-inner.is-swiping { cursor: grabbing; }
/* ドラッグ中はトランジション無し（指/マウスに完全追従） */
.ms-stage-inner.is-swiping { transition: none; }
/* アニメ中のみトランジション有効 */
.ms-stage-inner.is-swiping-anim {
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ms-stage-inner img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 6px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    cursor: default;
}
.ms-stage.is-edit .ms-stage-inner img {
    outline: 2px dashed #f59e0b;
    outline-offset: 4px;
}
/* 編集モード（選択ツール時）のみ画像クリックで差し替え */
.ms-stage-inner[data-tool="select"] img { cursor: pointer; }
.ms-stage-inner[data-tool="click"] img,
.ms-stage-inner[data-tool="number"] img,
.ms-stage-inner[data-tool="callout"] img,
.ms-stage-inner[data-tool="arrow"] img,
.ms-stage-inner[data-tool="line"] img,
.ms-stage-inner[data-tool="box"] img,
.ms-stage-inner[data-tool="finger"] img,
.ms-stage-inner[data-tool="image"] img { cursor: crosshair; }
.ms-stage-inner[data-tool="delete"] img { cursor: not-allowed; }
/* 表示モードの画像はデフォルト */
.ms-stage:not(.is-edit) .ms-stage-inner img { cursor: default; }

/* SVG オーバーレイ */
.ms-marker-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}
.ms-marker-svg.is-edit { pointer-events: none; }
.ms-marker-svg.is-edit .ms-marker { pointer-events: auto; cursor: pointer; }
.ms-marker-svg.is-edit .ms-marker-handle { pointer-events: auto; cursor: move; }
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-marker-handle.ms-handle-arrow-start,
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-marker-handle.ms-handle-arrow-end,
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-marker-handle.ms-handle-callout-anchor,
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-marker-handle.ms-handle-image-anchor {
    cursor: crosshair;
}
/* ボックスのリサイズハンドル (8方向) */
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-handle-box-nw,
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-handle-box-se { cursor: nwse-resize; }
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-handle-box-ne,
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-handle-box-sw { cursor: nesw-resize; }
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-handle-box-n,
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-handle-box-s { cursor: ns-resize; }
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-handle-box-e,
.ms-marker-svg.is-edit .ms-marker.is-selected .ms-handle-box-w { cursor: ew-resize; }
/* 波紋アニメ */
@keyframes ms-ripple {
    0%   { transform: scale(1);   opacity: 0.7; }
    100% { transform: scale(2.6); opacity: 0;   }
}
.ms-marker-ripple {
    transform-origin: center;
    transform-box: fill-box;
    animation: ms-ripple 1.5s ease-out infinite;
}
.ms-marker-ripple-2 { animation-delay: 0.75s; }

/* ボックス（四角の枠）マーカー: 枠のパルスアニメーション（注目を引くための明滅） */
@keyframes ms-box-pulse {
    0%, 100% { stroke-opacity: 1; }
    50%      { stroke-opacity: 0.3; }
}
.ms-marker-box-animate {
    animation: ms-box-pulse 1.4s ease-in-out infinite;
}

/* マーカーツールバー: 高さ固定・横はみ出しはスクロール（fix: 縦圧迫対策） */
.ms-marker-toolbar {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    height: 56px;
    box-sizing: border-box;
    padding: 6px 12px;
    background: #fff7ed;
    border-bottom: 1px solid #fdba74;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    scrollbar-width: thin;
    scrollbar-color: #fdba74 transparent;
}
.ms-marker-toolbar::-webkit-scrollbar { height: 6px; }
.ms-marker-toolbar::-webkit-scrollbar-track { background: transparent; }
.ms-marker-toolbar::-webkit-scrollbar-thumb {
    background: rgba(180, 83, 9, 0.35);
    border-radius: 3px;
}
.ms-marker-toolbar .ms-mt-btn {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    padding: 5px 9px;
    cursor: pointer;
    font-size: 13px !important;
    color: #374151;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 28px;
    flex-shrink: 0;
}
.ms-marker-toolbar .ms-mt-btn:hover { background: #f3f4f6; }
.ms-marker-toolbar .ms-mt-btn.is-active {
    background: #f59e0b;
    color: #fff;
    border-color: #b45309;
}
.ms-marker-toolbar .ms-mt-text {
    font-weight: 700;
    font-size: 14px !important;
}
.ms-marker-toolbar .ms-mt-colors {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid #fdba74;
}
.ms-marker-toolbar .ms-mt-color {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #d1d5db;
    cursor: pointer;
    padding: 0;
}
.ms-marker-toolbar .ms-mt-color.is-active {
    box-shadow: 0 0 0 2px #1f2937;
}
.ms-marker-toolbar .ms-mt-color-custom {
    width: 26px;
    height: 24px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 0;
    background: #fff;
    cursor: pointer;
}
/* 線の太さプリセット */
.ms-marker-toolbar .ms-mt-widths {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid #fdba74;
}
.ms-marker-toolbar .ms-mt-width {
    width: 30px;
    height: 26px;
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 4px;
    padding: 0 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.ms-marker-toolbar .ms-mt-width:hover { background: #f3f4f6; }
.ms-marker-toolbar .ms-mt-width.is-active {
    background: #f59e0b;
    border-color: #b45309;
}
.ms-marker-toolbar .ms-mt-width.is-active .ms-mt-width-preview {
    background: #fff;
}
.ms-marker-toolbar .ms-mt-width-preview {
    display: block;
    width: 20px;
    background: #374151;
    border-radius: 999px;
}
/* 線種プリセット（実線/破線/点線） */
.ms-marker-toolbar .ms-mt-styles {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid #fdba74;
}
.ms-marker-toolbar .ms-mt-style {
    width: 30px;
    height: 26px;
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 4px;
    padding: 0 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.ms-marker-toolbar .ms-mt-style:hover { background: #f3f4f6; }
.ms-marker-toolbar .ms-mt-style.is-active {
    background: #f59e0b;
    border-color: #b45309;
}
.ms-marker-toolbar .ms-mt-style.is-active .ms-mt-style-preview {
    border-color: #fff;
}
.ms-marker-toolbar .ms-mt-style-preview {
    display: block;
    width: 20px;
    height: 0;
    border-top: 2px solid #374151;
}
.ms-marker-toolbar .ms-mt-style-preview-solid { border-top-style: solid; }
.ms-marker-toolbar .ms-mt-style-preview-dashed { border-top-style: dashed; }
.ms-marker-toolbar .ms-mt-style-preview-dotted { border-top-style: dotted; }
/* ▢ボックス（四角の枠）の枠アニメーション設定（box ツール選択中 or box マーカー選択中のみ表示） */
.ms-marker-toolbar .ms-mt-box-opts {
    display: none;
    flex-direction: row;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid #fdba74;
}
.ms-marker-toolbar.is-box-active .ms-mt-box-opts {
    display: inline-flex;
}
.ms-marker-toolbar .ms-mt-box-animate-row {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 5px;
    font-size: 11px !important;
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
}
/* 縦横比固定トグル（画像/ボックス共通、box or image ツール選択中 or box/image マーカー選択中のみ表示） */
.ms-marker-toolbar .ms-mt-aspect-opts {
    display: none;
    flex-direction: row;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid #fdba74;
}
.ms-marker-toolbar.is-aspect-active .ms-mt-aspect-opts {
    display: inline-flex;
}
.ms-marker-toolbar .ms-mt-aspect-lock-row {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 5px;
    font-size: 11px !important;
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
}
/* ●クリックマーカーの拡大縮小 + 透過率（click ツール選択中 or click マーカー選択中のみ表示） */
.ms-marker-toolbar .ms-mt-click-opts {
    display: none;
    flex-direction: row;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 10px;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid #fdba74;
}
.ms-marker-toolbar.is-click-active .ms-mt-click-opts {
    display: inline-flex;
}
.ms-marker-toolbar .ms-mt-slider-row {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 6px;
    line-height: 1;
}
.ms-marker-toolbar .ms-mt-slider-label {
    font-size: 11px !important;
    color: #6b7280;
    width: 32px;
    text-align: right;
}
.ms-marker-toolbar .ms-mt-slider {
    width: 110px;
    min-width: 110px;
    flex-shrink: 0;
    accent-color: #f59e0b;
    height: 4px;
    cursor: pointer;
}
.ms-marker-toolbar .ms-mt-slider-val {
    font-size: 11px !important;
    color: #374151;
    min-width: 32px;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}
/* 👆指マーカーの回転角度（finger ツール選択中 or finger マーカー選択中のみ表示） */
.ms-marker-toolbar .ms-mt-finger-opts {
    display: none;
    flex-direction: row;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 10px;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid #fdba74;
}
.ms-marker-toolbar.is-finger-active .ms-mt-finger-opts {
    display: inline-flex;
}
.ms-marker-toolbar .ms-mt-finger-presets {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 2px;
    max-width: none;
}
.ms-marker-toolbar .ms-mt-finger-preset {
    width: 30px;
    height: 20px;
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 4px;
    padding: 0;
    cursor: pointer;
    font-size: 10px !important;
    color: #374151;
    line-height: 1;
}
.ms-marker-toolbar .ms-mt-finger-preset:hover { background: #f3f4f6; }
.ms-marker-toolbar .ms-mt-finger-preset.is-active {
    background: #f59e0b;
    border-color: #b45309;
    color: #fff;
}
/* 🖼️画像マーカーの設定（image ツール選択中 or image マーカー選択中のみ表示） */
.ms-marker-toolbar .ms-mt-image-opts {
    display: none;
    flex-direction: row;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 10px;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid #fdba74;
}
.ms-marker-toolbar.is-image-active .ms-mt-image-opts {
    display: inline-flex;
}
.ms-marker-toolbar .ms-mt-image-add {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px !important;
    color: #374151;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 24px;
}
.ms-marker-toolbar .ms-mt-image-add:hover { background: #f3f4f6; }
.ms-marker-toolbar .ms-mt-image-add { flex-shrink: 0; }
.ms-marker-toolbar .ms-mt-image-border-row,
.ms-marker-toolbar .ms-mt-image-shadow-row {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 5px;
    font-size: 11px !important;
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
}
.ms-marker-toolbar .ms-mt-image-border-colors {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
}
.ms-marker-toolbar .ms-mt-image-border-color {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #d1d5db;
    cursor: pointer;
    padding: 0;
}
.ms-marker-toolbar .ms-mt-image-border-color.is-active {
    box-shadow: 0 0 0 2px #1f2937;
}
/* 画像マーカーの吹き出し用ライン（anchor）設定 */
.ms-marker-toolbar .ms-mt-image-anchor-row {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 5px;
    font-size: 11px !important;
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
}
.ms-marker-toolbar .ms-mt-image-anchor-colors {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
}
.ms-marker-toolbar .ms-mt-image-anchor-color {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #d1d5db;
    cursor: pointer;
    padding: 0;
}
.ms-marker-toolbar .ms-mt-image-anchor-color.is-active {
    box-shadow: 0 0 0 2px #1f2937;
}
.ms-marker-toolbar .ms-mt-image-anchor-styles {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
}
.ms-marker-toolbar .ms-mt-image-anchor-style {
    width: 26px;
    height: 22px;
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 4px;
    padding: 0 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.ms-marker-toolbar .ms-mt-image-anchor-style:hover { background: #f3f4f6; }
.ms-marker-toolbar .ms-mt-image-anchor-style.is-active {
    background: #f59e0b;
    border-color: #b45309;
}
.ms-marker-toolbar .ms-mt-image-anchor-style.is-active .ms-mt-style-preview {
    border-color: #fff;
}
/* クリップボード貼り付けボタン */
.ms-marker-toolbar .ms-mt-paste-wrap {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid #fdba74;
}
.ms-marker-toolbar .ms-mt-paste {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 13px !important;
    color: #0f766e;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    font-weight: 600;
}
.ms-marker-toolbar .ms-mt-paste:hover {
    background: #ecfeff;
    border-color: #0d9488;
    color: #0f766e;
}
.ms-marker-toolbar .ms-mt-paste i { font-size: 14px !important; }
.ms-marker-toolbar .ms-mt-paste .ms-mt-paste-label { white-space: nowrap; }
@media (max-width: 640px) {
    .ms-marker-toolbar .ms-mt-paste .ms-mt-paste-label { display: none; }
}
.ms-stage .ms-image-hint {
    position: absolute;
    bottom: 24px;
    right: 24px;
    background: rgba(245, 158, 11, 0.95);
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px !important;
    display: none;
}
.ms-stage.is-edit .ms-image-hint { display: block; }

/* ドラッグ&ドロップ: 編集モード時のみ表示。overlay 自体は常時DOMにあるが is-drag-over で可視化 */
.ms-stage .ms-drop-overlay {
    position: absolute;
    inset: 12px;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(245, 158, 11, 0.18);
    color: #fff;
    font-size: 20px !important;
    font-weight: 700;
    border: 3px dashed #f59e0b;
    border-radius: 8px;
    pointer-events: none;
    z-index: 20;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.ms-stage .ms-drop-overlay i { font-size: 40px !important; opacity: 0.95; }
.ms-stage.is-edit.is-drag-over .ms-drop-overlay { display: flex; }

.ms-caption {
    flex: 0 0 auto;
    padding: 16px 24px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    max-height: 35vh;
    overflow-y: auto;
}
.ms-caption .ms-slide-title {
    font-size: 18px !important;
    font-weight: 700;
    color: #111827;
    margin: 0 0 8px 0;
    line-height: 1.4;
}
.ms-caption .ms-slide-desc {
    font-size: 14px !important;
    color: #374151;
    line-height: 1.7;
    white-space: pre-wrap;
    margin: 0;
}
.ms-caption.is-edit .ms-slide-title,
.ms-caption.is-edit .ms-slide-desc {
    outline: 1px dashed #f59e0b;
    outline-offset: 2px;
    padding: 4px 6px;
    border-radius: 3px;
    background: #fffbeb;
}
.ms-caption.is-edit .ms-slide-title:focus,
.ms-caption.is-edit .ms-slide-desc:focus {
    outline: 2px solid #f59e0b;
    background: #fff;
}
/* 音声読み上げ専用入力欄。編集モードのみ表示（表示モードでは非表示） */
.ms-slide-voice-wrap {
    display: none;
}
.ms-caption.is-edit .ms-slide-voice-wrap {
    display: block;
    margin-top: 6px;
}
.ms-slide-voice-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.ms-slide-voice-label {
    font-size: 11px;
    color: #6b7280;
}
.ms-slide-voice-copy {
    font-size: 11px;
    color: #6b7280;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    padding: 2px 6px;
    cursor: pointer;
}
.ms-slide-voice-copy:hover {
    background: #f3f4f6;
    color: #374151;
}
.ms-slide-voice {
    font-size: 13px !important;
    color: #4b5563;
    line-height: 1.6;
    white-space: pre-wrap;
    margin: 2px 0 0 0;
    border: 1px dashed #d1d5db;
    background: #f9fafb;
    padding: 4px 6px;
    border-radius: 3px;
    min-height: 1.6em;
}
.ms-caption.is-edit .ms-slide-voice:focus {
    outline: 2px solid #f59e0b;
    background: #fff;
}
/* テロップ有効時（表示モード）は画像上と内容が重複するため下部キャプション枠ごと非表示 */
.ms-caption.ms-caption--telop-hides-body {
    display: none;
}

/* ── テロップ (画像上のタイトル・説明文オーバーレイ) ── */
.ms-stage-inner .ms-telop {
    position: absolute;
    font-family: 'Hiragino Sans', 'Meiryo', 'Segoe UI', sans-serif;
    font-weight: 900;
    line-height: 1.25;
    padding: 6px 14px;
    background: rgba(0, 0, 0, 0);
    z-index: 5;
    pointer-events: none;
    max-width: 92%;
    word-break: break-word;
    white-space: pre-wrap;
    letter-spacing: 0.01em;
}
.ms-stage-inner .ms-telop-title { font-weight: 900; }
.ms-stage-inner .ms-telop-desc { font-weight: 700; }
/* 9 分割位置 */
.ms-stage-inner .ms-telop-pos-top-left       { top: 4%; left: 4%; text-align: left; }
.ms-stage-inner .ms-telop-pos-top-center     { top: 4%; left: 50%; transform: translateX(-50%); text-align: center; }
.ms-stage-inner .ms-telop-pos-top-right      { top: 4%; right: 4%; text-align: right; }
.ms-stage-inner .ms-telop-pos-middle-left    { top: 50%; left: 4%; transform: translateY(-50%); text-align: left; }
.ms-stage-inner .ms-telop-pos-middle-center  { top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
.ms-stage-inner .ms-telop-pos-middle-right   { top: 50%; right: 4%; transform: translateY(-50%); text-align: right; }
.ms-stage-inner .ms-telop-pos-bottom-left    { bottom: 4%; left: 4%; text-align: left; }
.ms-stage-inner .ms-telop-pos-bottom-center  { bottom: 4%; left: 50%; transform: translateX(-50%); text-align: center; }
.ms-stage-inner .ms-telop-pos-bottom-right   { bottom: 4%; right: 4%; text-align: right; }

/* テロップ設定パネル */
.ms-telop-panel {
    margin-top: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fafafa;
}
.ms-telop-panel-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    background: #f3f4f6;
    border-radius: 8px 8px 0 0;
}
.ms-telop-panel:not(.is-open) .ms-telop-panel-head { border-bottom: none; border-radius: 8px; }
.ms-telop-panel-toggle {
    background: transparent;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-weight: 700;
    color: #111827;
    font-size: 13px !important;
    padding: 2px 4px;
}
.ms-telop-panel-toggle i { font-size: 13px !important; }
.ms-telop-enable {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px !important;
    color: #0f766e;
    font-weight: 700;
}
.ms-telop-panel-body {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ms-telop-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 18px;
    padding-bottom: 10px;
    border-bottom: 1px dashed #e5e7eb;
}
.ms-telop-row:last-of-type { border-bottom: none; padding-bottom: 0; }
.ms-telop-row-label {
    flex: 0 0 auto;
    width: 60px;
    font-weight: 700;
    color: #111827;
    padding-top: 22px;
    font-size: 13px !important;
}
.ms-telop-row-group { display: flex; flex-direction: column; gap: 4px; }
.ms-telop-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 6px;
    flex-wrap: wrap;
}
.ms-telop-apply-all {
    background: #0f766e;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 7px 14px;
    font-size: 13px !important;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.ms-telop-apply-all:hover { background: #0e6660; }
.ms-telop-apply-all i { font-size: 13px !important; }
.ms-telop-section { display: flex; flex-direction: column; gap: 6px; }
.ms-telop-label {
    font-size: 12px !important;
    color: #6b7280;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.ms-telop-pos-grid {
    display: grid;
    grid-template-columns: repeat(3, 22px);
    grid-template-rows: repeat(3, 22px);
    gap: 3px;
}
.ms-telop-pos-btn {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    cursor: pointer;
    padding: 0;
    position: relative;
}
.ms-telop-pos-btn:hover { background: #f3f4f6; }
.ms-telop-pos-btn.is-active {
    background: #f59e0b;
    border-color: #b45309;
}
.ms-telop-pos-btn.is-active::after {
    content: '';
    position: absolute;
    inset: 6px;
    background: #fff;
    border-radius: 999px;
}
.ms-telop-size, .ms-telop-colors {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.ms-telop-size-btn {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 13px !important;
    color: #374151;
}
.ms-telop-size-btn:hover { background: #f3f4f6; }
.ms-telop-size-btn.is-active {
    background: #f59e0b;
    color: #fff;
    border-color: #b45309;
}
.ms-telop-color {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #d1d5db;
    cursor: pointer;
    padding: 0;
}
.ms-telop-color.is-active { box-shadow: 0 0 0 2px #1f2937; }
.ms-telop-color-custom {
    width: 26px;
    height: 24px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 0;
    background: #fff;
    cursor: pointer;
}
.ms-telop-outline-row {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding-top: 18px;
}
.ms-telop-outline,
.ms-telop-shadow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px !important;
    color: #374151;
    font-weight: 600;
}
.ms-telop-ow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.ms-telop-ow-slider {
    width: 90px;
}
.ms-telop-ow-value {
    font-size: 12px !important;
    color: #374151;
    font-weight: 700;
    min-width: 56px;
    text-align: right;
}
.ms-telop-lh {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.ms-telop-lh-slider {
    width: 90px;
}
.ms-telop-lh-value {
    font-size: 12px !important;
    color: #374151;
    font-weight: 700;
    min-width: 24px;
    text-align: right;
}

/* ── スライドショーモード ──
   is-slideshow クラス付与時は 章内スライドのみ表示にし、余計な UI を隠す */
#manualSlidesOverlay.is-slideshow .ms-sidebar,
#manualSlidesOverlay.is-slideshow .ms-caption,
#manualSlidesOverlay.is-slideshow .ms-thumb-bar,
#manualSlidesOverlay.is-slideshow .ms-footer,
#manualSlidesOverlay.is-slideshow .ms-menu-toggle,
#manualSlidesOverlay.is-slideshow .ms-toc-btn,
#manualSlidesOverlay.is-slideshow .ms-search-wrap { display: none !important; }
#manualSlidesOverlay.is-slideshow .ms-body { flex-direction: column; }
#manualSlidesOverlay.is-slideshow .ms-stage { background: #000; padding: 0; }
#manualSlidesOverlay.is-slideshow .ms-stage-inner img { box-shadow: none; border-radius: 0; }

/* コントロールバー (右下フローティング・コンパクト) */
.ms-ss-bar {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 9500;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(17, 24, 39, 0.82);
    color: #fff;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
    pointer-events: auto;
    opacity: 0.85;
    transition: opacity 0.15s ease;
}
.ms-ss-bar:hover { opacity: 1; }
.ms-ss-bar .ms-ss-btn {
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 999px;
    width: 26px;
    height: 26px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px !important;
    padding: 0;
}
.ms-ss-bar .ms-ss-btn:hover { background: rgba(255,255,255,0.1); }
.ms-ss-bar .ms-ss-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.ms-ss-bar .ms-ss-btn.ms-ss-play {
    background: #f59e0b;
    border-color: #b45309;
    width: 30px;
    height: 30px;
    font-size: 12px !important;
}
.ms-ss-bar .ms-ss-btn.ms-ss-play:hover { background: #fbbf24; }
.ms-ss-bar .ms-ss-pos {
    font-size: 11px !important;
    color: #e5e7eb;
    padding: 0 4px;
    white-space: nowrap;
    max-width: 22vw;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ms-ss-bar .ms-ss-interval {
    background: #1f2937;
    color: #fff;
    border: 1px solid #4b5563;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 11px !important;
    cursor: pointer;
    height: 22px;
}
.ms-ss-bar .ms-ss-voice-btn.is-active { background: #16a34a; border-color: #15803d; }
.ms-ss-bar .ms-ss-voice-btn.is-disabled,
.ms-ss-bar .ms-ss-rate-select:disabled { opacity: 0.35; cursor: not-allowed; }
.ms-ss-bar .ms-ss-rate-select {
    background: #1f2937;
    color: #fff;
    border: 1px solid #4b5563;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 11px !important;
    cursor: pointer;
    height: 22px;
}
/* ── フッター（ナビ） ── */
.ms-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: #111827;
    color: #f9fafb;
}
.ms-footer .ms-nav-btn {
    background: #374151;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 14px !important;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s ease;
}
.ms-footer .ms-nav-btn:hover:not(:disabled) { background: #4b5563; }
.ms-footer .ms-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.ms-footer .ms-page-info {
    flex: 1 1 auto;
    text-align: center;
    font-size: 13px !important;
    color: #d1d5db;
}
.ms-footer .ms-action-group {
    display: flex;
    gap: 8px;
}
.ms-footer .ms-action-btn {
    background: transparent;
    color: #d1d5db;
    border: 1px solid #4b5563;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px !important;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.ms-footer .ms-action-btn:hover { background: #374151; color: #fff; }
.ms-footer .ms-action-btn.is-primary {
    background: #f59e0b;
    color: #fff;
    border-color: #f59e0b;
}
.ms-footer .ms-action-btn.is-primary:hover { background: #d97706; }
.ms-footer .ms-action-btn.is-primary:disabled {
    background: #6b7280;
    border-color: #6b7280;
    cursor: not-allowed;
}

/* ── サムネイル一覧（編集モード時） ── */
.ms-thumb-bar {
    flex: 0 0 auto;
    display: none;
    gap: 8px;
    padding: 8px 16px;
    background: #f3f4f6;
    border-top: 1px solid #e5e7eb;
    overflow-x: auto;
}
.ms-main.is-edit .ms-thumb-bar { display: flex; }
.ms-thumb {
    flex: 0 0 auto;
    width: 96px;
    height: 56px;
    border: 2px solid transparent;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    overflow: hidden;
    position: relative;
}
.ms-thumb.is-current { border-color: #f59e0b; }
.ms-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.ms-thumb .ms-thumb-num {
    position: absolute;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 10px !important;
    padding: 1px 4px;
    border-bottom-right-radius: 4px;
}
.ms-thumb-add {
    flex: 0 0 auto;
    width: 96px;
    height: 56px;
    border: 2px dashed #9ca3af;
    border-radius: 4px;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    font-size: 18px !important;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ms-thumb-add:hover { border-color: #f59e0b; color: #f59e0b; }

/* ── 隠しファイル input ── */
.ms-hidden-file {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* ── スマホ対応 ── */
@media (max-width: 768px) {
    .ms-sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 2;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        flex: 0 0 80%;
        max-width: 320px;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.2);
    }
    .ms-body.is-sidebar-open .ms-sidebar { transform: translateX(0); }
    .ms-body { position: relative; }
    .ms-header .ms-title { font-size: 14px !important; }
    .ms-caption .ms-slide-title { font-size: 16px !important; }
    .ms-caption .ms-slide-desc { font-size: 13px !important; }
    .ms-footer .ms-nav-btn { padding: 6px 10px; font-size: 12px !important; }
    .ms-footer .ms-action-btn { padding: 6px 8px; font-size: 12px !important; }
    .ms-menu-toggle { display: inline-flex !important; }
}
/* 章リスト開閉ボタン。PC でも表示する (表示モードはサイドバー既定 collapsed のため、
   これが無いと章リストを戻す手段が無くなる)。スライドショー/印刷/目次専用モードでは
   別ルールが display:none !important で伏せる。 */
.ms-menu-toggle {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: #fff;
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 14px !important;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    transition: background 0.15s ease;
}
.ms-menu-toggle:hover { background: rgba(255, 255, 255, 0.35); }
.ms-menu-toggle.is-active {
    background: #fff;
    color: #d97706;
    border-color: #fff;
}

/* ── 印刷モード ──
   1スライド=1ページ（A4 横）。UIは全て非表示。 */
@media print {
    @page { size: A4 landscape; margin: 12mm; }
    body * { visibility: hidden !important; }
    #manualSlidesOverlay,
    #manualSlidesOverlay * { visibility: visible !important; }
    #manualSlidesOverlay {
        position: static !important;
        background: #fff !important;
        display: block !important;
        color: #000 !important;
    }
    .ms-header, .ms-footer, .ms-sidebar, .ms-thumb-bar,
    .ms-marker-toolbar,
    .ms-stage, .ms-stage .ms-image-hint, .ms-menu-toggle,
    .ms-toc-modal-overlay { display: none !important; }
    /* 波紋アニメ・ボックス枠パルスは印刷時は静止 */
    .ms-marker-ripple { animation: none !important; opacity: 1 !important; }
    .ms-marker-box-animate { animation: none !important; stroke-opacity: 1 !important; }
    .ms-body, .ms-main { display: block !important; }
    .ms-print-root { display: block !important; }
    .ms-print-page {
        page-break-after: always;
        padding: 4mm;
        text-align: center;
    }
    .ms-print-chapter, .ms-print-title, .ms-print-desc { text-align: left; }
    .ms-print-page:last-child { page-break-after: auto; }
    .ms-print-chapter {
        font-size: 12pt !important;
        color: #b45309 !important;
        margin: 0 0 4mm 0;
        font-weight: 700;
    }
    .ms-print-title {
        font-size: 18pt !important;
        color: #111827 !important;
        margin: 0 0 6mm 0;
        font-weight: 700;
    }
    .ms-print-img-wrap {
        position: relative;
        display: inline-block;
        margin: 0 auto 6mm auto;
        max-width: 100%;
        line-height: 0;
    }
    .ms-print-img {
        display: block;
        max-width: 100%;
        max-height: 130mm;
        margin: 0 auto;
        object-fit: contain;
    }
    .ms-print-marker-svg {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        pointer-events: none;
        overflow: visible;
    }
    /* 印刷用テロップ (画像の上に絶対配置)。container query が効かない環境向けに vmin 単位でスケール */
    .ms-print-img-wrap { container-type: inline-size; }
    .ms-print-telop {
        position: absolute;
        font-family: 'Hiragino Sans','Meiryo','Segoe UI',sans-serif;
        font-weight: 900;
        padding: 1mm 2mm;
        max-width: 92%;
        line-height: 1.25;
        white-space: pre-wrap;
        word-break: break-word;
    }
    .ms-print-telop-title { font-weight: 900; }
    .ms-print-telop-desc  { font-weight: 700; }
    .ms-print-telop-pos-top-left      { top: 3%; left: 3%; text-align: left; }
    .ms-print-telop-pos-top-center    { top: 3%; left: 50%; transform: translateX(-50%); text-align: center; }
    .ms-print-telop-pos-top-right     { top: 3%; right: 3%; text-align: right; }
    .ms-print-telop-pos-middle-left   { top: 50%; left: 3%; transform: translateY(-50%); text-align: left; }
    .ms-print-telop-pos-middle-center { top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
    .ms-print-telop-pos-middle-right  { top: 50%; right: 3%; transform: translateY(-50%); text-align: right; }
    .ms-print-telop-pos-bottom-left   { bottom: 3%; left: 3%; text-align: left; }
    .ms-print-telop-pos-bottom-center { bottom: 3%; left: 50%; transform: translateX(-50%); text-align: center; }
    .ms-print-telop-pos-bottom-right  { bottom: 3%; right: 3%; text-align: right; }
    .ms-print-desc {
        font-size: 11pt !important;
        color: #1f2937 !important;
        line-height: 1.6;
        white-space: pre-wrap;
    }
    /* 通常UIは隠す */
    .ms-print-hidden-on-print { display: none !important; }
}

/* 画面表示時は印刷用要素を隠す */
.ms-print-root { display: none; }

/* 目次モーダルを開くボタン（ヘッダー）。モーダル表示中は .ms-btn.is-active が効く */
.ms-header .ms-toc-btn {
    padding: 6px 10px;
}

/* 「使い方」経由で TOC モーダルだけ表示する時のモード。裏の章内容/ヘッダー/フッター/サイドバーを隠す。
   TOC から章/スライドが選ばれる (goTo 実行) と JS 側で is-toc-only が外れ、通常の閲覧画面へ切り替わる。 */
#manualSlidesOverlay.is-toc-only .ms-header,
#manualSlidesOverlay.is-toc-only .ms-body,
#manualSlidesOverlay.is-toc-only .ms-footer,
#manualSlidesOverlay.is-toc-only .ms-menu-toggle { display: none !important; }
#manualSlidesOverlay.is-toc-only { background: rgba(17, 24, 39, 0.55); }

/* =========================================================
   目次モーダル (全画面。カテゴリ→章→スライドをテキストで一覧)
   ========================================================= */
.ms-toc-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9600;
    background: rgba(17, 24, 39, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: ms-toc-fade-in 0.15s ease-out;
}
@keyframes ms-toc-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.ms-toc-modal-content {
    background: #ffffff;
    color: #1f2937;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    width: min(920px, 100%);
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ms-toc-modal-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: linear-gradient(135deg, #f59e0b 0%, #b45309 100%);
    color: #fff;
    border-bottom: 1px solid #e5e7eb;
}
.ms-toc-modal-title {
    flex: 1 1 auto;
    font-size: 18px !important;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.ms-toc-modal-close {
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 20px !important;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
.ms-toc-modal-close:hover { background: rgba(255, 255, 255, 0.3); }
/* 検索バー (モーダルヘッダー直下・sticky で最上部に固定) */
.ms-toc-modal-searchbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
}
.ms-toc-modal-search-icon {
    color: #9ca3af;
    font-size: 13px !important;
    flex: 0 0 auto;
}
.ms-toc-modal-search-input {
    flex: 1 1 auto;
    min-width: 0;
    background: #ffffff;
    border: 1px solid #d1d5db;
    outline: none;
    color: #1f2937;
    font-size: 14px !important;
    padding: 6px 10px;
    border-radius: 5px;
}
.ms-toc-modal-search-input:focus { border-color: #f59e0b; box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2); }
.ms-toc-modal-search-input::placeholder { color: #9ca3af; }
.ms-toc-modal-search-input::-webkit-search-cancel-button { display: none; }
.ms-toc-modal-search-clear {
    flex: 0 0 auto;
    background: transparent;
    border: none;
    color: #9ca3af;
    font-size: 13px !important;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
}
.ms-toc-modal-search-clear:hover { color: #b45309; background: #fff7ed; }
/* よく検索される語のチップ列 (検索バー直下)。行数が増えても目次本文を潰さないよう高さを抑える */
.ms-toc-modal-tagbar {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 20px 10px;
    background: #fffbeb;
    border-bottom: 1px solid #e5e7eb;
    /* 92px だと3行目が見切れてスクロールしないと読めないため、3行(実測110px)が
       収まる高さにする。4行以上になった場合の保険として overflow-y は残す。 */
    max-height: 120px;
    overflow-y: auto;
}
.ms-toc-tag {
    flex: 0 0 auto;
    background: #ffffff;
    border: 1px solid #fcd34d;
    color: #92400e;
    font-size: 12px !important;
    line-height: 1.4;
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.ms-toc-tag:hover { background: #fef3c7; border-color: #f59e0b; }
.ms-toc-tag:focus-visible { outline: 2px solid #f59e0b; outline-offset: 1px; }
.ms-toc-tag.is-active {
    background: #f59e0b;
    border-color: #b45309;
    color: #ffffff;
    font-weight: 700;
}
.ms-toc-modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 20px 24px 28px;
    background: #fafaf9;
}
/* サイドバー章の一時ハイライト (目次から遷移直後の "追随してフォーカス" 用) */
.ms-sidebar .ms-chapter.ms-chapter-flash > .ms-chapter-head {
    background: #fef3c7 !important;
    animation: ms-chapter-flash-anim 1.2s ease-out;
}
@keyframes ms-chapter-flash-anim {
    0%   { background: #fde68a; box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.5); }
    100% { background: transparent; box-shadow: none; }
}
/* カテゴリ セクション */
.ms-toc-cat {
    margin-bottom: 22px;
    padding: 14px 16px 12px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.ms-toc-cat:last-child { margin-bottom: 0; }
.ms-toc-cat-label {
    margin: 0 0 10px;
    padding: 0 0 8px;
    border-bottom: 2px solid #f59e0b;
    color: #b45309;
    font-size: 15px !important;
    font-weight: 700;
    letter-spacing: 0.02em;
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.ms-toc-cat-count {
    color: #9ca3af;
    font-size: 12px !important;
    font-weight: 500;
}
/* 章ブロック */
.ms-toc-chapter {
    padding: 8px 0 8px 4px;
    border-top: 1px dashed #f3f4f6;
}
.ms-toc-chapter:first-of-type { border-top: none; }
.ms-toc-chapter-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    color: #1f2937;
    font-size: 14px !important;
    font-weight: 600;
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.12s ease, color 0.12s ease;
}
.ms-toc-chapter-title:hover {
    background: #fff7ed;
    color: #b45309;
    text-decoration: underline;
}
.ms-toc-chapter-title.is-current {
    background: #fef3c7;
    color: #92400e;
}

/* 章アイコン（目次・サイドバー共通）
   本体ヘッダーのボタンと同じ「角丸バッジ + 中央アイコン」だが、
   カテゴリ見出し（暖色・下線）と競合しないよう寒色にし、サイズも一回り小さくする。 */
.ms-ch-icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: #eff6ff;
    border: 1px solid #dbeafe;
    color: #2563eb;
    line-height: 1;
}
.ms-ch-icon i { font-size: 11px !important; }
.ms-ch-icon--side {
    width: 20px;
    height: 20px;
    border-radius: 5px;
}
.ms-ch-icon--side i { font-size: 10px !important; }
.ms-chapter.is-current > .ms-chapter-head .ms-ch-icon {
    background: #dbeafe;
    border-color: #bfdbfe;
}
.ms-toc-chapter-title:hover .ms-ch-icon { background: #dbeafe; }
.ms-toc-chapter-title.is-current .ms-ch-icon {
    background: #ffffff;
    border-color: #fcd34d;
    color: #b45309;
}

/* アイコンピッカー（章ドラッグハンドル右クリック → アイコンを変更） */
.ms-icon-picker { min-width: 252px; }
.ms-icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(8, 26px);
    gap: 4px;
    padding: 8px;
}
.ms-icon-picker-item {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #374151;
    cursor: pointer;
}
.ms-icon-picker-item i { font-size: 12px !important; }
.ms-icon-picker-item:hover {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}
.ms-icon-picker-item.is-current {
    background: #2563eb;
    border-color: #1d4ed8;
    color: #ffffff;
}
/* スライド リスト */
.ms-toc-slides {
    list-style: none;
    margin: 4px 0 4px 20px;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 2px 12px;
}
.ms-toc-slide-li {
    counter-increment: none;
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 0;
}
.ms-toc-slide-li::before {
    content: counter(list-item) ".";
    color: #9ca3af;
    font-size: 12px !important;
    font-variant-numeric: tabular-nums;
    min-width: 22px;
    text-align: right;
    flex: 0 0 auto;
}
.ms-toc-slides { counter-reset: list-item; }
.ms-toc-slide-li { counter-increment: list-item; }
.ms-toc-slide {
    flex: 1 1 auto;
    display: block;
    padding: 3px 6px;
    color: #374151;
    font-size: 13px !important;
    text-decoration: none;
    border-radius: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background 0.12s ease, color 0.12s ease;
}
.ms-toc-slide:hover {
    background: #fff7ed;
    color: #b45309;
}
.ms-toc-slide.is-current {
    background: #fef3c7;
    color: #92400e;
    font-weight: 600;
}
/* 同一タイトルが N 枚あるグループの枚数表示 (グレー小文字) */
.ms-toc-slide-count {
    color: #9ca3af;
    font-size: 11px !important;
    font-weight: 400;
    margin-left: 4px;
}
.ms-toc-slide.is-current .ms-toc-slide-count {
    color: #b45309;
}
.ms-toc-empty {
    text-align: center;
    color: #9ca3af;
    padding: 40px 0;
    font-size: 14px !important;
}
/* スマホ: モーダル幅と余白を詰める */
@media (max-width: 768px) {
    .ms-toc-modal-overlay { padding: 12px; }
    .ms-toc-modal-body { padding: 14px; }
    /* スマホは縦を稼ぐため折り返さず横スクロール（1行固定） */
    .ms-toc-modal-tagbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        max-height: none;
        padding: 8px 14px;
        -webkit-overflow-scrolling: touch;
    }
    .ms-toc-cat { padding: 12px 12px 10px; }
    .ms-toc-slides {
        grid-template-columns: 1fr;
        margin-left: 12px;
    }
    .ms-toc-modal-title { font-size: 16px !important; }
}

/* スマホ: ヘッダーの各ボタンを縮小（検索欄はサイドバー最上部へ移設済み） */
@media (max-width: 768px) {
    .ms-header .ms-toc-btn span,
    .ms-header .ms-toc-btn { font-size: 12px !important; }
    .ms-sidebar .ms-search-input { font-size: 12px !important; }
    .ms-search-results { left: 8px; right: 8px; }
}

/* =========================================================
   text / freehand マーカー
   ========================================================= */
/* text マーカー設置中: クロスヘア */
.ms-stage-inner[data-tool="text"] img,
.ms-stage-inner[data-tool="freehand"] img { cursor: crosshair; }
/* freehand 描画中はテキスト選択を抑止 */
.ms-stage-inner[data-tool="freehand"] { user-select: none; }
/* text マーカー本体は中央寄せ＋細い縁取りで視認性確保（描画は SVG 側で完結） */
.ms-marker-text text { user-select: none; }
