/* ══════════════════════════════════════════════════
   MICRO-INTERACTION LAB v3.1 — Master Stylesheet
   Apple-style Motion · 60fps · Premium UI · GPU Optimized
   ══════════════════════════════════════════════════ */

/* ── Global Easing Tokens ── */
:root {
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-spring: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Smooth scroll ── */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
  overflow-x: hidden;
}

/* ── Selection color ── */
::selection {
  background: rgba(0, 122, 255, 0.15);
  color: inherit;
}

/* ── Custom Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.18); }
.dark ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); }
.dark ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.1); }

/* ── Body global transition ── */
body {
  transition: background-color 0.5s ease, color 0.5s ease;
  overflow-x: hidden;
  position: relative;
  width: 100%;
}

/* ══════════════════════════════════════
   NAV GLASS — Premium Frosted Glass
   ══════════════════════════════════════ */
.nav-glass {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.03),
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 4px 16px rgba(0, 0, 0, 0.04);
  transition: all 0.5s var(--ease-smooth);
}

.dark .nav-glass {
  background: rgba(20, 20, 22, 0.72);
  border-color: rgba(255, 255, 255, 0.06);
  box-shadow:
    0 0 0 0.5px rgba(255, 255, 255, 0.03),
    0 1px 2px rgba(0, 0, 0, 0.2),
    0 4px 16px rgba(0, 0, 0, 0.2);
}

/* Top refraction highlight */
.nav-glass::before {
  content: '';
  position: absolute;
  top: 0; left: 16px; right: 16px;
  height: 0.5px;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.8) 20%, rgba(255,255,255,0.9) 50%, rgba(255,255,255,0.8) 80%, transparent 100%);
  pointer-events: none;
  border-radius: 1px;
}
.dark .nav-glass::before {
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.08) 20%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.08) 80%, transparent 100%);
}

/* Nav scrolled state (added by JS) */
.nav-glass.scrolled {
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.04),
    0 2px 4px rgba(0, 0, 0, 0.06),
    0 8px 24px rgba(0, 0, 0, 0.06);
}
.dark .nav-glass.scrolled {
  box-shadow:
    0 0 0 0.5px rgba(255, 255, 255, 0.04),
    0 2px 4px rgba(0, 0, 0, 0.3),
    0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ── Nav Pill Track ── */
.nav-pill-track {
  position: relative;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 12px;
}
.dark .nav-pill-track {
  background: rgba(255, 255, 255, 0.04);
}

/* ── Nav Sliding Indicator ── */
.nav-indicator {
  position: absolute;
  height: calc(100% - 6px);
  top: 3px;
  border-radius: 10px;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 0 0 0.5px rgba(0,0,0,0.04);
  transition: left 0.35s var(--ease-out-expo), width 0.35s var(--ease-out-expo), opacity 0.2s ease;
  will-change: left, width;
  z-index: 1;
  opacity: 0;
}
.nav-indicator.stretching {
  transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}
.nav-indicator.settling {
  transition: left 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}
.dark .nav-indicator {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2), 0 0 0 0.5px rgba(255,255,255,0.06);
}

