:root {
  color-scheme: light dark;
  --paper: #F2F5F4;
  --ink: #14212B;
  --soft: #55656F;
  --rule: #D5DCDB;
  --line: #2B5B6B;
  --decrypt-fill: #A5472D;
  --backdrop: #C5D0D8;
  --interface: "Avenir Next", "Segoe UI Variable Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --reading: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #101A21;
    --ink: #E7EDF0;
    --soft: #9FB0BA;
    --rule: #2A3944;
    --line: #93C5D6;
    --decrypt-fill: #DF9A7C;
    --backdrop: #263843;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 1.125rem/1.6 var(--reading); }
.page { max-width: 80rem; margin-inline: auto; padding: 3.25rem 1.5rem 5rem; }
.lesson-header { padding-bottom: 2.5rem; }
h1, h2, h3, .course-label, button, label, select, caption, .interface-note, summary { font-family: var(--interface); }
h1, h2, h3, p, figure { margin: 0; }
h1 { max-width: 21ch; font-size: clamp(2.5rem, 6vw, 4.25rem); line-height: 1.04; letter-spacing: -0.025em; }
h2 { font-size: 1.625rem; line-height: 1.2; letter-spacing: -0.015em; }
h3 { font-size: 1.1875rem; line-height: 1.3; }
.course-label { margin-bottom: 0.625rem; color: var(--soft); font-size: 0.9375rem; font-weight: 600; }
.course-label span { margin-inline: 0.3em; }
.course-label a { display: inline-flex; align-items: center; min-height: 2.75rem; }
a, summary { color: var(--line); text-decoration: underline; text-decoration-thickness: 1px; }
a:hover, summary:hover { text-decoration-thickness: 2px; }
.lede { max-width: 38rem; margin-top: 1rem; font-size: 1.25rem; }

.experiment { border-block: 1px solid var(--rule); padding-block: 1.5rem; }
.activity-intro { margin-top: 0.375rem; max-width: 40rem; }
.messages {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: 1rem;
  margin-top: 1.35rem;
  padding-block: 1.1rem;
  border-block: 1px solid var(--line);
}
.messages h3, .chart-field legend { margin-bottom: 0.35rem; font-size: 0.9375rem; }
.message code { font-size: 1.125rem; }
.message .word { display: inline-block; }
.message .letter { border-bottom: 2px solid transparent; }
.message .current { color: var(--line); border-color: currentColor; }
.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem clamp(1rem, 3vw, 2rem);
  margin-top: 1.25rem;
}
.chart-field { min-inline-size: 0; margin: 0; border: 0; padding: 0; }
.chart-field legend { padding: 0; font-family: var(--interface); font-weight: 700; }
.count-chart { margin: 0; padding: 0; list-style: none; }
.count-chart li + li { margin-top: 0.2rem; }
button, select, .count-row {
  min-height: 2.75rem;
  border: 1px solid var(--soft);
  border-radius: 0.4rem;
  padding: 0.5rem 0.65rem;
  color: var(--ink);
  background: var(--paper);
  font-size: 0.875rem;
  font-weight: 600;
}
button, select, summary, .count-row { cursor: pointer; }
button:hover, .count-row:hover { text-decoration: underline; }
select:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--line); outline-offset: 3px; }
.chart-choice:focus-visible + .count-row { outline: 2px solid var(--line); outline-offset: 3px; }
.count-row {
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr) 1.25rem 1.6rem;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  text-align: left;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.count-row span:nth-child(3), .chart-guess { text-align: right; }
.chart-guess { color: var(--line); }
.chart-choice:checked + .count-row { border-color: var(--line); box-shadow: inset 0 0 0 1px var(--line); }
.count-row .bar { height: 0.42rem; border-radius: 0.12rem; background: var(--line); }
.guess-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.guess-controls label { width: 100%; font-size: 0.9375rem; font-weight: 650; }
.interface-note { margin-top: 0.55rem; color: var(--soft); font-size: 0.9375rem; }
.interface-note.feedback { min-height: 3.2em; color: var(--ink); }
.clue { border-top: 1px solid var(--rule); }
.clue p { margin-top: 0.25rem; }
.fallback { border-block: 1px solid var(--rule); padding-block: 1rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.reading { max-width: 40rem; margin-top: 3.25rem; }
.reading p { margin-top: 1rem; }
.reading h2:not(:first-child) { margin-top: 3.25rem; }
code { font: 1em/1.6 var(--mono); overflow-wrap: anywhere; }
.solution { margin-top: 1rem; }
.counts-table { width: 100%; max-width: 27rem; margin-block: 1.25rem; border-collapse: collapse; text-align: left; }
.counts-table caption { color: var(--soft); text-align: left; }
.counts-table caption, .counts-table th { font-size: 0.9375rem; font-family: var(--interface); }
.counts-table th, .counts-table td { border-bottom: 1px solid var(--rule); padding: 0.35rem 0.25rem 0.35rem 0; }
.counts-table td { font-family: var(--mono); }
.check { margin-top: 3.25rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
details { margin-top: 0.35rem; }
summary { min-height: 2.75rem; width: fit-content; padding-block: 0.5rem; font-size: 0.9375rem; font-weight: 600; }

@media (max-width: 39rem) {
  .page { padding-top: 2rem; }
  .workbench { grid-template-columns: 1fr; }
}

@media (forced-colors: active) {
  .count-row .bar { forced-color-adjust: none; background: CanvasText; }
  .chart-choice:checked + .count-row { border: 2px solid Highlight; }
  .message .current { border-color: Highlight; }
}

@media print {
  :root { --paper: #fff; --ink: #000; --soft: #000; --rule: #999; --line: #000; }
  .page { padding: 0; }
  .experiment { display: none; }
  .fallback[hidden] { display: block !important; }
  .reading details:not([open]), .reading summary { display: none; }
  .reading { margin-top: 0; }
}
