/* ===================================================================
   FEUILLE DE STYLE DIAPORAMA INTERACTIF (KAMISHIBAI)
   - Refonte mobile complète (juin 2026)
   =================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Kiwi+Maru:wght@400;500&family=Noto+Sans+JP:wght@500;700&family=Klee+One:wght@400;600&family=Yuji+Syuku&display=swap');

.diaporama-container {
    --diapo-font-size-factor: 0.9;
    --diapo-zoom-factor: 1;
    position: relative;
    max-width: 100%;
    width: 100%;
    margin: 2em auto;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    border: 1px solid #eaeaea;
    container-type: inline-size;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
        "header"
        "viewport"
        "controls"
        "textbox"
        "footer";
    box-sizing: border-box;
}

.diaporama-header {
    grid-area: header;
}

/* --- Viewport Image (Kamishibai) --- */
.diaporama-viewport {
    grid-area: viewport;
    position: relative;
    width: 100%;
    background: #1a1a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    container-type: inline-size;
}

.diaporama-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s ease-in-out;
    opacity: 0;
}

.diaporama-image.active {
    opacity: 1;
}

/* --- Barre des Contrôles Globale --- */
.diaporama-controls {
    grid-area: controls;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 12px 20px;
    background: #fdfdfd;
    border-bottom: 1px solid #f0f0f0;
    gap: 12px;
    box-sizing: border-box;
}

/* --- Sélecteur de Grade (iOS Style) --- */
.diaporama-grade-selector {
    display: flex;
    background: #f1f1f1;
    border-radius: 30px;
    padding: 3px;
    border: 1px solid #e5e5e5;
    flex-shrink: 0;
}

.diaporama-grade-btn {
    border: none;
    background: transparent;
    padding: 6px 14px;
    font-size: 0.85em;
    font-weight: 600;
    color: #666;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    white-space: nowrap;
}

.diaporama-grade-btn:hover {
    color: #333;
}

/* Classes dynamiques pour le bouton actif par grade */
.diaporama-grade-btn.active {
    color: #ffffff;
    background-color: #0074c7; /* Fallback par défaut (Bleu) */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.diaporama-grade-btn.active.g1 {
    background-color: #4caf50;
}

/* Vert */
.diaporama-grade-btn.active.g2 {
    background-color: #f39c12;
}

/* Orange */
.diaporama-grade-btn.active.g3 {
    background-color: #2196f3;
}

/* Bleu */
.diaporama-grade-btn.active.g4 {
    background-color: #9c27b0;
}

/* Violet */
.diaporama-grade-btn.active.natif {
    background-color: #8c1c13;
}

/* Rouge */

/* --- Toggles d'affichage de texte & audio --- */
.diaporama-display-toggles {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.diaporama-toggle-btn {
    background: #ffffff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: #555;
    transition: all 0.2s ease;
    font-weight: bold;
    white-space: nowrap;
}

.diaporama-toggle-btn:hover {
    border-color: #999;
    background: #fafafa;
}

.diaporama-toggle-btn.active {
    background: #eef5fa;
    border-color: #0074c7;
    color: #0074c7;
}

.diaporama-audio-btn {
    border: 1px solid #dcdcdc;
    background: #ffffff;
    color: #0074c7;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.diaporama-audio-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 8px rgba(0, 116, 199, 0.2);
}

.diaporama-audio-btn.playing {
    background: #0074c7;
    color: #ffffff;
    border-color: #0074c7;
    animation: pulse 1.5s infinite;
}

/* --- Zone de Texte --- */
.diaporama-textbox {
    grid-area: textbox;
    padding: 24px 30px;
    min-height: 120px;
    background: #ffffff;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: font-size 0.2s ease;
    box-sizing: border-box;
    font-size: calc(var(--diapo-zoom-factor, 1) * 3.3cqw);
}

.diaporama-jp-text {
    font-size: calc(clamp(14px, 1.15em, 2.2rem) * var(--diapo-font-size-factor, 1));
    font-weight: 600;
    line-height: 1.8;
    color: #2c3e50;
    margin: 0;
    font-family: "Kiwi Maru", "Noto Sans JP", sans-serif;
    letter-spacing: 0.05em;
    display: none;
    word-break: break-word;
    overflow-wrap: break-word;
}

.diaporama-jp-text.active {
    display: block;
}

/* Support Ruby / Furigana */
.diaporama-jp-text ruby {
    ruby-position: over;
}

.diaporama-jp-text rt {
    font-size: 0.55em;
    color: #7f8c8d;
    user-select: none;
}

/* Traduction française */
.diaporama-fr-text {
    font-size: calc(0.9em * var(--diapo-font-size-factor, 1));
    color: #555555;
    margin-top: 14px;
    line-height: 1.6;
    border-left: 3px solid #ddd;
    padding-left: 14px;
    font-style: italic;
    display: none;
    word-break: break-word;
    overflow-wrap: break-word;
}

.diaporama-fr-text.active {
    display: block;
}

/* --- Barre de Navigation Basse --- */
.diaporama-footer {
    grid-area: footer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #fdfdfd;
    gap: 8px;
    box-sizing: border-box;
}

.diaporama-nav-btn {
    border: none;
    background: #8c1c13;
    color: #ffffff;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.diaporama-nav-btn:hover {
    background: #a02017;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(140, 28, 19, 0.2);
}

.diaporama-nav-btn:disabled {
    background: #e0e0e0;
    color: #999999;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.diaporama-progress-indicator {
    font-size: 0.9em;
    color: #666;
    font-weight: 600;
    flex-shrink: 0;
}

/* Timeline (Barre de progression) */
.diaporama-timeline {
    flex: 1;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    margin: 0 15px;
    position: relative;
    cursor: pointer;
    overflow: hidden;
}

.diaporama-timeline-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: #4CAF50; /* Vert très frais et lisible */
    width: 0%;
    transition: width 0.3s ease;
}

