/* ==========================================================================
   TECHEED — High-Performance Visual & Kinetic Effects (v3.0 Modern Edition)
   Compositor-Only (60 FPS GPU-Accelerated), CSS Logical Properties & A11y
   Crafted for Saeed Rezaei / techeed.ir
   ========================================================================== */

/* Film Grain / Cyber Noise Overlay */
.fx-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* Floating Light Particles */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.particle {
  position: absolute;
  inset-block-end: -20px;
  width: 2px;
  height: 2px;
  background: var(--primary);
  border-radius: var(--radius-full, 9999px);
  box-shadow: 0 0 6px var(--primary);
  animation: floatUp linear infinite;
  transition: background var(--duration-normal, 0.25s) var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
  will-change: transform, opacity;
}

@keyframes floatUp {
  0% { transform: translateY(0) scale(0.5); opacity: 0; }
  20% { opacity: 0.8; }
  80% { opacity: 0.6; }
  100% { transform: translateY(-105vh) scale(1.2); opacity: 0; }
}

/* Marquee / Infinite Ticker with Neon Glow */
.ticker {
  overflow: hidden;
  white-space: nowrap;
  padding-block: var(--space-md, 16px);
  padding-inline: 0;
  background: var(--bg-surface);
  border-block-start: 1px solid var(--border-active, var(--border-active));
  border-block-end: 1px solid var(--border-active, var(--border-active));
  position: relative;
  z-index: 2;
  user-select: none;
  box-shadow: 0 0 25px var(--primary-glow);
}

.ticker b {
  display: inline-block;
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--text-muted);
  text-transform: uppercase;
  animation: marquee 30s linear infinite;
  will-change: transform;
}

.ticker b i {
  color: var(--primary);
  font-style: normal;
  margin-inline: 16px;
  text-shadow: 0 0 8px var(--primary-glow);
}

@keyframes marquee {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* ==========================================================================
   KINETIC SPLIT-WORD REVEAL (Apple / Awwwards Style)
   ========================================================================== */
.word-wrap {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
  margin-inline-end: 0.24em;
  line-height: inherit;
}

.word-inner {
  display: inline-block;
  transform: translateY(125%) rotate(5deg);
  opacity: 0;
  filter: blur(8px);
  transition: transform 0.85s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)), 
              opacity 0.85s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)), 
              filter 0.85s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
  will-change: transform, opacity, filter;
}

.show .word-inner, 
.show.word-inner,
.in-view .word-inner,
.hero .word-inner {
  transform: translateY(0) rotate(0deg);
  opacity: 1;
  filter: blur(0);
}

/* Chapter Horizon Beam Line - 100% Compositor (scaleX) */
.chapter::after,
.chapter-beam {
  content: '';
  display: inline-block;
  height: 2px;
  width: 75px;
  vertical-align: middle;
  margin-inline-start: 14px;
  background: linear-gradient(to right, var(--primary), transparent);
  box-shadow: 0 0 10px var(--primary-glow);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 1.1s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
  will-change: transform;
}

body.rtl-mode .chapter::after,
[dir="rtl"] .chapter::after,
body.rtl-mode .chapter-beam,
[dir="rtl"] .chapter-beam {
  transform-origin: right center;
  background: linear-gradient(to left, var(--primary), transparent);
}

.show .chapter::after,
.in-view .chapter::after,
.show .chapter-beam,
.in-view .chapter-beam {
  transform: scaleX(1);
}

/* Laser Scanline on Card Reveal - 100% Compositor (translateY) */
.card-scanline {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  inset-inline-end: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 5%, var(--primary) 45%, var(--color-white) 55%, var(--primary) 65%, transparent 95%);
  box-shadow: 0 0 15px var(--primary-glow);
  opacity: 0;
  pointer-events: none;
  z-index: 8;
  will-change: transform, opacity;
}

.show .card-scanline,
.show.card-scanline {
  animation: cardScan 1.2s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)) forwards;
}

@keyframes cardScan {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 0.9; }
  100% { transform: translateY(280px); opacity: 0; }
}

/* Staggered Reveal on Scroll (Desktop & Mobile) */
.reveal {
  opacity: 0;
  transform: perspective(1000px) rotateX(10deg) translateY(40px) scale(0.97);
  transition: opacity 0.85s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)), 
              transform 0.85s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)), 
              box-shadow 0.85s ease;
  will-change: opacity, transform;
}

