/* Mobile-first overrides for the landing experience */
@media (max-width: 768px) {
  /* Touch interaction optimizations */
  * {
    touch-action: manipulation;
  }

  button,
  a {
    min-height: 44px;
    min-width: 44px;
  }

  html,
  body {
    width: 100%;
    overflow-x: hidden;
  }

  body {
    padding: 0;
  }

  body.mobile-bg-gradient {
    background: #02070c;
  }

  /* ==========================================
     CANVAS VISIBILITY - CRITICAL FIX
  ========================================== */
  /* Hide background animation canvases on mobile */
  #bgCanvas,
  #particleCanvas {
    display: none !important;
  }

  /* ALLOW Chart.js canvases to show - DON'T HIDE THEM */
  canvas:not(#bgCanvas):not(#particleCanvas) {
    display: block !important;
    max-width: 100% !important;
    height: auto !important;
  }

  #navbar {
    width: 100%;
    left: 0;
    right: 0;
    padding: 12px 0;
    backdrop-filter: blur(16px);
  }

  .nav-container {
    padding: 0 16px;
    justify-content: space-between;
  }

  .nav-container.center-aligned {
    justify-content: space-between;
  }

  .hamburger-menu {
    display: flex;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid rgba(var(--accent-color-rgb, 0, 255, 255), 0.35);
    background: rgba(255, 255, 255, 0.04);
    color: var(--accent-color);
  }

  .hamburger-menu.active {
    background: rgba(var(--accent-color-rgb, 0, 255, 255), 0.2);
    color: #fff;
  }

  .nav-menu {
    position: fixed;
    top: 72px;
    right: 16px;
    left: 16px;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 20px;
    border-radius: 12px;
    background: rgba(8, 15, 22, 0.5);
    border: 1px solid rgba(var(--accent-color-rgb, 0, 255, 255), 0.35);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    z-index: 1200;
  }

  .nav-menu.active {
    display: flex;
  }

  .nav-menu li {
    width: 100%;
    display: flex;
  }

  .nav-menu a,
  .nav-menu button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    font-size: 1rem;
  }

  .nav-menu a:hover,
  .nav-menu button:hover,
  .nav-menu a:focus-visible,
  .nav-menu button:focus-visible {
    border-color: rgba(var(--accent-color-rgb, 0, 255, 255), 0.45);
    background: rgba(var(--accent-color-rgb, 0, 255, 255), 0.15);
  }

  .nav-menu .navbar-whitepaper,
  .nav-menu .navbar-connect {
    justify-content: center;
    font-weight: 600;
  }

  .container {
    width: 100%;
    margin: 96px auto 32px;
    padding: 0 18px;
  }

  section {
    padding: 32px 0;
    margin-bottom: 32px;
  }

  .section-description {
    text-align: left;
    margin-bottom: 24px;
  }

  .hero-content {
    gap: 24px;
    padding: 0;
  }

  .hero-header {
    gap: 20px;
  }

  .hero-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .hero-btn {
    width: 100%;
    justify-content: center;
  }

  .energy-stats-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }

  .stat-item {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 16px 12px;
  }

  .token-hero {
    flex-direction: column;
    gap: 24px;
    text-align: center;
    padding: 24px;
  }

  .token-hero-info {
    width: 100%;
  }

  .token-info-panel {
    padding: 24px;
    background: rgba(0, 0, 0, 0.2) !important;
  }

  .token-info-panel .contract-address {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .features-grid,
  .token-stats-grid,
  .steps-container,
  .address-cards,
  .links-grid,
  .tokenomics-grid,
  .security-features,
  .metrics-visualization,
  .flex-fund-dashboard,
  .project-specs,
  .specs-primary,
  .specs-detail,
  .energy-sources,
  .distribution-info {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .wallet-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    background: rgba(0, 0, 0, 0.2) !important;
  }

  .market-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .market-stats {
    text-align: left;
  }

  .transaction-type-toggle {
    flex-direction: column;
    border-radius: 8px;
    overflow: hidden;
  }

  .transaction-type-btn {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .transaction-type-btn:last-child {
    border-bottom: none;
  }

  .transaction-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .blockchain-container {
    flex-direction: column;
    align-items: stretch;
  }

  .blockchain-block {
    width: 100%;
    min-width: auto;
  }

  .timeline-axis,
  .timeline-track,
  .timeline-node:nth-child(odd) .node-content::before,
  .timeline-node:nth-child(even) .node-content::before,
  .node-dot {
    display: none;
  }

  .timeline-node .node-content {
    margin: 0;
    padding: 20px;
    text-align: left;
  }

  .calculator-container,
  .dashboard-container,
  .simulator-container,
  .assistant-interface {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .checkbox-group {
    grid-template-columns: 1fr;
  }

  .assistant-sidebar {
    order: -1;
  }

  .contact-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
  }

  .contact-info {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .social-icons {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 12px;
  }

  .contact-form-container form {
    padding: 20px;
  }

  .footer-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    text-align: left;
  }

  .footer-links {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .footer-bottom {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  /* ==========================================
     TRANSPARENT BACKGROUNDS FOR ANIMATION
  ========================================== */

  /* Token section components - semi-transparent */
  .token-container,
  .token-info,
  .token-details,
  .sever-token-section {
    background: rgba(0, 0, 0, 0.22);
  }

  /* Battery & Fund components - semi-transparent */
  .battery-container,
  .flex-fund-container,
  .fund-panel,
  .battery-panel {
    background: rgba(0, 0, 0, 0.22);
  }

  /* Financial components - semi-transparent */
  .snapshot-card,
  .financial-card,
  .metric-card {
    background: rgba(0, 0, 0, 0.22);
  }

  /* Keep card borders but make backgrounds see-through */
  .card,
  .panel,
  .info-card {
    background: rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(5px);
  }
}

@media (max-width: 480px) {
  #navbar {
    padding: 10px 0;
  }

  .nav-menu {
    top: 58px;
    right: 12px;
    left: 12px;
    padding: 18px;
  }

  .token-hero {
    padding: 20px;
  }

  .token-info-panel,
  .contact-form-container form {
    padding: 18px;
  }

  .hero-actions {
    gap: 10px;
  }

  .hero-btn {
    font-size: 0.95rem;
    padding: 12px;
  }

  /* Transparent backgrounds already defined in 768px block above */
}

/* ==========================================
   LANDSCAPE MOBILE ORIENTATION
========================================== */
@media (max-width: 768px) and (orientation: landscape) {
  #navbar {
    padding: 8px 0;
  }

  .nav-menu {
    max-height: 60vh;
    overflow-y: auto;
  }
}

/* ==========================================
   MOBILE TOUCH ENHANCEMENTS
========================================== */
@media (max-width: 768px) {
  /* Optimize touch interactions */
  * {
    -webkit-tap-highlight-color: rgba(var(--accent-color-rgb, 0, 255, 255), 0.2);
    tap-highlight-color: rgba(var(--accent-color-rgb, 0, 255, 255), 0.2);
  }

  /* Improve touch targets - minimum 44x44px */
  button,
  .btn,
  .hero-btn,
  a,
  .nav-menu a,
  .connect-button,
  .social-icon,
  .action-btn,
  input[type="button"],
  input[type="submit"],
  input[type="reset"] {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
  }

  /* Better scrolling on touch devices */
  .nav-menu,
  .blockchain-container,
  .transaction-list,
  .timeline-container,
  .overflow-auto {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Active state for touch feedback */
  button.touch-active,
  .btn.touch-active,
  .hero-btn.touch-active,
  .nav-menu a.touch-active,
  .connect-button.touch-active,
  .social-icon.touch-active,
  .action-btn.touch-active,
  .card.touch-active,
  .feature-card.touch-active {
    opacity: 0.85;
    transform: scale(0.98);
    transition: opacity 0.1s ease, transform 0.1s ease;
  }

  /* Prevent text selection on interactive elements during touch */
  button,
  .btn,
  .hero-btn,
  .nav-menu a,
  .connect-button,
  .social-icon,
  .action-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  /* Smooth momentum scrolling for iOS */
  body,
  html {
    -webkit-overflow-scrolling: touch;
  }

  /* Fix for input zoom on iOS */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  textarea,
  select {
    font-size: 16px !important; /* Prevents auto-zoom on iOS */
  }

  /* Improve form element touch targets */
  input,
  textarea,
  select {
    min-height: 44px;
    padding: 12px;
  }

  /* Better touch response for links */
  a {
    touch-action: manipulation;
    -webkit-touch-callout: none; /* Disable iOS callout */
  }

  /* Prevent pull-to-refresh on specific elements */
  canvas,
  #bgCanvas {
    overscroll-behavior-y: contain;
    touch-action: pan-x pan-y;
  }
}

/* ==========================================
   MOBILE PERFORMANCE OPTIMIZATIONS
========================================== */
@media (max-width: 768px) {
  /* Reduce animations on low-end devices if preferred */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }

  /* Hardware acceleration for smooth animations */
  .nav-menu,
  .hamburger-menu,
  button,
  .btn,
  .card {
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
}

/* ==========================================
   MEDIA AND SVG RESPONSIVENESS
========================================== */
@media (max-width: 768px) {
  /* Ensure all SVGs are responsive */
  svg {
    max-width: 100%;
    height: auto;
  }

  /* Ensure images are responsive */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Ensure videos are responsive */
  video {
    max-width: 100%;
    height: auto;
  }

  /* Ensure iframes are responsive */
  iframe {
    max-width: 100%;
  }

  /* Loading overlay mobile optimization */
  #loadingOverlay {
    position: fixed;
    width: 100vw;
    height: 100vh;
  }

  /* Loading SVG scaling */
  .blockchain-loading-visual svg {
    max-width: 90%;
    height: auto;
  }
}

