/* VN UI — textbox overlays the canvas; controls + log live docked in #pickers. */

/* ── Global VN-active state ──────────────────────────────────────────── */
body.vn-active #category-bar,
body.vn-active #item-panel {
    display: none !important;
}

body.vn-active #vn-panel { display: flex; }
#vn-panel { display: none; }

/* Hide mode: only hide the canvas textbox (panel/settings stay). Click canvas to restore. */
body.vn-hidden #vn-overlay .vn-textbox { visibility: hidden; }

/* Preview mode: strip chrome — only Hide + Exit remain. No log panel. */
body.vn-preview .vn-btn-auto,
body.vn-preview .vn-btn-skip,
body.vn-preview .vn-btn-settings,
body.vn-preview .vn-log-header,
body.vn-preview .vn-log-list { display: none !important; }
body.vn-preview .vn-panel-controls::before {
    content: 'Preview';
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 10px 8px 4px;
    align-self: center;
}

/* ── Canvas overlay (click-to-advance + textbox) ─────────────────────── */
#vn-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    animation: vn-scene-enter 0.35s ease-out;
}

@keyframes vn-scene-enter {
    from { opacity: 0; }
    to { opacity: 1; }
}

.vn-textbox {
    --vn-textbox-opacity: 0.75;
    background: rgba(0, 0, 0, var(--vn-textbox-opacity));
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 14px 18px 20px;
    min-height: 90px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
    z-index: 51;
}

.vn-speaker {
    --speaker-color: #ffc4de;
    color: var(--speaker-color);
    text-shadow:
        -1px -1px 0 rgba(0, 0, 0, 1),
         1px -1px 0 rgba(0, 0, 0, 1),
        -1px  1px 0 rgba(0, 0, 0, 1),
         1px  1px 0 rgba(0, 0, 0, 1),
        0 0 6px rgba(0, 0, 0, 0.8),
        0 0 12px color-mix(in srgb, var(--speaker-color) 40%, transparent);
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: 0.3px;
}

.vn-dialogue {
    color: #f5f5f5;
    text-shadow:
        0 1px 3px rgba(0, 0, 0, 0.95),
        0 0 8px rgba(0, 0, 0, 0.7),
        0 0 1px rgba(0, 0, 0, 1);
    font-size: 14px;
    line-height: 1.6;
    min-height: 2.8em;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Typewriter cursor */
.vn-dialogue.vn-typing::after {
    content: '▌';
    animation: vn-blink 0.6s step-end infinite;
    color: var(--accent, #E66DA5);
    margin-left: 1px;
}

@keyframes vn-blink {
    50% { opacity: 0; }
}

/* Click-to-advance indicator */
.vn-textbox::after {
    content: '';
    position: absolute;
    bottom: 8px;
    right: 14px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid rgba(255, 255, 255, 0.5);
    animation: vn-bounce 1s ease-in-out infinite;
}

@keyframes vn-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(3px); }
}

