/* ============================================
   UI/UX Enhancements - Next Level Features
   ============================================ */

/* ============================================
   CSS Custom Properties for Enhanced Features
   ============================================ */
:root {
  /* Magnetic button */
  --magnetic-strength: 0.3;
  --magnetic-radius: 150px;
  
  /* Cursor effects */
  --cursor-size: 20px;
  --cursor-color: rgba(37, 99, 235, 0.5);
  --cursor-hover-size: 50px;
  --cursor-hover-color: rgba(37, 99, 235, 0.2);
  
  /* Grain texture */
  --grain-opacity: 0.03;
  --grain-size: 200px;
  
  /* Dynamic shadows */
  --shadow-light-x: -20px;
  --shadow-light-y: -20px;
  --shadow-light-color: rgba(255, 255, 255, 0.1);
  
  /* Skeleton loading */
  --skeleton-base: rgba(200, 200, 200, 0.15);
  --skeleton-shine: rgba(255, 255, 255, 0.1);
  
  /* Parallax */
  --parallax-speed: 0.5;
}

/* ============================================
   Custom Cursor
   ============================================ */
.custom-cursor {
  position: fixed;
  width: var(--cursor-size);
  height: var(--cursor-size);
  border: 2px solid var(--cursor-color);
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  transition: width 0.3s ease, height 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
  mix-blend-mode: difference;
}

.custom-cursor.cursor-hover {
  width: var(--cursor-hover-size);
  height: var(--cursor-hover-size);
  background-color: var(--cursor-hover-color);
  border-color: transparent;
}

.custom-cursor.cursor-click {
  transform: translate(-50%, -50%) scale(0.8);
}

.cursor-dot {
  position: fixed;
  width: 6px;
  height: 6px;
  background-color: var(--cursor-color);
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
}

/* Hide default cursor on interactive elements when custom cursor is active */
body.has-custom-cursor a,
body.has-custom-cursor button,
body.has-custom-cursor [role="button"],
body.has-custom-cursor input,
body.has-custom-cursor textarea,
body.has-custom-cursor select {
  cursor: none;
}

/* ============================================
   Magnetic Buttons
   ============================================ */
.magnetic-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 2rem;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  will-change: transform;
}

.magnetic-btn::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-color), var(--accent-warm));
  z-index: -1;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.magnetic-btn:hover::before {
  opacity: 1;
}

.magnetic-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.3);
}

/* ============================================
   Grain Texture Overlay
   ============================================ */
.grain-overlay {
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  pointer-events: none;
  z-index: 9998;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  animation: grainShift 8s steps(10) infinite;
}

@keyframes grainShift {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-5%, -10%); }
  20% { transform: translate(-15%, 5%); }
  30% { transform: translate(7%, -25%); }
  40% { transform: translate(-5%, 25%); }
  50% { transform: translate(-15%, 10%); }
  60% { transform: translate(15%, 0%); }
  70% { transform: translate(0%, 15%); }
  80% { transform: translate(3%, 35%); }
  90% { transform: translate(-10%, 10%); }
}

/* ============================================
   3D Card Transforms
   ============================================ */
.card-3d {
  perspective: 1000px;
  transform-style: preserve-3d;
}

.card-3d-inner {
  position: relative;
  transition: transform 0.6s ease, box-shadow 0.6s ease;
  transform-style: preserve-3d;
}

.card-3d:hover .card-3d-inner {
  transform: rotateX(5deg) rotateY(-5deg) translateY(-8px);
  box-shadow: 
    -20px 20px 40px rgba(0, 0, 0, 0.15),
    20px -20px 40px rgba(255, 255, 255, 0.1);
}

/* ============================================
   Parallax Elements
   ============================================ */
.parallax-element {
  will-change: transform;
  transition: transform 0.1s linear;
}

.parallax-hero {
  position: relative;
  overflow: hidden;
}

.parallax-hero .parallax-bg {
  position: absolute;
  top: -20%;
  left: -20%;
  width: 140%;
  height: 140%;
  will-change: transform;
}

/* ============================================
   Skeleton Loading States
   ============================================ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--skeleton-base) 25%,
    var(--skeleton-shine) 50%,
    var(--skeleton-base) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 8px;
}

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

.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
}

.skeleton-title {
  height: 2em;
  width: 60%;
  margin-bottom: 1em;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-image {
  width: 100%;
  height: 200px;
}

/* ============================================
   Reading Time Indicator
   ============================================ */
.reading-time {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.25rem 0.75rem;
  background: rgba(37, 99, 235, 0.08);
  border-radius: 20px;
}

.reading-time svg {
  width: 16px;
  height: 16px;
}

/* ============================================
   Breadcrumb Navigation
   ============================================ */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--accent-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

