/* C, from the ground up — base structure: layout, lesson blocks, exercises, editor, console.
   The look itself (tokens, type, the terminal frame) comes from terminal.css, which overrides
   these defaults for :root[data-look='terminal']. */

:root {
  --paper: #0b0c0b;
  --paper-raised: #111411;
  --paper-sunk: #070807;
  --form: #3ddc4a;
  --form-strong: #7cf08a;
  --form-soft: #24402a;
  --form-faint: #142017;
  --ink: #dbe9d8;
  --ink-2: #b2c7af;
  --ink-3: #8ba487;
  --mast-bg: #111411;
  --mast-ink: #dbe9d8;
  --mast-ink-2: #b2c7af;
  --mast-rule: #24402a;
  --on-form: #071007;
  --red: #ff5f56;
  --red-soft: #2e1210;
  --warn: #ffb000;
  --warn-soft: #261d07;
  --hot: #3b3305;

  --tk-kw: #c879ff;
  --tk-type: #2cb2ff;
  --tk-str: #ffb000;
  --tk-num: #ff7ab8;
  --tk-com: #7c977a;
  --tk-pre: #22d3c5;
  --tk-fn: #dbe9d8;

  --font-read: 'JetBrains Mono', ui-monospace, monospace;
  --font-code: 'JetBrains Mono', ui-monospace, monospace;
  --font-form: 'VT323', ui-monospace, monospace;

  --code-size: 0.9375rem;
  --code-lh: 1.5rem;
  --code-pad-y: 0.75rem;
  --mast-h: 4.75rem;
  --rail-w: 15.5rem;
  --ident-w: 15rem;
  --measure: 44rem;
  --radius: 3px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  color-scheme: dark;
}

/* ---------- base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--mast-h) + 1.5rem);
  scrollbar-color: var(--form-soft) transparent;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.0625rem/1.65 var(--font-read);
  font-variant-numeric: tabular-nums;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--form-soft);
  color: var(--ink);
}

:focus-visible {
  outline: 2px solid var(--form);
  outline-offset: 2px;
  border-radius: 1px;
}

a {
  color: var(--form-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: color-mix(in srgb, var(--form) 45%, transparent);
}
a:hover {
  text-decoration-color: currentColor;
}

code {
  font-family: var(--font-code);
  font-size: 0.92em;
  background: var(--form-faint);
  padding: 0.05em 0.3em;
  border-radius: 2px;
  overflow-wrap: break-word;
}

pre {
  margin: 0;
  font-family: var(--font-code);
}

h1,
h2,
h3 {
  text-wrap: balance;
}

[hidden] {
  display: none !important;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0.5rem;
  z-index: 100;
  background: var(--paper-raised);
  padding: 0.5rem 1rem;
}
.skip:focus {
  left: 0.5rem;
}

.icon {
  display: inline-flex;
  width: 1.125em;
  height: 1.125em;
  flex: none;
}
.icon svg {
  width: 100%;
  height: 100%;
}

.field-label {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 650;
  font-size: 0.75rem;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--form);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
}

/* ---------- masthead: the printed header of the coding form ---------- */

.masthead {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--mast-bg);
  color: var(--mast-ink);
}

