/* ===== ローカル漫画フォント @font-face ===== */
@font-face { font-family: 'YasashisaAntique'; src: url('fonts/YasashisaAntique.otf') format('opentype'); font-display: swap; }
@font-face { font-family: 'GenEiAntiqueN'; src: url('fonts/GenEiAntiqueN.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'GenEiKiwamiGo'; src: url('fonts/GenEiKiwamiGo.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'GenEiMGothic2Bold'; src: url('fonts/GenEiMGothic2-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'GenEiNuGothicEB'; src: url('fonts/GenEiNuGothic-EB.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: '851ChikaraDzuyoku'; src: url('fonts/851CHIKARA-DZUYOKU.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'AnkokuZonji'; src: url('fonts/AnkokuZonji.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'ShinComic'; src: url('fonts/ShinComic.otf') format('opentype'); font-display: swap; }
@font-face { font-family: 'FZImokenpi'; src: url('fonts/FZ-Imokenpi.otf') format('opentype'); font-display: swap; }
@font-face { font-family: 'UtaMin'; src: url('fonts/UtaMin.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Keifont'; src: url('fonts/keifont.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'TamanegKaisho'; src: url('fonts/TamanegKaisho.ttf') format('truetype'); font-display: swap; }

/* ===== Scriptoon V2 - CSS ===== */

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

:root {
    --primary: #4A7CFA;
    --primary-hover: #3A6AE8;
    --primary-light: rgba(74, 124, 250, 0.1);
    --accent: #6C5CE7;
    --accent-hover: #5A4BD5;
    --secondary: #636e72;
    --secondary-hover: #535c60;
    --success: #00b894;
    --danger: #e74c3c;
    --bg: #F0F2F5;
    --card: #FFFFFF;
    --text: #2D3436;
    --text-secondary: #636e72;
    --text-light: #b2bec3;
    --border: #DFE6E9;
    --input-bg: #F5F6FA;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --transition: 0.2s ease;
}

body {
    font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== ヘッダー ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px; /* 高さを60pxに固定 */
    padding: 0 20px; /* 上下パディングを0にして中央揃えにする */
    box-sizing: border-box;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-left h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
}

.mode-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    background: var(--primary);
    color: white;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.api-warning {
    display: none;
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 4px 10px;
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
}

.api-warning.show {
    display: block;
}

.header-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all var(--transition);
}

.header-btn:hover {
    background: var(--border);
    transform: translateY(-1px);
}

/* ===== ステータスバー ===== */
.status-bar {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 20px;
    background: #eef4ff;
    border-bottom: 1px solid var(--primary);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--primary);
    position: sticky;
    top: 57px;
    z-index: 99;
}

.status-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.status-row.is-error {
    color: #c0392b;
}

.status-row .status-message {
    text-align: center;
}

.status-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--primary-light);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== メイン3パネル ===== */
.app-container {
    min-height: 100vh;
}

.panels-container {
    display: grid;
    grid-template-columns: 1fr 1.4fr 1.2fr;
    gap: 0;
    min-height: calc(100vh - 60px);
}

.panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--card);
    height: calc(100vh - 60px);
    overflow: hidden;
}

.panel:last-child {
    border-right: none;
}

.panel-header {
    padding: 12px 16px;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.panel-body {
    flex: 1;
    padding: 14px 14px 40px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    min-height: 0;
}

.right-sticky-top {
    position: sticky;
    top: -14px;
    z-index: 20;
    background: var(--card, #fff);
    padding: 14px 14px 8px 14px;
    margin: -14px -14px 0 -14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.panel-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: var(--card);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 1;
    min-height: 0;
    overflow-y: auto;
}

/* ===== 共通要素 ===== */
.section-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
    margin-top: 4px;
}

.divider {
    height: 1px;
    background: linear-gradient(to right, transparent, var(--border), transparent);
    margin: 6px 0;
}

/* テキストエリア */
textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 0.88rem;
    font-family: inherit;
    resize: vertical;
    transition: all var(--transition);
    line-height: 1.6;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px var(--primary-light);
}

.textarea-large {
    min-height: 160px;
}

#ekonteContent {
    min-height: 320px;
    font-size: 1rem;
    line-height: 1.8;
}



