:root {
  color-scheme: light dark;

  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --code: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* Interface */
  --bg: #f3f4f6;
  --panel: #ffffff;
  --hover: #eceef1;
  --line: #dfe2e6;
  --line-strong: #c5cad1;
  --text: #1c1f24;
  --muted: #626a75;
  --accent: #cc0000;
  --accent-hover: #a80000;
  --accent-soft: rgba(204, 0, 0, 0.07);
  --on-accent: #ffffff;
  --error: #b42318;
  --shadow: rgba(16, 24, 40, 0.12);
  --backdrop: rgba(16, 24, 40, 0.35);
  --accent-text: #cc0000;
  --overlay: rgba(255, 255, 255, 0.72);
  --segment-track: #e6e8ec;
  --segment-selected: #ffffff;
  --highlight: rgba(204, 0, 0, 0.16);

  /* RDF terms */
  --term-uri: var(--text);
  --term-literal: #2b62b8;
  --term-bnode: var(--muted);

  /* Graph */
  --graph-1: #cc0000;
  --graph-2: #2f6fde;
  --graph-3: #1f9e74;
  --graph-4: #d98e04;
  --graph-5: #8e5cd9;
  --graph-6: #c2417a;
  --graph-7: #0f8fb3;
  --graph-8: #6b7a2a;
  --graph-untyped: #8a919c;
  --graph-edge: #a3a9b2;
  --graph-faded: #dde0e4;
  --graph-label: var(--text);
  --graph-hover-bg: var(--panel);
  --graph-hover-text: var(--text);
  --graph-hover-border: var(--line-strong);

  /* Editor: Tokyo Night, as in the motion-spec dashboard */
  --editor-bg: #1a1b26;
  --editor-panel: #16161e;
  --editor-text: #c0caf5;
  --editor-dim: #a9b1d6;
  --editor-gutter: #3b4261;
  --editor-selection: #33467c;
  --editor-active-line: rgba(255, 255, 255, 0.04);
  --editor-error-line: rgba(247, 118, 142, 0.16);
  --syntax-comment: #565f89;
  --syntax-keyword: #bb9af7;
  --syntax-string: #9ece6a;
  --syntax-number: #ff9e64;
  --syntax-type: #2ac3de;
  --syntax-property: #7aa2f7;
  --syntax-operator: #89ddff;
  --syntax-invalid: #f7768e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #16191e;
    --hover: #1f242b;
    --line: #2a2f37;
    --line-strong: #3a414b;
    --text: #e4e6ea;
    --muted: #9aa1ab;
    --accent-soft: rgba(255, 90, 90, 0.1);
    --error: #ff8a80;
    --shadow: rgba(0, 0, 0, 0.45);
    --backdrop: rgba(0, 0, 0, 0.6);
    --accent-text: #ff7a7a;
    --overlay: rgba(15, 17, 21, 0.72);
    --segment-track: #0b0d10;
    --segment-selected: #2c323b;
    --highlight: rgba(255, 110, 110, 0.28);
    --term-literal: #7aaaf0;
    --graph-2: #5b8ef0;
    --graph-3: #3cc093;
    --graph-4: #f0a92a;
    --graph-5: #a983ec;
    --graph-6: #e0679c;
    --graph-7: #33b3d6;
    --graph-8: #9aab4a;
    --graph-untyped: #7c838e;
    --graph-edge: #5c636e;
    --graph-faded: #2a2f37;
  }
}

* {
  box-sizing: border-box;
}

/* Elements given a display of their own would otherwise ignore the hidden attribute. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--ui);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

/* Header */

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

.bar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.bar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* Layout */

.workbench {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 0;
}

.work {
  display: grid;
  grid-template-rows: var(--editor-height, 50%) 6px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

/* File tree */

.files {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 8px 12px;
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.files-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 8px;
}

.files-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.files-actions {
  display: flex;
  gap: 2px;
}

/* Set here, not only in the sprite: <use> copies just the symbol, not the sprite root's attributes. */
.icon {
  flex: none;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
}

.icon-button:hover:not(:disabled) {
  color: var(--text);
  background: var(--hover);
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.file-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.file-list li {
  display: flex;
  align-items: center;
  border-radius: 6px;
}

/* Each level of folder nesting indents the row. */
#file-list li {
  padding-left: calc(var(--depth, 0) * 14px);
}

/* The list takes the panel's free space, so dropping anywhere below the rows means the top level. */
#file-list {
  flex: 1 0 auto;
  min-height: 48px;
  border-radius: 6px;
}

