/* ============================
   Fichier : cosmos.css
   Description : effets « Roar Cosmos » communs aux pages :
   orbite autour du curseur, apparition des sections au scroll,
   trajectoire du vaisseau (séparation hero / à propos) et constellations.
   Tout s'efface avec prefers-reduced-motion.
   ============================ */

/* ============================================ */
/* ORBITE AUTOUR DU CURSEUR                     */
/* ============================================ */

/* Ornement « orbite » de la charte : ellipse inclinée à -18° + petite planète.
   Or sur la nuit, améthyste sur la lune (classe posée en JS). Le vrai curseur reste visible. */
.cursor-orbit {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 3000;
    width: 64px;
    height: 64px;
    margin: -32px 0 0 -32px;
    pointer-events: none;
    color: var(--amethyste);
    opacity: 0;
    transition: opacity 0.3s ease, color 0.3s ease;
    will-change: transform;
}

.cursor-orbit.is-active { opacity: 1; }
.cursor-orbit.is-nuit   { color: var(--or); }

.cursor-orbit svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Au survol d'un élément cliquable, l'orbite s'élargit */
.cursor-orbit.is-hover svg { transform: scale(1.45); }

.cursor-orbit__ring {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.2;
    stroke-dasharray: 2 4;
    stroke-linecap: round;
    opacity: 0.55;
}

.cursor-orbit__planet { fill: currentColor; }

/* ============================================ */
/* APPARITION DES SECTIONS                      */
/* ============================================ */

/* La classe .fx-reveal n'est posée qu'en JS : sans JS, tout reste visible.
   `translate` (et non `transform`) pour ne pas gêner les survols des cartes. */
.fx-ready .fx-reveal {
    opacity: 0;
    translate: 0 28px;
    transition:
        opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1),
        translate 0.8s cubic-bezier(0.22, 1, 0.36, 1);
    transition-delay: calc(var(--fx-i, 0) * 90ms);
}

.fx-ready .fx-reveal.is-visible {
    opacity: 1;
    translate: 0 0;
}

