/* Phone-only refinements. Desktop rules remain untouched. */
@media (max-width: 700px),
  (max-height: 500px) and (max-width: 1000px) and (pointer: coarse) {
  html {
    scroll-padding-top: 80px;
  }
  body {
    -webkit-text-size-adjust: 100%;
  }
  button,
  a {
    -webkit-tap-highlight-color: transparent;
  }
  #ui-wrapper.sticky-top {
    top: calc(12px + env(safe-area-inset-top));
    left: 12px;
    transform: none;
    max-width: calc(100vw - 76px);
    width: calc(100vw - 76px);
    animation: none;
  }
  #ui {
    width: 100%;
    justify-content: space-evenly;
    gap: 4px;
    padding: 4px 8px;
    font-size: 11px;
    letter-spacing: 0.04em;
  }
  #ui a {
    min-height: 40px;
    padding: 0 5px;
    letter-spacing: 0.04em;
  }
  #ui-wrapper:not(.sticky-top) {
    max-width: calc(100vw - 32px);
  }
  .sphere-exit > span,
  .project-return > span,
  .design-return > span,
  .photo-return > span {
    display: none !important;
  }
  .sphere-exit:not(.controls-container),
  .project-return,
  .design-return,
  .photo-return {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .sphere-exit > svg,
  .project-return > svg,
  .design-return > svg,
  .photo-return > svg {
    width: 15px;
    height: 15px;
  }
  .project-return,
  .design-return,
  .photo-return {
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
    z-index: 1002;
  }
  .sphere-header {
    padding: calc(12px + env(safe-area-inset-top)) 12px 0;
    align-items: flex-start;
  }
  .sphere-header h2 {
    margin-top: 58px;
  }
  .sphere-header .sphere-exit {
    margin-left: auto;
  }
  .portfolio-intro {
    padding: 55px 24px;
  }
  .portfolio-intro h2 {
    font-size: clamp(26px, 7.5vw, 38px);
  }
  .portfolio-intro__text {
    font-size: 13px;
    line-height: 1.7;
  }
  .contact-section {
    padding-left: 24px;
    padding-right: 24px;
  }
  .contact-section h2 {
    font-size: clamp(25px, 7vw, 38px);
    overflow-wrap: break-word;
  }
  .contact-links a {
    font-size: clamp(15px, 4.4vw, 21px);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  footer {
    padding-left: 22px;
    padding-right: 22px;
  }
  footer p {
    font-size: 11px;
    line-height: 1.65;
  }
  /* Design project index: compact tappable rows rather than oversized hover images. */
  body:has(.menu) main {
    min-height: 100svh;
    padding: calc(90px + env(safe-area-inset-top)) 20px
      calc(40px + env(safe-area-inset-bottom));
    display: grid;
    place-items: center;
  }
  .menu {
    width: min(100%, 380px);
    padding: 0;
  }
  .menu__item {
    pointer-events: auto;
    width: 100%;
    grid-template-columns: 56px minmax(0, 1fr);
    grid-template-areas: "preview text" "preview sub";
    column-gap: 16px;
    padding: 9px 0;
  }
  .menu__item::before {
    display: none;
  }
  .menu__item-text {
    justify-self: start;
    text-align: left;
  }
  .menu__item-textinner {
    font-size: clamp(18px, 5.2vw, 23px);
    white-space: normal;
    transform: none !important;
  }
  .menu__item-sub {
    justify-self: start;
    text-align: left;
    opacity: 1;
    font-size: 8px;
    padding-top: 3px;
  }
  .menu__item .touch-project-image {
    display: block;
    grid-area: preview;
    width: 56px;
    height: 62px;
    object-fit: cover;
    margin: 0;
    align-self: center;
    pointer-events: auto;
  }
  .hover-reveal {
    display: none !important;
  }
  /* Photo canvas: a full-width focus view with reachable close and zoom controls. */
  .split-screen-container {
    height: 100svh;
  }
  .split-screen-container .split-left {
    width: 100vw;
    height: 100svh;
  }
  .split-screen-container .split-right {
    display: none;
  }
  .zoom-target {
    height: 100%;
    width: 100%;
  }
  .scaling-image-overlay img {
    object-fit: contain;
  }
  .close-button {
    top: calc(76px + env(safe-area-inset-top));
    right: 14px;
    width: 42px;
    height: 42px;
    transform: none;
  }
  .close-button svg {
    width: 28px;
    height: 28px;
  }
  .controls-container,
  .controls-container.split-mode {
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 28px);
    width: max-content;
  }
  .controls-container .switch-button {
    min-height: 42px;
    padding: 8px 13px;
    font-size: 11px !important;
  }
  .page-vignette-extreme {
    background: linear-gradient(to bottom, #ffffff50, transparent 30%);
  }
  /* Fixed horizontal project gallery, sized to a phone viewport. */
  .project-connected .project-frame {
    top: calc(79px + env(safe-area-inset-top));
    left: 6vw;
    right: 6vw;
    padding: 0;
    min-height: 0;
  }
  .project-frame__title {
    font-size: 21px;
  }
  .project-frame__text {
    font-size: 10px;
    line-height: 1.5;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .project-connected .project-gallery-stage {
    top: calc(155px + env(safe-area-inset-top));
    bottom: calc(92px + env(safe-area-inset-bottom));
    height: auto !important;
    touch-action: none;
  }
  .project-connected .connected-grid {
    --project-image-height: calc(
      100svh - 280px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
    gap: 24px;
    padding-left: 6vw;
    padding-right: 6vw;
  }
  .project-composition-column {
    justify-content: center;
    gap: 28px;
  }
  .project-composition-column.is-feature .grid__item-img {
    width: min(86vw, calc(var(--project-image-height) * var(--img-ratio)));
    height: auto !important;
    max-height: none;
    aspect-ratio: var(--img-ratio);
  }
  .project-composition-column.is-pair .grid__item-img {
    width: min(
      66vw,
      calc((var(--project-image-height) - 44px) / 2 * var(--img-ratio))
    );
    height: auto !important;
    aspect-ratio: var(--img-ratio);
  }
  .project-composition-note {
    width: 125px;
    flex-basis: 125px;
  }
  .project-composition-note h2 {
    font-size: 18px;
  }
  .project-composition-note p {
    font-size: 10px;
    line-height: 1.65;
  }
  .project-dock {
    left: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    bottom: env(safe-area-inset-bottom);
    padding: 12px 14px 18px;
    gap: 2px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .project-dock-item,
  .project-dock-item.is-hover,
  .project-dock-item.is-near,
  .project-dock-item.is-far {
    font-size: 13px;
  }
  .project-dock-item a {
    padding: 12px 10px;
    min-height: 44px;
  }
  .project-dock-item[aria-current] a {
    color: #0048ff;
  }
  .project-dock-preview {
    display: none !important;
  }
}
@media (max-width: 700px) and (max-height: 500px),
  (max-height: 500px) and (max-width: 1000px) and (pointer: coarse) {
  .project-connected .project-frame {
    top: 70px;
  }
  .project-frame__text {
    display: none;
  }
  .project-connected .project-gallery-stage {
    top: 105px;
    bottom: 65px;
  }
  .project-connected .connected-grid {
    --project-image-height: calc(100svh - 200px);
  }
  .project-dock {
    padding-top: 2px;
    padding-bottom: 4px;
  }
  .project-dock-item a {
    min-height: 40px;
  }
  .menu__item .touch-project-image {
    height: 42px;
    width: 44px;
  }
  .menu__item {
    padding: 5px 0;
    grid-template-columns: 44px 1fr;
  }
  .menu__item-textinner {
    font-size: 18px;
  }
}

/* Compact floating navigation on phones. */
@media (max-width: 700px),
  (max-height: 500px) and (max-width: 1000px) and (pointer: coarse) {
  #ui-wrapper,
  #ui-wrapper.sticky-top {
    width: max-content;
    max-width: calc(100vw - 116px);
    left: 50%;
    transform: translateX(-50%);
  }
  #ui-wrapper.sticky-top {
    top: calc(16px + env(safe-area-inset-top));
  }
  #ui {
    width: auto;
    justify-content: center;
    gap: 10px;
    padding: 3px 12px;
    font-size: 10px;
    letter-spacing: 0.025em;
  }
  #ui a {
    min-height: 30px;
    padding: 0 3px;
    letter-spacing: 0.025em;
  }
}
/* Phone layout: long descriptions wrap within the existing compact menu. */
@media (max-width: 700px),
  (max-height: 500px) and (max-width: 1000px) and (pointer: coarse) {
  .menu__item {
    min-width: 0;
  }
  .menu__item-text,
  .menu__item-sub {
    min-width: 0;
    max-width: 100%;
  }
  .menu__item-sub {
    white-space: normal;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }
  .contact-links {
    min-width: 0;
  }
  .contact-links a {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  #ui a {
    position: relative;
  }
  #ui a::after {
    content: "";
    position: absolute;
    inset: -4px -2px;
  }
  .project-dock-item a {
    touch-action: pan-x;
  }
  .project-gallery-stage {
    user-select: none;
    -webkit-user-select: none;
  }
}
@media (max-width: 360px) {
  .project-connected .project-gallery-stage {
    top: calc(170px + env(safe-area-inset-top));
  }
  .project-connected .connected-grid {
    --project-image-height: calc(
      100svh - 295px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
  }
  .project-frame__text {
    -webkit-line-clamp: 3;
    font-size: 9px;
    line-height: 1.45;
  }
  .controls-container .switch-button {
    padding-left: 10px;
    padding-right: 10px;
  }
}

@media (max-width: 700px),
  (max-height: 500px) and (max-width: 1000px) and (pointer: coarse) {
  .menu__item {
    grid-template-rows: auto auto;
  }
  .menu__item-sub {
    position: static;
    left: auto;
    top: auto;
    width: auto;
    margin: 0;
    transform: none;
  }
}