.textarea-medium {
    min-height: 120px;
}

.textarea-small {
    min-height: 70px;
}

/* input */
input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 0.9rem;
    transition: all var(--transition);
}

input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* セレクト */
select {
    padding: 6px 10px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* 設定モーダル内セレクト */
.setting-select {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.9rem;
    border-radius: var(--radius-md);
    margin-top: 6px;
}

/* ===== ボタン ===== */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(74, 124, 250, 0.3);
}

.btn-accent {
    background: var(--accent);
    color: white;
}

.btn-accent:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3);
}

.btn-secondary {
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-warning {
    background: #F1C40F;
    color: #fff;
}

.btn-warning:hover:not(:disabled) {
    background: #D4AC0D;
}

.btn-success:hover:not(:disabled) {
    background: #00a381;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #c0392b;
}

.btn-full {
    width: 100%;
}

.btn-row {
    display: flex;
    gap: 8px;
}

.btn-row .btn {
    flex: 1;
}

.input-action-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-small-icon {
    width: 42px;
    /* 少し大きめに調整 */
    height: 38px;
    /* 他のボタンと高さを合わせる */
    padding: 0;
    flex-shrink: 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== 一括生成する ===== */
.bulk-gen-enable {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.bulk-range-custom {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    white-space: nowrap;
}

/* 一括生成ON時に画像数欄をグレーアウト */
.setting-item.disabled-setting {
    opacity: 0.45;
}

.setting-item.disabled-setting label,
.setting-item.disabled-setting select {
    cursor: not-allowed;
}

/* ===== 一括生成範囲 ===== */
.bulk-range-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 0.9rem;
}

.bulk-range-all {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.bulk-range-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
}

.bulk-range-num {
    width: 56px;
    padding: 4px 6px;
    text-align: center;
}

.bulk-range-num:disabled {
    background: #f0f0f0;
    color: #aaa;
    cursor: not-allowed;
}

.bulk-range-sep,
.bulk-range-unit {
    color: var(--text-light);
}

/* ===== 設定グループ（ラベル＋ゴミ箱＋一覧を枠で囲う） ===== */
.settings-group {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 12px;
    background: #fafafa;
}

.settings-group .section-label {
    margin-bottom: 8px;
}

/* グループ枠内のゴミ箱ボタンを、枠外（提案する横）のゴミ箱と同じ右端に揃える */
.settings-group .section-label .btn-small-icon {
    margin-right: -11px;
}

/* ===== キャラクター設定コンテナ ===== */
.char-settings-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.no-char-message {
    text-align: center;
    padding: 20px 12px;
    color: var(--text-light);
    font-size: 0.85rem;
}

.char-setting-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--card);
    flex-shrink: 0;
}

.char-setting-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--primary);
    color: white;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}

.char-setting-header:hover {
    background: var(--primary-hover);
}

.char-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.char-header-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.char-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: white;
    flex-shrink: 0;
}

.char-setting-header .toggle-icon {
    font-size: 0.7rem;
    transition: transform var(--transition);
}

.char-setting-header .toggle-icon.collapsed {
    transform: rotate(-90deg);
}

.char-setting-body {
    padding: 10px;
}

.char-setting-body.collapsed {
    display: none;
}

.char-setting-body textarea {
    width: 100%;
    min-height: 300px;
    max-height: 60vh;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    font-size: 0.8rem;
    line-height: 1.5;
    resize: vertical;
    overflow-y: scroll !important;
    box-sizing: border-box;
    font-family: inherit;
}


/* ===== クリックで拡大モーダルを開く textarea ===== */
.textarea-clickexpand {
    cursor: pointer;
}

.textarea-clickexpand:hover {
    border-color: var(--primary);
    background: var(--primary-light, rgba(99,102,241,0.04));
}