/* --- Animations --- */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 116, 199, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(0, 116, 199, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 116, 199, 0);
    }
}

/* ===================================================================
   ADAPTATIONS MOBILE (max-width: 600px)
   FIX PRINCIPAL : suppression du calc(100%+20px) qui causait le
   débordement horizontal. Le conteneur reste à 100% de son parent.
   =================================================================== */
@media (max-width: 600px) {
    .diaporama-container {
        /* Supprimé : margin: 1em -10px + width: calc(100%+20px) */
        /* Ces valeurs causaient le débordement et le masquage des boutons */
        margin: 0;
        /* Pas de marge : le <main> gère l'espacement */
        width: 100%;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    /* Contrôles en colonne sur mobile */
    .diaporama-controls {
        flex-direction: column;
        align-items: stretch;
        padding: 10px 12px;
        gap: 8px;
    }

    /* Grade selector centré */
    .diaporama-grade-selector {
        justify-content: center;
        width: 100%;
    }

    .diaporama-grade-btn {
        flex: 1;
        text-align: center;
        padding: 6px 8px;
        font-size: 0.8em;
    }

    /* Boutons toggle : grille 4 colonnes pour tout faire tenir */
    .diaporama-display-toggles {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
        width: 100%;
    }

    .diaporama-toggle-btn {
        padding: 6px 4px;
        font-size: 0.78em;
        justify-content: center;
        gap: 3px;
    }

    /* Le bouton audio (rond) prend 1 cellule dans la grille */
    .diaporama-audio-btn {
        width: 100%;
        height: 36px;
        border-radius: 8px;
    }

    /* Textbox plus compacte */
    .diaporama-textbox {
        padding: 12px 14px;
        min-height: auto;
    }

    .diaporama-jp-text {
        font-size: 1.15em;
    }

    .diaporama-fr-text {
        font-size: 0.95em;
        margin-top: 10px;
    }

    /* Footer navigation */
    .diaporama-footer {
        padding: 10px 12px;
    }

    .diaporama-nav-btn {
        padding: 8px 12px;
        font-size: 0.85em;
    }

    /* Moins de dots sur mobile pour éviter le débordement */
    .diaporama-dot {
        width: 6px;
        height: 6px;
    }
}

/* ===================================================================
   MODE INCRUSTATION (Texte sur l'image)
   =================================================================== */
.diaporama-container.overlay-mode {
    grid-template-areas:
        "header"
        "viewport"
        "controls"
        "footer";
}

.diaporama-container.overlay-mode .diaporama-textbox {
    grid-area: viewport;
    align-self: end;
    z-index: 2;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.55) 75%, rgba(0, 0, 0, 0) 100%);
    border-bottom: none;
    padding: 30px 40px 20px;
    pointer-events: none;
    min-height: auto;
}

.diaporama-container.overlay-mode .diaporama-jp-text {
    color: #ffffff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8), 0 2px 10px rgba(0, 0, 0, 0.4);
}

