@import url('https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&display=swap');

@font-face {
  font-family: 'CrimsonText';
  src: url('../fonts/CrimsonText-Regular.woff2') format('woff2'),
       url('../fonts/CrimsonText-Regular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'CrimsonText';
  src: url('../fonts/CrimsonText-SemiBold.woff2') format('woff2'),
       url('../fonts/CrimsonText-SemiBold.woff') format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

.align-center { text-align: center; }

.mini_infoP{color:red;}

.story-creator-wizard {
    max-width: 900px;
    margin: 20px auto;
    font-family: sans-serif;
    color: #ffffff;
    overflow-x: hidden;
}

#generator-view,
#advanced-mode-container {
    max-width: 100%;
    overflow-x: hidden;
}

.unsaved-story-banner, .premium-upgrade-banner {
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    border: 2px solid #e17055;
    border-radius: 12px;
    padding: 15px 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(225, 112, 85, 0.2);
    animation: slideDown 0.4s ease-out;
}

.unsaved-story-banner.hidden {
    display: none;
}

.banner-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.banner-icon {
    font-size: 28px;
    line-height: 1;
}

.banner-text {
    flex: 1;
    color: #2d3436;
    font-size: 14px;
}

.banner-text strong {
    font-size: 16px;
    display: block;
    margin-bottom: 3px;
}

.banner-actions {
    display: flex;
    gap: 10px;
}

.btn-recover {
    background: #00b894;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-recover:hover {
    background: #00a383;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 184, 148, 0.3);
}

.btn-dismiss {
    background: transparent;
    border: none;
    color: #636e72;
    font-size: 20px;
    cursor: pointer;
    padding: 5px 10px;
    line-height: 1;
    transition: color 0.3s ease;
}

.btn-dismiss:hover {
    color: #2d3436;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.form-group input[type="text"],
.form-group textarea,
.form-group select {
    max-width: 100%;
    box-sizing: border-box;
}

.tag-helper-group,
.radio-options-group,
.mode-selection-buttons {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.story-creator-wizard h2 { border-bottom: 2px solid #d081e7; padding-bottom: 10px; margin-bottom: 20px; color: #ffffff; margin-left: -10px;}
.story-creator-wizard h3 { margin-top: 25px; margin-bottom: 10px; color: #ffffff; }

/* Style pour le sélecteur de mode */
#generation-mode-selector {
    text-align: center;
    padding: 40px 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #313b77;
}

.mode-selection-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
    flex-wrap: wrap;
    padding: 15px 0;
}

.mode-select-btn {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    border: 2px solid #ccc;
    border-radius: 8px;
    background-color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    max-width: 550px;
    min-width: 150px;
    text-align: center;
    margin: 0 auto;
}

.mode-select-btn:hover {
    border-color: #ff69b4;
    transform: translateY(-5px);
    box-shadow: 0 4px 15px rgba(255, 105, 180, 0.2);
    background-color: black;
    color: white;
}

.mode-title {
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 8px;
}

.mode-description {
    font-size: 0.9em;
    color: #666;
}

/* Style pour le conteneur du mode rapide */
#quick-mode-container {
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #313b77;
}

/* Options du mode rapide */
.quick-options-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin: 15px 0;
}

.quick-option label {
    font-size: 1.1em;
    font-weight: 600;
    color: #fff;
    margin-bottom: 5px;
    display: block;
}

.quick-option select {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background-color: #fff;
    transition: all 0.3s ease;
}

.quick-option select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.hidden {
    display: none !important;
}

.loader-container {
    text-align: center;
    margin-top: 20px;
}

.loader {
    border: 5px solid #f3f3f3; /* Gris clair */
    border-top: 5px solid #6a4ff2; /* Violet */
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

#loader-div{
    display: flex;
    flex-direction: column;
    align-items: center;
    height: auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.back-btn {
    background: #fff;
    color: red;
    cursor: pointer;
    font-size: 0.9em;
    margin-bottom: 15px;
    display: block;
    border: solid 1px red;
}
.back-btn:hover {
    color: #ff69b4;
}

#form-column {
    flex: 1;
    min-width: 300px;
}

div#preset-management-area {
    background-color: #8e24aa;
    padding: 20px;
    border-radius: 12px;
}

.preset-input-group {
    display: flex;
    gap: 10px;
}
.preset-input-group select,
.preset-input-group input {
    flex-grow: 1; /* Le champ prend toute la place disponible */
    min-width: 0; /* Permet à l'input de rétrécir correctement dans le conteneur flex */
}
.preset-input-group button {
    flex-shrink: 0; /* Empêche le bouton de rétrécir */
    padding: 10px 15px;
}

#preset-manager {
    background-color: #e8f5e9; /* Vert clair */
    border-color: #a5d6a7;
}

#preset-manager p {
    color: #2e7d32; /* Vert foncé */
    font-size: 0.9em;
    margin-top: 15px;
}

#delete-preset-btn {
    padding: 10px;
    line-height: 1;
}

