/* ---------------------------------------------------------------------------
   Responsive layer for the design prototype.

   The pages are inline-styled (they came out of a visual design tool), and an
   inline style beats a stylesheet rule -- so these overrides are !important by
   necessity. Layout containers carry a data-r hook added by hand; matching on
   [style*="..."] does NOT work here because the browser normalises the style
   attribute (minmax(0,7fr) is stored as minmax(0px, 7fr)), so those selectors
   silently never fire.

   This is a prototype-stage shim. When these layouts are ported to the CMS,
   express the breakpoints in the component styles and delete this file.

   Hooks:
     data-r="split"        two-column content split
     data-r="index-grid"   the 12-column Projects editorial grid
     data-r="row-3"        three-up row
     data-r="row-4"        four-up row
     data-r="labelrow"     fixed label column + value
     data-r="footer-grid"  footer 2fr 1fr 1fr

   Two breakpoints:
     <= 900px  tablet   two-column splits collapse, gutters tighten
     <= 640px  phone    everything single column, footer and label rows stack

   Before this the site had no width breakpoints at all -- the only media query
   in the whole prototype was prefers-reduced-motion. At 375px the work grid
   stayed two columns and rendered architectural photography 96-195px wide.
--------------------------------------------------------------------------- */

/* === tablet ============================================================== */
@media (max-width: 900px) {

  /* Gutters: 48px each side costs a quarter of a small screen. */
  header, footer, main, section, nav > div {
    padding-left: 28px !important;
    padding-right: 28px !important;
  }

  /* Brand and nav share one space-between row, which silently stops working
     the moment they stop fitting: they do not push each other, they overlap,
     and by 700px the word "Projects" sits on top of the logo. Tightening the
     nav buys most of the range back, and letting the header wrap covers the
     rest -- the nav drops to its own full-width line only when the row truly
     cannot hold it, so the wider tablet sizes keep the single-row lockup. */
  header {
    flex-wrap: wrap !important;
    gap: 12px 24px !important;
  }
  header nav { gap: 24px !important; }

  [data-r="split"] {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 40px !important;
  }
  /* Children placed with an explicit grid-column (the project gallery uses
     "1", "2" and "1 / -1") would otherwise create an implicit second column
     and squeeze images to ~54px. Make every child span the single column. */
  [data-r="split"] > * {
    grid-column: 1 / -1 !important;
    grid-row: auto !important;
    margin-top: 0 !important;
  }

  [data-r="index-grid"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  [data-r="index-grid"] > figure {
    grid-column: auto !important;
    margin-top: 0 !important;
  }

  [data-r="row-3"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  [data-r="row-4"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }

  /* The Home "Selected Work" grid used to be hand-placed -- explicit
     grid-column / grid-row, margin rhythm, 82% and 70% widths -- and needed a
     wholesale reset here. It is a uniform 2-up now, so the generic
     [data-r="split"] rules above already stack it and the reset is gone: its
     margin-bottom was adding to the grid gap and double-spacing the stack. */

  /* 92vh of viewport is a lot of chrome on a short screen. */
  section[style*="92vh"], section[style*="86vh"] {
    height: auto !important;
    min-height: 72vh !important;
  }
}

/* === phone =============================================================== */
@media (max-width: 640px) {

  header, footer, main, section, nav > div {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }

  /* The header is one flex row -- brand, then nav -- and space-between only
     works while both fit on that row. Here the nav wraps to three lines, so
     it grows taller than the brand and butts straight up against it, and the
     whole bar reaches 188px of sticky chrome on an 812px screen. Stack the
     two instead, and let it scroll away rather than following the reader
     down. The brand image is trimmed to match: it is the tallest thing in
     the header now that the wordmark is gone. */
  header {
    position: static !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }
  header > a img { height: 44px !important; }

  /* Nav wrapped and overflowed; its links were 16px tall against a 44px
     minimum tap target. */
  header nav {
    width: 100% !important;
    flex-wrap: wrap !important;
    gap: 4px 18px !important;
  }
  header nav a {
    padding-top: 12px !important;
    padding-bottom: 12px !important;
    display: inline-flex !important;
    align-items: center !important;
    min-height: 44px !important;
  }

  [data-r="index-grid"],
  [data-r="row-3"],
  [data-r="row-4"],
  [data-r="split"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* The Craft detail row staggers its middle cell down 56px. In one column
     that is not a stagger, it is 88px of air above the second image and 32px
     above the others, which reads as a mistake. Left alone at 900px, where
     two columns still make a stagger out of it. Child combinator on purpose:
     the cells carry the offset, the text inside them carries its own margins
     and must keep them. */
  [data-r="row-3"] > * { margin-top: 0 !important; }

  /* A fixed 110-130px label column squeezes the value into a two-word
     ribbon. Stack them. */
  [data-r="labelrow"] {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 4px !important;
  }

  /* 2fr 1fr 1fr becomes three unreadable slivers. */
  [data-r="footer-grid"] {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 32px !important;
  }

  /* The tall-portrait override that used to live here (3/4 and 4/5 crops in
     "Selected Work", forced to 4/3 so they didn't occupy two screens) matched
     nothing once that grid became uniformly 4/3. */

  section[style*="92vh"], section[style*="86vh"] { min-height: 62vh !important; }

  /* Stacked CTAs rather than two buttons fighting for one line. */
  section[style*="92vh"] div[style*="gap:16px"],
  section[style*="92vh"] div[style*="gap: 16px"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }

  /* Nothing may push the page sideways. */
  html, body { overflow-x: hidden !important; }
}
