@media screen and (max-width: 1400px) {
  #profile {
    height: 83vh;
    margin-bottom: 6rem;
  }

  .about-containers {
    flex-wrap: wrap;
  }

  #contact,
  #projects {
    height: fit-content;
  }
}

@media screen and (max-width: 1200px) {
  #desktop-nav {
    display: none;
  }

  #hamburger-nav {
    display: flex;
  }

  #experience,
  .experience-details-container {
    margin-top: 2rem;
  }

  #profile,
  .section-container {
    display: block;
  }

  section,
  .section-container {
    height: fit-content;
  }

  section {
    margin: 0 5%;
  }

  #profile {
    margin-top: 70px;
  }

  #contact {
    margin-top: 70px;
  }

  .section__pic-container {
    width: 275px;
    height: 275px;
    margin: 0 auto 2rem;
  }

  #about .section__pic-container {
    display: none;
  }

  .about-containers {
    margin-top: 2rem;
  }

  #about-title {
    margin-bottom: 1rem;
  }
}

@media screen and (max-width: 1024px) {
  #professional-experience .timeline-line {
    display: none;
  }

  #professional-experience .experience-cards-container {
    margin-top: 2rem;
  }

  #professional-experience .experience-card {
    justify-content: center;
    padding: 0;
  }

  #professional-experience .card-content {
    max-width: 100%;
  }

  #professional-experience .card-header {
    flex-direction: column;
    align-items: start;
  }

  #professional-experience .icon-wrapper,
  #professional-experience .position-company {
    width: 100%;
  }

  #professional-experience .period {
    margin-top: 0.5rem;
    align-self: flex-start;
  }
}

@media screen and (max-width: 600px) {
  /* Keep the title-to-content rhythm consistent across every section. */
  #about-title {
    margin-bottom: 0;
  }

  #about .about-containers {
    margin: 2rem 0 0;
  }

  #about .text-container {
    margin-top: 1rem;
  }

  #experience .experience-details-container > .about-containers,
  #projects .experience-details-container > .about-containers,
  #work-together .experience-details-container > .about-containers {
    margin: 0;
  }

  #contact {
    height: auto;
    min-height: 40vh;
  }

  #profile {
    height: auto;
    min-height: 0;
    margin-bottom: 0;
    padding: 2rem 0 3rem;
  }

  article {
    font-size: 1rem;
  }

  footer nav {
    height: fit-content;
    margin-bottom: 2rem;
  }

  .about-containers,
  .contact-info-upper-container,
  .btn-container {
    flex-wrap: wrap;
  }

  #work-together .about-containers .details-container {
    flex: 1 1 100%;
  }

  #work-together .btn-container {
    margin-top: 2rem;
  }

  .contact-info-container {
    margin: 0;
  }

  .contact-info-container p,
  .nav-links li a {
    font-size: 1rem;
  }

  .experience-sub-title {
    font-size: 1.25rem;
  }

  .logo {
    font-size: 1.5rem;
  }

  .nav-links {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }

  .section__pic-container {
    width: auto;
    height: 46vw;
    justify-content: center;
  }

  .section__text__p2 {
    font-size: 1.25rem;
  }

  .title {
    font-size: 2rem;
  }

  .text-container {
    text-align: left; /* Avoid uneven word gaps from justify on narrow screens */
    padding: 0 1.25rem; /* Equal gap left & right so the block sits centered */
  }

  #about-title1 {
    text-align-last: center;
  }

  #hamburger-nav {
    height: 60px; /* Slightly smaller for mobile */
    padding: 0 15px;
  }

  .hamburger-icon {
    height: 20px; /* Slightly smaller icon */
  }

  .hamburger-icon span {
    height: 2px; /* Maintain line thickness */
  }

  .menu-links a {
    font-size: 1.25rem; /* Slightly smaller font for mobile links */
    padding: 8px; /* Smaller padding for mobile links */
  }

  .modal {
    height: 100vh;
    height: 100svh;
    height: 100dvh;
  }

  .modal-content {
    width: 100%;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 0;
    border-radius: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .modal-header {
    display: grid;
    grid-template-columns: 2.75rem 1fr 2.75rem;
    align-items: center;
    min-height: 4.25rem;
    padding: env(safe-area-inset-top, 0px) 1rem 0;
    flex: 0 0 auto;
  }

  .modal-header .close-btn,
  .mobile-expand-image-btn {
    display: grid;
    place-items: center;
    position: static;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-color);
    font-size: 2rem;
    line-height: 1;
  }

  .mobile-expand-image-btn {
    justify-self: end;
    font-size: 1.45rem;
    cursor: pointer;
  }

  .mobile-slide-count {
    display: block;
    justify-self: center;
    color: var(--muted-text-color);
    font-size: 0.95rem;
  }

  .modal-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex: 1;
    height: 0;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0 1rem 1rem;
  }

  .slideshow-container,
  .modal-text-content {
    max-width: 100%;
    width: 100%;
  }

  .slideshow {
    max-height: none;
    aspect-ratio: 16 / 9;
  }

  .slideshow-container .expand-image-btn {
    display: none;
  }

  .slideshow-meta {
    margin-top: 0.75rem;
  }

  .modal-text-content {
    padding: 0;
  }

  .modal-text-content h2 {
    font-size: clamp(2rem, 10vw, 2.5rem);
    margin-bottom: 0.75rem;
  }

  .modal-text-content p {
    font-size: 1rem;
    line-height: 1.55;
  }

  #modal-description.is-collapsible:not(.is-expanded) {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }

  .description-toggle:not([hidden]) {
    display: inline-flex;
    align-self: flex-start;
    margin-top: -0.25rem;
    padding: 0;
    border: 0;
    border-bottom: 1px solid currentColor;
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    font: inherit;
    line-height: 1.4;
  }

  .modal-links {
    display: none;
  }

  .modal-footer {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #e5e5e5;
    background: var(--background-color);
    flex: 0 0 auto;
    position: relative;
    z-index: 2;
  }

  .modal-footer .btn {
    flex: 1;
    width: 100%;
    padding: 0.65rem 1rem;
    text-decoration: none;
  }

  .modal-links .btn {
    width: 100%;
  }

  .tech-list {
    gap: 0.55rem;
  }

  .tech-list span {
    padding: 0.4rem 0.7rem;
  }

  .image-lightbox {
    padding: 1.25rem;
  }

  .image-lightbox-close {
    top: 0.75rem;
    right: 1rem;
  }

  .lightbox-prev {
    left: 0.75rem;
  }

  .lightbox-next {
    right: 0.75rem;
  }

  .skills-container {
    gap: 0.8rem; /* Slightly reduce gap on mobile */
    align-items: center; /* Center each row block within the card */
  }

  .skill-item {
    justify-content: flex-start; /* Logo stays left, text next to it */
    width: 190px; /* Allows longer skill names to stay on one line */
    transform: translateX(20px); /* Move only the icon-and-name rows, not the section heading */
  }

  .skill-name {
    flex-grow: 0; /* Stop name from stretching */
    white-space: nowrap;
  }

  /* One predictable gap from a completed section to the next heading. */
  main > section:not(#profile) {
    margin: 4rem 5% 0;
    padding-top: 0;
    padding-bottom: 0;
  }

  footer {
    margin-top: 4rem;
    padding-top: 0;
  }
}
