/* Import hand-drawn fonts */
@import url('https://fonts.googleapis.com/css2?family=Kalam:wght@400;700&family=Caveat:wght@400;700&family=Amatic+SC:wght@700&display=swap');

/* Story overlay */
.story-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.92);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.6s ease;
    overflow: hidden;
}

.story-overlay.active {
    opacity: 1;
    visibility: visible;
}

.story-background {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.05;
    filter: blur(8px) brightness(0.5);
}

.story-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2vh 3vw;
    z-index: 1001;
}

.story-text-container {
    max-width: 1400px;
    width: 95%;
    height: 90vh;
    max-height: 900px;
    text-align: center;
    background: rgba(20, 20, 30, 0.85);

    /* Hand-drawn border effect */
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;

    /* Apply distortion filter */
    filter: url(#distortionFilter);

    padding: 2.5rem 3rem;
    box-shadow:
            0 8px 32px rgba(0, 0, 0, 0.3),
            inset 0 0 20px rgba(255, 255, 255, 0.02);

    animation: storyContainerAppear 0.8s ease-out 0.2s both, handDrawnWobble 8s ease-in-out infinite;

    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    scroll-padding-bottom: 2rem;

    /* Hand-drawn appearance */
    position: relative;
    transform: rotate(-0.1deg);
}

/* Add hand-drawn border overlay */
.story-text-container::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 225px 25px 255px 25px/25px 255px 25px 225px;
    transform: rotate(0.3deg);
    z-index: -1;
}

/* Scrollbar personnalisée style hand-drawn */
.story-text-container::-webkit-scrollbar {
    width: 12px;
}

.story-text-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.story-text-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px 3px 8px 3px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.story-text-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.story-title {
    font-size: 2.8rem;
    font-weight: 700;
    font-family: 'Amatic SC', 'Kalam', cursive;
    color: rgba(255, 255, 255, 0.95);
    margin-bottom: 1.8rem;
    text-shadow:
            2px 2px 4px rgba(0, 0, 0, 0.5),
            -1px -1px 2px rgba(255, 255, 255, 0.1);
    opacity: 0;
    animation: storyTitleAppear 0.6s ease-out 0.5s both, handDrawnText 4s ease-in-out infinite;
    letter-spacing: 2px;
    line-height: 1.3;
    flex-shrink: 0;
    transform: rotate(-1deg) skewX(-2deg);
    filter: url(#distortionFilter);
}

/* Hand-drawn underline for title */
.story-title::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 20%;
    right: 20%;
    height: 3px;
    background: linear-gradient(90deg,
    transparent,
    rgba(255, 255, 255, 0.3) 20%,
    rgba(255, 255, 255, 0.5) 50%,
    rgba(255, 255, 255, 0.3) 80%,
    transparent
    );
    border-radius: 50% 20% 50% 20%;
    transform: rotate(-0.5deg);
}

.story-text {
    font-size: 1.5rem;
    line-height: 2.1;
    color: rgba(255, 255, 255, 0.85);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
    margin-bottom: 1rem;
    font-family: 'Caveat', 'Kalam', cursive;
    text-align: left;
    text-indent: 2em;
    position: relative;
    width: 100%;
    word-spacing: 0.15em;
    flex-grow: 1;
    min-height: 0;

    /* Hand-written appearance */
    transform: rotate(0.2deg);
    letter-spacing: 0.5px;
}

/* Espace supplémentaire après le contenu */
.story-text::after {
    content: '';
    display: block;
    height: 2rem;
}

/* Add slight rotation to paragraphs for organic feel */
.story-text p:nth-child(odd) {
    transform: rotate(-0.1deg);
}

.story-text p:nth-child(even) {
    transform: rotate(0.1deg);
}

/* Le curseur de machine à écrire (.typewriter-cursor) a été supprimé car non utilisé par le JS */

.story-close-button {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 1002;
    opacity: 0;
    animation: storyCloseButtonAppear 0.4s ease-out 1s both, handDrawnRotate 6s ease-in-out infinite;
    transform: rotate(-3deg);
    filter: url(#distortionFilter);
}

.story-close-button:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.1) rotate(5deg);
    border-radius: 225px 25px 255px 25px/25px 255px 25px 225px;
}

.story-close-button::before {
    content: '✕';
    font-size: 1.4rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 700;
    font-family: 'Kalam', cursive;
    transform: rotate(10deg);
}

/* Particles with hand-drawn feel */
.story-particles {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.story-particle {
    position: absolute;
    width: 3px;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 40% 60% 60% 40%;
    animation: storyParticleFloat 25s linear infinite;
    filter: url(#distortionFilter);
}

.story-particle:nth-child(2n) {
    background: rgba(255, 255, 255, 0.2);
    animation-duration: 30s;
    border-radius: 60% 40% 40% 60%;
}

.story-particle:nth-child(3n) {
    background: rgba(255, 255, 255, 0.15);
    animation-duration: 20s;
    width: 4px;
    height: 4px;
    border-radius: 30% 70% 70% 30%;
}

/* Les éléments décoratifs non utilisés (.story-image-mask, .story-decor-left, .story-decor-right) ont été supprimés. */

/* New animations for hand-drawn effect */
@keyframes handDrawnWobble {
    0%, 100% {
        transform: rotate(-0.1deg) translateY(0px);
        border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    }
    25% {
        transform: rotate(0.05deg) translateY(-0.2px);
        border-radius: 225px 25px 255px 25px/25px 255px 25px 225px;
    }
    50% {
        transform: rotate(-0.08deg) translateY(0.2px);
        border-radius: 245px 20px 235px 20px/20px 235px 20px 245px;
    }
    75% {
        transform: rotate(0.02deg) translateY(-0.1px);
        border-radius: 235px 18px 245px 18px/18px 245px 18px 235px;
    }
}

@keyframes handDrawnText {
    0%, 100% { transform: rotate(-1deg) skewX(-2deg) translateX(0px); }
    50% { transform: rotate(-0.5deg) skewX(-1deg) translateX(1px); }
}

@keyframes handDrawnRotate {
    0%, 100% { transform: rotate(-3deg); }
    33% { transform: rotate(2deg); }
    66% { transform: rotate(-1deg); }
}

/* Responsive */
@media (max-width: 768px) {
    .story-content {
        padding: 1vh 3vw 3vh 3vw;
    }

    .story-text-container {
        padding: 1.5rem 1.5rem 3rem 1.5rem;
        height: 85vh;
        max-height: calc(100vh - 4rem);
    }

    .story-title {
        font-size: 2.2rem;
        margin-bottom: 1rem;
    }

    .story-text {
        font-size: 1.3rem;
        line-height: 1.8;
        text-indent: 1.5em;
        padding-bottom: 2rem;
    }

    .story-close-button {
        top: 15px;
        right: 15px;
        width: 40px;
        height: 40px;
    }
}

/* Écrans très larges */
@media (min-width: 1920px) {
    .story-text-container {
        max-width: 1600px;
        padding: 3rem 4rem;
    }

    .story-text {
        font-size: 1.35rem;
        line-height: 2;
    }
}
