

/* Lecture d'une histoire (modal #modal-story, app/features/stories.js) : plein écran façon stories,
   image en fond, barres de progression en haut, titre et texte par-dessus en bas.
   Fond et textes suivent le thème (--ColorBackground / --ColorText). */
#modal-story.container-modal {
    justify-content: center;
}

#modal-story .modal-content {
    position: relative;
    height: 100dvh;
    max-width: 28rem;
    padding: 0;
    gap: 0;
    border-radius: 0;
    background-color: var(--ColorBackground);
    overflow: hidden;
}

#modal-story .container-close-button {
    display: none;
}

#modal-story .modal-content .content {
    position: absolute;
    inset: 0;
    height: auto;
    padding: 0;
}

/* Remplace le padding commun des enfants de .content (css/modal.css) */
#modal-story .modal-content .content > .story-stage {
    padding: 0;
}

#modal-story .modal-content .content > .story-top {
    padding: calc(0.75rem + env(safe-area-inset-top)) 0.75rem 1.5rem;
}

#modal-story .story-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    touch-action: none; /* glisser horizontal et vers le bas gérés en JS (app/features/stories.js) */
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

#modal-story .story {
    position: absolute;
    inset: 0;
    transition: transform 0.25s ease;
}

#modal-story .story-stage.swiping {
    cursor: grabbing;
}

#modal-story .story.enter-next {
    animation: storyEnterNext 0.3s ease backwards;
}

#modal-story .story.enter-prev {
    animation: storyEnterPrev 0.3s ease backwards;
}

@keyframes storyEnterNext {
    from { transform: translateX(40%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes storyEnterPrev {
    from { transform: translateX(-40%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

#modal-story .story-image {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-color: var(--ColorContainer);
}

/* Image montrée en entier (logo de l'édition en intro) : image en haut puis texte en dessous,
   en colonne, sans jamais se superposer quand le texte défile */
#modal-story .story.story-contain {
    display: flex;
    flex-direction: column;
}

#modal-story .story-image.contain {
    position: relative;
    inset: auto;
    flex: 0 0 auto;
    height: 35%;
    padding: calc(4.5rem + env(safe-area-inset-top)) 2rem 0.5rem;
    background-size: contain;
    background-repeat: no-repeat;
    background-origin: content-box;
    background-clip: content-box;
    background-color: transparent;
}

#modal-story .story-contain .story-caption {
    position: relative;
    flex: 1;
    min-height: 0;
    max-height: none;
    padding-top: 1rem;
    background: none;
}

/* Haut : barres de progression (une par histoire) et fermeture, sur un léger dégradé */
#modal-story .story-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    background: linear-gradient(to bottom, color-mix(in srgb, var(--ColorBackground) 70%, transparent), transparent);
    pointer-events: none;
}

#modal-story .story-progress {
    display: flex;
    gap: 0.25rem;
    width: 100%;
}

#modal-story .story-progress span {
    flex: 1;
    width: auto;
    height: 3px;
    border-radius: 3px;
    background-color: color-mix(in srgb, var(--ColorText) 30%, transparent);
    transition: background-color 0.3s ease;
}

#modal-story .story-progress span.done {
    background-color: var(--ColorText);
}

#modal-story .story-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: none;
    background: none;
    color: var(--ColorText);
    font-size: 1.4rem;
    cursor: pointer;
    pointer-events: auto;
}

/* Bas : titre et texte sur un dégradé, le texte long défile dans sa zone */
#modal-story .story-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 60%;
    overflow-y: auto;
    padding: 6rem 1.25rem calc(1.75rem + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--ColorBackground) 40%, color-mix(in srgb, var(--ColorBackground) 75%, transparent) 75%, transparent);
    color: var(--ColorText);
    scrollbar-width: none;
}

/* Texte plus long que sa zone : défilement vertical natif (pas de fermeture en glissant) */
#modal-story .story-caption.scrollable {
    touch-action: pan-y;
}

#modal-story .story-caption::-webkit-scrollbar {
    display: none;
}

#modal-story .story-title {
    font-family: var(--FontFocus);
    font-size: 1.5rem;
    line-height: 1.2;
}

#modal-story .story-text {
    line-height: 1.6;
}

@media (min-width: 600px) {
    #modal-story .modal-content {
        height: calc(100dvh - 2rem);
        border-radius: 1.25rem;
    }
}

/* Accueil : histoires en bulles, défilement horizontal ; contour coloré tant qu'elles ne sont pas lues */
.story-bubbles {
    display: flex;
    flex-direction: row;
    gap: 0.25rem;
    overflow-x: auto;
    padding: 0.25rem 0.25rem 0.5rem;
    scrollbar-width: none;
}

.story-bubbles::-webkit-scrollbar {
    display: none;
}

.story-bubbles .story-bubble {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    flex: 0 0 5.25rem;
    width: 5.25rem;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--ColorText);
    cursor: pointer;
}

.story-bubble-ring {
    display: block;
    width: 4.25rem;
    height: 4.25rem;
    padding: 3px;
    border-radius: 50%;
    background: var(--ColorPrimary);
    box-sizing: border-box;
    transition: background-color 0.2s ease;
}

.story-bubble.seen .story-bubble-ring {
    background: var(--ColorRow);
}

.story-bubble-image {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--ColorBackground);
    box-sizing: border-box;
    background-color: var(--ColorContainer);
    background-size: cover;
    background-position: center;
}

.story-bubble-image.contain {
    background-size: 80%;
    background-repeat: no-repeat;
}

/* Nom sur deux lignes au plus, hauteur fixe de deux lignes : bulles fantômes et vraies bulles alignées */
.story-bubble-name {
    height: calc(0.7rem * 1.2 * 2);
    width: 100%;
    font-size: 0.7rem;
    line-height: 1.2;
    text-align: center;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow-wrap: break-word;
}

/* Bulles fantômes pendant le chargement (app/pages/home.js) */
.story-bubbles .story-bubble.ghost {
    cursor: default;
    /* Même apparition différée que les squelettes (css/skeleton.css) */
    opacity: 0;
    animation: skeletonIn 0.2s ease-out 0.3s forwards;
}

.story-bubble.ghost .story-bubble-ring,
.story-bubble-bar {
    background: color-mix(in srgb, var(--ColorRow) calc(var(--skeleton-fade) * 100%), transparent);
    animation: skeletonPulse 1.2s ease-in-out 0.5s infinite alternate;
}

@media (prefers-reduced-motion: reduce) {
    .story-bubble.ghost .story-bubble-ring,
    .story-bubble-bar {
        animation: none;
    }
}

/* Nom fantôme : une barre à la place du texte */
.story-bubble.ghost .story-bubble-name {
    display: flex;
    justify-content: center;
    padding-top: 0.2rem;
}

.story-bubble-bar {
    width: 70%;
    height: 0.45rem;
    border-radius: 0.25rem;
}

/* Vraies bulles : simple fondu sur place (pas de glissement), elles prennent la place des fantômes */
.story-bubbles.appear {
    animation: storyAppear 0.3s ease-out;
}

@keyframes storyAppear {
    from { opacity: 0; }
}

.story-bubble.seen .story-bubble-name {
    opacity: 0.7;
}

/* La règle commune de css/main.css ajoute des marges aux petits-enfants d'un .p-0 ([data-stories]) :
   plus spécifique, elle est annulée ici pour que les noms tiennent dans la bulle */
html:is(.game) section .p-0 > .story-bubbles > .story-bubble {
	padding: 0;
}
