/* ==========================================================================
   RESET & VARIABLES THÈME POUDLARD / PUPITRE AUX BOUGIES
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-night: #0b0507;
    --bg-hall: #260e16;
    --parchment-light: #fcf3dc;
    --ink-dry: #2a1114;
    --gold-bright: #ffe89e;
    --gold-main: #d4af37;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-night);
    color: var(--parchment-light);
    font-family: 'Charm', cursive;
}

.svg-defs {
    position: absolute;
    pointer-events: none;
}

/* ==========================================================================
   ARRIÈRE-PLAN CHALEUREUX ÉCLAIRÉ AUX BOUGIES
   ========================================================================== */
.great-hall-bg {
    position: fixed;
    inset: 0;
    background:
        /* Lueur chaude venant du coin bas-gauche / table aux chandelles */
        radial-gradient(ellipse 70% 60% at 28% 78%, rgba(145, 72, 24, 0.24) 0%, transparent 65%),
        radial-gradient(ellipse 75% 55% at 52% 30%, rgba(108, 28, 48, 0.42) 0%, transparent 66%),
        radial-gradient(circle at 50% 50%, var(--bg-hall) 0%, var(--bg-night) 84%);
    z-index: 1;
    pointer-events: none;
}

.ambient-vignette {
    position: absolute;
    inset: 0;
    box-shadow: inset 0 0 140px rgba(0, 0, 0, 0.88);
}

.nebula-glow {
    position: absolute;
    inset: -15%;
    background: radial-gradient(circle at 48% 52%, rgba(212, 175, 55, 0.09), transparent 58%);
    animation: nebula-pulse 9s ease-in-out infinite alternate;
}

@keyframes nebula-pulse {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.1); opacity: 1; }
}

.candles-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.floating-candle {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: candle-float var(--dur, 7s) ease-in-out infinite alternate;
    animation-delay: var(--delay, 0s);
    opacity: var(--opacity, 0.75);
    filter: blur(var(--blur, 0px));
}

