/**
 * UYI Write - AI Tools Panel Styles
 */

.sidebar-left-indicator {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 15px solid transparent;
    border-bottom: 15px solid transparent;
    border-left: 10px solid var(--text-primary);
    z-index: 10;
    cursor: pointer;
    transition: opacity 0.2s;
    opacity: 0.5;
}

.sidebar-left-indicator:hover {
    opacity: 1;
}

.sidebar-right.pinned .sidebar-left-indicator {
    opacity: 1;
}

/* Left Sidebar Indicator (facing left) */
.sidebar-right-indicator {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 15px solid transparent;
    border-bottom: 15px solid transparent;
    border-right: 10px solid var(--text-primary);
    z-index: 10;
    cursor: pointer;
    transition: opacity 0.2s;
    opacity: 0.5;
}

.sidebar-right-indicator:hover {
    opacity: 1;
}

.sidebar-left.pinned .sidebar-right-indicator {
    opacity: 1;
}

.sidebar-right.sliding-away {
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.sidebar-right.sliding-back {
    transform: translateX(0);
    transition: transform 0.3s ease;
}

.ai-tools-panel {
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

#ai-tools-sidebar {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#ai-tools-sidebar .ai-tools-panel {
    flex: 1 1 0;
    overflow-y: auto;
}

.ai-tools-undo-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

/* Undo/Redo in sidebar - don't stretch full width */
.ai-tools-undo-section .ai-tool-control-btn {
    min-width: auto;
    flex: 1;
}

.ai-tool-section {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ai-tool-section-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    min-height: 20px;
    box-sizing: border-box;
    padding: 0 var(--spacing-sm);
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
    width: 100%;
}

.ai-tool-section-header .ai-tool-icon-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-tool-section-header .ai-tool-icon-svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: block;
}

/* Write / Rewrite rows with inline detail selectors */
.ai-tool-write-actions-block {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    align-items: center;
    width: 100%;
}

.ai-tool-write-actions-block .ai-tool-btn-row-divider {
    width: 90%;
    min-width: 90%;
    height: 1px;
    background-color: var(--border-color);
    margin: var(--spacing-sm) auto;
    flex-shrink: 0;
}

.ai-tool-write-actions-block .ai-tool-action-row {
    width: 90%;
    min-width: 90%;
}

.ai-tool-write-actions-block .ai-tool-action-main.ai-tool-btn {
    width: auto;
    min-width: 0;
}

.ai-tool-write-actions-block .ai-tool-action-grammar.ai-tool-btn {
    width: 90%;
    min-width: 90%;
    margin-bottom: var(--spacing-sm);
}

.ai-tool-detail-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    width: 90%;
    min-width: 90%;
}

.ai-tool-detail-header-spacer {
    flex: 1;
    min-width: 0;
}

.ai-tool-detail-label {
    flex: 0 0 52px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-align: right;
}

.ai-tool-action-row {
    display: flex;
    align-items: stretch;
    gap: var(--spacing-xs);
}

.ai-tool-action-main {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.ai-tool-action-grammar {
    width: 100%;
}

.ai-tool-detail-stack {
    flex: 0 0 35px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-tool-detail-btn {
    flex: 1;
    min-height: 0;
    padding: 2px;
    border: 1px solid transparent;
    background: transparent;
    color: #4a4a4a;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.1;
    cursor: pointer;
    text-align: center;
    width: 35px;
}

.ai-tool-detail-btn[data-pct="0"].active {
    background: #0b1c2c;
    border-color: #0b1c2c;
    color: #fff;
}

.ai-tool-detail-btn[data-pct="50"].active {
    background: #713f81;
    border-color: #713f81;
    color: #fff;
}

.ai-tool-detail-btn[data-pct="100"].active {
    background: #e54d42;
    border-color: #e54d42;
    color: #fff;
}

.ai-tool-detail-btn:hover:not(.active) {
    color: #6a6a6a;
}

.ai-tool-detail-btn:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
}

/* Write / Rewrite / Grammar — stacked with thin dividers */
.ai-tool-write-actions .ai-tool-btn {
    margin-bottom: 0;
}

.ai-tool-write-actions .ai-tool-btn-row-divider {
    width: 90%;
    min-width: 90%;
    height: 1px;
    background-color: var(--border-color);
    margin: var(--spacing-sm) auto;
    flex-shrink: 0;
}

.ai-tool-write-actions .ai-tool-btn-write-primary,
.ai-tool-write-actions .ai-tool-btn-rewrite-primary,
.ai-tool-write-actions-block .ai-tool-btn-write-primary,
.ai-tool-write-actions-block .ai-tool-btn-rewrite-primary {
    min-height: 52px;
    padding: var(--spacing-md) var(--spacing-md);
}

body.page-write #ai-write-section-btn.ai-tool-btn-write-primary {
    background-color: #8e44ad;
    border-color: #8e44ad;
    color: #fff;
}

body.page-write #ai-write-section-btn.ai-tool-btn-write-primary:hover,
body.page-write #ai-write-section-btn.ai-tool-btn-write-primary:focus-visible {
    background-color: #7d3d9a;
    border-color: #7d3d9a;
    color: #fff;
}

body.page-write #ai-write-section-btn.ai-tool-btn-write-primary.active,
body.page-write #ai-write-section-btn.ai-tool-btn-write-primary.active:hover {
    background-color: #7d3d9a;
    border-color: #7d3d9a;
    color: #fff;
}

/* Write toggle caret: left when collapsed, right when panel is open */
body.page-write #ai-write-section-btn.ai-tool-btn-write-primary::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    flex-shrink: 0;
    border-style: solid;
    border-width: 5px 7px 5px 0;
    border-color: transparent currentColor transparent transparent;
}

body.page-write #ai-write-section-btn.ai-tool-btn-write-primary.active::before {
    border-width: 5px 0 5px 7px;
    border-color: transparent transparent transparent currentColor;
}

.ai-tool-write-actions .ai-tool-btn-rewrite-primary,
.ai-tool-write-actions-block .ai-tool-btn-rewrite-primary {
    background-color: #de745f;
    border-color: #de745f;
    color: #fff;
}

.ai-tool-write-actions .ai-tool-btn-rewrite-primary:hover,
.ai-tool-write-actions-block .ai-tool-btn-rewrite-primary:hover {
    background-color: #cf6a55;
    border-color: #cf6a55;
    color: #fff;
}

.ai-tool-write-actions .ai-tool-btn-rewrite-primary:active,
.ai-tool-write-actions-block .ai-tool-btn-rewrite-primary:active {
    filter: brightness(0.96);
    transform: translateY(1px);
}

.ai-tool-write-actions .ai-tool-btn-grammar,
.ai-tool-write-actions-block .ai-tool-btn-grammar {
    background-color: #e8b84a;
    border-color: #e8b84a;
    color: #fff;
}

.ai-tool-write-actions .ai-tool-btn-grammar:hover,
.ai-tool-write-actions-block .ai-tool-btn-grammar:hover {
    background-color: #d4a542;
    border-color: #d4a542;
    color: #fff;
}

.ai-tool-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: var(--spacing-md) 0;
}

.ai-tool-buttons-group {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-top: var(--spacing-sm);
    align-items: center;
}

#ai-grammar-btn {
    /* margin-top: 20vh; */
    justify-content: center;
    text-align: center;
}

.ai-tool-buttons-group .ai-tool-btn {
    margin-bottom: var(--spacing-sm);
    width: 90%;
    min-width: 90%;
}

.ai-tool-buttons-group .ai-tool-btn:last-child {
    margin-bottom: 0;
}

/* AI Provider Selector */
.ai-provider-selector {
    margin: 0;
}

.ai-provider-selector select {
    padding: var(--spacing-xs) var(--spacing-sm);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.7rem;
    min-width: 120px;
}

/* AI Tool Buttons */


.ai-tool-btn {
    width: 90%;
    min-width: 90%;
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--accent);
    border: 1px solid var(--accent);
    color: #fff;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    border-radius: 6px;
    font-family: inherit;
}

/* Icon + label buttons: align icon and text from the left */
.ai-tool-btn:has(.ai-tool-icon-cell) {
    text-align: left;
    justify-content: flex-start;
}

/* Fixed-width icon column so all button icons and text align */
.ai-tool-icon-cell {
    width: 24px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-tool-icon-cell svg {
    width: 18px;
    height: 18px;
    display: block;
}

.ai-tool-btn:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.ai-tool-btn.active {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.ai-tool-btn.active:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.ai-tool-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-tool-icon-plus {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-tool-icon-plus svg {
    color: var(--text-primary);
}

/* Icons on blue ai-tool-btn must be white in both light and dark theme */
.ai-tool-btn .ai-tool-icon,
.ai-tool-btn .ai-tool-icon-plus svg,
.ai-tool-btn .ai-tool-icon-cell svg {
    color: #fff;
}

.ai-tool-btn-label {
    white-space: nowrap;
}

.ai-tool-btn-text-multiline {
    display: flex;
    flex-direction: column;
    gap: 0;
    line-height: 1.2;
    flex: 1;
    white-space: nowrap;
}

.ai-tool-btn-text-multiline span {
    display: block;
}

/* Format Settings button (top) and Creation Settings button - distinct from primary actions */
.ai-tool-novel-settings-row,
.ai-tool-creation-settings-row {
    margin-bottom: var(--spacing-sm);
}
.ai-tool-btn-settings {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.8rem;
    width: 90%;
    min-width: 90%;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
    margin: auto;
}
.ai-tool-btn-settings:hover {
    background: var(--bg-primary);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}
.ai-tool-btn-settings .ai-tool-settings-icon {
    opacity: 0.9;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ai-tool-btn-settings .ai-tool-settings-icon svg {
    width: 14px;
    height: 14px;
    display: block;
}

/* Rewrite button loading spinner - force perfect circle */
.ai-rewrite-btn-spinner {
    display: block;
    width: 12px;
    height: 12px;
    min-width: 12px;
    min-height: 12px;
    max-width: 12px;
    max-height: 12px;
    margin-left: 6px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    box-sizing: border-box;
    flex-shrink: 0;
    align-self: center;
    animation: ai-rewrite-spin 0.7s linear infinite;
}
@keyframes ai-rewrite-spin {
    to { transform: rotate(360deg); }
}

/* Editor AI overlay: fixed over viewport so status label / cancel stay on top */
.editor-ai-overlay {
    position: fixed !important;
    inset: 0 !important;
    z-index: 10050 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    pointer-events: auto;
}

.editor-ai-overlay-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.75rem 1.5rem;
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    min-width: 220px;
}

.editor-ai-overlay-logo {
    width: 64px;
    height: auto;
    display: block;
    filter: none !important;
    animation: editor-ai-overlay-logo-glow 2.4s ease-in-out infinite;
}

@keyframes editor-ai-overlay-logo-glow {
    0%, 100% {
        opacity: 0.55;
        filter: drop-shadow(0 0 2px rgba(124, 92, 250, 0.25));
    }
    50% {
        opacity: 1;
        filter: drop-shadow(0 0 10px rgba(124, 92, 250, 0.65));
    }
}

.editor-ai-overlay-label {
    font-size: 1.25rem;
    font-weight: 600;
    color: #ffffff !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    letter-spacing: 0.02em;
}

.editor-ai-overlay-progress {
    width: 100%;
    height: 3px;
    margin-top: 0.15rem;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 2px;
    overflow: hidden;
}

.editor-ai-overlay-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent, #7c5cfa);
    border-radius: 2px;
}

.editor-ai-overlay-progress.is-indeterminate .editor-ai-overlay-progress-fill {
    width: 100% !important;
    background: linear-gradient(
        90deg,
        rgba(124, 92, 250, 0.15) 0%,
        rgba(124, 92, 250, 0.35) 25%,
        rgba(124, 92, 250, 0.95) 50%,
        rgba(124, 92, 250, 0.35) 75%,
        rgba(124, 92, 250, 0.15) 100%
    );
    background-size: 200% 100%;
    animation: editor-ai-overlay-progress-slide 1.1s linear infinite;
}

@keyframes editor-ai-overlay-progress-slide {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .editor-ai-overlay-logo {
        animation: none;
        opacity: 0.85;
    }
    .editor-ai-overlay-progress.is-indeterminate .editor-ai-overlay-progress-fill {
        animation: none;
    }
}

.editor-ai-overlay-cancel {
    margin-top: 0.25rem;
    padding: 0.5rem 1.25rem;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-size: 0.95rem;
    font-weight: 600;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    cursor: pointer;
}

.editor-ai-overlay-cancel:hover {
    background: rgba(255, 255, 255, 0.2);
}

.editor-ai-overlay-cancel:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
}

/* Brainstorm Modal */
.brainstorm-modal {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 3000;
}

.brainstorm-content {
    max-width: 1400px;
    width: 95%;
    max-height: 95vh;
    min-height: 80vh;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-radius: 8px;
}

.brainstorm-content .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.brainstorm-content .modal-header h2 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
    pointer-events: none;
}

.brainstorm-back-btn {
    background: transparent;
    border: none;
    color: #4a9eff;
    font-size: 0.9rem;
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    transition: all 0.2s;
    border-radius: 4px;
    font-family: inherit;
}

.brainstorm-back-btn:hover {
    background-color: rgba(74, 158, 255, 0.1);
}

.brainstorm-body {
    padding: var(--spacing-lg);
    overflow-y: auto;
    flex: 1;
    min-height: calc(80vh - 100px);
    max-height: calc(95vh - 100px);
}

.brainstorm-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    min-height: calc(80vh - 150px);
}

.brainstorm-column {
    display: flex;
    flex-direction: column;
    padding: var(--spacing-md);
    min-height: 100%;
    background-color: var(--bg-primary);
}

.brainstorm-column:not(:last-child) {
    border-right: 1px solid var(--border-color);
}

.brainstorm-column-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
}

.brainstorm-column-header:hover {
    opacity: 0.8;
}

.brainstorm-column-header.brainstorm-column-header--disabled {
    cursor: default;
    opacity: 0.55;
    pointer-events: none;
}

.brainstorm-column-header.brainstorm-column-header--disabled .brainstorm-info-icon {
    pointer-events: auto;
    cursor: pointer;
    opacity: 1;
}

.brainstorm-chapter-item-title {
    flex: 1;
    min-width: 0;
}

.brainstorm-add-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.brainstorm-add-row .brainstorm-step-text,
.brainstorm-add-row .brainstorm-prose {
    flex: 1;
    min-width: 0;
    margin: 0;
}

.brainstorm-add-mind-map-btn {
    flex: 0 0 auto;
    align-self: flex-start;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.2;
    padding: 0.2rem 0.45rem;
    color: var(--text-primary);
    background: transparent;
    border: 1px solid var(--accent, #6366f1);
    cursor: pointer;
    white-space: nowrap;
}

.brainstorm-add-mind-map-btn:hover:not(:disabled) {
    background: var(--accent, #6366f1);
    color: #fff;
}

.brainstorm-add-mind-map-btn:disabled,
.brainstorm-add-mind-map-btn.is-added {
    opacity: 0.55;
    cursor: default;
}

.brainstorm-chapter-item .brainstorm-add-mind-map-btn {
    margin-left: auto;
}

@media (max-width: 640px) {
    .brainstorm-add-row {
        flex-direction: column;
        align-items: stretch;
    }

    .brainstorm-add-mind-map-btn {
        align-self: flex-start;
    }
}

/* Legible “i” glyph inside accent-ring info controls (Brainstorm, Creation Settings, Name List, …) */
.ui-info-glyph {
    font-family: serif;
    font-size: 1em;
    font-style: normal;
    font-weight: 600;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    text-align: center;
    padding: 0;
    margin: 0;
}

/* Accent ring + transparent fill; filled accent on hover (matches active setting chips) */
.brainstorm-info-icon,
.creation-settings-info-icon,
.name-list-info-btn,
.sequence-settings-info-icon {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    font-size: 0.7rem;
    padding: 0;
    border: 1px solid var(--accent);
    border-radius: 50%;
    background: transparent;
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
    opacity: 0.85;
    transition: opacity 0.2s, background 0.2s, color 0.2s;
    box-sizing: border-box;
}

.creation-settings-info-icon {
    cursor: help;
}

button.brainstorm-info-icon,
.name-list-info-btn,
.sequence-settings-info-icon {
    cursor: pointer;
}

.brainstorm-info-icon:hover,
.creation-settings-info-icon:hover,
.name-list-info-btn:hover,
.sequence-settings-info-icon:hover {
    opacity: 1;
    background: var(--accent);
    color: var(--bg-primary, #fff);
}

.brainstorm-column-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0;
    flex: 1;
}

.brainstorm-chapter-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-xs) 0;
}

.brainstorm-chapter-item {
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    color: var(--text-primary);
    padding: var(--spacing-xs) 0;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.brainstorm-chapter-item:hover {
    color: var(--text-secondary);
}

.brainstorm-chapter-item.active {
    font-weight: 500;
    color: var(--text-primary);
}

.brainstorm-chapter-item.active .brainstorm-chapter-arrow {
    display: inline-block;
    margin-right: var(--spacing-xs);
    color: var(--text-primary);
}

.brainstorm-chapter-arrow {
    display: none;
    font-size: 1rem;
    line-height: 1;
}

.brainstorm-chapter-content {
    margin-top: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: normal;
    min-height: 100px;
}

/* Structured render (summary / weak-points / what-next); loading & errors stay plain text */
.brainstorm-chapter-content--summary .brainstorm-prose,
.brainstorm-chapter-content--weak-points .brainstorm-prose,
.brainstorm-chapter-content--what-next .brainstorm-prose {
    margin: 0 0 var(--spacing-sm) 0;
}

.brainstorm-chapter-content--summary .brainstorm-prose:last-child,
.brainstorm-chapter-content--weak-points .brainstorm-prose:last-child,
.brainstorm-chapter-content--what-next .brainstorm-prose:last-child {
    margin-bottom: 0;
}

.brainstorm-chapter-content--summary .brainstorm-prose {
    line-height: 1.65;
}

.brainstorm-bullets {
    margin: 0;
    padding: 0 0 0 1.2em;
    list-style-type: disc;
}

.brainstorm-bullets li {
    margin-bottom: var(--spacing-sm);
    padding-left: var(--spacing-xs);
}

.brainstorm-bullets li:last-child {
    margin-bottom: 0;
}

.brainstorm-bullets + .brainstorm-prose--weak-fallback {
    margin-top: var(--spacing-sm);
}

.brainstorm-steps {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: brainstorm-step;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.brainstorm-steps li {
    counter-increment: brainstorm-step;
    position: relative;
    padding-left: 2.35rem;
    margin: 0;
    line-height: 1.55;
}

.brainstorm-steps li::before {
    content: counter(brainstorm-step) ".";
    position: absolute;
    left: 0;
    top: 0;
    width: 1.85rem;
    font-weight: 600;
    font-size: 0.88em;
    color: var(--accent);
    text-align: right;
    line-height: inherit;
}

.brainstorm-chapter-content.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-style: italic;
    min-height: 100px;
}

.brainstorm-chapter-content.empty {
    display: none;
}

.brainstorm-column-chevron {
    display: none;
    margin-left: auto;
    flex-shrink: 0;
    color: var(--text-secondary);
    line-height: 0;
}

.brainstorm-column-chevron svg {
    display: block;
}

@media (max-width: 1199px) {
    .brainstorm-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        min-height: 100%;
        border-radius: 0;
    }

    .brainstorm-content .modal-header {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .brainstorm-body {
        padding: 0;
        min-height: 0;
        max-height: none;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .brainstorm-columns {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: auto;
        border: none;
        border-radius: 0;
        border-top: 1px solid var(--border-color);
    }

    .brainstorm-column {
        min-height: 0;
        padding: 0;
        background-color: var(--bg-primary);
    }

    .brainstorm-column:not(:last-child) {
        border-right: none;
    }

    .brainstorm-column:not(.is-open) {
        flex: 0 0 auto;
    }

    .brainstorm-column.is-open {
        flex: 1 1 auto;
        min-height: 0;
    }

    .brainstorm-column-header {
        margin-bottom: 0;
        padding: 0.7rem 0.85rem;
        border-bottom: 1px solid var(--border-color);
        gap: 0.5rem;
    }

    .brainstorm-column-title {
        white-space: nowrap;
    }

    .brainstorm-column.is-open .brainstorm-column-header {
        background: var(--bg-secondary);
    }

    .brainstorm-column-chevron {
        display: block;
        transform: rotate(-90deg);
    }

    .brainstorm-column.is-open .brainstorm-column-chevron {
        transform: none;
        color: var(--text-primary);
    }

    .brainstorm-column:not(.is-open) .brainstorm-chapter-list {
        display: none;
    }

    .brainstorm-column.is-open .brainstorm-chapter-list {
        padding: 0.5rem 0.85rem;
        min-height: 0;
    }

    .brainstorm-chapter-content {
        padding: var(--spacing-sm);
        min-height: 0;
    }
}

/* Story section — Characters (green) */
#ai-characters-references-btn.ai-tool-btn-characters {
    margin-bottom: var(--spacing-md);
    margin-left: auto;
    margin-right: auto;
    background-color: #83b25e;
    border-color: #83b25e;
}

#ai-characters-references-btn.ai-tool-btn-characters:hover {
    background-color: #739f52;
    border-color: #739f52;
    color: #fff;
}

/* Story section — Mind Map (teal) */
#ai-story-board-btn.ai-tool-btn-mind-map {
    margin-bottom: var(--spacing-md);
    margin-left: auto;
    margin-right: auto;
    background-color: #5bd1bc;
    border-color: #5bd1bc;
}

#ai-story-board-btn.ai-tool-btn-mind-map:hover {
    background-color: #4bc0ab;
    border-color: #4bc0ab;
    color: #fff;
}

/* Voice Actors, Brainstorm, Name Index, Word Finder — classic sidebar blue */
#ai-voice-actions-btn,
#ai-brainstorm-btn,
#story-brainstorm-btn,
#ai-name-ideas-btn,
#ai-word-finder-btn,
#ai-dictionary-btn {
    background-color: #305da4;
    border-color: #305da4;
}

#ai-voice-actions-btn:hover,
#ai-brainstorm-btn:hover,
#story-brainstorm-btn:hover,
#ai-name-ideas-btn:hover,
#ai-word-finder-btn:hover,
#ai-dictionary-btn:hover {
    background-color: #28528f;
    border-color: #28528f;
    color: #fff;
}

#ai-add-people-places-lore-btn {
    margin-bottom: var(--spacing-md);
    margin-left: auto;
    margin-right: auto;
}

#ai-brainstorm-btn,
#story-brainstorm-btn,
#ai-name-ideas-btn,
#ai-word-finder-btn,
#ai-dictionary-btn {
    margin-bottom: var(--spacing-md);
    margin-left: auto;
    margin-right: auto;
}

#ai-brainstorm-btn .ai-tool-icon-cell,
#story-brainstorm-btn .ai-tool-icon-cell,
#ai-name-ideas-btn .ai-tool-icon-cell,
#ai-word-finder-btn .ai-tool-icon-cell,
#ai-dictionary-btn .ai-tool-icon-cell {
    width: 1.15rem;
    height: 1.15rem;
    flex: 0 0 1.15rem;
}

#ai-word-finder-btn,
#ai-dictionary-btn {
    margin-left: auto;
    margin-right: auto;
}

/* Lore Lexicon — purple accent (embed iframe, same action as character modal Fantasy Index). */
#ai-fantasy-index-btn.ai-tool-btn-fantasy-index {
    margin-left: auto;
    margin-right: auto;
    background-color: #7b52c4;
    border-color: #7b52c4;
}

#ai-fantasy-index-btn.ai-tool-btn-fantasy-index:hover {
    background-color: #6a45ad;
    border-color: #6a45ad;
    color: #fff;
}

#ai-fantasy-index-btn .ai-tool-icon-cell i,
#ai-fantasy-index-btn .ai-tool-icon-cell svg {
    font-size: 15px;
    line-height: 1;
    color: #fff;
}

/* Only let the label grow on icon+label buttons; centered buttons stay centered */
.ai-tool-btn:has(.ai-tool-icon-cell) .ai-tool-btn-label,
.ai-tool-btn:has(.ai-tool-icon-cell) .ai-tool-btn-text-multiline {
    flex: 1;
}

/* Write Section - Fixed overlay panel */
.ai-write-section {
    position: fixed;
    top: var(--header-height);
    right: var(--sidebar-width);
    bottom: 0;
    width: 400px;
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-width));
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: var(--spacing-md);
    z-index: 502;
    overflow-y: auto;
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.2);
    display: none;
}

.ai-write-section[style*="display: block"],
.ai-write-section[style*="display:flex"] {
    display: flex !important;
    flex-direction: column;
}

/* Adjust for collapsed sidebar */
.main-layout:has(.sidebar-right.collapsed) .ai-write-section {
    right: var(--sidebar-collapsed-width);
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-collapsed-width));
}

.ai-write-input {
    width: 100%;
    padding: var(--spacing-sm);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.9rem;
    margin-bottom: var(--spacing-sm);
    min-height: 80px;
    resize: vertical;
    flex: 1;
}

.ai-write-actions {
    display: flex;
    gap: var(--spacing-sm);
}

/* Rewrite Controls - Fixed overlay panel */
.ai-rewrite-controls {
    position: fixed;
    top: var(--header-height);
    right: var(--sidebar-width);
    bottom: 0;
    width: 400px;
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-width));
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: var(--spacing-md);
    z-index: 502;
    overflow-y: auto;
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.2);
    display: none;
}

.ai-rewrite-controls[style*="display: block"],
.ai-rewrite-controls[style*="display:flex"] {
    display: flex !important;
    flex-direction: column;
}

.main-layout:has(.sidebar-right.collapsed) .ai-rewrite-controls {
    right: var(--sidebar-collapsed-width);
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-collapsed-width));
}

.rewrite-tone-group {
    margin-bottom: var(--spacing-md);
}

.rewrite-tone-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}

.rewrite-tone-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.rewrite-tone-option {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.rewrite-tone-option input[type="radio"],
.rewrite-tone-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent);
    border-radius: 4px;
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--bg-primary);
    border: 2px solid var(--border-color);
    position: relative;
    flex-shrink: 0;
}

.rewrite-tone-option input[type="checkbox"]:checked {
    background-color: var(--accent);
    border-color: var(--accent);
}

.rewrite-tone-option input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: bold;
}

.rewrite-tone-option label {
    font-size: 0.85rem;
    margin: 0;
    margin-left: var(--spacing-xs);
    cursor: pointer;
    color: var(--text-primary);
}

.rewrite-slider-group {
    margin-bottom: var(--spacing-md);
}

.rewrite-slider-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}

.rewrite-slider {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-primary);
    outline: none;
    -webkit-appearance: none;
    margin: 0 var(--spacing-xs);
}

.rewrite-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
}

.rewrite-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
}

/* Grammar Check - Fixed overlay panel */
.grammar-errors {
    position: fixed;
    top: var(--header-height);
    right: var(--sidebar-width);
    bottom: 0;
    width: 400px;
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-width));
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: var(--spacing-md);
    z-index: 502;
    overflow-y: auto;
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.2);
    display: none;
}

.grammar-errors[style*="display: block"],
.grammar-errors[style*="display:flex"] {
    display: flex !important;
    flex-direction: column;
}

.main-layout:has(.sidebar-right.collapsed) .grammar-errors {
    right: var(--sidebar-collapsed-width);
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-collapsed-width));
}

.grammar-error-item {
    padding: var(--spacing-sm);
    background-color: rgba(211, 47, 47, 0.1);
    border-left: 3px solid var(--error);
    margin-bottom: var(--spacing-sm);
    border-radius: 4px;
}

.grammar-error-text {
    font-size: 0.85rem;
    margin-bottom: var(--spacing-xs);
}

.grammar-error-suggestion {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Analyze Paragraph - Fixed overlay panel */
.analyze-results {
    position: fixed;
    top: var(--header-height);
    right: var(--sidebar-width);
    bottom: 0;
    width: 400px;
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-width));
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: var(--spacing-md);
    z-index: 502;
    overflow-y: auto;
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.2);
    display: none;
}

.analyze-results[style*="display: block"],
.analyze-results[style*="display:flex"] {
    display: flex !important;
    flex-direction: column;
}

.main-layout:has(.sidebar-right.collapsed) .analyze-results {
    right: var(--sidebar-collapsed-width);
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-collapsed-width));
}

.analyze-result-section {
    margin-bottom: var(--spacing-md);
}

.analyze-result-section:last-child {
    margin-bottom: 0;
}

.analyze-result-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
    text-transform: uppercase;
}

.analyze-result-value {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* Loading States */
.ai-loading {
    text-align: center;
    padding: var(--spacing-lg);
    color: var(--text-secondary);
}

.ai-loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* AI Tools Top Section */
.ai-tools-top-section {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: none !important;
    height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
    z-index: 500;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    max-height: calc(100vh - var(--header-height));
    overflow-y: auto;
}

.ai-tools-top-section[style*="display: block"] {
    display: block !important;
    height: auto;
    overflow-y: auto;
    padding: 0;
}

.ai-tool-top-panel {
    width: 100%;
}

.ai-tool-top-control-bar {
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    padding: var(--spacing-sm) var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
}

.ai-tool-control-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    transition: color 0.2s;
    font-family: var(--font-ui);
    border-radius: 0;
    width: auto;
    min-width: 80%;
    text-decoration: none;
}

.ai-tool-control-btn:visited,
.ai-tool-control-btn:active {
    color: var(--text-secondary);
    text-decoration: none;
}

.ai-tool-control-btn:hover {
    background-color: transparent;
    color: var(--text-primary);
}

/* Undo/Redo: clear hook-arrow icons (no circular frame) */
.undo-redo-icon,
.undo-redo-icon-circle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	margin-right: 6px;
	vertical-align: middle;
	flex-shrink: 0;
}

.undo-redo-icon svg,
.undo-redo-icon-circle svg {
	width: 18px;
	height: 18px;
	display: block;
	stroke: currentColor;
	fill: none;
}

.ai-tool-control-title {
    flex: 1;
    text-align: center;
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-primary);
}

.ai-tool-control-apply {
    background-color: var(--accent);
    border: none;
    color: #fff;
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
    transition: background-color 0.2s;
}

.ai-tool-control-apply:hover {
    background-color: var(--accent-hover);
}

.ai-tool-control-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: var(--spacing-xs) var(--spacing-sm);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: color 0.2s;
    margin-left: var(--spacing-sm);
}

.ai-tool-control-close:hover {
    color: var(--text-primary);
}

.ai-tool-top-content {
    padding: var(--spacing-lg);
    max-width: 1200px;
    margin: 0 auto;
}

.ai-write-top-input {
    width: 100%;
    padding: var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 1rem;
    min-height: 120px;
    resize: vertical;
    font-family: var(--font-ui);
    line-height: 1.6;
}

.ai-rewrite-top-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-xl);
    align-items: start;
}

.rewrite-slider-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-sm);
    width: 100%;
}

.rewrite-slider-container .rewrite-slider {
    width: 100%;
    order: 2;
}

.slider-markers {
    display: flex;
    justify-content: space-between;
    width: 100%;
    order: 3;
    margin-top: var(--spacing-xs);
}

.slider-marker {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    flex: 1;
}

@media (max-width: 768px) {
    .ai-rewrite-top-controls {
        grid-template-columns: 1fr;
    }
    
    .rewrite-tone-options {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .rewrite-slider-container {
        flex-wrap: wrap;
    }
}

/* Grammar Check Fixed Left Panel */
.grammar-check-sidebar {
    z-index: 200;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    left: 0;
    top: var(--header-height);
    /* Overlay on top of chapters sidebar */
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
}

.grammar-panel-content {
    padding: var(--spacing-md);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.grammar-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.grammar-panel-header h3 {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--text-primary);
    margin: 0;
}

.grammar-panel-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: var(--spacing-xs) var(--spacing-sm);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: color 0.2s;
}

.grammar-panel-close:hover {
    color: var(--text-primary);
}

.grammar-panel-body {
    flex: 1;
    overflow-y: auto;
}

.grammar-no-errors {
    padding: var(--spacing-md);
    text-align: center;
    color: var(--success);
    font-size: 0.9rem;
}

.grammar-checking {
    padding: var(--spacing-md);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.grammar-errors-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.grammar-errors-count {
    flex: 1;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.grammar-apply-all-btn,
.grammar-dismiss-all-btn {
    font-family: inherit;
    font-size: 0.75rem;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
}

.grammar-apply-all-btn:hover,
.grammar-dismiss-all-btn:hover {
    background: var(--bg-tertiary);
}

.grammar-errors-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.grammar-suggestion-type {
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.grammar-suggestion-message {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    line-height: 1.3;
}

#ai-panel-right[data-panel-type="grammar"] #ai-panel-generate-section {
    display: none;
}

.grammar-suggestion-item {
    padding: 8px 12px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.2s;
    white-space: normal;
}

.grammar-suggestion-item:hover {
    background-color: var(--bg-tertiary);
}

.grammar-suggestion-error {
    font-size: 0.8rem;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.2;
}

.grammar-suggestion-error strong {
    color: var(--error);
    font-weight: 600;
}

.grammar-suggestion-correction {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    line-height: 1.2;
}

.grammar-suggestion-correction strong {
    color: var(--success);
    font-weight: 600;
}

.grammar-suggestion-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.grammar-apply-btn,
.grammar-delete-btn {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.grammar-apply-btn {
    background-color: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.grammar-apply-btn:hover {
    background-color: var(--accent-hover);
}

.grammar-delete-btn {
    background-color: transparent;
    color: var(--text-secondary);
}

.grammar-delete-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Floating panel: review auto-applied grammar/punctuation fixes */
.grammar-review-panel {
    position: fixed;
    right: var(--spacing-md);
    bottom: var(--spacing-md);
    width: min(360px, calc(100vw - 2 * var(--spacing-md)));
    max-height: min(420px, 50vh);
    z-index: 10002;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.grammar-review-panel.is-open {
    display: flex;
}

.grammar-review-panel-inner {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.grammar-review-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.grammar-review-title {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.grammar-review-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.grammar-review-close:hover {
    color: var(--text-primary);
}

.grammar-review-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md) 0;
    border-bottom: 0;
    flex-shrink: 0;
}

.grammar-review-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
}

.grammar-review-nav-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
}

.grammar-review-nav-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.grammar-review-counter {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.grammar-review-body {
    padding: var(--spacing-md);
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.grammar-review-diff {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    font-size: 0.85rem;
    line-height: 1.4;
}

.grammar-review-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: baseline;
}

.grammar-review-label {
    flex: 0 0 auto;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    min-width: 2.25rem;
}

.grammar-review-was {
    color: var(--error);
    word-break: break-word;
}

.grammar-review-now {
    color: var(--success);
    word-break: break-word;
}

.grammar-review-type {
    display: none;
}

.grammar-review-message {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    line-height: 1.3;
}

.grammar-review-actions {
    display: flex;
    gap: 6px;
}

.grammar-review-apply-btn,
.grammar-review-skip-btn,
.grammar-review-apply-all-btn,
.grammar-review-revert-btn,
.grammar-review-revert-all-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
}

.grammar-review-kbd-wrap {
    display: none;
    align-items: center;
    gap: 3px;
}

.grammar-review-kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2em;
    padding: 1px 5px;
    font-size: 0.65rem;
    font-family: inherit;
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: 0;
    text-transform: none;
    border: 1px solid currentColor;
    border-radius: 4px;
    opacity: 0.72;
}

@media (min-width: 900px) {
    .grammar-review-kbd-wrap {
        display: inline-flex;
    }
}

.grammar-review-apply-btn,
.grammar-review-skip-btn {
    flex: 1;
}

.grammar-review-apply-btn {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.grammar-review-apply-all-btn {
    width: 100%;
    margin-top: 8px;
    flex-wrap: wrap;
}

.grammar-review-apply-all-btn[hidden],
.grammar-review-revert-all-btn[hidden] {
    display: none;
}

.grammar-review-apply-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.grammar-review-skip-btn:hover:not(:disabled),
.grammar-review-apply-all-btn:hover:not(:disabled),
.grammar-review-revert-btn:hover:not(:disabled),
.grammar-review-revert-all-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
}

.grammar-review-apply-btn:disabled,
.grammar-review-skip-btn:disabled,
.grammar-review-apply-all-btn:disabled,
.grammar-review-revert-btn:disabled,
.grammar-review-revert-all-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

body.page-write .grammar-review-panel {
    right: calc(var(--sidebar-width, 140px) + 12px);
}

/* Analyze Rating Display */
.analyze-rating-section {
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.analyze-rating-display {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.analyze-rating-value {
    font-size: 2rem;
    font-weight: bold;
    text-align: center;
}

.analyze-rating-bar {
    width: 100%;
    height: 20px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.analyze-rating-bar-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s ease;
}

.analyze-list {
    list-style: none;
    padding-left: 0;
    margin: var(--spacing-sm) 0;
}

.analyze-list li {
    padding: var(--spacing-xs) 0;
    padding-left: var(--spacing-md);
    position: relative;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.analyze-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: bold;
}

/* AI Debug Sidebar - Left Panel */
.sidebar-debug {
    width: 400px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    z-index: 102;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: var(--header-height);
    bottom: 0;
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.3);
}

.ai-debug-sidebar-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.ai-debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background-color: var(--bg-tertiary);
}

.ai-debug-header h4 {
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-primary);
    margin: 0;
}

.ai-debug-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: var(--spacing-xs);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    transition: color 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.ai-debug-close:hover {
    color: var(--text-primary);
    background-color: var(--bg-primary);
}

.ai-debug-close svg {
    width: 18px;
    height: 18px;
    display: block;
}

.ai-debug-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
}

.ai-debug-section {
    margin-bottom: var(--spacing-lg);
}

.ai-debug-section:last-child {
    margin-bottom: 0;
}

.ai-debug-label {
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-debug-text {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: var(--spacing-md);
    font-size: 0.85rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
    margin: 0;
    line-height: 1.6;
    min-height: 120px;
    max-height: 400px;
    width: 100%;
}

/* AI Panel Right Side (new layout) */
.ai-panel-right {
    position: fixed;
    top: var(--header-height);
    right: var(--sidebar-width);
    bottom: 0;
    width: 500px;
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-width));
    background-color: var(--bg-primary);
    border-left: 1px solid var(--border-color);
    z-index: 501;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.2);
    transition: right 0.3s ease, max-width 0.3s ease;
}

/* When sidebar slides away, AI panel slides to edge (fallback CSS) */
.main-layout:has(.sidebar-right.sliding-away) .ai-panel-right {
    right: 0;
    max-width: calc(100vw - var(--sidebar-left-width));
}

.main-layout:has(.sidebar-right.collapsed) .ai-panel-right {
    right: var(--sidebar-collapsed-width);
    max-width: calc(100vw - var(--sidebar-left-width) - var(--sidebar-collapsed-width));
}

