/* The Learn page. Colors and controls come from style.css. */

body.learn {
  display: block;
  overflow: visible;
  height: auto;
  min-height: 100%;
}
body.learn #panel { position: sticky; top: 0; z-index: 10; }

#page {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 44px;
  max-width: 1220px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

/* The list down the side. */
#toc {
  position: sticky;
  top: 76px;
  align-self: start;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  font-size: 13.5px;
  line-height: 1.35;
  scrollbar-width: thin;
  scrollbar-color: #2e2e3e transparent;
}
#toc a {
  color: var(--dim);
  text-decoration: none;
  padding: 3px 10px;
  border-left: 2px solid transparent;
}
#toc a:hover { color: var(--text); }
#toc a[aria-current] { color: var(--text); border-left-color: var(--accent); }
.toc-group { margin: 16px 0 4px; padding-left: 12px; color: #74748c; font-size: 12px; font-weight: 600; }

#content {
  min-width: 0;
  max-width: 900px;
  font-size: 16px;
  line-height: 1.6;
}
#content > section, .algo-group { margin-bottom: 64px; }
#content section, .algo { scroll-margin-top: 76px; }
#content p { margin: 0 0 14px; }
#content a:not(.button):not(.chip):not(.race-cell) { color: #a9b8ff; }

h2 { font-size: 27px; line-height: 1.25; margin: 0 0 14px; }
h3, h4 { line-height: 1.3; }
.lead { font-size: 18px; }
.aside { color: var(--dim); font-size: 15px; }
.star { color: #ffd166; font-size: 0.8em; }

/* The algorithm list at the top. */
.pick-group h3 { font-size: 13px; color: var(--dim); font-weight: 600; margin: 18px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--control);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.chip:hover { background: var(--hover); }

/* The four moves. */
.moves {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0 0;
}
.move {
  margin: 0;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.move canvas { display: block; width: 100%; height: 124px; border-radius: 6px; }
.move figcaption { font-size: 14px; line-height: 1.45; color: var(--dim); margin-top: 10px; }
.move figcaption b { display: block; color: var(--text); font-size: 15px; margin-bottom: 2px; }

/* The key to what the players draw. */
.legend { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 14px; }
.key { flex: 0 0 30px; height: 6px; border-radius: 2px; }
.key-mark { background: #ffffff; }
.key-done { background: #3ee07a; }
.key-range { height: 20px; background: rgba(125, 149, 255, 0.22); }
.key-tray { height: 20px; border: 1px solid #4a4a5e; border-radius: 5px; }
.key-line { height: 0; border-top: 2px dashed rgba(255, 255, 255, 0.8); border-radius: 0; }

/* A picture of a whole run. */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 32px;
  align-items: start;
}
.picture { margin: 0; }
.picture-frame { position: relative; width: 224px; }
.picture canvas {
  display: block;
  width: 224px;
  height: 224px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 4px;
}
.picture figcaption { color: var(--dim); font-size: 13px; margin-top: 6px; max-width: 224px; }
.example { padding-right: 72px; }
.pin { position: absolute; left: calc(100% + 10px); font-size: 13px; color: var(--dim); white-space: nowrap; }
.pin-top { top: -2px; }
.pin-bottom { bottom: -2px; }

/* One algorithm. */
.algo { padding: 40px 0 8px; border-top: 1px solid var(--line); }
.algo-group > h2 { margin-bottom: 6px; }
.group-intro { color: var(--dim); }
.algo h3 { font-size: 24px; margin: 0 0 6px; }
.algo .idea { font-size: 17.5px; margin-bottom: 18px; }
.how h4, .facts h4 { margin: 0 0 6px; font-size: 13px; color: var(--dim); font-weight: 600; }
.how ol { margin: 0; padding-left: 1.5em; }
.how li { margin-bottom: 6px; padding-left: 4px; }
.how li::marker { color: var(--dim); }

/* The step-by-step player. */
.player {
  position: relative;
  margin: 22px 0 20px;
  padding: 14px 16px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
#content .say { margin: 0 0 10px; }
#content .say.measure { position: absolute; top: 0; left: 0; visibility: hidden; pointer-events: none; }
canvas.screen { display: block; width: 100%; height: 250px; border-radius: 6px; }
canvas.screen.with-tree { height: 430px; }
#content .stepline {
  min-height: 1.5em;
  margin: 10px 0 10px;
  color: var(--dim);
  font-size: 14.5px;
  font-variant-numeric: tabular-nums;
}
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: 14px; }
.controls .play { min-width: 92px; }
.controls button:disabled { opacity: 0.45; cursor: default; }
.controls button:disabled:hover { background: var(--control); }
.controls .scrub { flex: 1 1 140px; width: auto; min-width: 100px; }
.controls .speed { color: var(--dim); }
.tally {
  border-collapse: collapse;
  margin: 10px 0 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.tally th { text-align: left; color: var(--dim); font-weight: 500; padding: 2px 14px 2px 0; }
.tally td { min-width: 2.4em; text-align: center; padding: 2px 8px; border-left: 1px solid var(--line); }

/* Under the player. */
.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 32px;
  margin: 0 0 6px;
}
#content .facts p { margin: 0 0 14px; font-size: 15px; }
.counts { font-size: 14px; color: var(--dim); }
.counts table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.counts th { color: var(--dim); font-weight: 500; text-align: left; font-size: 12.5px; padding: 0 18px 2px 0; }
.counts td { color: var(--text); font-size: 15px; padding: 0 18px 0 0; }
#content .watch {
  padding: 10px 14px;
  background: #161624;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
}
.watch .button { margin-left: 4px; }

/* The race. */
.race-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 14px 0; font-size: 14px; }
.race-controls .primary { min-width: 92px; }
.race-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 10px; margin-bottom: 14px; }
.race-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 8px 8px 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.race-cell:hover { border-color: #4a4a66; }
.race-cell canvas { display: block; width: 100%; height: 64px; border-radius: 4px; }
.race-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.race-status { font-size: 12.5px; color: var(--dim); font-variant-numeric: tabular-nums; }
.race-cell.finished .race-status { color: #3ee07a; }

/* How the work grows. */
.table-wrap { overflow-x: auto; margin: 16px 0 20px; }
#growthTable { width: 100%; border-collapse: collapse; font-size: 14.5px; font-variant-numeric: tabular-nums; }
#growthTable th {
  text-align: right;
  vertical-align: bottom;
  color: var(--dim);
  font-weight: 500;
  font-size: 13px;
  line-height: 1.3;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
#growthTable td { text-align: right; padding: 5px 10px; border-bottom: 1px solid #1d1d28; white-space: nowrap; }
#growthTable th:first-child, #growthTable td:first-child { text-align: left; padding-left: 0; }
#content #growthTable a { color: var(--text); text-decoration: none; }
#content #growthTable a:hover { text-decoration: underline; }
#growthTable .wait { color: var(--dim); text-align: left; }

.end { color: var(--dim); }

@media (max-width: 1000px) {
  #page { grid-template-columns: minmax(0, 1fr); }
  #toc { display: none; }
}

@media (max-width: 760px) {
  .moves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .facts { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 520px) {
  #page { padding: 20px 16px 60px; }
  h2 { font-size: 23px; }
  .algo h3 { font-size: 21px; }
  .player { padding: 12px 10px 10px; }
  canvas.screen { height: 220px; }
  canvas.screen.with-tree { height: 400px; }
  #content .stepline { min-height: 3em; }
  .move canvas { height: 100px; }
}