/* ── Nav Pills ── */
.nav-pill {
  color: rgba(107, 114, 128, 0.8);
  white-space: nowrap;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dark .nav-pill {
  color: rgba(156, 163, 175, 0.7);
}
.nav-pill:hover {
  color: rgba(17, 24, 39, 0.9);
}
.dark .nav-pill:hover {
  color: rgba(243, 244, 246, 0.9);
}
.nav-pill.active {
  color: #111827;
  font-weight: 600;
}
.dark .nav-pill.active {
  color: #f3f4f6;
  font-weight: 600;
}

/* ── Nav Action Buttons ── */
.nav-action-btn {
  color: rgba(107, 114, 128, 0.7);
  position: relative;
  overflow: hidden;
}
.dark .nav-action-btn {
  color: rgba(156, 163, 175, 0.6);
}
.nav-action-btn:hover {
  color: rgba(17, 24, 39, 0.9);
  background: rgba(0, 0, 0, 0.04);
}
.dark .nav-action-btn:hover {
  color: rgba(243, 244, 246, 0.9);
  background: rgba(255, 255, 255, 0.06);
}

/* ── Nav Logo — Faceted Gem Icon ── */
.logo-icon {
  transition: transform 0.4s var(--ease-spring), filter 0.4s var(--ease-smooth);
  will-change: transform;
  filter: drop-shadow(0 2px 8px rgba(99, 102, 241, 0.3));
}
.nav-logo:hover .logo-icon {
  transform: scale(1.1) rotate(-3deg);
  filter: drop-shadow(0 4px 14px rgba(99, 102, 241, 0.4));
}

/* ── Mobile Menu ── */
.mobile-menu {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  transform-origin: top center;
  transition: all 0.3s var(--ease-spring);
}
.dark .mobile-menu {
  background: rgba(20, 20, 22, 0.85);
  border-color: rgba(255, 255, 255, 0.06);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.mobile-menu.open {
  display: block;
  animation: menu-enter 0.3s var(--ease-spring) forwards;
}
.mobile-menu.closing {
  animation: menu-exit 0.2s var(--ease-smooth) forwards;
}

@keyframes menu-enter {
  from { opacity: 0; transform: scale(0.95) translateY(-8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes menu-exit {
  from { opacity: 1; transform: scale(1) translateY(0); }
  to { opacity: 0; transform: scale(0.95) translateY(-8px); }
}

.mobile-nav-link {
  color: rgba(107, 114, 128, 0.8);
}
.dark .mobile-nav-link {
  color: rgba(156, 163, 175, 0.7);
}
.mobile-nav-link:hover, .mobile-nav-link.active {
  color: #111827;
  background: rgba(0, 0, 0, 0.04);
}
.dark .mobile-nav-link:hover, .dark .mobile-nav-link.active {
  color: #f3f4f6;
  background: rgba(255, 255, 255, 0.06);
}

/* Hamburger animation */
.hamburger-icon.open span:nth-child(1) {
  transform: rotate(45deg) translate(3px, 4px);
}
.hamburger-icon.open span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.hamburger-icon.open span:nth-child(3) {
  transform: rotate(-45deg) translate(3px, -4px);
}

/* ══════════════════════════════════════
   THEME TOGGLE — Smooth Icon Morph
   ══════════════════════════════════════ */
.theme-icon-wrapper {
  position: relative;
  width: 15px;
  height: 15px;
}
.theme-icon-wrapper svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: transform 0.6s var(--ease-spring), opacity 0.4s ease;
  will-change: transform;
}
/* Sun (visible in dark mode) */
.theme-sun {
  opacity: 0;
  transform: rotate(-45deg) scale(0);
}
.dark .theme-sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}
/* Moon (visible in light mode) */
.theme-moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}
.dark .theme-moon {
  opacity: 0;
  transform: rotate(45deg) scale(0);
}

/* Global smooth color transitions for theme switch */
*,
*::before,
*::after {
  transition-property: background-color, border-color, color, fill, stroke, box-shadow;
  transition-duration: 0s;
  transition-timing-function: ease;
}
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
  transition-duration: 0.5s !important;
}

/* ══════════════════════════════════════
   HERO SECTION
   ══════════════════════════════════════ */

/* Hero orb float */
@keyframes orb-float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -30px) scale(1.05); }
  50% { transform: translate(-20px, 20px) scale(0.95); }
  75% { transform: translate(20px, 10px) scale(1.02); }
}

/* Hero elements entrance */
.hero-element {
  opacity: 0;
  transform: translateY(24px) scale(0.98);
  animation: hero-enter 0.9s var(--ease-out-expo) forwards;
  animation-delay: var(--delay, 0s);
  will-change: transform, opacity;
}
@keyframes hero-enter {
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Scroll dot */
@keyframes scroll-dot {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(6px); }
}
.animate-scroll-dot {
  animation: scroll-dot 1.5s ease-in-out infinite;
}

