/* ============================================================
   CODECHOMPER V2 — Animations
   Scroll animations · Glitch · Typing cursor · Micro-interactions
   ============================================================ */


/* ============================
   SCROLL-TRIGGERED FADE-IN-UP
   Add .fade-in-up to any element.
   JS adds .is-visible when it enters the viewport.
   Use --delay CSS var on children for stagger.
   ============================ */

.fade-in-up {
  opacity: 0;
  transform: translateY(32px);
  transition:
    opacity 0.6s ease var(--delay, 0s),
    transform 0.6s ease var(--delay, 0s);
}

.fade-in-up.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Fade-in only (no vertical movement) */
.fade-in {
  opacity: 0;
  transition: opacity 0.7s ease var(--delay, 0s);
}

.fade-in.is-visible {
  opacity: 1;
}

/* Slide in from left */
.slide-in-left {
  opacity: 0;
  transform: translateX(-48px);
  transition:
    opacity 0.7s ease var(--delay, 0s),
    transform 0.7s ease var(--delay, 0s);
}

.slide-in-left.is-visible {
  opacity: 1;
  transform: translateX(0);
}

/* Slide in from right */
.slide-in-right {
  opacity: 0;
  transform: translateX(48px);
  transition:
    opacity 0.7s ease var(--delay, 0s),
    transform 0.7s ease var(--delay, 0s);
}

.slide-in-right.is-visible {
  opacity: 1;
  transform: translateX(0);
}


/* ============================
   GLITCH TEXT EFFECT
   Apply .glitch to a text element.
   Uses CSS custom properties for color channels.
   ============================ */

@keyframes glitch-skew {
  0%   { transform: skew(0deg); }
  10%  { transform: skew(-1deg); }
  20%  { transform: skew(0.5deg); }
  30%  { transform: skew(0deg); }
  40%  { transform: skew(0.8deg); }
  50%  { transform: skew(-0.5deg); }
  60%  { transform: skew(0deg); }
  70%  { transform: skew(-1.5deg); }
  80%  { transform: skew(0deg); }
  90%  { transform: skew(0.3deg); }
  100% { transform: skew(0deg); }
}

@keyframes glitch-clip-1 {
  0%   { clip-path: inset(40% 0 50% 0); transform: translate(-3px, 0); }
  20%  { clip-path: inset(10% 0 70% 0); transform: translate(3px, 0); }
  40%  { clip-path: inset(80% 0 5%  0); transform: translate(-3px, 0); }
  60%  { clip-path: inset(25% 0 60% 0); transform: translate(3px, 0); }
  80%  { clip-path: inset(60% 0 20% 0); transform: translate(-3px, 0); }
  100% { clip-path: inset(40% 0 50% 0); transform: translate(0, 0); }
}

@keyframes glitch-clip-2 {
  0%   { clip-path: inset(60% 0 10% 0); transform: translate(3px, 0); }
  20%  { clip-path: inset(5%  0 80% 0); transform: translate(-3px, 0); }
  40%  { clip-path: inset(50% 0 30% 0); transform: translate(3px, 0); }
  60%  { clip-path: inset(15% 0 65% 0); transform: translate(-3px, 0); }
  80%  { clip-path: inset(35% 0 45% 0); transform: translate(3px, 0); }
  100% { clip-path: inset(60% 0 10% 0); transform: translate(0, 0); }
}

.glitch {
  position: relative;
  animation: glitch-skew 4s infinite linear alternate-reverse;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  width: 100%;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
}

.glitch::before {
  left: 2px;
  color: var(--accent);
  animation: glitch-clip-1 3s infinite linear alternate-reverse;
  opacity: 0.6;
}

.glitch::after {
  left: -2px;
  color: var(--primary);
  animation: glitch-clip-2 3s infinite linear alternate-reverse;
  opacity: 0.6;
}

/* Subtle glitch — less aggressive, used on headings */
.glitch-subtle::before {
  animation-duration: 5s;
  opacity: 0.35;
}
.glitch-subtle::after {
  animation-duration: 5s;
  opacity: 0.35;
}


/* ============================
   GLITCH BARS
   Animated horizontal accent lines that flicker
   ============================ */

@keyframes glitch-bar-flicker {
  0%, 100% { opacity: 0.9; width: 200px; }
  25%       { opacity: 0.4; width: 180px; }
  50%       { opacity: 0.8; width: 220px; }
  75%       { opacity: 0.3; width: 160px; }
}

@keyframes glitch-bar-flicker-2 {
  0%, 100% { opacity: 0.7; width: 100px; }
  33%       { opacity: 0.2; width: 80px; }
  66%       { opacity: 0.9; width: 120px; }
}

.glitch-bar-anim {
  animation: glitch-bar-flicker 2.8s ease-in-out infinite;
}

.glitch-bar-anim-2 {
  animation: glitch-bar-flicker-2 2.2s ease-in-out infinite;
  animation-delay: 0.4s;
}


/* ============================
   TYPING CURSOR
   Used in terminal and typewriter effects
   ============================ */

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

.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background-color: var(--primary);
  vertical-align: text-bottom;
  animation: cursor-blink 1s step-end infinite;
  margin-left: 2px;
}

.typing-cursor--accent {
  background-color: var(--accent);
}


/* ============================
   COUNT-UP NUMBER ANIMATION
   JS toggles .is-counting; CSS handles visual pop
   ============================ */

@keyframes number-pop {
  0%   { transform: scale(0.85); opacity: 0.5; }
  60%  { transform: scale(1.08); }
  100% { transform: scale(1);    opacity: 1; }
}

.count-up-target {
  display: inline-block;
}

.count-up-target.is-counting {
  animation: number-pop 0.5s ease forwards;
}


/* ============================
   PAGE TRANSITION (body fade-in on load)
   ============================ */

@keyframes page-enter {
  from { opacity: 0; }
  to   { opacity: 1; }
}

body {
  animation: page-enter 0.4s ease forwards;
}


/* ============================
   ACCENT BAR GROW (horizontal rule animate in)
   ============================ */

@keyframes bar-grow-h {
  from { transform: scaleX(0); transform-origin: left; }
  to   { transform: scaleX(1); transform-origin: left; }
}

.bar-grow {
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.6s ease var(--delay, 0s);
}

.bar-grow.is-visible {
  transform: scaleX(1);
}


/* ============================
   TERMINAL BOOT SEQUENCE
   Lines animate in one by one via JS-assigned stagger delays
   ============================ */

.term-line {
  opacity: 0;
  transition: opacity 0.1s ease;
  white-space: nowrap;
  overflow: hidden;
}

.term-line.is-visible {
  opacity: 1;
}


/* ============================
   HOVER: Image zoom-in (used on project/game image panels)
   ============================ */

.img-hover-zoom {
  overflow: hidden;
}

.img-hover-zoom img,
.img-hover-zoom .img-fill {
  transition: transform 0.5s ease;
}

.img-hover-zoom:hover img,
.img-hover-zoom:hover .img-fill {
  transform: scale(1.04);
}


/* ============================
   ACCENT BAR FLASH (on hover for section headers)
   ============================ */

.section-accent-bar {
  transition: background-color 0.3s ease, opacity 0.3s ease;
}


/* ============================
   SPIN (used for loading states)
   ============================ */

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spin {
  animation: spin 1s linear infinite;
}