.mast-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-height: 3.5rem;
  padding-inline: 0.75rem 0.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-right: 1.25rem;
  color: var(--mast-ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand-c {
  font-family: var(--font-form);
  font-weight: 800;
  font-stretch: 75%;
  font-size: 2rem;
  line-height: 1;
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--mast-ink-2);
  border-radius: 2px;
}
.brand-rest {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 650;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.form-fields {
  display: flex;
  flex: 1;
  margin: 0;
  min-width: 0;
  border-left: 1px solid var(--mast-rule);
}
.field {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.35rem 0.9rem;
  border-right: 1px solid var(--mast-rule);
  min-width: 0;
}
.field dt {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 600;
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mast-ink-2);
}
.field dd {
  margin: 0;
  font-family: var(--font-code);
  font-size: 0.9rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-program {
  flex: 1;
}
.field-compiler dd[data-state='loading'] {
  color: var(--mast-ink-2);
}
.field-compiler dd[data-state='error'] {
  color: #ffd2cc;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--mast-ink);
  width: 2.75rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 1.15rem;
}
.icon-btn:hover {
  background: color-mix(in srgb, var(--mast-ink) 12%, transparent);
}
.icon-btn:focus-visible {
  outline-color: var(--mast-ink);
  outline-offset: -4px;
}
.rail-toggle {
  display: none;
}

/* the 1–80 column ruler printed under the form header */
.ruler {
  display: flex;
  height: 1.25rem;
  background: var(--paper);
  border-bottom: 1px solid var(--form);
  overflow: hidden;
}
.ruler .col {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  border-left: 1px solid var(--form-soft);
  font-family: var(--font-form);
  font-stretch: 75%;
  font-size: 0.6875rem;
  line-height: 1.25rem;
  color: var(--form);
  padding-left: 2px;
  white-space: nowrap;
}
.ruler .col::after {
  content: '';
  position: absolute;
  left: -1px;
  bottom: 0;
  width: 1px;
  height: 0.3rem;
  background: var(--form);
}
.ruler .col.is-five::after {
  height: 0.5rem;
}
.ruler .col.is-ten::after {
  height: 100%;
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--ident-w);
  align-items: start;
  min-height: calc(100vh - var(--mast-h));
}

#view {
  grid-column: 2;
  padding: 2.5rem clamp(1.25rem, 4vw, 3.5rem) 6rem;
  min-width: 0;
  outline: none;
}
#view > * {
  max-width: var(--measure);
  margin-inline: auto;
}
#view > .home {
  max-width: 52rem;
}
.loading-sheet {
  color: var(--ink-3);
}

/* ---------- rail: the statement-number column ---------- */

.rail {
  grid-column: 1;
  position: sticky;
  top: var(--mast-h);
  height: calc(100vh - var(--mast-h));
  overflow-y: auto;
  border-right: 1px solid var(--form);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
}
.rail-head {
  display: grid;
  grid-template-columns: 3rem 1fr;
  border-bottom: 1px solid var(--form);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 1;
}
.rail-head .field-label {
  padding: 0.5rem 0.65rem 0.4rem;
}
.rail-head .field-label:first-child {
  border-right: 1px solid var(--form-soft);
}
.rail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}
.rail-part {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 600;
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 0.85rem 0.65rem 0.3rem 3.65rem;
  border-bottom: 1px solid var(--form-soft);
  background: linear-gradient(to right, transparent calc(3rem - 1px), var(--form-soft) calc(3rem - 1px), var(--form-soft) 3rem, transparent 3rem);
}
.rail-row {
  position: relative;
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr) 1.75rem;
  align-items: center;
  min-height: 2.5rem;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--form-soft);
  font-size: 0.92rem;
  line-height: 1.25;
}
.rail-row:hover {
  background: var(--form-faint);
}
.rail-no {
  align-self: stretch;
  display: grid;
  place-items: center;
  font-family: var(--font-code);
  font-size: 0.85rem;
  color: var(--form);
  border-right: 1px solid var(--form-soft);
}
.rail-title {
  padding: 0.45rem 0.65rem;
}
.rail-row.is-active {
  background: var(--form-faint);
}
.rail-row.is-active .rail-no {
  background: var(--form);
  color: var(--on-form);
  border-right-color: var(--form);
}
.rail-row.is-active .rail-title {
  font-weight: 700;
}

/* state is a mark, not a hue: empty box / pencil tick / checked box */
.rail-mark,
.ex-mark {
  width: 1rem;
  height: 1rem;
  border: 1.5px solid var(--form);
  border-radius: 1px;
  display: grid;
  place-items: center;
  position: relative;
  color: var(--on-form);
}
.rail-row.is-partial .rail-mark::after {
  content: '';
  position: absolute;
  width: 1.5px;
  height: 0.75rem;
  background: var(--form);
  transform: rotate(35deg);
}
.rail-row.is-done .rail-mark {
  background: var(--form);
}
.rail-mark .icon,
.ex-mark .icon {
  width: 0.8rem;
  height: 0.8rem;
}
/* the folded corner: where you stopped */
.rail-row.is-flagged::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 0.75rem;
  height: 0.75rem;
  background: linear-gradient(225deg, var(--paper) 50%, var(--form) 50%);
  box-shadow: -1px 1px 1px color-mix(in srgb, var(--ink) 18%, transparent);
}
.rail-foot {
  border-top: 1px solid var(--form);
}
.rail-play .rail-no .icon {
  width: 1rem;
  height: 1rem;
}
.rail-play {
  grid-template-columns: 3rem 1fr;
}
.rail-tally {
  padding: 0.6rem 0.65rem 0.8rem 3.65rem;
  font-size: 0.82rem;
  color: var(--ink-2);
}
.tally-num {
  font-family: var(--font-code);
  color: var(--form);
}

