/* =========================================================
   MATURE NERD READER
   Living Archive + Fullscreen Article Reader
   ========================================================= */


/* =========================================================
   GENERATED ARCHIVE WALL
   ========================================================= */

.mn-generated-archive {
    box-sizing: border-box;

    display: grid;

    grid-template-columns: repeat(12, minmax(0, 1fr));

    /*
     * Small invisible rows allow differently sized tiles
     * to pack together instead of creating conventional rows.
     */
    grid-auto-rows: 10px;
    grid-auto-flow: dense;

    gap: 10px;

    width: 100%;
    max-width: 100%;

    margin: 0;
    padding: 10px;
}


/* =========================================================
   GENERATED TILE
   ========================================================= */

.mn-generated-tile {
    position: relative;

    box-sizing: border-box;

    overflow: hidden;

    min-width: 0;

    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;

    cursor: pointer;
}


/* =========================================================
   LIVING COLLAGE GEOMETRY
   ========================================================= */

/*
 * Default tile behavior.
 */

.mn-generated-archive .mn-generated-tile {
    grid-column: span 6;
    grid-row: span 28;

    width: 100%;
    height: 100%;

    aspect-ratio: auto;
}


/*
 * TILE 1
 * Newest article becomes the large opening anchor.
 */

.mn-generated-archive .mn-generated-tile:nth-child(1) {
    grid-column: span 8;
    grid-row: span 40;
}


/*
 * TILE 2
 * Upper-right companion.
 */

.mn-generated-archive .mn-generated-tile:nth-child(2) {
    grid-column: span 4;
    grid-row: span 20;
}


/*
 * TILE 3
 * Slides directly underneath tile 2.
 */

.mn-generated-archive .mn-generated-tile:nth-child(3) {
    grid-column: span 4;
    grid-row: span 20;
}


/*
 * TILE 4 + 5
 * Unequal pair.
 */

.mn-generated-archive .mn-generated-tile:nth-child(4) {
    grid-column: span 5;
    grid-row: span 28;
}


.mn-generated-archive .mn-generated-tile:nth-child(5) {
    grid-column: span 7;
    grid-row: span 28;
}


/*
 * TILE 6 + 7
 * Reverse the visual weight.
 */

.mn-generated-archive .mn-generated-tile:nth-child(6) {
    grid-column: span 7;
    grid-row: span 30;
}


.mn-generated-archive .mn-generated-tile:nth-child(7) {
    grid-column: span 5;
    grid-row: span 30;
}


/*
 * Continuing collage rhythm.
 */

.mn-generated-archive .mn-generated-tile:nth-child(6n + 8) {
    grid-column: span 4;
    grid-row: span 24;
}


.mn-generated-archive .mn-generated-tile:nth-child(6n + 9) {
    grid-column: span 8;
    grid-row: span 24;
}


.mn-generated-archive .mn-generated-tile:nth-child(6n + 10) {
    grid-column: span 7;
    grid-row: span 28;
}


.mn-generated-archive .mn-generated-tile:nth-child(6n + 11) {
    grid-column: span 5;
    grid-row: span 28;
}


.mn-generated-archive .mn-generated-tile:nth-child(6n + 12),
.mn-generated-archive .mn-generated-tile:nth-child(6n + 13) {
    grid-column: span 6;
    grid-row: span 28;
}


/* =========================================================
   ACCESSIBLE TILE TITLE
   Hidden visually because title is already in artwork.
   ========================================================= */

.mn-tile-accessible-title {
    position: absolute !important;

    width: 1px !important;
    height: 1px !important;

    padding: 0 !important;
    margin: -1px !important;

    overflow: hidden !important;

    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;

    border: 0 !important;
}


/* =========================================================
   ARTICLE TILE TRANSITION FOUNDATION
   ========================================================= */

.mn-article-tile {
    transition:
        top 0.55s cubic-bezier(.22, 1, .36, 1),
        left 0.55s cubic-bezier(.22, 1, .36, 1),
        width 0.55s cubic-bezier(.22, 1, .36, 1),
        height 0.55s cubic-bezier(.22, 1, .36, 1),
        border-radius 0.55s ease;
}


/* Reader stays hidden while tile lives in archive. */

.mn-article-tile .mn-reader {
    display: none;
}


/* =========================================================
   PLACEHOLDER
   Holds tile's original position while reader is fullscreen.
   ========================================================= */

.mn-tile-placeholder {
    visibility: hidden;

    pointer-events: none;
}


/* =========================================================
   OPENING / OPEN / CLOSING TILE
   ========================================================= */