.ai-panel-right-header {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.ai-panel-right-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.ai-panel-top-btn {
    background-color: var(--bg-tertiary);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 500;
}

.ai-panel-top-btn:hover {
    background-color: var(--bg-primary);
    border-color: rgba(255, 255, 255, 0.4);
}

.ai-panel-icon {
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

.ai-panel-icon svg {
    width: 12px;
    height: 12px;
    display: block;
}

.ai-panel-icon .ui-info-glyph {
    font-size: 0.7rem;
    font-weight: 600;
}

.ai-panel-main-title {
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-primary);
    text-align: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    padding-bottom: var(--spacing-xs);
    pointer-events: none;
}

.ai-panel-main-title::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 1px;
    background-color: rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

.ai-panel-right-control-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    gap: var(--spacing-sm);
    position: relative;
}

.ai-panel-right-control-bar > .ai-panel-control-btn:first-child {
    flex: 0 0 auto;
}

.ai-panel-right-control-bar > .ai-panel-control-btn:last-child {
    flex: 0 0 auto;
}

.ai-panel-apply-group {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    flex: 0 0 auto;
    margin: 0 auto;
}

#ai-panel-apply-group-rewrite {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
}

/* Hide regenerate button in rewrite panel */
#ai-panel-apply-group-rewrite .ai-panel-regenerate-icon-btn {
    display: none !important;
}

/* Hide Creation Settings button in rewrite panel (it should only appear in write panel) */
/* Hide when apply group is visible OR when panel type is rewrite */
.ai-panel-right-control-bar:has(#ai-panel-apply-group-rewrite:not([style*="display: none"])) .ai-panel-creation-settings-btn,
#ai-panel-right[data-panel-type="rewrite"] .ai-panel-creation-settings-btn {
    display: none !important;
}

.ai-panel-regenerate-icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--bg-primary);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    padding: 0;
    flex-shrink: 0;
}

.ai-panel-regenerate-icon-btn:hover {
    background-color: var(--bg-tertiary);
    border-color: rgba(255, 255, 255, 0.4);
    color: var(--text-primary);
}

.ai-panel-regenerate-icon-btn svg {
    width: 16px;
    height: 16px;
    display: block;
    stroke: currentColor;
    fill: none;
}

.ai-panel-control-group {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex: 1;
}

.ai-panel-right-title-group {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex: 1;
}

.ai-panel-control-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    transition: color 0.2s;
    border-radius: 0;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-family: inherit;
    text-decoration: none;
}

.ai-panel-control-btn:visited,
.ai-panel-control-btn:active {
    color: var(--text-secondary);
    text-decoration: none;
}

.ai-panel-control-btn:hover {
    background-color: transparent;
    color: var(--text-primary);
}

.ai-panel-control-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.ai-panel-title {
    flex: 1;
    text-align: center;
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-primary);
}

.ai-panel-apply-btn {
    justify-self: center;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 120px;
}

.ai-panel-apply-btn:hover {
    background-color: var(--bg-primary);
    border-color: rgba(255, 255, 255, 0.4);
}

.ai-panel-creation-settings-btn {
    background-color: var(--accent);
    border: 2px solid var(--accent);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-family: inherit;
    text-decoration: none;
    flex: 0 0 auto;
}

.ai-panel-creation-settings-btn:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.ai-panel-apply-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ai-panel-close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: var(--spacing-xs) var(--spacing-sm);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: color 0.2s;
    border-radius: 4px;
}

.ai-panel-close-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-primary);
}

.ai-panel-right-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    min-height: 0;
}

.ai-panel-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    flex-shrink: 0;
}

.ai-panel-section-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--spacing-xs);
    width: 100%;
}

.ai-panel-section-title {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    width: 100%;
    display: block;
}

.ai-panel-paragraph-display {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: var(--spacing-md);
    min-height: 100px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.ai-panel-paragraph-placeholder {
    color: var(--text-secondary);
    font-style: italic;
    margin: 0;
}

.ai-panel-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

#ai-panel-instructions-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Instructions: char count (left) + “Write from Beat” (right) above the textarea */
.ai-panel-instructions-toolbar {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-sm);
    flex-shrink: 0;
    margin: 0;
    padding: 0 0 4px;
    min-width: 0;
}

.ai-panel-instructions-toolbar .ai-panel-story-context-slot {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* Write: optional Act → Chapter → Beat (revealed via “Write from Beat”) */
.ai-panel-story-context-slot {
    flex-shrink: 0;
}

.ai-panel-story-context-slot[hidden] {
    display: none !important;
}

.ai-panel-write-from-beat-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin: 0;
    padding: 0;
    min-height: 0;
    line-height: 1;
}

.ai-panel-write-from-beat-btn {
    margin: 0;
    padding: 2px 6px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-ui, inherit);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.25;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-panel-write-from-beat-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.06);
}

body.theme-light .ai-panel-write-from-beat-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.ai-panel-write-from-beat-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.ai-panel-story-context {
    flex-shrink: 0;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    font-size: 11px;
    line-height: 1.35;
    color: var(--text-secondary);
}

.ai-panel-story-context[hidden] {
    display: none !important;
}

.ai-panel-story-context-flow {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 2px 6px;
    min-width: 0;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
}

.ai-panel-story-context-arrow {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    opacity: 0.88;
    user-select: none;
    pointer-events: none;
}

.ai-panel-story-context-arrow-svg {
    display: block;
    vertical-align: middle;
}

.ai-panel-story-context-select {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
    margin: 0;
    padding: 4px 22px;
    font-family: inherit;
    font-size: 11px;
    line-height: 1.35;
    font-weight: 500;
    color: var(--text-primary);
    background-color: transparent;
    border: none;
    border-radius: 2px;
    cursor: pointer;
    text-align: center;
    text-align-last: center;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23948f9e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 11px 11px;
    box-shadow: none;
}

.ai-panel-story-context-select:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

body.theme-light .ai-panel-story-context-select:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.ai-panel-story-context-select--beat {
    flex: 1.1 1 0;
    min-width: 4rem;
}

body.theme-light .ai-panel-story-context-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23787096' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

.ai-panel-story-context-select:focus {
    outline: none;
    box-shadow: none;
    background-color: rgba(255, 255, 255, 0.06);
}

.ai-panel-story-context-select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

body.theme-light .ai-panel-story-context-select:focus {
    background-color: rgba(0, 0, 0, 0.05);
}

.ai-panel-story-context-select::-ms-expand {
    display: none;
}

.ai-panel-input {
    width: 100%;
    padding: var(--spacing-sm);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.9rem;
    min-height: 80px;
    flex: 1;
    height: 100%;
    resize: vertical;
    font-family: inherit;
    box-sizing: border-box;
    overflow-y: auto;
}

.ai-panel-instructions-field {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
}

#ai-panel-instructions-section #ai-panel-instructions {
    flex: 1;
    min-height: 80px;
}

.ai-panel-instructions-counter {
    flex-shrink: 0;
    align-self: center;
    font-family: var(--font-ui, inherit);
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 2px 4px 2px 0;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.ai-panel-instructions-counter--warn {
    color: #ff5252;
    text-shadow:
        0 0 6px rgba(255, 82, 82, 0.95),
        0 0 14px rgba(255, 60, 60, 0.55),
        0 0 22px rgba(255, 40, 40, 0.35);
}

body.theme-light .ai-panel-instructions-counter--warn {
    color: #d32f2f;
    text-shadow:
        0 0 4px rgba(211, 47, 47, 0.45),
        0 0 12px rgba(211, 47, 47, 0.28);
}

#ai-panel-instructions::placeholder {
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.65;
}

body.theme-light #ai-panel-instructions::placeholder {
    color: rgba(0, 0, 0, 0.5);
}

.ai-panel-status-section {
    padding: 0;
    margin: 0;
    background-color: transparent;
    border: none;
}

.ai-panel-status {
    background-color: transparent;
    border: none;
    border-radius: 0;
    padding: var(--spacing-xs) 0;
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.4;
    opacity: 0.6;
}

.ai-panel-status-item {
    margin-bottom: 0;
}

.ai-panel-preview-content {
    width: 100%;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: var(--spacing-md);
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
    font-family: inherit;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.ai-panel-preview-content:focus {
    outline: 1px solid var(--accent);
    outline-offset: -1px;
}

.ai-panel-preview-content[contenteditable="true"] {
    cursor: text;
}

.ai-panel-preview-content[contenteditable="true"]:empty:before {
    content: attr(data-placeholder);
    color: var(--text-secondary);
    opacity: 0.5;
}

.ai-panel-preview-content span.character-mention,
.ai-panel-preview-content span.place-mention {
    /* Dull background applied via inline style in JS */
    padding: 0 2px;
}

.ai-panel-preview-actions {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
}

.btn-block {
    width: 100%;
}

body.page-write #ai-panel-generate-btn.btn-primary {
    background-color: #8e44ad;
    border-color: #8e44ad;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

body.page-write #ai-panel-generate-btn.btn-primary:hover,
body.page-write #ai-panel-generate-btn.btn-primary:focus-visible {
    background-color: #7d3d9a;
    border-color: #7d3d9a;
    color: #fff;
}

.ai-panel-generate-btn-row {
    display: inline-flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    white-space: nowrap;
    line-height: 1;
}

#ai-panel-generate-btn.is-busy .ink-action-cost,
#ai-panel-generate-btn:disabled .ink-action-cost {
    opacity: 0.55;
}

.ai-panel-mobile-back-btn {
    display: none;
}

.ai-panel-top-right {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin-left: auto;
}

body.ink-depleted #ai-panel-generate-btn[data-ink-guarded] {
    opacity: 0.38;
    pointer-events: none;
    filter: grayscale(0.85);
}

/* Write History Styles */
#ai-write-history-section {
    margin-top: var(--spacing-md);
    max-height: 300px;
    overflow-y: auto;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#ai-write-history-section.ai-write-history-visible {
    opacity: 1;
}

.ai-write-history-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.ai-write-history-item {
    padding: var(--spacing-sm);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.6;
}

.ai-write-history-item:hover {
    opacity: 1;
    background-color: var(--bg-tertiary);
    border-color: var(--accent);
}

.ai-write-history-preview {
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.4;
    margin-bottom: var(--spacing-xs);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-write-history-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.ai-write-history-empty {
    padding: var(--spacing-md);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
}

/* Creation Settings Modal */
.creation-settings-modal {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 4000;
}

.creation-settings-modal .modal-header {
    position: relative;
    gap: var(--spacing-md);
    display: flex;
    align-items: center;
}

.creation-settings-modal .modal-header h2 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    font-size: 1.1rem;
    font-weight: 500;
    text-align: center;
    pointer-events: none;
}

/* Info control in modal header must receive clicks (parent h2 has pointer-events: none) */
#creation-settings-modal-info-btn {
    pointer-events: auto;
    cursor: pointer;
    margin-left: 0px;
    flex-shrink: 0;
}

.creation-settings-modal .modal-header #creation-settings-default-btn {
    flex-shrink: 0;
    width: auto;
    min-width: auto !important;
}

.creation-settings-modal .modal-header #character-creation-settings-default-btn,
.creation-settings-modal .modal-header #location-settings-default-btn,
.creation-settings-modal .modal-header #lore-settings-default-btn,
.creation-settings-modal .modal-header #item-settings-default-btn {
    flex-shrink: 0;
    width: auto;
    min-width: auto !important;
    margin-left: auto;
    padding: var(--spacing-sm) var(--spacing-lg);
}


.creation-settings-content {
    max-width: 1000px;
    width: 90%;
    max-height: 90vh;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
}

.modal-back-btn {
    background-color: var(--accent);
    border: 1px solid var(--accent);
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    padding: var(--spacing-sm) var(--spacing-md);
    margin-right: var(--spacing-md);
    transition: all 0.2s;
    border-radius: 4px;
    min-width: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.modal-back-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-back-btn-icon svg {
    width: 1em;
    height: 1em;
    display: block;
}

.modal-title-leading-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.35rem;
    vertical-align: middle;
    color: var(--text-primary);
    flex-shrink: 0;
}

.modal-title-leading-icon svg {
    width: 1.25em;
    height: 1.25em;
    display: block;
}

.modal-close-icon-svg {
    display: block;
}

.modal-back-btn:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.creation-settings-body {
    padding: var(--spacing-xl);
    overflow-y: auto;
    max-height: calc(90vh - 100px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: calc(var(--spacing-xl) * 2);
    align-items: start;
}

.creation-settings-left-column {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-xl) * 1.5);
    grid-column: 1;
    position: relative;
}

/* Keep the left preview region full-height in simplified Creation Settings layout. */
#creation-settings-modal .creation-settings-body {
    align-items: stretch;
    min-height: 420px;
}
#creation-settings-modal .creation-settings-left-column {
    align-self: stretch;
    min-height: 100%;
}

/* Format Settings: left column stretches to match right column height so hover panel is tall enough */
#novel-settings-modal .creation-settings-left-column {
    align-self: stretch;
}
#novel-settings-modal #novel-settings-hover-panel {
    top: 0;
}

/* Format Settings modal: min-height to match Creation Settings modal proportions */
#novel-settings-modal .creation-settings-body {
    min-height: 420px;
}

#ai-assistant-settings-modal .creation-settings-left-column {
    align-self: stretch;
}

#ai-assistant-settings-modal #ai-assistant-settings-hover-panel {
    top: 0;
}

#ai-assistant-settings-modal .creation-settings-body {
    min-height: 420px;
}

#ai-assistant-settings-modal .ai-assistant-settings-voice .ai-assistant-persona-dd,
#ai-assistant-settings-modal .ai-assistant-settings-voice .ai-assistant-persona-blurb {
    display: none;
}

#ai-assistant-settings-modal .ai-assistant-settings-voice .ai-assistant-picks {
    margin: 0;
}

#ai-assistant-settings-modal .creation-settings-rating-btn[data-assistant-persona] {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

#ai-assistant-settings-modal .creation-settings-rating-btn[data-assistant-persona] .ai-assistant-persona-thumb {
    width: 14px;
    height: 14px;
}

#ai-assistant-settings-modal .ai-assistant-settings-details {
    padding: 0.65rem 0.75rem;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.88rem;
    line-height: 1.45;
}

#ai-assistant-settings-modal .ai-assistant-settings-details strong {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.92rem;
}

#ai-assistant-settings-modal .ai-assistant-settings-details p {
    margin: 0;
    color: var(--text-secondary);
}

body.theme-light #ai-assistant-settings-modal .ai-assistant-settings-details {
    background: rgba(0, 0, 0, 0.04);
}

/* Hover info panel over Customize section (left half of Creation Settings modal) */
.creation-settings-hover-panel {
    position: absolute;
    top: 0px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    background-color: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
    border-radius: 8px;
    padding: var(--spacing-lg);
    overflow: auto;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease-out, visibility 0.22s ease-out;
}

.creation-settings-hover-panel.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.creation-settings-hover-panel-inner {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.creation-settings-hover-panel-inner .hover-panel-category {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    border-left: 3px solid var(--accent);
    padding-left: var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
    text-align: left;
}

.creation-settings-hover-panel-inner .hover-panel-option {
    font-weight: 600;
    font-size: 1.05rem;
    font-style: italic;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: var(--spacing-md);
}

.creation-settings-hover-panel-inner .hover-panel-lock-note {
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
    font-size: 0.85rem;
}

.creation-settings-hover-panel-inner .hover-panel-lock-note strong {
    display: block;
    margin-bottom: var(--spacing-xs);
}

.creation-settings-hover-panel-inner .hover-panel-lock-note em {
    font-style: italic;
    color: var(--text-secondary, rgba(255, 255, 255, 0.8));
}

.creation-settings-hover-panel-inner .hover-panel-from,
.creation-settings-hover-panel-inner .hover-panel-to {
    margin-top: var(--spacing-md);
}

.creation-settings-hover-panel-inner .hover-panel-from:first-child,
.creation-settings-hover-panel-inner .hover-panel-to:first-child {
    margin-top: 0;
}

.creation-settings-hover-panel-inner .hover-panel-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary, rgba(255, 255, 255, 0.7));
    margin-bottom: var(--spacing-xs);
}

.creation-settings-hover-panel-inner .hover-panel-block {
    white-space: pre-wrap;
    margin-bottom: var(--spacing-sm);
    border-left: 3px solid var(--accent);
    padding-left: var(--spacing-md);
}

.creation-settings-hover-panel-inner .hover-panel-block:last-child {
    margin-bottom: 0;
}

/* Light theme: Creation Settings hover info panel */
body.theme-light .creation-settings-hover-panel {
    background-color: rgba(255, 255, 255, 0.88);
    border-color: rgba(0, 0, 0, 0.12);
}
body.theme-light .creation-settings-hover-panel-inner {
    color: #303030;
}
body.theme-light .creation-settings-hover-panel-inner .hover-panel-category {
    color: #1e3a5f;
    border-left-color: var(--accent);
}
body.theme-light .creation-settings-hover-panel-inner .hover-panel-option {
    color: #303030;
}
body.theme-light .creation-settings-hover-panel-inner .hover-panel-lock-note {
    border-top-color: rgba(0, 0, 0, 0.12);
}
body.theme-light .creation-settings-hover-panel-inner .hover-panel-lock-note em {
    color: rgba(0, 0, 0, 0.65);
}
body.theme-light .creation-settings-hover-panel-inner .hover-panel-label {
    color: rgba(0, 0, 0, 0.55);
}
body.theme-light .creation-settings-hover-panel-inner .hover-panel-block {
    color: #303030;
    border-left-color: var(--accent);
}

.creation-settings-right-column {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    grid-column: 2;
}

.creation-settings-content-wrapper {
    filter: blur(0);
    pointer-events: auto;
    user-select: auto;
    opacity: 1;
}

/* Mini hover panel for Writing Focus / Story Tone (left column, below Story Tone) */
.creation-settings-focus-tone-hover-panel {
    margin-top: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    min-height: 2.5rem;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.25);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease-out, visibility 0.22s ease-out;
}

.creation-settings-focus-tone-hover-panel.visible {
    opacity: 1;
    visibility: visible;
}

.creation-settings-focus-tone-hover-panel-inner {
    color: var(--text-secondary, rgba(255, 255, 255, 0.85));
}

body.theme-light .creation-settings-focus-tone-hover-panel {
    background-color: rgba(0, 0, 0, 0.06);
    border-left-color: var(--accent);
}

body.theme-light .creation-settings-focus-tone-hover-panel-inner {
    color: rgba(0, 0, 0, 0.7);
}

.creation-settings-footer {
    padding: var(--spacing-lg) var(--spacing-xl);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    background-color: var(--bg-secondary);
}

.creation-settings-apply-btn {
    background-color: #3b82f6;
    border: 1px solid #3b82f6;
    color: white;
    padding: var(--spacing-sm) var(--spacing-xl);
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 100px;
}

.creation-settings-apply-btn:hover {
    background-color: #2563eb;
    border-color: #2563eb;
}

.creation-settings-section {
    margin-bottom: var(--spacing-lg);
}

.creation-settings-section:last-child {
    margin-bottom: 0;
}

/* Hide explicit content slider when age-restricted (under 18) */
body:not(.allow-explicit-content) .creation-settings-explicit-section {
    display: none !important;
}

.creation-settings-section-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.creation-settings-section-title {
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

/* Percentage shown on button only; hide value span in title */
.creation-settings-section-title .creation-settings-slider-value {
    display: none;
}
.creation-settings-slider-value {
    font-weight: normal;
    color: var(--text-secondary);
}

.creation-settings-rating-value {
    font-weight: normal;
    color: var(--text-secondary);
    margin-left: 4px;
}

/* Narrative tense lock button – by value in section title */
.creation-settings-tense-lock-btn {
    margin-left: 6px;
    padding: 2px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.2s ease, background-color 0.2s ease;
}
.creation-settings-tense-lock-btn:hover {
    color: var(--text-primary);
}
.creation-settings-tense-lock-btn .creation-settings-tense-lock-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.creation-settings-tense-lock-btn.creation-settings-tense-lock-highlight {
    animation: creation-settings-tense-lock-flash 0.6s ease;
}
@keyframes creation-settings-tense-lock-flash {
    0%, 100% { color: var(--text-secondary); }
    50% { color: var(--accent); }
}

.creation-settings-min-max {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: auto;
}

.creation-settings-focus-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-lg);
}

.creation-settings-focus-column {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.creation-settings-checkbox-option {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    border-radius: 4px;
    transition: background-color 0.2s;
}

.creation-settings-checkbox-option:hover {
    background-color: var(--bg-tertiary);
}

.creation-settings-checkbox-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent);
    border-radius: 4px;
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--bg-primary);
    border: 2px solid var(--border-color);
    position: relative;
    flex-shrink: 0;
}

.creation-settings-checkbox-option input[type="checkbox"]:checked {
    background-color: var(--accent);
    border-color: var(--accent);
}

.creation-settings-checkbox-option input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: bold;
}

.creation-settings-checkbox-option label {
    font-size: 0.85rem;
    margin: 0;
    cursor: pointer;
    color: var(--text-primary);
    flex: 1;
}

.creation-settings-tone-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-lg);
}

.creation-settings-tone-column {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.creation-settings-slider-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    /* Extend clickable/draggable area from top of thumb to bottom of labels */
    padding: 12px 0;
    margin: -12px 0; /* offset padding so layout stays the same */
    cursor: pointer;
}

.creation-settings-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
    margin-bottom: var(--spacing-sm);
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

.creation-settings-slider:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.creation-settings-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
}

.creation-settings-slider::-moz-range-track {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
}

.creation-settings-slider-markers {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: var(--spacing-xs);
}

.creation-settings-slider-markers span {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s ease;
    padding: 2px 4px;
    border-radius: 3px;
}

.creation-settings-slider-markers span:hover {
    color: var(--accent);
    background-color: rgba(37, 99, 235, 0.1);
}

/* Explicit Content Rating Buttons */
.creation-settings-rating-buttons {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

/* Wrapper for each option (button + optional "default" label) */
.creation-settings-option-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 60px;
    position: relative;
}
.creation-settings-pct-buttons .creation-settings-option-wrap {
    min-width: 0;
    flex: 1 1 0;
}
.creation-settings-option-wrap .creation-settings-rating-btn {
    width: 100%;
}
/* Default option: subtle blue tint on the button + "Default" tooltip (no text label) */
.creation-settings-default-option .creation-settings-rating-btn {
    background-color: rgba(37, 99, 235, 0.05);
}
.creation-settings-default-option .creation-settings-rating-btn.active {
    background-color: var(--accent);
}
body.theme-light .creation-settings-default-option .creation-settings-rating-btn:not(.active) {
    background-color: rgba(37, 99, 168, 0.17);
}
.creation-settings-default-label {
    display: none;
}

/* Percentage toggles (Detail, Story Assistance, Formal): keep all 5 in one row */
.creation-settings-pct-buttons {
    flex-wrap: nowrap;
}
.creation-settings-pct-buttons .creation-settings-rating-btn {
    min-width: 0;
    flex: 1 1 0;
}

.creation-settings-rating-btn {
    flex: 1;
    min-width: 60px;
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--bg-tertiary);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.creation-settings-rating-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.18);
    color: var(--text-primary);
}

.creation-settings-rating-btn.active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.creation-settings-rating-btn.active:hover {
    background-color: #1d4ed8;
    border-color: #1d4ed8;
}

/* Light theme: visible borders on selector/rating buttons (Preferences + Creation Settings) */
body.theme-light .creation-settings-rating-btn {
    border-color: rgba(0, 0, 0, 0.18);
}
body.theme-light .creation-settings-rating-btn:hover {
    border-color: rgba(0, 0, 0, 0.28);
}
body.theme-light .creation-settings-rating-btn.active {
    border-color: var(--accent);
}
body.theme-light .creation-settings-rating-btn.active:hover {
    border-color: #1d4ed8;
}

.creation-settings-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
    margin-top: -5px; /* Center the thumb vertically on the 6px track */
}

.creation-settings-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
    margin-top: -5px; /* Center the thumb vertically on the 6px track */
}

/* AI Panel Creation Settings (inline version for Rewrite panel) */
.ai-panel-creation-settings-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: calc(var(--spacing-xl) * 1.5);
    align-items: start;
}

.ai-panel-creation-settings-container-rewrite {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.ai-panel-creation-settings-left-column {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-xl) * 1.5);
}

.ai-panel-creation-settings-right-column {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-xl) * 1.5);
}

/* Ensure creation settings sections work in panel context */
#ai-panel-creation-settings-section .creation-settings-section {
    margin-bottom: calc(var(--spacing-xl) * 1.5);
}

#ai-panel-creation-settings-section .creation-settings-section:last-child {
    margin-bottom: 0;
}

