/* Elon Musk Facts
   Serif type carries the record itself. Sans type carries everything around
   it: dates, labels, sources, navigation. Red marks Musk's own words. */

:root {
    --paper: #f8f5ef;
    --paper-tint: #efeae0;
    --ink: #17181c;
    --ink-soft: #454953;
    --ink-faint: #666b76;
    --rule: #d9d3c7;
    --rule-strong: #17181c;
    --accent: #b42318;
    --link: #1c4e8f;
    --ok: #1e7b34;

    --hero-bg: #111318;
    --hero-ink: #f6f3ec;
    --hero-soft: #d5d2ca;
    --hero-faint: #a4a8b1;
    --hero-rule: #30333b;
    --hero-accent: #f0624f;

    --label-words: #b42318;
    --label-court: #1c4e8f;
    --label-regulator: #0f6b63;
    --label-settlement: #6b4e1e;
    --label-pending: #8a5a00;
    --label-research: #2a6a34;
    --label-news: #555a63;

    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    --icon-share: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8'/%3E%3Cpath d='M16 6l-4-4-4 4'/%3E%3Cpath d='M12 2v13'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #14161a;
        --paper-tint: #1d2026;
        --ink: #ebe8e2;
        --ink-soft: #bdbfc5;
        --ink-faint: #979ba5;
        --rule: #2c2f37;
        --rule-strong: #6a6e78;
        --accent: #ff8571;
        --link: #8fb8f6;
        --ok: #6dd487;

        --hero-bg: #0b0c0f;
        --hero-rule: #262931;

        --label-words: #ff8571;
        --label-court: #9cc0ff;
        --label-regulator: #7fd6cb;
        --label-settlement: #e0c79a;
        --label-pending: #f2c770;
        --label-research: #9bd6a2;
        --label-news: #bdbfc5;
    }
}

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

* {
    margin: 0;
    padding: 0;
}

html {
    font-family: var(--sans);
    font-size: 18px;
    line-height: 1.6;
    color: var(--ink);
    background: var(--paper);
    -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

a {
    color: var(--link);
}

a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: 3px;
}

/* Keyboard users can jump past the opening; hidden until it has focus */
.skip-link {
    position: absolute;
    left: 0.75rem;
    top: -4rem;
    z-index: 10;
    padding: 0.5rem 0.8rem;
    background: var(--hero-ink);
    color: var(--hero-bg);
    font-size: 0.85rem;
    font-weight: 600;
}

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

.wrap {
    max-width: 44rem;
    margin: 0 auto;
    padding: 0 1.25rem;
}

/* Opening: site name, title, summary, quote and key figures on a dark band */
.hero {
    background: var(--hero-bg);
    color: var(--hero-ink);
    border-bottom: 1px solid var(--hero-rule);
    padding-bottom: 3.25rem;
}

.hero a:focus-visible {
    outline-color: var(--hero-ink);
}

.masthead {
    border-bottom: 1px solid var(--hero-rule);
}

.masthead .wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.55rem 2rem;
    padding-top: 1.05rem;
    padding-bottom: 1.05rem;
}

.wordmark {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--hero-ink);
    text-decoration: none;
}

.wordmark svg {
    width: 1.3rem;
    height: 1.3rem;
    flex: none;
}

.wordmark rect {
    fill: var(--hero-ink);
}

.wordmark path {
    fill: none;
    stroke: var(--hero-bg);
    stroke-width: 12;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Top navigation: one link per section of the site */
.site-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.1rem 1.3rem;
    list-style: none;
}

.site-nav a {
    display: block;
    padding: 0.2rem 0 0.15rem;
    border-bottom: 2px solid transparent;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--hero-faint);
    text-decoration: none;
}

.site-nav a:hover {
    color: var(--hero-ink);
}

.site-nav a[aria-current="page"] {
    border-bottom-color: var(--hero-accent);
    color: var(--hero-ink);
}

h1 {
    position: relative;
    z-index: 1;
    padding-top: 3.25rem;
    font-family: var(--serif);
    font-size: clamp(2.5rem, 7.2vw, 4.4rem);
    font-weight: 700;
    line-height: 1.04;
    letter-spacing: -0.02em;
    text-wrap: balance;
}

.hero-body {
    display: grid;
    align-items: start;
    row-gap: 2.25rem;
}

.hero-body h1 {
    margin-bottom: -0.65rem;
}

.dek {
    font-family: var(--serif);
    font-size: 1.18rem;
    line-height: 1.55;
    color: var(--hero-soft);
}

.updated {
    margin-top: 1.1rem;
    font-size: 0.78rem;
    color: var(--hero-faint);
}

