/* ===============================================
   NAVNEET MALLICK — MOBILE & RESPONSIVE QUERIES
   =============================================== */

/* ── MOBILE-SPECIFIC KEYFRAMES ──────────────────── */
/* Calmer float for mobile — 8px travel vs 20px on desktop */
@keyframes floatMobile {
  0%, 100% { transform: translateY(0);    }
  50%       { transform: translateY(-8px); }
}

/* ── GLOBAL MOBILE BASE ─────────────────────────── */
html {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scroll-padding-top: 64px; /* match mobile navbar height */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

* { 
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

/* Prevent zoom on input focus */
input, textarea, select {
  font-size: 16px !important;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *:not(#boot-overlay):not(#boot-overlay *):not(.t-line):not(.t-output),
  *:not(#boot-overlay):not(#boot-overlay *)::before,
  *:not(#boot-overlay):not(#boot-overlay *)::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── TABLET (max-width: 900px) ─────────────────── */
@media (max-width: 900px) {
  .nav-links { display: none; }

  /* Always show terminal section on all mobile/tablet — no reveal fade */
  #terminal-intro.reveal,
  #terminal-intro.reveal.active {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  /* Show hacker button on all mobile/tablet sizes */
  #mobile-hacker-btn-wrap {
    display: flex !important;
  }

  /* ── Bottom nav visible on all mobile/tablet sizes ── */
  #mobile-bottom-nav { 
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background: rgba(7, 11, 31, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 229, 255, 0.15);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    height: 64px;
    padding-bottom: env(safe-area-inset-bottom);
    justify-content: space-around;
    align-items: center;
  }

  #mobile-bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 16px;
    min-width: 56px;
    min-height: 52px;
    color: rgba(234, 242, 255, 0.55);
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    letter-spacing: 0.5px;
    -webkit-user-select: none;
    user-select: none;
  }

  #mobile-bottom-nav a i {
    font-size: 21px;
    transition: all 0.25s ease;
  }

  #mobile-bottom-nav a span {
    font-size: 10px;
    opacity: 0.8;
    transition: all 0.25s ease;
  }

  #mobile-bottom-nav a.active {
    color: var(--accent);
    background: rgba(0, 229, 255, 0.1);
  }

  #mobile-bottom-nav a.active i {
    font-size: 23px;
    color: var(--accent);
    text-shadow: 0 0 10px rgba(0, 229, 255, 0.6);
  }

  #mobile-bottom-nav a.active span {
    opacity: 1;
    color: var(--accent);
  }

  #mobile-bottom-nav a:not(.active):active {
    background: rgba(0, 229, 255, 0.08);
    color: var(--accent);
    transform: scale(0.95);
  }

  /* Ensure page content doesn't hide behind bottom nav */
  body {
    padding-bottom: max(64px, calc(64px + env(safe-area-inset-bottom)));
  }

  footer {
    margin-bottom: 0;
  }

  .hero {
    text-align: center;
    justify-content: center;
    flex-direction: column-reverse;
    padding: 110px 6% 60px;
    gap: 30px;
  }

  .hero-left { width: 100%; }
  .hero-left h1 { font-size: clamp(1.8rem, 6vw, 2.4rem); }
  .hero-buttons { justify-content: center; }
  .hero-right { display: flex; justify-content: center; }

  /* ── Profile image — tablet ── */
  .pp-img {
    max-width: 260px;
    /* Gentle float only — no profileGlow colour shift on tablet */
    animation: 7s ease-in-out infinite floatMobile;
    border-width: 4px;
  }
  .hero-right::before {
    width: 300px;
    height: 300px;
    /* Subtle slow rotation only */
    animation: 20s linear infinite rotate;
    opacity: 0.12;
    filter: blur(40px);
  }

  .section-title {
    font-size: clamp(1.5rem, 5vw, 2rem);
    letter-spacing: 2px;
    margin: 40px 0 35px;
  }

  .project-container {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    padding: 0 5%;
    gap: 20px;
  }

  .project-card { height: 260px; }
  .map { padding: 0 5%; }
  .cert-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); padding: 0 5%; }
  .contact-form { padding: 0 5%; }
  .skills-container { padding: 0 5%; }
  .skills-table-wrap { padding: 0 5%; }
  #github-stats { padding: 0 5% 40px; }
  .terminal-intro-section { padding: 40px 5%; }
  .theme-wrapper-container { padding: 30px 5%; }
  #certifications { padding: 30px 5%; }
  .about-section { padding: 60px 6%; }
  .about-grid { grid-template-columns: 1fr; gap: 40px; }
  .about-info { padding: 24px 20px; }

  /* Disable heavy effects on tablet too */
  .project-card,
  .cert-card,
  .stat-card,
  .exp-card,
  .timeline-content {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
}

