/* ============================================================
   fx.css : terminal interactif, toasts, mode Overtake (DA Télémétrie)
   Pendant de js/terminal.js. Chaque token a une valeur de repli :
   core.css peut ne pas encore les définir.
   Classe interne du mode Overtake : html.drs (nom historique).
   ============================================================ */

/* Texte réservé aux lecteurs d'écran, limité à nos composants */
:where(.terminal, .gb-toasts) .sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------
   1. TERMINAL INTERACTIF (accueil, section #stack)
   Le JS recopie la taille de police, l'interligne et la marge
   du <pre> dans --fx-fs, --fx-lh et --fx-px.
   ------------------------------------------------------------ */
.terminal.is-interactive {
  --fx-ink: var(--text, #e9edf6);
  --fx-dim: #8d95a8;                       /* 6.4:1 sur #0b0e14 */
  --fx-accent: var(--livery-glow, #6fa0ff);
  --fx-cyan: var(--cyan, #40e0ff);
  --fx-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.terminal.is-live { cursor: text; }

/* Un seul curseur : celui de la saisie remplace le bloc décoratif */
.terminal.is-live .term-body .cursor { display: none; }

/* Commande clear : l'écran se vide, lignes décoratives comprises */
.terminal.is-cleared .term-body { display: none; }
.terminal.is-cleared .term-out,
.terminal.is-cleared .term-out:empty + .term-form { padding-top: 1em; }

.term-out,
.term-hint,
.term-form {
  box-sizing: border-box;
  padding-inline: var(--fx-px, 18px);
  font-family: var(--fx-mono);
  font-size: var(--fx-fs, clamp(0.72rem, 0.66rem + 0.22vw, 0.8125rem));
  line-height: var(--fx-lh, 1.75);
  color: var(--fx-ink);
  text-align: left;
}

/* Zone de sortie : hauteur bornée, elle défile au lieu d'allonger la page */
.term-out {
  max-height: min(19rem, 38vh);
  overflow-y: auto;
  overflow-x: hidden;
  padding-block: 0.15em 0.35em;
  scrollbar-width: thin;
  scrollbar-color: rgba(150, 175, 255, 0.28) transparent;
}

.term-out:empty { display: none; }

.term-out::-webkit-scrollbar { width: 6px; }
.term-out::-webkit-scrollbar-track { background: transparent; }
.term-out::-webkit-scrollbar-thumb { background: rgba(150, 175, 255, 0.28); }
.term-out::-webkit-scrollbar-thumb:hover { background: rgba(150, 175, 255, 0.5); }

.term-out:focus-visible {
  outline: 2px solid var(--fx-accent);
  outline-offset: -2px;
}

.t-block + .t-block { margin-top: 0.4em; }

.t-line {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Couleurs (toutes AA sur carbone) */
.term-out .prompt,
.term-ps1 { white-space: nowrap; }
.ps-user { color: var(--fx-accent); }
.ps-path { color: var(--fx-cyan); }
.ps-sign { color: var(--fx-ink); margin-left: 0.1ch; }

.term-out .cmd { color: var(--fx-ink); font-weight: 600; }
.term-out .key { color: var(--fx-cyan); }
.term-out .str { color: var(--fx-accent); }
.term-out .com,
.term-hint .com,
.t-dim { color: var(--fx-dim); }
.t-ok,
.t-green { color: var(--green, #23d56b); }
.t-purple { color: var(--purple, #b44dff); }
.t-yellow { color: var(--yellow, #ffd23f); }
.t-err { color: var(--red, #ff2d3d); }

.term-out a {
  color: var(--fx-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: color 0.2s ease;
}

.term-out a:hover { color: var(--fx-ink); }

.term-out a:focus-visible {
  outline: 2px solid var(--fx-cyan);
  outline-offset: 2px;
  border-radius: 1px;
}

/* sudo hire guylann */
.t-granted {
  display: inline-block;
  padding: 0.2em 0.8em;
  border: 1px solid var(--green, #23d56b);
  background: rgba(35, 213, 107, 0.08);
  color: var(--green, #23d56b);
  font-weight: 700;
  letter-spacing: 0.22em;
  box-shadow:
    -4px -4px 0 -3px var(--green, #23d56b),
    4px 4px 0 -3px var(--green, #23d56b);
}

/* f1 : voyant LIVE (1 clignotement par seconde, sous le seuil WCAG 2.3.1) */
.t-live {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  color: var(--red, #ff2d3d);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.t-live::before {
  content: "";
  width: 0.5em;
  height: 0.5em;
  border-radius: 50%;
  background: currentColor;
}

/* Indice et ligne de saisie */
.term-hint { margin: 0; }
.term-hint b { color: var(--fx-ink); font-weight: 600; }

.term-form {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 1ch;
  margin: 0;
  padding-block: 0.3em 1.1em;
}

.term-input {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--fx-ink);
  font: inherit;
  letter-spacing: inherit;
  caret-color: var(--fx-cyan);
  box-shadow: none;
  appearance: none;
}

.term-input:focus,
.term-input:focus-visible { outline: none; }

/* Focus visible porté par la ligne entière : filet cyan + voile */
.term-form:focus-within {
  background: rgba(64, 224, 255, 0.06);
  box-shadow: inset 2px 0 0 var(--fx-cyan);
}

.term-out ::selection,
.term-input::selection {
  background: rgba(10, 92, 240, 0.6);
  color: #fff;
}

/* Mobile : 16px minimum, sinon iOS zoome au focus */
@media (pointer: coarse) {
  .term-input { font-size: max(16px, 1em); }
}

/* Avant la fin de la frappe : place réservée (pas de saut de mise en page), rien de visible */
.terminal.is-interactive:not(.is-live) .term-form,
.terminal.is-interactive:not(.is-live) .term-hint { visibility: hidden; }

@media (prefers-reduced-motion: no-preference) {
  .terminal.is-live .term-form,
  .terminal.is-live .term-hint { animation: fx-fade-up 0.35s cubic-bezier(0.22, 1, 0.36, 1) both; }

  /* Sorties tapées très vite, ligne par ligne */
  .t-line { animation: fx-type 0.18s steps(14, end) both; }
  .t-line.t-echo { animation: none; }

  .t-live::before { animation: fx-blink 1s steps(1, end) infinite; }
}

@keyframes fx-type {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(-0.5em -1em -0.5em -0.5em); }
}

@keyframes fx-fade-up {
  from { opacity: 0; transform: translate3d(0, 6px, 0); }
  to { opacity: 1; transform: none; }
}

@keyframes fx-blink {
  50% { opacity: 0.25; }
}

/* ------------------------------------------------------------
   2. TOASTS (window.GB.toast)
   ------------------------------------------------------------ */
.gb-toasts {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 9500;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.gb-toast {
  --c: var(--livery-2, #3d7dff);
  position: relative;
  box-sizing: border-box;
  width: 100%;
  padding: 14px 52px 16px 16px;
  background: var(--carbon-2, #0b0e14);
  border: 1px solid var(--line-2, rgba(150, 175, 255, 0.28));
  color: var(--text, #e9edf6);
  font-family: "Titillium Web", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.9375rem;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 24px 48px -18px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  opacity: 0;
  transform: translate3d(0, 14px, 0);
  transition: opacity 0.28s ease, transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.gb-toast.is-in { opacity: 1; transform: none; }

.gb-toast.is-out {
  opacity: 0;
  transform: translate3d(24px, 0, 0);
  transition-duration: 0.22s;
}

/* Crochets d'angle HUD (un seul pseudo-élément, 8 dégradés) */
.gb-toast::before {
  content: "";
  position: absolute;
  inset: -1px;
  pointer-events: none;
  background:
    linear-gradient(var(--c), var(--c)) left top / 10px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) left top / 2px 10px no-repeat,
    linear-gradient(var(--c), var(--c)) right top / 10px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) right top / 2px 10px no-repeat,
    linear-gradient(var(--c), var(--c)) left bottom / 10px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) left bottom / 2px 10px no-repeat,
    linear-gradient(var(--c), var(--c)) right bottom / 10px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) right bottom / 2px 10px no-repeat;
}

.gb-toast-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 6px;
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--livery-glow, #6fa0ff);
}

.gb-toast-head::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  background: currentColor;
}

.gb-toast-body p { margin: 0; }
.gb-toast-body strong { font-weight: 700; color: var(--white, #f6f7fb); }

.gb-toast-body a {
  color: var(--livery-glow, #6fa0ff);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.gb-toast-body a:hover { color: var(--white, #f6f7fb); }

.gb-toast a:focus-visible,
.gb-toast-close:focus-visible {
  outline: 2px solid var(--cyan, #40e0ff);
  outline-offset: 2px;
}

.gb-toast-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: #8d95a8;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.gb-toast-close:hover {
  color: var(--text, #e9edf6);
  border-color: var(--line-2, rgba(150, 175, 255, 0.28));
}

/* Durée de vie restante (en pause au survol et au focus, comme le minuteur) */
.gb-toast-life {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--c);
  transform-origin: left center;
  animation: fx-life var(--life, 6s) linear forwards;
}

.gb-toast.is-paused .gb-toast-life { animation-play-state: paused; }

@keyframes fx-life {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* Radio d'équipe : onde audio en barres */
.gb-toast--radio { --c: var(--yellow, #ffd23f); }
.gb-toast--radio .gb-toast-head { color: var(--yellow, #ffd23f); }

.gb-wave {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 14px;
  margin-left: auto;
}

.gb-wave i {
  display: block;
  width: 2px;
  height: 100%;
  background: currentColor;
  transform: scaleY(var(--s, 0.5));
  animation: fx-wave 0.9s ease-in-out calc(var(--i, 0) * -0.11s) infinite alternate;
}

.gb-wave i:nth-child(3n) { animation-duration: 0.7s; }
.gb-wave i:nth-child(3n + 1) { animation-duration: 1.1s; }

@keyframes fx-wave {
  0% { transform: scaleY(0.18); }
  55% { transform: scaleY(1); }
  100% { transform: scaleY(0.4); }
}

/* Mode Overtake : grand titre italique façon F1 */
.gb-toast-big {
  margin: 2px 0 4px !important;
  font-family: "Anybody", "Arial Narrow", sans-serif;
  font-size: 1.3rem;
  font-style: italic;
  font-weight: 900;
  font-stretch: 108%;
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.gb-toast-big[data-state="on"] { color: var(--green, #23d56b); }
.gb-toast--drs:has([data-state="on"]) { --c: var(--green, #23d56b); }
.gb-toast-sub { color: #aeb5c5; font-size: 0.875rem; }

/* ------------------------------------------------------------
   3. MODE OVERTAKE (classe html.drs)
   Traînées de vitesse plein écran, purement décoratives.
   ------------------------------------------------------------ */

/* Léger renforcement des accents : filets et lueurs plus présents */
html.drs {
  --line: rgba(150, 175, 255, 0.22);
  --line-2: rgba(150, 175, 255, 0.42);
  --livery-glow: #93b8ff;
  --cyan: #74eaff;
}

.fx-drs {
  position: fixed;
  inset: 0;
  z-index: 9400;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

html.drs .fx-drs {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease;
}

/* Liseré bleu de livrée sur les bords */
.fx-drs::before {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow:
    inset 0 0 0 1px rgba(61, 125, 255, 0.55),
    inset 0 0 110px rgba(10, 92, 240, 0.2);
}

.fx-drs i {
  position: absolute;
  top: var(--y, 50%);
  right: 0;
  width: var(--w, 30vw);
  height: 1px;
  background: linear-gradient(90deg, rgba(64, 224, 255, 0.95), rgba(111, 160, 255, 0.55) 35%, rgba(111, 160, 255, 0));
  opacity: var(--o, 0.6);
  transform: translate3d(100vw, 0, 0);
}

/* Les traînées filent de droite à gauche, uniquement quand le mode est actif */
html.drs .fx-drs i {
  will-change: transform;
  animation: fx-streak var(--d, 0.7s) linear var(--delay, 0s) infinite;
}

@keyframes fx-streak {
  from { transform: translate3d(100vw, 0, 0); }
  to { transform: translate3d(calc(-100vw - 100%), 0, 0); }
}

/* ------------------------------------------------------------
   4. PETITS ÉCRANS
   ------------------------------------------------------------ */
@media (max-width: 639.98px) {
  .gb-toasts {
    right: 12px;
    left: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: auto;
  }

  .term-out { max-height: min(17rem, 46vh); }
}

/* ------------------------------------------------------------
   5. MOUVEMENT RÉDUIT : états finaux, aucune boucle
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .gb-toast,
  .gb-toast.is-out,
  .fx-drs,
  html.drs .fx-drs { transition: none; }

  .gb-toast { transform: none; }
  .gb-toast-life { display: none; }
  .gb-wave i { animation: none; }

  /* Pas de traînées : un liseré bleu fixe sur les bords suffit */
  .fx-drs i { display: none; }
  .fx-drs::before { box-shadow: inset 0 0 0 3px var(--livery, #0a5cf0); }
}

/* ------------------------------------------------------------
   6. IMPRESSION
   ------------------------------------------------------------ */
@media print {
  .gb-toasts,
  .fx-drs,
  .term-hint,
  .term-form { display: none !important; }

  .term-out { max-height: none; overflow: visible; }
}
