/*
  xnano editorial theme: home.

  The homepage is a sequence of spreads laid straight on the drafting table: a constructed
  wordmark, an asymmetric statement beside a terminal exhibit, an index of the manual and
  three spreads on what the framework draws, plays and hears.
*/

/* The homepage is not printed on a sheet: its compositions sit on the table itself. */
.md-main__inner:has(.xn-home) {
    min-height: 0;
    margin-top: 0;
    padding-top: 0;
    background: transparent;
    box-shadow: none;
}

.md-main__inner:has(.xn-home)::before,
.md-main__inner:has(.xn-home)::after,
.md-main__inner:has(.xn-home) > .md-sidebar--secondary {
    display: none;
}

@media (min-width: 76.25em) {
    .md-main__inner:has(.xn-home) > .md-sidebar--primary {
        display: none;
    }
}

.md-content__inner:has(.xn-home) {
    padding: 0 1.2rem;
}

.xn-home {
    --xn-box: 3.2rem;
    padding-top: 2.6rem;
}

/* Every spread opens with a running rule: its number on the left, its subject on the right. */
.xn-home .xn-rule {
    border-bottom-color: var(--xn-rule-strong);
}

/* ── 01: the constructed wordmark ──────────────────────────────────────────────────── */
.xn-hero__kicker {
    margin: 2.4rem 0 0.4rem calc(var(--xn-box) + 0.8rem);
    color: var(--xn-ink);
}

.xn-construct {
    display: block;
}

.xn-construct__frame {
    position: relative;
    width: fit-content;
    padding: var(--xn-box) calc(var(--xn-box) + 0.8rem);
}

.xn-construct__word {
    position: relative;
    display: block;
    width: fit-content;
    padding: 0 0.03em;
    /* Trim the line box to the letters: a lowercase word runs from x-height to baseline. */
    text-box: trim-both ex alphabetic;
    color: var(--xn-ink);
    font-family: var(--xn-font-display);
    font-size: var(--xn-size-wordmark);
    font-weight: 600;
    letter-spacing: -0.055em;
    line-height: 0.8;
}

/* The word's bounding box, in the accent like a drafting annotation. */
.xn-construct__word::after {
    content: "";
    position: absolute;
    inset: 0;
    border: var(--xn-rule) solid var(--xn-accent);
}

.xn-construct__guide {
    position: absolute;
    background: var(--xn-accent);
    opacity: 0.45;
}

.xn-construct__guide--top,
.xn-construct__guide--bottom {
    left: 0;
    right: 0;
    height: var(--xn-rule);
}

.xn-construct__guide--top {
    top: var(--xn-box);
}

.xn-construct__guide--bottom {
    bottom: var(--xn-box);
}

.xn-construct__guide--left,
.xn-construct__guide--right {
    top: 0;
    bottom: 0;
    width: var(--xn-rule);
}

.xn-construct__guide--left {
    left: calc(var(--xn-box) + 0.8rem);
}

.xn-construct__guide--right {
    right: calc(var(--xn-box) + 0.8rem);
}

/* Registration boxes at the four corners of the drawing. */
.xn-construct__corner {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--xn-box);
    height: var(--xn-box);
    border: var(--xn-rule) solid var(--xn-rule-subtle);
    background: var(--xn-sheet);
}

.xn-construct__corner::after {
    content: "\00d7";
    color: var(--xn-ink-3);
    font-family: var(--xn-font-mono);
    font-size: 0.62rem;
}

.xn-construct__corner--top-left { top: 0; left: 0; }
.xn-construct__corner--top-right { top: 0; right: 0; }
.xn-construct__corner--bottom-left { bottom: 0; left: 0; }
.xn-construct__corner--bottom-right { bottom: 0; right: 0; }

/* The word's real measurements, filled in by js/construction.js. */
.xn-construct__height,
.xn-construct__width {
    position: absolute;
    display: flex;
    align-items: center;
    color: var(--xn-ink-2);
    font-family: var(--xn-font-mono);
    font-size: 0.52rem;
    letter-spacing: 0.06em;
}