.candle-flame {
    width: 6px;
    height: 11px;
    border-radius: 50% 50% 45% 45%;
    background: radial-gradient(circle at 50% 70%, #ffffff 0%, #ffe680 45%, #ff9d2e 100%);
    box-shadow: 0 0 12px 4px rgba(255, 210, 96, 0.55), 0 0 28px 8px rgba(255, 166, 43, 0.25);
    animation: flicker 1.8s ease-in-out infinite alternate;
    transform-origin: bottom center;
}

.candle-body {
    width: 6px;
    height: var(--height, 26px);
    background: linear-gradient(180deg, #fff8e7 0%, #d9c69e 60%, rgba(217, 198, 158, 0.15) 100%);
    border-radius: 2px 2px 0 0;
}

@keyframes candle-float {
    0% { transform: translateY(0px) translateX(-3px); }
    100% { transform: translateY(-16px) translateX(4px); }
}

@keyframes flicker {
    0% { transform: scale(1) rotate(-2deg); opacity: 0.9; }
    50% { transform: scale(1.08, 0.94) rotate(2deg); opacity: 1; }
    100% { transform: scale(0.95, 1.07) rotate(-1deg); opacity: 0.85; }
}

#magic-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 60;
}

.sound-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 70;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid rgba(212, 175, 55, 0.35);
    background: rgba(24, 8, 13, 0.65);
    backdrop-filter: blur(6px);
    color: var(--gold-bright);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.sound-toggle:hover {
    transform: scale(1.08);
    border-color: var(--gold-bright);
    background: rgba(59, 10, 23, 0.85);
}

.sound-toggle .icon-sound-off { display: none; }
.sound-toggle.muted .icon-sound-on { display: none; }
.sound-toggle.muted .icon-sound-off { display: block; opacity: 0.65; }

/* ==========================================================================
   SCÈNE PRINCIPALE & EN-TÊTE
   ========================================================================== */
.scene-container {
    position: relative;
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    perspective: 1100px;
    z-index: 15;
}

.header-block {
    text-align: center;
    margin-bottom: 10px;
    transition: opacity 0.65s ease, transform 0.65s ease, max-height 0.65s ease, margin 0.65s ease;
    max-height: 120px;
    z-index: 20;
}

.header-subtitle {
    font-family: 'Charm', cursive;
    font-size: clamp(1.02rem, 3.2vw, 1.25rem);
    letter-spacing: 0.04em;
    color: rgba(249, 226, 156, 0.88);
    margin-bottom: 2px;
}

.header-title {
    font-family: 'Great Vibes', cursive;
    font-size: clamp(2.6rem, 8vw, 3.6rem);
    color: var(--gold-bright);
    font-weight: 400;
    text-shadow: 0 3px 20px rgba(212, 175, 55, 0.45);
}

.scene-container.opened .header-block {
    opacity: 0;
    transform: translateY(-28px) scale(0.94);
    max-height: 0;
    margin-bottom: 0;
    overflow: hidden;
    pointer-events: none;
}

/* ==========================================================================
   ÉTAT 1 : ROULEAU FERMÉ EN DIAGONALE 3D
   ========================================================================== */
.closed-scroll-wrapper {
    position: relative;
    width: min(94vw, 520px);
    cursor: pointer;
    z-index: 22;
    transform-style: preserve-3d;
    transition:
        transform 0.75s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity 0.55s ease;
}

.closed-scroll-wrapper:hover:not(.is-breaking) {
    transform: translate3d(0, -6px, 22px) scale(1.03);
}

.closed-scroll-levitation {
    position: relative;
    width: 100%;
    transform-style: preserve-3d;
    animation: closed-scroll-float 5s ease-in-out infinite;
}

@keyframes closed-scroll-float {
    0%, 100% {
        transform: translate3d(0px, 0px, 0px) rotateX(12deg) rotateY(8deg) rotateZ(-2deg);
    }
    50% {
        transform: translate3d(0px, -14px, 20px) rotateX(6deg) rotateY(3deg) rotateZ(1.5deg);
    }
}

.closed-scroll-halo {
    position: absolute;
    inset: 14% 12%;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(212, 175, 55, 0.26) 0%, rgba(168, 28, 44, 0.14) 48%, transparent 72%);
    filter: blur(22px);
    transform: translateZ(-30px);
    pointer-events: none;
}

.closed-scroll-svg {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
}

.ribbon-tails-anim {
    transform-origin: 250px 180px;
    animation: ribbon-sway 3.8s ease-in-out infinite alternate;
}

@keyframes ribbon-sway {
    0% { transform: rotate(-2deg); }
    100% { transform: rotate(2.8deg); }
}

.closed-seal-group {
    transform-origin: 278px 150px;
    transition: transform 0.35s ease, opacity 0.4s ease;
    animation: seal-glow-pulse 2.8s ease-in-out infinite;
}

@keyframes seal-glow-pulse {
    0%, 100% { filter: drop-shadow(0 6px 8px rgba(18, 2, 5, 0.65)); }
    50% { filter: drop-shadow(0 0 16px rgba(255, 215, 115, 0.58)); }
}

.seal-cracks-svg {
    opacity: 0;
    filter: drop-shadow(0 0 8px #ffea99);
    transition: opacity 0.15s ease;
}

.closed-scroll-wrapper.seal-cracking .seal-cracks-svg {
    opacity: 1;
}

.closed-ribbon-group,
.closed-ribbon-back {
    transform-origin: 280px 155px;
    transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.45s ease;
}

.closed-scroll-wrapper.is-breaking .closed-seal-group {
    animation: none;
    transform: scale(1.45) rotate(14deg);
    opacity: 0;
}

.closed-scroll-wrapper.is-breaking .closed-ribbon-group,
.closed-scroll-wrapper.is-breaking .closed-ribbon-back {
    transform: scale(1.22) translateY(-10px);
    opacity: 0;
}

.closed-scroll-wrapper.morphing-to-open {
    transform: translate3d(0, -165px, 10px) rotateZ(-14deg) scale(0.9);
    opacity: 0;
    pointer-events: none;
}

.scene-container.scroll-unrolling .closed-scroll-wrapper,
.scene-container.scroll-open .closed-scroll-wrapper {
    position: absolute;
    pointer-events: none;
}

.closed-floor-shadow {
    width: 66%;
    height: 22px;
    margin: -10px auto 0;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(0, 0, 0, 0.82) 0%, transparent 72%);
    filter: blur(9px);
    transform: rotate(16deg) translateZ(-45px);
    animation: floor-shadow-float 5s ease-in-out infinite;
}

