/* ═══════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════ */

/* ── Fade in ── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInSlow {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.8s ease forwards;
}

/* ── Glitch text ── */
.glitch-text {
    position: relative;
}

.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.glitch-text::before {
    left: 2px;
    text-shadow: -2px 0 #e63946;
    clip: rect(24px, 550px, 90px, 0);
    animation: glitch-anim-1 3s infinite linear alternate-reverse;
}

.glitch-text::after {
    left: -2px;
    text-shadow: 2px 0 #00b4d8;
    clip: rect(85px, 550px, 140px, 0);
    animation: glitch-anim-2 3s infinite linear alternate-reverse;
}

@keyframes glitch-anim-1 {
    0%   { clip: rect(20px, 9999px, 40px, 0); }
    10%  { clip: rect(60px, 9999px, 80px, 0); }
    20%  { clip: rect(10px, 9999px, 30px, 0); }
    30%  { clip: rect(50px, 9999px, 70px, 0); }
    40%  { clip: rect(30px, 9999px, 55px, 0); }
    50%  { clip: rect(5px, 9999px, 25px, 0); }
    60%  { clip: rect(45px, 9999px, 65px, 0); }
    70%  { clip: rect(15px, 9999px, 35px, 0); }
    80%  { clip: rect(55px, 9999px, 75px, 0); }
    90%  { clip: rect(25px, 9999px, 50px, 0); }
    100% { clip: rect(40px, 9999px, 60px, 0); }
}

@keyframes glitch-anim-2 {
    0%   { clip: rect(65px, 9999px, 85px, 0); }
    10%  { clip: rect(15px, 9999px, 35px, 0); }
    20%  { clip: rect(55px, 9999px, 75px, 0); }
    30%  { clip: rect(25px, 9999px, 45px, 0); }
    40%  { clip: rect(70px, 9999px, 90px, 0); }
    50%  { clip: rect(35px, 9999px, 55px, 0); }
    60%  { clip: rect(10px, 9999px, 30px, 0); }
    70%  { clip: rect(60px, 9999px, 80px, 0); }
    80%  { clip: rect(20px, 9999px, 40px, 0); }
    90%  { clip: rect(50px, 9999px, 70px, 0); }
    100% { clip: rect(30px, 9999px, 50px, 0); }
}

/* ── Typewriter cursor ── */
.typewriter-cursor::after {
    content: '█';
    animation: blink 0.8s infinite;
    color: var(--cyan);
    margin-left: 2px;
}

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

/* ── Glitch screen (Niveau 5) ── */
@keyframes glitchScreen {
    0%   { transform: translate(0); filter: none; }
    2%   { transform: translate(-3px, 1px); filter: hue-rotate(90deg); }
    4%   { transform: translate(3px, -2px); filter: hue-rotate(-90deg); }
    6%   { transform: translate(0); filter: none; }
    8%   { transform: translate(2px, 3px); filter: saturate(5); }
    10%  { transform: translate(-2px, -1px); filter: saturate(0.5); }
    12%  { transform: translate(0); filter: none; }
    100% { transform: translate(0); filter: none; }
}

.glitch-effect {
    animation: glitchScreen 0.5s ease;
}

/* ── Shake (alert) ── */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.5s ease;
}

/* ── Pulse glow ── */
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 5px var(--cyan-dim); }
    50%      { box-shadow: 0 0 20px var(--cyan-glow), 0 0 40px var(--cyan-dim); }
}

.pulse-glow {
    animation: pulseGlow 2s infinite ease-in-out;
}

/* ── Static noise (end screen) ── */
@keyframes staticNoise {
    0%   { background-position: 0 0; }
    100% { background-position: 100% 100%; }
}

.static-noise {
    position: relative;
}

.static-noise::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.15'/%3E%3C/svg%3E");
    pointer-events: none;
    animation: staticNoise 0.1s infinite;
    opacity: 0.3;
}

/* ── Level transition ── */
@keyframes levelIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.level-enter {
    animation: levelIn 0.6s ease forwards;
}

/* ── Connection lost text flicker ── */
@keyframes flicker {
    0%, 100% { opacity: 1; }
    41% { opacity: 1; }
    42% { opacity: 0.3; }
    43% { opacity: 1; }
    45% { opacity: 0.5; }
    46% { opacity: 1; }
    50% { opacity: 1; }
    51% { opacity: 0.2; }
    52% { opacity: 1; }
}

.flicker {
    animation: flicker 3s infinite;
}

/* ── Gold shimmer for badges ── */
@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.shimmer {
    background: linear-gradient(
        90deg,
        var(--gold) 0%,
        #fff 25%,
        var(--gold) 50%
    );
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 3s infinite linear;
}
