/* ==========================================================================
   PAGE GLITCH — /assets/css/glitch-page.css
   Utilise les variables de thème de style.css (--bg-page, --accent-color…),
   donc elle suit automatiquement le thème choisi.
   Cycle de 6 s : repos → montée → pic → redescente → repos
   (les pourcentages sont les mêmes que le glitch du header).
   ========================================================================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Fond plein écran ---------- */
.gp-stage {
  --gp-soft:  color-mix(in srgb, var(--accent-color) 45%, transparent);
  --gp-mid:   color-mix(in srgb, var(--accent-color) 75%, transparent);
  --gp-dark:  color-mix(in srgb, var(--bg-page) 70%, transparent);
  --gp-pink:  color-mix(in srgb, #ff2bd6 65%, transparent);
  --gp-lilac: color-mix(in srgb, var(--text-muted) 30%, transparent);

  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: var(--bg-page);
}

.gp-stage > * {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.gp-page .site-footer {
  position: relative;
  z-index: 2;
}

/* 1. Voile coloré (bords + diagonale) */
.gp-wash {
  background:
    radial-gradient(ellipse 55% 120% at 0% 50%,   rgba(255, 43, 214, 0.90), transparent 70%),
    radial-gradient(ellipse 90% 60%  at 40% 0%,   rgba(255, 43, 214, 0.50), transparent 75%),
    radial-gradient(ellipse 70% 90%  at 100% 100%, var(--gp-mid), transparent 70%),
    linear-gradient(135deg, var(--gp-soft), transparent 75%);
  mix-blend-mode: screen;
  animation:
    gp-env-a 6s steps(1, end) infinite,
    gp-jump-wash 1.1s steps(1, end) infinite;
}

/* 2. Gros carrés / blocs */
.gp-blocks {
  background:
    linear-gradient(var(--gp-soft),  var(--gp-soft))  38% 20% / 14vw 16vh no-repeat,
    linear-gradient(var(--gp-lilac), var(--gp-lilac)) 12% 55% / 18vw 12vh no-repeat,
    linear-gradient(var(--gp-mid),   var(--gp-mid))   48% 58% /  9vw 11vh no-repeat,
    linear-gradient(var(--gp-pink),  var(--gp-pink))   5% 72% / 16vw 10vh no-repeat,
    linear-gradient(var(--gp-pink),  var(--gp-pink))  55% 90% / 24vw  7vh no-repeat,
    linear-gradient(var(--gp-dark),  var(--gp-dark))  80% 25% / 20vw 14vh no-repeat,
    linear-gradient(var(--gp-dark),  var(--gp-dark))  28% 82% / 22vw  9vh no-repeat,
    linear-gradient(var(--gp-soft),  var(--gp-soft))  70% 62% / 12vw 11vh no-repeat,
    linear-gradient(var(--gp-mid),   var(--gp-mid))   90%  8% /  8vw 20vh no-repeat,
    linear-gradient(var(--gp-lilac), var(--gp-lilac)) 60%  5% / 14vw  6vh no-repeat;
  animation:
    gp-env-a 6s steps(1, end) infinite,
    gp-jump-blocks 1.2s steps(1, end) infinite;
}

/* 3. Colonnes verticales sur toute la hauteur */
.gp-streaks {
  background:
    linear-gradient(rgba(255, 255, 255, 0.90), rgba(255, 255, 255, 0.05)) 18% 0   /  2px 100% no-repeat,
    linear-gradient(rgba(255, 255, 255, 0.80), rgba(255, 255, 255, 0.05)) 56% 0   /  1px  60% no-repeat,
    linear-gradient(rgba(255, 255, 255, 0.70), transparent)               92% 0   /  1px  90% no-repeat,
    linear-gradient(rgba(255, 43, 214, 0.90),  rgba(255, 43, 214, 0.15))   6% 0   / 14px 100% no-repeat,
    linear-gradient(rgba(255, 43, 214, 0.80),  rgba(255, 43, 214, 0.10))  44% 0   /  9px  70% no-repeat,
    linear-gradient(var(--gp-mid), transparent)                           70% 30% / 10px  70% no-repeat,
    linear-gradient(rgba(0, 240, 255, 0.90),   rgba(0, 240, 255, 0.25))   85% 20% /  6px  80% no-repeat,
    linear-gradient(rgba(0, 240, 255, 0.80),   transparent)               31% 10% /  3px  50% no-repeat;
  animation:
    gp-env-b 6s steps(1, end) infinite,
    gp-jump-streaks 0.8s steps(1, end) infinite;
}

/* 4. Barres tramées en damier */
.gp-dither {
  background: repeating-conic-gradient(#00f0ff 0 25%, transparent 0 50%) 0 0 / 4px 4px;
  -webkit-mask:
    linear-gradient(#000, #000) 78% 0   / 5vw 100% no-repeat,
    linear-gradient(#000, #000) 30% 20% / 8vw  60% no-repeat,
    linear-gradient(#000, #000) 92% 10% / 3vw  50% no-repeat,
    linear-gradient(#000, #000) 12% 70% / 6vw  30% no-repeat;
          mask:
    linear-gradient(#000, #000) 78% 0   / 5vw 100% no-repeat,
    linear-gradient(#000, #000) 30% 20% / 8vw  60% no-repeat,
    linear-gradient(#000, #000) 92% 10% / 3vw  50% no-repeat,
    linear-gradient(#000, #000) 12% 70% / 6vw  30% no-repeat;
  animation:
    gp-env-c 6s steps(1, end) infinite,
    gp-jump-dither 0.6s steps(1, end) infinite;
}

/* 5. Lignes horizontales qui glitchent sur toute la largeur */
.gp-slices {
  overflow: hidden;
  animation: gp-env-b 6s steps(1, end) infinite;
}

.gp-slice {
  position: absolute;
  inset: auto;
  left: 0;
  right: 0;
  top: var(--top);
  height: var(--h);
  background: linear-gradient(90deg, var(--accent-color), #ff2bd6 45%, #00f0ff 80%, #ffffff);
  mix-blend-mode: screen;
  opacity: 0;
  animation: gp-slice var(--dur) steps(1, end) infinite;
  animation-delay: var(--delay);
}

/* 6. Barre de balayage lente + scanlines (toujours discrètes) */
.gp-scan {
  bottom: auto;
  height: 14vh;
  background: linear-gradient(transparent, rgba(255, 255, 255, 0.08), transparent);
  opacity: 1;
  animation: gp-scan 4.5s linear infinite;
}

.gp-scanlines {
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
  opacity: 1;
}

/* ---------- Contenu ---------- */
.gp-main {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 32px 16px;
  min-height: calc(100vh - 140px);
}

.gp-text-stack {
  position: relative;
  width: min(100%, 760px);
  animation: gp-shake 6s steps(1, end) infinite;
}

.gp-layer {
  font-family: ui-monospace, "Cascadia Code", "Courier New", monospace;
  text-align: center;
}

.gp-base {
  animation: gp-rgb 6s steps(1, end) infinite;
}

.gp-title {
  font-size: clamp(2rem, 9vw, 5.5rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1;
  white-space: nowrap;
  color: var(--accent-color);
  margin-bottom: 4vh;
}

.gp-lines {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  font-size: clamp(0.62rem, 1.7vw, 1rem);
  text-align: left;
}

.gp-line {
  white-space: pre;
  overflow: hidden;
  color: var(--text-main);
}
.gp-line:nth-child(3n) { color: var(--text-muted); }
.gp-line:nth-child(5n) { color: var(--accent-color); }

/* Copies du texte, découpées en bandes décalées (vraies déchirures) */
.gp-tear {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
}

.gp-tear .gp-title,
.gp-tear .gp-line {
  color: var(--tint);
}

.gp-tear-1 { --tint: #00f0ff; animation: gp-env-b 6s steps(1, end) infinite, gp-tear-a 1.3s steps(1, end) infinite; }
.gp-tear-2 { --tint: #ff2bd6; animation: gp-env-a 6s steps(1, end) infinite, gp-tear-b 0.9s steps(1, end) infinite; }
.gp-tear-3 { --tint: #ffffff; animation: gp-env-c 6s steps(1, end) infinite, gp-tear-c 1.7s steps(1, end) infinite; }

.gp-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.gp-warning {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.gp-btn {
  cursor: pointer;
  font-family: inherit;
}

/* ---------- Enveloppes d'intensité (6 s) ---------- */
@keyframes gp-env-a {
  0%, 19% { opacity: 0; }
  20% { opacity: 0.30; }
  26% { opacity: 0.60; }
  32% { opacity: 0.85; }
  40% { opacity: 1; }
  48% { opacity: 0.75; }
  56% { opacity: 1; }
  64% { opacity: 0.70; }
  72% { opacity: 0.45; }
  80% { opacity: 0.25; }
  88% { opacity: 0.10; }
  92%, 100% { opacity: 0; }
}

@keyframes gp-env-b {
  0%, 24% { opacity: 0; }
  26% { opacity: 0.55; }
  34% { opacity: 1; }
  42% { opacity: 0.70; }
  50% { opacity: 1; }
  60% { opacity: 0.90; }
  68% { opacity: 0.55; }
  76% { opacity: 0.35; }
  84% { opacity: 0.12; }
  90%, 100% { opacity: 0; }
}

@keyframes gp-env-c {
  0%, 34% { opacity: 0; }
  36% { opacity: 0.90; }
  42% { opacity: 0.30; }
  48% { opacity: 1; }
  54% { opacity: 0.50; }
  60% { opacity: 0.95; }
  66% { opacity: 0.40; }
  72%, 100% { opacity: 0; }
}

/* ---------- Sauts d'image du fond ---------- */
@keyframes gp-jump-wash {
  0%   { transform: translate(0, 0)    scaleX(1); }
  22%  { transform: translate(-3vw, 0) scaleX(1.1); }
  44%  { transform: translate(2vw, 0)  scaleX(0.95); }
  66%  { transform: translate(0, 0)    scaleX(1.05); }
  88%  { transform: translate(-1vw, 0) scaleX(1); }
}

@keyframes gp-jump-blocks {
  0%   { transform: translate(0, 0)        scale(1, 1);    clip-path: inset(0 0 0 0); }
  11%  { transform: translate(-4vw, 0)     scale(-1, 1);   clip-path: inset(0 0 30% 0); }
  22%  { transform: translate(3vw, 2vh)    scale(1, -1);   clip-path: inset(20% 0 0 0); }
  33%  { transform: translate(0, 0)        scale(1.1, 1);  clip-path: inset(0 0 0 25%); }
  44%  { transform: translate(6vw, -1vh)   scale(-1, -1);  clip-path: inset(10% 20% 30% 0); }
  55%  { transform: translate(-3vw, 1vh)   scale(1.2, 1);  clip-path: inset(0 0 55% 30%); }
  66%  { transform: translate(2vw, 0)      scale(1, 1.15); clip-path: inset(35% 0 0 10%); }
  77%  { transform: translate(-5vw, 0)     scale(-1.1, 1); clip-path: inset(0 15% 0 0); }
  88%  { transform: translate(0, 0)        scale(1, 1);    clip-path: inset(0 0 0 0); }
}

@keyframes gp-jump-streaks {
  0%   { transform: translateX(0);      clip-path: inset(0 0 0 0); }
  14%  { transform: translateX(5vw);    clip-path: inset(0 0 40% 0); }
  28%  { transform: translateX(-7vw) scaleX(-1); clip-path: inset(0 0 0 0); }
  42%  { transform: translateX(3vw);    clip-path: inset(25% 0 0 0); }
  57%  { transform: translateX(-9vw);   clip-path: inset(0 30% 0 0); }
  71%  { transform: translateX(8vw) scaleX(-1); clip-path: inset(0 0 20% 0); }
  85%  { transform: translateX(-2vw);   clip-path: inset(0 0 0 20%); }
}

@keyframes gp-jump-dither {
  0%   { transform: translate(0, 0);      clip-path: inset(0 0 0 0); }
  20%  { transform: translate(-6vw, 0);   clip-path: inset(0 0 45% 0); }
  40%  { transform: translate(4vw, 0) scaleX(-1); clip-path: inset(30% 0 0 0); }
  60%  { transform: translate(-3vw, 0);   clip-path: inset(0 0 0 0); }
  80%  { transform: translate(8vw, 0);    clip-path: inset(10% 0 25% 0); }
}

/* Une ligne horizontale : apparaît, glisse sur le côté, disparaît */
@keyframes gp-slice {
  0%, 100% { opacity: 0; }
  10% { opacity: 0.85; transform: translateX(-8vw); }
  18% { opacity: 0.50; transform: translateX(10vw) scaleY(0.4); }
  26% { opacity: 0; }
  60% { opacity: 0.70; transform: translateX(5vw); }
  66% { opacity: 0; }
}

@keyframes gp-scan {
  from { transform: translateY(-100%); }
  to   { transform: translateY(100vh); }
}

/* ---------- Texte : tremblement, séparation RGB, déchirures ---------- */
@keyframes gp-shake {
  0%, 34%  { transform: none; }
  36% { transform: translate(-4px, 0) skewX(-2deg); }
  40% { transform: translate(3px, 1px); }
  46% { transform: none; }
  52% { transform: translate(5px, 0) skewX(3deg); }
  56% { transform: none; }
  62% { transform: translate(-3px, -1px); }
  66%, 100% { transform: none; }
}

@keyframes gp-rgb {
  0%, 19%  { text-shadow: none; }
  22% { text-shadow: 1px 0 #00f0ff, -1px 0 #ff2bd6; }
  40% { text-shadow: 3px 0 #00f0ff, -3px 0 #ff2bd6; }
  55% { text-shadow: -4px 0 #00f0ff, 4px 0 #ff2bd6; }
  70% { text-shadow: 2px 0 #00f0ff, -2px 0 #ff2bd6; }
  86% { text-shadow: 1px 0 #00f0ff, -1px 0 #ff2bd6; }
  93%, 100% { text-shadow: none; }
}

@keyframes gp-tear-a {
  0%  { clip-path: inset(12% 0 80% 0); transform: translateX(-3vw); }
  10% { clip-path: inset(100% 0 0 0);  transform: none; }
  22% { clip-path: inset(48% 0 44% 0); transform: translateX(4vw); }
  34% { clip-path: inset(100% 0 0 0);  transform: none; }
  46% { clip-path: inset(70% 0 22% 0); transform: translateX(-5vw); }
  58% { clip-path: inset(25% 0 66% 0); transform: translateX(2vw); }
  70% { clip-path: inset(100% 0 0 0);  transform: none; }
  82% { clip-path: inset(88% 0 6% 0);  transform: translateX(6vw); }
  92% { clip-path: inset(100% 0 0 0);  transform: none; }
}

@keyframes gp-tear-b {
  0%  { clip-path: inset(100% 0 0 0); transform: none; }
  15% { clip-path: inset(5% 0 90% 0);  transform: translateX(5vw); }
  30% { clip-path: inset(100% 0 0 0);  transform: none; }
  45% { clip-path: inset(36% 0 56% 0); transform: translateX(-6vw); }
  60% { clip-path: inset(62% 0 30% 0); transform: translateX(3vw); }
  75% { clip-path: inset(100% 0 0 0);  transform: none; }
  90% { clip-path: inset(80% 0 14% 0); transform: translateX(-4vw); }
}

@keyframes gp-tear-c {
  0%  { clip-path: inset(100% 0 0 0); transform: none; }
  12% { clip-path: inset(20% 0 70% 0); transform: translateX(7vw); }
  24% { clip-path: inset(100% 0 0 0);  transform: none; }
  50% { clip-path: inset(52% 0 40% 0); transform: translateX(-8vw); }
  62% { clip-path: inset(100% 0 0 0);  transform: none; }
  80% { clip-path: inset(74% 0 18% 0); transform: translateX(5vw); }
  90% { clip-path: inset(100% 0 0 0);  transform: none; }
}

/* ---------- Mode calme (bouton) + préférence système ---------- */
.gp-calm .gp-stage > *,
.gp-calm .gp-slice,
.gp-calm .gp-text-stack,
.gp-calm .gp-base {
  animation: none;
}
.gp-calm .gp-stage > * { opacity: 0; }
.gp-calm .gp-stage > .gp-scanlines { opacity: 1; }
.gp-calm .gp-tear { display: none; }

@media (prefers-reduced-motion: reduce) {
  .gp-stage > *,
  .gp-slice,
  .gp-text-stack,
  .gp-base {
    animation: none;
  }
  .gp-stage > * { opacity: 0; }
  .gp-stage > .gp-scanlines { opacity: 1; }
  .gp-tear { display: none; }
}
