* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
    --bg: #fafafa; --panel: #ffffff; --panel-2: #f5f5f5; --border: #e5e5e5;
    --ink: #1a1a1a; --ink-dim: #777; --ink-faint: #aaa;
    --success: #2d8a4e; --error: #c0392b; --warn: #d4a017; --info: #4a6cf7;
    --accent: #6c5ce7; --accent-2: #a29bfe; --accent-3: #fd79a8;
    --accent-img: #0984e3; --accent-txt: #e17055;
    --radius: 12px;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background: var(--bg); color: var(--ink); min-height: 100vh;
    padding: 1.5rem 1rem 6rem; font-size: 15px; line-height: 1.5;
    max-width: 1000px; margin: 0 auto;
}
header { margin-bottom: 1.5rem; text-align: center; }
h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.3rem; }
h1 .emoji { font-size: 1.8rem; }
.subtitle { font-size: 0.85rem; color: var(--ink-dim); font-style: italic; }
.subtitle a {
    color: var(--accent); text-decoration: none; font-weight: 600;
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.3rem 0.8rem; border-radius: 20px;
    background: #f0eeff; transition: all 0.15s;
    cursor: pointer; user-select: none;
}
.subtitle a:hover { background: var(--accent); color: #fff; }
.subtitle a:active { transform: scale(0.97); }

/* BANNIÈRE CORS */
.cors-alert {
    background: #fef3c7; border: 2px solid #fbbf24;
    border-radius: 10px; padding: 0.9rem 1rem;
    font-size: 0.8rem; color: #78350f;
    margin-bottom: 1rem; display: none; line-height: 1.5;
}
.cors-alert.visible { display: block; }
.cors-alert strong { color: #7c2d12; }
.cors-alert code {
    background: #fff; padding: 0.15rem 0.4rem; border-radius: 4px;
    font-family: ui-monospace, monospace; font-size: 0.75rem;
    border: 1px solid #fcd34d;
}

.mode-selector {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 0.6rem; margin-bottom: 1rem;
}
.mode-card {
    padding: 1.1rem 1rem; border-radius: 12px;
    border: 2px solid var(--border); background: var(--panel);
    cursor: pointer; text-align: center;
    transition: all 0.2s; font-family: inherit;
}
.mode-card:active { transform: scale(0.98); }
.mode-card.selected { border-color: var(--accent); background: #f0eeff; }
.mode-card.img.selected { border-color: var(--accent-img); background: #e8f4ff; }
.mode-card.txt.selected { border-color: var(--accent-txt); background: #ffece5; }
.mode-card .mc-icon { font-size: 2rem; display: block; margin-bottom: 0.4rem; }
.mode-card .mc-title { font-size: 0.9rem; font-weight: 700; margin-bottom: 0.2rem; }
.mode-card .mc-desc { font-size: 0.7rem; color: var(--ink-dim); line-height: 1.3; }
.mode-card.selected .mc-title { color: var(--accent); }
.mode-card.img.selected .mc-title { color: var(--accent-img); }
.mode-card.txt.selected .mc-title { color: var(--accent-txt); }

.toast {
    position: fixed; top: 1.5rem; left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--ink); color: #fff;
    padding: 0.85rem 1.4rem; border-radius: 10px;
    font-size: 0.85rem; font-weight: 500;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1000; opacity: 0;
    transition: transform 0.35s ease, opacity 0.35s ease;
    max-width: 90vw; text-align: center;
    display: flex; align-items: center; gap: 0.5rem;
}
.toast.visible { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.warn { background: var(--warn); }

.diag-bar {
    background: #1a1a1a; color: #fff; padding: 0.6rem 0.9rem;
    border-radius: 8px; font-size: 0.72rem; margin-bottom: 1rem;
    font-family: ui-monospace, monospace;
    display: flex; flex-wrap: wrap; gap: 0.6rem; line-height: 1.4;
}
.diag-bar .diag-item { display: flex; align-items: center; gap: 0.3rem; }
.diag-bar .diag-ok { color: #4ade80; }
.diag-bar .diag-ko { color: #f87171; }
.diag-bar .diag-wait { color: #fbbf24; }

/* BARRE DE SUPPORT FLOTTANTE */
.support-fab {
    position: fixed; bottom: 80px; right: 16px;
    background: #25D366; color: #fff;
    border: none; border-radius: 50%;
    width: 56px; height: 56px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem; cursor: pointer;
    box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4);
    z-index: 150;
    transition: transform 0.2s;
}
.support-fab:active { transform: scale(0.9); }
.support-fab .badge-dot {
    position: absolute; top: 8px; right: 8px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--error); border: 2px solid #fff;
    display: none;
}
.support-fab.has-bug .badge-dot { display: block; }

/* ÉCRAN D'ERREUR */
.error-screen {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 3000; display: none;
    align-items: center; justify-content: center;
    padding: 1rem;
}
.error-screen.visible { display: flex; }
.error-box {
    background: #fff; border-radius: 14px;
    padding: 1.5rem 1.3rem;
    max-width: 420px; width: 100%;
    text-align: center;
    animation: slideUp 0.3s ease;
}
@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.error-box .eb-icon {
    font-size: 3rem; margin-bottom: 0.8rem;
}
.error-box .eb-title {
    font-size: 1.1rem; font-weight: 700;
    margin-bottom: 0.4rem; color: var(--error);
}
.error-box .eb-desc {
    font-size: 0.85rem; color: var(--ink-dim);
    margin-bottom: 1.2rem; line-height: 1.5;
}
.error-box .eb-actions {
    display: flex; flex-direction: column; gap: 0.5rem;
}
.error-box .eb-btn {
    padding: 0.85rem 1rem; border-radius: 10px;
    border: none; font-size: 0.88rem; font-weight: 600;
    font-family: inherit; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.error-box .eb-btn-primary {
    background: #25D366; color: #fff;
}
.error-box .eb-btn-secondary {
    background: var(--panel-2); border: 1px solid var(--border); color: var(--ink);
}
.error-box .eb-btn:active { transform: scale(0.97); }
.error-box .eb-details {
    font-size: 0.7rem; color: var(--ink-faint);
    margin-top: 1rem; padding-top: 0.8rem;
    border-top: 1px solid var(--border);
    font-family: ui-monospace, monospace;
    text-align: left; max-height: 100px; overflow-y: auto;
    word-break: break-word;
}

/* MODE DEBUG */
.debug-panel {
    position: fixed; bottom: 16px; left: 16px;
    background: #1a1a1a; color: #4ade80;
    border-radius: 10px; padding: 0.8rem 1rem;
    font-family: ui-monospace, monospace;
    font-size: 0.68rem; line-height: 1.5;
    max-width: 320px; max-height: 400px; overflow-y: auto;
    z-index: 400; display: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    border: 1px solid #333;
}
.debug-panel.visible { display: block; }
.debug-panel .dp-title {
    color: #fff; font-weight: 700;
    margin-bottom: 0.5rem; font-size: 0.75rem;
    display: flex; justify-content: space-between; align-items: center;
}
.debug-panel .dp-line {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.debug-panel .dp-close {
    background: transparent; border: 1px solid #555;
    color: #fff; font-size: 0.65rem;
    padding: 0.1rem 0.4rem; border-radius: 4px;
    cursor: pointer; font-family: inherit;
}
.debug-panel .dp-copy {
    background: #4ade80; color: #000;
    border: none; padding: 0.4rem 0.7rem;
    border-radius: 6px; font-size: 0.7rem;
    font-weight: 700; margin-top: 0.6rem;
    cursor: pointer; width: 100%;
    font-family: inherit;
}

.section {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden;
}
.section-header {
    padding: 0.9rem 1.1rem; cursor: pointer; user-select: none;
    display: flex; justify-content: space-between; align-items: center;
}
.section-header:active { background: var(--panel-2); }
.section-title {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em;
    color: var(--ink-dim); font-weight: 600;
}
.section-title .badge {
    display: inline-block; margin-left: 0.4rem; padding: 0.1rem 0.4rem;
    background: var(--ink); color: #fff; border-radius: 10px;
    font-size: 0.65rem; letter-spacing: 0;
}
.section-title .badge.soft { background: var(--accent); color: #fff; }
.section-title .badge.count { background: var(--accent-2); color: #fff; }
.section-title .badge.new { background: var(--accent-3); color: #fff; }
.section-title .badge.opt { background: #ddd; color: #666; }
.section-title .badge.on { background: var(--success); color: #fff; }
.section-title .badge.off { background: #ccc; color: #666; }
.section-title .badge.fmt { background: var(--accent-img); color: #fff; }
.section-header .chevron {
    font-size: 0.7rem; color: var(--ink-faint); transition: transform 0.2s;
}
.section.open .section-header .chevron { transform: rotate(180deg); }
.section-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.section.open .section-body { max-height: 20000px; }
.section-content { padding: 0 1.1rem 1.1rem; }

.api-panel {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.2rem;
    margin-bottom: 1rem; transition: border-color 0.3s;
}
.api-panel.ok { border-color: var(--success); }
.api-key-input {
    width: 100%; padding: 0.85rem 1rem; border-radius: 8px;
    border: 1px solid var(--border); background: #fafafa; color: var(--ink);
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.85rem; margin-bottom: 0.6rem;
}
.api-key-input:focus { outline: none; border-color: var(--ink); }
.api-save-btn {
    width: 100%; padding: 0.8rem 1.2rem; border-radius: 8px; border: none;
    background: var(--ink); color: #fff; font-size: 0.9rem; font-weight: 600;
    font-family: inherit; cursor: pointer; margin-bottom: 0.6rem;
}
.api-test-btn {
    width: 100%; padding: 0.7rem 1.2rem; border-radius: 8px;
    border: 1px solid var(--success); background: #e3f5e9;
    color: var(--success); font-size: 0.85rem; font-weight: 600;
    font-family: inherit; cursor: pointer; margin-bottom: 0.6rem;
}
.api-status-line {
    font-size: 0.75rem; padding: 0.55rem 0.85rem; border-radius: 6px;
    margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.5rem;
    background: var(--panel-2); color: var(--ink-dim);
}
.api-status-line.ok { background: #e3f5e9; color: var(--success); font-weight: 600; }
.api-status-line.error { background: #fdecea; color: var(--error); font-weight: 600; }
.api-status-line .status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--ink-faint); flex-shrink: 0;
}
.api-status-line.ok .status-dot { background: var(--success); }
.api-status-line.error .status-dot { background: var(--error); }
.api-hint { font-size: 0.72rem; color: var(--ink-dim); margin-top: 0.4rem; }
.api-hint a { color: var(--ink); text-decoration: underline; }

.upload-zone {
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 2rem 1rem; text-align: center; cursor: pointer;
    transition: border-color 0.2s, background 0.2s; margin-bottom: 0.8rem;
    background: var(--panel);
}
.upload-zone:active { border-color: var(--accent); background: #f0eeff; }
.upload-zone.dragover { border-color: var(--accent); background: #f0eeff; border-style: solid; }
.upload-zone input[type="file"] { display: none; }
.upload-icon { font-size: 2.5rem; margin-bottom: 0.6rem; }
.upload-text { font-size: 0.95rem; color: var(--ink); margin-bottom: 0.2rem; font-weight: 600; }
.upload-hint { font-size: 0.75rem; color: var(--ink-dim); }

.upload-progress {
    margin-top: 0.8rem; padding: 0.6rem 0.9rem;
    background: #f0eeff; border-radius: 8px;
    font-size: 0.78rem; color: var(--accent); display: none;
}
.upload-progress.visible { display: block; }
.upload-progress .up-bar {
    height: 6px; background: #e0ddf8; border-radius: 3px;
    overflow: hidden; margin-top: 0.4rem;
}
.upload-progress .up-bar-fill {
    height: 100%; background: var(--accent);
    border-radius: 3px; transition: width 0.2s; width: 0%;
}
.upload-progress .up-text {
    display: flex; justify-content: space-between;
    font-weight: 600; font-size: 0.75rem;
}

.images-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.7rem; flex-wrap: wrap; gap: 0.5rem;
    padding: 0.6rem 0.9rem; background: var(--panel-2);
    border-radius: 8px; font-size: 0.78rem;
}
.images-toolbar .it-count { font-weight: 600; color: var(--ink); }
.images-toolbar .it-count .it-selected { color: var(--accent); }
.images-toolbar .it-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.images-toolbar .it-btn {
    padding: 0.35rem 0.7rem; border-radius: 6px;
    border: 1px solid var(--border); background: var(--panel);
    color: var(--ink-dim); font-size: 0.72rem; cursor: pointer;
    font-family: inherit;
}
.images-toolbar .it-btn.danger { color: var(--error); border-color: #f5d0c9; }
.images-toolbar .it-btn.accent { color: var(--accent); border-color: var(--accent-2); background: #f0eeff; }

.images-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 0.5rem; margin-bottom: 1rem;
}
.image-card {
    position: relative; border-radius: 8px; overflow: hidden;
    border: 2px solid var(--border); background: #f0f0f0;
    aspect-ratio: 9/16; cursor: pointer;
}
.image-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.25);
}
.image-card.unselected { opacity: 0.4; filter: grayscale(0.5); }
.image-card .check-badge {
    position: absolute; top: 4px; left: 4px;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.image-card.unselected .check-badge { background: transparent; border-color: var(--ink-faint); }
.image-card .remove-btn {
    position: absolute; top: 4px; right: 4px;
    background: rgba(0,0,0,0.65); color: #fff; border: none;
    width: 22px; height: 22px; border-radius: 50%; font-size: 11px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    z-index: 2;
}

.scene-panel {
    background: linear-gradient(135deg, #f0eeff 0%, #fff5f0 100%);
    border: 2px solid var(--accent);
    border-radius: 12px; padding: 1.3rem 1.1rem;
    margin-bottom: 1rem;
}
.scene-panel .sp-title {
    font-size: 1rem; font-weight: 700; color: var(--accent);
    margin-bottom: 0.4rem;
    display: flex; align-items: center; gap: 0.5rem;
}
.scene-panel .sp-title .sp-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--accent); color: #fff;
    font-size: 0.75rem; font-weight: 700;
}
.scene-panel .sp-sub {
    font-size: 0.78rem; color: var(--ink-dim);
    margin-bottom: 1rem; line-height: 1.5;
}
.scene-textarea {
    width: 100%; padding: 1rem;
    border-radius: 8px; border: 2px solid var(--accent-2);
    background: #fff; color: var(--ink);
    font-family: inherit; font-size: 0.9rem;
    min-height: 140px; resize: vertical; line-height: 1.5;
}
.scene-textarea:focus { outline: none; border-color: var(--accent); }
.scene-textarea::placeholder { color: var(--ink-faint); }

.scene-presets {
    display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem;
}
.scene-preset {
    padding: 0.4rem 0.8rem; border-radius: 16px;
    border: 1px solid var(--accent); background: #fff;
    color: var(--accent); font-size: 0.72rem;
    cursor: pointer; user-select: none;
    font-family: inherit; transition: all 0.15s;
}
.scene-preset:active { transform: scale(0.96); }

.text-prompt-panel {
    background: linear-gradient(135deg, #fff5f0 0%, #fff 100%);
    border: 2px solid var(--accent-txt);
    border-radius: 12px; padding: 1.2rem 1.1rem;
    margin-bottom: 1rem;
}
.text-prompt-panel .tp-title {
    font-size: 0.95rem; font-weight: 700; color: var(--accent-txt);
    margin-bottom: 0.3rem;
}
.text-prompt-panel .tp-sub {
    font-size: 0.75rem; color: var(--ink-dim);
    margin-bottom: 0.9rem; line-height: 1.4;
}
.text-prompt-textarea {
    width: 100%; padding: 0.9rem 1rem; border-radius: 8px;
    border: 1px solid var(--border); background: #fff; color: var(--ink);
    font-family: inherit; font-size: 0.9rem; min-height: 120px;
    resize: vertical; line-height: 1.5;
}
.text-prompt-textarea:focus { outline: none; border-color: var(--accent-txt); }

.text-preset-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; }
.text-preset-tag {
    padding: 0.35rem 0.7rem; border-radius: 16px;
    border: 1px solid var(--accent-txt); background: #fff;
    color: var(--accent-txt); font-size: 0.72rem; cursor: pointer;
    font-family: inherit; user-select: none;
}
.text-count-hint {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.7rem; color: var(--ink-dim); margin-top: 0.5rem;
}

.inspire-hero {
    background: linear-gradient(135deg, #6c5ce7 0%, #fd79a8 100%);
    padding: 1.2rem 1.1rem; border-radius: 10px;
    color: #fff; margin-bottom: 1rem;
    display: flex; justify-content: space-between; align-items: center;
    gap: 1rem; flex-wrap: wrap;
}
.inspire-hero .ih-text { flex: 1; min-width: 200px; }
.inspire-hero .ih-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 0.3rem; }
.inspire-hero .ih-desc { font-size: 0.75rem; opacity: 0.9; line-height: 1.4; }
.inspire-hero .ih-btn {
    padding: 0.7rem 1.2rem; border-radius: 8px;
    background: #fff; color: var(--accent);
    font-size: 0.82rem; font-weight: 700;
    font-family: inherit; cursor: pointer; border: none;
    white-space: nowrap;
}

.inspire-categories {
    display: flex; gap: 0.4rem; overflow-x: auto;
    margin-bottom: 1rem; padding-bottom: 0.4rem;
}
.inspire-cat {
    padding: 0.4rem 0.9rem; border-radius: 20px;
    border: 1px solid var(--border); background: var(--panel-2);
    font-size: 0.75rem; cursor: pointer; white-space: nowrap;
    font-family: inherit; flex-shrink: 0;
}
.inspire-cat.selected {
    background: var(--accent); color: #fff;
    border-color: var(--accent); font-weight: 600;
}

.inspire-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.7rem;
}
.inspire-card {
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 10px; padding: 0.9rem 1rem; cursor: pointer;
    transition: all 0.15s;
}
.inspire-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.inspire-card .ic-emoji { font-size: 1.8rem; margin-bottom: 0.3rem; display: block; }
.inspire-card .ic-title { font-size: 0.85rem; font-weight: 700; margin-bottom: 0.3rem; }
.inspire-card .ic-desc { font-size: 0.72rem; color: var(--ink-dim); line-height: 1.4; margin-bottom: 0.5rem; }
.inspire-card .ic-tags { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.inspire-card .ic-tag {
    font-size: 0.62rem; padding: 0.15rem 0.5rem;
    background: #f0eeff; color: var(--accent);
    border-radius: 10px; font-weight: 600;
}

.favorites-toolbar { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; flex-wrap: wrap; }
.fav-btn {
    padding: 0.5rem 0.9rem; border-radius: 8px;
    border: 1px solid var(--accent); background: #f0eeff;
    color: var(--accent); font-size: 0.75rem; font-weight: 600;
    font-family: inherit; cursor: pointer;
}
.fav-btn.neutral { border-color: var(--border); background: var(--panel-2); color: var(--ink-dim); }
.favorites-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem; margin-bottom: 0.6rem;
}
.fav-card {
    padding: 0.7rem 0.85rem; border-radius: 8px;
    border: 1px solid var(--border); background: var(--panel-2);
    cursor: pointer; position: relative;
}
.fav-card .fav-name {
    font-size: 0.82rem; font-weight: 600;
    margin-bottom: 0.2rem; padding-right: 1.4rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fav-card .fav-meta { font-size: 0.68rem; color: var(--ink-dim); display: flex; gap: 0.4rem; flex-wrap: wrap; }
.fav-card .fav-delete {
    position: absolute; top: 4px; right: 4px;
    background: transparent; border: none; color: var(--error);
    font-size: 0.9rem; cursor: pointer; padding: 0.2rem; line-height: 1;
}
.fav-empty {
    font-size: 0.75rem; color: var(--ink-dim); font-style: italic;
    padding: 0.6rem; text-align: center;
}

.prompt-main {
    width: 100%; padding: 0.85rem 1rem; border-radius: 8px;
    border: 1px solid var(--border); background: #fafafa; color: var(--ink);
    font-family: inherit; font-size: 0.9rem; min-height: 80px; resize: vertical;
    line-height: 1.5;
}
.prompt-main:focus { outline: none; border-color: var(--ink); }
.prompt-presets { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; }
.prompt-preset {
    padding: 0.35rem 0.7rem; border-radius: 16px;
    border: 1px solid var(--border); background: var(--panel-2);
    font-size: 0.72rem; cursor: pointer; user-select: none;
}

.format-selector {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem; margin-bottom: 1rem;
}
.format-card {
    padding: 0.9rem 0.8rem; border-radius: 10px;
    border: 2px solid var(--border); background: var(--panel-2);
    cursor: pointer; text-align: center; font-family: inherit;
    transition: all 0.15s;
    display: flex; flex-direction: column; align-items: center;
    gap: 0.5rem;
}
.format-card:active { transform: scale(0.98); }
.format-card.selected { border-color: var(--accent-img); background: #e8f4ff; }
.format-card .fc-frame {
    width: 40px; height: 40px;
    border: 2px solid var(--ink-dim);
    border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.format-card.selected .fc-frame { border-color: var(--accent-img); }
.format-card .fc-ratio-portrait { width: 22px; height: 40px; }
.format-card .fc-ratio-landscape { width: 40px; height: 22px; }
.format-card .fc-ratio-square { width: 32px; height: 32px; }
.format-card .fc-ratio-cinema { width: 40px; height: 17px; }
.format-card .fc-name { font-size: 0.8rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.format-card.selected .fc-name { color: var(--accent-img); }
.format-card .fc-ratio-text {
    font-size: 0.65rem; color: var(--ink-dim);
    text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
}
.format-card.selected .fc-ratio-text { color: var(--accent-img); }
.format-card .fc-usage { font-size: 0.62rem; color: var(--ink-faint); line-height: 1.25; font-style: italic; }

.perso-toggle {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.8rem 1rem; border-radius: 10px;
    background: linear-gradient(135deg, #f0eeff 0%, #fff 100%);
    border: 1px solid var(--accent-2);
    margin-bottom: 1rem;
}
.perso-toggle .pt-text { flex: 1; min-width: 0; }
.perso-toggle .pt-title { font-size: 0.85rem; font-weight: 700; color: var(--accent); margin-bottom: 0.15rem; }
.perso-toggle .pt-desc { font-size: 0.7rem; color: var(--ink-dim); line-height: 1.35; }
.perso-toggle .pt-switch {
    position: relative; width: 52px; height: 28px;
    background: var(--border); border-radius: 14px;
    cursor: pointer; transition: background 0.2s;
    flex-shrink: 0; margin-left: 0.8rem;
}
.perso-toggle .pt-switch.on { background: var(--accent); }
.perso-toggle .pt-switch::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px; border-radius: 50%;
    background: #fff; transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.perso-toggle .pt-switch.on::after { transform: translateX(24px); }

.char-count-selector {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem; margin-bottom: 1rem;
}
.char-count-btn {
    padding: 1rem 0.5rem; border-radius: 10px;
    border: 2px solid var(--border); background: var(--panel-2);
    cursor: pointer; text-align: center; font-family: inherit;
}
.char-count-btn.selected {
    border-color: var(--accent); background: #f0eeff; color: var(--accent);
}
.char-count-btn .cc-num { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1; }
.char-count-btn .cc-label {
    display: block; font-size: 0.65rem; text-transform: uppercase;
    letter-spacing: 0.05em; margin-top: 0.3rem; font-weight: 600;
    color: var(--ink-dim);
}
.char-count-btn.selected .cc-label { color: var(--accent); }

.character-card {
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 10px; padding: 0.9rem 1rem; margin-bottom: 0.7rem;
}
.character-card .char-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.6rem;
}
.character-card .char-badge {
    display: inline-block; padding: 0.15rem 0.5rem; border-radius: 10px;
    background: var(--accent); color: #fff; font-size: 0.65rem;
    font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.character-card .field-label {
    display: block; font-size: 0.68rem; color: var(--ink-dim);
    text-transform: uppercase; letter-spacing: 0.05em;
    font-weight: 600; margin: 0.5rem 0 0.3rem;
}
.character-card .field-label .opt { color: var(--ink-faint); text-transform: none; letter-spacing: 0; font-weight: 400; }
.character-card input[type="text"],
.character-card select,
.character-card textarea {
    width: 100%; padding: 0.6rem 0.8rem; border-radius: 6px;
    border: 1px solid var(--border); background: #fff; color: var(--ink);
    font-family: inherit; font-size: 0.85rem;
}
.character-card textarea { min-height: 55px; resize: vertical; line-height: 1.45; }
.character-card input:focus,
.character-card select:focus,
.character-card textarea:focus { outline: none; border-color: var(--accent); }

.voice-row { display: flex; gap: 0.4rem; align-items: stretch; }
.voice-row select { flex: 1; min-width: 0; }
.voice-test-btn {
    padding: 0.6rem 0.9rem; border-radius: 6px;
    border: 1px solid var(--accent); background: #f0eeff;
    color: var(--accent); font-size: 0.75rem; font-weight: 600;
    font-family: inherit; cursor: pointer; white-space: nowrap;
}
.voice-test-btn.playing { background: var(--accent); color: #fff; }

.voice-status {
    font-size: 0.68rem; color: var(--ink-dim);
    margin-top: 0.4rem; padding: 0.4rem 0.6rem;
    background: #fff9f5; border-left: 2px solid var(--warn);
    border-radius: 4px; line-height: 1.35;
}
.voice-status.ok {
    background: #e3f5e9; border-left-color: var(--success);
    color: var(--success);
}

.control-row { margin-bottom: 0.9rem; }
.control-label {
    display: block; font-size: 0.72rem; color: var(--ink-dim);
    margin-bottom: 0.4rem; text-transform: uppercase;
    letter-spacing: 0.06em; font-weight: 600;
}
select, input[type="range"] {
    width: 100%; padding: 0.7rem 0.9rem; border-radius: 8px;
    border: 1px solid var(--border); background: #fafafa;
    color: var(--ink); font-family: inherit; font-size: 0.88rem;
}
select { -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%231a1a1a' d='M0 0l5 6 5-6z'/></svg>");
    background-repeat: no-repeat; background-position: right 0.9rem center; background-size: 10px;
}

.variants-selector {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem; margin-bottom: 0.8rem;
}
.variant-btn {
    padding: 0.8rem 0.5rem; border-radius: 10px;
    border: 2px solid var(--border); background: var(--panel-2);
    cursor: pointer; text-align: center; font-family: inherit;
}
.variant-btn.selected {
    border-color: var(--accent); background: #f0eeff; color: var(--accent);
}
.variant-btn .vb-num { display: block; font-size: 1.2rem; font-weight: 700; line-height: 1; }
.variant-btn .vb-label {
    display: block; font-size: 0.65rem; text-transform: uppercase;
    letter-spacing: 0.05em; margin-top: 0.3rem; font-weight: 600;
    color: var(--ink-dim);
}
.variant-btn.selected .vb-label { color: var(--accent); }

.btn-primary {
    width: 100%; padding: 1.1rem; border-radius: var(--radius);
    border: none; background: var(--accent); color: #fff;
    font-size: 1rem; font-weight: 600; font-family: inherit;
    cursor: pointer; margin-bottom: 1rem;
}
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary .reason {
    display: block; font-size: 0.65rem; font-weight: 400;
    opacity: 0.85; margin-top: 0.15rem; font-style: italic;
}

.btn-actions-row {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 0.5rem; margin-bottom: 1rem;
}
.btn-secondary {
    padding: 0.8rem; border-radius: var(--radius);
    border: 1px solid var(--accent); background: #f0eeff;
    color: var(--accent); font-size: 0.85rem; font-weight: 600;
    font-family: inherit; cursor: pointer;
}
.btn-secondary:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-stop {
    width: 100%; padding: 0.8rem; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--panel);
    color: var(--error); font-size: 0.85rem; font-weight: 600;
    font-family: inherit; cursor: pointer; margin-bottom: 1rem;
    display: none;
}
.btn-stop.visible { display: block; }

.resume-banner {
    background: #fef3c7; border: 1px solid #fbbf24;
    border-radius: 8px; padding: 0.8rem 1rem;
    font-size: 0.8rem; color: #78350f;
    margin-bottom: 1rem;
    display: flex; align-items: center; gap: 0.7rem;
    flex-wrap: wrap;
}
.resume-banner.hidden { display: none; }
.resume-banner .rb-text { flex: 1; min-width: 200px; }
.resume-banner button {
    padding: 0.5rem 1rem; border-radius: 6px;
    background: #fbbf24; color: #78350f; border: none;
    font-size: 0.78rem; font-weight: 700; font-family: inherit;
    cursor: pointer;
}

.queue { margin-top: 1rem; }
.queue-summary {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 8px; padding: 0.7rem 0.9rem; margin-bottom: 0.6rem;
    font-size: 0.78rem; display: flex; justify-content: space-between;
    align-items: center; flex-wrap: wrap; gap: 0.4rem;
}
.queue-item {
    display: flex; align-items: center; gap: 0.8rem;
    padding: 0.7rem 0.8rem; border-radius: 8px;
    border: 1px solid var(--border); margin-bottom: 0.4rem;
    background: var(--panel); font-size: 0.82rem;
}
.queue-item.pending { opacity: 0.5; }
.queue-item.processing { border-color: var(--accent); }
.queue-item.done { border-color: var(--success); }
.queue-item.failed { border-color: var(--error); }
.queue-item.skipped { opacity: 0.5; border-style: dashed; }
.queue-item .q-icon { font-size: 1rem; width: 1.5rem; text-align: center; flex-shrink: 0; }
.queue-item .q-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item .q-status { font-size: 0.72rem; color: var(--ink-dim); text-align: right; flex-shrink: 0; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-more {
    text-align: center; padding: 0.5rem; color: var(--ink-dim);
    font-size: 0.72rem; font-style: italic;
}

.gallery { margin-top: 1.5rem; }
.gallery-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.8rem; flex-wrap: wrap; gap: 0.5rem;
}
.gallery-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-dim); font-weight: 600; }
.gallery-count {
    font-size: 0.7rem; background: var(--ink); color: #fff;
    padding: 0.15rem 0.5rem; border-radius: 10px;
}
.gallery-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.gallery-actions button {
    font-size: 0.7rem; padding: 0.35rem 0.7rem;
    border-radius: 6px; cursor: pointer; font-family: inherit;
}
.gallery-actions .btn-zip {
    background: var(--accent); color: #fff; border: none; font-weight: 600;
}
.gallery-actions .btn-clear {
    background: transparent; border: 1px solid var(--border); color: var(--ink-dim);
}
.gallery-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.8rem;
}
.gallery-item {
    border-radius: var(--radius); overflow: hidden;
    border: 1px solid var(--border); background: #000;
}
.gallery-item video { width: 100%; display: block; object-fit: cover; }
.gallery-item video.auto { aspect-ratio: 1088/832; }
.gallery-item .g-caption {
    padding: 0.5rem 0.6rem; background: var(--panel);
    font-size: 0.7rem; color: var(--ink-dim); line-height: 1.35;
}
.gallery-item .g-caption .g-dialogue {
    display: block; color: var(--ink); font-style: italic;
    margin-top: 0.2rem; font-size: 0.68rem;
}
.gallery-item .g-actions {
    display: flex; gap: 0.3rem; padding: 0 0.6rem 0.5rem; background: var(--panel);
}
.gallery-item .g-actions button {
    flex: 1; padding: 0.4rem; border-radius: 6px;
    border: 1px solid var(--border); background: var(--panel-2);
    font-size: 0.68rem; cursor: pointer; font-family: inherit;
}
.gallery-item .g-actions button.primary {
    background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600;
}
.gallery-item .g-actions button.muted {
    background: var(--panel-2); color: var(--ink-dim);
}
.gallery-item .g-format-badge {
    position: absolute; top: 6px; right: 6px;
    background: rgba(0,0,0,0.7); color: #fff;
    font-size: 0.6rem; font-weight: 700;
    padding: 0.2rem 0.45rem; border-radius: 4px;
    letter-spacing: 0.05em;
}
.gallery-item { position: relative; }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 2000; display: none;
    align-items: center; justify-content: center;
    padding: 1rem;
}
.modal-overlay.visible { display: flex; }
.modal {
    background: var(--panel); border-radius: var(--radius);
    padding: 1.2rem; max-width: 500px; width: 100%;
    max-height: 85vh; overflow-y: auto;
}
.modal h3 { font-size: 1rem; margin-bottom: 0.8rem; font-weight: 600; }
.modal p { font-size: 0.8rem; color: var(--ink-dim); margin-bottom: 0.8rem; line-height: 1.45; }
.modal input[type="text"], .modal textarea {
    width: 100%; padding: 0.7rem 0.9rem; border-radius: 8px;
    border: 1px solid var(--border); background: #fafafa;
    font-family: inherit; font-size: 0.85rem; margin-bottom: 0.7rem;
}
.modal textarea { min-height: 150px; font-family: ui-monospace, monospace; font-size: 0.75rem; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.modal-actions button {
    flex: 1; padding: 0.75rem; border-radius: 8px;
    font-size: 0.85rem; font-weight: 600; font-family: inherit; cursor: pointer;
}
.modal-actions .btn-cancel { background: var(--panel-2); border: 1px solid var(--border); color: var(--ink); }
.modal-actions .btn-confirm { background: var(--accent); border: none; color: #fff; }

.status-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--ink); color: #fff; padding: 0.7rem 1rem;
    font-size: 0.78rem; display: flex; align-items: center; gap: 0.6rem;
    transform: translateY(100%); transition: transform 0.3s; z-index: 100;
}
.status-bar.visible { transform: translateY(0); }
.status-bar .spinner {
    width: 12px; height: 12px; border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff; border-radius: 50%;
    animation: spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

#noSleepCanvas, #noSleepVideo {
    position: fixed; top: 0; left: 0; width: 1px; height: 1px;
    opacity: 0.01; pointer-events: none; z-index: -1;
}

.mode-image-only, .mode-text-only { display: none; }
body.mode-image .mode-image-only { display: block; }
body.mode-text .mode-text-only { display: block; }

/* BARRE UTILISATEUR (Laravel) */
.user-bar {
    display: flex; justify-content: center; align-items: center; gap: 0.6rem;
    font-size: 0.78rem; color: var(--ink-dim); margin-bottom: 0.5rem;
}
.user-bar form { margin: 0; }
.ub-logout {
    font-family: inherit; font-size: 0.72rem; cursor: pointer;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--ink-dim);
    padding: 0.2rem 0.6rem; border-radius: 20px;
}
.ub-logout:hover { color: var(--error); border-color: var(--error); }
.resume-banner .rb-dismiss { background: transparent; border: 1px solid #fbbf24; }

/* MON COMPTE */
.profile-form input[type=text], .profile-form input[type=email], .profile-form input[type=password] {
    width: 100%; padding: 0.65rem 0.8rem; border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.9rem; font-family: inherit; background: var(--panel-2); color: var(--ink);
}
.profile-form input:focus { outline: none; border-color: var(--accent); background: #fff; }
.profile-password-form { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.profile-subtitle { font-size: 0.8rem; font-weight: 700; margin-bottom: 0.7rem; }

/* ÉTAT DE LA CLÉ / ESSAI */
.api-panel.trial { border-color: var(--warn); }
.api-panel.none { border-color: var(--error); }
.trial-bar { height: 6px; border-radius: 3px; background: var(--panel-2); margin-top: 0.6rem; overflow: hidden; }
.trial-bar-fill { height: 100%; border-radius: 3px; background: var(--warn); width: 0; transition: width 0.3s; }

/* QUOTAS AGNES & FORFAITS */
.agnes-quota { margin-top: 0.7rem; padding-top: 0.6rem; border-top: 1px dashed var(--border); font-size: 0.74rem; color: var(--ink-dim); line-height: 1.6; }
.agnes-quota strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.forfaits-list { margin-top: 0.7rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.forfait-chip { border: 1px solid var(--accent); border-radius: 10px; padding: 0.45rem 0.8rem; font-size: 0.76rem; background: #f0eeff; font-family: inherit; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 0.3rem; }
.forfait-chip:hover { background: #e4e0ff; }
.forfait-chip:disabled { opacity: 0.6; cursor: wait; }
.forfait-chip .fc-buy { margin-left: 0.4rem; background: var(--accent); color: #fff; border-radius: 6px; padding: 0.1rem 0.5rem; font-weight: 700; font-size: 0.7rem; }
.forfait-chip strong { color: var(--accent); }

/* ═══════════════════════════════════════════════════════════════
   TACTILE & MOBILE (studio, connexion, administration)
   ═══════════════════════════════════════════════════════════════ */

/* Retour visuel à l'appui et suppression du délai de 300 ms sur les éléments cliquables. */
* { -webkit-tap-highlight-color: rgba(108, 92, 231, 0.18); }
button, a, select, label, summary, input[type=checkbox], input[type=radio], input[type=range],
.section-header, .mode-card, .format-card, .upload-zone, .perso-toggle, .image-card, .fav-card, .inspire-card,
.scene-preset, .text-preset-tag, .prompt-preset, .forfait-chip {
    touch-action: manipulation;
}
button:active:not(:disabled), .section-header:active, .fav-card:active, .inspire-card:active { opacity: 0.75; }
button:disabled { cursor: not-allowed; }
html { -webkit-text-size-adjust: 100%; }
img, video { max-width: 100%; }

/* Encoches et barres système (iPhone) pour les éléments fixes. */
.support-fab { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); right: calc(16px + env(safe-area-inset-right, 0px)); }
.status-bar { padding-bottom: calc(0.8rem + env(safe-area-inset-bottom, 0px)); }

@media (max-width: 640px) {
    body {
        padding: 1rem calc(0.75rem + env(safe-area-inset-right, 0px)) calc(7rem + env(safe-area-inset-bottom, 0px)) calc(0.75rem + env(safe-area-inset-left, 0px));
        font-size: 15px;
    }
    h1 { font-size: 1.3rem; }

    /* 16 px minimum : en dessous, iOS zoome sur le champ à la saisie. */
    input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
        font-size: 16px !important;
    }

    /* Cibles tactiles d'au moins 44 px. */
    button, .ub-logout, .fav-btn, .it-btn, .inspire-cat, .scene-preset, .text-preset-tag, .prompt-preset,
    .forfait-chip, .subtitle a, .g-actions button, .voice-test-btn, select {
        min-height: 44px;
    }
    .ub-logout, .subtitle a { display: inline-flex; align-items: center; padding-left: 1rem; padding-right: 1rem; }
    .section-header { min-height: 52px; }
    input[type=range] { min-height: 36px; width: 100%; }

    .user-bar { flex-wrap: wrap; gap: 0.5rem; }
    .mode-card { padding: 0.9rem 0.6rem; }
    .diag-bar { font-size: 0.68rem; gap: 0.3rem 0.6rem; }

    /* Grilles : moins de colonnes sur petit écran. */
    .format-selector { grid-template-columns: repeat(2, 1fr); }
    .char-count-selector { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.35rem; }
    .char-count-btn { min-width: 0; padding-left: 0.2rem; padding-right: 0.2rem; }
    .char-count-btn .cc-label { font-size: 0.5rem; letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
    .variant-btn, .format-card { min-width: 0; }
    .gallery-grid { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
    .inspire-grid { grid-template-columns: 1fr; }
    .images-grid { grid-template-columns: repeat(3, 1fr); }
    .images-toolbar { flex-direction: column; align-items: stretch; gap: 0.5rem; }
    .images-toolbar .it-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.35rem; }
    .favorites-toolbar { display: grid; grid-template-columns: 1fr; gap: 0.4rem; }
    .favorites-toolbar .fav-btn, .profile-form .fav-btn { width: 100%; justify-content: center; }
    .gallery-header { flex-wrap: wrap; gap: 0.5rem; }
    .g-actions { flex-wrap: wrap; }
    .g-actions button { flex: 1 1 auto; }
    .inspire-hero { flex-direction: column; align-items: stretch; text-align: center; gap: 0.7rem; }
    .inspire-hero .ih-btn { width: 100%; }
    .resume-banner button { flex: 1; }

    /* Forfaits : un par ligne, bouton bien visible. */
    .forfaits-list { flex-direction: column; }
    .forfait-chip { width: 100%; justify-content: flex-start; padding: 0.6rem 0.8rem; font-size: 0.82rem; }
    .forfait-chip .fc-buy { margin-left: auto; padding: 0.3rem 0.7rem; font-size: 0.76rem; }

    /* Le bouton WhatsApp ne doit pas masquer le contenu. */
    .support-fab { width: 48px; height: 48px; font-size: 1.3rem; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); right: 12px; }

    /* Fenêtres modales en bas d'écran, pleine largeur. */
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 88vh; padding-bottom: calc(1.2rem + env(safe-area-inset-bottom, 0px)); }
    .modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .error-box { padding: 1.2rem 1rem; }
    .debug-panel { left: 8px; right: 8px; max-width: none; }
    .toast { top: calc(0.8rem + env(safe-area-inset-top, 0px)); width: calc(100vw - 1.5rem); max-width: none; }

    .queue-item { flex-wrap: wrap; }
    .queue-item .q-status { flex-basis: 100%; padding-left: 1.6rem; text-align: left; }

    .auth-card { padding: 1.2rem 1rem; margin-top: 0.5rem; }
}

@media (max-width: 340px) {
    .gallery-grid { grid-template-columns: 1fr; }
    .mode-card .mc-desc { display: none; }
    .variants-selector { gap: 0.3rem; }
}
