/*
 * Rust Edu site styles: plain CSS, no framework and no build step.
 *
 * Header, content and footer share one column, so they have one left edge.
 * Colors are only in the token blocks, as plain hex, which no browser can lose.
 * Text meets WCAG 2.1 AA (4.5:1) and focus outlines 3:1 in both themes. Links in
 * text stay underlined: color alone sets them off from the text by under 3:1.
 */

:root {
    color-scheme: light dark;

    --color-bg: #fbf8f3;
    --color-surface: #f4eee4;
    --color-text: #2a3439;
    --color-muted: #5f5b53;
    --color-link: #0b7261;
    --color-link-hover: #07594b;
    --color-rule: #e5ddd0;
    --color-focus: #a72145;
    --color-accent: #f74c00;

    /* Headings: the crab's orange, then blue, the split complement that the teal
       of links does not take, then blue's neighbor, violet. */
    --color-title: #b23d0c;
    --color-heading: #24528f;
    --color-subheading: #6b3fa0;

    --radius: 8px;
}

/* Screen only: paper stays dark on light. The theme button's choice, in
   data-theme, wins over the system's. */
@media screen and (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg: #1b1815;
        --color-surface: #26221e;
        --color-text: #ece7df;
        --color-muted: #b5aea3;
        --color-link: #4fc9ad;
        --color-link-hover: #86dcc8;
        --color-rule: #3b352e;
        --color-focus: #ffc832;
        --color-title: #ff8f5e;
        --color-heading: #93b5f2;
        --color-subheading: #c3a6ee;
    }

    /* The logo with light lettering takes the place of the one with black. */
    :root:not([data-theme="light"]) .site-logo img {
        display: none;
    }

    :root:not([data-theme="light"]) .site-logo [src$="#dark"] {
        display: block;
    }
}

@media screen {
    :root[data-theme="light"] {
        color-scheme: light;
    }

    :root[data-theme="dark"] {
        color-scheme: dark;

        --color-bg: #1b1815;
        --color-surface: #26221e;
        --color-text: #ece7df;
        --color-muted: #b5aea3;
        --color-link: #4fc9ad;
        --color-link-hover: #86dcc8;
        --color-rule: #3b352e;
        --color-focus: #ffc832;
        --color-title: #ff8f5e;
        --color-heading: #93b5f2;
        --color-subheading: #c3a6ee;
    }

    :root[data-theme="dark"] .site-logo img {
        display: none;
    }

    :root[data-theme="dark"] .site-logo [src$="#dark"] {
        display: block;
    }
}

/* Base */

* {
    box-sizing: border-box;
}

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

body {
    display: flex;
    flex-direction: column;
    max-width: 42rem;
    min-height: 100vh;
    margin: 0 auto;
    padding: 0 1rem;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
        "Apple Color Emoji", "Segoe UI Emoji";
    font-size: 1.0625rem;
    line-height: 1.6;
    overflow-wrap: break-word;
}

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

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

:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

img {
    display: block;
    height: auto;
}

strong {
    font-weight: 600;
}

.skip-link {
    position: absolute;
    z-index: 1;
    top: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--color-bg);
}

.skip-link:not(:focus) {
    transform: translateY(-200%);
}

/* Header */

.site-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-rule);
}

/* The drawing's empty margin hangs out of the column, so the R stands on the
   text's edge, and stays in the link, clear of the focus ring. */
.site-logo {
    margin-left: -11px;
}

/* The logo for the dark theme, whose lettering is light. In both logos the line
   around the black cap has the light paper's color, so it shows only on dark. */
.site-logo [src$="#dark"] {
    display: none;
}

