/* Chunky Bacon - a Ruby exercise book.

   Two voices. Chunky speaks in hand lettering (Shantell Sans): the title,
   his speech bubbles, the loading screen. Everything the learner reads and
   types is print: Atkinson Hyperlegible Next, and its Mono for code, which
   keeps 0/O and 1/l/I apart for people typing their first programs.

   The page is a squared school exercise book (Rechenheft) with a red margin
   line; code cells are white worksheets on it. Colours come from the fox
   drawing itself: its outline ink, its orange, the bacon and the fat. */

:root {
  --paper: #ffffff;
  --karo: #e3eaf1;        /* grid lines of the exercise book */
  --margin-line: #e9a393; /* the red margin line */
  --ink: #1a1208;         /* the fox's outline ink */
  --ink-soft: #5f5247;    /* secondary text, 6.6:1 on paper */
  --rule: #d4dbe3;        /* hairlines inside cells and widgets */
  --fox: #e8722a;         /* actions and the active lesson; ink on it is 6:1 */
  --fox-light: #f39a60;
  --bacon: #c14a2e;       /* links; 4.9:1 on paper */
  --fat: #fdeee3;         /* bacon fat: task boxes */
  --highlight: #ffc9a1;   /* highlighter marking the current lesson */
  --code-bg: #eef2f6;     /* inline code, printed examples, output */
  --ok: #2e7d32;
  --err: #b3261e;
  --focus: #2f6db5;

  --font-print: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-code: "Atkinson Hyperlegible Mono", ui-monospace, "Cascadia Code", Menlo, monospace;
  --font-hand: "Shantell Sans", "Segoe Print", "Comic Sans MS", system-ui, sans-serif;

  --grid: 24px;
  --page: 74rem;
  --column: 44rem;        /* the lesson column: text ~65ch, cells full width */
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  font-family: var(--font-print);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--karo) 1px, transparent 1px),
    linear-gradient(90deg, var(--karo) 1px, transparent 1px);
  background-size: var(--grid) var(--grid);
  background-position: -1px -1px;
}

::selection { background: var(--highlight); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

a { color: var(--bacon); text-underline-offset: 0.15em; }
a:hover { color: var(--ink); }

/* ---------- loading screen: the first thing everyone sees ---------- */
.spinner {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1rem;
}
.spinner-image {
  width: 150px;
  animation: wobble 1.6s ease-in-out infinite;
}
.spinner h1 {
  font-family: var(--font-hand);
  font-weight: 700;
  font-variation-settings: "INFM" 60, "BNCE" 25;
  font-size: clamp(2rem, 6vw, 3.25rem);
  line-height: 1.05;
  margin: 0.8rem 0 0.6rem;
  text-wrap: balance;
}
.spinner p {
  margin: 0 0 1.4rem;
  color: var(--ink-soft);
  max-width: 34rem;
}
/* indeterminate: a strip of bacon sliding through a frame */
.load-bar {
  width: min(16rem, 70vw);
  height: 10px;
  border: 2px solid var(--ink);
  border-radius: 5px;
  overflow: hidden;
  background: var(--paper);
}
.load-bar::before {
  content: "";
  display: block;
  width: calc(100% + 84px);
  height: 100%;
  background: repeating-linear-gradient(90deg,
    var(--fox) 0 18px, var(--bacon) 18px 30px, #f6c9a8 30px 42px);
  animation: bacon-slide 0.8s linear infinite;
  will-change: transform;
}
@keyframes wobble {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg); }
}

/* ---------- masthead ---------- */
header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem max(1.5rem, calc((100% - var(--page)) / 2 + 1.5rem));
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
}
header #mascot { width: 58px; height: 58px; flex: none; }
header .headerText { flex: 1; min-width: 0; }
header h1 {
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 700;
  font-variation-settings: "INFM" 50, "BNCE" 15;
  font-size: 1.75rem;
  line-height: 1.1;
}
header p { margin: 0.2rem 0 0; color: var(--ink-soft); font-size: 0.95rem; }
header select, header .nav-jump {
  font: 600 0.95rem/1.2 var(--font-print);
  color: var(--ink);
  padding: 0.4rem 0.6rem;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
  cursor: pointer;
}
header .nav-jump { display: none; font-size: 1.1rem; }
header .nav-jump:hover { background: var(--fat); }

