:root {
  color-scheme: light dark;
  --paper: #F2F5F4;
  --ink: #14212B;
  --soft: #55656F;
  --rule: #D5DCDB;
  --line: #2B5B6B;
  --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;
    --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, legend, .interface-note, .selection-note, caption, th, 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; }
.fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.8fr);
  gap: 1rem 2rem;
  margin-top: 1.25rem;
}
.fields label, legend { font-size: 0.9375rem; font-weight: 650; }
textarea, button, .choice span, .character {
  min-height: 2.75rem;
  border: 1px solid var(--soft);
  border-radius: 0.4rem;
  padding: 0.45rem 0.65rem;
  background: var(--paper);
  color: var(--ink);
}
textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  resize: vertical;
  font: 1.125rem/1.5 var(--mono);
}
fieldset { min-inline-size: 0; margin: 0; border: 0; padding: 0; }
legend { padding: 0; }
.format-choices { display: flex; gap: 0.35rem; margin-top: 0.25rem; }
.choice, .character, button:not(:disabled) { cursor: pointer; }
.choice span { display: grid; place-items: center; min-width: 3.25rem; }
.choice :checked + span { border-color: var(--line); background: var(--line); color: var(--paper); }
button { font-size: 0.875rem; font-weight: 600; }
button:not(:disabled):hover { text-decoration: underline; }
button:disabled { border-color: var(--rule); color: var(--soft); }
:focus-visible, .choice :focus-visible + span, .mapping input:focus-visible + .character {
  outline: 2px solid var(--line);
  outline-offset: 3px;
}
.interface-note { margin-top: 0.35rem; color: var(--soft); font-size: 0.9375rem; }
#length-note:empty { margin: 0; }
.trace { margin-top: 1.4rem; width: 100%; }
.trace legend { margin-bottom: 0.15rem; }
.mapping {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  min-height: 4.65rem;
  margin: 0.7rem 0 0;
  padding: 0;
  list-style: none;
}
.mapping li { min-width: 0; max-width: 100%; }
.character {
  display: grid;
  place-items: center;
  min-width: 2.75rem;
  font: 650 1.05rem var(--mono);
  overflow-wrap: anywhere;
}
.byte-strip { display: flex; flex-wrap: wrap; gap: 1px; border-bottom: 2px solid var(--rule); }
.byte-strip code { padding: 0.3rem 0.25rem; font-size: 0.875rem; }
.mapping .selected .character { border-color: var(--line); box-shadow: inset 0 0 0 1px var(--line); }
.mapping .selected .byte-strip { border-color: var(--line); background: color-mix(in srgb, var(--line) 14%, var(--paper)); }
.selection-note { min-height: 2.8em; margin-top: 0.8rem; color: var(--soft); font-size: 0.9375rem; }
.decode { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.75rem 1.25rem; }
.decode-button:not(:disabled) { border-color: var(--line); color: var(--line); }
.decode h3 { font-size: 0.9375rem; }
.decoded-text {
  width: fit-content;
  min-width: 4rem;
  min-height: 1.9rem;
  border-bottom: 1px solid var(--rule);
  padding-inline: 0.25rem;
  font: 1rem/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.fallback { border-block: 1px solid var(--rule); padding-block: 1rem; }

.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); }
.worked { width: 100%; max-width: 29rem; margin-block: 1.25rem; border-collapse: collapse; }
.worked caption { margin-bottom: 0.35rem; text-align: left; color: var(--soft); font-size: 0.9375rem; }
.worked th, .worked td { border-bottom: 1px solid var(--rule); padding: 0.35rem 0.35rem 0.35rem 0; text-align: left; }
.worked th { color: var(--soft); font-size: 0.8125rem; }
.worked td { font-size: 0.9375rem; }
.worked td code { display: inline; }
.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; cursor: pointer; font-size: 0.9375rem; font-weight: 600; }

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

@media (max-width: 24rem) {
  .byte-strip code { font-size: 0.75rem; }
}

@media (forced-colors: active) {
  .choice :checked + span, .mapping .selected .character { border: 2px solid Highlight; }
  .mapping .selected .byte-strip { border-color: Highlight; }
}

@media print {
  :root { --paper: #fff; --ink: #000; --soft: #000; --rule: #999; --line: #000; }
  .page { padding: 0; }
  .experiment, .fallback { display: none; }
  .reading { margin-top: 0; }
  .worked { break-inside: avoid; }
}