/* ---------- identification field (right margin) ---------- */

.ident {
  grid-column: 3;
  position: sticky;
  top: var(--mast-h);
  max-height: calc(100vh - var(--mast-h));
  overflow-y: auto;
  padding: 2.5rem 1.25rem 2rem 0;
  font-size: 0.88rem;
  line-height: 1.4;
  scrollbar-width: thin;
}
.ident-block {
  border-top: 1px solid var(--form);
  padding-top: 0.5rem;
  margin-bottom: 2rem;
}
.ident-block .field-label {
  margin-bottom: 0.5rem;
}
.toc,
.docs {
  list-style: none;
  margin: 0;
  padding: 0;
}
.toc a,
.docs a {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0;
  color: var(--ink-2);
  text-decoration: none;
  border-bottom: 1px solid var(--form-soft);
}
.toc a:hover,
.docs a:hover {
  color: var(--ink);
}
.toc a.is-current {
  color: var(--ink);
  font-weight: 700;
}
.toc code {
  font-size: 0.85em;
}
.docs a .icon {
  color: var(--form);
  margin-top: 0.1rem;
}
.toc-tally {
  flex: none;
  padding-top: 0.25rem;
}

.tally {
  display: inline-flex;
  gap: 2px;
}
.tally-box {
  width: 0.55rem;
  height: 0.55rem;
  border: 1px solid var(--form);
  border-radius: 1px;
}
.tally-box.is-done {
  background: var(--form);
}

/* ---------- reading typography ---------- */

.display {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 700;
  font-size: clamp(2.25rem, 5vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.01em;
  margin: 0.25rem 0 0.75rem;
  color: var(--ink);
}
.lede {
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 0 0 1.5rem;
  max-width: 38rem;
}

.lesson-head {
  margin-bottom: 3rem;
}
.lesson-facts {
  display: flex;
  margin: 0 0 1.5rem;
  border-block: 1px solid var(--form);
}
.lesson-facts > div {
  padding: 0.45rem 1.5rem 0.45rem 0;
  margin-right: 1rem;
  border-right: 1px solid var(--form-soft);
}
.lesson-facts > div:last-child {
  border-right: 0;
}
.lesson-facts dt {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 600;
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--form);
}
.lesson-facts dd {
  margin: 0;
  font-size: 0.95rem;
}
.goals ul {
  margin: 0.4rem 0 0;
  padding-left: 1.25rem;
}
.goals li {
  margin-bottom: 0.2rem;
}
.goals li::marker {
  color: var(--form);
}

.lesson-section {
  margin-bottom: 3.5rem;
}
.lesson-section > h2,
.home h2,
.part-title {
  font-family: var(--font-form);
  font-stretch: 80%;
  font-weight: 700;
  font-size: 1.65rem;
  line-height: 1.15;
  letter-spacing: -0.005em;
  margin: 0 0 1rem;
  padding-top: 0.6rem;
  border-top: 2px solid var(--form);
}
.lesson-section h3 {
  font-size: 1.12rem;
  margin: 2rem 0 0.5rem;
}
.lesson-section p,
.lesson-section ul,
.lesson-section ol {
  margin: 0 0 1rem;
}
.lesson-section li {
  margin-bottom: 0.3rem;
}
.lesson-section li::marker {
  color: var(--form);
}
strong {
  font-weight: 700;
}