.textarea-clickexpand:focus {
    outline: none;
}

/* ===== 画像ドロップゾーン ===== */
.char-image-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    min-height: 140px;
    max-height: 260px;
    overflow-y: auto;
    position: relative;
    cursor: pointer;
    transition: all var(--transition);
}

.char-image-zone:hover,
.char-image-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    color: var(--text-light);
}

.drop-placeholder.hidden {
    display: none;
}

.drop-icon {
    font-size: 2.4rem;
    margin-bottom: 6px;
    opacity: 0.5;
}

.drop-placeholder p {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 2px;
}

.drop-placeholder small {
    font-size: 0.72rem;
    opacity: 0.7;
}

.char-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 6px;
    padding: 8px;
    align-items: start;
}

.scene-ref-label {
    margin-top: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light, #666);
}

.scene-ref-images {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px;
    border: 1px dashed transparent;
    border-radius: var(--radius-sm);
    transition: background 0.15s, border-color 0.15s;
}

.scene-ref-images.dragover {
    background: rgba(74, 144, 226, 0.08);
    border-color: var(--primary, #4a90e2);
}

.scene-ref-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 64px;
}

.scene-ref-item img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.scene-ref-item-green img {
    border: 2px solid #22c55e;
}

.scene-ref-item-prevpage img {
    border: 2px solid #3b82f6;
}

.scene-ref-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: var(--danger, #d33);
    color: #fff;
    font-size: 0.8rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5;
}

.scene-ref-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-basis: 100%;
}

.scene-ref-add-btn,
.scene-ref-auto-btn {
    font-size: 0.7rem;
    padding: 2px 8px;
}

.scene-ref-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    padding: 6px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    flex-basis: 100%;
    max-height: 220px;
    overflow-y: auto;
}

.scene-ref-pick-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 64px;
    cursor: pointer;
}

.scene-ref-pick-item img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.scene-ref-pick-item:hover img {
    border-color: var(--primary, #4a90e2);
}

.scene-ref-caption {
    font-size: 0.65rem;
    color: var(--text-light, #666);
    text-align: center;
    word-break: break-all;
    line-height: 1.2;
}

.scene-ref-empty {
    font-size: 0.7rem;
    color: var(--text-light, #666);
    padding: 4px 0;
}

.char-image-set {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.char-image-set .char-image-name {
    width: 100%;
    box-sizing: border-box;
    padding: 2px 4px;
    font-size: 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    text-align: center;
}

.char-image-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    cursor: pointer;
}

.char-image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.char-image-item .remove-btn,
.scene-image-item .remove-btn,
.ed-gen-result-item .remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition);
    z-index: 10;
    /* 必ず保存ボタンより前面に表示 */
}

.char-image-item:hover .remove-btn,
.scene-image-item:hover .remove-btn,
.ed-gen-result-item:hover .remove-btn {
    opacity: 1;
}

.char-image-item .download-btn,
.scene-image-item .download-btn,
.ed-gen-result-item .download-btn {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition);
    z-index: 5;
}

.char-image-item:hover .download-btn,
.scene-image-item:hover .download-btn,
.ed-gen-result-item:hover .download-btn {
    opacity: 1;
}

/* ===== 設定グリッド ===== */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* 設定グリッド + 前ページ画像 のレイアウト */
.settings-with-prevpage {
    display: flex;
    gap: 8px;
    align-items: stretch;
    container-type: inline-size;
    /* 下のアクションボタン行(margin-top:-14px)が最下段の要素に重なって
       見切れるのを防ぐためのクリアランス */
    margin-bottom: 16px;
}

/* 設定エリアを縮小（前ページ画像の幅を確保するため） */
.settings-with-prevpage .setting-item label {
    min-width: 0;
    font-size: 0.72rem;
}

.settings-with-prevpage .setting-item select {
    padding: 4px 6px;
    font-size: 0.78rem;
}

.settings-with-prevpage .settings-grid {
    gap: 6px;
}

