/* ═══ Performance & mobile-first hardening ═══ */

html {
  scroll-padding-top: var(--header-offset);
  -webkit-tap-highlight-color: transparent;
}

/* Below-fold: defer paint on desktop only — CV on mobile breaks
   scroll metrics, ScrollTrigger reveals, and iOS height jumps */
@media (min-width: 901px) and (hover: hover) and (pointer: fine) {
  .section:not(.hero):not(#hero) {
    content-visibility: auto;
    contain-intrinsic-size: auto 520px;
  }

  .console,
  .catalogue,
  .runway {
    content-visibility: auto;
    contain-intrinsic-size: auto 640px;
  }
}

/* Safe areas (notch / home indicator) */
.site-header,
.header {
  padding-top: max(1.25rem, env(safe-area-inset-top, 0px));
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}

@media (max-width: 540px) {
  .site-header,
  .header {
    padding-top: max(0.85rem, env(safe-area-inset-top, 0px));
  }
}

.site-footer {
  padding-bottom: max(clamp(4.25rem, 10vh, 6.5rem), env(safe-area-inset-bottom, 0px));
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}

/* Touch targets — WCAG 2.5.5 / iOS HIG */
.btn,
.site-footer__list a,
.site-footer__top,
.nav-overlay__link,
.nav-overlay__meta-link,
.nav-overlay__social,
.site-header__menu-btn,
.theme-toggle,
.contact__field input,
.contact__field textarea,
.contact__submit,
.contact__channel,
.faq__question,
.projects__all-btn {
  min-height: var(--touch-min);
}

.site-header__menu-btn,
.theme-toggle {
  min-width: var(--touch-min);
}

.nav-overlay__link {
  min-height: max(3.25rem, var(--touch-min));
}

.nav-overlay__meta-link,
.nav-overlay__social {
  display: inline-flex;
  align-items: center;
}

@media (max-height: 560px) {
  .nav-overlay__link {
    min-height: max(2.5rem, var(--touch-min));
  }
}

/* Coarse pointer: lighter effects, native scroll feel, pressed states */
@media (hover: none), (pointer: coarse) {
  body::before {
    opacity: calc(var(--grain-opacity) * 0.45);
  }

  .btn--ghost {
    backdrop-filter: none;
  }

  .btn:active,
  .contact__submit:active,
  .site-header__cta:active,
  .btn-primary:active {
    transform: translateY(1px);
  }

  a.catalogue__item--cta {
    background: var(--bg-elevated);
  }

  a.catalogue__item--cta .catalogue__item-inner--cta::after {
    border-color: var(--signal);
    opacity: 0.85;
  }

  .project-showcase:active,
  .project-card:active,
  .signal-edge:active {
    --signal-edge: 1;
  }

  .dossier__entry.is-active .dossier__entry-num,
  .dossier__entry.is-active .dossier__entry-label,
  .dossier__entry.is-active .dossier__entry-copy,
  .dossier__entry.is-active .dossier__entry-icon {
    color: var(--signal);
  }
}

/* Prevent horizontal bleed site-wide */
html,
body {
  max-width: 100%;
  overflow-x: clip;
}

img,
video,
svg,
canvas,
iframe {
  max-width: 100%;
}

.section__inner,
.site-header__inner,
.nav-overlay__panel,
.site-footer__inner {
  min-width: 0;
}

/* Ultra-narrow (320–360) — prevent horizontal bleed */
@media (max-width: 360px) {
  .hero__actions {
    flex-direction: column;
    align-items: stretch;
  }

  .hero__actions .btn {
    width: 100%;
    justify-content: center;
  }

  .catalogue {
    min-width: 0;
  }

  .catalogue__metric-value {
    font-size: clamp(1.5rem, 8vw, 2rem);
  }

  .console__hud {
    font-size: 0.625rem;
    gap: 0.35rem;
  }

  .section-meta__tags {
    flex-wrap: wrap;
  }

  .btn {
    padding-inline: 1.25rem;
  }

  .contact__form {
    padding: 1rem;
  }

  .site-footer__mark {
    font-size: clamp(3.25rem, 20vw, 5.5rem);
    max-width: 100%;
  }

  .signal__title-word {
    font-size: clamp(1.95rem, 12.5vw, 2.65rem);
  }
}

/* Tablet portrait: keep grids single-column, denser rhythm */
@media (min-width: 541px) and (max-width: 900px) {
  .catalogue__title {
    font-size: clamp(1.35rem, 3.2vw, 1.75rem);
  }

  .dossier__entry-copy {
    font-size: clamp(1.3rem, 3.5vw, 1.65rem);
  }
}

/* Short landscape: stack signal stats, compact runway */
@media (max-height: 500px) and (orientation: landscape) {
  .signal__stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .signal__title-word {
    font-size: clamp(1.85rem, 10vh, 2.75rem);
  }

  .runway__phase {
    gap: 0.75rem 1rem;
  }

  .console__log {
    min-height: 160px;
  }
}

/* Save-data / reduced bandwidth hint from boot script */
html.ft-save-data .hero__ft,
html.ft-save-data .hero__stage,
html.ft-save-data .grid-bg,
html.ft-save-data .signal-wake {
  display: none !important;
}

html.ft-save-data body::before {
  opacity: 0;
}

/* ═══ Reduced-motion map (8.8) — CSS fallbacks; JS gates GSAP/canvas ═══
   Covered systems:
   - intro (hero.css + html.motion-reduced)
   - LOCK-ON waveform (js/lock-waveform.js → static LOCKED)
   - channel lock flash / scan line
   - marquee (js/sections.js skips)
   - vault log pulse / blink
   - menu overlay (instant open/close)
   - smooth scroll (gsap-setup useNativeScroll)
   - FAQ height (native details when reduced)
*/
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .marquee__inner,
  .marquee__track {
    transform: none !important;
    animation: none !important;
    will-change: auto;
  }

  .console__log-live i,
  .console__log-cursor,
  .console__log-line,
  .console__live i,
  .hero__readout-item--live i,
  .hero__eyebrow-dot,
  .site-footer__pulse,
  .section-meta__scan::after {
    animation: none !important;
  }

  .contact__form--loading .contact__submit-arrow {
    animation: none !important;
  }

  [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
  }
}

html.motion-reduced .marquee__inner,
html.motion-reduced .marquee__track {
  transform: none !important;
  animation: none !important;
}

html.motion-reduced [data-reveal] {
  opacity: 1 !important;
  transform: none !important;
}

html.motion-reduced .section-meta__scan::after,
html.motion-reduced .console__log-live i,
html.motion-reduced .console__log-cursor,
html.motion-reduced .console__live i,
html.motion-reduced .hero__readout-item--live i,
html.motion-reduced .site-footer__pulse {
  animation: none !important;
}

/* Skip target: no outline ring on programmatic focus */
#main:focus {
  outline: none;
}

#main:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--color-signal, var(--signal)) 75%, var(--color-fg, var(--fg)));
  outline-offset: 4px;
}