/* Compact styling for rewrite panel */
#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-section {
    margin-bottom: var(--spacing-md);
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-section:last-child {
    margin-bottom: 0;
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-section-header {
    margin-bottom: var(--spacing-sm);
    gap: var(--spacing-xs);
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-section-title {
    font-size: 0.875rem;
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-slider-group {
    gap: var(--spacing-xs);
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-slider-markers {
    margin-top: var(--spacing-xs);
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-slider-markers span {
    font-size: 0.7rem;
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-min-max {
    font-size: 0.7rem;
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-focus-grid {
    gap: var(--spacing-sm);
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-focus-column {
    gap: var(--spacing-xs);
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-tone-grid {
    gap: var(--spacing-sm);
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-tone-column {
    gap: var(--spacing-xs);
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-checkbox-option {
    padding: var(--spacing-xs);
}

#ai-panel-creation-settings-section .ai-panel-creation-settings-container-rewrite .creation-settings-checkbox-option label {
    font-size: 0.8rem;
}

/* Places/People/Lore Modal */
.places-people-lore-modal {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 3000;
}

.places-people-lore-content {
    max-width: 1200px;
    width: 90%;
    max-height: 95vh;
    min-height: 80vh;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
}

.places-people-lore-content .modal-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.places-people-lore-content .modal-header .modal-back-btn {
    justify-self: start;
    flex-shrink: 0;
}

.places-people-lore-header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
}

.places-people-lore-header-title-info {
    flex-shrink: 0;
    cursor: help;
}

.places-people-lore-header-title-info[hidden] {
    display: none !important;
}

.places-people-lore-header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    justify-self: end;
    min-height: 2.25rem;
    min-width: 0;
    flex-shrink: 0;
}

.places-people-lore-content .modal-header h2 {
    flex: 0 1 auto;
    min-width: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    font-size: 1.1rem;
    font-weight: 500;
    text-align: center;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.places-people-lore-type-nav {
    display: none;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-type-nav,
.places-people-lore-modal.single-ref-mode .places-people-lore-type-nav {
    display: flex;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-content .modal-header h2,
.places-people-lore-modal.single-ref-mode .places-people-lore-content .modal-header h2 {
    min-width: 7.5rem;
}

.places-people-lore-type-nav svg {
    width: 16px;
    height: 16px;
    display: block;
    flex-shrink: 0;
}

.places-people-lore-type-nav:hover,
.places-people-lore-type-nav:focus-visible {
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--accent);
}

body.theme-light .places-people-lore-type-nav:hover,
body.theme-light .places-people-lore-type-nav:focus-visible {
    border-color: rgba(48, 48, 48, 0.2);
    background-color: rgba(48, 48, 48, 0.06);
}

.places-people-lore-header-add-label-short {
    display: none;
}

.places-people-lore-header-char-actions {
    display: none;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-header-char-actions {
    display: flex;
}

.places-people-lore-header-new-character-btn {
    white-space: nowrap;
}

@media (max-width: 768px) {
    .places-people-lore-content .modal-header,
    .add-person-place-lore-modal .modal-header {
        padding: var(--spacing-md) var(--spacing-sm);
    }

    .places-people-lore-header-center {
        gap: 4px;
    }

    .places-people-lore-type-nav {
        width: 28px;
        height: 28px;
    }

    .places-people-lore-content .modal-header h2 {
        font-size: 1rem;
    }

    .places-people-lore-header-new-entity-btn svg,
    .places-people-lore-header-new-character-btn svg {
        display: none;
    }

    .places-people-lore-header-new-entity-btn .places-people-lore-header-add-label-full,
    .places-people-lore-header-new-character-btn .places-people-lore-header-add-label-full {
        display: none;
    }

    .places-people-lore-header-new-entity-btn .places-people-lore-header-add-label-short,
    .places-people-lore-header-new-character-btn .places-people-lore-header-add-label-short {
        display: inline;
    }

    .places-people-lore-header-new-entity-btn,
    .places-people-lore-header-new-character-btn {
        padding: 0.45rem 0.7rem !important;
    }

    .places-people-lore-header-entity-actions,
    .places-people-lore-header-char-actions {
        flex-wrap: nowrap;
    }

    .add-person-place-lore-modal .modal-header h2 svg {
        display: none;
    }
}

.places-people-lore-header-char-actions .places-people-lore-add-btn,
.places-people-lore-header-entity-actions .places-people-lore-add-btn {
    flex: 0 0 auto !important;
}

.places-people-lore-body {
    padding: var(--spacing-lg);
    overflow-y: auto;
    flex: 1;
    min-height: calc(80vh - 100px);
    max-height: calc(95vh - 100px);
    display: flex;
    flex-direction: column;
}

.places-people-lore-columns {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    flex: 1;
    min-height: calc(80vh - 150px);
    overflow: visible;
}

.places-people-lore-column {
    display: flex;
    flex-direction: column;
    padding: 0 var(--spacing-md);
    min-height: 100%;
    overflow: visible;
}

.places-people-lore-column:not(:last-child) {
    border-right: 1px solid var(--border-color);
}

.places-people-lore-header-entity-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.places-people-lore-header-entity-actions[hidden] {
    display: none;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-columns {
    grid-template-columns: 1fr;
    border-right: none;
    border-left: none;
    min-height: auto;
    flex: 1 1 auto;
    align-content: start;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-column:not(:last-child) {
    border-right: none;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-column {
    padding: 0;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-column-header {
    display: none;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-content {
    max-width: 980px;
    width: min(980px, 96vw);
    min-height: 72vh;
    padding: 0;
    background: #0a0a0c;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.places-people-lore-modal.single-ref-mode .places-people-lore-body {
    background: transparent;
    color: #f4f4f5;
    padding: var(--spacing-lg) var(--spacing-xl);
}

.places-people-lore-modal.single-ref-mode .modal-header {
    background: transparent;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.places-people-lore-modal.single-ref-mode .modal-header h2 {
    color: #fafafa;
    font-weight: 600;
    font-size: 1.15rem;
    letter-spacing: 0.02em;
}

.places-people-lore-modal.single-ref-mode #places-people-lore-back-btn {
    background: #7c3aed !important;
    border-color: #7c3aed !important;
    color: #fff !important;
    border-radius: 8px !important;
    padding: 0.45rem 0.85rem !important;
    font-weight: 600;
    z-index: 2;
}

.places-people-lore-modal.single-ref-mode #places-people-lore-back-btn:hover {
    filter: brightness(1.08);
}

.places-people-lore-modal.single-ref-mode .places-people-lore-header-new-entity-btn {
    background: #7c3aed !important;
    border-color: #7c3aed !important;
    border-radius: 8px !important;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    padding: 4px 0 12px;
    align-content: start;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-list .characters-modal-tier-empty {
    grid-column: 1 / -1;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-item-card {
    background: #1e1e22 !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 10px !important;
    text-align: left;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-item-card .places-people-lore-item-name {
    color: #fafafa !important;
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.3;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-item-card-keyinfo {
    font-size: 0.78rem;
    color: rgba(244, 244, 245, 0.55);
    line-height: 1.4;
    margin-top: 5px;
    text-align: left;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-character-portrait {
    width: 52px;
    height: 52px;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-suggestions-bottom-header {
    color: rgba(244, 244, 245, 0.55);
}

.places-people-lore-modal.single-ref-mode .places-people-lore-suggestion-chip {
    background: #1e1e22;
    border-color: rgba(255, 255, 255, 0.12);
    color: #f4f4f5;
}

body.theme-light .places-people-lore-modal.single-ref-mode .places-people-lore-content {
    background: #fff;
    border-color: var(--border-color);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12);
}

body.theme-light .places-people-lore-modal.single-ref-mode .places-people-lore-body,
body.theme-light .places-people-lore-modal.single-ref-mode .modal-header h2 {
    color: var(--text-primary);
}

body.theme-light .places-people-lore-modal.single-ref-mode .places-people-lore-item-card {
    background: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

body.theme-light .places-people-lore-modal.single-ref-mode .places-people-lore-item-card .places-people-lore-item-name {
    color: var(--text-primary) !important;
}

body.theme-light .places-people-lore-modal.single-ref-mode .places-people-lore-item-card-keyinfo {
    color: var(--text-secondary);
}

body.theme-light .places-people-lore-modal.single-ref-mode .places-people-lore-character-portrait {
    border-color: var(--border-color);
}

.places-people-lore-modal.characters-only-mode .places-people-lore-columns {
    grid-template-columns: 1fr;
    border-right: none;
    border-left: none;
    min-height: auto;
    flex: 1 1 auto;
    align-content: start;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-column {
    padding: 0;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-column:not(:last-child) {
    border-right: none;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-column-header {
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.places-people-lore-modal.characters-only-mode .places-people-lore-column:first-child .places-people-lore-column-header {
    display: none;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-column .places-people-lore-add-btn {
    max-width: 220px;
    flex: 0 0 auto !important;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-list--person-flat {
    display: none !important;
}

.places-people-lore-modal:not(.characters-only-mode) #characters-modal-tiered-layout {
    display: none !important;
}

.places-people-lore-person-column-inner {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

/* Write: Characters-only modal — dark shell, tier rows, horizontal scroll */
.places-people-lore-modal-snow-surface {
    position: relative;
    overflow: hidden;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-content {
    max-width: 980px;
    width: min(980px, 96vw);
    min-height: 72vh;
    /* Flush with card edges: override global .modal-content padding so header isn’t inset */
    padding: 0;
    background: #0a0a0c;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.places-people-lore-modal.characters-only-mode .places-people-lore-body {
    background: transparent;
    color: #f4f4f5;
    padding: var(--spacing-lg) var(--spacing-xl);
}

.places-people-lore-modal.characters-only-mode .modal-header {
    background: transparent;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.places-people-lore-modal.characters-only-mode .modal-header h2 {
    color: #fafafa;
    font-weight: 600;
    font-size: 1.15rem;
    letter-spacing: 0.02em;
}

.places-people-lore-modal.characters-only-mode #places-people-lore-back-btn {
    background: #7c3aed !important;
    border-color: #7c3aed !important;
    color: #fff !important;
    border-radius: 8px !important;
    padding: 0.45rem 0.85rem !important;
    font-weight: 600;
    z-index: 2;
}

.places-people-lore-modal.characters-only-mode #places-people-lore-back-btn:hover {
    filter: brightness(1.08);
}

.places-people-lore-modal.characters-only-mode .places-people-lore-header-new-character-btn {
    background: #7c3aed !important;
    border-color: #7c3aed !important;
    border-radius: 8px !important;
}


.characters-modal-tiered-layout {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
    align-items: stretch;
    text-align: center;
    flex: 1;
    min-height: 0;
}

.characters-modal-tier-spinner {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    padding: 0.75rem 0 0.35rem;
}

.characters-modal-tier-spinner-icon {
    display: block;
    width: 22px;
    height: 22px;
    border: 2px solid rgba(124, 92, 250, 0.22);
    border-top-color: rgba(124, 92, 250, 0.85);
    border-radius: 50%;
    box-sizing: border-box;
    animation: ai-rewrite-spin 0.7s linear infinite;
}

body.theme-light .characters-modal-tier-spinner-icon {
    border-color: rgba(48, 48, 48, 0.14);
    border-top-color: rgba(48, 48, 48, 0.55);
}

.characters-modal-tier {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
}

.characters-modal-tier-head {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: var(--spacing-md);
    width: 100%;
    max-width: min(920px, 100%);
    margin: 0 auto 2px;
    text-align: center;
    user-select: none;
    -webkit-user-select: none;
}

.characters-modal-tier-head-text {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    justify-self: center;
    align-self: center;
}

.characters-modal-tier-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: #fafafa;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    user-select: none;
    -webkit-user-select: none;
}

.characters-modal-tier-sub {
    margin: 0.15rem 0 0;
    font-size: 0.8rem;
    font-style: italic;
    color: rgba(244, 244, 245, 0.45);
    user-select: none;
    -webkit-user-select: none;
}

.characters-modal-tier-add-btn {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.65rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    color: rgba(244, 244, 245, 0.88);
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.characters-modal-tier-add-btn:hover,
.characters-modal-tier-add-btn:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.22);
    color: #fafafa;
}

.characters-modal-tier-add-btn svg {
    flex-shrink: 0;
    opacity: 0.9;
}

.characters-modal-tier-scroll {
    width: 100%;
    max-width: min(920px, 100%);
    margin: 0 auto;
    overflow-x: visible;
    overflow-y: visible;
    padding-bottom: 0;
}

.characters-modal-tier-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-flow: row;
    gap: 12px 14px;
    width: 100%;
    margin: 0 auto;
    min-height: 0;
    align-items: stretch;
}

.characters-modal-tier-grid > .places-people-lore-item-card {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Single character in a tier: span both columns and center */
.characters-modal-tier-grid > .places-people-lore-item-card:only-child {
    grid-column: 1 / -1;
    justify-self: center;
    max-width: min(300px, 100%);
    width: 100%;
}

.characters-modal-tier-empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 1.25rem 0.5rem;
    color: rgba(244, 244, 245, 0.38);
    user-select: none;
    -webkit-user-select: none;
    font-size: 0.82rem;
    font-style: italic;
    text-align: center;
}

.characters-modal-tier-grid > .places-people-lore-item-card.is-tier-collapsed-hidden {
    display: none;
}

.encyclopedia-tier-show-more {
    display: flex;
    justify-content: center;
    margin: 6px 0 0;
}

.encyclopedia-tier-show-more[hidden] {
    display: none;
}

.encyclopedia-tier-show-more-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: transparent;
    border: none;
    color: rgba(244, 244, 245, 0.62);
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
}

.encyclopedia-tier-show-more-btn:hover,
.encyclopedia-tier-show-more-btn:focus-visible {
    color: #fafafa;
}

body.theme-light .encyclopedia-tier-show-more-btn {
    color: var(--text-secondary);
}

body.theme-light .encyclopedia-tier-show-more-btn:hover,
body.theme-light .encyclopedia-tier-show-more-btn:focus-visible {
    color: var(--text-primary);
}

.places-people-lore-modal.places-only-mode #places-people-lore-location-list,
.places-people-lore-modal.lore-only-mode #places-people-lore-lore-list,
.places-people-lore-modal.items-only-mode #places-people-lore-item-list {
    display: none !important;
}

.places-people-lore-modal:not(.places-only-mode) #places-modal-tiered-layout,
.places-people-lore-modal:not(.lore-only-mode) #lore-modal-tiered-layout,
.places-people-lore-modal:not(.items-only-mode) #items-modal-tiered-layout {
    display: none !important;
}

.places-people-lore-modal.places-only-mode #places-modal-tiered-layout,
.places-people-lore-modal.lore-only-mode #lore-modal-tiered-layout,
.places-people-lore-modal.items-only-mode #items-modal-tiered-layout {
    display: flex;
}

.places-people-lore-header-lore-actions {
    display: none;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.places-people-lore-modal.lore-only-mode .places-people-lore-header-lore-actions {
    display: flex;
}

.places-people-lore-header-rename-lore-btn,
.places-people-lore-header-publish-lore-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
}

.places-people-lore-header-rename-lore-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #f4f4f5;
}

.places-people-lore-header-rename-lore-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.places-people-lore-header-publish-lore-btn {
    background: #7c3aed;
    border: 1px solid #7c3aed;
    color: #fff;
}

.places-people-lore-header-publish-lore-btn:hover {
    filter: brightness(1.08);
}

body.theme-light .places-people-lore-header-rename-lore-btn {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.places-people-lore-header-lore-actions[hidden] {
    display: none !important;
}

.places-people-lore-modal.lore-only-mode .places-people-lore-header-lore-actions:not([hidden]) {
    display: flex;
}

.places-people-lore-modal.single-ref-mode .places-people-lore-item-card[data-place-id],
.places-people-lore-modal.single-ref-mode .places-people-lore-item-card[data-lore-id],
.places-people-lore-modal.single-ref-mode .places-people-lore-item-card[data-item-id] {
    cursor: grab;
}

.encyclopedia-publish-modal {
    z-index: 4200;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
}

.encyclopedia-publish-dialog {
    width: min(520px, 94vw);
    max-height: 82vh;
    overflow: auto;
    background: #141418;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 1.1rem 1.15rem 1rem;
    color: #f4f4f5;
}

.encyclopedia-publish-dialog h3 {
    margin: 0 0 0.4rem;
    font-size: 1.05rem;
}

.encyclopedia-publish-dialog > p {
    margin: 0 0 0.85rem;
    font-size: 0.82rem;
    color: rgba(244, 244, 245, 0.62);
    line-height: 1.4;
}

.encyclopedia-publish-group {
    margin-bottom: 0.75rem;
}

.encyclopedia-publish-group h4 {
    margin: 0 0 0.35rem;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(244, 244, 245, 0.5);
}

.encyclopedia-publish-empty {
    margin: 0;
    font-size: 0.8rem;
    font-style: italic;
    color: rgba(244, 244, 245, 0.38);
}

.encyclopedia-publish-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0;
    cursor: pointer;
    font-size: 0.88rem;
}

.encyclopedia-publish-name {
    flex: 1;
    min-width: 0;
}

.encyclopedia-publish-badge {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #c4b5fd;
    border: 1px solid rgba(124, 58, 237, 0.45);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}

.encyclopedia-publish-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 0.85rem;
}

.app-prompt-input {
    width: 100%;
    box-sizing: border-box;
    margin: 0.15rem 0 0.35rem;
    padding: 0.5rem 0.65rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: inherit;
    font: inherit;
    border-radius: 6px;
}

.app-prompt-hint {
    margin: 0 0 0.85rem;
    font-size: 0.75rem;
    line-height: 1.35;
    color: var(--text-secondary);
}

.places-people-lore-modal.characters-only-mode .characters-modal-tier-grid.drag-over,
.places-people-lore-modal.single-ref-mode .characters-modal-tier-grid.drag-over {
    outline: 2px dashed rgba(129, 140, 248, 0.75);
    outline-offset: 4px;
    border-radius: 8px;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-item-card[data-character-id] {
    cursor: grab;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-item-card.character-tier-card-dragging {
    opacity: 0.55;
    cursor: grabbing;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-item-card[data-character-id]:active {
    cursor: grabbing;
}

@media (max-width: 720px) {
    .characters-modal-tier-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 440px) {
    .characters-modal-tier-grid {
        grid-template-columns: 1fr;
    }

    .places-people-lore-modal.characters-only-mode .places-people-lore-content {
        width: min(100%, 96vw);
    }
}

.places-people-lore-modal.characters-only-mode .characters-modal-tiered-layout.drag-over {
    outline: 2px dashed rgba(129, 140, 248, 0.75);
    outline-offset: 6px;
    border-radius: 12px;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-suggestions-bottom {
    display: none !important;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-suggestions-bottom-header {
    color: rgba(244, 244, 245, 0.55);
}

.places-people-lore-modal.characters-only-mode .places-people-lore-suggestion-chip {
    background: #1e1e22;
    border-color: rgba(255, 255, 255, 0.12);
    color: #f4f4f5;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-item-card {
    background: #1e1e22 !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 10px !important;
    text-align: left;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-item-card .places-people-lore-item-name {
    color: #fafafa !important;
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.3;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-item-card-keyinfo {
    font-size: 0.78rem;
    color: rgba(244, 244, 245, 0.55);
    line-height: 1.4;
    margin-top: 5px;
    text-align: left;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-character-portrait {
    width: 52px;
    height: 52px;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-character-portrait img {
    object-fit: cover;
    object-position: 50% -15%;
    display: block;
    scale: 2;
}

/* Characters modal: light theme (shell was dark-only; match body.theme-light) */
body.theme-light .places-people-lore-modal.characters-only-mode {
    background-color: rgba(15, 23, 42, 0.28);
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.12);
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-body {
    color: var(--text-primary);
}

body.theme-light .places-people-lore-modal.characters-only-mode .modal-header {
    border-bottom: 1px solid var(--border-color);
}

body.theme-light .places-people-lore-modal.characters-only-mode .modal-header h2 {
    color: var(--text-primary);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tiered-layout.drag-over {
    outline-color: var(--accent);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier-title,
body.theme-light .places-people-lore-modal.single-ref-mode .characters-modal-tier-title {
    color: var(--text-primary);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier-sub,
body.theme-light .places-people-lore-modal.single-ref-mode .characters-modal-tier-sub {
    color: var(--text-secondary);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier-add-btn,
body.theme-light .places-people-lore-modal.single-ref-mode .characters-modal-tier-add-btn {
    border-color: rgba(48, 48, 48, 0.14);
    background: rgba(48, 48, 48, 0.04);
    color: var(--text-primary);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier-add-btn:hover,
body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier-add-btn:focus-visible,
body.theme-light .places-people-lore-modal.single-ref-mode .characters-modal-tier-add-btn:hover,
body.theme-light .places-people-lore-modal.single-ref-mode .characters-modal-tier-add-btn:focus-visible {
    background: rgba(48, 48, 48, 0.08);
    border-color: rgba(48, 48, 48, 0.22);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier-empty,
body.theme-light .places-people-lore-modal.single-ref-mode .characters-modal-tier-empty {
    color: var(--text-secondary);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier-grid.drag-over {
    outline-color: var(--accent);
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-suggestions-bottom {
    border-top-color: var(--border-color);
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-suggestions-bottom-header {
    color: var(--text-secondary);
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-suggestion-chip {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-item-card {
    background: var(--bg-primary) !important;
    border: 1px solid var(--border-color) !important;
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-item-card .places-people-lore-item-name {
    color: var(--text-primary) !important;
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-item-card-keyinfo {
    color: var(--text-secondary);
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-character-portrait {
    border-color: var(--border-color);
}

.places-people-lore-column-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.places-people-lore-info-icon {
    cursor: help !important;
    width: 16px !important;
    height: 16px !important;
    min-width: 16px !important;
    min-height: 16px !important;
    font-size: 0.7rem !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: 1px solid var(--accent) !important;
    border-radius: 50% !important;
    background: transparent !important;
    color: var(--accent) !important;
    flex-shrink: 0 !important;
    line-height: 1 !important;
    opacity: 0.85 !important;
    transition: opacity 0.2s, background 0.2s, color 0.2s !important;
    box-sizing: border-box !important;
}

.places-people-lore-info-icon:hover {
    opacity: 1 !important;
    background: var(--accent) !important;
    color: var(--bg-primary, #fff) !important;
}

.places-people-lore-info-icon .ui-info-glyph {
    font-size: 1em !important;
    font-weight: 600 !important;
}

.places-people-lore-add-btn {
    background-color: var(--accent) !important;
    border: 1px solid var(--accent) !important;
    color: #fff !important;
    padding: var(--spacing-sm) var(--spacing-md) !important;
    border-radius: 4px !important;
    font-size: 0.85rem !important;
    cursor: pointer !important;
    transition: all 0.2s !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: var(--spacing-xs) !important;
    flex: 1 !important;
    min-height: 32px !important;
    text-align: center !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    font-family: inherit !important;
    outline: none !important;
}

.places-people-lore-add-btn:hover {
    background-color: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
    color: #fff !important;
}

.places-people-lore-add-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.places-people-lore-add-icon {
    font-size: 1rem;
    font-weight: bold;
}

.places-people-lore-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    min-height: 200px;
    flex: 1;
    overflow-y: auto;
    overflow-x: visible;
    padding-top: var(--spacing-xs);
    position: relative;
}

.places-people-lore-item {
    background-color: var(--bg-primary) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    padding: var(--spacing-sm) var(--spacing-md) !important;
    border-radius: 6px !important;
    display: flex !important;
    align-items: center !important;
    gap: var(--spacing-sm) !important;
    transition: all 0.2s !important;
    cursor: default !important;
}

.places-people-lore-item-main {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.places-people-lore-item-meta {
    font-size: 0.76rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.places-people-lore-item-details {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.places-people-lore-detail-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.72rem;
    line-height: 1.2;
    white-space: nowrap;
}

.places-people-lore-item-card {
    align-items: flex-start !important;
    padding: var(--spacing-md) !important;
    cursor: pointer !important;
}

.places-people-lore-character-portrait {
    position: relative;
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.places-people-lore-character-portrait.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.places-people-lore-character-portrait.is-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    box-sizing: border-box;
    animation: ai-rewrite-spin 0.7s linear infinite;
    z-index: 1;
}

.places-people-lore-character-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 26%;
    display: block;
}

.places-people-lore-entity-image img {
    object-position: 50% 50%;
}

.places-people-lore-item-card.is-opening {
    opacity: 0.72;
}

.places-people-lore-item-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.places-people-lore-item-card-top-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--spacing-sm);
}

.places-people-lore-item-card-tools {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    flex-shrink: 0;
}

.places-people-lore-item-card .places-people-lore-item-main {
    flex: 1;
    min-width: 0;
}

.places-people-lore-item-card .places-people-lore-item-name {
    cursor: inherit !important;
    padding: 0 !important;
}

.places-people-lore-item-card .places-people-lore-item-name:hover {
    color: var(--text-primary) !important;
}

.places-people-lore-item--character:not(.places-people-lore-item-card) .places-people-lore-item-name:hover {
    color: var(--text-primary) !important;
}

.places-people-lore-item-card .places-people-lore-color-picker-wrapper {
    margin-top: 0;
}

.places-people-lore-item-card .places-people-lore-color-btn {
    width: 28px !important;
    height: 28px !important;
}

.places-people-lore-item-card .places-people-lore-item-delete {
    margin-left: 0 !important;
    border-left: none !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px !important;
    align-self: flex-start;
}

.places-people-lore-item-card:focus {
    outline: none;
}

.places-people-lore-item-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.places-people-lore-item--character:not(.places-people-lore-item-card) {
    cursor: pointer !important;
}

.places-people-lore-item:hover {
    background-color: var(--bg-tertiary) !important;
    border-color: var(--border-color) !important;
}

/* Suggestions row at bottom — off. Harvest scan is also disabled. */
.places-people-lore-suggestions-bottom {
    display: none !important;
    margin-top: var(--spacing-sm);
    padding-top: var(--spacing-sm);
    border-top: 1px solid var(--border-color);
    width: 100%;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-suggestions-bottom {
    margin-top: auto;
}
.places-people-lore-suggestions-bottom-header {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.02em;
}
.places-people-lore-suggestions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    max-height: 7.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 2px;
    scrollbar-width: thin;
}
.places-people-lore-suggestions-empty {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
}
.places-people-lore-suggestion-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 999px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    cursor: grab;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    user-select: none;
    max-width: 100%;
}
.places-people-lore-suggestion-chip:hover {
    background-color: var(--bg-secondary);
    border-color: var(--accent);
}
.places-people-lore-suggestion-chip.dragging {
    opacity: 0.5;
    cursor: grabbing;
}
.places-people-lore-suggestion-chip-name {
    font-size: 0.72rem;
    line-height: 1.25;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 14rem;
}
.places-people-lore-suggestion-chip-ignore {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}
.places-people-lore-suggestion-chip-ignore:hover {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.places-people-lore-suggestion-chip-ignore svg {
    width: 12px;
    height: 12px;
    display: block;
    flex-shrink: 0;
}
.places-people-lore-list.drag-over {
    background-color: var(--bg-tertiary);
    border: 2px dashed var(--accent);
}

/* Delete button confirmation state */
.places-people-lore-item-delete.delete-confirming {
    background-color: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
}

/* Undo toast stack (bottom-right, multiple toasts stack upward) */
.undo-toast-stack {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10001;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
    max-width: min(420px, calc(100vw - 2rem));
}

.undo-toast-stack .undo-toast {
    pointer-events: auto;
    min-width: 200px;
}

/* Undo toast */
.undo-toast {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: var(--spacing-sm) var(--spacing-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.9rem;
    color: var(--text-primary);
    animation: slideInUp 0.3s ease-out;
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.undo-toast-btn {
    background-color: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.undo-toast-btn:hover {
    background-color: var(--accent-hover, var(--accent));
    opacity: 0.9;
}

.grammar-suggest-toast {
    flex-wrap: wrap;
    align-items: center;
    max-width: min(420px, calc(100vw - 2rem));
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.grammar-suggest-kind {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 3px 8px;
    color: #fff;
    background: var(--accent);
    border-radius: 999px;
}

.grammar-suggest-toast--tense .grammar-suggest-kind {
    background: var(--color-core);
}

.grammar-suggest-toast--perspective .grammar-suggest-kind {
    background: var(--color-supporting-b);
}

.grammar-suggest-toast--grammar .grammar-suggest-kind {
    background: var(--warning);
    color: #303030;
}

.grammar-suggest-toast--punctuation .grammar-suggest-kind,
.grammar-suggest-toast--spelling .grammar-suggest-kind {
    background: var(--color-supporting-a);
}

.grammar-suggest-text {
    flex: 1 1 140px;
    min-width: 0;
    line-height: 1.3;
}

.grammar-suggest-toast .undo-toast-btn,
.grammar-suggest-dismiss {
    border-radius: 999px;
    padding: 5px 14px;
    line-height: 1.2;
}

.grammar-suggest-dismiss {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}

.grammar-suggest-dismiss:hover {
    background: var(--bg-primary);
}

/* Custom Color Picker */
.places-people-lore-color-picker-wrapper {
    position: relative !important;
    flex-shrink: 0 !important;
}

.places-people-lore-color-btn {
    width: 24px !important;
    height: 24px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    padding: 0 !important;
    background-color: var(--bg-primary) !important;
    flex-shrink: 0 !important;
    transition: all 0.2s !important;
}

.places-people-lore-color-btn:hover {
    border-color: var(--accent) !important;
    transform: scale(1.1) !important;
}

.places-people-lore-color-picker {
    position: fixed !important;
    background-color: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    padding: var(--spacing-sm) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    z-index: 10000 !important;
    width: 180px !important;
    max-height: none !important;
    overflow: visible !important;
}

.places-people-lore-color-presets {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 6px !important;
}

.places-people-lore-color-preset {
    width: 32px !important;
    height: 32px !important;
    border: 2px solid var(--border-color) !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    padding: 0 !important;
    transition: all 0.2s !important;
    flex-shrink: 0 !important;
}

.places-people-lore-color-preset:hover {
    border-color: var(--accent) !important;
    transform: scale(1.1) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
}

.places-people-lore-color-custom {
    margin-top: var(--spacing-sm) !important;
    padding-top: var(--spacing-sm) !important;
    border-top: 1px solid var(--border-color) !important;
    padding-bottom: var(--spacing-xs) !important;
}

.places-people-lore-color-custom-label {
    display: block !important;
    font-size: 0.75rem !important;
    color: var(--text-secondary) !important;
    margin-bottom: var(--spacing-xs) !important;
    font-weight: 500 !important;
}

.places-people-lore-color-custom-wrapper {
    display: flex !important;
    gap: var(--spacing-xs) !important;
    align-items: center !important;
}

.places-people-lore-color-custom-input {
    width: 40px !important;
    height: 35px !important;
    border: 2px solid var(--border-color) !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    padding: 0 !important;
    background: none !important;
    flex-shrink: 0 !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
}

.places-people-lore-color-custom-input::-webkit-color-swatch-wrapper {
    padding: 0 !important;
}

.places-people-lore-color-custom-input::-webkit-color-swatch {
    border: none !important;
    border-radius: 4px !important;
}

.places-people-lore-color-custom-input::-moz-color-swatch {
    border: none !important;
    border-radius: 4px !important;
}

.places-people-lore-color-custom-input:hover {
    border-color: var(--accent) !important;
}

.places-people-lore-color-custom-text {
    width: 100px !important;
    background-color: var(--bg-tertiary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px !important;
    color: var(--text-primary) !important;
    padding: var(--spacing-xs) var(--spacing-sm) !important;
    font-size: 0.85rem !important;
    font-family: monospace !important;
    transition: border-color 0.2s !important;
    flex-shrink: 0 !important;
}

.places-people-lore-color-custom-text:focus {
    outline: none !important;
    border-color: var(--accent) !important;
}

.places-people-lore-color-custom-text::placeholder {
    color: var(--text-secondary) !important;
    opacity: 0.5 !important;
}

/* Legacy color input (hidden) */
.places-people-lore-item-color {
    display: none !important;
}

.places-people-lore-item-name {
    flex: 1 !important;
    font-size: 0.85rem !important;
    color: var(--text-primary) !important;
    cursor: pointer !important;
    padding: var(--spacing-xs) 0 !important;
    transition: color 0.2s !important;
}

.places-people-lore-item-name:hover {
    color: #4a9eff !important;
}

.places-people-lore-item-delete {
    background: transparent !important;
    border: none !important;
    border-left: 1px solid var(--border-color) !important;
    color: var(--text-secondary) !important;
    cursor: pointer !important;
    padding: var(--spacing-xs) var(--spacing-sm) !important;
    margin-left: var(--spacing-sm) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s !important;
    flex-shrink: 0 !important;
    opacity: 0.6 !important;
}

.places-people-lore-item-delete:hover {
    color: var(--error) !important;
    opacity: 1 !important;
    background-color: var(--bg-tertiary) !important;
}

.places-people-lore-item-delete svg {
    width: 16px !important;
    height: 16px !important;
    display: block !important;
}

/* Add Person/Place/Lore Modal */
.add-person-place-lore-modal {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 3000;
}

.add-person-place-lore-content {
    max-width: 1400px;
    width: 95%;
    max-height: 90vh;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Add Person / Location / Lore / Item: dark parchment behind the form */
#character-modal .add-person-place-lore-content,
#lore-modal .add-person-place-lore-content,
#place-modal .add-person-place-lore-content,
#item-modal .add-person-place-lore-content {
    isolation: isolate;
    overflow: hidden;
}

#character-modal[style*="flex"] .add-person-place-lore-content::before,
#lore-modal[style*="flex"] .add-person-place-lore-content::before,
#place-modal[style*="flex"] .add-person-place-lore-content::before,
#item-modal[style*="flex"] .add-person-place-lore-content::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    border-radius: inherit;
    background-image: url('/assets/images/character-modal-mystery-parchment.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.42;
    mix-blend-mode: initial;
}

#character-modal .add-person-place-lore-content > *,
#lore-modal .add-person-place-lore-content > *,
#place-modal .add-person-place-lore-content > *,
#item-modal .add-person-place-lore-content > * {
    position: relative;
    z-index: 1;
}

body.theme-light #character-modal[style*="flex"] .add-person-place-lore-content::before,
body.theme-light #lore-modal[style*="flex"] .add-person-place-lore-content::before,
body.theme-light #place-modal[style*="flex"] .add-person-place-lore-content::before,
body.theme-light #item-modal[style*="flex"] .add-person-place-lore-content::before {
    opacity: 0.14;
    mix-blend-mode: multiply;
}

.add-person-place-lore-modal .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.add-person-place-lore-modal .modal-header .modal-back-btn {
    flex-shrink: 0;
}

.add-person-place-lore-modal .modal-header h2 {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 1.2rem;
    font-weight: 500;
    text-align: center;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.add-person-place-lore-header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-shrink: 0;
}

.character-modal-save-btn {
    min-width: 4.5rem;
    background-color: #e17055;
    border: 1px solid #e17055;
    color: #fff;
}

.character-modal-save-btn:hover:not(:disabled),
.character-modal-save-btn:focus-visible:not(:disabled) {
    background-color: #d46248;
    border-color: #d46248;
    color: #fff;
}

/* Add Person + Image Settings: compact, cohesive primary chrome */
.add-person-place-lore-modal .modal-back-btn,
#sequence-creation-settings-modal .modal-back-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 6px;
    margin-right: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.add-person-place-lore-modal .btn.btn-primary,
.add-person-place-lore-modal .character-modal-save-btn,
#sequence-creation-settings-modal .btn.btn-primary,
#sequence-creation-settings-modal .sequence-settings-apply-btn {
    padding: 0.45rem 0.85rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    min-width: 0;
}

.add-person-place-lore-modal .name-ideas-btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.add-person-place-lore-modal .name-ideas-btn:hover {
    opacity: 1;
    filter: brightness(1.06);
}

.add-person-place-lore-modal .add-person-place-lore-help-btn,
.add-person-place-lore-modal .add-person-place-lore-history-btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.8125rem;
    border-radius: 6px;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.add-person-place-lore-modal .add-person-place-lore-help-btn:hover,
.add-person-place-lore-modal .add-person-place-lore-history-btn:hover {
    opacity: 1;
    filter: brightness(1.06);
}

.add-person-place-lore-modal .add-person-place-lore-apply-btn {
    padding: 0.45rem 0.85rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.add-person-place-lore-modal .character-portrait-generate-btn {
    font-weight: 500;
    font-size: 0.8125rem;
    padding: 0.38rem 0.75rem;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.character-modal-unsaved-actions .btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 6px;
}

/* Unsaved changes prompt (Add Person modal) */
.character-modal-unsaved-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    border-radius: inherit;
}

.character-modal-unsaved-dialog {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: var(--spacing-lg);
    max-width: 22rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.character-modal-unsaved-title {
    margin: 0 0 var(--spacing-md);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.character-modal-unsaved-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm);
}

.character-modal-unsaved-actions #character-modal-unsaved-cancel {
    grid-column: 1 / -1;
}

/* Lore Lexicon / Fantasy Index embed */
.fantasy-index-embed-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 12000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.fantasy-index-embed-dialog {
    display: flex;
    flex-direction: column;
    width: min(1080px, calc(100vw - 2rem));
    height: min(82vh, 760px);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.fantasy-index-embed-toolbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.fantasy-index-embed-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-ui, var(--font-brand, inherit));
}

.fantasy-index-embed-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    margin: 0;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.fantasy-index-embed-close-btn:hover {
    background: var(--bg-tertiary, rgba(0, 0, 0, 0.06));
    color: var(--text-primary);
    border-color: var(--border-color-strong, var(--border-color));
}

.fantasy-index-embed-body {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

.fantasy-index-embed-body .lexicon-embed {
    flex: 1 1 auto;
    min-height: 0;
}

.fantasy-index-embed-body .lexicon-embed-loading {
    position: absolute;
    inset: 0;
    z-index: 20;
}

@media (max-width: 700px) {
    .fantasy-index-embed-modal {
        padding: 0.5rem;
        align-items: stretch;
    }

    .fantasy-index-embed-dialog {
        width: 100%;
        height: min(94vh, 100%);
    }
}

.add-person-place-lore-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    padding: 0;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

/* Character modal: lobby portrait column (author only; hidden in read-only via JS + body class) */
.character-modal-body {
    display: grid;
    grid-template-columns: minmax(280px, 420px) 1fr 1fr;
    gap: 0;
    padding: 0;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.character-modal-body.character-modal-body--portrait-collapsed {
    grid-template-columns: 64px 1fr 1fr;
}

.add-person-place-lore-body.character-modal-body {
    grid-template-columns: minmax(280px, 420px) 1fr 1fr;
}

.add-person-place-lore-body.character-modal-body.character-modal-body--portrait-collapsed {
    grid-template-columns: 64px 1fr 1fr;
}

.character-modal-portrait-column {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    border-right: 1px solid var(--border-color);
    background: var(--bg-secondary, #1a1a1a);
    position: relative;
    overflow: visible;
    z-index: 2;
}

.character-modal-portrait-column.is-collapsed {
    width: 64px;
    max-width: 64px;
    min-width: 64px;
    cursor: pointer;
}

.character-modal-portrait-column.is-collapsed .character-portrait-lobby {
    overflow: hidden;
    min-height: 0;
    pointer-events: none;
}

.character-modal-portrait-column.is-collapsed .character-portrait-gallery-btn,
.character-modal-portrait-column.is-collapsed .character-portrait-gallery-panel,
.character-modal-portrait-column.is-collapsed .character-portrait-generate-wrap,
.character-modal-portrait-column.is-collapsed .character-portrait-upload-btn,
.character-modal-portrait-column.is-collapsed .character-portrait-delete-btn {
    display: none;
}

.character-modal-portrait-column.is-collapsed .character-portrait-action-stack {
    inset: 0;
    top: 0;
    right: 0;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.character-portrait-column-hint {
    display: none;
}

.character-modal-portrait-column.is-collapsed .character-portrait-column-hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: rgba(255, 255, 255, 0.72);
    pointer-events: none;
}

body.theme-light .character-modal-portrait-column.is-collapsed .character-portrait-column-hint {
    color: rgba(48, 48, 48, 0.62);
}

.character-modal-portrait-column.is-collapsed .character-portrait-column-toggle {
    pointer-events: auto;
}

.character-portrait-column-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    font: inherit;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    flex-shrink: 0;
}

.character-portrait-column-toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.character-portrait-column-toggle:hover,
.character-portrait-column-toggle:focus-visible {
    background: var(--accent-hover);
}

.character-portrait-column-toggle:focus-visible {
    outline: 2px solid var(--accent-hover);
    outline-offset: 2px;
}

.character-modal-portrait-column.is-expanded .character-portrait-column-toggle-chevron {
    transform: rotate(180deg);
}

.character-portrait-lobby {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: min(72vh, 520px);
    /* padding: var(--spacing-sm); */
}

.character-portrait-media {
    position: relative;
    flex: 1;
    min-height: 240px;
    border-radius: 10px;
    /* Allow model dropdown to extend outside image bounds; clip image via children */
    overflow: visible;
    background: #2e2e31;
}

.character-portrait-placeholder {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.12)),
        repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.03) 0, rgba(255, 255, 255, 0.03) 6px, transparent 6px, transparent 12px);
}

/* Cover portrait (sequence.css later sets .sequence-generated-image to contain — override here) */
.character-portrait-result-card .sequence-generated-image.character-portrait-image,
#character-portrait-image.character-portrait-image {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    object-fit: cover !important;
    object-position: center top;
    cursor: zoom-in;
}

.character-portrait-media.has-portrait .character-portrait-placeholder {
    display: none !important;
}

.character-portrait-generate-wrap {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    z-index: 4;
    max-width: 96%;
    text-align: center;
}

.character-portrait-quota-status {
    margin-top: 0.35rem;
    justify-content: center;
    text-align: center;
    width: 100%;
}

.character-portrait-media.has-portrait .character-portrait-generate-wrap {
    display: none !important;
}

.character-portrait-media:not(.has-portrait) .character-portrait-generate-wrap {
    flex-direction: column;
}

.character-portrait-model-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
    max-width: 100%;
    padding: 0.35rem 0.5rem;
    font: inherit;
    font-size: 0.82rem;
    color: var(--text-primary, #fff);
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    cursor: pointer;
}

.character-portrait-model-trigger-inner {
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.character-portrait-gen-label {
    opacity: 0.9;
}

.character-portrait-model-label {
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 600;
}

.character-portrait-model-caret {
    font-size: 0.75rem;
    opacity: 0.85;
}

.character-portrait-model-menu {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 100%;
    margin-top: 4px;
    min-width: 12rem;
    padding: 0.25rem 0;
    background: var(--bg-primary, #1a1b1b);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    z-index: 5;
}

/* Bottom overlay (has portrait): open menu upward so it stays inside the frame */
.character-portrait-media.has-portrait .character-portrait-model-menu {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 6px;
}

.character-portrait-generate-wrap .character-portrait-model-menu {
    z-index: 40;
}

.character-portrait-model-option {
    display: block;
    width: 100%;
    padding: 0.45rem 0.75rem;
    text-align: left;
    font: inherit;
    font-size: 0.85rem;
    color: var(--text-primary);
    background: transparent;
    border: none;
    cursor: pointer;
}

.character-portrait-model-option:hover {
    background: rgba(255, 255, 255, 0.06);
}

.character-portrait-model-picker {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
}

.character-portrait-media.has-portrait .character-portrait-model-picker {
    align-items: flex-start;
}

.character-portrait-generate-btn {
    min-width: 7.5rem;
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.character-portrait-generate-btn {
    border: 1px solid color-mix(in srgb, var(--accent, #4a9eff) 55%, transparent);
    background: var(--accent, #4a9eff);
    color: #fff;
}

.character-portrait-generate-btn:hover {
    background: color-mix(in srgb, var(--accent, #4a9eff) 82%, #ffffff 18%);
    border-color: color-mix(in srgb, var(--accent, #4a9eff) 72%, #ffffff 28%);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent, #4a9eff) 35%, transparent);
}

.character-portrait-generate-btn:active {
    background: color-mix(in srgb, var(--accent, #4a9eff) 78%, #000000 22%);
}

.character-portrait-generate-btn:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent, #4a9eff) 65%, #ffffff 35%);
    outline-offset: 2px;
}

/* Portrait generation always uses Grok; model dropdown hidden */
.character-portrait-model-picker {
    display: none !important;
}

.character-portrait-result-card {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    border-radius: 10px;
    overflow: hidden;
}

.character-portrait-result-card .character-portrait-sequence-preview {
    position: relative;
    flex: 1;
    min-height: 0 !important;
    height: 100%;
    aspect-ratio: auto;
    align-items: stretch;
    justify-content: stretch;
}

.character-portrait-image-corner-actions {
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
}

.character-portrait-action-stack {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    pointer-events: auto;
}

.character-portrait-corner-btn {
    position: relative;
    top: auto;
    right: auto;
    left: auto;
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(0, 0, 0, 0.48);
    color: #fff;
    cursor: pointer;
    pointer-events: auto;
    overflow: hidden;
    transition: background 0.15s, border-color 0.15s;
}

.character-portrait-corner-btn:hover {
    background: rgba(0, 0, 0, 0.62);
    border-color: rgba(255, 255, 255, 0.45);
}

.character-portrait-icon-btn {
    width: auto;
    min-width: 36px;
    height: 36px;
    justify-content: flex-end;
    overflow: hidden;
}

.character-portrait-icon-btn-glyph {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.character-portrait-icon-btn-label {
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    padding: 0;
    transition: max-width 0.22s ease, opacity 0.18s ease, padding 0.22s ease;
}

/* Regenerate stays expanded by default (label left, icon right) */
.character-portrait-action-stack .character-portrait-refresh-btn .character-portrait-icon-btn-label {
    max-width: 5.75rem;
    opacity: 1;
    padding-left: 0.55rem;
}

/* Hover/focus one button: collapse siblings, expand the active label */
.character-portrait-action-stack:has(.character-portrait-icon-btn:hover) .character-portrait-icon-btn-label,
.character-portrait-action-stack:has(.character-portrait-icon-btn:focus-visible) .character-portrait-icon-btn-label {
    max-width: 0;
    opacity: 0;
    padding-left: 0;
}

.character-portrait-action-stack:has(.character-portrait-icon-btn:hover) .character-portrait-icon-btn:hover .character-portrait-icon-btn-label,
.character-portrait-action-stack:has(.character-portrait-icon-btn:focus-visible) .character-portrait-icon-btn:focus-visible .character-portrait-icon-btn-label {
    max-width: 5.75rem;
    opacity: 1;
    padding-left: 0.55rem;
}

.character-portrait-icon-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.45);
    outline-offset: 2px;
}

.character-portrait-delete-btn[hidden] {
    display: none !important;
}

.character-portrait-media:not(.has-portrait) .character-portrait-refresh-btn {
    display: none !important;
}

.character-portrait-media:not(.has-portrait) .character-portrait-upload-btn .character-portrait-icon-btn-label {
    max-width: 4.5rem;
    opacity: 1;
    padding-left: 0.55rem;
}

.character-portrait-gallery-btn {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 8;
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.92);
    cursor: pointer;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
}

.character-portrait-gallery-btn:hover,
.character-portrait-gallery-btn:focus-visible {
    color: #fff;
}

.character-portrait-gallery-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.55);
    outline-offset: 2px;
}

.character-portrait-gallery-icon {
    display: block;
}

.character-portrait-gallery-panel {
    position: absolute;
    inset: 0;
    z-index: 9;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.65rem 0.7rem 0.75rem;
    border-radius: 10px;
    background: rgba(20, 20, 22, 0.94);
    color: #fff;
    overflow: hidden;
}

.character-portrait-gallery-panel[hidden] {
    display: none !important;
}

.character-portrait-gallery-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0;
}

.character-portrait-gallery-panel-title {
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.character-portrait-gallery-close {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    cursor: pointer;
}

.character-portrait-gallery-close:hover {
    background: rgba(255, 255, 255, 0.12);
}

.character-portrait-gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
    overflow: auto;
    min-height: 0;
    flex: 1;
    align-content: start;
}

.character-portrait-gallery-item {
    position: relative;
    aspect-ratio: 3 / 4;
    border-radius: 6px;
    overflow: hidden;
    background: #1a1a1c;
}

.character-portrait-gallery-thumb {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    overflow: hidden;
    background: transparent;
    cursor: pointer;
}

.character-portrait-gallery-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
}

.character-portrait-gallery-thumb:hover,
.character-portrait-gallery-item.is-active .character-portrait-gallery-thumb {
    border-color: rgba(255, 255, 255, 0.55);
}

.character-portrait-gallery-item-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s;
}

.character-portrait-gallery-item:hover .character-portrait-gallery-item-delete,
.character-portrait-gallery-item:focus-within .character-portrait-gallery-item-delete {
    opacity: 1;
}

.character-portrait-gallery-empty {
    margin: 0;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.65);
}

.character-portrait-media.character-portrait-gallery-open .character-portrait-gallery-btn {
    color: #fff;
}

body.theme-light .character-portrait-gallery-panel {
    background: rgba(48, 48, 48, 0.96);
}

@media (max-width: 480px) {
    .character-portrait-icon-btn-label {
        font-size: 0.68rem;
    }
}

/* Fullscreen lightbox (portrait zoom) */
.character-portrait-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10050;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    box-sizing: border-box;
}

.character-portrait-lightbox.is-open {
    display: flex;
}

.character-portrait-lightbox-backdrop {
    position: absolute;
    inset: 0;
    cursor: zoom-out;
}

.character-portrait-lightbox-content {
    position: relative;
    z-index: 1;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-portrait-lightbox-content img {
    max-width: min(100vw - 48px, 100%);
    max-height: calc(100vh - 96px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.character-portrait-lightbox-close {
    position: fixed;
    top: var(--spacing-md);
    right: var(--spacing-md);
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10051;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.character-portrait-lightbox-close svg {
    width: 22px;
    height: 22px;
    display: block;
}

.character-portrait-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* Image Settings: above Add Person / entity modals (3000) and other creation-settings overlays (4000) */
#sequence-creation-settings-modal.creation-settings-modal {
    z-index: 4100;
}

/* Book cover Image Settings from Publish: above .modal (2000), editor-ai-overlay (10050), so Apply receives clicks */
#sequence-creation-settings-modal.sequence-creation-settings-modal--book-cover.creation-settings-modal {
    z-index: 10060;
}

#sequence-image-settings-info-modal {
    z-index: 4200;
}

/* Image Settings – match Creation Settings modal (header, option buttons, footer) */
#sequence-creation-settings-modal .sequence-image-settings-header {
    flex-wrap: nowrap;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

#sequence-creation-settings-modal .sequence-image-settings-header h2 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    font-size: 1.1rem;
    font-weight: 500;
    text-align: center;
    pointer-events: none;
    width: 100%;
    box-sizing: border-box;
}

#sequence-creation-settings-modal #sequence-image-settings-info {
    margin-left: auto;
    pointer-events: auto;
}

#sequence-creation-settings-modal .sequence-settings-default-btn {
    flex-shrink: 0;
    width: auto !important;
    min-width: 72px !important;
    padding: 0.4rem 0.7rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 6px;
}

#sequence-creation-settings-modal .sequence-settings-title.creation-settings-section-title {
    margin: 0 0 var(--spacing-sm);
    font-size: 1rem;
}

#sequence-creation-settings-modal .seq-setting-btn {
    padding: 0.4rem 0.55rem;
    background-color: var(--bg-tertiary);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    font-family: inherit;
}

#sequence-creation-settings-modal .seq-setting-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.18);
    color: var(--text-primary);
}

#sequence-creation-settings-modal .seq-setting-btn.active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
    box-shadow: none;
}

#sequence-creation-settings-modal .seq-setting-btn.active:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

body.theme-light #sequence-creation-settings-modal .seq-setting-btn {
    border-color: rgba(0, 0, 0, 0.18);
}

body.theme-light #sequence-creation-settings-modal .seq-setting-btn:hover {
    border-color: rgba(0, 0, 0, 0.28);
}

body.theme-light #sequence-creation-settings-modal .seq-setting-btn.active {
    border-color: var(--accent);
}

body.theme-light #sequence-creation-settings-modal .seq-setting-btn.active:hover {
    border-color: var(--accent-hover);
}

#sequence-creation-settings-modal .seq-detail-buttons .seq-setting-btn {
    flex: 1;
    min-width: 45px;
}

#sequence-creation-settings-modal .sequence-creation-settings-content.creation-settings-content {
    max-width: min(560px, 92vw);
    width: min(560px, 92vw);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Simplified Write portrait settings: only Style / Mood / Genre — keep panel compact */
#sequence-creation-settings-modal.sequence-creation-settings-modal--write-simplified .sequence-creation-settings-content.creation-settings-content {
    max-width: min(420px, 94vw);
    width: min(420px, 94vw);
}

#sequence-creation-settings-modal.sequence-creation-settings-modal--book-cover .sequence-creation-settings-content.creation-settings-content {
    max-width: min(420px, 94vw);
    width: min(420px, 94vw);
}

#sequence-creation-settings-modal .sequence-creation-settings-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: var(--spacing-xl);
}

#sequence-creation-settings-modal .sequence-creation-settings-footer {
    padding: var(--spacing-md) 0 0;
    margin-top: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    background: transparent;
}

body.theme-light #sequence-creation-settings-modal .sequence-creation-settings-footer {
    border-top-color: rgba(0, 0, 0, 0.12);
}

.character-portrait-media-is-loading .character-portrait-generate-wrap {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.character-portrait-media-is-loading .character-portrait-image-corner-actions {
    opacity: 0.35;
    pointer-events: none;
}

.character-portrait-media-is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 5;
}

.character-portrait-media-is-loading::before {
    content: attr(data-loading-label);
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 6;
    max-width: calc(100% - 1.5rem);
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.35;
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
    white-space: normal;
}

.character-modal-main-columns {
    grid-column: 2 / 4;
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

body.editor-read-only .character-modal-main-columns {
    grid-column: 1 / 4;
}

body.editor-read-only .character-modal-body {
    grid-template-columns: 1fr 1fr;
}

.add-person-place-lore-left-panel {
    display: flex;
    flex-direction: column;
    padding: var(--spacing-lg);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.add-person-place-lore-right-panel {
    display: flex;
    flex-direction: column;
    padding: var(--spacing-lg);
    overflow-y: auto;
}

/* Add Person: inline Character Creation Settings column (replaces Notes-only right panel) */
.add-person-place-lore-right-panel.character-modal-inline-settings-column {
    overflow: hidden;
    min-height: 0;
}

.character-modal-inline-settings-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 92, 250, 0.35) transparent;
    scrollbar-gutter: stable;
}

#character-modal .add-person-place-lore-left-panel,
#character-modal .add-person-place-lore-description-display,
#character-modal .character-modal-inline-textarea,
#lore-modal .add-person-place-lore-left-panel,
#lore-modal .add-person-place-lore-description-display,
#place-modal .add-person-place-lore-left-panel,
#place-modal .add-person-place-lore-description-display,
#item-modal .add-person-place-lore-left-panel,
#item-modal .add-person-place-lore-description-display {
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 92, 250, 0.35) transparent;
    scrollbar-gutter: stable;
}

#character-modal .character-modal-inline-settings-scroll::-webkit-scrollbar,
#character-modal .add-person-place-lore-left-panel::-webkit-scrollbar,
#character-modal .add-person-place-lore-description-display::-webkit-scrollbar,
#character-modal .character-modal-inline-textarea::-webkit-scrollbar,
#lore-modal .character-modal-inline-settings-scroll::-webkit-scrollbar,
#lore-modal .add-person-place-lore-left-panel::-webkit-scrollbar,
#lore-modal .add-person-place-lore-description-display::-webkit-scrollbar,
#place-modal .character-modal-inline-settings-scroll::-webkit-scrollbar,
#place-modal .add-person-place-lore-left-panel::-webkit-scrollbar,
#place-modal .add-person-place-lore-description-display::-webkit-scrollbar,
#item-modal .character-modal-inline-settings-scroll::-webkit-scrollbar,
#item-modal .add-person-place-lore-left-panel::-webkit-scrollbar,
#item-modal .add-person-place-lore-description-display::-webkit-scrollbar {
    width: 5px;
}

#character-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-track,
#character-modal .add-person-place-lore-left-panel::-webkit-scrollbar-track,
#character-modal .add-person-place-lore-description-display::-webkit-scrollbar-track,
#character-modal .character-modal-inline-textarea::-webkit-scrollbar-track,
#lore-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-track,
#lore-modal .add-person-place-lore-left-panel::-webkit-scrollbar-track,
#lore-modal .add-person-place-lore-description-display::-webkit-scrollbar-track,
#place-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-track,
#place-modal .add-person-place-lore-left-panel::-webkit-scrollbar-track,
#place-modal .add-person-place-lore-description-display::-webkit-scrollbar-track,
#item-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-track,
#item-modal .add-person-place-lore-left-panel::-webkit-scrollbar-track,
#item-modal .add-person-place-lore-description-display::-webkit-scrollbar-track {
    background: transparent;
}

#character-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb,
#character-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb,
#character-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb,
#character-modal .character-modal-inline-textarea::-webkit-scrollbar-thumb,
#lore-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb,
#lore-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb,
#lore-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb,
#place-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb,
#place-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb,
#place-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb,
#item-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb,
#item-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb,
#item-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb {
    background: rgba(124, 92, 250, 0.28);
    border-radius: 100px;
}

#character-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb:hover,
#character-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb:hover,
#character-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb:hover,
#character-modal .character-modal-inline-textarea::-webkit-scrollbar-thumb:hover,
#lore-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb:hover,
#lore-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb:hover,
#lore-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb:hover,
#place-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb:hover,
#place-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb:hover,
#place-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb:hover,
#item-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb:hover,
#item-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb:hover,
#item-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb:hover {
    background: rgba(124, 92, 250, 0.5);
}

body.theme-light #character-modal .character-modal-inline-settings-scroll,
body.theme-light #character-modal .add-person-place-lore-left-panel,
body.theme-light #character-modal .add-person-place-lore-description-display,
body.theme-light #character-modal .character-modal-inline-textarea,
body.theme-light #lore-modal .character-modal-inline-settings-scroll,
body.theme-light #lore-modal .add-person-place-lore-left-panel,
body.theme-light #lore-modal .add-person-place-lore-description-display,
body.theme-light #place-modal .character-modal-inline-settings-scroll,
body.theme-light #place-modal .add-person-place-lore-left-panel,
body.theme-light #place-modal .add-person-place-lore-description-display,
body.theme-light #item-modal .character-modal-inline-settings-scroll,
body.theme-light #item-modal .add-person-place-lore-left-panel,
body.theme-light #item-modal .add-person-place-lore-description-display {
    scrollbar-color: rgba(48, 48, 48, 0.28) transparent;
}

body.theme-light #character-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb,
body.theme-light #character-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb,
body.theme-light #character-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb,
body.theme-light #character-modal .character-modal-inline-textarea::-webkit-scrollbar-thumb,
body.theme-light #lore-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb,
body.theme-light #lore-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb,
body.theme-light #lore-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb,
body.theme-light #place-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb,
body.theme-light #place-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb,
body.theme-light #place-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb,
body.theme-light #item-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb,
body.theme-light #item-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb,
body.theme-light #item-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb {
    background: rgba(48, 48, 48, 0.22);
}

body.theme-light #character-modal .character-modal-inline-settings-scroll::-webkit-scrollbar-thumb:hover,
body.theme-light #character-modal .add-person-place-lore-left-panel::-webkit-scrollbar-thumb:hover,
body.theme-light #character-modal .add-person-place-lore-description-display::-webkit-scrollbar-thumb:hover,
body.theme-light #character-modal .character-modal-inline-textarea::-webkit-scrollbar-thumb:hover {
    background: rgba(48, 48, 48, 0.38);
}

.character-modal-inline-settings-column .character-creation-settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--spacing-md);
}

.entity-ref-edit-modal .add-person-place-lore-right-panel.character-modal-inline-settings-column {
    overflow: hidden;
    min-height: 0;
}

.entity-ref-edit-modal .add-person-place-lore-name-group {
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
}

.entity-ref-edit-modal .character-name-tiny-label {
    display: block;
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-secondary, #888);
}

.entity-ref-edit-modal .entity-ref-desc-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.65rem;
}

.entity-ref-edit-modal .character-modal-role-generate-btn,
#place-editor-apply-btn,
#lore-editor-apply-btn,
#item-editor-apply-btn {
    display: none !important;
}

.entity-ref-edit-modal .entity-ref-desc-row .character-biography-inline-heading {
    text-align: left;
}

#lore-modal .add-person-place-lore-name-input,
#place-modal .add-person-place-lore-name-input,
#item-modal .add-person-place-lore-name-input {
    width: 100%;
    box-sizing: border-box;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 4px;
    font-size: 0.9rem;
    min-height: 2.35rem;
}

#lore-modal .add-person-place-lore-description-display,
#place-modal .add-person-place-lore-description-display,
#item-modal .add-person-place-lore-description-display {
    padding: 0.45rem 0.55rem;
    border-radius: 4px;
    font-size: 0.85rem;
    line-height: 1.45;
    min-height: 8.5rem;
}

#lore-modal .add-person-place-lore-description-display[contenteditable="true"]:empty:before,
#place-modal .add-person-place-lore-description-display[contenteditable="true"]:empty:before,
#item-modal .add-person-place-lore-description-display[contenteditable="true"]:empty:before {
    color: rgba(255, 255, 255, 0.17);
    opacity: 1;
}

body.theme-light #lore-modal .add-person-place-lore-description-display[contenteditable="true"]:empty:before,
body.theme-light #place-modal .add-person-place-lore-description-display[contenteditable="true"]:empty:before,
body.theme-light #item-modal .add-person-place-lore-description-display[contenteditable="true"]:empty:before {
    color: rgba(0, 0, 0, 0.26);
}

#lore-modal .add-person-place-lore-description-display[contenteditable="true"]:focus:empty:before,
#place-modal .add-person-place-lore-description-display[contenteditable="true"]:focus:empty:before,
#item-modal .add-person-place-lore-description-display[contenteditable="true"]:focus:empty:before {
    content: none;
}

#lore-settings-modal,
#location-settings-modal,
#item-settings-modal {
    display: none !important;
}

.character-modal-inline-text-fields--right-column .character-modal-inline-field--activity {
    width: 100%;
}

.character-inline-label-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.3rem;
    min-width: 0;
    overflow: hidden;
}

.character-inline-label-row .character-field-redo-btn {
    margin-left: auto;
}

.character-inline-label-row > label,
.character-inline-label-row > .character-modal-inline-field-label {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.character-inline-label-row .character-field-redo-btn,
.character-inline-label-row .character-field-undo-btn,
.character-inline-label-row .character-field-random-btn {
    flex-shrink: 0;
}

.character-inline-label-row--race .character-race-fantasy-index-btn {
    margin-left: auto;
}

.character-age-range-inputs {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 0.5rem;
    align-items: end;
}

.character-age-range-field {
    display: block;
}

.character-age-range-divider {
    color: var(--text-secondary);
    font-size: 0.82rem;
    padding-bottom: 0.15rem;
}

.character-field-random-btn,
.character-field-undo-btn,
.character-field-redo-btn {
    margin: 0;
    padding: 0.1rem 0.4rem;
    font-size: 0.62rem;
    font-weight: 600;
    line-height: 1.2;
    text-transform: lowercase;
    color: var(--text-primary, #fff);
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
}

.character-field-undo-btn,
.character-field-redo-btn {
    font-size: 0.75rem;
    padding: 0.08rem 0.42rem;
}

.character-field-random-btn:hover,
.character-field-undo-btn:hover:not(:disabled),
.character-field-redo-btn:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.38);
}

/* Character modal: random actions stay subtle until hover, focus, or click */
#character-modal .character-field-random-btn,
#character-modal .character-name-part-random-btn {
    opacity: 0.5;
    transition: opacity 0.15s ease, border-color 0.15s ease;
}

#character-modal .character-field-random-btn:hover,
#character-modal .character-field-random-btn:focus,
#character-modal .character-field-random-btn:focus-visible,
#character-modal .character-field-random-btn:active,
#character-modal .character-name-part-random-btn:hover,
#character-modal .character-name-part-random-btn:focus,
#character-modal .character-name-part-random-btn:focus-visible,
#character-modal .character-name-part-random-btn:active {
    opacity: 1;
}

.character-field-undo-btn:disabled,
.character-field-redo-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

/* Keep redo in document flow so toggling visible does not shift undo/random (slot stays width). */
.character-field-redo-btn:not(.character-inline-redo--visible) {
    visibility: hidden;
    pointer-events: none;
}

.character-modal-inline-field .character-inline-label-row + .character-modal-inline-textarea {
    margin-top: 0;
}

@media (max-width: 1100px) {
    .character-modal-inline-settings-column .character-creation-settings-grid {
        grid-template-columns: 1fr;
    }
}

.character-modal-bio-generate-block {
    margin-top: var(--spacing-md);
    flex-shrink: 0;
}

.character-modal-bio-generate-controls {
    justify-content: center;
    margin-bottom: 0;
    margin-top: 0;
    flex-shrink: 0;
}

.add-person-place-lore-editor-header.character-modal-inline-settings-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: var(--spacing-sm);
}

