/*
Styles for the explainer. The colours are defined once, here, for the light
and the dark theme; the canvases read them through js/core/theme.js.

The three hues mean the same thing everywhere:
    blue    what the filter believes
    orange  what a sensor reads
    green   what the model predicts
*/

@font-face {
  font-family: 'Lato';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(../assets/fonts/lato/lato-italic-400-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Lato';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(../assets/fonts/lato/lato-italic-400-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../assets/fonts/lato/lato-normal-400-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../assets/fonts/lato/lato-normal-400-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(../assets/fonts/lato/lato-normal-700-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(../assets/fonts/lato/lato-normal-700-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    color-scheme: light;
    --is-dark: 0;
    --surface: #ffffff;
    --surface-2: #f4f5f6;
    --ink: #606c76;
    --ink-2: #606c76;
    --muted: #737d86;
    --grid: #e1e5e8;
    --axis: #b5bec5;
    --blue: #286fbf;
    --orange: #c55225;
    --green: #248260;
    --body: #5b5a56;
    --body-2: #2f2e2c;
    --body-3: #a9a79f;
    --floor: #d6d5cd;
    --link: #9b4dca;
    --brand: #111111;
    --page-width: 70rem;
    --text-width: 41rem;
    --figure-width: 54rem;
    --font: "Lato", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --is-dark: 1;
        --surface: #181b1e;
        --surface-2: #24292e;
        --ink: #d4dbe0;
        --ink-2: #bcc6ce;
        --muted: #929ea8;
        --grid: #30373d;
        --axis: #55616b;
        --blue: #74adef;
        --orange: #f18d60;
        --green: #50bc97;
        --body: #a3a199;
        --body-2: #d8d6cd;
        --body-3: #6b6964;
        --floor: #3a3f43;
        --link: #c392e5;
        --brand: #eef1f4;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --is-dark: 1;
    --surface: #181b1e;
    --surface-2: #24292e;
    --ink: #d4dbe0;
    --ink-2: #bcc6ce;
    --muted: #929ea8;
    --grid: #30373d;
    --axis: #55616b;
    --blue: #74adef;
    --orange: #f18d60;
    --green: #50bc97;
    --body: #a3a199;
    --body-2: #d8d6cd;
    --body-3: #6b6964;
    --floor: #3a3f43;
    --link: #c392e5;
    --brand: #eef1f4;
}

* {
    box-sizing: border-box;
}

html {
    font-size: 112.5%;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    /* Keep short pages aligned with articles that have a vertical scrollbar. */
    scrollbar-gutter: stable;
}

body {
    margin: 0;
    background: var(--surface);
    color: var(--ink);
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: 0.01em;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

button,
input,
select,
textarea {
    font-family: inherit;
}

header.title,
main {
    width: 100%;
    max-width: var(--page-width);
    margin: 0 auto;
    padding-inline: 20px;
}

main {
    padding-bottom: 6rem;
}

header.title > *,
main > *,
.footer > * {
    max-width: var(--text-width);
    margin-inline: auto;
}

/* E76's open header and light typography, with a narrower reading column. */
.site-header {
    width: 100%;
    max-width: calc(var(--text-width) + 40px);
    margin: 0 auto;
    padding: 50px 20px 20px;
}

.site-brand {
    display: inline-flex;
    color: var(--brand);
    vertical-align: top;
}

.site-logo {
    display: block;
    width: 55px;
    height: 55px;
    background: currentColor;
    -webkit-mask: url("../assets/e76.svg") center / contain no-repeat;
    mask: url("../assets/e76.svg") center / contain no-repeat;
}

h1,
h2,
h3 {
    font-weight: 700;
    letter-spacing: -1px;
}

h1 {
    font-size: 2.55rem;
    line-height: 1.2;
    margin-block: 0 1.25rem;
}

.byline {
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0;
}

h2 {
    font-size: 2rem;
    line-height: 1.25;
    margin-top: 3.5rem;
    margin-bottom: 1.25rem;
    scroll-margin-top: 1.5rem;
}

h3 {
    font-size: 1.55rem;
    line-height: 1.3;
    margin-top: 2.5rem;
    margin-bottom: 1.25rem;
}

p,
ul,
ol {
    margin-top: 0;
    margin-bottom: 1.5625rem;
}

ul,
ol {
    padding-left: 1.3rem;
}

li {
    margin-bottom: 0.625rem;
}

a {
    color: var(--link);
    text-decoration: none;
    overflow-wrap: anywhere;
}

a:hover {
    color: var(--ink);
}

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

code {
    font-family: var(--font);
    font-size: 0.86em;
    background: var(--surface-2);
    padding: 0.08em 0.32em;
    border-radius: 4px;
}

strong {
    font-weight: 600;
}

/* A word in the text which names a part of the figure: ink text, coloured underline. */
.k {
    text-decoration: underline;
    text-decoration-thickness: 3px;
    text-underline-offset: 4px;
    text-decoration-color: var(--k, var(--muted));
    text-decoration-skip-ink: none;
    font-weight: 400;
    cursor: default;
    border-radius: 3px;
    transition: background-color 0.15s;
}

.k:hover,
.k:focus-visible {
    background: color-mix(in srgb, var(--k, var(--muted)) 16%, transparent);
    outline: none;
}

.k-blue { --k: var(--blue); }
.k-orange { --k: var(--orange); }
.k-green { --k: var(--green); }
.k-ink { --k: var(--ink-2); }

/* A phrase in the text which changes the figure when pressed. */
button.act {
    font: inherit;
    color: inherit;
    background: var(--surface-2);
    border: 0;
    border-bottom: 2px solid var(--axis);
    border-radius: 5px 5px 2px 2px;
    padding: 0 0.3em;
    margin: 0;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
}

button.act:hover,
button.act:focus-visible {
    background: color-mix(in srgb, var(--link) 12%, var(--surface-2));
    border-bottom-color: var(--link);
    outline: none;
}

/* A number in the text which is filled in from the live estimator. */
.live {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.live:empty::before {
    content: "…";
    color: var(--muted);
}

/* Figures. */
figure.fig {
    max-width: var(--figure-width);
    margin: 2rem auto 2.4rem;
    padding: 0;
    scroll-margin-top: 1rem;
}

figure.fig.wide {
    max-width: 64rem;
}

figure.fig.narrow {
    max-width: var(--text-width);
}

.fig-stage {
    position: relative;
    width: 100%;
    aspect-ratio: var(--ratio, 16 / 9);
}

.fig-stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.fig-stage canvas.grab {
    cursor: grab;
}

.fig-stage canvas.grabbing {
    cursor: grabbing;
}

.fig-stage canvas.scrub {
    cursor: ew-resize;
}

.fig-controls {
    max-width: var(--text-width);
    margin: 0.7rem auto 0;
    display: grid;
    gap: 0.45rem;
}

figcaption {
    max-width: var(--text-width);
    margin: 0.8rem auto 0;
    color: var(--ink-2);
    font-size: 0.86rem;
    line-height: 1.5;
}

/* Controls. */
.ctl {
    display: grid;
    align-items: center;
    column-gap: 0.8rem;
    font-size: 0.86rem;
    color: var(--ink-2);
    min-height: 2rem;
}

.ctl-slider {
    grid-template-columns: minmax(7.5rem, 11rem) 1fr minmax(4.6rem, auto);
}

.ctl-label {
    line-height: 1.25;
}

.ctl-value {
    font-variant-numeric: tabular-nums;
    text-align: right;
    color: var(--ink);
    white-space: nowrap;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 2rem;
    margin: 0;
    background: transparent;
    cursor: pointer;
    --fill: 50%;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--ink-2) var(--fill), var(--grid) var(--fill));
}

input[type="range"]::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--ink-2) var(--fill), var(--grid) var(--fill));
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    margin-top: -8px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--ink);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--ink);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

