/* The code workspace.
 *
 * Palette and layout from the concept package (code-editor-tokens.json).
 * The editor's own metrics are the delicate part and are called out where
 * they appear: the textarea and the painted copy behind it MUST agree on
 * every property that affects where a character lands, or the caret sits in
 * one place and its colour in another.
 */

.code-workspace {
  --c-ink: #172033;
  --c-muted: #667085;
  --c-faint: #98a2b3;
  --c-line: #d8dee8;
  --c-bg: #f7f9fc;
  --c-paper: #ffffff;
  --c-dark: #222936;

  --c-accent: #8755ff;
  --c-accent-soft: #f3eeff;
  --c-orange: #ff6b35;
  --c-blue: #3b82f6;
  --c-green: #22c55e;
  --c-teal: #14b8a6;
  --c-amber: #f59e0b;
  --c-red: #ef4444;

  /* The editor surface. Dark whatever the rest of the app is doing: an
   * editor is where a learner looks for minutes at a time. */
  --c-editor: #111827;
  --c-editor-2: #182235;
  --c-editor-line: #1f2a3d;
  --c-editor-text: #e6edf7;

  /* THE METRICS. Both layers of the editor read these and nothing else. */
  --code-font: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono",
               Menlo, Consolas, "Liberation Mono", monospace;
  /* 14px is the floor the specification sets for desktop; the compact
   * tablet size below it is 13px and is set in the media query. */
  --code-size: 14px;
  --code-line: 22px;
  --code-pad-y: 12px;
  --code-pad-x: 14px;

  /* The pane widths. Defined here rather than left to the fallback inside
   * each var(), so a drag has something to change and both columns have
   * one place they are decided. 250px is the width the specification asks
   * for the file explorer. */
  --files-width: 250px;
  --preview-width: 40%;
  --console-height: 190px;

  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ------------------------------------------------------------- the top bar */

.code-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--c-line);
  background: var(--c-paper);
}

.code-bar-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.code-bar-kind {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--c-accent-soft);
  color: var(--c-accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.code-bar-spacer { flex: 1; }

.code-bar button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--c-line);
  border-radius: 9px;
  background: var(--c-paper);
  color: var(--c-ink);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.code-bar button:hover:not(:disabled) { background: var(--c-bg); }
.code-bar button:disabled { opacity: 0.45; cursor: default; }

.code-bar button.primary {
  border-color: transparent;
  background: var(--c-accent);
  color: #fff;
}

.code-bar button.primary:hover:not(:disabled) { background: #6d3bc4; }

.code-bar button.running {
  background: var(--c-red);
  border-color: transparent;
  color: #fff;
}

.code-save-state {
  color: var(--c-muted);
  font-size: 0.78rem;
  min-width: 84px;
  text-align: right;
}

.code-save-state[data-state="unsaved"] { color: var(--c-amber); }
.code-save-state[data-state="saving"] { color: var(--c-blue); }
.code-save-state[data-state="failed"] { color: var(--c-red); font-weight: 700; }

/* --------------------------------------------------------------- the panes */

/* Files, its handle, the editor, the result's handle, the result. The
 * handles are columns of their own so folding a pane to zero leaves the
 * handle exactly where the seam was. */
.code-panes {
  position: relative;
  display: grid;
  grid-template-columns: var(--files-width) 1fr;
  min-height: 0;
}

.code-panes[data-preview="on"] {
  grid-template-columns: var(--files-width) 1fr var(--preview-width);
}

/* Each child names its own column, and that is not tidiness.
 *
 * Auto-placement fills the tracks in document order, so hiding the file
 * pane with `display: none` moved every later child back one track: the
 * editor landed in the 18px handle column and the whole workspace
 * collapsed to a sliver. Named columns cannot shift. */
.code-panes > .code-files-pane { grid-column: 1; }
.code-panes > .code-editor-pane { grid-column: 2; }
.code-panes > .code-preview-pane { grid-column: 3; }

.code-pane {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--c-line);
}

.code-pane:last-child { border-right: 0; }

.code-pane-head {
  display: flex;
  align-items: center;
  /* Never wraps. Wrapping put the Canvas and Variables tabs onto the line
   * the filename was already on and printed them over each other. */
  flex-wrap: nowrap;
  gap: 8px;
  padding: 9px 12px;
  overflow: hidden;
  border-bottom: 1px solid var(--c-line);
  background: var(--c-paper);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--c-muted);
}