.xn-construct__height {
    top: 50%;
    left: 0;
    width: calc(var(--xn-box) + 0.8rem);
    justify-content: flex-end;
    gap: 0.35rem;
    transform: translateY(-50%);
}

.xn-construct__height::after {
    content: "";
    width: 0.5rem;
    height: var(--xn-rule);
    background: var(--xn-accent);
}

.xn-construct__width {
    left: calc(var(--xn-box) + 0.8rem);
    right: calc(var(--xn-box) + 0.8rem);
    bottom: calc(var(--xn-box) / 2 - 0.35rem);
    gap: 0.5rem;
}

.xn-construct__width::before,
.xn-construct__width::after {
    content: "";
    flex: 1;
    height: 0.4rem;
    background:
        linear-gradient(var(--xn-accent), var(--xn-accent)) center / 100% var(--xn-rule) no-repeat;
}

.xn-construct__width::before {
    box-shadow: inset var(--xn-rule) 0 0 var(--xn-accent);
}

.xn-construct__width::after {
    box-shadow: inset calc(-1 * var(--xn-rule)) 0 0 var(--xn-accent);
}

/* ── The statement and its actions ─────────────────────────────────────────────────── */
.xn-split {
    position: relative;
    margin-top: 3.6rem;
    padding-top: 2.4rem;
    border-top: var(--xn-rule) solid var(--xn-rule-subtle);
}

.xn-split__mark {
    position: absolute;
    top: 48%;
}

.xn-split__mark--left {
    left: -2.4rem;
}

.xn-split__mark--right {
    right: -2.4rem;
}

.xn-statement {
    max-width: 23em;
    margin: 0.2rem 0 0;
    color: var(--xn-ink);
    font-family: var(--xn-font-mono);
    font-size: 0.88rem;
    line-height: 1.62;
}

.xn-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin: 2rem 0 2.6rem;
}

.xn-meta span {
    margin: 0 0.7em;
    color: var(--xn-rule-strong);
}

.md-typeset .xn-terminal,
.md-typeset .xn-spread__figure {
    text-align: left;
}

.xn-terminal .md-clipboard,
.xn-terminal .md-code__nav {
    display: none;
}

/* The hero's example: its code, then what it draws, in the page's own colors. */
.xn-terminal {
    --xn-crop-color: var(--xn-rule-strong);
    position: relative;
    margin: 0;
    border: var(--xn-rule) solid var(--xn-rule-subtle);
    background: var(--xn-code-bg);
    color: var(--xn-ink);
}

/* The showcase: rhythm games made with xnano, one tab and one recording for each. The
   recordings are drawn on the page's color, so the frame alone sets them apart. */
.xn-showcase {
    --xn-crop-color: var(--xn-rule-strong);
    min-width: 0;
    margin: 0;
    border: var(--xn-rule) solid var(--xn-rule-subtle);
    background: var(--xn-page);
}

.xn-showcase__tabs {
    display: flex;
    border-bottom: var(--xn-rule) solid var(--xn-rule-subtle);
    background: var(--xn-sheet);
}

.xn-showcase__tab {
    padding: var(--xn-space-12) var(--xn-space-16);
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--xn-ink-3);
    cursor: pointer;
    font-family: var(--xn-font-mono);
    font-size: var(--xn-size-label);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    transition:
        color var(--xn-speed) var(--xn-ease),
        border-color var(--xn-speed) var(--xn-ease);
}

.xn-showcase__tab:hover {
    color: var(--xn-ink);
}

.xn-showcase__tab[aria-selected="true"] {
    border-bottom-color: var(--xn-accent);
    color: var(--xn-ink);
}

.xn-showcase__tab:focus-visible {
    outline: var(--xn-rule) solid var(--xn-accent);
    outline-offset: calc(-1 * var(--xn-space-4));
}

.xn-showcase__panel img {
    display: block;
    width: 100%;
    height: auto;
}

