/* The tutorial's page (Learn.App): a header, then the lesson's text, its
   code and the result side by side, each scrolling on its own; under 900
   pixels, one column the page scrolls through. */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1c1c1e;
  --muted: #62626a;
  --panel: #f5f5f6;
  --border: #d8d8dc;
  --accent: #3b5bdb;
  --error: #b42318;
  --warning: #9a6700;
  --active-line: rgba(59, 91, 219, 0.06);
  --source-line: rgba(59, 91, 219, 0.18);
  --source-fill: rgba(59, 91, 219, 0.12);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316;
    --fg: #e6e6e9;
    --muted: #a0a0a8;
    --panel: #1c1c21;
    --border: #36363e;
    --accent: #8ea4ff;
    --error: #ff9b8f;
    --warning: #f0c060;
    --active-line: rgba(142, 164, 255, 0.08);
    --source-line: rgba(142, 164, 255, 0.22);
    --source-fill: rgba(142, 164, 255, 0.16);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

code,
pre {
  font-family: var(--mono);
  font-size: 0.9em;
}

:not(pre) > code {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.25em;
}

pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  line-height: 1.45;
}

button {
  font: inherit;
  font-size: 0.9rem;
  padding: 4px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.learn-compile:not(:disabled),
button.learn-load,
button.learn-retry {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

/* The header. */

.learn {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.learn-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
}

.learn-brand {
  font-weight: 600;
  color: inherit;
  text-decoration: none;
}

.learn-pager {
  display: flex;
  gap: 14px;
  align-items: center;
}

.learn-position,
.learn-status,
.learn-note,
.learn-file {
  color: var(--muted);
  font-size: 0.85rem;
}

.learn-status {
  margin-left: auto;
}

.learn-disabled {
  color: var(--muted);
  opacity: 0.6;
}

/* The introduction. */

.learn-home {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.learn-lessons li {
  margin-bottom: 6px;
}

/* A lesson: three columns. */

.learn-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.learn-lesson {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr) minmax(0, 0.9fr);
  min-height: 0;
}

.learn-lesson > * {
  padding: 16px 20px;
  overflow: auto;
}

.learn-text {
  max-width: 70ch;
}

.learn-text h1 {
  font-size: 1.5rem;
  margin-top: 0.2em;
}

.learn-text h2 {
  font-size: 1.15rem;
}

.learn-text h3 {
  font-size: 1rem;
}

.learn-text blockquote {
  margin: 1em 0;
  padding-left: 14px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.learn-pager-bottom {
  margin: 2em 0 1em;
  justify-content: space-between;
}

/* The playground: a narrow panel in place of the text, with the layers to
   check and the arguments to add. */

.learn-lesson.learn-playground {
  grid-template-columns: minmax(0, 0.65fr) minmax(0, 1.3fr) minmax(0, 1fr);
}

.learn-layers {
  margin: 1em 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.learn-layers legend {
  padding: 0 4px;
  font-weight: 600;
  font-size: 0.9rem;
}

.learn-layers ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.learn-layer {
  cursor: pointer;
  overflow-wrap: anywhere;
}

.learn-extra label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.learn-extra-args {
  width: 100%;
  font: inherit;
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.learn-code,
.learn-result-column {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.learn-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* The editor keeps its height when what is under it (a long list of
   diagnostics, the types) is more than the column holds: the column
   scrolls instead. */
.learn-editor {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.learn-editor:empty {
  display: none;
}

.learn-editor .cm-editor {
  min-height: 320px;
  max-height: 70vh;
}

.learn-fallback {
  margin: 0;
  white-space: pre;
}

.learn-diagnostics {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.learn-diagnostics li {
  border-left: 3px solid var(--error);
  padding-left: 10px;
}

.learn-diagnostics li.learn-warning {
  border-left-color: var(--warning);
}

.learn-diagnostics pre {
  margin: 4px 0 0;
  white-space: pre-wrap;
  font-size: 0.8rem;
}

button.learn-location {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.85rem;
  text-decoration: underline;
}

span.learn-location {
  font-family: var(--mono);
  font-size: 0.85rem;
}

/* The live check: what it did, and the types of the module's bindings. */

.learn-check {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.learn-bindings h2 {
  margin: 0 0 4px;
  font-size: 0.9rem;
}

.learn-bindings p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

.learn-bindings ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

button.learn-binding {
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg);
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
  overflow-wrap: anywhere;
}

button.learn-binding code {
  background: none;
  border: 0;
  padding: 0;
}

button.learn-binding:hover code,
button.learn-binding:focus-visible code {
  text-decoration: underline;
}

.learn-error {
  color: var(--error);
}

/* The result. */

.learn-compiler p {
  margin: 0 0 8px;
}

.learn-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--panel);
  border: 1px solid var(--border);
  overflow: hidden;
}

.learn-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

.learn-bar-busy .learn-bar-fill {
  animation: learn-busy 1.2s ease-in-out infinite alternate;
}

@keyframes learn-busy {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(330%);
  }
}

.learn-outcome {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.learn-result {
  min-height: 3em;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
}

.learn-result:empty {
  display: none;
}

.learn-stdout,
.learn-stderr pre {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.8rem;
}

.learn-stderr summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
}

/* The Source mode (js/source.js): the toggle, pressed while it is on, and the
   box over the element under the pointer, fixed over its rectangle, with
   where it was built at its top left corner. The box takes no pointer
   events, so the element under it is still the one pointed at. */

button.learn-source[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.learn-result.learn-sourcing {
  cursor: crosshair;
}

.learn-source-box {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  outline: 2px solid var(--accent);
  background: var(--source-fill);
  border-radius: 2px;
}

.learn-source-label {
  position: absolute;
  left: -2px;
  bottom: 100%;
  margin-bottom: 2px;
  padding: 0 5px;
  border-radius: 3px;
  background: var(--accent);
  color: var(--bg);
  font: 11px/1.6 var(--mono);
  white-space: nowrap;
}

/* One column. */

@media (max-width: 900px) {
  .learn-lesson {
    display: block;
  }

  .learn-lesson > * {
    overflow: visible;
    max-width: none;
  }

  .learn-code,
  .learn-result-column {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .learn-status {
    margin-left: 0;
  }
}

@media (min-width: 901px) {
  .learn {
    height: 100vh;
  }

  /* A lesson's three columns scroll each on their own; the introduction,
     which has no columns, scrolls as a whole on a short viewport. */
  .learn-main:has(.learn-lesson) {
    overflow: hidden;
  }

  .learn-main:has(.learn-home) {
    overflow: auto;
  }
}