.diaporama-container.overlay-mode .diaporama-jp-text rt {
    color: #f0f0f0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.diaporama-container.overlay-mode .diaporama-fr-text {
    color: #dddddd;
    border-left-color: #8c1c13;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}



/* ===================================================================
   PLEIN ÉCRAN — Mode portrait
   =================================================================== */
.diaporama-container:fullscreen,
.diaporama-container:-webkit-full-screen {
    max-width: 100%;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
    background: #000;
    display: grid;
    grid-template-rows: auto 1fr auto auto auto;
    overflow-y: auto;
}

.diaporama-container:fullscreen .diaporama-viewport,
.diaporama-container:-webkit-full-screen .diaporama-viewport {
    /* Occupe toute la cellule grid, centré, ratio 16:9 conservé */
    width: 100%;
    height: 100%;
    aspect-ratio: 16 / 9;
    max-width: calc(100vh * 16 / 9);
    max-height: calc(100vw * 9 / 16);
    margin: 0 auto;
    align-self: center;
    justify-self: center;
}

    /* Fullscreen textbox: keep centered and constrained */
    .diaporama-container:fullscreen .diaporama-textbox {
        width: 100%;
        max-width: 90%;
        margin: 0 auto;
        padding: 16px 20px;
        box-sizing: border-box;
    }
    /* Ensure overlay-mode textbox stays at bottom in fullscreen */
    .diaporama-container:fullscreen.overlay-mode .diaporama-textbox {
        align-self: end;
        margin: 0 auto;
        width: 100%;
    }

.diaporama-container:fullscreen .diaporama-jp-text,
.diaporama-container:-webkit-full-screen .diaporama-jp-text {
    color: #f0f0f0;
}

.diaporama-container:fullscreen .diaporama-fr-text,
.diaporama-container:-webkit-full-screen .diaporama-fr-text {
    color: #bbb;
    border-left-color: #8c1c13;
}

.diaporama-container:fullscreen .diaporama-controls,
.diaporama-container:-webkit-full-screen .diaporama-controls {
    background: #1a1a1a;
    border-bottom-color: #333;
}

/* --- Mode portrait plein écran avec texte déporté --- */
.diaporama-container.portrait-fullscreen-mode {
    grid-template-areas:
        "header"
        "viewport"
        "textbox"
        "controls"
        "footer" !important;
    grid-template-rows: auto 1fr auto auto auto !important;
}

.diaporama-container.portrait-fullscreen-mode .diaporama-textbox {
    display: flex !important;
    background: #1a1a1a !important;
    border-top: 1px solid #333 !important;
    border-bottom: none !important;
    padding: 16px 20px !important;
    min-height: auto !important;
    align-self: stretch !important;
}

.diaporama-container.portrait-fullscreen-mode .diaporama-jp-text {
    display: block !important;
    font-size: calc(clamp(1.2rem, 5.5vw, 1.65rem) * var(--diapo-font-size-factor, 1) * var(--diapo-zoom-factor, 1)) !important;
    color: #ffffff !important;
}

.diaporama-container.portrait-fullscreen-mode .diaporama-fr-text {
    display: block !important;
    font-size: calc(clamp(0.95rem, 4vw, 1.25rem) * var(--diapo-font-size-factor, 1) * var(--diapo-zoom-factor, 1)) !important;
    color: #bbbbbb !important;
    border-left-color: #8c1c13 !important;
    margin-top: 12px !important;
}

.diaporama-container:fullscreen .diaporama-footer,
.diaporama-container:-webkit-full-screen .diaporama-footer {
    background: #1a1a1a;
}

.diaporama-container:fullscreen .diaporama-toggle-btn,
.diaporama-container:-webkit-full-screen .diaporama-toggle-btn {
    background: #2a2a2a;
    border-color: #444;
    color: #ccc;
}

.diaporama-container:fullscreen .diaporama-toggle-btn img,
.diaporama-container:-webkit-full-screen .diaporama-toggle-btn img {
    filter: brightness(0) invert(0.85);
}

.diaporama-container:fullscreen .diaporama-toggle-btn.active,
.diaporama-container:-webkit-full-screen .diaporama-toggle-btn.active {
    background: #0074c7;
    border-color: #0074c7;
    color: #fff;
}

.diaporama-container:fullscreen .diaporama-toggle-btn.active img,
.diaporama-container:-webkit-full-screen .diaporama-toggle-btn.active img {
    filter: brightness(0) invert(1);
}

/* ===================================================================
   PLEIN ÉCRAN MOBILE — Mode PAYSAGE (landscape)
   Sur smartphone en paysage, l'image prend max de place,
   les contrôles et texte sont compactés en bas
   =================================================================== */
@media screen and (max-width: 900px) and (orientation: landscape) {

    .diaporama-container:fullscreen,
    .diaporama-container:-webkit-full-screen {
        grid-template-rows: 1fr auto;
        grid-template-areas:
            "viewport"
            "footer";
    }

    /* L'image s'adapte strictement à l'espace restant sans écraser le footer */
    .diaporama-container:fullscreen .diaporama-viewport,
    .diaporama-container:-webkit-full-screen .diaporama-viewport {
        aspect-ratio: 16 / 9;
        width: 100%;
        height: auto;
        max-width: 100%;
        max-height: 100%;
        justify-self: center;
        align-self: center;
    }

    /* Header masqué en paysage plein écran */
    .diaporama-container:fullscreen>div:first-child,
    .diaporama-container:-webkit-full-screen>div:first-child {
        display: none;
    }

    /* Contrôles masqués en paysage pour maximiser l'image */
    .diaporama-container:fullscreen .diaporama-controls,
    .diaporama-container:-webkit-full-screen .diaporama-controls {
        display: none;
    }

    /* Textbox en overlay sur l'image (bas de l'écran) */
    .diaporama-container:fullscreen .diaporama-textbox,
    .diaporama-container:-webkit-full-screen .diaporama-textbox {
        position: absolute;
        bottom: 52px;
        /* au-dessus du footer */
        left: 0;
        right: 0;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0) 100%);
        padding: 20px 20px 10px;
        border-bottom: none;
        min-height: auto;
        pointer-events: none;
        z-index: 5;
    }

    .diaporama-container:fullscreen .diaporama-jp-text,
    .diaporama-container:-webkit-full-screen .diaporama-jp-text {
        font-size: calc(clamp(1.1rem, 2vw, 1.4rem) * var(--diapo-font-size-factor, 1) * var(--diapo-zoom-factor, 1));
        color: #fff;
        text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
    }

    .diaporama-container:fullscreen .diaporama-fr-text,
    .diaporama-container:-webkit-full-screen .diaporama-fr-text {
        color: #ddd;
        font-size: calc(0.9em * var(--diapo-font-size-factor, 1) * var(--diapo-zoom-factor, 1));
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
        border-left-color: #8c1c13;
    }

    /* Marge en haut pour éviter de rogner le Kanji en paysage (ciblage de la nouvelle classe .is-positioned-top) */
    .diaporama-container:fullscreen .diaporama-mot-libre.is-positioned-top,
    .diaporama-container:-webkit-full-screen .diaporama-mot-libre.is-positioned-top {
        top: 25px !important;
        margin-top: 0 !important;
    }

    /* Contrôles dupliqués dans le footer en mode paysage */
    .diaporama-container:fullscreen .diaporama-mobile-landscape-controls,
    .diaporama-container:-webkit-full-screen .diaporama-mobile-landscape-controls {
        display: flex !important;
        flex-direction: row;
        gap: 6px;
        align-items: center;
        justify-content: center;
    }

    /* Uniformisation des boutons dupliqués en ronds (comme l'audio) et miniaturisation */
    .diaporama-container:fullscreen .diaporama-mobile-landscape-controls .diaporama-toggle-btn,
    .diaporama-container:-webkit-full-screen .diaporama-mobile-landscape-controls .diaporama-toggle-btn,
    .diaporama-container:fullscreen .diaporama-mobile-landscape-controls .diaporama-audio-btn,
    .diaporama-container:-webkit-full-screen .diaporama-mobile-landscape-controls .diaporama-audio-btn {
        width: 30px;
        height: 30px;
        border-radius: 50%;
        padding: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 0.95em;
    }

    /* Masquage de la timeline pour faire de la place aux boutons en mode paysage */
    .diaporama-container:fullscreen .diaporama-timeline,
    .diaporama-container:-webkit-full-screen .diaporama-timeline {
        display: none !important;
    }

    /* Footer très compact en paysage pour maximiser l'image */
    .diaporama-container:fullscreen .diaporama-footer,
    .diaporama-container:-webkit-full-screen .diaporama-footer {
        padding: 4px 10px;
    }

    .diaporama-container:fullscreen .diaporama-nav-btn,
    .diaporama-container:-webkit-full-screen .diaporama-nav-btn {
        padding: 4px 10px;
        font-size: 0.8em;
    }
}