.code-pane-head .code-bar-spacer { flex: 1; }

.code-pane-head button {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--c-muted);
  cursor: pointer;
}

.code-pane-head button:hover { background: var(--c-bg); color: var(--c-ink); }

/* ----------------------------------------------------------- the file tree */

.code-files {
  overflow: auto;
  padding: 6px;
  background: var(--c-paper);
}

.code-file {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--c-ink);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.code-file:hover { background: var(--c-bg); }

.code-file[aria-selected="true"] {
  background: var(--c-accent-soft);
  color: var(--c-accent);
  font-weight: 700;
}

.code-file[data-drop="into"] {
  outline: 2px solid var(--c-accent);
  outline-offset: -2px;
  background: var(--c-accent-soft);
}

/* Dropping onto the empty space below the tree means the top of the
 * project, which is a real target and has to look like one. */
.code-files[data-drop="root"] {
  outline: 2px dashed var(--c-accent);
  outline-offset: -4px;
}

/* The keyboard has to be visible. A tree row is a div, so it gets none of
 * the focus ring a button would have had. */
.code-file:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: -2px;
}

.code-file[draggable="true"]:active { opacity: 0.55; }

.code-file-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
}

.code-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-file-note {
  color: var(--c-faint);
  font-size: 0.72rem;
}

.code-file-twist {
  flex: none;
  width: 12px;
  color: var(--c-faint);
  transition: transform 0.12s ease;
}

.code-file[data-open="false"] .code-file-twist { transform: rotate(-90deg); }

.code-file-rename {
  flex: 1;
  min-width: 0;
  padding: 2px 6px;
  border: 1px solid var(--c-accent);
  border-radius: 5px;
  font: inherit;
  font-size: 0.85rem;
}

/* -------------------------------------------------------------- the editor */

.code-editor-pane { background: var(--c-editor); }

.code-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--c-editor-line);
  background: var(--c-editor-2);
  scrollbar-width: thin;
}

.code-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 9px 12px;
  border: 0;
  border-right: 1px solid var(--c-editor-line);
  background: transparent;
  color: #93a2ba;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.code-tab:hover { color: var(--c-editor-text); }

.code-tab[aria-current="true"] {
  background: var(--c-editor);
  color: var(--c-editor-text);
  box-shadow: inset 0 -2px 0 var(--c-accent);
}

.code-tab-close {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  color: inherit;
  opacity: 0.6;
}

.code-tab-close:hover { background: rgb(255 255 255 / 0.15); opacity: 1; }
.code-tab[data-dirty="true"] .code-tab-close::before { content: "\2022"; font-size: 1.1rem; }
.code-tab[data-dirty="true"]:hover .code-tab-close::before { content: none; }

.code-editor-stack {
  position: relative;
  min-height: 0;
  background: var(--c-editor);
}

/* The editor proper. Two layers, one set of metrics.
 *
 * NOT absolutely positioned: `CodeEditor` adds this class to the element it
 * is given, which is the same element as `.code-editor-stack`. Taking it out
 * of flow took it out of the row the console shares with it, and the console
 * ended up drawn on top of the last lines of the file. It fills its row
 * instead, which is what it was there to do. */
.code-editor {
  display: grid;
  grid-template-columns: auto 1fr;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--c-editor);
}

.code-gutter,
.code-paint,
.code-input {
  /* Everything below this line must match across all three. */
  margin: 0;
  font-family: var(--code-font);
  font-size: var(--code-size);
  line-height: var(--code-line);
  font-weight: 400;
  letter-spacing: normal;
  word-spacing: normal;
  tab-size: 2;
  white-space: pre;
}

.code-gutter {
  padding: var(--code-pad-y) 10px var(--code-pad-y) 14px;
  overflow: hidden;
  border-right: 1px solid var(--c-editor-line);
  background: var(--c-editor);
  color: #4a5a75;
  text-align: right;
  user-select: none;
}

