/* Keep the photographic scene and every SVG in exactly the same frame.
   On phones the themes switch exclusively, without two composited photos. */
@media (max-width: 650px) {
  main {
    --scene-width: 1100px;
    --scene-top: 160px;
    /* Keep the native crop on phones, but cover the right edge up to 650px. */
    --scene-left: max(calc(50% - 820px), calc(100% - 1098px));
    --sky-left: #233c85;
    --sky-right: #233d87;
    --sky-entry: linear-gradient(to bottom, transparent 0, #000 74px, #000 100%);
    height: 690px;
    isolation: isolate;
  }
  html[data-theme="day"] main { --sky-left: #82c2fb; --sky-right: #88c5fb; }
  /* Continue the source artwork's sky behind the navigation and identity.
     The colours are sampled from the actual cropped PNG top edge. */
  main::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 350px;
    z-index: -1;
    pointer-events: none;
    background: linear-gradient(90deg, var(--sky-left), var(--sky-right));
  }
  main > .scene-image,
  main > .overlay,
  main > .valley-fog,
  main > .laptop-screen,
  main > .sky-details,
  main > .scene-interactions,
  main::after {
    position: absolute;
    inset: var(--scene-top) auto auto var(--scene-left);
    width: var(--scene-width);
    height: auto;
    max-width: none;
    aspect-ratio: 1487 / 1058;
    box-sizing: border-box;
  }
  main > .scene-evening { display: block; }
  main > .day { display: none; transition: none; }
  html[data-theme="day"] main > .scene-evening { display: none; }
  html[data-theme="day"] main > .day { display: block; opacity: 1; }
  html[data-theme="evening"] main > .day { display: none; }
  main > .scene-image {
    -webkit-mask-image: var(--landscape-feather), var(--sky-entry);
    mask-image: var(--landscape-feather), var(--sky-entry);
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
  }
  html[data-theme="day"] main::after {
    /* The text wash must also fade in; otherwise it recreates a top seam. */
    -webkit-mask-image: var(--landscape-feather), linear-gradient(to bottom, transparent 0, #000 74px, #000 31%, transparent 53%);
    mask-image: var(--landscape-feather), linear-gradient(to bottom, transparent 0, #000 74px, #000 31%, transparent 53%);
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
  }
  main > .night-sky { top: 0; }

  .site-header { gap: 12px; padding-top: 8px; padding-bottom: 8px; }
  .primary-nav { gap: clamp(10px, 3.3vw, 16px); }
  .primary-nav a { min-height: 44px; padding: 0 2px; font-size: 12px; }
  .site-header .scene-controls button { position: relative; display: block; box-sizing: border-box; width: 44px; height: 44px; min-height: 44px; padding: 0; font-size: 0; }
  html[data-theme] .site-header .scene-controls button { border: 0; border-radius: 3px; background: transparent; box-shadow: none; color: var(--nav-ink); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .site-header .scene-controls { position: relative; padding-left: 8px; }
  .site-header .scene-controls::before { content: ""; position: absolute; left: 0; top: 50%; width: 1px; height: 16px; transform: translateY(-50%); background: var(--nav-ink); opacity: .22; }
  .scene-controls button::before { content: ""; position: absolute; left: 50%; top: 50%; width: 19px; height: 19px; transform: translate(-50%, -50%); background: currentColor; -webkit-mask: var(--theme-icon) center / contain no-repeat; mask: var(--theme-icon) center / contain no-repeat; }
  .scene-controls button { --theme-icon: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%221.6%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M20.985%2012.486A9%209%200%201%201%2011.51%203.01a7%207%200%200%200%209.475%209.475Z%22%2F%3E%3C%2Fsvg%3E"); }
  html[data-theme="day"] .scene-controls button { --theme-icon: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%221.6%22%20stroke-linecap%3D%22round%22%3E%3Ccircle%20cx%3D%2212%22%20cy%3D%2212%22%20r%3D%224%22%2F%3E%3Cpath%20d%3D%22M12%202v2m0%2016v2M2%2012h2m16%200h2M4.93%204.93l1.42%201.42m11.3%2011.3%201.42%201.42M4.93%2019.07l1.42-1.42m11.3-11.3%201.42-1.42%22%2F%3E%3C%2Fsvg%3E"); }
  .identity, .hero-copy, .about-copy, .contact-bottom { min-width: 0; }
  .hero-copy h1 { min-width: 0; }
  .hero-actions { column-gap: 21px; row-gap: 12px; }
  .hero-actions .work-link, .hero-actions .linkedin-link { min-height: 44px; box-sizing: border-box; }
  .selected-work, .page-section, .page-footer { overflow-wrap: break-word; }
  .project-heading h3 { overflow-wrap: anywhere; }
  .project-preview, .preview-coinhub { aspect-ratio: 1.35; padding: 16px 16px 36px; }
  .screenshot-label { left: 16px; bottom: 12px; }
  .project-details summary { min-height: 48px; box-sizing: border-box; }
  .work-filters { column-gap: 18px; row-gap: 4px; }
  .story-steps p { font-size: 14px; line-height: 1.65; }
  .story-steps .story-panel { max-width: 100%; }
  .map-branches > span { min-width: 0; }
  .page-footer { flex-wrap: wrap; row-gap: 10px; }
}
@media (max-width: 359px) {
  .primary-nav { gap: 9px; }
  .primary-nav a { font-size: 11px; }
  .hero-copy h1 { font-size: 29px; }
  .identity { gap: 11px; }
}