.md-typeset .xn-showcase__caption {
    margin: 0;
    padding: var(--xn-space-12) var(--xn-space-16);
    border-top: var(--xn-rule) solid var(--xn-rule-subtle);
    background: var(--xn-sheet);
    color: var(--xn-ink-2);
    font-size: 0.66rem;
    line-height: 1.5;
}

.md-typeset .xn-showcase__caption a {
    margin-left: var(--xn-space-4);
    font-family: var(--xn-font-mono);
    font-size: 0.6rem;
}

/* ── 03 and 04: the rhythm games, and the example that runs in the browser ─────────── */
/* Each is a short text beside its exhibit: the games' recordings, or the runnable example. */
.xn-games,
.xn-playground {
    margin-top: 5.2rem;
}

.xn-exhibit {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 3.2rem;
    align-items: start;
    margin-top: var(--xn-space-32);
}

.md-typeset .xn-exhibit__text p {
    max-width: 23em;
    margin: 0 0 var(--xn-space-16);
    color: var(--xn-ink-2);
    font-size: 0.75rem;
    line-height: 1.6;
}

.md-typeset .xn-exhibit__text .xn-exhibit__lead {
    color: var(--xn-ink);
    font-family: var(--xn-font-mono);
    font-size: 0.88rem;
    line-height: 1.62;
}

/* The runnable example: a bar, the editor, a bar, then the output as a terminal screen.
   As a grid item it may shrink below its longest line, which then scrolls. */
.xn-runnable {
    min-width: 0;
}

.md-typeset .xn-runnable .pyodide {
    padding: 0;
    border-radius: 0;
    background: transparent;
    font-family: var(--xn-font-mono);
}

.md-typeset .xn-runnable .pyodide-editor-bar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin: 0;
    padding: var(--xn-space-8) var(--xn-space-16);
    border-bottom: var(--xn-rule) solid var(--xn-rule-subtle);
    color: var(--xn-ink-3);
    font-family: var(--xn-font-mono);
    font-size: var(--xn-size-label);
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.md-typeset .xn-runnable .pyodide > .pyodide-editor-bar ~ .pyodide-editor-bar {
    border-top: var(--xn-rule) solid var(--xn-rule-subtle);
}

.md-typeset .xn-runnable .pyodide-bar-item {
    width: auto;
}

.md-typeset .xn-runnable .pyodide-clickable {
    color: var(--xn-accent-ink);
    cursor: pointer;
    transition: color var(--xn-speed) var(--xn-ease);
}

.md-typeset .xn-runnable .pyodide-clickable:hover {
    color: var(--xn-ink);
}

/* While Python loads, the run control says that work is in progress. */
.md-typeset .xn-runnable [data-md-exec-state="loading"] .pyodide-clickable {
    cursor: progress;
    opacity: 0.6;
}

.md-typeset .xn-runnable .pyodide-editor {
    margin: 0;
    padding: var(--xn-space-12) var(--xn-space-16);
    font-size: 0.56rem;
    line-height: 1.6;
    overflow-x: auto;
}

.md-typeset .xn-runnable .pyodide > pre {
    margin: 0;
    padding: var(--xn-space-16);
    background: var(--xn-terminal-background);
    overflow-x: auto;
}

/* Box drawing characters only join up with a line height close to 1. */
.md-typeset .xn-runnable .pyodide-output {
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--xn-terminal-foreground);
    font-family: var(--xn-font-mono);
    font-size: 0.56rem;
    line-height: 1.2;
    white-space: pre;
}

.md-typeset .xn-runnable__caption {
    max-width: none;
    margin: 0;
    padding: var(--xn-space-8) var(--xn-space-16);
    border-top: var(--xn-rule) solid var(--xn-rule-subtle);
    color: var(--xn-ink-3);
    font-family: var(--xn-font-mono);
    font-size: var(--xn-size-label);
    font-style: normal;
    letter-spacing: 0.02em;
    line-height: 1.5;
    text-align: left;
    text-transform: none;
}