.mn-article-tile.mn-opening,
.mn-article-tile.mn-open,
.mn-article-tile.mn-closing {
    position: fixed !important;

    z-index: 999999 !important;

    margin: 0 !important;

    max-width: none !important;

    transform: none !important;

    box-sizing: border-box;

    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
}


/* =========================================================
   FULLSCREEN ARTICLE
   ========================================================= */

.mn-article-tile.mn-open {
    top: 0 !important;
    left: 0 !important;

    width: 100vw !important;
    height: 100vh !important;

    border-radius: 0 !important;

    overflow-y: auto;
    overflow-x: hidden;

    cursor: default;

    background-color: #000;
}


/* =========================================================
   FULLSCREEN READER
   ========================================================= */

.mn-article-tile.mn-open .mn-reader {
    position: relative;

    display: block;

    box-sizing: border-box;

    width: 100%;
    min-height: 100vh;

    margin-top: 58vh;
    margin-right: 0;
    margin-left: 0;

    padding:
        clamp(42px, 6vw, 90px)
        clamp(28px, 8vw, 130px)
        100px;

    background: #fff;

    border-radius: 32px 32px 0 0;

    color: #111;

    cursor: auto;

    opacity: 0;

    transform: translateY(60px);

    transition:
        opacity 0.65s ease,
        transform 0.75s cubic-bezier(.22, 1, .36, 1);
}


/* Reader reveal */

.mn-article-tile.mn-open.mn-reader-ready .mn-reader {
    opacity: 1;

    transform: translateY(0);
}


/* =========================================================
   GHOST FADE
   Featured image dissolves into article.
   ========================================================= */

.mn-article-tile.mn-open .mn-reader::before {
    content: "";

    position: absolute;

    left: 0;
    right: 0;
    top: -180px;

    height: 180px;

    pointer-events: none;

    background:
        linear-gradient(
            to bottom,
            rgba(255,255,255,0),
            rgba(255,255,255,0.10) 18%,
            rgba(255,255,255,0.35) 42%,
            rgba(255,255,255,0.72) 70%,
            rgba(255,255,255,1) 100%
        );
}


/* =========================================================
   ARTICLE CONTENT
   ========================================================= */

.mn-reader-content {
    position: relative;

    z-index: 2;

    width: 100%;
    max-width: 900px;

    margin: 0 auto;
}


.mn-reader-content .mn-article-body {
    width: 100%;
}


.mn-reader-content h1 {
    margin-top: 0;
    margin-bottom: 0.75em;

    font-size: clamp(2.1rem, 4vw, 4.75rem);
    line-height: 0.98;

    overflow-wrap: anywhere;
}


.mn-reader-content h2 {
    margin-top: 1.8em;
    margin-bottom: 0.65em;

    line-height: 1.1;
}


.mn-reader-content h3 {
    margin-top: 1.5em;
    margin-bottom: 0.55em;

    line-height: 1.15;
}


.mn-reader-content p,
.mn-reader-content li {
    line-height: 1.7;
}


.mn-reader-content img,
.mn-reader-content video,
.mn-reader-content iframe {
    max-width: 100%;
    height: auto;
}


/* =========================================================
   LOADING / ERROR / EMPTY STATES
   ========================================================= */

.mn-reader-loading,
.mn-reader-error,
.mn-archive-empty {
    box-sizing: border-box;

    width: 100%;

    padding: 32px;

    font-weight: 700;
    line-height: 1.5;
}


.mn-reader-error {
    color: #8a0000;
}


.mn-archive-empty {
    grid-column: 1 / -1;

    text-align: center;
}


/* =========================================================
   RETURN TO ARCHIVE BUTTON
   ========================================================= */

.mn-return {
    position: sticky !important;

    top: 24px !important;

    float: right;

    margin-top: 24px;
    margin-right: 24px;

    z-index: 1000001 !important;

    display: none;

    box-sizing: border-box;

    padding: 13px 18px;

    border: 0;
    border-radius: 999px;

    background: rgba(0, 0, 0, 0.82);

    color: #fff;

    font: inherit;
    font-size: 13px;
    font-weight: 800;

    letter-spacing: 0.08em;

    cursor: pointer;

    box-shadow: 0 8px 30px rgba(0,0,0,0.22);

    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}


.mn-article-tile.mn-open .mn-return {
    display: block;
}


.mn-return:hover,
.mn-return:focus-visible {
    background: #000;
}


.mn-return:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}


/* =========================================================
   PAGE LOCK WHILE READER IS OPEN
   ========================================================= */

body.mn-reader-active {
    overflow: hidden !important;
}


