/* ═══════════════════════════════════════════════════════════════
   MOBILE.CSS — Comprehensive Mobile & Cross-Device Fixes
   Fixes: iOS background-attachment, blob overflow, layout breaks,
          custom cursor on touch, padding/spacing, all grids
   Import LAST in every page's <head>
═══════════════════════════════════════════════════════════════ */

/* ── 1. iOS Safari: background-attachment: fixed causes blank/glitch ── */
@supports (-webkit-touch-callout: none) {
  body,
  .page-common body {
    background-attachment: scroll !important;
  }
}
@media (max-width: 1024px) {
  body { background-attachment: scroll !important; }
}

/* ── 2. Global overflow guard ── */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}
* { box-sizing: border-box; }

/* ── 3. Hide custom cursor on touch devices ── */
@media (hover: none) and (pointer: coarse) {
  .cursor-dot,
  .cursor-glow { display: none !important; }
}

/* ══════════════════════════════════════════════════════════
   TABLET (≤ 900px)
══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {

  /* Nav */
  .nav-links { display: none !important; }
  .hamburger { display: flex !important; }
  .bmc-nav-text { display: none; }

  /* Blobs — scale down so they don't cause overflow */
  .blob-1 { width: 340px !important; height: 340px !important; top: -100px !important; left: -100px !important; }
  .blob-2 { width: 280px !important; height: 280px !important; bottom: -80px !important; right: -80px !important; }
  .blob-3 { width: 220px !important; height: 220px !important; }
  .section-blob-a { width: 280px !important; height: 280px !important; top: -80px !important; right: -60px !important; }
  .section-blob-b { width: 200px !important; height: 200px !important; }

  /* Section orbs — hide on tablet/mobile to prevent overflow */
  .section-orb-1 { width: 200px !important; height: 200px !important; top: -40px !important; right: -40px !important; }
  .section-orb-2 { width: 120px !important; height: 120px !important; }

  /* Hero grid → single column */
  #hero .container {
    grid-template-columns: 1fr !important;
    gap: 2rem !important;
    padding-top: calc(var(--nav-height) + 2.5rem) !important;
    padding-bottom: 3rem !important;
  }
  .hero-3d-card { order: -1; }
  .card-3d-inner { max-width: 100% !important; margin: 0 auto; }

  /* Hero stat badges */
  .hero-stats { flex-direction: column !important; }
  .stat-badge { min-width: unset !important; width: 100%; }

  /* Hero CTAs */
  .hero-ctas { flex-direction: row; flex-wrap: wrap; }

  /* About grid */
  .about-grid { grid-template-columns: 1fr !important; gap: 2rem !important; }
  .about-avatar { max-width: 320px; margin: 0 auto; }

  /* Why strip */
  .why-strip { flex-direction: column !important; }
  .why-divider { width: 100% !important; height: 1px !important; margin: 0 !important; }
  .why-item { padding: 1.8rem 1.4rem !important; }

  /* Services */
  .services-grid { grid-template-columns: 1fr !important; }

  /* Blog teaser */
  .blog-teaser-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Blog grid */
  .blog-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .featured-card { grid-column: span 2 !important; }

  /* Projects */
  .projects-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .project-card.featured { grid-column: span 2 !important; }
  .projects-stats-bar { grid-template-columns: repeat(2, 1fr) !important; }

  /* Achievements */
  .achievements-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Stack grid */
  .stack-grid { grid-template-columns: repeat(4, 1fr) !important; }

  /* Footer */
  .footer-top { grid-template-columns: 1fr 1fr !important; gap: 2rem !important; }

  /* Contact layout */
  .contact-layout { grid-template-columns: 1fr !important; gap: 2rem !important; }

  /* Resume grid */
  .resume-grid { grid-template-columns: 1fr !important; gap: 2rem !important; }
  .resume-sidebar { position: static !important; }

  /* About body */
  .about-body { grid-template-columns: 1fr !important; gap: 2rem !important; }
  .id-card-v2 { position: static !important; }
  .about-stats-row { grid-template-columns: repeat(2, 1fr) !important; }

  /* CTA section */
  .cta-section { padding: 2.5rem 1.8rem !important; }
  .about-cta-banner { flex-direction: column !important; text-align: center !important; padding: 2rem 1.5rem !important; }
  .about-cta-banner-btns { justify-content: center !important; }

  /* Page hero padding */
  .page-hero { padding-top: calc(var(--nav-height) + 3rem) !important; padding-bottom: 2.5rem !important; }
  .about-page-hero { padding-top: calc(var(--nav-height) + 3rem) !important; }

  /* Resume PDF */
  .resume-pdf-wrapper iframe { height: 500px !important; }
  .resume-pdf-wrapper { min-height: unset !important; }
}