/* --- Style du Stepper --- */
.story-stepper { display: flex; border-bottom: 1px solid #e0e0e0; margin-bottom: 20px; flex-wrap: wrap; }
.step { border-right: 2px solid #f0f0f1; padding: 15px; cursor: pointer; font-weight: 500; color: #666; border-bottom: 3px solid transparent; transition: all 0.3s ease; display: flex; align-items: center; gap: 8px; flex-grow: 1; justify-content: center; text-align: center; }
.step.active { color: #8e24aa; border-bottom-color: #8e24aa; font-weight: 700; }
.step span { background-color: #ccc; color: white; border-radius: 50%; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; transition: background-color 0.3s ease; flex-shrink: 0;}
.step.active span { background-color: #8e24aa; }

/* --- Visibilité des étapes --- */
.step-content { display: none; animation: fadeIn 0.5s; }
.step-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- Style des conteneurs de formulaire --- */
#character-creator, #scenario-creator, #style-selector, #review-summary-content { background: #313b77; padding: 25px; border-radius: 12px; border: 1px solid #e0e0e0; }
#review-summary-content { overflow-x: hidden; }
#style-selector { overflow-x: hidden; }
.form-group { margin-bottom: 20px; }
.form-instructions { font-size: 0.9em; color: #ffefab; margin: -10px 0 20px 0; font-style: italic; }
.form-instructions-grey { font-size: 0.9em; color: #666; margin: -10px 0 20px 0; font-style: italic; }
.form-instructions-small { font-size: 0.9em; color: #999; margin-top: 5px; font-style: italic; }

label { display: block; font-weight: 600; margin-bottom: 10px; font-size: 1.1em; margin-left: -7px; }
input[type="text"], textarea, select { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 6px; box-sizing: border-box; transition: border-color 0.2s; font-size: 1rem; font-family: inherit; background-color: #fff; }
input[type="text"]:focus, textarea:focus, select:focus { outline: none; border-color: #8e24aa; box-shadow: 0 0 4px rgba(142, 36, 170, 0.3); }
textarea { resize: vertical; margin-top: 0 !important; }
select { appearance: none; -webkit-appearance: none; background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23666%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E'); background-repeat: no-repeat; background-position: right .7em top 50%; background-size: .65em auto; padding-right: 2.5em; }

/* --- Style pour les Info-bulles (Tooltips) --- */

/* Style du petit badge (?) */
.tooltip-trigger {
    display: inline-block;
    margin-left: 8px;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    background-color: #007bff;
    width: 20px;
    height: 20px;
    line-height: 19px;
    text-align: center;
    border-radius: 50%;
    cursor: help; /* Change le curseur pour indiquer qu'il y a une aide */
    position: relative; /* Indispensable pour positionner l'info-bulle */
}

/* L'info-bulle elle-même (créée avec un pseudo-élément ::after) */
.tooltip-trigger::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #2d3748;
    color: #fff;
    padding: 10px 15px;
    border-radius: 5px;
    font-size: 14px;
    font-weight: normal;
    line-height: 1.4;
    width: 280px; /* Largeur fixe, importante pour les calculs */
    text-align: left;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
    z-index: 100;
}

.tooltip-trigger.tooltip-align-left::after {
    left: 0;
    transform: translateX(0); /* On annule la translation */
}

.tooltip-trigger.tooltip-align-left::before {
    left: 15px; /* On ajuste aussi la flèche */
    transform: translateX(0);
}


/* NOUVEAU : Classe pour aligner le tooltip à gauche (pour les triggers à droite de l'écran) */
.tooltip-trigger.tooltip-align-right::after {
    left: auto; /* On annule le 'left: 50%' */
    right: 0;
    transform: translateX(0); /* On annule la translation */
}

.tooltip-trigger.tooltip-align-right::before {
    left: auto; /* On annule le 'left' */
    right: 5px; /* On ajuste aussi la flèche */
    transform: translateX(0);
}

/* Petite flèche en dessous de l'info-bulle */
.tooltip-trigger::before {
    content: '';
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%) translateY(20px); /* Positionne la flèche juste sous la bulle */
    border: 8px solid transparent;
    border-top-color: #2d3748; /* Même couleur que le fond de la bulle */
    
    /* Initialement cachée */
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
    z-index: 101;
}

/* Au survol du badge (?), on affiche l'info-bulle et sa flèche */
.tooltip-trigger:hover::after,
.tooltip-trigger:hover::before {
    visibility: visible;
    opacity: 1;
}
/* --- Style pour les boutons radio --- */
.radio-options-group { display: flex; flex-direction: column; gap: 10px; }
.radio-option { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.radio-option input[type="radio"] { margin: 0; flex-shrink: 0; width: 1.2em; height: 1.2em; }
.radio-option label { margin-bottom: 0; font-weight: normal; cursor: pointer; color:#dcdcdc;}

/* --- Style des Tags --- */
.tag-helper-group { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px;}
.tag { background-color: #f0f0f0; color: #555; border: 1px solid #ddd; padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 14px; transition: all 0.2s ease-in-out; }
.tag:hover { background-color: #e0e0e0; border-color: #ccc; }
.tag.selected { background-color: #d77bff; color: white; border-color: #d77bff; font-weight: bold; }

/* --- Boutons d'action & Assistants --- */
.action-btn { width: 100%; padding: 15px; font-size: 16px; font-weight: bold; background: linear-gradient(45deg, #ff8a00, #e52e71); color: white; border: none; border-radius: 8px; cursor: pointer; margin: 20px 0; transition: transform 0.2s, box-shadow 0.2s; }
.action-btn:hover { transform: scale(1.02); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); color: #fff; font-weight: bold; }

/* --- Description générée --- */
.description-group { position: relative; margin-top: 25px; }
.description-group textarea { background: #f9f9f9; border: 1px dashed #ccc; font-family: monospace; font-size: 0.9em; white-space: pre-wrap; }

/* --- Navigation des personnages --- */
#character-tabs { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; padding-bottom: 10px; flex-wrap: wrap;}
.character-limit-badge {
    display: block;
    font-size: 15px;
    font-weight: normal;
}
.premium-badge {
    background: linear-gradient(135deg, #667eea20 0%, #764ba220 100%);
    padding: 3px 10px;
    border-radius: 10px;
    color: #fff;
}
.free-badge {
    color: #f2d902;
    font-style: italic;
}
.tabs-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex-grow: 1;
    border-bottom: 1px solid;
    margin-right: 20px;
}
.char-tab { color: #313b77; background-color: #f0f0f0; border: 1px solid #ddd; padding: 10px 15px; border-radius: 8px 8px 0 0; cursor: pointer; font-weight: 500; transition: all 0.2s ease; }
.char-tab.active { background-color: #fff; border-bottom-color: #fff; font-weight: 700; color: #8e24aa; }
#add-character-btn { background-color: #8e24aa; color: white; border: none; border-radius: 6px; padding: 8px 16px; font-size: 17px; font-weight: bold; cursor: pointer; transition: background 0.2s; flex-shrink: 0; }
#add-character-btn:hover { background-color: #6a1b9a; }

/* --- Navigation des étapes --- */
.step-navigation { display: flex; gap:1.5em; justify-content: space-between; margin-top: 30px; padding-top: 20px; border-top: 1px solid #eee; }
.step-nav-btn { padding: 12px 25px; font-size: 16px; font-weight: bold; border: 1px solid #ccc; background-color: #f8f8f8; color: #333; border-radius: 8px; cursor: pointer; transition: all 0.2s ease; }
.step-nav-btn:hover { background-color: #e9e9e9; border-color: #aaa; }
.step-nav-btn:disabled { background-color: #e0e0e0; cursor: not-allowed; }
#next-step-btn { background-color: #8e24aa; color: white; border-color: #8e24aa; }
#next-step-btn:hover { background-color: #6a1b9a; border-color: #6a1b9a; }
#generate-story-btn.final-btn { background: linear-gradient(45deg, #ff8a00, #e52e71); border: none; color: white; flex-grow: 1; }

/* --- Écran de Révision (Étape 3) --- */
.review-section { border: 1px solid #eee; border-radius: 8px; padding: 10px 20px; margin-bottom: 20px; background: #fafafa; }
.review-section .radio-option label {
    margin-bottom: 0;
    font-weight: normal;
    cursor: pointer;
    color: #3d3d3d;
}
.review-section.instruction-module { background-color: #ce93d8; border-color: #ffffff; }
.review-section h3 { margin-top: 10px; border-bottom: 1px solid #313b77; padding-bottom: 10px; color: #313b77}
.review-section pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word; /* Alias moderne de word-wrap */
    font-family: inherit;
    font-size: 0.95em;
    color: #333;
    max-width: 100%;     /* Empêche le débordement horizontal */
    overflow-x: hidden;  /* Cache toute barre de défilement horizontale */
    word-break: break-all; /* Force la césure pour les très longues chaînes */
}

/* --- Style de la Modale pour l'Assistant IA --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; transition: opacity 0.3s ease; }
.modal-overlay:not(.hidden) { opacity: 1; }
.modal-container { background: #fff; padding: 20px; border-radius: 12px; width: 95%; max-width: 800px; max-height: 90vh; display: flex; flex-direction: column; position: relative; transform: scale(0.95); transition: transform 0.3s ease; }
.modal-overlay:not(.hidden) .modal-container { transform: scale(1); }
.modal-content { overflow-y: auto; flex-grow: 1; }
.modal-close-btn { position: absolute; top: 10px; right: 15px; background: none; border: none; font-size: 28px; color: #999; cursor: pointer; line-height: 1; padding: 0; }
.modal-close-btn:hover { color: #333; }
.hidden { display: none !important; }

/* --- Styles pour le contenu du chatbot DANS la modale --- */
.use-description-btn { display: block; width: calc(100% - 20px); margin: 15px auto 10px; padding: 12px; font-size: 15px; font-weight: bold; background-color: #28a745; color: white; border: none; border-radius: 8px; cursor: pointer; transition: background-color 0.2s; }
.use-description-btn:hover { background-color: #218838; }

#previous-summary-section.hidden { display: none; }

/* --- Styles pour la Modale de Résultat --- */
#result-modal .modal-container {
    max-width: 90vw; /* Prendra jusqu'à 90% de la largeur de l'écran */
    width: 1200px;   /* Largeur maximale souhaitée sur grands écrans */
}

#result-modal h2 {
    margin-top: 0;
    padding-bottom: 15px;
    border-bottom: 2px solid #8e24aa;
}

.result-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap; /* Permet aux boutons de passer à la ligne si pas assez de place */
    justify-content: center;
    padding: 10px;
    margin-top: 10px; /* On remplace margin-bottom par margin-top */
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.action-btn-secondary, .action-btn-primary {
    padding: 5px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    font-size: 14px;
}

.action-btn-secondary {
    background-color: #f0f0f0;
    border-color: #ddd;
    color: #333;
}
.action-btn-secondary:hover {
    background-color: #e0e0e0;
}

.action-btn-primary {
    background-color: #8e24aa;
    color: white;
}
.action-btn-primary:hover {
    background-color: #6a1b9a;
}

.story-content-area {
    background-color: #fdfdfd;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 20px;
    min-height: 200px;
    max-height: 60vh;
    overflow-y: auto;
    white-space: pre-wrap; /* Conserve les sauts de ligne et espaces */
    line-height: 1.6;
    color: #333;
}

/* --- NOUVEAU: Styles pour la navigation par onglets --- */
.tabs-nav-container {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
}
.tab-btn {
    flex-grow: 1;
    padding: 15px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    background-color: #f9f9f9;
    border: none;
    border-bottom: 3px solid transparent;
    color: #666;
    transition: all 0.3s ease;
    border-top: 1px solid #e5e2e2;
}
.tab-btn:hover {
    background-color: #24273a;
    color: #fff;
}
.tab-btn.active {
    color: #fff;
    border-bottom-color: #8e24aa;
    background-color: #313b77;
}
.hidden {
    display: none;
}

/* --- NOUVEAU: Styles pour le Tableau de Bord --- */
#dashboard-view {
    background: #313b77;
    padding: 25px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
}
#dashboard-view h2 {
    margin-top: 0;
    padding-bottom: 15px;
    border-bottom: 2px solid #8e24aa;
    color: #ffffff;
}
.dashboard-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}
.action-btn-danger {
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    border: 1px solid #dc3545;
    background-color: #f8d7da;
    color: #721c24;
    transition: all 0.2s ease;
    font-size: 14px;
}
.action-btn-danger:hover {
    background-color: #dc3545;
    color: white;
}

/* --- GRILLE DU TABLEAU DE BORD --- */
#story-dashboard-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 50px;
    padding: 40px;
}

/* --- CONTENEUR AVEC PERSPECTIVE --- */
.book-container {
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 900px;
    cursor: pointer;
}

/* --- ANIMATION D'ENTRÉE --- */
@keyframes initAnimation {
    0% {
        transform: rotateY(0deg);
    }
    100% {
        transform: rotateY(-24deg);
    }
}

/* --- GRILLE DU TABLEAU DE BORD --- */
#story-dashboard-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 50px;
    padding: 40px;
}

/* --- ANIMATION D'ENTRÉE --- */
@keyframes initAnimation {
    0% {
        transform: rotateY(0deg);
    }
    100% {
        transform: rotateY(-24deg);
    }
}

/* --- LE LIVRE EN 3D --- */
.book {
    width: 200px;
    height: 300px;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateY(-24deg);
    transition: transform 1.5s ease;
    animation: 1s ease 0s 1 initAnimation;
}

/* Au survol : le livre se redresse */
.book-container:hover .book,
.book-container:focus .book {
    transform: rotateY(0deg);
}

/* --- LA COUVERTURE (image) --- */
.book > .book-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 300px;
    transform: translateZ(27.5px);
    background-color: #103b9d;
    border-radius: 0 2px 2px 0;
    box-shadow: 5px 5px 20px #666;
    object-fit: cover;
}

/* --- LA TRANCHE (::before) avec effet de pages --- */
.book::before {
    position: absolute;
    content: ' ';
    left: 0;
    top: 1px;
    width: 53px;
    height: 298px;
    transform: translateX(171.5px) rotateY(90deg);
    background: linear-gradient(90deg, 
        #fff 0%,
        #f9f9f9 5%,
        #fff 10%,
        #f9f9f9 15%,
        #fff 20%,
        #f9f9f9 25%,
        #fff 30%,
        #f9f9f9 35%,
        #fff 40%,
        #f9f9f9 45%,
        #fff 50%,
        #f9f9f9 55%,
        #fff 60%,
        #f9f9f9 65%,
        #fff 70%,
        #f9f9f9 75%,
        #fff 80%,
        #f9f9f9 85%,
        #fff 90%,
        #f9f9f9 95%,
        #fff 100%
    );
}

/* --- LE DOS DU LIVRE (::after) --- */
.book::after {
    position: absolute;
    top: 0;
    left: 0;
    content: ' ';
    width: 200px;
    height: 300px;
    transform: translateZ(-27.5px);
    background-color: #103b9d;
    border-radius: 0 2px 2px 0;
    box-shadow: -10px 0 50px 10px #2539b2
}

/* --- TITRE TOUJOURS VISIBLE --- */
.book-title-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0 2px 2px 0;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 50%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 15px;
    transform: translateZ(30px);
    pointer-events: none;
}

.story-card-title {
    color: white;
    font-size: 1.3em;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,1);
    line-height: 1.2;
    margin: 0;
}

/* --- OVERLAY POUR LES BOUTONS (VISIBLE AU SURVOL) --- */
.book-actions-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0 2px 2px 0;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.3) 50%, rgba(0,0,0,0) 70%);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 15px;
    padding-top: 15px;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    pointer-events: none;
    transform: translateZ(31px);
}

.book-container:hover .book-actions-overlay {
    opacity: 1;
}

/* --- BOUTONS D'ACTION --- */
.story-card-actions {
    display: flex;
    gap: 10px;
    pointer-events: auto;
    transform: translateY(10px);
    transition: transform 0.5s ease;
}

.book-container:hover .story-card-actions {
    transform: translateY(0);
}

.story-card-actions .action-btn-secondary,
.story-card-actions .action-btn-danger {
    flex: 1;
    font-size: 12px;
    padding: 5px 5px;
    background-color: rgba(20, 20, 20, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    backdrop-filter: blur(4px);
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.story-card-actions .action-btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.story-card-actions .action-btn-danger:hover {
    background-color: #dc3545;
}

/* --- MESSAGE TABLEAU VIDE --- */
.empty-dashboard-message {
    grid-column: 1 / -1;
    text-align: center;
    color: #666;
    font-size: 1.2em;
    padding: 40px;
}

/* On n'a plus besoin de ce bouton, car cliquer sur la carte ouvrira le livre */
.view-item-btn {
    display: none;
}

.empty-dashboard-message {
    grid-column: 1 / -1;
    text-align: center;
    color: #cccccc; /* Un peu plus clair sur fond sombre */
    background-color: rgba(0,0,0,0.2);
    padding: 40px;
    border-radius: 8px;
    font-style: italic;
}

#continue-from-viewed-btn {
    display: none;
}

/* Quand la classe .view-mode est ajoutée au conteneur... */
.modal-content.view-mode #save-to-dashboard-btn,
.modal-content.view-mode #continue-story-btn {
    display: none;
}

.modal-content.view-mode #continue-from-viewed-btn {
    display: inline-block;
}

.flipbook-viewport {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    min-height: 600px;
}

#flipbook {
    width: auto; /* Laissez la bibliothèque définir la largeur fixe */
    height: auto; /* Laissez la bibliothèque définir la hauteur fixe */
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3); /* Ombre réaliste autour du livre */
}

/* Amélioration des gradients de reliure (déjà présent, intensifiez) */
.st-page.st-page-left {
    background-image: linear-gradient(to right, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0) 15%); /* Plus prononcé */
}
.st-page.st-page-right {
    background-image: linear-gradient(to left, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0) 15%);
}

/* --- Structure de la Page du Livre (CORRIGÉ) --- */

/* La page devient un conteneur Flex vertical. */
.st-page {
    display: flex;
    flex-direction: column;
    background-color: #fdfaf4;
    background-image: url('images/ricepaper2.webp');
    background-repeat: repeat;
    color: #3d3d3d;
    font-family: 'Merriweather', serif;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.1);
}

.st-page .image-page {
    width: 100%;
    height: 100%;
    background-size: cover; /* L'image couvre toute la page */
    background-position: center center; /* L'image est centrée */
    background-repeat: no-repeat;
}

/* Le conteneur du texte grandit pour prendre toute la place disponible. */
#flipbook .page-wrapper {
    height: 95%;
    flex-grow: 1; /* Permet au contenu de prendre toute la hauteur disponible */
    min-height: 0;  /* Essentiel pour que l'overflow fonctionne dans un flex-item */
    overflow-y: auto; /* Active le défilement vertical si le contenu dépasse */
    
    padding: 30px 22px 10px 22px;
    box-sizing: border-box;
    width: 100%;
    font-family: CrimsonText, serif;
    font-size: 16px;
    line-height: 1.4;
    text-align: justify;

    /* ✅ AJOUT : Règles typographiques anti-orphelines */
    orphans: 3;  /* Minimum 3 lignes en bas de page */
    widows: 3;   /* Minimum 3 lignes en haut de nouvelle page */
    
    /* ✅ Empêche la coupure des mots en fin de ligne */
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: auto; /* Active la césure automatique en français */
    -webkit-hyphens: auto;
    -ms-hyphens: auto;
}

/* Le pied de page ne grandit pas et ne rétrécit pas. */
.page-footer {
    flex-shrink: 0; /* Empêche le pied de page de rétrécir */
    padding: 5px 20px 10px 20px;
    text-align: center;
    font-size: 12px;
    color: #888;
    font-style: italic;
    box-sizing: border-box; /* S'assure que le padding est inclus dans la hauteur */
}

/* Optionnel mais recommandé : Style plus discret pour la barre de défilement */
#flipbook .page-wrapper::-webkit-scrollbar {
  width: 8px;
}
#flipbook .page-wrapper::-webkit-scrollbar-track {
  background: transparent;
}
#flipbook .page-wrapper::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}
/* ✅ Empêcher les coupures de paragraphes */
#flipbook .page-wrapper p,
#flipbook .page-wrapper br + * {
    page-break-inside: avoid;
    break-inside: avoid;
}

/* ✅ Amélioration de la césure des mots */
#flipbook .page-wrapper {
    text-align: justify; /* Justifié pour meilleure répartition */
    text-justify: inter-word;
}

.lettrine {
    float: left; /* Positionne la lettre à gauche */
    font-size: 3.5em; /* Taille agrandie (ajustez selon vos besoins, ex. 3em, 4em) */
    line-height: 0.8; /* Réduit l'espacement vertical pour un effet compact */
    margin-right: 0.1em; /* Petit espace après la lettrine */
    margin-bottom: -0.1em; /* Ajuste pour aligner avec le texte */
    font-weight: bold; /* Optionnel : rend la lettre plus épaisse */
    color: #2c3e50; /* Optionnel : couleur personnalisée, ex. un bleu foncé */
}

.title-page {
    display: flex;
    flex-direction: column; 
    justify-content: center; 
    align-items: center;     
    height: 100%;
    padding: 20px;
    box-sizing: border-box;
    text-align: center;
}

/* --- NOUVEAU STYLE DE COUVERTURE 'CHARME' --- */

/* Conteneur principal de la page de couverture avec image */
.title-page.with-cover {
    background-size: cover;
    background-position: center center;
    display: flex;
    /* Aligne le bandeau en bas */
    justify-content: flex-end;
    align-items: center;
    flex-direction: column;
    /* Un peu d'espace en bas */
    padding-bottom: 5%;
}

/* Le bandeau blanc semi-transparent */
.title-page.with-cover .title-overlay {
    /* Fond blanc avec une légère transparence et un dégradé subtil */
    background: linear-gradient(to bottom, rgba(252, 252, 252, 0.6), rgba(248, 248, 248, 0.8));
    color: #4a3e3a; /* Couleur de texte brune foncée, plus douce que le noir */
    border-radius: 4px;
    text-align: center;
    width: 95%;
    max-width: 500px; /* Limite la largeur sur les grands écrans */
    padding: 1rem 1.1rem;
    
    /* Ombre portée douce pour donner du relief */
    box-shadow: 0 4px 25px rgba(0, 0, 0, 0.2);

    /* Retire le filtre de flou qui n'est plus nécessaire */
    backdrop-filter: none;
}

/* Le titre principal du livre */
.title-page.with-cover .book-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: clamp(1.8rem, 5vw, 2.8rem); /* Taille de police réactive */
    font-weight: 600; /* Semi-gras */
    line-height: 1.1;
    margin: 0 0 0.75rem 0;
    
    /* Retire l'ancienne ombre pour texte blanc */
    text-shadow: none; 
}

/* Le nom de l'auteur */
.title-page.with-cover .book-author {
    font-family: 'Cormorant Garamond', serif;
    font-size: clamp(1rem, 2.5vw, 1.2rem); /* Taille de police réactive */
    font-weight: 400; /* Poids normal */
    margin: 0;
    opacity: 0.9;
    
    /* Retire l'ancienne ombre */
    text-shadow: none;
    
    /* Ajoute un séparateur au-dessus de l'auteur, comme dans l'exemple */
    position: relative;
    padding-top: 0.1rem;
}

/* Le trait séparateur au-dessus de l'auteur */
.title-page.with-cover .book-author::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px; /* Largeur du trait */
    height: 1px; /* Épaisseur du trait */
    background-color: #4a3e3a;
    opacity: 0.4;
}

.book-title {
    font-family: 'Georgia', 'Times New Roman', serif; 
    font-size: 2.8rem;
    font-weight: bold;
    margin: 0 0 20px 0;
    line-height: 1.2;
    color: #333;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2); /* Ombre sur le texte pour profondeur */
}

.title-separator {
    width: 80px;
    height: 2px;
    background-color: #aaa;
    margin: 20px 0;
}

.book-author {
    font-family: 'Merriweather', serif; 
    font-size: 1.2rem;
    font-style: italic;
    color: #666;
    margin-top: 20px;
}

.end-page {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.end-page span {
    font-family: 'Dancing Script', cursive; 
    font-size: 4rem;
    color: #888;
}

#story-result-content {
    display: none;
}

#result-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background-color: #24273a;
    display: flex;
    flex-direction: column;
    padding: 15px;
    box-sizing: border-box;
    overflow-y: auto;
}