/* ── TABLET LANDSCAPE (768px - 900px) ─────────────────── */
@media (max-width: 900px) and (orientation: landscape) {
  .hero {
    flex-direction: row;
    padding: 60px 6% 30px;
    min-height: auto;
    gap: 20px;
  }
  .pp-img { max-width: 160px; animation-duration: 10s; }
  .hero-right::before { width: 190px; height: 190px; }
  .hero-left h1 { font-size: 1.6rem; }
  .section-title { font-size: 1.4rem; }
}

/* ── MOBILE (max-width: 600px) ──────────────────── */
@media (max-width: 600px) {
  html { 
    scroll-padding-top: 64px;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  body {
    overscroll-behavior-y: auto;
    scroll-behavior: smooth;
  }

  /* Navbar - Fixed z-index to ensure visibility */
  .navbar { 
    padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-left));
    height: 64px; 
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    width: 100%;
    backdrop-filter: blur(10px);
  }
  #nav-logo-img { height: 40px; }
  #nav-actions-box { 
    padding: 7px 12px; 
    gap: 8px;
    padding-right: max(12px, env(safe-area-inset-right));
  }
  #theme-text { display: none; }
  #theme-btn { 
    position: relative; 
    z-index: 1001; 
    pointer-events: auto;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  #shortcuts-hint { display: none; }
  #nav-dropdown { 
    min-width: calc(100vw - 24px); 
    right: max(4px, env(safe-area-inset-right));
    left: max(4px, env(safe-area-inset-left));
    z-index: 1002;
    position: fixed;
    top: 64px;
    max-height: calc(100vh - 64px - 60px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: rgba(7, 11, 31, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 229, 255, 0.15);
    border-radius: 12px;
    margin: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  }

  #nav-dropdown a {
    padding: 14px 16px;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: rgba(234, 242, 255, 0.8);
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
  }

  #nav-dropdown a:active {
    background: rgba(0, 229, 255, 0.1);
    border-left-color: var(--accent);
    color: var(--accent);
  }

  #nav-dropdown a i {
    width: 20px;
    text-align: center;
    color: var(--accent);
  }

  .dropdown-header {
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--accent);
    opacity: 0.7;
    margin-top: 8px;
  }

  .dropdown-header:first-child {
    margin-top: 0;
  }

  .dropdown-divider {
    height: 1px;
    background: rgba(0, 229, 255, 0.1);
    margin: 8px 0;
  }

  /* Hero */
  .hero { 
    padding: 50px 5% 50px; 
    gap: 20px;
    margin-top: 64px;
  }
  .hero-left h1 { font-size: clamp(1.5rem, 7vw, 1.9rem); }
  .hero-left p { font-size: 1rem !important; }
  .hero-bio { font-size: 0.9rem !important; }
  
  /* Glitch effect - simplify for mobile */
  .hero-left h1 span.hero-glitch::before,
  .hero-left h1 span.hero-glitch::after {
    display: none;
  }
  .hero-left h1 span.glitching::before,
  .hero-left h1 span.glitching::after {
    display: block !important;
  }
  
  .hero-buttons {
    flex-direction: column;
    gap: 10px;
    align-items: center;
    margin-top: 16px;
  }
  .btn-cv { margin-left: 0; }
  .hero-buttons .btn { 
    width: 100%; 
    max-width: 220px; 
    text-align: center; 
    padding: 14px 20px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Profile image — mobile ── */
  .pp-img {
    max-width: 220px;
    /* Halved travel distance, slower period — feels calm not jittery */
    animation: 8s ease-in-out infinite floatMobile;
    border-width: 4px;
  }
  .hero-right::before {
    width: 260px;
    height: 260px;
    /* Subtle slow rotation only */
    animation: 20s linear infinite rotate;
    opacity: 0.1;
    filter: blur(45px);
  }

  /* Section titles */
  .section-title {
    font-size: clamp(1.2rem, 6vw, 1.6rem);
    letter-spacing: 1px;
    margin: 28px 0 24px;
    animation: none !important;
    background-position: 0% center !important;
  }

  /* Projects */
  .project-container { grid-template-columns: 1fr; padding: 0 4%; gap: 14px; }
  .project-card { 
    height: 210px;
    min-height: 200px;
  }
  .overlay {
    opacity: 1;
    background: linear-gradient(to top, rgba(5,8,20,0.95) 0%, rgba(5,8,20,0.5) 50%, transparent 100%);
    justify-content: flex-end;
    transform: none;
    position: relative;
    z-index: 10;
    pointer-events: auto;
  }
  .overlay .btn { 
    transform: none; 
    opacity: 1; 
    padding: 10px 16px; 
    font-size: 12px; 
    margin-top: 0;
    position: relative;
    z-index: 11;
    pointer-events: auto;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .overlay-btns {
    position: relative;
    z-index: 11;
    pointer-events: auto;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  .overlay-btns .btn,
  .overlay-btns .btn-cv {
    position: relative;
    z-index: 12;
    pointer-events: auto;
    cursor: pointer;
  }
  .project-card:hover { transform: none; }
  .overlay h3 { font-size: 1rem; margin-bottom: 6px; }
  .overlay p { font-size: 0.78rem; margin-bottom: 10px; }
  .project-tabs {
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0 4% 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
  .project-tabs::-webkit-scrollbar { display: none; }
  .project-tab { 
    padding: 10px 14px; 
    font-size: 12px; 
    flex-shrink: 0;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Stats */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 0 4%; }
  .stat-card { 
    padding: 18px 10px;
    min-height: 100px;
  }
  .stat-number { font-size: 1.8rem; }
  .stat-card i { font-size: 1.5rem; }
  .stat-card p { font-size: 0.78rem; }

  /* Certs */
  .cert-grid { grid-template-columns: repeat(2, 1fr); padding: 0 4%; gap: 12px; }
  .cert-card { 
    padding: 20px 14px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .cert-card h3 { font-size: 0.95rem; }
  .cert-icon { width: 44px; height: 44px; font-size: 1.2rem; }

  /* Contact */
  .contact-card { 
    padding: 20px 16px; 
    margin: 0 12px;
    min-height: 60px;
  }
  .input-group input,
  .input-group textarea { 
    padding: 14px 16px 14px 44px; 
    font-size: 16px;
    min-height: 44px;
  }
  .input-group i { left: 14px; }
  .input-group textarea { min-height: 130px; }
  .contact-form button { 
    min-width: 180px;
    min-height: 44px;
  }

  /* Map */
  .map { padding: 0 4%; }
  .map iframe { height: 240px; }

  /* Timeline / Experience */
  .exp-card, .timeline-content { 
    padding: 18px 14px;
    min-height: 80px;
  }
  .timeline { padding-left: 18px; margin-left: 8px; }
  .timeline-item::before { left: -27px; }

  /* Terminal */
  .terminal { max-width: 100%; width: 100%; }
  .terminal-body { font-size: 12px; min-height: 200px; padding: 15px; }
  .terminal-card { transform: none !important; animation: none !important; box-shadow: 0 10px 30px rgba(0,0,0,0.4) !important; }
  .t-input { font-size: 12px !important; width: 60% !important; }
  .terminal-intro-section { padding: 30px 4% !important; }

  /* Always show terminal section — no reveal fade on mobile */
  #terminal-intro.reveal,
  #terminal-intro.reveal.active {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  
  /* Lenient reveal for other sections on mobile */
  .reveal {
    transition-duration: 0.4s !important; /* Faster transition */
    transform: translateY(15px); /* Less distance to travel */
  }
  .reveal.active {
    transform: translateY(0);
  }

  /* Show hacker button on mobile */
  #mobile-hacker-btn-wrap {
    display: flex !important;
  }

  /* About */
  .about-section { padding: 40px 5%; }
  .about-grid { gap: 24px; }
  .about-info { 
    padding: 16px 14px;
    min-height: 60px;
  }
  .about-info-item { 
    font-size: 0.82rem; 
    gap: 8px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .about-info-item i { width: 28px; height: 28px; font-size: 11px; }
  .about-tags { gap: 6px; }
  .about-tags span { font-size: 0.72rem; padding: 4px 10px; }
  .currently-learning { padding: 8px 10px; }
  .learning-item { font-size: 0.7rem; padding: 3px 8px; }

  /* Music player - compact strip */
  #music-player {
    bottom: 68px;
    right: 12px;
    left: auto;
    max-width: 180px;
    padding: 6px 10px;
    gap: 6px;
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  #music-track-name { max-width: 90px; font-size: 9px; }
  #music-volume { display: none !important; }
  #music-mode-btn { display: none !important; }
  #music-external-link { display: none !important; }
  .music-notification-badge { display: none !important; }
  .game-notification-badge { font-size: 7px; padding: 2px 4px; }
  .game-notification-pulse { display: none; }

  /* Back to top */
  #back-to-top { 
    bottom: 130px; 
    right: 14px; 
    width: 44px; 
    height: 44px; 
    font-size: 14px;
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: max(130px, calc(130px + env(safe-area-inset-bottom)));
    position: fixed;
    z-index: 998;
    background: linear-gradient(135deg, var(--accent), var(--secondary));
    border: none;
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 229, 255, 0.3);
    transition: all 0.3s ease;
    opacity: 0;
    pointer-events: none;
  }

  #back-to-top.show {
    display: flex;
    opacity: 1;
    pointer-events: auto;
  }

  #back-to-top:active {
    transform: scale(0.95);
  }

  /* Toast */
  #toast-container { 
    right: 8px; 
    left: 8px; 
    bottom: 80px;
    right: max(8px, env(safe-area-inset-right));
    left: max(8px, env(safe-area-inset-left));
    bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
  }
  .toast { max-width: 100%; font-size: 13px; }

  /* Footer */
  footer { 
    padding: 24px 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(80px, calc(64px + env(safe-area-inset-bottom)));
    gap: 10px; 
  }
  .social-icons { gap: 10px; }
  .social-icons a { 
    width: 44px; 
    height: 44px; 
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Mobile bottom nav — base styles in 900px block above */

  /* Skills table */
  .skills-table-container { padding: 8px 10px 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .skills-tabular { min-width: 300px; }
  .skills-tabular th { padding: 10px 12px; font-size: 0.72rem; }
  .skills-tabular td { padding: 10px 12px; }
  .tech-tag { font-size: 0.75rem; padding: 4px 8px; gap: 4px; }
  .tech-tag i { font-size: 13px; width: 14px; height: 14px; }
  .prof-bar { width: 100px; height: 6px; }
  .prof-label { font-size: 10px; }
  .cat-cell { font-size: 0.82rem; min-width: 90px; }

  /* Easter egg modal */
  .egg-box { 
    padding: 24px 18px;
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }
  .egg-title { font-size: 1.2rem; }
  .egg-emoji { font-size: 2.5rem; }

  /* Disable heavy effects */
  .scanlines,
  #matrix-canvas,
  .cursor-dot,
  .cursor-ring,
  #spotlight { display: none !important; }

  .project-card,
  .cert-card,
  .stat-card,
  .exp-card,
  .timeline-content,
  .about-info,
  .contact-card {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2) !important;
  }
}

