/* Case study card (partials/story-card): paper card with a layered scene. */

/* Case studies: white paper cards with a layered paper-cut scene that drifts apart on hover */
.story-card {
    display: flex;
    flex-direction: column;
    background: #fff;
    box-shadow: 6px 6px 0 rgb(49 54 70 / 0.08), 0 0 0 1px rgb(49 54 70 / 0.06);
    transition: transform 0.4s ease-out, box-shadow 0.4s ease-out;
}

.story-card:hover,
.story-card:focus-visible {
    transform: translateY(-8px);
    box-shadow: 10px 16px 0 rgb(49 54 70 / 0.1), 0 0 0 1px rgb(49 54 70 / 0.06);
}

.story-art {
    position: relative;
    display: block;
    aspect-ratio: 16 / 11;
    overflow: hidden;
    background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
}

.story-art svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.story-back,
.story-mid {
    transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.story-card:hover .story-back { transform: translateY(5px); }
.story-card:hover .story-mid { transform: translateY(-6px); }

.story-tag {
    position: absolute;
    top: 14px;
    left: 14px;
    padding: 2px 12px 4px;
    background: #fff;
    font-family: var(--font-script);
    font-size: 19px;
    line-height: 1.2;
    color: var(--color-teal-dark);
    box-shadow: 3px 3px 0 rgb(49 54 70 / 0.1);
}

.story-sdg {
    /* goal chips stay on one line each and wrap onto the next row when a story serves many goals */
    white-space: nowrap;
    padding: 3px 8px;
    background: var(--goal);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #fff;
}

@media (prefers-reduced-motion: reduce) {
    .story-card,
    .story-back,
    .story-mid {
        transition: none;
    }
}

/* cover fallback when no photo was uploaded: the main goal's paper model on its colour */
.cover-fallback {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 50% 60%, rgb(255 255 255 / 0.18), transparent 60%),
        var(--goal);
}

.cover-fallback svg,
.story-art .cover-fallback svg,
.event-card-photo .cover-fallback svg {
    position: static;
    width: 34%;
    height: auto;
    max-width: 140px;
    filter: drop-shadow(4px 5px 0 rgb(0 0 0 / 0.18));
}

/* On phones the home page's card rows (case studies, news, events) stack one under the other, like the list pages */

/* the headline: a reading size, at most three lines (long Thai titles end in "…", the full one shows on hover),
   and always three lines tall so every card in a row lines up */
.story-title {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    min-height: calc(3 * 1.6em);
    font-size: 16px;
    line-height: 1.6;
}

/* the home page's case studies and news (.is-rail): the first card large — two columns wide and two rows tall —
   with the next four as a 2 × 2 block beside it; news (.is-flip) puts the large one on the right */
@media (min-width: 1024px) {
    .is-rail .card-grid:has(> .story-card:nth-child(5)) {
        grid-auto-flow: dense;
    }

    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) {
        grid-column: 1 / span 2;
        grid-row: 1 / span 2;
    }

    .is-rail .card-grid.is-flip > .story-card:first-child:nth-last-child(5) {
        grid-column: 3 / span 2;
    }

    /* the large card's picture grows to fill its height, its headline is larger */
    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) .story-art {
        flex: 1;
        aspect-ratio: auto;
        min-height: 320px;
    }

    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) .story-title {
        font-size: 22px;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        min-height: calc(2 * 1.6em);
    }
}

@media (min-width: 1024px) {
    /* the words under the large card's picture take only the room they need; the picture takes the rest */
    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) > span:last-child {
        flex: none;
    }
}

/* the date under the goal chips, with a small calendar */
.story-date {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: color-mix(in srgb, var(--color-navy) 55%, #fff);
}

.story-date svg {
    width: 14px;
    height: 14px;
}

/* the summary: only on the large card of the home page's rows, where there is room for it */
.story-summary {
    display: none;
}

@media (min-width: 1024px) {
    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) .story-summary {
        display: -webkit-box;
        overflow: hidden;
        margin-top: 10px;
        font-size: 15px;
        line-height: 1.7;
        color: color-mix(in srgb, var(--color-navy) 65%, #fff);
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        line-clamp: 3;
    }

    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) .story-date {
        font-size: 13px;
    }
}

/* a calmer size for the home page's large-first rows: the small cards a little shorter (wider picture, two-line
   headline), the large card's picture filling no more than the two small rows beside it */
