/*
 * Substack Article Grid
 * Intentionally minimal so it resembles Substack's clean publication grids
 * while allowing typography to be configured in WordPress.
 */

.sag-grid {
    --sag-columns: 3;
    --sag-font-family: inherit;
    --sag-title-size: 29px;
    --sag-excerpt-size: 18px;
    --sag-date-size: 14px;
    --sag-article-spacing: 42px;

    display: grid;
    grid-template-columns: repeat(var(--sag-columns), minmax(0, 1fr));
    column-gap: var(--sag-article-spacing);
    row-gap: var(--sag-article-spacing);
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--sag-font-family);
}

.sag-card {
    min-width: 0;
    margin: 0;
    padding: 0;
}

.sag-card__image-link {
    display: block;
    margin: 0 0 20px;
    border: 0;
    text-decoration: none;
}

.sag-card__image {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: cover;
    border-radius: 6px;
    background: #f1f1f1;
}

.sag-card__image--placeholder {
    background:
        linear-gradient(135deg, rgba(0, 0, 0, 0.035), rgba(0, 0, 0, 0.08));
}

.sag-grid .sag-card .sag-card__title {
    margin: 0 0 7px;
    padding: 0;
    font-family: var(--sag-font-family) !important;
    font-size: var(--sag-title-size) !important;
    font-weight: 700;
    line-height: 1.18;
    letter-spacing: -0.02em;
}

/*
 * Set the size explicitly on the link as well as the H2. Many WordPress
 * themes apply their own font-size directly to heading links, which prevents
 * the link from inheriting the configured size from the H2.
 */
.sag-grid .sag-card .sag-card__title > a {
    color: inherit;
    font-family: var(--sag-font-family) !important;
    font-size: var(--sag-title-size) !important;
    font-weight: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    text-decoration: none;
}

.sag-card__title a:hover,
.sag-card__title a:focus-visible {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.sag-card__excerpt {
    margin: 0 0 11px;
    color: inherit;
    opacity: 0.86;
    font-family: var(--sag-font-family);
    font-size: var(--sag-excerpt-size);
    line-height: 1.35;

    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}



/* Grid short-byline subtitles should always display in full. */
.sag-grid .sag-card__subtitle {
    display: block;
    overflow: visible;
    -webkit-box-orient: initial;
    -webkit-line-clamp: unset;
    line-clamp: unset;
    white-space: normal;
}

.sag-card__date {
    display: block;
    margin-top: 12px;
    color: inherit;
    opacity: 0.55;
    font-family: var(--sag-font-family);
    font-size: var(--sag-date-size);
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}


/* Featured article ---------------------------------------------------------
 * When an odd article count is requested, the first article spans the full
 * grid width as a hero. The remaining even number of articles flows normally.
 */
.sag-grid > .sag-card--featured {
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: hidden;
    box-sizing: border-box;
}

.sag-grid > .sag-card--featured > .sag-featured__link {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
    color: #fff;
    text-decoration: none !important;
    border: 0;
}

.sag-grid > .sag-card--featured > .sag-featured__link > .sag-featured__media {
    position: relative;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 340px;
    aspect-ratio: 2.35 / 1;
    overflow: hidden;
    box-sizing: border-box;
    border-radius: 6px;
    background: #222;
    isolation: isolate;
}

.sag-featured__image {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.001);
    transition: transform 280ms ease;
}

.sag-featured__image--placeholder {
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.2)),
        #333;
}

.sag-featured__shade {
    position: absolute;
    inset: 0;
    z-index: 1;
    background:
        linear-gradient(
            90deg,
            rgba(0, 0, 0, 0.82) 0%,
            rgba(0, 0, 0, 0.66) 38%,
            rgba(0, 0, 0, 0.30) 68%,
            rgba(0, 0, 0, 0.08) 100%
        );
}

.sag-featured__content {
    position: absolute;
    z-index: 2;
    left: clamp(28px, 5vw, 64px);
    right: clamp(28px, 40%, 520px);
    bottom: clamp(30px, 8vw, 78px);
    color: #fff;
}