/* The photo's edges fade into the dark band instead of ending in a frame */
.hero-photo {
    max-width: 26rem;
}

.hero-photo img {
    display: block;
    width: 100%;
    height: auto;
    -webkit-mask-image: linear-gradient(to right, transparent, #000 13%, #000 94%, transparent),
        linear-gradient(to bottom, transparent, #000 7%, #000 80%, transparent);
    -webkit-mask-composite: source-in;
    mask-image: linear-gradient(to right, transparent, #000 13%, #000 94%, transparent),
        linear-gradient(to bottom, transparent, #000 7%, #000 80%, transparent);
    mask-composite: intersect;
}

.hero-photo figcaption {
    margin-top: 0.5rem;
    font-size: 0.7rem;
    line-height: 1.5;
    color: var(--hero-faint);
}

.hero-photo figcaption a {
    color: inherit;
    text-underline-offset: 0.15em;
}

.hero-quote {
    border-left: 4px solid var(--hero-accent);
    padding-left: 1.35rem;
}

.hero-quote blockquote {
    font-family: var(--serif);
    font-size: clamp(1.6rem, 4.6vw, 2.15rem);
    line-height: 1.2;
    letter-spacing: -0.01em;
    text-wrap: balance;
}

.hero-quote figcaption {
    margin-top: 0.85rem;
    font-size: 0.8rem;
    color: var(--hero-faint);
}

.stats {
    display: grid;
    gap: 1.6rem;
    margin-top: 3rem;
    list-style: none;
}

.stats li {
    border-top: 1px solid var(--hero-rule);
    padding-top: 1.1rem;
}

.stat-num {
    display: block;
    font-family: var(--serif);
    /* scales with the screen on phones so the longest figure stays on one line */
    font-size: clamp(1.9rem, 9.8vw, 3.3rem);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
    font-variant-numeric: lining-nums tabular-nums;
    white-space: nowrap;
}

.stat-label {
    display: block;
    max-width: 30ch;
    margin-top: 0.65rem;
    font-size: 0.86rem;
    line-height: 1.45;
    color: var(--hero-soft);
}

.stats-note {
    max-width: 44rem;
    margin-top: 1.9rem;
    font-size: 0.78rem;
    line-height: 1.55;
    color: var(--hero-faint);
}

/* Body: section list, reading note, then the numbered sections */
.layout {
    padding-top: 2.5rem;
    padding-bottom: 4.5rem;
}

.toc {
    margin-bottom: 2.5rem;
    padding: 1.1rem 1.25rem 0.9rem;
    border: 1px solid var(--rule);
    font-size: 0.85rem;
}

.toc-title {
    margin-bottom: 0.5rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.toc ol {
    display: grid;
    list-style: none;
    counter-reset: toc;
}

.toc li {
    counter-increment: toc;
}

.toc a {
    display: grid;
    grid-template-columns: 1.7rem 1fr;
    padding: 0.35rem 0;
    line-height: 1.35;
    color: var(--ink-soft);
    text-decoration: none;
}

.toc a::before {
    content: counter(toc, decimal-leading-zero);
    padding-top: 0.14rem;
    font-size: 0.7rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--ink-faint);
}

.toc a:hover {
    color: var(--ink);
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.toc a[aria-current] {
    font-weight: 600;
    color: var(--ink);
}

.toc a[aria-current]::before {
    color: var(--accent);
}

.reading-note {
    padding: 1.5rem 1.5rem 1.6rem;
    background: var(--paper-tint);
    font-size: 0.9rem;
    line-height: 1.6;
}

.reading-note h2 {
    margin-bottom: 0.8rem;
    font-size: 1rem;
    font-weight: 700;
}

.reading-note-body {
    display: grid;
    gap: 0.8rem 2rem;
}

.sections {
    counter-reset: section;
}

.section {
    margin-top: 4rem;
    padding-top: 1.2rem;
    border-top: 2px solid var(--rule-strong);
    counter-increment: section;
    scroll-margin-top: 1.5rem;
}

.section > h2 {
    font-family: var(--serif);
    font-size: clamp(1.7rem, 5vw, 2.2rem);
    font-weight: 700;
    line-height: 1.14;
    letter-spacing: -0.015em;
    text-wrap: balance;
}

.section > h2::before {
    content: counter(section, decimal-leading-zero);
    display: block;
    margin-bottom: 0.55rem;
    font-family: var(--sans);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--accent);
}

.section-intro {
    max-width: 38rem;
    margin-top: 0.65rem;
    margin-bottom: 1.6rem;
    font-family: var(--serif);
    font-size: 1.08rem;
    line-height: 1.55;
    color: var(--ink-soft);
}

/* One fact: date and label, the fact, an optional status note, sources */
.fact {
    padding: 1.6rem 0 1.7rem;
    border-top: 1px solid var(--rule);
    scroll-margin-top: 1.5rem;
}

.fact:target {
    background: var(--paper-tint);
    box-shadow: -1rem 0 0 var(--paper-tint), 1rem 0 0 var(--paper-tint);
}

/* Photos between facts: the picture sits where a fact's text does, and its
   caption where the date does */
.plate {
    margin: 0;
    padding: 1.6rem 0 1.7rem;
    border-top: 1px solid var(--rule);
}

.plate img {
    display: block;
    width: 100%;
    height: auto;
    background: var(--paper-tint);
}

.plate figcaption {
    margin-top: 0.6rem;
    font-size: 0.74rem;
    line-height: 1.5;
    color: var(--ink-soft);
}

.plate-credit {
    display: block;
    margin-top: 0.3rem;
    color: var(--ink-faint);
}

.plate-credit a {
    color: inherit;
    text-underline-offset: 0.15em;
}

.fact-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.3rem 0.9rem;
    margin-bottom: 0.65rem;
}

.fact time {
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.35;
    font-variant-numeric: tabular-nums;
}

.label {
    display: inline-flex;
    align-items: baseline;
    gap: 0.45rem;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.label::before {
    content: "";
    flex: none;
    width: 0.55em;
    height: 0.55em;
    background: currentColor;
}

.label-words { color: var(--label-words); }
.label-court { color: var(--label-court); }
.label-regulator { color: var(--label-regulator); }
.label-settlement { color: var(--label-settlement); }
.label-pending { color: var(--label-pending); }
.label-research { color: var(--label-research); }
.label-news { color: var(--label-news); }

.fact > p {
    font-family: var(--serif);
    font-size: 1.06rem;
    line-height: 1.62;
}

.fact > .status {
    margin-top: 1rem;
    padding: 0.7rem 0.9rem;
    background: var(--paper-tint);
    font-family: var(--sans);
    font-size: 0.84rem;
    line-height: 1.55;
    color: var(--ink-soft);
}

.fact:target > .status {
    background: var(--paper);
}

.status strong {
    color: var(--ink);
}

.fact-links {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.3rem 1rem;
    margin-top: 1rem;
    font-size: 0.82rem;
}

.sources-label {
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.fact-links a {
    text-decoration-line: underline;
    text-decoration-thickness: 1px;
    text-decoration-color: color-mix(in srgb, var(--link) 35%, transparent);
    text-underline-offset: 0.2em;
}

.fact-links a:hover {
    text-decoration-color: currentColor;
}

.share-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: auto;
    padding: 0.15rem 0;
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--ink-faint);
    background: none;
    border: 0;
    cursor: pointer;
}

.share-btn::before {
    content: "";
    width: 0.95em;
    height: 0.95em;
    background: currentColor;
    -webkit-mask: var(--icon-share) center / contain no-repeat;
    mask: var(--icon-share) center / contain no-repeat;
}

.share-btn:hover {
    color: var(--ink);
}

.share-btn.copied {
    color: var(--ok);
}

/* Footer */
.site-footer {
    padding: 2.25rem 0 2.75rem;
    background: var(--hero-bg);
    border-top: 1px solid var(--hero-rule);
    font-size: 0.8rem;
    color: var(--hero-faint);
}

.site-footer p + p {
    margin-top: 0.35rem;
}

.site-footer a {
    color: var(--hero-ink);
}

.site-footer a:focus-visible {
    outline-color: var(--hero-ink);
}

/* Sections with nothing written yet, and the 404 page: the dark band fills
   the screen above the footer */
.stub {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.stub .hero {
    flex: 1;
}

.notfound {
    min-height: 100vh;
    border-bottom: 0;
}

.stub .dek,
.notfound .dek {
    max-width: 34rem;
    margin-top: 1.25rem;
}

.stub .back,
.notfound .back {
    display: inline-block;
    margin-top: 2rem;
    font-size: 0.9rem;
    color: var(--hero-ink);
}

/* Small screens */
@media (max-width: 540px) {
    html {
        font-size: 17px;
    }
}

/* One column: the photo comes straight after the headline, so it shows on the
   first screen of a phone */
@media (max-width: 719px) {
    .hero-body h1 {
        order: -2;
    }

    .hero-photo {
        order: -1;
        margin-top: -0.75rem;
    }
}

/* Room for columns: the photo beside the quote, each figure beside its
   caption, the reading note in two columns, each fact's date and label to the
   left of its text */
@media (min-width: 600px) {
    .toc ol {
        grid-template-columns: 1fr 1fr;
        column-gap: 1.75rem;
    }

    /* Figure beside caption. The figure column is as wide as the widest figure on
       the page, so a long one ("$291.5 million") cannot run into its caption. */
    .stats {
        grid-template-columns: minmax(16rem, max-content) minmax(0, 1fr);
        column-gap: 1.5rem;
    }

    .stats li {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: subgrid;
        align-items: center;
    }

    .stat-num {
        font-size: clamp(2.5rem, 7vw, 3.3rem);
    }

    .stat-label {
        max-width: 36ch;
        margin-top: 0;
    }
}

@media (min-width: 720px) {
    .hero-body {
        grid-template-columns: 19rem minmax(0, 1fr);
        grid-template-areas:
            "title title"
            "intro intro"
            "photo quote";
        column-gap: 2.5rem;
    }

    .hero-body h1 {
        grid-area: title;
    }

    .hero-intro {
        grid-area: intro;
    }

    .hero-photo {
        grid-area: photo;
    }

    .hero-quote {
        grid-area: quote;
        align-self: center;
    }

    .reading-note-body {
        grid-template-columns: 1fr 1fr;
    }

    .fact {
        display: grid;
        grid-template-columns: 8.25rem minmax(0, 1fr);
        column-gap: 1.75rem;
    }

    .fact > * {
        grid-column: 2;
    }

    .fact > .fact-meta {
        grid-column: 1;
        grid-row: 1 / span 4;
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: flex-start;
        gap: 0.45rem;
        margin-bottom: 0;
        padding-top: 0.32rem;
    }

    .plate {
        display: grid;
        grid-template-columns: 8.25rem minmax(0, 1fr);
        column-gap: 1.75rem;
    }

    .plate img {
        grid-column: 2;
        grid-row: 1;
    }

    .plate figcaption {
        grid-column: 1;
        grid-row: 1;
        margin-top: 0;
    }
}

/* Wide screens: summary and quote beside the photo, figures in a row, section
   list pinned beside the facts */
@media (min-width: 1100px) {
    .wrap {
        max-width: 62rem;
        padding: 0 1.5rem;
    }

    /* The photo starts at the top of the band and rises behind the end of
       the headline, which stays on one line across both columns */
    .hero-body {
        grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
        grid-template-rows: auto auto 1fr;
        grid-template-areas: none;
        column-gap: 4.5rem;
    }

    .hero-body h1 {
        grid-area: 1 / 1 / 2 / -1;
        text-shadow: 0 0 1.5rem var(--hero-bg), 0 0 0.5rem var(--hero-bg);
    }

    .hero-intro {
        grid-area: 2 / 1;
    }

    .hero-quote {
        grid-area: 3 / 1;
        align-self: start;
    }

    .hero-quote blockquote {
        font-size: 2rem;
    }

    .hero-photo {
        grid-area: 1 / 2 / 4 / 3;
        max-width: none;
    }

    .hero-photo img {
        -webkit-mask-image: linear-gradient(to right, transparent, #000 13%, #000 94%, transparent),
            linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.55) 22%, #000 40%, #000 82%, transparent);
        mask-image: linear-gradient(to right, transparent, #000 13%, #000 94%, transparent),
            linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.55) 22%, #000 40%, #000 82%, transparent);
    }

    .stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 2.25rem;
        margin-top: 3.5rem;
    }

    .stats li {
        display: block;
        grid-column: auto;
    }

    .stat-label {
        max-width: 30ch;
        margin-top: 0.65rem;
    }

    .layout {
        display: grid;
        grid-template-columns: 12rem minmax(0, 44rem);
        justify-content: space-between;
        align-items: start;
        padding-top: 3.5rem;
    }

    .toc {
        position: sticky;
        top: 2rem;
        margin-bottom: 0;
        padding: 0;
        border: 0;
    }

    .toc ol {
        grid-template-columns: 1fr;
    }
}

/* Printing: black on white, one column, no navigation or share buttons */
@media print {
    :root {
        --paper: #fff;
        --paper-tint: #f1f1f1;
        --ink: #000;
        --ink-soft: #222;
        --ink-faint: #444;
        --rule: #bbb;
        --rule-strong: #000;
        --link: #000;
        --hero-bg: #fff;
        --hero-ink: #000;
        --hero-soft: #222;
        --hero-faint: #444;
        --hero-rule: #bbb;
    }

    html {
        font-size: 10.5pt;
    }

    .skip-link,
    .site-nav,
    .toc,
    .share-btn {
        display: none;
    }

    .layout {
        display: block;
    }

    .hero-body h1 {
        text-shadow: none;
    }

    .fact,
    .plate,
    .reading-note,
    .stats li {
        break-inside: avoid;
    }

    .section > h2 {
        break-after: avoid;
    }
}