.settings-with-prevpage .textarea-small {
    min-height: 48px;
}

.settings-with-prevpage .settings-left {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.prev-page-area {
    flex: 0 0 100px;
    max-width: 100px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}


.prev-page-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
    margin-top: 4px;
    text-align: center;
    white-space: nowrap;
}

.prev-page-zone {
    flex: 1;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    position: relative;
    cursor: pointer;
    transition: all var(--transition);
    min-height: 96px;
    overflow: hidden;
    background: var(--card, #fff);
    width: 100%;
}

.prev-page-zone:hover,
.prev-page-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.prev-page-zone .drop-placeholder {
    padding: 8px 4px;
}

.prev-page-zone .drop-icon {
    font-size: 1.6rem;
    margin-bottom: 2px;
}

.prev-page-zone .drop-placeholder p {
    font-size: 0.72rem;
    margin-bottom: 2px;
}

.prev-page-zone .drop-placeholder small {
    font-size: 0.62rem;
}

.prev-page-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    position: absolute;
    inset: 0;
    background: #fafafa;
}

.prev-page-preview.hidden,
.prev-page-remove.hidden {
    display: none !important;
}

.prev-page-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
}

.prev-page-remove:hover {
    background: rgba(220,40,40,0.9);
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.setting-item label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 55px;
}

.setting-item select {
    flex: 1;
    min-width: 0;
}

/* ===== 右パネル - シーン ===== */
.right-top-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    container-type: inline-size;
    /* margin-bottom: 12px; 元のマージン削除 */
    position: sticky;
    top: -14px;
    /* panel-bodyのpadding分 */
    z-index: 10;
    background: var(--card);
    padding-top: 14px;
    margin-top: -14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    /* コンテンツとの間隔 */
    flex-shrink: 0;
    /* 縮小しない */
}

.right-top-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    white-space: nowrap;
    padding: 8px 4px;
    /* コンテナ幅(右パネル)に対して文字サイズを自動調整。"シーンを登録する"が見切れないよう抑える */
    font-size: clamp(0.55rem, 2.4cqw, 0.78rem);
    overflow: visible;
}

.scenes-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.no-scenes-message {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-light);
    font-size: 0.85rem;
}

/* シーンカード */
.scene-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.scene-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--input-bg);
    border-bottom: 1px solid var(--border);
    gap: 6px;
}

.scene-card-header .scene-title {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text);
}

.scene-card-header .btn {
    font-size: 0.72rem;
    padding: 4px 10px;
}

.scene-content-area {
    display: none;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.scene-content-area.show {
    display: block;
}

.scene-content-area textarea {
    min-height: 80px;
    font-size: 0.8rem;
}

/* シーン画像グリッド */
.scene-images-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: 6px;
}

.scene-image-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.scene-image-item {
    position: relative;
    width: 100%;
    aspect-ratio: 2/3; /* アスペクト比を親で保証する */
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--input-bg);
    border: 1px solid var(--border);
    cursor: pointer;
}

.scene-image-item img {
    width: 100%;
    height: 100%; /* コンテナ全体を埋める */
    display: block;
    object-fit: contain; /* 比率を崩さずに収める */
    background: #000; /* 余白がある場合は黒にする */
}

.scene-image-item .img-placeholder {
    width: 100%;
    height: 100%; /* アスペクト比は親で保証されているので100%にする */
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    font-size: 0.7rem;
}

/* ===== 画像マーカー（機能13） ===== */
.image-markers {
    display: flex;
    gap: 8px;
    justify-content: center;
    padding: 4px 0;
}

.marker-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #BDC3C7;
    cursor: pointer;
    transition: all var(--transition);
    border: 2px solid transparent;
}

.marker-dot:hover {
    transform: scale(1.2);
}

.marker-dot.green {
    background: #27AE60;
    border-color: #1E8449;
    box-shadow: 0 0 6px rgba(39, 174, 96, 0.4);
}

.inspection-arrow {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #F1C40F;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    z-index: 2;
}