.root-drop {
  display: none !important;
  gap: 8px;
  margin-bottom: 4px;
  padding: 6px 8px !important;
  color: var(--muted);
  font-size: 12.5px;
  border: 1px dashed var(--line-strong);
}

.root-drop .icon {
  width: 14px;
  height: 14px;
}

#file-list.dragging .root-drop {
  display: flex !important;
}

#file-list.drop-target,
.file-list li.drop-target {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.file-list li.folder-row.selected {
  background: var(--hover);
}

.folder-chevron {
  display: grid;
  flex: none;
  place-items: center;
  width: 14px;
  color: var(--muted);
}

.folder-chevron .icon {
  width: 13px;
  height: 13px;
  transition: transform 0.12s ease;
}

.folder[aria-expanded="true"] .folder-chevron .icon {
  transform: rotate(90deg);
}

.folder > .icon {
  width: 15px;
  height: 15px;
  color: var(--muted);
}

.folder .name {
  font-family: var(--ui);
  font-weight: 500;
}

.tab-folder {
  margin-left: 6px;
  color: var(--editor-gutter);
  font-size: 11.5px;
}

.file-list li:hover {
  background: var(--hover);
}

.file-list li.active {
  background: var(--accent-soft);
}

.file-list .file {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px 4px 5px 8px;
  text-align: left;
  background: none;
  border: 0;
}

/* Rows are the draggable items: no text selection to compete with the drag. */
#file-list li[role="treeitem"] {
  cursor: pointer;
  user-select: none;
}

#file-list li[role="treeitem"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

#file-list li[draggable="true"]:active {
  cursor: grabbing;
}

.file-list .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 13px var(--code);
}

.file-list .server-only .name {
  color: var(--muted);
  font-style: italic;
}

.file-list .dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text);
}

.file-list .count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* In the dataset: a database icon before the name. The slot is kept empty otherwise, so names line up. */
.loaded-marker {
  display: grid;
  flex: none;
  place-items: center;
  width: 14px;
  color: var(--accent-text);
}

.loaded-marker .icon {
  width: 14px;
  height: 14px;
}

.file-list .not-loaded .name {
  color: var(--muted);
}

.file-actions {
  display: flex;
  flex: none;
  opacity: 0;
}

.file-list li:hover .file-actions,
.file-actions:focus-within {
  opacity: 1;
}

.file-actions button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
}

.file-actions .icon {
  width: 14px;
  height: 14px;
}

.file-actions button:hover {
  color: var(--text);
  background: var(--line);
}

/* Run is the one action drawn solid, in the accent colour, everywhere it appears. */
.icon use[href$="#play"] {
  fill: currentColor;
}

.file-actions .run-action,
.file-actions .run-action:hover {
  color: var(--accent-text);
}

.file-actions button:last-child:hover {
  color: var(--accent);
}

.file-list .empty {
  padding: 4px 8px;
  color: var(--muted);
  font-size: 13px;
}

.file-list li:has(.name-input) {
  flex-direction: column;
  align-items: stretch;
  margin: 4px 0;
  padding-right: 4px;
}

.file-list li:has(.name-input):hover {
  background: none;
}

.name-input {
  width: 100%;
  padding: 4px 6px;
  font: 13px var(--code);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 5px;
}

.name-input:focus-visible {
  outline: none;
}

.name-error {
  padding: 2px 4px 0;
  color: var(--error);
  font-size: 12px;
}

.name-error:empty {
  display: none;
}

.name-hint {
  padding: 4px 4px 0;
  color: var(--muted);
  font: 11.5px/1.5 var(--code);
  white-space: pre-line;
}

.examples summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  list-style: none;
}

.examples summary::-webkit-details-marker {
  display: none;
}

.examples summary:hover {
  color: var(--text);
  background: var(--hover);
}

.examples .chevron {
  width: 14px;
  height: 14px;
  transition: transform 0.12s ease;
}

.examples[open] .chevron {
  transform: rotate(90deg);
}

.examples .file-list {
  padding-left: 18px;
}