/* ══════════════════════════════════════════════════════════
   MOBILE (≤ 640px)
══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

  /* Section spacing */
  section { padding: 3.5rem 0 !important; }
  .section-header { margin-bottom: 2rem !important; }
  --section-gap: 3.5rem;

  /* Container padding */
  .container { padding: 0 1rem !important; }

  /* Nav right — hide bmc on very small */
  .nav-right .btn-primary { display: none !important; }
  .bmc-nav { display: none !important; }

  /* Hero */
  #hero .container {
    padding-top: calc(var(--nav-height) + 2rem) !important;
    padding-bottom: 2.5rem !important;
  }
  .hero-name {
    font-size: clamp(2rem, 8vw, 3rem) !important;
    line-height: 1.1 !important;
  }
  .hero-sub { font-size: 0.9rem !important; max-width: 100% !important; }
  .hero-ctas { flex-direction: column !important; }
  .hero-ctas .btn { width: 100%; justify-content: center; }
  .hero-stats { flex-direction: column !important; gap: 0.6rem !important; }
  .stat-badge { min-width: unset !important; }
  .card-3d-inner { padding: 1.2rem !important; }
  .card-3d-code { font-size: 0.75rem !important; line-height: 1.8 !important; }

  /* Hero identity chips */
  .hero-identity-chips { flex-wrap: wrap; gap: 0.35rem !important; }
  .identity-chip { font-size: 0.68rem !important; padding: 0.22rem 0.65rem !important; }

  /* Hero orbs — hide on mobile */
  .orb-1, .orb-2, .orb-3 { display: none !important; }

  /* Blobs even smaller */
  .blob-1 { width: 200px !important; height: 200px !important; top: -60px !important; left: -60px !important; }
  .blob-2 { width: 180px !important; height: 180px !important; }
  .blob-3 { display: none !important; }
  .section-blob-a { width: 180px !important; height: 180px !important; }
  .section-blob-b { width: 150px !important; height: 150px !important; }
  .section-orb-1, .section-orb-2 { display: none !important; }

  /* About section */
  .about-stats-row { grid-template-columns: repeat(2, 1fr) !important; gap: 0.75rem !important; }
  .about-stat-card { padding: 1.3rem 0.9rem !important; }
  .about-page-title { font-size: 1.9rem !important; }
  .about-chips { flex-wrap: wrap; gap: 0.4rem !important; }
  .about-chip { font-size: 0.75rem !important; padding: 0.32rem 0.8rem !important; }
  .about-cta-banner { padding: 1.6rem 1.2rem !important; }

  /* Services */
  .services-grid { gap: 1rem !important; }
  .service-card { padding: 1.6rem 1.3rem !important; }

  /* Blog teaser */
  .blog-teaser-grid { grid-template-columns: 1fr !important; }
  .blog-teaser-card { padding: 1.3rem !important; }

  /* Blog page */
  .blog-grid,
  .blog-grid.list-view { grid-template-columns: 1fr !important; }
  .featured-card,
  .blog-grid.list-view .featured-card { grid-column: span 1 !important; }
  .blog-grid.list-view .blog-card { flex-direction: column !important; max-height: none !important; }
  .blog-grid.list-view .blog-card-img { width: 100% !important; aspect-ratio: 16/9 !important; }
  .blog-author-strip { flex-direction: column !important; align-items: flex-start !important; }
  .blog-author-divider { display: none !important; }
  .blog-hero-content { max-width: 100% !important; }

  /* Projects */
  .projects-grid { grid-template-columns: 1fr !important; gap: 1rem !important; }
  .project-card.featured { grid-column: span 1 !important; }
  .projects-stats-bar { grid-template-columns: repeat(2, 1fr) !important; gap: 0.75rem !important; padding: 1.5rem 0 0.5rem !important; }
  .project-card { padding: 1.25rem 1.2rem !important; }

  /* Achievements */
  .achievements-grid { grid-template-columns: 1fr !important; }

  /* Stack grid */
  .stack-grid { grid-template-columns: repeat(3, 1fr) !important; }

  /* Experience timeline */
  .exp-timeline { padding-left: 1.8rem !important; }
  .exp-dot { left: -1.8rem !important; }
  .exp-card { padding: 1.4rem 1.2rem !important; }
  .exp-card h3 { font-size: 1rem !important; }
  .exp-card ul li { font-size: 0.83rem !important; }
  .exp-top { flex-direction: column; align-items: flex-start !important; gap: 0.4rem !important; }

  /* Contact */
  .contact-form { padding: 1.4rem 1.1rem !important; }
  .contact-method-selector { flex-direction: column !important; }
  .method-btn { width: 100% !important; }
  .contact-info h2 { font-size: 1.8rem !important; }
  .contact-links-row { flex-direction: column !important; align-items: stretch; }
  .contact-links-row .btn { justify-content: center !important; }

  /* Resume */
  .resume-pdf-wrapper iframe { height: 400px !important; }
  .resume-section { padding: 1.3rem 1.1rem !important; }
  .resume-actions { flex-direction: column !important; }
  .resume-actions .btn { width: 100% !important; justify-content: center !important; }

  /* Footer */
  .footer-top { grid-template-columns: 1fr !important; gap: 1.8rem !important; }
  .footer-bottom { flex-direction: column !important; text-align: center !important; }

  /* Form rows — stack columns */
  .form-row { grid-template-columns: 1fr !important; }

  /* CTA section */
  .cta-section { padding: 2rem 1.2rem !important; }
  .cta-section > div { flex-direction: column !important; align-items: stretch !important; }
  .cta-section > div .btn { justify-content: center !important; }

  /* Page hero */
  .page-hero { padding-top: calc(var(--nav-height) + 2.5rem) !important; padding-bottom: 2rem !important; }
  .page-hero-title { font-size: clamp(1.8rem, 7vw, 2.4rem) !important; }
  .page-hero-sub { font-size: 0.9rem !important; }

  /* About page hero */
  .about-page-hero { padding-top: calc(var(--nav-height) + 2.5rem) !important; padding-bottom: 2rem !important; }

  /* Strengths grid */
  .strengths-grid { grid-template-columns: 1fr !important; }
  .open-to-grid { grid-template-columns: 1fr !important; }
  .values-grid { grid-template-columns: 1fr !important; }

  /* Mobile menu button area fix */
  .bmc-strip { flex-direction: column !important; text-align: center !important; }

  /* Section label */
  .section-header h2 { font-size: clamp(1.5rem, 6vw, 2rem) !important; }

  /* Typing wrapper */
  .typing-wrapper { font-size: 0.88rem !important; }
}

