/*
 * LOOP Food — iPhone / Safari stability layer
 *
 * This file intentionally loads last. It is not a second visual direction:
 * it resolves two reproducible mobile faults in the existing composition:
 * Safari text autosizing against absolute hero slots, and touch landscape
 * falling through to the short-desktop scene.
 */

:root {
  --loop-safe-top: env(safe-area-inset-top, 0px);
  --loop-safe-right: env(safe-area-inset-right, 0px);
  --loop-safe-bottom: env(safe-area-inset-bottom, 0px);
  --loop-safe-left: env(safe-area-inset-left, 0px);
  --loop-header-offset: calc(var(--v4-header, 4.5rem) + var(--loop-safe-top));
}

/* Keep touch targets fully reachable at narrow and square viewport edges. */
@media (min-width: 24.01rem) and (max-width: 43.75rem) and (max-height: 42rem) {
  .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="1"] .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="2"] .hero__robot.r-robot-reference-zone {
    right: 5% !important;
    left: auto !important;
    width: 42% !important;
  }
}

@media (max-width: 18rem) and (min-height: 42.0625rem) and (orientation: portrait) {
  .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="1"] .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="2"] .hero__robot.r-robot-reference-zone {
    right: 5% !important;
    left: auto !important;
    width: 42% !important;
  }
}

@media (min-width: 45rem) and (max-width: 49rem) and (max-height: 48rem) {
  .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="1"] .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="2"] .hero__robot.r-robot-reference-zone {
    right: 5% !important;
    left: auto !important;
    width: 40% !important;
  }

  .hero__signal-card {
    display: none !important;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 42rem) {
  .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="1"] .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="2"] .hero__robot.r-robot-reference-zone {
    right: 5% !important;
    left: auto !important;
    width: 42% !important;
  }
}

html,
body {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@media (max-width: 53.75rem) {
  .site-header.r-hero-navigation {
    height: var(--loop-header-offset);
    padding-top: var(--loop-safe-top);
  }

  .site-header__bar {
    height: var(--v4-header);
    padding-right: max(var(--v4-gutter), var(--loop-safe-right));
    padding-left: max(var(--v4-gutter), var(--loop-safe-left));
  }

  .primary-nav.is-open {
    top: var(--loop-header-offset);
    max-height: calc(100dvh - var(--loop-header-offset));
    padding-right: max(var(--v4-gutter), var(--loop-safe-right));
    padding-left: max(var(--v4-gutter), var(--loop-safe-left));
  }

  .hero__copy.r-hero-copy {
    top: calc(var(--loop-header-offset) + 1.55rem);
  }

  /* The former height-driven rig exceeded its button by up to 12px after a
     tap. Make the narrow touch stage width-driven so head, neck and torso
     share one bounded coordinate system. */
  .hero__robot.r-robot-reference-zone .robot-rig {
    width: 100%;
    height: auto;
    min-width: 0;
    max-width: 100%;
    max-height: 100%;
    align-self: end;
  }

  /* Mobile is recomposed: copy owns the upper third; the chef begins after
     the lede instead of moving beneath it. */
  .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="1"] .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="2"] .hero__robot.r-robot-reference-zone {
    top: 44.5%;
    left: 43%;
    width: 53%;
    height: 39%;
  }

  .hero__copy.r-hero-copy,
  .hero__actions.r-hero-actions,
  .hero__tickets {
    isolation: isolate;
  }
}

