/* The look of every page: black on white, Figtree for titles, Work Sans for text. */

:root {
    --text: #000;
    --bg: #fff;
    --arrow: #f25c05; /* the tree's arrows */
    --line: 3px; /* their thickness */
    --radius: 16px; /* the blocks' corners */
    --column: 720px; /* the text's width */
}

* {
    box-sizing: border-box;
}
html {
    background: var(--bg);
    color: var(--text);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
body {
    margin: 0;
    font:
        20px/1.65 "Work Sans",
        sans-serif;
}
/* The bar on top: the site's pages, in the middle. */
.nav {
    display: flex;
    justify-content: center;
    gap: 32px;
    max-width: 1240px;
    margin: 0 auto;
    padding: 16px;
    border-bottom: 1px solid var(--text);
    font: 700 15px/1 "Figtree", sans-serif;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.nav a {
    text-decoration: none;
}
.nav a:hover,
.nav a[aria-current="page"] {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 5px;
}

main {
    max-width: 36em;
    margin: 0 auto;
    padding: 56px 16px 120px;
    overflow-wrap: break-word;
}

h1,
h2,
h3 {
    font-family: "Figtree", sans-serif;
    font-weight: 700;
    line-height: 1.2;
    margin: 1.76em 0 0.6em;
}
h1 {
    text-align: center;
    font-size: 1.7em;
    border-bottom: 1px solid var(--text);
    padding-bottom: 0.2em;
}
h2 {
    font-size: 1.3em;
}
/* The page's title: its first heading, the "===" one. */
h1.title {
    font-size: 2.1em;
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -0.02em;
    margin: 0.4em 0 1.2em;
    padding: 0 0 0.5em;
    border-bottom: 4px solid var(--text);
}

p {
    margin: 0 0 1em;
}
a {
    color: var(--text);
    text-underline-offset: 3px;
}
strong {
    font-weight: 600;
}
code {
    font-family: ui-monospace, monospace;
    font-size: 0.88em;
}
blockquote {
    margin: 1.2em 0;
    padding-left: 1em;
    border-left: 3px solid var(--text);
}
hr {
    border: 0;
    border-top: 1px solid var(--text);
    margin: 2.5em 0;
}
img {
    max-width: 100%;
}

/* The video, where the markdown says {song}. */
.video {
    aspect-ratio: 16 / 9;
    margin: 1.5em 0;
    border: 1px solid var(--text);
}
.video iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}
/* The videos pasted as they are into the markdown (the build gathers them): two a row in the text's
   column. A picture opening a paragraph takes the width of one of them (--thumb). */
:root {
    --thumb-gap: 20px;
    --thumb: calc((100% - var(--thumb-gap)) / 2);
}
main.page > .videos {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--thumb-gap);
    margin-top: 1.5em;
    margin-bottom: 1.5em;
}
.videos iframe {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    border: 0;
}

/* A picture opening a paragraph (or its link) stands on the left of the paragraph's text. */
p:has(> img:first-child, > a:first-child > img) {
    display: flow-root;
}
p > img:first-child,
p > a:first-child:has(> img) {
    float: left;
    width: var(--thumb);
    margin: 0.3em var(--thumb-gap) 0.5em 0;
}
p > a:first-child > img {
    display: block;
    width: 100%;
    border-radius: 8px;
}

/* The article's dialogue: the "M:" / "A:" opening a line. */
.speaker {
    font-weight: 600;
}

/* ---- The tree page ---- */

/* Its text keeps the column; only the tree's branches spread wider. */
main.page {
    max-width: 1240px;
}
.page > :not(.tree),
.tree > :not(.fork):not(.fork-phone) {
    max-width: min(var(--column), 100%);
    margin-left: auto;
    margin-right: auto;
}
.tree {
    margin: 2em 0 3em;
}

.block {
    border: 1px solid var(--text);
    font-size: 1.1em;
    border-radius: var(--radius);
    padding: 22px 28px 6px;
    background: var(--bg);
}

/* An arrow: its word under the block above, then from the word a curve --w wide and --h high
   bowing out to the right, and its head. */
