/* ===================================================
   台本エディタ — editor.css
   テーマ CSS 変数（main.css で定義）を使用。全テーマ自動対応。
=================================================== */

/* ── レイアウト ── */
.editor-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 80px 16px 100px;
}

.editor-back-link {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    color: var(--text-sub);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.15s;
}
.editor-back-link:hover {
    color: var(--primary);
}
.editor-back-link .material-symbols-rounded {
    font-size: 20px;
}

/* ── メタデータ ── */
.editor-meta {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}
.editor-meta__row {
    display: flex;
    gap: 12px;
}
.editor-meta__field {
    margin-bottom: 10px;
}
.editor-meta__field--half {
    flex: 1;
    min-width: 0;
}
.editor-meta__label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-sub);
    margin-bottom: 4px;
    letter-spacing: 0.03em;
}
.editor-meta__input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}
.editor-meta__input:focus {
    border-color: var(--primary);
}
.editor-meta__timestamp {
    font-size: 0.75rem;
    color: var(--muted);
    text-align: right;
}

/* ── 登場人物レジストリ ── */
.char-registry {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 16px;
    overflow: hidden;
}
.char-registry__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
}
.char-registry__chevron {
    transition: transform 0.2s;
    font-size: 22px;
    color: var(--muted);
}
.char-registry__header[aria-expanded="false"] .char-registry__chevron {
    transform: rotate(-90deg);
}
.char-registry__body {
    padding: 0 16px 14px;
}
.char-registry__body[hidden] {
    display: none;
}
.char-registry__list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
    min-height: 0;
}
.char-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px 5px 8px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    border: 1px solid var(--border);
    background: var(--bg);
}
.char-chip__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.char-chip__remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    color: var(--muted);
    padding: 0 0 0 2px;
    transition: color 0.15s;
}
.char-chip__remove:hover {
    color: var(--coral);
}
.char-registry__add {
    display: flex;
    gap: 8px;
}
.char-registry__input {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.char-registry__input:focus {
    border-color: var(--primary);
}
.char-registry__btn-add {
    padding: 7px 14px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s;
}
.char-registry__btn-add:hover {
    opacity: 0.85;
}

/* ── Editor.js コンテナ ── */
.editor-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 8px;
    min-height: 300px;
}
.editor-block-hint {
    text-align: center;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 12px;
}
.editor-block-hint kbd {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--border-md);
    border-radius: 4px;
    font-size: 0.8rem;
    font-family: inherit;
    background: var(--bg);
}

/* Editor.js 基本オーバーライド */
.codex-editor {
    font-family: 'Noto Sans JP', 'M PLUS Rounded 1c', sans-serif;
}
.ce-block__content {
    max-width: 100%;
    margin: 0;
}
.codex-editor__redactor {
    padding-bottom: 100px !important;
}
.ce-toolbar__content {
    max-width: 100%;
}
.ce-toolbar__plus {
    color: var(--primary);
}

/* ── カスタムブロック共通 ── */
.ce-script-block {
    padding: 10px 12px;
    border-radius: 8px;
    margin: 4px 0;
    transition: box-shadow 0.15s;
    position: relative;
}
.ce-script-block:focus-within {
    box-shadow: 0 0 0 2px var(--primary-dim);
}
.ce-script-block__type-label {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 4px;
}

/* ── 見出しブロック ── */
.ce-script-heading {
    border-bottom: 2px solid var(--primary-dim);
    background: var(--primary-faint);
}
.ce-script-heading__levels {
    display: inline-flex;
    gap: 4px;
    margin-left: 8px;
    vertical-align: middle;
}
.ce-script-heading__level-btn {
    padding: 1px 7px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text-sub);
    font-size: 0.7rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.4;
}
.ce-script-heading__level-btn--active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.ce-script-heading__text {
    outline: none;
    font-weight: 700;
    color: var(--primary);
    min-height: 1.2em;
}
.ce-script-heading__text--lv1 { font-size: 1.25rem; }
.ce-script-heading__text--lv2 { font-size: 1.1rem; }
.ce-script-heading__text--lv3 { font-size: 0.95rem; }
.ce-script-heading__text:empty::before {
    content: '見出しを入力…';
    color: var(--muted);
    pointer-events: none;
}

/* ── セリフブロック ── */
.ce-script-dialogue {
    background: var(--bg);
    border-left: 5px solid var(--border-md);
    padding-left: 14px;
}
.ce-script-dialogue__header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.ce-script-dialogue__select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-surface);
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    min-width: 80px;
    max-width: 180px;
}
.ce-script-dialogue__select:focus {
    border-color: var(--primary);
}
.ce-script-dialogue__char-input {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-surface);
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    width: 120px;
}
.ce-script-dialogue__char-input:focus {
    border-color: var(--primary);
}
.ce-script-dialogue__text {
    outline: none;
    color: var(--text);
    min-height: 1.2em;
    line-height: 1.7;
}
.ce-script-dialogue__text:empty::before {
    content: 'セリフを入力…';
    color: var(--muted);
    pointer-events: none;
}

/* ── ト書きブロック ── */
.ce-script-stage {
    background: transparent;
    border-left: 3px solid var(--stage-col);
    padding-left: 14px;
}
.ce-script-stage__text {
    outline: none;
    color: var(--stage-col);
    font-style: italic;
    min-height: 1.2em;
    line-height: 1.6;
}
.ce-script-stage__text:empty::before {
    content: 'ト書きを入力…';
    color: var(--muted);
    font-style: italic;
    pointer-events: none;
}

/* ── 演出メモブロック ── */
.ce-script-memo {
    background: var(--primary-faint);
    border-left: 3px solid var(--primary-dim);
}
.ce-script-memo__text {
    outline: none;
    color: var(--text-sub);
    min-height: 1.2em;
    line-height: 1.6;
}
.ce-script-memo__text:empty::before {
    content: '演出メモを入力…';
    color: var(--muted);
    pointer-events: none;
}

/* ── 区切り線ブロック ── */
.ce-script-divider {
    padding: 8px 0;
}
.ce-script-divider hr {
    border: none;
    border-top: 2px dashed var(--primary-dim);
    margin: 0;
}

/* ── 下部ツールバー ── */
.editor-toolbar-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    z-index: 100;
    justify-content: center;
}
.editor-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}
.editor-btn:active {
    transform: scale(0.97);
}
.editor-btn .material-symbols-rounded {
    font-size: 20px;
}
.editor-btn--save {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-md);
}
.editor-btn--save:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.editor-btn--start {
    background: var(--primary);
    color: #fff;
}
.editor-btn--start:hover {
    opacity: 0.88;
}

/* ── レスポンシブ ── */
@media (min-width: 768px) {
    .editor-main {
        padding-top: 100px;
    }
    .editor-toolbar-bottom {
        max-width: 720px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 12px 12px 0 0;
    }
}