.sag-grid .sag-card--featured .sag-featured__title {
    margin: 0 0 10px;
    color: #fff !important;
    font-family: var(--sag-font-family) !important;
    font-size: clamp(
        var(--sag-title-size),
        calc(var(--sag-title-size) * 1.35),
        64px
    ) !important;
    font-weight: 700;
    line-height: 1.08;
    letter-spacing: -0.025em;
    text-wrap: balance;
}

.sag-card--featured .sag-featured__excerpt {
    max-width: 720px;
    margin: 0 0 12px;
    color: #fff;
    opacity: 0.92;
    font-family: var(--sag-font-family);
    font-size: var(--sag-excerpt-size);
    line-height: 1.4;
}

.sag-card--featured .sag-featured__date {
    margin: 0 0 18px;
    color: #fff;
    opacity: 0.78;
    font-family: var(--sag-font-family);
    font-size: var(--sag-date-size);
}

.sag-featured__cta {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    margin-top: 8px;
    font-family: var(--sag-font-family);
    font-size: max(11px, calc(var(--sag-date-size) * 0.88));
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sag-featured__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    border-radius: 999px;
    background: #fff;
    color: #111;
    font-size: 24px;
    font-weight: 400;
    line-height: 1;
    transition:
        transform 180ms ease,
        background-color 180ms ease;
}

.sag-featured__link:hover .sag-featured__image,
.sag-featured__link:focus-visible .sag-featured__image {
    transform: scale(1.018);
}

.sag-featured__link:hover .sag-featured__arrow,
.sag-featured__link:focus-visible .sag-featured__arrow {
    transform: translateX(3px);
}

.sag-featured__link:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 4px;
}

.sag-message {
    padding: 12px 14px;
    border: 1px solid currentColor;
    border-radius: 4px;
}

.sag-message--warning,
.sag-message--error {
    font-weight: 600;
}

@media (max-width: 900px) {
    .sag-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sag-featured__media {
        aspect-ratio: 16 / 8;
        min-height: 330px;
    }

    .sag-featured__content {
        right: clamp(28px, 22vw, 220px);
    }
}

@media (max-width: 620px) {
    .sag-grid {
        grid-template-columns: 1fr;
    }

    .sag-card__image-link {
        margin-bottom: 16px;
    }

    /*
     * Single-column/mobile view intentionally disables the hero treatment.
     * The featured article is restyled as a normal article card so the first
     * item does not become an oversized panel on small screens.
     */
    .sag-grid > .sag-card--featured {
        grid-column: auto;
        overflow: visible;
    }

    .sag-grid > .sag-card--featured > .sag-featured__link {
        display: block;
        color: inherit;
        text-decoration: none !important;
    }

    .sag-grid > .sag-card--featured > .sag-featured__link > .sag-featured__media {
        position: static;
        min-height: 0;
        aspect-ratio: auto;
        overflow: visible;
        border-radius: 0;
        background: transparent;
        isolation: auto;
    }

    .sag-card--featured .sag-featured__image {
        position: static;
        inset: auto;
        width: 100%;
        height: auto;
        aspect-ratio: 3 / 2;
        margin: 0 0 16px;
        object-fit: cover;
        border-radius: 6px;
        transform: none !important;
    }

    .sag-card--featured .sag-featured__image--placeholder {
        display: block;
        aspect-ratio: 3 / 2;
        background:
            linear-gradient(135deg, rgba(0, 0, 0, 0.035), rgba(0, 0, 0, 0.08));
    }

    .sag-card--featured .sag-featured__shade {
        display: none;
    }

    .sag-card--featured .sag-featured__content {
        position: static;
        color: inherit;
    }

    .sag-grid .sag-card--featured .sag-featured__title {
        margin: 0 0 7px;
        color: inherit !important;
        font-size: var(--sag-title-size) !important;
        font-weight: 700;
        line-height: 1.18;
        letter-spacing: -0.02em;
        text-wrap: initial;
    }

    .sag-card--featured .sag-featured__excerpt {
        max-width: none;
        margin: 0 0 11px;
        color: inherit;
        opacity: 0.86;
        font-size: var(--sag-excerpt-size);
        line-height: 1.35;
    }

    .sag-card--featured .sag-featured__date {
        display: block;
        margin-top: 12px;
        margin-bottom: 0;
        color: inherit;
        opacity: 0.55;
        font-size: var(--sag-date-size);
        font-weight: 500;
        line-height: 1.2;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    .sag-card--featured .sag-featured__cta {
        display: none;
    }
}


/* Newspaper layout ---------------------------------------------------------
 * Persistent two-column newspaper for [article_feed_newspaper].
 *
 * Left 2/3: expanded full-feed articles.
 * Right 1/3: compact article cards.
 */
.sag-newspaper {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    color: inherit;
    font-family: var(--sag-font-family);
}

.sag-newspaper *,
.sag-newspaper *::before,
.sag-newspaper *::after {
    box-sizing: border-box;
}

.sag-newspaper__rule {
    width: 100%;
    height: 1px;
    margin: var(--sag-article-spacing) 0 0;
    background: currentColor;
    opacity: 0.2;
}

.sag-newspaper__rule--heavy {
    height: 3px;
    margin: 0 0 clamp(14px, 1.6vw, 22px);
    opacity: 0.86;
}

.sag-newspaper__columns {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr);
    gap: var(--sag-article-spacing);
    align-items: start;
    width: 100%;
    min-width: 0;
}

