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

:root {
    --bg-page: #f3f7fb;
    --bg-orb-a: #d4bbf7;
    --bg-orb-b: #bfd5ff;
    --bg-orb-c: #f0bbf7;
    --surface: rgba(255, 255, 255, 0.8);
    --surface-strong: #ffffff;
    --surface-muted: #f8fbff;
    --text-primary: #10243a;
    --text-secondary: #51667c;
    --text-soft: #7d8ea1;
    --border: rgba(16, 36, 58, 0.12);
    --border-strong: rgba(16, 36, 58, 0.2);
    --accent: #7c3aed;
    --accent-strong: #5b21b6;
    --accent-soft: #ede9fe;
    --success: #1f9d66;
    --warning: #cf8a00;
    --error: #c93d4a;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --shadow-sm: 0 6px 18px rgba(16, 36, 58, 0.08);
    --shadow-md: 0 16px 44px rgba(16, 36, 58, 0.12);
    --shadow-lg: 0 24px 56px rgba(16, 36, 58, 0.18);
    --transition: 180ms ease;
    /* Aliases used in inline styles */
    --surface-color: #ffffff;
    --text-color: #10243a;
}

[data-theme="dark"] {
    --bg-page: #0d1117;
    --bg-orb-a: #2d1b69;
    --bg-orb-b: #1a1040;
    --bg-orb-c: #3b0764;
    --surface: rgba(22, 27, 34, 0.85);
    --surface-strong: #161b22;
    --surface-muted: #111820;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-soft: #6e7681;
    --border: rgba(201, 209, 217, 0.12);
    --border-strong: rgba(201, 209, 217, 0.2);
    --accent: #a78bfa;
    --accent-strong: #c4b5fd;
    --accent-soft: rgba(167, 139, 250, 0.15);
    --success: #3fb950;
    --warning: #d29922;
    --error: #f85149;
    --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 16px 44px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.55);
    /* Aliases used in inline styles */
    --surface-color: #161b22;
    --text-color: #c9d1d9;
}

html,
body {
    min-height: 100%;
}

body {
    background:
        radial-gradient(
            48rem 28rem at 12% -8%,
            var(--bg-orb-a) 0%,
            transparent 60%
        ),
        radial-gradient(
            42rem 24rem at 100% 8%,
            var(--bg-orb-b) 0%,
            transparent 58%
        ),
        radial-gradient(
            30rem 24rem at 70% 100%,
            var(--bg-orb-c) 0%,
            transparent 62%
        ),
        var(--bg-page);
    color: var(--text-primary);
    font-family: "Sora", "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
    line-height: 1.5;
}

.container {
    width: min(1280px, 100% - 2rem);
    margin: 1.25rem auto 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.header {
    padding: 1.4rem 1.6rem;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(167, 139, 250, 0.25);
    background: linear-gradient(
        120deg,
        rgba(255, 255, 255, 0.82),
        rgba(237, 233, 254, 0.6)
    );
    box-shadow: var(--shadow-md), 0 0 0 1px rgba(124, 58, 237, 0.06);
    backdrop-filter: blur(8px);
}

.title {
    font-size: clamp(1.55rem, 2.3vw, 2.55rem);
    letter-spacing: -0.03em;
    font-weight: 700;
    margin-bottom: 0.3rem;
    background: linear-gradient(135deg, #7c3aed 0%, #a855f7 50%, #6366f1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: clamp(0.94rem, 1.4vw, 1.05rem);
    max-width: 68ch;
}

.main {
    display: grid;
    gap: 1.1rem;
}

.input-section,
.stream-section,
.result-section {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    padding: clamp(1rem, 2.5vw, 1.7rem);
}

.result-section {
    background: var(--surface-strong);
}

.form-group {
    margin-bottom: 1rem;
}

.label {
    display: block;
    margin-bottom: 0.45rem;
    color: var(--text-primary);
    font-size: 0.92rem;
    font-weight: 600;
}

.input,
.textarea,
textarea.content-box,
input[type="file"] {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 0.74rem 0.92rem;
    font: inherit;
    transition:
        border-color var(--transition),
        box-shadow var(--transition),
        background var(--transition);
}

.textarea {
    min-height: 110px;
    resize: vertical;
}

.input:hover,
.textarea:hover,
textarea.content-box:hover,
input[type="file"]:hover {
    border-color: var(--border-strong);
}

.input:focus,
.textarea:focus,
textarea.content-box:focus,
input[type="file"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

textarea.content-box {
    padding: 0.95rem !important;
    border-color: rgba(16, 36, 58, 0.14) !important;
    background: var(--surface-muted) !important;
}

.form-row {
    display: flex;
    gap: 0.8rem;
    align-items: flex-start !important;
    flex-wrap: wrap;
}

.form-row > .form-group {
    flex: 1;
    min-width: 230px;
}

.generation-buttons {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
    align-items: stretch;
}

.generation-buttons > button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.top-import-actions {
    display: flex;
    justify-content: flex-end;
}

#import-card-top-btn {
    min-height: 42px;
}

#generate-btn {
    flex: 1 1 240px !important;
    min-width: 0 !important;
}

#stop-btn {
    min-height: 44px;
}

.btn-primary,
.btn-secondary,
.btn-outline,
.btn-stop,
.btn-small {
    border-radius: 999px;
    border: 1px solid transparent;
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.1;
    padding: 0.7rem 1.15rem;
    transition:
        transform var(--transition),
        box-shadow var(--transition),
        border-color var(--transition),
        background var(--transition),
        color var(--transition);
}

