/* Shared styles for the BEE 4750/4850 explainers.
   Colours: Okabe-Ito in the decks' order, validated with the dataviz palette checker
   (light: exact Okabe-Ito; dark: the same hues stepped for the dark surface).
   kit/theme-boot.js always sets data-theme to "light" or "dark" before the first paint, so the dark
   tokens are defined once, below. */

:root {
  color-scheme: light;
  --page: #f8f7f4;
  --surface: #fdfdfc;
  --surface-2: #f1f0ec;
  --ink: #141413;
  --ink-2: #4c4b47;
  --muted: #696762;   /* 5.2:1 on --page, enough for 0.75rem labels */
  --grid: #e3e1da;
  --axis: #b9b7ae;
  --border: rgba(20, 20, 19, 0.12);
  --link: #0062a0;
  --focus: #0072b2;

  /* categorical series, fixed order */
  --s1: #0072b2;   /* blue */
  --s2: #d55e00;   /* vermillion */
  --s3: #009e73;   /* bluish green */
  --s4: #e69f00;   /* orange */
  --s5: #cc79a7;   /* reddish purple */
  /* roles used across the explainers */
  --data: var(--s1);       /* the record */
  --observed: var(--s2);   /* the observed statistic, the real thing */
  --model: #8d8b84;        /* draws from a model or null */
  --model-fill: #c9c7bf;

  --serif: "Source Serif 4", "Source Serif Pro", "Iowan Old Style", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 10px;
  --text-width: 44rem;
  --wide-width: 66rem;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c6c5bb;
  --muted: #94928b;
  --grid: #2c2c2a;
  --axis: #45453f;
  --border: rgba(255, 255, 255, 0.12);
  --link: #6cb6ec;
  --focus: #3d9be0;
  --s1: #3d9be0;
  --s2: #db6530;
  --s3: #179f78;
  --s4: #b88310;
  --s5: #c9709f;
  --model: #8a8881;
  --model-fill: #4a4945;
}

* { box-sizing: border-box; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
/* layout rules such as display: grid would otherwise override the hidden attribute */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 4rem; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.62;
}
a { color: var(--link); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.wrap { max-width: var(--text-width); margin: 0 auto; padding: 0 16px; }
.wide { max-width: var(--wide-width); margin: 0 auto; padding: 0 16px; }

/* ---- header and navigation ---------------------------------------------------------------- */

.hero { padding: 3.5rem 0 1.5rem; }
.course {
  font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 0.75rem;
}
h1 {
  font-family: var(--serif); font-weight: 600; font-size: clamp(2rem, 5.5vw, 3rem);
  line-height: 1.1; margin: 0 0 1rem; letter-spacing: -0.01em;
}
.dek { font-size: 1.2rem; color: var(--ink-2); margin: 0; max-width: 38rem; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.topbar .wide { display: flex; align-items: center; gap: 0.75rem; min-height: 3rem; }
.topbar nav {
  display: flex; gap: 0.15rem; overflow-x: auto; scrollbar-width: none; flex: 1;
  white-space: nowrap;
}
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a {
  font-size: 0.85rem; color: var(--ink-2); text-decoration: none;
  padding: 0.35rem 0.6rem; border-radius: 6px;
}
.topbar nav a:hover, .topbar nav a.active { background: var(--surface-2); color: var(--ink); }
.topbar .tools { display: flex; gap: 0.4rem; flex: none; }

/* ---- prose --------------------------------------------------------------------------------- */

section.part { padding: 2.5rem 0 1rem; }
h2 {
  font-family: var(--serif); font-weight: 600; font-size: 1.75rem; line-height: 1.2;
  margin: 0 0 0.9rem;
}
h3 { font-size: 1.05rem; margin: 1.6rem 0 0.4rem; }
p { margin: 0 0 1rem; }
ol, ul { padding-left: 1.3rem; margin: 0 0 1rem; }
li { margin: 0.2rem 0; }
strong { font-weight: 600; }
.num { font-family: var(--mono); font-size: 0.94em; font-variant-numeric: tabular-nums; }
.small { font-size: 0.9rem; color: var(--ink-2); }

/* the five steps of a test, or any short numbered procedure */
ol.steps { counter-reset: step; list-style: none; padding: 0; }
ol.steps > li {
  counter-increment: step; position: relative; padding: 0.15rem 0 0.15rem 2.2rem; margin: 0.35rem 0;
}
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 0.2rem;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--surface-2); color: var(--ink-2);
  font-size: 0.8rem; font-weight: 600; display: grid; place-items: center;
}

/* ---- figures and controls ------------------------------------------------------------------ */

.figure {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px 12px; margin: 1.25rem 0 1.5rem;
}
.figure .title { font-weight: 600; font-size: 0.95rem; margin: 0 0 0.15rem; }
.figure .subtitle { font-size: 0.85rem; color: var(--muted); margin: 0 0 0.6rem; }
.figure .chart { width: 100%; position: relative; }
.figure .chart svg { display: block; width: 100%; overflow: visible; }
.figure .caption { font-size: 0.85rem; color: var(--ink-2); margin: 0.5rem 0 0; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 1.25rem; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 0 1.25rem; }
@media (min-width: 860px) { .grid-3 { grid-template-columns: 1fr 1fr 1fr; } }
.grid-2-1 { display: grid; grid-template-columns: 1fr; gap: 0 1.25rem; }
@media (min-width: 760px) { .grid-2-1 { grid-template-columns: 1.6fr 1fr; } }

