/* ==========================================================================
   MIRIADE Wild — atelier (page Créer) : formulaire en étapes, barre de
   progression collante, barre d'outils unique, verrouillage pendant la
   génération. Chargé après styles.css et book3d.css.
   ========================================================================== */

/* ---------- accueil compact une fois connecté·e --------------------------- */
body.is-logged .hero { grid-template-columns: 1fr; gap: 0; margin-bottom: clamp(16px, 2.5vw, 26px); }
body.is-logged .hero-art, body.is-logged .hero-stats, body.is-logged .hero-eyebrow { display: none; }
body.is-logged .hero h1 { font-size: clamp(1.5rem, 2.6vw, 2rem); margin-bottom: 6px; }
body.is-logged .hero p { font-size: .95rem; max-width: 70ch; }

/* ---------- formulaire en étapes ------------------------------------------ */
.studio-head { padding-bottom: 6px; }
.form-section { padding-top: 6px; }
.step { position: relative; padding: 18px 0 22px; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; padding-top: 8px; }
.step-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.step-num {
    display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
    background: var(--grad-primary); color: #fff; font-weight: 800; font-size: .85rem; align-self: center;
    box-shadow: 0 6px 16px -6px rgba(79, 70, 229, .7);
}
.step-head h3 { font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; }
.step-head p { color: var(--ink-3); font-size: .88rem; flex-basis: 100%; margin: -4px 0 0 40px; }
.step .selectors-section { margin-top: 0; padding-top: 0; border-top: 0; }
.step .form-grid { align-items: start; }

/* dictée : langue dans un petit menu */
.stt-pop { position: relative; }
.stt-pop > summary {
    list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
    font-size: .78rem; color: var(--ink-3); padding: 5px 10px; border-radius: var(--r-pill); border: 1px solid transparent;
}
.stt-pop > summary::-webkit-details-marker { display: none; }
.stt-pop > summary:hover, .stt-pop[open] > summary { border-color: var(--line-2); color: var(--ink); background: var(--surface); }
.stt-pop .form-group select.stt-lang-select, .stt-pop select.stt-lang-select {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 220px; max-width: none;
    background-color: var(--surface); border: 1px solid var(--line-2); color: var(--ink); font-size: .85rem; padding: 9px 30px 9px 12px;
    border-radius: var(--r); box-shadow: var(--shadow-3);
}

/* grille des styles graphiques (le <select> reste synchronisé, masqué) */
.mwv2-hidden { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important; opacity: 0; pointer-events: none; }
.mwv2-styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.stylechip {
    display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 12px; text-align: left;
    border: 1.5px solid var(--line-2); border-radius: var(--r); background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: .86rem;
    transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast); cursor: pointer; line-height: 1.2;
}
.stylechip .ic { font-size: 1.15rem; flex: 0 0 auto; }
.stylechip:hover { border-color: var(--ink-3); transform: translateY(-1px); }
.stylechip[aria-checked="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-ink); box-shadow: var(--ring); }
.stylechip:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* nombre de pages : pastilles */
.mwv2-pages { display: flex; flex-wrap: wrap; gap: 6px; }
.pagechip {
    min-width: 46px; padding: 9px 12px; border-radius: var(--r); border: 1.5px solid var(--line-2); background: var(--surface-2); color: var(--ink);
    font-weight: 700; font-size: .95rem; cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.pagechip small { display: block; font-size: .66rem; font-weight: 600; color: var(--ink-3); }
.pagechip:hover:not(:disabled) { border-color: var(--ink-3); transform: translateY(-1px); }
.pagechip[aria-checked="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-ink); box-shadow: var(--ring); }
.pagechip[aria-checked="true"] small { color: var(--primary-ink); }
.pagechip:disabled { opacity: .4; cursor: not-allowed; }

/* étape 3 : options repliables */
.mwv2-options { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface-2); }
.mwv2-options > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.mwv2-options > summary::-webkit-details-marker { display: none; }
.mwv2-options > summary .t { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; }
.mwv2-options > summary .mwv2-sum { flex: 1; color: var(--ink-3); font-size: .86rem; }
.mwv2-options > summary .chev { width: 10px; height: 10px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); transition: transform var(--t-fast); margin-right: 6px; }
.mwv2-options[open] > summary .chev { transform: rotate(-135deg); }
.mwv2-options > .mwv2-opts { padding: 4px 16px 18px; border-top: 1px solid var(--line); margin: 0; }
.mwv2-block { padding: 14px 0; border-bottom: 1px dashed var(--line-2); }
.mwv2-block:last-of-type { border-bottom: 0; }
.mwv2-block > .mwv2-block-title { font-weight: 700; font-size: .92rem; margin-bottom: 4px; }
.mwv2-block > .mwv2-block-title small { font-weight: 400; color: var(--ink-3); }
.mwv2-block > .mwv2-block-help { color: var(--ink-3); font-size: .82rem; margin-bottom: 10px; }
.mwv2-opts label.chk { align-items: flex-start; }
.mwv2-opts label.chk span small { display: block; color: var(--ink-3); }
.mwv2-refs { border: 0; padding: 0; }
.mwv2-refs > div:first-child, .mwv2-block .mwv2-refs > small { display: none !important; }

/* actions : barre collante en bas du formulaire, avec le coût total */
.form-actions { position: sticky; bottom: 0; z-index: 5; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); margin-top: 8px; padding-bottom: 14px; border-radius: 0 0 var(--r-xl) var(--r-xl); }
.form-actions .mwv2-total { font-size: .9rem; color: var(--ink-2); white-space: nowrap; }
.form-actions .mwv2-total b { color: var(--ink); font-size: 1.05rem; }