.marker-dot.yellow {
    background: #F1C40F;
    border-color: #B7950B;
    box-shadow: 0 0 6px rgba(241, 196, 15, 0.4);
}

.marker-dot.red {
    background: #E74C3C;
    border-color: #C0392B;
    box-shadow: 0 0 6px rgba(231, 76, 60, 0.4);
}

/* ===== モーダル ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--card);
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-xl);
    padding: 24px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}

.chat-modal-content {
    max-width: 650px;
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.close-modal-btn {
    background: transparent;
    border: none;
    font-size: 1.8rem;
    color: var(--text-light);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}

.close-modal-btn:hover {
    color: var(--text);
}

.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.modal-actions .btn {
    flex: 1;
}

/* 画像ビューア */
.image-viewer-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#viewerImage {
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    object-fit: contain;
}

.close-viewer-btn {
    position: absolute;
    top: -40px;
    right: 0;
    background: transparent;
    border: none;
    color: white;
    font-size: 2.5rem;
    cursor: pointer;
    line-height: 1;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* ===== チャット ===== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 300px;
    max-height: 50vh;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--input-bg);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
}

.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 0.85rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-bubble.user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
    align-self: flex-start;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input-area textarea {
    flex: 1;
    min-height: 40px;
    max-height: 100px;
}

.chat-input-area .btn {
    height: 40px;
}

#chatApplyBtn {
    margin-top: 10px;
    width: 100%;
}

/* ===== アニメーション ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ===== レスポンシブ ===== */
@media (max-width: 1024px) {
    .panels-container {
        grid-template-columns: 1fr;
    }

    .panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: none;
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 8px 12px;
    }

    .header-left h1 {
        font-size: 1.1rem;
    }

    .panel-body {
        padding: 10px;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== スクロールバー ===== */
.panel::-webkit-scrollbar {
    width: 5px;
}

.panel::-webkit-scrollbar-track {
    background: transparent;
}

.panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.panel::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

/* ===== ローディングオーバーレイ ===== */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    z-index: 5;
}

.loading-overlay .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--primary-light);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===== APIヘルプリンク ===== */
.api-help-links {
    display: block;
    margin-top: 12px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.8;
}

.api-help-links a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition);
}

.api-help-links a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* ===== 原稿モード ===== */

/* モード切替バッジ */
.mode-badge {
    cursor: pointer;
    user-select: none;
    transition: all var(--transition);
    opacity: 0.5;
}

.mode-badge.active {
    opacity: 1;
}

.mode-badge:hover {
    opacity: 0.8;
    transform: translateY(-1px);
}

.mode-badge-manuscript {
    background: var(--success) !important;
}

.mode-badge-manuscript.active {
    background: var(--success) !important;
    box-shadow: 0 2px 8px rgba(0, 184, 148, 0.4);
}

/* 原稿モード ボタン */
.btn-manuscript {
    background: var(--success);
    color: white;
}

.btn-manuscript:hover:not(:disabled) {
    background: #00a381;
    box-shadow: 0 2px 8px rgba(0, 184, 148, 0.3);
}

.btn-lg {
    padding: 12px 24px;
    font-size: 0.95rem;
}

/* 原稿モード コンテナ */
.ms-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 20px;
    min-height: calc(100vh - 120px);
}

/* ルート選択 */
.ms-route-header {
    text-align: center;
    margin-bottom: 32px;
}

.ms-route-header h2 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.ms-route-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.ms-route-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.ms-route-card {
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 32px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.ms-route-card:hover {
    border-color: var(--success);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.ms-route-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.ms-route-card h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.ms-route-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ページヘッダー */
.ms-page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.ms-page-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

.ms-back-btn {
    flex-shrink: 0;
}

/* ステップインジケーター */
.ms-steps-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 28px;
    padding: 16px;
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.ms-step-dot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--input-bg);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-light);
    transition: all 0.3s ease;
    flex-shrink: 0;
    cursor: pointer;
}

.ms-step-dot:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-sm);
}

