/*
 * The track page (track-view.js), and the Markdown of its read steps. Colours
 * come only from the theme contract's variables in style.css's :root.
 */

/* ---------- Where you are: the bar above every track screen ---------- */

.trackbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-4);
  font-size: var(--fs-sm);
}

.trackbar__back {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--ctl-h);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-accent-deep);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.trackbar__track {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--color-muted);
  text-decoration: none;
}

.trackbar__track:hover,
.trackbar__back:hover {
  text-decoration: underline;
}

/* ---------- The overview ---------- */

.track__kind {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: 0 0 var(--sp-2);
  color: var(--color-ink-soft);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.track__intro h2 {
  margin: 0;
}

.track__objectives {
  margin: var(--sp-3) 0 0;
  padding-left: 1.25rem;
}

.track__objectives li + li {
  margin-top: var(--sp-1);
}

.track__resources,
.step__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin: var(--sp-4) 0 0;
  padding: 0;
  list-style: none;
}

.step__links {
  margin: 0 0 var(--sp-4);
}

.md .step__links {
  margin: var(--sp-3) 0 0;
  padding-left: 0;
}

.track__resources .btn,
.step__links .btn {
  white-space: normal;
  text-align: left;
}

/* On the overview the notebooks are quiet links with their icon, so the
   sections stay the thing to press. */
.resources--quiet {
  gap: 0 var(--sp-4);
}

.resource-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--ctl-h);
  color: var(--color-accent-deep);
  font-weight: 600;
}

/* The overview's lead section: its Start or Continue drawn as the accent
   button, inside the row that is the button. */
.rows__go {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--color-accent-deep);
  color: var(--color-bg);
}

/* ---------- One step ---------- */

.track--step {
  display: grid;
  gap: var(--sp-4);
}

.trackview {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-6);
}

.trackview__main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-4);
  min-width: 0;
}

.trackview__rail {
  display: none;
}

.stephead h2 {
  margin: 0;
}

.stephead__why {
  margin-top: var(--sp-1);
  color: var(--color-ink-soft);
}

.strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-4);
  margin-top: var(--sp-3);
}

.strip__pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.strip__pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  padding: 0 var(--sp-3);
  border: 1.5px solid var(--color-line-strong);
  border-radius: var(--r-pill);
  background: var(--color-surface);
  color: var(--color-ink-soft);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-decoration: none;
}

.strip__pill--done {
  border-color: var(--color-accent-soft);
  background: var(--color-accent-soft);
  color: var(--color-accent-deep);
}

.strip__pill--current {
  border-color: var(--color-accent-deep);
  background: var(--color-accent-deep);
  color: var(--color-bg);
}

.strip__pill:focus-visible {
  outline: 2px solid var(--color-accent-deep);
  outline-offset: 2px;
}

.strip__text {
  color: var(--color-muted);
  font-size: var(--fs-sm);
}

.stepcard .step__title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-1) var(--sp-3);
  margin: 0 0 var(--sp-4);
  color: var(--color-ink);
  font-size: var(--fs-h3);
}

.step__done {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  color: var(--status-positive);
  font-size: var(--fs-sm);
  font-weight: 600;
}

/* Back on the left, the one forward button on the right. On a phone the
   footer stays at the bottom of the screen while the step scrolls. */
.stepfoot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
}

.stepfoot__back {
  margin-right: auto;
}

.stepfoot__next {
  white-space: normal;
  text-align: left;
}

@media (max-width: 600px) {
  .stepfoot {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 0 calc(-1 * var(--page-pad));
    padding: var(--sp-3) var(--page-pad);
    border-top: 1px solid var(--color-line);
    background: var(--color-surface);
  }

  .stepfoot__back {
    padding: 0 var(--sp-3);
  }

  .stepfoot__next {
    flex: 1;
    padding: var(--sp-2) var(--sp-4);
    justify-content: space-between;
  }
}

/* The section's steps and the track's other sections: a closed "Steps (n)"
   list at the top of the step, a rail beside it on wide screens. */
.trackall-box summary {
  min-height: var(--ctl-h);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--color-accent-deep);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.trackall-box summary::-webkit-details-marker {
  display: none;
}

.trackall-box[open] .trackall-box__chevron {
  transform: rotate(180deg);
}

.trackall-box[open] > .trackall {
  margin-top: var(--sp-2);
}

.trackall {
  margin: 0;
  padding: 0;
  list-style: none;
}

.trackall__section + .trackall__section {
  margin-top: var(--sp-4);
}

.trackall__title {
  display: block;
  margin-bottom: var(--sp-1);
  color: var(--color-ink-soft);
  font-size: var(--fs-sm);
  font-weight: 600;
}

/* Another section: its title only, a link to it. */
.trackall__title--link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-height: var(--ctl-h);
  margin: 0;
  padding: 0 var(--sp-2);
  border-radius: var(--r-ctl);
  text-decoration: none;
}