/* tables printed on the form */
.table-wrap {
  overflow-x: auto;
  margin: 0 0 1.25rem;
}
.grid-table {
  border-collapse: collapse;
  font-size: 0.95rem;
  min-width: 60%;
}
.grid-table th {
  text-align: left;
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 650;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--form);
  border-bottom: 1.5px solid var(--form);
  padding: 0.4rem 0.75rem 0.3rem 0;
}
.grid-table td code {
  white-space: nowrap;
}
.grid-table td {
  border-bottom: 1px solid var(--form-soft);
  padding: 0.4rem 0.75rem 0.4rem 0;
  vertical-align: top;
}

/* callouts: a boxed margin note, labelled like a form field */
.callout {
  margin: 1.5rem 0;
  padding: 0.75rem 1rem 0.25rem;
  border: 1px solid var(--form-soft);
  background: var(--paper-raised);
  border-radius: var(--radius);
}
.callout-label {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--form);
  margin-bottom: 0.25rem;
}
.callout-warn {
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
  background: var(--warn-soft);
}
.callout-warn .callout-label {
  color: var(--warn);
}
.callout-deep .callout-label {
  color: var(--ink-2);
}
.callout p:last-child {
  margin-bottom: 0.75rem;
}

/* ---------- code: written on the ruled coding sheet ---------- */

.code-sheet {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  margin: 0 0 1rem;
  border: 1px solid var(--form-soft);
  border-radius: var(--radius);
  background: var(--paper-sunk);
  font-size: var(--code-size);
  line-height: var(--code-lh);
  overflow: hidden;
}
.code-gutter {
  padding: var(--code-pad-y) 0.6rem var(--code-pad-y) 0.75rem;
  text-align: right;
  color: var(--form);
  opacity: 0.85;
  border-right: 1px solid var(--form-soft);
  background: var(--form-faint);
  user-select: none;
  font-size: 0.8em;
  line-height: calc(var(--code-lh) / 0.8 * 1);
  line-height: var(--code-lh);
}
.code-gutter span {
  display: inline-block;
  min-width: 1.5ch;
}
.code-gutter .mark-error {
  color: var(--paper);
  background: var(--red);
  border-radius: 2px;
  padding-inline: 0.25em;
  margin-right: -0.25em;
}
.code-gutter .mark-warning {
  color: var(--paper);
  background: var(--warn);
  border-radius: 2px;
  padding-inline: 0.25em;
  margin-right: -0.25em;
}
.code-body {
  padding: var(--code-pad-y) 1rem;
  overflow-x: auto;
  white-space: pre;
  tab-size: 4;
  font-family: var(--font-code);
  font-size: inherit;
  line-height: inherit;
  color: var(--ink);
  /* one ruled line per row of the sheet */
  background-image: linear-gradient(to bottom, transparent calc(var(--code-lh) - 1px), var(--form-faint) calc(var(--code-lh) - 1px));
  background-size: 100% var(--code-lh);
  background-position: 0 var(--code-pad-y);
  background-repeat: repeat-y;
  background-attachment: local;
  scrollbar-width: thin;
}
.code-body code,
.editor-highlight code {
  background: none;
  padding: 0;
  font-size: inherit;
  border-radius: 0;
  overflow-wrap: normal;
}
.code-plain .code-gutter {
  display: none;
}
.code-plain {
  grid-template-columns: minmax(0, 1fr);
}

.tk-kw {
  color: var(--tk-kw);
  font-weight: 700;
}
.tk-type {
  color: var(--tk-type);
  font-weight: 600;
}
.tk-str {
  color: var(--tk-str);
}
.tk-num {
  color: var(--tk-num);
}
.tk-com {
  color: var(--tk-com);
  font-style: italic;
}
.tk-pre {
  color: var(--tk-pre);
}
.tk-fn {
  color: var(--tk-fn);
  font-weight: 600;
}

/* editor = highlighted pre under a transparent textarea */
.editor {
  background: var(--paper-raised);
  border-color: var(--form);
}
.editor:focus-within {
  box-shadow: 0 0 0 1px var(--form);
}
.editor-stack {
  position: relative;
  min-width: 0;
}
.editor-highlight {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  margin: 0;
}
.editor-input {
  display: block;
  position: relative;
  width: 100%;
  margin: 0;
  border: 0;
  padding: var(--code-pad-y) 1rem;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
  font-family: var(--font-code);
  font-size: inherit;
  line-height: var(--code-lh);
  white-space: pre;
  overflow-x: auto;
  overflow-y: hidden;
  resize: none;
  tab-size: 4;
  outline: none;
  scrollbar-width: thin;
}
.editor-input::selection {
  background: color-mix(in srgb, var(--form) 28%, transparent);
  color: transparent;
}