.reveal.show {
  opacity: 1;
  transform: perspective(1000px) rotateX(0deg) translateY(0) scale(1);
}

/* Staggered Delays for Siblings */
.project:nth-child(1) { transition-delay: 0.05s; }
.project:nth-child(2) { transition-delay: 0.18s; }
.project:nth-child(3) { transition-delay: 0.32s; }

.pillar-card:nth-child(1) { transition-delay: 0.06s; }
.pillar-card:nth-child(2) { transition-delay: 0.16s; }
.pillar-card:nth-child(3) { transition-delay: 0.26s; }
.pillar-card:nth-child(4) { transition-delay: 0.36s; }

.cards article:nth-child(1) { transition-delay: 0.08s; }
.cards article:nth-child(2) { transition-delay: 0.22s; }
.cards article:nth-child(3) { transition-delay: 0.36s; }

/* Cyber Text Scramble Glyph Styling */
.scramble-glyph {
  color: var(--primary);
  font-family: var(--font-mono, monospace);
  font-weight: 700;
  display: inline-block;
  text-shadow: 0 0 8px var(--primary-glow);
  transform: scale(1.08);
}

/* Text Shimmer Gradient Animation */
.shimmer-text {
  background: linear-gradient(90deg, var(--color-cream) 0%, var(--primary) 30%, var(--primary-light) 50%, var(--primary) 70%, var(--color-cream) 100%);
  background-size: 200% auto;
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  display: inline-block;
  animation: textShimmer 6s linear infinite;
  will-change: background-position;
}

@keyframes textShimmer {
  0% { background-position: 0% center; }
  100% { background-position: 200% center; }
}

/* Brand & Heading Cyber Glitch on Hover & Scroll-In */
.glitch-hover {
  transition: all 0.2s ease;
  display: inline-block;
}

.glitch-hover:hover, .glitch-hover.glitch-active {
  animation: cyberGlitch 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes cyberGlitch {
  0% { transform: translate(0); text-shadow: -1.5px 0 var(--primary), 1.5px 0 var(--color-accent-blue); }
  25% { transform: translate(-1px, 1px); text-shadow: 1.5px 0 var(--primary), -1.5px 0 var(--color-accent-blue); }
  50% { transform: translate(1px, -1px); text-shadow: -1px 0 var(--primary), 1px 0 var(--color-accent-blue); }
  75% { transform: translate(-1px, -0.5px); text-shadow: 1px 0 var(--primary), -1px 0 var(--color-accent-blue); }
  100% { transform: translate(0); text-shadow: none; }
}

/* Interactive Spotlight / Mouse Torch on Cards */
.project::before, .ide::before, .cards article::before, .pillar-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(380px circle at var(--mouse-x, -500px) var(--mouse-y, -500px), var(--primary-glow), transparent 45%);
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.project:hover::before, .ide:hover::before, .cards article:hover::before, .pillar-card:hover::before {
  opacity: 1;
}

/* Click & Mobile Touch Shockwave / Kinetic Ripple */
.click-shockwave {
  position: fixed;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full, 9999px);
  border: 2px solid var(--primary, var(--primary-glow));
  box-shadow: 0 0 18px var(--primary-glow);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.2);
  animation: shockwave 0.65s var(--ease-snappy, cubic-bezier(0.1, 0.8, 0.3, 1)) forwards;
  z-index: 99999;
  will-change: transform, opacity;
}

@keyframes shockwave {
  0% { transform: translate(-50%, -50%) scale(0.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(5.5); opacity: 0; }
}

/* Project Card 3D Depth & Glowing Edge */
.project {
  transform-style: preserve-3d;
  perspective: 1000px;
  transition: transform 0.45s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)), 
              border-color 0.3s ease, 
              box-shadow 0.45s ease;
  will-change: transform, box-shadow;
}

.project:hover {
  border-color: var(--border-active, var(--border-active));
  box-shadow: var(--shadow-xl, 0 25px 60px -15px rgba(0, 0, 0, 0.9)), 0 0 25px var(--primary-glow);
}

.project .visual {
  transition: transform 0.4s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)), box-shadow 0.4s ease;
  border-radius: var(--radius-md, 10px);
}

.project:hover .visual {
  box-shadow: 0 25px 50px -12px var(--primary-glow);
}

