/* Figure colours read the page's tokens; the home map's own stylesheet falls back to the light values. */
:root {
  --fig-bg: var(--surface);
  --fig-ink: var(--ink);
  --fig-muted: var(--muted);
  --fig-body: var(--muted);
  --fig-faint: var(--faint);
  --fig-line: var(--wire);
  --fig-faint-line: var(--line);
  --fig-stroke: var(--line-strong);
  --fig-node: var(--surface);
  --fig-external: var(--sunken);
  /* A system outside the runtime: a folder, a model's API, a workspace. Sunken in light; in dark the sunken fill
     would read as a hole in the card, so it stands a step over the surface instead. */
  --fig-outside-fill: var(--sunken);
  --fig-region: var(--boundary);
  --fig-outside: var(--warn);
  --fig-accent: var(--accent);
  --fig-accent-ink: var(--accent-ink);
  --fig-accent-pale: var(--accent-pale);
  --fig-on-accent: var(--on-accent);
  --fig-ok: var(--ok);
  --fig-ok-pale: var(--ok-pale);
  --fig-danger: var(--danger);
  --fig-danger-pale: var(--danger-pale);
  --fig-warn: var(--warn);
  --fig-warn-pale: var(--warn-pale);
  --fig-series-ink: var(--series-ink);
  /* The home map colours a part by what it deals with: what you supply, the model, tools, storage. Each has the
     actor's colour for its mark, a pale ground and a soft outline. */
  --fig-you: var(--actor-you);
  --fig-you-pale: color-mix(in srgb, var(--actor-you) 9%, var(--surface));
  --fig-you-line: color-mix(in srgb, var(--actor-you) 45%, var(--surface));
  --fig-you-active: color-mix(in srgb, var(--actor-you) 18%, var(--surface));
  --fig-model: var(--actor-model);
  --fig-model-pale: color-mix(in srgb, var(--actor-model) 9%, var(--surface));
  --fig-model-line: color-mix(in srgb, var(--actor-model) 45%, var(--surface));
  --fig-model-active: color-mix(in srgb, var(--actor-model) 18%, var(--surface));
  --fig-tool: var(--actor-tool);
  --fig-tool-pale: color-mix(in srgb, var(--actor-tool) 9%, var(--surface));
  --fig-tool-line: color-mix(in srgb, var(--actor-tool) 45%, var(--surface));
  --fig-tool-active: color-mix(in srgb, var(--actor-tool) 18%, var(--surface));
  --fig-tool-on-active: var(--fig-tool);  /* a tool part's words on its fill in use */
  --fig-store: var(--actor-session);
  --fig-store-pale: color-mix(in srgb, var(--actor-session) 9%, var(--surface));
  --fig-store-line: color-mix(in srgb, var(--actor-session) 45%, var(--surface));
  --fig-store-active: color-mix(in srgb, var(--actor-session) 18%, var(--surface));
  /* The Loop on the home map, and the line round a group of parts: a process, the runtime, a part outside it. */
  --fig-loop-pale: var(--accent-pale);
  --fig-group-line: var(--line-strong);
}
/* On the dark surface a 9% tint is still near black, so a part's hue would show in its outline alone. The dark theme
   mixes more of the colour into the fill and the outline. Blue takes less in its fill than violet, so the two stand
   apart; its outline takes more, since the dark theme's blue is a step darker than the other hues. */
:root[data-theme="dark"] {
  --fig-you-pale: color-mix(in srgb, var(--actor-you) 20%, var(--surface));
  --fig-you-line: color-mix(in srgb, var(--actor-you) 56%, var(--surface));
  --fig-you-active: color-mix(in srgb, var(--actor-you) 28%, var(--surface));
  --fig-model-pale: color-mix(in srgb, var(--actor-model) 16%, var(--surface));
  --fig-model-line: color-mix(in srgb, var(--actor-model) 64%, var(--surface));
  --fig-model-active: color-mix(in srgb, var(--actor-model) 28%, var(--surface));
  --fig-tool-pale: color-mix(in srgb, var(--actor-tool) 20%, var(--surface));
  --fig-tool-line: color-mix(in srgb, var(--actor-tool) 56%, var(--surface));
  --fig-tool-active: color-mix(in srgb, var(--actor-tool) 28%, var(--surface));
  /* The tool colour stands under 4.5:1 on that fill, so its words there are in ink. */
  --fig-tool-on-active: var(--ink);
  --fig-store-pale: color-mix(in srgb, var(--actor-session) 22%, var(--surface));
  --fig-store-line: color-mix(in srgb, var(--actor-session) 56%, var(--surface));
  --fig-store-active: color-mix(in srgb, var(--actor-session) 28%, var(--surface));
  --fig-loop-pale: color-mix(in srgb, var(--accent) 28%, var(--surface));
  --fig-group-line: color-mix(in srgb, var(--wire) 75%, var(--surface));
  --fig-outside-fill: var(--stage);
}
.engineering-viewport {
  background: var(--fig-bg);
  overflow: auto;
  margin: 0 16px;
  border-radius: var(--radius);
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}
.engineering-viewport:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.engineering-art {
  width: 100%;
  height: auto;
  display: block;
  min-width: 900px;
}
/* The home map stands on the page with no frame and no heading of its own. Beside it, on the right, is an axis of
   the course's stages: choosing one draws the map as it stands after that stage. Under both, one line says what
   the chosen stage adds and changes; it keeps the height of its longest stage, so choosing another never moves
   the page. */