.ms-step-dot.active {
    background: var(--success);
    border-color: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 184, 148, 0.3);
}

.ms-step-dot.completed {
    background: #b2dfdb;
    border-color: var(--success);
    color: var(--success);
}

.ms-step-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    max-width: 60px;
}

/* ステップパネル */
.ms-step-panel {
    background: var(--card);
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
}

.ms-step-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--success);
}

.ms-step-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

/* フォームグループ */
.ms-form-group {
    margin-bottom: 20px;
}

.ms-form-group>label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 8px;
}

.ms-required {
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 500;
}

.ms-optional {
    color: var(--text-light);
    font-size: 0.8rem;
    font-weight: 400;
}

/* ステップアクション */
.ms-step-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.ms-step-actions .btn {
    flex: 1;
}

/* キャラクター登録クラスタ */
.ms-char-cluster {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    overflow: hidden;
}

.ms-char-cluster-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--success);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
}

.ms-char-cluster-body {
    display: flex;
    gap: 12px;
    padding: 12px;
    align-items: flex-start;
}

.ms-char-image-area {
    flex-shrink: 0;
    width: 100px;
}

.ms-char-dropzone {
    width: 100px;
    height: 100px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: all var(--transition);
}

.ms-char-dropzone:hover {
    border-color: var(--success);
    background: rgba(0, 184, 148, 0.05);
}

.ms-char-dropzone .drop-placeholder {
    padding: 8px;
}

.ms-char-dropzone .drop-icon {
    font-size: 1.5rem;
    margin-bottom: 2px;
}

.ms-char-dropzone small {
    font-size: 0.65rem;
}

.ms-char-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
}

.ms-char-image-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: var(--danger-color, #ff4757);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 0.75rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.ms-char-dropzone.has-image .ms-char-image-remove {
    display: flex;
    opacity: 0;
    transition: opacity 0.2s;
}

.ms-char-dropzone.has-image:hover .ms-char-image-remove {
    opacity: 1;
}

.ms-char-name-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ms-char-name-area label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.ms-char-name-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.88rem;
    font-family: inherit;
    transition: all var(--transition);
}

.ms-char-name-input:focus {
    outline: none;
    border-color: var(--success);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.1);
}

/* 世界観選択 */
.ms-worldview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.ms-worldview-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ms-worldview-group-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.ms-worldview-btn {
    padding: 10px 16px;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--text);
    transition: all 0.2s ease;
    text-align: left;
}

.ms-worldview-btn:hover {
    border-color: var(--success);
    background: rgba(0, 184, 148, 0.05);
}

.ms-worldview-btn.selected {
    border-color: var(--success);
    background: rgba(0, 184, 148, 0.1);
    color: var(--success);
    font-weight: 700;
    box-shadow: 0 0 0 2px rgba(0, 184, 148, 0.2);
}

/* プロット提案 */
.ms-proposals-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 16px;
}

.ms-proposal-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    background: var(--card);
}

.ms-proposal-label {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--success);
    margin-bottom: 8px;
}

/* 決定ボタン */
.ms-decide-btns {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.ms-decide-btns .btn {
    flex: 1;
}

.ms-decide-btns .btn.selected {
    background-color: #ff4757;
    border-color: #ff4757;
    color: white;
}

/* セクション選択 */
.ms-section-select {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.ms-section-select-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ms-section-select .btn {
    width: 100%;
}

.ms-section-guide {
    display: block;
    margin-top: 8px;
    font-size: 0.82rem;
    color: #95a5a6;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s;
}

.ms-section-guide:hover {
    color: #7f8c8d;
}

/* 移行情報 */
.ms-migrate-info {
    background: rgba(0, 184, 148, 0.08);
    border: 1px solid rgba(0, 184, 148, 0.2);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 20px;
}

.ms-migrate-info p {
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 8px;
    line-height: 1.6;
}

.ms-migrate-info p:last-child {
    margin-bottom: 0;
}

/* プログレスバー */
.ms-progress-bar {
    background: var(--input-bg);
    border-radius: var(--radius-md);
    height: 32px;
    position: relative;
    overflow: hidden;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

.ms-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #00d2a8);
    border-radius: var(--radius-md);
    transition: width 0.5s ease;
    width: 0%;
}

.ms-progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
}

/* レスポンシブ（原稿モード） */
@media (max-width: 768px) {
    .ms-route-cards {
        grid-template-columns: 1fr;
    }

    .ms-worldview-grid {
        grid-template-columns: 1fr;
    }

    .ms-char-cluster-body {
        flex-direction: column;
        align-items: stretch;
    }

    .ms-char-image-area {
        width: 100%;
    }

    .ms-char-dropzone {
        width: 100%;
        height: 120px;
    }

    .ms-decide-btns {
        flex-direction: column;
    }
}

/* ===== 画像テキスト編集エディタ ===== */
#imageEditorModal {
    z-index: 2000;
}