#result-view.is-loading .result-toolbar {
    display: none !important;
}

#result-view.hidden {
    display: none;
}

.nav-button-wrapper {
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 15px;
    width: 100%;
    padding: 3px 10px 10px 10px;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

/* --- MODIFIÉ : Style par défaut des boutons (pour DESKTOP) --- */
.nav-button {
    /* On annule tout positionnement absolu */
    position: static;
    transform: none;
    
    /* Style unifié Mobile & Desktop */
    min-width: 180px;
    width: auto;
    height: auto;
    flex-grow: 0; /* Les boutons se partagent la largeur */
    flex-basis: 0;

    border-radius: 6px;
    padding: 5px 10px; /* Moins de padding pour être plus petits */
    font-size: 0.9em;  /* Police plus petite */
    opacity: 1;
    background: #4a4e69;
    border: 1px solid #9a8c98;
    color: #fff;
    cursor: pointer;
    transition: background-color 0.2s;
}

.nav-button:hover {
    background: #6b7091;
}

/* On retire les pseudo-éléments qui affichaient les chevrons seuls */
.nav-button.prev-button::before,
.nav-button.next-button::before {
    content: none;
}

.nav-button:disabled {
    opacity: 0.1;
    cursor: default;
}

.hidden-nav-button {
    display: none !important;
}

#page-counter {
    font-size: 0.9em;
    color: #c7c8d1;
    font-weight: bold;
    white-space: nowrap; /* Empêche le texte de passer à la ligne */
}

