/* Reader-facing copy only. Keep the original homepage hero and navigation untouched. */
:where(main, article) :is(h1, h2, h3, h4):not(:where(#hero *)) {
    text-wrap: balance;
}
:where(main, article) :is(p, li, dd, figcaption, summary):not(:where(#hero *, nav *, .modal *, .carousel *)) {
    text-wrap: pretty;
}

/* These captions and brief summaries occupy a narrow, fixed measure. */
:is(#services, #projects) .card :is(h3, p),
#gallery .photos .small,
.dc-service-planning :is(.dc-planning-steps p, .dc-planning-cta p),
#dc-additions .dc-addition-description,
.dc-service-card-copy p,
.dc-four-season figcaption {
    text-wrap: balance;
}
#gallery .photos .small {
    font-size: .9375rem;
    line-height: 1.6;
    text-align: start;
}
article .text-justify,
article blockquote.card-bodyquote {
    text-align: start;
}

/* On an ordinary three-across gallery, widen the row before a short tail.
   Seven photos become 3 + 4; eleven become 3 + 4 + 4. */
@media (min-width: 992px) {
    :is(#services, #projects, #gallery) .row:has(> .col-lg-4):not(:has(> [style*="display:contents"])):has(> :last-child:nth-child(3n + 1)) > .col-lg-4:nth-last-child(-n + 4),
    :is(#services, #projects, #gallery) .row:has(> :nth-child(8)):has(> :last-child:nth-child(3n + 2)) > .col-lg-4:nth-last-child(-n + 8) {
        width: 25%;
    }
    :is(#services, #projects, #gallery) .row:has(> :only-child) > .col-lg-4 {
        width: 100%;
        max-width: 44rem;
    }
    :is(#services, #projects, #gallery) .row:has(> :last-child:nth-child(5)) > .col-lg-4:nth-child(-n + 2) {
        width: 50%;
    }
}
@media (min-width: 768px) and (max-width: 991.98px) {
    :is(#services, #projects, #gallery) .row:has(> :nth-child(3)):has(> :last-child:nth-child(odd)) > .col-md-6:nth-last-child(-n + 3) {
        width: 33.333333%;
    }
}

/* Published editorial galleries use two columns. Give their final three a complete row. */
@media (min-width: 651px) {
    .dc-project-story .dc-gallery:has(> :last-child:nth-child(2n + 3)) {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
    .dc-project-story .dc-gallery:has(> :last-child:nth-child(2n + 3)) > figure {
        grid-column: span 3;
    }
    .dc-project-story .dc-gallery:has(> :last-child:nth-child(2n + 3)) > figure:nth-last-child(-n + 3) {
        grid-column: span 2;
    }
}
@media (min-width: 781px) {
    .mc-build-grid:has(> :last-child:nth-child(2n + 3)) {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
    .mc-build-grid:has(> :last-child:nth-child(2n + 3)) > figure {
        grid-column: span 3;
    }
    .mc-build-grid:has(> :last-child:nth-child(2n + 3)) > figure:nth-last-child(-n + 3) {
        grid-column: span 2;
    }
}
/* The Dilworth filters set spans on the visible photographs in source order. */
@media (width > 1000px) {
    #dc-dilworth-project .gallery {
        grid-template-columns: repeat(12, minmax(0, 1fr));
    }
    #dc-dilworth-project .gallery > figure {
        grid-column: span var(--dc-gallery-desktop-span, 4);
    }
}
@media (700px < width <= 1000px) {
    #dc-dilworth-project .gallery {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
    #dc-dilworth-project .gallery > figure {
        grid-column: span var(--dc-gallery-tablet-span, 3);
    }
}
@media (576px <= width < 768px) {
    #servicesCarousel .row:has(> .col-sm-6:nth-child(3):last-child) > .col-sm-6 {
        width: 33.333333%;
    }
}

/* Keep the existing thumbnail widths for complete stage rows in the service lightbox.
   Redistribute only groups whose last row would otherwise hold one or two photos. */
@media (min-width: 768px) {
    #dc-porch-project-dialog .dc-porch-thumb-grid {
        grid-template-columns: repeat(12, minmax(0, 1fr));
    }
    #dc-porch-project-dialog .dc-porch-thumb-grid > button {
        grid-column: span 2;
    }
    #dc-porch-project-dialog .dc-porch-thumb-grid:has(> :last-child:nth-child(6n + 7)) > button:nth-last-child(-n + 7) {
        grid-column: span 4;
    }
    #dc-porch-project-dialog .dc-porch-thumb-grid:has(> :last-child:nth-child(6n + 7)) > button:nth-last-child(-n + 4),
    #dc-porch-project-dialog .dc-porch-thumb-grid:has(> :last-child:nth-child(6n + 8)) > button:nth-last-child(-n + 8) {
        grid-column: span 3;
    }
}
@media (width < 768px) {
    #dc-porch-project-dialog .dc-porch-thumb-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
    #dc-porch-project-dialog .dc-porch-thumb-grid > button {
        grid-column: span 2;
    }
    #dc-porch-project-dialog .dc-porch-thumb-grid:has(> :last-child:nth-child(3n + 4)) > button:nth-child(-n + 4),
    #dc-porch-project-dialog .dc-porch-thumb-grid:has(> :last-child:nth-child(3n + 5)) > button:nth-child(-n + 2) {
        grid-column: span 3;
    }
}

