
/* Always clip intentional bleed (hero/mq) so scrollWidth stays clean */
.name-window,
.mast,
.mq,
.tile,
.oficio-grid,
.hero-track {
  max-width: 100%;
}
.name-window,
.mast,
.mq,
.tile {
  overflow: hidden;
}
.html-clip-fix {}
html, body {
  overflow-x: clip;
  max-width: 100vw;
}
/* Mobile polish — additive; desktop untouched above 800px / fine pointer */

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

body {
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.bar {
  top: var(--window);
  padding-left: max(var(--pad), env(safe-area-inset-left, 0px));
  padding-right: max(var(--pad), env(safe-area-inset-right, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  min-height: var(--hdr);
}

.name-window {
  padding-top: max(2px, env(safe-area-inset-top, 0px));
}

.menu {
  padding-top: max(28px, env(safe-area-inset-top, 0px));
  padding-bottom: max(48px, env(safe-area-inset-bottom, 0px));
  padding-left: max(var(--pad), env(safe-area-inset-left, 0px));
  padding-right: max(var(--pad), env(safe-area-inset-right, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.menu nav a {
  min-height: 48px;
  display: flex;
  align-items: center;
}

.text-btn,
.bar-menu,
.flip-hit,
.links a,
.contact-actions a,
.menu-top .text-btn {
  touch-action: manipulation;
}

.js .face {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Coarse / touch: drop GPU-heavy will-change and sticky stack thrash helpers */
@media (pointer: coarse), (hover: none) {
  .hero-track,
  .plate {
    will-change: auto !important;
  }

  .js .flip-inner {
    transition-duration: .55s;
  }

  /* Pause marquees by default on touch — less jank; user can still read */
  .mq-track {
    animation-play-state: paused;
  }

  .tile:focus-within .mq-track,
  .mq:focus-within .mq-track {
    animation-play-state: running;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mq-track {
    animation: none !important;
  }
  .hero-track {
    transform: none !important;
  }
  .js .plate {
    transform: none !important;
  }
}

/* Narrow phones */
@media (width <= 800px) {
  :root {
    --hdr: 52px;
    --mast: min(148px, 22vw);
    --window: max(48px, env(safe-area-inset-top, 0px) + 40px);
    --pad: max(16px, env(safe-area-inset-left, 0px));
  }

  /* Prefer dynamic viewport to avoid iOS 100svh jump */
  .js .sheet {
    height: calc(100svh - var(--window) - var(--hdr));
    height: calc(100dvh - var(--window) - var(--hdr));
    max-height: calc(100dvh - var(--window) - var(--hdr));
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
    contain: layout paint;
  }

  .stage {
    padding-left: max(var(--pad), env(safe-area-inset-left, 0px));
    padding-right: max(var(--pad), env(safe-area-inset-right, 0px));
  }

  .hero-track {
    font-size: clamp(64px, 22vw, 112px);
    margin-left: -0.18em;
  }

  .face-title {
    font-size: clamp(36px, 11vw, 52px);
    word-break: break-word;
  }

  .cifra {
    font-size: clamp(56px, 16vw, 96px);
  }

  .js .shot-main {
    height: min(220px, 38vw + 80px);
  }

  .portrait {
    height: min(46svh, 420px);
    min-height: 220px;
  }

  .line,
  .lede,
  .detalle,
  .cifra-text {
    overflow-wrap: anywhere;
  }

  .tech li {
    padding: 8px 12px;
    min-height: 36px;
  }

  .colo-name {
    font-size: clamp(48px, 14vw, 120px);
    overflow-wrap: anywhere;
  }

  .sec-head.is-contact h2 {
    font-size: clamp(40px, 12vw, 72px);
  }

  /* Flip faces: allow natural scroll length on very small screens instead of clipped sticky hell */
  .js .face {
    overscroll-behavior: contain;
  }
}

/* iPhone SE / very small */
@media (width <= 380px) {
  :root {
    --mast: 120px;
    --window: 48px;
  }

  body {
    font-size: 15.5px;
  }

  .role {
    font-size: clamp(44px, 12.5vw, 56px);
  }

  .js .shot-main {
    height: 180px;
    margin: 10px 10px 0;
  }

  .face-copy,
  .face-back {
    padding: 16px 14px;
  }

  .stk-soc,
  .stk-a11y {
    width: 64px;
    height: 64px;
    font-size: 11px;
  }

  .mark {
    font-size: 24px;
  }
}

/* Landscape phones — short height only; do not dismantle flip 3D */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  :root {
    --mast: 64px;
    --window: 36px;
    --hdr: 44px;
  }

  .name-window,
  .mast {
    overflow: hidden;
  }

  .stickers-top {
    display: none;
  }

  .stage {
    grid-template-columns: minmax(100px, 0.7fr) 1.3fr;
    gap: 12px 16px;
    height: auto;
    min-height: calc(100dvh - var(--mast) - var(--hdr));
    padding-bottom: 12px;
  }

  .portrait {
    height: auto;
    min-height: 0;
    max-height: calc(100dvh - var(--mast) - var(--hdr) - 20px);
  }

  .portrait img {
    max-width: 100%;
    height: auto;
    max-height: calc(100dvh - var(--mast) - var(--hdr) - 20px);
    object-fit: cover;
  }

  .js .sheet {
    height: auto;
    min-height: calc(100dvh - var(--window) - var(--hdr));
    max-height: none;
    position: relative;
    top: auto;
  }

  .js .flip {
    min-height: 60dvh;
  }

  .role {
    font-size: clamp(28px, 7vw, 48px);
  }

  .lede {
    font-size: 14px;
  }
}

/* Tablet portrait polish */
@media (width >= 700px) and (width <= 980px) {
  .js .face-front {
    grid-template-columns: minmax(0, 1fr) minmax(200px, 1fr);
  }

  .face-title {
    font-size: clamp(44px, 6vw, 68px);
  }
}

/* Low-power / save-data: kill decorative motion */
@media (prefers-reduced-motion: reduce), (update: slow) {
  .mq-track {
    animation: none !important;
  }
}

/* Tap targets on sticky bar */
@media (width <= 800px) {
  .bar-menu,
  .bar .text-btn,
  .bar-mail {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    padding: 8px 4px;
  }

  .mark {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .rail a {
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .email-xl {
    font-size: clamp(22px, 7.2vw, 40px);
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .contact-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 18px;
  }

  .contact-actions a,
  .contact-actions .text-btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .links a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 6px 0;
  }

  /* Flip hit area — keep invisible but large enough */
  .js .flip-hit {
    min-height: 48px;
  }

  /* Reduce sticky stack paint cost */
  .js .sheet {
    will-change: auto;
  }

  .plate {
    will-change: auto;
  }
}

/* Phone landscape short height — SE landscape 667x375 */
@media (max-width: 900px) and (max-height: 450px) and (orientation: landscape) {
  :root {
    --mast: 56px;
    --window: 36px;
    --hdr: 44px;
  }

  .name-window,
  .mast {
    max-height: var(--mast);
  }

  .stickers-top,
  .stickers-bot {
    display: none;
  }

  .stage {
    grid-template-columns: 120px 1fr;
    gap: 12px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .portrait {
    max-height: calc(100dvh - var(--mast) - var(--hdr) - 16px);
  }

  .role {
    font-size: clamp(28px, 8vw, 48px);
  }

  .lede {
    font-size: 14px;
  }
}

/* Dialog menu: safe area + larger close */
.menu::backdrop {
  background: rgba(20, 16, 12, 0.35);
}

.menu .menu-top {
  position: sticky;
  top: 0;
  background: inherit;
  padding-bottom: 8px;
  z-index: 1;
}

.menu .text-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 8px;
}

/* Prevent iOS tap highlight flash on chrome controls */
.text-btn,
.bar-menu,
.flip-hit,
.rail a {
  -webkit-tap-highlight-color: transparent;
}


/* Desktop hero: restore original viewport-tall stage so the photo stays
   proportional (like the user's screenshot). Circle + headline are normal
   flow / absolute-in-portrait — they scroll 1:1 with the page (no sticky,
   no parallax). overflow:visible so a short window can reveal "e IA" as the
   stage scrolls up instead of hard-clipping it forever. */
@media (width > 800px) {
  .stage {
    height: calc(100svh - var(--mast) - var(--hdr));
    min-height: calc(100svh - var(--mast) - var(--hdr));
    max-height: none;
    overflow: visible;
    align-items: stretch;
  }

  .portrait {
    height: 100%;
    max-height: calc(100svh - var(--mast) - var(--hdr));
    min-height: 0;
    align-self: stretch;
  }

  .portrait img {
    height: 100%;
    width: auto;
    max-width: 74%;
    object-fit: cover;
  }

  .stage-copy {
    height: 100%;
    max-height: calc(100svh - var(--mast) - var(--hdr));
    min-height: 0;
    justify-content: space-between;
  }

  .role,
  .role-block {
    transform: none !important;
    will-change: auto;
  }

  /* Rail: below mast+bar; stage gets a right gutter so SOC never sits under it. */
  .rail {
    top: calc(var(--mast) + var(--hdr) + 14px);
    bottom: auto;
    right: 12px;
    transform: none;
    align-content: start;
  }
}

/* Reserve rail gutter + show rail only on roomy desktops */
@media (width > 1280px) and (min-height: 721px) {
  .stage {
    padding-right: calc(var(--pad) + 48px);
  }
}

@media (width > 800px) and (max-height: 720px),
       (width > 800px) and (max-width: 1280px) {
  .rail {
    display: none !important;
  }
}

/* Tiny desktop windows: keep photo from dominating; tighten stage copy a bit */
@media (width > 800px) and (max-height: 560px) {
  .portrait {
    max-height: calc(100svh - var(--mast) - var(--hdr));
  }

  .portrait img {
    max-width: 68%;
  }

  .lede,
  .stage-mail {
    display: none;
  }
}

/* Disc parallax: keep headline (stage-copy) above the rising circle */
@media (width > 800px) {
  .portrait { z-index: 1; }
  .disc { z-index: 0; }
  .stage-copy, .role, .role-block { z-index: 2; position: relative; }
}

/* Let the disc rise out of the portrait without clipping */
@media (width > 800px) {
  .portrait { overflow: visible; }
}

/* Headline fit: size the black role from remaining hero height so all 3 lines
   ("e IA") clear the fold. Marquee, photo, disc parallax, and badges unchanged. */
@media (width > 800px) {
  .role {
    /* 2.7 ≈ 3 lines at line-height 0.88 + small slack; 150px reserved for top stickers/padding */
    font-size: clamp(
      48px,
      min(6.15vw, calc((100svh - var(--mast) - var(--hdr) - 168px) / 2.75)),
      104px
    );
    line-height: 0.88;
  }

  .role-block {
    flex: 0 0 auto;
  }
}

@media (width > 800px) and (max-height: 820px) {
  .stage-copy {
    justify-content: flex-start;
    gap: 8px;
    padding-top: 10px;
    padding-bottom: 12px;
  }

  .lede,
  .stage-mail,
  .stickers-bot {
    display: none;
  }
}

@media (width > 800px) and (max-height: 620px) {
  .role {
    font-size: clamp(
      42px,
      min(5vw, calc((100svh - var(--mast) - var(--hdr) - 130px) / 2.7)),
      56px
    );
  }
}

/* ── Mobile / low-end scroll performance (visual design unchanged) ── */

/* Soften plate shadows — big soft shadows + sticky = GPU thrash on mid Androids */
@media (pointer: coarse), (hover: none), (max-width: 800px) {
  .plate {
    box-shadow: 0 8px 20px #1111110a;
  }
}

/*
 * Mobile orange disc: gentle DOWN drift on scroll (~0.3×), compositor-friendly.
 * Prefer CSS scroll-driven animation (Chrome/Android). JS fallback for Safari.
 * Headline stays above (z-index). Cap travel so it does not invade the next section.
 */
@keyframes disc-mobile-down {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(0, 160px, 0); }
}

@media (pointer: coarse), (hover: none), (max-width: 800px) {
  @media (prefers-reduced-motion: no-preference) {
    .disc {
      z-index: 0;
      will-change: transform;
      backface-visibility: hidden;
    }
    .portrait { z-index: 1; overflow: visible; }
    .stage-copy,
    .role,
    .role-block {
      z-index: 2;
      position: relative;
    }

    /* Chrome / Android: scroll-driven, no main-thread work */
    @supports (animation-timeline: scroll()) {
      html.has-sda .disc {
        animation-name: disc-mobile-down;
        animation-timing-function: linear;
        animation-fill-mode: both;
        animation-timeline: scroll(root block);
        /* 160px over ~500px scroll ≈ 0.32×; capped so it stays in hero */
        animation-range: 0px 500px;
      }
    }
  }
}

/* Offscreen sections: skip rendering work until near viewport */
@media (width <= 800px) {
  #oficio,
  #recorrido,
  #contacto,
  .colophon {
    content-visibility: auto;
    contain-intrinsic-size: 1px 720px;
  }

  /* Sheets already sticky; contain helps without changing stick behavior */
  .js .sheet {
    contain: layout paint style;
  }

  /* Sticky name + bar: isolate to reduce invalidation fan-out */
  .name-window,
  .mast,
  .bar {
    contain: layout paint;
  }

}

/* Save-Data / slow update: freeze marquees entirely */
@media (prefers-reduced-motion: reduce), (update: slow) {
  .mq-track {
    animation: none !important;
  }
  .disc {
    transform: none !important;
  }
}

/* Avoid 100vh iOS resize jank: prefer dvh everywhere sticky heights use svh */
@supports (height: 100dvh) {
  @media (width <= 800px) {
    .js .tile {
      height: min(560px, 68dvh);
    }
  }
}
