:root {
  --bg: #fbfbfa;
  --panel: #ffffff;
  --fg: #1d1f23;
  --muted: #6b7280;
  --line: #e4e4e0;
  --accent: #2f5fd0;
  --err: #c62828;
  --warn: #b26a00;
  --ok: #2e7d32;
  --kw: #7b3fb5;
  --var: #9a3412;
  --str: #2e7d32;
  --num: #0e7490;
  --cmt: #8a8f98;
  --builtin: #2f5fd0;
  --full: #c2410c;
  --partial: #0f766e;
  --row-alt: #f6f6f3;
  --note: #4f6fa8;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
  --code-size: 14px;
  --code-line: 20px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --panel: #1b1e23;
    --fg: #e6e6e3;
    --muted: #9aa0a8;
    --line: #2c3037;
    --accent: #7aa2ff;
    --err: #ff6b6b;
    --warn: #f0b440;
    --ok: #6fcf7a;
    --kw: #c79bff;
    --var: #ff9e64;
    --str: #9ece6a;
    --num: #5ccfe6;
    --cmt: #6b7280;
    --builtin: #7aa2ff;
    --full: #ff9e64;
    --partial: #4fd6be;
    --row-alt: #1f2228;
    --note: #8fa8d8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.04em; color: var(--fg); text-decoration: none; }
.brand img { display: block; border-radius: 5px; }
.sub { color: var(--muted); }

.bar select, .bar input, .bar button {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
}

.limit { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.limit input { width: 6.5em; }

#run {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 4px 16px;
  cursor: pointer;
}
#run:disabled { opacity: 0.5; cursor: default; }

.bar button.ghost { background: var(--bg); cursor: pointer; }
.bar button.ghost:hover { border-color: var(--accent); }
.data { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.data-list { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  font-size: 12px;
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: var(--bg);
}
.chip.bad { color: var(--err); border-color: var(--err); }
.chip { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { all: unset; cursor: pointer; margin-left: 4px; color: var(--muted); }

.status { color: var(--muted); margin-left: auto; }
.bar .gh { display: inline-flex; color: var(--muted); }
.bar .gh:hover { color: var(--fg); }
.bar .gh svg { display: block; }
.status.bad { color: var(--err); }

.split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, var(--left, 1fr)) 6px minmax(240px, 1fr);
}

.pane { min-height: 0; display: flex; flex-direction: column; }
.divider {
  cursor: col-resize;
  background: var(--line);
  border-left: 2px solid var(--bg);
  border-right: 2px solid var(--bg);
}
.divider:hover, .divider.dragging, .divider:focus-visible { background: var(--accent); outline: none; }
body.resizing { cursor: col-resize; user-select: none; }

/* Autocompletion */
.complete {
  position: absolute;
  z-index: 6;
  margin: 0;
  padding: 4px;
  list-style: none;
  min-width: 240px;
  max-width: min(520px, 100%);
  max-height: 228px;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.complete[hidden] { display: none; }
.complete li { display: flex; gap: 8px; align-items: baseline; padding: 3px 8px; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.complete li.active { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.complete .lbl { font: 13px var(--mono); color: var(--fg); }
.complete .kind { font-size: 11px; color: var(--accent); }
.complete .det { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

/* Export menu */
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  min-width: 250px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}
.menu[hidden] { display: none; }
.menu button {
  text-align: left;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: none;
  border: 0;
  border-radius: 5px;
  padding: 6px 10px;
  cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--row-alt); outline: none; }
.menu button:disabled { color: var(--muted); cursor: default; background: none; }

/* Result table toolbar and tab groups */
.table-bar { display: flex; align-items: center; gap: 6px; padding: 6px 16px; border-bottom: 1px solid var(--line); }
.table-bar[hidden] { display: none; }
.table-title { flex: 1; color: var(--muted); font-size: 13px; }
button.small { font-size: 12px; padding: 2px 10px; }
button.ghost { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
button.ghost:hover { border-color: var(--accent); }
.tabs .group { align-self: center; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 2px 0 8px; }
.tabs .group:first-child { margin-left: 0; }

/* Data tab */
.data-hint { padding: 8px 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.data-wrap { flex: 1; min-height: 0; overflow: auto; padding: 12px 16px 24px; }
.dcard { margin-bottom: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.dhead { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.dhead h3 { margin: 0; font: 600 14px var(--mono); }
.dhead .counts { flex: 1; color: var(--muted); font-size: 12px; }
.badge { font-size: 11px; padding: 0 6px; border-radius: 8px; border: 1px solid var(--line); color: var(--muted); }
.dtable { border-collapse: collapse; width: 100%; font: 13px/1.4 var(--mono); }
.dtable th { position: static; text-align: left; padding: 4px 8px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); background: var(--panel); }
.dtable th small { font-weight: 400; margin-left: 4px; }
.dtable td { padding: 1px 4px; border-bottom: 1px solid var(--line); }
.dtable input {
  width: 100%;
  min-width: 60px;
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 4px;
}
.dtable input:hover { border-color: var(--line); }
.dtable input:focus { border-color: var(--accent); outline: none; background: var(--bg); }
.dtable input.bad { border-color: var(--err); background: color-mix(in srgb, var(--err) 8%, transparent); }
.dtable input.num { text-align: right; }
.dtable td.act { width: 28px; text-align: center; }
.dtable .del { all: unset; cursor: pointer; color: var(--muted); padding: 0 6px; border-radius: 4px; }
.dtable .del:hover { color: var(--err); background: var(--row-alt); }
.dtable tr.file td { color: var(--muted); padding: 4px 8px; }
.dtable tr.file td.src { font: 11px system-ui, sans-serif; }
.dfoot { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; align-items: center; }
.dfoot .msg { color: var(--err); font-size: 12px; }
.dpaste { padding: 0 12px 10px; }
.dpaste textarea { width: 100%; min-height: 90px; font: 13px var(--mono); color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.dempty { color: var(--muted); padding: 24px 4px; }

.editor { flex: 1; min-height: 0; display: flex; background: var(--panel); }

.gutter {
  flex: none;
  width: 3.6em;
  overflow: hidden;
  padding: 8px 8px 8px 0;
  text-align: right;
  color: var(--muted);
  font: var(--code-size)/var(--code-line) var(--mono);
  border-right: 1px solid var(--line);
  user-select: none;
}
.gutter div { height: var(--code-line); }
.gutter .g-error { color: var(--err); font-weight: 700; }
.gutter .g-warning { color: var(--warn); font-weight: 700; }

.code { position: relative; flex: 1; min-width: 0; }

.hl, #src {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  font: var(--code-size)/var(--code-line) var(--mono);
  white-space: pre;
  tab-size: 4;
  letter-spacing: normal;
}

.hl { overflow: hidden; pointer-events: none; color: var(--fg); }

#src {
  overflow: auto;
  resize: none;
  outline: none;
  background: transparent;
  color: transparent;
  caret-color: var(--fg);
}
#src::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: transparent; }

.hl .k { color: var(--kw); font-weight: 600; }
.hl .v { color: var(--var); }
.hl .s { color: var(--str); }
.hl .n { color: var(--num); }
.hl .c { color: var(--cmt); font-style: italic; }
.hl .b { color: var(--builtin); }
.hl .af { color: var(--full); font-weight: 700; }
.hl .ap { color: var(--partial); font-weight: 700; }
.hl .neg { color: var(--err); font-weight: 700; }
.hl .op { color: var(--muted); font-weight: 700; }
.hl .sq-error { text-decoration: underline wavy var(--err); text-decoration-skip-ink: none; }
.hl .sq-warning { text-decoration: underline wavy var(--warn); text-decoration-skip-ink: none; }
.hl .sq-note { text-decoration: underline dotted var(--note); text-decoration-skip-ink: none; }
.gutter .g-note { color: var(--note); }
.diags .d-note .sev { color: var(--note); }

.models {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.models .label { color: var(--muted); margin-right: 4px; }
.models button {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 9px;
  cursor: pointer;
}
.models button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs button.answer { color: var(--accent); font-weight: 600; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }
.views { display: flex; gap: 4px; padding: 8px 16px 0; }
.views button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 4px 10px;
  cursor: pointer;
}
.views button.active { color: var(--fg); border-bottom-color: var(--accent); }
tr.why { cursor: pointer; }
tr.why:hover td { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.graph-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.graph-bar select, .graph-bar button {
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
}
.graph-bar button { cursor: pointer; }
.graph-note { color: var(--muted); font-size: 13px; }
.graph-wrap { flex: 1; min-height: 0; overflow: auto; background: var(--panel); padding: 8px; }
.graph-wrap svg { display: block; max-width: none; }

/* Picture: the result drawn as the problem looks, played as an animation */
.picture-bar input[type="range"] { flex: 1; min-width: 80px; accent-color: var(--accent); }
.picture-bar .play { min-width: 5.5em; }
.picture-wrap { flex: 1; min-height: 0; position: relative; background: var(--panel); }
.picture-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.picture-wrap .note { position: absolute; inset: 0; }

.dlq-graph .g-node .shape { fill: var(--panel); stroke: var(--muted); stroke-width: 1.2; }
.dlq-graph .g-grp0 .shape { fill: color-mix(in srgb, #4f7cff 13%, var(--panel)); }
.dlq-graph .g-grp1 .shape { fill: color-mix(in srgb, #2e9d4f 13%, var(--panel)); }
.dlq-graph .g-grp2 .shape { fill: color-mix(in srgb, #e08a00 14%, var(--panel)); }
.dlq-graph .g-grp3 .shape { fill: color-mix(in srgb, #9b4fd1 13%, var(--panel)); }
.dlq-graph .g-grp4 .shape { fill: color-mix(in srgb, #12a3a3 13%, var(--panel)); }
.dlq-graph .g-grp5 .shape { fill: color-mix(in srgb, #d1495b 13%, var(--panel)); }
.dlq-graph .g-node.ext .shape { fill: var(--row-alt); }
.dlq-graph .g-node.rule .shape { fill: color-mix(in srgb, var(--kw) 12%, var(--panel)); }
.dlq-graph .g-node.attr .shape { fill: color-mix(in srgb, var(--warn) 10%, var(--panel)); }
.dlq-graph .g-node.agg .shape { fill: color-mix(in srgb, var(--kw) 12%, var(--panel)); }
.dlq-graph .g-node.fterm .shape { stroke: var(--fg); stroke-width: 3; }
.dlq-graph .g-node.fresh .shape { stroke-dasharray: 4 3; }
.dlq-graph .g-node.target .shape { stroke: var(--accent); stroke-width: 2.5; }
.dlq-graph .g-node text { font: 12px system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--fg); }
.dlq-graph .g-node text.sub { fill: var(--muted); font-size: 11px; }
.dlq-graph .g-node[data-line], .dlq-graph .g-node[data-fact] { cursor: pointer; }
.dlq-graph .g-node[data-line]:hover .shape, .dlq-graph .g-node[data-fact]:hover .shape { stroke: var(--accent); stroke-width: 2; }
.dlq-graph .g-edge path { fill: none; stroke: var(--muted); stroke-width: 1.2; }
/* A halo in the background colour: an edge that passes near a label breaks around it. */
.dlq-graph .g-edge text { font: 11px system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--muted); paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
.dlq-graph .g-edge.partial path { stroke: var(--partial); stroke-dasharray: 5 3; }
.dlq-graph .g-edge.partial text { fill: var(--partial); }
.dlq-graph .g-edge.full path { stroke: var(--full); }
.dlq-graph .g-edge.full text { fill: var(--full); }
.dlq-graph .g-edge.cyclic path { stroke: var(--err); stroke-width: 2.2; }
.dlq-graph .g-edge.cyclic text { fill: var(--err); }
.dlq-graph .g-edge.agg path { stroke: var(--kw); }
.dlq-graph .g-edge.agg text { fill: var(--kw); }
.dlq-graph .g-edge.fterm path { stroke: var(--fg); stroke-width: 3; }
.dlq-graph .g-edge.f path { stroke-dasharray: 5 3; }
.dlq-graph .g-arrow { fill: var(--muted); }
.dlq-graph .g-arrow.partial { fill: var(--partial); }
.dlq-graph .g-arrow.full { fill: var(--full); }
.dlq-graph .g-arrow.cyclic { fill: var(--err); }
.dlq-graph .g-arrow.agg { fill: var(--kw); }
.dlq-graph .g-arrow.fterm { fill: var(--fg); }

.diags {
  flex: none;
  max-height: 32%;
  overflow: auto;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 13px;
}
.diags li { padding: 3px 12px; cursor: pointer; }
.diags li:hover { background: var(--row-alt); }
.diags .loc { font-family: var(--mono); color: var(--muted); margin-right: 6px; }
.diags .sev { font-weight: 600; margin-right: 6px; }
.diags .d-error .sev { color: var(--err); }
.diags .d-warning .sev { color: var(--warn); }

.summary { padding: 10px 16px; border-bottom: 1px solid var(--line); color: var(--muted); }
.summary strong { color: var(--fg); }
.summary .stopped { color: var(--warn); display: block; margin-top: 4px; }
.summary .strata { font-family: var(--mono); font-size: 13px; }

.violations { margin: 0; padding: 8px 16px 8px 32px; border-bottom: 1px solid var(--line); color: var(--err); }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 16px 0;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 4px 10px;
  cursor: pointer;
}
.tabs button.active { color: var(--fg); background: var(--panel); border-color: var(--line); margin-bottom: -1px; }
.tabs button .count { color: var(--muted); margin-left: 4px; }
.tabs button.ext { font-style: italic; }

.table-wrap { flex: 1; min-height: 0; overflow: auto; background: var(--panel); }

table { border-collapse: collapse; font: 13px/1.4 var(--mono); min-width: 100%; }
th, td { padding: 3px 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
td.step, th.step { color: var(--muted); text-align: right; }
tbody tr:nth-child(even) { background: var(--row-alt); }
.note { padding: 8px 16px; color: var(--muted); }

@media (max-width: 860px) {
  .split { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .divider { display: none; }
  .editor-pane { border-bottom: 1px solid var(--line); }
  .bar { padding: 8px 16px; }
  .status { margin-left: 0; width: 100%; }
}

/* Phones: one column the page scrolls through - the editor most of a screen
   high, the result below it - instead of two half-screen panes each with its
   own scroll areas; the toolbar packs into two rows. */
@media (max-width: 600px) {
  :root { --code-size: 13px; --code-line: 19px; }
  html, body { height: auto; }
  body { display: block; }

  .bar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand examples mode"
      "limit limit run"
      "data data export"
      "status status gh";
    gap: 8px;
    padding: 8px 12px;
  }
  .sub { display: none; }
  .brand { grid-area: brand; }
  #examples { grid-area: examples; width: 100%; }
  #mode { grid-area: mode; }
  .limit { grid-area: limit; }
  .limit input { width: 6em; }
  #run { grid-area: run; padding: 6px 22px; }
  .data { grid-area: data; }
  .menu-wrap { grid-area: export; justify-self: end; }
  .status { grid-area: status; font-size: 12px; }
  .bar .gh { grid-area: gh; justify-self: end; }
  .bar select, .bar input, .bar button { padding: 6px 8px; }

  .split { display: block; }
  .editor-pane { height: 64vh; height: 64svh; min-height: 320px; border-bottom: 1px solid var(--line); }
  .diags { max-height: 30%; }
  .views { padding: 6px 12px 0; }
  .summary, .table-bar, .models, .graph-bar { padding-left: 12px; padding-right: 12px; }
  .tabs { padding: 8px 12px 0; }
  .table-wrap { max-height: 70vh; max-height: 70svh; }
  .graph-wrap { height: 70vh; height: 70svh; flex: none; }
  .picture-wrap { height: 60vh; height: 60svh; flex: none; }
  .data-hint { padding: 8px 12px; }
  .data-wrap { padding: 10px 12px 20px; }
  th, td { padding: 3px 8px; }
}
