/* ============================================================
   QreaLAB V01 — gatekeeper.css
   ------------------------------------------------------------
   L'écran d'initialisation.

   ── Ce qu'on ne fait PAS ───────────────────────────────────
   Pas de lignes de balayage, pas de courbure d'écran, pas de bruit
   analogique, pas de décalage chromatique. L'installation n'est pas
   vieille : elle est simplement éteinte. Le fond doit rester
   qualitatif et moderne.

   ── Pilotage ───────────────────────────────────────────────
   Le JS n'ajoute que des classes de phase (p0 → p4) sur #gatekeeper.
   Toute la mise en scène est ici : une phase = une règle. C'est ce
   qui permet de retoucher le rythme sans toucher au JS.
   ============================================================ */

.gate {
    position: fixed;
    inset: 0;
    z-index: var(--z-gatekeeper);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-lg);
    padding: var(--space-xl) var(--space-lg);
    /* Presque éteint. Le dégradé très large suggère une source
       lointaine plutôt qu'un fond décoratif. */
    background:
        radial-gradient(140% 110% at 50% 44%,
            #070b12 0%,
            #04060b 42%,
            #010205 100%);
    /* Le seul texte du gatekeeper est du texte système. */
    font-family: var(--font-mono);
}

.gate.is-active {
    display: flex;
}

.gate.is-gone {
    display: none;
}

/* Sortie : l'écran s'écarte très légèrement de l'œil. Le flash
   couvre l'essentiel, ce mouvement n'est qu'un appui. */
.gate.is-leaving {
    animation: gate-leave 460ms var(--ease-out) forwards;
}

@keyframes gate-leave {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(1.06); }
}

/* ══════════════════════════════════════════════════════════
   PHASE 0 — le fond
   ══════════════════════════════════════════════════════════ */

.gate__backdrop {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.gate-shape {
    position: absolute;
    opacity: 0;
    /* « Cherchent leur position » : elles arrivent d'un très léger
       décalage, jamais d'un mouvement spectaculaire. */
    transform: translate(6px, -4px);
    transition:
        opacity 1.4s var(--ease-out) var(--delay, 0s),
        transform 1.8s var(--ease-out) var(--delay, 0s);
}

.gate.p0 .gate-shape {
    opacity: 1;
    transform: translate(0, 0);
}

.gate-shape--rect {
    border: 1px solid rgba(150, 180, 200, 0.05);
    border-radius: var(--radius-sm);
    background: linear-gradient(150deg, rgba(150, 180, 200, 0.016), transparent);
}

.gate-shape--line {
    height: 1px;
    background: linear-gradient(90deg,
        rgba(150, 180, 200, 0) 0%,
        rgba(150, 180, 200, 0.1) 40%,
        rgba(150, 180, 200, 0) 100%);
}

.gate-shape--ring {
    border: 1px solid rgba(150, 180, 200, 0.045);
    border-radius: 50%;
}

/* Micro-clignotements : c'est le seul « défaut » autorisé, et il
   reste propre — une variation d'opacité, rien d'autre. */
.gate-shape--dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: rgba(160, 200, 220, 0.5);
}

.gate.p0 .gate-shape--dot {
    animation: gate-flicker 4.2s steps(1, end) infinite;
    animation-delay: var(--delay, 0s);
}

@keyframes gate-flicker {
    0%, 40% { opacity: 0.5; }
    41%, 43% { opacity: 0.06; }
    44%, 72% { opacity: 0.7; }
    73%, 74% { opacity: 0.1; }
    75%, 100% { opacity: 0.4; }
}

/* Variation générale de luminosité : l'alimentation n'est pas encore
   stable. S'arrête dès que le Q est stabilisé. */
.gate.p0::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(90% 80% at 50% 46%, rgba(120, 170, 200, 0.03), transparent 70%);
    animation: gate-power 3.4s var(--ease-in-out) infinite;
}

.gate.p2-stable::after {
    animation: none;
    opacity: 0.6;
}

@keyframes gate-power {
    0%, 100% { opacity: 0.35; }
    30% { opacity: 1; }
    52% { opacity: 0.5; }
    68% { opacity: 0.9; }
}

/* ══════════════════════════════════════════════════════════
   ALLUMAGE — l'écran s'allume physiquement
   ══════════════════════════════════════════════════════════
   Avant le journal de démarrage : une ligne de lumière traverse
   le champ, s'étire, puis se diffuse. Pas un effet CRT — une
   montée en puissance propre, comme un éclairage qui revient.
   ══════════════════════════════════════════════════════════ */

