/* The page content is the only scrolling surface on phones. The village is
   painted on the viewport underneath it, outside of that scroll container. */
@media (pointer: coarse), (max-width: 760px) {
  html[data-theme] {
    --scroll-inset: 3px;
    position: relative;
    width: 100%;
    height: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    isolation: isolate;
    overscroll-behavior: none;
  }
  html[data-theme] body[class] {
    box-sizing: border-box;
    /* Android Chrome treats an edge-to-edge scrollport as the document and
       uses its swipes to collapse the address bar. An inset at the top keeps
       native scrolling inside the page, including at fractional screen scales. */
    position: absolute;
    inset: var(--scroll-inset) 0 0;
    width: 100%;
    height: auto;
    min-height: 0;
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: none;
    background: transparent !important;
  }
  html[data-theme] body.glass-interior > :is(header, nav, main, footer) { flex-shrink: 0; }
  html[data-theme] body::before { content: none; }
  /* A top address bar moves the top of the web surface in screen coordinates.
     The lower edge stays put. Keep the original artwork aligned to that edge
     and give it the same scale it has when the address bar is visible. */
  html[data-theme] {
    --village-height: var(--portrait-area, 100svh);
    --village-image: url("/assets/teracota-mobil-v123.webp");
    --village-size: 100% var(--village-height);
  }
  html[data-theme][data-mobile-art="landscape"] {
    --village-image: url("/assets/teracota-desktop-v123.webp");
    /* The landscape source is 1536 × 1024, bottom-aligned and cropped to cover. */
    --village-size: auto max(var(--village-height), 66.666667vw);
  }
  html[data-theme]::before,
  html[data-theme]::after {
    content: "";
    position: fixed;
    inset: auto 0 0;
    z-index: -1;
    width: 100%;
    height: var(--village-height);
    pointer-events: none;
    transform: translateZ(0);
    background: var(--terra-canvas, #f8e3ca) var(--village-image) center bottom / var(--village-size) no-repeat;
  }
  html[data-theme="terracotta"]::before,
  html[data-theme="terracotta"]::after {
    background-image: linear-gradient(to bottom, #f9e5cf80, #f9e5cfdc 42px, transparent 116px), var(--village-image);
    background-size: 100% 100%, var(--village-size);
  }
  /* If the browser independently reveals more space above the scene, reflect
     the top edge of the same image there. The houses are always the bottom. */
  html[data-theme]::after {
    bottom: var(--village-height);
    transform: translateZ(0) scaleY(-1);
  }
  html[data-theme="studio"]::before,
  html[data-theme="studio"]::after {
    background-color: #132338;
    background-blend-mode: soft-light;
  }

  html[data-theme="studio"] body.creator-page > .site-backdrop { display: none; }

  /* Short phones may scroll Home as well. The footer belongs to the bottom
     of the scene, even if the scene is taller than the visible area. */
  html[data-theme] body.cinematic-home {
    display: grid;
    grid-template: "scene" minmax(min-content, 1fr) / minmax(0, 1fr);
  }
  html[data-theme] body.cinematic-home > main { grid-area: scene; }
  html[data-theme="terracotta"] body.home-page .cinema-stage {
    height: calc(100svh - var(--scroll-inset));
  }
  html[data-theme] body.cinematic-home > .compact-footer {
    grid-area: scene;
    position: relative;
    align-self: end;
    bottom: auto;
    margin-block-end: 4px;
  }
}

/* Size the home portrait against its pinned layer, including its crop when
   the phone turns. Only foreground content follows the available page height. */
html[data-mobile-art][data-theme="terracotta"] body.home-page > .site-backdrop {
  container: portrait-art / size;
  inset: auto 0 0;
  height: var(--portrait-area);
  min-height: 0;
}
html[data-mobile-art][data-theme="terracotta"] body.home-page .site-backdrop .backdrop-sharp {
  inset: 0;
  width: 100%;
  height: 100%;
  transform: none;
  background-position: center -6cqh;
  background-size: auto 105%;
  -webkit-mask-image: linear-gradient(black 0 35%, transparent 55%);
  mask-image: linear-gradient(black 0 35%, transparent 55%);
}
@container portrait-art (orientation: landscape) or (min-width: 1000px) {
  html[data-mobile-art][data-theme="terracotta"] body.home-page .site-backdrop .backdrop-sharp {
    inset: 0 auto auto 50%;
    width: min(57cqh, 50cqw);
    height: 44cqh;
    transform: translateX(-56%);
    background-size: 100% auto;
    background-position: center max(-15cqh, -13.2cqw);
    -webkit-mask-image: linear-gradient(to right, transparent, black 9% 92%, transparent), linear-gradient(black 0 68%, transparent 100%);
    mask-image: linear-gradient(to right, transparent, black 9% 92%, transparent), linear-gradient(black 0 68%, transparent 100%);
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
  }
}
@container portrait-art (orientation: landscape) and (max-height: 650px) {
  html[data-mobile-art][data-theme="terracotta"] body.home-page .site-backdrop .backdrop-sharp {
    width: min(51cqh, 48cqw);
    height: 38cqh;
  }
}
@container portrait-art (orientation: landscape) and (max-height: 550px) {
  html[data-mobile-art][data-theme="terracotta"] body.home-page .site-backdrop .backdrop-sharp {
    width: min(49cqh, 36cqw);
    height: 35cqh;
    background-position: center -15cqh;
  }
}
@container portrait-art (orientation: landscape) and (max-height: 350px) {
  html[data-mobile-art][data-theme="terracotta"] body.home-page .site-backdrop .backdrop-sharp { height: 31cqh; }
}

/* Keep the focus ring and pointer target in place while a social icon lifts. */
@media (prefers-reduced-motion: no-preference) {
  .home-community .community-mark,
  .site-header .header-actions .header-music > :is(svg, img),
  .media-platforms .hub-link .hub-icon {
    transition: translate 150ms ease-out, scale 100ms ease-out,
                box-shadow 180ms ease, border-color 180ms ease;
  }
  .home-community .community-link:focus-visible .community-mark,
  .site-header .header-actions .header-music:focus-visible > :is(svg, img),
  .media-platforms .hub-link:focus-visible .hub-icon {
    translate: 0 -2px;
  }
  /* Creator's stylesheet already lifts the entire circle on mouse hover. */
  body.creator-page .creator-socials .social-icon-link:focus-visible {
    transform: translateY(-2px);
  }
  @media (hover: hover) and (pointer: fine) {
    .home-community .community-link:hover .community-mark,
    .site-header .header-actions .header-music:hover > :is(svg, img),
    .media-platforms .hub-link:hover .hub-icon {
      translate: 0 -2px;
    }
  }
  .home-community .community-link:active .community-mark,
  .site-header .header-actions .header-music:active > :is(svg, img),
  .media-platforms .hub-link:active .hub-icon {
    translate: 0;
    scale: .96;
  }
  /* The icon provides the header press feedback inside its stationary disc. */
  html body .site-header .header-actions a.header-music:active { transform: none; }

  html body :is(.header-personalized, .header-home-return, .creator-contact,
                .atelier-tabs button, .atelier-live, .atelier-whatsapp,
                .atelier-examples-trigger, .carousel-arrow, .sample-controls .button) {
    transition: scale 110ms ease-out, background-color 180ms ease,
                border-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
  }
  html body :is(.header-personalized, .header-home-return, .creator-contact,
                .atelier-tabs button, .atelier-live, .atelier-whatsapp,
                .atelier-examples-trigger, .carousel-arrow, .sample-controls .button):not(:disabled, [aria-disabled="true"]):active {
    scale: .975;
    transition-duration: 65ms;
  }
  html body .site-header .header-actions a.header-personalized:active { transform: none; }
}
