/* ==========================================================================
   MOBILE — phone & tablet fixes. Loaded last so it overrides other files.
   Smooth on low-power phones: fewer heavy effects, tap-friendly sizes,
   safe-area support (notch / home bar), bottom-sheet project pop-up.
   ========================================================================== */

/* ---------- All touch devices ---------- */
html { -webkit-tap-highlight-color: transparent; }
a, button, .project-card, .filter-btn { touch-action: manipulation; }
body { overscroll-behavior-y: none; }

/* No hover on touch: stop "sticky" hover lifts after a tap */
@media (hover: none) {
  .card:hover, .project-card:hover, .stat-card:hover, .edu-card:hover, .cert-card:hover,
  .award-card:hover, .expertise-card:hover, .exp-card:hover, .pub-card:hover,
  .btn:hover, .btn-primary:hover, .icon-btn:hover, .social-pill:hover, .contact-mail-btn:hover {
    transform: none;
  }
  .spotlight::after { display: none; }
  .project-card:hover .project-visual img { transform: none; }
}

/* ---------- Tablet & phone (≤ 960px) ---------- */
@media (max-width: 960px) {
  /* lighter background = smoother scrolling */
  .orb { animation: none; filter: blur(54px); }
  .bg-noise, .cursor-glow { display: none; }
  .hero-photo-glow { filter: blur(34px); }
  .term-card { animation: none; }

  /* cheaper glass effects */
  .nav.is-scrolled .nav-inner { -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
  .btn-ghost, .badge, .hero-status { -webkit-backdrop-filter: none; backdrop-filter: none; }

  /* full phone height, ignoring the browser address bar jump */
  .hero { min-height: 100svh; }
  .js main > section.section { min-height: 100svh; }

  /* notch / home-bar safe areas */
  .nav { padding-top: max(12px, env(safe-area-inset-top)); padding-left: max(var(--gutter), env(safe-area-inset-left)); padding-right: max(var(--gutter), env(safe-area-inset-right)); }
  .mobile-menu { padding-bottom: max(40px, env(safe-area-inset-bottom)); }
  .back-to-top { right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); }
  .footer { padding-bottom: max(36px, env(safe-area-inset-bottom)); }
  .toast { bottom: max(28px, env(safe-area-inset-bottom)); }

  /* quicker, lighter page change */
  .js main > section.is-active { animation-duration: .45s; }

  /* never let decorative glows widen the page (stops sideways scroll / zoom-out) */
  main, .footer { overflow-x: clip; }
  .about-profile { overflow: hidden; }

  /* mobile menu: show which page you're on */
  .mobile-link.is-active { color: var(--accent); }
  .mobile-link.is-active .num { color: var(--accent); }
}