.btn-primary {
    color: #fff;
    background: linear-gradient(140deg, #7c3aed 0%, #5b21b6 100%);
    box-shadow: 0 9px 24px rgba(124, 58, 237, 0.34);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 13px 28px rgba(124, 58, 237, 0.42);
}

.btn-primary:disabled {
    opacity: 0.64;
    cursor: not-allowed;
}

.btn-secondary {
    color: #fff;
    background: linear-gradient(140deg, #2ca56f 0%, #1f8f5f 100%);
}

.btn-secondary:hover,
.btn-stop:hover,
.btn-outline:hover,
.btn-small:hover {
    transform: translateY(-1px);
}

.btn-outline,
.btn-small {
    color: var(--text-primary);
    border-color: var(--border);
    background: linear-gradient(180deg, #ffffff, #f5f9ff);
}

[data-theme="dark"] .btn-outline,
[data-theme="dark"] .btn-small {
    background: var(--surface);
    border-color: var(--border-strong);
}

[data-theme="dark"] .header {
    background: linear-gradient(
        120deg,
        rgba(45, 27, 105, 0.7),
        rgba(22, 27, 34, 0.85)
    );
    border-color: rgba(167, 139, 250, 0.2);
}

[data-theme="dark"] .footer {
    background: rgba(22, 27, 34, 0.85);
    border-color: var(--border);
}

[data-theme="dark"] .api-status {
    background: var(--surface-strong);
    border-color: var(--border-strong);
}

[data-theme="dark"] .api-settings-modal {
    background: linear-gradient(180deg, #161b22, #111820);
    border-color: var(--border-strong);
}

[data-theme="dark"] .modal-header {
    background: rgba(22, 27, 34, 0.96);
    border-color: var(--border);
}

[data-theme="dark"] .modal-close {
    background: var(--surface-strong);
    border-color: var(--border-strong);
    color: var(--text-secondary);
}

[data-theme="dark"] .modal-close:hover {
    background: var(--surface-muted);
    color: var(--text-primary);
}

.btn-outline:hover,
.btn-small:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 8px 20px rgba(124, 58, 237, 0.14);
}

.btn-stop {
    color: #fff;
    border-color: rgba(201, 61, 74, 0.6);
    background: linear-gradient(140deg, #d54e5a 0%, #b73f49 100%);
}

.btn-small {
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.72rem;
    font-size: 0.82rem;
}

.section-title {
    font-size: 1.06rem;
    letter-spacing: -0.01em;
    margin-bottom: 0.75rem;
}

.stream-section {
    display: none;
}

.stream-box {
    min-height: 150px;
    max-height: 360px;
    overflow: auto;
    border: 1px solid var(--border);
    background: repeating-linear-gradient(
        180deg,
        #f6fbff,
        #f6fbff 28px,
        #f3f8fc 28px,
        #f3f8fc 56px
    );
    border-radius: var(--radius-md);
    padding: 0.9rem;
    color: #0f2b46;
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: "IBM Plex Mono", "Consolas", monospace;
}

.stream-placeholder {
    color: var(--text-soft);
    font-style: italic;
}

.result-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
}

.character-field {
    margin-bottom: 1.15rem !important;
}

.character-field > div:first-child {
    margin-bottom: 0.42rem !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.character-field h3 {
    font-size: 0.96rem !important;
    letter-spacing: -0.01em;
}

.character-field .btn-secondary {
    margin-left: auto;
    white-space: nowrap;
}

.image-preview .content-box {
    min-height: 330px;
    padding: 0.75rem;
    background: linear-gradient(160deg, var(--surface-muted) 0%, var(--accent-soft) 100%);
}

.content-box {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-muted);
    padding: 1rem;
}

.image-container {
    width: 100%;
    display: flex;
    justify-content: center;
}

.generated-image {
    max-width: 100%;
    height: auto;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.image-placeholder {
    min-height: 270px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.loading-spinner {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 3px solid rgba(124, 58, 237, 0.18);
    border-top-color: var(--accent);
    animation: spin 900ms linear infinite;
}

/* Example Messages Section */
.example-messages-section {
    background: linear-gradient(
        160deg,
        rgba(139, 92, 246, 0.05) 0%,
        rgba(59, 130, 246, 0.05) 100%
    );
    border: 1px solid rgba(139, 92, 246, 0.15);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-top: 1.5rem;
}

#example-messages-output {
    background: var(--surface-color);
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: var(--radius-md);
    padding: 1rem;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.875rem;
    line-height: 1.7;
    white-space: pre-wrap;
    max-height: 400px;
    overflow-y: auto;
    color: var(--text-color);
}

#example-messages-output::-webkit-scrollbar {
    width: 6px;
}

#example-messages-output::-webkit-scrollbar-track {
    background: rgba(139, 92, 246, 0.1);
    border-radius: 3px;
}

#example-messages-output::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.3);
    border-radius: 3px;
}

#example-messages-output::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.5);
}

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

.image-controls {
    margin-top: 0.75rem;
}

.image-controls-wrapper {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.66rem;
}

.image-buttons-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.46rem;
}

.image-buttons-row > .btn-small {
    flex: 1 1 110px;
}

/* Free image dropdown */
.free-image-dropdown-wrapper {
    position: relative;
    flex: 1 1 110px;
}

.free-image-dropdown-wrapper > .btn-small {
    width: 100%;
}

.free-image-menu {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 0;
    z-index: 600;
    background: var(--surface-color);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.35);
    min-width: 190px;
    padding: 0.35rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.free-image-menu-header {
    font-size: 0.7rem;
    color: var(--text-secondary);
    padding: 0.2rem 0.5rem 0.3rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.15rem;
    white-space: nowrap;
}