/* A phone in landscape can be wider than the nominal mobile breakpoint.
   Target touch capability as well as height so it never falls into the
   short-desktop hero that has a 34rem minimum height. */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 42rem) {
  :root {
    --v4-header: 3.75rem;
  }

  .site-header.r-hero-navigation {
    height: var(--loop-header-offset);
    padding-top: var(--loop-safe-top);
  }

  .site-header__bar {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: .45rem;
    height: var(--v4-header);
    padding-right: max(1rem, var(--loop-safe-right));
    padding-left: max(1rem, var(--loop-safe-left));
  }

  .primary-nav {
    display: none;
  }

  .primary-nav.is-open {
    position: fixed;
    top: var(--loop-header-offset);
    right: 0;
    left: 0;
    display: flex;
    max-height: calc(100dvh - var(--loop-header-offset));
    align-items: stretch;
    flex-direction: column;
    gap: 0;
    padding: .5rem max(1rem, var(--loop-safe-right)) .75rem max(1rem, var(--loop-safe-left));
    overflow-y: auto;
    border-bottom: var(--v4-rule);
    color: var(--v4-ink);
    background: var(--v4-cream);
  }

  .primary-nav.is-open a {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    border-bottom: 1px solid rgba(17, 16, 13, .18);
  }

  .menu-toggle {
    display: inline-flex;
  }

  .motion-toggle {
    min-height: 2.55rem;
    padding-inline: .72rem;
    font-size: .62rem;
  }

  .header-cta {
    min-height: 2.55rem;
    padding-inline: .9rem;
  }

  .hero.comp-frame {
    height: 100svh;
    min-height: 0;
  }

  .hero__copy.r-hero-copy {
    top: calc(var(--loop-header-offset) + .5rem);
    right: auto;
    left: max(1rem, var(--loop-safe-left));
    width: 45%;
  }

  .hero .eyebrow {
    margin-bottom: .38rem;
    font-size: .55rem;
    line-height: 1.2;
  }

  .hero .eyebrow span {
    padding: .24rem .42rem;
  }

  .hero h1 {
    max-width: 8ch;
    font-size: clamp(2.25rem, 5vw, 3rem);
    line-height: .88;
  }

  .hero__lede {
    max-width: 34ch;
    margin-top: .4rem;
    font-size: .75rem;
    line-height: 1.34;
  }

  .hero__tickets,
  .hero__pizza.r-hero-pizza,
  .hero__state,
  .hero__state.hero__state--direct {
    display: none;
  }

  .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="1"] .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="2"] .hero__robot.r-robot-reference-zone {
    top: calc(var(--loop-header-offset) + 1rem);
    left: 56%;
    width: 36%;
    height: calc(100% - var(--loop-header-offset) - 1.5rem);
  }

  .hero__robot.r-robot-reference-zone .robot-rig {
    width: auto;
    height: 100%;
    min-width: 0;
    max-width: 100%;
    max-height: 100%;
  }

  .hero__actions.r-hero-actions {
    top: auto;
    right: auto;
    bottom: max(.55rem, var(--loop-safe-bottom));
    left: max(1rem, var(--loop-safe-left));
    width: 44%;
  }

  .hero__cta-row {
    display: block;
  }

  .hero .primary-cta {
    min-height: 2.55rem;
    padding-inline: .85rem;
    font-size: .62rem;
  }

  .hero .text-link,
  .hero__touch-hint {
    display: none;
  }
}

/* The journey stage is sticky on a phone. Reserve a real third grid row for
   its disclosure instead of letting the footnote sit over the final rail stop
   when Safari's visible viewport is shortened by browser chrome. */
