/* ==========================================================================
   Project detail pages: mobile treatment
   Shared by the 23 project pages (venice-canal-residence, malibu-midcentury-
   modern, sherman-oaks-adu, ...). Loads last so it wins the cascade.

   The problem, measured on venice-canal-residence at 390px:

     first gallery photo ................ 3,638px down the page
     project description (211 words) .... 1,430px tall
     features list (12 items) ........... 1,237px tall

   That is roughly nine screens of scrolling before a single project photo.
   The gallery is the reason somebody opens a project page, and it was buried
   under the entire write-up.

   Three changes, all mobile-only:

     1. Gallery first. `.project-content` becomes a flex column and the
        sections are ordered by class, so the photos come immediately after
        the hero and the write-up follows. Ordering by class rather than by
        position means it works whether a page has 2 or 3 sections, and it
        no-ops safely on the one page with no gallery at all.

     2. The description collapses to its first paragraph with a "Read more"
        toggle, so the text is available without being a wall.

     3. The features list becomes two columns of short chips instead of 12
        full-width rows.
   ========================================================================== */

@media screen and (max-width: 767px) {

  /* ---- 1. Gallery above the write-up ------------------------------------ */
  .project-content {
    display: flex;
    flex-direction: column;
    padding: 0 0 40px;
  }

  /* Every direct child gets an explicit order. Flex defaults to order:0, so
     anything left out (the prev/next links, which are a sibling of the
     sections rather than inside one) would sort ahead of the gallery. */
  .project-content > * {
    order: 3;
    width: 100%;
  }

  /* Default for any section not named below (e.g. a testimonial): after the
     gallery and the overview, in source order. */
  .project-content > .project-section {
    order: 3;
    margin-bottom: 36px;
  }

  .project-content > .project-section:has(.project-gallery) {
    order: 1;
  }

  .project-content > .project-section:has(.project-overview) {
    order: 2;
  }

  /* Always last: it is the way off the page. */
  .project-content > .project-navigation {
    order: 9;
    margin-top: 8px;
  }

  /* :has() is well supported on current iOS/Android, but if it is missing the
     page simply keeps source order (text, then gallery) rather than breaking.
     The rules below apply either way. */

  .project-section:last-child {
    margin-bottom: 0;
  }

  /* ---- 2. Hero ----------------------------------------------------------
     560px of hero with the three detail items stacked into a 216px column
     pushed the title off centre and wasted most of the screen. */
  /* A fixed height, not auto: .project-hero-image is absolutely positioned at
     height:100%, so an auto-height hero gives it nothing to resolve against
     and the photo spills past the section. */
  .project-hero {
    height: 62vh;
    height: 62dvh;
    min-height: 400px;
    max-height: 520px;
    overflow: hidden;
  }

  .project-hero-image {
    height: 100%;
    width: 100%;
    object-fit: cover;
  }

  .project-hero-content {
    width: 100%;
    padding: 0 20px;
  }

  .project-hero-title {
    font-size: 1.85rem;
    line-height: 1.14;
    margin-bottom: 6px;
  }

  .project-hero-subtitle {
    font-size: 1rem;
    font-weight: 400;
    margin-bottom: 18px;
  }

  /* One row of three, not a stacked column. These are short values (type,
     square footage, year) and read fine side by side at this size. */
  .project-hero-details {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 0;
    margin-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.22);
    padding-top: 14px;
  }

  .project-detail-item {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 6px;
  }

  .project-detail-item + .project-detail-item {
    border-left: 1px solid rgba(255, 255, 255, 0.22);
  }

  .detail-label {
    font-size: 0.6rem;
    letter-spacing: 0.08em;
    margin-bottom: 3px;
    display: block;
  }

  .detail-value {
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.25;
  }

  /* ---- 3. Gallery -------------------------------------------------------
     Each page carries an inline <style> for the carousel with a fixed
     `height: 400px` container and `object-fit: contain`. A landscape photo
     inside a 390x400 box letterboxes, so the slide was mostly black bars.

     Use an aspect ratio and `cover` instead: the frame follows the image
     shape and the photo fills it.
     --------------------------------------------------------------------- */
  .project-gallery {
    margin: 0 0 8px;
  }

  .gallery-title {
    font-size: 1.4rem;
    margin: 28px 0 16px;
  }

  .gallery-carousel {
    margin: 0 auto;
  }

  .carousel-container {
    height: auto;
    aspect-ratio: 4 / 3;
  }

  .carousel-slide img {
    object-fit: cover;
  }

  /* 41 dots at 18px each need ~740px, so they wrapped to three rows inside a
     90px scroll box that read as a broken grid. One horizontally scrollable
     row instead, with the counter ("12 / 41") carrying the real position. */
  .carousel-dots {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 12px 14px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .carousel-dots::-webkit-scrollbar { display: none; }

  .carousel-dot {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    margin: 0;
  }

  .carousel-nav {
    width: 38px;
    height: 38px;
    font-size: 17px;
  }

  .carousel-counter {
    top: 12px;
    right: 12px;
    padding: 5px 9px;
    font-size: 12px;
  }

  /* ---- 4. Overview: side-by-side columns stack -------------------------- */
  .project-overview {
    display: flex;
    flex-direction: column;
    gap: 26px;
  }

  .project-description h2 {
    font-size: 1.5rem;
    line-height: 1.2;
    margin-bottom: 14px;
  }

  .project-description p {
    font-size: 0.97rem;
    line-height: 1.7;
    margin-bottom: 14px;
  }

  /* Collapsed state: show the first paragraph, fade the rest behind a
     toggle. JS adds .is-collapsed only when there is more than one
     paragraph, so short write-ups are never given a pointless button. */
  .project-description.is-collapsed .pd-extra {
    display: none;
  }

  .pd-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 2px 0 4px;
    padding: 9px 0;
    background: none;
    border: 0;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--primary-color, #1c3f60);
    cursor: pointer;
  }

  .pd-toggle::after {
    content: '';
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translate(-1px, -1px);
    transition: transform 0.2s ease;
  }

  .project-description:not(.is-collapsed) .pd-toggle::after {
    transform: rotate(-135deg) translate(-1px, -1px);
  }

  /* ---- 5. Features as chips ---------------------------------------------
     40px of padding around 12 full-width rows made this taller than the
     description it sat beside. Two columns of compact chips instead. */
  .project-features {
    background-color: #f7f8fa;
    padding: 20px 16px 22px;
    border-radius: 8px;
  }

  .project-features h3 {
    font-size: 1.1rem;
    margin-bottom: 14px;
  }

  .features-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
  }

  .features-list li {
    padding-left: 14px;
    margin-bottom: 0;
    font-size: 0.82rem;
    line-height: 1.4;
  }

  .features-list li:before {
    width: 5px;
    height: 5px;
    top: 7px;
  }

  /* ---- 6. Tail sections -------------------------------------------------- */
  .project-navigation {
    padding: 0 18px;
    gap: 12px;
  }

  .project-cta {
    padding: 40px 20px 46px;
  }

  .project-cta h2 {
    font-size: 1.45rem;
    line-height: 1.2;
  }
}

/* Single-column chips on the narrowest phones: two columns of a long feature
   ("Custom rift-cut white oak cabinetry and millwork throughout") turns into
   five-line towers under ~360px. */
@media screen and (max-width: 360px) {
  .features-list { grid-template-columns: 1fr; }
  .project-hero-title { font-size: 1.65rem; }
  .detail-value { font-size: 0.8rem; }
}