/* Barre d'outils en haut */
#result-view .result-toolbar {
    flex-shrink: 0; /* Empêche la barre de rétrécir */
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 5px 0 10px 0;
    order: 3;
}

#result-view .nav-button-wrapper {
    order: 1;
    flex-shrink: 0; /* Empêche la barre de rétrécir */
}

/* 2. Le livre reste au MILIEU et prend toute la place restante */
#result-view #flipbook-container {
    order: 2;
    flex-grow: 1; /* Prend l'espace disponible */
    height: 0; 
    overflow: hidden;
    position: relative;
}

#flipbook-container.flipbook-viewport {
    flex-grow: 1; 
    min-height: 0; 
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#result-view #result-loading-indicator {
    display: flex; /* Assure qu'il est visible */
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex-grow: 1; /* Il prend toute la place */
    overflow-y: auto;
    padding-top: 6vh;
    box-sizing: border-box;
    color: #ffffff;
}

#result-view.is-loading .result-toolbar,
#result-view.is-loading .result-summary,
#result-view.is-loading #flipbook-container {
    visibility: hidden;
}

p#loading-message {
    text-align: center;
}

#result-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(36, 39, 58, 0.85); /* Fond semi-transparent */
    z-index: 20; /* Pour s'afficher au-dessus du livre */
    
    display: flex;
    justify-content: center;
    align-items: center;
    
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none; /* N'est pas cliquable quand il est caché */
}