.breadcrumb a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.breadcrumb-separator {
  opacity: 0.5;
}

/* ============================================
   Scroll Progress Indicator (Enhanced)
   ============================================ */
.scroll-progress-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.05);
}

.scroll-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-color), var(--accent-warm));
  transition: width 0.1s linear;
  box-shadow: 0 0 10px var(--accent-color);
}

/* ============================================
   Keyboard Shortcuts Modal
   ============================================ */
.keyboard-shortcuts {
  position: fixed;
  bottom: 5rem;
  right: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 1000;
}

.keyboard-shortcuts.visible {
  opacity: 1;
  visibility: visible;
}

.keyboard-shortcuts kbd {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  font-family: monospace;
  font-size: 0.7rem;
  background: var(--surface-raised);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  margin: 0 0.2rem;
}

/* ============================================
   Related Content Cards
   ============================================ */
.related-content {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

.related-content h3 {
  margin-bottom: 1.5rem;
  font-size: 1.25rem;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.related-card {
  padding: 1.25rem;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.related-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
}

.related-card h4 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  line-height: 1.4;
}

.related-card .related-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ============================================
   Social Proof Elements
   ============================================ */
.social-proof {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: rgba(37, 99, 235, 0.05);
  border-radius: 24px;
  font-size: 0.85rem;
}

.social-proof-avatars {
  display: flex;
}

.social-proof-avatars img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--surface-card);
  margin-left: -8px;
}

.social-proof-avatars img:first-child {
  margin-left: 0;
}

/* ============================================
   Content Filter/Tabs
   ============================================ */
.content-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1.5rem 0;
}

.filter-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--surface-card);
  color: var(--text-color);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.filter-btn.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: white;
}

/* ============================================
   Image Gallery with Lightbox
   ============================================ */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.gallery-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 12px;
  cursor: pointer;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.gallery-item:hover img {
  transform: scale(1.1);
}

.gallery-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
  display: flex;
  align-items: flex-end;
  padding: 1rem;
}

.gallery-item:hover .gallery-overlay {
  opacity: 1;
}

.gallery-overlay span {
  color: white;
  font-size: 0.9rem;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.lightbox.active {
  display: flex;
}

.lightbox img {
  max-width: 90%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1.5rem;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s ease;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ============================================
   Animated Background Particles
   ============================================ */
.particles-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--accent-color);
  border-radius: 50%;
  opacity: 0;
  animation: particleFloat linear infinite;
}

@keyframes particleFloat {
  0% {
    opacity: 0;
    transform: translateY(100vh) scale(0);
  }
  10% {
    opacity: 0.6;
  }
  90% {
    opacity: 0.6;
  }
  100% {
    opacity: 0;
    transform: translateY(-10vh) scale(1);
  }
}

/* ============================================
   Dynamic Shadow Effect
   ============================================ */
.dynamic-shadow {
  position: relative;
}

.dynamic-shadow::before {
  content: '';
  position: absolute;
  top: var(--shadow-light-y);
  left: var(--shadow-light-x);
  width: 60%;
  height: 60%;
  background: var(--shadow-light-color);
  filter: blur(40px);
  border-radius: 50%;
  z-index: -1;
  transition: all 0.3s ease;
}

/* ============================================
   Skip Link (Accessibility)
   ============================================ */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.5rem;
  background: var(--accent-color);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  z-index: 10001;
  transition: top 0.3s ease;
}

.skip-link:focus {
  top: 1rem;
}

/* ============================================
   Text Size Controls (Accessibility)
   ============================================ */
.text-size-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
}

.text-size-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface-card);
  color: var(--text-color);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.text-size-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.text-size-btn.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: white;
}

/* ============================================
   Reduced Motion Support
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .grain-overlay,
  .particle,
  .skeleton,
  .parallax-element,
  .card-3d-inner,
  .custom-cursor,
  .cursor-dot {
    animation: none !important;
    transition: none !important;
  }
  
  .custom-cursor,
  .cursor-dot {
    display: none !important;
  }
}

/* ============================================
   Dark Mode Adjustments
   ============================================ */
[data-theme="dark"] .grain-overlay {
  opacity: 0.02;
}

[data-theme="dark"] .skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.08) 25%,
    rgba(255, 255, 255, 0.15) 50%,
    rgba(255, 255, 255, 0.08) 75%
  );
}

/* ============================================
   Mobile Optimizations
   ============================================ */
@media (max-width: 768px) {
  .custom-cursor,
  .cursor-dot,
  .grain-overlay,
  .particles-container,
  .keyboard-shortcuts {
    display: none !important;
  }
  
  .card-3d:hover .card-3d-inner {
    transform: none;
  }
  
  .related-grid {
    grid-template-columns: 1fr;
  }
}