.ed-container {
    width: 98vw;
    height: 96vh;
    background: var(--card);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

/* ツールバー */
.ed-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #1e1e2e;
    border-bottom: 1px solid #333;
    flex-wrap: wrap;
    min-height: 48px;
}

.ed-toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px;
    border-right: 1px solid #444;
}

.ed-toolbar-group:last-child {
    border-right: none;
}

.ed-toolbar-right {
    margin-left: auto;
}

.ed-tool-btn {
    padding: 6px 12px;
    background: #2d2d3e;
    border: 1px solid #444;
    border-radius: 6px;
    color: #ccc;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.ed-tool-btn:hover {
    background: #3d3d5e;
    color: #fff;
}

.ed-tool-btn.active {
    background: #5b6abf;
    border-color: #7b8de0;
    color: #fff;
    box-shadow: 0 0 8px rgba(91, 106, 191, 0.4);
}

.ed-action-btn {
    padding: 5px 10px;
    background: #2d2d3e;
    border: 1px solid #444;
    border-radius: 6px;
    color: #ccc;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.ed-action-btn:hover:not(:disabled) {
    background: #3d3d5e;
    color: #fff;
}

.ed-action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ed-save-btn {
    background: #2a4e8e;
    border-color: #3a6eae;
}

.ed-save-btn:hover {
    background: #3a6eae !important;
}

.ed-export-btn {
    background: #2a5e3a;
    border-color: #3a7e4a;
}

.ed-export-btn:hover {
    background: #3a7e4a !important;
}

.ed-close-btn {
    width: 36px;
    height: 36px;
    background: #e74c3c;
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    line-height: 1;
}

.ed-close-btn:hover {
    background: #c0392b;
}

.ed-eyedropper-color {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #666;
    background: #ffffff;
    cursor: pointer;
}

/* メインレイアウト */
.ed-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.ed-canvas-area {
    flex: 1;
    position: relative;
    background: #2a2a2a;
    overflow: hidden;
    display: grid;
    gap: 8px;
    padding: 8px;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.ed-doc {
    position: relative;
    background: #1f1f1f;
    border: 2px solid #444;
    border-radius: 6px;
    overflow: hidden;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ed-doc.active {
    border-color: var(--primary, #4A76FF);
    box-shadow: 0 0 0 2px rgba(74, 118, 255, 0.35);
}

.ed-doc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #2c2c2c;
    color: #ddd;
    padding: 4px 8px;
    font-size: 0.75rem;
    border-bottom: 1px solid #444;
    flex-shrink: 0;
}

.ed-doc-header .ed-doc-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ed-doc-close {
    background: rgba(231, 76, 60, 0.85);
    color: #fff;
    border: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: 6px;
}

.ed-doc-canvas-wrap {
    flex: 1;
    position: relative;
    background: #2a2a2a;
    overflow: hidden;
}

.ed-doc-canvas-wrap canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* 画像生成パネル */
.ed-gen-panel {
    width: 280px;
    background: #f8f9fa;
    border-left: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
    flex-shrink: 0;
}

.ed-gen-panel select,
.ed-gen-panel textarea,
.ed-gen-panel input[type="number"] {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text);
}

.ed-gen-panel .ed-prop-row > label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* プロパティパネル */
.ed-prop-panel {
    width: 260px;
    background: #f8f9fa;
    border-left: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
    flex-shrink: 0;
}

.ed-prop-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary);
}