@keyframes floor-shadow-float {
    0%, 100% { transform: rotate(16deg) scale(1); opacity: 0.78; }
    50% { transform: rotate(18deg) scale(0.84); opacity: 0.44; }
}

.hint-text {
    margin-top: 12px;
    font-family: 'Charm', cursive;
    font-size: clamp(1.06rem, 3.5vw, 1.24rem);
    letter-spacing: 0.03em;
    color: var(--gold-bright);
    text-align: center;
    animation: hint-fade 2.5s ease-in-out infinite;
    transition: opacity 0.45s ease, max-height 0.45s ease, margin 0.45s ease;
    max-height: 60px;
}

.scene-container.opened .hint-text {
    opacity: 0;
    max-height: 0;
    margin-top: 0;
    overflow: hidden;
    pointer-events: none;
}

@keyframes hint-fade {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 0.96; }
}

/* ==========================================================================
   ÉTAT 2 : PARCHEMIN POSÉ SUR UNE TABLE INCLINÉE, VU DU COIN BAS-GAUCHE
   ========================================================================== */
.open-perspective-stage {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 18px;
    /* Perspective photographique réaliste façon pupitre / table inclinée devant soi */
    perspective: 920px;
    /* Point de fuite décalé pour simuler notre position au coin bas-gauche */
    perspective-origin: 34% 76%;
    pointer-events: none;
    opacity: 0;
    z-index: 25;
    transition: opacity 0.4s ease;
}

.scene-container.scroll-unrolling .open-perspective-stage,
.scene-container.scroll-open .open-perspective-stage {
    opacity: 1;
    pointer-events: auto;
}

/* Inclinaison 3D :
   - rotateX positif (+20deg) : posé sur un plan incliné vers l'arrière (le bas est proche de nous, le haut s'éloigne)
   - rotateY positif (+11deg) : on se tient vers la gauche, donc le bord gauche est plus proche que le bord droit
   - rotateZ négatif (-4.5deg) : posé légèrement en biais naturel sur la table devant le coin bas-gauche */
.parchment-3d-rig {
    --rx: 20deg;
    --ry: 11deg;
    --rz: -4.5deg;
    position: relative;
    width: min(88vw, 495px);
    transform-style: preserve-3d;
    transform-origin: 38% 62%;
    transform:
        rotateX(var(--rx))
        rotateY(var(--ry))
        rotateZ(var(--rz));
    transition: transform 0.28s ease-out;
    animation: gentle-magic-hover 6.5s ease-in-out infinite;
}

@keyframes gentle-magic-hover {
    0%, 100% {
        translate: 0px 2px 0px;
    }
    50% {
        translate: 0px -6px 10px;
    }
}

/* Ombre portée réaliste sur la table inclinée sous le parchemin */
.parchment-table-shadow {
    position: absolute;
    inset: 18px -18px -22px 18px;
    border-radius: 20px;
    background: radial-gradient(ellipse at 50% 50%, rgba(3, 1, 2, 0.9) 25%, rgba(5, 2, 3, 0.55) 70%, transparent 100%);
    filter: blur(22px);
    transform: translateZ(-42px);
    opacity: 0;
    transition: opacity 0.9s ease;
    pointer-events: none;
}

.scene-container.scroll-unrolling .parchment-table-shadow,
.scene-container.scroll-open .parchment-table-shadow {
    opacity: 1;
}