/* ── 05: where to go next ─────────────────────────────────────────────────────────── */
.xn-index {
    margin-top: 5.2rem;
}

.md-typeset ul.xn-index__list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 0;
    padding: 0;
    border-bottom: var(--xn-rule) solid var(--xn-rule-subtle);
    list-style: none;
}

.md-typeset .xn-index__list > li {
    margin: 0;
    padding: 0;
}

.xn-index__list > li + li {
    border-left: var(--xn-rule) solid var(--xn-rule-subtle);
}

/* An entry: its icon, its title, a sentence, and the path it leads to. */
.md-typeset a.xn-index__entry {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--xn-space-8);
    height: 100%;
    padding: var(--xn-space-24) var(--xn-space-24) var(--xn-space-20);
    color: var(--xn-ink);
    text-decoration: none;
    transition: background-color var(--xn-speed) var(--xn-ease);
}

.md-typeset a.xn-index__entry:hover {
    background-color: var(--xn-sheet);
}

.md-typeset a.xn-index__entry:focus-visible {
    outline: var(--xn-rule) solid var(--xn-accent);
    outline-offset: calc(-1 * var(--xn-rule));
}

/* The icon sits in a square tile two icons wide, outlined like the site's buttons. */
.xn-index__icon {
    display: grid;
    place-items: center;
    width: calc(2 * var(--xn-icon));
    height: calc(2 * var(--xn-icon));
    margin-bottom: var(--xn-space-8);
    border: var(--xn-rule) solid var(--xn-rule-strong);
    background-color: var(--xn-sheet);
    color: var(--xn-ink-2);
    transition:
        border-color var(--xn-speed) var(--xn-ease),
        color var(--xn-speed) var(--xn-ease);
}

.xn-index__icon svg {
    width: var(--xn-icon);
    height: var(--xn-icon);
    fill: none;
    stroke: currentColor;
    stroke-width: var(--xn-icon-stroke);
    stroke-linecap: round;
    stroke-linejoin: round;
}

.xn-index__entry:hover .xn-index__icon,
.xn-index__entry:focus-visible .xn-index__icon {
    border-color: var(--xn-ink);
    color: var(--xn-ink);
}

.xn-index__title {
    font-family: var(--xn-font-text);
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.4;
}

.xn-index__title .xn-arrow {
    display: inline-block;
    margin-left: var(--xn-space-2);
    color: var(--xn-ink-3);
    transition:
        color var(--xn-speed) var(--xn-ease),
        transform var(--xn-speed) var(--xn-ease);
}

.xn-index__entry:hover .xn-arrow,
.xn-index__entry:focus-visible .xn-arrow {
    color: var(--xn-accent);
    transform: translate(0.1rem, -0.1rem);
}

.xn-index__text {
    color: var(--xn-ink-2);
    font-size: 0.7rem;
    line-height: 1.5;
}

/* The path sits at the foot of the entry, so the entries end on one line. */
.xn-index__path {
    margin-top: auto;
    padding-top: var(--xn-space-12);
    color: var(--xn-ink-3);
    font-family: var(--xn-font-mono);
    font-size: var(--xn-size-label);
    letter-spacing: 0.02em;
}

/* ── 02: spreads ───────────────────────────────────────────────────────────────────── */
.xn-spreads {
    margin-top: 5.2rem;
}

.xn-spread {
    display: grid;
    grid-template-columns: minmax(0, 6fr) minmax(0, 5fr);
    grid-template-areas:
        "word figure"
        "text figure";
    column-gap: 3.2rem;
    row-gap: 1.2rem;
    padding: 3rem 0 3.2rem;
    border-bottom: var(--xn-rule) solid var(--xn-rule-subtle);
}

.xn-spread--reverse {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    grid-template-areas:
        "figure word"
        "figure text";
}