/* ── SMALL MOBILE (max-width: 400px) ────────────── */
@media (max-width: 400px) {
  .hero-left h1 { font-size: 1.4rem; }
  .pp-img { max-width: 190px; }
  .hero-right::before { width: 220px; height: 220px; }
  .project-tab { padding: 7px 12px; font-size: 11px; }
  .stat-number { font-size: 1.6rem; }
  #nav-logo-img { height: 36px; }
  .cert-grid { grid-template-columns: 1fr; }
  .cert-card { padding: 16px 12px; }
  .skills-tabular { min-width: 300px; }
  .tech-tag { font-size: 0.7rem; padding: 3px 7px; }
}

/* ── ULTRA-SMALL (max-width: 360px) ─────────────── */
@media (max-width: 360px) {
  .hero-left h1 { font-size: 1.3rem; }
  .pp-img { max-width: 170px; }
  .hero-right::before { width: 200px; height: 200px; }
  .section-title { font-size: 1.15rem; letter-spacing: 0.5px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px 8px; }
  .stat-number { font-size: 1.5rem; }
  footer a { font-size: 16px; }
  #music-player { max-width: 160px; }
  .navbar { padding: 0 12px; }
  #nav-actions-box { padding: 6px 10px; gap: 6px; }
}

/* ── SMALL MOBILE LANDSCAPE (max-width: 600px, orientation: landscape) ───────────────────────────── */
@media (max-width: 600px) and (orientation: landscape) {
  .hero {
    flex-direction: row;
    padding: 50px 4% 20px;
    min-height: auto;
    gap: 15px;
    margin-top: 64px;
  }
  .hero-left h1 { font-size: 1.3rem; }
  .hero-left p { font-size: 0.85rem !important; }
  .hero-bio { display: none; }
  .hero-buttons {
    flex-direction: row;
    gap: 8px;
    margin-top: 8px;
  }
  .hero-buttons .btn { 
    width: auto;
    max-width: 100px;
    padding: 8px 12px;
    font-size: 11px;
    min-height: 40px;
  }
  .pp-img { max-width: 140px; }
  .hero-right::before { width: 160px; height: 160px; }
  .section-title { font-size: 1.1rem; margin: 20px 0 16px; }
  .project-container { gap: 10px; }
  .project-card { height: 150px; }
  .stats-grid { gap: 8px; }
  .stat-card { padding: 12px 8px; }
  .stat-number { font-size: 1.4rem; }
}