.ed-prop-label {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
    margin-top: 8px;
}

.ed-prop-row {
    margin-bottom: 12px;
}

.ed-prop-row > label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.ed-prop-row textarea,
.ed-prop-row input[type="number"],
.ed-prop-row select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text);
    transition: border-color 0.2s;
}

.ed-prop-row textarea:focus,
.ed-prop-row input:focus,
.ed-prop-row select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(74, 118, 255, 0.15);
}

.ed-prop-row input[type="color"] {
    width: 100%;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.ed-prop-row input[type="checkbox"] {
    margin-right: 6px;
    width: auto;
    cursor: pointer;
}

.ed-color-pick {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ed-color-pick input[type="color"] {
    width: 60px;
    height: 32px;
}

.ed-color-preview {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: #ffffff;
}

.ed-prop-hint {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 4px;
    line-height: 1.5;
}

.ed-prop-empty {
    text-align: center;
    color: var(--text-light);
    font-size: 0.85rem;
    margin-top: 40px;
    line-height: 1.6;
}

/* 画像生成セクション */
.ed-gen-section {
    margin-bottom: 8px;
}

.ed-gen-ref-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    min-height: 60px;
    padding: 6px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
}

.ed-gen-ref-grid.dragover {
    border-color: var(--primary);
    background: #eef3ff;
}

.ed-gen-ref-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.ed-gen-ref-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ed-gen-ref-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: rgba(231, 76, 60, 0.9);
    color: #fff;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ed-gen-results {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.ed-gen-result-item {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
}

.ed-gen-result-item img {
    width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
}

.ed-gen-results-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-light);
    font-size: 0.8rem;
    padding: 12px;
}

/* レスポンシブ（エディタ） */
@media (max-width: 768px) {
    .ed-container {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }

    .ed-main {
        flex-direction: column;
    }

    .ed-prop-panel {
        width: 100%;
        max-height: 200px;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    .ed-toolbar {
        padding: 6px 8px;
        gap: 4px;
    }

    .ed-tool-btn, .ed-action-btn {
        padding: 4px 8px;
        font-size: 0.7rem;
    }

    .ed-toolbar-group {
        padding: 0 2px;
    }
}

/* インラインテキスト編集（透明オーバーレイ） */
.ed-inline-textarea {
    font-family: inherit;
    box-sizing: border-box;
    overflow: hidden;
    min-width: 40px;
    min-height: 24px;
    max-width: 90vw;
    max-height: 80vh;
    background: transparent;
    border: 1px dashed rgba(91, 106, 191, 0.6);
    caret-color: #ff6b00;
}

.ed-inline-textarea:focus {
    border-color: rgba(255, 107, 0, 0.5);
    box-shadow: none;
}

/* 非モーダル（背後スクロール・操作可能）な拡大モーダル */
.modal-overlay.non-modal {
    pointer-events: none;
    background: transparent; /* 背景の暗幕をなくす */
}

.modal-overlay.non-modal .modal-content {
    pointer-events: auto;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    position: fixed; /* 画面に固定し、ドラッグで動かせるようにする */
    resize: both; /* ユーザーが自由にサイズ変更できるようにする */
    overflow: hidden; /* リサイズ用のスクロールバーが二重になるのを防ぐ */
    min-width: 350px;
    min-height: 250px;
}

/* 左寄せ（右パネルを露出させるため） */
.modal-overlay.align-left {
    justify-content: flex-start;
    padding-left: 20px;
}

.modal-overlay.align-left .modal-content {
    margin-left: 0;
    margin-right: auto;
    /* fixed配置になるため、max-width等の設定は初期位置・初期サイズとしてJS側で設定します */
}
