:root {
  --bg: #fbfbf9;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e2dc;
  --accent: #b5371f;
  --keyword: #a4306f;
  --type: #1f6aa5;
  --literal: #2c7a3b;
  --comment: #8a8a83;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --fg: #e6e6e1;
    --muted: #9a9a93;
    --line: #2e2e2b;
    --accent: #f0785a;
    --keyword: #e48ac0;
    --type: #7ab8ea;
    --literal: #8fcf8f;
    --comment: #7b7b75;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 0.75rem 1rem;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 system-ui, sans-serif;
}

header { position: sticky; top: 0; z-index: 1; padding: 0.75rem 0 0.5rem; background: var(--bg);
  border-bottom: 1px solid var(--line); }
#title { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
h1 { margin: 0; font-size: 1.3rem; }
header p { margin: 0; color: var(--muted); }
#title p { flex: 1; }
#help { display: grid; margin-top: 0.3rem; font-size: 0.85rem; }
#help > p { grid-area: 1 / 1; }
#links { color: var(--muted); font-size: 0.85rem; }
#links a { color: var(--accent); text-decoration: none; }
#links a:hover { text-decoration: underline; }
button { font: inherit; padding: 0.2rem 0.9rem; border: 1px solid var(--accent); border-radius: 4px;
  background: none; color: var(--accent); cursor: pointer; }
#stop[hidden] { display: inline-block; visibility: hidden; }
button:disabled { opacity: 0.5; cursor: progress; }
#modes button { border-radius: 0; }
#modes button:first-child { border-radius: 4px 0 0 4px; }
#modes button:last-child { border-radius: 0 4px 4px 0; border-left: 0; }
#modes button[aria-pressed="true"] { background: var(--accent); color: var(--bg); }
body[data-mode="file"] .repl-only, body:not([data-mode="file"]) .file-only { display: none !important; }
body[data-mode="file"] #help .repl-only, body:not([data-mode="file"]) #help .file-only {
  display: block !important; visibility: hidden; }
body[data-mode="file"] #stop { display: inline-block !important; visibility: hidden; }

#file { padding-top: 0.5rem; font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
#toolbar { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.6rem; margin-bottom: 0.5rem;
  font-family: system-ui, sans-serif; }
#toolbar button { flex: none; }
#file-status { flex: 1 0 10rem; min-height: 1.45em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); }
#file-stop[hidden] { display: inline-block; visibility: hidden; }
#file-editor { display: flex; border: 1px solid var(--line); border-radius: 4px; }
#gutter { padding: 0.4rem 0.6rem 0.4rem 1.2rem; text-align: right; color: var(--muted);
  border-right: 1px solid var(--line); user-select: none; white-space: pre; }
#gutter .error { color: var(--accent); font-weight: 600; }
#gutter .error::before { content: "●"; position: absolute; margin-left: -1.1rem; }
#code-area { flex: 1; min-width: 0; overflow-x: auto; padding: 0.4rem 0.6rem; }
#code-box { position: relative; width: max-content; min-width: 100%; }
#code-shade, #code { white-space: pre; overflow-wrap: normal; }
#code { position: absolute; inset: 0; width: 100%; padding: 0; border: 0; resize: none;
  overflow: hidden; outline: none; background: transparent; color: transparent; caret-color: var(--fg); }
#file-out { margin-top: 0.75rem; padding: 0.4rem 0.6rem; min-height: 4em; border: 1px solid var(--line);
  border-radius: 4px; }
#file-out:empty::before { content: "Output appears here."; color: var(--muted); }
#file-out .note { color: var(--accent); }

#terminal { padding-top: 0.5rem;
  font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre, textarea { font: inherit; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
#out > div { min-height: 1.4em; }
#out .note { color: var(--accent); }

#line { display: flex; }
.prompt { color: var(--muted); white-space: pre; }
#editor { position: relative; flex: 1; }
#shade, #in { padding: 0; border: 0; width: 100%; }
#in { position: absolute; inset: 0; resize: none; overflow: hidden; outline: none;
  background: transparent; color: transparent; caret-color: var(--fg); }
#in:disabled { cursor: progress; }

#choices { list-style: none; margin: 0.3rem 0 0; padding: 0.3rem 0; columns: 14rem auto;
  border: 1px solid var(--line); border-radius: 4px; }
#choices li { padding: 0 0.6rem; cursor: pointer; break-inside: avoid; }
#choices li.header { color: var(--muted); cursor: default; }
#choices li[aria-selected="true"] { background: var(--line); }
#status { color: var(--muted); margin: 0.5rem 0 0; }
#status:empty { display: none; }

.b { font-weight: 600; }
.c30, .c90, .c37, .c97 { color: var(--muted); }
.c31, .c91 { color: var(--accent); }
.c32, .c92 { color: var(--literal); }
.c33, .c93, .c35, .c95 { color: var(--keyword); }
.c34, .c94, .c36, .c96 { color: var(--type); }