.arrow {
    --w: 8px;
    --h: 64px;
}
.arrow > span {
    display: block;
    text-align: center;
    margin-top: 10px;
}
.arrow > .path {
    position: relative;
    height: var(--h);
    margin-top: 6px;
}
.arrow > .path > .bow {
    position: absolute;
    left: 50%;
    top: 0;
    width: var(--w);
    height: 100%;
    overflow: visible;
}
/* The head: its tip at the curve's end, turned the way the curve arrives (--dx, --dy, from sitegen/tree.py). */
.arrow > .path::after,
.fork .head {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 0;
    transform-origin: 50% 100%;
    transform: translateX(-50%)
        rotate(
            calc(
                atan2(calc(var(--dy) * var(--h)), calc(var(--dx) * var(--w))) -
                    90deg
            )
        );
    border: 9px solid transparent;
    border-bottom: 0;
    border-top: 14px solid var(--arrow);
}
.arrow > span,
.fork-label,
summary .label {
    font:
        700 14px/1 "Figtree",
        sans-serif;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.arrow.bare {
    --h: 48px;
}
.arrow.bare > .path {
    margin-top: 0;
}
.bow path,
.curve path {
    fill: none;
    stroke: var(--arrow);
    stroke-width: var(--line);
    vector-effect: non-scaling-stroke;
}

/* A fork, on a wide screen: the branches side by side. Branch i's word stands under the block above
   at i/(n+1) of its width (--start), and its arrow curves from the word down to the middle of its
   column (--end). Lengths are in the fork's width (cqw), so that the head can be turned with them. */
.fork {
    --gap: 48px;
    --curve: 130px;
    --word: 30px;
    container-type: inline-size;
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--n), 1fr);
    gap: 0 var(--gap);
    padding-top: var(--curve);
}
.fork > .branch {
    --block: min(var(--column), 100cqw);
    --col: calc((100cqw - (var(--n) - 1) * var(--gap)) / var(--n));
    --start: calc(
        50cqw - var(--block) / 2 + var(--block) * var(--i) / (var(--n) + 1)
    );
    --end: calc(var(--col) / 2 + (var(--i) - 1) * (var(--col) + var(--gap)));
    --left: min(var(--start), var(--end));
    --w: max(8px, max(var(--start), var(--end)) - var(--left));
    --h: calc(var(--curve) - var(--word));
}
.fork > .branch > .curve {
    position: absolute;
    top: var(--word);
    left: var(--left);
    width: var(--w);
    height: var(--h);
    overflow: visible;
}
.fork > .branch > .head {
    left: var(--end);
    top: calc(var(--curve) - 14px);
    bottom: auto;
}
.fork-label {
    position: absolute;
    left: var(--start);
    top: 10px;
    transform: translateX(-50%);
}

/* A fork, on a phone: each branch folded under its arrow's word. */
.fork-phone {
    display: none;
}
details {
    margin-top: 12px;
}
summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: baseline;
    gap: 12px;
    border: 1px solid var(--text);
    border-radius: var(--radius);
    padding: 14px 18px;
}
summary::-webkit-details-marker {
    display: none;
}
summary .label {
    flex: 1;
    font-size: 16px;
}
summary::after {
    content: "+";
    font:
        700 1.2em/1 "Figtree",
        sans-serif;
}
details[open] > summary {
    background: var(--text);
    color: var(--bg);
    border-radius: var(--radius) var(--radius) 0 0;
}
details[open] > summary::after {
    content: "−";
}
/* Opened, the branch's first block hangs from the summary. */
details > .branch > .block:first-child {
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    padding-top: 16px;
}

/* What the tree's page got wrong, if anything. */
.problems {
    border: 2px dashed var(--text);
    padding: 12px 20px;
    margin-bottom: 2em;
}

/* ---- A link's preview, shown when the mouse rests on it (sitegen/previews.py) ---- */

.tippy-box[data-theme~="preview"] {
    background: var(--bg);
    border: 1px solid var(--text);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
    overflow: hidden;
}
.tippy-box[data-theme~="preview"] .tippy-content {
    padding: 0;
}
.preview {
    display: block;
    color: var(--text);
    text-decoration: none;
    padding-bottom: 14px;
}
.preview img {
    display: block;
    width: 100%;
    aspect-ratio: 1.91;
    object-fit: cover;
    border-bottom: 1px solid var(--text);
    margin-bottom: 12px;
}
.preview .site,
.preview .title,
.preview .description {
    display: block;
    padding: 0 16px;
}
.preview .site {
    font: 700 12px/1.4 "Figtree", sans-serif;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--arrow);
}
.preview .title {
    font: 700 17px/1.25 "Figtree", sans-serif;
    margin: 4px 0 6px;
}
.preview .description {
    font-size: 14px;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
}

/* ---- Smaller screens ---- */

@media (max-width: 900px) {
    .fork {
        display: none;
    }
    .fork-phone {
        display: block;
    }
}

@media (max-width: 600px) {
    main.page > .videos {
        grid-template-columns: 1fr;
    }
    p > img:first-child,
    p > a:first-child:has(> img) {
        float: none;
        display: block;
        width: 100%;
        margin: 0 0 0.8em;
    }
    body {
        font-size: 17px;
        line-height: 1.6;
    }
    main {
        padding-top: 32px;
    }
    h1 {
        font-size: 1.5em;
        margin-top: 1.44em;
    }
    h1.title {
        font-size: 1.85em;
        margin-top: 0;
    }
    h2 {
        font-size: 1.2em;
    }
    .video {
        margin-left: -16px;
        margin-right: -16px;
        border-left: 0;
        border-right: 0;
    }
    .block {
        padding: 16px 18px 4px;
    }
    .arrow {
        --h: 48px;
    }
}