.md-typeset .xn-spread__word {
    grid-area: word;
    align-self: end;
    margin: 0;
    padding: 0;
    border: 0;
    color: var(--xn-ink);
    font-family: var(--xn-font-display);
    font-size: var(--xn-size-editorial);
    font-weight: 400;
    letter-spacing: -0.045em;
    line-height: 0.9;
}

.md-typeset .xn-spread__word::before,
.md-typeset .xn-spread__word::after {
    display: none;
}

.xn-spread__text {
    grid-area: text;
    align-self: start;
    max-width: 25rem;
    margin: 0;
    color: var(--xn-ink-2);
    font-size: 0.8rem;
    line-height: 1.6;
}

.md-typeset .xn-spread__figure {
    grid-area: figure;
    align-self: center;
    margin: 0;
}

/* The animations are drawn on the table's own color, so they sit on it without a frame. */
.xn-spread__figure img {
    display: block;
    width: 100%;
}

/* The examples' wrapper, and the page's own text around it: only the title, which the
   homepage keeps for its outline but does not show. */
xn-features {
    display: block;
}

.xn-home__text {
    max-width: var(--xn-reading);
}

.md-typeset .xn-spread__text > p {
    margin: 0;
}

.md-typeset .xn-spread__text > p + p {
    margin-top: 0.7em;
}

.xn-home__text > h1:first-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
}

/* ── Narrower screens: the compositions re-stack ───────────────────────────────────── */
@media (max-width: 59.9375em) {
    .xn-home {
        --xn-box: 2.2rem;
    }

    .xn-construct {
        grid-template-columns: minmax(0, 1fr);
        gap: 1rem;
    }

    .xn-split__mark {
        display: none;
    }

    .xn-exhibit {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--xn-space-24);
    }

    .md-typeset ul.xn-index__list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .xn-index__list > li:nth-child(odd) {
        border-left: 0;
    }

    .xn-index__list > li:nth-child(n + 3) {
        border-top: var(--xn-rule) solid var(--xn-rule-subtle);
    }

    .xn-spread,
    .xn-spread--reverse {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "word"
            "text"
            "figure";
    }
}

@media (max-width: 44.9375em) {
    .xn-home {
        --xn-box: 1.4rem;
        padding-top: 1.6rem;
    }

    .xn-hero__kicker {
        margin-left: 0;
    }

    .xn-construct__frame {
        width: 100%;
        padding-left: 0.6rem;
        padding-right: 0.6rem;
    }

    .xn-construct__word {
        font-size: 22vw;
    }

    .xn-construct__corner,
    .xn-construct__height {
        display: none;
    }

    .xn-construct__guide--left {
        left: 0.6rem;
    }

    .xn-construct__guide--right {
        right: 0.6rem;
    }

    .xn-construct__width {
        left: 0.6rem;
        right: 0.6rem;
    }

    .md-typeset ul.xn-index__list {
        grid-template-columns: minmax(0, 1fr);
    }

    .xn-index__list > li + li {
        border-left: 0;
        border-top: var(--xn-rule) solid var(--xn-rule-subtle);
    }

    /* Each entry becomes a row: the icon beside its title, sentence and path. */
    .md-typeset a.xn-index__entry {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-areas:
            "icon title"
            "icon text"
            "icon path";
        column-gap: var(--xn-space-16);
        row-gap: var(--xn-space-4);
        padding: var(--xn-space-20) 0;
    }

    .md-typeset a.xn-index__entry:hover {
        background-color: transparent;
    }

    .xn-index__icon {
        grid-area: icon;
        margin-bottom: 0;
    }

    .xn-index__title {
        grid-area: title;
    }

    .xn-index__text {
        grid-area: text;
    }

    .xn-index__path {
        grid-area: path;
        padding-top: var(--xn-space-4);
    }
}

/* The theme indents every list for prose; these lists are layouts, not prose. */
.md-typeset .xn-index__list,
.md-typeset .xn-index__list > li {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

.xn-statement em {
    font-family: var(--xn-font-display);
    font-style: italic;
}