/* ---------- génération : barre de progression collante -------------------- */
.loading.active { position: sticky; top: calc(var(--header-h) + 8px); z-index: 60; padding: 12px 16px 14px; text-align: left; margin-bottom: 18px; }
.loading-book { display: none; }
.loading-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 16px 20px; align-items: center; }
.generation-steps { margin: 0; gap: 6px; justify-content: flex-start; }
.gen-step { padding: 6px 11px; font-size: .8rem; }
.gen-step.active { animation: none; }
.step-arrow { font-size: .8rem; }
.loading-main { min-width: 0; }
#loading-text { margin: 0 0 6px; font-size: .9rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 0; }
.progress-bar { margin: 0; max-width: none; height: 8px; }
.loading-meta { flex-direction: column; align-items: flex-end; gap: 2px; font-size: .78rem; white-space: nowrap; }
.loading-actions { margin: 0; }
@media (max-width: 900px) {
    .loading-row { grid-template-columns: minmax(0, 1fr) auto; }
    .generation-steps { grid-column: 1 / -1; }
    .loading-meta { display: none; }
}

/* pendant la génération : aucun contrôle de page n'est actif */
body.is-generating .image-controls, body.is-generating .btn-edit-title, body.is-generating .btn-edit-text,
body.is-generating .btn-retry-image, body.is-generating .version-indicator, body.is-generating .mwv2-bar { display: none !important; }
body.is-generating .book-page:hover { transform: none; box-shadow: var(--shadow-2); }
body.is-generating .page-image:hover img { transform: none; }
body.is-generating .story-controls { display: none; }
body.is-generating .book-page .page-text::after {
    content: 'Génération en cours…'; align-self: flex-start; margin-top: 4px;
    font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--primary-ink);
    background: var(--primary-soft); padding: 4px 10px; border-radius: var(--r-pill);
}
body.is-generating .book-page[data-done="1"] .page-text::after { content: 'Page prête'; color: var(--success); background: var(--success-soft); }

/* ---------- titre et couverture (sous le titre de l'histoire) -------------- */
.mwv2-titlebar { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }
.mwv2-covthumb { width: 54px; aspect-ratio: 2 / 3; padding: 0; border: 0; border-radius: 3px 7px 7px 3px; overflow: hidden; cursor: pointer;
    background: var(--surface-2); box-shadow: 0 8px 18px -8px rgba(20, 16, 50, .6), 0 1px 3px rgba(20, 16, 50, .25); transition: transform var(--t-fast); }
.mwv2-covthumb:hover { transform: translateY(-2px) rotate(-2deg); }
.mwv2-covthumb:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.mwv2-covthumb canvas { width: 100%; height: 100%; display: block; }
body.is-generating .mwv2-titlebar { display: none; }

/* ---------- barre d'outils unique de l'histoire --------------------------- */
.story-controls .btn-primary { padding: 8px 14px; }
.tb-menu { position: relative; }
.tb-menu-list {
    position: absolute; left: 0; top: calc(100% + 6px); z-index: 80; min-width: 260px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-4); padding: 6px;
}
.tb-menu-list[hidden] { display: none; }
.tb-menu-list button {
    display: block; width: 100%; text-align: left; border: 0; background: transparent; color: var(--ink);
    padding: 10px 12px; border-radius: var(--r-sm); font-size: .9rem; font-weight: 500; cursor: pointer;
}
.tb-menu-list button:hover, .tb-menu-list button:focus-visible { background: var(--surface-3); outline: none; }
.tb-menu-list button small { display: block; color: var(--ink-3); font-size: .76rem; }
.toolbar-group.right .btn-ghost { border: 1px solid var(--line-2); }
.mwv2-bar { display: none; }

@media (max-width: 760px) {
    .step-head p { margin-left: 0; }
    .mwv2-styles { grid-template-columns: repeat(2, 1fr); }
    .form-actions .mwv2-total { display: none; }
    .story-controls .btn-primary .label { display: inline; }
}
