:root {
  --bg: #fff;
  --fg: #000;
  --muted: #6b6b6b;
  --line: #e3e3e3;
  --accent: #2383e2;
  --warn: #b35900;
  --playing: #2383e2;
  color-scheme: light;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

html.transparent, html.transparent body { background: transparent; }

/* --- view --------------------------------------------------------------- */

#view { padding: 4px; }

#paper { width: 100%; }

#audio { max-width: 480px; margin-top: 4px; }
#audio[hidden] { display: none; }

#empty { color: var(--muted); margin: 8px; }
#empty a { color: var(--accent); }

/* Currently sounding notes during playback. */
.abc-playing { fill: var(--playing); }

/* Make the abcjs synth control blend in rather than look like a widget. */
.abcjs-inline-audio {
  height: 28px;
  padding: 0 4px;
  border-radius: 6px;
  background: #f1f1ef;
  color: #37352f;
}
.abcjs-inline-audio .abcjs-btn g { fill: #37352f; stroke: #37352f; }
.abcjs-inline-audio .abcjs-btn:hover g { fill: var(--accent); stroke: var(--accent); }
.abcjs-inline-audio .abcjs-midi-clock { color: #37352f; }
.abcjs-inline-audio .abcjs-midi-progress-background { background-color: #d9d9d6; }
.abcjs-inline-audio .abcjs-midi-progress-indicator { background-color: #37352f; }

/* --- editor ------------------------------------------------------------- */

html.editing, html.editing body { height: 100%; background: #f7f7f5; }

#editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  padding: 10px 12px;
  box-sizing: border-box;
}
#editor[hidden] { display: none; }
#editor.dropping { outline: 3px dashed var(--accent); outline-offset: -6px; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.row label { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.spacer { flex: 1; }

#editor input, #editor select, #editor button { font: inherit; }
#editor input:not([type="checkbox"]), #editor select {
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}
#editor input[type="number"] { width: 4.5em; }
.meta .title { font-weight: 600; width: 14em; }

#editor button {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--fg);
  cursor: pointer;
  line-height: 1.2;
}
#editor button:hover { border-color: #c9c9c6; background: #fbfbfa; }
#editor button:disabled { opacity: 0.4; cursor: default; }
#editor button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#editor button.quiet { border-color: transparent; background: transparent; color: #37352f; }
#editor button.quiet:hover { background: #ebebea; }
#editor button.quiet[aria-pressed="true"] { background: #e0e0de; color: #37352f; }
#editor button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.work { flex: 1; display: flex; gap: 10px; min-height: 180px; }

#preview-frame {
  position: relative;
  flex: 3;
  min-width: 0;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
/* Checkerboard so a transparent embed is visibly transparent. */
#preview-frame.transparent {
  background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0 / 16px 16px;
}
#preview-paper svg { cursor: pointer; }
#preview-paper svg:focus, #preview-paper svg *:focus { outline: none; }
#preview-audio { max-width: 480px; margin-top: 6px; }
#preview-audio[hidden] { display: none; }

#caret {
  position: absolute;
  width: 2px;
  background: var(--accent);
  border-radius: 1px;
  pointer-events: none;
  animation: blink 1.1s steps(2, start) infinite;
}
#caret[hidden] { display: none; }
@keyframes blink { to { visibility: hidden; } }

#save-state { color: var(--muted); font-size: 12px; white-space: nowrap; }
#save-state.error { color: #c4291c; }

/* Saved tunes */
#library {
  flex: 0 0 230px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}