input[type="range"]:focus-visible {
    outline: none;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
    outline: 3px solid color-mix(in srgb, var(--link) 55%, transparent);
    outline-offset: 2px;
}

input[type="range"]:focus-visible::-moz-range-thumb {
    outline: 3px solid color-mix(in srgb, var(--link) 55%, transparent);
    outline-offset: 2px;
}

.ctl-toggle {
    grid-template-columns: auto 1fr;
    cursor: pointer;
    justify-content: start;
}

.ctl-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.ctl-switch {
    width: 2.3rem;
    height: 1.3rem;
    border-radius: 1rem;
    background: var(--axis);
    position: relative;
    transition: background-color 0.15s;
}

.ctl-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(1.3rem - 4px);
    height: calc(1.3rem - 4px);
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s;
}

.ctl-toggle input:checked + .ctl-switch {
    background: var(--ink);
}

.ctl-toggle input:checked + .ctl-switch::after {
    transform: translateX(1rem);
}

.ctl-toggle input:focus-visible + .ctl-switch {
    outline: 3px solid color-mix(in srgb, var(--link) 55%, transparent);
    outline-offset: 2px;
}

.ctl-choice {
    grid-template-columns: auto 1fr;
    justify-content: start;
}

.seg {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    background: var(--surface-2);
    border-radius: 8px;
    padding: 2px;
    justify-self: start;
}