.drop {
  position: relative;
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 10px;
  cursor: pointer;
}

.drop strong {
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
}

.drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.drop input:focus-visible {
  outline: none;
}

/* Hover, a drag over it, and keyboard focus all show the same way: the dashed border turns red. */
.drop:hover,
.drop.over,
.drop:has(input:focus-visible) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Editor groups and their tabs */

.editors {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  background: var(--editor-bg);
}

.editors.is-split {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.group {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.editors.is-split .group + .group {
  border-left: 1px solid var(--editor-gutter);
}

/* The bar ends in a hairline; the open tab covers it, so the tab and its code read as one surface. */
.group-bar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
  background: var(--editor-panel);
  box-shadow: inset 0 -1px 0 var(--editor-gutter);
}

.tabs {
  display: flex;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  display: flex;
  align-items: center;
}

.tab:hover:not([aria-selected="true"]) {
  background: var(--editor-bg);
}

.tab[aria-selected="true"] {
  background: var(--editor-bg);
  box-shadow:
    inset 1px 0 0 var(--editor-gutter),
    inset -1px 0 0 var(--editor-gutter),
    inset 0 1px 0 var(--editor-gutter);
}

.tab-name {
  padding: 0 4px 0 12px;
  height: 100%;
  font: 12.5px var(--code);
  white-space: nowrap;
  color: var(--editor-dim);
  background: none;
  border: 0;
}

.tab[aria-selected="true"] .tab-name {
  color: var(--editor-text);
}

/* In a split, the side not being worked in is dimmed until clicked into. */
.editors.is-split .group:not(.focused) .tabs,
.editors.is-split .group:not(.focused) .editor-host {
  opacity: 0.55;
  transition: opacity 0.12s ease;
}

/* The close button doubles as the unsaved dot, as in most editors: dot at rest, x on hover. */
.tab-close {
  position: relative;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 6px;
  padding: 0;
  color: var(--editor-dim);
  background: none;
  border: 0;
  border-radius: 5px;
}

.tab-close .icon {
  width: 14px;
  height: 14px;
  visibility: hidden;
}

.tab:hover .tab-close .icon,
.tab[aria-selected="true"]:not(.dirty) .tab-close .icon,
.tab-close:focus-visible .icon {
  visibility: visible;
}

.tab.dirty .tab-close::before {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--editor-text);
}

.tab.dirty:hover .tab-close::before,
.tab.dirty .tab-close:focus-visible::before {
  display: none;
}

.tab-close:hover {
  color: var(--editor-text);
  background: var(--editor-gutter);
}

.group-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
}

.group-actions .ghost {
  color: var(--editor-dim);
  border-color: var(--editor-gutter);
}

.group-actions .ghost:hover:not(:disabled) {
  color: var(--editor-text);
  border-color: var(--editor-dim);
}

.group-actions .ghost:disabled {
  opacity: 0.4;
  cursor: default;
}

.group-actions .icon-button {
  color: var(--editor-dim);
}

.group-actions .icon-button:hover {
  color: var(--editor-text);
  background: var(--editor-gutter);
}

.editor-host {
  min-height: 0;
  overflow: hidden;
}

.editor-host .cm-editor {
  height: 100%;
}

.placeholder {
  margin: 0;
  padding: 24px;
  color: var(--editor-dim);
}

.primary,
.ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.primary .icon,
.ghost .icon {
  width: 14px;
  height: 14px;
}

.primary {
  padding: 5px 14px;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border: 0;
  border-radius: 7px;
}

.primary:hover {
  background: var(--accent-hover);
}

.ghost {
  padding: 5px 10px;
  font-size: 13px;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
}

.ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.splitter {
  cursor: row-resize;
  background: var(--line);
}

.splitter:hover,
.splitter:focus-visible {
  background: var(--accent);
  outline: none;
}

/* Results */

.results {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  background: var(--panel);
}

.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

