/* Distill-style article on white around a bright-field view of the liquid.
   Colors sampled from Citron's photo "Clarkia pulchella flower" (Wikimedia
   Commons, CC BY-SA 3.0), the plant whose pollen Robert Brown watched in 1827:
   the soil's greys for the liquid, the petals' magenta for the beads, a leaf
   green for the diffusive fit. */
:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --text: rgba(0, 0, 0, 0.8);
    --text-2: rgba(0, 0, 0, 0.6);
    --text-3: rgba(0, 0, 0, 0.45);
    --hairline: rgba(0, 0, 0, 0.1);
    --grid: rgba(0, 0, 0, 0.08);
    --accent: #871e9b;          /* petal shadow */
    --accent-ink: #ffffff;
    --series: #871e9b;
    --ballistic: rgba(0, 0, 0, 0.45);
    --diffusive: #5b8c4e;       /* leaf */
    --viewport-bg: #cacabf;     /* light soil */
    --mol-cool: #97948a;        /* soil */
    --mol-hot: #4c494a;         /* soil in shadow */
    --bead: #c966db;            /* petal */
    --bead-hi: #e588f3;
    --bead-lo: #871e9b;
    --trail: #871e9b;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --text-col: 648px;
    --page-col: 984px;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 17px/1.7 var(--font);
}

a { color: inherit; text-decoration-color: rgba(0, 0, 0, 0.3); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }

nav.site, .title, .byline, .prose, .appendix > * {
    max-width: var(--text-col);
    margin-left: auto;
    margin-right: auto;
}

nav.site { padding: 14px 16px 0; font-size: 13px; max-width: var(--page-col); }
nav.site a { color: var(--text-3); text-decoration: none; }
nav.site a:hover { color: var(--text); }

.title { padding: 56px 16px 28px; }

.title h1 {
    margin: 0 0 12px;
    font-size: clamp(36px, 6vw, 50px);
    line-height: 1.1;
    font-weight: 700;
    color: rgba(0, 0, 0, 0.85);
}

.description { margin: 0; font-size: 21px; line-height: 1.5; color: var(--text-2); }

/* --- Demo */

.viewport {
    position: relative;
    width: 100%;
    height: clamp(320px, 62vh, 760px);
    background: var(--viewport-bg);
}

.viewport canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
#overlay { touch-action: pan-y; }   /* a touch that starts on a bead is captured in main.js */
body.dragged .hint { opacity: 0; }

.status {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    text-align: center;
    color: var(--text-2);
    font-size: 15px;
}

.status:empty { display: none; }

.hint {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    margin: 0;
    font-size: 12px;
    white-space: nowrap;
    padding: 2px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-2);
    pointer-events: none;
    transition: opacity 0.6s;
}

body:not(.ready) .hint { display: none; }

.panel { max-width: var(--page-col); margin: 0 auto; padding: 14px 16px 0; }

.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 28px;
    font-size: 14px;
}

.slider { display: inline-flex; align-items: center; gap: 10px; }
.slider .label { min-width: 0; }
.slider input { width: 150px; accent-color: var(--accent); }
.slider output { font: 13px var(--mono); color: var(--text-2); min-width: 7.5em; font-variant-numeric: tabular-nums; }

.label {
    color: var(--text-3);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

button {
    font: inherit;
    font-size: 14px;
    padding: 4px 12px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 5px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

button:hover { border-color: rgba(0, 0, 0, 0.4); }

.results {
    margin-top: 14px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 210px;
    gap: 20px;
    align-items: end;
}

@media (max-width: 700px) {
    .results { grid-template-columns: minmax(0, 1fr); }
}

.chart-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 12px;
}

.chart-title { font-weight: 600; font-size: 13px; color: var(--text); }

.legend { display: inline-flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); }
.legend span::before { content: ''; display: inline-block; vertical-align: middle; margin-right: 6px; }
.legend .dot::before { width: 6px; height: 6px; border-radius: 50%; background: var(--series); }
.legend .dash::before { width: 14px; height: 0; border-top: 2px dashed var(--ballistic); }
.legend .dots::before { width: 14px; height: 0; border-top: 2px dotted var(--diffusive); }

.chart-wrap { position: relative; }
.chart-wrap canvas { display: block; width: 100%; height: 190px; }

.readouts {
    margin: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
    border-top: 1px solid var(--hairline);
}

@media (max-width: 700px) {
    .readouts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
    .readouts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.readouts div { padding: 7px 0; border-bottom: 1px solid var(--hairline); min-width: 0; }
.readouts dt {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.readouts dd { margin: 0; font: 14px var(--mono); color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Byline */

.byline {
    margin-top: 36px;
    padding: 12px 16px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px 24px;
    border-top: 1px solid var(--hairline);
    border-bottom: 1px solid var(--hairline);
    font-size: 13px;
    line-height: 1.5;
}

.byline h3 {
    margin: 0 0 4px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
}

.byline p { margin: 0; color: var(--text); }

@media (max-width: 560px) {
    .byline { grid-template-columns: minmax(0, 1fr); }
}

/* --- Article */

.prose { padding: 32px 16px 48px; }

.prose h2 {
    margin: 2.2rem 0 1.2rem;
    padding-bottom: 0.9rem;
    border-bottom: 1px solid var(--hairline);
    font-size: 24px;
    line-height: 1.25;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.85);
}

.prose p { margin: 0 0 1.1em; }

.prose .katex-display { margin: 0.6em 0 1.1em; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

.prose table { border-collapse: collapse; font-size: 14px; margin: 0.4em 0 1.3em; width: 100%; }
.prose th, .prose td { text-align: right; padding: 5px 10px; border-bottom: 1px solid var(--hairline); font-variant-numeric: tabular-nums; }
.prose th:first-child, .prose td:first-child { text-align: left; padding-left: 0; }
.prose th { font-weight: 600; font-size: 12px; color: var(--text-2); }

button.inline {
    display: inline;
    margin: 0 0.15em;
    padding: 0 9px;
    font-size: 14px;
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    border-radius: 999px;
}

code { font: 0.9em var(--mono); }

figure { margin: 1.4em 0; }
figure img { display: block; width: 100%; height: auto; }
figcaption { font-size: 13px; line-height: 1.5; color: var(--text-2); margin-top: 8px; }

a.cite { color: var(--text-2); text-decoration: none; font-size: 0.85em; white-space: nowrap; }
a.cite:hover { color: var(--accent); }

/* --- Appendix */

.appendix {
    border-top: 1px solid var(--hairline);
    padding: 20px 16px 64px;
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.6;
}

.appendix > * { max-width: calc(var(--text-col) - 32px); }

.appendix h3 {
    margin-top: 22px;
    margin-bottom: 8px;
    font-size: 15px;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.65);
}

.appendix a { color: var(--text-2); }

.refs { padding-left: 1.3em; margin-top: 0; }
.refs li { margin-bottom: 0.5em; }
.refs li:target { background: #fff8d6; }
