/* Mobile layout overrides */

@media (max-width: 700px) {
  :root {
    --mobile-footer-clearance: 118px;
  }

  body {
    padding: 14px 10px calc(var(--mobile-footer-clearance) + env(safe-area-inset-bottom));
    overflow: auto;
  }

  .site-shell {
    width: min(var(--site-width), calc(100vw - 20px));
    margin: 0 auto;
    gap: 0;
  }

  /* Fixed mobile chrome: full-width opaque layer so page content can never
     draw over or through the navigation while scrolling. */
  .site-footer,
  .site-footer--work {
    position: fixed;
    z-index: 1000;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
      "nav"
      "copyright";
    justify-items: center;
    align-items: center;
    gap: 0;
    row-gap: 7px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    background: var(--bg);
    transform: none !important;
    transition: none !important;
    isolation: isolate;
  }

  /* Work follows the reference: display selector first, then menu, then name. */
  .site-footer--work {
    grid-template-areas:
      "display"
      "nav"
      "copyright";
    row-gap: 8px;
  }

  body[data-menu-sliding="true"] .site-footer {
    transform: none !important;
  }

  .footer-nav {
    grid-area: nav;
    width: 100%;
    justify-content: center;
    gap: 12px;
    flex-wrap: nowrap;
    text-align: center;
  }

  .footer-copyright {
    grid-area: copyright;
    display: block;
    justify-self: center;
    text-align: center;
  }

  .display-switch,
  .site-footer--work .display-switch {
    grid-area: display;
    justify-self: center;
    margin: 0;
  }

  /* Work gets the full usable mobile viewport above the fixed footer. */
  .work-page {
    width: 100%;
    height: calc(100dvh - 152px - env(safe-area-inset-bottom));
    max-height: calc(100dvh - 152px - env(safe-area-inset-bottom));
    min-height: 320px;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .work-list-wrap {
    width: 100%;
    overflow-x: hidden;
    padding-bottom: 12px;
  }

  .work-list {
    width: 100%;
    min-width: 0;
  }

  /* On a narrow screen the four desktop cells become a readable 3-column,
     2-line row: title | format | year, with brand directly under format. */
  .work-list__header {
    display: none;
  }

  .work-list__row {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.35fr) auto;
    grid-template-rows: auto auto;
    column-gap: 9px;
    row-gap: 1px;
    align-items: start;
    padding: 7px 0;
    line-height: 1.18;
  }

  .work-list__row > span:nth-child(1) {
    grid-column: 1;
    grid-row: 1 / span 2;
    min-width: 0;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .work-list__row > span:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .work-list__row > span:nth-child(3) {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .work-list__row > span:nth-child(4) {
    grid-column: 3;
    grid-row: 1;
    text-align: right;
    white-space: nowrap;
  }

  /* Mobile Grid is always two columns, matching the supplied reference. */
  .work-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px 10px;
  }

  .work-grid-card__media {
    width: 100%;
    aspect-ratio: 4 / 3;
  }

  .work-grid-card__title {
    padding-top: 5px;
    line-height: 1.15;
  }

  .work-hover-preview {
    display: none !important;
  }

  /* The footer credit opens upward on mobile so it stays inside the viewport. */
  .site-credit-popover {
    right: 50%;
    left: auto;
    top: auto !important;
    bottom: calc(100% + 8px) !important;
    transform: translateX(50%);
    max-width: calc(100vw - 32px);
    text-align: center;
  }
}

@media (max-width: 420px) {
  .footer-nav {
    gap: 9px;
  }

  .work-list__row {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.25fr) auto;
    column-gap: 7px;
  }
}

@media (max-width: 360px) {
  .footer-nav {
    gap: 7px;
  }
}