#result-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: all; /* Devient "présent" quand il est visible */
}

#result-overlay .overlay-content {
    text-align: center;
    color: #ffffff;
    padding: 20px;
}

#result-overlay p {
    margin-top: 20px;
    font-size: 1.1em;
    max-width: 400px;
}

#result-loading-indicator {
    padding: 20px;
    overflow-y: auto; /* Permet de scroller si le formulaire est trop haut pour l'écran */
}

.newsletter-form-container {
    width: 100%;
    max-width: 540px; 
    margin-top: 10px;
    padding-top: 30px;
    border-top: 1px solid rgba(255, 255, 255, 0.2); 
}

.newsletter-intro {
    font-size: 1.1em;
    color: #e0e0e0;
    text-align: center;
    margin-bottom: 15px;
    line-height: 1.5;
}

/* Conteneur avec position relative pour positionner la croix */
.premium-upgrade-banner,
.llm-premium-notice,
.premium-presets-info {
    position: relative;
    padding-right: 40px; /* Espace pour la croix */
}

/* Style de la croix de fermeture */
.close-banner-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: #999;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    padding: 0;
    z-index: 10;
}

.close-banner-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #FF424D;
    transform: rotate(90deg);
}

.close-banner-btn:active {
    transform: rotate(90deg) scale(0.95);
}

