/*************************************************************************************
*
* Page transition
*
*************************************************************************************/

/* The Feed page opens without the site's page transition. */
@view-transition{
    navigation: none;
}

/*************************************************************************************
*
* Base
*
* Every rule starts with .feed-page, because the editor loads this file too.
*
*************************************************************************************/

.feed-page{
    --grid-step: 24px;
    --grid-line-width: 1px;
    --article-width: calc(var(--grid-step) * 26);
    --wide-width: 1440px;

    --page-color: #f5f5f5;
    --ink-color: rgba(0, 0, 0, 0.9);
    --muted-color: rgba(0, 0, 0, 0.5);
    --grid-line-color: rgba(62, 70, 59, 0.05);
    --accent-color: #e33120;

    margin: 0;
    container-type: inline-size;
    color-scheme: light;
    background-color: var(--page-color);
    color: var(--ink-color);
    font-family: Menlo, monospace;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    font-size: 16px;
    line-height: var(--grid-step);
}

.feed-page *{
    box-sizing: border-box;
}

.feed-page a{
    color: inherit;
    text-decoration: none;
    text-underline-offset: 2px;
}

.feed-page a:hover,
.feed-page a:active{
    text-decoration: underline;
}

.feed-page a:focus-visible,
.feed-page button:focus-visible{
    outline: 2px solid var(--accent-color);
    outline-offset: 3px;
}

/*************************************************************************************
*
* Page
*
*************************************************************************************/

.feed-page main{
    min-height: 100dvh;
    padding-bottom: var(--grid-step);

    /* Vertical lines, a strip hiding the first horizontal line, then horizontal lines. */
    background-image:
        linear-gradient(90deg, var(--grid-line-color) var(--grid-line-width), transparent var(--grid-line-width)),
        linear-gradient(var(--page-color), var(--page-color)),
        linear-gradient(var(--grid-line-color) var(--grid-line-width), transparent var(--grid-line-width));
    background-size:
        var(--grid-step) var(--grid-step),
        100% var(--grid-line-width),
        var(--grid-step) var(--grid-step);
    background-position:
        calc(50% + var(--grid-step) / 2) top,
        left top,
        calc(50% + var(--grid-step) / 2) top;
    background-repeat: repeat, no-repeat, repeat;
}

.feed-page main > .header,
.feed-page main > .feed,
.feed-page main > .footer{
    width: min(var(--article-width), round(down, calc(100% - var(--grid-step) * 2), calc(var(--grid-step) * 2)));
    margin-inline: auto;
}

/*************************************************************************************
*
* Header and footer
*
*************************************************************************************/

/* Each text line is one grid row, its baseline on the row's bottom line */
.feed-page .header,
.feed-page .footer{
    display: grid;
    font-family: Menlo, monospace;
    font-size: 14px;
}

.feed-page .header{
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
        "mark title name"
        "mark description description";
    padding-top: calc(var(--grid-step) * 3);
}

.feed-page .footer{
    grid-template-columns: auto minmax(0, 1fr);
    align-items: end;
    padding-top: calc(var(--grid-step) * 4);
}

.feed-page :is(.header, .footer) :is(.title, .description, .name){
    height: var(--grid-step);
    margin: 0;
    padding-top: calc(var(--grid-step) - 1cap);
    font-size: inherit;
    line-height: var(--grid-step);
    text-box-trim: trim-both;
    text-box-edge: cap alphabetic;
    white-space: nowrap;
}

/* TV icon: two cells in the header, one in the footer */
.feed-page .mark{
    display: block;
    margin-right: 12px;
}

.feed-page .header .mark{
    grid-area: mark;
    width: calc(var(--grid-step) * 2);
    height: calc(var(--grid-step) * 2);
}

.feed-page .footer .mark{
    width: var(--grid-step);
    height: var(--grid-step);
}

.feed-page .mark svg{
    display: block;
    width: 100%;
    height: 100%;
}

/* The TV's light pulses slowly */
.feed-page .mark .light{
    animation: feed_light_pulse 2400ms ease-in-out infinite alternate;
}