/* ── GAME MODAL MOBILE (optimized for all screen sizes) ──────────────────────────── */
@media (max-width: 700px) {
  #game-modal { 
    z-index: 9999999 !important;
    position: fixed !important;
    inset: 0 !important;
    padding: max(20px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(80px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)) !important;
    display: none;
    align-items: center;
    justify-content: flex-start !important;
    flex-direction: column;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    background: rgba(0,0,0,0.92) !important;
  }

  /* Game box styling - optimized for mobile */
  #game-box { 
    padding: 16px !important; 
    z-index: 9999999 !important;
    height: auto !important;
    max-height: none !important;
    width: 100% !important;
    max-width: 600px !important;
    margin: 0 auto !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: visible !important;
    overflow-x: hidden;
    border-radius: 12px;
    background: #0a0e27 !important;
  }

  /* Header row with game tabs - horizontal scroll on small screens */
  #game-box > div:first-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
  }

  /* Game tab buttons - responsive sizing */
  #game-tab-runner,
  #game-tab-snake,
  #game-tab-mine,
  #game-tab-asteroid {
    padding: 8px 12px !important;
    font-size: 11px !important;
    letter-spacing: 0.5px !important;
    min-height: 40px;
    min-width: 72px;
    flex: 1;
    min-flex: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Close button - always accessible */
  #game-box button[onclick="closeRunnerGame()"] {
    min-height: 40px;
    min-width: 40px;
    flex-shrink: 0;
  }

  /* Notification/More games section */
  #game-box > div:nth-child(2) {
    margin-bottom: 12px !important;
    padding: 8px !important;
    border-radius: 8px;
    font-size: 11px !important;
  }

  #game-box > div:nth-child(2) a {
    font-size: 10px !important;
    gap: 4px !important;
    flex-wrap: wrap;
  }

  #game-panel-runner,
  #game-panel-snake,
  #game-panel-mine,
  #game-panel-asteroid {
    width: 100%;
    display: block !important;
    overflow: visible !important;
  }

  /* Title styling in game panels */
  #game-panel-runner > div:first-child,
  #game-panel-snake > div:first-child,
  #game-panel-mine > div:first-child,
  #game-panel-asteroid > div:first-child {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
  }

  #game-panel-runner > div:first-child > span:first-child,
  #game-panel-snake > div:first-child > span:first-child,
  #game-panel-mine > div:first-child > span:first-child,
  #game-panel-asteroid > div:first-child > span:first-child {
    font-size: 12px !important;
  }

  #game-panel-runner > div:first-child > div,
  #game-panel-snake > div:first-child > div,
  #game-panel-mine > div:first-child > div,
  #game-panel-asteroid > div:first-child > div {
    flex-wrap: wrap;
    gap: 10px;
  }

  #game-panel-runner > div:first-child > div > span,
  #game-panel-snake > div:first-child > div > span,
  #game-panel-mine > div:first-child > div > span,
  #game-panel-asteroid > div:first-child > div > span {
    font-size: 12px !important;
  }

  /* Canvas scaling - proper aspect ratio maintenance */
  #game-canvas { 
    width: 100% !important; 
    height: auto !important;
    aspect-ratio: 620 / 160;
    min-height: 80px;
    max-height: 60vh;
    display: block;
    background: #05081a;
    border-radius: 6px;
    border: 1px solid rgba(0, 229, 255, 0.1);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
  }

  #snake-canvas { 
    width: 100% !important; 
    height: auto !important;
    aspect-ratio: 620 / 320;
    min-height: 100px;
    max-height: 60vh;
    display: block;
    background: #05081a;
    border-radius: 6px;
    border: 1px solid rgba(245, 158, 11, 0.1);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
  }

  #asteroid-canvas,
  #mine-canvas { 
    width: 100% !important; 
    height: auto !important;
    display: block;
    background: #05081a;
    border-radius: 6px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
  }

  #asteroid-canvas {
    aspect-ratio: 14.2 / 20;
    min-height: 280px;
    max-height: 70vh;
    width: auto !important;
    max-width: 100%;
    margin: 0 auto;
    border: 1px solid rgba(168, 85, 247, 0.1);
  }

  #mine-canvas {
    aspect-ratio: 1;
    min-height: 100px;
    max-height: 70vh;
    width: auto !important;
    max-width: 100%;
    margin: 0 auto;
    border: 1px solid rgba(34, 197, 94, 0.1);
  }

  /* Controls info text - responsive sizing */
  #game-panel-runner > div:last-child,
  #game-panel-snake > div:last-child,
  #game-panel-mine > div:last-child,
  #game-panel-asteroid > div:last-child {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
  }

  #game-panel-runner > div:last-child > p,
  #game-panel-snake > div:last-child > p,
  #game-panel-mine > div:last-child > p,
  #game-panel-asteroid > div:last-child > p {
    font-size: 10px !important;
    opacity: 0.4 !important;
    margin: 0 !important;
    line-height: 1.2;
  }

  #game-panel-runner > div:last-child > span,
  #game-panel-snake > div:last-child > span,
  #game-panel-mine > div:last-child > span,
  #game-panel-asteroid > div:last-child > span {
    font-size: 10px !important;
    text-align: right;
  }

  /* Mine difficulty buttons - responsive grid */
  #game-panel-mine > div:nth-child(2) {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    gap: 6px;
    margin-bottom: 8px !important;
  }

  #game-panel-mine > div:nth-child(2) button {
    padding: 6px 8px !important;
    font-size: 10px !important;
    min-height: 36px;
  }

  /* Disable scanlines and heavy effects on mobile */
  .scanlines {
    display: none !important;
  }

  /* Ensure proper scrolling area */
  #game-box {
    max-height: calc(100vh - 120px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  /* Prevent body scroll when game is open */
  body:has(#game-modal[aria-hidden="false"]) {
    overflow: hidden;
  }
}