/* Button Kinetic Hover & Shimmer Wipe */
.button, .toplink, .social-pill {
  position: relative;
  overflow: hidden;
  transition: transform 0.25s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)), 
              box-shadow 0.25s ease,
              background-color 0.2s ease,
              color 0.2s ease;
}

.button:after, .toplink:after {
  content: '';
  position: absolute;
  inset-block-start: -50%;
  inset-inline-start: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.28), transparent);
  transform: rotate(45deg) translateY(-100%);
  transition: transform 0.65s ease;
  will-change: transform;
}

.button:hover:after, .toplink:hover:after {
  transform: rotate(45deg) translateY(100%);
}

/* ==========================================================================
   MOBILE-SPECIFIC SCROLL & TOUCH KINETICS (@media max-width: 950px)
   ========================================================================== */
@media (max-width: 950px) {
  /* Dynamic Breathing Neon Borders on Mobile Cards in View */
  .reveal.show.project,
  .reveal.show.pillar-card,
  .reveal.show.cards article {
    border-color: var(--border-active);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.8), 0 0 20px var(--primary-glow);
    animation: mobileBreathingGlow 4s ease-in-out infinite alternate;
  }

  @keyframes mobileBreathingGlow {
    0% { border-color: rgba(255, 255, 255, 0.1); box-shadow: 0 10px 30px rgba(0,0,0,0.6), 0 0 10px transparent; }
    100% { border-color: var(--border-active); box-shadow: 0 18px 45px rgba(0,0,0,0.8), 0 0 22px var(--primary-glow); }
  }

  /* 3D Isometric Tilt for Lab Cards on Mobile Scroll */
  .cards {
    perspective: 1000px !important;
  }
  .cards article:nth-child(1) {
    transform: perspective(700px) rotateY(-3deg) rotateX(4deg) translateY(0);
  }
  .cards article:nth-child(2) {
    transform: perspective(700px) rotateY(3deg) rotateX(4deg) translateY(15px);
  }
  .cards article:nth-child(3) {
    transform: perspective(700px) rotateY(-2deg) rotateX(5deg) translateY(0);
  }

  /* Mobile Touch Tap Active State */
  .project:active, .cards article:active, .pillar-card:active {
    transform: scale(0.97) translateY(2px) !important;
    border-color: var(--primary) !important;
  }

  /* Smooth Snap Horizontal Project Rail on Mobile */
  .rail {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-block-end: 25px;
  }
  body.rtl-mode .rail,
  [dir="rtl"] .rail {
    padding-inline-end: 0 !important;
    padding-inline-start: 6% !important;
  }
  .project {
    scroll-snap-align: center;
  }

  /* Clean Kinetic Glow for Hero Headings on Mobile (Zero vertical drift) */
  .hero h1 i {
    display: inline;
    animation: heroGlowText 4s ease-in-out infinite alternate;
  }
  @keyframes heroGlowText {
    0% { text-shadow: 0 0 10px rgba(255, 90, 31, 0.2); }
    100% { text-shadow: 0 0 20px var(--primary-glow); }
  }

  /* Mobile Ambient Glow Motion */
  .ambient-glow {
    width: 90vw !important;
    height: 90vw !important;
    filter: blur(60px) !important;
    opacity: 0.45 !important;
  }
}

/* ==========================================================================
   ACCESSIBILITY: PREFERS-REDUCED-MOTION SAFEGUARD
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .word-inner {
    transform: none !important;
    opacity: 1 !important;
    filter: none !important;
  }
  .reveal {
    opacity: 1 !important;
    transform: none !important;
  }
  .chapter-beam {
    transform: scaleX(1) !important;
  }
  .card-scanline {
    display: none !important;
  }
  .particle,
  .fx-noise {
    display: none !important;
  }
}

/* ==========================================================================
   Native CSS Scroll-Driven Animations (Compositor Level)
   ========================================================================== */
@supports (animation-timeline: scroll()) {
  .scroll-progress {
    transform-origin: left center;
    animation: scrollProgress linear auto;
    animation-timeline: scroll(root block);
  }
  [dir="rtl"] .scroll-progress,
  body.rtl-mode .scroll-progress {
    transform-origin: right center;
  }
  @keyframes scrollProgress {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
  }
}

/* Section visibility is controlled progressively; essential content is never hidden. */