.free-image-option {
    width: 100%;
    text-align: left;
    padding: 0.38rem 0.6rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.free-image-option:hover {
    background: var(--accent-dim, rgba(99, 102, 241, 0.15));
    color: var(--accent);
}

/* SillyTavern connection status */
.st-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.st-status-ok { color: #28a745; }
.st-status-err { color: var(--error, #c93d4a); }

/* Tags widget */
.tags-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    min-height: 2.2rem;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-color, #fff);
    cursor: text;
}
.tags-container:focus-within {
    border-color: var(--primary, #7c3aed);
    box-shadow: 0 0 0 2px rgba(124,58,237,0.15);
}
.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.72rem;
    background: var(--surface-secondary, #ede9fe);
    color: var(--primary, #5b21b6);
    border-radius: 99px;
    padding: 0.15rem 0.55rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.tag-pill:hover { background: #ddd6fe; }
.tag-pill-remove { font-size: 0.85em; opacity: 0.6; line-height: 1; }
.tags-input {
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.8rem;
    color: var(--text-color);
    min-width: 140px;
    flex: 1;
    padding: 0;
}


.st-card {
    display: flex;
    flex-direction: row;
    gap: 0.6rem;
    align-items: flex-start;
    padding: 0.5rem 0.62rem;
}
.st-card-thumb-wrap {
    position: relative;
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.st-card-thumb {
    position: relative;
    z-index: 1;
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--border);
}
.st-card-thumb-placeholder {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: var(--surface-secondary, #e8e8e8);
    border-radius: var(--radius-sm);
}
.st-card-body {
    flex: 1;
    min-width: 0;
}
.st-card-snippet {
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin: 0.15rem 0 0.3rem;
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.st-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 0.3rem;
}
.st-card-tag {
    font-size: 0.68rem;
    background: var(--surface-secondary, #eef);
    color: var(--text-secondary);
    border-radius: 3px;
    padding: 0.1rem 0.35rem;
}
.st-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.1rem;
}
.st-card-footer .library-item-date { margin-bottom: 0; }

.actions {
    border-top: 1px solid var(--border);
    padding-top: 0.85rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
}

.actions > button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.library-status {
    color: var(--text-secondary);
    margin: 0 0 0.65rem;
    font-size: 0.86rem;
}

.library-title {
    margin-bottom: 0.5rem;
    font-size: 0.94rem;
}

.library-list {
    min-height: 230px;
    max-height: 420px;
    overflow: auto;
    background: var(--surface-muted);
    align-content: flex-start;
}

.library-empty {
    color: var(--text-soft);
    font-style: italic;
}

.library-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-strong);
    padding: 0.62rem;
    margin-bottom: 0.56rem;
}

.library-item:last-child {
    margin-bottom: 0;
}

.library-item-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.library-item-date {
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin-bottom: 0.48rem;
}

.library-item-actions {
    display: flex;
    gap: 0.38rem;
    flex-wrap: wrap;
}

.library-item-actions .btn-small {
    min-width: 72px;
}

#library-section .result-grid {
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: stretch;
}

#library-section .result-grid > div {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#library-section .library-list {
    flex: 1;
    min-height: 220px;
}

.footer {
    margin-top: 0.2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.76);
    backdrop-filter: blur(6px);
    padding: 0.75rem 0.9rem;
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 0.7rem;
}

.footer-left,
.footer-center,
.footer-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.footer-center,
.footer-right {
    justify-self: end;
}

.api-status {
    display: inline-flex;
    align-items: center;
    gap: 0.42rem;
    color: var(--text-secondary);
    padding: 0.44rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    font-size: 0.82rem;
    cursor: pointer;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-indicator {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: var(--text-soft);
    box-shadow: 0 0 0 4px rgba(81, 102, 124, 0.12);
}

.status-online {
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(31, 157, 102, 0.2);
}

.status-offline {
    background: var(--error);
    box-shadow: 0 0 0 4px rgba(201, 61, 74, 0.2);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(14, 23, 37, 0.42);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1100;
}

.modal-overlay.show {
    display: flex;
    animation: fadeIn 140ms ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.api-settings-modal {
    width: min(760px, 100%);
    max-height: min(88vh, 980px);
    overflow: auto;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.45);
    background: linear-gradient(180deg, #ffffff, #f8fbff);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

.modal-title {
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.modal-close {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--text-secondary);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    background: #f2f8ff;
    color: var(--text-primary);
}

.modal-body {
    padding: 1rem 1.2rem 1.15rem;
}

.file-input-wrapper {
    display: flex;
    align-items: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: #c3d1dd;
    transition: var(--transition);
    cursor: pointer;
}

.slider::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.16);
    transition: var(--transition);
}

.switch input:checked + .slider {
    background: var(--accent);
}

.switch input:checked + .slider::before {
    transform: translateX(22px);
}

.switch input:focus + .slider {
    outline: none;
    box-shadow: 0 0 0 3px rgba(14, 122, 138, 0.2);
}

.notification {
    border-radius: var(--radius-sm);
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.4rem;
}

.tag {
    font-size: 0.77rem;
    padding: 0.2rem 0.52rem;
    border-radius: 999px;
    background: #eaf5ff;
    color: var(--text-secondary);
}

.form-section {
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: #f9fcff;
    margin-bottom: 0.8rem;
}

.form-section-title {
    margin-bottom: 0.55rem;
    font-size: 0.9rem;
    font-weight: 600;
}

@media (max-width: 980px) {
    .container {
        width: min(1120px, 100% - 1rem);
        margin-top: 0.8rem;
    }

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

    #library-section .result-grid {
        grid-template-columns: 1fr;
    }

    .footer {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
    }

    .footer-center,
    .footer-right {
        justify-self: center;
    }
}

@media (max-width: 700px) {
    .container {
        width: calc(100% - 0.7rem);
        margin-bottom: 1rem;
    }

    .header,
    .input-section,
    .stream-section,
    .result-section,
    .footer {
        border-radius: var(--radius-md);
        padding: 0.82rem;
    }

    .title {
        font-size: 1.35rem;
    }

    .subtitle {
        font-size: 0.88rem;
    }

    .form-row {
        flex-direction: column !important;
        gap: 0.35rem !important;
    }

    .form-row > .form-group {
        min-width: 100%;
    }

    .generation-buttons,
    .actions {
        flex-direction: column;
    }

    .generation-buttons > button,
    .actions > button {
        width: 100%;
    }

    .top-import-actions {
        justify-content: stretch;
    }

    #import-card-top-btn {
        width: 100%;
    }

    .stream-box {
        min-height: 120px;
        max-height: 300px;
    }

    .image-buttons-row {
        display: grid;
        grid-template-columns: 1fr;
    }

    .character-field .btn-secondary {
        margin-left: 0;
        width: 100%;
    }

    .footer-left,
    .footer-center,
    .footer-right {
        width: 100%;
        justify-content: center;
    }

    .api-status {
        white-space: normal;
        text-align: center;
    }

    .modal-body {
        padding: 0.9rem;
    }

    .api-settings-modal {
        width: 100%;
        max-height: 92vh;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Drag-and-drop overlay ─────────────────────────────────────────── */
#drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(14, 23, 37, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 120ms ease;
}

#drop-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

#drop-overlay-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    border: 3px dashed rgba(255, 255, 255, 0.55);
    border-radius: 1.5rem;
    padding: 3rem 4.5rem;
    color: #fff;
    text-align: center;
}

#drop-overlay-icon { font-size: 3.5rem; line-height: 1; }
#drop-overlay-text { font-size: 1.5rem; font-weight: 600; }
#drop-overlay-sub  { font-size: 0.875rem; opacity: 0.65; }

#drop-import-modal { z-index: 2100; }

/* ── Name Picker Modal ─────────────────────────────────────────────── */
.name-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

/* ── Card Diff View ─────────────────────────────────────────────────────── */

.diff-field {
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.diff-field-title {
    background: var(--surface-muted);
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.diff-content {
    padding: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.6;
    white-space: pre-wrap;
    font-family: "IBM Plex Mono", monospace;
}

.diff-del {
    background: rgba(249, 65, 80, 0.15);
    color: var(--error);
    text-decoration: line-through;
    border-radius: 2px;
    padding: 0 2px;
}

.diff-add {
    background: rgba(63, 185, 80, 0.15);
    color: var(--success);
    border-radius: 2px;
    padding: 0 2px;
}

[data-theme="dark"] .diff-del {
    background: rgba(248, 81, 73, 0.25);
}

[data-theme="dark"] .diff-add {
    background: rgba(63, 185, 80, 0.25);
}

.name-picker-option {
    width: 100%;
    padding: 0.65rem 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: left;
    background: var(--surface-color);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: border-color 120ms, background 120ms, transform 80ms;
    color: var(--text-primary);
    font-family: inherit;
}

.name-picker-option:hover {
    border-color: var(--primary);
    background: rgba(139, 92, 246, 0.06);
    transform: translateY(-1px);
}

.name-picker-option:active {
    transform: translateY(0);
}

/* ---------- Chat Tester ---------- */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--bg-page);
}

.chat-message {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-width: 92%;
    animation: fadeIn 200ms ease-out;
}

.chat-message-user {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-message-character {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-message-inner {
    display: flex;
    gap: 0.55rem;
    align-items: flex-end;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
    user-select: none;
}

.chat-avatar-user {
    background: var(--accent);
    color: #fff;
    order: 1;
}

.chat-avatar-char {
    background: var(--surface-muted);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-message-body {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.chat-message-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0 0.25rem;
}

.chat-message-content {
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-lg);
    font-size: calc(0.9375rem * var(--chat-text-zoom, 1));
    line-height: 1.5;
    word-break: break-word;
}

.chat-message-user .chat-message-content {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 0.25rem;
}

.chat-message-character .chat-message-content {
    background: var(--surface-strong);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0.25rem;
}

/* Markdown support */
.chat-message-content pre.chat-code-block {
    background: rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
    font-family: "IBM Plex Mono", "Consolas", monospace;
    font-size: 0.82rem;
    line-height: 1.45;
    overflow-x: auto;
    margin: 0.25rem 0;
}

.chat-message-content code.chat-inline-code {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    padding: 0.05rem 0.3rem;
    font-family: "IBM Plex Mono", "Consolas", monospace;
    font-size: 0.84em;
}

.chat-message-content blockquote.chat-blockquote {
    border-left: 3px solid var(--accent);
    margin: 0.25rem 0;
    padding-left: 0.65rem;
    color: var(--text-secondary);
    font-style: italic;
}

.chat-message-content strong {
    font-weight: 700;
}

.chat-message-content del {
    opacity: 0.7;
}

.chat-message-actions {
    display: flex;
    gap: 0.35rem;
    opacity: 0;
    transition: opacity 120ms;
    padding: 0 0.25rem;
}

.chat-message:hover .chat-message-actions {
    opacity: 1;
}

.chat-action-btn {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    background: var(--surface-strong);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 120ms, color 120ms;
}

.chat-action-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Regen button — amber tint to stand out from other actions */
.chat-regen-btn {
    color: #b45309;
    border-color: #d97706;
}

.chat-regen-btn:hover {
    background: #d97706 !important;
    border-color: #b45309 !important;
    color: #fff !important;
}

[data-theme="dark"] .chat-regen-btn {
    color: #fbbf24;
    border-color: #d97706;
}

[data-theme="dark"] .chat-regen-btn:hover {
    background: #d97706 !important;
    border-color: #b45309 !important;
    color: #fff !important;
}

/* Swipe bar */
.chat-swipe-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.15rem 0.5rem;
    font-size: 0.72rem;
    color: var(--text-secondary);
    align-self: flex-start;
    margin-left: 2.6rem;
}

.chat-swipe-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 0.1rem 0.35rem;
    transition: background 120ms, color 120ms, border-color 120ms;
}

.chat-swipe-btn:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-strong);
}

