/**
 * NovaCalc Website - Optimized CSS
 * Smooth animations, lag-free performance, polished UI
 */

/* ============================================================================
   PERFORMANCE OPTIMIZATIONS
   ============================================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Enable GPU acceleration */
html {
  scroll-behavior: smooth;
  text-rendering: optimizeLegibility;
}

body {
  overflow-x: hidden;
}

/* GPU acceleration - only apply to actively animating elements */
.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* will-change is added dynamically via JS before animation starts */
.animating {
  will-change: transform, opacity;
}

/* ============================================================================
   SMOOTH ANIMATIONS
   ============================================================================ */

/* Base smooth transitions */
.glass,
.feature,
.panel,
.kpi,
.btn,
.pill,
.footer-links a,
.footer-social a,
.theme-toggle,
.feature-icon {
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              opacity 0.4s ease-out,
              box-shadow 0.3s ease,
              background 0.3s ease,
              border-color 0.3s ease;
}

/* Feature-specific transitions */
.feature {
  transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              opacity 0.5s ease-out,
              box-shadow 0.3s ease,
              background 0.3s ease;
}

/* Hero and panel transitions */
.hero,
.panel {
  transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              opacity 0.6s ease-out;
}

/* ============================================================================
   HOVER EFFECTS - SMOOTH
   ============================================================================ */

/* Glass hover */
.glass:hover {
  transform: translateY(-4px);
  box-shadow: 
    0 8px 32px rgba(140, 130, 180, 0.2),
    0 16px 64px rgba(140, 130, 180, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

/* Feature hover - smooth lift */
.feature:hover {
  transform: translateY(-6px) scale(1.01);
  box-shadow: 
    0 12px 40px rgba(91, 143, 249, 0.15),
    0 20px 60px rgba(140, 130, 180, 0.1);
}

/* Button hover */
.btn:hover {
  transform: translateY(-2px);
}

.btn-solid:hover {
  box-shadow: 0 8px 24px rgba(91, 143, 249, 0.35);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.45);
}

/* Pill hover */
.pill:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.15);
}

/* Theme toggle hover */
.theme-toggle:hover {
  transform: scale(1.1) rotate(5deg);
}

/* Feature icon hover */
.feature:hover .feature-icon {
  transform: scale(1.1) rotate(-3deg);
  box-shadow: 0 12px 32px rgba(91, 143, 249, 0.4);
}

/* Footer links hover */
.footer-links a:hover,
.footer-social a:hover {
  transform: translateY(-2px);
}

/* ============================================================================
   SCROLL ANIMATIONS
   ============================================================================ */

/* Initial state - hidden */
.animate-on-scroll {
  opacity: 0;
  transform: translateY(25px);
  transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              opacity 0.6s ease-out;
}

/* Visible state */
.animate-on-scroll.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered delays */
.features .feature:nth-child(1),
.grid .feature:nth-child(1) { transition-delay: 0.05s; }
.features .feature:nth-child(2),
.grid .feature:nth-child(2) { transition-delay: 0.1s; }
.features .feature:nth-child(3),
.grid .feature:nth-child(3) { transition-delay: 0.15s; }

/* ============================================================================
   SMOOTH SCROLL PROGRESS
   ============================================================================ */

.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--accent, #5b8ff9), var(--accent-light, #6fa0ff));
  z-index: 9999;
  box-shadow: 0 0 10px var(--accent-light, #6fa0ff);
  transition: width 0.1s linear;
  will-change: width;
}

/* ============================================================================
   AMBIENT GLOW - SMOOTH
   ============================================================================ */