.add-person-place-lore-editor-header.character-modal-inline-settings-header .add-person-place-lore-help-btn {
    grid-column: 1;
    justify-self: start;
    flex-shrink: 0;
}

.add-person-place-lore-editor-header.character-modal-inline-settings-header .character-modal-inline-settings-title {
    grid-column: 2;
    margin: 0;
    flex: unset;
    text-align: center;
}

.add-person-place-lore-name-group {
    margin-bottom: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: nowrap;
}

#character-modal #character-alternate-names-group {
    margin-bottom: 0.25rem;
    gap: 0.5rem;
}

#character-modal #character-alternate-names-group .add-person-place-lore-label {
    margin-bottom: 0;
}

#character-modal .character-nickname-pills-wrap:empty {
    display: none;
    min-height: 0;
    margin-bottom: 0;
}

.add-person-place-lore-label {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.add-person-place-lore-name-input {
    flex: 1;
    padding: var(--spacing-sm);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
}

.add-person-place-lore-name-input:focus,
#character-modal .character-name-inline-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

body.theme-light .add-person-place-lore-name-input:focus,
body.theme-light #character-modal .character-name-inline-input:focus {
    border-color: rgba(0, 0, 0, 0.22);
    background-color: rgba(0, 0, 0, 0.045);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Add Person left column: identity heading + prominent character role (full width under names) */
.character-modal-identity-heading {
    margin: 0 0 0.65rem;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-ui, var(--font-brand, inherit));
    letter-spacing: 0.02em;
}

.entity-ref-identity-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    margin: 0 0 0.65rem;
}

.entity-ref-identity-heading-row .character-modal-identity-heading {
    margin: 0;
}

.entity-ref-identity-heading-row .character-name-action-btn {
    flex-shrink: 0;
}

.character-modal-character-role-block {
    margin: 0.35rem 0 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: 100%;
}

.character-modal-character-role-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    min-width: 0;
}

.character-modal-character-role-row .character-modal-character-role-select {
    flex: 1 1 auto;
    min-width: 0;
}

.character-modal-role-generate-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 2.5rem;
    padding: 0.45rem 1rem;
}

.character-modal-left-activity {
    margin-top: 1rem;
    width: 100%;
}

#character-modal .character-appearance-inline-select,
#character-modal .character-modal-hair-select,
.character-basic-wizard-modal .character-modal-hair-select {
    width: 100%;
    box-sizing: border-box;
    min-height: 2.35rem;
    padding: 0.4rem 2rem 0.4rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 0.88rem;
    font-family: inherit;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    color-scheme: dark;
    cursor: pointer;
    appearance: auto;
}

#character-modal .character-appearance-inline-select option,
#character-modal .character-modal-hair-select option,
.character-basic-wizard-modal .character-modal-hair-select option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

body.theme-light #character-modal .character-appearance-inline-select,
body.theme-light #character-modal .character-modal-hair-select,
body.theme-light .character-basic-wizard-modal .character-modal-hair-select {
    color-scheme: light;
    background-color: var(--bg-primary);
}

body.theme-light #character-modal .character-appearance-inline-select option,
body.theme-light #character-modal .character-modal-hair-select option,
body.theme-light .character-basic-wizard-modal .character-modal-hair-select option {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

#character-modal .character-appearance-inline-select:focus,
#character-modal .character-modal-hair-select:focus,
.character-basic-wizard-modal .character-modal-hair-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

body.theme-light #character-modal .character-appearance-inline-select:focus,
body.theme-light #character-modal .character-modal-hair-select:focus,
body.theme-light .character-basic-wizard-modal .character-modal-hair-select:focus {
    border-color: rgba(0, 0, 0, 0.22);
    background-color: rgba(0, 0, 0, 0.045);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.character-modal-character-role-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

#character-modal .character-modal-character-role-select {
    width: 100%;
    box-sizing: border-box;
    min-height: 2.5rem;
    padding: 0.45rem 2rem 0.45rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    font-size: 0.92rem;
    font-family: inherit;
    color: var(--text-primary);
    cursor: pointer;
    appearance: auto;
    /* Solid surface (not translucent) so Win/Chrome native list picks up a consistent dark/light scheme */
    background-color: var(--bg-secondary);
    color-scheme: dark;
}

/* Native dropdown list options: Chrome/Edge on Windows otherwise often show pale panel + light text → unreadable */
#character-modal .character-modal-character-role-select option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

body.theme-light #character-modal .character-modal-character-role-select {
    color-scheme: light;
    background-color: var(--bg-primary);
}

body.theme-light #character-modal .character-modal-character-role-select option {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

#character-modal .character-modal-character-role-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

body.theme-light #character-modal .character-modal-character-role-select:focus {
    border-color: rgba(0, 0, 0, 0.22);
    background-color: rgba(0, 0, 0, 0.045);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Character name inline: [title 15%][first 25%][middle 25%][last 25%], Name Ideas below */
.character-name-inline-block {
    margin-bottom: 0.35rem;
}

.character-name-inline-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.character-name-field-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
    overflow: hidden;
    align-content: start;
}

.character-name-field-title {
    flex: 0 0 15%;
}

.character-name-field-first,
.character-name-field-wrap:not(.character-name-field-title) {
    flex: 1 1 25%;
}

.character-name-field-wrap:not(.character-name-field-title) {
    padding-top: 1.05rem;
}

.character-name-field-wrap .character-name-inline-input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding-top: var(--spacing-sm);
}

.character-name-field-wrap .character-name-tiny-label {
    position: static;
    display: block;
    margin-bottom: 0;
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--text-secondary, #888);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.character-name-part-actions {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.15rem;
    margin-bottom: 0;
    max-width: 100%;
}

.character-name-part-random-btn,
.character-name-part-undo-btn,
.character-name-part-redo-btn {
    margin: 0;
    padding: 0.08rem 0.28rem;
    font-size: 0.58rem;
    font-weight: 600;
    line-height: 1.2;
    text-transform: lowercase;
    color: var(--text-primary, #fff);
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    flex-shrink: 0;
}

.character-name-part-undo-btn,
.character-name-part-redo-btn {
    font-size: 0.72rem;
    padding: 0.06rem 0.32rem;
}

.character-name-part-random-btn:hover,
.character-name-part-undo-btn:hover:not(:disabled),
.character-name-part-redo-btn:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.4);
}

.character-name-part-undo-btn:not(.character-inline-undo--visible),
.character-field-undo-btn:not(.character-inline-undo--visible) {
    display: none;
}

.character-name-part-redo-btn:not(.character-inline-redo--visible) {
    visibility: hidden;
    pointer-events: none;
}

.character-name-part-undo-btn:disabled,
.character-name-part-redo-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.character-name-actions-row {
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.character-name-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0;
}

.character-name-action-icon {
    flex-shrink: 0;
    font-size: 0.9rem;
    line-height: 1;
}

/* Inline settings live in the right column; keep legacy modal opener out of layout */
#character-creation-settings-btn {
    display: none !important;
}

/* Nickname pills in character modal */
.character-nickname-pills-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.5rem;
    min-height: 2rem;
    margin-bottom: 0.5rem;
}

.character-nickname-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.4rem;
    background: var(--bg-primary, #2a2a2a);
    border: 1px solid var(--border-color, #444);
    border-radius: 6px;
    font-size: 0.85rem;
}

.character-nickname-pill-text {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.character-nickname-pill-input {
    width: 80px;
    min-width: 60px;
    padding: 0.1rem 0.25rem;
    background: var(--bg-secondary, #1e1e1e);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.character-nickname-pill-edit,
.character-nickname-pill-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.1rem;
    font-size: 0.9rem;
    line-height: 1;
    border-radius: 2px;
}

.character-nickname-pill-edit:hover,
.character-nickname-pill-delete:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.08);
}

.character-add-nickname-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
    background: transparent;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
}

.character-add-nickname-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.add-person-place-lore-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.add-person-place-lore-controls.character-biography-controls-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: var(--spacing-sm);
}

.add-person-place-lore-controls.character-biography-controls-row #character-left-redo-btn {
    justify-self: start;
}

.add-person-place-lore-controls.character-biography-controls-row #character-left-undo-btn {
    justify-self: end;
}

.character-biography-inline-heading {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    text-align: center;
}

.character-biography-inline-heading .character-bio-char-count {
    font-weight: 500;
    margin-left: 0.35rem;
}

.add-person-place-lore-control-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    transition: all 0.2s;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    text-decoration: none;
}

.add-person-place-lore-control-btn:visited,
.add-person-place-lore-control-btn:active {
    color: var(--text-secondary);
    text-decoration: none;
}

.add-person-place-lore-control-btn:hover {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.add-person-place-lore-settings-btn {
    background-color: var(--accent);
    border: 1px solid var(--accent);
    color: #ffffff;
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    flex: 0 0 auto;
}

.add-person-place-lore-settings-btn:hover {
    background-color: var(--accent-hover, #2d5a7d);
    border-color: var(--accent-hover, #2d5a7d);
    opacity: 0.9;
}

.add-person-place-lore-description-display {
    flex: 1;
    padding: var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    min-height: 300px;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    overflow-y: auto;
}

/* Editable left panel (same as editor content when contenteditable) */
.add-person-place-lore-description-display[contenteditable="true"] {
    outline: none;
}

.add-person-place-lore-description-display[contenteditable="true"]:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

.add-person-place-lore-description-display[contenteditable="true"]:empty:before {
    content: attr(data-placeholder);
    color: var(--text-secondary);
    opacity: 0.5;
}

/* Add Person: biography — tall enough to show the 750-char cap, scroll if needed */
#character-modal .add-person-place-lore-left-panel .add-person-place-lore-description-display.character-modal-biography-body {
    flex: 0 0 auto;
    display: block;
    width: 100%;
    box-sizing: border-box;
    min-height: 8.5rem;
    max-height: 14rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    resize: vertical;
    padding: 0.45rem 0.55rem;
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--text-primary);
    font-family: inherit;
}

#character-modal .add-person-place-lore-left-panel .add-person-place-lore-description-display.character-modal-biography-body:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

body.theme-light #character-modal .add-person-place-lore-left-panel .add-person-place-lore-description-display.character-modal-biography-body:focus {
    border-color: rgba(0, 0, 0, 0.22);
    background-color: rgba(0, 0, 0, 0.045);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.character-modal-inline-field--appearance-block {
    width: 100%;
}

#character-modal .character-modal-appearance-paragraph {
    min-height: 5.5rem;
    max-height: 10rem;
    resize: vertical;
}

.character-appearance-inline-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem 0.75rem;
    width: 100%;
}

.character-appearance-inline-cell--full {
    grid-column: 1 / -1;
}

.character-appearance-inline-sublabel {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.character-appearance-inline-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    margin-bottom: 0.25rem;
    min-width: 0;
}

.character-appearance-inline-label-row .character-appearance-inline-sublabel {
    margin-bottom: 0;
    flex: 1 1 auto;
    min-width: 0;
}

.character-appearance-inline-label-row .character-basic-wizard-sublabel {
    margin-bottom: 0;
    flex: 1 1 auto;
    min-width: 0;
}

.character-appearance-inline-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.45rem 0.85rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: inherit;
    line-height: 1.35;
    min-height: 2.35rem;
}

.character-appearance-inline-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

body.theme-light .character-appearance-inline-input:focus {
    border-color: rgba(0, 0, 0, 0.22);
    background-color: rgba(0, 0, 0, 0.045);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.character-modal-inline-field--appearance-block .character-inline-label-row {
    margin-bottom: 0.45rem;
}

.character-inline-label-row--appearance-head > label,
.character-inline-label-row--appearance-head > .character-modal-inline-field-label {
    flex: 0 1 auto;
    width: auto;
}

.character-inline-label-row--appearance-head .character-field-redo-btn {
    margin-left: auto;
}


.character-modal-inline-settings-column .character-modal-inline-text-fields--right-column {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.character-modal-inline-field-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.character-modal-inline-textarea {
    width: 100%;
    box-sizing: border-box;
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
    min-height: 4.25rem;
}

.character-modal-inline-textarea--compact {
    min-height: 2.5rem;
    max-height: 6rem;
}

.character-modal-inline-input {
    width: 100%;
    box-sizing: border-box;
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: inherit;
    line-height: 1.45;
    min-height: 2.5rem;
}

.character-modal-inline-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

.character-modal-inline-textarea:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

body.theme-light .character-modal-inline-input:focus,
body.theme-light .character-modal-inline-textarea:focus {
    border-color: rgba(0, 0, 0, 0.22);
    background-color: rgba(0, 0, 0, 0.045);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.add-person-place-lore-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

.add-person-place-lore-editor-title {
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-primary);
    margin: 0;
    flex: 1;
    text-align: center;
}

.add-person-place-lore-help-btn,
.add-person-place-lore-history-btn {
    background-color: var(--accent);
    border: 1px solid var(--accent);
    color: #ffffff;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.85rem;
    font-family: inherit;
}

.add-person-place-lore-help-btn:hover,
.add-person-place-lore-history-btn:hover {
    background-color: var(--accent-hover, #2d5a7d);
    border-color: var(--accent-hover, #2d5a7d);
    opacity: 0.9;
}

.add-person-place-lore-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.add-person-place-lore-icon svg {
    display: block;
    width: 14px;
    height: 14px;
}

.add-person-place-lore-editor-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.add-person-place-lore-editor-input {
    display: none;
}

.add-person-place-lore-apply-btn {
    background-color: var(--accent);
    border: 1px solid var(--accent);
    color: #ffffff;
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.add-person-place-lore-apply-btn:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

.add-person-place-lore-editor-content {
    flex: 1;
    padding: var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    min-height: 400px;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    overflow-y: auto;
    cursor: text;
    outline: none;
}

.add-person-place-lore-editor-content[contenteditable="true"]:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

.add-person-place-lore-editor-content[contenteditable="true"]:empty:before {
    content: attr(data-placeholder);
    color: var(--text-secondary);
    opacity: 0.5;
}

@media (max-width: 768px) {
    .ai-panel-right {
        width: 100%;
        max-width: 100%;
        right: 0;
        left: 0;
        z-index: 640;
        padding-bottom: calc(var(--write-tabbar-height, 3.4rem) + env(safe-area-inset-bottom, 0px));
        box-sizing: border-box;
    }

    body.page-write .ai-panel-mobile-back-btn {
        display: inline-flex;
    }

    body.page-write #ai-panel-help-btn > span:not(.ai-panel-icon) {
        display: none;
    }
    
    .creation-settings-body {
        grid-template-columns: 1fr;
    }
    
    .creation-settings-left-column,
    .creation-settings-right-column {
        grid-column: 1;
    }
    
    .creation-settings-focus-grid {
        grid-template-columns: 1fr;
    }
    
    .creation-settings-tone-grid {
        grid-template-columns: 1fr;
    }
    
    .places-people-lore-columns {
        grid-template-columns: 1fr;
    }
    
    .places-people-lore-column:not(:last-child) {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: var(--spacing-md);
        margin-bottom: var(--spacing-md);
    }
    
    .add-person-place-lore-body {
        grid-template-columns: 1fr;
    }
    
    .add-person-place-lore-left-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
}

/* Custom Confirmation Modal */
.custom-confirm-modal {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 4000;
}

.custom-confirm-content {
    max-width: 400px;
    width: 90%;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
}

.custom-confirm-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.custom-confirm-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.custom-confirm-body {
    padding: var(--spacing-lg);
}

.custom-confirm-body p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Info modal: on document.body when open (see showPlacesPeopleLoreInfoModal); above entity modals (~3000–5000) */
#places-people-lore-info-modal {
    z-index: 10000;
}

/* Info modal content box – subtle accent and background variation */
#places-people-lore-info-modal .custom-confirm-content {
    border-left: 4px solid var(--accent);
    background: linear-gradient(to bottom, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
}

body.theme-light #places-people-lore-info-modal .custom-confirm-content {
    background: linear-gradient(to bottom, #f8f9fa 0%, #eef1f4 100%);
}

/* Info modal (places-people-lore-info) – formatted content */
#places-people-lore-info-modal .custom-confirm-header h3 {
    font-weight: 700;
}

#places-people-lore-info-modal .custom-confirm-body {
    font-size: 0.9rem;
}

#places-people-lore-info-modal .info-modal-body {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.65;
    margin-bottom: var(--spacing-md);
}

#places-people-lore-info-modal .info-modal-item {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.65;
    margin-bottom: var(--spacing-md);
}

#places-people-lore-info-modal .info-modal-item:last-child,
#places-people-lore-info-modal .info-modal-body:last-child {
    margin-bottom: 0;
}

#places-people-lore-info-modal .info-pct {
    font-weight: 700;
    margin-right: 0.25em;
}

#places-people-lore-info-modal .info-pct-0 { color: #94a3b8; }
#places-people-lore-info-modal .info-pct-25 { color: #60a5fa; }
#places-people-lore-info-modal .info-pct-50 { color: var(--accent); }
#places-people-lore-info-modal .info-pct-75 { color: #818cf8; }
#places-people-lore-info-modal .info-pct-100 { color: #a78bfa; }

#places-people-lore-info-modal .info-modal-item strong {
    color: var(--text-primary);
    font-weight: 600;
}

#places-people-lore-info-modal .info-modal-desc {
    font-weight: 400;
}

#places-people-lore-info-modal .info-modal-example {
    font-style: italic;
    color: var(--text-primary);
    opacity: 0.95;
}

/* Rich text: key terms with colour variation */
#places-people-lore-info-modal .info-modal-term-punctuation {
    color: #60a5fa;
    font-weight: 600;
}

#places-people-lore-info-modal .info-modal-term-spelling {
    color: #34d399;
    font-weight: 600;
}

#places-people-lore-info-modal .info-modal-term-comma {
    color: #a78bfa;
    font-weight: 500;
}

#places-people-lore-info-modal .info-modal-term-ref {
    color: var(--text-secondary);
    font-style: italic;
}

body.theme-light #places-people-lore-info-modal .info-modal-term-punctuation { color: #2563eb; }
body.theme-light #places-people-lore-info-modal .info-modal-term-spelling { color: #059669; }
body.theme-light #places-people-lore-info-modal .info-modal-term-comma { color: #7c3aed; }

/* Editorial style blocks (US / UK) – distinct background tints */
#places-people-lore-info-modal .info-modal-blocks {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

#places-people-lore-info-modal .info-modal-block {
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: 6px;
    border-left: 3px solid;
}

#places-people-lore-info-modal .info-modal-block-us {
    background: rgba(59, 130, 246, 0.12);
    border-left-color: #3b82f6;
}

#places-people-lore-info-modal .info-modal-block-uk {
    background: rgba(34, 197, 94, 0.12);
    border-left-color: #22c55e;
}

body.theme-light #places-people-lore-info-modal .info-modal-block-us {
    background: rgba(37, 99, 235, 0.08);
    border-left-color: #2563eb;
}

body.theme-light #places-people-lore-info-modal .info-modal-block-uk {
    background: rgba(5, 150, 105, 0.08);
    border-left-color: #059669;
}

#places-people-lore-info-modal .info-modal-block-title {
    font-weight: 700;
}

#places-people-lore-info-modal .info-modal-block-us .info-modal-block-title { color: #60a5fa; }
#places-people-lore-info-modal .info-modal-block-uk .info-modal-block-title { color: #34d399; }
body.theme-light #places-people-lore-info-modal .info-modal-block-us .info-modal-block-title { color: #2563eb; }
body.theme-light #places-people-lore-info-modal .info-modal-block-uk .info-modal-block-title { color: #059669; }

/* Labelled items (e.g. First person, Third person) */
#places-people-lore-info-modal .info-modal-label {
    color: var(--accent);
}

/* Light theme: darker percentage colors for contrast */
body.theme-light #places-people-lore-info-modal .info-pct-0 { color: #64748b; }
body.theme-light #places-people-lore-info-modal .info-pct-25 { color: #2563eb; }
body.theme-light #places-people-lore-info-modal .info-pct-50 { color: var(--accent); }
body.theme-light #places-people-lore-info-modal .info-pct-75 { color: #4f46e5; }
body.theme-light #places-people-lore-info-modal .info-pct-100 { color: #7c3aed; }

.custom-confirm-actions {
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: var(--spacing-sm);
    justify-content: flex-end;
}

.custom-confirm-actions .btn {
    min-width: auto !important;
    width: auto;
}

/* Character Creation Settings Form */
.character-creation-settings-form {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-xl) * 1.5);
    width: 100%;
}

.character-creation-settings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-lg);
}

.character-creation-settings-field {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    min-width: 0;
    overflow: visible;
}

.input-overflow-expand {
    display: none;
    position: fixed;
    z-index: 3600;
    margin: 0;
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--accent);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    line-height: 1.4;
    min-height: 2.4rem;
    max-height: 11rem;
    resize: none;
    overflow-y: auto;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    box-sizing: border-box;
}

.input-overflow-expand.is-open {
    display: block;
}

body.theme-light .input-overflow-expand {
    background-color: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.14);
}

.character-creation-settings-field-full {
    grid-column: 1 / -1;
}

.character-creation-settings-field label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
}

.character-race-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: var(--spacing-xs);
}

.character-race-label-row label {
    margin-bottom: 0;
}

.character-race-fantasy-index-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.85rem;
    height: 1.85rem;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 0.35rem;
    background: var(--bg-primary);
    color: var(--accent, #22c55e);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.character-race-fantasy-index-btn:hover,
.character-race-fantasy-index-btn:focus-visible {
    background: rgba(var(--accent-rgb, 45, 90, 125), 0.12);
    border-color: var(--accent);
    outline: none;
}

body.theme-light .character-race-fantasy-index-btn {
    color: #16a34a;
}

.character-creation-settings-field input[type="text"],
.character-creation-settings-field textarea,
.character-creation-settings-field select.character-creation-settings-select {
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: all 0.2s;
    width: 100%;
}

.character-creation-settings-field select.character-creation-settings-select {
    cursor: pointer;
    appearance: auto;
    min-height: 2.35rem;
}

/* Add Person / Location / Lore / Item: deeper field surfaces, quieter placeholders */
#character-modal .character-creation-settings-field input[type="text"],
#character-modal .character-creation-settings-field textarea,
#character-modal .character-creation-settings-field select.character-creation-settings-select,
#character-modal .character-modal-inline-textarea,
#character-modal .character-modal-inline-input,
#character-modal .character-appearance-inline-input,
#character-modal .character-appearance-inline-select,
#character-modal .character-name-inline-input,
#character-modal .character-modal-appearance-paragraph,
#character-modal .add-person-place-lore-left-panel .character-modal-biography-body,
#lore-modal .character-creation-settings-field input[type="text"],
#lore-modal .add-person-place-lore-name-input,
#lore-modal .add-person-place-lore-description-display,
#place-modal .character-creation-settings-field input[type="text"],
#place-modal .add-person-place-lore-name-input,
#place-modal .add-person-place-lore-description-display,
#item-modal .character-creation-settings-field input[type="text"],
#item-modal .add-person-place-lore-name-input,
#item-modal .add-person-place-lore-description-display {
    background-color: rgba(0, 0, 0, 0.22);
}

body.theme-light #character-modal .character-creation-settings-field input[type="text"],
body.theme-light #character-modal .character-creation-settings-field textarea,
body.theme-light #character-modal .character-creation-settings-field select.character-creation-settings-select,
body.theme-light #character-modal .character-modal-inline-textarea,
body.theme-light #character-modal .character-modal-inline-input,
body.theme-light #character-modal .character-appearance-inline-input,
body.theme-light #character-modal .character-appearance-inline-select,
body.theme-light #character-modal .character-name-inline-input,
body.theme-light #character-modal .character-modal-appearance-paragraph,
body.theme-light #character-modal .add-person-place-lore-left-panel .character-modal-biography-body,
body.theme-light #lore-modal .character-creation-settings-field input[type="text"],
body.theme-light #lore-modal .add-person-place-lore-name-input,
body.theme-light #lore-modal .add-person-place-lore-description-display,
body.theme-light #place-modal .character-creation-settings-field input[type="text"],
body.theme-light #place-modal .add-person-place-lore-name-input,
body.theme-light #place-modal .add-person-place-lore-description-display,
body.theme-light #item-modal .character-creation-settings-field input[type="text"],
body.theme-light #item-modal .add-person-place-lore-name-input,
body.theme-light #item-modal .add-person-place-lore-description-display {
    background-color: rgba(0, 0, 0, 0.04);
}

#character-modal input::placeholder,
#character-modal textarea::placeholder,
#lore-modal input::placeholder,
#place-modal input::placeholder,
#item-modal input::placeholder {
    color: rgba(255, 255, 255, 0.17);
    opacity: 1;
}

body.theme-light #character-modal input::placeholder,
body.theme-light #character-modal textarea::placeholder,
body.theme-light #lore-modal input::placeholder,
body.theme-light #place-modal input::placeholder,
body.theme-light #item-modal input::placeholder {
    color: rgba(0, 0, 0, 0.26);
    opacity: 1;
}

#character-modal input:focus:not(.character-suggestion-combo)::placeholder,
#character-modal textarea:focus:not(.character-suggestion-combo)::placeholder,
#lore-modal input:focus::placeholder,
#place-modal input:focus::placeholder,
#item-modal input:focus::placeholder {
    color: transparent;
    opacity: 0;
}

#character-modal input.character-suggestion-combo:focus::placeholder,
#character-modal textarea.character-suggestion-combo:focus::placeholder {
    color: rgba(255, 255, 255, 0.17);
    opacity: 1;
}

body.theme-light #character-modal input.character-suggestion-combo:focus::placeholder,
body.theme-light #character-modal textarea.character-suggestion-combo:focus::placeholder {
    color: rgba(0, 0, 0, 0.26);
    opacity: 1;
}

.add-person-place-lore-left-panel .add-person-place-lore-description-display.character-modal-biography-body[contenteditable="true"]:empty:before {
    color: rgba(255, 255, 255, 0.17);
    opacity: 1;
}

body.theme-light .add-person-place-lore-left-panel .add-person-place-lore-description-display.character-modal-biography-body[contenteditable="true"]:empty:before {
    color: rgba(0, 0, 0, 0.26);
    opacity: 1;
}

/* Select “Choose…” placeholder options — muted until a value is picked */
#character-modal select.character-modal-character-role-select:has(option[value=""]:checked),
#character-modal select.character-modal-hair-select:has(option[value=""]:checked),
#character-modal select.character-appearance-inline-select:has(option[value=""]:checked) {
    color: rgba(255, 255, 255, 0.17);
}

body.theme-light #character-modal select.character-modal-character-role-select:has(option[value=""]:checked),
body.theme-light #character-modal select.character-modal-hair-select:has(option[value=""]:checked),
body.theme-light #character-modal select.character-appearance-inline-select:has(option[value=""]:checked) {
    color: rgba(0, 0, 0, 0.26);
}

