/* CSS for mad star */

/* Colours and sizes, as variables (dark versions below) */

:root {
    --bg: #ffffff;
    --text: #1f2328;
    --muted: #5b6470;
    --accent: #2a5db0;
    --accent-hover: #1b4282;
    --rule: #e2e5e9;
    --tint: #f4f6f9;
    --header-bg: #07090f;
    --header-text: #ffffff;
    --header-soft: #b9c6d8;
    --content-width: 58rem;
    --gutter: 1.25rem;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111317;
        --text: #e4e7eb;
        --muted: #9aa3ae;
        --accent: #86b2ff;
        --accent-hover: #b3cfff;
        --rule: #2b3038;
        --tint: #1a1e24;
    }
}

/* General layout: the header band runs the full width; everything else
   sits in a centred column */

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 1.0625rem;
    line-height: 1.6;
}

main, footer, nav ul#nav-links, nav.breadcrumb, header .masthead {
    width: min(100% - 2 * var(--gutter), var(--content-width));
    margin-left: auto;
    margin-right: auto;
}

main {
    padding: 1.5rem 0 2rem;
}

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

/* "Skip to content": hidden until it gets keyboard focus */

a.skip-link {
    position: absolute;
    left: 0.75rem;
    top: -3rem;
    z-index: 10;
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    background-color: var(--bg);
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

a.skip-link:focus {
    top: 0.75rem;
}

/* Header band: wordmark and tagline over the banner image (a pulsating
   star; a CSS starfield shows if the image is missing) */

header {
    background-color: var(--header-bg);
    background-image:
        linear-gradient(90deg, rgba(7, 9, 15, 0.92) 0%, rgba(7, 9, 15, 0.55) 45%, rgba(7, 9, 15, 0) 75%),
        url("../images/banner.jpg"),
        radial-gradient(circle at 72% 55%, #fff7e0 0, #ffc46b 2.2rem, #e2563a 3.6rem, rgba(120, 30, 60, 0.6) 5.5rem, rgba(7, 9, 15, 0) 9rem),
        radial-gradient(1px 1px at 20% 30%, #ffffff 50%, transparent 51%),
        radial-gradient(1px 1px at 55% 20%, #cfe0ff 50%, transparent 51%),
        radial-gradient(1px 1px at 88% 75%, #ffffff 50%, transparent 51%),
        radial-gradient(1px 1px at 40% 80%, #ffe9cf 50%, transparent 51%);
    background-repeat: no-repeat;
    background-size: cover, cover, auto, auto, auto, auto, auto;
    background-position: center, right center, center, center, center, center, center;
    color: var(--header-text);
}

header .masthead {
    padding: 2.25rem 0 2rem;
    min-height: 10rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

header a.wordmark {
    color: var(--header-text);
    text-decoration: none;
    font-size: clamp(2.6rem, 7vw, 4.25rem);
    line-height: 1;
    letter-spacing: -0.02em;
}

header a.wordmark .wm-mad {
    font-weight: 800;
}

header a.wordmark .wm-star {
    font-weight: 300;
    color: var(--header-soft);
}

@media (max-width: 40rem) {
    header {
        background-image:
            linear-gradient(90deg, rgba(7, 9, 15, 0.95) 0%, rgba(7, 9, 15, 0.8) 60%, rgba(7, 9, 15, 0.2) 100%),
            url("../images/banner.jpg"),
            radial-gradient(circle at 85% 50%, #fff7e0 0, #ffc46b 1.6rem, #e2563a 2.6rem, rgba(120, 30, 60, 0.6) 4rem, rgba(7, 9, 15, 0) 6.5rem);
        background-size: cover, cover, auto;
        background-position: center, 70% center, center;
    }
    header .masthead {
        min-height: 8rem;
        padding: 1.75rem 0 1.5rem;
    }
}

header p.tagline {
    margin: 0.6rem 0 0;
    color: var(--header-soft);
    font-size: 0.875rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* Navbar: a plain row of links that wraps on narrow screens; the current
   section is underlined in the accent colour */

nav.site-nav {
    border-bottom: 1px solid var(--rule);
}

nav ul#nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0 1.4rem;
    margin-top: 0;
    margin-bottom: 0;
    padding: 0;
    list-style: none;
}

nav ul#nav-links a {
    display: block;
    padding: 0.8rem 0 0.65rem;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 0.95rem;
    text-decoration: none;
}

nav ul#nav-links a:hover {
    color: var(--text);
}

nav ul#nav-links a[aria-current] {
    color: var(--text);
    border-bottom-color: var(--accent);
}

@media (max-width: 40rem) {
    nav ul#nav-links {
        gap: 0 1rem;
    }
    nav ul#nav-links a {
        padding: 0.5rem 0 0.35rem;
    }
}

/* Breadcrumb: above the page title, only on pages below the top level */

nav.breadcrumb {
    padding-top: 1.25rem;
    color: var(--muted);
    font-size: 0.8125rem;
}

nav.breadcrumb ol {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    list-style: none;
}

nav.breadcrumb li + li::before {
    content: "/";
    padding: 0 0.45rem;
    color: var(--rule);
}

nav.breadcrumb a {
    color: var(--muted);
    text-decoration: none;
}

nav.breadcrumb a:hover {
    color: var(--accent);
    text-decoration: underline;
}

nav.breadcrumb ~ main {
    padding-top: 0.25rem;
}

/* Headings */

h1, h2, h3, h4 {
    line-height: 1.25;
    font-weight: 600;
}

h1 {
    margin: 0.5rem 0 1rem;
    font-size: clamp(1.7rem, 4vw, 2.1rem);
    letter-spacing: -0.01em;
}

h2 {
    margin: 2.25rem 0 0.75rem;
    font-size: 1.45rem;
}

h3 {
    margin: 1.75rem 0 0.5rem;
    font-size: 1.15rem;
}

h4 {
    margin: 1.5rem 0 0.5rem;
    font-size: 1rem;
    font-style: italic;
    font-weight: 600;
}

/* Text effects */

a {
    color: var(--accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.15em;
}

a:hover {
    color: var(--accent-hover);
    text-decoration-thickness: 2px;
}

a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 2px;
}

span.monospace, code {
    font-family: var(--mono);
    font-size: 0.9em;
    background-color: var(--tint);
    padding: 0.05em 0.3em;
    border-radius: 4px;
}

hr {
    border: none;
    border-top: 1px solid var(--rule);
    margin: 2rem 0;
}

/* Table of Contents */

ul#toc {
    display: inline-block;
    margin: 0.5rem 0 1.5rem;
    padding: 1rem 1.5rem 1rem 2.25rem;
    background-color: var(--tint);
    border-radius: 8px;
    font-size: 0.95rem;
}

ul#toc ul {
    padding-left: 1.25rem;
}

/* Footer */

footer {
    clear: both;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.25rem 1.5rem;
    padding: 1.25rem 0 2.5rem;
    border-top: 1px solid var(--rule);
    color: var(--muted);
    font-size: 0.8125rem;
}

/* Forms */

fieldset {
    margin: 1.25rem 0;
    padding: 1rem 1.25rem 1.25rem;
    border: 1px solid var(--rule);
    border-radius: 8px;
    background-color: var(--tint);
}

fieldset legend {
    padding: 0 0.5rem;
    font-weight: 600;
}

fieldset ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

fieldset li {
    padding: 0.35rem 0;
}

fieldset li label {
    float: left;
    width: 15%;
    margin-top: 0.35rem;
    text-align: right;
}

fieldset li input, fieldset li textarea, fieldset li select {
    width: 80%;
    margin-left: 10px;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--rule);
    border-radius: 6px;
    background-color: var(--bg);
    color: var(--text);
    font: inherit;
}