/* Animation de fermeture */
.banner-closing {
    animation: slideOutUp 0.3s ease-out forwards;
}

@keyframes slideOutUp {
    0% {
        opacity: 1;
        transform: translateY(0);
        max-height: 1000px;
    }
    100% {
        opacity: 0;
        transform: translateY(-20px);
        max-height: 0;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }
}

/* Bannière fermée (cachée) */
.banner-hidden {
    display: none !important;
}
/* --- Styles pour la bannière Premium pendant le chargement --- */

/* Conteneur principal de la bannière */
#loading-premium-promo-banner {
    animation: fadeIn 0.5s ease-in-out;
    text-align: center;
}

/* Badge "Offre de lancement" */
#loading-premium-promo-banner .early-bird-badge {
    background: #FF424D;
    color: white;
    display: inline-block;
    padding: 5px 15px;
    border-radius: 20px;
    font-weight: bold;
    margin-bottom: 15px;
}

/* Titre principal */
#loading-premium-promo-banner h3 {
    margin: 10px 0;
    color: #333;
}

/* Liste des avantages */
#loading-premium-promo-banner .premium-benefits ul {
    list-style: none;
    padding: 0;
    text-align: left; /* Pour aligner les puces */
    display: inline-block; /* Pour centrer le bloc de liste */
    margin: 20px 0;
}