.character-modal-bio-count-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 0.35rem;
    flex-shrink: 0;
}

.character-bio-char-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.character-bio-char-count--at-limit {
    color: var(--accent);
}

.add-person-place-lore-left-panel .add-person-place-lore-description-display.character-modal-biography-body[contenteditable="true"]:focus:empty:before {
    content: none;
}

.character-creation-settings-field input[type="text"]:focus,
.character-creation-settings-field textarea:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.28);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
}

body.theme-light .character-creation-settings-field input[type="text"]:focus,
body.theme-light .character-creation-settings-field textarea:focus {
    border-color: rgba(0, 0, 0, 0.22);
    background-color: rgba(0, 0, 0, 0.045);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.character-creation-settings-field textarea {
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
}

@media (max-width: 1200px) {
    .character-creation-settings-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .character-creation-settings-grid {
        grid-template-columns: 1fr;
    }
}

/* Custom Suggestion Dropdown */
.character-suggestion-dropdown {
    position: absolute;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    z-index: 50000;
    margin-top: 2px;
}

.character-suggestion-item {
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.15s;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    overflow-wrap: break-word;
    word-break: break-word;
}

.character-suggestion-item:last-child {
    border-bottom: none;
}

.character-suggestion-group {
    padding: 0.45rem 0.75rem 0.25rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: color-mix(in srgb, var(--bg-primary) 86%, transparent);
}

.character-suggestion-item--rich {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.6rem;
}

.character-suggestion-item-title {
    font-weight: 600;
}

.character-suggestion-item-meta {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.character-suggestion-item:hover,
.character-suggestion-item.selected {
    background-color: var(--accent);
    color: var(--text-primary);
}

.character-suggestion-item:active {
    background-color: var(--accent-hover);
}

/* Scrollbar for suggestion dropdown */
.character-suggestion-dropdown::-webkit-scrollbar {
    width: 6px;
}

.character-suggestion-dropdown::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.character-suggestion-dropdown::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.character-suggestion-dropdown::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Name Ideas Button (place/lore/item modals + fallback) */
.name-ideas-btn {
    background-color: var(--accent);
    border: 1px solid var(--accent);
    color: #ffffff;
    padding: 0.4rem 0.65rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, filter 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.name-ideas-btn:hover {
    background-color: var(--accent-hover, #2d5a7d);
    border-color: var(--accent-hover, #2d5a7d);
    opacity: 1;
    filter: brightness(1.05);
}

/* Name List Modal */
.name-list-modal {
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    z-index: 5200;
}

.name-list-content {
    max-width: 1400px;
    width: 95%;
    min-height: 70vh;
    max-height: 90vh;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    font-family: var(--font-ui);
    border-radius: 12px;
    overflow: hidden;
    box-shadow:
        0 24px 48px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(124, 92, 250, 0.12);
}

.name-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.name-list-header-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    pointer-events: auto;
}

.name-list-header-center h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 500;
    text-align: center;
    pointer-events: none;
}

.name-list-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.name-list-type-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-primary);
}

/* .name-list-info-btn base + hover: shared with .brainstorm-info-icon above */

.name-list-type-nav {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
}

.name-list-type-nav svg {
    width: 18px;
    height: 18px;
    display: block;
    flex-shrink: 0;
}

.name-list-type-nav:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--accent);
    color: var(--accent);
}

.name-list-type-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-width: 120px;
}

.name-list-type-label {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
}

.name-list-type-info-btn {
    flex-shrink: 0;
}

.name-list-panels {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 400px);
    gap: 0;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

@media (max-width: 768px) {
    .name-list-modal {
        z-index: 5200;
        align-items: stretch;
        justify-content: stretch;
        padding: 0;
    }

    .name-list-content {
        width: 100%;
        max-width: none;
        min-height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .name-list-header {
        position: relative;
        padding: var(--spacing-sm) var(--spacing-md);
        gap: var(--spacing-sm);
    }

    .name-list-header-center {
        position: static;
        left: auto;
        transform: none;
        flex: 1;
        min-width: 0;
        pointer-events: auto;
    }

    .name-list-header-center h2 {
        pointer-events: auto;
        font-size: 1rem;
    }

    .name-list-header > div:last-child:empty {
        display: none;
    }

    .name-list-panels {
        grid-template-columns: 1fr;
        overflow: auto;
    }

    .name-list-filter-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: none;
        overflow: visible;
    }
}

.name-list-filter-panel {
    padding: 1rem 1.125rem 1.125rem;
    border-right: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.name-list-filter-panel h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    flex-shrink: 0;
}

/* Filter layout: basic row + collapsible Advanced section */
#name-list-filters-container {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.name-list-filters-basic,
.name-list-filters-advanced-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.625rem;
    align-items: stretch;
}

.name-list-filters-basic {
    flex-shrink: 0;
}

.name-list-filters-advanced {
    flex-shrink: 0;
}

.name-list-filters-advanced-summary {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.name-list-filters-advanced-summary::-webkit-details-marker {
    display: none;
}

.name-list-filters-advanced-chevron {
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
}

.name-list-filters-advanced[open] .name-list-filters-advanced-chevron {
    transform: rotate(180deg);
}

.name-list-filters-advanced-grid {
    margin-top: 0.625rem;
}

.name-list-filters-basic .name-list-filter-category,
.name-list-filters-advanced-grid .name-list-filter-category {
    min-height: 10.5rem;
}

.name-list-filter-category {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.625rem 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: auto;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

body.theme-light .name-list-filter-category {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.name-list-filter-category:hover {
    border-color: rgba(124, 92, 250, 0.45);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.04),
        0 0 0 1px rgba(124, 92, 250, 0.12);
}

body.theme-light .name-list-filter-category:hover {
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.65),
        0 0 0 1px rgba(124, 92, 250, 0.18);
}

.name-list-filter-category h4 {
    position: relative;
    margin: 0 0 0.5rem 0;
    padding-bottom: 0.5rem;
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    border-bottom: none;
}

.name-list-filter-category h4::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 1.75rem;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
    opacity: 0.9;
}

.name-list-filter-options {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.25rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 92, 250, 0.35) transparent;
}

.name-list-filter-options::-webkit-scrollbar {
    width: 5px;
}

.name-list-filter-options::-webkit-scrollbar-track {
    background: transparent;
}

.name-list-filter-options::-webkit-scrollbar-thumb {
    background: rgba(124, 92, 250, 0.28);
    border-radius: 100px;
}

.name-list-filter-options::-webkit-scrollbar-thumb:hover {
    background: rgba(124, 92, 250, 0.5);
}

.name-list-filter-option {
    cursor: pointer;
    padding: 0;
    border-radius: 6px;
    transition: background-color 0.15s ease;
}

.name-list-filter-option:hover {
    background-color: var(--bg-tertiary);
}

.name-list-filter-option-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.375rem 0.375rem 0.375rem 0.25rem;
    width: 100%;
    box-sizing: border-box;
    user-select: none;
    border-radius: 6px;
}

.name-list-filter-option input[type="checkbox"],
.name-list-filter-option input[type="radio"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.name-list-filter-option-label span {
    font-size: 0.8125rem;
    line-height: 1.35;
    color: var(--text-primary);
}

.name-list-filter-option:hover .name-list-filter-option-label span {
    color: var(--accent);
}

.name-list-results-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-secondary);
    min-width: 0;
}

.name-list-results-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding: 0.75rem 1.125rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    flex-shrink: 0;
}

.name-list-modal--auto-generate .name-list-generate-btn {
    display: none !important;
}

.name-list-results-header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.name-list-apply-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    background-color: var(--accent);
    color: var(--bg-primary, #fff);
    border: 1px solid var(--accent);
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, opacity 0.2s;
}

.name-list-apply-btn:hover {
    background-color: var(--accent-hover, #2d5a7d);
    border-color: var(--accent-hover, #2d5a7d);
    opacity: 0.95;
}

.name-list-results-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.name-list-generate-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    background-color: var(--accent);
    color: var(--bg-primary, #fff);
    border: 1px solid var(--accent);
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, opacity 0.2s;
}

.name-list-generate-btn:hover {
    background-color: var(--accent-hover, #2d5a7d);
    border-color: var(--accent-hover, #2d5a7d);
    opacity: 0.95;
}

.name-list-results {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 1.125rem;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 92, 250, 0.35) transparent;
}

.name-list-results::-webkit-scrollbar {
    width: 6px;
}

.name-list-results::-webkit-scrollbar-track {
    background: transparent;
}

.name-list-results::-webkit-scrollbar-thumb {
    background: rgba(124, 92, 250, 0.28);
    border-radius: 100px;
}

.name-list-results::-webkit-scrollbar-thumb:hover {
    background: rgba(124, 92, 250, 0.45);
}

/* Column layout for character First/Middle/Last name pairing */
.name-list-results-columns {
    flex-direction: row;
    gap: var(--spacing-md);
    align-items: stretch;
    overflow: visible;
}

.name-list-results.name-list-results-columns.name-list-results--busy {
    position: relative;
}

.name-list-results--busy .name-list-column-body {
    opacity: 0.55;
    transition: opacity 0.15s ease;
}

.name-list-results-busy-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(26, 27, 27, 0.72);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 2;
    pointer-events: none;
}

body.theme-light .name-list-results-busy-overlay {
    background: rgba(255, 255, 255, 0.78);
    color: var(--text-secondary);
}

.name-list-column {
    position: relative;
    z-index: 0;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: visible;
    background-color: var(--bg-primary);
}

.name-list-column:focus-within,
.name-list-column:hover {
    z-index: 3;
}

.name-list-column-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--bg-tertiary);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    border-radius: 6px 6px 0 0;
    overflow: visible;
}

.name-list-column-header-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.name-list-column-regenerate-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, border-color 0.2s;
}

.name-list-column-regenerate-btn svg {
    width: 16px;
    height: 16px;
    display: block;
}

.name-list-column-regenerate-btn:hover,
.name-list-column-regenerate-btn:focus-visible {
    color: var(--accent);
    border-color: rgba(124, 92, 250, 0.5);
    background: transparent;
}

.name-list-regen-tooltip {
    position: fixed;
    z-index: 12050;
    max-width: min(220px, 42vw);
    padding: 0.35rem 0.5rem;
    font-size: 0.72rem;
    line-height: 1.35;
    font-weight: 500;
    color: #fff;
    background: rgba(9, 11, 16, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
    pointer-events: none;
}

.name-list-regen-tooltip[hidden] {
    display: none !important;
}

body.theme-light .name-list-regen-tooltip {
    color: #fff;
    background: rgba(9, 11, 16, 0.96);
}

.name-list-compose-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    padding: 0.5rem 1.125rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    flex-shrink: 0;
}

.name-list-compose-bar[hidden] {
    display: none !important;
}

.name-list-compose-preview {
    font-size: 0.9rem;
    color: var(--text-secondary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.name-list-compose-use-btn {
    flex-shrink: 0;
    padding: var(--spacing-xs) var(--spacing-md);
    background-color: var(--accent);
    color: var(--bg-primary, #fff);
    border: 1px solid var(--accent);
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.name-list-compose-use-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.name-list-compose-use-btn:not(:disabled):hover {
    opacity: 0.92;
}

.name-list-column-body {
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    padding: var(--spacing-xs);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    border-radius: 0 0 6px 6px;
    background-color: var(--bg-primary);
}

.name-list-column-empty {
    padding: var(--spacing-lg);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.name-list-item.selected {
    background-color: rgba(74, 158, 255, 0.2);
    border-color: var(--accent);
    color: var(--accent);
}

.name-list-item.selected::after {
    content: '✓';
    margin-left: auto;
    font-weight: bold;
    color: var(--accent);
}

.name-list-item {
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.name-list-item[draggable="true"] {
    cursor: grab;
}

.name-list-item[draggable="true"]:active {
    cursor: grabbing;
}

.name-list-item.name-list-item--dragging {
    opacity: 0.45;
}

.name-list-column-body.name-list-column-body--drop-target {
    outline: 1px dashed rgba(124, 92, 250, 0.55);
    outline-offset: -2px;
    background: rgba(124, 92, 250, 0.06);
}

.name-list-item.name-list-item--drop-before {
    box-shadow: inset 0 2px 0 var(--accent);
}

.name-list-item.name-list-item--drop-after {
    box-shadow: inset 0 -2px 0 var(--accent);
}

.name-list-item:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateX(4px);
}

.name-list-placeholder,
.name-list-loading,
.name-list-error,
.name-list-empty {
    margin: auto;
    max-width: 20rem;
    padding: 1.75rem 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.55;
    border: 1px dashed rgba(124, 92, 250, 0.28);
    border-radius: 10px;
    background-color: var(--bg-primary);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

body.theme-light .name-list-placeholder,
body.theme-light .name-list-loading,
body.theme-light .name-list-error,
body.theme-light .name-list-empty {
    box-shadow: none;
    border-color: rgba(124, 92, 250, 0.22);
}

.name-list-placeholder {
    color: var(--text-secondary);
}

.name-list-loading {
    color: var(--text-secondary);
}

.name-list-error {
    color: var(--error);
    border-color: rgba(211, 47, 47, 0.35);
}

/* Word Finder Modal */
.word-finder-modal {
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    z-index: 4000;
}

.word-finder-content {
    max-width: 640px;
    width: 92%;
    min-height: 420px;
    max-height: 85vh;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    font-family: var(--font-ui);
    border-radius: 8px;
    overflow: hidden;
    box-shadow:
        0 24px 48px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(124, 92, 250, 0.12);
}

.word-finder-content > .word-finder-header.modal-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    min-height: 44px;
}

.word-finder-header h2 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: 1.05rem;
    font-weight: 500;
    text-align: center;
    pointer-events: none;
    white-space: nowrap;
}

.word-finder-header-spacer {
    width: 72px;
    flex-shrink: 0;
    visibility: hidden;
}

.word-finder-back-btn.modal-back-btn {
    position: relative;
    z-index: 1;
    margin-right: 0;
    background-color: #305da4;
    border-color: #305da4;
}

.word-finder-back-btn.modal-back-btn:hover {
    background-color: #28528f;
    border-color: #28528f;
    color: #fff;
}

.word-finder-body {
    padding: var(--spacing-md) var(--spacing-lg) var(--spacing-lg);
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.word-finder-lead {
    margin: 0 0 var(--spacing-md);
    color: var(--text-secondary);
    font-size: 0.95rem;
    text-align: center;
}

.word-finder-search-row {
    margin-bottom: var(--spacing-md);
}

.word-finder-input-wrap {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 0.55rem var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background-color: var(--bg-primary);
}

.word-finder-input-icon {
    display: inline-flex;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.word-finder-input-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

.word-finder-input {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.95rem;
    padding: 0;
    min-width: 0;
}

.word-finder-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.3;
}

body.theme-light .word-finder-input::placeholder {
    opacity: 0.35;
}

.word-finder-input:focus {
    outline: none;
}

.word-finder-search-btn {
    display: block;
    margin: 0 auto var(--spacing-lg);
    min-width: 132px;
    padding: 0.55rem var(--spacing-xl);
    border: 1px solid #305da4;
    border-radius: 999px;
    background-color: #305da4;
    color: #fff;
    font-size: 0.95rem;
    cursor: pointer;
}

.word-finder-search-btn:hover:not(:disabled) {
    background-color: #28528f;
    border-color: #28528f;
}

.word-finder-search-btn:disabled {
    opacity: 0.75;
    cursor: wait;
}

.word-finder-results {
    flex: 1;
    min-height: 180px;
}

.word-finder-results-label {
    margin: 0 0 var(--spacing-sm);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.word-finder-words-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(var(--word-finder-cols, 3), minmax(0, 1fr));
    grid-auto-flow: column;
    grid-template-rows: repeat(var(--word-finder-rows, 5), minmax(1.75rem, auto));
    gap: var(--spacing-xs) var(--spacing-lg);
    min-height: 9rem;
}

.word-finder-word-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.92rem;
    text-align: left;
    cursor: pointer;
}

.word-finder-word-btn:hover {
    color: #5a8fd4;
}

.word-finder-word-btn:hover .word-finder-word-bullet {
    color: #5a8fd4;
}

.word-finder-word-bullet {
    color: var(--text-secondary);
    flex-shrink: 0;
    line-height: 1;
}

.word-finder-word-text {
    min-width: 0;
}

.word-finder-word-placeholder {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 1.75rem;
}

.word-finder-word-placeholder .word-finder-word-bullet {
    opacity: 0.28;
}

.word-finder-placeholder-text {
    color: var(--text-secondary);
    opacity: 0.3;
    font-size: 0.92rem;
}

body.theme-light .word-finder-placeholder-text {
    opacity: 0.35;
}

.word-finder-words-list--loading .word-finder-word-placeholder {
    opacity: 0.5;
}

.word-finder-words-list--loading .word-finder-placeholder-text {
    opacity: 0.4;
}

.word-finder-empty,
.word-finder-error {
    grid-column: 1 / -1;
    padding: var(--spacing-md) 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.word-finder-error {
    color: var(--error);
}

@media (max-width: 640px) {
    .word-finder-words-list {
        --word-finder-cols: 1;
        --word-finder-rows: auto;
        grid-template-columns: 1fr;
        grid-auto-flow: row;
        grid-template-rows: none;
    }
}

/* Dictionary Modal */
.dictionary-modal {
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    z-index: 4000;
}

.dictionary-content {
    max-width: 640px;
    width: 92%;
    min-height: 420px;
    max-height: 85vh;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    font-family: var(--font-ui);
    border-radius: 8px;
    overflow: hidden;
    box-shadow:
        0 24px 48px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(124, 92, 250, 0.12);
}

.dictionary-content > .dictionary-header.modal-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    min-height: 44px;
}

.dictionary-header h2 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: 1.05rem;
    font-weight: 500;
    text-align: center;
    pointer-events: none;
    white-space: nowrap;
}

.dictionary-header-spacer {
    width: 72px;
    flex-shrink: 0;
    visibility: hidden;
}

.dictionary-back-btn.modal-back-btn {
    position: relative;
    z-index: 1;
    margin-right: 0;
    background-color: #305da4;
    border-color: #305da4;
}

.dictionary-back-btn.modal-back-btn:hover {
    background-color: #28528f;
    border-color: #28528f;
    color: #fff;
}

.dictionary-body {
    padding: var(--spacing-md) var(--spacing-lg) var(--spacing-lg);
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.dictionary-sources {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    width: 100%;
    margin: 0 0 var(--spacing-md);
}

.dictionary-sense {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    width: 100%;
    margin: calc(var(--spacing-md) * -0.5) 0 var(--spacing-md);
}

.dictionary-sense[hidden] {
    display: none;
}

.dictionary-source-btn {
    flex: 0 1 auto;
    min-width: 5.5rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    padding: 0.4rem 0.9rem;
    font-size: 0.82rem;
    cursor: pointer;
}

.dictionary-source-btn.is-active {
    background: #305da4;
    border-color: #305da4;
    color: #fff;
}

.dictionary-source-btn:hover:not(.is-active) {
    color: var(--text-primary);
}

.dictionary-sense-btn {
    min-width: 0;
    padding: 0.22rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.dictionary-sense-btn.is-active {
    background: transparent;
    border-color: #5a8fd4;
    color: #7eb0e8;
}

.dictionary-sense-btn:hover:not(.is-active) {
    color: var(--text-primary);
}

body.theme-light .dictionary-sense-btn.is-active {
    border-color: #305da4;
    color: #305da4;
}

.dictionary-sources--many .dictionary-source-btn {
    min-width: 0;
    padding: 0.35rem 0.8rem;
}

.dictionary-search-row {
    margin-bottom: var(--spacing-md);
}

.dictionary-input-wrap {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 0.55rem var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background-color: var(--bg-primary);
}

.dictionary-input-icon {
    display: inline-flex;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.dictionary-input-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

.dictionary-input {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.95rem;
    padding: 0;
    min-width: 0;
}

.dictionary-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.3;
}

body.theme-light .dictionary-input::placeholder {
    opacity: 0.35;
}

.dictionary-input:focus {
    outline: none;
}

.dictionary-results {
    flex: 1;
    min-height: 180px;
}

.dictionary-results-label {
    margin: 0 0 var(--spacing-sm);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.dictionary-words-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(var(--dictionary-cols, 3), minmax(0, 1fr));
    grid-auto-flow: column;
    grid-template-rows: repeat(var(--dictionary-rows, 5), minmax(1.75rem, auto));
    gap: var(--spacing-xs) var(--spacing-lg);
    min-height: 9rem;
}

.dictionary-word-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.92rem;
    text-align: left;
    cursor: pointer;
}

.dictionary-word-btn:hover {
    color: #5a8fd4;
}

.dictionary-word-btn:hover .dictionary-word-bullet {
    color: #5a8fd4;
}

.dictionary-word-bullet {
    color: var(--text-secondary);
    flex-shrink: 0;
    line-height: 1;
}

.dictionary-empty,
.dictionary-error {
    padding: var(--spacing-md) 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.dictionary-error {
    color: var(--error);
}

.dictionary-section + .dictionary-section,
.dictionary-entries + .dictionary-section {
    margin-top: var(--spacing-md);
}

.dictionary-entry + .dictionary-entry {
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

.dictionary-entry-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.15rem;
}

.dictionary-entry-icon {
    display: inline-flex;
    color: #5a8fd4;
    flex-shrink: 0;
}

.dictionary-entry-icon svg {
    width: 20px;
    height: 20px;
    display: block;
}

.dictionary-entry-word {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-brand);
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
    cursor: pointer;
}

.dictionary-entry-word:hover {
    color: #5a8fd4;
}

.dictionary-entry-phonetic {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.dictionary-meaning + .dictionary-meaning {
    margin-top: 0.75rem;
}

.dictionary-pos-badge {
    display: inline-block;
    margin: 0.35rem 0 0.1rem;
    padding: 0.12rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-style: normal;
    letter-spacing: 0.02em;
    text-transform: lowercase;
}

.dictionary-pos-badge--noun {
    color: #7eb0e8;
    background: rgba(90, 143, 212, 0.16);
}

.dictionary-pos-badge--verb {
    color: #7ec9a0;
    background: rgba(107, 179, 138, 0.18);
}

.dictionary-pos-badge--adjective {
    color: #d4b56a;
    background: rgba(196, 163, 90, 0.18);
}

.dictionary-pos-badge--adverb {
    color: #b89ad4;
    background: rgba(155, 123, 184, 0.18);
}

.dictionary-pos-badge--other {
    color: var(--text-secondary);
    background: rgba(128, 128, 128, 0.14);
}

.dictionary-def-list {
    margin: 0.35rem 0 0;
    padding: 0 0 0 1.2rem;
}

.dictionary-def-list li {
    margin: 0 0 0.5rem;
}

.dictionary-def-list li::marker {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.dictionary-def {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.45;
    color: var(--text-primary);
}

.dictionary-example {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    margin: 0.25rem 0 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
    line-height: 1.4;
}

.dictionary-example-icon {
    display: inline-flex;
    flex-shrink: 0;
    opacity: 0.55;
    margin-top: 0.12rem;
}

.dictionary-example-icon svg {
    width: 13px;
    height: 13px;
    display: block;
}

.dictionary-attribution {
    margin: var(--spacing-md) 0 0;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.dictionary-word-placeholder {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 1.75rem;
}

.dictionary-word-placeholder .dictionary-word-bullet {
    opacity: 0.28;
}

.dictionary-placeholder-text {
    color: var(--text-secondary);
    opacity: 0.3;
    font-size: 0.92rem;
}

body.theme-light .dictionary-placeholder-text {
    opacity: 0.35;
}

.dictionary-results--example .dictionary-results-label,
.dictionary-results--example .dictionary-entry-word,
.dictionary-results--example .dictionary-entry-icon,
.dictionary-results--example .dictionary-pos-badge,
.dictionary-results--example .dictionary-def,
.dictionary-results--example .dictionary-example {
    color: var(--text-secondary);
    opacity: 0.35;
}

.dictionary-results--example .dictionary-entry-word {
    cursor: default;
    font-weight: 600;
}

@media (max-width: 640px) {
    .dictionary-words-list {
        --dictionary-cols: 1;
        --dictionary-rows: auto;
        grid-template-columns: 1fr;
        grid-auto-flow: row;
        grid-template-rows: none;
    }
}

/* AI Assistant — Ask anything */
#ai-ask-anything-btn {
    background-color: #7b4bb7;
    border-color: #7b4bb7;
    margin-bottom: var(--spacing-md);
    margin-left: auto;
    margin-right: auto;
}

#ai-ask-anything-btn:hover {
    background-color: #6a3fa3;
    border-color: #6a3fa3;
    color: #fff;
}

/* Write-page tool list: color on icons, not candy fills */
#ai-tools-sidebar .ai-tool-section {
    align-items: stretch;
}

#ai-tools-sidebar .ai-tool-section-header {
    justify-content: flex-start;
    min-height: 0;
    padding: 0.15rem 0.4rem 0.2rem;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    opacity: 0.7;
}

#ai-tools-sidebar .ai-tool-section-header-encyclopedai {
    text-transform: none;
    letter-spacing: 0.04em;
}

#ai-tools-sidebar .ai-tool-section-header .ai-tool-icon-wrap {
    display: none;
}

#ai-tools-sidebar .ai-tool-section + .ai-tool-divider {
    display: none;
}

#ai-tools-sidebar .ai-tool-divider {
    margin: 0.55rem 0;
}

#ai-tools-sidebar .ai-tool-write-actions-block,
#ai-tools-sidebar .ai-tool-buttons-group {
    align-items: stretch;
    width: 100%;
    margin-top: 0.15rem;
    gap: 1px;
}

#ai-tools-sidebar .ai-tool-btn,
#ai-tools-sidebar .ai-tool-write-actions-block .ai-tool-action-grammar.ai-tool-btn,
#ai-tools-sidebar .ai-tool-buttons-group .ai-tool-btn,
#ai-tools-sidebar #ai-characters-references-btn.ai-tool-btn-characters,
#ai-tools-sidebar #ai-story-board-btn.ai-tool-btn-mind-map,
#ai-tools-sidebar #ai-character-maps-btn.ai-tool-btn-relationships,
#ai-tools-sidebar #ai-location-btn,
#ai-tools-sidebar #ai-lore-btn,
#ai-tools-sidebar #ai-items-btn,
#ai-tools-sidebar #ai-voice-actions-btn,
#ai-tools-sidebar #ai-add-people-places-lore-btn,
#ai-tools-sidebar #ai-brainstorm-btn,
#ai-tools-sidebar #story-brainstorm-btn,
#ai-tools-sidebar #ai-name-ideas-btn,
#ai-tools-sidebar #ai-word-finder-btn,
#ai-tools-sidebar #ai-dictionary-btn,
#ai-tools-sidebar #ai-ask-anything-btn,
#ai-tools-sidebar #ai-fantasy-index-btn.ai-tool-btn-fantasy-index {
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0.38rem 0.4rem;
    background: transparent;
    border: 0;
    border-radius: 0;
    color: var(--text-primary);
    justify-content: flex-start;
    text-align: left;
    gap: 0.5rem;
}

#ai-tools-sidebar .ai-tool-btn:hover,
#ai-tools-sidebar .ai-tool-write-actions-block .ai-tool-action-grammar.ai-tool-btn:hover,
#ai-tools-sidebar #ai-characters-references-btn.ai-tool-btn-characters:hover,
#ai-tools-sidebar #ai-location-btn:hover,
#ai-tools-sidebar #ai-lore-btn:hover,
#ai-tools-sidebar #ai-items-btn:hover,
#ai-tools-sidebar #ai-story-board-btn.ai-tool-btn-mind-map:hover,
#ai-tools-sidebar #ai-voice-actions-btn:hover,
#ai-tools-sidebar #ai-brainstorm-btn:hover,
#ai-tools-sidebar #story-brainstorm-btn:hover,
#ai-tools-sidebar #ai-name-ideas-btn:hover,
#ai-tools-sidebar #ai-word-finder-btn:hover,
#ai-tools-sidebar #ai-dictionary-btn:hover,
#ai-tools-sidebar #ai-ask-anything-btn:hover,
#ai-tools-sidebar #ai-fantasy-index-btn.ai-tool-btn-fantasy-index:hover {
    background: rgba(255, 255, 255, 0.06);
    border: 0;
    color: var(--text-primary);
}

#ai-tools-sidebar .ai-tool-btn.active,
#ai-tools-sidebar .ai-tool-btn.active:hover {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    box-shadow: inset 2px 0 0 var(--accent);
    color: var(--text-primary);
}

#ai-tools-sidebar .ai-tool-btn .ai-tool-icon-cell {
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 1.25rem;
}

#ai-tools-sidebar .ai-tool-btn .ai-tool-icon-cell,
#ai-tools-sidebar .ai-tool-btn .ai-tool-icon-cell svg,
#ai-tools-sidebar .ai-tool-btn .ai-tool-icon-cell i {
    color: inherit;
}

#ai-tools-sidebar .ai-tool-btn .ai-tool-btn-label,
#ai-tools-sidebar .ai-tool-btn .ai-tool-btn-text-multiline {
    color: var(--text-primary);
    flex: 0 1 auto;
    text-align: left;
}

#ai-tools-sidebar #ai-grammar-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-grammar-btn .ai-tool-icon-cell svg {
    color: #e8b84a;
}

#ai-tools-sidebar #ai-characters-references-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-characters-references-btn .ai-tool-icon-cell svg {
    color: #83b25e;
}

#ai-tools-sidebar #ai-story-board-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-story-board-btn .ai-tool-icon-cell svg {
    color: #5bd1bc;
}

#ai-tools-sidebar #ai-character-maps-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-character-maps-btn .ai-tool-icon-cell svg {
    color: #e07a9a;
}

#ai-tools-sidebar #ai-location-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-location-btn .ai-tool-icon-cell svg {
    color: #e0a15a;
}

#ai-tools-sidebar #ai-lore-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-lore-btn .ai-tool-icon-cell svg {
    color: #c48ae0;
}

#ai-tools-sidebar #ai-items-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-items-btn .ai-tool-icon-cell svg {
    color: #d4c35a;
}

#ai-tools-sidebar #ai-voice-actions-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-voice-actions-btn .ai-tool-icon-cell svg {
    color: #7ea2f5;
}

#ai-tools-sidebar #ai-brainstorm-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-brainstorm-btn .ai-tool-icon-cell svg,
#ai-tools-sidebar #story-brainstorm-btn .ai-tool-icon-cell,
#ai-tools-sidebar #story-brainstorm-btn .ai-tool-icon-cell svg {
    color: #f08a5a;
}

#ai-tools-sidebar #ai-name-ideas-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-name-ideas-btn .ai-tool-icon-cell svg {
    color: #5ac48a;
}

#ai-tools-sidebar #ai-word-finder-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-word-finder-btn .ai-tool-icon-cell svg,
#ai-tools-sidebar #ai-dictionary-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-dictionary-btn .ai-tool-icon-cell svg {
    color: #7ea2f5;
}

#ai-tools-sidebar #ai-ask-anything-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-ask-anything-btn .ai-tool-icon-cell svg {
    color: #9b7cff;
}

#ai-tools-sidebar #ai-fantasy-index-btn .ai-tool-icon-cell,
#ai-tools-sidebar #ai-fantasy-index-btn .ai-tool-icon-cell i,
#ai-tools-sidebar #ai-fantasy-index-btn .ai-tool-icon-cell svg {
    color: #7b52c4;
}

body.theme-light #ai-tools-sidebar .ai-tool-btn:hover,
body.theme-light #ai-tools-sidebar .ai-tool-write-actions-block .ai-tool-action-grammar.ai-tool-btn:hover,
body.theme-light #ai-tools-sidebar #ai-characters-references-btn.ai-tool-btn-characters:hover,
body.theme-light #ai-tools-sidebar #ai-location-btn:hover,
body.theme-light #ai-tools-sidebar #ai-lore-btn:hover,
body.theme-light #ai-tools-sidebar #ai-items-btn:hover,
body.theme-light #ai-tools-sidebar #ai-story-board-btn.ai-tool-btn-mind-map:hover,
body.theme-light #ai-tools-sidebar #ai-brainstorm-btn:hover,
body.theme-light #ai-tools-sidebar #story-brainstorm-btn:hover,
body.theme-light #ai-tools-sidebar #ai-name-ideas-btn:hover,
body.theme-light #ai-tools-sidebar #ai-word-finder-btn:hover,
body.theme-light #ai-tools-sidebar #ai-dictionary-btn:hover,
body.theme-light #ai-tools-sidebar #ai-ask-anything-btn:hover,
body.theme-light #ai-tools-sidebar #ai-fantasy-index-btn.ai-tool-btn-fantasy-index:hover {
    background: rgba(0, 0, 0, 0.05);
}

.ai-assistant-modal {
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    z-index: 4000;
}

.ai-assistant-content {
    max-width: 980px;
    width: min(94vw, 980px);
    height: min(88vh, 760px);
    min-height: 520px;
    max-height: 88vh;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: row;
    font-family: var(--font-ui);
    border-radius: 8px;
    overflow: hidden;
    box-shadow:
        0 24px 48px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(123, 75, 183, 0.15);
    padding: 0;
    position: relative;
}

.ai-assistant-content.modal-content {
    padding: 0;
    overflow: hidden;
    max-width: 980px;
}

.ai-assistant-sidebar {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: var(--spacing-sm);
    background-color: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    min-height: 0;
}

.ai-assistant-sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.ai-assistant-new-chat-btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 0.65rem;
    border: 1px solid rgba(123, 75, 183, 0.45);
    background-color: #7b4bb7;
    color: #fff;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
}

.ai-assistant-new-chat-btn:hover:not(:disabled) {
    background-color: #6a3fa3;
    border-color: #6a3fa3;
}

.ai-assistant-new-chat-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ai-assistant-new-chat-btn svg {
    flex-shrink: 0;
}

.ai-assistant-call-btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 0.65rem;
    border: 1px solid #2b8a86;
    background-color: #2b8a86;
    color: #fff;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
}

.ai-assistant-call-btn:hover:not(:disabled) {
    background-color: #247875;
    border-color: #247875;
    color: #fff;
}

.ai-assistant-call-btn.is-active {
    background-color: var(--error);
    border-color: var(--error);
    color: #fff;
}

.ai-assistant-call-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ai-assistant-call-btn svg {
    flex-shrink: 0;
}

.ai-assistant-sidebar-label {
    padding: 0.35rem 0.35rem 0;
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ai-assistant-msg[data-persona="writer"] .ai-assistant-msg-who,
.ai-assistant-companion-assistant[data-persona="writer"] .ai-assistant-msg-who {
    color: #e17055;
}

.ai-assistant-msg[data-persona="architect"] .ai-assistant-msg-who,
.ai-assistant-companion-assistant[data-persona="architect"] .ai-assistant-msg-who {
    color: #2b8a86;
}

.ai-assistant-msg[data-persona="assistant"] .ai-assistant-msg-who,
.ai-assistant-companion-assistant[data-persona="assistant"] .ai-assistant-msg-who {
    color: #7b4bb7;
}

.ai-assistant-persona-blurb {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.72rem;
    line-height: 1.35;
}

.ai-assistant-chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.ai-assistant-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ai-assistant-content > .ai-assistant-header.modal-header,
.ai-assistant-main > .ai-assistant-header.modal-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    min-height: 44px;
    flex-shrink: 0;
}

.ai-assistant-header h2 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: 1.05rem;
    font-weight: 500;
    text-align: center;
    pointer-events: none;
    white-space: nowrap;
}

.ai-assistant-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 76px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.ai-assistant-back-btn.modal-back-btn {
    position: relative;
    z-index: 1;
    margin-right: 0;
    background-color: #7b4bb7;
    border-color: #7b4bb7;
}

.ai-assistant-back-btn.modal-back-btn:hover {
    background-color: #6a3fa3;
    border-color: #6a3fa3;
    color: #fff;
}

.ai-assistant-history-empty {
    margin: 0;
    padding: 0.65rem 0.5rem;
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.4;
}

.ai-assistant-history-row {
    position: relative;
    width: 100%;
}

.ai-assistant-history-item {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    text-align: left;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    padding: 0.55rem 1.7rem 0.55rem 0.55rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.35;
    border-radius: 6px;
}

.ai-assistant-history-delete {
    position: absolute;
    top: 50%;
    right: 0.3rem;
    transform: translateY(-50%);
    width: 1.4rem;
    height: 1.4rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
}

.ai-assistant-history-row:hover .ai-assistant-history-delete,
.ai-assistant-history-row.is-reveal .ai-assistant-history-delete {
    opacity: 1;
    pointer-events: auto;
}

.ai-assistant-history-delete:hover {
    color: var(--text-primary);
}

.ai-assistant-history-item:hover {
    background-color: rgba(123, 75, 183, 0.16);
}

.ai-assistant-history-item.is-active {
    background-color: rgba(123, 75, 183, 0.22);
}