fieldset li textarea {
    margin-top: 0;
    margin-bottom: 0;
}

/* Form fields everywhere (the tool forms as well as the admin editor) */

main input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="hidden"]),
main select, main textarea {
    padding: 0.3rem 0.5rem;
    border: 1px solid #c9ced6;
    border-radius: 6px;
    background-color: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    line-height: 1.4;
}

main input:focus, main select:focus, main textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

main input[type="checkbox"], main input[type="radio"] {
    accent-color: var(--accent);
}

@media (prefers-color-scheme: dark) {
    main input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="hidden"]),
    main select, main textarea {
        border-color: #3a414b;
    }
}

form input.submit, form input[type="submit"] {
    margin: 0.5rem 0;
    padding: 0.45rem 1.1rem;
    border: none;
    border-radius: 6px;
    background-color: var(--accent);
    color: #ffffff;
    font: inherit;
    cursor: pointer;
}

form input.submit:hover, form input[type="submit"]:hover {
    background-color: var(--accent-hover);
}

@media (max-width: 40rem) {
    fieldset li label {
        float: none;
        display: block;
        width: auto;
        text-align: left;
    }
    fieldset li input, fieldset li textarea, fieldset li select {
        width: 100%;
        margin-left: 0;
    }
}

/* Definition lists */

