:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #d9dde3;
  --text: #1d2330;
  --muted: #6b7484;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --error: #b3261e;
  --warning: #8a5a00;
  --desk: #e7eaee;
  --active-line: rgb(47 111 79 / 6%);
  --selection: rgb(47 111 79 / 20%);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --split: 45%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181d;
    --panel: #1c2027;
    --border: #2e343e;
    --text: #e3e6eb;
    --muted: #8d96a5;
    --accent: #4f9f74;
    --error: #ff8a80;
    --warning: #e0b45c;
    --desk: #101317;
    --active-line: rgb(255 255 255 / 4%);
    --selection: rgb(79 159 116 / 30%);
  }
}

* { box-sizing: border-box; }

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

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

a { color: inherit; }

.muted { color: var(--muted); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.masthead {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
  text-decoration: none;
}

.brand img { border-radius: 6px; }

.masthead nav {
  display: flex;
  gap: 16px;
  margin-left: auto;
}

.masthead nav a {
  color: var(--muted);
  text-decoration: none;
}

.masthead nav a:hover { color: var(--text); }

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

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.divider {
  cursor: col-resize;
  background: var(--border);
  border-left: 2px solid var(--bg);
  border-right: 2px solid var(--bg);
}

.divider:hover, .divider:focus-visible, .divider.dragging { background: var(--accent); }

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 44px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.spacer { flex: 1; }

button, select {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:has(.icon) {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.icon {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button:hover:not(:disabled), select:hover { border-color: var(--muted); }

button:disabled { opacity: 0.45; cursor: default; }

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.group { display: inline-flex; }
.group button { border-radius: 0; margin-left: -1px; }
.group button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.group button:last-child { border-radius: 0 6px 6px 0; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  user-select: none;
}

.status {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status.error { color: var(--error); }

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

.editor .cm-editor {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
}

.editor .cm-editor.cm-focused { outline: none; }

.editor .cm-scroller {
  font-family: var(--mono);
  line-height: 20px;
}

.editor .cm-content { padding: 10px 0; caret-color: var(--text); }

.editor .cm-cursor { border-left-color: var(--text); }

.editor .cm-gutters {
  border-right: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
}

.editor .cm-lineNumbers .cm-gutterElement { padding: 0 8px 0 14px; }

.editor .cm-activeLine { background: var(--active-line); }
.editor .cm-activeLineGutter { background: var(--active-line); color: var(--text); }

.editor .cm-selectionBackground,
.editor .cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground,
.editor .cm-content ::selection { background: var(--selection) !important; }

.editor .cm-matchingBracket {
  background: var(--selection);
  outline: 1px solid var(--muted);
}

.editor .cm-panels {
  border-color: var(--border);
  background: var(--bg);
  color: var(--text);
}

.editor .cm-tooltip {
  border-color: var(--border);
  background: var(--panel);
  color: var(--text);
}

.editor .cm-tooltip-autocomplete > ul > li[aria-selected] {
  background: var(--accent);
  color: var(--accent-text);
}


.log {
  height: 30%;
  min-height: 60px;
  overflow: auto;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font: 12px/18px var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.log .line.error { color: var(--error); }
.log .line.warning { color: var(--warning); }
.log .line.progress { color: var(--muted); }

.log a {
  cursor: pointer;
  text-decoration: underline dotted;
}

.pages {
  flex: 1;
  overflow: auto;
  padding: 18px;
  background: var(--desk);
  --zoom: 1;
}

.pages.stale .page { opacity: 0.55; }

.page {
  position: relative;
  width: fit-content;
  margin: 0 auto 18px;
  background: #ffffff;
  color: #000000;
  box-shadow: 0 1px 3px rgb(0 0 0 / 25%), 0 6px 18px rgb(0 0 0 / 8%);
  transition: opacity 0.15s;
}

.page svg { display: block; }

.page.cropped { padding: 16px; }

.page .page-download {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgb(0 0 0 / 60%);
  color: #ffffff;
  font-size: 12px;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.page:hover .page-download { opacity: 1; }

.placeholder {
  margin-top: 15vh;
  color: var(--muted);
  text-align: center;
}

/* LilyTub measures generic text families with LilyPond's own fonts, which
   the page loads from the data bundle; the SVG must be drawn with them. */
.page text[font-family="serif"] { font-family: "C059", serif; }
.page text[font-family="sans"],
.page text[font-family="sans-serif"] { font-family: "Nimbus Sans", sans-serif; }
.page text[font-family="typewriter"],
.page text[font-family="mono"],
.page text[font-family="monospace"] { font-family: "Nimbus Mono PS", monospace; }

@media (max-width: 760px) {
  .split {
    grid-template-columns: 1fr;
    grid-template-rows: 55vh auto;
    overflow: auto;
  }

  .divider { display: none; }

  .preview-pane { min-height: 70vh; }

  .masthead nav a:first-child { display: none; }
}