.site-header ul,
.site-footer ul {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Not gap: an older browser has no flex gap. */
.site-header li,
.site-footer li {
    margin-right: 1.25rem;
}

.site-header li:last-child {
    margin-right: 0;
}

.site-nav {
    display: flex;
    align-items: center;
}

.site-nav a {
    padding: 0.25rem 0;
    color: var(--color-text);
    font-size: 1rem;
}

.theme-toggle {
    margin-left: 1.25rem;
    padding: 0.3125rem;
    border: 1px solid var(--color-rule);
    border-radius: var(--radius);
    background: none;
    color: var(--color-text);
    cursor: pointer;
}

.theme-toggle:hover {
    border-color: currentColor;
    color: var(--color-link);
}

.theme-toggle svg {
    display: block;
}

.site-nav a,
.news-list a {
    display: block;
    font-weight: 500;
    text-decoration: none;
}

.site-nav a:hover,
.news-list a:hover,
.site-footer a:hover {
    color: var(--color-link);
    text-decoration: underline;
}

/* Content: the HTML that Markdown produces */

main {
    flex-grow: 1;
    padding: 3rem 0 4rem;
}

h1,
h2,
h3 {
    font-weight: 600;
    line-height: 1.25;
    text-wrap: balance;
}

/* Wider splits "Rust-Edu". */
h1 {
    max-width: 12.1em;
    margin: 0 0 1.25rem;
    color: var(--color-title);
    font-size: 2rem;
}

h2 {
    margin: 3rem 0 0.75rem;
    color: var(--color-heading);
    font-size: 1.375rem;
}

h3 {
    margin: 2rem 0 0.5rem;
    color: var(--color-subheading);
    font-size: 1.125rem;
}

h2 + h3 {
    margin-top: 0;
}

main p,
main ul,
main ol,
pre {
    margin: 0 0 1.25rem;
}

main ul,
main ol {
    padding-left: 1.5rem;
}

main li + li {
    margin-top: 0.5rem;
}

li ul,
li ol {
    margin: 0.5rem 0 0;
}

li > p {
    margin-bottom: 0.5rem;
}

li::marker {
    color: var(--color-muted);
}

blockquote {
    margin: 1.5rem 0;
    padding-left: 1rem;
    border-left: 1px solid var(--color-muted);
}

code,
pre {
    background: var(--color-surface);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

code {
    padding: 0.1em 0.3em;
    font-size: 0.875em;
}

pre {
    overflow-x: auto;
    padding: 1rem;
}

pre code {
    padding: 0;
}

/* These hold a photo's space while it loads; then its own ratio takes over. */
main img {
    width: 100%;
    aspect-ratio: auto 16 / 9;
    border-radius: var(--radius);
}

/* A bold line right above a photo is its label, colored as a sub-heading. */
main p:has(> strong:only-child):has(+ p > img) {
    margin-bottom: 0.5rem;
    color: var(--color-subheading);
}

main p + p:has(> strong:only-child):has(+ p > img) {
    margin-top: 2rem;
}

/* Home: the statement keeps the text color beside the crab. */

.site-hero h1 {
    margin: 0 0 1.25rem -0.025em;
    color: var(--color-text);
    font-size: 2.5rem;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.site-hero a {
    display: inline-block;
    margin-right: 1.25rem;
    padding: 0.5rem 0;
    font-weight: 500;
}

.site-hero a:first-child {
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    background: var(--color-link);
    color: var(--color-bg);
    text-decoration: none;
}

.site-hero a:first-child:hover {
    background: var(--color-link-hover);
}

/* News */

.byline,
.news-feeds,
.news-list time,
.site-footer {
    color: var(--color-muted);
    font-size: 0.9375rem;
}

/* A post's byline, and the line under the heading of /news/ that links to the
   feeds, which looks like it. */
.byline,
.news-feeds {
    margin-top: -0.75rem;
}

.news-list {
    padding: 0;
    list-style: none;
}

.news-list li {
    margin: 0;
    padding: 0.75rem 0;
    text-wrap: pretty;
}

.news-list li + li {
    border-top: 1px solid var(--color-rule);
}

.news-list time {
    font-variant-numeric: tabular-nums;
}

/* Footer */

.site-footer {
    padding: 1rem 0 2rem;
    border-top: 1px solid var(--color-rule);
}

.site-footer p {
    margin: 0 0 0.25rem;
}

.site-footer a {
    color: inherit;
}

/* About 73 characters a line, and dated rows */

@media (min-width: 40rem) {
    body {
        font-size: 1.125rem;
    }

    .site-hero h1 {
        font-size: 3rem;
    }

    .news-list li {
        display: grid;
        grid-template-columns: 6.5rem minmax(0, 1fr);
        align-items: baseline;
    }
}

/* Top rule, footer band and crab. */

body {
    max-width: none;
    padding: 0;
    border-top: 3px solid var(--color-accent);
}

.site-header,
main,
.site-footer p,
.site-footer nav {
    width: calc(100% - 2rem);
    max-width: 40rem;
    margin-left: auto;
    margin-right: auto;
}

.skip-link {
    margin: 0 1rem;
    margin: 0 max(1rem, 50% - 20rem);
}

.site-footer {
    background: var(--color-surface);
}

.site-hero {
    position: relative;
}

.site-hero h1 {
    max-width: 84%;
}

.site-hero img {
    position: absolute;
    top: 0.5rem;
    right: 0;
    width: 14%;
}

/* Paper drops the button's fill. */

@media print {
    .site-hero a:first-child {
        background: none;
        color: var(--color-text);
    }

    .theme-toggle {
        display: none;
    }
}