.code-scroll {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.code-paint,
.code-input {
  position: absolute;
  inset: 0;
  padding: var(--code-pad-y) var(--code-pad-x);
  border: 0;
  overflow: auto;
}

.code-paint {
  pointer-events: none;
  color: var(--c-editor-text);
  overflow: hidden;
}

/* The layers that actually move.
 *
 * They hold only the lines on screen and are slid into place; their parents
 * stay put and clip. Sliding the parent instead took its bottom edge above
 * the bottom of the view, and the rows below it had nothing to be drawn on
 * — which showed as a few lines of code and then an empty editor.
 *
 * `display: block` so a span can hold lines at all, and `will-change` so
 * the slide stays on the compositor instead of repainting the column. */
.code-paint-lines,
.code-gutter-lines {
  display: block;
  will-change: transform;
}

.code-input {
  /* The text is invisible; only the caret and selection show through, and
   * the colour comes from the painted copy underneath. */
  color: transparent;
  background: transparent;
  caret-color: var(--c-orange);
  resize: none;
  outline: none;
}

.code-input::selection { background: rgb(135 85 255 / 0.35); }

/* The colours. One per token kind, and no more. */
.tok-comment { color: #6b7f9e; font-style: italic; }
.tok-string  { color: #7ee0a8; }
.tok-number  { color: #ffb86b; }
.tok-keyword { color: #c39bff; font-weight: 600; }
.tok-name    { color: #6fc3ff; }
.tok-tag     { color: #ff8f6b; }
.tok-attr    { color: #ffd479; }
.tok-punct   { color: #8ea0bd; }

/* -------------------------------------------------------------- the finder */

.code-find {
  position: absolute;
  top: 10px;
  right: 18px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--c-editor-line);
  border-radius: 10px;
  background: var(--c-editor-2);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.35);
}

.code-find input {
  width: 180px;
  padding: 5px 8px;
  border: 1px solid var(--c-editor-line);
  border-radius: 6px;
  background: var(--c-editor);
  color: var(--c-editor-text);
  font: inherit;
  font-size: 0.82rem;
  outline: none;
}

.code-find input:focus { border-color: var(--c-accent); }
/* A border colour alone is too faint to find the caret by. */
.code-find input:focus-visible { box-shadow: 0 0 0 2px var(--c-accent); }

.code-find-count {
  color: #93a2ba;
  font-size: 0.76rem;
  min-width: 62px;
}

.code-find button {
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #93a2ba;
  font: inherit;
  cursor: pointer;
}

.code-find button:hover { background: rgb(255 255 255 / 0.1); color: #fff; }

/* ------------------------------------------------------- image and binary */

.code-viewer {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  padding: 24px;
  overflow: auto;
  text-align: center;
  color: #93a2ba;
}

.code-viewer img {
  max-width: 100%;
  max-height: 55vh;
  border-radius: 10px;
  background: repeating-conic-gradient(#2a3548 0 25%, #222c3d 0 50%) 0 0 / 18px 18px;
}

.code-viewer-name { color: var(--c-editor-text); font-weight: 700; }
.code-viewer-note { font-size: 0.82rem; }

/* ------------------------------------------------------------- the preview */

.code-preview-pane { background: var(--c-paper); }

.code-preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.code-preview-empty {
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 32px;
  text-align: center;
  color: var(--c-muted);
  font-size: 0.86rem;
}

/* The file being shown. It gives way before the tabs do — knowing WHICH
 * view you are looking at matters more than knowing the filename, which is
 * also on the editor tab a few inches away. */
.code-preview-url {
  flex: 0 1 auto;
  min-width: 0;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--c-bg);
  color: var(--c-muted);
  font-family: var(--code-font);
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------- the console */

.code-console {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  border-top: 1px solid var(--c-editor-line);
  background: var(--c-editor-2);
}

.code-console-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--c-editor-line);
  color: #93a2ba;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.code-console-lines {
  overflow: auto;
  padding: 8px 12px 12px;
  font-family: var(--code-font);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--c-editor-text);
}

.code-console-line { white-space: pre-wrap; word-break: break-word; }
.code-console-line[data-kind="error"] { color: #ff9a9a; }
.code-console-line[data-kind="warn"] { color: #ffd479; }
.code-console-line[data-kind="note"] { color: #93a2ba; font-style: italic; }
.code-console-line[data-kind="good"] { color: #7ee0a8; }
.code-console-line[data-kind="prompt"] { color: #c39bff; }

.code-console-line[data-kind="error"] .code-jump {
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.code-ask {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--c-editor-line);
}

.code-ask input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--c-editor-line);
  border-radius: 7px;
  background: var(--c-editor);
  color: var(--c-editor-text);
  font-family: var(--code-font);
  font-size: 12.5px;
  outline: none;
}

.code-ask input:focus { border-color: var(--c-accent); }
.code-ask input:focus-visible { box-shadow: 0 0 0 2px var(--c-accent); }

/* ---------------------------------------------------------------- dividers */

/* The drag handles. A column handle sits on its pane's right edge as an
 * overlay rather than as another grid column, so adding one does not change
 * the track list the panes are laid out on. */
.code-grip {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.12s ease;
}

.code-grip-col {
  position: absolute;
  top: 0;
  right: -3px;
  bottom: 0;
  width: 7px;
  z-index: 6;
}

.code-grip:hover, .code-grip[data-dragging="true"] { background: var(--c-accent); }

/* ------------------------------------------------------------- the toaster */

.code-toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 11px;
  background: var(--c-dark);
  color: #fff;
  font-size: 0.86rem;
  box-shadow: 0 12px 30px rgb(23 32 51 / 0.3);
}

.code-toast[data-tone="bad"] { background: var(--c-red); }
.code-toast[data-tone="good"] { background: #16803d; }

/* ---------------------------------------------------------------- the menu */

.code-menu {
  position: fixed;
  z-index: 40;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--c-line);
  border-radius: 11px;
  background: var(--c-paper);
  box-shadow: 0 14px 36px rgb(23 32 51 / 0.18);
}

.code-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--c-ink);
  font: inherit;
  font-size: 0.86rem;
  text-align: left;
  cursor: pointer;
}

.code-menu button:hover { background: var(--c-bg); }
.code-menu button[data-tone="bad"] { color: var(--c-red); }
.code-menu button[data-tone="bad"]:hover { background: #fff0f0; }
.code-menu hr { margin: 5px 6px; border: 0; border-top: 1px solid var(--c-line); }

/* --------------------------------------------------------- narrow windows */

@media (max-width: 900px) {
  .code-workspace { --code-size: 13px; --code-line: 20px; }

  .code-panes,
  .code-panes[data-preview="on"] { grid-template-columns: 1fr; }
  .code-panes > .code-pane:not(.code-editor-pane) { display: none; }
  .code-panes[data-only="files"] > .code-files-pane { display: grid; }
  .code-panes[data-only="files"] > .code-editor-pane { display: none; }
  .code-panes[data-only="preview"] > .code-preview-pane { display: grid; }
  .code-panes[data-only="preview"] > .code-editor-pane { display: none; }
}

/* ------------------------------------------- what workspace.js also needs */

/* The editor pane splits into the editor and the console below it. The
 * console's height is a custom property so the drag handle can set it
 * without this file having to know a number. */
.code-editor-holder {
  display: grid;
  grid-template-rows: 1fr auto var(--console-height, 190px);
  min-height: 0;
}

.code-grip-rows {
  width: auto;
  height: 5px;
  cursor: row-resize;
}

.code-file-more {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--c-faint);
  opacity: 0;
  cursor: pointer;
}

.code-file:hover .code-file-more,
.code-file-more:focus-visible { opacity: 1; }
.code-file-more:hover { background: var(--c-line); color: var(--c-ink); }

/* The file's own mark. A fixed box, so every name in the tree starts at
 * the same x whatever its icon is. */
.code-file-mark {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
}

.code-right-tab {
  display: inline-flex;
  align-items: center;
  flex: none;
  white-space: nowrap;
  gap: 6px;
  color: var(--c-ink);
  font-weight: 800;
}

.code-right-body {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--c-paper);
}

.code-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
}

.code-viewer code {
  padding: 2px 6px;
  border-radius: 5px;
  background: rgb(255 255 255 / 0.08);
  color: var(--c-editor-text);
  font-family: var(--code-font);
  font-size: 0.85em;
}

/* The view slot in the app shell. Positioned so the workspace inside it can
 * fill it absolutely, the same way the design workbench does. */
.code-editor-view {
  position: relative;
  min-height: 0;
  height: 100%;
}

.code-editor-view[hidden] { display: none; }

/* A pane that is off is out of the grid entirely. Without this the browser
 * keeps `display: grid` from the .code-pane rule and the hidden attribute
 * does nothing. */
.code-pane[hidden] { display: none; }

/* The one action a toast may carry. Undo, in practice. */
.code-toast-action {
  padding: 5px 12px;
  border: 1px solid rgb(255 255 255 / 0.35);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.code-toast-action:hover { background: rgb(255 255 255 / 0.15); }

/* ------------------------------------------------------- touch and small
 *
 * The tablet edition keeps the desktop model and gets bigger targets, not
 * a different interface. 44px is the floor the specification sets, and it
 * applies to anything a finger has to hit.
 */
@media (pointer: coarse) {
  .code-bar button,
  .code-pane-head button,
  .code-tab,
  .code-file,
  .code-file-more {
    min-height: 44px;
  }

  .code-pane-head button,
  .code-file-more { min-width: 44px; }

  /* Always visible: there is no hover on a touch screen, so a control that
   * appears on hover is a control that does not exist. */
  .code-file-more { opacity: 1; }

  .code-grip { width: 12px; }
  .code-grip-rows { height: 12px; }
}

/* The smallest screen this is meant to work on: 1024x600 landscape. The
 * file list gives way before the editor does, which is the order the
 * specification asks for. */
@media (max-width: 1100px) {
  .code-workspace { --files-width: 208px; }
}

@media (max-height: 640px) {
  .code-workspace { --console-height: 128px; }
  .code-bar { padding: 6px 12px; }
  .code-pane-head { padding: 6px 12px; }
}

/* ------------------------------------------------------- the right pane */

.code-right-tabs {
  display: flex;
  flex: 0 0 auto;
  gap: 2px;
}

.code-right-tab {
  display: inline-flex;
  align-items: center;
  flex: none;
  white-space: nowrap;
  gap: 6px;
  padding: 5px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--c-muted);
  font: inherit;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.code-right-tab:hover { background: var(--c-bg); color: var(--c-ink); }

.code-right-tab[aria-selected="true"] {
  background: var(--c-accent-soft);
  color: var(--c-accent);
}

.code-canvas[hidden], .code-variables[hidden] { display: none; }

/* What the program's variables ended up holding. A table, because that is
 * what a list of name-and-value is, and a screen reader can then say which
 * column it is reading. */
.code-variables {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 12px 14px;
}

.code-variables-empty {
  margin: 24px 0;
  color: var(--c-muted);
  font-size: 0.86rem;
  text-align: center;
}

.code-variables-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.code-variables-table th,
.code-variables-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--c-line);
  text-align: left;
  vertical-align: top;
}

.code-variables-table thead th {
  position: sticky;
  top: -12px;
  background: var(--c-paper);
  color: var(--c-muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.code-variables-table tbody th {
  font-family: var(--code-font);
  font-weight: 700;
  color: var(--c-accent);
  white-space: nowrap;
}

.code-variables-table td {
  font-family: var(--code-font);
  word-break: break-word;
}

.code-variables-kind {
  color: var(--c-faint);
  font-family: inherit !important;
  white-space: nowrap;
}

/* ---------------------------------------------------------- the examples */

.code-help {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(420px, calc(100% - 32px));
  max-height: min(560px, calc(100% - 90px));
  border: 1px solid var(--c-line);
  border-radius: 14px;
  background: var(--c-paper);
  box-shadow: 0 18px 44px rgb(23 32 51 / 0.22);
  overflow: hidden;
}

.code-help-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--c-line);
}

.code-help-head strong { font-size: 0.9rem; }

.code-help-topics {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
}

.code-help-topics button {
  padding: 5px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--c-muted);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.code-help-topics button:hover { background: var(--c-bg); color: var(--c-ink); }

.code-help-topics button[aria-selected="true"] {
  background: var(--c-accent-soft);
  color: var(--c-accent);
}

.code-help-close {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--c-muted);
  cursor: pointer;
}

.code-help-close:hover { background: var(--c-bg); color: var(--c-ink); }

.code-help-list {
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.code-help-item {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.code-help-item:hover {
  border-color: var(--c-accent);
  background: var(--c-bg);
}

.code-help-title { font-size: 0.86rem; font-weight: 700; color: var(--c-ink); }
.code-help-note { font-size: 0.74rem; color: var(--c-muted); }

.code-help-code {
  margin: 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--c-editor);
  color: var(--c-editor-text);
  font-family: var(--code-font);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
  overflow-x: auto;
}

.code-help-foot {
  margin: 0;
  padding: 9px 12px;
  border-top: 1px solid var(--c-line);
  color: var(--c-muted);
  font-size: 0.76rem;
}

/* ------------------------------------------------------- the first time */

.code-coach {
  position: absolute;
  z-index: 40;
  width: 288px;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--c-dark);
  color: #fff;
  box-shadow: 0 18px 44px rgb(23 32 51 / 0.34);
}

.code-coach-step {
  margin: 0 0 4px;
  color: #9fb0c9;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.code-coach-title { margin: 0 0 6px; font-size: 1.05rem; }
.code-coach-what { margin: 0 0 14px; font-size: 0.86rem; line-height: 1.5; color: #d5deea; }

.code-coach-buttons { display: flex; justify-content: flex-end; gap: 8px; }

.code-coach-buttons button {
  padding: 8px 15px;
  border: 1px solid rgb(255 255 255 / 0.28);
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.code-coach-buttons button:hover { background: rgb(255 255 255 / 0.12); }

.code-coach-buttons .primary {
  border-color: transparent;
  background: var(--c-accent);
}

.code-coach-buttons .primary:hover { background: #6d3bc4; }

/* What the current step is pointing at. */
[data-coached="true"] {
  position: relative;
  z-index: 39;
  outline: 3px solid var(--c-accent);
  outline-offset: -3px;
  border-radius: 4px;
}

/* The live-preview toggle. A pressed state rather than a checkbox, because
 * it is a thing that is on or off rather than a setting being filled in. */
.code-live {
  padding: 4px 10px !important;
  border: 1px solid var(--c-line) !important;
  border-radius: 999px !important;
  background: transparent;
  color: var(--c-muted);
  font-size: 0.7rem !important;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  width: auto !important;
  height: auto !important;
  cursor: pointer;
}

.code-live[aria-pressed="true"] {
  border-color: transparent !important;
  background: var(--c-green);
  color: #fff;
}

/* =========================================================== dark theme
 *
 * The editor surface was dark already, which made the rest of the workspace
 * around it look like a light window with a hole cut in it once the app's
 * own theme went dark. These are the panels, not the code: the token
 * colours in the editor are the same in both themes because code that
 * changes colour with the furniture is code you have to re-learn to read.
 *
 * The washes become tints OF the dark panel rather than tints of white. A
 * pale wash printed on a dark surface is a light rectangle with dark text
 * in it, which is the one thing a dark theme must not do.
 */
:root[data-theme="dark"] .code-workspace {
  --c-ink: #e6edf7;
  --c-muted: #9aa9c0;
  --c-faint: #6c7c96;
  --c-line: #2a3446;
  --c-bg: #131a26;
  --c-paper: #182130;
  --c-dark: #0d131d;

  --c-accent: #a985ff;
  --c-accent-soft: #2a2145;

  --c-editor: #0f1620;
  --c-editor-2: #141d2b;
  --c-editor-line: #253044;
}

:root[data-theme="dark"] .code-preview-pane,
:root[data-theme="dark"] .code-right-body {
  background: var(--c-paper);
}

/* The learner's own page is THEIR page. It keeps its own colours whatever
 * the IDE is wearing — a white page in a dark editor is correct, because a
 * white page is what they wrote. */
:root[data-theme="dark"] .code-preview-frame { background: #fff; }

:root[data-theme="dark"] .code-menu,
:root[data-theme="dark"] .code-help {
  background: var(--c-paper);
  border-color: var(--c-line);
  box-shadow: 0 18px 44px rgb(0 0 0 / 0.5);
}

:root[data-theme="dark"] .code-menu button[data-tone="bad"]:hover {
  background: #3a1d1d;
}

:root[data-theme="dark"] .code-file-rename {
  background: var(--c-editor);
  color: var(--c-ink);
}

:root[data-theme="dark"] .code-variables-table thead th { background: var(--c-paper); }

:root[data-theme="dark"] .code-canvas {
  /* The drawing surface stays white: a turtle drawing is a picture the
   * learner made, not part of the furniture. */
  background: #fff;
}

/* ------------------------------------------------------ folding the panes
 *
 * The same idea as the palette and simulator handles in the block shell:
 * a seam you can press to give the space to whatever you are working in.
 */
.code-fold {
  position: absolute;
  top: 50%;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 22px;
  height: 54px;
  margin-top: -27px;
  padding: 0;
  border: 1px solid var(--c-line);
  border-radius: 10px;
  background: var(--c-paper);
  color: var(--c-muted);
  cursor: pointer;
  box-shadow: 0 2px 8px rgb(16 24 40 / 0.1);
}

.code-fold:hover { background: var(--c-bg); color: var(--c-ink); }

.code-fold:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

.code-fold[hidden] { display: none; }

/* Each sits half over the seam it belongs to, following that pane's own
 * width, so a dragged divider takes its handle with it. */
.code-fold-files { left: calc(var(--files-width) - 11px); }
.code-fold-preview { right: calc(var(--preview-width) - 11px); }

/* The chevron points at what pressing it will do: inward to put a pane
 * away, outward to bring it back. */
.code-fold svg { transition: transform 0.16s ease; }
.code-fold-files[data-folded="true"] svg { transform: rotate(180deg); }
.code-fold-preview svg { transform: rotate(180deg); }
.code-fold-preview[data-folded="true"] svg { transform: none; }

/* Folded is zero width with nothing spilling out, rather than removed:
 * see the note above about what removing a grid child does to the ones
 * after it. */
.code-panes[data-preview="off"] { --preview-width: 0px; }
.code-panes[data-files="folded"] { --files-width: 0px; }
.code-panes[data-files="folded"] > .code-files-pane {
  overflow: hidden;
  border-right: 0;
}

/* The supplied icons, from the concept package's own set.
 *
 * They carry their own colour, so they are never tinted here — an HTML5
 * shield that is not orange is not the HTML5 shield. `flex: none` keeps
 * them from being squeezed when a filename is long. */
.code-brand-icon {
  flex: none;
  display: block;
  object-fit: contain;
}

.code-console-head .code-brand-icon { opacity: 0.8; }

/* ----------------------------------------------------- making a new file
 *
 * A panel, because the browser dialog this replaces is refused outright by
 * Electron and by several browsers — the button simply did nothing. It sits
 * over the file list, near the button that opened it.
 */
.code-new {
  position: absolute;
  top: 52px;
  left: 12px;
  z-index: 35;
  display: grid;
  gap: 10px;
  width: min(300px, calc(100% - 24px));
  padding: 14px;
  border: 1px solid var(--c-line);
  border-radius: 13px;
  background: var(--c-paper);
  box-shadow: 0 16px 40px rgb(23 32 51 / 0.2);
}

.code-new-where {
  margin: 0;
  color: var(--c-muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.code-new-where strong { color: var(--c-accent); }

.code-new-name {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--c-line);
  border-radius: 9px;
  background: var(--c-bg);
  color: var(--c-ink);
  font: inherit;
  font-size: 0.92rem;
  outline: none;
}

.code-new-name:focus { border-color: var(--c-accent); }
.code-new-name:focus-visible { box-shadow: 0 0 0 2px var(--c-accent); }

/* The ending is chosen, not typed. Asking a learner to spell ".html"
 * correctly is a spelling test between them and a file. */
.code-new-endings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 6px;
}

.code-new-endings button {
  display: grid;
  gap: 1px;
  padding: 7px 8px;
  border: 1px solid var(--c-line);
  border-radius: 9px;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.code-new-endings button:hover { border-color: var(--c-accent); }

.code-new-endings button[aria-checked="true"] {
  border-color: var(--c-accent);
  background: var(--c-accent-soft);
}

.code-new-ending {
  color: var(--c-accent);
  font-family: var(--code-font);
  font-size: 0.82rem;
  font-weight: 700;
}

.code-new-what { color: var(--c-muted); font-size: 0.68rem; }

.code-new-problem {
  margin: 0;
  color: var(--c-red);
  font-size: 0.78rem;
}

.code-new-problem[hidden] { display: none; }

.code-new-buttons { display: flex; justify-content: flex-end; gap: 8px; }

.code-new-buttons button {
  padding: 8px 15px;
  border: 1px solid var(--c-line);
  border-radius: 9px;
  background: transparent;
  color: var(--c-ink);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.code-new-buttons button:hover { background: var(--c-bg); }

.code-new-buttons .primary {
  border-color: transparent;
  background: var(--c-accent);
  color: #fff;
}

.code-new-buttons .primary:hover { background: #6d3bc4; }