.example {
  margin: 0 0 1.5rem;
}
.example .code-sheet {
  margin-bottom: 0.5rem;
}

/* ---------- buttons & toolbars ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 0.75rem;
}
.toolbar-spacer {
  flex: 1;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.5rem;
  padding: 0.4rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-form);
  font-stretch: 85%;
  font-weight: 650;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}
.btn .icon {
  width: 1rem;
  height: 1rem;
}
.btn-primary {
  background: var(--form);
  color: var(--on-form);
}
.btn-primary:hover {
  background: var(--form-strong);
}
.btn-secondary {
  border-color: var(--form);
  color: var(--form-strong);
  background: transparent;
}
.btn-secondary:hover {
  background: var(--form-faint);
}
.btn-quiet {
  color: var(--ink-2);
  background: transparent;
  padding-inline: 0.65rem;
}
.btn-quiet:hover {
  background: var(--form-faint);
  color: var(--ink);
}
.btn-danger {
  background: var(--red);
  color: var(--paper);
}
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}
.btn.is-busy {
  cursor: progress;
  opacity: 0.8;
}
.linklike {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink-3);
  font: inherit;
  font-size: 0.88rem;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}
.linklike:hover {
  color: var(--red);
}

/* ---------- stdin, prediction, field inputs ---------- */

.stdin-field,
.predict-field {
  display: grid;
  gap: 0.3rem;
  margin: 0.5rem 0;
}
.stdin-input,
.predict-input {
  width: 100%;
  font: var(--code-size) / var(--code-lh) var(--font-code);
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--form-soft);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  resize: vertical;
}
.stdin-input:focus,
.predict-input:focus {
  outline: none;
  border-color: var(--form);
  box-shadow: 0 0 0 1px var(--form);
}
.stdin-input::placeholder,
.predict-input::placeholder {
  color: var(--ink-3);
}
.given-input pre {
  font-size: var(--code-size);
  background: var(--paper-sunk);
  border: 1px dashed var(--form-soft);
  padding: 0.4rem 0.75rem;
  margin: 0.3rem 0 0.75rem;
  border-radius: var(--radius);
}

/* ---------- console ---------- */

