/* Light or dark as the system asks; a site that embeds the page can fix the theme with
   data-theme="light", "dark", "colour" or "khaki" on <html>. In colour the accent is the
   background; in khaki, ink on a grey khaki in monospace, the accent is the ink. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#fff, #000);
  --ink: light-dark(oklch(0.18 0.006 260), oklch(0.95 0.003 260));
  --muted: light-dark(oklch(0.48 0.008 260), oklch(0.70 0.006 260));
  --dim: light-dark(oklch(0.55 0.007 260), oklch(0.60 0.006 260));
  --faint: light-dark(oklch(0.72 0.006 260), oklch(0.45 0.006 260));
  --line: light-dark(oklch(0.87 0.004 260), oklch(0.28 0.004 260));
  --field: light-dark(oklch(0.975 0.002 260), oklch(0.16 0.004 260));
  --accent: light-dark(oklch(0.52 0.22 264), oklch(0.70 0.17 264));
  --on-accent: light-dark(#fff, #000);
  --sans: "Inter Variable", Inter, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono Variable", "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --run: 0.9rem;   /* horizontal run of a connector in the diagram */
  --node: 7.5rem;  /* width of one column of the diagram */
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="colour"] {
  color-scheme: dark;
  --bg: oklch(0.52 0.22 264);
  --ink: #fff;
  --muted: oklch(1 0 0 / 0.87);
  --dim: oklch(1 0 0 / 0.84);
  --faint: oklch(1 0 0 / 0.55);
  --line: oklch(1 0 0 / 0.32);
  --field: oklch(1 0 0 / 0.1);
  --accent: #fff;
  --on-accent: oklch(0.52 0.22 264);
}
:root[data-theme="khaki"] {
  color-scheme: light;
  --bg: oklch(0.85 0.03 95);
  --ink: oklch(0.33 0.02 90);
  --muted: oklch(0.41 0.02 90);
  --dim: oklch(0.45 0.02 90);
  --faint: oklch(0.62 0.025 92);
  --line: oklch(0.72 0.03 93);
  --field: oklch(0.80 0.032 94);
  --accent: oklch(0.33 0.02 90);
  --on-accent: oklch(0.85 0.03 95);
  --sans: var(--mono);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 0.9375rem/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; border-radius: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.top, .diagram, .panel, .foot { max-width: 80rem; margin-inline: auto; padding-inline: 2rem; }

/* ---------------------------------------------------------------- header */

.top { padding-block: 3rem 1.75rem; }
.top h1 { margin: 0 0 0.6rem; font-size: clamp(2.25rem, 5vw, 3.25rem); font-weight: 700; line-height: 1; letter-spacing: -0.035em; }
.top p { margin: 0; max-width: 34rem; font-size: 1.0625rem; color: var(--muted); }

/* --------------------------------------------------------------- diagram */

.diagram { padding-block: 1.5rem; overflow-x: auto; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line); }

.tree { position: relative; display: flex; align-items: center; width: max-content; font-size: 0.8125rem; line-height: 1.25; }
.tree ul { display: flex; flex-direction: column; margin: 0 0 0 var(--run); padding: 0; list-style: none; }
.tree li { display: flex; align-items: center; padding-left: var(--run); }

