/* ELUD responsive composition layer.
   Loaded last so every generated route shares the same layout contracts.
   Width is fluid; individual text blocks stay at readable measure. Portrait
   foldables use the ordinary one-column fallback. Segmented Edge/Chromium
   browsers receive a hinge-aware two-column enhancement when available. */

/* Prevent auto min-content grid widths from pushing columns beyond the viewport. */
.hs-grid > *, .story-grid > *, .grid-2 > *, .grid-3 > *,
.tiles-2 > *, .tiles-4 > *, .fam-3 > *, .fam-4 > *,
.ea-band > *, .ea-layout > *, .cfg > *, .legal-layout > *,
.roadmap > *, .footer .cols > * { min-width: 0; }
.ea-band, .ea-layout, .legal-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.legal-layout { grid-template-columns: 220px minmax(0, 1fr); }
.legal-doc, .legal-toc { min-width: 0; }
.legal-doc { overflow-wrap: anywhere; }
.legal-table { max-width: 100%; }
.legal-table table { min-width: 420px; }
/* Scroll only a genuine tabular dataset, not the page itself. */
.legal-toc a { overflow-wrap: anywhere; }
.ea-band .build-actions, .ea-band .actions { min-width: 0; }

/* Large desktop / ultrawide: expand the stage, not the line length of copy. */
@media (min-width: 1920px) {
  :root { --elud-container: 1520px; --elud-text-body: 17px; }
  .hs-copy .display { font-size: clamp(5rem, 4.8vw, 7.5rem); }
  .section-head { max-width: 820px; }
  .hs-copy .lead { max-width: 38ch; }
}
@media (min-width: 2560px) {
  :root { --elud-container: 1760px; }
  .hs-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: clamp(64px, 3vw, 96px); }
  .section { padding-block: clamp(120px, 5vw, 176px); }
}

/* Compact desktop and tablets: a single, legible header action plus a menu.
   This avoids squeezing five links through 761–900px viewports. */
@media (max-width: 900px) {
  .gnav .wrap { gap: clamp(8px, 2vw, 18px); }
  .gnav nav > ul { display: none; }
  .gnav .menu-btn { display: grid; flex: none; }
  .gnav .ea { display: inline-flex; flex: none; }
  .gnav.is-open nav > ul {
    display: grid; position: absolute; top: 100%; left: 0; right: 0;
    gap: 0; padding: 8px max(20px, env(safe-area-inset-right, 0px)) 18px;
    background: var(--elud-bg); border-bottom: var(--elud-line);
    max-height: calc(100dvh - 64px); overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: 0 12px 24px rgb(27 27 28 / .07);
  }
  .gnav.is-open ul a { min-height: 52px; font-size: 16px; width: 100%; }
  .gnav.is-open ul .m-only { display: block; }
}

/* Narrow desktop, tablet and continuous-foldable fallback: keep the message
   before the interactive render. Image-first previously buried both CTAs well
   below the first viewport, especially on iPhone Duo's unfolded display. */
@media (max-width: 960px) {
  .hs-grid, .story-grid, .grid-2, .grid-3, .ea-band, .ea-layout { grid-template-columns: minmax(0, 1fr); }
  .hs-grid { align-items: start; gap: clamp(24px, 4vw, 48px); }
  .hs-copy { order: 0; }
  .hs-stage { order: 1; width: 100%; max-width: 720px; margin-inline: auto; }
  .hs-copy .display { font-size: clamp(3rem, 7.8vw, 5.25rem); line-height: .98; }
  .hs-copy .lead { max-width: 58ch; }
  .story-stage { max-width: 560px; margin-inline: auto; }
  .story-stage .viewer.hero { aspect-ratio: 1 / 1; height: auto; }
  .cfg-visual { max-width: 720px; margin-inline: auto; width: 100%; }
  .tiles-2, .fam-3 { grid-template-columns: minmax(0, 1fr); }
  .legal-layout { grid-template-columns: minmax(0, 1fr); }
  .legal-toc { min-width: 0; }
}

