:root {
  color-scheme: light dark;
  --page: #f4f6f7; --panel: #ffffff; --well: #fbfcfc; --text: #1c2327; --muted: #55636b; --line: #cfd8dc;
  --accent: #0b63ce; --on-accent: #ffffff; --error: #b3261e;
  --comment: #6a737d; --string: #0a6b3d; --number: #a04a00; --keyword: #7a1fc9; --known: #0b63ce;
  font: 16px/1.45 system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #15191c; --panel: #1e2428; --well: #12161a; --text: #e6eaec; --muted: #9aa7ae; --line: #37434a;
    --accent: #6aa9ff; --on-accent: #0d1114; --error: #ff8a80;
    --comment: #8b98a1; --string: #7fd4a0; --number: #f2b27a; --keyword: #c9a4ff; --known: #7db7ff;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text); }
header, footer { padding: 0.75rem 1rem; }
header h1 { display: inline; margin: 0 0.75rem 0 0; font-size: 1.4rem; }
header p { display: inline; color: var(--muted); }
footer { color: var(--muted); font-size: 0.85rem; max-width: 60rem; }
a { color: var(--accent); }

main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; padding: 0 1rem; }
@media (max-width: 60rem) { main { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 1rem 1rem; min-width: 0; }
.heading { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.heading h2 { margin: 0 auto 0 0; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; margin-bottom: 0.25rem; }

button, input, select { font: inherit; color: inherit; }
button, select, input { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 0.3rem 0.7rem; }
button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button:disabled, select:disabled, input:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.4rem 0; }
.error { color: var(--error); font-weight: 600; margin: 0.4rem 0; }
.error:empty { display: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

#files, #new-file { display: flex; flex-wrap: wrap; align-items: end; gap: 0.4rem; margin-top: 0.5rem; }
#files button[aria-pressed="true"] { border-color: var(--accent); border-width: 2px; font-weight: 600; }
#new-file label { display: grid; font-size: 0.85rem; color: var(--muted); }
#new-file input { width: 10rem; color: var(--text); }

/* The program box: the textarea lies exactly over its highlighted copy. */
.editor { position: relative; height: 24rem; margin-top: 0.5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--well); }
.editor pre, .editor textarea {
  position: absolute; inset: 0; margin: 0; padding: 0.6rem; border: 0; border-radius: 6px;
  font: 14px/1.5 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; tab-size: 4; white-space: pre;
}
.editor pre { overflow: hidden; pointer-events: none; }
.editor code { font: inherit; }
.editor textarea { overflow: auto; resize: none; background: transparent; color: transparent; caret-color: var(--text); }
.comment { color: var(--comment); font-style: italic; }
.string { color: var(--string); }
.number { color: var(--number); }
.keyword { color: var(--keyword); font-weight: 600; }
.known { color: var(--known); }
.suggestions { display: flex; gap: 0.3rem; flex-wrap: wrap; min-height: 2.1rem; padding-top: 0.4rem; }
.suggestions button { padding: 0.1rem 0.5rem; font: 13px ui-monospace, Consolas, Menlo, monospace; }
.suggestions button:first-child { border-color: var(--accent); }

#output, #robot-lines { margin: 0; padding: 0.6rem; border: 1px solid var(--line); border-radius: 6px; overflow: auto; font: 13px/1.45 ui-monospace, Consolas, Menlo, monospace; white-space: pre-wrap; }
#output { height: 12rem; }

#view { height: 26rem; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#view.unavailable { display: grid; place-items: center; height: auto; padding: 1rem; color: var(--muted); }
#view canvas { display: block; }
.status { margin: 0.5rem 0; font-weight: 600; }
#hub-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-top: 0.5rem; }
#drive-pad { margin-top: 0.5rem; padding: 0.5rem; border: 1px dashed var(--line); border-radius: 6px; text-align: center; color: var(--muted); cursor: pointer; }
#drive-pad:focus { border-style: solid; border-color: var(--accent); color: var(--text); }
#hub-buttons span { font-size: 0.85rem; color: var(--muted); }
#hub-buttons button.held { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
#result { margin: 0.5rem 0; }
#result p { margin: 0.2rem 0; }

fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 0.75rem 0 0; }
fieldset, .fields { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; }
.fields { margin: 0.5rem 0; }
.fields label, fieldset label { display: grid; font-size: 0.85rem; color: var(--muted); }
.fields input, fieldset input { width: 9rem; color: var(--text); }
label.check { display: flex; align-items: center; gap: 0.4rem; }
label.check input { width: auto; }
label.check.inline { display: inline-flex; }
fieldset button { align-self: end; }
fieldset p { flex-basis: 100%; margin: 0; }
.fields input[type="text"] { width: 14rem; }
table { border-collapse: collapse; margin: 0.5rem 0; }
caption { text-align: left; font-weight: 600; padding-bottom: 0.25rem; }
th { text-align: left; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
th, td { padding: 0.15rem 0.5rem 0.15rem 0; }
/* Relative, so that the visually hidden labels inside scroll with the table. */
.scroll { overflow-x: auto; position: relative; }
.scroll input[type="number"] { width: 5.5rem; }
.scroll input[type="text"] { width: 7rem; }
.scroll input[type="color"] { padding: 0; width: 2.5rem; height: 2rem; }
