:root {
    --bg-app: #080b12;
    --bg-sidebar: #0d111b;
    --bg-header: #101622;
    --bg-tabs: #0a0e16;
    --bg-tab-hover: #111722;
    --bg-input: #121824;
    --bg-prompt-box: #0a0e15;
    --bg-workspace-glow: #111c31;
    --bg-image-frame: #070a10;
    --bg-icon-button: #252d3d;
    --bg-icon-button-hover: #354158;
    --bg-thumb-delete: #1a212f;

    --border-color: #252d3d;
    --border-input: #30394b;

    --text-primary: #ffffff;
    --text-body: #e8edf7;
    --text-detail-value: #e9eef8;
    --text-muted: #7f8ba3;
    --text-tab: #77839a;
    --text-field-label: #aab5c8;
    --text-prompt-title: #8c99b0;
    --text-prompt-value: #bdc7d8;
    --text-help: #66738a;
    --text-placeholder: #4d596d;
    --text-lock: #66738a;

    --accent: #00aeea;
    --accent-bright: #00bfff;
    --accent-range-value: #00c4ff;

    --button-primary: #087da8;
    --button-primary-hover: #0998c9;
    --button-generate: #00a86b;
    --button-generate-hover: #00c47d;
    --button-secondary: #252d3d;
    --button-secondary-hover: #303a4e;
    --gender-active: #087ca5;
    --gender-hover: #15556c;
    --danger: #a83232;
}

/* =========================================================
   FANTASY THEME (dark green palette)

   Applied whenever body.fantasy-theme is set (toggled in
   script.js alongside the Sci-Fi / Fantasy genre switch).
   Mirrors the RELATIONSHIPS between the default dark-blue
   palette's variables (background depth, text contrast,
   accent/button hierarchy) rather than reskinning a single
   color — every var that the default palette defines is
   redefined here with a forest-green / emerald equivalent.
   ========================================================= */

body.fantasy-theme {
    --bg-app: #080c08;
    --bg-sidebar: #0d150e;
    --bg-header: #0f1c11;
    --bg-tabs: #0a120a;
    --bg-tab-hover: #12211a;
    --bg-input: #142415;
    --bg-prompt-box: #0d150d;
    --bg-workspace-glow: #12291a;
    --bg-image-frame: #08100a;
    --bg-icon-button: #26352a;
    --bg-icon-button-hover: #3a543d;
    --bg-thumb-delete: #1c2a1e;

    --border-color: #26352a;
    --border-input: #34513a;

    --text-primary: #ffffff;
    --text-body: #e8f7ec;
    --text-detail-value: #e9f8ee;
    --text-muted: #85a390;
    --text-tab: #7a9782;
    --text-field-label: #adc8b2;
    --text-prompt-title: #93b09b;
    --text-prompt-value: #c1d8c6;
    --text-help: #6a8a72;
    --text-placeholder: #4f6d55;
    --text-lock: #6a8a72;

    --accent: #26c281;
    --accent-bright: #37e696;
    --accent-range-value: #3ff0a0;

    --button-primary: #0f8a52;
    --button-primary-hover: #12a862;
    --button-generate: #4c9a2a;
    --button-generate-hover: #5fbf35;
    --button-secondary: #26352a;
    --button-secondary-hover: #324736;
    --gender-active: #157a4f;
    --gender-hover: #1e5c3d;
    --danger: #a83232;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg-app);
    color: var(--text-body);
    -webkit-text-size-adjust: 100%;
}

button,
select,
input,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

/* =========================================================
   APP
   ========================================================= */

.app {
    display: flex;
    width: 100%;
    height: 100vh;
}

/* =========================================================
   LEFT SIDE
   ========================================================= */

.sidebar {
    width: 720px;
    min-width: 720px;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
}

.header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-header);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
}

.header-top .image-actions {
    flex-shrink: 0;
    width: auto;
}

.header-top .image-actions button {
    flex: 0 0 auto;
    width: auto;
    padding: 14px 21px;
    font-size: 18px;
}