/* Use short, readable measures for body headings and project notes. */
.type-post #page-content .wp-block-heading,
article.dc-article-archive h2 {
    font-size: clamp(1.5rem, 2.25vw, 2rem);
    line-height: 1.25;
    text-wrap: balance;
}
.type-post #page-content h3.wp-block-heading,
section[aria-labelledby="dc-design-questions"] h3 {
    font-size: clamp(1.3rem, 1.9vw, 1.65rem);
    line-height: 1.3;
    text-wrap: balance;
}
:where(#dc-midcentury, #dc-dilworth-project, .dc-project-story, .dc-brick-porch, #page-content) figure figcaption {
    text-wrap: balance;
}
#dc-midcentury .mc-photo figcaption,
#dc-dilworth-project .gallery figcaption {
    font-size: .9375rem;
    line-height: 1.6;
}
#hero.dc-title-only {
    min-height: 0;
    padding-block: clamp(2rem, 4vw, 3.5rem);
    background: #f7f5f1;
}
#hero.dc-title-only h1 {
    margin: 0;
    color: #29261f;
    font-size: clamp(1.9rem, 3.5vw, 2.75rem);
    line-height: 1.2;
    text-wrap: balance;
}
#testimonial.dc-single-review {
    max-width: 51rem;
    margin: 0 auto;
    padding: clamp(2rem, 4vw, 3.5rem) 1rem;
}
.dc-single-review h1 {
    font-size: clamp(1.75rem, 3vw, 2.5rem);
    margin: 0 0 1.25rem;
}
.dc-single-review blockquote {
    text-align: start;
    padding: clamp(1.25rem, 3vw, 2rem);
    font-size: 1rem;
    line-height: 1.7;
}
.dc-single-review blockquote p:last-of-type {
    margin-bottom: 1.25rem;
}
.dc-single-review .blockquote-footer {
    margin: 0;
    gap: 1rem;
    align-items: baseline;
}

.landing-page-additions .landing-locations #serving-locations,
.landing-page-additions .landing-locations #serving-locations :is(h2, a, small) {
    color: #fff;
}
.landing-page-additions .landing-locations #serving-locations a:hover,
.landing-page-additions .landing-locations #serving-locations a:focus-visible {
    color: #ffed8d;
    text-decoration: underline;
}

.dc-line-ending { white-space: nowrap; }
#hero.dc-title-only h1 { text-align: center; }
#projects .card h3 {
    font-size: clamp(1.35rem, 2vw, 1.7rem);
    line-height: 1.3;
}