/* Hero CTA buttons */
.hero-cta-primary {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  transition: transform 0.3s var(--ease-spring), box-shadow 0.3s var(--ease-smooth);
}
.hero-cta-primary:hover {
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}
.dark .hero-cta-primary {
  box-shadow: 0 4px 16px rgba(255, 255, 255, 0.1);
}
.dark .hero-cta-primary:hover {
  box-shadow: 0 8px 28px rgba(255, 255, 255, 0.15);
}

.hero-cta-secondary {
  background: rgba(243, 244, 246, 0.8);
  color: rgba(55, 65, 81, 1);
  border: 1px solid rgba(229, 231, 235, 0.6);
  transition: all 0.3s var(--ease-spring);
}
.hero-cta-secondary:hover {
  background: rgba(229, 231, 235, 0.9);
  transform: translateY(-1px);
}
.dark .hero-cta-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(209, 213, 219, 1);
  border-color: rgba(255, 255, 255, 0.08);
}
.dark .hero-cta-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Hero floating particles — GPU optimized */
.hero-particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  animation: particle-float 12s ease-in-out infinite;
  will-change: transform, opacity;
}
@keyframes particle-float {
  0%, 100% { opacity: 0; transform: translateY(0) scale(0.5); }
  10% { opacity: 0.6; }
  50% { opacity: 0.3; transform: translateY(-80px) scale(1); }
  90% { opacity: 0.6; }
}

/* ══════════════════════════════════════
   SECTION HEADERS & DIVIDERS
   ══════════════════════════════════════ */

.section-glow {
  opacity: 0;
  transition: opacity 0.8s var(--ease-smooth);
}
.section-glow.visible {
  opacity: 1;
}

.section-header {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.8s var(--ease-out-expo), transform 0.8s var(--ease-out-expo);
  will-change: transform, opacity;
}
.section-header.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Section header accent dot glow pulse */
.section-header .rounded-full[class*="shadow-"] {
  animation: dot-glow 2s ease-in-out infinite;
}
@keyframes dot-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ══════════════════════════════════════
   COMPONENT CARDS — Stagger Reveal (GPU)
   ══════════════════════════════════════ */
.component-card,
.tilt-card,
.glow-card,
.glass-card,
.reveal-card,
.stacked-card,
.spotlight-card {
  opacity: 0;
  transform: translateY(24px) scale(0.98);
  transition:
    opacity 0.6s var(--ease-out-expo),
    transform 0.6s var(--ease-out-expo),
    box-shadow 0.5s var(--ease-smooth),
    border-color 0.5s var(--ease-smooth);
  will-change: transform, opacity;
}
.component-card.visible,
.tilt-card.visible,
.glow-card.visible,
.glass-card.visible,
.reveal-card.visible,
.stacked-card.visible,
.spotlight-card.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ══════════════════════════════════════
   TILT CARD — 3D Perspective (GPU)
   ══════════════════════════════════════ */
.perspective-container { perspective: 800px; }
.tilt-card-inner {
  transform-style: preserve-3d;
  will-change: transform;
}
.tilt-card-float {
  transition: transform 600ms var(--ease-spring);
  will-change: transform;
}
.tilt-card-glare {
  background: radial-gradient(circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
    rgba(255, 255, 255, 0.15) 0%, transparent 60%);
}

/* ══════════════════════════════════════
   NEON BUTTON
   ══════════════════════════════════════ */
.neon-btn-wrapper { --size: 200%; }
.neon-border {
  width: var(--size); height: var(--size);
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
}

/* ══════════════════════════════════════
   INPUT FOCUS GLOW
   ══════════════════════════════════════ */
.input-focus-glow:focus-within .input-glow-border { opacity: 1; }

/* ══════════════════════════════════════
   VALIDATION STATES
   ══════════════════════════════════════ */