/* The home map's ground takes the cards' corner. */
.runtime-map .e-region.is-ground { rx: var(--radius-card); ry: var(--radius-card); }
/* The map starts at the column's left edge, under the title, and its axis stands beside it. */
.runtime-map {
  display: grid;
  grid-template-columns: minmax(0, 720px) max-content;
  justify-content: start;
  column-gap: 40px;
  margin: 8px 0 0;
}
.runtime-map > .engineering-viewport {
  margin: 0;
  background: none;
}
/* The figure's own ground is left out: the map stands on the page's. */
.runtime-map .engineering-art .e-bg {
  display: none;
}
/* The sentence under the map takes the map's width and adds nothing to it. It starts where the key does. */
.runtime-map > .map-stage-line {
  grid-column: 1;
  box-sizing: border-box;
  width: 0;
  min-width: 100%;
  padding-left: calc(min(100%, 720px) * var(--key-inset));
}
/* The map starts at the column's left edge at every width, as the title over it does. */
.runtime-map .engineering-art {
  min-width: 600px;
  max-width: 720px;
  margin-inline: 0;
}
/* The key under the map stands outside its scroll box, in the map's own drawing: its entries on equal columns, inset
   from the map's sides as far as the map's parts are. An entry the map does not draw now (no lesson completed, no
   stage chosen) keeps its cell unseen, so the key is as tall at every stage and nothing under it moves. */
.runtime-map > .map-key {
  grid-column: 1;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(var(--key-columns), minmax(0, 1fr));
  grid-template-rows: repeat(var(--key-rows), 24px);
  align-items: center;
  width: min(100%, 720px);
  margin: 4px 0 0;
  padding: 0 calc(min(100%, 720px) * var(--key-inset));
  list-style: none;
  color: var(--muted);
  font: 400 var(--text-xs) / 1.3 var(--sans);
}
.map-key > li {
  grid-row: var(--row);
  grid-column: var(--column);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}
.map-key > li.is-unseen { visibility: hidden; }
.map-key-icon { flex: none; overflow: visible; }
/* The axis: a node for each stage on one line, as tall as the map's ground, and after the last a node for the
   whole runtime, "All". A node is filled for every stage the map has reached. The rows, set on the element, are
   the ground's share of the figure cut into one row for each stage and one for "All"; the line runs from the
   first node to the last, and its filled part to the node of the last stage reached, which it slides to when
   another is chosen. */
.map-stages {
  --row: calc(var(--ground) / (var(--stages) + 1));
  --all: calc(var(--over) + var(--ground) + var(--under));
  position: relative;
  align-self: stretch;
  display: grid;
}
/* The item shown stands on a block of colour with no outline. When another is chosen the block travels to it:
   the edge on the side it is going to leaves first and the other follows, so it stretches and then settles. */
.map-stage-box {
  --top: calc((var(--over) + var(--row) * (var(--at) + 0.5)) / var(--all) * 100% - 20px);
  position: absolute;
  left: -8px;
  right: 0;
  top: var(--top);
  bottom: calc(100% - var(--top) - 40px);
  border-radius: var(--radius-sm);
  background: var(--accent-pale);
  pointer-events: none;
  transition: bottom 0.3s cubic-bezier(0.3, 0.7, 0.2, 1), top 0.3s cubic-bezier(0.3, 0.7, 0.2, 1) 0.09s;
}
.map-stages[data-dir="up"] .map-stage-box {
  transition: top 0.3s cubic-bezier(0.3, 0.7, 0.2, 1), bottom 0.3s cubic-bezier(0.3, 0.7, 0.2, 1) 0.09s;
}
.map-stages::before,
.map-stages::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 12px;
  top: calc((var(--over) + var(--row) * 0.5) / var(--all) * 100%);
  width: 2px;
  height: calc(var(--row) * var(--stages) / var(--all) * 100%);
  background: var(--line-strong);
}
.map-stages::after {
  height: calc(var(--row) * (var(--reached) - 1) / var(--all) * 100%);
  background: var(--accent);
  transition: height 0.36s cubic-bezier(0.3, 0.7, 0.2, 1);
}
/* An item is a node on the line and a name. The node holds the stage's number, as the stage marks of a figure's
   timeline do; the name is in the weight of the map's own labels, so the axis does not outweigh the map. */