/* Tablet content must use the available width without turning into a phone
   list, particularly in portrait and on the unfolded ~890px iPhone Duo. */
@media (min-width: 601px) and (max-width: 960px) {
  .hs-foot { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hs-foot li + li { padding-left: 16px; border-left: var(--elud-line); border-top: 0; }
  .hs-foot li { padding: 18px 12px 12px 0; gap: 5px 10px; }
  .hs-foot b { font-size: clamp(16px, 2.2vw, 20px); }
  .hs-foot span:last-child { font-size: 14px; }
  .footer .cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Phone, folded Duo outer display, and small embedded webviews. */
@media (max-width: 600px) {
  .hero-studio { padding-top: clamp(24px, 5vw, 42px); }
  .hs-grid { gap: clamp(22px, 6vw, 34px); }
  .hs-stage { max-width: 100%; }
  .hs-copy .display { font-size: clamp(2.5rem, 10.6vw, 3.65rem); line-height: 1.01; letter-spacing: -.04em; }
  .hs-copy .lead { font-size: clamp(16px, 3.8vw, 18px); line-height: 1.5; }
  .hs-copy .actions { gap: 16px; }
  .hs-foot { grid-template-columns: minmax(0, 1fr); margin-top: 34px; }
  .hs-foot li { min-width: 0; padding: 15px 0; }
  .hs-foot li + li { padding-left: 0; border-left: 0; border-top: var(--elud-line); }
  .viewer.hero { max-width: 100%; }
  .render-fig { aspect-ratio: 4 / 3; }
  .render-fig img { object-fit: contain; }
  .ea-band { padding: clamp(18px, 5vw, 28px); }
  .ea-pending, .ea-form { padding: clamp(18px, 5vw, 28px); }
  .legal-toc { padding: 14px; }
  .legal-meta, .row-2, .interest { grid-template-columns: minmax(0, 1fr); }
  .bar .wrap, .build-actions { min-width: 0; }
  .footer .cols { gap: 22px; }
  .signup-consent { overflow-wrap: anywhere; }
  .chapter .principles li { grid-template-columns: 32px minmax(0, 1fr); gap: 10px; }
  .chapter .principles li p { grid-column: 2; }
}
@media (max-width: 360px) {
  /* In 320px layouts the extra header link becomes a two-line tap target.
     It remains accessible through the mobile menu's Updates link. */
  .gnav .ea { display: none; }
  .wrap { padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px)); }
  .hs-copy .display { font-size: clamp(2.35rem, 11vw, 2.65rem); }
  .btn, .chip { white-space: normal; }
  .viewer-ctrl { right: 8px; bottom: 8px; }
  .viewer-ctrl button { width: 44px; height: 44px; }
  .stage .tag { max-width: calc(100% - 24px); }
  .legal-toc, .legal-doc { max-width: 100%; }
  .step-h { align-items: flex-start; }
  .done-card dl div { flex-wrap: wrap; }
}

/* Landscape phones, small-height browser windows and tabletop foldable poses:
   do not let a square viewer or pinned actions take over the entire viewport. */
@media (max-height: 560px) and (orientation: landscape) {
  .gnav .wrap { height: 56px; }
  .gnav.is-open nav > ul { max-height: calc(100dvh - 56px); }
  .lnav { top: 56px; }
  .lnav .wrap { height: 48px; }
  html, html:has(.lnav) { scroll-padding-top: 116px; }
  .hero-studio { padding-block: 22px 40px; }
  .hs-grid { align-items: start; }
  .hs-stage .viewer.hero, .story-stage .viewer.hero, .cfg-visual .stage {
    aspect-ratio: 16 / 10; height: auto; max-height: 68svh;
  }
  .story-stage { position: static; }
  .bar { position: static; }
  body:not(.is-done) { padding-bottom: 0; }
}