.view-tabs {
  display: flex;
  padding: 3px;
  background: var(--segment-track);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.view-tabs button {
  padding: 4px 14px;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
}

.view-tabs button:hover:not(:disabled):not([aria-selected="true"]) {
  color: var(--text);
}

.view-tabs button[aria-selected="true"] {
  font-weight: 600;
  color: var(--accent-text);
  background: var(--segment-selected);
  box-shadow: 0 1px 3px var(--shadow);
}

.view-tabs button:disabled {
  cursor: default;
  opacity: 0.45;
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  white-space: pre-wrap;
}

.status.error {
  color: var(--error);
  font-family: var(--code);
  font-size: 12.5px;
}

.view {
  min-height: 0;
  overflow: auto;
}

.view .empty {
  margin: 0;
  padding: 24px;
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  font: 12.5px/1.4 var(--code);
}

th,
td {
  padding: 5px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

th {
  position: sticky;
  top: 0;
  font: 600 12px var(--ui);
  color: var(--muted);
  background: var(--panel);
}

/* Results table */

.table-view {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.table-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.table-search {
  display: flex;
  align-items: center;
  gap: 2px;
  width: min(380px, 100%);
  padding: 0 4px 0 8px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
}

.table-search:focus-within {
  border-color: var(--accent);
}

.table-search input {
  flex: 1;
  min-width: 0;
  padding: 5px 4px;
  font: 13px var(--ui);
  color: var(--text);
  background: none;
  border: 0;
}

.table-search input:focus-visible {
  outline: none;
}

.table-search:has(input[aria-invalid="true"]) {
  border-color: var(--error);
}

.tool {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 5px;
}

.tool .icon {
  width: 15px;
  height: 15px;
}

.tool:hover {
  color: var(--text);
  background: var(--hover);
}

.tool[aria-pressed="true"] {
  color: var(--accent-text);
  background: var(--accent-soft);
}

.table-count {
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* The small outlined button for secondary text actions: Clear filters, Show/Hide all, Select/Clear shown. */
.ghost.small {
  flex: none;
  gap: 4px;
  padding: 2px 8px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  border-radius: 6px;
}

.ghost.small .icon {
  width: 13px;
  height: 13px;
}

.ghost.small:hover {
  color: var(--accent-text);
  border-color: var(--accent);
}

.table-tools .spacer {
  flex: 1;
}

.table-scroll {
  min-height: 0;
  overflow: auto;
}

table.grid {
  table-layout: fixed;
}

.grid td {
  height: 28px;
  padding: 0 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.grid tr.spacer-row td {
  padding: 0;
  border: 0;
}

.grid tbody tr:not(.spacer-row):hover td {
  background: var(--hover);
}

.grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 32px;
  padding: 0 4px 0 12px;
  white-space: nowrap;
}

.grid th > * {
  vertical-align: middle;
}

.column-name {
  display: inline-block;
  max-width: calc(100% - 34px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.column-filter {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-left: 4px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 5px;
  opacity: 0.55;
}

.grid th:hover .column-filter,
.column-filter:focus-visible,
.column-filter[aria-expanded="true"] {
  opacity: 1;
}

.column-filter .icon {
  width: 13px;
  height: 13px;
}

.column-filter:hover {
  color: var(--text);
  background: var(--hover);
}

.column-filter.active {
  color: var(--accent-text);
  background: var(--accent-soft);
  opacity: 1;
}

.column-resize {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
}

.column-resize:hover {
  background: var(--accent);
}

mark {
  color: inherit;
  background: var(--highlight);
  border-radius: 2px;
}

.table-scroll > .empty {
  margin: 0;
  padding: 24px;
  color: var(--muted);
}

/* Column filter panel */

.facet {
  position: absolute;
  z-index: 5;
  display: grid;
  gap: 12px;
  width: 300px;
  max-height: calc(100% - 16px);
  padding: 12px;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px var(--shadow);
}

.facet section,
.facet fieldset {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

.facet h3,
.facet legend {
  margin: 0 0 2px;
  padding: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.facet input[type="search"] {
  width: 100%;
  padding: 5px 8px;
  font: 13px var(--ui);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.facet input[type="search"]:focus-visible {
  outline: none;
  border-color: var(--accent);
}

.facet-values {
  max-height: 220px;
  overflow: auto;
}

.facet-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  font-size: 12.5px;
  border-radius: 5px;
  cursor: pointer;
}

.facet-option:hover {
  background: var(--hover);
}

.facet-option input {
  margin: 0;
  accent-color: var(--accent);
}

.facet-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--code);
}

.facet-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.facet-bulk {
  display: flex;
  gap: 12px;
}

.facet-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.facet-note:empty {
  display: none;
}

.facet-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

td.uri {
  color: var(--term-uri);
}

td.literal {
  color: var(--term-literal);
}

td.bnode {
  color: var(--term-bnode);
}

/* Graph */

.graph-view {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.graph-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.graph-canvas {
  position: absolute;
  inset: 0;
}

/* In place of a graph: why there is none for the current results. */
.graph-message {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 24px;
  color: var(--muted);
  background: var(--panel);
}

.search-count {
  padding-right: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.tool-divider {
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--line);
}

.legend {
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 260px;
  max-width: calc(100% - 20px);
  padding: 8px 6px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow);
}

.legend > input[type="search"] {
  flex: none;
  padding: 5px 8px;
  font: 12.5px var(--ui);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.legend > input[type="search"]:focus-visible {
  outline: none;
  border-color: var(--accent);
}

/* Open sections share the height; each list scrolls on its own. */
.legend-sections {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.legend-section {
  display: flex;
  flex: none;
  flex-direction: column;
  min-height: 0;
}

/* Open sections split the height evenly; a closed one keeps just its header. */
.legend-section.open {
  flex: 1 1 0;
}

.legend-header {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  padding-right: 4px;
}

.legend-toggle {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: left;
  background: none;
  border: 0;
  border-radius: 5px;
}

.legend-toggle:hover {
  color: var(--text);
  background: var(--hover);
}

.legend-toggle .icon {
  width: 13px;
  height: 13px;
  transition: transform 0.12s ease;
}

.legend-toggle[aria-expanded="true"] .icon {
  transform: rotate(90deg);
}

.legend-toggle .count {
  font-weight: 400;
}

.legend-header .ghost.small {
  padding: 1px 6px;
  font-size: 11.5px;
}

.legend-list {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 3px 8px;
  font: 12px var(--code);
  text-align: left;
  background: none;
  border: 0;
  border-radius: 5px;
}

.legend-item .count {
  flex: none;
}

.legend-item:hover {
  background: var(--hover);
}

.legend-item[aria-pressed="false"] {
  opacity: 0.4;
}

.legend-item[aria-pressed="false"] .legend-name {
  text-decoration: line-through;
}

.legend-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend .swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend .count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.legend-empty {
  margin: 0;
  padding: 2px 8px;
  color: var(--muted);
  font-size: 12px;
}

.inspector {
  position: absolute;
  top: 10px;
  right: 10px;
  bottom: 10px;
  width: min(340px, 45%);
  padding: 14px;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px var(--shadow);
}

.inspector h3 {
  margin: 0 28px 12px 0;
  font: 600 13px var(--code);
  word-break: break-all;
}

.inspector .close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
}

.inspector .close:hover {
  color: var(--accent);
  background: var(--hover);
}

.inspector dl {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: 5px 12px;
  margin: 0;
  font: 12px/1.4 var(--code);
}

.inspector dt {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  color: var(--muted);
}

.inspector dt .icon {
  width: 12px;
  height: 12px;
  margin-top: 2px;
}

.inspector dd {
  margin: 0;
  word-break: break-all;
}

.inspector-link {
  padding: 0;
  font: inherit;
  text-align: left;
  color: var(--accent-text);
  background: none;
  border: 0;
  word-break: break-all;
}

.inspector-link:hover {
  text-decoration: underline;
}

.focus-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.view-tabs.small button {
  padding: 2px 9px;
  font-size: 12px;
}

.inspector dd.literal {
  color: var(--term-literal);
}

/* Loading: one overlay, placed over whichever region is busy */

.files,
.results {
  position: relative;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  background: var(--overlay);
  backdrop-filter: blur(1px);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

/* Dialogs */

.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 48px var(--shadow);
}

.dialog::backdrop {
  background: var(--backdrop);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 650;
  word-break: break-all;
}

.dialog p {
  margin: 0 0 20px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Narrow screens: files above the work area, split editors stacked */

@media (max-width: 820px) {
  body {
    height: auto;
  }

  .workbench {
    grid-template-columns: 1fr;
  }

  .files {
    max-height: 40vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .work {
    grid-template-rows: 60vh 6px 60vh;
  }

  .editors.is-split {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: minmax(0, 1fr);
  }

  .editors.is-split .group + .group {
    border-left: 0;
    border-top: 1px solid var(--editor-gutter);
  }
}