.console {
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--form-soft);
  border-radius: var(--radius);
  background: var(--paper-raised);
}
.console > section {
  padding: 0.6rem 0.9rem;
}
.console > section + section {
  border-top: 1px solid var(--form-soft);
}
.console-label {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 650;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--form);
  margin-bottom: 0.35rem;
}
.console-out {
  font-size: var(--code-size);
  line-height: var(--code-lh);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 22rem;
  overflow-y: auto;
  color: var(--ink);
}
.console-out.is-empty {
  color: var(--ink-3);
  font-style: italic;
}
.console-err {
  color: var(--warn);
}
.console-status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--ink-3);
  margin-top: 0.4rem;
}
.console > .console-status {
  padding: 0.6rem 0.9rem;
  margin: 0;
}
.console-status .icon {
  color: var(--form);
}
.console-status.is-error {
  color: var(--red);
  font-weight: 600;
}
.console-status.is-busy {
  color: var(--ink-2);
}
.spinner {
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid var(--form-soft);
  border-top-color: var(--form);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

.console-diag.is-error {
  background: var(--red-soft);
}
.console-diag.is-error .console-label {
  color: var(--red);
}
.console-diag.is-warn .console-label {
  color: var(--warn);
}
.diag-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.diag {
  padding: 0.35rem 0;
}
.diag + .diag {
  border-top: 1px dashed color-mix(in srgb, var(--ink) 15%, transparent);
}
.diag-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}
.diag-kind {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--red);
}
.diag-warning .diag-kind {
  color: var(--warn);
}
.diag-line {
  font-family: var(--font-code);
  font-size: 0.82rem;
  color: var(--ink-2);
}
.diag-msg {
  background: none;
  padding: 0;
  font-size: 0.88rem;
  color: var(--ink);
}
.diag-explain {
  margin: 0.25rem 0 0;
  font-size: 0.95rem;
}
.diag-raw {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.diag-raw summary {
  cursor: pointer;
  color: var(--ink-2);
}
.diag-raw pre {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre;
  overflow-x: auto;
  color: var(--ink-2);
  padding-bottom: 0.25rem;
}

/* ---------- exercises: a boxed form ---------- */

.exercise {
  margin: 2.25rem 0 2.75rem;
  border: 1px solid var(--form);
  border-radius: var(--radius);
  background: var(--paper-raised);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 6%, transparent), 0 6px 18px -10px color-mix(in srgb, var(--ink) 18%, transparent);
}
.ex-head {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: stretch;
  border-bottom: 1px solid var(--form);
  background: var(--form-faint);
}
.ex-seq {
  display: grid;
  place-items: center;
  padding: 0 0.75rem;
  font-family: var(--font-code);
  font-size: 0.85rem;
  background: var(--form);
  color: var(--on-form);
}
.ex-type {
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 650;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--form);
  border-right: 1px solid var(--form-soft);
  white-space: nowrap;
}
.ex-title {
  margin: 0;
  padding: 0.6rem 0.9rem;
  font-size: 1.05rem;
  line-height: 1.3;
}
.ex-head .ex-mark {
  align-self: center;
  margin: 0 0.9rem;
  width: 1.25rem;
  height: 1.25rem;
}
.exercise.is-solved .ex-mark {
  background: var(--form);
}
.exercise.is-solved .ex-mark .icon {
  width: 1rem;
  height: 1rem;
}
.exercise.is-solved .ex-mark path {
  stroke-dasharray: 22;
  stroke-dashoffset: 0;
  animation: tick 520ms var(--ease-out) both;
}
@keyframes tick {
  from {
    stroke-dashoffset: 22;
  }
}
.ex-prompt,
.ex-work,
.ex-explain {
  padding: 0 1.1rem;
}
.ex-prompt {
  padding-top: 1rem;
}
.ex-prompt > :last-child {
  margin-bottom: 0.75rem;
}
.ex-work {
  padding-bottom: 0.75rem;
}
.ex-explain {
  border-top: 1px dashed var(--form-soft);
  padding-top: 0.75rem;
  padding-bottom: 0.25rem;
}
.ex-explain .field-label {
  margin-bottom: 0.25rem;
}

.ex-feedback {
  margin: 0.5rem 0;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius);
  font-size: 0.97rem;
}
.ex-feedback.is-pass {
  background: var(--form-faint);
  color: var(--form-strong);
}
.ex-feedback.is-error {
  background: var(--red-soft);
  color: var(--red);
}
.ex-feedback.is-info {
  background: var(--paper-sunk);
  color: var(--ink-2);
}

.hint,
.solution {
  border-top: 1px dashed var(--form-soft);
  padding-top: 0.6rem;
  margin-top: 0.75rem;
}
.hint p:last-child {
  margin-bottom: 0.5rem;
}

.tests {
  list-style: none;
  margin: 0.5rem 0;
  padding: 0;
  border: 1px solid var(--form-soft);
  border-radius: var(--radius);
}
.test {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr);
  gap: 0 0.5rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.95rem;
}
.test + .test {
  border-top: 1px solid var(--form-soft);
}
.test-mark {
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.1rem;
  border: 1.5px solid var(--form-soft);
  border-radius: 1px;
}
.test.is-pass .test-mark {
  background: var(--form);
  border-color: var(--form);
  color: var(--on-form);
}
.test.is-fail .test-mark {
  border-color: var(--red);
  color: var(--red);
}
.test.is-running .test-mark {
  border-style: dashed;
}
.test-mark .icon {
  width: 0.9rem;
  height: 0.9rem;
}
.test-detail {
  grid-column: 2;
}
.test-detail p {
  margin: 0.15rem 0 0.4rem;
  color: var(--red);
}
.compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.compare pre {
  margin-top: 0.2rem;
  font-size: 0.85rem;
  line-height: 1.45;
  background: var(--paper-sunk);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* quiz */
.quiz-note {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--ink-2);
}
.options {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}
.option label {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr);
  gap: 0.65rem;
  align-items: start;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--form-soft);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}