/* =========================================================
   TABLET / MOBILE
   ========================================================= */

@media (max-width: 767px) {

    /*
     * Mobile returns to a simple vertical stream.
     * The desktop collage should not play Tetris on a phone.
     */

    .mn-generated-archive {
        grid-template-columns: 1fr;
        grid-auto-rows: auto;

        gap: 8px;

        padding: 8px;
    }


    .mn-generated-archive .mn-generated-tile,
    .mn-generated-archive .mn-generated-tile:nth-child(n) {
        grid-column: 1 / -1;
        grid-row: auto;

        width: 100%;
        height: auto;

        aspect-ratio: 16 / 9;
    }


    /*
     * Fullscreen reader.
     */

    .mn-article-tile.mn-open .mn-reader {
        width: calc(100% - 24px);

        min-height: 100vh;

        margin-top: 56vh;
        margin-right: 12px;
        margin-left: 12px;

        padding:
            42px
            22px
            80px;

        border-radius: 24px 24px 0 0;
    }


    .mn-article-tile.mn-open .mn-reader::before {
        top: -140px;

        height: 140px;
    }


    .mn-return {
        top: 14px;
        right: 14px;

        padding: 11px 14px;

        font-size: 12px;
    }


    .mn-reader-content h1 {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }
}


/* =========================================================
   SMALL PHONES
   ========================================================= */

@media (max-width: 430px) {

    .mn-article-tile.mn-open .mn-reader {
        width: calc(100% - 16px);

        margin-right: 8px;
        margin-left: 8px;

        padding:
            36px
            18px
            70px;
    }

    .mn-return {
        font-size: 11px;
        margin-top: 16px;
        margin-right: 16px;
    }

    .mn-return::after {
        content: none;
    }
}

/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

    .mn-article-tile,
    .mn-article-tile.mn-open .mn-reader {
        transition: none !important;
    }
}

/* =========================================================
   HOMEPAGE LATEST POST WINDOW
   ========================================================= */

.mn-latest-post {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    text-decoration: none !important;
    cursor: pointer;
}

.mn-latest-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0);
    transition: background .3s ease;
}

.mn-latest-read {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 26px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: rgba(0, 0, 0, .65);
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: .12em;
    opacity: 0;
    transform: translateY(10px);
    transition:
        opacity .3s ease,
        transform .3s ease,
        background .3s ease;
}

.mn-latest-post:hover .mn-latest-overlay,
.mn-latest-post:focus-visible .mn-latest-overlay {
    background: rgba(0, 0, 0, .28);
}

.mn-latest-post:hover .mn-latest-read,
.mn-latest-post:focus-visible .mn-latest-read {
    opacity: 1;
    transform: translateY(0);
}

.mn-latest-post:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 3px;
}


/* Touch devices have no meaningful hover.
   The entire image remains tappable. */

@media (hover: none) {

    .mn-latest-read {
        display: none;
    }

}

/* =========================================================
   HOMEPAGE LATEST POST PLACEMENT
   ========================================================= */

.mn-home-latest .elementor-widget-container,
.mn-home-latest .elementor-shortcode {
    width: 100%;
    height: 100%;
}

.mn-home-latest .mn-latest-post {
    display: block;
    width: 100% !important;
    height: 100% !important;
    min-height: 100%;
    aspect-ratio: auto !important;

    background-size: cover !important;
    background-position: center center !important;
    background-repeat: no-repeat !important;
}

/* =========================================================
   TABLET
   ========================================================= */

@media (min-width: 768px) and (max-width: 1024px) {

    .mn-home-latest .elementor-widget-container,
    .mn-home-latest .elementor-shortcode {
        width: 100% !important;
        height: auto !important;
    }

    .mn-home-latest .mn-latest-post {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        aspect-ratio: 16 / 9 !important;

        background-size: cover !important;
        background-position: center center !important;
        background-repeat: no-repeat !important;
    }

}


/* Mobile */
@media (max-width: 767px) {

    .mn-home-latest {
        width: 100% !important;
        height: auto !important;
    }

    .mn-home-latest .elementor-widget-container,
    .mn-home-latest .elementor-shortcode {
        width: 100% !important;
    }

    .mn-home-latest .mn-latest-post {
        width: 135% !important;
        max-width: none !important;
        height: auto !important;
        min-height: 0 !important;
        aspect-ratio: 16 / 9 !important;

        margin-left: 50% !important;
        transform: translateX(-50%);

        background-size: contain !important;
        background-position: center center !important;
        background-repeat: no-repeat !important;
    }
}