/* Structure complète du parchemin déroulé : [volute haut] + [feuille] + [volute bas] */
.unrolled-scroll {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform-style: preserve-3d;
}

/* Volutes cylindriques haute et basse (plus larges que la feuille, comme un vrai parchemin) */
.scroll-roll {
    position: relative;
    width: 108%;
    z-index: 8;
    pointer-events: none;
    flex-shrink: 0;
}

.roll-svg {
    width: 100%;
    display: block;
    filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.55));
}

.scroll-roll-top {
    height: 44px;
    margin-bottom: -10px;
    transform: translateZ(10px);
}

.scroll-roll-bottom {
    height: 48px;
    margin-top: -10px;
    transform: translateZ(14px);
}

/* Feuille centrale qui se déroule de 0 à sa pleine hauteur en poussant la volute du bas devant elle ! */
.parchment-sheet-wrap {
    position: relative;
    width: 100%;
    max-height: 0;
    opacity: 0.4;
    overflow: hidden;
    transition:
        max-height 1.45s cubic-bezier(0.22, 1, 0.36, 1),
        opacity 0.45s ease;
}

.scene-container.scroll-unrolling .parchment-sheet-wrap,
.scene-container.scroll-open .parchment-sheet-wrap {
    max-height: 76dvh;
    opacity: 1;
}

/* Fond SVG de la feuille aux bords crantés */
.sheet-bg-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 1;
    pointer-events: none;
}

/* Texture fibreuse de vélin */
.vellum-texture-layer {
    position: absolute;
    inset: 4px 16px;
    background: #f8ebd0;
    filter: url(#vellum-grain);
    opacity: 0.25;
    pointer-events: none;
    z-index: 2;
}

/* Cadre intérieur fin & filigrane */
.parchment-ornaments {
    position: absolute;
    inset: 16px 26px;
    border: 1px solid rgba(150, 106, 26, 0.34);
    border-radius: 3px;
    pointer-events: none;
    z-index: 3;
}

.corner {
    position: absolute;
    width: 14px;
    height: 14px;
    border-color: rgba(145, 102, 18, 0.6);
    border-style: solid;
}

.corner-tl { top: 4px; left: 4px; border-width: 2px 0 0 2px; }
.corner-tr { top: 4px; right: 4px; border-width: 2px 2px 0 0; }
.corner-bl { bottom: 4px; left: 4px; border-width: 0 0 2px 2px; }
.corner-br { bottom: 4px; right: 4px; border-width: 0 2px 2px 0; }

.parchment-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.075;
}