/* ── VN panel (docked in #pickers) ───────────────────────────────────── */
.vn-panel {
    flex: 1;
    flex-direction: column;
    min-height: 0;
    background: var(--surface, #fff);
    overflow: hidden;
    position: relative;
}

.vn-panel-controls {
    display: flex;
    gap: 4px;
    padding: 8px 10px;
    background: var(--surface-sunken, #f4edf0);
    border-bottom: 1px solid var(--border-accent, #e0d6dc);
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* ── Buttons (shared with settings popover) ──────────────────────────── */
.vn-ctrl-btn {
    background: var(--surface, #fff);
    color: var(--text-muted, #888);
    border: 1px solid var(--border, #e0d6dc);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    font-family: inherit;
    min-height: 32px;
}

.vn-ctrl-btn:hover {
    background: var(--surface-hover, #f4edf0);
    color: var(--accent, #E66DA5);
    border-color: var(--accent, #E66DA5);
}

.vn-ctrl-btn.active {
    background: var(--accent, #E66DA5);
    color: #fff;
    border-color: var(--accent, #E66DA5);
}

.vn-btn-exit {
    margin-left: auto;
    background: transparent;
    color: #c44;
    border-color: #eac6c6;
    font-weight: 700;
}

.vn-btn-exit:hover {
    background: #f5c2c2;
    color: #a00;
    border-color: #c44;
}

.vn-btn-settings {
    font-size: 14px;
    padding: 6px 10px;
}

/* ── Log (always visible in panel) ───────────────────────────────────── */
.vn-log-header {
    padding: 10px 14px 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted, #888);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.vn-log-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 14px 14px;
    min-height: 0;
}

.vn-log-list::-webkit-scrollbar { width: 6px; }
.vn-log-list::-webkit-scrollbar-track { background: var(--scrollbar-track); }
.vn-log-list::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

.vn-log-entry {
    margin-bottom: 10px;
    line-height: 1.5;
    padding: 6px 10px;
    background: var(--surface-sunken, #f4edf0);
    border-radius: 6px;
    border-left: 2px solid var(--accent, #E66DA5);
    animation: vn-log-enter 0.32s cubic-bezier(0.22, 0.61, 0.36, 1);
    transform-origin: left center;
}

@keyframes vn-log-enter {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.97);
        border-left-color: transparent;
    }
    60% {
        opacity: 1;
        border-left-color: var(--accent, #E66DA5);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.vn-log-speaker {
    font-weight: 700;
    font-size: 11px;
    display: block;
    margin-bottom: 2px;
    text-shadow:
        -1px -1px 0 rgba(0, 0, 0, 0.15),
         1px -1px 0 rgba(0, 0, 0, 0.15),
        -1px  1px 0 rgba(0, 0, 0, 0.15),
         1px  1px 0 rgba(0, 0, 0, 0.15);
}

.vn-log-text {
    color: var(--text-secondary, #555);
    font-size: 13px;
}

/* ── Settings popover ────────────────────────────────────────────────── */
.vn-settings-popover {
    position: absolute;
    top: 52px;
    right: 12px;
    z-index: 55;
    background: var(--surface, #fff);
    border: 1px solid var(--border-accent, #e0d6dc);
    border-radius: 8px;
    padding: 12px 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    min-width: 240px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.vn-settings-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.vn-settings-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #888);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.vn-settings-speed {
    display: flex;
    gap: 4px;
}

.vn-settings-speed .vn-ctrl-btn {
    flex: 1;
    padding: 5px 8px;
    font-size: 11px;
    min-height: 28px;
}

.vn-settings-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vn-settings-slider {
    flex: 1;
    accent-color: var(--accent, #E66DA5);
}

.vn-settings-readout {
    font-size: 11px;
    color: var(--text-muted, #888);
    min-width: 38px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ── Scenario list (shown in #item-panel when Scenes tab active) ─────── */
.vn-scenario-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vn-scenario-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: 8px;
    transition: border-color 0.15s, background 0.15s;
}

.vn-scenario-card:hover {
    border-color: var(--border-accent);
    background: var(--surface-hover);
}

.vn-scenario-card.vn-scenario-demo {
    border-style: dashed;
    border-color: var(--border-accent);
}

.vn-scenario-card.vn-scenario-demo:hover {
    border-style: solid;
}

.vn-scenario-info {
    flex: 1;
    min-width: 0;
}

.vn-scenario-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 4px;
}

.vn-scenario-name-editable {
    cursor: text;
}
.vn-scenario-name-editable:hover {
    background: var(--surface-hover);
}

.vn-scenario-name-input {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 2px 4px;
    margin: -2px -4px;
    width: 100%;
    font-family: inherit;
    outline: none;
}

.vn-scenario-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.vn-scenario-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.vn-scenario-action {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    background: var(--border-accent);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.vn-scenario-action:hover {
    background: var(--accent);
    color: #fff;
}

.vn-scenario-delete:hover {
    background: #e74c3c;
    color: #fff;
}

.vn-scenario-add {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    min-height: 48px;
    background: transparent;
    border: 2px dashed var(--border-accent);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    font-family: inherit;
}

.vn-scenario-add:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--surface-hover);
}

.vn-scenario-add span:first-child {
    font-size: 18px;
    line-height: 1;
}

.vn-scenario-add-label { font-weight: 500; }

/* ── Multi-character layout ──────────────────────────────────────────── */
.vn-characters {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
}

.vn-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 320px;
    height: 427px;
    z-index: 0;
}

.vn-char-slot {
    position: absolute;
    top: 0;
    width: 460px;
    height: 600px;
    transition: opacity 0.3s, filter 0.3s, transform 0.3s, left 0.3s;
    opacity: 0.96;
    filter: brightness(0.8);
    transform: scale(0.94);
    transform-origin: bottom center;
    z-index: 1;
    animation: vn-char-enter 0.55s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes vn-char-enter {
    from { opacity: 0; transform: translateY(24px) scale(0.88); }
    to { opacity: 0.96; transform: translateY(0) scale(0.94); }
}

.vn-char-slot.speaking {
    opacity: 1;
    filter: brightness(1);
    transform: scale(0.96);
    z-index: 2;
}

/* Hidden character (default state; beats reveal via visible: true) */
.vn-char-slot.vn-char-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.9);
}

/* Main canvas hidden (single-char mode, default until revealed) */
/* No transition — VN cover/uncover transitions handle smooth reveals. */
#live2d_wrap.vn-char-hidden {
    opacity: 0;
    pointer-events: none;
}

.vn-char-canvas {
    width: 428px;
    height: 428px;
}

/* ── VN scene editor (body.vn-editing) ──────────────────────────────── */
body.vn-editing #category-bar,
body.vn-editing #item-panel { display: none !important; }

body.vn-editing #vn-editor { display: flex; }
#vn-editor { display: none; }

/* Picker mode (overlayed over editor): show item-panel, hide editor */
body.vn-editing.vn-picking #vn-editor { display: none !important; }
body.vn-editing.vn-picking #item-panel { display: block !important; }

.vn-picker-header {
    position: sticky;
    top: -10px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin: -10px -10px 10px -10px;
    background: var(--surface-sunken);
    border-bottom: 1px solid var(--border-accent);
    flex-wrap: wrap;
}
.vn-picker-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}
.vn-picker-search {
    flex: 1 1 200px;
    min-width: 160px;
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-primary);
    font-family: inherit;
}
.vn-picker-search:focus {
    outline: none;
    border-color: var(--accent);
}
.vn-picker-grid-wrap {
    padding: 0;
}
.vn-picker-grid-wrap .empty-state {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Thumbnail preview used in outfit rows + bg field */
.vn-thumb {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-sunken);
}
.vn-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.vn-thumb-empty {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
}

.vn-editor {
    flex: 1;
    flex-direction: column;
    min-height: 0;
    background: var(--surface);
    overflow: hidden;
}

.vn-editor-top {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--surface-sunken);
    border-bottom: 1px solid var(--border-accent);
    flex-shrink: 0;
}

.vn-editor-crumb {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: text;
    transition: background 0.15s, color 0.15s;
}

.vn-editor-crumb:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.vn-editor-crumb-input {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 4px 6px;
    font-family: inherit;
    outline: none;
}

.vn-editor-btn {
    padding: 4px 10px;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    min-height: 28px;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.vn-editor-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.vn-editor-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.vn-editor-btn.active:hover {
    color: #fff;
    filter: brightness(1.08);
}

.vn-editor-view-toggle {
    display: inline-flex;
    gap: 0;
    border-radius: 6px;
    overflow: hidden;
}
.vn-editor-view-toggle .vn-editor-view-btn {
    border-radius: 0;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 600;
}
.vn-editor-view-toggle .vn-editor-view-btn:first-child {
    border-radius: 6px 0 0 6px;
}
.vn-editor-view-toggle .vn-editor-view-btn:last-child {
    border-radius: 0 6px 6px 0;
    border-left-width: 0;
}
.vn-editor-view-toggle .vn-editor-view-btn.active:last-child {
    border-left-width: 1px;
}

.vn-editor-btn.vn-editor-profiles-empty {
    position: relative;
}

.vn-editor-btn.vn-editor-profiles-empty::after {
    content: '';
    position: absolute;
    top: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--surface);
    pointer-events: none;
}

.vn-editor-profiles-nudge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin: 0 0 12px;
    border: 1px dashed var(--accent);
    border-radius: 8px;
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
    font-size: 13px;
    color: var(--text-primary);
}

.vn-editor-profiles-nudge-icon {
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
}

.vn-editor-profiles-nudge-text {
    flex: 1;
    line-height: 1.4;
}

.vn-editor-profiles-nudge-btn {
    flex-shrink: 0;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.vn-editor-profiles-nudge-btn:hover {
    filter: brightness(1.08);
    color: #fff;
}

@media (max-width: 768px) {
    .vn-editor-profiles-nudge {
        flex-wrap: wrap;
    }
    .vn-editor-profiles-nudge-text {
        flex-basis: 100%;
    }
}

.vn-editor-play {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.vn-editor-play:hover {
    filter: brightness(1.08);
    color: #fff;
    border-color: var(--accent);
}
.vn-editor-back { background: transparent; }

/* Editor body: two columns (beat list + form) */
.vn-editor-body {
    flex: 1;
    display: flex;
    gap: 10px;
    padding: 10px;
    min-height: 0;
}

.vn-editor-beatlist {
    flex: 0 0 34%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    min-width: 200px;
}

.vn-editor-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    min-width: 0;
}

.vn-editor-col-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 2px;
    flex-shrink: 0;
}

.vn-editor-beats {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 4px;
    min-height: 0;
}

.vn-editor-beats::-webkit-scrollbar { width: 6px; }
.vn-editor-beats::-webkit-scrollbar-track { background: var(--scrollbar-track); }
.vn-editor-beats::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

.vn-editor-beat {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: grab;
    transition: border-color 0.15s, background 0.15s;
}
.vn-editor-beat:hover {
    border-color: var(--border-accent);
    background: var(--surface-hover);
}
.vn-editor-beat.active {
    border-color: var(--accent);
    background: var(--accent-glow);
}
.vn-editor-beat.dragging {
    opacity: 0.4;
    cursor: grabbing;
}
.vn-editor-beat.drag-over {
    border-color: var(--accent);
    border-style: dashed;
    background: var(--accent-glow);
}

.vn-editor-beat-num {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--border-accent);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.vn-editor-beat.active .vn-editor-beat-num {
    background: var(--accent);
    color: #fff;
}

.vn-editor-beat-body {
    flex: 1;
    min-width: 0;
}
.vn-editor-beat-speaker {
    font-size: 11px;
    color: var(--accent);
    font-weight: 700;
    margin-bottom: 2px;
}
.vn-editor-beat-text {
    font-size: 12px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.vn-editor-beat-empty {
    color: var(--text-muted);
    font-style: italic;
}

.vn-editor-beat-del {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.vn-editor-beat:hover .vn-editor-beat-del { opacity: 1; }
.vn-editor-beat-del:hover {
    background: #e74c3c;
    color: #fff;
}

.vn-editor-add-beat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    background: transparent;
    border: 2px dashed var(--border-accent);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.vn-editor-add-beat:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--surface-hover);
}
.vn-editor-add-beat span:first-child {
    font-size: 14px;
    line-height: 1;
}

.vn-editor-form-body {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-height: 0;
}
.vn-editor-form-body::-webkit-scrollbar { width: 6px; }
.vn-editor-form-body::-webkit-scrollbar-track { background: var(--scrollbar-track); }
.vn-editor-form-body::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

.vn-editor-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
}

/* ── Beat form (M4) ─────────────────────────────────────────────────── */
.vn-editor-form-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.vn-editor-form-title {
    flex: 1;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

.vn-editor-form-actions {
    display: flex;
    gap: 4px;
}

.vn-editor-form-hide {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-soft, var(--text-primary));
    cursor: pointer;
    user-select: none;
    padding: 2px 6px;
    border-radius: 4px;
}

.vn-editor-form-hide:hover {
    background: var(--surface-hover, rgba(0,0,0,0.05));
}

.vn-editor-form-hide input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

.vn-editor-icon-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    border-radius: 6px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    font-family: inherit;
}
.vn-editor-icon-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}
.vn-editor-icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.vn-editor-form-del:hover:not(:disabled) {
    background: #e74c3c;
    color: #fff;
    border-color: #e74c3c;
}

.vn-editor-form-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vn-editor-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.vn-editor-field-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.vn-editor-input {
    font-size: 13px;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    font-family: inherit;
}
.vn-editor-input:focus {
    outline: none;
    border-color: var(--accent);
}

select.vn-editor-input { cursor: pointer; }

.vn-editor-textarea {
    font-size: 13px;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
    min-height: 64px;
    max-height: 300px;
}
.vn-editor-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.vn-editor-speaker-wrap { display: flex; }
.vn-editor-speaker-wrap .vn-editor-input { flex: 1; }

.vn-editor-number-wrap {
    display: flex;
    gap: 4px;
}
.vn-editor-number-wrap .vn-editor-input { flex: 1; min-width: 0; }

.vn-editor-clear-btn {
    width: 32px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    font-family: inherit;
    transition: border-color 0.15s, color 0.15s;
}
.vn-editor-clear-btn:hover {
    border-color: #e74c3c;
    color: #e74c3c;
}

.vn-editor-form-hint {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
    padding: 8px 10px;
    background: var(--surface-sunken);
    border-radius: 6px;
    border-left: 2px solid var(--border-accent);
}

/* ── Dialogue block (always visible, empty = transition beat) ───────── */
.vn-editor-dialogue {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

/* Text formatting toolbar */
.vn-text-toolbar {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.vn-text-toolbar-btn {
    padding: 4px 10px;
    min-width: 32px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    position: relative;
}
.vn-text-toolbar-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.vn-text-toolbar-bold {
    font-weight: 700;
}
.vn-text-toolbar-italic {
    font-style: italic;
}
.vn-text-toolbar-color-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

/* ── Actions bar ────────────────────────────────────────────────────── */
.vn-editor-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 4px;
}

.vn-editor-action-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.vn-editor-action-empty {
    padding: 10px 12px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    background: var(--surface-sunken);
    border-radius: 6px;
    border-left: 2px solid var(--border-accent);
}

.vn-editor-action {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.vn-editor-action.vn-action-flash {
    animation: vn-action-flash 1.5s ease-out;
}
@keyframes vn-action-flash {
    0%   { background: var(--accent-glow-lg); border-color: var(--accent); }
    100% { background: var(--surface); border-color: var(--border); }
}

.vn-editor-action-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vn-editor-action-icon {
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
}

.vn-editor-action-label {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.vn-editor-action-editor {
    min-width: 0;
    width: 100%;
}
.vn-editor-action-editor.vn-editor-input,
.vn-editor-action-editor .vn-editor-input {
    width: 100%;
}

.vn-editor-action-remove {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}

.vn-editor-add-action {
    width: 100%;
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text-muted);
    background: transparent;
    border: 2px dashed var(--border-accent);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    margin-top: 4px;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.vn-editor-add-action:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--surface-hover);
}
.vn-editor-add-action:focus {
    outline: none;
    border-color: var(--accent);
    border-style: solid;
}

/* Pickable ID field (bg) */
.vn-pickable-wrap {
    display: flex;
    gap: 4px;
    align-items: center;
}
.vn-pickable-wrap .vn-thumb {
    width: 32px;
    height: 32px;
}
.vn-pickable-wrap .vn-editor-input { flex: 1; min-width: 0; }

/* Transition editor (select + duration) */
.vn-transition-editor {
    display: flex;
    gap: 6px;
    align-items: center;
}
.vn-transition-editor > select {
    flex: 1;
    min-width: 0;
}
.vn-transition-dur {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}
.vn-transition-dur .vn-editor-input {
    width: 68px;
    text-align: right;
}
.vn-transition-dur-label {
    font-size: 11px;
    color: var(--text-muted);
}

/* Outfit action editor spans full width (layout is column inside .vn-editor-action now) */

/* ── Per-character property editor (emotion/blush/sweat) ──────────── */
.vn-charprop-editor {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.vn-charprop-row {
    display: grid;
    grid-template-columns: 28px auto 1fr 28px;
    gap: 8px;
    align-items: center;
    padding: 4px 6px;
    background: var(--surface-sunken);
    border-radius: 6px;
}

.vn-charprop-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.vn-charprop-editor-el { min-width: 0; width: 100%; }

.vn-charprop-add {
    width: 100%;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text-muted);
    background: transparent;
    border: 1px dashed var(--border-accent);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s, color 0.15s;
}
.vn-charprop-add:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.vn-charprop-add:focus {
    outline: none;
    border-color: var(--accent);
}

/* Character avatar chip (reused in charprop rows + outfit group headers) */
.vn-char-avatar {
    --avatar-color: var(--accent);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--avatar-color);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    letter-spacing: 0;
}

/* ── Outfit editor (uses design-standard styling) ─────────────────── */
.vn-outfit-editor {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.vn-outfit-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.vn-outfit-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 2px 4px;
    border-bottom: 1px dashed var(--border);
    margin-bottom: 2px;
}

.vn-outfit-group-name {
    flex: 1;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vn-outfit-row {
    display: grid;
    grid-template-columns: 40px auto 1fr 28px 28px;
    gap: 6px;
    align-items: center;
    padding: 4px 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.vn-outfit-slot {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    font-family: ui-monospace, monospace;
    white-space: nowrap;
}
.vn-outfit-id { min-width: 0; }

.vn-outfit-add {
    width: 100%;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text-muted);
    background: transparent;
    border: 1px dashed var(--border-accent);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s, color 0.15s;
}
.vn-outfit-add:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.vn-outfit-add:focus {
    outline: none;
    border-color: var(--accent);
}

/* Hidden/skipped beat indicator in the list */
.vn-editor-beat.skipped {
    opacity: 0.55;
    border-style: dashed;
}
.vn-editor-beat.skipped .vn-editor-beat-num {
    background: var(--border);
}
.vn-editor-beat.skipped .vn-editor-beat-text::after {
    content: ' · hidden';
    color: var(--text-muted);
    font-style: italic;
}

/* Edit action button on scenario card (inherits .vn-scenario-action) */

/* ── Profiles view ──────────────────────────────────────────────────── */
.vn-profiles-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    overflow-y: auto;
    min-height: 0;
}

.vn-profiles-view::-webkit-scrollbar { width: 6px; }
.vn-profiles-view::-webkit-scrollbar-track { background: var(--scrollbar-track); }
.vn-profiles-view::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

.vn-profiles-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.vn-profile-row {
    display: grid;
    grid-template-columns: 34px 1fr auto auto 28px;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color 0.15s;
}

.vn-profile-row:hover { border-color: var(--border-accent); }
.vn-profile-row.active { border-color: var(--accent); background: var(--accent-glow); cursor: default; }
.vn-profile-row:not(.active) { cursor: pointer; }

.vn-profile-color {
    width: 34px;
    height: 34px;
    padding: 0;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
}
.vn-profile-color::-webkit-color-swatch-wrapper { padding: 0; }
.vn-profile-color::-webkit-color-swatch { border: none; border-radius: 50%; }
.vn-profile-color::-moz-color-swatch { border: none; border-radius: 50%; }

.vn-profile-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    font-family: inherit;
    min-width: 0;
}
.vn-profile-name:focus {
    outline: none;
    border-color: var(--accent);
}

.vn-profile-select {
    font-size: 12px;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 8px;
    font-family: inherit;
    cursor: pointer;
    max-width: 150px;
    min-width: 0;
}
.vn-profile-select:focus {
    outline: none;
    border-color: var(--accent);
}

.vn-profile-del {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.vn-profile-row:hover .vn-profile-del { opacity: 1; }
.vn-profile-del:hover {
    background: #e74c3c;
    color: #fff;
}

.vn-profile-add {
    display: flex;
    gap: 6px;
    padding: 4px 0;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.vn-profile-add-input {
    flex: 1;
    min-width: 120px;
    font-size: 13px;
    padding: 8px 10px;
    border: 2px dashed var(--border-accent);
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
}
.vn-profile-add-input:focus {
    outline: none;
    border-color: var(--accent);
    border-style: solid;
}
.vn-profile-add-source {
    font-size: 12px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-muted);
    font-family: inherit;
    cursor: pointer;
    min-width: 0;
}
.vn-profile-add-source:focus { outline: none; border-color: var(--accent); }
.vn-profile-add-btn { flex-shrink: 0; }

/* Girl dropdown + refresh button combo */
.vn-profile-girl-wrap {
    display: flex;
    gap: 2px;
    min-width: 0;
}
.vn-profile-girl-wrap .vn-profile-select {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.vn-profile-refresh {
    width: 28px;
    border: 1px solid var(--border);
    border-left: none;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.vn-profile-refresh:hover:not(:disabled) {
    background: var(--accent-glow);
    color: var(--accent);
    border-color: var(--accent);
}
.vn-profile-refresh:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.vn-profile-refresh.flash {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ── Mobile ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Playback controls (VN active) */
    .vn-panel-controls {
        padding: 6px 8px;
    }
    .vn-ctrl-btn {
        padding: 5px 10px;
        font-size: 11px;
        min-height: 30px;
    }

    /* Editor body stacks, beat list becomes a horizontal chip strip */
    .vn-editor-body {
        flex-direction: column;
        gap: 6px;
        padding: 8px;
    }

    .vn-editor-beatlist {
        flex: 0 0 auto;
        flex-direction: row;
        align-items: stretch;
        gap: 6px;
        min-width: 0;
    }

    /* Hide header on mobile — the chips speak for themselves */
    .vn-editor-beatlist .vn-editor-col-header { display: none; }

    .vn-editor-beats {
        flex: 1;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 0 0 4px 0;
        gap: 6px;
        min-width: 0;
    }

    .vn-editor-beats::-webkit-scrollbar { height: 4px; width: auto; }

    .vn-editor-beat {
        flex: 0 0 auto;
        min-width: 110px;
        max-width: 160px;
        padding: 6px 8px;
    }

    /* Hide inline delete on mobile — delete from the form header instead */
    .vn-editor-beat-del { display: none; }

    .vn-editor-add-beat {
        flex: 0 0 auto;
        min-width: 64px;
        padding: 6px 10px;
    }
    .vn-editor-add-beat span:last-child { display: none; }

    .vn-editor-form {
        flex: 1;
        min-height: 200px;
    }

    /* Profiles: wrap to 3 rows — color+name+del on top, selects below */
    .vn-profile-row {
        grid-template-columns: 34px 1fr 28px;
        grid-template-areas:
            "color name del"
            "girl girl girl"
            "emo emo emo";
        gap: 6px;
    }
    .vn-profile-color { grid-area: color; }
    .vn-profile-name { grid-area: name; }
    .vn-profile-del { grid-area: del; }
    .vn-profile-girl-wrap { grid-area: girl; }
    .vn-profile-row > select.vn-profile-select { grid-area: emo; }
    .vn-profile-select { max-width: 100%; }
    .vn-profile-girl-wrap .vn-profile-select { min-width: 0; flex: 1; }

    .vn-profile-add-source { flex: 1 1 100%; }
}