.header h1 {
    margin: 0;
    font-size: 20px;
    color: var(--text-primary);
}

/* =========================================================
   GENRE SWITCH (Sci-Fi / Fantasy)
   ========================================================= */

.genre-switch-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.genre-switch {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.genre-switch-label {
    font-size: 11px;
    font-weight: bold;
    color: var(--text-muted);
    user-select: none;
}

.header p {
    margin: 5px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

/* =========================================================
   TABS
   ========================================================= */

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tabs);
}

.tab {
    flex: 1;
    padding: 13px 6px;
    border: none;
    background: transparent;
    color: var(--text-tab);
    font-size: 12px;
    border-bottom: 2px solid transparent;
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-tab-hover);
}

.tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-bright);
    background: var(--bg-tab-hover);
}

/* =========================================================
   CONTENT
   ========================================================= */

.panel-container {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
}

.panel {
    display: none;
}

.panel.active {
    display: block;
}

/* =========================================================
   FORM
   ========================================================= */

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-field-label);
    font-size: 12px;
    font-weight: bold;
}

.field-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.field-label-row label {
    margin-bottom: 0;
}

.field-label-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.enable-switch {
    position: relative;
    display: inline-block;
    width: 30px;
    height: 16px;
    flex-shrink: 0;
}

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

.enable-switch .slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: var(--border-input);
    border-radius: 16px;
    transition: 0.15s;
}

.enable-switch .slider::before {
    content: "";
    position: absolute;
    height: 12px;
    width: 12px;
    left: 2px;
    top: 2px;
    background: white;
    border-radius: 50%;
    transition: 0.15s;
}

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

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

.lock-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
    line-height: 1;
    color: var(--text-lock);
    opacity: 0.6;
    transition: 0.15s;
}

.lock-toggle:hover {
    opacity: 1;
}

.lock-toggle.locked {
    opacity: 1;
    filter: drop-shadow(0 0 3px rgba(0, 196, 255, 0.6));
}

.seed-inline .lock-toggle {
    flex-shrink: 0;
}

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--border-input);
    border-radius: 5px;
    background: var(--bg-input);
    color: var(--text-primary);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
}

input:disabled,
select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-sidebar);
}

textarea {
    min-height: 100px;
    resize: vertical;
}

.row {
    display: flex;
    gap: 10px;
}

.row > .field {
    flex: 1;
}

/* =========================================================
   GENDER SWITCH
   ========================================================= */

.gender-switch {
    display: flex;
    width: 100%;
    height: 38px;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    overflow: hidden;
}

.gender-option {
    flex: 1;
    border: none;
    background: var(--bg-input);
    color: #707c91;
    transition: 0.15s;
}

.gender-option.active {
    background: var(--gender-active);
    color: white;
}

.gender-option:hover {
    background: var(--gender-hover);
    color: white;
}

/* =========================================================
   BUTTONS
   ========================================================= */

.button {
    width: 100%;
    padding: 11px 15px;
    border: none;
    border-radius: 6px;
    color: white;
    background: var(--button-primary);
    font-weight: bold;
    transition: 0.15s;
}

.button:hover {
    background: var(--button-primary-hover);
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.button.secondary {
    background: var(--button-secondary);
}

.button.secondary:hover {
    background: var(--button-secondary-hover);
}

.button.generate {
    background: var(--button-generate);
}

.button.generate:hover {
    background: var(--button-generate-hover);
}

.button.random {
    width: auto;
    padding: 8px 12px;
    font-size: 12px;
}

/* =========================================================
   CHARACTER DETAILS
   ========================================================= */

.character-card {
    background: var(--bg-header);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: 14px;
}

.character-card h3 {
    margin: 0 0 12px;
    font-size: 15px;
}

.detail {
    margin-bottom: 10px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 10px;
}

.detail-grid .detail {
    margin-bottom: 0;
}

.detail-title {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-help);
    margin-bottom: 3px;
}