/* ==========================================
   MOBILE NAVIGATION IMPROVEMENTS
========================================== */
@media (max-width: 768px) {
  /* Prevent body scroll when menu is open */
  body.menu-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  /* Improve hamburger menu accessibility */
  .hamburger-menu {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(var(--accent-color-rgb, 0, 255, 255), 0.3);
  }

  /* Ensure nav menu is scrollable */
  .nav-menu {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* Better spacing for nav items on small screens */
  .nav-menu li {
    margin: 4px 0;
  }
}

/* ==========================================
   MOBILE TEXT AND TYPOGRAPHY
========================================== */
@media (max-width: 768px) {
  /* Prevent text overflow */
  h1, h2, h3, h4, h5, h6, p, li, span {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
  }

  /* Improve readability */
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Prevent horizontal scroll from long content */
  pre, code {
    max-width: 100%;
    overflow-x: auto;
    word-break: break-all;
    white-space: pre-wrap;
  }
}

/* ==========================================
   MOBILE ACCESSIBILITY IMPROVEMENTS
========================================== */
@media (max-width: 768px) {
  /* Focus visible for keyboard navigation */
  *:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
  }

  /* Skip to main content link for screen readers */
  .skip-to-main {
    position: absolute;
    left: -9999px;
    z-index: 999;
  }

  .skip-to-main:focus {
    left: 0;
    top: 0;
    background: var(--accent-color);
    color: var(--bg-color);
    padding: 10px 20px;
  }
}
