/* wiki.css - the whole look of the wiki. Hand-written, no build step.
   It follows the blog's style (../../static/css/style.css): Inconsolata,
   black on white, a 650px column, `tree`-style lists and a typed-out title.
   Everything the wiki needs lives inside wiki/, so the folder works alone. */

@font-face {
    font-family: "Inconsolata";
    src: url("../fonts/Inconsolata/Inconsolata-VariableFont_wdth,wght.ttf") format("truetype");
    font-weight: 200 900;
    font-stretch: 50% 200%;
    font-display: swap;
}

/* Boxicons 3 (Basic): the file / folder icons in the trees */
@font-face {
    font-family: "boxicons";
    src: url("../fonts/Boxicons/boxicons.woff2") format("woff2");
    font-display: block;
}

/* ------------------------------------------------------------------ base */

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

body {
    max-width: 650px;
    margin: 40px 20px;
    font-family: "Inconsolata", monospace;
    font-size: 18px;
    line-height: 1.6;
    color: #000;
    background: #fff;
}

h1, h2, h3, h4 {
    line-height: 1.2;
}

h2 {
    margin-top: 1.8em;
    padding-bottom: 0.15em;
    border-bottom: 1px solid #000;
}

h3 {
    margin-top: 1.5em;
}

a {
    color: #000;
}

/* jumping to a section should not hide its heading under the window edge */
[id] {
    scroll-margin-top: 1em;
}

/* the page font is already monospace: undo the browser's own code font size */
pre,
code,
kbd {
    font-family: inherit;
    font-size: inherit;
}

pre {
    overflow-x: auto;
    padding: 0.5em 1ch;
    border: 1px solid #000;
    line-height: 1.3;
}

blockquote {
    margin: 1em 0;
    padding-left: 2ch;
    border-left: 1px solid #000;
}

hr {
    border: 0;
    border-top: 1px solid #000;
}

img {
    max-width: 100%;
    height: auto;
}

figure {
    margin: 1.5em 0;
}

figure img {
    border: 2px solid #000;
}

figcaption {
    font-style: italic;
}

/* ------------------------------------------------------- title + cursor */

h1::after {
    content: "";
    display: inline-block;
    width: 0.5em;
    height: 1em;
    margin-left: 0.15em;
    vertical-align: text-bottom;
    background: #000;
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* type the title out one character at a time. Set --chars on the <h1> to
   the number of characters in the title (spaces count). Works because every
   Inconsolata glyph is exactly 0.5em wide. */
h1.typed {
    --per-char: 80ms;
    /* shrink long titles so they fit on one line */
    font-size: min(2em, calc(min(100vw - 40px, 650px) * 2 / (var(--chars) + 3)));
    white-space: nowrap;
}

h1.typed span {
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    vertical-align: bottom;
    width: calc(var(--chars) * 0.5em);
    animation: type calc(var(--chars) * var(--per-char)) steps(var(--chars)) both;
}

h1.typed::after {
    animation-delay: calc(var(--chars) * var(--per-char));
}

@keyframes type {
    from { width: 0; }
}

@media (prefers-reduced-motion: reduce) {
    h1.typed span,
    h1::after {
        animation: none;
    }
}

/* ------------------------------------------------- top bar, path, footer */

/* the bar at the top of every page */
.bar {
    padding-bottom: 0.3em;
    border-bottom: 1px solid #000;
}

.bar a {
    text-decoration: none;
}

.bar a:hover,
.bar a:focus-visible {
    text-decoration: underline;
}

/* the page we are on, in the bar */
.bar [aria-current] {
    font-weight: 700;
}

/* where a page lives: wiki/anatomy/leaf, written like a path */
.path {
    margin: 1.5em 0 0;
    font-style: italic;
}

footer {
    margin-top: 3em;
    padding-top: 0.3em;
    border-top: 1px solid #000;
}

footer p {
    margin: 0.3em 0;
}

/* --------------------------------------------- category label (└─ path) */

/* the categories an article belongs to, at its foot. The same └─ corner
   and folder icon as the blog's category labels. */
.cat {
    position: relative;
    padding-left: 3ch;
    font-style: italic;
}

.cat::after {
    content: "";
    position: absolute;
    left: 0.5ch;
    top: 0;
    width: 1.5ch;
    height: 0.8em;
    border-left: 1px solid #000;
    border-bottom: 1px solid #000;
}

.cat::before {
    content: "\f425";
    content: "\f425" / "";
    margin-right: 0.5ch;
    font-family: "boxicons";
    font-style: normal;
    font-weight: normal;
    vertical-align: -0.1em;
}

/* ------------------------------------------------------------- the tree */

/* nested lists drawn like `tree` output:
     <ul class="tree"><li class="dir">...<ul><li>...</li></ul></li></ul>
   Each entry gets a 2ch icon (file, or folder for class="dir"), and the
   lines run down from the middle of the parent's icon. */
.tree,
.tree ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.tree {
    margin: 1em 0;
}

.tree ul {
    margin-left: 1ch;
}

.tree ul li {
    position: relative;
    padding-left: 3ch;
}

/* │ trunk down past each entry */
.tree ul li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    border-left: 1px solid #000;
}