.detail-value {
    font-size: 13px;
    color: var(--text-detail-value);
    white-space: pre-wrap;
}

/* =========================================================
   EDITABLE FIELDS
   ========================================================= */

textarea.detail-value {
    width: 100%;
    min-height: 70px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--text-detail-value);
    font-size: 13px;
    font-family: inherit;
    padding: 4px 6px;
    resize: none;
    overflow: hidden;
    white-space: pre-wrap;
}

textarea.detail-value:hover {
    border-color: var(--border-input);
}

textarea.detail-value:focus {
    border-color: var(--accent);
    background: var(--bg-input);
}

textarea.prompt-text {
    width: 100%;
    min-height: 80px;
    font-family: inherit;
    resize: none;
    overflow: hidden;
}

/* =========================================================
   SEED CONTROL
   ========================================================= */

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

.seed-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.seed-inline label {
    color: var(--text-field-label);
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
}

.seed-inline input {
    flex: 1;
    min-width: 0;
}

/* =========================================================
   PROMPTS
   ========================================================= */

.prompt-box {
    margin-bottom: 15px;
}

.row > .prompt-box {
    flex: 1;
}

.prompt-title {
    margin-bottom: 6px;
    color: var(--text-prompt-title);
    font-size: 11px;
    font-weight: bold;
}

.prompt-text {
    background: var(--bg-prompt-box);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-prompt-value);
    white-space: pre-wrap;
}

input.prompt-text-input {
    width: 100%;
    background: var(--bg-prompt-box);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px;
    font-size: 11px;
    color: var(--text-prompt-value);
}

input.prompt-text-input:focus {
    border-color: var(--accent);
}

/* =========================================================
   SETTINGS
   ========================================================= */

.settings-section {
    padding-bottom: 18px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-title {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: bold;
}

.help {
    margin-top: 5px;
    font-size: 10px;
    color: var(--text-help);
    line-height: 1.4;
}

/* =========================================================
   IMAGE SETTINGS
   ========================================================= */

.range-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.range-row input {
    flex: 1;
}

.range-value {
    width: 45px;
    text-align: right;
    color: var(--accent-range-value);
    font-size: 12px;
}

/* =========================================================
   RIGHT SIDE
   ========================================================= */

.workspace {
    flex: 1;
    height: 100%;
    overflow: hidden;
    padding: 22px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(
        circle at top right,
        var(--bg-workspace-glow) 0,
        var(--bg-app) 45%
    );
}

.status {
    font-size: 11px;
    color: var(--text-muted);
}

.status-error {
    color: #ff8a8a;
}

.status-success {
    color: #d5dbe6;
}

/* =========================================================
   WORKSPACE IMAGE (image only — no chrome of any kind)
   ========================================================= */

.image-only {
    width: min(800px, calc(100vh - 44px), 100%);
    height: min(800px, calc(100vh - 44px), 100%);
    background: var(--bg-image-frame);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-only img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.image-only.has-image {
    cursor: zoom-in;
}

.placeholder {
    text-align: center;
    color: var(--text-placeholder);
    font-size: 12px;
    padding: 30px;
}

/* =========================================================
   LIGHTBOX (full-screen image view — click the workspace
   image to open on any screen size; also opened automatically
   on mobile right after a generation finishes, since the
   workspace sits below the sidebar there and would otherwise
   go unnoticed off-screen)
   ========================================================= */

.lightbox-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: 20px;
    background: rgba(0, 0, 0, 0.92);
    align-items: center;
    justify-content: center;
}

.lightbox-overlay.visible {
    display: flex;
}

.lightbox-overlay img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.lightbox-close,
.lightbox-open-tab {
    position: fixed;
    top: 16px;
    color: #fff;
    opacity: 0.8;
    z-index: 1001;
}

.lightbox-close:hover,
.lightbox-open-tab:hover {
    opacity: 1;
}

.lightbox-close {
    right: 20px;
    font-size: 26px;
    line-height: 1;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
}

.lightbox-open-tab {
    right: 60px;
    font-size: 13px;
    text-decoration: none;
    padding: 8px 0;
}

/* =========================================================
   GALLERY
   ========================================================= */

.gallery-entry {
    margin-bottom: 14px;
    cursor: pointer;
    transition: 0.15s;
}

.gallery-entry:hover {
    border-color: var(--accent);
}

.gallery-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}