#loading-premium-promo-banner .premium-benefits li {
    margin-bottom: 10px;
}

/* Bouton d'action principal */
#loading-premium-promo-banner .premium-subscribe-button {
    background: #FF424D;
    color: white;
    padding: 15px 40px;
    text-decoration: none;
    border-radius: 5px;
    display: inline-block;
    font-weight: bold;
    font-size: 18px;
    transition: transform 0.2s, box-shadow 0.2s;
}

#loading-premium-promo-banner .premium-subscribe-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(255, 66, 77, 0.4);
}

/* Texte secondaire */
#loading-premium-promo-banner p {
    margin-top: 15px;
    font-size: 14px;
    color: #666;
}

/* Lien pour connecter Patreon */
#loading-premium-promo-banner .connect-patreon-button {
    color: #FF424D;
    text-decoration: underline;
}

/* Conteneur de la promo premium pendant le chargement */
#loading-premium-promo {
    width: 100%;
    max-width: 600px;
    margin: 30px auto 0 auto;
    animation: fadeIn 0.5s ease-in-out;
}

/* On réutilise le style de la bannière, mais on ajuste les couleurs pour le fond sombre */
#loading-premium-promo .premium-upgrade-banner {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.15) 100%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #f0f0f0;
    padding: 20px;
}

#loading-premium-promo .banner-text {
    color: #e0e0e0;
}

#loading-premium-promo .banner-text strong {
    color: #ffffff;
}

#loading-premium-promo .btn-recover {
    background-color: #8e24aa;
}
#loading-premium-promo .btn-recover:hover {
    background-color: #6a1b9a;
}

/* Petit texte sous la bannière de chargement */
.premium-notice {
    text-align: center;
    font-size: 13px;
    color: #9a9a9a;
    margin-top: 10px;
    font-style: italic;
}

/* Texte d'intro pour le sondage */
.survey-intro {
    text-align: center;
    color: #c0c0c0;
    margin-bottom: 15px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

/* --- AJOUTS RESPONSIVES POUR LA NOUVELLE VUE --- */
@media (max-width: 768px) {

    .mode-selection-buttons {
        flex-direction: column; 
        gap: 15px;
    }
    .mode-select-btn {
        width: 100%;
    }
    .quick-options-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    #result-view {
        padding: 10px;
        min-height: 90vh; /* NOUVEAU : Assure une hauteur minimale */
        display: flex;
        flex-direction: column;
    }

    #flipbook .page-wrapper {
        padding: 20px 15px; /* Un peu moins de padding horizontal */
        font-size: 16px;
        position: relative; /* Aide Webkit à calculer la hauteur */
        flex-grow: 1; /* Doit prendre l'espace restant */
        min-height: 0; /* Permet au conteneur de rétrécir */
        overflow-y: auto; /* Active le défilement vertical */
        -webkit-overflow-scrolling: touch; /* Active le défilement fluide sur iOS */
    }

    /* La modale reste immersive sur mobile */
    #result-modal .modal-container {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        padding: 10px;
        box-sizing: border-box;
        display: flex; /* NOUVEAU : Utilise flex pour gérer la hauteur */
        flex-direction: column; /* NOUVEAU : Empile les éléments verticalement */
    }

    #result-modal .modal-content {
        padding: 5px;
        flex-grow: 1; /* NOUVEAU : Prend tout l'espace restant */
        display: flex; /* NOUVEAU : Flex pour le flipbook */
        flex-direction: column; /* NOUVEAU : Empile verticalement */
    }

    /* On réduit les marges internes des pages sur les petits écrans */
    #flipbook .page-wrapper {
        padding: 20px;
        font-size: 16px;
        line-height: 1.6;
        flex-grow: 1;
        height: 94%;
    }
    
    .book-title {
        font-size: 1.8rem; 
    }

    .book-author {
        font-size: 1rem;
    }

    /* On s'assure que la barre d'outils s'adapte bien */
    .result-toolbar {
        justify-content: center;
        gap: 8px;
    }

    .result-toolbar .action-btn-primary,
    .result-toolbar .action-btn-secondary {
        padding: 10px 12px;
        font-size: 13px;
    }
    #result-view .result-toolbar {
        gap: 5px;
        margin-bottom: 10px;
    }

    #result-view .result-toolbar .action-btn-primary,
    #result-view .result-toolbar .action-btn-secondary {
        padding: 4px 8px;
        font-size: 0.8em;
        flex-grow: 1;
        flex-basis: 0;
    }   

    #flipbook-container {
        flex-grow: 1; /* Le livre prend la place disponible */
        /*min-height: 0; /* Important pour le flexbox shrinking */
        max-height: 70vh; /* Limite la hauteur du conteneur */
        min-height: 500px; /* Hauteur minimale raisonnable */
    }

    #flipbook {
        max-height: 650px !important;
    }

    #page-counter {
        display: none; /* Masque le compteur sur les écrans de moins de 768px */
    }

    .nav-button {
        min-width: 150px; /* On peut réduire la largeur minimale sur mobile */
        padding: 8px 10px;
    }
}

@media (max-width: 600px) {
    .story-creator-wizard,
    #review-summary-content,
    .story-stepper,
    .tabs-nav-container {
        max-width: 100%;
        width: 100%;
        padding: 0;
        box-sizing: border-box;
    }

    .review-section {
        padding: 8px;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }

    .step, .tab-btn {
        flex-grow: 0;
        flex-basis: auto;
        font-size: 1rem;
        padding: 8px 12px;
    }

    .preset-input-group {
        flex-wrap: wrap;
        max-width: 100%;
    }

    #result-modal .modal-container {
        max-width: 100%;
        width: 95%;
    }

    #review-summary-content {
        padding: 15px;
    }

    label { margin-left: -3px; }
    .step-navigation { margin-top: 5px; } 
}