.trackall__title--link:hover {
  background: var(--color-surface-2);
}

/* Titles of other sections sit together; the current section's list has
   space around it. */
.trackall__section:not(.trackall__section--current) + .trackall__section:not(.trackall__section--current) {
  margin-top: 0;
}

.trackall__steps {
  margin: 0;
  padding: 0;
  list-style: none;
}

.trackall__step {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--ctl-h);
  padding: 0 var(--sp-2);
  border-radius: var(--r-ctl);
  color: var(--color-ink);
  text-decoration: none;
}

.trackall__step:hover {
  background: var(--color-surface-2);
}

.trackall__step--current {
  background: var(--color-accent-soft);
  font-weight: 600;
}

@media (min-width: 1100px) {
  .trackview {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .trackview__rail {
    display: block;
    position: sticky;
    top: var(--sp-4);
    align-self: start;
    max-height: calc(100vh - 2 * var(--sp-4));
    overflow-y: auto;
  }

  .trackview__rail-title {
    margin-bottom: var(--sp-3);
    color: var(--color-ink);
    font-weight: 600;
  }

  .trackall-box {
    display: none;
  }
}

/* ---------- The end of a section ---------- */

.sectionend__next {
  margin-top: var(--sp-4);
}

.sectionend__left {
  margin-top: var(--sp-2);
  color: var(--color-ink-soft);
}

.sectionend__why {
  display: block;
  margin-top: var(--sp-1);
  color: var(--color-muted);
  font-size: var(--fs-sm);
}

.sectionend__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-5);
}

.sectionend__track {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--sp-2);
  color: var(--color-accent-deep);
}

.sectionend__first {
  margin-top: var(--sp-4);
  text-decoration: none;
}

/* A read step's Markdown, rendered on the server: a reading column of
   about 66 characters, with space between blocks. */
.md {
  max-width: 66ch;
  color: var(--color-ink);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.md > * {
  margin: 0;
}

.md > * + * {
  margin-top: var(--sp-3);
}

.md ul,
.md ol {
  padding-left: 1.5em;
}

.md li + li {
  margin-top: var(--sp-1);
}

/* Its headings arrive from h4 down, below the section (h2) and the step
   title (h3) (markdown.js): 18px, bigger than the text, smaller than the
   step title. */
.md h4,
.md h5,
.md h6 {
  color: var(--color-ink);
  font-size: var(--fs-h4);
  font-weight: 700;
  line-height: 1.3;
}

.md * + h4,
.md * + h5,
.md * + h6 {
  margin-top: var(--sp-5);
}

.md h4 + *,
.md h5 + *,
.md h6 + * {
  margin-top: var(--sp-2);
}

.md-chunk > *,
.md-panel > *,
.md-details__body > * {
  margin: 0;
}

.md-chunk > * + *,
.md-panel > * + *,
.md-details__body > * + * {
  margin-top: var(--sp-3);
}

/* A chunk: one "##" heading and what follows it, set off by space and a
   divider so a long step reads as a few short pieces. */
.md > .md-chunk {
  padding-top: var(--sp-5);
  border-top: 1px solid var(--color-line);
}

.md > .md-chunk:first-child {
  padding-top: 0;
  border-top: 0;
}

.md > * + .md-chunk,
.md > .md-chunk + * {
  margin-top: var(--sp-5);
}

.md-chunk > h4:first-child,
.md-chunk > h5:first-child {
  margin-top: 0;
}

/* Where to work and Check yourself: tinted panels with an icon and a label. */
.md-panel {
  padding: var(--sp-4);
  border-radius: var(--r-ctl);
  background: var(--color-surface-2);
}

.md-panel--check {
  background: var(--color-accent-soft);
}

.md > .md-panel,
.md > .md-stretch {
  margin-top: var(--sp-5);
}

.md > .md-panel:first-child {
  margin-top: 0;
}

.md-panel__label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--color-ink);
  font-weight: 700;
}

.md-panel--check .md-panel__label .icon {
  color: var(--color-accent-deep);
}

.md-links-slot:empty {
  display: none;
}

/* Show the answers, and Stretch: closed until asked for. */
.md-answer,
.md-stretch {
  border-radius: var(--r-ctl);
}

.md-answer > summary,
.md-stretch > summary {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--ctl-h);
  color: var(--color-accent-deep);
  font-weight: 600;
  cursor: pointer;
}

.md-details__chevron {
  margin-left: auto;
  transition: none;
}

details[open] > summary > .md-details__chevron {
  transform: rotate(180deg);
}

.md-answer > summary::-webkit-details-marker,
.md-stretch > summary::-webkit-details-marker {
  display: none;
}

.md-answer > summary,
.md-stretch > summary {
  list-style: none;
}

.md-answer > .md-details__body {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-ctl);
  background: var(--color-surface);
}