/* ── SMALLER PHONES (max-width: 480px) ────────────────────────── */
@media (max-width: 480px) {
  #game-box {
    padding: 10px !important;
    width: calc(100% - 20px);
    margin: 10px auto;
  }

  #game-tab-runner,
  #game-tab-snake,
  #game-tab-mine,
  #game-tab-asteroid {
    padding: 6px 10px !important;
    font-size: 10px !important;
    min-height: 36px;
    min-width: 60px;
  }

  #game-canvas {
    min-height: 100px;
    max-height: 40vh;
  }

  #snake-canvas,
  #asteroid-canvas {
    min-height: 120px;
    max-height: 45vh;
  }

  #mine-canvas {
    min-height: 120px;
    max-height: 50vh;
  }

  #game-panel-runner > div:first-child,
  #game-panel-snake > div:first-child,
  #game-panel-mine > div:first-child,
  #game-panel-asteroid > div:first-child {
    gap: 4px;
    margin-bottom: 6px;
  }

  #game-panel-runner > div:last-child,
  #game-panel-snake > div:last-child,
  #game-panel-mine > div:last-child,
  #game-panel-asteroid > div:last-child {
    gap: 4px;
    margin-top: 6px;
  }

  #game-panel-runner > div:last-child > p,
  #game-panel-snake > div:last-child > p,
  #game-panel-mine > div:last-child > p,
  #game-panel-asteroid > div:last-child > p {
    font-size: 9px !important;
  }
}