@keyframes feed_light_pulse{
    from{
        opacity: 1;
    }

    to{
        opacity: 0.25;
    }
}

@media (prefers-reduced-motion: reduce){
    .feed-page .mark .light{
        animation: none;
    }
}

.feed-page .header .title{
    grid-area: title;
    font-weight: 700;
}

.feed-page .header .description{
    grid-area: description;
    color: var(--muted-color);
}

.feed-page .header .name{
    grid-area: name;
}

.feed-page .name{
    justify-self: end;
}

/* Narrow: the name goes on its own row, under the description */
@container (max-width: 359px){
    .feed-page .header{
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-areas:
            "mark title"
            "mark description"
            ". name";
    }

    .feed-page .header .name{
        margin-top: var(--grid-step);
    }
}

/*************************************************************************************
*
* Entries
*
* .feed-editor is the same content while editing in the editor.
*
*************************************************************************************/

.feed-page .entry{
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    padding-top: calc(var(--grid-step) * 3);
    scroll-margin-top: calc(-2 * var(--grid-step));
}

.feed-page .date{
    justify-self: start;
    color: var(--muted-color);
    font-size: 14px;
    line-height: var(--grid-step);
    height: var(--grid-step);
}

.feed-page :is(.entry, .feed-editor) > p{
    /* --text-size is the value applied by the editor. 16 is the default. */
    --line: round(up, calc(var(--text-size, 16px) * var(--text-leading, 1.4)), var(--grid-step));
    font-weight: var(--text-weight, 400);
    color: var(--text-ink, inherit);
}

/* Links in entry text use the browser's own colors: blue, and purple once visited. */
.feed-page :is(.entry, .feed-editor) > p a{
    color: revert;
    text-decoration: underline;
}

/* The date has a fixed height of one step, so trimming its text cannot change its height. */
.feed-page .date{
    text-box-trim: trim-both;
    text-box-edge: cap alphabetic;
    padding-top: calc(round(up, 1cap, var(--grid-step)) - 1cap);
    position: relative;
}

/*
 * The trimmed box ends on the baseline, so the permalink would not respond below it.
 * This invisible strip under the box extends the hover and click area by a quarter step, without moving anything.
 * It starts at the baseline, so the text itself stays selectable letter by letter.
 */
.feed-page .date::after{
    content: "";
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: calc(var(--grid-step) / 4);
}

/*
 * Paragraphs on the grid, for any font.
 *
 * The paragraph has a font size of 0, so its lines are exactly --line tall
 * with the baseline exactly in the middle, whatever font the reader has.
 * Its text sits in one wrapper span, with the real size and no line height of its own.
 * The wrapper moves the text down onto the first grid line at or below the middle of the line.
 * The bottom margin removes the rest of the last line, so the paragraph ends on that line.
 * Every height is a whole number of grid steps, so nothing drifts however long the page.
 */
.feed-page :is(.entry, .feed-editor) > p{
    --first-baseline: round(up, calc(var(--line) / 2), var(--grid-step));
    font-size: 0;
    line-height: var(--line);
    margin-bottom: calc(var(--first-baseline) - var(--line));
}

.feed-page :is(.entry, .feed-editor) > p > span{
    font-size: var(--text-size, 16px);
    line-height: 0;
    position: relative;
    top: calc(var(--first-baseline) - var(--line) / 2);
}

/*************************************************************************************
*
* Spacing between blocks
*
* One grid step between blocks, except right after the date.
* A figure sits one step below the date, and the editor can remove its space.
*
*************************************************************************************/

.feed-page :is(.entry, .feed-editor) > *{
    margin-block: 0;
}

.feed-page :is(.entry, .feed-editor) > * + *{
    margin-top: var(--grid-step);
}

.feed-page .date + *{
    margin-top: 0;
}

.feed-page .date + figure,
.feed-page .feed-editor > figure:first-child{
    margin-top: var(--grid-step);
}

.feed-page :is(.entry, .feed-editor) > figure[data-no-space-above],
.feed-page :is(.entry, .feed-editor) > figure[data-no-space-below] + *{
    margin-top: 0;
}