.ai-assistant-history-item-title {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-assistant-history-item-meta {
    color: var(--text-secondary);
    font-size: 0.72rem;
}

.ai-assistant-body.modal-body {
    margin-top: 0;
}

.ai-assistant-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.ai-assistant-thread-wrap {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.ai-assistant-thread {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    box-sizing: border-box;
}

.ai-assistant-thread:not(.ai-assistant-thread--empty) {
    justify-content: flex-end;
}

.ai-assistant-thread--empty {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.ai-assistant-thread-empty {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
    margin: 0;
    max-width: 22rem;
}

.ai-assistant-msg {
    display: flex;
    flex-direction: column;
}

.ai-assistant-msg-meta {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.28rem;
    color: var(--text-secondary);
}

.ai-assistant-msg-who {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.ai-assistant-msg-meta .ai-assistant-persona-thumb {
    width: 14px;
    height: 14px;
}

.ai-assistant-msg--user {
    align-items: flex-end;
}

.ai-assistant-msg--live .ai-assistant-msg-body {
    opacity: 0.8;
}

.ai-assistant-msg--assistant .ai-assistant-msg-body {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 14px 14px 14px 4px;
    padding: 0.65rem 0.9rem;
    max-width: 100%;
    white-space: normal;
}

.ai-assistant-msg-body {
    font-size: 0.92rem;
    line-height: 1.55;
    word-break: break-word;
    color: var(--text-primary);
}

.ai-assistant-msg--user .ai-assistant-msg-body {
    background-color: rgba(123, 75, 183, 0.22);
    border: 1px solid rgba(123, 75, 183, 0.4);
    border-radius: 14px 14px 4px 14px;
    max-width: 85%;
    padding: 0.55rem 0.85rem;
    white-space: pre-wrap;
}

.ai-assistant-p,
.ai-assistant-h {
    margin: 0 0 0.45rem;
}

.ai-assistant-p:last-child,
.ai-assistant-h:last-child {
    margin-bottom: 0;
}

.ai-assistant-h {
    font-size: 0.92rem;
    font-weight: 600;
    font-style: normal;
}

.ai-assistant-list {
    margin: 0 0 0.55rem;
    padding-left: 1.15rem;
}

.ai-assistant-list--ol {
    padding-left: 1.25rem;
}

.ai-assistant-list:last-child {
    margin-bottom: 0;
}

.ai-assistant-list li {
    margin-bottom: 0.25rem;
}

.ai-assistant-list li:last-child {
    margin-bottom: 0;
}

.ai-assistant-p strong,
.ai-assistant-h strong,
.ai-assistant-list strong {
    font-weight: 600;
    color: var(--text-primary);
}

.ai-assistant-p em,
.ai-assistant-list em {
    font-style: italic;
}

.ai-assistant-speak-btn {
    align-self: flex-start;
    margin-top: 0.25rem;
    width: 1.6rem;
    height: 1.6rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ai-assistant-speak-btn:hover,
.ai-assistant-speak-btn.needs-play,
.ai-assistant-speak-btn.is-playing {
    color: #7b4bb7;
}

.ai-assistant-msg--loading {
    align-self: flex-start;
}

.ai-assistant-msg--loading .ai-assistant-msg-body {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 14px 14px 14px 4px;
    padding: 0.55rem 0.85rem;
    color: var(--text-secondary);
    font-style: normal;
    white-space: nowrap;
}

.ai-assistant-typing {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.ai-assistant-typing span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: var(--text-secondary);
    opacity: 0.45;
    animation: ai-assistant-typing 1.2s infinite ease-in-out;
}

.ai-assistant-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.ai-assistant-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes ai-assistant-typing {
    0%, 80%, 100% {
        opacity: 0.35;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

.ai-assistant-typing-label {
    font-size: 0.88rem;
}

.ai-assistant-compose {
    flex-shrink: 0;
    padding: var(--spacing-sm) var(--spacing-md) var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

.ai-assistant-input-wrap {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    min-height: 44px;
    padding: 0.2rem 0.3rem 0.2rem 0.3rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background-color: var(--bg-primary);
}

.ai-assistant-compose-persona {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding-right: 0.25rem;
    margin-right: 0.05rem;
    border-right: 1px solid var(--border-color);
}

.ai-assistant-persona-step {
    width: 16px;
    height: 32px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ai-assistant-persona-step:hover,
.ai-assistant-persona-step:focus-visible {
    color: var(--text-primary);
    outline: none;
}

.ai-assistant-persona-now {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    max-width: 8rem;
    padding: 0.1rem 0.05rem;
    border: 0;
    background: transparent;
    color: inherit;
    font-family: inherit;
    text-align: left;
    cursor: default;
}

.ai-assistant-persona-now-head {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    min-width: 0;
    max-width: 100%;
}

.ai-assistant-persona-now-head .ai-assistant-persona-thumb {
    width: 12px;
    height: 12px;
}

.ai-assistant-persona-now-name {
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.15;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.ai-assistant-persona-now-skills {
    font-size: 0.68rem;
    line-height: 1.2;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.ai-assistant-persona-tip {
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    z-index: 5400;
    width: 16.5rem;
    padding: 0.5rem 0.65rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
}

.ai-assistant-persona-tip strong {
    display: block;
    font-size: 0.84rem;
    margin-bottom: 0.2rem;
}

.ai-assistant-persona-tip p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.78rem;
    line-height: 1.35;
}

.ai-assistant-input-wrap:focus-within {
    border-color: rgba(123, 75, 183, 0.55);
}

.ai-assistant-input {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.35;
    padding: 0.45rem 0;
    min-width: 0;
    min-height: 1.35rem;
    max-height: 120px;
    resize: none;
    overflow-y: auto;
    vertical-align: middle;
}

.ai-assistant-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.75;
}

.ai-assistant-input:focus {
    outline: none;
}

.ai-assistant-mic-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ai-assistant-mic-btn svg {
    display: block;
}

.ai-assistant-mic-btn:hover:not(:disabled) {
    color: #7b4bb7;
}

.ai-assistant-mic-btn.is-listening {
    color: #fff;
    background-color: #7b4bb7;
}

.ai-assistant-mic-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ai-assistant-hangup-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ai-assistant-hangup-btn:hover:not(.is-active) {
    color: #2b8a86;
}

.ai-assistant-hangup-btn.is-active {
    background-color: var(--error);
    color: #fff;
}

.ai-assistant-hangup-btn.is-active:hover {
    background-color: #b71c1c;
}

.ai-assistant-hangup-btn svg {
    display: block;
}

.ai-assistant-send-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: #7b4bb7;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ai-assistant-send-btn svg {
    display: block;
}

.ai-assistant-send-btn:hover:not(:disabled) {
    background-color: #6a3fa3;
}

.ai-assistant-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ai-assistant-error {
    flex-shrink: 0;
    color: #e06060;
    font-size: 0.82rem;
    padding: 0 var(--spacing-md) var(--spacing-xs);
    margin: 0;
}

.ai-assistant-companion {
    position: fixed;
    left: 50%;
    bottom: calc(var(--editor-stats-height, 42px) + 0.75rem);
    transform: translateX(-50%);
    z-index: 4300;
    pointer-events: auto;
    width: min(22rem, calc(100vw - 2rem));
    padding: 0.55rem 0.7rem 0.7rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.ai-assistant-companion[hidden] {
    display: none !important;
}

.ai-assistant-companion.is-modal-open {
    display: none !important;
}

.editor-stats .ai-assistant-companion {
    position: static;
    left: auto;
    bottom: auto;
    transform: none;
    z-index: auto;
    width: auto;
    padding: 0;
    border: 0;
    background: transparent;
}

#ai-tools-sidebar .ai-assistant-companion {
    position: relative;
    left: auto;
    bottom: auto;
    transform: none;
    z-index: 2;
    width: 100%;
    flex: 0 0 auto;
    padding: 0.45rem 0.55rem 0.7rem;
    border: 0;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

#ai-tools-sidebar .ai-assistant-companion:not(.is-active) .ai-assistant-companion-bubbles,
#ai-tools-sidebar .ai-assistant-companion .ai-assistant-companion-fold,
#ai-tools-sidebar .ai-assistant-companion .ai-assistant-picks {
    display: none;
}

#ai-tools-sidebar .ai-assistant-companion.is-active .ai-assistant-companion-bubbles {
    display: flex;
    max-height: min(36vh, 16rem);
    overflow-y: auto;
}

#ai-tools-sidebar .ai-assistant-companion-controls {
    justify-content: center;
}

#ai-tools-sidebar .ai-assistant-companion-hangup,
#ai-tools-sidebar .ai-assistant-companion-mic {
    width: 44px;
    height: 44px;
    box-shadow: none;
}

#ai-tools-sidebar .ai-assistant-companion:not(.is-active) .ai-assistant-companion-hangup {
    background-color: #2b8a86;
    color: #fff;
}

#ai-tools-sidebar .ai-assistant-companion:not(.is-active) .ai-assistant-companion-hangup:hover {
    background-color: #247875;
}

.ai-assistant-companion-dock {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    pointer-events: auto;
    cursor: default;
    touch-action: auto;
    overflow: visible;
}

.ai-assistant-companion-dock button,
.ai-assistant-companion-dock select {
    cursor: pointer;
}

.ai-assistant-companion-dock.is-collapsed .ai-assistant-companion-bubbles,
.ai-assistant-companion-dock.is-collapsed .ai-assistant-picks {
    display: none;
}

.ai-assistant-companion-fold {
    width: 32px;
    height: 18px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-assistant-companion-fold:hover,
.ai-assistant-companion-fold:focus-visible {
    color: var(--text-primary);
    outline: none;
}

.ai-assistant-companion-fold svg {
    display: block;
}

.ai-assistant-companion-dock.is-collapsed .ai-assistant-companion-fold svg {
    transform: rotate(180deg);
}

.ai-assistant-companion-dock .ai-assistant-picks {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 1rem;
    white-space: nowrap;
}

.ai-assistant-pick-field {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.12rem;
}

.ai-assistant-companion-dock .ai-assistant-persona-trigger {
    height: auto;
    font-size: 0.75rem;
    color: var(--text-primary);
}

.ai-assistant-companion-dock .ai-assistant-persona-thumb {
    width: 28px;
    height: 28px;
}

.ai-assistant-companion-dock .ai-assistant-persona-caret {
    margin-left: 0.15rem;
}

.ai-assistant-pick-kind {
    color: var(--text-secondary);
    font-size: 0.68rem;
    line-height: 1;
}

.ai-assistant-voice-wrap,
.ai-assistant-voice-dd {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    position: relative;
}

.ai-assistant-companion-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-assistant-voice-select,
.ai-assistant-voice-trigger {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.75rem;
    height: 20px;
    max-width: none;
    padding: 0;
    cursor: pointer;
}

.ai-assistant-voice-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
}

.ai-assistant-voice-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-assistant-voice-status {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.ai-assistant-voice-status[hidden] {
    display: none !important;
}

.ai-assistant-voice-status svg {
    width: 12px;
    height: 12px;
    display: block;
}

.ai-assistant-voice-status[data-state="ready"] {
    color: var(--accent, #3a5a7a);
}

.ai-assistant-voice-spinner {
    display: block;
    box-sizing: border-box;
    width: 10px;
    height: 10px;
    border: 1.5px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    flex-shrink: 0;
    animation: ai-assistant-voice-spin 0.65s linear infinite;
}

@keyframes ai-assistant-voice-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.ai-assistant-voice-option-label {
    flex: 1 1 auto;
    min-width: 0;
}

.ai-assistant-voice-price {
    display: inline-flex;
    align-items: center;
    gap: 0.18rem;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.ai-assistant-voice-price[hidden] {
    display: none !important;
}

.ai-assistant-voice-price-n,
.ai-assistant-voice-price-s {
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.ai-assistant-voice-ink {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    display: block;
}

.ai-assistant-voice-select:hover,
.ai-assistant-voice-select:focus-visible,
.ai-assistant-voice-trigger:hover,
.ai-assistant-voice-trigger:focus-visible {
    color: var(--text-primary);
    outline: none;
}

.ai-assistant-voice-menu {
    position: fixed;
    z-index: 5200;
    display: flex;
    flex-direction: column;
    min-width: 9rem;
    padding: 0.2rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
}

.ai-assistant-voice-menu[hidden] {
    display: none !important;
}

.ai-assistant-voice-option {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.4rem;
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.78rem;
    text-align: left;
    padding: 0.3rem 0.4rem;
    cursor: pointer;
}

.ai-assistant-voice-option .ai-assistant-voice-price {
    margin-left: auto;
}

.ai-assistant-voice-option:hover,
.ai-assistant-voice-option.is-active,
.ai-assistant-voice-option[aria-selected="true"] {
    background: rgba(123, 75, 183, 0.16);
}

.ai-assistant-persona-dd {
    position: relative;
}

.ai-assistant-persona-dd.is-open {
    z-index: 5300;
}

.ai-assistant-persona-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.75rem;
    padding: 0;
    cursor: pointer;
}

.ai-assistant-persona-trigger:hover,
.ai-assistant-persona-trigger:focus-visible {
    color: var(--text-primary);
    outline: none;
}

.ai-assistant-persona-thumb {
    width: 18px;
    height: 18px;
    border-radius: 0;
    overflow: visible;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: currentColor;
}

.ai-assistant-persona-thumb img,
.ai-assistant-persona-thumb svg,
.ai-assistant-persona-shape {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.ai-assistant-persona-caret {
    display: inline-flex;
    margin-left: auto;
    color: var(--text-secondary);
}

.ai-assistant-persona-dd.is-open .ai-assistant-persona-caret {
    transform: rotate(180deg);
}

.ai-assistant-persona-menu {
    display: none;
    position: absolute;
    left: 0;
    bottom: calc(100% + 6px);
    z-index: 5300;
    min-width: 10rem;
    flex-direction: column;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 0.2rem;
}

.ai-assistant-persona-dd.is-open .ai-assistant-persona-menu {
    display: flex;
}

.ai-assistant-persona-option {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.78rem;
    padding: 0.3rem 0.35rem;
    cursor: pointer;
    text-align: left;
}

.ai-assistant-persona-option:hover,
.ai-assistant-persona-option.is-active {
    background: rgba(123, 75, 183, 0.16);
}

.ai-assistant-companion-bubbles {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    pointer-events: auto;
    cursor: default;
    touch-action: pan-y;
}

.ai-assistant-companion.is-modal-open .ai-assistant-companion-bubbles {
    display: none;
}

.ai-assistant-companion-user,
.ai-assistant-companion-assistant {
    font-family: var(--font-ui);
    font-size: 0.88rem;
    line-height: 1.45;
    color: var(--text-primary);
    word-break: break-word;
    max-height: 28vh;
    overflow-y: auto;
}

.ai-assistant-companion-user,
.ai-assistant-companion-assistant,
.ai-assistant-companion-actions .ai-assistant-action {
    background-color: var(--bg-primary);
    backdrop-filter: blur(16px) saturate(1.15);
    -webkit-backdrop-filter: blur(16px) saturate(1.15);
}

.ai-assistant-companion-user {
    align-self: flex-end;
    max-width: 90%;
    background-color: color-mix(in srgb, #7b4bb7 32%, var(--bg-primary) 68%);
    border: 1px solid rgba(123, 75, 183, 0.45);
    border-radius: 14px 14px 4px 14px;
    padding: 0.45rem 0.7rem;
}

.ai-assistant-companion-assistant {
    align-self: flex-start;
    width: 100%;
    background-color: color-mix(in srgb, var(--bg-primary) 88%, #000 12%);
    border: 1px solid var(--border-color);
    border-radius: 14px 14px 14px 4px;
    padding: 0.5rem 0.75rem;
}

.ai-assistant-companion-actions .ai-assistant-action {
    background-color: color-mix(in srgb, var(--bg-primary) 86%, #7b4bb7 14%);
}

.ai-assistant-companion-assistant .ai-assistant-p,
.ai-assistant-companion-assistant .ai-assistant-h,
.ai-assistant-companion-assistant .ai-assistant-list {
    margin-bottom: 0.35rem;
}

.ai-assistant-actions,
.ai-assistant-companion-actions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.4rem;
    width: 100%;
    max-height: 14rem;
    overflow: auto;
}

.ai-assistant-msg .ai-assistant-actions {
    display: flex;
    flex-direction: column;
    max-height: none;
    overflow: visible;
}

.ai-assistant-msg .ai-assistant-action {
    min-width: 0;
}

.ai-assistant-action {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
    padding: 0.4rem 0.5rem;
    border: 1px solid rgba(123, 75, 183, 0.28);
    background-color: rgba(123, 75, 183, 0.08);
}

.ai-assistant-action-head {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    flex-wrap: wrap;
}

.ai-assistant-action-open {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    text-align: left;
    cursor: default;
}

button.ai-assistant-action-open {
    cursor: pointer;
}

.ai-assistant-action-facts {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.ai-assistant-action-facts > div {
    display: grid;
    grid-template-columns: 4.2rem 1fr;
    gap: 0.35rem;
    min-width: 0;
}

.ai-assistant-action-facts dt {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: capitalize;
}

.ai-assistant-action-facts dd {
    margin: 0;
    color: var(--text-primary);
    font-size: 0.78rem;
    line-height: 1.3;
    word-break: break-word;
}

.ai-assistant-action-btns {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 0 0 auto;
    gap: 0.25rem;
}

.ai-assistant-action-go,
.ai-assistant-action-cancel {
    flex: 0 0 auto;
    padding: 0.2rem 0.5rem;
    border: 0;
    font-family: inherit;
    font-size: 0.74rem;
    text-align: center;
    cursor: pointer;
}

.ai-assistant-action-go {
    background-color: #7b4bb7;
    color: #fff;
}

.ai-assistant-action-cancel {
    background: transparent;
    color: var(--text-secondary);
}

.ai-assistant-action.is-applying .ai-assistant-action-go {
    background-color: var(--error);
}

.ai-assistant-action.is-applied .ai-assistant-action-btns {
    justify-content: flex-end;
}

.ai-assistant-action.is-applied .ai-assistant-action-go {
    flex: 0 0 auto;
    min-width: 0;
    padding: 0.25rem 0.5rem;
    font-size: 0.72rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.ai-assistant-action.is-undone .ai-assistant-action-go {
    background-color: #7b4bb7;
    color: #fff;
    cursor: pointer;
}

.ai-assistant-action.is-cancelled .ai-assistant-action-go {
    background-color: transparent;
    color: var(--text-secondary);
    cursor: default;
}

.ai-assistant-companion-hangup,
.ai-assistant-companion-mic {
    width: 56px;
    height: 56px;
    padding: 0;
    border: 0;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    border-radius: 50%;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}

.ai-assistant-companion-hangup {
    background-color: var(--error);
}

.ai-assistant-companion-hangup:hover,
.ai-assistant-companion-hangup.is-hot {
    background-color: #b71c1c;
}

.ai-assistant-companion-mic {
    background-color: #7b4bb7;
}

.ai-assistant-companion-mic.is-listening {
    box-shadow: 0 0 0 6px rgba(123, 75, 183, 0.28);
}

.ai-assistant-companion-mic.is-muted {
    background-color: #4a4450;
    box-shadow: none;
}

.ai-assistant-companion-hangup svg,
.ai-assistant-companion-mic svg {
    display: block;
}

@media (max-width: 760px) {
    .ai-assistant-content {
        width: calc(100vw - 1rem);
        height: calc(100vh - 1rem);
        min-height: 0;
        max-height: calc(100vh - 1rem);
    }

    .ai-assistant-sidebar {
        width: 160px;
    }

    .ai-assistant-header-actions {
        min-width: 64px;
    }

    .ai-assistant-thread {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .ai-assistant-msg--user .ai-assistant-msg-body {
        max-width: 92%;
    }

    .ai-assistant-persona-now {
        min-width: 0;
    }

    .ai-assistant-persona-now-skills {
        display: none;
    }

    .ai-assistant-persona-tip {
        width: min(16.5rem, calc(100vw - 2rem));
    }
}

/* Story Board Modal */
/* Mind Map subviews: one floating close — positioned against modal card, not inner padded toolbar */
.story-board-modal.story-board-modal--subview .story-board-content {
    position: relative;
}

.story-board-subview-close-floating {
    display: none;
}

.story-board-modal.story-board-modal--subview .story-board-subview-close-floating {
    display: inline-flex;
}

.story-board-subview-close-btn--corner {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-lg);
    z-index: 20;
}

.story-board-modal {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 3000;
}

/* Act / Chapter / Beat editor opened from Overview Map: above fullscreen overview blur (z-index 5000) */
.story-board-modal.story-board-modal--over-overview {
    z-index: 5100 !important;
    background: transparent !important;
    backdrop-filter: none !important;
    pointer-events: auto;
}

.story-board-modal.story-board-modal--over-overview .story-board-content {
    pointer-events: auto;
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.55);
}

/* Mind Map Build / Chapter Build / Beat editor: no top header row */
.story-board-modal.story-board-modal--subview .modal-header {
    display: none !important;
}

.story-board-content {
    max-width: 700px;
    width: 90%;
    max-height: 90vh;
    /* Taller shell so Chapter Build has room for beats + breathing room (see client reference) */
    min-height: max(540px, 50vh);
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
}

.story-board-content .modal-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.story-board-content .modal-header h2 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.1rem;
    font-weight: 500;
    pointer-events: none;
}

.story-board-header-icon {
    display: flex;
    align-items: center;
}

.story-board-header-icon svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.story-board-content .modal-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 var(--spacing-sm);
    line-height: 1;
}

.story-board-content .modal-close-btn:hover {
    color: var(--text-primary);
}

.story-board-body {
    padding: var(--spacing-xl);
    padding-bottom: calc(var(--spacing-xl) + var(--spacing-md));
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.story-board-write-by {
    margin: 0 0 var(--spacing-md);
    font-size: 1rem;
    color: var(--text-secondary);
    text-align: center;
}

.story-board-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-lg);
    justify-items: center;
}

.story-board-option {
    position: relative !important;
    width: 100%;
    max-width: 15rem;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.92) !important;
    cursor: pointer;
    overflow: hidden;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 0 !important;
    box-sizing: border-box;
    background-color: #000 !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, background-image 0.2s ease;
}

.story-board-option:hover {
    border-color: transparent !important;
    background-image: linear-gradient(#000, #000), linear-gradient(135deg, #455ED2 0%, #7c5cfa 45%, #ec4899 100%) !important;
    background-origin: border-box !important;
    -webkit-background-clip: padding-box, border-box !important;
    background-clip: padding-box, border-box !important;
    box-shadow: none !important;
}

.story-board-option-snow-surface .story-board-option-graphic {
    position: relative;
    z-index: 1 !important;
}

.story-board-option-snow-surface .story-board-option-label {
    z-index: 1 !important;
}

.story-board-option-graphic {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    width: 100%;
    padding: 0.5rem 0.75rem 0.2rem;
    box-sizing: border-box;
}

.story-board-option-graphic img {
    width: min(68%, 8.25rem);
    height: auto;
    display: block;
    pointer-events: none;
    object-fit: contain;
    object-position: center center;
}

.story-board-option-mind-map .story-board-option-graphic img {
    width: 100% !important;
    height: 104% !important;
    margin-bottom: 20px !important;
    max-width: none !important;
    object-fit: contain !important;
}

.story-board-option-chapter-map .story-board-option-graphic {
    padding: 0.45rem 0.9rem 0.15rem !important;
    align-items: center !important;
    justify-content: center !important;
}

.story-board-option-chapter-map .story-board-option-graphic img {
    width: 100%;
    height: 96%;
    margin-bottom: 50px !important;
    object-fit: contain !important;
    object-position: center center !important;
}

.story-board-option-mind-map .story-board-option-label,
.story-board-option-chapter-map .story-board-option-label {
    color: #fff !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 0 8px rgba(0, 0, 0, 0.25) !important;
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 25px !important;
    text-align: center !important;
    font-size: 18px !important;
    font-weight: 600 !important;
}

.story-board-option-chapter-map .story-board-option-label {
    font-size: 15px !important;
}

.story-board-dashboard-footer {
    display: flex;
    justify-content: center;
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-md);
}

.story-board-overview-open-btn {
    padding: var(--spacing-sm) var(--spacing-xl);
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: var(--text-primary);
    border-radius: 9999px;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.story-board-overview-open-btn:hover {
    border-color: var(--accent);
    background: rgba(69, 94, 210, 0.12);
    color: var(--text-primary);
}

.character-maps-modal {
    z-index: 3150;
}

/* Full viewport below write header — canvas fills the space */
.character-maps-modal.character-maps-modal--fullscreen {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    overflow: hidden;
    background: transparent;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 5000;
}

.character-maps-close-floating {
    position: relative;
    flex-shrink: 0;
    width: 2.35rem;
    height: 2.35rem;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(22, 20, 30, 0.92);
    color: var(--text-primary);
    cursor: pointer;
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.45);
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.character-maps-close-floating:hover {
    background: rgba(40, 36, 52, 0.96);
    border-color: rgba(200, 190, 230, 0.35);
}

.character-maps-close-floating:active {
    transform: scale(0.96);
}

.character-maps-family-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem 0.45rem;
    pointer-events: auto;
}

.character-maps-header-end-spacer {
    flex-shrink: 0;
    width: 2.35rem;
    height: 2.35rem;
    pointer-events: none;
}

.character-maps-family-header-row {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem 0.65rem;
}

.character-maps-header-map-switch {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.character-maps-header-map-dropdown .character-maps-map-menu {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 8px;
    z-index: 50;
}

.character-maps-family-heading {
    flex: 1 1 0;
    min-width: 0;
    width: 0;
    max-width: 40rem;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
    padding: 0.2rem 0.5rem;
    font-family: inherit;
    font-size: clamp(1.45rem, 3.2vw, 2.1rem);
    font-weight: 650;
    letter-spacing: -0.02em;
    text-align: center;
    color: var(--text-primary);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    outline: none;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.character-maps-family-heading::placeholder {
    color: rgba(200, 195, 215, 0.45);
    font-weight: 500;
}

.character-maps-family-heading:hover {
    border-bottom-color: rgba(155, 126, 210, 0.25);
}

.character-maps-family-heading:focus {
    border-bottom-color: rgba(155, 126, 210, 0.65);
}

.character-maps-header-family-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.character-maps-header-new-family-btn {
    position: relative;
    flex-shrink: 0;
    width: 2.35rem;
    height: 2.35rem;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid rgba(155, 126, 210, 0.45);
    background: rgba(155, 126, 210, 0.12);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.character-maps-header-new-family-btn:hover {
    background: rgba(155, 126, 210, 0.22);
    border-color: rgba(180, 160, 230, 0.55);
}

.character-maps-header-new-family-btn[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 100%;
    bottom: auto;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 8px;
    margin-bottom: 0;
    padding: 0.4rem 0.55rem;
    border-radius: 8px;
    max-width: 14rem;
    font-size: 0.72rem;
    line-height: 1.3;
    font-weight: 500;
    white-space: normal;
    text-align: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    z-index: 55;
}

.character-maps-header-delete-family-btn {
    position: relative;
    flex-shrink: 0;
    width: 2.35rem;
    height: 2.35rem;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid rgba(220, 120, 120, 0.45);
    background: rgba(200, 90, 90, 0.12);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.character-maps-header-delete-family-btn:hover {
    background: rgba(200, 90, 90, 0.22);
    border-color: rgba(235, 140, 130, 0.55);
}

.character-maps-header-delete-family-btn[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 100%;
    bottom: auto;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 8px;
    margin-bottom: 0;
    padding: 0.4rem 0.55rem;
    border-radius: 8px;
    max-width: 14rem;
    font-size: 0.72rem;
    line-height: 1.3;
    font-weight: 500;
    white-space: normal;
    text-align: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    z-index: 55;
}

/* Family map caret: tooltip to the left so it does not clip the viewport top or cover the dropdown (menu opens below). */
.character-maps-family-header .character-maps-float-icon-btn.character-maps-float-map-caret[data-tooltip]:hover::after {
    bottom: auto;
    top: 50%;
    left: auto;
    right: 100%;
    transform: translateY(-50%);
    margin-bottom: 0;
    margin-right: 10px;
    margin-top: 0;
    margin-left: 0;
    max-width: 14rem;
    white-space: normal;
    text-align: center;
    font-weight: 500;
    line-height: 1.3;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 60;
}

.character-maps-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: var(--spacing-md);
    gap: var(--spacing-sm);
}

.character-maps-modal--fullscreen .character-maps-body {
    flex: 1;
    min-height: 0;
    width: 100%;
    padding: 0;
    gap: 0;
    overflow: hidden;
}

.character-maps-body--map-focus {
    padding: var(--spacing-sm);
    gap: 0;
}

.character-maps-modal--fullscreen .character-maps-body--map-focus {
    padding: 0;
}

.character-maps-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
}

.character-maps-hint {
    margin: 0;
    font-size: 0.88rem;
    color: var(--text-secondary);
    max-width: 42rem;
}

.character-maps-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-sm);
}

.character-maps-tool-btn {
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
}

.character-maps-tool-btn--primary {
    border-color: rgba(155, 126, 210, 0.55);
    background: rgba(155, 126, 210, 0.12);
}

.character-maps-save-status {
    font-size: 0.8rem;
    min-width: 4rem;
}

.character-maps-save-status--float {
    pointer-events: none;
    font-size: 0.72rem;
    text-align: center;
    max-width: 14rem;
    line-height: 1.25;
}

.character-maps-workspace {
    display: flex;
    flex: 1;
    min-height: min(52vh, 640px);
    gap: var(--spacing-md);
    align-items: stretch;
    position: relative;
}

.character-maps-body--map-focus .character-maps-workspace {
    min-height: min(62vh, 720px);
}

.character-maps-modal--fullscreen .character-maps-workspace {
    flex: 1;
    min-height: 0;
    width: 100%;
    overflow: hidden;
}

.character-maps-workspace--canvas-only {
    flex-direction: column;
}

.character-maps-workspace--canvas-only .character-maps-pan {
    flex: 1;
    min-height: 0;
}

.character-maps-modal--fullscreen .character-maps-workspace--canvas-only .character-maps-pan {
    min-height: 0;
    overflow: hidden;
    border: none;
    border-radius: 0;
}

body.character-maps-modal-open {
    overflow: hidden;
}

.character-maps-floating-tools {
    position: absolute;
    left: 50%;
    bottom: var(--spacing-md);
    transform: translateX(-50%);
    z-index: 40;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}

.character-maps-float-map-dropdown {
    position: relative;
}

.character-maps-map-menu {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    min-width: 11rem;
    max-height: 15rem;
    overflow-y: auto;
    padding: 0.3rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    z-index: 30;
}

.character-maps-map-menu.is-open {
    display: block;
}

.character-maps-map-menu-item {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    padding: 0.45rem 0.55rem;
    margin: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.82rem;
    cursor: pointer;
    font-family: inherit;
}

.character-maps-map-menu-item:hover,
.character-maps-map-menu-item:focus-visible {
    background: rgba(155, 126, 210, 0.16);
    outline: none;
}

.character-maps-map-menu-item.is-active {
    background: rgba(155, 126, 210, 0.24);
    font-weight: 600;
}

.character-maps-float-map-caret[aria-expanded='true'] svg {
    transform: rotate(180deg);
}

.character-maps-float-map-caret svg {
    transition: transform 0.2s ease;
}

.character-maps-floating-tools .character-maps-float-inner {
    pointer-events: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.45rem 0.65rem;
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

.character-maps-float-icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.35rem;
    height: 2.35rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.character-maps-float-icon-btn:hover {
    background: rgba(155, 126, 210, 0.22);
    color: var(--text-primary);
}

.character-maps-float-icon-btn:disabled,
.character-maps-float-icon-btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.character-maps-float-icon-btn[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    padding: 0.4rem 0.55rem;
    max-width: 14rem;
    font-size: 0.72rem;
    line-height: 1.3;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    white-space: normal;
    text-align: center;
    z-index: 20;
    pointer-events: none;
}

.character-maps-float-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    min-width: 8rem;
    max-width: 13rem;
}

.character-maps-float-title {
    flex: 1;
    min-width: 0;
    box-sizing: border-box;
    padding: 0.28rem 0.45rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.78rem;
    font-family: inherit;
}

.character-maps-float-new-family-btn {
    position: relative;
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.character-maps-float-new-family-btn:hover {
    border-color: rgba(155, 126, 210, 0.55);
    background: rgba(155, 126, 210, 0.14);
}

.character-maps-float-new-family-btn[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    padding: 0.4rem 0.55rem;
    max-width: 12rem;
    font-size: 0.72rem;
    line-height: 1.3;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    white-space: normal;
    text-align: center;
    z-index: 20;
    pointer-events: none;
}

/* Must beat .story-board-modal--over-overview (5100). */
.modal.character-maps-delete-confirm {
    z-index: 5200;
}

.modal.character-maps-starter-modal {
    z-index: 5300;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.character-maps-starter-content {
    width: min(32rem, 100%);
    max-height: min(80vh, 34rem);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem 1.1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.character-maps-starter-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 650;
    color: var(--text-primary);
}

.character-maps-starter-hint {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--text-secondary);
}

.character-maps-starter-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    min-height: 0;
    flex: 1;
}

.character-maps-starter-item {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    padding: 0.55rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    cursor: pointer;
}

.character-maps-starter-item:hover {
    border-color: rgba(155, 126, 210, 0.45);
}

.character-maps-starter-item-input {
    margin-top: 0.2rem;
    flex-shrink: 0;
}

.character-maps-starter-item-body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.character-maps-starter-item-title {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
}

.character-maps-starter-item-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.character-maps-starter-item-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.character-maps-starter-chip {
    font-size: 0.72rem;
    line-height: 1.3;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: rgba(155, 126, 210, 0.14);
    border: 1px solid rgba(155, 126, 210, 0.28);
    color: var(--text-primary);
}

.character-maps-starter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
}

.character-maps-starter-add-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.character-maps-starter-skip-btn {
    margin-left: auto;
    padding: 0.35rem 0.5rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
    font-family: inherit;
}

.character-maps-starter-skip-btn:hover {
    color: var(--text-primary);
}

body.theme-light .character-maps-starter-chip {
    background: rgba(155, 126, 210, 0.1);
}

.character-maps-workspace--canvas-only {
    overflow: visible;
}

.character-maps-canvas {
    position: relative;
    margin: 0 auto;
}

.character-maps-inner--wide-canvas {
    width: max-content;
    min-width: 100%;
    box-sizing: border-box;
}

.character-maps-edge-toolbar {
    position: absolute;
    z-index: 25;
    left: 0;
    top: 0;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 3px;
    border-radius: 999px;
    background: rgba(40, 36, 58, 0.96);
    border: 2px solid rgba(196, 184, 232, 0.95);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

.character-maps-edge-tool-btn {
    width: 26px;
    height: 26px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: rgba(235, 225, 200, 0.95);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    flex-shrink: 0;
}

.character-maps-edge-tool-btn:hover {
    background: rgba(80, 72, 110, 0.55);
}

.character-maps-edge-tool-btn--delete:hover {
    background: rgba(120, 48, 48, 0.45);
    color: #ffd0d0;
}

.character-maps-edges-svg {
    overflow: visible;
}

.character-maps-nodes-layer {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.character-maps-node-editor {
    position: absolute;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.character-maps-node-card {
    position: relative;
    border-radius: 50%;
    overflow: visible;
    box-sizing: border-box;
    border: 2px solid rgba(196, 184, 232, 0.95);
    background: radial-gradient(circle at 35% 30%, rgba(155, 135, 210, 0.35), rgba(12, 14, 22, 0.88));
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    cursor: grab;
    touch-action: none;
}

.character-maps-node-card:active {
    cursor: grabbing;
}

.character-maps-node-editor--placement-hover .character-maps-node-card {
    box-shadow:
        0 0 0 3px rgba(196, 184, 232, 0.98),
        0 0 18px rgba(155, 135, 210, 0.45),
        0 6px 20px rgba(0, 0, 0, 0.35);
    border-color: rgba(235, 225, 250, 0.98);
}

.character-maps-node-face {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    overflow: hidden;
}

.character-maps-node-face--empty {
    background: transparent;
}

.character-maps-node-face--unknown {
    background: radial-gradient(circle at 50% 45%, rgba(120, 110, 170, 0.35), rgba(12, 14, 22, 0.75));
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-maps-node-unknown-q {
    font-size: clamp(1.8rem, 52%, 3.2rem);
    font-weight: 800;
    line-height: 1;
    color: rgba(235, 225, 200, 0.88);
    user-select: none;
    pointer-events: none;
}

.character-maps-node-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 12%;
    display: block;
}

.character-maps-node-name--below {
    margin: 0.2rem 0 0.15rem;
    padding: 0;
    max-width: 160%;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    color: rgba(245, 235, 215, 0.95);
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.character-maps-node-name--below:hover {
    color: #fff8e8;
}

.character-maps-node-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 0.1rem;
    flex-shrink: 0;
}

.character-maps-node-assign {
    position: relative;
    width: 1.65rem;
    height: 1.65rem;
    padding: 0;
    border: 2px solid rgba(196, 184, 232, 0.9);
    border-radius: 50%;
    background: rgba(40, 36, 58, 0.95);
    color: rgba(235, 225, 200, 0.95);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    transition: background 0.15s ease, transform 0.1s ease;
}

.character-maps-node-assign:hover {
    background: rgba(55, 50, 78, 0.98);
}

.character-maps-node-assign[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 6px;
    padding: 0.35rem 0.45rem;
    max-width: 11rem;
    font-size: 0.68rem;
    line-height: 1.25;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    white-space: normal;
    text-align: center;
    pointer-events: none;
}

.character-maps-node-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 1.35rem;
    height: 1.35rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(20, 18, 28, 0.88);
    color: #e8a0a0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    opacity: 0.55;
    transition: opacity 0.15s ease;
}

.character-maps-node-editor:hover .character-maps-node-remove,
.character-maps-node-remove:focus-visible {
    opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
    .character-maps-node-remove {
        opacity: 0;
    }

    .character-maps-node-editor:hover .character-maps-node-remove,
    .character-maps-node-remove:focus-visible {
        opacity: 1;
    }
}

.character-maps-node-plus {
    position: relative;
    width: 1.65rem;
    height: 1.65rem;
    padding: 0;
    border: 2px solid rgba(196, 184, 232, 0.9);
    border-radius: 50%;
    background: rgba(40, 36, 58, 0.95);
    color: rgba(235, 225, 200, 0.95);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    transition: background 0.15s ease, transform 0.1s ease;
}

.character-maps-node-plus[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 6px;
    padding: 0.35rem 0.45rem;
    max-width: 11rem;
    font-size: 0.68rem;
    line-height: 1.25;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    white-space: normal;
    text-align: center;
    pointer-events: none;
}

.character-maps-node-plus:hover {
    background: rgba(55, 50, 78, 0.98);
}

.character-maps-node-ghost {
    position: absolute;
    border-radius: 50%;
    border: 2px dashed rgba(200, 180, 140, 0.65);
    background: rgba(40, 38, 55, 0.25);
    pointer-events: none;
    z-index: 1;
}

.character-maps-pan--placing {
    cursor: crosshair;
}

.character-maps-popover {
    position: absolute;
    z-index: 40;
    min-width: 10rem;
    max-width: 16rem;
    padding: 0.5rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.character-maps-popover--wide {
    min-width: 12rem;
    max-width: 20rem;
}

.character-maps-popover--picker {
    min-width: 14rem;
    max-width: 22rem;
}

.character-maps-character-picker {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
}

.character-maps-character-picker-search {
    width: 100%;
    box-sizing: border-box;
    padding: 0.35rem 0.45rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-family: inherit;
}

.character-maps-character-picker-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: min(220px, 42vh);
    overflow-y: auto;
    margin: 0;
    padding: 0.1rem 0;
}

.character-maps-character-picker-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0.35rem 0.4rem;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.character-maps-character-picker-option:hover {
    border-color: rgba(155, 126, 210, 0.35);
    background: rgba(155, 126, 210, 0.08);
}

.character-maps-character-picker-option.is-selected {
    border-color: rgba(155, 126, 210, 0.55);
    background: rgba(155, 126, 210, 0.16);
}

.character-maps-character-picker-option[hidden] {
    display: none;
}

.character-maps-character-picker-face {
    flex-shrink: 0;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-maps-character-picker-face img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 26%;
    display: block;
}

.character-maps-character-picker-face--mystery {
    background: radial-gradient(circle at 50% 45%, rgba(120, 110, 170, 0.35), rgba(12, 14, 22, 0.75));
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1;
    color: rgba(235, 225, 200, 0.9);
}

.character-maps-character-picker-face--initials {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.character-maps-character-picker-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.character-maps-character-picker-name {
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.character-maps-character-picker-hint {
    font-size: 0.68rem;
    line-height: 1.25;
    color: var(--text-secondary);
}

.character-maps-popover-hint {
    margin: 0;
    font-size: 0.7rem;
    line-height: 1.4;
    color: rgba(195, 188, 215, 0.88);
}

.character-maps-popover-hint strong {
    color: rgba(238, 232, 252, 0.98);
    font-weight: 650;
}

.character-maps-popover-hint--compact {
    font-size: 0.68rem;
    line-height: 1.35;
    opacity: 0.92;
}

.character-maps-popover-field-label {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary, rgba(200, 194, 220, 0.92));
    letter-spacing: 0.02em;
}

.character-maps-popover-preview {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin: 0;
    padding-top: 0.1rem;
}

.character-maps-popover-preview-line {
    margin: 0;
    font-size: 0.7rem;
    line-height: 1.4;
    color: rgba(185, 178, 210, 0.9);
}

.character-maps-popover-preview-or {
    margin: 0;
    font-size: 0.65rem;
    line-height: 1.3;
    font-style: italic;
    text-align: center;
    color: rgba(165, 158, 195, 0.75);
}

.character-maps-float-placement-hint {
    pointer-events: none;
    max-width: min(36rem, 92vw);
    padding: 0.35rem 0.65rem;
    margin: 0;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(18, 16, 28, 0.92);
    font-size: 0.72rem;
    line-height: 1.35;
    color: rgba(210, 202, 235, 0.92);
    text-align: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.character-maps-popover-select,
.character-maps-popover-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.35rem 0.45rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-family: inherit;
}

.character-maps-popover-done {
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    border: 1px solid rgba(155, 126, 210, 0.55);
    background: rgba(155, 126, 210, 0.18);
    color: var(--text-primary);
    font-size: 0.82rem;
    cursor: pointer;
    font-family: inherit;
}

.character-maps-map-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.character-maps-map-tab {
    padding: 0.3rem 0.55rem;
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
    font-family: inherit;
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.character-maps-map-tab.is-active {
    border-color: rgba(155, 126, 210, 0.7);
    color: var(--text-primary);
    background: rgba(155, 126, 210, 0.1);
}

.character-maps-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.character-maps-input,
.character-maps-select {
    width: 100%;
    box-sizing: border-box;
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
}

.character-maps-add-row {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.character-maps-add-row .character-maps-select {
    flex: 1;
}

.character-maps-delete-map-btn {
    margin-top: 0.35rem;
    width: 100%;
    padding: 0.4rem;
    border-radius: 8px;
    border: 1px solid rgba(200, 80, 80, 0.45);
    background: transparent;
    color: #c45a5a;
    font-size: 0.82rem;
    cursor: pointer;
    font-family: inherit;
}

.character-maps-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: var(--spacing-sm) 0;
}

.character-maps-node-list,
.character-maps-edge-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.35rem;
    max-height: 11rem;
    overflow: auto;
}

.character-maps-node-row,
.character-maps-edge-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    font-size: 0.82rem;
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--border-color);
}

.character-maps-node-row-tools button {
    min-width: 1.75rem;
    padding: 0.15rem 0.35rem;
    margin-left: 0.15rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    cursor: pointer;
    font-size: 0.75rem;
}

.character-maps-row-remove {
    border: none !important;
    background: transparent !important;
    color: #c45a5a;
    cursor: pointer;
    font-size: 0.78rem;
}

.character-maps-edge-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
}

.character-maps-edge-grid .character-maps-input {
    grid-column: 1 / -1;
}

.character-maps-edge-grid #character-maps-add-edge-btn {
    grid-column: 1 / -1;
}

.character-maps-pan {
    flex: 1;
    min-width: 0;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    overflow: auto;
    cursor: grab;
    touch-action: none;
    position: relative;
    background: rgba(12, 10, 18, 0.35);
}

.character-maps-pan.character-maps-pan-dragging {
    cursor: grabbing;
}

.character-maps-zoom-wrap {
    width: max-content;
    min-width: 100%;
    height: 100%;
    min-height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    overflow: visible;
    box-sizing: border-box;
}

.character-maps-inner {
    position: relative;
    min-height: 200px;
    padding: var(--spacing-md);
    width: 100%;
    box-sizing: border-box;
}

.character-maps-inner .character-maps-svg {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
    user-select: none;
}

.character-map-fobj {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: transparent;
}

.character-map-fobj-inner {
    font-size: 11px;
    line-height: 1.25;
    text-align: center;
    color: #fff;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    padding: 4px 8px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.character-maps-empty-preview {
    margin: 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: var(--spacing-xl);
}

body.theme-light .character-maps-pan {
    background: rgba(30, 32, 42, 0.06);
}

body.theme-light .character-map-fobj-inner {
    color: rgba(255, 255, 255, 0.95);
}

.story-board-overview-modal {
    background-color: rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(2px);
    z-index: 3100;
}

/* Full viewport below write header (modal is moved to body in story-board.js). */
.story-board-overview-modal.story-board-overview-modal--fullscreen {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    background: #ffffff29;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 5000;
}

body.theme-light .story-board-overview-modal.story-board-overview-modal--fullscreen {
    background: #00000029;
}

.story-board-overview-modal--fullscreen .story-board-overview-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background-color: transparent;
    box-shadow: none;
    overflow: hidden;
}

.story-board-overview-modal--fullscreen .story-board-overview-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: min(17.5rem, 32vw) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    margin-top: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
    position: relative;
}

.story-board-overview-notes {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem 0.65rem;
    background: transparent;
    pointer-events: auto;
    overflow: hidden;
    min-height: 0;
}

.story-board-overview-notes-panel {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.story-board-overview-modal--fullscreen .story-board-overview-notes-shell {
    grid-column: 1;
    grid-row: 2;
    z-index: 3;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border-color);
    background: linear-gradient(180deg, rgba(18, 17, 26, 0.58), rgba(18, 17, 26, 0.18));
    transition: width 0.22s ease;
}

.story-board-overview-modal--fullscreen .story-board-overview-body.story-board-overview-brainstorm-collapsed {
    grid-template-columns: 2.75rem minmax(0, 1fr);
}

.story-board-overview-notes-shell.is-collapsed .story-board-overview-notes-heading {
    display: none;
}

.story-board-overview-notes-shell.is-collapsed .story-board-overview-notes-header {
    justify-content: center;
    padding: 0.55rem 0 0;
}

.story-board-overview-notes-shell.is-collapsed .story-board-overview-notes-panel {
    display: none;
}

.story-board-overview-notes-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    padding: 0.7rem 0.75rem 0;
}

.story-board-overview-notes-heading {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 1;
    min-width: 0;
}

.story-board-overview-notes-title-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    color: color-mix(in srgb, var(--accent, #a08cdc) 88%, white);
}

.story-board-overview-notes-title-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.story-board-overview-notes-title {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.72);
}

.story-board-overview-notes-toggle {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.65rem;
    height: 1.65rem;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.72);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.story-board-overview-notes-toggle:hover,
.story-board-overview-notes-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.95);
    border-color: rgba(255, 255, 255, 0.22);
}