.ambient-glow {
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: 
    radial-gradient(circle at 30% 30%, rgba(91, 143, 249, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 70% 70%, rgba(111, 160, 255, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(91, 143, 249, 0.04) 0%, transparent 70%);
  pointer-events: none;
  z-index: -1;
  transition: transform 1s ease-out, opacity 1s ease-out;
  will-change: transform;
}

/* ============================================================================
   BUTTON ENHANCEMENTS
   ============================================================================ */

.btn {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  /* Prevent text selection during click */
  user-select: none;
  -webkit-user-select: none;
}

/* Ripple effect on click */
.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.4s ease, height 0.4s ease;
}

.btn:active::before {
  width: 300px;
  height: 300px;
}

/* Loading state */
.btn.loading {
  pointer-events: none;
  opacity: 0.8;
}

.btn.loading::after {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

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

/* ============================================================================
   FOCUS STATES - SMOOTH
   ============================================================================ */

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent, #5b8ff9);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ============================================================================
   SMOOTH THEME TRANSITION
   ============================================================================ */

[data-theme="dark"] .ambient-glow {
  opacity: 0.7;
  filter: saturate(130%);
}

/* Smooth color transitions */
body,
.glass,
.feature,
.panel,
.btn,
.pill,
.footer-links a,
.footer-social a {
  transition: background 0.3s ease,
              color 0.3s ease,
              border-color 0.3s ease,
              box-shadow 0.3s ease;
}

/* ============================================================================
   REDUCED MOTION SUPPORT
   ============================================================================ */

@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;
  }

  .animate-on-scroll {
    opacity: 1;
    transform: none;
  }

  .ambient-glow {
    animation: none;
  }
}

/* ============================================================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================================================ */

@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .btn,
  .pill,
  .theme-toggle {
    min-height: 44px;
    min-width: 44px;
  }

  /* Disable hover effects on touch */
  .glass:hover,
  .feature:hover,
  .btn:hover,
  .pill:hover {
    transform: none;
  }

  /* But keep active states */
  .btn:active,
  .pill:active {
    transform: scale(0.98);
  }
}

/* ============================================================================
   SKIP LINK
   Hidden until keyboard focus — helps keyboard / screen-reader users skip
   the topbar straight to the main content.
   ============================================================================ */