/* Connectors are drawn by wires() in app.js, on top of this layout. */
.wires { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.wires path { fill: none; stroke: var(--line); stroke-width: 1; }
.wires path.on { stroke: var(--accent); stroke-width: 1.5; }

.node { flex: none; width: var(--node); margin-block: 1px; padding: 0.28rem 0.45rem; border: 0; background: none; text-align: left; cursor: pointer; }
.node:hover { color: var(--accent); }
.node.root { width: auto; padding-left: 0; font-weight: 600; }
.node.test { width: auto; font-weight: 600; white-space: nowrap; }
.node.jump { width: auto; white-space: nowrap; }

.tree li.off > .node { color: var(--dim); }
.tree li.off > .node:hover { color: var(--accent); }
.tree li.on > .node { color: var(--accent); font-weight: 600; }
.tree li.leaf.on > .node { background: var(--accent); color: var(--on-accent); }

/* On a narrow screen the diagram is folded under its title, closed until asked for. */
.fold summary { display: flex; align-items: baseline; justify-content: space-between; font-size: 0.875rem; font-weight: 600; list-style: none; cursor: pointer; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: "+"; font: 400 1.125rem/1 var(--mono); color: var(--muted); }
.fold[open] summary::after { content: "\2212"; }
.fold[open] summary { margin-bottom: 1.25rem; }

/* ----------------------------------------------------------------- panel */

.panel { padding-block: 2rem 4rem; min-height: 24rem; }

.crumbs { display: flex; flex-wrap: wrap; gap: 0 0.5rem; margin: 0 0 1rem; padding: 0; list-style: none; font-size: 0.8125rem; color: var(--muted); }
.crumbs li + li::before { content: "/"; margin-right: 0.5rem; color: var(--faint); }

.link { padding: 0; border: 0; background: none; cursor: pointer; text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 0.2em; }
.link:hover { color: var(--accent); text-decoration-color: currentColor; }

.panel h2 { margin: 0 0 1.25rem; max-width: 32ch; font-size: 1.75rem; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; }

/* What a subject is, before the first question. */
.intro { max-width: 62ch; margin: 0 0 2.25rem; color: var(--muted); }
.intro p { margin: 0 0 0.5rem; }
.intro ul { margin: 0; padding-left: 1rem; }
.intro li { margin-bottom: 0.35rem; }
.intro li::marker { color: var(--faint); }

/* What a question means, between it and its options. */
.question-about { max-width: 62ch; margin: -0.25rem 0 1.75rem; color: var(--muted); }
.question-about p { margin: 0 0 0.5rem; }

.options { max-width: 56rem; margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--ink); }
.options li { border-bottom: 1px solid var(--line); }
.options button { display: grid; grid-template-columns: 17rem 1fr; gap: 1.5rem; align-items: baseline; width: 100%; padding: 1rem 0; border: 0; background: none; text-align: left; cursor: pointer; }
.option-label { font-size: 1.125rem; font-weight: 600; }
.option-hint { max-width: 60ch; color: var(--muted); }
.options button:hover .option-label { color: var(--accent); }

.work { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 3rem; align-items: start; padding-top: 1.5rem; border-top: 1px solid var(--ink); }

/* ---------------------------------------------------------------- theory */

.theory .about { max-width: 62ch; margin: 0 0 1.5rem; font-size: inherit; }

.theory section { margin-top: 1.25rem; padding-top: 0.7rem; border-top: 1px solid var(--line); }
.theory h3 { margin: 0 0 0.5rem; font-size: 0.8125rem; font-weight: 600; }
.theory p, .theory li { max-width: 62ch; margin: 0 0 0.55rem; font-size: 0.875rem; }
.theory ul { margin: 0; padding-left: 1rem; }
.theory li::marker { color: var(--faint); }

/* Formulae sit flush left with the text, in display style. */
math { font-size: 1.06em; }
.theory p.formula { margin: 0.8rem 0; overflow-x: auto; overflow-y: hidden; }
.formula math { display: inline math; math-style: normal; }

/* The data and the result, one under the other. */
.result { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }

/* ---------------------------------------------------------------- inputs */

.field { margin-bottom: 1.1rem; }
.field label, .label { display: block; margin: 0 0 0.3rem; font-size: 0.8125rem; font-weight: 600; }

input[type="text"], textarea, select { width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--line); background: var(--field); }
input[type="text"], textarea { font-family: var(--mono); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
input[type="text"]:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: -1px; }
textarea { display: block; min-height: 6.5rem; line-height: 1.45; resize: vertical; }