.chat-swipe-count {
    font-variant-numeric: tabular-nums;
    min-width: 3ch;
    text-align: center;
}

.chat-input-area {
    border-top: 1px solid var(--border);
    background: var(--surface-strong);
    padding: 0.75rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input, #chat-message-input {
    flex: 1;
    resize: none;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-page);
    color: var(--text-primary);
    font-family: inherit;
    font-size: calc(0.9375rem * var(--chat-text-zoom, 1));
    line-height: 1.4;
    transition: border-color 120ms, box-shadow 120ms;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 122, 138, 0.15);
}

.chat-send-btn {
    padding: 0.55rem 0.9rem;
    font-size: 1rem;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.chat-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chat-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-toolbar-right {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.chat-persona-input {
    width: 100px;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-page);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.8125rem;
}

.chat-token-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Typing indicator */
.chat-typing-dots {
    display: flex;
    gap: 0.3rem;
    padding: 0.6rem 0.85rem;
}

.chat-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: chatTypingBounce 1.2s infinite ease-in-out;
}

.chat-typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.chat-typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.chat-typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chatTypingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-6px);
    }
}

/* Dark mode overrides */
[data-theme="dark"] .chat-message-character .chat-message-content {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chat-input {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .chat-persona-input {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .chat-action-btn {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chat-action-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
}

[data-theme="dark"] .chat-avatar-char {
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] pre.chat-code-block,
[data-theme="dark"] code.chat-inline-code {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] blockquote.chat-blockquote {
    border-left-color: var(--accent-strong);
}

/* ── Image Gallery / Lightbox ──────────────────────────────────────────────── */

.gallery-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 10001;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.gallery-overlay.show {
    display: flex;
}

.gallery-toolbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    z-index: 10;
    flex-wrap: wrap;
}

.gallery-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.375rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.gallery-btn:hover {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.4);
}

.gallery-use-btn {
    background: var(--accent, #58a6ff);
    border-color: var(--accent, #58a6ff);
    font-weight: 600;
}

.gallery-use-btn:hover {
    background: var(--accent-strong, #79c0ff);
    border-color: var(--accent-strong, #79c0ff);
}

.gallery-counter {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    width: 3rem;
    height: 3rem;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}

.gallery-nav:hover {
    background: rgba(0, 0, 0, 0.7);
    border-color: rgba(255, 255, 255, 0.4);
}

.gallery-nav-prev { left: 1rem; }
.gallery-nav-next { right: 1rem; }

.gallery-image-container {
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: default;
}

.gallery-image-container img {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 0.05s ease-out;
    user-select: none;
    -webkit-user-drag: none;
}

.gallery-meta {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.75rem;
    align-items: center;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.8);
    max-width: min(90vw, 600px);
}

.gallery-meta-model {
    font-weight: 600;
    font-family: "IBM Plex Mono", monospace;
    color: var(--accent, #58a6ff);
    white-space: nowrap;
}

.gallery-meta-prompt {
    color: rgba(255, 255, 255, 0.6);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Magnifying glass trigger on image cards */
.gallery-zoom-trigger {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 2;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.15s;
}

.gallery-zoom-trigger:hover {
    transform: scale(1.15);
    background: var(--accent, #58a6ff);
}

/* ── Chat Params Toolbar ───────────────────────────────────────────────────── */

.chat-toolbar-params {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    padding: 0.5rem 0;
    border-top: 1px solid var(--border);
    margin-top: 0.25rem;
}

.chat-param-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.chat-param-slider {
    width: 70px;
    accent-color: var(--accent);
}

.chat-param-number {
    width: 65px;
    padding: 0.2rem 0.35rem;
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    background: var(--surface-muted);
    color: var(--text-primary);
    font-size: 0.8rem;
    text-align: center;
}

.chat-persona-select {
    font-size: 0.75rem;
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    background: var(--surface-muted);
    color: var(--text-secondary);
    cursor: pointer;
    max-width: 100px;
}

/* ── Transcript List ──────────────────────────────────────────────────────── */

.transcript-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.transcript-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 0.4rem;
}

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

.transcript-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.transcript-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.transcript-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}

/* ── Persona List ─────────────────────────────────────────────────────────── */

.persona-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.persona-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 0.4rem;
}

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

.persona-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.persona-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.persona-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}

/* ── Lorebook Highlight ────────────────────────────────────────────────────── */

.lorebook-highlight {
    background: rgba(88, 166, 255, 0.2);
    border-bottom: 1px dashed var(--accent);
    cursor: help;
    border-radius: 2px;
    padding: 0 1px;
}

[data-theme="dark"] .lorebook-highlight {
    background: rgba(88, 166, 255, 0.15);
}

.btn-danger {
    background: var(--error) !important;
    color: #fff !important;
    border-color: var(--error) !important;
}

.btn-danger:hover {
    opacity: 0.85;
}

/* ── Batch Generation ──────────────────────────────────────────────────────── */

.batch-count-select {
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    background: var(--surface-muted);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}

.batch-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.batch-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.batch-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.batch-card.batch-card-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

.batch-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.batch-card-num {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    flex-shrink: 0;
}

.batch-card-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.batch-card-section {
    flex: 1;
    min-width: 0;
}

.batch-card-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.15rem;
}

.batch-card-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.batch-pick-btn {
    margin-top: auto;
    width: 100%;
}

.batch-detail {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

.batch-detail-pick-btn {
    width: 100%;
}

/* ── Generation Mode Selector ────────────────────────────────────────────────── */

.mode-selector {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--surface-muted);
}

.mode-option {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-right: 1px solid var(--border);
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.mode-option:last-child {
    border-right: none;
}

.mode-option:hover {
    background: var(--surface);
}

.mode-option:has(input:checked) {
    background: var(--accent);
    color: #fff;
}

.mode-option input[type="radio"] {
    display: none;
}

/* Search status (shown inside search-mode-inputs) */
#search-status {
    display: none;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    padding: 0.15rem 0.5rem;
    border-radius: 0.25rem;
    font-style: italic;
    margin-top: 0.35rem;
}

#search-status.searching {
    display: inline-flex;
    color: var(--accent);
    animation: searchPulse 1.5s ease-in-out infinite;
}

#search-status.found {
    display: inline-flex;
    color: var(--success);
    background: rgba(31, 157, 102, 0.1);
}