/* ---------- Phone (≤ 640px) ---------- */
@media (max-width: 640px) {
  :root { --nav-h: 80px; }
  .section { padding-block: 40px 64px; }
  .js main > section.section { padding-top: calc(var(--nav-h) + 8px); }
  .section-head { margin-bottom: 28px; }
  .section-title { font-size: clamp(1.75rem, 8.2vw, 2.4rem); }
  .nowrap { white-space: nowrap; }

  /* hero */
  .hero { padding: calc(var(--nav-h) + 4px) 0 48px; align-items: flex-start; }
  .hero-title { font-size: clamp(2.7rem, 15vw, 3.6rem); }
  .hero-tagline { font-size: 1.12rem; }
  .hero-bio { font-size: .98rem; }
  .hero-cta .btn { flex: 1 1 140px; }
  .hero-visual { max-width: 100%; margin-top: 8px; }
  /* social links wrap onto two rows instead of being cut off */
  .hero-links { flex-wrap: wrap; overflow: visible; gap: 8px; }
  .hero-links .social-pill { padding: 8px 13px; font-size: .82rem; }

  /* tap-friendly controls (44px) + no iOS zoom on inputs */
  .btn { height: 48px; }
  .btn-sm { height: 42px; }
  .icon-btn { width: 44px; height: 44px; }
  .field input, .field textarea { font-size: 16px; }
  .filter-btn { padding: 10px 15px; }

  /* filters scroll sideways in one line instead of 3 rows */
  .filters {
    flex-wrap: nowrap; overflow-x: auto; min-width: 0;
    margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter);
    scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
    /* soft fade on the right hints that the row scrolls */
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
  }
  .filters::-webkit-scrollbar { display: none; }
  .filter-btn { flex-shrink: 0; scroll-snap-align: start; scroll-margin-left: var(--gutter); }
  .filter-btn:last-child { margin-right: 24px; }
  /* nowrap: a wrapping column flexbox grows to the filters' full width (page overflow bug) */
  .projects-toolbar { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 10px; margin-bottom: 24px; }
  .projects-grid { gap: 16px; }

  /* about */
  .about-heading-icon { width: 42px; height: 42px; font-size: 19px; }
  .about-lead { font-size: 1.22rem; }
  .about-para { font-size: 1rem; }

  /* cards a little tighter */
  .expertise-card, .exp-card, .pub-main, .pub-side { padding: 22px 18px; }
  .stack-tag { font-size: .74rem; padding: 4px 11px; }
  .edu-card, .cert-card, .award-card { padding-inline: 16px; }
  .contact-card { padding: 28px 18px; border-radius: 24px; }
  .contact-mail-btn { width: 100%; padding: 15px 18px; font-size: clamp(.86rem, 4.1vw, .96rem); }
  .contact-alt { gap: 8px 18px; }
  .contact-title { font-size: clamp(1.8rem, 9vw, 2.4rem); }
  .contact-divider { margin: 34px 0 22px; }
  .form-foot { flex-direction: column-reverse; align-items: stretch; gap: 12px; }
  .form-foot .btn { width: 100%; }
  .form-note { text-align: center; }

  /* experience timeline: slimmer rail so cards get more width */
  .timeline { padding-left: 24px; }
  .timeline-track { left: 5px; }
  .timeline-dot { left: -26px; top: 26px; width: 16px; height: 16px; }
  .timeline-dot::after { width: 6px; height: 6px; }
  .timeline-item.is-passed .timeline-dot { box-shadow: 0 0 0 4px var(--tag-bg); }
  .exp-role { font-size: 1.18rem; }
  .exp-list li { font-size: .94rem; }

  /* split blocks (education / certs / awards) a little tighter */
  .split-block { margin-top: 48px; padding-top: 40px; gap: 22px; }

  /* research: equal full-width buttons */
  .pub-actions .btn { flex: 1 1 100%; }
  .pub-title { font-size: clamp(1.22rem, 5.6vw, 1.45rem); }

  /* footer: tidy grid, stacked bottom line */
  .footer { padding-top: 44px; }
  .footer-top { gap: 26px; }
  .footer-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; width: 100%; }
  .footer-bottom { flex-direction: column; gap: 6px; margin-top: 30px; }

  /* project pop-up becomes a bottom sheet */
  .modal { padding: 0; place-items: end center; }
  .modal-dialog {
    width: 100%; max-height: 92svh;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%); opacity: 1;
    padding-bottom: env(safe-area-inset-bottom);
  }
  /* grab handle so it reads as a sheet */
  .modal-dialog::before {
    content: ''; position: sticky; top: 0; z-index: 4; display: block;
    width: 40px; height: 4px; margin: 0 auto -4px; border-radius: 4px;
    background: rgba(255, 255, 255, .55); box-shadow: 0 0 0 1px rgba(0, 0, 0, .12);
    transform: translateY(8px);
  }
  .modal.is-open .modal-dialog { transform: none; }
  .modal .project-visual { aspect-ratio: 16 / 9; }
  .modal .project-badges { top: 14px; left: 14px; right: 66px; }
  .modal-close { top: 12px; right: 12px; }
  .modal-body { padding: 22px 18px 28px; }
  .modal-title { font-size: clamp(1.45rem, 7vw, 1.9rem); }
  .modal-actions .btn { flex: 1 1 100%; }

  /* terminal fits small screens */
  .term-body { font-size: .74rem; padding: 16px 14px 18px; }
  .term-title { display: none; }

  .toast { width: calc(100% - 32px); justify-content: center; }
}

/* ---------- Small phones (≤ 380px) ---------- */
@media (max-width: 380px) {
  :root { --gutter: 14px; }
  .nav-logo .logo-text { display: none; }
  .hero-title { font-size: clamp(2.2rem, 13vw, 2.5rem); }
  .hero-cta .btn { flex: 1 1 100%; }
  .stat-card { padding: 14px 10px; }
  .stat-value { font-size: 1.7rem; }
  .stat-label { font-size: .72rem; }
  .about-profile .about-photo { width: min(260px, 70vw); }
  .cert-card { gap: 14px; }
  .cert-logo { width: 48px; height: 48px; }
  .footer-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Tablet (641px – 960px): use the extra width ---------- */
@media (min-width: 641px) and (max-width: 960px) {
  .hero-visual { max-width: none; }
  .hero-grid { gap: 40px; }
  .term-body { font-size: .86rem; }
  .about-profile .about-photo { width: min(280px, 46vw); }
  .modal-dialog { width: min(680px, 100%); }
}

/* Landscape phones: don't force full-height pages */
@media (max-height: 520px) and (orientation: landscape) {
  .hero, .js main > section.section { min-height: 0; }
}