/* Contenu intérieur de la feuille : marges confortables pour que rien ne soit jamais coupé */
.parchment-scroll-inner {
    position: relative;
    z-index: 4;
    max-height: 74dvh;
    padding: clamp(18px, 3.2vh, 26px) clamp(32px, 6vw, 46px) clamp(20px, 3.4vh, 28px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.parchment-scroll-inner::-webkit-scrollbar {
    width: 4px;
}

.parchment-scroll-inner::-webkit-scrollbar-thumb {
    background: rgba(156, 112, 20, 0.4);
    border-radius: 4px;
}

/* ==========================================================================
   TEXTE MANUSCRIT CALIBRÉ POUR TENIR ENTIÈREMENT SANS COUPURE
   ========================================================================== */
.letter-crest-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 6px;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.letter-crest-header.visible {
    opacity: 1;
    transform: translateY(0);
}

.crest-line {
    flex: 1;
    max-width: 70px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(145, 102, 18, 0.58), transparent);
}

.crest-star {
    font-size: 0.72rem;
    letter-spacing: 0.28em;
    color: #916612;
}

.letter-content {
    color: var(--ink-dry);
    font-family: 'Charm', cursive;
    font-size: clamp(1.04rem, 2.35vh, 1.24rem);
    line-height: 1.44;
    font-weight: 400;
    text-align: left;
    margin-bottom: 8px;
}

.salutation {
    font-family: 'Great Vibes', cursive;
    font-size: clamp(1.7rem, 4.2vh, 2.18rem);
    color: #6b1529;
    font-weight: 400;
    line-height: 1.2;
    margin-bottom: 6px;
    min-height: 1.2em;
}

.main-text {
    white-space: pre-wrap;
    min-height: 6.5em;
}

.signature {
    font-family: 'Great Vibes', cursive;
    font-size: clamp(1.65rem, 4vh, 2.1rem);
    color: #6b1529;
    font-weight: 400;
    text-align: right;
    margin-top: 8px;
    min-height: 1.2em;
}

.ink-char {
    display: inline;
    animation: ink-absorb 0.48s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes ink-absorb {
    0% {
        opacity: 0;
        color: #d49b1a;
        text-shadow: 0 0 10px rgba(242, 196, 77, 0.9);
    }
    45% {
        opacity: 1;
        color: #8f5614;
        text-shadow: 0 0 6px rgba(212, 175, 55, 0.45);
    }
    100% {
        opacity: 1;
        color: inherit;
        text-shadow: none;
    }
}

.ink-cursor {
    display: inline-block;
    width: 1px;
    height: 0.9em;
    vertical-align: baseline;
    pointer-events: none;
}

/* ==========================================================================
   PLUME DORÉE QUI ÉCRIT EN DIRECT
   ========================================================================== */
.quill-pen {
    position: fixed;
    top: 0;
    left: 0;
    width: 92px;
    height: 92px;
    pointer-events: none;
    z-index: 55;
    opacity: 0;
    transform-origin: 3px 90px;
    will-change: transform, opacity;
    transition: opacity 0.35s ease;
}

.quill-pen.visible {
    opacity: 1;
}

.quill-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(5px 12px 8px rgba(22, 9, 4, 0.45));
}

.quill-shadow {
    position: absolute;
    left: 4px;
    bottom: -2px;
    width: 22px;
    height: 7px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(44, 19, 22, 0.42) 0%, transparent 72%);
    transform: translate(-50%, 50%);
}

/* ==========================================================================
   PIED DE PARCHEMIN DÉGAGÉ : L'OURS VINCENNES
   ========================================================================== */
.restaurant-footer {
    opacity: 0;
    transform: translateY(10px);
    filter: blur(3px);
    transition: opacity 1.2s ease, transform 1.1s ease, filter 1.1s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid rgba(154, 112, 32, 0.4);
}

.restaurant-footer.visible {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
}

.marauder-banner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.marauder-caption {
    font-family: 'Charm', cursive;
    font-size: 0.92rem;
    letter-spacing: 0.03em;
    color: #856217;
}

.bear-emblem {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bear-title {
    font-family: 'Great Vibes', cursive;
    font-size: clamp(1.52rem, 3.8vh, 1.9rem);
    font-weight: 400;
    letter-spacing: 0.02em;
    color: #5c3f06;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.replay-btn {
    margin-top: 8px;
    background: rgba(107, 21, 41, 0.08);
    border: 1px solid rgba(107, 21, 41, 0.35);
    color: #6b1529;
    font-family: 'Charm', cursive;
    font-size: 0.9rem;
    letter-spacing: 0.03em;
    padding: 4px 18px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.replay-btn:hover {
    background: #6b1529;
    color: #fcf6e6;
    box-shadow: 0 4px 14px rgba(107, 21, 41, 0.3);
}

@media (max-width: 520px) {
    .quill-pen {
        width: 74px;
        height: 74px;
        transform-origin: 2px 72px;
    }

    .parchment-3d-rig {
        --rx: 16deg;
        --ry: 8deg;
        --rz: -3deg;
        width: 91vw;
    }

    .scroll-roll-top {
        height: 36px;
        margin-bottom: -8px;
    }

    .scroll-roll-bottom {
        height: 40px;
        margin-top: -8px;
    }

    .parchment-ornaments {
        inset: 12px 20px;
    }

    .parchment-scroll-inner {
        padding: 16px 24px 18px;
    }
}
