/* ActTrader homepage — mobile, tablet (iPad), and touch responsive overrides */

/* ── Global scroll model (critical for iOS) ──
   Only `html` may be the scroll container. Never set overflow-x on `body`
   while leaving overflow-y visible — CSS then computes overflow-y to auto
   and iOS traps touch scroll inside body. */
html {
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
}

body,
body.v3-page,
body.v4-page {
  margin: 0 !important;
  max-width: 100%;
  overflow: visible !important;
  height: auto !important;
  min-height: 0 !important;
  position: relative;
  touch-action: pan-y;
}

/* Clip horizontal bleed inside the document flow without creating a
   vertical scrollport (height stays auto, so overflow-y never scrolls). */
#main-content,
.page {
  max-width: 100%;
  overflow-x: clip;
}

/* Story arc rail scrolls internally — never widen the page */
.v4-page .story-flow,
.v4-page .v4-story .col {
  max-width: 100%;
  overflow-x: auto;
}

@media (max-width: 1024px) {
  html, body {
    max-width: 100%;
    width: 100%;
  }

  #main-content,
  .stack-container,
  .ch-scope,
  .ch-pin,
  .stage,
  .stage-pin,
  .container,
  .index-list,
  .page {
    max-width: 100%;
  }

  /* Do NOT set overflow-x on bare `section` — that turns every section into
     its own scroll container and blocks page scroll when one is 100vh tall. */
  .stage-terminal,
  .stage-terminal.is-macbook,
  .ch-card,
  .marquee {
    max-width: 100%;
  }

  /* Homepage hero: fill first screen, never become a scroll trap */
  .hero-main {
    overflow: visible !important;
  }

  /* Stage mocks — fit viewport without breaking scroll-driven 3D */
  .stage-terminal,
  .stage-terminal.is-macbook {
    width: min(92vw, 980px) !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .stage-terminal.is-phone {
    width: min(72vw, 300px) !important;
    margin-left: auto;
    margin-right: auto;
  }

  /* Giant watermark text must not expand layout */
  .stage-watermark,
  .s-wm {
    font-size: clamp(24px, 8vw, 72px) !important;
    max-width: 96vw;
    overflow: hidden;
    white-space: normal;
    word-break: break-word;
    text-overflow: clip;
  }

  /* Decorative layers — contain within viewport */
  .stage-pin::before,
  .stage-pin::after {
    width: calc(100% - 32px) !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
  }

  .ch-glow {
    width: 100% !important;
    max-width: 100% !important;
    left: 0 !important;
    transform: none !important;
  }

  .heritage { overflow-x: clip; }
  .heritage-bg-numeral { display: none; }

  .product-row,
  .row-desc {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .marquee { max-width: 100%; }

  .stage-terminal.is-macbook {
    overflow: hidden !important;
  }

  .stage-terminal .terminal-mock,
  .stage-terminal .platform-shot-mock,
  .stage-terminal .bm-mock,
  .stage-terminal .actfx-mock,
  .stage-terminal .prop-mock,
  .stage-terminal .ai-mock {
    max-width: 100%;
    overflow: hidden;
  }

  .nav, header, footer {
    max-width: 100%;
  }
  footer .container {
    max-width: 100%;
    overflow-x: clip;
  }
}

/* ── Tablet landscape + iPad Pro (769px – 1024px) ── */
@media (min-width: 769px) and (max-width: 1024px) {
  .container { padding: 0 28px; }
  .section-pad { padding: 96px 0; }
  .section-title { font-size: clamp(32px, 4.5vw, 48px); }

  .product-row {
    grid-template-columns: 52px 160px 1fr 200px 48px;
    gap: 20px;
    padding: 32px 20px;
  }
  .product-row .row-kicker-block,
  .product-row .row-desc { display: block; }
  .row-desc { max-width: none; font-size: 12px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .footer-grid { grid-template-columns: repeat(2, 1fr); gap: 32px; }

  .roadmap-flow {
    grid-template-columns: repeat(2, 1fr);
    border-left: 1px solid var(--line);
  }
  .milestone { border-right: 0; border-bottom: 1px solid var(--line); }
  .milestone:nth-child(odd) { border-right: 1px solid var(--line); }
  .milestone:nth-last-child(-n+2) { border-bottom: 0; }
  .roadmap-flow::before { display: none; }

  .ecosystem-diagram { max-width: 560px; }
  .eco-node { width: 100px; }
  .eco-node-dot { width: 48px; height: 48px; }
  .eco-center { width: 130px; height: 130px; }

  .stack-intro { padding: 100px 28px 64px; }
  .heritage-grid { gap: 64px; }
  .vision-header { margin-bottom: 56px; }
}

/* ── Mobile + iPad portrait (max 768px) ── */
@media (max-width: 768px) {
  nav { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .logo-text { display: inline; font-size: 14px; }
  .nav-toggle { display: flex; order: 2; margin-left: auto; margin-right: 8px; }
  .nav-cta { order: 3; font-size: 11px; padding: 8px 14px; }
  .nav-links {
    display: none;
    order: 4;
    flex-basis: 100%;
    flex-direction: column;
    gap: 14px;
    padding: 16px 0 8px;
    border-top: 1px solid var(--line);
    margin-top: 8px;
  }
  .nav-links.open { display: flex; }

  .container { padding: 0 18px; }
  .section-pad { padding: 72px 0; }
  .section-head { margin-bottom: 48px; }
  .section-lede { font-size: 15px; }

  /* Product index — full content, stacked layout */
  .product-row {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    grid-template-rows: auto auto auto auto;
    gap: 10px 14px;
    padding: 24px 16px;
    align-items: start;
  }
  .product-row:hover { padding-left: 16px; }
  .row-num {
    grid-row: 1;
    grid-column: 1;
    align-self: start;
    padding-top: 2px;
  }
  .row-kicker-block {
    grid-row: 1;
    grid-column: 2 / 3;
    display: flex !important;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }
  .row-arrow {
    grid-row: 1;
    grid-column: 3;
    align-self: start;
    font-size: 18px;
  }
  .row-name {
    grid-row: 2;
    grid-column: 1 / 4;
    font-size: clamp(22px, 6vw, 30px);
  }
  .row-desc {
    grid-row: 3;
    grid-column: 1 / 4;
    display: block !important;
    max-width: none;
    font-size: 13px;
    line-height: 1.55;
  }

  /* Stack intro */
  .stack-intro {
    padding: 80px 18px 48px;
  }
  .stack-intro h2 { font-size: clamp(32px, 8vw, 48px); }
  .stack-intro p { font-size: 14px; padding: 0 4px; }
  .stack-intro .hint { font-size: 10px; }

  .stage-label h2 { font-size: clamp(24px, 6vw, 34px) !important; }

  /* Heritage */
  .heritage { padding: 80px 0; }
  .heritage-grid { grid-template-columns: 1fr; gap: 40px; }
  .heritage-text h2 { font-size: clamp(32px, 8vw, 48px); }
  .heritage-body { font-size: 15px; max-width: none; }
  .heritage-year { font-size: 80px; }
  .heritage-marks { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .heritage-bg-numeral { opacity: 0.025; font-size: 280px; bottom: -60px; right: -40px; }

  /* Vision roadmap */
  .vision { padding: 80px 0; }
  .vision-header h2 { font-size: clamp(32px, 7vw, 44px); }
  .roadmap-flow { grid-template-columns: 1fr; }
  .milestone { border-right: 0; border-bottom: 1px solid var(--line); padding: 24px 18px; }
  .milestone:last-child { border-bottom: 0; }
  .roadmap-flow::before { display: none; }

  /* Ecosystem — grid layout, same nodes */
  .ecosystem-diagram {
    aspect-ratio: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    max-width: none;
    margin-top: 40px;
    padding: 0 4px;
  }
  .eco-ring,
  .eco-center { display: none; }
  .eco-node {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    width: 100%;
    padding: 16px 12px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--r-lg, 16px);
  }
  .eco-node-dot { width: 44px; height: 44px; margin-bottom: 8px; }
  .eco-node-label { font-size: 9px; }

  /* Stats + footer + final */
  .stats-bar { padding: 72px 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-cell { padding: 28px 18px; }
  .stat-cell .val { font-size: clamp(28px, 7vw, 36px); }

  .footer-grid { grid-template-columns: 1fr; gap: 28px; }
  .footer-bottom { flex-direction: column; gap: 12px; text-align: center; }

  .final { padding: 96px 0; }
  .final-title { font-size: clamp(30px, 8vw, 44px); }
  .final-sub { font-size: 15px; padding: 0 8px; }
  .hero-ctas { flex-direction: column; align-items: stretch; gap: 12px; }
  .btn-primary, .btn-ghost { justify-content: center; width: 100%; }

  .marquee { margin-top: 64px; }
  .marquee-item { font-size: 15px; }

  .deep-grid { grid-template-columns: 1fr !important; gap: 32px; padding: 48px 0; }
  .deep-features { grid-template-columns: 1fr; }
  .deep-metrics { grid-template-columns: 1fr 1fr; }
}

/* ── Small phones (max 480px) ── */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .ecosystem-diagram { grid-template-columns: 1fr; }
  .heritage-marks { grid-template-columns: 1fr; }
  .deep-metrics { grid-template-columns: 1fr; }
  .ch-h1, .ch-h1-2 { font-size: clamp(36px, 11vw, 52px) !important; }
  .ch-sub { font-size: 14px; }
}

@media (min-width: 1024px) and (max-width: 1440px) {
  .ch-card {
    width: min(94vw, 1120px) !important;
    height: min(82vh, 680px) !important;
    max-height: calc(100dvh - 100px);
  }
  .ch-card-inner {
    grid-template-columns: minmax(220px, 0.95fr) minmax(280px, 1.05fr) !important;
    gap: 20px !important;
    padding: 24px 32px !important;
  }
  .ch-watermark {
    right: 12px !important;
    width: min(50%, 400px) !important;
  }
  .ch-wm-text {
    font-size: clamp(36px, 4.8vw, 68px) !important;
    opacity: 0.5 !important;
  }
  .ch-phone-inner { transform: scale(0.88) !important; }
  .ch-phone-stage { max-width: none !important; justify-self: center !important; }
  .ch-card-copy h3 { font-size: clamp(20px, 2vw, 26px) !important; }
  .ch-card-copy p { font-size: 13px !important; max-width: 100%; }
  .ch-badge.b-top { top: 8% !important; left: 2px !important; transform: none !important; }
  .ch-badge.b-bot { bottom: 12% !important; right: 2px !important; transform: none !important; }
  .ch-mobile-shot .ch-mobile-img { object-position: center top; }
}

@media (min-width: 1024px) and (max-height: 860px) {
  .ch-card { height: min(86vh, 620px) !important; }
  .ch-phone-inner { transform: scale(0.82) !important; }
  .ch-wm-text { font-size: clamp(32px, 4vw, 56px) !important; opacity: 0.45 !important; }
}

/* ── Cinematic hero — tablet / narrow desktop layout fixes ── */
@media (max-width: 1024px) {
  .ch-scope {
    height: auto;
  }
  .ch-pin {
    min-height: 100vh;
    min-height: 100dvh;
  }
  .ch-card {
    width: min(94vw, 720px) !important;
    height: min(78vh, 680px) !important;
    max-height: calc(100dvh - 120px);
  }
  .ch-card-inner {
    padding: 28px 20px !important;
    gap: 12px;
    align-content: center;
  }
  .ch-phone-stage {
    height: min(46vh, 380px) !important;
    width: fit-content !important;
    margin-inline: auto !important;
  }
  .ch-phone-inner {
    transform: scale(0.58) !important;
  }
  .ch-card-copy {
    padding: 0 8px;
  }
  .ch-card-copy h3 {
    font-size: clamp(20px, 5vw, 28px);
    margin-bottom: 8px;
  }
  .ch-cta-wrap {
    padding: 88px 20px 48px;
    justify-content: center;
  }
  .ch-badge { display: none; }
}

@media (max-width: 768px) {
  .ch-scope { height: auto; }
  .ch-card {
    width: min(96vw, 560px) !important;
    height: min(72vh, 620px) !important;
  }
  .ch-phone-inner { transform: scale(0.5) !important; }
  .ch-watermark { display: none; }
}

/* ── Hero + stages: typography on touch — scroll animations stay in index.html ── */
@media (max-width: 1024px) {
  .ch-h1, .ch-h1-2 { font-size: clamp(36px, 9vw, 64px); }
  .ch-sub { font-size: clamp(14px, 3.5vw, 17px); padding: 0 8px; }

  .stage-label {
    top: 7% !important;
    width: 92%;
  }
  .stage-label h2 { font-size: clamp(26px, 6.5vw, 40px) !important; }
  .stage-chip,
  .stage-orbital,
  .stage-quotes,
  .stage-ticker { display: none !important; }
  .stage-terminal::before { animation: none; }
}

/* Touch: disable hover shifts that break layout */
@media (hover: none) {
  .product-row:hover { padding-left: 16px; }
  [data-magnetic] { transform: none !important; }
}

/* iOS Safari — reduce compositor jank during sticky scroll */
@media (pointer: coarse) {
  .stack-container {
    perspective: none;
  }
  .stage-pin {
    transform: none !important;
    -webkit-transform: none !important;
    transform-style: flat;
  }
  .stage-terminal,
  .stage-label,
  .stage-watermark {
    transform-style: flat;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  .stage-atmosphere {
    display: none;
  }
  .stage-terminal::before {
    animation: none !important;
    display: none;
  }
  .stack-container * {
    animation: none !important;
  }
  .ch-pin {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  .ch-text-wrap,
  .ch-card,
  .ch-cta-wrap {
    filter: none !important;
  }
  .engage-atmosphere {
    opacity: 0.5;
  }
}

/* ── Touch / mobile: native swipe — no sticky scroll traps ── */
@media (pointer: coarse), (max-width: 1024px) {
  html {
    scroll-behavior: auto !important;
    overflow-x: hidden !important;
    overflow-y: scroll !important;
  }
  body,
  body.v3-page,
  body.v4-page {
    touch-action: pan-y;
    overscroll-behavior-y: auto;
    overflow: visible !important;
    height: auto !important;
  }

  .hero-main,
  .v4-story,
  .chapter,
  .page,
  #main-content {
    overflow: visible !important;
  }

  /* Hero: normal document flow instead of 260vh pinned scrub */
  .ch-scope {
    height: auto !important;
  }
  .ch-pin {
    position: relative !important;
    top: auto !important;
    height: auto !important;
    min-height: 100dvh;
    overflow: visible !important;
  }
  .ch-text-wrap {
    position: relative !important;
    inset: auto !important;
    min-height: 100dvh;
    padding: 96px 20px 40px;
  }
  .ch-card-stage {
    position: relative !important;
    inset: auto !important;
    padding: 8px 0 56px;
    pointer-events: auto;
  }
  .ch-card {
    transform: none !important;
    margin: 0 auto;
  }
  .ch-cta-wrap {
    display: none !important;
  }

  /* Product stages: stacked sections, not 200vh sticky pins */
  .stage {
    height: auto !important;
    overflow: visible !important;
  }
  .stage-pin {
    position: relative !important;
    top: auto !important;
    height: auto !important;
    overflow: visible !important;
    padding: 56px 0 64px !important;
  }
  .stage-pin::before,
  .stage-pin::after {
    display: none !important;
  }
  .stage-label {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    margin: 0 auto 28px !important;
  }
  .s-terminal,
  body.is-touch-device .s-terminal {
    transform: none !important;
    opacity: 1 !important;
  }
  .stage-label.s-lbl,
  body.is-touch-device .stage-label.s-lbl {
    transform: none !important;
    opacity: 1 !important;
  }
  .stage-watermark.s-wm,
  body.is-touch-device .stage-watermark.s-wm {
    opacity: 0.06 !important;
  }
}

/* ── Laptop / small desktop: keep stage decorations inside the card ── */
@media (min-width: 1025px) and (max-width: 1680px) {
  .stage-label {
    top: 14% !important;
    width: min(88%, 560px);
  }

  .stage-label h2 {
    font-size: clamp(28px, 3.2vw, 44px) !important;
  }

  .stage-watermark.s-wm {
    font-size: clamp(28px, 4.2vw, 72px) !important;
    max-width: min(82vw, 680px);
  }

  .stage-orbital {
    max-width: min(200px, 22vw);
    font-size: 10px;
    padding: 7px 12px;
  }

  .stage-chip {
    max-width: min(148px, 17vw);
    padding: 10px 12px;
    font-size: 10px;
  }

  .stage-chip .val {
    font-size: 15px;
  }

  .stage-ticker .row {
    font-size: clamp(28px, 4.5vw, 72px) !important;
  }

  .stage-quote {
    font-size: 10px;
    max-width: min(200px, 24vw);
  }

  .stage-progress {
    bottom: clamp(28px, 4vh, 40px);
  }
}

/* Safe area for notched phones / iPad */
@supports (padding: max(0px)) {
  nav { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  body { padding-bottom: env(safe-area-inset-bottom); }
}