/* Segmented / hinged browsers (Edge, Chrome): keep adjacent panels wholly on
   either side of a physical fold. Safari, including iPhone Duo, currently uses
   the safe fluid layout above because viewport segments aren't exposed. */
@media (horizontal-viewport-segments: 2) and (min-width: 800px) and (max-width: 1400px) {
  :root {
    --elud-fold-gap: max(40px, calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0) + 48px));
  }
  /* On physical dual-panel devices, global navigation is a right-panel menu.
     The normal full-width link row would put a tap target over the hinge. */
  .gnav nav > ul { display: none; }
  .gnav .menu-btn { display: grid; flex: none; }
  .gnav .ea { display: inline-flex; }
  .gnav.is-open nav > ul {
    display: grid; position: absolute; top: 100%;
    left: env(viewport-segment-left 1 0); right: 0;
    max-width: env(viewport-segment-width 1 0);
    background: var(--elud-bg); border-bottom: var(--elud-line);
    padding: 8px 18px 18px; max-height: calc(100dvh - 64px);
    overflow-y: auto; overscroll-behavior: contain;
    box-shadow: 0 12px 24px rgb(27 27 28 / .07);
  }
  .gnav.is-open ul a { min-height: 52px; font-size: 16px; }
  /* The local product index scrolls inside the *right* panel. The primary
     build CTA is already present in the global header on both panels. */
  .lnav .wrap { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--elud-fold-gap); }
  .lnav .name { display: block; grid-column: 1; margin-right: 0; }
  .lnav ul { grid-column: 2; min-width: 0; width: 100%; overflow-x: auto; }
  .lnav .wrap > .btn { display: none; }
  .hs-grid, .story-grid, .cfg, .ea-layout, .grid-2, .tiles-2, .fam-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: var(--elud-fold-gap);
  }
  .hs-copy { order: 0; }
  .hs-stage { order: 1; max-width: none; }
  .hs-copy .display { font-size: clamp(2.3rem, 3.8vw, 4.5rem); }
  .story-stage { margin-inline: 0; max-width: none; }
  /* Avoid centered headings and concept-card columns crossing the fold. */
  .p-hero.center .wrap, .legal-hero .wrap {
    max-width: env(viewport-segment-width 0 0);
    margin-left: 0; margin-right: auto; text-align: left;
  }
  .p-hero.center .sub-title, .p-hero.center .actions { margin-left: 0; margin-right: 0; justify-content: flex-start; }
  .section-head { max-width: calc(env(viewport-segment-width 0 0) - 2 * clamp(20px, 4vw, 48px)); }
  .hs-foot, .tiles-4, .fam-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--elud-fold-gap); }
  .hs-foot li:nth-child(3) { padding-left: 0; border-left: 0; border-top: var(--elud-line); }
  .story-stage .viewer.hero { aspect-ratio: 1 / 1; height: auto; }
  /* A legal document otherwise runs across the physical hinge: put the TOC
     wholly on the left and the reading column on the right. */
  .legal-layout {
    max-width: var(--elud-container); grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: var(--elud-fold-gap);
  }
  .legal-doc, .legal-toc { min-width: 0; }
  .roadmap, .footer .cols { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--elud-fold-gap); }
  .bar .wrap { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--elud-fold-gap); }
  .bar .wrap > :last-child { justify-self: end; }
}
@media (vertical-viewport-segments: 2) {
  .story-stage, .cfg-visual { position: static; }
  .bar { position: static; }
  body:not(.is-done) { padding-bottom: 0; }
}
/* Draft legal placeholders can contain long addresses; never force a 320px
   viewport to scroll sideways just to display a bracketed drafting token. */
@media (max-width: 600px) {
  .legal-doc .ph, .legal-draft .ph { white-space: normal; overflow-wrap: anywhere; }
  .legal-meta dd { overflow-wrap: anywhere; }
}