.md-stretch {
  padding: 0 var(--sp-4);
  background: var(--color-surface-2);
}

.md-stretch > .md-details__body {
  padding-bottom: var(--sp-4);
}

/* Predict and Trap: the two callouts, an icon beside one short line. */
.md blockquote.md-callout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--sp-1) var(--sp-3);
  align-items: start;
  padding: var(--sp-3) var(--sp-4);
  border-left: 0;
  border-radius: var(--r-ctl);
  background: var(--color-surface-2);
}

.md-callout > .icon {
  margin-top: 0.15em;
  color: var(--color-accent-deep);
}

.md-callout > * {
  grid-column: 2;
  margin: 0;
}

.md-callout > .icon {
  grid-column: 1;
  grid-row: 1;
}

.md-callout--trap {
  background: color-mix(in srgb, var(--status-warning) 10%, var(--color-surface));
}

.md-callout--trap > .icon {
  color: var(--status-warning);
}

/* Figures (```visual) sit in the reading column at their natural size. */
.md .qv {
  margin: 0;
}

.md * + .qv {
  margin-top: var(--sp-4);
}

/* A figure drawn under 300px wide (after-render.js) is centred, with its
   caption, so figure widths in one step do not jump from the left edge. */
.md .qv--centred .qv__svg {
  margin-inline: auto;
}

.md .qv--centred .qv__caption {
  text-align: center;
}

/* Narrower than its natural size, a figure's labels shrink with it. Below
   600px a figure inside a panel (Where to work, Check yourself, an answer,
   Stretch) cancels the panel's side padding, one panel deep or two, so it is
   as wide as a figure outside one. Its caption stays in line with the text. */
@media (max-width: 599.98px) {
  .md :is(.md-panel, .md-stretch, .md-answer > .md-details__body) .qv__frame {
    max-width: none;
    margin-inline: calc(-1 * var(--sp-4));
  }

  .md :is(.md-panel, .md-stretch, .md-answer > .md-details__body) :is(.md-panel, .md-stretch, .md-answer > .md-details__body) .qv__frame {
    margin-inline: calc(-2 * var(--sp-4));
  }
}

.md-figure-error {
  color: var(--status-critical);
}

.md img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Code blocks: a fill and no border, scrolling sideways in their own box. */
.md pre {
  overflow-x: auto;
  padding: var(--sp-3) var(--sp-4);
  border: 0;
  border-radius: var(--r-ctl);
  background: var(--color-surface-2);
  font-family: var(--font-mono);
  font-size: var(--fs-code);
  line-height: 1.5;
}

.md code {
  font-family: var(--font-mono);
  font-size: var(--fs-code);
}

.md pre code {
  font-size: inherit;
}

.md table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
}

.md th,
.md td {
  overflow-wrap: break-word;
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--color-line);
  text-align: left;
}

.md blockquote {
  padding-left: var(--sp-3);
  border-left: 3px solid var(--color-line-strong);
}

.md a {
  color: var(--color-accent-deep);
}

/* ---------- Practice and reflect steps (step-player.js) ---------- */

.practice {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.practice__question {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.practice__question .prompt-text--lead {
  margin: 0;
}

.practice__dyn {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.practice__dyn:empty {
  display: none;
}

.practice__verdict {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: 0;
  color: var(--color-ink);
  font-size: var(--fs-h4);
  font-weight: 600;
}

.practice__result {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-ctl);
  background: var(--color-surface-2);
}

.practice__result--right {
  background: var(--color-accent-soft);
}

.practice__explain,
.practice__key-text {
  margin: 0;
  max-width: 66ch;
}

.practice__key {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.practice__key-code {
  margin: 0;
}

.practice__hints {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.practice__hint {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-ctl);
  background: var(--color-surface-2);
  max-width: 66ch;
}

.practice__hint-label {
  color: var(--color-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.practice__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.practice__note {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--fs-sm);
}

.reflect {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.reflect__prompt {
  margin: 0;
  max-width: 66ch;
  font-size: var(--fs-h4);
  font-weight: 600;
}

.reflect__text {
  width: 100%;
  min-height: 7.5em;
  resize: vertical;
}

.reflect__count {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--fs-sm);
}

.reflect__count:empty {
  display: none;
}

.reflect__count--over {
  color: var(--status-critical);
  font-weight: 600;
}

.reflect__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.reflect__status {
  margin: 0;
  color: var(--color-ink-soft);
  /* Clears the sticky footer when the line is scrolled into view. */
  scroll-margin-bottom: 160px;
}

.reflect__readers {
  margin: 0;
  color: var(--color-ink-soft);
  font-size: var(--fs-sm);
}

.reflect__status:empty {
  display: none;
}

@media (max-width: 600px) {
  .practice__actions .btn {
    flex: 1 1 100%;
  }
}
