/* One reading column, set like a textbook page. */

:root {
  --text: #1c1b19;
  --muted: #6b675f;
  --rule: #d9d5cc;
  --page: #fdfcf9;
  --tint: #f4f1ea;
  --link: #1f4e8c;
  --column: 40rem;
  --sans: system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  line-height: 1.6;
}

.site-header,
main {
  max-width: var(--column);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.site-header {
  padding-top: 1.5rem;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.site-header a {
  color: var(--muted);
  text-decoration: none;
}

.site-header a:hover {
  color: var(--text);
}

main {
  padding-top: 2rem;
  padding-bottom: 6rem;
}

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

h1 {
  margin: 0 0 2rem;
  font-size: 2.2rem;
}

h2 {
  margin: 3rem 0 0.75rem;
  font-size: 1.35rem;
}

p,
ul,
ol,
table,
blockquote {
  margin: 0 0 1.1rem;
}

a {
  color: var(--link);
}

li {
  margin-bottom: 0.3rem;
}

/* A blockquote is a callout: ordinary text set off by a thin rule on the
   left, with no box. Bold text at its very start is its label, as in
   "> **On paper** Draw the tree." */
blockquote {
  padding: 0.1rem 0 0.1rem 1rem;
  border-left: 2px solid #3a74b8;
}

blockquote > p:first-child > strong:first-child {
  display: block;
  margin-bottom: 0.15rem;
  color: #3a74b8;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

blockquote > :last-child {
  margin-bottom: 0;
}

/* Tables: rules above and below, numbers lined up in columns. */
table {
  width: 100%;
  border-collapse: collapse;
  border-top: 1.5px solid var(--text);
  border-bottom: 1.5px solid var(--text);
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 0.45rem 0.75rem 0.45rem 0;
  text-align: left;
  vertical-align: baseline;
}

th {
  border-bottom: 1px solid var(--text);
  font-weight: 600;
}

tr + tr td {
  border-top: 1px solid var(--rule);
}

/* Math. A long formula scrolls sideways instead of widening the page. */
.katex {
  font-size: 1.05em;
}

.katex-display {
  margin: 1.7rem 0;
  padding: 0.2rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Visuals. The look follows the lesson figures on gtcloudrobotics.com;
   see docs/VISUALS.md. A visual draws inside <visual-name>, which holds a
   canvas, a readout, a row of controls, and a caption. */
figure.visual {
  margin: 1.8rem 0;
}

figure.visual > * {
  display: block;
}

/* Before the script has loaded, and until the visual comes near the screen
   and starts, hold the space with an empty panel. */
figure.visual > :not(:defined),
figure.visual > :empty {
  aspect-ratio: 3 / 2;
  border-radius: 8px;
  background: #f2f1ed;
}

.fig-canvas {
  /* Lets the labels size themselves from the width of the canvas. */
  container-type: inline-size;
  position: relative;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: 8px;
  background: #f2f1ed;
}

.fig-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.fig-labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.fig-label {
  position: absolute;
  left: 0;
  top: 0;
  /* The label sits centered just above its point. */
  transform: translate(-50%, -120%);
  color: #55555c;
  font-family: var(--sans);
  /* Labels shrink with the canvas on a narrow screen. */
  font-size: clamp(0.45rem, 1.9cqw, 0.72rem);
  line-height: 1.2;
  white-space: nowrap;
  text-align: center;
  /* A panel-colored chip, so a label stays readable over the scene. */
  padding: 0.1em 0.45em;
  border-radius: 0.5em;
  background: rgb(242 241 237 / 0.88);
  transition: opacity 0.3s;
}

.fig-label b {
  color: #2a2a2e;
}

/* A flat drawing: an SVG as wide as its box. A part marked "new" was
   added by the current step, and fades in. */
.fig-flat {
  font-family: var(--sans);
}

.fig-flat svg {
  display: block;
  width: 100%;
  height: auto;
}

.fig-flat .new {
  animation: fig-appear 0.45s ease-out;
}

@keyframes fig-appear {
  from {
    opacity: 0;
  }
}

/* The still image of the canvas, shown only on a printed page. */
.fig-print {
  display: none;
}

/* The Pause button in the corner of every canvas. */
.fig-pause {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 2;
  padding: 0.25rem 0.7rem;
  border: 1px solid #c9c7c0;
  border-radius: 999px;
  background: #fdfcf9;
  color: #2a2a2e;
  font-family: var(--sans);
  font-size: 0.78rem;
  cursor: pointer;
}

.fig-pause[aria-pressed="true"] {
  background: #2a2a2e;
  border-color: #2a2a2e;
  color: #fdfcf9;
}

/* A label for a part of the drawing that has been faded. */
.fig-label.dim,
.fig-label.dim b {
  color: #b3b2ad;
}

/* A number written on the drawing, e.g. a probability on a branch. */
.fig-number {
  color: #2a2a2e;
  font-variant-numeric: tabular-nums;
}

.fig-readout,
.fig-controls,
.fig-caption {
  font-family: var(--sans);
}

.fig-readout {
  min-height: 1.5em;
  margin-top: 0.6rem;
  color: #55555c;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.fig-readout b {
  color: #2a2a2e;
}

/* A label in the readout, before its value. */
.fig-readout i {
  margin: 0 0.3em 0 0.9em;
  color: #9a9aa2;
  font-style: normal;
}

.fig-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 1.1rem;
  margin-top: 0.6rem;
  font-size: 0.76rem;
}

.fig-slider {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: #55555c;
}

.fig-slider input {
  width: 8rem;
  accent-color: #2e2e33;
}

.fig-slider output {
  min-width: 7.5em;
  color: #2a2a2e;
  font-variant-numeric: tabular-nums;
}

.fig-choice {
  display: flex;
  gap: 0.3rem;
}

.fig-btn {
  padding: 0.15rem 0.75rem;
  border: 1.5px solid #c9c6bd;
  border-radius: 999px;
  background: transparent;
  color: #2a2a2e;
  font: inherit;
  cursor: pointer;
}

.fig-btn:hover {
  border-color: #2e2e33;
}

.fig-btn[aria-pressed="true"] {
  border-color: #2e2e33;
  background: #2e2e33;
  color: #fff;
}

.fig-caption {
  margin-top: 0.7rem;
  color: #71717a;
  font-size: 0.74rem;
  line-height: 1.45;
  text-align: center;
}

.fig-error {
  padding: 4rem 1rem;
  color: #71717a;
  font-family: var(--sans);
  font-size: 0.8rem;
  text-align: center;
}

/* The course home page. */
.description {
  color: var(--muted);
}

/* The line of links under a lesson's title: small, gray, each with an
   icon. It is for a teacher, so it stays out of a student's way. */
.lesson-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.4rem;
  margin: -1.3rem 0 2.2rem;
  font-family: var(--sans);
  font-size: 0.78rem;
}

.lesson-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  text-decoration: none;
}

.lesson-links a:hover {
  color: var(--link);
}

.lesson-links svg {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The list of lessons: one line for each, with its summary in gray. */
.lesson-summary {
  color: var(--muted);
}

.lesson-list {
  padding-left: 1.4rem;
  font-size: 1.1rem;
}

h3 {
  margin: 1.75rem 0 0.5rem;
  font-size: 1.1rem;
}

h4 {
  margin: 1.4rem 0 0.4rem;
  font-size: 1rem;
}

/* Practice problems at the end of a lesson. The solution is one box that
   opens. */
.practice {
  margin-top: 4rem;
  padding-top: 0.5rem;
  border-top: 1.5px solid var(--text);
}

/* Each problem is set apart by a thin rule and its number. */
.problem {
  margin-top: 3rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
}

.problem-number {
  margin: 0 0 0.2rem;
  color: #3a74b8;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.problem h3 {
  margin-top: 0;
}

.problem details {
  margin-top: 1.4rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
}

.problem summary {
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
}

.problem details[open] summary {
  border-bottom: 1px solid var(--rule);
}

.problem details > :not(summary) {
  margin-left: 0.9rem;
  margin-right: 0.9rem;
}

/* A table is as wide as the box, less the two margins. */
.problem details > table {
  width: calc(100% - 1.8rem);
}

.problem details > :nth-child(2) {
  margin-top: 1rem;
}

.problem details > :last-child {
  margin-bottom: 1rem;
}

.answer p {
  display: inline;
}

@media (max-width: 30rem) {
  html {
    font-size: 16px;
  }
}

/* Printing a lesson: black on white, with no site header. */
@media print {
  @page {
    margin: 2cm;
  }

  html {
    font-size: 11pt;
  }

  body {
    background: #fff;
    color: #000;
  }

  .site-header,
  .lesson-links {
    display: none;
  }

  main {
    max-width: none;
    padding: 0;
  }

  /* A page does not break just after a heading. */
  h1,
  h2,
  h3,
  h4 {
    break-after: avoid;
  }

  /* A part of a flat drawing that fades in on the screen is printed as it
     is. A fade that has not run would print as nothing. */
  .fig-flat .new {
    animation: none;
  }

  /* A printed visual is a picture, so its controls are left out. */
  .fig-pause,
  .fig-controls {
    display: none;
  }

  figure.visual {
    max-width: 13cm;
    margin-left: auto;
    margin-right: auto;
    break-inside: avoid;
  }

  /* The still image takes the place of the live canvas. */
  .fig-canvas canvas {
    display: none;
  }

  .fig-print {
    display: block;
    width: 100%;
    height: 100%;
  }

  /* Backgrounds are kept, so the figure panel and label chips print. */
  .fig-canvas,
  .fig-label {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