.option label:hover {
  background: var(--form-faint);
}
.option input {
  appearance: none;
  margin: 0.2rem 0 0;
  width: 1.1rem;
  height: 1.1rem;
  border: 1.5px solid var(--form);
  border-radius: 1px;
  background: var(--paper-raised);
  cursor: pointer;
}
.option input[type='radio'] {
  border-radius: 50%;
}
.option input:checked {
  background: var(--form);
  box-shadow: inset 0 0 0 2.5px var(--paper-raised);
}
.option-box {
  display: none;
}
.option label:has(input:checked) {
  border-color: var(--form);
}
.option.is-right label {
  border-color: var(--form);
  background: var(--form-faint);
}
.option.is-wrong label {
  border-color: var(--red);
  background: var(--red-soft);
}
.option.is-missed label {
  border-style: dashed;
  border-color: var(--form);
}
.option-text p {
  margin: 0;
}

/* fill-in blanks */
.blank {
  font: inherit;
  font-family: var(--font-code);
  color: var(--ink);
  background: var(--hot);
  border: 0;
  border-bottom: 1.5px solid var(--form);
  border-radius: 2px 2px 0 0;
  padding: 0 0.2ch;
  margin: 0 0.1ch;
  height: calc(var(--code-lh) - 2px);
  line-height: inherit;
  vertical-align: baseline;
}
.blank:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--form);
}
.blank.is-right {
  background: var(--form-faint);
  color: var(--form-strong);
}
.blank.is-wrong {
  background: var(--red-soft);
  border-bottom-color: var(--red);
  color: var(--red);
}
.blank.is-revealed {
  background: var(--warn-soft);
  border-bottom-color: var(--warn);
}
.fill-sheet .code-body {
  white-space: pre;
}

/* ---------- memory diagram: the ruled cells of the form ---------- */

.memory-figure {
  margin: 0 0 1.5rem;
}
.memory-figure .table-wrap {
  margin-bottom: 0.4rem;
}
.memory {
  border-collapse: collapse;
  min-width: min(100%, 30rem);
  font-size: 0.95rem;
  background: var(--paper-raised);
}
.memory th {
  font-family: var(--font-form);
  font-stretch: 75%;
  font-weight: 650;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--form);
  text-align: left;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--form);
  border-width: 0 0 1.5px;
}
.memory td {
  white-space: nowrap;
  border: 1px solid var(--form-soft);
  padding: 0.35rem 0.75rem;
  height: 2.4rem;
}
.memory td code {
  background: none;
  padding: 0;
}
.memory .m-addr {
  font-family: var(--font-code);
  font-size: 0.88rem;
  color: var(--form);
  background: var(--form-faint);
  text-align: right;
  white-space: nowrap;
  border-left: 0;
}
.memory th.m-addr {
  background: none;
}
.memory .m-name {
  font-family: var(--font-code);
  font-weight: 700;
}
.memory .m-type {
  font-family: var(--font-code);
  color: var(--ink-2);
  font-size: 0.88rem;
}
.memory .m-val {
  font-family: var(--font-code);
  min-width: 7rem;
  font-weight: 600;
}
.memory .m-note {
  white-space: normal;
  min-width: 12rem;
  color: var(--ink-2);
  font-size: 0.88rem;
  border-right: 0;
}
.memory tr.is-hot td:not(.m-addr) {
  background: var(--hot);
}
.memory tr.is-hot .m-addr {
  color: var(--form-strong);
  font-weight: 700;
}
.memory .blank {
  height: 1.7rem;
}
figcaption {
  font-size: 0.88rem;
  color: var(--ink-2);
}

/* ---------- home ---------- */