/* └ the last entry's trunk stops at its branch */
.tree ul li:last-child::before {
    bottom: auto;
    height: 0.8em;
}

/* ── branch into the entry */
.tree ul li::after {
    content: "";
    position: absolute;
    left: 0;
    top: 0.8em;
    width: 2.5ch;
    border-top: 1px solid #000;
}

/* the icon in front of every entry: a file, a folder, or (top level) an
   open folder */
.tree li > :first-child:not(details)::before {
    content: "\f3f8";
    content: "\f3f8" / "";
    display: inline-block;
    width: 2ch;
    margin-right: 1ch;
    text-align: center;
    font-family: "boxicons";
    font-style: normal;
    font-weight: normal;
    line-height: 1;
    vertical-align: -0.1em;
}

.tree li.dir > :first-child:not(details)::before {
    content: "\f425";
    content: "\f425" / "";
}

.tree > li.dir > :first-child:not(details)::before,
.tree li.dir.open > :first-child:not(details)::before {
    content: "\f41e";
    content: "\f41e" / "";
}

/* the one-line note after an entry's link */
.tree .note {
    font-style: italic;
}

/* a collapsible branch: <li class="dir"><details open><summary>... */
.tree details > summary {
    list-style: none;
    width: fit-content;
    cursor: pointer;
}

.tree details > summary::-webkit-details-marker {
    display: none;
}

.tree li.dir > details > summary::before {
    content: "\f425";
    content: "\f425" / "";
    display: inline-block;
    width: 2ch;
    margin-right: 1ch;
    text-align: center;
    font-family: "boxicons";
    font-style: normal;
    font-weight: normal;
    line-height: 1;
    vertical-align: -0.1em;
}

.tree li.dir > details[open] > summary::before {
    content: "\f41e";
    content: "\f41e" / "";
}

/* ------------------------------------------------------- contents (toc) */

/* the contents box at the top of an article: a tree with no icons */
.toc {
    width: fit-content;
    max-width: 100%;
    margin: 1.5em 0;
    padding: 0.4em 2ch 0.6em;
    border: 1px solid #000;
}

.toc summary {
    font-weight: 700;
    cursor: pointer;
}

.toc .tree {
    margin: 0.3em 0 0;
}

.toc .tree li > :first-child::before {
    content: none;
}

.toc .tree ul li {
    padding-left: 2ch;
}

.toc .tree ul li::after {
    width: 1.5ch;
}

/* ------------------------------------------------------------- infobox */

/* the box of facts at the side of an article (a taxobox for species).
   In the text column on narrow screens; on wide screens it hangs in the
   empty space to the right of the column. */
.infobox {
    margin: 1.5em 0;
    border: 1px solid #000;
    border-collapse: collapse;
    width: 100%;
    line-height: 1.35;
}

.infobox caption {
    padding: 0.3em 1ch;
    border: 1px solid #000;
    border-bottom: 0;
    font-weight: 700;
    text-align: left;
}

.infobox th,
.infobox td {
    padding: 0.2em 1ch;
    vertical-align: top;
    text-align: left;
}

.infobox th {
    font-weight: normal;
    white-space: nowrap;
}

/* a full-width heading row inside the box */
.infobox th[colspan] {
    padding-top: 0.4em;
    border-top: 1px solid #000;
    font-weight: 700;
    text-align: center;
}

.infobox pre {
    margin: 0;
    border: 0;
    line-height: 1.1;
}

/* ---------------------------------------------------------- plant art */