/* progress: where the work is saved; the dot says whether a folder is on */
header .progress-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font: 600 0.95rem/1.2 var(--font-print);
  color: var(--ink);
  padding: 0.4rem 0.7rem;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
}
header .progress-btn:hover { background: var(--fat); }
.progress-icon {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}
.progress-dot {
  display: none;
  position: absolute;
  top: -5px;
  right: -5px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--paper);
}
.progress-btn.is-connected .progress-dot { display: block; background: var(--ok); }
.progress-btn.needs-attention .progress-dot { display: block; background: var(--fox); }

/* ---------- layout: the index in the margin, the lesson on the page ---------- */
.layout {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  column-gap: 2rem;
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* 37 lessons do not fit a screen: the index scrolls on its own */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 1.6rem 0.4rem 2.5rem 0;
}

main {
  min-width: 0;
  border-left: 2px solid var(--margin-line);
  padding: 2rem 0 3rem 2.5rem;
}
main > * { max-width: var(--column); }

/* ---------- the workshop's entry, above the lessons ---------- */
.workshop-link {
  display: block;
  margin: 0 0 1.2rem;
  padding: 0.45rem 0.7rem;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
}
.workshop-link:hover { background: var(--fat); color: var(--ink); }
.workshop-link.active { background: var(--highlight); }

/* ---------- lesson index ---------- */
nav#lessonNav { display: flex; flex-direction: column; }
.nav-section {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
  padding: 1.3rem 0.5rem 0.35rem;
}
.nav-section:first-child { padding-top: 0; }
nav#lessonNav a {
  display: block;
  padding: 0.28rem 0.5rem;
  border-radius: 4px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.94rem;
  line-height: 1.35;
  cursor: pointer;
}
nav#lessonNav a:hover { background: var(--code-bg); }
/* the current lesson is marked like with a highlighter: slanted ends */
nav#lessonNav a.active {
  font-weight: 700;
  background: linear-gradient(100deg,
    transparent 0.2rem, var(--highlight) 0.2rem,
    var(--highlight) calc(100% - 0.2rem), transparent calc(100% - 0.2rem));
}
nav#lessonNav a.done::after { content: " ✓"; color: var(--ok); font-weight: 700; }

/* ---------- gems panel ---------- */
#gemsPanel {
  margin-top: 1.8rem;
  padding: 1rem 0.5rem 0;
  border-top: 1.5px solid var(--ink);
}
#gemsPanel h3 { margin: 0 0 0.6rem; font-size: 0.95rem; font-weight: 700; }
#gemsList { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.7rem; }
#gemsList .gem-chip {
  font: 400 0.8rem/1.3 var(--font-code);
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--ink-soft);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
}
#gemsList .gem-chip:hover { background: var(--fat); border-color: var(--ink); }
#gemsList .gem-chip.installed { background: #e3f2e4; border-color: var(--ok); color: #1f5d23; }
.gemsInstallRow { display: flex; gap: 0.4rem; }
.gemsInstallRow input {
  flex: 1;
  min-width: 0;
  font: 0.88rem/1.3 var(--font-code);
  padding: 0.35rem 0.5rem;
  border: 1.5px solid var(--ink-soft);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}
.gemsInstallRow button { font-size: 0.85rem; padding: 0.3rem 0.7rem; }
#gemsNote { font-size: 0.8rem; line-height: 1.45; color: var(--ink-soft); margin: 0.7rem 0 0; }
#gemsNote code { font-family: var(--font-code); font-size: 0.95em; }