.skip-link {
  position: fixed;
  top: -100px;
  left: 12px;
  z-index: 10000;
  padding: 12px 18px;
  background: var(--accent, #5b8ff9);
  color: #ffffff;
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 6px 20px rgba(91, 143, 249, 0.45);
  transition: top 0.2s ease;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 0;
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* ============================================================================
   MOBILE NAV TOGGLE
   Injected by js/app.js. Hidden on desktop; shown on narrow viewports.
   ============================================================================ */

.mobile-nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 14px;
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.4));
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.22) 0%, rgba(255, 255, 255, 0.08) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-primary, #2a2438);
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: 0 2px 12px var(--glass-shadow, rgba(140, 130, 180, 0.18));
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.mobile-nav-toggle:active {
  transform: scale(0.96);
}
.mobile-nav-toggle > i {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.mobile-nav-toggle .fa-times { opacity: 0; transform: rotate(-90deg) scale(0.7); }
.mobile-nav-toggle[aria-expanded="true"] .fa-bars  { opacity: 0; transform: rotate(90deg) scale(0.7); }
.mobile-nav-toggle[aria-expanded="true"] .fa-times { opacity: 1; transform: rotate(0) scale(1); }

[data-theme="dark"] .mobile-nav-toggle {
  background: linear-gradient(135deg, rgba(94, 231, 255, 0.18) 0%, rgba(124, 92, 255, 0.1) 100%);
  border-color: rgba(94, 231, 255, 0.32);
  color: var(--accent, #5ee7ff);
}

/* ============================================================================
   MOBILE MENU OVERLAY (behind the slide-down panel)
   ============================================================================ */

.mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 10, 17, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 97;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.mobile-nav-overlay.visible { opacity: 1; }

/* When nav is open, prevent background scroll on iOS / Android */
body.nav-open {
  overflow: hidden;
  touch-action: none;
}

/* ============================================================================
   MOBILE OPTIMIZATIONS
   ============================================================================ */

@media (max-width: 1024px) {
  /* Slightly tighter shells on tablets — gives content more breathing room. */
  .shell { padding: 20px; gap: 24px; }
  .footer-content { gap: 20px; }
}

@media (max-width: 768px) {
  /* ----- Base mobile resets ----- */
  html { -webkit-text-size-adjust: 100%; }
  body {
    /* 16px base font prevents iOS auto-zoom on form input focus. */
    font-size: 16px;
    line-height: 1.55;
  }
  /* Suppress the ugly grey flash some Android browsers show on tap. */
  a, button, .btn, .pill, .feature, .theme-toggle, .mobile-nav-toggle,
  .footer-links a, .footer-social a, .asset-links a {
    -webkit-tap-highlight-color: transparent;
    /* Removes the 300ms tap delay on older mobile browsers. */
    touch-action: manipulation;
  }

  /* ----- Reduce animation complexity on mobile ----- */
  .animate-on-scroll {
    opacity: 1;
    transform: none;
    transition: none;
  }
  .ambient-glow { display: none; }

  /* ----- Topbar: single row, brand + hamburger, no nav pills inline ----- */
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    gap: 12px;
    position: sticky;
    top: 12px;
  }
  .topbar .brand {
    justify-content: flex-start;
    font-size: 17px;
  }
  .topbar .brand-badge {
    width: 34px; height: 34px;
  }
  /* Hide inline theme toggle in the topbar — moved into the mobile menu. */
  .topbar > .theme-toggle { display: none; }

  /* ----- Show hamburger ----- */
  .mobile-nav-toggle { display: flex; }
  .mobile-nav-overlay { display: block; }

  /* ----- Nav pills: collapse to a slide-down panel ----- */
  .nav-pills {
    position: fixed;
    top: 72px;            /* just below the topbar */
    left: 12px;
    right: 12px;
    z-index: 99;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 6px;
    padding: 14px;
    border-radius: 18px;
    background: linear-gradient(
      135deg,
      var(--glass-highlight, rgba(255, 255, 255, 0.34)) 0%,
      var(--glass-bg, rgba(255, 255, 255, 0.18)) 60%,
      var(--glass-lowlight, rgba(255, 255, 255, 0.12)) 100%
    );
    backdrop-filter: var(--glass-blur, blur(20px) saturate(180%));
    -webkit-backdrop-filter: var(--glass-blur, blur(20px) saturate(180%));
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.4));
    border-top-color: var(--glass-highlight-strong, rgba(255, 255, 255, 0.75));
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.22);
    transform: translateY(-12px) scale(0.97);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.2s ease;
    max-height: calc(100vh - 96px - env(safe-area-inset-bottom, 0));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .nav-pills.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
  }
  /* Each pill becomes a full-width tap target. */
  .nav-pills .pill {
    width: 100%;
    padding: 14px 18px;
    font-size: 16px;
    font-weight: 500;
    text-align: left;
    min-height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
  }
  .nav-pills .pill.active {
    background: var(--pill-active-bg, rgba(91, 143, 249, 0.18));
    border-color: var(--pill-active-border, rgba(91, 143, 249, 0.4));
  }
  /* Theme toggle inside the menu — single tap target. */
  .nav-pills .theme-toggle-mobile { display: none; }
  @media (max-width: 768px) {
  .nav-pills .theme-toggle-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 18px;
    min-height: 48px;
    border-radius: 12px;
    margin-top: 6px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.3));
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary, #5a5268);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .nav-pills .theme-toggle-mobile i { font-size: 16px; }
  [data-theme="dark"] .nav-pills .theme-toggle-mobile {
    background: linear-gradient(135deg, rgba(15, 23, 38, 0.46) 0%, rgba(8, 13, 24, 0.32) 100%);
    border-color: rgba(196, 232, 255, 0.12);
  }
  }

  /* ----- Hero / typography ----- */
  .hero { padding: 32px 20px; }
  .hero h1 { font-size: clamp(28px, 8vw, 40px); line-height: 1.15; }
  .hero p  { font-size: 16px; line-height: 1.6; }

  /* ----- Buttons become full-width and tappable ----- */
  .btn {
    width: 100%;
    min-height: 52px;
    padding: 14px 20px;
    font-size: 16px;
    text-align: center;
  }
  .button-row {
    flex-direction: column;
    width: 100%;
    gap: 10px;
  }
  .button-row .btn { width: 100%; }

  .download-cta { flex-direction: column; width: 100%; gap: 10px; }
  .download-cta .btn { width: 100%; }

  .asset-links { width: 100%; flex-direction: column; gap: 8px; }
  .asset-links a { width: 100%; text-align: center; padding: 14px 16px; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; }

  /* ----- Grids collapse to a single column ----- */
  .features,
  .grid { grid-template-columns: 1fr; }
  .feature { padding: 24px 20px; }
  .feature h3 { font-size: 18px; }
  .feature p  { font-size: 15px; }
  .feature-icon { width: 48px; height: 48px; }
  .feature-icon i { font-size: 20px; }

  .panel { padding: 24px 20px; }
  .panel h2 { font-size: 20px; }

  .download-panel { padding: 18px 16px; }

  /* ----- Legal pages ----- */
  .legal-page { padding: 28px 20px; }
  .legal-page h1 { font-size: 32px; line-height: 1.15; }
  .legal-page h2 { font-size: 20px; margin-top: 32px; }
  .legal-page h3 { font-size: 17px; }
  .legal-page p  { font-size: 16px; line-height: 1.7; }
  .legal-page li { font-size: 15px; }
  .feature-card { padding: 18px 16px; }

  /* ----- Footer ----- */
  footer { padding: 28px 20px; }
  .footer-content { flex-direction: column; gap: 16px; text-align: center; }
  .footer-brand { justify-content: center; }
  .footer-links {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }
  .footer-links a {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
  }
  .footer-social {
    justify-content: center;
    gap: 12px;
  }
  .footer-social a {
    width: 48px;
    height: 48px;
  }
  .footer-social i { font-size: 18px; }

  /* ----- Back-home link ----- */
  .back-home {
    width: 100%;
    justify-content: center;
    min-height: 48px;
    padding: 14px 20px;
  }
}

