/* The playground: a workbench. The program sits on the left like a notebook
   margin; the model stands on the paper at right, and the word's steps run
   along its foot, read right to left. The colours are the site's (site.css):
   white paper, black ink, and Byrne's red, yellow and blue for the faces. */
:root {
  --bg: var(--paper);
  --panel: var(--paper);
  --stage: var(--paper);
  --line: var(--rule);
  --fg: var(--ink);
  --muted: var(--grey);
  --accent: var(--ink);
  --accent-soft: #fbf0cf;
  --error: var(--red);
  --ok: var(--blue);
  --display: var(--text);
  --body: var(--text);
  --code-size: 13px;
  --code-line: 21px;
  --hl-label: #9a6800;          /* Byrne's yellow, dark enough to read on white */
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --accent-soft: #3a321c; --hl-label: var(--yellow); } }
:root[data-theme="dark"] { --accent-soft: #3a321c; --hl-label: var(--yellow); }

html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 380 14px/1.45 var(--body);
  display: flex; flex-direction: column;
}
button, select, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- header ------------------------------------------------------------------ */
header {
  display: flex; align-items: center; gap: 12px 18px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 600; font-stretch: 115%; letter-spacing: .04em; text-decoration: none; font-size: 15px; }
.site-links { display: flex; gap: 18px; margin-right: auto; font-size: 14px; }
.site-links a { color: var(--muted); text-decoration: none; }
.site-links a:hover { color: var(--fg); }
.engine { font: 12px var(--mono); color: var(--muted); display: flex; align-items: center; gap: 6px; }
.engine::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.engine[data-state="ready"]::before { background: var(--ok); }
.engine[data-state="failed"]::before { background: var(--error); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 0;
  padding: 6px 11px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--fg); }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.btn.primary { background: var(--fg); border-color: var(--fg); color: var(--bg); font-weight: 500; }
select.btn { padding-right: 8px; }

/* --- the bench ---------------------------------------------------------------- */
main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(320px, 40%) 1fr;
}
.side { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }

.editor { position: relative; flex: 1 1 55%; min-height: 220px; display: flex; overflow: hidden; border-bottom: 1px solid var(--line); }
.gutter {
  flex: none; width: 46px; overflow: hidden; padding-block: 10px;
  font: var(--code-size)/var(--code-line) var(--mono); color: var(--muted);
  border-right: 1px solid var(--line); user-select: none; font-variant-numeric: tabular-nums;
}
.gutter div { height: var(--code-line); display: flex; justify-content: space-between; padding-inline: 6px 6px; }
.gutter .mark { width: 8px; text-align: center; }
.gutter .error .mark { color: var(--error); }
.gutter .shape .mark { color: var(--ok); }
.gutter .define .mark, .gutter .operator .mark { color: var(--muted); }
.code { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.focus-bar {
  position: absolute; left: 0; right: 0; height: var(--code-line); background: var(--accent-soft);
  pointer-events: none; transform: translateY(0);
}
/* The text you type is transparent; the coloured copy behind it (lang.js highlight)
   shows through, moved with the textarea's scroll. Same font, padding and tabs. */
textarea#program, .highlight {
  margin: 0; border: 0; padding: 10px 12px; white-space: pre; tab-size: 2;
  font: var(--code-size)/var(--code-line) var(--mono);
}
textarea#program {
  position: absolute; inset: 0; width: 100%; height: 100%; resize: none;
  background: transparent; outline: none; overflow: auto;
  color: transparent; caret-color: var(--fg);
}
textarea#program::selection { color: transparent; background: color-mix(in srgb, var(--blue) 22%, transparent); }
.highlight { position: absolute; top: 0; left: 0; min-width: 100%; pointer-events: none; color: var(--fg); }
.hl-op { color: var(--red); }
.hl-sel { color: var(--blue); }
.hl-label { color: var(--hl-label); }
.hl-seed { font-weight: 500; }
.hl-def { font-weight: 500; }
.hl-num, .hl-punct, .hl-key, .hl-str { color: var(--muted); }
.hl-cmt { color: var(--muted); font-style: italic; }