@media (min-width: 1024px) {
    .is-rail .card-grid:has(> .story-card:nth-child(5)) {
        gap: 20px;
    }

    .is-rail .card-grid:has(> .story-card:nth-child(5)) > .story-card:not(:first-child) .story-art {
        aspect-ratio: 16 / 9;
    }

    .is-rail .card-grid:has(> .story-card:nth-child(5)) > .story-card:not(:first-child) > span:last-child {
        padding: 14px 16px 16px;
    }

    .is-rail .card-grid:has(> .story-card:nth-child(5)) > .story-card:not(:first-child) .story-title {
        font-size: 15px;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        min-height: calc(2 * 1.6em);
    }

    .is-rail .card-grid:has(> .story-card:nth-child(5)) > .story-card:not(:first-child) .story-title + * ,
    .is-rail .card-grid:has(> .story-card:nth-child(5)) > .story-card:not(:first-child) span.mt-auto {
        padding-top: 10px;
    }

    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) .story-art {
        min-height: 0;
    }

    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) > span:last-child {
        padding: 18px 22px 20px;
    }

    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) .story-title {
        font-size: 19px;
    }

    .is-rail .card-grid > .story-card:first-child:nth-last-child(5) .story-summary {
        -webkit-line-clamp: 2;
        line-clamp: 2;
        font-size: 14px;
    }
}

/* "+N": the goals a card has no room for (components/ui/sdg-chips), grey, named on hover */
.story-sdg.is-more,
.about-goal.is-more {
    background: #e3e7ec;
    color: #5b6372;
    cursor: help;
}

/* on the cards the chips are a touch smaller and closer, so five of them (or four and "+N") share one row */
.story-card .story-sdg,
.event-card .story-sdg,
.doc-sheet .story-sdg {
    padding: 2px 6px;
    font-size: 10px;
    letter-spacing: 0.02em;
}

/* the date and how often an item has been opened, side by side (cards and item pages) */
.story-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 14px;
}

/* "👁 1,204 views": how often an item, a document or a goal's page has been opened (App\Support\Analytics\Visits) */
.view-count {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    color: color-mix(in srgb, var(--color-navy) 55%, #fff);
}

.view-count svg {
    flex: none;
    width: 14px;
    height: 14px;
}

/* on a goal's sky: white */
.view-count.is-light {
    font-size: 13px;
    color: #fff;
    text-shadow: 0 1px 8px rgb(30 70 110 / 0.35);
}

/* the home page's events (.is-rail) on a laptop: like the case studies and news, the newest large — two columns wide,
   two rows tall, its picture filling the height — and the next four as a 2 × 2 block beside it */
@media (min-width: 1024px) {
    .is-rail .card-grid:has(> .event-card:nth-child(5)) {
        grid-auto-flow: dense;
        gap: 20px;
    }

    .is-rail .card-grid > .event-card:first-child:nth-last-child(5) {
        grid-column: 1 / span 2;
        grid-row: 1 / span 2;
    }

    .is-rail .card-grid > .event-card:first-child:nth-last-child(5) .event-card-photo {
        flex: 1;
        aspect-ratio: auto;
        min-height: 300px;
    }

    .is-rail .card-grid > .event-card:first-child:nth-last-child(5) .event-card-title {
        font-size: 22px;
    }

    /* the words take only the room they need, the picture the rest */
    .is-rail .card-grid > .event-card:first-child:nth-last-child(5) .event-card-body {
        flex: none;
    }

    .is-rail .card-grid:has(> .event-card:nth-child(5)) > .event-card:not(:first-child) .event-card-photo {
        aspect-ratio: 16 / 8;
    }

    .is-rail .card-grid:has(> .event-card:nth-child(5)) > .event-card:not(:first-child) .event-card-desc {
        display: none;
    }
}

/* the home page's rows (.is-rail) on a phone: the newest card wide across the top and lying on its side — picture on
   the left, words on the right — then the rest two to a row (.phone-two in pages/goal.css) */
@media (max-width: 639px) {
    .is-rail .phone-two > :first-child {
        grid-column: 1 / -1;
    }

    /* news and case studies */
    .is-rail .phone-two > .story-card:first-child {
        flex-direction: row;
    }

    .is-rail .phone-two > .story-card:first-child .story-art {
        flex: 0 0 46%;
        aspect-ratio: auto;
        min-height: 170px;
    }

    .is-rail .phone-two > .story-card:first-child > span:last-child {
        flex: 1;
        min-width: 0;
        padding: 12px 12px 12px;
    }

    .is-rail .phone-two > .story-card:first-child .story-title {
        font-size: 14px;
        line-height: 1.45;
        min-height: 0;
    }

    /* events: picture left, details right, the colour stripe still along the foot */
    .is-rail .phone-two > .event-card:first-child {
        display: grid;
        grid-template-columns: 46% minmax(0, 1fr);
        grid-template-rows: 1fr auto;
    }

    .is-rail .phone-two > .event-card:first-child .event-card-photo {
        aspect-ratio: auto;
        min-height: 170px;
    }

    .is-rail .phone-two > .event-card:first-child .event-card-body {
        border-top: 0;
        border-left: 2px dashed #e3e8ee;
    }

    .is-rail .phone-two > .event-card:first-child .event-card-body::before,
    .is-rail .phone-two > .event-card:first-child .event-card-body::after {
        display: none;
    }

    .is-rail .phone-two > .event-card:first-child .event-stripes {
        grid-column: 1 / -1;
    }

    .is-rail .phone-two > .event-card:first-child .event-card-title {
        font-size: 14px;
    }
}