/* each page's ASCII plant, right after the <h1>:
     <figure class="plant" aria-hidden="true"><pre>...</pre>
         <figcaption>...</figcaption></figure>
   Like the blog's art it only shows when there is room beside the text.
   It hangs in the space right of the column, and an infobox further down
   the page stacks underneath it. The plants are shaded like the fern on
   the main page and drawn by tools/wikiplants.py; at 7px, 86 columns fill
   the 34ch the art has. */
.plant {
    display: none;
}

.plant pre {
    display: inline-block;
    margin: 0;
    padding: 0;
    border: 0;
    overflow: visible;
    font-size: 7px;
    font-weight: 700;
    line-height: 1;
    text-align: left;
}

.plant figcaption {
    margin-top: 0.6em;
    font-size: 16px;
}

@media (min-width: 1100px) {
    .plant,
    .infobox {
        float: right;
        clear: right;
        width: 34ch;
        margin: 0 -38ch 1.5em 0;
    }

    .plant {
        display: block;
        text-align: center;
    }
}

/* -------------------------------------------------------------- tables */

/* wide tables scroll sideways instead of widening the page */
.scroll {
    overflow-x: auto;
    margin: 1.5em 0;
}

.wikitable {
    border-collapse: collapse;
    line-height: 1.35;
}

.wikitable caption {
    padding-bottom: 0.3em;
    font-style: italic;
    text-align: left;
}

.wikitable th,
.wikitable td {
    padding: 0.25em 1ch;
    border: 1px solid #000;
    vertical-align: top;
    text-align: left;
}

/* -------------------------------------------------- notices and notes */

/* italic note under a heading: "for the other meaning, see ..." */
.hatnote {
    padding-left: 2ch;
    font-style: italic;
}

/* a boxed notice, e.g. "this article is a stub" */
.notice {
    margin: 1.5em 0;
    padding: 0.5em 1ch;
    border: 1px dashed #000;
}

/* a link to a page nobody has written yet. A real <a> would be a broken
   link, so these are <span class="new" title="not written yet">. */
.new {
    text-decoration: underline dotted;
    text-underline-offset: 0.2em;
    cursor: help;
}

/* scientific names */
.sci {
    font-style: italic;
}

/* ------------------------------------------------- citations, footnotes */

sup {
    line-height: 0;
}

sup a {
    text-decoration: none;
}

.refs {
    padding-left: 4ch;
}

.refs li {
    margin-bottom: 0.3em;
}

/* ^ jump back up to where the source is cited */
.refs .up {
    text-decoration: none;
}

/* whatever a link just jumped to (a source, a glossary term) is shown
   inverted, white on black, so the eye finds it */
:target {
    background: #000;
    color: #fff;
    outline: 0.25em solid #000;
}

:target a {
    color: #fff;
}

/* ------------------------------------------------------------ glossary */

.glossary dt {
    margin-top: 1em;
    font-weight: 700;
}

.glossary dd {
    margin-left: 4ch;
}

/* the A B C ... jump row */
.letters {
    word-spacing: 0.5ch;
}

/* -------------------------------------------------------- main page */

.intro {
    font-style: italic;
}

/* the boxed "featured article" and "did you know" sections */
.box {
    margin: 2em 0;
    padding: 0 2ch 0.5em;
    border: 1px solid #000;
}

.box > h2 {
    margin: 0 -2ch 0.6em;
    padding: 0.3em 2ch;
    background: #000;
    color: #fff;
    border: 0;
    font-size: 1em;
}

/* the ASCII fern on the main page: fixed in the empty space right of the
   column, like the blog's ASCII art, and left out when there's no room.
   --rows and --cols are the size of the art in characters; the text
   shrinks to fit the window but never grows past 9px. */
.art {
    --rows: 87;
    --cols: 90;
    position: fixed;
    top: 50%;
    left: calc(670px + (100vw - 670px) / 2);
    transform: translate(-50%, -50%);
    margin: 0;
    pointer-events: none;
}

.art pre {
    margin: 0;
    padding: 0;
    border: 0;
    overflow: visible;
    font-size: min(9px, calc((100vw - 710px) * 2 / var(--cols)), calc(80vh / var(--rows) / 1.1));
    font-weight: 700;
    line-height: 1.1;
}

.art figcaption {
    margin-top: 1em;
    text-align: center;
    white-space: nowrap;
}

@media (max-width: 1100px) {
    .art {
        display: none;
    }
}