.gate__wake {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 1;
    width: 100%;
    height: 2px;
    transform: translate(-50%, -50%) scaleX(0);
    background: linear-gradient(90deg,
        rgba(243, 249, 255, 0) 0%,
        rgba(228, 248, 255, 0.95) 50%,
        rgba(243, 249, 255, 0) 100%);
    box-shadow:
        0 0 26px rgba(95, 232, 255, 0.55),
        0 0 80px rgba(95, 232, 255, 0.28);
    opacity: 0;
    pointer-events: none;
}

.gate.wake .gate__wake {
    animation: gate-wake 1.15s var(--ease-out) forwards;
}

@keyframes gate-wake {
    0% { opacity: 0; transform: translate(-50%, -50%) scaleX(0); }
    16% { opacity: 1; }
    52% { opacity: 0.95; transform: translate(-50%, -50%) scaleX(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scaleX(1) scaleY(26); }
}

/* La montée en lumière qui accompagne la ligne : la variation
   d'alimentation de P0 se stabilise une fois l'allumage joué. */
.gate.wake::after {
    animation: none;
    opacity: 0.85;
}

/* ══════════════════════════════════════════════════════════
   MISE EN PAGE
   ══════════════════════════════════════════════════════════ */

.gate__stage {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
    width: 100%;
    max-width: 560px;
    text-align: center;
}

/* ══════════════════════════════════════════════════════════
   PHASE 1 — le journal de démarrage
   ══════════════════════════════════════════════════════════ */

.gate__boot {
    /* Hauteur réservée : sans elle, l'ajout de chaque ligne
       déplacerait tout le reste de la composition. */
    min-height: 150px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 5px;
    text-align: left;
    opacity: 0;
    transition: opacity var(--t-normal) var(--ease-out);
}

.gate.p1 .gate__boot {
    opacity: 1;
}

/* Le log s'estompe légèrement pendant que le Q prend sa place, mais
   il reste lisible : l'activité du système ne doit pas disparaître
   d'un coup quand le Q apparaît. */
.gate.p2 .gate__boot {
    opacity: 0.4;
    transition: opacity var(--t-slow) var(--ease-out);
}

.gate.p3-online .gate__boot {
    opacity: 0.4;
}

.gate-boot__line {
    font-size: var(--fs-xs);
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

.gate-boot__line::before {
    content: '> ';
    color: var(--signal-dim);
}

/* Les lignes « mémoire… partielle » et « signature inconnue »
   sont volontairement moins lisibles : le système lui-même n'en
   fait pas grand cas. */
.gate-boot__line.is-dim {
    color: var(--text-dim);
}

.gate-boot__cursor {
    display: inline-block;
    width: 7px;
    height: 1em;
    margin-left: 2px;
    background: var(--signal);
    vertical-align: text-bottom;
    animation: gate-caret 1s steps(1, end) infinite;
}

@keyframes gate-caret {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* ══════════════════════════════════════════════════════════
   PHASE 2 — le Q
   ══════════════════════════════════════════════════════════ */

.gate__core {
    position: relative;
    width: 190px;
    height: 190px;
    display: grid;
    place-items: center;
}

.gate__core-halo {
    position: absolute;
    width: 460px;
    height: 460px;
    border-radius: 50%;
    background: radial-gradient(50% 50% at 50% 50%,
        rgba(243, 249, 255, 0.1) 0%,
        rgba(95, 232, 255, 0.055) 34%,
        rgba(169, 112, 255, 0.028) 58%,
        rgba(0, 0, 0, 0) 100%);
    opacity: 0;
    transition: opacity 1.1s var(--ease-out);
}

/* Deux halos de couleur décalés : la signature spectrale du Q est
   présente dès le gatekeeper, discrètement. */
.gate__core-halo--cyan {
    width: 340px;
    height: 340px;
    transform: translate(-34px, 22px);
    background: radial-gradient(50% 50% at 50% 50%,
        rgba(95, 232, 255, 0.14) 0%,
        rgba(95, 232, 255, 0.04) 42%,
        rgba(0, 0, 0, 0) 100%);
}

.gate__core-halo--violet {
    width: 340px;
    height: 340px;
    transform: translate(34px, -22px);
    background: radial-gradient(50% 50% at 50% 50%,
        rgba(169, 112, 255, 0.12) 0%,
        rgba(169, 112, 255, 0.035) 42%,
        rgba(0, 0, 0, 0) 100%);
}

.gate.p2 .gate__core-halo { opacity: 0.5; }
.gate.p2-stable .gate__core-halo { opacity: 0.8; }

.gate__core-ring {
    position: absolute;
    border: 1px solid rgba(95, 232, 255, 0.2);
    border-radius: 50%;
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 900ms var(--ease-out), transform 900ms var(--ease-out);
}

.gate__core-ring--a { width: 190px; height: 190px; }
.gate__core-ring--b {
    width: 132px;
    height: 132px;
    border-style: dashed;
    border-color: rgba(169, 112, 255, 0.24);
}

.gate.p2 .gate__core-ring {
    opacity: 1;
    transform: scale(1);
}

.gate.p2-stable .gate__core-ring--a { animation: ring-spin 40s linear infinite; }
.gate.p2-stable .gate__core-ring--b { animation: ring-spin 26s linear infinite reverse; }

/* Le logo. Apparition en deux temps : il se dessine (p2), puis il
   se stabilise et prend sa pleine intensité (p2-stable). Couleurs
   d'origine du fichier ; la lumière est portée par les halos et
   les ombres portées. */
.gate__logo {
    position: relative;
    width: 96px;
    height: auto;
    opacity: 0;
    transform: scale(0.86);
    filter: brightness(1.04) saturate(1);
    transition:
        opacity 900ms var(--ease-out),
        transform 900ms var(--ease-out),
        filter 900ms var(--ease-out);
}

.gate.p2 .gate__logo {
    opacity: 0.7;
    transform: scale(1);
}

.gate.p2-stable .gate__logo {
    opacity: 1;
    /* Intensité contenue : le Q reste le point focal, mais une lumière
       élégante plutôt qu'un éclat agressif. */
    filter:
        brightness(1.02) saturate(1)
        drop-shadow(0 0 8px rgba(200, 245, 255, 0.6))
        drop-shadow(0 0 22px rgba(95, 232, 255, 0.45))
        drop-shadow(0 0 52px rgba(169, 112, 255, 0.34));
    animation: gate-logo-glow 4.2s var(--ease-in-out) infinite;
}

/* La lumière du Q respire : le symbole n'est jamais tout à fait
   au repos. */
@keyframes gate-logo-glow {
    0%, 100% {
        filter:
            brightness(1.02) saturate(1)
            drop-shadow(0 0 8px rgba(200, 245, 255, 0.6))
            drop-shadow(0 0 22px rgba(95, 232, 255, 0.45))
            drop-shadow(0 0 52px rgba(169, 112, 255, 0.34));
    }
    50% {
        filter:
            brightness(1.06) saturate(1.04)
            drop-shadow(0 0 12px rgba(220, 250, 255, 0.72))
            drop-shadow(0 0 32px rgba(95, 232, 255, 0.58))
            drop-shadow(0 0 68px rgba(169, 112, 255, 0.46));
    }
}

/* ══════════════════════════════════════════════════════════
   PHASE 3 — les états système
   ══════════════════════════════════════════════════════════ */

.gate__states {
    display: flex;
    flex-direction: column;
    gap: var(--space-2xs);
    min-height: 52px;
}

.gate__state {
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    letter-spacing: var(--ls-wide);
    color: var(--text-bright);
    opacity: 0;
    transform: translateY(4px);
    transition: opacity var(--t-slow) var(--ease-out), transform var(--t-slow) var(--ease-out);
}

.gate__state--operator {
    color: var(--signal);
}

.gate.p3-online .gate__state--online,
.gate.p3-operator .gate__state--operator {
    opacity: 1;
    transform: translateY(0);
}

/* ══════════════════════════════════════════════════════════
   PHASE 4 — la commande
   ══════════════════════════════════════════════════════════
   Une commande de l'installation, pas un bouton marketing : pas de
   fond plein, pas de coins arrondis généreux, pas d'ombre portée.
   ══════════════════════════════════════════════════════════ */

.gate__command {
    position: relative;
    padding: var(--space-sm) var(--space-lg);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    letter-spacing: var(--ls-wide);
    text-transform: uppercase;
    color: var(--text-bright);
    background: rgba(88, 210, 238, 0.05);
    border: 1px solid var(--line-signal);
    border-radius: var(--radius-xs);
    opacity: 0;
    transform: translateY(6px);
    transition:
        opacity var(--t-slow) var(--ease-out),
        transform var(--t-slow) var(--ease-out),
        background var(--t-fast) var(--ease-out),
        border-color var(--t-fast) var(--ease-out);
}

.gate__command.is-hidden {
    pointer-events: none;
}

.gate.p4 .gate__command {
    opacity: 1;
    transform: translateY(0);
}

.gate__command::before {
    content: '> ';
    color: var(--signal);
}

/* Une respiration très discrète une fois la commande affichée :
   elle reste une commande de l'installation, pas un bouton marketing. */
.gate.p4 .gate__command {
    animation: gate-command-breathe 5s var(--ease-in-out) 1.4s infinite;
}

@keyframes gate-command-breathe {
    0%, 100% {
        background: rgba(88, 210, 238, 0.05);
        border-color: var(--line-signal);
    }
    50% {
        background: rgba(88, 210, 238, 0.09);
        border-color: rgba(88, 210, 238, 0.34);
    }
}

.gate__command:hover,
.gate__command:focus-visible {
    background: rgba(88, 210, 238, 0.13);
    border-color: rgba(88, 210, 238, 0.55);
    box-shadow: 0 0 18px rgba(95, 232, 255, 0.14);
}

/* Réaction nette au clic : la commande s'enfonce brièvement, comme
   un contact physique avec l'installation. */
.gate__command:active {
    transform: translateY(7px) scale(0.985);
    background: rgba(88, 210, 238, 0.2);
    border-color: rgba(95, 232, 255, 0.7);
    transition-duration: 60ms;
}

/* ══════════════════════════════════════════════════════════
   LANGUE
   ══════════════════════════════════════════════════════════ */

.gate__lang {
    position: absolute;
    right: calc(var(--space-lg) + var(--safe-right));
    top: calc(var(--space-lg) + var(--safe-top));
    z-index: 3;
    font-family: var(--font-mono);
    font-size: var(--fs-2xs);
    letter-spacing: var(--ls-label);
    color: var(--text-dim);
    opacity: 0;
    transition: opacity var(--t-slow) var(--ease-out), color var(--t-fast) var(--ease-out);
}

.gate.p1 .gate__lang {
    opacity: 1;
}

.gate.is-quiet .gate__lang {
    opacity: 0;
}

.gate__lang:hover,
.gate__lang:focus-visible {
    color: var(--signal);
}

/* ══════════════════════════════════════════════════════════
   PHASE 5 — le flash de bascule
   ══════════════════════════════════════════════════════════
   Il ne sert pas à impressionner : il masque l'instant où le monde
   devient visible. On ne voit donc jamais la scène « apparaître ».
   ══════════════════════════════════════════════════════════ */

.gate-flash {
    position: fixed;
    inset: 0;
    z-index: var(--z-flash);
    background: #dff2fa;
    opacity: 0;
    pointer-events: none;
}

.gate-flash.is-firing {
    opacity: 0.92;
    transition: opacity 90ms linear;
}

.gate-flash.is-fading {
    opacity: 0;
    transition: opacity 400ms var(--ease-out);
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
    .gate {
        gap: var(--space-md);
        padding: var(--space-lg) var(--space-md);
    }

    .gate__stage {
        max-width: none;
        gap: var(--space-md);
    }

    .gate__boot {
        min-height: 128px;
    }

    .gate-boot__line {
        font-size: var(--fs-2xs);
    }

    .gate__core {
        width: 140px;
        height: 140px;
    }

    .gate__core-ring--a { width: 140px; height: 140px; }
    .gate__core-ring--b { width: 98px; height: 98px; }
    .gate__core-halo { width: 300px; height: 300px; }
    .gate__logo { width: 72px; }

    .gate__command {
        padding: var(--space-sm) var(--space-md);
    }

    /* Les formes de fond sont réduites : sur un petit écran, elles
       encombreraient le texte au lieu de suggérer un volume. */
    .gate-shape--rect,
    .gate-shape--ring {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gate-shape--dot,
    .gate.p0::after,
    .gate__core-ring,
    .gate-boot__cursor,
    .gate__logo,
    .gate__wake {
        animation: none !important;
    }
}