/* ── LARGE TABLETS (768px - 900px) ────────────────────────── */
@media (min-width: 701px) and (max-width: 900px) {
  #game-modal {
    justify-content: center;
  }

  #game-box {
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
  }

  #game-canvas {
    max-height: 60vh;
  }

  #snake-canvas,
  #asteroid-canvas {
    max-height: 65vh;
  }

  #mine-canvas {
    max-height: 70vh;
  }
}

/* ── ENHANCED MOBILE GAME CONTROLS ────────────────────────────── */
@media (max-width: 700px) {
  /* Touch-friendly active states */
  #game-tab-runner:active,
  #game-tab-snake:active,
  #game-tab-mine:active,
  #game-tab-asteroid:active {
    transform: scale(0.97);
    opacity: 0.9;
  }

  #game-panel-mine > div:nth-child(2) button:active {
    transform: scale(0.95);
    opacity: 0.8;
  }

  /* Improve canvas touch responsiveness */
  canvas {
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
  }

  /* Better button feedback on mobile */
  button[onclick*="Game"],
  #game-tab-runner,
  #game-tab-snake,
  #game-tab-mine,
  #game-tab-asteroid {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }
}

/* ── PROJECT FILTER TABS ────────────────────────── */
@media (max-width: 600px) {
  #projects-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── LOW-END DEVICE OPTIMIZATIONS ──────────────── */
[data-low-end="true"] .scanlines,
[data-low-end="true"] .particles,
[data-low-end="true"] #hero-canvas,
[data-low-end="true"] #spotlight {
  display: none !important;
}