.controls { display: flex; flex-wrap: wrap; gap: 0.6rem 1.1rem; align-items: center; margin: 0 0 0.8rem; }
.control { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.control > .label { font-size: 0.78rem; color: var(--muted); letter-spacing: 0.02em; }
.control.inline { flex-direction: row; align-items: center; gap: 0.5rem; }
.control output { font-family: var(--mono); font-size: 0.85rem; color: var(--ink); min-width: 3.2rem; }
input[type="range"] { width: 11rem; accent-color: var(--s1); }
@media (max-width: 480px) { input[type="range"] { width: 100%; } .control { flex: 1 1 100%; } }

.btn {
  font: inherit; font-size: 0.88rem; line-height: 1.2; cursor: pointer;
  padding: 0.45rem 0.8rem; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink);
}
.btn:hover { border-color: var(--axis); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--ink); color: var(--page); border-color: var(--ink); }
.btn.primary:hover { opacity: 0.88; }
.btn.small { font-size: 0.8rem; padding: 0.3rem 0.6rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* segmented choice: a row of radio buttons styled as one control */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span {
  display: block; font-size: 0.85rem; padding: 0.38rem 0.75rem; color: var(--ink-2);
  background: var(--surface); border-right: 1px solid var(--border);
}
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--ink); color: var(--page); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }

/* key numbers under a figure */
.readout { display: flex; flex-wrap: wrap; gap: 0.5rem 1.6rem; margin: 0.4rem 0 0; }
.stat { display: flex; flex-direction: column; }
.stat .k { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.02em; }
.stat .v { font-family: var(--mono); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat .v.big { font-size: 1.6rem; }
.stat .note { font-size: 0.75rem; color: var(--muted); }

/* legend: identity never by colour alone */
.legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; font-size: 0.82rem; color: var(--ink-2); margin: 0.2rem 0 0.4rem; }
.legend .key { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend svg { flex: none; }

/* guess-then-reveal */
.guess {
  border: 1px dashed var(--axis); border-radius: var(--radius); padding: 0.9rem 1rem; margin: 1.25rem 0;
  background: var(--surface);
}
.guess .eyebrow { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 0.35rem; }
.guess p:last-child { margin-bottom: 0; }
.guess .choices { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.6rem 0 0.2rem; }
.guess .choices .btn[aria-pressed="true"] { background: var(--ink); color: var(--page); border-color: var(--ink); }
.reveal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.75rem 1rem; margin: 0 0 1rem; font-size: 0.95rem;
}
.guess .reveal { background: none; border: 0; padding: 0; margin: 0.5rem 0 0; }

/* lineups: a grid of real buttons, each holding a small chart */
.lineup { display: grid; grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr)); gap: 8px; }
.lineup button {
  position: relative; padding: 0; margin: 0; border: 1px solid transparent; border-radius: 6px;
  background: var(--surface-2); cursor: pointer; color: inherit; font: inherit; text-align: left;
}
.lineup button:hover:not(:disabled) { border-color: var(--axis); }
.lineup button:disabled { cursor: default; }
.lineup button svg { display: block; width: 100%; height: auto; }
.lineup .number, .lineup .tag {
  position: absolute; top: 3px; font-size: 11px; line-height: 1.2; color: var(--muted);
}
.lineup .number { left: 6px; }
.lineup .tag { right: 6px; color: var(--ink); font-weight: 600; }
.lineup button.is-real { border: 2.5px solid var(--observed); }
.lineup button.is-pick:not(.is-real) { border: 2.5px dashed var(--ink); }

table.results {
  border-collapse: collapse; width: 100%; font-size: 0.88rem; font-variant-numeric: tabular-nums;
}
table.results th, table.results td {
  padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap;
}
table.results th:first-child, table.results td:first-child { text-align: left; }
table.results thead th { color: var(--muted); font-weight: 400; font-size: 0.78rem; }
table.results td.num-cell { font-family: var(--mono); }
.table-scroll { overflow-x: auto; margin: 0 0 0.8rem; }

.aside {
  border-left: 3px solid var(--axis); padding: 0.2rem 0 0.2rem 1rem; margin: 1.2rem 0;
  color: var(--ink-2);
}

/* optional mathematics */
.math { display: none; }
body.show-math .math { display: block; }
.math-block {
  background: var(--surface-2); border-radius: 8px; padding: 0.6rem 0.9rem; margin: 0.6rem 0 1rem;
  overflow-x: auto; font-size: 0.95rem;
}

/* hover tooltip */
.tip {
  position: fixed; z-index: 50; pointer-events: none; display: none;
  background: var(--ink); color: var(--page); font-size: 0.8rem; line-height: 1.35;
  padding: 0.35rem 0.55rem; border-radius: 6px; max-width: 16rem;
  font-variant-numeric: tabular-nums;
}

/* chart text and chrome */
svg text { font-family: var(--sans); fill: var(--muted); font-size: 12px; }
svg .axis-label { fill: var(--ink-2); font-size: 12.5px; }
svg .direct-label { fill: var(--ink-2); font-size: 12px; }
svg .direct-label.strong { fill: var(--ink); font-weight: 600; }
svg .tick line { stroke: var(--grid); }
svg .domain { stroke: var(--axis); }
svg .gridline { stroke: var(--grid); stroke-width: 1; }

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

footer.about {
  margin-top: 3rem; padding: 2rem 0 4rem; border-top: 1px solid var(--border);
  font-size: 0.9rem; color: var(--ink-2);
}
footer.about h2 { font-size: 1.2rem; }
footer.about dl { display: grid; grid-template-columns: 1fr; gap: 0.2rem 1rem; margin: 0; }
@media (min-width: 640px) { footer.about dl { grid-template-columns: 9rem 1fr; } }
footer.about dt { color: var(--muted); }
footer.about dd { margin: 0 0 0.6rem; }

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--page); padding: 0.5rem 0.9rem; border-radius: 8px;
  font-size: 0.85rem; opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { .topbar, .controls, .btn { display: none !important; } }
