/* ==========================================================================
   MIRIADE Wild — styles du livre 3D (lecteur) et des outils v2 de l'atelier
   ========================================================================== */
html.b3d-open, html.b3d-open body { overflow: hidden; }

/* ------------------------------------------------------------ lecteur */
.b3d-overlay {
    --b3d-ink: #f3f2ff; --b3d-dim: rgba(232, 230, 255, .66); --b3d-line: rgba(255, 255, 255, .13);
    --b3d-glass: rgba(255, 255, 255, .07); --b3d-glass-2: rgba(255, 255, 255, .14); --b3d-accent: #fbbf24; --b3d-focus: #a5b4fc;
    position: fixed; inset: 0; z-index: 3000; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; grid-template-columns: minmax(0, 1fr);
    color: var(--b3d-ink); font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; outline: none;
    opacity: 0; transition: opacity .25s ease;
}
.b3d-overlay.is-in { opacity: 1; }
.b3d-overlay.is-out { opacity: 0; pointer-events: none; }
.b3d-bg {
    position: absolute; inset: 0; z-index: 0; pointer-events: none;
    background:
        radial-gradient(46% 42% at 50% 52%, rgba(196, 186, 255, .30) 0%, rgba(150, 132, 255, .12) 55%, rgba(124, 92, 255, 0) 100%),
        radial-gradient(120% 90% at 50% 45%, #2b2768 0%, #18164a 46%, #0a0920 100%);
}
.b3d-overlay .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.b3d-overlay svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.b3d-overlay svg circle { fill: currentColor; stroke: none; }

/* barre du haut */
.b3d-top { position: relative; z-index: 4; display: flex; align-items: center; gap: 12px; padding: 12px 16px 6px; transition: opacity .3s; }
.b3d-heading { flex: 1 1 auto; min-width: 0; }
.b3d-title { margin: 0; font-family: Fraunces, Georgia, serif; font-weight: 600; font-size: clamp(1.02rem, 1.6vw, 1.28rem); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b3d-sub { margin: 2px 0 0; font-size: .8rem; color: var(--b3d-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b3d-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.b3d-primary { display: contents; }
.b3d-ibtn {
    appearance: none; display: inline-grid; place-items: center; width: 42px; height: 42px; padding: 0; border-radius: 999px;
    border: 1px solid var(--b3d-line); background: var(--b3d-glass); color: inherit; font: inherit; font-weight: 700; cursor: pointer;
    transition: background .15s, border-color .15s, transform .15s;
}
.b3d-ibtn.sm { width: 36px; height: 36px; font-size: .86rem; }
.b3d-ibtn:hover:not(:disabled) { background: var(--b3d-glass-2); border-color: rgba(255, 255, 255, .26); }
.b3d-ibtn:active:not(:disabled) { transform: scale(.94); }
.b3d-ibtn[aria-pressed="true"], .b3d-ibtn[aria-expanded="true"] { background: rgba(251, 191, 36, .2); border-color: rgba(251, 191, 36, .7); color: #fde68a; }
.b3d-ibtn:disabled { opacity: .35; cursor: default; }
.b3d-ibtn[hidden] { display: none; }
.b3d-pbtn {
    appearance: none; display: inline-flex; align-items: center; gap: 6px; height: 42px; padding: 0 18px; border-radius: 999px; border: 0; cursor: pointer;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); color: #fff; font: inherit; font-weight: 600; font-size: .92rem;
    box-shadow: 0 6px 20px -6px rgba(124, 58, 237, .8); transition: filter .15s, transform .15s;
}
.b3d-pbtn:hover { filter: brightness(1.1); }
.b3d-pbtn:active { transform: scale(.96); }
.b3d-pbtn[aria-pressed="true"] { background: linear-gradient(135deg, #f59e0b 0%, #f43f5e 100%); }
.b3d-overlay :focus-visible { outline: 3px solid var(--b3d-focus); outline-offset: 2px; }

/* scène */
.b3d-stage { position: relative; z-index: 1; min-height: 0; }
.b3d-canvas {
    position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; cursor: default;
    opacity: 0; transform: translateY(14px) scale(.97); transition: opacity .45s ease, transform .7s cubic-bezier(.2, .8, .2, 1);
}
.b3d-canvas.is-ready { opacity: 1; transform: none; }
.b3d-text-on .b3d-canvas, .b3d-text-on .b3d-side { visibility: hidden; }
.b3d-side {
    position: absolute; top: 50%; z-index: 3; width: 50px; height: 50px; margin-top: -25px; border-radius: 999px; padding: 0;
    display: grid; place-items: center; border: 1px solid var(--b3d-line); background: rgba(10, 9, 30, .35); color: #fff; cursor: pointer;
    opacity: .55; transition: opacity .2s, background .2s;
}
.b3d-side svg { width: 24px; height: 24px; }
.b3d-side-l { left: 14px; } .b3d-side-r { right: 14px; }
.b3d-side:hover:not(:disabled), .b3d-side:focus-visible { opacity: 1; background: rgba(79, 70, 229, .55); }
.b3d-side:disabled { opacity: 0; pointer-events: none; }
.b3d-touch .b3d-side { display: none; }
.b3d-loading { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; z-index: 5; font-size: .95rem; color: var(--b3d-dim); }
.b3d-spin { width: 36px; height: 36px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .15); border-top-color: var(--b3d-accent); animation: b3d-spin .9s linear infinite; }
@keyframes b3d-spin { to { transform: rotate(360deg); } }
.b3d-hint {
    position: absolute; left: 50%; bottom: 10px; z-index: 3; transform: translate(-50%, 8px); max-width: min(92vw, 560px);
    background: rgba(10, 9, 30, .78); border: 1px solid var(--b3d-line); border-radius: 999px; padding: 9px 18px; font-size: .86rem; text-align: center;
    opacity: 0; transition: opacity .4s, transform .4s; pointer-events: none;
}
.b3d-hint.on { opacity: 1; transform: translate(-50%, 0); }
.b3d-blank { position: absolute; inset: 0; background: #000; z-index: 20; }

/* sous-titre de narration */
.b3d-caption { position: relative; z-index: 4; margin: 0 auto 6px; max-width: min(920px, 94vw); padding: 0 12px; }
.b3d-caption[hidden] { display: none; }
.b3d-caption-text {
    background: rgba(12, 11, 34, .86); border: 1px solid var(--b3d-line); border-radius: 16px; padding: 12px 18px; text-align: center;
    font-family: Literata, Fraunces, Georgia, serif; font-size: clamp(1.02rem, 1.9vw, 1.3rem); line-height: 1.55; box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

.b3d-overlay mark.b3d-mark { background: #fbbf24; color: #17152e; border-radius: 5px; padding: 0 .12em; box-shadow: 0 0 0 2px rgba(251, 191, 36, .35); }
.b3d-contrast mark.b3d-mark { background: #ffd400; color: #000; box-shadow: none; }

/* barre du bas : pastilles de pages */
.b3d-bottom { position: relative; z-index: 4; display: flex; align-items: center; justify-content: center; gap: 16px; padding: 6px 16px 16px; transition: opacity .3s; }
.b3d-pager { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; overflow: hidden; }
.b3d-dot { appearance: none; border: 0; padding: 0; width: 8px; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, .28); cursor: pointer; transition: background .2s, width .25s; }
.b3d-dot.is-story { width: 18px; }
.b3d-dot:hover { background: rgba(255, 255, 255, .6); }
.b3d-dot.on { background: var(--b3d-accent); width: 30px; }
.b3d-count { min-width: 128px; font-size: .86rem; font-weight: 600; color: var(--b3d-dim); font-variant-numeric: tabular-nums; }

/* menus flottants */
.b3d-pop {
    position: absolute; z-index: 10; width: min(340px, calc(100vw - 24px)); max-height: calc(100vh - 90px); overflow: auto;
    background: #1c1a45; border: 1px solid rgba(255, 255, 255, .16); border-radius: 18px; padding: 8px; box-shadow: 0 24px 60px -12px rgba(0, 0, 0, .7);
}
.b3d-pop[hidden] { display: none; }
.b3d-mi { display: block; width: 100%; text-align: left; appearance: none; border: 0; background: transparent; color: inherit; font: inherit; padding: 10px 12px; border-radius: 12px; cursor: pointer; }
.b3d-mi:hover, .b3d-mi:focus-visible { background: rgba(255, 255, 255, .08); }
.b3d-mi-l { display: block; font-weight: 600; font-size: .94rem; }
.b3d-mi small { display: block; margin-top: 2px; color: var(--b3d-dim); font-size: .78rem; line-height: 1.35; }
.b3d-mi[aria-pressed="true"] .b3d-mi-l { color: #fde68a; }
.b3d-mi-help { margin: 6px 4px 2px; padding: 10px 8px 4px; border-top: 1px solid var(--b3d-line); font-size: .76rem; line-height: 1.5; color: var(--b3d-dim); }
.b3d-mi-help b { color: var(--b3d-ink); font-weight: 600; margin-right: 4px; }
.b3d-panel { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.b3d-panel h3 { margin: 0 0 2px; font-family: Fraunces, Georgia, serif; font-weight: 600; font-size: 1.05rem; }
.b3d-sw { position: relative; display: block; padding-left: 52px; min-height: 26px; font-size: .92rem; line-height: 1.35; cursor: pointer; }
.b3d-sw input { position: absolute; opacity: 0; left: 0; top: 0; width: 40px; height: 24px; margin: 0; cursor: pointer; }
.b3d-sw span { position: absolute; left: 0; top: 1px; width: 40px; height: 24px; border-radius: 999px; background: rgba(255, 255, 255, .18); transition: background .2s; }
.b3d-sw span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.b3d-sw input:checked + span { background: #6366f1; }
.b3d-sw input:checked + span::after { transform: translateX(16px); }
.b3d-sw input:focus-visible + span { outline: 3px solid var(--b3d-focus); outline-offset: 2px; }
.b3d-sw small { display: block; color: var(--b3d-dim); font-size: .78rem; }
.b3d-size-row { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.b3d-size-row > span { flex: 1; }
.b3d-size { min-width: 54px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* mode texte accessible */
.b3d-textview { position: absolute; inset: 0; z-index: 2; overflow: auto; padding: 12px 16px 20px; display: flex; justify-content: center; }
.b3d-textview[hidden] { display: none; }
.b3d-tv-page {
    --s: var(--b3d-scale, 1); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 28px; align-items: center;
    max-width: 1120px; width: 100%; align-self: flex-start; background: #fffdf9; color: #1d1c2e; border-radius: 22px; padding: 24px; box-shadow: 0 24px 60px -18px rgba(0, 0, 0, .6);
}
.b3d-tv-page:not(:has(img)) { grid-template-columns: 1fr; max-width: 760px; }
.b3d-tv-page img { width: 100%; max-height: calc(100vh - 230px); object-fit: contain; border-radius: 14px; background: #f1f0ec; }
.b3d-tv-page h2, .b3d-tv-page p, .b3d-tv-page li { color: inherit; }
.b3d-tv-page .b3d-tv-num { margin: 0 0 8px; font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: #4338ca; font-weight: 700; }
.b3d-tv-text h2 { margin: 0 0 14px; font-family: Fraunces, Georgia, serif; font-weight: 600; font-size: calc(1.75rem * var(--s)); line-height: 1.2; }
.b3d-tv-body { margin: 0; font-family: Literata, Fraunces, Georgia, serif; font-size: calc(1.22rem * var(--s)); line-height: 1.7; padding-left: 0; }
ul.b3d-tv-body { list-style: none; }
.b3d-readable .b3d-tv-page, .b3d-readable .b3d-tv-text h2, .b3d-readable .b3d-tv-body, .b3d-readable .b3d-caption-text { font-family: 'Atkinson Hyperlegible', Lexend, Verdana, Arial, sans-serif; }
.b3d-readable .b3d-tv-body { letter-spacing: .03em; word-spacing: .12em; line-height: 1.9; }

/* contraste élevé */
.b3d-contrast .b3d-bg { background: #000; }
.b3d-contrast { --b3d-dim: #fff; --b3d-line: #fff; --b3d-glass: #000; --b3d-glass-2: #222; }
.b3d-contrast .b3d-ibtn, .b3d-contrast .b3d-side { border-width: 2px; }
.b3d-contrast .b3d-pop, .b3d-contrast .b3d-caption-text { background: #000; border: 2px solid #fff; }
.b3d-contrast .b3d-tv-page { background: #fff; color: #000; }
.b3d-contrast .b3d-tv-page .b3d-tv-num { color: #00338a; }
.b3d-contrast .b3d-dot { background: #777; } .b3d-contrast .b3d-dot.on { background: #ffd400; }

/* mode classe : plein écran, gros boutons, interface qui s'efface */
.b3d-class .b3d-top { padding: 10px 18px 4px; }
.b3d-class .b3d-sub { display: none; }
.b3d-class .b3d-title { font-size: clamp(1.2rem, 2.2vw, 1.7rem); }
.b3d-class .b3d-side { width: 64px; height: 64px; margin-top: -32px; opacity: .4; }
.b3d-class .b3d-caption-text { font-size: clamp(1.4rem, 2.8vw, 2.2rem); }
.b3d-class .b3d-count { font-size: 1.05rem; }
.b3d-class.b3d-idle { cursor: none; }
.b3d-class.b3d-idle .b3d-top, .b3d-class.b3d-idle .b3d-bottom, .b3d-class.b3d-idle .b3d-side { opacity: 0; pointer-events: none; }

/* petits écrans */
@media (max-width: 640px) {
    .b3d-top { padding: 10px 10px 4px; gap: 8px; }
    .b3d-sub { display: none; }
    .b3d-title { font-size: 1rem; }
    .b3d-ibtn { width: 38px; height: 38px; }
    .b3d-actions { gap: 6px; }
    .b3d-pbtn { height: 38px; padding: 0 12px; }
    .b3d-pbtn .lbl { display: none; }
    .b3d-bottom { gap: 10px; padding: 4px 10px 12px; }
    .b3d-count { min-width: 0; font-size: .8rem; }
    .b3d-dot.is-story { width: 12px; } .b3d-dot.on { width: 22px; }
    .b3d-tv-page { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
    .b3d-textview { padding: 6px 10px 16px; }
}
@media (max-width: 380px) { .b3d-actions [data-act="class"] { display: none; } }
@media (prefers-reduced-motion: reduce) {
    .b3d-overlay, .b3d-canvas, .b3d-hint, .b3d-dot, .b3d-ibtn, .b3d-side { transition: none !important; }
    .b3d-spin { animation-duration: 3s; }
}
@media print { .b3d-overlay { display: none !important; } }

/* ------------------------------------------------------ atelier v2 */
.mwv2-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; align-items: center; }
.mwv2-bar .btn { white-space: nowrap; }
.mwv2-fieldset { border: 1px dashed var(--line, #ccc); border-radius: 14px; padding: 12px 14px; margin: 14px 0; }
.mwv2-fieldset legend { padding: 0 8px; font-weight: 700; font-size: .9rem; color: var(--ink-2, #555); }
.mwv2-opts { display: grid; gap: 10px; margin-top: 10px; }
.mwv2-opts label.chk { display: flex; gap: 8px; align-items: flex-start; font-size: .92rem; line-height: 1.35; cursor: pointer; }
.mwv2-opts label.chk input { margin-top: 3px; width: 18px; height: 18px; }
.mwv2-opts small { color: var(--ink-3, #777); display: block; }
.mwv2-char { display: grid; grid-template-columns: 1fr 70px 1.3fr 28px; gap: 8px; align-items: center; margin-bottom: 8px; }
.mwv2-char input, .mwv2-char select { min-width: 0; }
@media (max-width: 720px) { .mwv2-char { grid-template-columns: 1fr 1fr; } }
.mwv2-modal { position: fixed; inset: 0; z-index: 4500; background: rgba(15, 12, 24, .62); display: flex; align-items: center; justify-content: center; padding: 16px; }
.mwv2-card { background: var(--surface, #fff); color: var(--ink, #1c1a33); border-radius: 20px; box-shadow: 0 24px 80px rgba(0, 0, 0, .4); width: min(920px, 100%); max-height: 92vh; overflow: auto; padding: 20px 22px; }
.mwv2-card h3 { margin: 0 0 6px; font-family: var(--font-display, Fraunces, Georgia, serif); }
.mwv2-card .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.mwv2-close { float: right; border: 0; background: transparent; font-size: 1.6rem; cursor: pointer; color: inherit; }
.mwv2-variants { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.mwv2-variants figure { margin: 0; border: 2px solid transparent; border-radius: 12px; overflow: hidden; cursor: pointer; background: var(--surface-2, #f2f0ea); position: relative; }
.mwv2-variants figure.sel { border-color: var(--accent, #7c5cff); box-shadow: 0 0 0 3px rgba(124, 92, 255, .25); }
.mwv2-variants img { width: 100%; display: block; aspect-ratio: 9/16; object-fit: cover; }
.mwv2-variants figcaption { position: absolute; left: 6px; top: 6px; background: rgba(0, 0, 0, .6); color: #fff; font-size: .72rem; padding: 2px 7px; border-radius: 999px; }
.mwv2-zone { position: relative; display: inline-block; max-width: 100%; line-height: 0; cursor: crosshair; border-radius: 12px; overflow: hidden; }
.mwv2-zone img { max-width: 100%; max-height: 58vh; display: block; }
.mwv2-zone .ring { position: absolute; border: 4px solid #ff2d2d; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, .6); }
.mwv2-compare { position: relative; display: inline-block; max-width: 100%; line-height: 0; user-select: none; border-radius: 12px; overflow: hidden; }
.mwv2-compare img { max-width: 100%; max-height: 62vh; display: block; }
.mwv2-compare .top { position: absolute; inset: 0; clip-path: inset(0 50% 0 0); }
.mwv2-compare input[type=range] { position: absolute; left: 0; right: 0; bottom: 8px; width: 100%; accent-color: #7c5cff; }
.mwv2-thumbs { display: flex; gap: 8px; overflow: auto; padding: 6px 0; }
.mwv2-thumbs button { border: 2px solid transparent; border-radius: 10px; padding: 0; background: none; cursor: pointer; flex: 0 0 auto; }
.mwv2-thumbs button.sel { border-color: var(--accent, #7c5cff); } .mwv2-thumbs img { height: 90px; display: block; border-radius: 8px; }

/* pied de page des financeurs : les logos ne débordent plus sur téléphone (défilement horizontal) */
.site-footer-v2-link { flex-wrap: wrap; max-width: 100%; gap: 14px 28px; }
.site-footer-v2-link img { max-width: 100%; height: auto; max-height: 54px; }

/* télécommande : image seule / texte seul, le reste de l'écran est masqué */
.b3d-viewmask { position: absolute; z-index: 2; pointer-events: none; border-radius: 3px; box-shadow: 0 0 0 200vmax rgba(13, 11, 38, .985); }
.b3d-viewmask[hidden] { display: none; }

/* livre fermé : le doigt peut le faire tourner (appui long puis glisser) sans faire défiler */
.b3d-closed .b3d-canvas { touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