[data-low-end="true"] .project-card,
[data-low-end="true"] .cert-card,
[data-low-end="true"] .stat-card {
  box-shadow: none !important;
  backdrop-filter: none !important;
  background: var(--card-bg-fallback, #121836) !important;
}

[data-low-end="true"] *:not(#boot-overlay):not(#boot-overlay *):not(.t-line):not(.t-output):not(.t-cursor) {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* ── MOBILE PERFORMANCE: Kill expensive CSS animations ── */
@media (max-width: 900px) {
  /* Kill infinite background animations */
  body::before { animation: none !important; }
  body::after  { animation: none !important; }

  /* Kill particle floats */
  .particle { display: none !important; }

  /* Kill cert ring pulse */
  .cert-icon::after { animation: none !important; }

  /* Kill timeline dot pulse */
  .timeline-item::before { animation: none !important; }

  /* Kill hero gradient text animation — static gradient is fine */
  .hero-left h1 span {
    animation: none !important;
    background-position: 0% center !important;
  }

  /* Kill scroll progress gradient animation */
  #scroll-progress { animation: none !important; }

  /* Kill audio visualizer bars */
  .audio-bar, .viz-bar { animation: none !important; }

  /* Kill hero profile float — replaced by floatMobile */
  .pp-img { animation: 8s ease-in-out infinite floatMobile !important; }

  /* Kill hero right ring rotation */
  .hero-right::before { animation: 20s linear infinite rotate !important; }

  /* Kill glitch pseudo-elements */
  .hero-glitch::before,
  .hero-glitch::after { display: none !important; }

  /* Simplify will-change to reduce GPU layers */
  * { will-change: auto !important; }
  .pp-img, .terminal-card, .project-card { will-change: transform !important; }
}