.map-stages button {
  position: relative;
  z-index: 2;
  align-self: center;
  display: grid;
  grid-template-columns: 26px auto auto;
  justify-content: start;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 0 12px 0 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  font: 400 var(--text-sm) / 1.3 var(--sans);
  text-align: left;
  transition: color 0.2s ease;
}
.map-stage-n {
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--paper);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
/* The node of the whole runtime, where the axis ends, holds a ring in place of a number. */
.map-stage-n.is-end {
  background: var(--line-strong);
  box-shadow: inset 0 0 0 5px var(--paper);
}
/* How many of the stage's lessons the reader has completed, quiet beside its name; green once all are. */
.map-stage-count {
  margin-left: -4px;
  color: var(--faint);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}
.map-stage-count.is-done { color: var(--ok); font-weight: 600; }
/* A stage the map has reached: its node is filled and its name is in ink. */
.map-stages button.is-reached {
  color: var(--ink);
}
.map-stages button.is-reached .map-stage-n {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.map-stages button:hover {
  color: var(--ink);
}
/* The item shown is named in the accent; nothing changes weight or size, so nothing moves. */
.map-stages button[aria-pressed="true"] {
  color: var(--accent-ink);
}
/* What the chosen stage is about: its number, as its node on the axis shows it, and one sentence in ink, starting
   where the map's key starts. */
.map-stage-line {
  display: grid;
  margin: 0;
  padding-top: 8px;
  font: 400 var(--text-sm) / 22px var(--sans);
  color: var(--ink);
}
.map-stage-line > p { grid-area: 1 / 1; display: flex; align-items: start; gap: 10px; margin: 0; }
.map-line-n {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.map-stage-line > p[aria-hidden="true"] { visibility: hidden; }
/* A part or line the chosen stage brings fades in where it stands; one it does without fades out first. Nothing
   that stays is drawn again, so nothing moves. */
.runtime-map .e-enter {
  animation: map-enter 0.4s ease both;
  animation-delay: calc(var(--n, 0) * 35ms);
}
@keyframes map-enter {
  from { opacity: 0; }
}
.runtime-map .e-leave {
  opacity: 0;
  transition: opacity 0.16s ease;
}
@media (prefers-reduced-motion: reduce) {
  .runtime-map .e-enter { animation: none; }
  .runtime-map .e-leave, .map-stages::after, .map-stages button, .map-stages .map-stage-n,
  .map-stages .map-stage-box { transition: none; }
}
/* The axis stands beside the map, as tall as it; the key and the sentence stand under the map. */
.runtime-map > .map-stages {
  grid-row: 1;
  grid-column: 2;
}
/* Where the column has no room for the axis beside the map, the stages stand in rows under the key. The stage shown
   keeps its pale block, on its own button; each button has room for the block at its left, so the nodes still start
   at the column's edge. */
@media (max-width: 1180px) {
  .runtime-map {
    grid-template-columns: minmax(0, 1fr);
  }
  .runtime-map > .map-stages {
    grid-row: auto;
    grid-column: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 0 8px;
    margin-left: -8px;
    padding-top: 12px;
  }
  .map-stages button {
    padding-left: 8px;
  }
  .map-stages button[aria-pressed="true"] {
    background: var(--accent-pale);
  }
  .map-stages::before,
  .map-stages::after {
    content: none;
  }
  .map-stage-box {
    display: none;
  }
}
/* On a phone the map scrolls sideways in its box; the key wraps on two columns under it, in the column, and the
   sentence starts at the column's edge. */
@media (max-width: 720px) {
  .runtime-map > .map-key {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-rows: 24px;
    width: 100%;
    padding: 0;
  }
  .map-key > li {
    grid-row: auto;
    grid-column: auto;
  }
  .runtime-map > .map-stage-line {
    padding-left: 0;
  }
  /* The stages stand on two even columns, as the key over them does; on a phone, where two names would not fit
     beside each other, one to a row. */
  .runtime-map > .map-stages > button {
    flex: 0 0 calc(50% - 4px);
  }
}
@media (max-width: 600px) {
  .runtime-map > .map-stages > button {
    flex-basis: 100%;
  }
}
@media (min-width: 1600px) {
  .engineering-viewport {
    max-width: 1300px;
    margin-left: auto;
    margin-right: auto;
  }
}
@media (max-width: 720px) {
  .engineering-viewport {
    margin: 0 8px;
  }
  .engineering-art {
    min-width: 850px;
  }
}