#search-status.not-found {
    display: inline-flex;
    color: var(--warning);
    background: rgba(207, 138, 0, 0.1);
}

#search-status.error {
    display: inline-flex;
    color: var(--error);
    background: rgba(201, 61, 74, 0.1);
}

@keyframes searchPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

[data-theme="dark"] .mode-selector {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .mode-option {
    border-color: rgba(255, 255, 255, 0.12);
}

/* ── Input Hint Text ────────────────────────────────────────────────────────── */

.input-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0.25rem 0 0;
    line-height: 1.4;
    opacity: 0.85;
}

/* ── Inspire Me Mode ──────────────────────────────────────────────────────────── */

.inspire-ideas-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

@media (max-width: 640px) {
    .inspire-ideas-grid {
        grid-template-columns: 1fr;
    }
}

.inspire-idea-card {
    background: var(--surface-muted);
    border: 2px solid var(--border);
    border-radius: 0.6rem;
    padding: 1rem 1.25rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.inspire-idea-card:hover {
    border-color: var(--accent-soft);
    background: var(--surface);
}

.inspire-idea-card.selected {
    border-color: var(--accent);
    background: var(--accent-weak, rgba(0, 102, 204, 0.08));
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}

.inspire-idea-card .idea-num {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.inspire-idea-card .idea-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.inspire-idea-card .idea-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    flex: 1;
}

/* ── TTS Narration Controls ──────────────────────────────────────────────── */

#sw-narration-controls {
    animation: narration-slide-in 0.25s ease-out;
}

@keyframes narration-slide-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

#sw-narration-controls .btn-small {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

#sw-narration-controls .btn-small:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}

/* TTS settings labels with inline checkboxes */
#sw-settings-panel label.label input[type="checkbox"] {
    margin: 0;
    accent-color: var(--accent);
    width: 1rem;
    height: 1rem;
}

/* TTS speed/volume range sliders */
#sw-tts-speed,
#sw-tts-volume {
    accent-color: var(--accent);
}

/* ==========================================================================
   RICH EMBEDDED UI ELEMENTS (Roleplay Chat)
   ========================================================================== */

/* Text Messages (Simulated Phone) */
.rich-text-message {
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    max-width: 300px;
    box-shadow: var(--shadow-sm);
    font-family: "IBM Plex Sans", sans-serif;
}