/* Cache global par défaut des contrôles dupliqués */
.diaporama-mobile-landscape-controls {
    display: none !important;
}

/* ===================================================================
   PLEIN ÉCRAN MOBILE — Mode PORTRAIT sur smartphone
   =================================================================== */
@media screen and (max-width: 600px) {

    .diaporama-container:fullscreen .diaporama-controls,
    .diaporama-container:-webkit-full-screen .diaporama-controls {
        flex-direction: column;
        padding: 8px 10px;
        gap: 6px;
    }

    .diaporama-container:fullscreen .diaporama-display-toggles,
    .diaporama-container:-webkit-full-screen .diaporama-display-toggles {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 5px;
        width: 100%;
    }

    .diaporama-container:fullscreen .diaporama-toggle-btn,
    .diaporama-container:-webkit-full-screen .diaporama-toggle-btn {
        padding: 5px 3px;
        font-size: 0.75em;
    }

    .diaporama-container:fullscreen .diaporama-grade-selector,
    .diaporama-container:-webkit-full-screen .diaporama-grade-selector {
        width: 100%;
        justify-content: center;
    }

    .diaporama-container:fullscreen .diaporama-grade-btn,
    .diaporama-container:-webkit-full-screen .diaporama-grade-btn {
        flex: 1;
        text-align: center;
        font-size: 0.8em;
    }

    .diaporama-container:fullscreen .diaporama-audio-btn,
    .diaporama-container:-webkit-full-screen .diaporama-audio-btn {
        width: 100%;
        height: 34px;
        border-radius: 8px;
    }

    .diaporama-container:fullscreen .diaporama-footer,
    .diaporama-container:-webkit-full-screen .diaporama-footer {
        padding: 8px 10px;
    }

    /* En mode paysage plein écran, le footer est plus compact, on baisse un peu la bulle */
    .diaporama-container:fullscreen .diaporama-zoom-popup,
    .diaporama-container:-webkit-full-screen .diaporama-zoom-popup {
        bottom: 50px;
    }

    .diaporama-container:fullscreen .diaporama-nav-btn,
    .diaporama-container:-webkit-full-screen .diaporama-nav-btn {
        padding: 7px 10px;
        font-size: 0.8em;
    }
}

