/* ==========================================================================
   Comprehensive Responsive System & Cross-Browser Compatibility
   Optimized for: Mobile (320px-480px), Tablets (768px-1024px), Desktop (1200px+)
   Browsers: Chrome, Safari (iOS/macOS), Edge, Firefox, Android Webview
   ========================================================================== */

/* Universal Overflow & Layout Guard */
html,
body {
  max-width: 100vw;
  overflow-x: hidden;
  position: relative;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Touch targets and tapping optimization */
a,
button,
input,
textarea,
select,
.filter-btn,
.screen-thumb-box,
.project-card-media {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Keyboard Accessibility Focus Rings */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.filter-btn:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

/* iOS Safari Safe Area Inset Support */
@supports (padding: max(0px)) {
  #header {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  .back-to-top {
    bottom: max(20px, calc(15px + env(safe-area-inset-bottom)));
    right: max(20px, calc(15px + env(safe-area-inset-right)));
  }

  #footer {
    padding-bottom: max(30px, calc(20px + env(safe-area-inset-bottom)));
  }
}

/* ==========================================================================
   Breakpoints
   ========================================================================== */

/* Large Tablets & Small Laptops (<= 1024px) */
@media (max-width: 1024px) {
  .section-wrapper {
    padding: 80px 20px;
  }

  .projects-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
  }

  .videos-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 22px;
  }

  .certificates-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
  }
}

/* Tablets & Mobile Landscape (<= 991px) */
@media (max-width: 991px) {
  .about-grid {
    display: flex;
    flex-direction: column;
    gap: 32px;
  }

  .profile-card-sticky {
    width: 100%;
    max-width: 100%;
    margin: 0;
    position: static;
    padding: 28px 22px;
    box-sizing: border-box;
  }

  .profile-meta-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px 20px;
    text-align: left;
  }

  .profile-meta-item:last-child {
    grid-column: 1 / -1;
  }

  .screens-heading {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .screens-heading .btn-open-gallery {
    width: 100% !important;
    justify-content: center;
    text-align: center;
    padding: 10px 16px !important;
    font-size: 0.82rem !important;
  }

  .contact-grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .skills-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 22px;
  }
}