.rich-text-sender {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.rich-text-content {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.4;
}

/* Stat / Progress Bars */
.rich-stat-bar-container {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    margin: 0.75rem 0;
    max-width: 350px;
}

.rich-stat-bar-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.rich-stat-value {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.rich-stat-bar-track {
    background: rgba(16, 36, 58, 0.1);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
    position: relative;
}

[data-theme="dark"] .rich-stat-bar-track {
    background: rgba(255, 255, 255, 0.1);
}

.rich-stat-bar-fill {
    background: var(--accent);
    height: 100%;
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* Task / Objective Indicators */
.rich-task-box {
    border-left: 3px solid var(--warning);
    background: var(--surface-strong);
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    border-radius: 0 8px 8px 0;
    box-shadow: var(--shadow-sm);
}

.rich-task-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--warning);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.rich-task-desc {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* Scene Image Loading State */
.chat-scene-image-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    margin-top: 0.75rem;
    background: var(--surface-muted);
    border: 1px dashed var(--border);
    border-radius: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    max-width: fit-content;
}

/* Scene Image Rendering */
.chat-scene-image-wrapper {
    position: relative;
    margin-top: 0.75rem;
    border-radius: 0.5rem;
    overflow: hidden;
    cursor: zoom-in;
    max-width: 350px;
    border: 1px solid var(--border);
    background: var(--surface-color);
}

.chat-scene-image {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
}

.chat-scene-image-wrapper .gallery-trigger-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s ease;
    backdrop-filter: blur(2px);
}

.chat-scene-image-wrapper:hover .gallery-trigger-overlay {
    opacity: 1;
}

/* ==========================================================================
   ROLEPLAY CHAT UI
   ========================================================================== */

.chat-container {
    display: flex;
    height: 75vh;
    min-height: 600px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Roleplay Chat — CSS Custom Properties
   ═══════════════════════════════════════════════════════════════════════ */
:root {
    --chat-avatar-size: 64px;
    --chat-avatar-gap: 10px;
    --chat-bubble-max-width: 85%;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Chat Container & Layout Chain (CSS-based height — no JS needed)
   ═══════════════════════════════════════════════════════════════════════ */
#view-roleplaychat {
    display: flex;
    overflow: hidden;
    box-sizing: border-box;
    width: 100%;
    max-width: 100vw;
    flex: 1;
    min-height: 0;
}

.chat-container {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Sidebar
   ═══════════════════════════════════════════════════════════════════════════ */
.chat-sidebar {
    width: 260px;
    min-width: 260px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--surface-muted);
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.chat-sidebar-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.chat-session-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chat-session-item {
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 0.5rem;
    transition: var(--transition);
    border: 1px solid transparent;
}

.chat-session-item:hover {
    background: var(--surface-strong);
}

.chat-session-item.active {
    background: var(--surface-strong);
    border-color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Main Chat Area
   ═══════════════════════════════════════════════════════════════════════════ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-page);
    min-width: 0;
    min-height: 0;
    position: relative; /* for scroll-to-bottom FAB */
}

.chat-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    flex-shrink: 0;
}

.chat-timeline {
    position: relative;
    flex: 1 1 0%;
    overflow-y: auto;
    padding: 1rem 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
}

.chat-placeholder {
    margin: auto;
    color: var(--text-secondary);
    font-style: italic;
}

/* Scroll-to-bottom floating button */
.chat-scroll-bottom-btn {
    position: absolute;
    bottom: 90px;
    right: 20px;
    z-index: 50;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
    animation: chatFabIn 0.25s ease-out;
}
@keyframes chatFabIn {
    from { transform: scale(0.5); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}
.chat-scroll-bottom-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Input Area
   ═══════════════════════════════════════════════════════════════════════════ */
.chat-input-area {
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

.chat-input-controls {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

#chat-message-input {
    flex: 1;
    resize: none;
    max-height: 150px;
    min-height: 42px;
    min-width: 120px;
    font-family: inherit;
    line-height: 1.5;
}

#chat-send-btn,
#chat-stop-btn {
    flex-shrink: 0;
    min-height: 42px;
    padding: 0 1.2rem;
}

/* OOC */
.chat-ooc-container input {
    width: 100%;
    border-style: dashed;
    border-color: var(--text-secondary);
    background: var(--surface-muted);
    font-size: 0.9rem;
    font-style: italic;
}

.chat-ooc-container input:focus {
    border-color: var(--accent);
}

/* OOC toggle badge */
#chat-toggle-ooc-btn {
    position: relative;
}
#chat-toggle-ooc-btn.has-ooc::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Message Bubbles
   ═══════════════════════════════════════════════════════════════════════════ */
.chat-bubble-wrapper {
    display: flex;
    gap: var(--chat-avatar-gap);
    margin-bottom: 0.75rem;
    width: 100%;
    box-sizing: border-box;
    max-width: var(--chat-bubble-max-width);
}

.chat-bubble-wrapper.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-bubble-wrapper.assistant {
    align-self: flex-start;
}

/* Avatar */
.chat-avatar-container {
    width: var(--chat-avatar-size);
    height: var(--chat-avatar-size);
    flex-shrink: 0;
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--surface-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Content column */
.chat-bubble-content-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.chat-bubble-wrapper.user .chat-bubble-content-col {
    align-items: flex-end;
}
.chat-bubble-wrapper.assistant .chat-bubble-content-col {
    align-items: flex-start;
}

/* Name row */
.chat-bubble-name {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 0.2rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 600;
    gap: 0.4rem;
}

.chat-bubble-name-text {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

/* Timestamp */
.chat-bubble-time {
    font-size: 0.68rem;
    color: var(--text-soft);
    font-weight: 400;
    white-space: nowrap;
}

/* Bubble */
.chat-bubble {
    padding: 0.7rem 0.95rem;
    border-radius: 0.75rem;
    font-size: calc(0.9375rem * var(--chat-text-zoom, 1));
    line-height: 1.55;
    word-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
}

.chat-bubble-wrapper.user .chat-bubble {
    background: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-right-radius: 0.2rem;
}

.chat-bubble-wrapper.assistant .chat-bubble {
    background: var(--bg-tertiary, rgba(0,0,0,0.06));
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0.2rem;
}

.chat-bubble pre {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Message actions (edit/delete) */
.chat-message-actions {
    display: flex;
    gap: 0.35rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-bubble-wrapper:hover .chat-message-actions,
.chat-bubble-wrapper.touch-device .chat-message-actions {
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Fullscreen Mode
   ═══════════════════════════════════════════════════════════════════════════ */
#view-roleplaychat.chat-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 9999 !important;
    background: var(--bg-page) !important;
    padding: 0.25rem !important;
    box-sizing: border-box !important;
}

html.chat-scroll-locked, body.chat-scroll-locked {
    overflow: hidden !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Character Accent Colours (group chat)
   ═══════════════════════════════════════════════════════════════════════════ */
.chat-bubble-wrapper.assistant .chat-bubble[data-char-accent] {
    border-left-width: 3px;
    border-left-style: solid;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Dark Mode
   ═══════════════════════════════════════════════════════════════════════════ */
[data-theme="dark"] .chat-bubble-wrapper.assistant .chat-bubble {
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] #chat-message-input {
    background: rgba(255, 255, 255, 0.04);
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE — Sidebar becomes a slide-out overlay drawer
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    :root {
        --chat-avatar-size: 36px;
        --chat-avatar-gap: 8px;
        --chat-bubble-max-width: 92%;
    }

    .chat-container {
        flex-direction: column;
    }

    /* Sidebar — overlay drawer */
    .chat-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        min-width: 280px;
        max-width: 85vw;
        height: 100%;
        height: 100dvh;
        z-index: 200;
        transform: translateX(-100%);
        opacity: 0;
        box-shadow: var(--shadow-lg);
        border-right: 1px solid var(--border);
        border-bottom: none;
    }

    .chat-sidebar.mobile-drawer-open {
        transform: translateX(0);
        opacity: 1;
    }

    /* Backdrop */
    .chat-sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 199;
        background: rgba(0,0,0,0.4);
        animation: chatFadeIn 0.2s ease;
    }
    .chat-sidebar-backdrop.active {
        display: block;
    }
    @keyframes chatFadeIn {
        from { opacity: 0; }
        to   { opacity: 1; }
    }

    /* Header compact on mobile */
    .chat-header {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }
    .chat-header-info h2 {
        font-size: 1rem !important;
    }

    /* Timeline — more padding at bottom for FAB */
    .chat-timeline {
        padding: 0.75rem 0.75rem 3rem;
        gap: 0.75rem;
    }

    /* Input area */
    .chat-input-area {
        padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
    }

    .chat-input-controls {
        gap: 0.4rem;
    }

    /* On very narrow screens (<500px), force textarea to full width */
    @media (max-width: 500px) {
        .chat-input-controls {
            flex-direction: row;
            flex-wrap: wrap;
        }
        #chat-message-input {
            flex-basis: 100%;
            order: 1;
        }
        #chat-toggle-ooc-btn {
            order: 2;
        }
        #chat-speaker-select {
            order: 3;
        }
        #chat-send-btn,
        #roleplay-send-btn,
        #chat-stop-btn,
        #roleplay-stop-btn {
            order: 4;
        }
        #roleplay-impersonate-btn {
            order: 4;
        }
    }

    /* FAB — position above the input area */
    .chat-scroll-bottom-btn {
        bottom: 80px;
        right: 12px;
    }

    /* Always show message actions on mobile (no hover) */
    .chat-bubble-wrapper .chat-message-actions {
        opacity: 1;
    }

    /* Character name in bubble actions shorter */
    .chat-bubble-name {
        font-size: 0.72rem;
    }

    /* Ensure the chat view fills available height on mobile without overlapping footer */
    #view-roleplaychat:not([style*="display: none"]) {
        height: auto !important;
    }
    .chat-scene-image-wrapper {
        max-width: 100%;
    }
}