/* ===================================================================
   MAIN DIAPORAMA : suppression du padding latéral sur mobile
   Le style inline "padding: 0 15px" sur <main class="diaporama-main">
   réduit la largeur disponible. On l'annule sur les petits écrans.
   =================================================================== */
@media (max-width: 600px) {
    main.diaporama-main {
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* Le lien "retour au blog" garde un peu de marge */
    main.diaporama-main>div:first-child {
        padding: 0 12px;
    }
}

/* ===================================================================
   TEXT OVERLAY DYNAMIQUE & VOCABULAIRE INTERACTIF
   =================================================================== */

/* Conteneur de superposition dynamique */
.diaporama-dynamic-overlay {
    position: absolute;
    z-index: 10;
    pointer-events: none;
    /* Laisse passer les clics vers l'image si besoin */
    background: rgba(255, 255, 255, 0.85);
    /* léger fond semi-transparent pour les caractères */
    padding: 10px 15px;
    border-radius: 8px;
    box-sizing: border-box;
    font-size: calc(var(--diapo-font-size-factor, 0.9) * var(--diapo-zoom-factor, 1) * 3.3cqw);
    line-height: 1.8;
}

.diaporama-dynamic-overlay .diaporama-jp-text {
    font-weight: 500;
    font-size: inherit;
    line-height: inherit;
    height: 100%;
}

.diaporama-dynamic-overlay .diaporama-jp-text,
.diaporama-dynamic-overlay .diaporama-fr-text {
    pointer-events: auto;
    /* Réactive les clics pour le texte */
}

/* En plein écran, garder le texte sombre dans l'overlay dynamique (fond blanc)
   pour éviter texte blanc sur fond blanc */
.diaporama-container:fullscreen .diaporama-dynamic-overlay .diaporama-jp-text,
.diaporama-container:-webkit-full-screen .diaporama-dynamic-overlay .diaporama-jp-text {
    color: #2c3e50 !important;
    text-shadow: none !important;
}

.diaporama-container:fullscreen .diaporama-dynamic-overlay .diaporama-jp-text rt,
.diaporama-container:-webkit-full-screen .diaporama-dynamic-overlay .diaporama-jp-text rt {
    color: #7f8c8d !important;
    text-shadow: none !important;
}

.diaporama-container:fullscreen .diaporama-dynamic-overlay .diaporama-fr-text,
.diaporama-container:-webkit-full-screen .diaporama-dynamic-overlay .diaporama-fr-text {
    color: #555 !important;
    text-shadow: none !important;
}

.diaporama-container:fullscreen .diaporama-dynamic-overlay .vocab-clickable,
.diaporama-container:-webkit-full-screen .diaporama-dynamic-overlay .vocab-clickable {
    color: #27ae60 !important;
}

/* Mot cliquable (Vocabulaire) */
.vocab-clickable {
    color: #27ae60;
    border-bottom: 1px dashed #27ae60;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-block;
}

.vocab-clickable:hover {
    background-color: rgba(39, 174, 96, 0.1);
    border-radius: 4px;
}

/* Tooltip Vocabulaire */
.diaporama-vocab-tooltip {
    position: absolute;
    z-index: 1000;
    background: #ffffff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    padding: 8px 12px;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #333;
    animation: fadeInTooltip 0.2s ease-out;
    pointer-events: auto;
    white-space: nowrap;
}

/* La petite flèche de la tooltip */
.diaporama-vocab-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: var(--arrow-left, 50%);
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: #ffffff transparent transparent transparent;
}

