/* Performance Optimizations for Core Web Vitals - 2025 SEO Best Practices */

/* Critical CSS for Above-the-Fold Content */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  background-color: #09090b; /* Zinc 950 */
  color: #e4e4e7; /* Zinc 200 */
  overflow-x: hidden;
  margin: 0;
  padding: 0;
  line-height: 1.6;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Font loading optimization */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/inter-var.woff2') format('woff2');
}

/* Preload critical fonts */
@font-face {
  font-family: 'Space Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/space-mono-v8-latin-regular.woff2') format('woff2');
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-v19-latin-regular.woff2') format('truetype');
}

/* Reduce layout shift - set explicit dimensions */
img, video, iframe, embed, object {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Skeleton loaders for better perceived performance */
.skeleton {
  background: linear-gradient(90deg, #27272a 25%, #3f3f46 50%, #27272a 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Optimized scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #09090b;
}

::-webkit-scrollbar-thumb {
  background: #27272a;
  border-radius: 3px;
  transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
  background: #3f3f46;
}

/* Text selection color for better UX */
::selection {
  background: rgba(16, 185, 129, 0.3);
  color: white;
}

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid #10b981;
  outline-offset: 2px;
}

/* Smooth scrolling behavior */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 4rem;
}

/* Improved font rendering */
.font-mono {
  font-family: 'Space Mono', 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace;
  font-feature-settings: 'calt' 1;
  font-variant-ligatures: contextual;
}

.font-digital {
  font-family: 'JetBrains Mono', 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  font-feature-settings: 'calt' 1;
  font-variant-ligatures: contextual;
}

/* Responsive typography for better CLS */
html {
  font-size: clamp(14px, 2.5vw, 16px);
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

/* Contain layout for better performance */
#root {
  contain: layout style;
}

/* GPU acceleration for animations */
.gpu-accelerated {
  transform: translateZ(0);
  will-change: transform;
  backface-visibility: hidden;
}

/* Reduce paint complexity */
.reduce-paint {
  contain: paint;
}

/* Optimize button interactions */
button, [role="button"] {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Better mobile viewport handling */
@viewport {
  width: device-width;
  zoom: 1.0;
}

/* Preload critical CSS */
.critical-css {
  display: block;
}

/* Hide non-critical elements initially */
.lazy-load {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.lazy-load.loaded {
  opacity: 1;
}

/* Optimized animations for better FID */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Performance-optimized transitions */
.fast-transition {
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.slow-transition {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Container queries for better responsive design */
@container (min-width: 400px) {
  .container-responsive {
    grid-template-columns: repeat(2, 1fr);
  }
}

@container (min-width: 800px) {
  .container-responsive {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Image optimization */
.optimized-image {
  content-visibility: auto;
  contain-intrinsic-size: 300px 200px;
}

/* Video optimization */
.optimized-video {
  contain: layout;
  will-change: transform;
}

/* Form optimization */
form {
  contain: layout style;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-color-scheme: light) {
  /* Light mode support if needed in future */
}

/* Performance monitoring utilities */
.performance-observer {
  position: fixed;
  bottom: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  font-size: 10px;
  font-family: monospace;
  z-index: 9999;
  display: none; /* Set to block to see performance metrics */
}

/* Critical CSS loading indicator */
.css-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, #10b981, #3b82f6, #8b5cf6);
  animation: css-loading 2s ease-in-out infinite;
  z-index: 9999;
}

@keyframes css-loading {
  0%, 100% { transform: translateX(-100%); }
  50% { transform: translateX(100%); }
}