.seg button,
.ctl-button {
    font: inherit;
    font-size: 0.84rem;
    color: var(--ink-2);
    background: transparent;
    border: 0;
    border-radius: 6px;
    padding: 0.28rem 0.7rem;
    cursor: pointer;
    line-height: 1.3;
}

.seg button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
    font-weight: 600;
}

.ctl-button {
    background: var(--surface-2);
    color: var(--ink);
    justify-self: start;
}

.ctl-button:hover,
.seg button:hover {
    color: var(--ink);
}

.ctl-button:hover {
    background: color-mix(in srgb, var(--ink) 9%, var(--surface-2));
}

.seg button:focus-visible,
.ctl-button:focus-visible,
.ctl-play:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--link) 55%, transparent);
    outline-offset: 1px;
}

.ctl-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.4rem;
}

.ctl-time {
    grid-template-columns: auto 1fr minmax(3.6rem, auto);
}

.ctl-play {
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    border: 0;
    background: var(--ink);
    color: var(--surface);
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
}

.ctl-play svg {
    width: 0.95rem;
    height: 0.95rem;
    fill: currentColor;
}

.ctl-readout {
    font-size: 0.86rem;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
}

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

/* Small tables of numbers. */
table.numbers {
    border-collapse: collapse;
    font-size: 0.86rem;
    width: 100%;
    font-variant-numeric: tabular-nums;
}

table.numbers th,
table.numbers td {
    text-align: right;
    padding: 0.32rem 0.6rem;
    border-bottom: 1px solid var(--grid);
}

table.numbers th:first-child,
table.numbers td:first-child {
    text-align: left;
    padding-left: 0;
}

table.numbers th {
    color: var(--ink-2);
    font-weight: 500;
}

/* A formula set apart from the text. */
.formula {
    font-size: 1.02rem;
    text-align: center;
    margin: 1.4rem auto;
    line-height: 1.9;
    overflow-x: auto;
    padding: 0.2rem 0;
}

.formula i,
p i.v {
    font-family: var(--font);
    font-style: italic;
}

.note {
    font-size: 0.86rem;
    color: var(--ink-2);
    border-left: 3px solid var(--grid);
    padding: 0.1rem 0 0.1rem 0.9rem;
}

.footer {
    border-top: 1px solid var(--grid);
    margin-top: 5rem;
    padding: 2rem 20px 4rem;
    font-size: 0.84rem;
    color: var(--ink-2);
}

.fig-error {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 1rem;
    color: var(--ink-2);
    font-size: 0.9rem;
}

@media (max-width: 640px) {
    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.65rem;
        margin-top: 3rem;
    }

    h3 {
        font-size: 1.35rem;
    }

    .fig-stage {
        aspect-ratio: var(--ratio-narrow, var(--ratio, 4 / 3));
    }

    .ctl-slider {
        grid-template-columns: 1fr auto;
        row-gap: 0;
    }

    .ctl-slider input {
        grid-column: 1 / -1;
        grid-row: 2;
    }
}

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