.validation-wrapper.is-valid .validation-input { border-color: #34C759; }
.validation-wrapper.is-valid .validation-icon { opacity: 1; transform: translateY(-50%) scale(1); }
.validation-wrapper.is-valid .valid-icon { display: block; }
.validation-wrapper.is-valid .validation-msg { opacity: 1; transform: translateY(0); color: #34C759; }

.validation-wrapper.is-invalid .validation-input { border-color: #FF3B30; }
.validation-wrapper.is-invalid .validation-icon { opacity: 1; transform: translateY(-50%) scale(1); }
.validation-wrapper.is-invalid .invalid-icon { display: block; }
.validation-wrapper.is-invalid .validation-msg { opacity: 1; transform: translateY(0); color: #FF3B30; }

/* ══════════════════════════════════════
   LOADER KEYFRAMES
   ══════════════════════════════════════ */
@keyframes wave-bar { 0%, 100% { height: 8px; } 50% { height: 28px; } }
@keyframes morph-square {
  0% { border-radius: 6px; transform: rotate(0deg) scale(1); }
  25% { border-radius: 50%; transform: rotate(90deg) scale(0.8); }
  50% { border-radius: 6px; transform: rotate(180deg) scale(1); }
  75% { border-radius: 50%; transform: rotate(270deg) scale(0.8); }
  100% { border-radius: 6px; transform: rotate(360deg) scale(1); }
}
@keyframes bounce-loader { from { transform: translateY(0); } to { transform: translateY(-12px); } }
@keyframes dna-helix { 0%, 100% { transform: translateY(-8px) scale(0.6); opacity: 0.4; } 50% { transform: translateY(8px) scale(1); opacity: 1; } }
@keyframes progress-bar { 0% { width: 0%; } 50% { width: 100%; } 100% { width: 0%; } }

/* ══════════════════════════════════════
   MORPH BUTTON STATES
   ══════════════════════════════════════ */
.morph-btn[data-state="loading"] { width: 48px !important; padding: 12px !important; border-radius: 50% !important; background-color: #007AFF !important; box-shadow: 0 4px 16px rgba(0,122,255,0.3) !important; }
.morph-btn[data-state="loading"] .morph-text { opacity: 0; }
.morph-btn[data-state="loading"] .morph-spinner { opacity: 1; animation: spin 0.8s linear infinite; }
.morph-btn[data-state="success"] { width: 48px !important; padding: 12px !important; border-radius: 50% !important; background-color: #34C759 !important; box-shadow: 0 4px 16px rgba(52,199,89,0.3) !important; }
.morph-btn[data-state="success"] .morph-text { opacity: 0; }
.morph-btn[data-state="success"] .morph-check { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════
   RIPPLE ANIMATION
   ══════════════════════════════════════ */
.ripple-effect {
  position: absolute; border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0);
  animation: ripple-expand 0.6s var(--ease-out-expo) forwards;
  pointer-events: none;
}
@keyframes ripple-expand { to { transform: scale(4); opacity: 0; } }

/* ══════════════════════════════════════
   i18n TRANSITION — Staggered Crossfade
   ══════════════════════════════════════ */
[data-i18n] {
  display: inline-block;
  transition: opacity 0.15s ease;
}
[data-i18n].i18n-fade-out {
  opacity: 0;
}

/* ══════════════════════════════════════
   PAGE LOAD ANIMATION
   ══════════════════════════════════════ */
.page-loading {
  opacity: 0;
}
.page-loaded {
  opacity: 1;
  transition: opacity 0.4s var(--ease-smooth);
}

/* ══════════════════════════════════════
   BACK TO TOP BUTTON
   ══════════════════════════════════════ */
#back-to-top {
  transition: opacity 0.3s var(--ease-smooth), transform 0.3s var(--ease-spring), box-shadow 0.3s var(--ease-smooth);
}

/* ══════════════════════════════════════
   RESPONSIVE — Mobile First Optimization
   ══════════════════════════════════════ */

/* ── Touch Devices: Tap Feedback ── */
@media (hover: none) and (pointer: coarse) {
  /* Disable hover effects that feel janky on touch */
  .component-card:hover,
  .tilt-card-inner:hover,
  .glow-card:hover,
  .glass-card:hover {
    transform: none !important;
  }
  /* Better tap feedback */
  .component-card:active,
  .mobile-nav-link:active,
  .hero-cta-primary:active,
  .hero-cta-secondary:active {
    transform: scale(0.97) !important;
    transition-duration: 0.1s !important;
  }
  .nav-action-btn:active {
    transform: scale(0.9);
    transition-duration: 0.1s;
  }
}

/* ── Small screens: ≤640px ── */
@media (max-width: 640px) {
  /* Tighter scroll padding for mobile nav */
  html { scroll-padding-top: 70px; }

  /* Nav: compact on mobile */
  .nav-glass {
    margin-left: 6px;
    margin-right: 6px;
    border-radius: 16px;
    padding: 0 2px;
  }

  /* Nav outer container: prevent overflow */
  #main-nav > div {
    padding-left: 2px;
    padding-right: 2px;
  }

  /* Hero: smaller orbs, less blur for perf */
  .hero-orb {
    width: 250px !important;
    height: 250px !important;
    filter: blur(50px) !important;
  }

  /* Hero: better mobile typography */
  .section-header h2 { font-size: 1.75rem; }
  .section-header p { font-size: 0.7rem; max-width: 220px; }

  /* Sections: tighter vertical rhythm */
  section { padding-left: 1rem; padding-right: 1rem; }
  .section-header { margin-bottom: 2rem !important; }

  /* Cards: reduce min-height */
  .component-card { min-height: 200px !important; padding: 1.25rem !important; }

  /* Tilt card: simpler on mobile (no 3D, it's touch) */
  .perspective-container { perspective: none; }
  .tilt-card-inner {
    transform: none !important;
    min-height: 240px !important;
    padding: 1.25rem !important;
  }

  /* Glow card */
  .glow-card { min-height: 240px !important; }
  .glow-card-content { padding: 1.25rem !important; }

  /* Inputs: full width on mobile */
  .input-focus-glow input,
  .float-input,
  .validation-input {
    font-size: 16px !important; /* Prevents iOS zoom */
  }

  /* Loaders grid: smaller cards */
  .loader-orbit, .loader-dots, .loader-wave {
    transform: scale(0.9);
  }

  /* Footer: compact */
  footer { padding: 3rem 1rem !important; }

  /* Back to top: smaller */
  #back-to-top {
    width: 36px;
    height: 36px;
    bottom: 16px;
    right: 16px;
  }

  /* Mobile menu: stagger links */
  .mobile-menu.open .mobile-nav-link {
    animation: mobile-link-enter 0.3s var(--ease-out-expo) forwards;
    opacity: 0;
  }
  .mobile-menu.open .mobile-nav-link:nth-child(1) { animation-delay: 0.03s; }
  .mobile-menu.open .mobile-nav-link:nth-child(2) { animation-delay: 0.06s; }
  .mobile-menu.open .mobile-nav-link:nth-child(3) { animation-delay: 0.09s; }
  .mobile-menu.open .mobile-nav-link:nth-child(4) { animation-delay: 0.12s; }
  .mobile-menu.open .mobile-nav-link:nth-child(5) { animation-delay: 0.15s; }

  /* Mobile nav link: bigger touch target */
  .mobile-nav-link {
    padding: 0.75rem 1rem !important;
    font-size: 15px !important;
    border-radius: 12px;
  }

  /* Reduce particle count on mobile (JS handles this, but hide extras) */
  .hero-particle:nth-child(n+8) { display: none; }
}

@keyframes mobile-link-enter {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Medium screens: 641px–768px ── */
@media (min-width: 641px) and (max-width: 768px) {
  .section-header h2 { font-size: 2rem; }
}

/* ── Safe area insets for notched phones ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  footer { padding-bottom: calc(3rem + env(safe-area-inset-bottom)); }
  #back-to-top { bottom: calc(16px + env(safe-area-inset-bottom)); }
  .nav-glass { margin-top: calc(8px + env(safe-area-inset-top, 0px)); }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