/* ==========================================================================
   ROLEPLAY CHAT - IMMERSIVE MOBILE FULLSCREEN OPTIMISATIONS (iPhone / iPad)
   ========================================================================== */
@media (max-width: 1024px) {
    /* Full-screen wrapper - edge-to-edge with no padding or borders */
    #view-roleplaychat.chat-fullscreen {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        z-index: 9999 !important;
        padding: 0 !important;
        background: var(--bg-page) !important;
        height: 100vh !important;
        height: 100dvh !important;
        min-height: 100vh !important;
        min-height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        overscroll-behavior: none !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-container {
        border: none !important;
        border-radius: 0 !important;
        height: 100% !important;
        min-height: 100% !important;
        max-height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-main {
        border-radius: 0 !important;
        height: 100% !important;
        min-height: 100% !important;
        max-height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    /* Immersive, Safe-Area-Aware Header */
    #view-roleplaychat.chat-fullscreen .chat-header {
        padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 0.75rem 0.6rem !important;
        background: var(--surface) !important;
        backdrop-filter: blur(12px) !important;
        -webkit-backdrop-filter: blur(12px) !important;
        border-bottom: 1px solid var(--border) !important;
        gap: 0.5rem !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-header-info {
        min-width: 0;
        flex: 1;
    }

    #view-roleplaychat.chat-fullscreen #chat-active-title {
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 40vw;
    }

    #view-roleplaychat.chat-fullscreen #chat-active-characters {
        font-size: 0.75rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
        max-width: 40vw;
    }

    /* Compact header actions for mobile */
    #view-roleplaychat.chat-fullscreen .chat-header-actions {
        gap: 0.4rem !important;
    }

    /* Hide the "Playing as:" text label to save horizontal space */
    #view-roleplaychat.chat-fullscreen .chat-header-actions div > span {
        display: none !important;
    }

    /* Compact rounded persona select dropdown */
    #view-roleplaychat.chat-fullscreen #chat-user-persona-select {
        max-width: 105px !important;
        border-radius: 20px !important;
        padding: 0.25rem 1.5rem 0.25rem 0.5rem !important;
        font-size: 0.78rem !important;
        height: 32px !important;
        background-position: right 0.4rem center !important;
    }

    /* Make Settings Button a circular gear icon */
    #view-roleplaychat.chat-fullscreen #chat-settings-btn {
        font-size: 0 !important;
        width: 32px !important;
        height: 32px !important;
        min-height: 32px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        border: 1px solid var(--border) !important;
        background: var(--surface-muted) !important;
    }

    #view-roleplaychat.chat-fullscreen #chat-settings-btn::before {
        content: '⚙️';
        font-size: 1.05rem !important;
    }

    /* Close/Exit button styled beautifully */
    #view-roleplaychat.chat-fullscreen #chat-fullscreen-toggle {
        font-size: 0.95rem !important;
        width: 32px !important;
        height: 32px !important;
        min-height: 32px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 !important;
        border-radius: 50% !important;
        background: var(--surface-muted) !important;
        border: 1px solid var(--border) !important;
        margin-left: 0.2rem !important;
    }

    /* Timeline & Message bubbles */
    #view-roleplaychat.chat-fullscreen .chat-timeline {
        padding: 1rem 0.75rem calc(1.5rem + env(safe-area-inset-bottom, 0px)) !important;
        background: var(--bg-page) !important;
        gap: 0.85rem !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important; /* smooth kinetic scrolling for iOS */
        flex: 1 1 0% !important;
        min-height: 0 !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-bubble-wrapper {
        max-width: 90% !important;
        gap: 8px !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-bubble-wrapper.user {
        max-width: 86% !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-avatar-container {
        width: 36px !important;
        height: 36px !important;
        border-radius: 50% !important; /* Circular avatars for a modern chat feel */
        box-shadow: var(--shadow-sm);
    }

    #view-roleplaychat.chat-fullscreen .chat-bubble {
        border-radius: 18px !important;
        padding: 0.7rem 0.95rem !important;
        font-size: 0.95rem !important;
        line-height: 1.5 !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04) !important;
    }

    /* User messages styling - accent background, white text */
    #view-roleplaychat.chat-fullscreen .chat-bubble-wrapper.user .chat-bubble {
        background: var(--accent) !important;
        color: #ffffff !important;
        border: none !important;
        border-bottom-right-radius: 4px !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-bubble-wrapper.user .chat-bubble * {
        color: #ffffff !important;
    }

    /* Resolve quotes color mismatch inside user bubbles */
    #view-roleplaychat.chat-fullscreen .chat-bubble-wrapper.user .chat-bubble span[style*="color"] {
        color: #ffe0b2 !important; /* Warm gold/peach for readability on accent bg */
        font-weight: 600 !important;
    }

    /* Assistant messages styling - surface background */
    #view-roleplaychat.chat-fullscreen .chat-bubble-wrapper.assistant .chat-bubble {
        background: var(--surface-strong) !important;
        color: var(--text-primary) !important;
        border: 1px solid var(--border) !important;
        border-bottom-left-radius: 4px !important;
    }

    /* Group chat indicator bar */
    #view-roleplaychat.chat-fullscreen .chat-bubble-wrapper.assistant .chat-bubble[data-char-accent] {
        border-left-width: 4px !important;
    }

    /* Message Header: align name and time nicely, keep actions pushed right */
    #view-roleplaychat.chat-fullscreen .chat-bubble-name {
        display: flex !important;
        align-items: center !important;
        width: 100% !important;
        gap: 0.4rem !important;
        font-size: 0.75rem !important;
        margin-bottom: 0.15rem !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-bubble-name-text {
        font-weight: 700 !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-bubble-time {
        margin-right: auto !important; /* Push everything else (actions) to the far right */
        opacity: 0.75 !important;
    }

    /* Touch-friendly, compact message action buttons */
    #view-roleplaychat.chat-fullscreen .chat-message-actions {
        opacity: 0.85 !important;
        margin-left: auto !important;
        gap: 0.25rem !important;
    }

    #view-roleplaychat.chat-fullscreen .chat-message-actions .chat-action-btn {
        padding: 0.2rem 0.4rem !important;
        font-size: 0.72rem !important;
        border-radius: 6px !important;
        background: var(--surface-muted) !important;
        border: 1px solid var(--border) !important;
        color: var(--text-secondary) !important;
        min-height: unset !important;
        height: auto !important;
    }

    /* Input area - sleek floating capsule design */
    #view-roleplaychat.chat-fullscreen .chat-input-area {
        padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom, 0px)) !important;
        background: var(--surface) !important;
        backdrop-filter: blur(12px) !important;
        -webkit-backdrop-filter: blur(12px) !important;
        border-top: 1px solid var(--border) !important;
    }

    /* OOC Note Row */
    #view-roleplaychat.chat-fullscreen .chat-ooc-container {
        margin-bottom: 0.25rem !important;
    }

    #view-roleplaychat.chat-fullscreen #chat-ooc-input {
        border-radius: 12px !important;
        padding: 0.4rem 0.75rem !important;
        font-size: 0.88rem !important;
        background: var(--surface-muted) !important;
        border: 1px dashed var(--border-strong) !important;
    }

    /* Grid layout for input controls row */
    #view-roleplaychat.chat-fullscreen .chat-input-controls {
        display: grid !important;
        grid-template-columns: auto 1fr auto auto !important;
        grid-template-rows: auto auto !important;
        gap: 0.4rem !important;
        align-items: end !important;
        width: 100% !important;
    }

    /* Character router speaker select on its own full-width row */
    #view-roleplaychat.chat-fullscreen #chat-speaker-select {
        grid-row: 1 !important;
        grid-column: 1 / span 4 !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 12px !important;
        height: 34px !important;
        font-size: 0.85rem !important;
        padding: 0.25rem 0.5rem !important;
        background: var(--surface-muted) !important;
        border: 1px solid var(--border) !important;
    }

    #view-roleplaychat.chat-fullscreen #chat-speaker-select[style*="display: none"] {
        display: none !important;
    }

    /* Mask icon for OOC toggle button */
    #view-roleplaychat.chat-fullscreen #chat-toggle-ooc-btn {
        grid-row: 2 !important;
        grid-column: 1 !important;
        font-size: 0 !important;
        width: 42px !important;
        height: 42px !important;
        min-height: 42px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        border: 1px solid var(--border) !important;
        background: var(--surface-muted) !important;
    }

    #view-roleplaychat.chat-fullscreen #chat-toggle-ooc-btn::before {
        content: '🎭';
        font-size: 1.2rem !important;
    }

    #view-roleplaychat.chat-fullscreen #chat-toggle-ooc-btn.has-ooc::after {
        top: 4px !important;
        right: 4px !important;
        width: 8px !important;
        height: 8px !important;
    }

    /* Capsule Textarea */
    #view-roleplaychat.chat-fullscreen #chat-message-input {
        grid-row: 2 !important;
        grid-column: 2 !important;
        border-radius: 20px !important;
        padding: 0.6rem 0.95rem !important;
        font-size: 16px !important; /* Prevent iOS Safari auto-zoom on focus */
        line-height: 1.3 !important;
        background: var(--surface-muted) !important;
        border: 1px solid var(--border) !important;
        min-height: 42px !important;
        max-height: 120px !important;
    }

    /* Edit mode textarea inside messages */
    #view-roleplaychat.chat-fullscreen .chat-bubble textarea {
        font-size: 16px !important; /* Prevent iOS Safari auto-zoom when editing a message */
        border-radius: 8px !important;
        padding: 0.5rem !important;
        background: var(--surface-muted) !important;
        border: 1px solid var(--border) !important;
    }

    /* Impersonate button as circular button */
    #view-roleplaychat.chat-fullscreen #roleplay-impersonate-btn {
        grid-row: 2 !important;
        grid-column: 3 !important;
        font-size: 0 !important;
        width: 42px !important;
        height: 42px !important;
        min-height: 42px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        border: 1px solid var(--border) !important;
        background: var(--surface-muted) !important;
        margin: 0 !important;
    }

    #view-roleplaychat.chat-fullscreen #roleplay-impersonate-btn::before {
        content: '👤';
        font-size: 1.15rem !important;
    }

    /* Send button as circular capsule */
    #view-roleplaychat.chat-fullscreen #roleplay-send-btn {
        grid-row: 2 !important;
        grid-column: 4 !important;
        font-size: 0 !important;
        width: 42px !important;
        height: 42px !important;
        min-height: 42px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        border: none !important;
        background: var(--accent) !important;
        color: #ffffff !important;
        box-shadow: 0 2px 8px rgba(14, 122, 138, 0.3) !important;
    }

    #view-roleplaychat.chat-fullscreen #roleplay-send-btn::before {
        content: '➤';
        font-size: 1.1rem !important;
    }

    #view-roleplaychat.chat-fullscreen #roleplay-send-btn:disabled {
        background: var(--border) !important;
        box-shadow: none !important;
        opacity: 0.6 !important;
    }

    /* Stop button as circular capsule */
    #view-roleplaychat.chat-fullscreen #roleplay-stop-btn {
        grid-row: 2 !important;
        grid-column: 4 !important;
        font-size: 0 !important;
        width: 42px !important;
        height: 42px !important;
        min-height: 42px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        border: none !important;
        background: var(--error) !important;
        color: #ffffff !important;
        box-shadow: 0 2px 8px rgba(201, 61, 74, 0.3) !important;
    }

    #view-roleplaychat.chat-fullscreen #roleplay-stop-btn::before {
        content: '⏹';
        font-size: 1.1rem !important;
    }

    #view-roleplaychat.chat-fullscreen #roleplay-send-btn[style*="display: none"],
    #view-roleplaychat.chat-fullscreen #roleplay-stop-btn[style*="display: none"],
    #view-roleplaychat.chat-fullscreen #roleplay-impersonate-btn[style*="display: none"] {
        display: none !important;
    }

    /* Position Scroll-to-bottom FAB above the input area */
    #view-roleplaychat.chat-fullscreen .chat-scroll-bottom-btn {
        bottom: calc(65px + env(safe-area-inset-bottom, 0px)) !important;
        right: 16px !important;
        background: var(--surface) !important;
        color: var(--text-primary) !important;
        border: 1px solid var(--border) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        box-shadow: var(--shadow-md) !important;
        width: 36px !important;
        height: 36px !important;
    }
}

/* ── Adventure Mode ──────────────────────────────────────────────────────────── */

#view-adventure .adv-story-segment {
    animation: fadeIn 0.3s ease-in-out;
}

#view-adventure .adv-option-btn {
    transition: all 0.2s ease-in-out;
    background: var(--surface-muted);
}

#view-adventure .adv-option-btn:hover {
    background: var(--surface);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

@media (max-width: 600px) {
    #adv-options-area {
        grid-template-columns: 1fr !important;
    }
}