/* ---------- lesson text ---------- */
.lessonText h2 {
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 1.1rem;
  text-wrap: balance;
}
.lessonText h3 { font-size: 1.3rem; font-weight: 700; line-height: 1.25; margin: 1.8rem 0 0.5rem; }
.lessonText p, .lessonText ul, .lessonText ol { max-width: 65ch; }
.lessonText p { margin: 0 0 0.9rem; }
.lessonText li { margin: 0.2rem 0; }
.lessonText strong { font-weight: 700; }
.lessonText code, .task code, #chunkyChat code { font-family: var(--font-code); }
.lessonText :not(pre) > code { font-size: 0.88em; }
.lessonText p > code, .lessonText li > code, .task code, #chunkyChat code {
  background: var(--code-bg);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  font-size: 0.88em;
}
/* printed examples: part of the book, not runnable, so no frame and no button */
.lessonText pre, .offweb pre {
  background: var(--code-bg);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}
kbd {
  font-family: var(--font-code);
  font-size: 0.8em;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--ink-soft);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--paper);
  white-space: nowrap;
}

.task {
  border-left: 4px solid var(--fox);
  background: var(--fat);
  padding: 0.75rem 1rem;
  border-radius: 0 6px 6px 0;
  margin: 1.4rem 0 0.5rem;
}
/* A task statement right above its exercise cell joins it: one orange
   block that says what to do and where to do it. The statement already
   starts with "Aufgabe:", so the cell drops its own label. */