/* Mobile Devices (<= 768px) */
@media (max-width: 768px) {
  .section-wrapper {
    padding: 70px 18px;
  }

  .section-header {
    margin-bottom: 38px;
  }

  .section-title {
    font-size: 1.85rem;
    letter-spacing: -0.5px;
  }

  .section-subtitle {
    font-size: 0.95rem;
  }

  /* Hero Section Responsive */
  #hero {
    padding: 120px 18px 60px;
    min-height: auto;
  }

  .hero-logo-img {
    max-height: 180px;
    max-width: 85%;
  }

  .hero-title {
    font-size: clamp(2rem, 7vw, 2.8rem);
    word-break: break-word;
  }

  .hero-subtitle {
    font-size: 1.05rem;
    line-height: 1.5;
  }

  .hero-bio {
    font-size: 0.96rem;
    padding: 0 4px;
    line-height: 1.7;
    margin-bottom: 28px;
  }

  /* Stats Row: 2x2 Grid */
  .hero-stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .stat-pill-card {
    padding: 12px 8px;
  }

  .stat-num {
    font-size: 1.4rem;
  }

  .stat-label {
    font-size: 0.75rem;
  }

  /* About / Professional Summary Section Mobile */
  .about-grid {
    gap: 28px;
  }

  .profile-card-sticky {
    max-width: 100%;
    padding: 24px 18px;
    border-radius: 16px;
  }

  .profile-avatar-box {
    width: 170px;
    height: 170px;
    margin: 0 auto 16px;
  }

  .profile-name {
    font-size: 1.28rem;
  }

  .profile-role {
    font-size: 0.85rem;
    margin-bottom: 16px;
  }

  .profile-meta-list {
    padding-top: 14px;
    gap: 10px;
  }

  .profile-meta-item {
    font-size: 0.84rem;
    gap: 10px;
  }

  .profile-meta-item i {
    width: 26px;
    height: 26px;
    font-size: 0.78rem;
  }

  .about-narrative h3 {
    font-size: 1.35rem;
    margin-bottom: 14px;
  }

  .about-narrative p {
    font-size: 0.94rem;
    line-height: 1.7;
    margin-bottom: 14px;
  }

  .about-highlights-chips {
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 18px 0 24px;
  }

  .highlight-chip {
    padding: 11px 14px;
    font-size: 0.84rem;
    border-radius: 10px;
  }

  .highlight-chip i {
    width: 26px;
    height: 26px;
    font-size: 0.8rem;
  }

  .flagship-card {
    padding: 22px 18px;
    border-radius: 16px;
    margin-top: 22px;
  }

  .flagship-title {
    font-size: 1.25rem;
  }

  .flagship-metrics-tags {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 18px;
  }

  .flagship-metric-tag {
    font-size: 0.8rem;
    padding: 8px 12px;
  }

  .screens-heading {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .screens-heading span {
    font-size: 0.78rem;
    line-height: 1.4;
  }

  .screens-heading .btn-open-gallery {
    width: 100% !important;
    justify-content: center;
    padding: 9px 14px !important;
    font-size: 0.8rem !important;
  }

  /* Timeline adjustments */
  .timeline-item {
    padding-left: 55px;
    margin-bottom: 30px;
  }

  .experience-card {
    padding: 22px 18px;
  }

  .exp-role-title {
    font-size: 1.15rem;
  }

  /* Portfolio & Videos */
  .projects-grid {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  .videos-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .certificates-grid {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  /* Footer */
  .footer-top-grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }

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

/* Small Smartphone Devices (<= 576px) */
@media (max-width: 576px) {
  .section-wrapper {
    padding: 55px 16px;
  }

  .navbar-container {
    padding: 0 14px;
  }

  .brand-text {
    font-size: 1.15rem;
  }

  /* Hero adjustments */
  .hero-logo-img {
    max-height: 140px;
    max-width: 90%;
  }

  .hero-title {
    font-size: 1.95rem;
    line-height: 1.2;
  }

  .hero-status-pill {
    font-size: 0.78rem;
    padding: 6px 14px;
    margin-bottom: 18px;
  }

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

  .btn-primary-gradient,
  .btn-secondary-glass {
    width: 100%;
    justify-content: center;
    padding: 12px 20px;
    font-size: 0.92rem;
  }

  /* Profile Card on Small Mobile */
  .profile-card-sticky {
    padding: 20px 14px;
    border-radius: 14px;
  }

  .profile-avatar-box {
    width: 150px;
    height: 150px;
    border-radius: 18px;
    padding: 5px;
    margin-bottom: 14px;
  }

  .profile-avatar-box img {
    border-radius: 13px;
  }

  .profile-name {
    font-size: 1.22rem;
  }

  .profile-role {
    font-size: 0.82rem;
  }

  .profile-meta-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .profile-meta-item {
    font-size: 0.82rem;
    gap: 9px;
  }

  .profile-meta-item i {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
    border-radius: 6px;
  }

  /* Flagship Card Small Mobile */
  .flagship-card {
    padding: 18px 14px;
    border-radius: 14px;
  }

  .flagship-title {
    font-size: 1.18rem;
  }

  .flagship-desc {
    font-size: 0.86rem;
    margin-bottom: 16px;
  }

  .flagship-store-buttons {
    gap: 10px;
    margin-bottom: 18px;
  }

  .flagship-store-buttons img {
    height: 34px;
  }

  .screen-thumb-box {
    flex: 0 0 95px;
    height: 168px;
    border-radius: 10px;
  }

  /* Timeline Mobile */
  .experience-timeline::before {
    left: 12px;
  }

  .timeline-item {
    padding-left: 36px;
    margin-bottom: 24px;
  }

  .timeline-dot {
    left: 4px;
    top: 22px;
    width: 18px;
    height: 18px;
  }

  .experience-card {
    padding: 18px 14px;
  }

  .exp-role-title {
    font-size: 1.05rem;
  }

  .exp-period-badge {
    font-size: 0.72rem;
    padding: 3px 8px;
  }

  .exp-responsibilities li {
    font-size: 0.86rem;
    padding-left: 16px;
  }

  /* Skills Grid */
  .skills-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .skill-pillar-card {
    padding: 22px 16px;
  }

  /* Portfolio Filters on Mobile */
  .portfolio-filters {
    gap: 6px;
    margin-bottom: 28px;
  }

  .filter-btn {
    padding: 6px 14px;
    font-size: 0.8rem;
  }

  /* Project Card Media */
  .project-card-media {
    height: 200px;
  }

  .project-card-body {
    padding: 18px 14px;
  }

  /* Certificates */
  .certificate-preview-box {
    height: 190px;
  }

  .certificate-info {
    padding: 18px 14px;
  }

  /* YouTube Banner */
  .youtube-subscribe-banner {
    padding: 22px 16px;
    flex-direction: column;
    text-align: center;
  }

  .yt-banner-left {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }

  .yt-banner-text h3 {
    font-size: 1.2rem;
  }

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

  /* Contact Form */
  .contact-info-panel,
  .contact-form-panel {
    padding: 22px 16px;
  }

  .form-control-custom {
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  /* Lightbox Mobile */
  .lightbox-modal {
    padding: 8px;
  }

  .lightbox-content-box {
    max-height: 98vh;
  }

  .lightbox-header {
    padding: 10px 12px;
  }

  .lightbox-title-wrap h4 {
    font-size: 0.95rem;
  }

  .lightbox-counter {
    font-size: 0.72rem;
  }

  .lightbox-body {
    min-height: 240px;
    padding: 8px;
  }

  .lightbox-main-img {
    max-height: 50vh;
  }

  .lightbox-nav-btn {
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
  }

  .lightbox-prev {
    left: 4px;
  }

  .lightbox-next {
    right: 4px;
  }

  .lightbox-thumbnails-strip {
    padding: 6px 8px;
    gap: 6px;
  }

  .lightbox-thumb-item {
    flex: 0 0 42px;
    height: 42px;
  }
}

/* Ultra Small Screens (<= 360px, e.g. iPhone SE, Galaxy Z Flip outer, Android compact) */
@media (max-width: 360px) {
  .section-title {
    font-size: 1.55rem;
  }

  .hero-title {
    font-size: 1.7rem;
  }

  .hero-stats-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .brand-text {
    font-size: 1.05rem;
  }

  .profile-card-sticky {
    padding: 16px 12px;
  }

  .profile-avatar-box {
    width: 130px;
    height: 130px;
  }

  .profile-name {
    font-size: 1.12rem;
  }

  .profile-role {
    font-size: 0.8rem;
  }

  .highlight-chip {
    padding: 9px 12px;
    font-size: 0.8rem;
    gap: 8px;
  }

  .highlight-chip i {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
  }

  .flagship-title {
    font-size: 1.1rem;
  }

  .screen-thumb-box {
    flex: 0 0 82px;
    height: 145px;
  }
}

/* Accessibility: 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;
  }
}