/*
 * A separator is a line across the text column, drawn on a grid line.
 * Its negative bottom margin cancels its own height, so the blocks after it stay on the grid.
 */
.feed-page :is(.entry, .feed-editor) > hr{
    justify-self: stretch;
    width: 100%;
    height: 1px;
    margin-bottom: -1px;
    border: 0;
    background-color: rgba(0, 0, 0, 0.2);
}

/*************************************************************************************
*
* Media
*
* .figure_content is the same row as .media-row while editing in the editor.
*
*************************************************************************************/

.feed-page figure{
    margin-inline: 0;
    justify-self: center;
    width: 100%;
    min-width: 0;
}

.feed-page figure.wide,
.feed-page figure.grid{
    width: min(100cqw, var(--wide-width));
}

.feed-page :is(.media-row, .figure_content){
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: center;
    gap: var(--grid-step);
}

.feed-page figure.grid :is(.media-row, .figure_content){
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    justify-items: center;
}

.feed-page figure[data-align="left"] :is(.media-row, .figure_content){
    justify-content: flex-start;
    justify-items: start;
}

.feed-page figure[data-align="right"] :is(.media-row, .figure_content){
    justify-content: flex-end;
    justify-items: end;
}

.feed-page .media-row > *,
.feed-page .media-row img,
.feed-page .media-row audio,
.feed-page .media-row iframe{
    display: block;
    width: 100%;
    min-width: 0;
}

.feed-page .media-row img{
    height: auto;
}

.feed-page .media-row .media_item{
    width: min(100%, var(--media-width));
}

.feed-page .media_item:has(:is(img, video):not([hidden])){
    container-type: inline-size;
}

/*
 * Images and videos take a whole number of grid steps.
 * The box gets that height directly; the picture keeps its ratio at the top of the box.
 */
.feed-page .media_item{
    --picture-height: calc(100cqw / (var(--media-source-ratio)));
}

.feed-page .media_item > a{
    display: block;
}

.feed-page .media_item > :is(.player, img, video):not([hidden]),
.feed-page .media_item > a > img:not([hidden]){
    height: round(up, var(--picture-height), var(--grid-step));
}

.feed-page .media_item > :is(img, video),
.feed-page .media_item > a > img{
    object-fit: contain;
    object-position: top;
}

/*************************************************************************************
*
* Playback
*
*************************************************************************************/

.feed-page .player{
    position: relative;
    isolation: isolate;
}

/* The video, its poster and its button cover the picture, at the top of the grid-rounded box. */
.feed-page .player video,
.feed-page .player .poster,
.feed-page .video-button{
    position: absolute;
    inset: 0 0 auto 0;
    width: 100%;
    height: var(--picture-height);
}

.feed-page .player video,
.feed-page .player .poster{
    object-fit: contain;
}

.feed-page .poster{
    pointer-events: none;
}

.feed-page .player[data-frame-ready] .poster{
    visibility: hidden;
}

.feed-page .video-button{
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    background: transparent;
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.feed-page .video-button[hidden],
.feed-page .video-message:empty{
    display: none;
}

.feed-page .video-icon{
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.48) url("feed-play.png") center / 24px 24px no-repeat;
    pointer-events: none;
    transition: opacity 140ms;
}

.feed-page .player[data-state="playing"] .video-icon{
    background-image: url("feed-pause.png");
    opacity: 0;
}

.feed-page .player[data-feedback] .video-icon,
.feed-page .player[data-state="playing"] .video-button:focus-visible .video-icon{
    opacity: 1;
}

.feed-page .player[data-state="loading"] .video-icon{
    background-image: none;
}

.feed-page .player[data-state="loading"] .video-icon::before{
    content: "";
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: feed-loading 800ms linear infinite;
}

.feed-page .video-message{
    position: absolute;
    inset-inline: 12px;
    bottom: 12px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 16px;
    text-align: center;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce){
    .feed-page .video-icon{
        transition: none;
    }

    .feed-page .player[data-state="loading"] .video-icon::before{
        animation: none;
    }
}

@keyframes feed-loading{
    to{
        transform: rotate(360deg);
    }
}