.notes { flex: 0 1 auto; max-height: 30%; overflow: auto; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.notes:empty { display: none; }
.note { display: flex; gap: 10px; font-size: 13px; cursor: pointer; padding: 3px 0; }
.note b { font: 500 12px var(--mono); color: var(--error); white-space: nowrap; font-variant-numeric: tabular-nums; }
.note span { min-width: 0; }
.note .cat { font: 12px var(--mono); color: var(--muted); }

details.reference { flex: 0 1 auto; overflow: auto; max-height: 45%; }
details.reference > summary {
  cursor: pointer; padding: 10px 14px; font: 500 12px var(--body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}
details.reference > summary a { margin-left: 10px; text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 380; }
.ref { padding: 0 14px 14px; display: grid; gap: 14px; }
.ref h3 { margin: 0 0 4px; font: 500 12px var(--body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.ref table { border-collapse: collapse; width: 100%; font-size: 13px; }
.ref td { padding: 3px 8px 3px 0; vertical-align: top; border-top: 1px solid var(--line); }
.ref td:first-child { font-family: var(--mono); white-space: nowrap; width: 1%; }
.ref .scroll { overflow-x: auto; }

/* --- the stage ---------------------------------------------------------------- */
.stage { position: relative; min-width: 0; min-height: 0; background: var(--stage); display: flex; flex-direction: column; }
.canvas-wrap { position: relative; flex: 1; min-height: 0; touch-action: none; cursor: grab; }
.canvas-wrap:active { cursor: grabbing; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.overlay { position: absolute; pointer-events: none; }
.word-title { top: 14px; left: 16px; right: 16px; display: grid; gap: 4px; }
.word-title .word { font: 500 15px/1.35 var(--mono); overflow-wrap: anywhere; }
.word-title .sub { font-size: 12px; color: var(--muted); }
.counts {
  top: 14px; right: 16px; font: 12px var(--mono); color: var(--muted); text-align: right;
  font-variant-numeric: tabular-nums; display: grid; gap: 2px;
}
.word-title { right: 190px; }
.message {
  inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted);
}
.message p { max-width: 42ch; margin: 0; }
.message .err { color: var(--error); font-family: var(--mono); font-size: 13px; }
.tip {
  position: absolute; pointer-events: none; padding: 6px 9px; border-radius: 0; background: var(--panel);
  border: 1px solid var(--line); font: 12px/1.4 var(--mono); white-space: nowrap; transform: translate(12px, 12px);

}

.foot { border-top: 1px solid var(--line); padding: 10px 16px 12px; display: grid; gap: 10px; background: var(--panel); }
.steps-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.steps-label { font: 500 11px var(--body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.steps { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; min-width: 0; direction: ltr; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 0; padding: 4px 8px; cursor: pointer;
  font: 13px var(--mono); white-space: nowrap;
}
.chip[aria-pressed="true"] { border-color: var(--fg); background: var(--accent-soft); }
.chip.pending { opacity: 0.45; }
.chip.failed { border-color: var(--error); color: var(--error); }
.view-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); overflow: hidden; }
.seg button { border: 0; background: var(--bg); padding: 4px 10px; cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--fg); color: var(--bg); font-weight: 500; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font: 12px var(--mono); min-width: 0; }
.legend span { display: inline-flex; align-items: center; gap: 5px; cursor: default; }
.legend i { width: 10px; height: 10px; display: inline-block; outline: 1px solid var(--edge); outline-offset: -1px; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 8px 14px; font-size: 13px;
}

@media (max-width: 760px) {
  body { height: auto; }
  main { grid-template-columns: 1fr; }
  .stage { order: -1; height: 72vh; min-height: 380px; }
  .side { border-right: 0; }
  .editor { min-height: 300px; }
  .notes, details.reference { max-height: none; }
  .word-title { right: 16px; top: 46px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto; } }