@media (max-width: 48rem) {
  /* Six journey stops and their explanatory text need more than a short
     Safari viewport can provide. This is a mobile reading sequence, not a
     shrunken pin: retaining the desktop pin makes the rail overflow into the
     disclosure below it. */
  .chapter-v4-ready .journey-section {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .chapter-v4-ready .journey-stage-v4 {
    position: relative;
    top: auto;
    height: auto;
    min-height: 0;
    padding: calc(var(--world-header-h) + .75rem) var(--world-gutter) 2rem;
    overflow: visible;
    grid-template-rows: auto minmax(0, 1fr) auto;
    row-gap: .7rem;
  }

  .chapter-v4-ready .journey-theatre {
    grid-row: 2;
    min-height: 0;
  }

  .chapter-v4-ready .journey-section .scene-footnote {
    position: static;
    z-index: 7;
    grid-row: 3;
    align-self: end;
    margin: 0;
    padding-top: .5rem;
    font-size: .66rem;
    line-height: 1.35;
  }
}

/* Phone reflow + readable labels. The previous display-size floor forced
   “experiência” outside its column at 390px and became worse at 320px. */
@media (max-width: 43.75rem) {
  .method-section .method-beat h3 {
    max-width: 100%;
    font-size: clamp(1.7rem, 9vw, 2.45rem) !important;
    line-height: 1.04;
    overflow-wrap: normal;
  }

  .hero__touch-hint,
  .journey-ticket__brand,
  .chapter-v4-ready .channel__type,
  .chapter-v4-ready .chapter-ticket-v4 > span,
  .chapter-v4-ready .chapter-ticket-v4 > small,
  .chapter-v4-ready .channel-hub-v4 span,
  .chapter-v4-ready .journey-section .scene-footnote,
  .scene-intro__signals strong {
    font-size: .7rem !important;
  }

  .journey-ticket__brand {
    letter-spacing: .08em;
  }

  .chapter-v4-ready .chapter-ticket-v4__kicker {
    max-width: 100%;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  .chapter-v4-ready .channel-hub-v4__type {
    max-width: 100%;
    letter-spacing: .06em;
  }
}

/* Keep all three compact header controls inside the narrowest iPhone layout. */
@media (max-width: 27rem) {
  .header-actions .header-cta {
    width: 2.75rem;
    min-width: 2.75rem;
    padding-inline: 0;
    justify-content: center;
    color: var(--v4-cream);
    background: var(--v4-ink);
  }

  .header-actions .header-cta span {
    display: none;
  }

  .header-actions .header-cta svg {
    display: block;
    flex: 0 0 1rem;
  }
}

/* A short, narrow portrait needs a split hero: keep copy in a left column,
   chef to its right, and the primary action in its own visible row. This
   prevents the character from covering the lede on 375×667 phones. */
@media (max-width: 25rem) and (max-height: 44rem) and (orientation: portrait) {
  .hero.comp-frame {
    height: max(100svh, 35rem) !important;
    min-height: 35rem !important;
  }

  .hero__copy.r-hero-copy {
    top: calc(var(--loop-header-offset) + 1rem) !important;
    right: auto !important;
    left: max(1rem, var(--loop-safe-left)) !important;
    width: 52% !important;
  }

  .hero h1 {
    max-width: 100% !important;
    font-size: clamp(1.85rem, 9.8vw, 2.15rem) !important;
    line-height: .94 !important;
  }

  .hero__lede {
    max-width: 100% !important;
    margin-top: .55rem !important;
    font-size: .78rem !important;
    line-height: 1.35 !important;
  }

  .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="1"] .hero__robot.r-robot-reference-zone,
  .hero[data-hero-state="2"] .hero__robot.r-robot-reference-zone {
    top: 34% !important;
    left: 59% !important;
    width: 39% !important;
    height: 42% !important;
  }

  .hero__actions.r-hero-actions {
    top: auto !important;
    right: max(1rem, var(--loop-safe-right)) !important;
    bottom: max(1rem, var(--loop-safe-bottom)) !important;
    left: max(1rem, var(--loop-safe-left)) !important;
    width: auto !important;
  }

  .hero__cta-row {
    display: block !important;
  }

  .hero .primary-cta {
    width: 100% !important;
    justify-content: space-between !important;
    font-size: .78rem !important;
  }

  .hero .text-link,
  .hero__touch-hint {
    display: none !important;
  }
}

/* Mobile reading pass: keep the editorial display voice, but stop compressed
   line boxes and outlined glyphs from colliding at phone widths. */
@media (max-width: 43.75rem) {
  .scene-intro h2,
  .journey-heading h2,
  .channels-heading h2,
  .operations-heading h2,
  .return-section h2,
  .food-film__copy h2,
  .diagnostic-copy h2,
  .diagnostic-output__heading h2,
  .chapter-v4-ready .control-deck__intro h3 {
    max-width: 100%;
    font-size: clamp(2.05rem, 9.6vw, 3.15rem);
    line-height: 1.04;
    letter-spacing: -.035em;
    overflow-wrap: normal;
    word-break: normal;
    text-wrap: balance;
  }

  .scene-intro h2 em,
  .journey-heading h2 em,
  .channels-heading h2 em,
  .operations-heading h2 em,
  .return-section h2 em,
  .food-film__copy h2 em,
  .diagnostic-copy h2 em,
  .diagnostic-output__heading h2 em {
    -webkit-text-fill-color: currentColor;
    -webkit-text-stroke: 0;
  }

  .hero h1 {
    line-height: .98;
  }

  .food-universe__masthead {
    top: 14%;
    width: 88%;
  }

  .food-universe__masthead h2 {
    max-width: 100%;
    font-size: clamp(2.05rem, 9.6vw, 3.05rem);
    line-height: 1.02;
    letter-spacing: -.035em;
    text-wrap: balance;
  }

  .food-universe__masthead h2 em {
    color: var(--food-world-ink);
    -webkit-text-fill-color: currentColor;
    -webkit-text-stroke: 0;
  }

  .food-universe__orbit {
    width: min(46vw, 17rem);
    opacity: .42;
  }

  .food-story h3 {
    max-width: 100%;
    font-size: clamp(1.85rem, 7.8vw, 2.45rem);
    line-height: 1.05;
    letter-spacing: -.035em;
    text-wrap: balance;
  }

  .section-kicker,
  .food-universe__topline .section-kicker,
  .food-universe__topline > span,
  .food-story > p,
  .chapter-v4-ready .control-deck__intro > p:first-child {
    letter-spacing: .075em;
    line-height: 1.4;
  }

  .scene-intro,
  .journey-section,
  .channels-section,
  .operations-section,
  .diagnostic-output-section,
  .return-section,
  .diagnostic-section {
    padding-block: clamp(3.5rem, 8vh, 4.5rem);
  }

  .journey-heading,
  .channels-heading,
  .operations-heading {
    gap: .8rem;
    margin-bottom: 2rem;
  }
}

/* A short portrait phone still gets the food scroll-story: one dish, one
   active chapter, and its copy in a single bounded viewport. */
@media (max-width: 43.75rem) {
  /* Keep the large decorative wordmark from reducing food-story legibility. */
  .food-universe__sticky::after {
    display: none;
  }
}

@media (orientation: portrait) and (max-width: 43.75rem) and (max-height: 42rem) {
  html[data-motion="full"] .food-universe {
    height: 360svh !important;
    min-height: 0 !important;
  }

  html[data-motion="full"] .food-universe__sticky {
    position: sticky !important;
    top: 0 !important;
    display: block !important;
    height: 100svh !important;
    min-height: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  html[data-motion="full"] .food-universe__topline {
    position: absolute !important;
    top: calc(var(--loop-header-offset) + .55rem) !important;
    right: var(--v4-gutter) !important;
    left: var(--v4-gutter) !important;
    width: auto !important;
    padding-bottom: .45rem !important;
  }

  html[data-motion="full"] .food-universe__masthead {
    position: absolute !important;
    top: calc(var(--loop-header-offset) + 3.2rem) !important;
    right: var(--v4-gutter) !important;
    left: var(--v4-gutter) !important;
    width: auto !important;
  }

  html[data-motion="full"] .food-universe__masthead h2 {
    max-width: 100% !important;
    font-size: clamp(2rem, 9vw, 2.4rem) !important;
    line-height: 1.02 !important;
    letter-spacing: -.035em !important;
  }

  html[data-motion="full"] .food-universe__plate {
    position: absolute !important;
    top: 38svh !important;
    right: auto !important;
    bottom: auto !important;
    left: 50% !important;
    width: min(60vw, 14rem) !important;
    height: clamp(10rem, 31svh, 12.25rem) !important;
    margin: 0 !important;
    transform: translateX(-50%) !important;
  }

  html[data-motion="full"] .food-universe__orbit {
    width: min(58vw, 12rem) !important;
    opacity: .24 !important;
  }

  html[data-motion="full"] .food-universe__plate figcaption {
    display: none !important;
  }

  html[data-motion="full"] .food-universe__copy {
    position: absolute !important;
    top: auto !important;
    right: var(--v4-gutter) !important;
    bottom: .85rem !important;
    left: var(--v4-gutter) !important;
    width: auto !important;
    height: min(9.4rem, 27svh) !important;
    min-height: 0 !important;
  }

  html[data-motion="full"] .food-story,
  html[data-motion="full"] .food-story.is-active {
    position: absolute !important;
    inset: 0 !important;
    display: flex !important;
    min-height: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    flex-direction: column !important;
    justify-content: flex-end !important;
    transform: translate3d(0, .75rem, 0) !important;
  }

  html[data-motion="full"] .food-story {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  html[data-motion="full"] .food-story.is-active {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: none !important;
  }

  html[data-motion="full"] .food-story h3 {
    font-size: clamp(1.65rem, 7vw, 1.9rem) !important;
    line-height: 1.04 !important;
  }

  html[data-motion="full"] .food-story > span {
    margin-top: .45rem !important;
    font-size: .82rem !important;
    line-height: 1.35 !important;
  }

  html[data-motion="full"] .food-universe__nav {
    position: absolute !important;
    top: 38svh !important;
    right: .35rem !important;
    bottom: auto !important;
    left: auto !important;
    width: 2.8rem !important;
  }

  html[data-motion="full"] .food-universe__nav button {
    min-height: 2.25rem !important;
    padding: .25rem !important;
  }

  html[data-motion="full"] .food-universe__signal {
    display: none !important;
  }
}