#library[hidden] { display: none; }
#lib-filter { width: 100%; box-sizing: border-box; }
#lib-list { flex: 1; overflow: auto; margin: 0; padding: 0; list-style: none; }
#lib-list li { display: flex; align-items: stretch; border-radius: 6px; }
#lib-list li:hover { background: #ebebea; }
#editor .lib-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  text-align: left;
}
#editor .lib-open:hover { background: transparent; }
#editor .lib-open[aria-current="true"] { background: #e3edf9; }
.lib-title { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.lib-meta { color: var(--muted); font-size: 11px; }
#editor .lib-delete {
  padding: 0 9px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  opacity: 0;
}
#lib-list li:hover .lib-delete, #editor .lib-delete:focus-visible { opacity: 1; }
#editor .lib-delete:hover { color: #c4291c; background: transparent; }
@media (hover: none) { #editor .lib-delete { opacity: 1; } }
#lib-empty { margin: 4px 8px; color: var(--muted); font-size: 12px; }

.source { flex: 2; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.source[hidden] { display: none; }

#abc {
  flex: 1;
  resize: none;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#abc:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

#warnings {
  margin: 0;
  max-height: 8em;
  overflow: auto;
  color: var(--warn);
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}
#warnings:empty { display: none; }

#status { margin: 0; min-height: 1.4em; color: var(--muted); font-size: 13px; }
#status.error { color: #c4291c; }

.palette .group { display: inline-flex; align-items: center; gap: 3px; }
.palette .group + .group { padding-left: 12px; border-left: 1px solid var(--line); }
.palette button.dur { display: inline-flex; padding: 2px 6px; }
.palette button.dot { font-weight: 800; font-size: 20px; line-height: 0.9; }
.palette .bar-btn { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-width: 2.4em; }

/* Piano: white keys in a row, black keys positioned over the gaps. */
.keyboard { display: flex; align-items: stretch; gap: 6px; }
.keyboard > button { padding: 0 6px; }
#oct-label { align-self: center; color: var(--muted); font-size: 12px; min-width: 5.5em; }
#keys {
  position: relative;
  flex: 1;
  max-width: 720px;
  height: 104px;
  display: grid;
  grid-template-columns: repeat(var(--whites), 1fr);
  user-select: none;
  touch-action: manipulation;
}
#editor .key { border-radius: 0 0 5px 5px; padding: 0; cursor: pointer; }
#editor .key.white {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 5px;
  margin-right: -1px;
  border: 1px solid #c9c9c6;
  background: #fff;
  color: #9b9a97;
  font-size: 11px;
}
#editor .key.black {
  position: absolute;
  top: 0;
  left: calc(var(--pos) * 100% / var(--whites));
  width: calc(100% / var(--whites) * 0.62);
  height: 62%;
  transform: translateX(-50%);
  border: 1px solid #1f1f1f;
  background: #2f2f2f;
  z-index: 1;
}
#editor .key.white:hover { background: #eef5fd; }
#editor .key.black:hover { background: #4a4a4a; }
#editor .key.white:active, #editor .key.white.on { background: #cfe3fa; }
#editor .key.black:active, #editor .key.black.on { background: var(--accent); border-color: var(--accent); }

/* Two-way switch (letter names / solfège) */
.segmented { display: inline-flex; align-self: center; }
#editor .segmented button { border-radius: 0; font-size: 12px; padding: 3px 8px; white-space: nowrap; }
#editor .segmented button + button { margin-left: -1px; }
#editor .segmented button:first-child { border-radius: 6px 0 0 6px; }
#editor .segmented button:last-child { border-radius: 0 6px 6px 0; }

.embed { padding-top: 8px; border-top: 1px solid var(--line); font-size: 13px; }
#embed-url {
  flex-basis: 100%;
  color: var(--muted);
  font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
  max-height: 2.6em;
  overflow: auto;
}

@media (max-width: 720px) {
  #editor { height: auto; min-height: 100%; }
  .work { flex-direction: column; }
  #library { flex-basis: auto; max-height: 35vh; }
  #preview-frame { min-height: 40vh; }
  .source #abc { min-height: 30vh; }
  .palette .group + .group { padding-left: 0; border-left: 0; }
  #keys { height: 88px; }
  #oct-label { display: none; }
  .keyboard { flex-wrap: wrap; }
  #keys { flex-basis: calc(100% - 90px); }
  #note-names { flex-basis: 100%; justify-content: center; }
  #editor .key.white { font-size: 9px; overflow: hidden; }
}