dt {
    font-weight: 600;
}

dd {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

/* Block-level Images */

div.block-img {
    text-align: center;
}

/* Floated images sit just before the paragraph they go with; the 1.3em
   top margin matches that paragraph's top margin (1em) plus half its
   line spacing, so the image's top lines up with the first line of text */

div.block-img.align-right {
    float: right;
    margin: 1.3em 0 1em 1.25rem;
}

div.block-img.align-left {
    float: left;
    margin: 1.3em 1.25rem 1em 0;
}

div.block-img.align-center {
    margin: 1.25rem auto;
}

div.block-img.framed {
    padding: 10px;
    border: 1px solid var(--rule);
    border-radius: 6px;
}

div.block-img p {
    margin: 0.5rem 0 0;
    padding: 0;
    color: var(--muted);
    font-size: 0.875rem;
}

/* General tables: scroll sideways on narrow screens rather than squash */

table {
    display: block;
    max-width: 100%;
    width: max-content;
    margin: 1rem auto;
    overflow-x: auto;
    border-collapse: collapse;
    font-size: 0.95rem;
}

th {
    border: 1px solid var(--rule);
    background-color: var(--tint);
    font-weight: 600;
    padding: 0.45rem 0.7rem;
    text-align: center;
}

td {
    border: 1px solid var(--rule);
    padding: 0.45rem 0.7rem;
    text-align: center;
}

/* Code version tables */

.code-version {
    font-size: 0.8rem;
}

/* Data file tables */

.data-files {
    font-size: 0.8rem;
}

/* Text decorations */

span.strike {
    text-decoration: line-through;
}

span.error {
    color: #d1242f;
}

/* Terminal output */

div.terminal {
    margin: 1rem 0;
    padding: 0.9rem 1rem;
    background-color: var(--tint);
    border-radius: 8px;
    white-space: pre-wrap;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 0.875rem;
}

/* Videos */

video {
    display: block;
    margin: 0 auto;
}

/* Printing: just the content, black on white, with link addresses */

@media print {
    :root {
        --bg: #ffffff;
        --text: #000000;
        --muted: #444444;
        --accent: #000000;
        --rule: #bbbbbb;
        --tint: #f2f2f2;
    }
    a.skip-link, header, nav.site-nav, nav.breadcrumb, ul#toc {
        display: none;
    }
    body {
        font-size: 11pt;
        line-height: 1.45;
    }
    main, footer {
        width: auto;
        padding: 0;
    }
    a {
        text-decoration: none;
    }
    main a[href^="http"]:not([href*="richtownsend.dev"])::after {
        content: " (" attr(href) ")";
        font-size: 0.85em;
        color: var(--muted);
        overflow-wrap: anywhere;
    }
    h1, h2, h3, h4 {
        break-after: avoid;
    }
    img, table, div.block-img, div.terminal, fieldset {
        break-inside: avoid;
    }
    table {
        display: table;
        width: auto;
    }
}