@media (max-width: 480px) {
    /* Ajustements fins pour les très petits écrans */
    #flipbook .page-wrapper {
        padding: 20px 20px 0 20px;
        font-size: 15px;
    }
}

/* Pour les très grands écrans mobiles (iPhone Pro Max, etc.) */
@media (max-width: 768px) and (min-height: 800px) {
    #flipbook-container {
        max-height: 75vh;
    }
    
    #flipbook {
        max-height: 600px !important;
    }
}

/* iPhone XR et tailles similaires */
@media (max-width: 414px) and (min-height: 800px) {
    #flipbook-container {
        max-height: 70vh;
    }
}

/* ======================================= */
/* == STYLES POUR LES HISTOIRES PUBLIQUES == */
/* ======================================= */

/* --- Grille des histoires --- */
.flirtyai-public-stories .stories-grid {
    display: grid;
    /* ✅ 1. Utilise la variable CSS définie en PHP pour le desktop */
    grid-template-columns: repeat(var(--grid-columns, 3), 1fr);
    gap: 50px 30px; /* Augmenter l'écart pour un meilleur espacement */
    padding: 20px 0;
}

/* ✅ 1. Gestion du responsive pour la grille */
@media (max-width: 1024px) {
    .flirtyai-public-stories .stories-grid {
        /* minmax est parfait pour le responsive : 
           les colonnes font au minimum 220px, et se partagent l'espace restant. */
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
}

@media (max-width: 768px) {
    /* Sur mobile, on passe à 2 colonnes */
    .flirtyai-public-stories .stories-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 40px 20px;
    }
}

@media (max-width: 480px) {
    .flirtyai-public-stories .stories-grid {
         grid-template-columns: 1fr;
    }
}

.book-meta {
    padding-top: 0.5rem;
    font-size: 0.85rem;
    color: #666;
}

/* --- Modale de lecture --- */
.story-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.story-modal.active {
    visibility: visible;
    opacity: 1;
}

.story-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.story-modal-content {
    position: relative;
    width: 95vw;
    height: 95vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.story-modal.active .story-modal-content {
    transform: scale(1);
}

.story-modal-close {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s;
    line-height: 40px;
    text-align: center;
}

.story-modal-close:hover {
    background: rgba(255,0,0,0.8);
}

/* --- Conteneur du flipbook dans la modale --- */
#story-reader-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative; /* Pour positionner la navigation */
}

/* Le viewport créé par le JS */
#story-reader-container .flipbook-viewport {
    width: 100%;
    height: calc(100% - 60px); /* Laisse de la place pour la navigation en dessous */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Les boutons de navigation */
#story-reader-container .nav-button-wrapper {
    margin-top: 15px;
    color: white;
}

/* --- Le livre 3D (pour le shortcode public) --- */
.flirtyai-public-stories .book {
    width: 200px;
    height: 300px;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateY(-24deg);
    transition: transform 1.5s ease;
}

.flirtyai-public-stories .book-container:hover .book {
    transform: rotateY(0deg);
}

.flirtyai-public-stories .book > .book-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 300px;
    transform: translateZ(27.5px);
    background-color: #eee; /* Couleur de fond si l'image ne charge pas */
    border-radius: 0 2px 2px 0;
    /* ✅ 2. OMBRE AMÉLIORÉE : Plus douce, noire et réaliste */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    object-fit: cover;
}

.flirtyai-public-stories .book::before {
    position: absolute;
    content: ' ';
    left: 0;
    top: 1px;
    width: 53px;
    height: 298px;
    transform: translateX(171.5px) rotateY(90deg);
    background: linear-gradient(90deg, 
        #fff 0%, #f9f9f9 5%, #fff 10%, #f9f9f9 15%, #fff 20%, #f9f9f9 25%,
        #fff 30%, #f9f9f9 35%, #fff 40%, #f9f9f9 45%, #fff 50%, #f9f9f9 55%,
        #fff 60%, #f9f9f9 65%, #fff 70%, #f9f9f9 75%, #fff 80%, #f9f9f9 85%,
        #fff 90%, #f9f9f9 95%, #fff 100%
    );
}

.flirtyai-public-stories .book::after {
    position: absolute;
    top: 0;
    left: 0;
    content: ' ';
    width: 200px;
    height: 300px;
    transform: translateZ(-27.5px);
    background-color: #ccc; /* Couleur du dos du livre */
    border-radius: 0 2px 2px 0;
    /* ✅ 2. OMBRE AMÉLIORÉE SUR LE DOS (plus subtile) */
    box-shadow: -5px 0 20px 5px rgba(0, 0, 0, 0.2);
}

/* --- Titre sur le livre --- */
.flirtyai-public-stories .book-title-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0 2px 2px 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 60%);
    display: flex;
    align-items: flex-end; /* Aligne le titre en bas */
    padding: 20px;
    box-sizing: border-box;
    transform: translateZ(28px); /* Légèrement devant la couverture */
    pointer-events: none; /* Pour que le clic passe au conteneur */
}

.flirtyai-public-stories .book-title-overlay h3 {
    color: white;
    font-size: 1.4rem;
    font-weight: bold;
    line-height: 1.2;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    margin: 0;
}

/* --- Conteneur général de la carte (livre + méta) --- */
.flirtyai-public-stories .book-container {
    display: flex;
    flex-direction: column; /* Pour que le meta soit sous le livre */
    align-items: center;
    justify-content: center;
    perspective: 900px;
    cursor: pointer;
    transition: transform 0.2s ease-out;
}

.flirtyai-public-stories .book-container:hover {
    transform: scale(1.05); /* Effet de zoom au survol */
}

/* --- Métadonnées sous le livre --- */
.flirtyai-public-stories .book-meta {
    padding-top: 15px;
    font-size: 0.9rem;
    color: #555;
    text-align: center;
}