.story-board-overview-notes-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.story-board-overview-notes-toggle-icon--brainstorm {
    display: none;
}

.story-board-overview-notes-shell.is-collapsed .story-board-overview-notes-toggle-icon--collapse {
    display: none;
}

.story-board-overview-notes-shell.is-collapsed .story-board-overview-notes-toggle-icon--brainstorm {
    display: inline-flex;
}

.story-board-overview-notes-shell.is-collapsed .story-board-overview-notes-toggle {
    width: 2rem;
    height: 2rem;
}

.story-board-overview-notes-empty {
    margin: 0;
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.48);
}

.story-board-overview-brainstorm-chapter {
    margin: 0;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.3;
}

.story-board-overview-brainstorm-body {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.story-board-overview-brainstorm-recap-block {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 0 1 auto;
    max-height: 50%;
    min-height: 0;
    overflow: hidden;
}

.story-board-overview-brainstorm-recap-block > .story-board-overview-brainstorm-section-title {
    margin-top: 0;
    flex-shrink: 0;
}

.story-board-overview-brainstorm-recap-block .story-board-overview-brainstorm-recap {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow: auto;
    margin-top: 0;
}

.story-board-overview-brainstorm-section-title {
    margin: 0.55rem 0 0;
    font-family: var(--font-ui);
    font-size: 0.62rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.34);
}

.story-board-overview-brainstorm-body > .story-board-overview-brainstorm-section-title:first-child {
    margin-top: 0;
}

.story-board-overview-brainstorm-copy-row {
    margin: 0.2rem 0 0;
    padding: 0.2rem 1.85rem 0.2rem 0.55rem;
    width: 100%;
    border: 0;
    border-left: 2px solid color-mix(in srgb, var(--accent, #7b4bb7) 42%, transparent);
    border-radius: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.94);
    font-family: var(--font-brand, var(--font-ui));
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.55;
    text-align: left;
    position: relative;
}

.story-board-overview-brainstorm-copy-text {
    margin: 0;
    display: block;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
    color: inherit;
    user-select: text;
    -webkit-user-select: text;
    cursor: text;
}

.story-board-overview-copy-btn {
    position: absolute;
    top: 0.05rem;
    right: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease, color 0.12s ease, background 0.12s ease;
}

.story-board-overview-brainstorm-copy-row:hover .story-board-overview-copy-btn,
.story-board-overview-copy-btn:focus-visible {
    opacity: 1;
}

.story-board-overview-copy-btn:hover,
.story-board-overview-copy-btn:focus-visible {
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
}

.story-board-overview-copy-btn-icon {
    display: block;
}

.story-board-overview-tooltip {
    position: fixed;
    z-index: 2147483000;
    max-width: min(14rem, calc(100vw - 1rem));
    padding: 0.3rem 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: #1a1d22;
    color: #fff;
    font-family: var(--font-ui);
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.25;
    pointer-events: none;
    opacity: 0;
    transform: translateY(2px);
    transition: opacity 0.12s ease, transform 0.12s ease;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
}

.story-board-overview-tooltip.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.story-board-overview-tooltip.story-board-overview-tooltip--cover {
    max-width: min(22rem, calc(100vw - 1.5rem));
    white-space: normal;
    font-weight: 500;
    font-size: 0.75rem;
    line-height: 1.45;
    padding: 0.45rem 0.55rem;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.story-board-overview-brainstorm-section {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

.story-board-overview-notes-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
    min-height: 0;
}

.story-board-overview-note {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.12rem;
    margin: 0;
    padding: 0.35rem 0.4rem;
    width: 100%;
    border: 0;
    background: rgba(255, 255, 255, 0.04);
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.story-board-overview-note:hover {
    background: rgba(255, 255, 255, 0.1);
}

.story-board-overview-notes-list .story-board-overview-brainstorm-thread {
    list-style: none;
}

.story-board-overview-note.is-undone {
    opacity: 0.55;
}

.story-board-overview-note-who {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.62);
}

.story-board-overview-note-who .ai-assistant-persona-shape {
    width: 0.7rem;
    height: 0.7rem;
    flex-shrink: 0;
}

.story-board-overview-note[data-persona="writer"] .story-board-overview-note-who {
    color: #e17055;
}

.story-board-overview-note[data-persona="architect"] .story-board-overview-note-who {
    color: #2b8a86;
}

.story-board-overview-note[data-persona="assistant"] .story-board-overview-note-who {
    color: #7b4bb7;
}

.story-board-overview-note-label {
    font-size: 0.84rem;
    line-height: 1.3;
    color: rgba(255, 255, 255, 0.92);
}

.story-board-overview-note-time {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
}

body.theme-light .story-board-overview-notes-shell {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.22));
}

body.theme-light .story-board-overview-notes-toggle {
    border-color: rgba(48, 48, 48, 0.12);
    background: rgba(48, 48, 48, 0.05);
    color: rgba(48, 48, 48, 0.65);
}

body.theme-light .story-board-overview-notes-toggle:hover,
body.theme-light .story-board-overview-notes-toggle:focus-visible {
    background: rgba(48, 48, 48, 0.1);
    color: rgba(48, 48, 48, 0.9);
}

body.theme-light .story-board-overview-notes-title,
body.theme-light .story-board-overview-note-label,
body.theme-light .story-board-overview-brainstorm-copy-row {
    color: rgba(48, 48, 48, 0.92);
}

body.theme-light .story-board-overview-brainstorm-chapter {
    color: rgba(48, 48, 48, 0.55);
}

body.theme-light .story-board-overview-brainstorm-section-title {
    color: rgba(48, 48, 48, 0.38);
}

body.theme-light .story-board-overview-copy-btn {
    color: rgba(48, 48, 48, 0.45);
}

body.theme-light .story-board-overview-copy-btn:hover,
body.theme-light .story-board-overview-copy-btn:focus-visible {
    color: rgba(48, 48, 48, 0.75);
    background: rgba(48, 48, 48, 0.08);
}

body.theme-light .story-board-overview-tooltip {
    background: #fff;
    color: #1a1d22;
    border-color: rgba(0, 0, 0, 0.1);
}

body.theme-light .story-board-overview-notes-empty,
body.theme-light .story-board-overview-note-time {
    color: rgba(48, 48, 48, 0.48);
}

body.theme-light .story-board-overview-note-who {
    color: rgba(48, 48, 48, 0.62);
}

body.theme-light .story-board-overview-note {
    background: rgba(48, 48, 48, 0.05);
}

body.theme-light .story-board-overview-note:hover {
    background: rgba(48, 48, 48, 0.1);
}

@media (max-width: 720px) {
    .story-board-overview-modal--fullscreen .story-board-overview-body {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr) minmax(8rem, 34vh);
    }

    .story-board-overview-modal--fullscreen .story-board-overview-notes-shell {
        grid-column: 1;
        grid-row: 3;
        border-right: none;
        border-top: 1px solid var(--border-color);
    }

    .story-board-overview-modal--fullscreen .story-board-overview-body.story-board-overview-brainstorm-collapsed {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr) 2.75rem;
    }

    .story-board-overview-modal--fullscreen .story-board-overview-body.story-board-overview-brainstorm-collapsed .story-board-overview-notes-shell {
        grid-row: 3;
        flex-direction: row;
        justify-content: center;
        border-top: 1px solid var(--border-color);
    }

    .story-board-overview-modal--fullscreen .story-board-overview-pan,
    .story-board-overview-modal--fullscreen .story-board-overview-loading,
    .story-board-overview-modal--fullscreen .story-board-overview-empty {
        grid-column: 1;
        grid-row: 2;
    }
}

.story-board-overview-heading-group {
    flex: 0 1 22rem;
    min-width: 0;
    max-width: min(36rem, 100%);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.story-board-overview-modal--fullscreen .story-board-overview-heading-group {
    flex: 0 1 auto;
    max-width: none;
}

.story-board-overview-modal--fullscreen .story-board-overview-toolbar-row {
    grid-column: 1 / -1;
    grid-row: 1;
    flex-shrink: 0;
    flex-grow: 0;
    margin: 0;
    padding: 0.65rem 1rem 0.45rem;
    flex-wrap: nowrap;
    align-items: center;
    align-content: center;
    gap: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(22, 20, 30, 0.88);
}

body.theme-light .story-board-overview-modal--fullscreen .story-board-overview-toolbar-row {
    background: var(--bg-secondary);
}

.story-board-overview-modal--fullscreen .story-board-overview-hint {
    margin: 0;
    flex: 0 1 auto;
    min-height: 0;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    scrollbar-width: thin;
}

.story-board-overview-modal--fullscreen .story-board-overview-toolbar {
    flex-shrink: 0;
    flex-wrap: nowrap;
}

.story-board-overview-modal--fullscreen .story-board-overview-loading,
.story-board-overview-modal--fullscreen .story-board-overview-empty {
    grid-column: 2;
    grid-row: 2;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

.story-board-overview-modal--fullscreen .story-board-overview-pan {
    grid-column: 2;
    grid-row: 2;
    min-height: 0;
    max-height: none;
    width: 100%;
    border-radius: 0;
    border: none;
    border-top: none;
    background: #12111a;
    position: relative;
}

.story-board-overview-map-hint {
    position: absolute;
    left: 50%;
    bottom: 0.85rem;
    transform: translateX(-50%);
    z-index: 4;
    margin: 0;
    max-width: min(28rem, calc(100% - 1.5rem));
    padding: 0.35rem 0.65rem;
    border-radius: 8px;
    background: rgba(12, 11, 18, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.78rem;
    line-height: 1.35;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.45s ease;
}

.story-board-overview-map-hint.is-visible {
    opacity: 1;
}

.story-board-overview-map-hint.is-faded {
    opacity: 0;
}

body.theme-light .story-board-overview-map-hint {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(48, 48, 48, 0.12);
    color: rgba(48, 48, 48, 0.72);
}

.story-board-overview-modal--fullscreen .story-board-overview-pan .story-board-overview-inner svg.story-board-overview-svg {
    max-width: none;
    max-height: none;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.story-board-overview-content {
    max-width: min(1920px, 98vw);
    width: 96vw;
    max-height: 94vh;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
}

.story-board-overview-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 500;
}

.story-board-overview-body {
    padding: var(--spacing-md) var(--spacing-lg) var(--spacing-lg);
    overflow: hidden;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.story-board-overview-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm) var(--spacing-md);
    margin: 0 0 var(--spacing-sm);
}

.story-board-overview-hint {
    margin: 0;
    flex: 1 1 200px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.story-board-overview-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem 0.75rem;
    flex-shrink: 0;
}

.story-board-overview-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-size: 0.8rem;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.story-board-overview-tool-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.22);
}

.story-board-overview-tool-btn:focus-visible {
    outline: 2px solid rgba(212, 168, 75, 0.65);
    outline-offset: 2px;
}

.story-board-overview-tool-btn--icon-only {
    padding: 0.4rem;
    min-width: 2.25rem;
}

.story-board-overview-tool-btn .story-board-overview-tool-icon {
    display: inline-flex;
    opacity: 0.92;
}

.story-board-overview-snow-control {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding-left: 0.15rem;
}

.story-board-bubble-cover-field,
.story-board-overview-cover-control {
    display: none !important;
}

.story-board-overview-cover-label {
    display: inline-flex;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    user-select: none;
    white-space: nowrap;
}

.story-board-overview-cover-switch.publish-switch {
    width: 2.5rem;
    height: 1.38rem;
}

/* Toggle ON: show bubble cover below header when present. */
.story-board-overview-pan.story-board-overview-show-cover .story-board-overview-node:has(.story-board-overview-node-cover) .story-board-overview-node-cover,
.story-board-overview-pan.story-board-overview-show-cover .story-board-overview-node:has(.story-board-overview-node-cover) .story-board-overview-node-header-rule {
    opacity: 1;
    visibility: visible;
}

/* Toggle OFF: show cover + divider on hover only. */
.story-board-overview-pan:not(.story-board-overview-show-cover) .story-board-overview-node:hover:has(.story-board-overview-node-cover) .story-board-overview-node-cover,
.story-board-overview-pan:not(.story-board-overview-show-cover) .story-board-overview-beat-cluster:hover .story-board-overview-node:has(.story-board-overview-node-cover) .story-board-overview-node-cover,
.story-board-overview-pan:not(.story-board-overview-show-cover) .story-board-overview-node:hover:has(.story-board-overview-node-cover) .story-board-overview-node-header-rule,
.story-board-overview-pan:not(.story-board-overview-show-cover) .story-board-overview-beat-cluster:hover .story-board-overview-node:has(.story-board-overview-node-cover) .story-board-overview-node-header-rule {
    opacity: 1;
    visibility: visible;
}

.story-board-overview-pan .story-board-overview-node-inner {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    text-align: center;
}

.story-board-overview-pan .story-board-overview-node-cover,
.story-board-overview-pan .story-board-overview-node-title,
.story-board-overview-pan .story-board-overview-node-header-rule {
    display: none;
}

.story-board-overview-pan .story-board-overview-node-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.story-board-overview-pan .story-board-overview-node-header-rule {
    flex-shrink: 0;
    width: 44%;
    height: 1px;
    margin: 2px 0 3px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    transform: scaleY(0.5);
    transform-origin: center center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.18s ease, visibility 0.18s ease;
}

.story-board-overview-pan .story-board-overview-node-cover {
    flex: 1 1 auto;
    min-height: 0;
    display: block;
    width: 76%;
    max-width: 76%;
    margin-left: auto;
    margin-right: auto;
    padding: 0 0 0.25rem;
    opacity: 0;
    visibility: hidden;
    font-size: 6.5px;
    line-height: 1.18;
    font-weight: 300;
    color: var(--text-primary);
    overflow: hidden;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
    white-space: pre-line;
    text-align: center;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    transition: opacity 0.18s ease, visibility 0.18s ease;
}

.story-board-overview-pan .story-board-overview-fobj--act .story-board-overview-node-cover {
    font-size: 8px;
    line-height: 1.14;
    width: 80%;
    max-width: 80%;
    padding-bottom: 0.35rem;
}

.story-board-overview-pan .story-board-overview-fobj--chapter .story-board-overview-node-cover {
    font-size: 5.5px;
    line-height: 1.16;
    width: 72%;
    max-width: 72%;
}

.story-board-overview-pan .story-board-overview-beat-fobj .story-board-overview-node-cover {
    font-size: 2.85px;
    line-height: 1.12;
    width: 68%;
    max-width: 68%;
}

.story-board-overview-pan .story-board-overview-node-title {
    flex: 1 1 auto;
    min-height: 0;
    display: block;
    width: 76%;
    max-width: 76%;
    margin-left: auto;
    margin-right: auto;
    padding: 0 0 0.25rem;
    font-size: 6.5px;
    line-height: 1.18;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    overflow-wrap: normal;
    word-break: normal;
    white-space: pre-line;
    text-align: center;
    box-sizing: border-box;
    cursor: pointer;
}

.story-board-overview-pan .story-board-overview-fobj--act .story-board-overview-node-title {
    font-size: 8px;
    line-height: 1.14;
    width: 80%;
    max-width: 80%;
    padding-bottom: 0.35rem;
}

.story-board-overview-pan .story-board-overview-fobj--chapter .story-board-overview-node-title {
    font-size: 5.5px;
    line-height: 1.16;
    width: 72%;
    max-width: 72%;
}

.story-board-overview-pan .story-board-overview-beat-fobj .story-board-overview-node-title {
    font-size: 2.85px;
    line-height: 1.12;
    width: 68%;
    max-width: 68%;
}

body.theme-light .story-board-overview-pan .story-board-overview-node-header-rule {
    background: rgba(255, 255, 255, 0.24);
}

.story-board-overview-pan .story-board-overview-act-stack,
.story-board-overview-pan .story-board-overview-chapter-stack,
.story-board-overview-pan .story-board-overview-beat-stack {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.story-board-overview-pan .story-board-overview-node:not(.story-board-overview-node--muted) .story-board-overview-act-heading,
.story-board-overview-pan .story-board-overview-node:not(.story-board-overview-node--muted) .story-board-overview-chapter-title,
.story-board-overview-pan .story-board-overview-node:not(.story-board-overview-node--muted) .story-board-overview-beat-num {
    color: rgba(255, 255, 255, 0.95);
}

.story-board-overview-pan .story-board-overview-node--muted .story-board-overview-act-heading,
.story-board-overview-pan .story-board-overview-node--muted .story-board-overview-chapter-title,
.story-board-overview-pan .story-board-overview-node--muted .story-board-overview-beat-num {
    color: rgba(150, 150, 158, 0.88);
}

.story-board-overview-pan .story-board-overview-node--muted:not(.story-board-overview-node--bubble) circle {
    stroke: rgba(130, 130, 140, 0.55) !important;
}

.story-board-overview-pan .story-board-overview-node--muted:not(.story-board-overview-node--bubble):hover circle,
.story-board-overview-pan .story-board-overview-node--muted:not(.story-board-overview-node--bubble):focus circle,
.story-board-overview-pan .story-board-overview-beat-cluster:hover .story-board-overview-node--muted:not(.story-board-overview-node--bubble) circle {
    stroke: rgba(130, 130, 140, 0.55) !important;
}

.story-board-overview-snow-label {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    user-select: none;
}

.story-board-overview-snow-switch.publish-switch {
    width: 2.5rem;
    height: 1.38rem;
}

.story-board-overview-pan.story-board-overview-snow-off .public-snow-canvas {
    opacity: 0;
    visibility: hidden;
}

.story-board-overview-loading,
.story-board-overview-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: var(--spacing-xl);
    font-size: 0.95rem;
}