.diaporama-vocab-tooltip::before {
    content: '';
    position: absolute;
    top: 100%;
    left: var(--arrow-left, 50%);
    margin-left: -7px;
    border-width: 7px;
    border-style: solid;
    border-color: #ddd transparent transparent transparent;
    z-index: -1;
}

/* Bouton Audio de la tooltip */
.vocab-tts-play {
    background: #eef5fa;
    border: 1px solid #0074c7;
    color: #0074c7;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8em;
    transition: all 0.2s ease;
    padding: 0;
}

.vocab-tts-play:hover {
    background: #0074c7;
    color: #ffffff;
    transform: scale(1.1);
}

.vocab-tts-play.playing {
    background: #0074c7;
    color: #ffffff;
    animation: pulseTTS 1s infinite;
}

@keyframes fadeInTooltip {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulseTTS {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 116, 199, 0.4);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(0, 116, 199, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 116, 199, 0);
    }
}

/* ===================================================================
   ÉLÉMENTS FLOTTANTS DYNAMIQUES (Mot libre & Kanji Box)
   =================================================================== */

.diaporama-vocab-card {
    /* Positionnement et Dimensions par défaut (surchargés par JS) */
    position: absolute;
    bottom: 2%;
    left: 1%;
    width: auto;
    min-width: 260px;
    max-width: clamp(280px, 42vw, 380px);
    max-height: 45vh;
    overflow-y: auto;
    padding: 8px 12px;
    box-sizing: border-box;

    /* Forme */
    border-radius: 16px;

    /* Fond semi-transparent (Couleur sable/crème très claire) */
    background-color: rgba(245, 240, 235, 0.85);

    /* L'effet de flou en arrière-plan (Glassmorphism) */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px); /* Pour la compatibilité Safari */

    /* Bordure fine et subtile pour accentuer l'effet de verre */
    border: 1px solid rgba(255, 255, 255, 0.4);

    /* Ombre très douce pour décoller le cadre du fond */
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.08);

    /* Typographie */
    font-family: sans-serif;
    color: #1a1a1a;
    line-height: 1.5;
    font-size: clamp(0.85rem, 1.8vw, 1.1rem);
    
    /* Flexbox pour le contenu injecté */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    z-index: 10;
}

/* --- Décalage dynamique de la Textbox (quand Kanji Box est présente) --- */
.diaporama-floating-elements {
    z-index: 20 !important; /* Toujours au-dessus de l'overlay de texte */
    font-size: 1.2cqw; /* Base scaling unit for all floating em units */
}