/* Extra-narrow phones (≤ 380 px) — tighten padding so content never
   feels cramped on the smallest common viewports (iPhone SE, etc.). */
@media (max-width: 380px) {
  .shell { padding: 12px; }
  .topbar { padding: 10px 12px; }
  .hero { padding: 24px 16px; }
  .feature { padding: 20px 16px; }
  .panel { padding: 20px 16px; }
  .legal-page { padding: 24px 16px; }
  .legal-page h1 { font-size: 28px; }
  .feature-card { padding: 16px 14px; }
  .pill { font-size: 15px; }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
  .scroll-progress,
  .ambient-glow,
  .theme-toggle,
  .animate-on-scroll {
    display: none !important;
  }

  .glass,
  .feature,
  .panel {
    opacity: 1 !important;
    transform: none !important;
    box-shadow: none !important;
    border: 1px solid #ddd !important;
  }
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

/* Smooth visibility */
.fade-in {
  animation: fadeIn 0.5s ease-out forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Smooth slide up */
.slide-up {
  animation: slideUp 0.5s ease-out forwards;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Smooth scale in */
.scale-in {
  animation: scaleIn 0.4s ease-out forwards;
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* No animation class */
.no-animation {
  animation: none !important;
  transition: none !important;
}

/* GPU acceleration helper */
.gpu {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Smooth text gradient */
.text-gradient {
  background: linear-gradient(135deg, var(--accent, #5b8ff9), var(--accent-light, #6fa0ff));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ============================================================================
   LOADED STATE
   ============================================================================ */

body.loaded .animate-on-scroll {
  opacity: 1;
  transform: translateY(0);
}

/* Initial state before JS loads */
body:not(.loaded) .animate-on-scroll {
  opacity: 1;
  transform: none;
}