.story-board-overview-loading.is-overlay,
.story-board-overview-modal--fullscreen .story-board-overview-loading.is-overlay {
    position: absolute;
    inset: 0;
    z-index: 8;
    flex: none;
    margin: 0;
    background: rgba(12, 12, 14, 0.58);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-board-overview-empty {
    color: var(--text-secondary);
}

/* Overview map canvas only: fantasy atmosphere + snow behind SVG (modal chrome stays on-brand above). */
.story-board-overview-pan {
    flex: 1;
    min-height: min(50vh, 520px);
    max-height: min(78vh, 1200px);
    overflow: hidden;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    /* Transparent so ambient snow (canvas, z-index 0) shows through around SVG nodes/lines */
    background: transparent;
    box-shadow: none;
    cursor: grab;
    touch-action: none;
    display: flex;
    align-items: stretch;
    justify-content: center;
    position: relative;
    isolation: isolate;
}

.story-board-overview-pan.story-board-overview-pan-dragging {
    cursor: grabbing;
}

/* Light theme: nodes keep dark fills from SVG; use light text so labels/readouts match dark theme legibility. */
body.theme-light .story-board-overview-pan {
    background: rgba(30, 32, 42, 0.045);
}

body.theme-light .story-board-overview-modal--fullscreen .story-board-overview-pan {
    background: #12111a;
}

body.theme-light .story-board-overview-pan .story-board-overview-fobj {
    color: rgba(255, 255, 255, 0.96);
}

body.theme-light .story-board-overview-pan .story-board-overview-act-heading,
body.theme-light .story-board-overview-pan .story-board-overview-chapter-title,
body.theme-light .story-board-overview-pan .story-board-overview-beat-num {
    color: rgba(255, 255, 255, 0.98);
}

body.theme-light .story-board-overview-pan .story-board-overview-act-body,
body.theme-light .story-board-overview-pan .story-board-overview-chapter-summary,
body.theme-light .story-board-overview-pan .story-board-overview-no-summary,
body.theme-light .story-board-overview-pan .story-board-overview-beat-name,
body.theme-light .story-board-overview-pan .story-board-overview-beat-name--placeholder {
    color: rgba(255, 255, 255, 0.78);
}

body.theme-light .story-board-overview-pan .story-board-overview-inner svg text {
    fill: rgba(90, 72, 48, 0.92);
}

.story-board-overview-pan > .public-snow-canvas {
    z-index: 0;
}

.story-board-overview-zoom-wrap {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    position: relative;
    z-index: 1;
    background: transparent;
    opacity: 1;
    transition: none;
}

/* Hide map only if layout is not ready for a one-shot fit. No fade (fade reads as a jerk). */
.story-board-overview-pan.story-board-overview-pan--map-settling .story-board-overview-zoom-wrap {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.story-board-overview-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    min-height: 0;
    box-sizing: border-box;
    background: transparent;
}

.story-board-overview-pan .story-board-overview-inner svg.story-board-overview-svg {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    overflow: visible;
    display: block;
    user-select: none;
    opacity: 1;
}

.story-board-overview-pan .story-board-overview-inner svg text {
    font-family: inherit;
}

.story-board-overview-entity-node {
    cursor: pointer;
}

.story-board-overview-entity-node:hover .story-board-overview-entity-node__bg,
.story-board-overview-entity-node:focus-visible .story-board-overview-entity-node__bg,
.story-board-overview-entity-node:hover .story-board-overview-entity-node__img,
.story-board-overview-entity-node:focus-visible .story-board-overview-entity-node__img {
    filter: brightness(1.1);
}

.story-board-overview-entity-node__label {
    user-select: none;
    letter-spacing: -0.02em;
}

body:has(#story-board-overview-modal[style*="flex"]) #character-modal.modal,
body:has(#story-board-overview-modal[style*="flex"]) #place-modal.modal,
body:has(#story-board-overview-modal[style*="flex"]) #lore-modal.modal,
body:has(#story-board-overview-modal[style*="flex"]) #item-modal.modal {
    z-index: 5200;
}

.story-board-overview-pan .story-board-overview-fobj {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 10px 12px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 8px;
    line-height: 1.3;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    hyphens: auto;
}

.story-board-overview-pan .story-board-overview-fobj--act {
    font-size: 7.5px;
    line-height: 1.25;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 8px 10px;
}

.story-board-overview-pan .story-board-overview-act-stack {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.story-board-overview-pan .story-board-overview-act-heading {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.12;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    letter-spacing: normal;
    color: var(--text-primary);
}

.story-board-overview-pan .story-board-overview-act-body {
    font-size: 11.5px;
    line-height: 1.38;
    font-weight: 400;
    color: var(--text-secondary);
}

.story-board-overview-pan .story-board-overview-act-body--empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    max-width: 100%;
    text-align: center;
}

.story-board-overview-pan .story-board-overview-act-body-row {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 4px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.story-board-overview-pan .story-board-overview-act-body-row .story-board-overview-act-body {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.story-board-overview-pan .story-board-overview-act-generate-btn {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 10.5px;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 9999px;
    cursor: pointer;
    transition: opacity 0.2s ease, filter 0.2s ease;
}

.story-board-overview-pan .story-board-overview-act-generate-btn:hover:not(:disabled) {
    filter: brightness(1.08);
}

.story-board-overview-pan .story-board-overview-act-generate-btn:disabled {
    opacity: 0.65;
    cursor: wait;
}

.story-board-overview-pan .story-board-overview-act-regenerate-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 26px;
    height: 26px;
    margin-top: 1px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.story-board-overview-pan .story-board-overview-act-regenerate-btn:hover:not(:disabled) {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(var(--accent-rgb, 74, 158, 255), 0.1);
}

.story-board-overview-pan .story-board-overview-act-regenerate-btn:disabled {
    opacity: 0.55;
    cursor: wait;
}

.story-board-overview-pan .story-board-overview-fobj--chapter {
    padding: 6px 8px;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
}

.story-board-overview-pan .story-board-overview-chapter-stack {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.story-board-overview-pan .story-board-overview-chapter-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    letter-spacing: normal;
    color: var(--text-primary);
}

.story-board-overview-pan .story-board-overview-chapter-summary {
    font-size: 11.5px;
    line-height: 1.38;
    color: var(--text-secondary);
    font-weight: 400;
}

.story-board-overview-pan .story-board-overview-chapter-summary--empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    max-width: 100%;
}

.story-board-overview-pan .story-board-overview-no-summary {
    font-size: 11px;
    color: var(--text-secondary);
}

.story-board-overview-pan .story-board-overview-summary-generate-btn {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 10.5px;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 9999px;
    cursor: pointer;
    transition: opacity 0.2s ease, filter 0.2s ease;
}

.story-board-overview-pan .story-board-overview-summary-generate-btn:hover:not(:disabled) {
    filter: brightness(1.08);
}

.story-board-overview-pan .story-board-overview-summary-generate-btn:disabled {
    opacity: 0.65;
    cursor: wait;
}

.story-board-overview-pan .story-board-overview-chapter-summary-row {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 4px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.story-board-overview-pan .story-board-overview-chapter-summary-row .story-board-overview-chapter-summary {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.story-board-overview-pan .story-board-overview-summary-regenerate-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 22px;
    height: 22px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    transition: opacity 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.story-board-overview-pan .story-board-overview-summary-regenerate-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.35);
}

.story-board-overview-pan .story-board-overview-summary-regenerate-btn:disabled {
    opacity: 0.65;
    cursor: wait;
}

body.theme-light .story-board-overview-pan .story-board-overview-summary-regenerate-btn {
    border-color: rgba(48, 48, 48, 0.2);
    background: rgba(48, 48, 48, 0.06);
    color: var(--text-secondary, #505050);
}

body.theme-light .story-board-overview-pan .story-board-overview-summary-regenerate-btn:hover:not(:disabled) {
    background: rgba(48, 48, 48, 0.1);
}

.story-board-overview-pan .story-board-overview-unassigned-actions {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-board-overview-pan .story-board-overview-add-act-btn {
    flex-shrink: 0;
    margin: 0;
    padding: 8px 18px;
    font-size: 0.82rem;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 9999px;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
    transition: filter 0.15s ease, transform 0.12s ease;
}

.story-board-overview-pan .story-board-overview-add-act-btn:hover {
    filter: brightness(1.08);
}

.story-board-overview-pan .story-board-overview-add-act-btn:active {
    transform: scale(0.98);
}

.story-board-overview-pan .story-board-overview-add-beat-fobj {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-board-overview-pan .story-board-overview-add-beat-btn {
    flex-shrink: 0;
    margin: 0;
    padding: 7px 14px;
    font-size: 0.72rem;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-weight: 600;
    line-height: 1.2;
    color: rgba(255, 255, 255, 0.95);
    background: rgba(155, 126, 217, 0.35);
    border: 1px solid rgba(196, 184, 232, 0.55);
    border-radius: 9999px;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
    transition: filter 0.15s ease, transform 0.12s ease, background 0.15s ease;
}

.story-board-overview-pan .story-board-overview-add-beat-btn:hover:not(:disabled) {
    filter: brightness(1.12);
    background: rgba(155, 126, 217, 0.48);
}

.story-board-overview-pan .story-board-overview-add-beat-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.story-board-overview-pan .story-board-overview-add-beat-btn:disabled {
    opacity: 0.55;
    cursor: wait;
}

.story-board-overview-pan .story-board-overview-chapter-mind {
    font-size: 11.5px;
    line-height: 1.38;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 400;
}

.story-board-overview-pan .story-board-overview-beat-fobj {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 3px 4px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-primary);
    font-size: 6.5px;
    line-height: 1.2;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.story-board-overview-pan .story-board-overview-beat-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
}

.story-board-overview-pan .story-board-overview-beat-num {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.1;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    letter-spacing: normal;
    color: var(--text-primary);
}

.story-board-overview-pan .story-board-overview-beat-name {
    flex: 1 1 auto;
    flex-shrink: 1;
    min-width: 0;
    min-height: 0;
    font-size: 9.5px;
    font-weight: 500;
    line-height: 1.2;
    color: var(--text-secondary);
    overflow: hidden;
}

.story-board-overview-pan .story-board-overview-beat-name--placeholder {
    font-weight: 400;
    font-style: italic;
    color: var(--text-secondary);
    opacity: 0.85;
}

.story-board-overview-pan .story-board-overview-beat-cluster {
    pointer-events: auto;
}

.story-board-overview-pan .story-board-overview-node {
    cursor: pointer;
}

.story-board-overview-pan .story-board-overview-node circle {
    transition: stroke 0.55s ease, stroke-width 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.story-board-overview-pan .story-board-overview-node:not(.story-board-overview-node--bubble):hover circle {
    stroke-width: 1.1px;
}

.story-board-overview-pan .story-board-overview-beat-cluster:hover .story-board-overview-beat-node:not(.story-board-overview-node--bubble) circle {
    stroke-width: 1px;
}

.story-board-overview-pan .story-board-overview-node:focus {
    outline: none;
}

.story-board-overview-pan .story-board-overview-node:not(.story-board-overview-node--bubble):focus circle {
    stroke-width: 1.05px;
}

@media (prefers-reduced-motion: reduce) {
    .story-board-overview-pan .story-board-overview-inner svg.story-board-overview-svg {
        animation: none;
        opacity: 1;
    }

    .story-board-overview-pan .story-board-overview-node circle {
        transition: none;
    }
}

.story-board-option-label {
    flex-shrink: 0;
    font-weight: 600;
    color: var(--text-primary);
}

/* General blue button style - pill when in Chapter Build / sub-views */
.story-board-header-back-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    background-color: var(--accent);
    border: 1px solid var(--accent);
    color: #fff;
    border-radius: 9999px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    font-family: inherit;
}

.story-board-header-back-btn:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.story-board-nav {
    margin-bottom: var(--spacing-md);
}

.story-board-back-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.95rem;
}

.story-board-back-btn:hover {
    text-decoration: underline;
}

.story-board-section-title {
    margin: 0 0 var(--spacing-md);
    font-size: 1.1rem;
    font-weight: 600;
}

.story-board-acts-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.story-board-act-card {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    background-color: var(--bg-tertiary);
}

.story-board-act-card:hover {
    border-color: var(--accent);
}

.story-board-act-card strong {
    flex-shrink: 0;
}

.story-board-act-card-title {
    flex: 1;
    min-width: 0;
}

.story-board-act-delete-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-board-act-delete-btn:hover {
    background-color: rgba(200, 60, 60, 0.15);
    color: var(--error, #c0392b);
}

.story-board-act-delete-btn svg {
    width: 14px;
    height: 14px;
    display: block;
}

.story-board-act-placeholder {
    color: rgba(128, 128, 128, 0.65);
    font-style: italic;
}

.story-board-add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-color);
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.95rem;
}

.story-board-add-act-btn {
    width: 100%;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: 9999px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.story-board-add-act-btn:hover {
    background-color: var(--bg-primary);
    border-color: var(--text-tertiary);
}

.story-board-add-btn:not(.story-board-add-act-btn):hover {
    border-color: var(--accent);
    background-color: rgba(var(--accent-rgb, 74, 158, 255), 0.1);
}

/* Voice Actions Modal (Radio Drama) – match References / Creation Settings weight */
.voice-actions-modal {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 3000;
}

.voice-actions-content {
    max-width: 920px;
    width: 94%;
    max-height: 90vh;
    min-height: 420px;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.voice-actions-content .modal-header.voice-actions-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-tertiary);
}

.voice-actions-content .modal-header.voice-actions-header h2 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.15rem;
    font-weight: 600;
    pointer-events: none;
}

.voice-actions-header-icon {
    display: flex;
    align-items: center;
}

.voice-actions-header-icon svg {
    width: 18px;
    height: 18px;
}

.voice-actions-content .modal-close-btn {
    position: relative;
    z-index: 1;
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 var(--spacing-sm);
    line-height: 1;
}

.voice-actions-content .modal-close-btn:hover {
    color: var(--text-primary);
}

.voice-actions-body {
    padding: var(--spacing-lg);
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

@media (min-width: 840px) {
    .voice-actions-body {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: start;
        gap: var(--spacing-lg);
    }

    .voice-actions-section-assignments {
        min-height: 200px;
    }
}

.voice-actions-section {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: var(--spacing-lg);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.voice-actions-section-assignments {
    flex: 1;
    min-height: 120px;
    display: flex;
    flex-direction: column;
}

.voice-actions-section-title {
    margin: 0 0 var(--spacing-xs);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.voice-actions-hint {
    margin: 0 0 var(--spacing-md);
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.45;
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

.voice-actions-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.voice-actions-actor-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-sm) var(--spacing-md);
    padding: var(--spacing-md);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    border-left: 4px solid #9ca3af;
    background-color: var(--bg-secondary);
}

.voice-actions-actor-swatch-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    flex-shrink: 0;
    border: 2px solid var(--border-color);
    cursor: pointer;
    padding: 0;
    transition: border-color 0.15s, transform 0.1s;
}

.voice-actions-actor-swatch-btn:hover {
    border-color: var(--text-secondary);
}

.voice-actions-swatch-color-picker {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

.voice-actions-actor-name-input {
    flex: 1;
    min-width: 80px;
    padding: 4px 6px;
    border: none;
    border-bottom: 1px solid transparent;
    border-radius: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s;
}

.voice-actions-actor-name-input:hover {
    border-bottom-color: var(--border-color);
}

.voice-actions-actor-name-input:focus {
    outline: none;
    border-bottom-color: var(--accent);
    background: var(--bg-tertiary);
}

.voice-actions-narrator-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.voice-actions-narrator-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.voice-actions-narrator-btn.voice-actions-narrator-btn-active {
    background: rgba(var(--accent-rgb, 74, 158, 255), 0.2);
    border-color: var(--accent);
    color: var(--accent);
}

.voice-actions-narrator-btn svg {
    width: 16px;
    height: 16px;
}

.voice-actions-gender-toggle-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
}

.voice-actions-gender-btn {
    padding: 4px 10px;
    font-size: 0.8rem;
    font-weight: 500;
    border: none;
    border-right: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.voice-actions-gender-btn:last-child {
    border-right: none;
}

.voice-actions-gender-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.voice-actions-gender-btn.voice-actions-gender-btn-active {
    background: rgba(var(--accent-rgb, 74, 158, 255), 0.2);
    color: var(--accent);
}

.voice-actions-actor-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.voice-actions-actor-actions button {
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.voice-actions-actor-actions button:hover {
    background: var(--bg-tertiary);
}

.voice-actions-actor-actions .voice-actions-delete-btn:hover {
    border-color: var(--error, #c0392b);
    color: var(--error, #c0392b);
    background: rgba(192, 57, 43, 0.08);
}

.voice-actions-add-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.voice-actions-add-form .voice-actions-input {
    flex: 1;
    min-width: 140px;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.voice-actions-color-input {
    width: 40px;
    height: 40px;
    padding: 2px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    background: var(--bg-primary);
}

.voice-actions-default-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
}

.voice-actions-add-actor-wrap {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--spacing-sm);
}

.voice-actions-add-actor-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: background 0.15s, border-color 0.15s;
}

.voice-actions-add-actor-btn:hover {
    background: var(--accent-hover, var(--accent));
    border-color: var(--accent-hover, var(--accent));
}

.voice-actions-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}

.voice-actions-save-btn {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.voice-actions-save-btn:hover {
    background: var(--accent-hover, var(--accent));
    border-color: var(--accent-hover, var(--accent));
}

.voice-actions-narrator-assignment-row {
    background: rgba(156, 163, 175, 0.12);
    border: 1px solid rgba(156, 163, 175, 0.35);
    border-radius: 8px;
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.voice-actions-narrator-assignment-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.voice-actions-narrator-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.voice-actions-narrator-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.85;
}

.voice-actions-narrator-select {
    color: var(--text-secondary);
}

.voice-actions-no-characters-hint {
    margin: var(--spacing-sm) 0 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.voice-actions-assignments {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: 1;
    min-height: 0;
    max-height: min(42vh, 360px);
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
}

.voice-actions-assignment-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(140px, 220px);
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.voice-actions-assignment-row:last-child {
    border-bottom: none;
}

.voice-actions-assignment-row:nth-child(even) {
    background: var(--bg-primary);
}

.voice-actions-assignment-char {
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.voice-actions-assignment-char-link {
    cursor: pointer;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 4px;
    padding: 4px 6px;
    margin: -4px -6px;
    transition: background 0.15s, color 0.15s;
    border-bottom: 1px dotted var(--border-color);
}

.voice-actions-assignment-char-link:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-color: transparent;
}

/* Character search */
.voice-actions-character-search {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
}

.voice-actions-character-search::placeholder {
    color: var(--text-tertiary);
}

.voice-actions-character-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(var(--accent-rgb, 74, 158, 255), 0.25);
}

@media (max-width: 520px) {
    .voice-actions-assignment-row {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .voice-actions-assignment-select {
        max-width: none;
        justify-self: stretch;
    }
}

.voice-actions-assignment-select {
    flex: 0 1 auto;
    width: 100%;
    max-width: 220px;
    min-width: 140px;
    justify-self: end;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

/* Radio Drama cast panel (above editor): voice actors + characters with ages, centered */
.radio-drama-cast-panel {
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    text-align: center;
}

.radio-drama-cast-section {
    margin-bottom: var(--spacing-md);
}

.radio-drama-cast-section:last-child {
    margin-bottom: 0;
}

.radio-drama-cast-heading {
    margin: 0 0 var(--spacing-sm);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
}

.radio-drama-cast-actors,
.radio-drama-cast-roles {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    align-items: center;
    justify-content: center;
}

.radio-drama-cast-actor-tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}

.radio-drama-cast-actor-tag:hover {
    opacity: 0.9;
}

.radio-drama-cast-role-tag {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.9rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}

.radio-drama-cast-role-tag:hover {
    opacity: 0.9;
}

.radio-drama-cast-role-tag .radio-drama-cast-role-age {
    font-size: 0.8rem;
    opacity: 0.9;
}

/* Accent is border + tint; names use theme text so light pills stay readable */
.radio-drama-cast-actor-name,
.radio-drama-cast-role-name {
    color: var(--text-primary);
}

/* Editor: Radio Drama dialogue highlighting on spoken text only */
.voice-dialogue-line {
    background: transparent !important;
    transition: none !important;
}

/* CVM/CVF (and CV) character lines: centred script dialogue */
body.page-write.book-writing-format-radio-drama .ql-editor .voice-dialogue-line--character {
    text-align: center;
}

.voice-dialogue-segment-empty {
    background-color: transparent !important;
    transition: none !important;
}

.voice-dialogue-read {
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
    /* Inline background updates on first paint / prefs must not animate (feels like a fade-in). */
    transition: none !important;
}

/* Keep mention chips visually consistent inside Radio Drama highlights. */
.ql-editor .voice-dialogue-read .character-mention,
.ql-editor .voice-dialogue-read .place-mention,
.ql-editor .voice-dialogue-read .lore-mention,
.ql-editor .voice-dialogue-read .item-mention,
.ql-editor .voice-dialogue-read [data-character-mention],
.ql-editor .voice-dialogue-read [data-place-mention],
.ql-editor .voice-dialogue-read [data-lore-mention],
.ql-editor .voice-dialogue-read [data-item-mention] {
    background-color: transparent !important;
    box-shadow: none !important;
}

/* In Radio Drama mode, dialogue color is the primary signal, so remove mention chips. */
body.radio-drama-voice-highlight-active .ql-editor .character-mention,
body.radio-drama-voice-highlight-active .ql-editor .place-mention,
body.radio-drama-voice-highlight-active .ql-editor .lore-mention,
body.radio-drama-voice-highlight-active .ql-editor .item-mention,
body.radio-drama-voice-highlight-active .ql-editor [data-character-mention],
body.radio-drama-voice-highlight-active .ql-editor [data-place-mention],
body.radio-drama-voice-highlight-active .ql-editor [data-lore-mention],
body.radio-drama-voice-highlight-active .ql-editor [data-item-mention] {
    background-color: transparent !important;
    box-shadow: none !important;
}

.ql-editor .voice-dialogue-segment,
.ql-editor .voice-dialogue-segment-empty {
    min-height: 0;
}

.story-board-act-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: var(--spacing-xl);
    flex-shrink: 0;
}

.story-board-act-nav-cluster {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.story-board-act-nav-cluster > .story-board-act-delete-nav-btn,
.story-board-act-nav-cluster > .story-board-act-add-btn {
    flex-shrink: 0;
}

.story-board-subview-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
}

.story-board-subview-close-btn:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}

.story-board-subview-close-btn .modal-close-icon-svg {
    display: block;
}

.story-board-act-nav-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    flex: 0 1 auto;
    min-width: 0;
}

.story-board-act-nav-btn {
    width: 36px;
    height: 36px;
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.story-board-act-nav-btn:hover:not(:disabled) {
    border-color: var(--accent);
}

.story-board-act-nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.story-board-act-add-btn {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    color: var(--accent);
}

.story-board-act-add-btn:hover {
    border-color: var(--accent);
    background-color: rgba(var(--accent-rgb, 74, 158, 255), 0.1);
}

.story-board-act-delete-nav-btn {
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-board-act-delete-nav-btn svg {
    flex-shrink: 0;
}

.story-board-act-delete-nav-btn-hidden,
.story-board-act-delete-nav-btn:disabled {
    opacity: 0.35;
    pointer-events: none;
    cursor: default;
}

.story-board-act-delete-nav-btn:hover {
    border-color: rgba(200, 60, 60, 0.5);
    background-color: rgba(200, 60, 60, 0.1);
    color: var(--error, #c0392b);
}

.story-board-act-title {
    font-weight: 600;
}

#story-board-act-build {
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    width: 100%;
}

.story-board-act-fields {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1 1 auto;
    min-height: 0;
    gap: var(--spacing-md);
}

.story-board-act-fields .story-board-label {
    align-self: center;
}

.story-board-act-fields .story-board-chapter-range {
    justify-content: center;
}

.story-board-act-fields .story-board-textarea {
    width: 100%;
}

.story-board-label {
    font-size: 0.9rem;
    font-weight: 500;
}

.story-board-chapter-range {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.story-board-input {
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.story-board-input-number {
    width: 60px;
}

.story-board-textarea {
    width: 100%;
    padding: var(--spacing-md);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: inherit;
    resize: vertical;
}

.story-board-act-info {
    flex: 1 1 auto;
    min-height: 200px;
}

.story-board-act-fields .story-board-bubble-picker {
    margin-top: auto;
    flex-shrink: 0;
}

.story-board-bubble-cover-field,
.story-board-overview-cover-toggle,
.story-board-overview-cover-label {
    display: none !important;
}

.story-board-bubble-cover-field {
    width: 100%;
    flex-direction: column;
    gap: 0.35rem;
}

.story-board-bubble-cover-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 0.75rem;
}

.story-board-bubble-cover-count {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.story-board-bubble-cover-input {
    width: 100%;
    border-radius: 8px;
    text-align: left;
}

.story-board-bubble-cover-textarea {
    min-height: 2.25rem;
    max-height: 9rem;
    resize: none;
    overflow-y: auto;
    line-height: 1.35;
    padding: var(--spacing-sm) var(--spacing-md);
    field-sizing: content;
}

.story-board-bubble-cover-textarea::placeholder {
    color: rgba(255, 255, 255, 0.17);
    opacity: 1;
}

body.theme-light .story-board-bubble-cover-textarea::placeholder {
    color: rgba(0, 0, 0, 0.26);
    opacity: 1;
}

.story-board-ch-summary-bubble-cover {
    margin-bottom: 0.75rem;
}

.story-board-beat-edit-fields .story-board-bubble-cover-field {
    margin-bottom: 0.25rem;
}

.story-board-bubble-picker {
    width: 100%;
    margin-top: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
}

.story-board-bubble-picker-label {
    align-self: center;
}

.story-board-bubble-swatches {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.story-board-bubble-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: var(--bubble-swatch);
    cursor: pointer;
    padding: 0;
    box-sizing: border-box;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.story-board-bubble-swatch:hover {
    transform: scale(1.08);
}

.story-board-bubble-swatch--selected {
    box-shadow: 0 0 0 2px var(--bg-secondary), 0 0 0 4px rgba(255, 255, 255, 0.85);
}

.story-board-beat-edit-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: var(--spacing-xl);
    flex-shrink: 0;
}

.story-board-beat-edit-nav-cluster {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.story-board-beat-edit-nav-cluster > .story-board-beat-edit-delete-btn,
.story-board-beat-edit-nav-cluster > .story-board-beat-edit-add-btn {
    flex-shrink: 0;
}

.story-board-beat-edit-nav-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    flex: 0 1 auto;
    min-width: 0;
}

.story-board-beat-edit-nav-btn {
    width: 36px;
    height: 36px;
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.story-board-beat-edit-nav-btn:hover:not(:disabled) {
    border-color: var(--accent);
}

.story-board-beat-edit-nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.story-board-beat-edit-add-btn {
    color: var(--accent);
}

.story-board-beat-edit-delete-btn {
    color: var(--text-tertiary);
}

.story-board-beat-edit-delete-btn:hover {
    border-color: rgba(200, 60, 60, 0.45);
    color: var(--error, #c0392b);
}

.story-board-beat-edit-title {
    font-weight: 600;
}

#story-board-beat-edit {
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    width: 100%;
}

.story-board-beat-edit-loading {
    flex: 0 0 auto;
    padding: 0.35rem 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
}

.story-board-beat-edit-fields {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    gap: var(--spacing-md);
    width: 100%;
}

.story-board-beat-edit-textarea {
    flex: 1 1 auto;
    min-height: 200px;
    width: 100%;
    resize: vertical;
}

.story-board-beat-edit-fields .story-board-bubble-picker {
    margin-top: auto;
    flex-shrink: 0;
}

.story-board-beat-delete-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.story-board-beat-delete-btn:hover {
    color: var(--error, #c0392b);
    background: rgba(200, 60, 60, 0.1);
}

/* Chapter Map: chapter nav (delete | chapter selector | add) */
.story-board-chapter-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: var(--spacing-xl);
    padding: 0;
}

.story-board-chapter-nav-cluster {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.story-board-chapter-nav-cluster > .story-board-chapter-delete-btn,
.story-board-chapter-nav-cluster > .story-board-chapter-add-btn {
    flex-shrink: 0;
}

.story-board-chapter-nav-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    flex: 0 1 auto;
    min-width: 0;
}

.story-board-chapter-nav-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-board-chapter-nav-btn:hover:not(:disabled) {
    background: var(--bg-primary);
    border-color: var(--text-tertiary);
}

.story-board-chapter-nav-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.story-board-chapter-add-btn {
    color: var(--accent);
}

.story-board-chapter-add-btn:hover {
    border-color: var(--accent);
    background-color: rgba(var(--accent-rgb, 74, 158, 255), 0.1);
}

.story-board-chapter-delete-btn {
    color: var(--text-tertiary);
}

.story-board-chapter-delete-btn:hover {
    border-color: rgba(200, 60, 60, 0.5);
    background-color: rgba(200, 60, 60, 0.1);
    color: var(--error, #c0392b);
}

/* Chapter Build: fill modal height; beats list grows so empty state matches taller layout */
.story-board-chapter-map-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.story-board-chapter-map-content .story-board-chapter-label {
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    font: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 0.18em;
}

.story-board-chapter-map-content .story-board-chapter-label:hover {
    color: var(--accent-color, var(--text-primary));
}

.story-board-instructions {
    margin: 0 0 var(--spacing-md);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.story-board-instructions-two-lines {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.4em;
    margin-bottom: var(--spacing-lg);
    padding: 0 var(--spacing-sm);
}

.story-board-beats-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    flex: 1 1 auto;
    min-height: min(320px, 42vh);
}

.story-board-beat-item {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-tertiary);
    overflow: hidden;
}

.story-board-beat-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-lg) var(--spacing-xl);
    cursor: pointer;
}

.story-board-beat-header:hover {
    background-color: var(--bg-primary);
}

.story-board-beat-drag {
    cursor: grab;
    color: var(--text-tertiary);
    font-size: 1rem;
    padding: 0 var(--spacing-xs);
    flex-shrink: 0;
}

.story-board-beat-drag:active {
    cursor: grabbing;
}

.story-board-beat-title {
    flex: 1;
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.35;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 0.16em;
    cursor: pointer;
}

.story-board-beat-toggle {
    flex-shrink: 0;
    color: var(--text-tertiary);
    font-size: 0.8rem;
}

.story-board-beat-details {
    padding: 0 var(--spacing-md) var(--spacing-md);
}

.story-board-beat-textarea {
    width: 100%;
    padding: var(--spacing-md);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 80px;
}

.story-board-beat-details .story-board-beat-item-bubble-cover {
    margin-bottom: 0.5rem;
}

.story-board-beat-bubble-cover-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-xs);
    padding: 0 2px;
}

.story-board-beat-bubble-cover-label {
    font-size: 0.72rem;
    color: var(--text-tertiary);
}

.story-board-beat-bubble-cover-count {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
}

.story-board-beat-item.story-board-beat-dragging {
    opacity: 0.7;
}

.story-board-beat-item.story-board-beat-drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(var(--accent-rgb, 74, 158, 255), 0.3);
}

/* Add Beat button - full width, light gray, blue plus and text, squarcle */
.story-board-add-beat-btn {
    flex-shrink: 0;
    width: 100%;
    padding: var(--spacing-md) var(--spacing-lg);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
}

.story-board-add-beat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.story-board-add-beat-icon svg {
    width: 14px;
    height: 14px;
    display: block;
}

.story-board-add-beat-btn:hover:not(:disabled) {
    background-color: var(--bg-primary);
    border-color: var(--accent);
}

.story-board-add-beat-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Delete confirm: above story-board-modal--over-overview (5100) and overview fullscreen (5000) */
.story-board-confirm-modal {
    z-index: 5200;
}

.story-board-confirm-content {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: var(--spacing-xl);
    max-width: 400px;
    width: 90%;
}

.story-board-confirm-message {
    margin: 0 0 var(--spacing-lg);
    color: var(--text-primary);
}

.story-board-confirm-actions {
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-end;
}

.story-board-confirm-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}

.story-board-confirm-cancel {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.story-board-confirm-cancel:hover {
    background: var(--bg-primary);
}

.story-board-confirm-delete {
    background: #c0392b;
    border: 1px solid #a93226;
    color: #fff;
}

.story-board-confirm-delete:hover {
    background: #a93226;
}

/* Writing format is set once at book creation; Format Settings keeps DB value but hides the control */
body.page-write #creation-writing-format-section {
    display: none !important;
}

/* New character: Basic vs Full choice + guided wizard */
.character-new-mode-modal,
.character-basic-wizard-modal {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 3040;
    align-items: center;
    justify-content: center;
}

.character-new-mode-content {
    position: relative;
    width: min(38rem, 94vw);
    max-width: min(38rem, 94vw);
    padding: 1.55rem 1.65rem 1.35rem;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: color-mix(in srgb, #ffffff 2.2%, #070709);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.04),
        0 28px 70px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.character-new-mode-content::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background:
        radial-gradient(ellipse 125% 95% at -6% -14%, color-mix(in srgb, #4ec8e8 22%, #070709) 0%, color-mix(in srgb, #4ec8e8 5%, #070709) 44%, #070709 76%),
        radial-gradient(ellipse 125% 95% at 106% -14%, color-mix(in srgb, #9b7aff 20%, #070709) 0%, color-mix(in srgb, #9b7aff 4.5%, #070709) 44%, #070709 76%),
        linear-gradient(to top, color-mix(in srgb, #f062b0 7%, #070709) 0%, #070709 36%);
    opacity: 0.68;
}

.character-new-mode-content::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px);
    background-size: 17px 16px;
    background-repeat: repeat;
    opacity: 0.09;
}

.character-new-mode-content > * {
    position: relative;
    z-index: 2;
}

.character-new-mode-content .character-new-mode-title::before {
    content: "";
    position: absolute;
    top: -1.25rem;
    left: calc(50% - 6rem);
    width: 12rem;
    height: 3px;
    border-radius: 999px;
    background: linear-gradient(90deg, #4ec8e8 0%, #7c5cfa 48%, #f062b0 100%);
    opacity: 0.5;
}

.character-new-mode-close {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--border-color) 65%, rgba(255, 255, 255, 0.22));
    background: color-mix(in srgb, var(--bg-secondary) 76%, var(--bg-primary) 24%);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.character-new-mode-back {
    position: absolute;
    top: var(--spacing-md);
    left: var(--spacing-md);
}

.character-new-mode-title {
    margin: 2.25rem 0 0.35rem;
    text-align: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    position: relative;
}

.character-new-mode-sub {
    margin: 0 0 var(--spacing-lg);
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.character-new-mode-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--spacing-md);
}

.character-new-mode-card {
    text-align: center;
    padding: 1rem 1.05rem;
    border-radius: 14px;
    border: 1px solid color-mix(in srgb, var(--border-color) 58%, rgba(255, 255, 255, 0.16));
    background: color-mix(in srgb, var(--bg-secondary) 56%, var(--bg-primary) 44%);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease, background 0.15s ease;
    font: inherit;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 10px 24px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

.character-new-mode-card::before {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    pointer-events: none;
    background:
        radial-gradient(120% 120% at 0% 0%, rgba(78, 200, 232, 0.11) 0%, rgba(78, 200, 232, 0) 45%),
        radial-gradient(140% 110% at 100% 0%, rgba(155, 122, 255, 0.14) 0%, rgba(155, 122, 255, 0) 50%);
    opacity: 0.7;
}

.character-new-mode-card:hover {
    border-color: color-mix(in srgb, #8f72ff 58%, var(--border-color));
    background: color-mix(in srgb, var(--bg-secondary) 38%, var(--bg-primary) 62%);
    box-shadow:
        0 0 0 1px rgba(143, 114, 255, 0.32),
        0 16px 30px rgba(0, 0, 0, 0.36);
    transform: translateY(-1px);
}

.character-new-mode-card-kicker {
    display: block;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent, #7e57c2);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.character-new-mode-card-icon {
    width: 2.15rem;
    height: 2.15rem;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.6rem;
    color: #c9b8ff;
    border: 1px solid color-mix(in srgb, var(--border-color) 58%, rgba(143, 114, 255, 0.42));
    background:
        radial-gradient(120% 120% at 0% 0%, rgba(78, 200, 232, 0.16) 0%, rgba(78, 200, 232, 0) 55%),
        radial-gradient(130% 100% at 100% 0%, rgba(155, 122, 255, 0.22) 0%, rgba(155, 122, 255, 0) 56%),
        color-mix(in srgb, var(--bg-secondary) 54%, var(--bg-primary) 46%);
}

.character-new-mode-card-title {
    display: block;
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.character-new-mode-card-desc {
    display: block;
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--text-secondary);
}

body.theme-light .character-new-mode-content {
    background:
        radial-gradient(ellipse 125% 90% at -6% -16%, color-mix(in srgb, #4ec8e8 12%, var(--bg-secondary)) 0%, color-mix(in srgb, #4ec8e8 3%, var(--bg-secondary)) 40%, var(--bg-secondary) 64%),
        radial-gradient(ellipse 110% 82% at 106% -6%, color-mix(in srgb, #9b7aff 11%, var(--bg-secondary)) 0%, color-mix(in srgb, #9b7aff 2.8%, var(--bg-secondary)) 42%, var(--bg-secondary) 66%),
        color-mix(in srgb, #000000 2.5%, var(--bg-secondary)),
        var(--bg-secondary);
    border: 1px solid color-mix(in srgb, var(--border-color) 92%, transparent);
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--border-color) 45%, transparent),
        0 24px 56px rgba(0, 0, 0, 0.12);
}

body.theme-light .character-new-mode-content::before,
body.theme-light .character-new-mode-content::after {
    opacity: 0;
}

body.theme-light .character-new-mode-card {
    background: color-mix(in srgb, #000000 1.8%, var(--bg-primary));
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.65),
        0 8px 18px rgba(20, 28, 45, 0.08);
}

body.theme-light .character-new-mode-card-icon {
    color: color-mix(in srgb, #6a42f4 75%, #2f7de0);
    border-color: color-mix(in srgb, var(--border-color) 85%, rgba(106, 66, 244, 0.26));
    background:
        radial-gradient(120% 120% at 0% 0%, rgba(78, 200, 232, 0.11) 0%, rgba(78, 200, 232, 0) 55%),
        radial-gradient(130% 100% at 100% 0%, rgba(155, 122, 255, 0.16) 0%, rgba(155, 122, 255, 0) 56%),
        color-mix(in srgb, #000000 1.8%, var(--bg-primary));
}

@media (max-width: 640px) {
    .character-new-mode-cards {
        grid-template-columns: 1fr;
    }
}

.character-basic-wizard-panel {
    position: relative;
    width: min(560px, 94vw);
    max-height: min(640px, 90vh);
    padding: 0.95rem 1.25rem 1.15rem;
    border-radius: 18px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    box-shadow: 0 20px 56px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.character-basic-wizard-close {
    position: absolute;
    top: 0.7rem;
    right: 0.7rem;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.character-basic-wizard-top-back {
    position: absolute;
    top: 0.7rem;
    left: 0.7rem;
}

.character-basic-wizard-heading {
    margin: 0.4rem 0 0.15rem;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
}

.character-basic-wizard-progress {
    margin: 0 0 0.55rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.character-basic-wizard-shell {
    display: flex;
    align-items: stretch;
    gap: var(--spacing-sm);
    flex: 1;
    min-height: 0;
}

.character-basic-wizard-frame {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: var(--spacing-md);
    background: var(--bg-primary);
    overflow: auto;
}

.character-basic-wizard-nav {
    flex-shrink: 0;
    align-self: center;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.character-basic-wizard-nav--disabled {
    opacity: 0.35;
    pointer-events: none;
    cursor: default;
}

.character-basic-wizard-field-block {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.character-basic-wizard-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-width: 0;
}

.character-basic-wizard-label-row .character-basic-wizard-label {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
}

.character-basic-wizard-label-row .character-basic-wizard-inline-actions {
    flex: 0 0 auto;
}

.character-basic-wizard-label-row--appearance-heading {
    align-items: flex-start;
    margin-bottom: 0.35rem;
}

.character-basic-wizard-label-row--appearance-heading .character-basic-wizard-label--appearance-section {
    margin: 0;
}

.character-basic-wizard-label-row--appearance-heading .character-basic-wizard-inline-actions {
    padding-top: 0.15rem;
}

.character-basic-wizard-label {
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
}

.character-basic-wizard-input,
.character-basic-wizard-textarea,
.character-basic-wizard-select {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: var(--font-ui, var(--font-brand, inherit));
    font-size: 0.9rem;
    padding: 0.55rem 0.65rem;
    outline: none;
    box-shadow: none;
    appearance: none;
    -webkit-appearance: none;
}

.character-basic-wizard-input::placeholder,
.character-basic-wizard-textarea::placeholder {
    color: rgba(255, 255, 255, 0.14);
}

.character-basic-wizard-textarea {
    resize: vertical;
    min-height: 4.5rem;
}

.character-basic-wizard-input:focus,
.character-basic-wizard-textarea:focus,
.character-basic-wizard-select:focus {
    outline: none !important;
    box-shadow: none !important;
    border-color: color-mix(in srgb, var(--border-color) 82%, #ffffff 18%);
}

.character-basic-wizard-name-actions {
    margin-bottom: 0.35rem;
}

.character-basic-wizard-name-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--spacing-sm);
}

@media (max-width: 520px) {
    .character-basic-wizard-name-grid {
        grid-template-columns: 1fr;
    }
}

.character-basic-wizard-name-cell {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: relative;
}

.character-basic-wizard-age-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 0.65rem;
    align-items: end;
}

.character-basic-wizard-age-cell {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.character-basic-wizard-age-caption {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.character-basic-wizard-age-divider {
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding-bottom: 0.55rem;
}

.character-basic-wizard-confirm {
    position: fixed;
    inset: 0;
    z-index: 52000;
    display: none;
    align-items: center;
    justify-content: center;
}

.character-basic-wizard-confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.character-basic-wizard-confirm-card {
    position: relative;
    width: min(360px, 90vw);
    padding: 1rem 1rem 0.95rem;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
}

.character-basic-wizard-confirm-title {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    color: var(--text-primary);
}

.character-basic-wizard-confirm-copy {
    margin: 0 0 0.9rem;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.character-basic-wizard-confirm-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.55rem;
}

.character-basic-wizard-confirm-actions .btn {
    min-width: auto;
    width: auto;
    flex: 0 0 auto;
}

.character-basic-wizard-label--appearance-section {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0.02em;
}

.character-basic-wizard-appearance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem 0.75rem;
    width: 100%;
}

.character-basic-wizard-appearance-cell--full {
    grid-column: 1 / -1;
}

.character-basic-wizard-sublabel {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    text-transform: capitalize;
    letter-spacing: 0.03em;
}

.character-basic-wizard-field-block--appearance .character-basic-wizard-input--pill {
    border-radius: 999px;
    min-height: 2.4rem;
}

.character-basic-wizard-field-block--appearance {
    width: 100%;
}

.character-basic-wizard-mini-actions {
    position: absolute;
    right: 0;
    top: 0;
    display: flex;
    gap: 4px;
}

.character-basic-wizard-random-chip,
.character-basic-wizard-inline-actions .character-basic-wizard-random-chip {
    font-size: 0.65rem;
    padding: 0.12rem 0.4rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
}

.character-basic-wizard-label--appearance-section {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0.02em;
}

.character-basic-wizard-appearance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem 0.75rem;
    width: 100%;
}

.character-basic-wizard-appearance-cell--full {
    grid-column: 1 / -1;
}

.character-basic-wizard-sublabel {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    text-transform: capitalize;
    letter-spacing: 0.03em;
}

.character-basic-wizard-field-block--appearance .character-basic-wizard-input--pill {
    border-radius: 999px;
    min-height: 2.4rem;
}

.character-basic-wizard-field-block--appearance {
    width: 100%;
}

/* Explicit content tier hidden: prompts use full ceiling (match source, no escalation); ages still capped in JS. */
.creation-settings-explicit-section {
    display: none !important;
}

/* --- Chapter summary modal (Overview Map chapter node) — match Act / Beat story-board-content --- */
.story-board-chapter-summary-modal {
    z-index: 3400;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.story-board-chapter-summary-modal.story-board-chapter-summary-modal--over-overview {
    z-index: 5100 !important;
    background: transparent !important;
    backdrop-filter: none !important;
    pointer-events: auto;
}

.story-board-chapter-summary-modal.story-board-chapter-summary-modal--over-overview .story-board-chapter-summary-modal-content {
    pointer-events: auto;
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.55);
}

.story-board-chapter-summary-modal-content {
    box-sizing: border-box;
    width: min(700px, 90vw);
    max-height: min(640px, 90vh);
    padding: 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.55);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.story-board-chapter-summary-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.story-board-ch-summary-title-label {
    flex: 1;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.story-board-chapter-summary-modal-content .story-board-ch-summary-close {
    flex-shrink: 0;
    position: relative;
    top: 0;
    right: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 var(--spacing-sm);
    line-height: 1;
}

.story-board-chapter-summary-modal-content .story-board-ch-summary-close:hover {
    color: var(--text-primary);
}

.story-board-chapter-summary-modal-body {
    padding: var(--spacing-xl);
    padding-bottom: calc(var(--spacing-xl) + var(--spacing-md));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.story-board-ch-summary-auto-row {
    display: flex;
    justify-content: flex-start;
}

.story-board-ch-summary-auto-btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: #f8fafc;
    font-family: var(--font-ui, 'Greycliff CF', 'Greycliff', sans-serif);
    font-size: 0.76rem;
    font-weight: 600;
    padding: 0.35rem 0.95rem;
    border-radius: 9999px;
    cursor: pointer;
    transition: filter 0.15s ease, border-color 0.15s ease;
}

.story-board-ch-summary-auto-btn:hover:not(:disabled) {
    filter: brightness(1.06);
    border-color: rgba(155, 126, 217, 0.55);
}

.story-board-ch-summary-auto-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.story-board-chapter-summary-modal-body .story-board-ch-summary-textarea {
    width: 100%;
    min-height: 200px;
}

.story-board-ch-summary-bubble-picker {
    width: 100%;
    margin-top: var(--spacing-lg);
    padding-top: 0;
    border-top: none;
}

.story-board-ch-summary-bubble-picker .story-board-label {
    align-self: center;
}

.story-board-ch-summary-bubble-picker .story-board-bubble-swatches {
    justify-content: center;
}

body.theme-light .story-board-chapter-summary-modal-content {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
}

body.theme-light .story-board-ch-summary-title-label {
    color: var(--text-primary);
}

/* Characters modal: tier rows only (no suggestions strip) */
.places-people-lore-modal.characters-only-mode .places-people-lore-body,
.places-people-lore-modal.single-ref-mode .places-people-lore-body {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-suggestions-bottom {
    display: none !important;
}

.places-people-lore-modal.characters-only-mode .places-people-lore-columns,
.places-people-lore-modal.single-ref-mode .places-people-lore-columns {
    flex: 1 1 auto;
}

.places-people-lore-modal.characters-only-mode .characters-modal-tiered-layout,
.places-people-lore-modal.single-ref-mode .characters-modal-tiered-layout {
    gap: 0;
}

.places-people-lore-modal.characters-only-mode .characters-modal-tier,
.places-people-lore-modal.single-ref-mode .characters-modal-tier {
    border-radius: 12px;
    padding: 14px 12px 16px;
    margin-bottom: 12px;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.08);
}

.places-people-lore-modal.characters-only-mode .characters-modal-tier:nth-of-type(1),
.places-people-lore-modal.single-ref-mode .characters-modal-tier:nth-of-type(1) {
    background: linear-gradient(180deg, #2f2e38 0%, #28272f 48%, #222128 100%);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.places-people-lore-modal.characters-only-mode .characters-modal-tier:nth-of-type(2),
.places-people-lore-modal.single-ref-mode .characters-modal-tier:nth-of-type(2) {
    background: linear-gradient(180deg, #201f27 0%, #1b1a21 52%, #16151d 100%);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.places-people-lore-modal.characters-only-mode .characters-modal-tier:nth-of-type(3),
.places-people-lore-modal.single-ref-mode .characters-modal-tier:nth-of-type(3) {
    background: linear-gradient(180deg, #141418 0%, #111115 52%, #0c0c0f 100%);
    border-color: rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.35);
}

body.theme-light .places-people-lore-modal.characters-only-mode .places-people-lore-suggestions-bottom {
    background: rgba(48, 48, 48, 0.04);
    border-color: rgba(48, 48, 48, 0.1);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier:nth-of-type(1),
body.theme-light .places-people-lore-modal.single-ref-mode .characters-modal-tier:nth-of-type(1) {
    background: linear-gradient(180deg, #fbfbfe 0%, #f3f2f8 52%, #eceaf3 100%);
    border-color: rgba(48, 48, 48, 0.1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier:nth-of-type(2),
body.theme-light .places-people-lore-modal.single-ref-mode .characters-modal-tier:nth-of-type(2) {
    background: linear-gradient(180deg, #f0eef5 0%, #eae7f1 52%, #e4e1ec 100%);
    border-color: rgba(48, 48, 48, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

body.theme-light .places-people-lore-modal.characters-only-mode .characters-modal-tier:nth-of-type(3),
body.theme-light .places-people-lore-modal.single-ref-mode .characters-modal-tier:nth-of-type(3) {
    background: linear-gradient(180deg, #e6e3ed 0%, #dfdceb 52%, #d8d5e6 100%);
    border-color: rgba(48, 48, 48, 0.07);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

/* Ink depleted: gray out AI tools and image generation */
body.ink-depleted .sidebar-ai-tools .ai-tool-btn,
body.ink-depleted .sidebar-ai-tools .ai-sidebar-action,
body.ink-depleted .character-portrait-generate-btn,
body.ink-depleted .profile-avatar-generate-btn,
body.ink-depleted .cover-gen-btn,
body.ink-depleted .publish-cover-gen-btn,
body.ink-depleted .sequence-frame-gen-btn,
body.ink-depleted .context-menu-item[data-ai-action],
body.ink-depleted [data-ink-guarded] {
    opacity: 0.38;
    pointer-events: none;
    filter: grayscale(0.85);
}

body.ink-depleted .sidebar-ai-tools .ai-tool-btn[aria-disabled="true"],
body.ink-depleted .character-portrait-generate-btn[disabled],
body.ink-depleted .profile-avatar-generate-btn[disabled] {
    cursor: not-allowed;
}

@media (max-width: 768px) {
    body.page-write #ai-tools-sidebar .ai-tools-panel {
        padding: 0.65rem 0.7rem 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    body.page-write #ai-tools-sidebar .ai-tool-btn {
        width: 100%;
        min-width: 0;
        min-height: 36px;
        font-size: 0.8rem;
        border-radius: 0;
        background: transparent;
        border: 0;
    }

    body.page-write #ai-tools-sidebar .ai-tool-detail-header {
        display: none;
    }

    body.page-write #ai-tools-sidebar .ai-tool-write-actions-block .ai-tool-action-row,
    body.page-write #ai-tools-sidebar .ai-tool-action-row {
        flex-direction: column;
        width: 100%;
        min-width: 0;
        gap: 0.35rem;
    }

    body.page-write #ai-tools-sidebar .ai-tool-write-actions-block .ai-tool-action-main.ai-tool-btn,
    body.page-write #ai-tools-sidebar .ai-tool-action-grammar.ai-tool-btn {
        width: 100%;
        min-width: 0;
        min-height: 36px;
    }

    body.page-write #ai-tools-sidebar .ai-tool-detail-stack {
        flex: none;
        flex-direction: row;
        width: 100%;
        gap: 0.35rem;
    }

    body.page-write #ai-tools-sidebar .ai-tool-detail-btn {
        flex: 1;
        min-height: 28px;
        padding: 0.2rem 0.35rem;
        font-size: 0.7rem;
    }

    body.page-write #ai-tools-sidebar .ai-tool-section-header {
        font-size: 0.58rem;
        margin-bottom: 0.15rem;
    }

    body.page-write #ai-tools-sidebar .ai-tool-divider {
        margin: 0.45rem 0;
    }
}

/* Generative AI off: keep markup, hide Grok tools. Writer TTS + Grammar stay. */
body.uyi-no-user-ai .uyi-user-ai-only,
body.uyi-no-user-ai #ai-word-finder-btn,
body.uyi-no-user-ai #ai-brainstorm-btn,
body.uyi-no-user-ai #ai-ask-anything-btn,
body.uyi-no-user-ai #tts-speak-btn,
body.uyi-no-user-ai .editor-stats-personas,
body.uyi-no-user-ai #chapters-assistant-settings-btn,
body.uyi-no-user-ai #ai-assistant-companion,
body.uyi-no-user-ai .character-modal-role-generate-btn,
body.uyi-no-user-ai #character-editor-apply-btn,
body.uyi-no-user-ai #lore-editor-apply-btn,
body.uyi-no-user-ai #place-editor-apply-btn,
body.uyi-no-user-ai #item-editor-apply-btn,
body.uyi-no-user-ai .story-board-overview-summary-generate-btn,
body.uyi-no-user-ai .story-board-overview-summary-regenerate-btn,
body.uyi-no-user-ai .story-board-overview-act-regenerate-btn,
body.uyi-no-user-ai #rewrite-result-panel {
    display: none !important;
}