.samples, .pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.samples.single { grid-template-columns: 1fr; }
.samples > .hint, .samples > .link, .samples > .note { grid-column: 1 / -1; justify-self: start; margin-bottom: 1.1rem; }

.sample-head { display: flex; align-items: baseline; gap: 0.75rem; margin-bottom: 0.3rem; }
.sample-head .label { margin: 0; }
input[type="text"].sample-name { flex: 1; min-width: 0; padding: 0; border: 0; border-bottom: 1px solid transparent; background: none; font: 600 0.8125rem var(--sans); }
input[type="text"].sample-name:hover, input[type="text"].sample-name:focus-visible { border-bottom-color: var(--faint); outline: 0; }
.remove { font-size: 0.8125rem; color: var(--muted); }

.hint, .echo { margin: 0.3rem 0 0; font-size: 0.8125rem; color: var(--muted); }
.echo { min-height: 1.25em; font-family: var(--mono); font-size: 0.75rem; }

.check { display: flex; align-items: center; gap: 0.5rem; }
.check input { accent-color: var(--accent); }
.check label { margin: 0; font-weight: 400; font-size: 0.9375rem; }

.actions { display: flex; gap: 1.25rem; margin-top: 1.5rem; font-size: 0.875rem; }

/* ---------------------------------------------------------------- result */