@media (min-width: 601px) {
    /* Mode incrustation classique (legacy) : décalage via padding (le dégradé reste plein écran) */
    .diaporama-container.overlay-mode.shift-textbox-right .diaporama-textbox {
        padding-left: clamp(230px, 42vw, 340px) !important;
    }

    .diaporama-container.overlay-mode.shift-textbox-left .diaporama-textbox {
        padding-right: clamp(230px, 42vw, 340px) !important;
    }

    /* Mode overlay dynamique : réduction réelle de la largeur pour éviter le mélange de fond */
    .diaporama-container.shift-textbox-right .diaporama-dynamic-overlay {
        left: clamp(270px, 44vw, 400px) !important;
        width: auto !important;
        right: 2.5% !important;
        padding-left: 15px !important;
    }

    .diaporama-container.shift-textbox-left .diaporama-dynamic-overlay {
        right: clamp(270px, 44vw, 400px) !important;
        width: auto !important;
        left: 2.5% !important;
        padding-right: 15px !important;
    }
}

/* --- Adaptations Mobile pour la Kanji Box / Vocab Card --- */
@media (max-width: 600px) {
    .diaporama-vocab-card {
        width: auto !important;
        min-width: 100px !important;
        max-width: 85% !important;
        padding: 10px 14px !important;
        font-size: clamp(0.75rem, 3vw, 0.95rem) !important;
        border-radius: 12px !important;
    }

    .diaporama-vocab-card.mobile-popup {
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        bottom: auto !important;
        right: auto !important;
        width: 85% !important;
        max-width: 320px !important;
        z-index: 100 !important;
        background-color: rgba(255, 255, 255, 0.96) !important;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25) !important;
        border: 1px solid rgba(0, 0, 0, 0.15) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        padding-right: 30px !important; /* Pour laisser de la place au bouton ✕ */
    }
}

/* --- Styles pour les Mots Libres flottants --- */
.mot-libre-vertical {
    writing-mode: vertical-rl;
    text-orientation: upright;
}

.mot-libre-simple {
    color: #1a1a1a;
    opacity: 0.85;
    mix-blend-mode: multiply;
    filter: drop-shadow(10px 10px 20px rgba(0,0,0,0.2)) blur(0.5px);
}

.mot-libre-degrade1 {
    background: linear-gradient(to bottom, #fff5cc, #fcf6ba, #bf953f, #f39c12, #8a6000);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent !important;
    filter: drop-shadow(0 0 20px rgba(255, 200, 50, 0.5)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
}

.mot-libre-dore {
    font-weight: 600;
    background: linear-gradient(to bottom, #fff8d0, #f5d87a, #c8860a, #f0a500, #7a4e00);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent !important;
    filter: drop-shadow(0 0 22px rgba(255, 190, 40, 0.6)) drop-shadow(0 3px 6px rgba(0, 0, 0, 0.95));
}

/* Classe utilitaire pour afficher proprement du texte français d'introduction */
.diaporama-intro-text {
    display: inline-block;
    width: 100%;
    font-size: clamp(0.95rem, 1.4vw, 1.15rem) !important;
    font-weight: normal !important;
    font-family: system-ui, -apple-system, sans-serif !important;
    letter-spacing: normal !important;
    line-height: 1.35 !important;
}

/* Badge d'information flottant (i) sur mobile */
.kanji-info-trigger {
    position: absolute !important;
    top: -12px !important;
    right: -20px !important;
    width: 22px !important;
    height: 22px !important;
    background: #0074c7 !important;
    color: #ffffff !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 14px !important;
    font-family: sans-serif !important;
    font-weight: bold !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3) !important;
    z-index: 50 !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    user-select: none !important;
    line-height: 1 !important;
    text-shadow: none !important;
    font-style: normal !important;
    writing-mode: horizontal-tb !important; /* Force la lecture horizontale */
}

.kanji-info-trigger-corner {
    width: 38px !important;
    height: 38px !important;
    background: rgba(0, 116, 199, 0.95) !important;
    color: #ffffff !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.35rem !important;
    font-weight: bold !important;
    box-shadow: 0 3px 8px rgba(0,0,0,0.25) !important;
    z-index: 30 !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    user-select: none !important;
    font-family: sans-serif !important;
    font-style: normal !important;
}

/* Modificateurs dynamiques pour la position du badge info */
.kanji-info-trigger.badge-top {
    top: -12px !important;
    bottom: auto !important;
}
.kanji-info-trigger.badge-bottom {
    bottom: -12px !important;
    top: auto !important;
}
.kanji-info-trigger.badge-left {
    left: -15px !important;
    right: auto !important;
}
.kanji-info-trigger.badge-right {
    right: -15px !important;
    left: auto !important;
}

/* ===================================================================
   LIMITATION DE LA MISE À L'ÉCHELLE POUR LES GRANDS ÉCRANS (DESKTOP)
   =================================================================== */
@media screen and (min-width: 1024px) {
    /* Limiter l'échelle gigantesque du cqw en plein écran sur ordinateur */
    .diaporama-container:fullscreen .diaporama-textbox,
    .diaporama-container:-webkit-full-screen .diaporama-textbox {
        font-size: calc(clamp(14px, 2.0cqw, 36px) * var(--diapo-zoom-factor, 1));
    }
    
    .diaporama-container:fullscreen .diaporama-dynamic-overlay,
    .diaporama-container:-webkit-full-screen .diaporama-dynamic-overlay {
        font-size: calc(clamp(14px, 2.0cqw, 36px) * var(--diapo-zoom-factor, 1) * var(--diapo-font-size-factor, 1));
    }
}

/* ===================================================================
   INTERFACE DU WIDGET ZOOM (POPUP HYBRIDE)
   =================================================================== */
.diaporama-zoom-popup-container {
    position: relative;
    display: inline-block;
}

.diaporama-zoom-popup {
    position: absolute;
    bottom: 70px; /* Au-dessus de la barre de contrôles globale */
    left: 50%;
    transform: translateX(-50%) translateY(15px);
    background: #ffffff;
    border: 1px solid #dcdcdc;
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 999;
}

.diaporama-zoom-popup.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Flèche du popup */
.diaporama-zoom-popup::after,
.diaporama-zoom-popup::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-style: solid;
    pointer-events: none;
}
.diaporama-zoom-popup::after {
    border-width: 8px;
    border-color: #ffffff transparent transparent transparent;
}
.diaporama-zoom-popup::before {
    border-width: 9px;
    border-color: #dcdcdc transparent transparent transparent;
    margin-top: 1px;
}

/* Boutons A- et A+ dans la popup */
.diaporama-zoom-btn-small {
    background: #f0f4f8;
    border: 1px solid #e1e8ed;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    font-size: 1.15em;
    font-weight: bold;
    color: #0074c7;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.diaporama-zoom-btn-small:hover {
    background: #e4eef6;
    border-color: #0074c7;
}

.diaporama-zoom-btn-small:active {
    transform: scale(0.95);
}

/* Curseur (Slider) de zoom */
.diaporama-zoom-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 140px;
    height: 8px;
    background: #e1e8ed;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.diaporama-zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #0074c7;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform 0.1s;
}