.lessonText:has(+ .cell.exercise) > .task:last-child {
  margin-bottom: 0;
  border: 2.5px solid var(--fox);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  padding: 0.85rem 1rem 0.8rem;
}
.lessonText:has(> .task:last-child) + .cell.exercise {
  margin-top: 0;
  border-top: 1px solid var(--fox-light);
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.lessonText:has(> .task:last-child) + .cell.exercise::before { display: none; }

/* "on your machine" boxes: things the browser sandbox cannot do */
.offweb {
  border-left: 4px solid var(--ink-soft);
  background: var(--code-bg);
  padding: 0.75rem 1rem;
  border-radius: 0 6px 6px 0;
  margin: 1.4rem 0 0.5rem;
}
.offweb::before { content: "💻\00a0"; }
.offweb pre { background: var(--paper); }

/* ---------- notebook cells: worksheets on the page ---------- */
.cell {
  margin: 1rem 0 1.5rem;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
  overflow: hidden;
  position: relative;
}
.cell.exercise { border: 2.5px solid var(--fox); }
.cell.exercise::before {
  content: attr(data-label);
  display: block;
  background: var(--fox);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.2rem 0.9rem;
}
/* beat codemirror.css's fixed 300px height regardless of load order */
.cell .CodeMirror {
  height: auto;
  font-family: var(--font-code);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  padding: 0.3rem 0;
}
.cell .CodeMirror-scroll { min-height: 2.2em; }
.cell .CodeMirror-gutters { background: var(--paper); border-right: 1px solid var(--rule); }
.cell .CodeMirror-linenumber { color: #7d8894; padding: 0 0.5rem 0 0.4rem; }
.cell .CodeMirror-cursor { border-left: 2px solid var(--ink); }
.cell .CodeMirror-selected, .cell .CodeMirror-focused .CodeMirror-selected { background: #ffe0c8; }
.cell .CodeMirror pre.CodeMirror-line { padding: 0 0.7rem; }

/* syntax colours: all at least 4.8:1 on paper */
.cell .cm-s-default .cm-keyword { color: #a8361a; }
.cell .cm-s-default .cm-def { color: var(--ink); font-weight: 700; }
.cell .cm-s-default .cm-string { color: #1f7a3f; }
.cell .cm-s-default .cm-string-2 { color: #9a4d00; }
.cell .cm-s-default .cm-number { color: #2f5f9e; }
.cell .cm-s-default .cm-atom,
.cell .cm-s-default .cm-builtin { color: #7b3fa0; }
.cell .cm-s-default .cm-variable-2 { color: #0e6a75; }
.cell .cm-s-default .cm-variable-3,
.cell .cm-s-default .cm-type { color: #0e6a75; }
.cell .cm-s-default .cm-comment { color: #6f655d; font-style: italic; }
.cell .cm-s-default .cm-bracket { color: #6f655d; }
.cell .CodeMirror-matchingbracket { color: var(--ink) !important; background: #ffe0c8; }

.cell-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 0.4rem 0.5rem 0.4rem 0.9rem;
  border-top: 1px solid var(--rule);
  background: var(--paper);
}
.cell-toolbar .run-cell {
  font-size: 0.9rem;
  padding: 0.3rem 0.95rem;
}

/* ---------- running a cell ----------
   Ruby blocks the main thread while a cell runs, so everything that moves
   here animates only transform or opacity: the browser runs those off the
   main thread, and they keep moving while Ruby works. The running look
   fades in after a beat, so a cell that finishes instantly does not flash. */
.cell.running::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% + 84px);
  height: 4px;
  background: repeating-linear-gradient(90deg,
    var(--fox) 0 18px, var(--bacon) 18px 30px, #f6c9a8 30px 42px);
  animation: bacon-slide 0.8s linear infinite, run-fade-in 0.2s ease-out 0.12s backwards;
  will-change: transform, opacity;
  pointer-events: none;
  z-index: 2;
}
/* An animation on its own layer, not a transition: a transition on an
   un-promoted element runs on the main thread and freezes at its start
   value for as long as Ruby is busy. */
.cell.running .CodeMirror {
  animation: run-dim 0.25s ease 0.12s both;
  will-change: opacity;
}
@keyframes run-dim {
  to { opacity: 0.55; }
}
.run-cell[disabled] { cursor: progress; opacity: 1; }
.run-cell .run-fox {
  width: 1.15em;
  height: 1.15em;
  margin-right: 0.4em;
  vertical-align: -0.22em;
  animation: wobble 0.5s ease-in-out infinite, run-fade-in 0.2s ease-out 0.12s backwards;
  will-change: transform, opacity;
}
@keyframes bacon-slide {
  from { transform: translateX(-84px); }
  to { transform: translateX(0); }
}
@keyframes run-fade-in {
  from { opacity: 0; }
}

/* after the run: the output slides in, an error shakes the cell, a solved
   exercise gets a green pulse */
.cell-out.reveal { animation: out-in 0.26s cubic-bezier(0.2, 0.7, 0.3, 1); }
@keyframes out-in {
  from { opacity: 0; transform: translateY(-6px); }
}
.cell.shake { animation: cell-shake 0.34s ease-in-out; }
@keyframes cell-shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
.cell.celebrate { animation: cell-pass 0.9s ease-out; }
@keyframes cell-pass {
  from { box-shadow: 0 0 0 0 rgba(46, 125, 50, 0.55); }
  to { box-shadow: 0 0 0 16px rgba(46, 125, 50, 0); }
}
.run-time {
  margin-right: auto;
  align-self: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.run-time.fresh { animation: out-in 0.3s ease-out; }

.cell-out {
  border-top: 1px solid var(--rule);
  padding: 0.6rem 0.9rem;
  background: var(--code-bg);
}
.cell-stdout {
  font-family: var(--font-code);
  white-space: pre-wrap;
  margin: 0 0 0.3rem;
  font-size: 0.9rem;
}
.cell-result {
  font-family: var(--font-code);
  color: var(--ok);
  font-size: 0.9rem;
}
.cell-error {
  font-family: var(--font-code);
  color: var(--err);
  white-space: pre-wrap;
  font-size: 0.9rem;
}
.cell-image {
  display: block;
  margin: 0.4rem 0;
  image-rendering: pixelated;
  width: 160px;
  max-width: 100%;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fff;
}
.marker { background: #ffd9d4; border-bottom: 2px solid var(--err); }

/* ---------- downloads: files a cell wrote ---------- */
.cell-downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.4rem 0;
}
.cell-download {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.25rem 0.7rem;
  border: 1.5px solid var(--bacon);
  border-radius: 999px;
  color: var(--bacon);
  background: var(--paper);
  font-family: var(--font-code);
  font-size: 0.86rem;
  text-decoration: none;
}
.cell-download:hover { background: var(--bacon); color: #fff; }
.cell-download small { opacity: 0.75; }

/* ---------- widgets: windows drawn in the same ink as the cells ---------- */
.shoes-app, .three-stage, .irb-term, .mini-browser, .file-explorer {
  margin: 0.7rem 0;
  max-width: 100%;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
}

/* Shoes app stage (lacci) */
.shoes-app {
  overflow: auto;
  background: var(--paper);
  font-family: var(--font-print);
  color: var(--ink);
}
.shoes-root { padding: 0.7rem 0.9rem; }
.shoes-stack { display: flex; flex-direction: column; align-items: stretch; gap: 0.35rem; }
.shoes-flow { display: flex; flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0.45rem; }
.shoes-text { margin: 0.15rem 0; line-height: 1.35; }
.shoes-app h1.shoes-text { font-size: 1.5rem; margin: 0.2rem 0; }
.shoes-app h2.shoes-text { font-size: 1.25rem; margin: 0.2rem 0; }
.shoes-app h3.shoes-text { font-size: 1.1rem; margin: 0.2rem 0; }
.shoes-button {
  align-self: flex-start;
  padding: 0.3rem 0.8rem;
  border: 1px solid #b9b2a8;
  border-radius: 6px;
  background: linear-gradient(#fff, #efeae4);
  /* the site's own button style is ink-on-orange; a Shoes button is not */
  color: var(--ink);
  font: inherit;
  font-weight: normal;
  box-shadow: none;
  text-shadow: none;
  cursor: pointer;
}
.shoes-button:hover { background: linear-gradient(#fff, #e6dfd6); color: var(--ink); }
.shoes-button:active { background: #e0d8cc; }
.shoes-editline, .shoes-editbox {
  padding: 0.25rem 0.4rem;
  border: 1px solid #b9b2a8;
  border-radius: 5px;
  font: inherit;
}
.shoes-editbox { min-height: 4rem; }
.shoes-link { color: var(--bacon); }
.shoes-image { max-width: 100%; }

/* 3D stage (three-rb) */
.three-stage {
  overflow: hidden;
  background: #151a20;
}
.three-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* IRB terminal */
.irb-term {
  background: #211a13;
  padding: 0.75rem 0.95rem;
  font-family: var(--font-code);
  font-size: 0.9rem;
  color: #f2e8da;
}
.irb-history {
  max-height: 260px;
  overflow-y: auto;
  margin-bottom: 0.2rem;
}
.irb-echo { color: #f2e8da; white-space: pre-wrap; }
.irb-stdout { margin: 0; color: #cfe3ff; white-space: pre-wrap; font-family: inherit; }
.irb-result { color: #8ee08f; }
.irb-error { color: #ff9d94; }
.irb-note { color: #f5bf4f; font-style: italic; }
.irb-line { display: flex; align-items: center; gap: 0.45rem; }
.irb-prompt { color: #f5bf4f; white-space: nowrap; }
.irb-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-family: inherit;
  font-size: inherit;
  caret-color: #8ee08f;
}
.irb-term:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }

/* mini browser */
.mini-browser {
  overflow: hidden;
  background: var(--paper);
}
.mb-chrome, .fe-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: var(--code-bg);
  border-bottom: 1px solid var(--rule);
}
.mb-dots, .fe-dots { display: flex; gap: 0.28rem; }
.mb-dots span, .fe-dots span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(26, 18, 8, 0.35);
}
.mb-dots span:nth-child(1), .fe-dots span:nth-child(1) { background: #f56d5c; }
.mb-dots span:nth-child(2), .fe-dots span:nth-child(2) { background: #f5bf4f; }
.mb-dots span:nth-child(3), .fe-dots span:nth-child(3) { background: #59c837; }
.mb-scheme {
  font-family: var(--font-code);
  font-size: 0.85rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.mb-url {
  flex: 1;
  min-width: 0;
  font-family: var(--font-code);
  font-size: 0.88rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid #b9c3cd;
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
}
button.mb-go {
  font-size: 0.85rem;
  padding: 0.25rem 0.8rem;
}
.mb-status {
  font-family: var(--font-code);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  min-width: 2.6em;
  text-align: center;
}
.mb-status.ok { background: #e3f2e4; color: var(--ok); }
.mb-status.err { background: #fde3df; color: var(--err); }
.mb-view {
  padding: 0.8rem 1rem;
  min-height: 60px;
  background: var(--paper);
}
.mb-view h1, .mb-view h2 { margin: 0.2rem 0 0.5rem; }
.mb-view a { color: #1a5dc8; text-decoration: underline; cursor: pointer; }
.mb-view pre { margin: 0; white-space: pre-wrap; font-size: 0.88rem; }
.mb-error { color: var(--err); }

/* file explorer (simulated filesystem) */
.file-explorer {
  overflow: hidden;
  background: var(--paper);
  font-size: 0.92rem;
}
.fe-title { font-weight: 700; color: var(--ink-soft); }
button.fe-refresh {
  margin-left: auto;
  font-size: 0.9rem;
  padding: 0.05rem 0.55rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid #b9c3cd;
}
button.fe-refresh:hover { background: var(--fat); }
.fe-list { list-style: none; margin: 0; padding: 0.3rem 0; max-height: 220px; overflow-y: auto; }
.fe-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.9rem;
  font-family: var(--font-code);
}
.fe-list li.fe-file { cursor: pointer; }
.fe-list li.fe-file:hover { background: var(--fat); }
.fe-list li.fe-dir { color: var(--ink-soft); }
.fe-name { flex: 1; }
.fe-size { color: var(--ink-soft); font-size: 0.8rem; }
.fe-preview {
  margin: 0;
  border-top: 1px solid var(--rule);
  background: var(--code-bg);
  padding: 0.6rem 0.9rem;
  font-family: var(--font-code);
  font-size: 0.86rem;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

/* ---------- buttons: ink on fox orange, outlined like the drawing ---------- */
.buttons { margin: 0.7rem 0; display: flex; gap: 0.6rem; }
button {
  font-family: var(--font-print);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
  padding: 0.5rem 1.2rem;
  border-radius: 6px;
  border: 1.5px solid var(--ink);
  cursor: pointer;
  background: var(--fox);
  color: var(--ink);
}
button:hover { background: var(--fox-light); }
button:active { transform: translateY(1px); }
button.reset {
  background: transparent;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.4rem 0.95rem;
  border-color: var(--ink-soft);
  color: var(--ink-soft);
}
button.reset:hover { background: var(--paper); color: var(--ink); border-color: var(--ink); }

/* ---------- the workshop: files beside a program editor ---------- */
.in-workshop main > * { max-width: 64rem; }
.workshop {
  display: grid;
  grid-template-columns: 12.5rem minmax(0, 1fr);
  gap: 1.2rem;
  align-items: start;
  margin-top: 1.2rem;
}
/* until the editor has room beside it, the file panel sits above it */
@media (max-width: 1100px) {
  .workshop { grid-template-columns: minmax(0, 1fr); }
}
.ws-files h3 { margin: 0; font-size: 0.95rem; font-weight: 700; }
.ws-where { margin: 0.1rem 0 0.6rem; font-size: 0.82rem; color: var(--ink-soft); overflow-wrap: anywhere; }
.ws-locked {
  font-size: 0.85rem;
  margin: 0 0 0.6rem;
  padding: 0.5rem 0.6rem;
  background: var(--fat);
  border-left: 3px solid var(--fox);
  border-radius: 0 4px 4px 0;
}
.ws-list { list-style: none; margin: 0 0 0.6rem; padding: 0; }
.ws-list li { display: flex; align-items: center; border-radius: 4px; }
.ws-list li:hover { background: var(--code-bg); }
.ws-list li.is-open {
  background: linear-gradient(100deg,
    transparent 0.2rem, var(--highlight) 0.2rem,
    var(--highlight) calc(100% - 0.2rem), transparent calc(100% - 0.2rem));
}
.ws-files button.ws-file {
  flex: 1;
  min-width: 0;
  text-align: left;
  font: 400 0.86rem/1.35 var(--font-code);
  padding: 0.3rem 0.5rem;
  background: transparent;
  border: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.ws-list li.is-open button.ws-file { font-weight: 700; }
.ws-files button.ws-del {
  flex: none;
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem 0.45rem;
  background: transparent;
  border: 0;
  color: var(--ink-soft);
  opacity: 0.45;
}
.ws-list li:hover button.ws-del, .ws-files button.ws-del:focus-visible { opacity: 1; }
.ws-files button.ws-del:hover { color: var(--err); background: transparent; }
.ws-files button.ws-action, .progress-dialog button.pd-secondary {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  background: var(--paper);
  color: var(--ink);
  border: 1.5px solid var(--ink-soft);
}
.ws-files button.ws-action:hover, .progress-dialog button.pd-secondary:hover { background: var(--fat); border-color: var(--ink); }
.ws-files button.ws-action:disabled { opacity: 0.45; cursor: not-allowed; }
.ws-newname {
  width: 100%;
  font: 0.86rem/1.3 var(--font-code);
  padding: 0.35rem 0.5rem;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
}
.ws-error { font-size: 0.8rem; color: var(--err); margin: 0.4rem 0 0; }
.ws-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; }

.cell.ws-editor { margin: 0; }
.ws-tab {
  font: 700 0.85rem/1.3 var(--font-code);
  padding: 0.4rem 0.9rem;
  background: var(--code-bg);
  border-bottom: 1px solid var(--rule);
  overflow-wrap: anywhere;
}
.ws-editor .CodeMirror-scroll { min-height: 20em; }
.ws-stdin { border-top: 1px solid var(--rule); }
.ws-stdin summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 0.35rem 0.9rem;
}
.ws-stdin textarea {
  display: block;
  width: calc(100% - 1.8rem);
  margin: 0 0.9rem 0.6rem;
  font: 0.88rem/1.45 var(--font-code);
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  resize: vertical;
}
/* a text file cannot be run (not the running state, which is disabled too) */
.run-cell[disabled]:not(:has(.run-fox)) { opacity: 0.45; cursor: not-allowed; }

/* ---------- the progress dialog ---------- */
.progress-dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1.3rem 1.5rem 1.1rem;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}
.progress-dialog::backdrop { background: rgba(26, 18, 8, 0.35); }
.pd-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.pd-head h2 { margin: 0; font-size: 1.45rem; font-weight: 800; line-height: 1.2; }
.progress-dialog button.pd-close {
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.1rem 0.45rem;
  background: transparent;
  border: 0;
  color: var(--ink-soft);
}
.progress-dialog button.pd-close:hover { color: var(--ink); background: var(--code-bg); }
.pd-intro { color: var(--ink-soft); margin: 0.5rem 0 0.4rem; }
.progress-dialog section { border-top: 1px solid var(--rule); margin-top: 1rem; padding-top: 0.2rem; }
.progress-dialog h3 { font-size: 1rem; font-weight: 700; margin: 0.8rem 0 0.2rem; }
.progress-dialog p { margin: 0.3rem 0 0.6rem; }
.pd-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.progress-dialog button.pd-primary { font-size: 0.95rem; padding: 0.45rem 1rem; }
.pd-connected { font-weight: 600; }
.pd-error, .pd-message.is-error { color: var(--err); }
.pd-message { min-height: 1.6em; margin: 1rem 0 0; font-weight: 600; }
.pd-message.is-ok { color: var(--ok); }

/* ---------- Chunky speaks: a comic speech bubble, hand-lettered ---------- */
#chunkyChat {
  --bubble: var(--paper);
  display: none;
  gap: 1.2rem;
  align-items: flex-end;
  margin: 2.2rem 0 1.2rem;
}
#chunkyChat.pass { --bubble: #e6f4e7; }
#chunkyChat.fail { --bubble: #fde6dc; }
#chunkyChat .chat-avatar { flex: none; }
#chunkyChat .chat-avatar img { width: 96px; display: block; }
#chunkyChat .chat-message {
  position: relative;
  flex: 1;
  min-width: 0;
  margin-bottom: 1.6rem;
  padding: 0.9rem 1.3rem;
  background: var(--bubble);
  border: 2.5px solid var(--ink);
  /* uneven corners: drawn by hand, not by a box model */
  border-radius: 30px 22px 28px 18px / 22px 28px 20px 30px;
  font-family: var(--font-hand);
  font-variation-settings: "INFM" 35;
  font-size: 1.05rem;
  line-height: 1.55;
  animation: bubble-pop 0.3s cubic-bezier(0.3, 1.4, 0.5, 1);
  transform-origin: 0 100%;
}
/* a different name per state restarts the pop when the verdict changes */
#chunkyChat.pass .chat-message { animation-name: bubble-pop-pass; }
#chunkyChat.fail .chat-message { animation-name: bubble-pop-fail; }
@keyframes bubble-pop { from { opacity: 0; transform: scale(0.9); } }
@keyframes bubble-pop-pass { from { opacity: 0; transform: scale(0.9); } }
@keyframes bubble-pop-fail { from { opacity: 0; transform: scale(0.9); } }
/* the tail, pointing down to Chunky's mouth: ink triangle, bubble inside */
#chunkyChat .chat-message::before,
#chunkyChat .chat-message::after {
  content: "";
  position: absolute;
  border-style: solid;
}
#chunkyChat .chat-message::before {
  left: -22px;
  bottom: 10px;
  border-width: 0 0 16px 26px;
  border-color: transparent transparent var(--ink) transparent;
  transform: skewY(-18deg);
}
#chunkyChat .chat-message::after {
  left: -15px;
  bottom: 13.5px;
  border-width: 0 0 11px 19px;
  border-color: transparent transparent var(--bubble) transparent;
  transform: skewY(-18deg);
}
#chunkyChat .chat-message p { margin: 0; }
#chunkyChat .chat-message strong { font-weight: 700; }
#chunkyChat .chat-message small { font-size: 0.9em; color: var(--ink-soft); }
#chunkyChat .chat-message a { color: var(--ink); font-weight: 700; text-decoration-color: var(--fox); text-decoration-thickness: 3px; }
#chunkyChat kbd { font-size: 0.78em; }

footer {
  max-width: 40rem;
  margin: 0 auto;
  text-align: center;
  padding: 2rem 1.5rem 3rem;
  color: var(--ink-soft);
  font-size: 0.88rem;
}
footer p { margin: 0.4rem 0; }
footer a { color: var(--ink); }

/* ---------- small screens: the lesson first, the index after it ---------- */
@media (max-width: 820px) {
  header { gap: 0.6rem; padding: 0.6rem 1rem; }
  header #mascot { width: 44px; height: 44px; }
  header h1 { font-size: 1.3rem; }
  header p { font-size: 0.85rem; }
  header .nav-jump { display: block; }
  header select, header .nav-jump { padding: 0.35rem 0.5rem; }

  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 1rem 0 0.5rem; }
  main { padding: 1.4rem 0 2rem 1rem; }
  .sidebar {
    order: 2;
    position: static;
    max-height: none;
    overflow: visible;
    padding: 1.5rem 0 1rem 0.5rem;
    border-top: 2px solid var(--ink);
  }
  .lessonText h2 { font-size: 1.7rem; }
  .cell .CodeMirror { font-size: 14px; }
  .workshop { grid-template-columns: minmax(0, 1fr); }
  .ws-editor .CodeMirror-scroll { min-height: 14em; }
  #chunkyChat { gap: 0.9rem; }
  #chunkyChat .chat-avatar img { width: 64px; }
}
/* phones: the title is the brand, the subtitle is the first thing to go */
@media (max-width: 520px) {
  header { gap: 0.5rem; }
  header #mascot { width: 40px; height: 40px; }
  header p { display: none; }
  header h1 { font-size: 1.05rem; }
  header .progress-btn { padding: 0.35rem 0.5rem; }
  header .progress-label { display: none; }
}
/* narrow phones: three buttons need the room, Chunky still waves from his
   speech bubble below */
@media (max-width: 420px) {
  header #mascot { display: none; }
  header h1 { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner-image,
  .load-bar::before,
  .cell.running::after,
  .run-cell .run-fox,
  .cell-out.reveal,
  .cell.shake,
  .cell.celebrate,
  .run-time.fresh,
  #chunkyChat .chat-message { animation: none; }
  .cell.running .CodeMirror { animation: none; opacity: 0.55; }
  button:active { transform: none; }
}
