/* Make the whole profile sheet scroll on phones so every section can be reached. */
@media (max-width: 600px) {
  .profile-modal,
  .profile-modal[open] {
    display: block;
    box-sizing: border-box;
    width: calc(100vw - 24px);
    max-width: none;
    max-height: calc(100dvh - 24px);
    margin: 12px auto;
    border-radius: 18px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: none;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .profile-modal::-webkit-scrollbar {
    display: none;
    width: 0;
  }

  .profile-modal > .profile-close {
    position: relative;
    display: grid;
    align-self: flex-end;
    z-index: 10;
    flex: 0 0 42px;
    margin: calc(18px + env(safe-area-inset-top, 0px)) calc(18px + env(safe-area-inset-right, 0px)) -60px auto;
    place-items: center;
    padding: 0;
  }

  .profile-modal > .profile-close .profile-close-mark {
    line-height: 1;
    transform: translateY(2px);
  }

  .profile-modal > #profileContent {
    display: block;
    height: auto;
    overflow: visible;
  }

  /* Preserve the desktop header arrangement and scale its columns to mobile. */
  .profile-modal .profile-summary {
    grid-template-columns: clamp(96px, 25vw, 120px) minmax(0, 1fr);
    align-items: start;
    gap: clamp(10px, 3vw, 16px);
    margin-top: clamp(-60px, -11vw, -42px);
  }

  .profile-modal .profile-summary > div:last-child {
    min-width: 0;
    padding-top: clamp(26px, 8.5vw, 34px);
  }

  .profile-modal .profile-avatar {
    width: clamp(96px, 25vw, 120px);
    height: clamp(96px, 25vw, 120px);
    border-width: 4px;
    font-size: clamp(34px, 9vw, 46px);
  }

  .profile-modal .profile-batch {
    top: -30px;
    left: -4px;
    margin: 0 0 -55px;
    padding: clamp(3px, 1vw, 4px) clamp(7px, 2.5vw, 10px);
    font-size: clamp(11px, 3vw, 12px);
    line-height: 1.2;
  }

  .profile-modal .profile-summary h2,
  .profile-modal .profile-summary .profile-lead {
    top: 0;
  }

  .profile-modal .profile-summary h2 {
    margin-bottom: 5px;
    font-size: clamp(17px, 4.6vw, 22px);
    line-height: 1.25;
  }

  .profile-modal .profile-lead {
    font-size: clamp(12px, 3.2vw, 15px);
    line-height: 1.45;
  }

  /* Keep the desktop column proportions, with minimum widths for readability. */
  .profile-education-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(6px, 1.8vw, 14px);
  }

  .profile-education-row .profile-education-institution {
    grid-column: 1 / -1;
  }

  .profile-education-row .profile-item {
    min-height: 72px;
    gap: clamp(4px, 1.5vw, 8px);
    padding: clamp(6px, 1.8vw, 9px) clamp(6px, 2vw, 10px);
  }

  .profile-core-grid .profile-item {
    min-height: 72px;
    padding: clamp(6px, 1.8vw, 9px) clamp(6px, 2vw, 10px);
  }

  .profile-education-row .profile-item img {
    width: clamp(16px, 4.5vw, 22px);
    height: clamp(16px, 4.5vw, 22px);
    flex: 0 0 clamp(16px, 4.5vw, 22px);
  }

  .profile-education-row .profile-item small { font-size: clamp(10px, 2.8vw, 12px); }
  .profile-education-row .profile-item strong { font-size: clamp(11px, 3vw, 14px); }

  .profile-body,
  .profile-body:has(.profile-education-list) {
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }
}