.sag-newspaper__full-column,
.sag-newspaper__card-column {
    min-width: 0;
}

.sag-newspaper__full-column {
    display: grid;
    gap: var(--sag-article-spacing);
}

.sag-newspaper__card-column {
    display: grid;
    gap: var(--sag-article-spacing);
    padding-left: var(--sag-article-spacing);
    border-left: 1px solid rgba(0, 0, 0, 0.18);
}

.sag-newspaper__full-article {
    min-width: 0;
    padding-bottom: var(--sag-article-spacing);
    border-bottom: 1px solid rgba(0, 0, 0, 0.16);
}

.sag-newspaper__card {
    min-width: 0;
    padding-bottom: var(--sag-article-spacing);
    border-bottom: 1px solid rgba(0, 0, 0, 0.16);
}

.sag-newspaper__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 5px 10px;
    margin: 0 0 8px;
}

.sag-newspaper__source {
    font-family: var(--sag-font-family);
    font-size: var(--sag-date-size);
    font-weight: 750;
    line-height: 1.2;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sag-newspaper__date {
    display: inline;
    margin: 0;
    color: inherit;
    opacity: 0.56;
    font-family: var(--sag-font-family);
    font-size: var(--sag-date-size);
    font-weight: 550;
    line-height: 1.2;
    letter-spacing: 0.02em;
}

.sag-newspaper .sag-newspaper__full-title {
    margin: 0 0 12px;
    padding: 0;
    font-family: var(--sag-font-family) !important;
    font-size: clamp(
        calc(var(--sag-title-size) * 1.12),
        calc(var(--sag-title-size) * 1.42),
        52px
    ) !important;
    font-weight: 800;
    line-height: 1.03;
    letter-spacing: -0.034em;
}

.sag-newspaper .sag-newspaper__card-title {
    margin: 0 0 8px;
    padding: 0;
    font-family: var(--sag-font-family) !important;
    font-size: max(18px, calc(var(--sag-title-size) * 0.82)) !important;
    font-weight: 760;
    line-height: 1.12;
    letter-spacing: -0.02em;
}

.sag-newspaper .sag-newspaper__full-title a,
.sag-newspaper .sag-newspaper__card-title a {
    color: inherit;
    font: inherit !important;
    text-decoration: none;
}

.sag-newspaper .sag-newspaper__full-title a:hover,
.sag-newspaper .sag-newspaper__full-title a:focus-visible,
.sag-newspaper .sag-newspaper__card-title a:hover,
.sag-newspaper .sag-newspaper__card-title a:focus-visible {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.sag-newspaper__full-body {
    font-family: var(--sag-font-family);
    font-size: var(--sag-excerpt-size);
    line-height: 1.55;
    opacity: 0.84;
}

.sag-newspaper__card-subtitle {
    font-family: var(--sag-font-family);
    font-size: max(13px, calc(var(--sag-excerpt-size) * 0.88));
    line-height: 1.45;
    opacity: 0.8;
}

.sag-newspaper__body p {
    margin: 0 0 0.82em;
}

.sag-newspaper__body p:last-child {
    margin-bottom: 0;
}

.sag-newspaper__body ul,
.sag-newspaper__body ol {
    margin: 0.7em 0 0.9em 1.2em;
    padding: 0;
}

.sag-newspaper__body blockquote {
    margin: 0.9em 0;
    padding-left: 1em;
    border-left: 3px solid rgba(0, 0, 0, 0.2);
    font-style: italic;
}

.sag-newspaper__body h2,
.sag-newspaper__body h3,
.sag-newspaper__body h4 {
    margin: 1em 0 0.45em;
    font-family: var(--sag-font-family);
    font-weight: 760;
    line-height: 1.15;
}

.sag-newspaper__body a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.sag-newspaper__body pre {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
}

.sag-newspaper__full-image-link,
.sag-newspaper__card-image-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.sag-newspaper__full-image-link {
    margin: 0 0 16px;
}

.sag-newspaper__full-image {
    display: block;
    width: 100%;
    max-height: 380px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

.sag-newspaper__card-image-link {
    margin: 0 0 11px;
}

.sag-newspaper__card-image {
    display: block;
    width: 100%;
    max-height: 180px;
    aspect-ratio: 3 / 2;
    object-fit: cover;
}

@media (max-width: 900px) {
    .sag-newspaper__columns {
        grid-template-columns: minmax(0, 1.6fr) minmax(220px, 1fr);
    }

    .sag-newspaper__card-column {
        padding-left: clamp(16px, 2.5vw, var(--sag-article-spacing));
    }
}

@media (max-width: 700px) {
    .sag-newspaper__columns {
        display: block;
    }

    .sag-newspaper__card-column {
        margin-top: var(--sag-article-spacing);
        padding: var(--sag-article-spacing) 0 0;
        border-left: 0;
        border-top: 2px solid currentColor;
    }
}

@media (max-width: 520px) {
    .sag-newspaper .sag-newspaper__full-title {
        font-size: max(var(--sag-title-size), 28px) !important;
    }
}


/* Article bylines -------------------------------------------------------- */
.sag-card__byline,
.sag-newspaper__byline {
    font-family: var(--sag-font-family);
    line-height: 1.35;
}

.sag-card__byline {
    margin: -2px 0 9px;
    font-size: max(11px, calc(var(--sag-date-size) * 0.95));
    font-weight: 650;
    opacity: 0.7;
}

.sag-newspaper__byline {
    margin: -2px 0 12px;
    font-size: max(12px, var(--sag-date-size));
    font-weight: 650;
    opacity: 0.72;
}

.sag-newspaper__byline--long {
    max-width: 72ch;
    font-weight: 550;
}


/* Newspaper continuation links ------------------------------------------ */
.sag-newspaper__continue {
    margin-top: 12px;
    text-align: right;
    font-family: var(--sag-font-family);
    font-size: var(--sag-date-size);
    font-weight: 550;
    line-height: 1.2;
}

.sag-newspaper__continue-publication {
    font-weight: 750;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sag-newspaper__continue a {
    color: inherit;
    text-decoration: none;
}

.sag-newspaper__continue a:hover,
.sag-newspaper__continue a:focus-visible {
    text-decoration: underline;
    text-underline-offset: 3px;
}



/* Newspaper archive infinite scroll --------------------------------------- */
.sag-newspaper__load-sentinel {
    min-height: 1px;
    width: 100%;
}

.sag-newspaper__loading {
    margin: 26px 0;
    text-align: center;
    font: inherit;
    opacity: .65;
}