.home-intro {
  margin-bottom: 3.5rem;
}
.home-intro .display {
  font-size: clamp(2.75rem, 7vw, 5rem);
}
.resume-note {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  color: var(--ink-2);
  font-size: 0.95rem;
}
.resume-note .icon {
  color: var(--form);
}
.part {
  margin-bottom: 2.5rem;
}
.part-title {
  font-size: 1.15rem;
  font-stretch: 75%;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--form);
  margin-bottom: 0;
}
.contents-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.contents-row {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr) auto 6.5rem;
  align-items: stretch;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--form-soft);
}
.contents-row:hover {
  background: var(--form-faint);
}
.c-no {
  display: grid;
  place-items: center;
  font-family: var(--font-code);
  color: var(--form);
  border-right: 1px solid var(--form-soft);
  font-size: 0.95rem;
}
.contents-row.is-done .c-no {
  background: var(--form);
  color: var(--on-form);
}
.c-text {
  display: grid;
  padding: 0.65rem 1rem;
}
.c-title {
  font-weight: 700;
  font-size: 1.05rem;
}
.c-sub {
  color: var(--ink-2);
  font-size: 0.92rem;
  line-height: 1.4;
}
.c-meta {
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  font-size: 0.85rem;
  color: var(--ink-3);
  white-space: nowrap;
  border-left: 1px solid var(--form-soft);
}
.c-tally {
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  border-left: 1px solid var(--form-soft);
}
.home-notes {
  margin-top: 3rem;
}
.home-notes h2 {
  font-size: 1.3rem;
}
.home-notes ul {
  padding-left: 1.25rem;
  margin: 0 0 2rem;
}
.home-notes li {
  margin-bottom: 0.5rem;
}
.home-notes li::marker {
  color: var(--form);
}

/* ---------- pager ---------- */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  border-top: 2px solid var(--form);
  padding-top: 1rem;
  margin-top: 4rem;
}
.pager-link {
  display: grid;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--form-soft);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
}
.pager-link:hover {
  border-color: var(--form);
  background: var(--form-faint);
}
.pager-link.is-next {
  text-align: right;
  justify-items: end;
}
.pager-title {
  font-weight: 700;
}

/* ---------- playground ---------- */

.playground .editor {
  min-height: 20rem;
}

/* ---------- dialog ---------- */

.dialog {
  border: 1px solid var(--form);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  padding: 1.25rem 1.5rem;
  max-width: 28rem;
  box-shadow: 0 12px 40px -12px color-mix(in srgb, #000 40%, transparent);
}
.dialog::backdrop {
  background: color-mix(in srgb, var(--paper) 60%, transparent);
}
.dialog h2 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
}

/* ---------- responsive ---------- */

@media (max-width: 1280px) {
  .layout {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
  }
  .ident {
    display: none;
  }
}

@media (max-width: 960px) {
  :root {
    --mast-h: 4.25rem;
  }
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  #view {
    grid-column: 1;
    padding: 1.75rem 1rem 5rem;
  }
  .rail-toggle {
    display: grid;
  }
  .rail {
    position: fixed;
    left: 0;
    top: var(--mast-h);
    bottom: 0;
    height: auto;
    width: min(20rem, 88vw);
    z-index: 15;
    transform: translateX(-102%);
    transition: transform 280ms var(--ease-out);
    box-shadow: 8px 0 24px -12px color-mix(in srgb, #000 35%, transparent);
  }
  body.rail-open .rail {
    transform: none;
  }
  body.rail-open .layout::after {
    content: '';
    position: fixed;
    inset: var(--mast-h) 0 0;
    z-index: 14;
    background: color-mix(in srgb, var(--ink) 28%, transparent);
  }
  .field-card,
  .field-program {
    display: none;
  }
  .form-fields {
    justify-content: flex-end;
  }
  .brand {
    padding-right: 0.75rem;
  }
  .ruler .col {
    font-size: 0;
  }
  .ruler .col.is-ten {
    font-size: 0.6875rem;
  }
}

@media (max-width: 560px) {
  .brand-rest {
    display: none;
  }
  .field {
    padding-inline: 0.6rem;
  }
  .contents-row {
    grid-template-columns: 2.75rem minmax(0, 1fr);
  }
  .c-meta,
  .c-tally {
    display: none;
  }
  .ex-head {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }
  .ex-type {
    display: none;
  }
  .ex-prompt,
  .ex-work,
  .ex-explain {
    padding-inline: 0.75rem;
  }
  .pager {
    grid-template-columns: 1fr;
  }
  .lesson-facts > div {
    padding-right: 1rem;
  }
  .code-body,
  .editor-input {
    padding-inline: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