/* ══════════════════════════════════════════════════════════
   SMALL MOBILE (≤ 420px)
══════════════════════════════════════════════════════════ */
@media (max-width: 420px) {

  .container { padding: 0 0.85rem !important; }

  /* Nav logo size */
  .nav-logo { font-size: 0.95rem !important; }

  /* Hero */
  .hero-name { font-size: clamp(1.75rem, 7.5vw, 2.5rem) !important; }
  .hero-badge { font-size: 0.72rem !important; padding: 0.28rem 0.75rem !important; }
  .hero-greeting { font-size: 0.65rem !important; letter-spacing: 0.1em !important; }

  /* About stats */
  .about-stats-row { grid-template-columns: 1fr 1fr !important; gap: 0.6rem !important; }
  .about-stat-card { padding: 1rem 0.75rem !important; }
  .about-stat-num { font-size: 1.6rem !important; }

  /* Projects stats */
  .projects-stats-bar { grid-template-columns: repeat(2, 1fr) !important; gap: 0.55rem !important; }
  .projects-stat-number { font-size: 1.6rem !important; }
  .projects-stat-item { padding: 1rem 0.75rem !important; border-radius: 14px !important; }

  /* Stack grid */
  .stack-grid { grid-template-columns: repeat(3, 1fr) !important; gap: 0.7rem !important; }
  .stack-item { padding: 1.1rem 0.5rem !important; }

  /* Card code */
  .card-3d-code { font-size: 0.72rem !important; }
  .card-3d-inner { padding: 1rem !important; }

  /* Exp card */
  .exp-card { padding: 1.1rem 0.9rem !important; border-radius: 18px !important; }

  /* Services */
  .service-card { padding: 1.3rem 1rem !important; border-radius: 18px !important; }

  /* Resume PDF */
  .resume-pdf-wrapper iframe { height: 340px !important; }

  /* Footer */
  .footer-logo { font-size: 1.1rem !important; }
  .footer-tagline { font-size: 0.82rem !important; }
  .footer-copy, .footer-built { font-size: 0.72rem !important; }

  /* Section header */
  .section-header { margin-bottom: 1.6rem !important; }
  section { padding: 2.8rem 0 !important; }

  /* Stat badge */
  .stat-badge { padding: 0.75rem 0.9rem !important; gap: 0.7rem !important; }
  .stat-text strong { font-size: 0.78rem !important; }
  .stat-text span { font-size: 0.67rem !important; }

  /* Why strip */
  .why-num { font-size: 2rem !important; }
  .why-label { font-size: 0.78rem !important; }
  .why-item { padding: 1.4rem 1rem !important; }

  /* Blog cards */
  .blog-card-body { padding: 1rem 1.1rem 1.2rem !important; }
  .blog-card-title { font-size: 0.92rem !important; }

  /* mobile menu fix */
  .mobile-menu { padding: 0.75rem 1rem 1.5rem !important; }
  .mobile-menu a { padding: 0.6rem 0.75rem !important; font-size: 0.92rem !important; }

  /* CTA banner */
  .about-cta-banner { padding: 1.3rem 1rem !important; }
  .about-cta-banner-text h2 { font-size: 1.15rem !important; }
  .about-cta-banner-btns { flex-direction: column !important; }
  .about-cta-banner-btns .btn { width: 100% !important; justify-content: center !important; }

  /* Project links */
  .project-links { flex-direction: row; flex-wrap: wrap; }
  .project-link { font-size: 0.74rem !important; padding: 0.36rem 0.75rem !important; }
}