.gallery-card-header h3 {
    margin: 0;
}

.gallery-name-block {
    min-width: 0;
}

.gallery-name-block .detail-value {
    margin-top: 6px;
}

.gallery-icon-button-group {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.gallery-icon-button {
    flex-shrink: 0;
    width: 45px;
    height: 45px;
    background: var(--bg-icon-button);
    border: none;
    border-radius: 6px;
    color: var(--text-detail-value);
    font-size: 21px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-icon-button:hover {
    background: var(--bg-icon-button-hover);
}

.gallery-icon-button-danger:hover {
    background: var(--danger);
}

.gallery-thumb-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
}

.gallery-thumb-wrap {
    position: relative;
    width: 72px;
    height: 72px;
}

.gallery-thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 5px;
    border: 1px solid var(--border-color);
    background: var(--bg-image-frame);
    cursor: pointer;
    transition: 0.15s;
}

.gallery-thumb:hover {
    border-color: var(--accent);
}

.gallery-thumb-delete {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-thumb-delete);
    color: #ff8a8a;
    font-size: 11px;
    font-weight: bold;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-thumb-delete:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--text-detail-value);
}

.gallery-signin-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 8px;
}

.gallery-view-mode-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
}

.gallery-per-row-select {
    width: auto;
    padding: 6px 8px;
    font-size: 12px;
}

.gallery-view-mode-text {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 62px;
    text-align: right;
}

.gallery-sort-label {
    font-size: 12px;
    font-weight: bold;
    color: var(--text-field-label);
    white-space: nowrap;
}

.gallery-sort-select {
    width: auto;
    padding: 6px 8px;
    font-size: 12px;
}

.gallery-image-grid {
    display: grid;
    gap: 10px;
}

.gallery-image-cell {
    position: relative;
    cursor: pointer;
}

.gallery-image-cell {
    min-width: 0;
}

.gallery-image-cell img {
    width: 100%;
    min-width: 0;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 5px;
    border: 1px solid var(--border-color);
    background: var(--bg-image-frame);
    transition: 0.15s;
}

.gallery-image-cell:hover img {
    border-color: var(--accent);
}

.gallery-image-cell-caption {
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-thumb-cloud-badge {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-thumb-delete);
    border: 1px solid var(--border-color);
    font-size: 11px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =========================================================
   IMAGE GENERATION BUTTONS
   ========================================================= */

.image-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.image-actions button {
    flex: 1;
}

/* =========================================================
   LOADING
   ========================================================= */

.loading {
    animation: pulse 1.3s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.45;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0.45;
    }
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 900px) {
    .sidebar {
        width: 360px;
        min-width: 360px;
    }
}

/* Below this width there isn't room for the sidebar + workspace
   side-by-side layout at all — stack them instead and let the
   whole page scroll rather than relying on the desktop layout's
   internal-panel scrolling. */
@media (max-width: 700px) {
    html,
    body {
        height: auto;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        width: 100%;
        min-width: 0;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .panel-container {
        overflow-y: visible;
    }

    .header-top {
        flex-direction: column;
    }

    .header-top .image-actions {
        width: 100%;
    }

    .header-top .image-actions button {
        flex: 1;
        width: auto;
    }

    .workspace {
        height: auto;
        min-height: 60vh;
        padding: 14px;
    }

    .image-only {
        width: min(600px, 100%);
        height: min(600px, 100vw);
    }

    .detail-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .row {
        flex-direction: column;
    }

    .gallery-icon-button {
        width: 38px;
        height: 38px;
        font-size: 17px;
    }
}
