/**
 * davito.dev — capa de movimiento común (la usan todas las páginas).
 *
 *  1. Grano de película sobre toda la página
 *  2. Cursor propio (fx.js lo crea solo con ratón y sin movimiento reducido)
 *  3. Botones magnéticos
 *  4. Indicador deslizante del dock
 *  5. Transición entre páginas (View Transitions, la lanza nav.js)
 *
 * Todo lo que se mueve depende de clases que pone fx.js (fx-cursor-on,
 * fx-magnet-on, fx-dock-on): sin JS no cambia nada.
 */

/* 1. Grano: ruido SVG muy tenue que salta 8 veces por segundo */
html::after {
  content: "";
  position: fixed;
  /* Un poco más grande que la ventana para poder moverlo sin que asomen los
     bordes, pero no mucho: es una capa del tamaño de la pantalla en la GPU */
  inset: -100px;
  z-index: 10060;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1.6 -.55'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  opacity: 0.075;
  animation: fxGrain 1s steps(8) infinite;
}

html[data-theme="light"]::after {
  filter: invert(1);
  opacity: 0.06;
}

@keyframes fxGrain {
  0% { transform: translate(0, 0); }
  12% { transform: translate(-40px, -60px); }
  25% { transform: translate(50px, 20px); }
  37% { transform: translate(-20px, 70px); }
  50% { transform: translate(70px, -30px); }
  62% { transform: translate(-60px, 40px); }
  75% { transform: translate(30px, 80px); }
  87% { transform: translate(-70px, -20px); }
  100% { transform: translate(0, 0); }
}

/* 2. Cursor propio */
@media (hover: hover) and (pointer: fine) {
  html.fx-cursor-on,
  html.fx-cursor-on * {
    cursor: none !important;
  }

  html.fx-cursor-on :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not([type="submit"]), textarea, select, [contenteditable="true"]) {
    cursor: auto !important;
  }
}

.fx-cursor,
.fx-cursor-dot {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  opacity: 0;
  will-change: transform;
  transition: opacity 0.25s ease;
}

.fx-cursor.is-visible,
.fx-cursor-dot.is-visible {
  opacity: 1;
}

.fx-cursor {
  z-index: 100000;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  mix-blend-mode: difference;
}

.fx-cursor::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1.5px solid #fff;
  border-radius: 50%;
  transition:
    transform 0.5s cubic-bezier(0.16, 1, 0.3, 1),
    background-color 0.3s ease,
    border-color 0.3s ease;
}

.fx-cursor.is-link::before {
  transform: scale(1.55);
  background-color: #fff;
}

.fx-cursor.is-down::before {
  transform: scale(0.78);
}

.fx-cursor.is-link.is-down::before {
  transform: scale(1.3);
}

.fx-cursor.is-text {
  opacity: 0;
}

/* Sobre una tarjeta: burbuja de color con la acción */
.fx-cursor.is-label {
  mix-blend-mode: normal;
}

.fx-cursor.is-label::before {
  transform: scale(2.35);
  background-color: var(--c-accent, #ff6b4a);
  border-color: transparent;
}

.fx-cursor-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  color: var(--c-accent-ink, #0b0b0e);
  text-transform: lowercase;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.2s ease, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.fx-cursor.is-label .fx-cursor-label {
  opacity: 1;
  transform: none;
}

.fx-cursor-dot {
  z-index: 100001;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: #fff;
  mix-blend-mode: difference;
}

.fx-cursor-dot.is-text,
.fx-cursor.is-label + .fx-cursor-dot {
  opacity: 0;
}

/* 3. Botones magnéticos (fx.js pone --mx/--my mientras el ratón está encima) */
html.fx-magnet-on :is(.btn, .top-chip, .lang-toggle-btn, .dock-tool-btn, .btn-cyber-ghost, .contact-mail, [data-magnetic]) {
  translate: var(--mx, 0px) var(--my, 0px);
  transition:
    translate 0.7s cubic-bezier(0.34, 1.56, 0.64, 1),
    transform 0.15s ease,
    background-color 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    box-shadow 0.25s ease;
}

html.fx-magnet-on :is(.btn, .top-chip, .lang-toggle-btn, .dock-tool-btn, .btn-cyber-ghost, .contact-mail, [data-magnetic]).is-magnet {
  transition:
    translate 0.18s ease-out,
    transform 0.15s ease,
    background-color 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    box-shadow 0.25s ease;
}

/* 4. Dock: una píldora que viaja hasta la sección activa */
html.fx-dock-on .cyber-dock {
  position: relative;
}

.dock-indicator {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 0;
  border-radius: 999px;
  background: var(--c-line);
  box-shadow: inset 0 0 0 1px var(--c-line-hi);
  pointer-events: none;
  opacity: 0;
  transition:
    transform 0.6s cubic-bezier(0.65, 0, 0.35, 1),
    width 0.6s cubic-bezier(0.65, 0, 0.35, 1),
    opacity 0.3s ease;
}

html.fx-dock-on .dock-link.is-active {
  background: transparent;
}

html.fx-dock-on :is(.dock-link, .dock-tool-btn, .dock-divider) {
  position: relative;
  z-index: 1;
}

/* 5. Transición entre páginas: la vieja se hunde y la nueva sube como un telón */
#cyber-lofi-widget {
  view-transition-name: lofi-widget;
}

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root) {
    animation: fxPageOut 0.5s cubic-bezier(0.76, 0, 0.24, 1) both;
  }

  ::view-transition-new(root) {
    animation: fxPageIn 0.75s cubic-bezier(0.76, 0, 0.24, 1) both;
  }
}

@keyframes fxPageOut {
  to {
    opacity: 0.35;
    transform: translateY(-6vh) scale(0.97);
  }
}

@keyframes fxPageIn {
  from {
    clip-path: inset(100% 0 0 0 round 24px);
    transform: translateY(8vh);
  }
  to {
    clip-path: inset(0 0 0 0 round 0);
    transform: none;
  }
}

/* Sin movimiento: nada de grano animado ni cursor propio */
@media (prefers-reduced-motion: reduce) {
  html::after {
    animation: none;
  }

  .fx-cursor,
  .fx-cursor-dot,
  .dock-indicator {
    display: none !important;
  }
}

@media print {
  html::after,
  .fx-cursor,
  .fx-cursor-dot {
    display: none !important;
  }
}