/* ══════════════════════════════════════════════════════════
   LANDSCAPE PHONE (short height)
══════════════════════════════════════════════════════════ */
@media (max-height: 500px) and (orientation: landscape) {
  #hero {
    min-height: auto !important;
    padding-top: calc(var(--nav-height) + 1rem) !important;
    padding-bottom: 2rem !important;
  }
  #hero .container { padding-top: calc(var(--nav-height) + 1rem) !important; }
  .hero-stats { display: none !important; }
  .hero-sub { display: none !important; }
}

/* ══════════════════════════════════════════════════════════
   TABLET PORTRAIT (641px - 900px) — Fine tuning
══════════════════════════════════════════════════════════ */
@media (min-width: 641px) and (max-width: 900px) {
  .hero-ctas { flex-direction: row; flex-wrap: wrap; }
  .hero-ctas .btn { flex: 1; justify-content: center; min-width: 140px; }
  .stat-badge { flex: 1; min-width: 180px !important; }
  .hero-stats { flex-direction: row !important; flex-wrap: wrap; }

  /* Projects 2-col on tablet */
  .projects-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .project-card.featured { grid-column: span 2 !important; }

  /* Blog 2-col */
  .blog-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* About stats */
  .about-stats-row { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ══════════════════════════════════════════════════════════
   TOUCH TARGET MINIMUM SIZE
══════════════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
  .btn,
  .nav-links li a,
  .mobile-menu a,
  .project-link,
  .blog-read-link,
  .filter-tab,
  .footer-social-link,
  .hamburger,
  .theme-toggle,
  .method-btn {
    min-height: 44px;
  }
  .hamburger { min-width: 44px; }
  .footer-social-link { min-width: 44px; }

  /* Disable hover-only animations on touch */
  .tilt-card { transform: none !important; }
  .service-card:hover,
  .project-card:hover,
  .exp-card:hover,
  .stat-badge:hover,
  .achievement-card:hover,
  .stack-item:hover,
  .blog-card:hover,
  .about-stat-card:hover {
    transform: translateZ(0) !important;
  }

  /* Disable particle canvas on mobile for performance */
  #particle-canvas { display: none !important; }
}