.diaporama-zoom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.diaporama-zoom-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #0074c7;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform 0.1s;
}

.diaporama-zoom-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
}

/* ===================================================================
   FURIGANA INTERACTIF
   =================================================================== */

.furigana-interactive ruby rt {
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: translateY(5px);
    pointer-events: none; /* Empêche le scintillement lors du hover */
}

/* Affichage au survol ou à l'appui */
.furigana-interactive ruby:hover rt,
.furigana-interactive ruby:active rt {
    opacity: 1;
    transform: translateY(0);
}

/* Sur mobile, on désactive l'affichage du furigana au tap SI le mot est un lien vers le dictionnaire (vocab-clickable) */
@media (max-width: 900px) {
    .furigana-interactive .vocab-clickable ruby:active rt {
        opacity: 0 !important;
        transform: translateY(5px) !important;
    }
}

/* ===================================================================
   MODALE D'AIDE (RACCOURCIS)
   =================================================================== */
.diaporama-help-modal {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.diaporama-help-modal.show {
    display: flex;
}

.diaporama-help-content {
    background: #ffffff;
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    text-align: left;
    color: #333;
}

.diaporama-help-content h3 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 1.2em;
    color: #111;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
}

.diaporama-help-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.diaporama-help-content li {
    margin-bottom: 12px;
    font-size: 0.95em;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.diaporama-help-content .help-icon {
    font-weight: bold;
    min-width: 90px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #111;
}

.diaporama-help-content .help-desc {
    color: #444;
    line-height: 1.4;
}

.diaporama-help-content ul.shortcuts-list li {
    align-items: center;
    justify-content: space-between;
}

.diaporama-help-content kbd {
    background: #f4f4f4;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.85em;
    font-family: monospace;
    font-weight: bold;
    color: #555;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

.diaporama-help-close {
    display: block;
    width: 100%;
    margin-top: 20px;
    padding: 10px;
    background: #f0f0f0;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.diaporama-help-close:hover {
    background: #e0e0e0;
}