/* Hero : entrée en cascade au chargement */
.fx-ready .hero .rc-hero__grid > div:first-child > *,
.fx-ready .hero .rc-hero__art {
    animation: fxRise 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.fx-ready .hero .rc-hero__grid > div:first-child > :nth-child(2) { animation-delay: 0.1s; }
.fx-ready .hero .rc-hero__grid > div:first-child > :nth-child(3) { animation-delay: 0.2s; }
.fx-ready .hero .rc-hero__grid > div:first-child > :nth-child(4) { animation-delay: 0.3s; }
.fx-ready .hero .rc-hero__art { animation-delay: 0.25s; animation-duration: 1.2s; }

@keyframes fxRise {
    from { opacity: 0; translate: 0 24px; }
    to   { opacity: 1; translate: 0 0; }
}

/* ============================================ */
/* TRAJECTOIRE DU VAISSEAU (hero → à propos)    */
/* ============================================ */

/* Bas du hero : la courbe sert de séparation avec la section lune suivante.
   Sous la ligne, un aplat lune ; sur la ligne, les pointillés or et le vaisseau. */
.space-route {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    height: 120px;
    pointer-events: none;
}

.space-route__path {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.space-route__ground {
    fill: var(--lune);
}

.space-route__line {
    fill: none;
    stroke: none;
}

/* Les points sont posés un à un en JS, à espacement fixe à l'écran :
   ils restent ronds quelle que soit la largeur de la page */
.space-route__dots {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.space-route__dots circle { fill: var(--or); }

/* Étoiles 4 branches posées le long de la route */
.space-route__spark {
    position: absolute;
    width: 14px;
    height: 14px;
    fill: var(--lavande);
    animation: fxTwinkle 4s ease-in-out infinite;
}

.space-route__spark--or { fill: var(--or); width: 18px; height: 18px; }

/* Le vaisseau pixel : positionné et orienté en JS le long de la courbe */
.space-ship {
    position: absolute;
    top: 0;
    left: 0;
    width: 80px;
    height: 55px;
    margin: -27.5px 0 0 -40px;
    will-change: transform;
}

.space-ship svg {
    display: block;
    width: 100%;
    height: 100%;
    /* Contour nuit d'un pixel : le vaisseau reste lisible à cheval sur la nuit et la lune */
    filter:
        drop-shadow(3px 0 0 var(--nuit))
        drop-shadow(-3px 0 0 var(--nuit))
        drop-shadow(0 3px 0 var(--nuit))
        drop-shadow(0 -3px 0 var(--nuit));
}

.space-ship__body   { fill: var(--lune); }
.space-ship__fin    { fill: var(--lavande); }
.space-ship__stripe { fill: var(--amethyste); }
.space-ship__window { fill: var(--nuit); }
.space-ship__glint  { fill: var(--lavande); }
.space-ship__flame  { fill: var(--or); }

.space-ship__flame--tip {
    animation: fxFlame 0.24s steps(1) infinite;
}

@keyframes fxFlame {
    50% { opacity: 0; }
}

/* ============================================ */
/* CONSTELLATIONS                               */
/* ============================================ */

/* Ornement au trait : améthyste sur la lune, or sur la nuit. Jamais derrière du texte :
   on les place dans les marges des sections et on les masque quand la place manque. */
.constellation {
    position: absolute;
    z-index: 0;
    pointer-events: none;
    color: var(--amethyste);
}

[data-theme="nuit"] .constellation { color: var(--or); }

.constellation svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.constellation__lines {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-dasharray: 2 6;
    stroke-linecap: round;
    stroke-opacity: 0.55;
    vector-effect: non-scaling-stroke;
}

.constellation__star {
    fill: currentColor;
    transform-box: fill-box;
    transform-origin: center;
}

/* Étoile la plus brillante : étoile 4 branches */
.constellation__spark { fill: var(--or); transform-box: fill-box; transform-origin: center; }
[data-theme="lune"] .constellation__spark { fill: var(--amethyste); }

/* Silhouette du dino en filigrane (constellation « dino ») */
.constellation__ghost { fill: currentColor; opacity: 0.1; }

/* Apparition : les traits se dessinent, puis les étoiles s'allument une à une */
.fx-ready .constellation .constellation__lines {
    stroke-dashoffset: 0;
    opacity: 0;
    transition: opacity 1.2s ease 0.2s;
}

.fx-ready .constellation .constellation__star,
.fx-ready .constellation .constellation__spark {
    opacity: 0;
    scale: 0;
    transition: opacity 0.5s ease, scale 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition-delay: calc(var(--fx-i, 0) * 120ms + 0.3s);
}

.fx-ready .constellation.is-visible .constellation__lines {
    opacity: 1;
    animation: fxDrift 6s linear infinite;
}

.fx-ready .constellation.is-visible .constellation__star,
.fx-ready .constellation.is-visible .constellation__spark {
    opacity: 1;
    scale: 1;
}

.fx-ready .constellation.is-visible .constellation__star {
    animation: fxTwinkle 3.6s ease-in-out infinite;
    animation-delay: calc(var(--fx-i, 0) * -0.7s);
}

/* Les pointillés glissent doucement le long des traits */
@keyframes fxDrift {
    to { stroke-dashoffset: -32; }
}

@keyframes fxTwinkle {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.45; }
}

/* ============================================ */
/* MOUVEMENT RÉDUIT                             */
/* ============================================ */

@media (prefers-reduced-motion: reduce) {
    .cursor-orbit { display: none; }

    .fx-ready .fx-reveal,
    .fx-ready .constellation .constellation__lines,
    .fx-ready .constellation .constellation__star,
    .fx-ready .constellation .constellation__spark {
        opacity: 1 !important;
        translate: none !important;
        scale: none !important;
        transition: none !important;
        animation: none !important;
    }

    .fx-ready .hero .rc-hero__grid > div:first-child > *,
    .fx-ready .hero .rc-hero__art,
    .space-route__spark,
    .space-ship__flame--tip {
        animation: none;
    }
}

/* Pas d'orbite sur les écrans tactiles */
@media (hover: none), (pointer: coarse) {
    .cursor-orbit { display: none; }
}