.p-value { margin: 0 0 0.75rem; font: 600 3rem/1 var(--mono); letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.p-value.significant { color: var(--accent); }
.verdict { max-width: 46ch; margin: 0 0 1.5rem; font-size: 1.0625rem; }
/* A page that runs two tests names each above its p-value. */
.verdict-title { margin: 0 0 0.6rem; font-size: 0.8125rem; font-weight: 600; }
.verdict + .verdict-title, .verdict + .note + .verdict-title { margin-top: 2rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }

/* The terms give way to the values on a narrow screen, where they wrap. */
.figures { display: grid; grid-template-columns: minmax(0, max-content) minmax(45%, 1fr); margin: 0 0 1.5rem; border-top: 1px solid var(--line); }
.figures dt, .figures dd { margin: 0; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.figures dt { padding-right: 2rem; color: var(--muted); }
.figures dd, .report-text { font-family: var(--mono); font-size: 0.875rem; font-variant-numeric: tabular-nums; }

.report { margin: 0 0 1.5rem; }
.report .label .link { margin-left: 0.5rem; font-weight: 400; color: var(--muted); }
.report-text { margin: 0; user-select: all; }

.note { max-width: 60ch; margin: 0 0 1rem; padding-left: 0.75rem; border-left: 2px solid var(--ink); font-size: 0.875rem; }
.note .link { margin-left: 0.25rem; }

/* Q-Q plots: hairline frame, points in ink, the line through the quartiles in the accent. */
.normality { margin: 0 0 1.5rem; }
.qq-row { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; margin: 0.4rem 0 0.6rem; }
.qq-figure { margin: 0; }
.qq-figure figcaption { margin-top: 0.3rem; font: 0.75rem var(--mono); color: var(--muted); }
.qq { display: block; }
.qq .frame { fill: none; stroke: var(--line); }
.qq .fit { stroke: var(--accent); stroke-width: 1; }
.qq circle { fill: var(--ink); }

/* Shares in the groups: bars in ink, the expectation under independent members in the accent. */
.splits { margin: 0 0 1.5rem; }
.shares { display: block; overflow: visible; }
.shares .axis { stroke: var(--line); }
.shares .bar { fill: var(--ink); }
/* In colour and khaki the accent is the ink's colour: the bars step back so that the expectation
   shows on them. */
:root[data-theme="colour"] .shares .bar, :root[data-theme="khaki"] .shares .bar { fill: var(--faint); }
.shares .expected { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.shares circle { fill: var(--accent); }
.shares text { font: 9px var(--mono); fill: var(--muted); }

/* A table wider than the screen scrolls in its own box. */
.table-scroll { margin: 0 0 1.5rem; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
caption { padding-bottom: 0.4rem; text-align: left; font-weight: 600; }
th, td { padding: 0.35rem 0 0.35rem 1rem; border-bottom: 1px solid var(--line); text-align: right; font-weight: 400; }
td { font-family: var(--mono); font-variant-numeric: tabular-nums; }
thead th { border-bottom-color: var(--ink); color: var(--muted); }
th:first-child { padding-left: 0; text-align: left; white-space: nowrap; }

/* The result in words, for screen readers: it is read once per result. */
.said { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.empty { color: var(--muted); }
.problem-title { margin: 0 0 0.25rem; font-weight: 600; }
.problem p { max-width: 46ch; }

/* ------------------------------------------------------------ step by step */

/* How the result was computed, with the numbers entered: a button under the figures opens the
   steps in a window centred over the dimmed page, numbered, formulae on their own lines, each
   followed by what its symbols stand for, and the distribution p is read from. */
.open-steps { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; width: 100%; margin: 0 0 1.5rem; padding: 0.65rem 0.85rem; border: 1px solid var(--ink); background: none; font-size: 0.9375rem; font-weight: 600; text-align: left; cursor: pointer; }
.open-steps::after { content: "\2192"; font: 400 1rem/1 var(--mono); }
.open-steps:hover { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
dialog.steps { width: min(46rem, 100vw - 2rem); max-width: none; max-height: min(56rem, 100dvh - 2rem); padding: 0; border: 1px solid var(--ink); background: var(--bg); color: var(--ink); }
dialog.steps[open] { display: flex; flex-direction: column; }
dialog.steps::backdrop { background: oklch(0 0 0 / 0.5); }
html:has(dialog.steps[open]) { overflow: hidden; }
.steps header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; padding: 1rem 1.5rem 0.9rem; border-bottom: 2px solid var(--ink); }
.steps header .label { margin-bottom: 0.2rem; color: var(--muted); font-weight: 400; }
.steps header h2 { margin: 0; font-size: 1.375rem; font-weight: 700; line-height: 1.15; letter-spacing: -0.015em; }
.steps header .scripts { display: flex; flex-wrap: wrap; gap: 0.2rem 0.75rem; margin: 0.5rem 0 0; font-size: 0.8125rem; color: var(--muted); }
.steps .download { white-space: nowrap; color: var(--ink); text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 0.2em; }
.steps .download::after { content: " \2193"; color: var(--accent); }
.steps .download:hover { color: var(--accent); text-decoration-color: currentColor; }
.steps .close { flex: none; padding: 0.35rem 0.7rem; border: 1px solid var(--line); background: none; font-size: 0.8125rem; cursor: pointer; }
.steps .close:hover { border-color: var(--accent); color: var(--accent); }
.steps-body { min-height: 0; padding: 0.25rem 1.5rem 1.5rem; overflow-y: auto; overscroll-behavior: contain; }
.steps ol { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; padding: 0.9rem 0 0.5rem; border-bottom: 1px solid var(--line); }
.steps h3 { margin: 0 0 0.5rem; font-size: 0.9375rem; font-weight: 600; }
.steps h3::before { content: counter(step); display: inline-block; min-width: 1.6rem; font: 500 0.875rem var(--mono); color: var(--accent); }
.steps li p { max-width: 62ch; margin: 0 0 0.5rem; font-size: 0.875rem; }
.steps p.formula { margin: 0.6rem 0; overflow-x: auto; overflow-y: hidden; }
.steps .table-scroll { margin: 0.5rem 0 0.75rem; }
.steps-body > .hint { margin: 1rem 0 0; }
.where { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.2rem 0.9rem; max-width: 62ch; margin: 0.25rem 0 0.75rem; padding-left: 0.75rem; border-left: 1px solid var(--line); font-size: 0.8125rem; }
.where dt { margin: 0; }
.where dd { margin: 0; color: var(--muted); }
:root[data-theme="colour"] dialog.steps::backdrop { background: oklch(0 0 0 / 0.35); }

/* The distribution p is read from: the curve or the bars in ink, what makes p in the accent. */
.null-figure { margin: 0.6rem 0 0.75rem; }
.null-figure figcaption { max-width: 46ch; margin-top: 0.3rem; font-size: 0.75rem; color: var(--muted); }
.null { display: block; max-width: 100%; height: auto; overflow: visible; }
.null .curve { fill: none; stroke: var(--ink); stroke-width: 1.25; }
.null .tail { fill: var(--accent); opacity: 0.4; }
.null .mark { stroke: var(--accent); stroke-width: 1.5; }
.null .mark.echo { stroke-dasharray: 2 2; }
.null .axis { stroke: var(--line); }
.null .bar { fill: var(--faint); }
.null .bar.counted { fill: var(--accent); }
.null text { font: 9px var(--mono); fill: var(--muted); }
.null text.strong { font-weight: 600; fill: var(--ink); }

/* ---------------------------------------------------------------- footer */

.foot { padding-block: 1.25rem 3rem; border-top: 1px solid var(--line); font-size: 0.8125rem; color: var(--muted); }
.foot p { margin: 0; }

/* Further reading: the books side by side, each its reference, then what it is for. */
.reading { margin-bottom: 1.75rem; }
.reading h2 { margin: 0 0 0.75rem; font-size: 0.8125rem; font-weight: 600; color: var(--ink); }
.reading ul { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.5rem; margin: 0 0 1rem; padding: 0; list-style: none; }
.reading li { padding-top: 0.6rem; border-top: 1px solid var(--line); }
.reading .ref { margin-bottom: 0.3rem; color: var(--ink); }
.reading a { color: inherit; text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 0.2em; }
.reading a:hover { color: var(--accent); text-decoration-color: currentColor; }
.reading .aside { max-width: 72ch; }

/* ----------------------------------------------------------------- khaki */

/* The title in capitals, spaced: only plain words are, as symbols keep their case. The answers
   to a question are boxes with a square before them, filled with the ink on hover, as the accent
   is the ink; so is a node of the diagram, under the pointer or chosen. */
:root[data-theme="khaki"] .top h1 { font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; }
:root[data-theme="khaki"] .reading h2 { letter-spacing: 0.08em; text-transform: uppercase; }
:root[data-theme="khaki"] .panel h2 { font-weight: 600; letter-spacing: 0; }
:root[data-theme="khaki"] .diagram { border-top-width: 1px; }
:root[data-theme="khaki"] .node:hover, :root[data-theme="khaki"] .tree li.off > .node:hover { background: var(--field); color: var(--ink); }
:root[data-theme="khaki"] .options { display: grid; gap: 0.375rem; border-top: 0; }
:root[data-theme="khaki"] .options li { border-bottom: 0; }
:root[data-theme="khaki"] .options button { padding: 0.8rem 0.9rem; background: var(--field); }
:root[data-theme="khaki"] .options button:hover { background: var(--ink); color: var(--bg); }
:root[data-theme="khaki"] .options button:hover :is(.option-label, .option-hint) { color: var(--bg); }
:root[data-theme="khaki"] .option-label::before { content: ""; display: inline-block; width: 0.45em; height: 0.45em; margin-right: 0.7em; vertical-align: 0.15em; background: currentColor; }

@media (max-width: 52rem) {
  .top, .diagram, .panel, .foot { padding-inline: 1.25rem; }
  .reading ul { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .work { grid-template-columns: minmax(0, 1fr); gap: 2rem; }
  .options button { grid-template-columns: 1fr; gap: 0.25rem; }
  .p-value { font-size: 2.25rem; }
}
