/* ── base ─────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

:root {
    --bg: #f5f5f5;
    --panel: #ffffff;
    --border: #dcdcdc;
    --text: #333333;
    --muted: #777777;
    --accent: #4CAF50;
    --topbar-h: 48px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── top bar ──────────────────────────────────────────────────── */

.topbar {
    height: var(--topbar-h);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    font-size: 16px;
    margin: 0;
    white-space: nowrap;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.status {
    font-size: 12px;
    color: #E65100;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 44vw;
}

/* ── two-pane layout ──────────────────────────────────────────── */

.panes {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}

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

.pane-editor {
    width: 38%;
    background: var(--panel);
    border-right: 1px solid var(--border);
}

.pane-score {
    flex: 1 1 auto;
}

.pane-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}

#abc {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    border: 0;
    outline: none;
    resize: none;
    padding: 12px;
    font-family: 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
    font-size: 13px;
    line-height: 1.55;
    tab-size: 4;
    color: var(--text);
    background: var(--panel);
}

.parse-messages {
    flex: 0 0 auto;
    max-height: 30%;
    overflow-y: auto;
    padding: 0 12px;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 11px;
    line-height: 1.5;
    border-top: 1px solid transparent;
}

.parse-messages:not(:empty) {
    padding: 8px 12px;
    border-top-color: var(--border);
    background: #FFF8E1;
}

.parse-messages .err { color: #C62828; }
.parse-messages .warn { color: #8D6E63; }

/* Draggable divider between the two panes. */
.splitter {
    flex: 0 0 6px;
    cursor: col-resize;
    background: transparent;
    position: relative;
}

.splitter::after {
    content: '';
    position: absolute;
    inset: 0 2px;
    background: var(--border);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}

.splitter:hover::after,
.splitter.dragging::after { opacity: 1; }

body.resizing { cursor: col-resize; user-select: none; }

/* ── controls ─────────────────────────────────────────────────── */

.controls {
    flex: 0 0 auto;
    padding: 10px 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.control-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.control-row + .control-row { margin-top: 8px; }

button {
    padding: 7px 14px;
    font-size: 13px;
    font-family: inherit;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: #e8e8e8;
    color: var(--text);
    transition: background 0.15s, opacity 0.15s;
}

button:hover:not(:disabled) { opacity: 0.85; }
button:disabled { opacity: 0.45; cursor: default; }

button.primary { background: var(--accent); color: #fff; }
button.danger  { background: #f44336; color: #fff; }
button.plain   { background: #e0e0e0; color: #555; padding: 7px 10px; }

button.toggle { background: #9E9E9E; color: #fff; }
button.toggle.on { background: #2196F3; }
#oneshotBtn.on { background: #9C27B0; }
#loopBtn.on    { background: #FF9800; }
#colorBtn.on   { background: #673AB7; }

button.step {
    padding: 5px 9px;
    font-size: 13px;
    background: #e0e0e0;
}

.link-btn {
    background: transparent;
    color: var(--muted);
    padding: 2px 7px;
    border: 1px solid var(--border);
    border-radius: 50%;
    font-size: 11px;
}

.field {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #555;
    background: #f7f7f7;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 8px;
}

.field > span:first-child { font-weight: 600; }
.field small { color: var(--muted); }

.field input[type="number"] {
    width: 52px;
    padding: 4px 6px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 12px;
}

.field select {
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 12px;
    background: #fff;
}

#example {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 12px;
    background: #fff;
    max-width: 210px;
}

.tonic-value {
    min-width: 84px;
    text-align: center;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 90px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 13px;
    height: 13px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

/* ── colour legend ────────────────────────────────────────────── */

.color-legend {
    display: none;
    flex-wrap: wrap;
    gap: 5px;
    padding: 8px 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.color-legend.visible { display: flex; }

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    background: #f7f7f7;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 11px;
    color: #555;
}

.legend-item.tonic { font-weight: 700; color: var(--text); }

.legend-swatch {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.35);
}

/* ── voices ───────────────────────────────────────────────────── */

.voice-controls {
    flex: 0 0 auto;
    padding: 8px 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    max-height: 22vh;
    overflow-y: auto;
}

.voice-controls h3 {
    margin: 0 0 7px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
}

.voice-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.no-voices { color: #aaa; font-style: italic; font-size: 12px; }

.voice-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    background: #f2f2f2;
    border-radius: 7px;
    font-size: 12px;
}

.voice-item .voice-name {
    font-weight: 600;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-item button {
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 600;
    border-radius: 4px;
    background: #e0e0e0;
}

.voice-item .mute-btn.on { background: #f44336; color: #fff; }
.voice-item .solo-btn.on { background: #FF9800; color: #fff; }

.voice-item .volume-value {
    font-size: 10px;
    color: var(--muted);
    min-width: 30px;
    text-align: right;
}

/* ── score ────────────────────────────────────────────────────── */

.score-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 16px;
}

.score {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    padding: 8px 4px 16px;
    min-height: 120px;
}

.score-svg { display: block; }

/* Only noteheads respond to clicks. Staff lines, bar lines and beams are
   painted over the notes, so without this they swallow clicks aimed at a note
   sitting on a line. */
.score svg { pointer-events: none; }

.score svg g.abcjs-note {
    pointer-events: all;
    cursor: pointer;
}

/* The sounding note. A drop-shadow tints the glyph itself, which works
   whether or not scale-degree colours are on. */
.score svg g.note-playing {
    fill: #1565C0;
    stroke: #1565C0;
}

.score svg g.note-playing.degree-colored {
    filter: drop-shadow(0 0 3px #1565C0);
}

/* Muted voices fade out but stay clickable. */
.score svg g.voice-muted { opacity: 0.28; }

/* Scale-degree colours: the notehead inherits `color`, and an outline keeps
   the pale degrees (white tonic, yellow leading note) readable on paper. */
.score svg g.degree-colored { fill: currentColor; }

.score svg g.degree-colored path,
.score svg g.degree-colored ellipse {
    stroke: rgba(0, 0, 0, 0.85);
    stroke-width: 0.7;
    paint-order: stroke fill;
}

.hints {
    flex: 0 0 auto;
    margin: 0;
    padding: 8px 14px;
    font-size: 11px;
    line-height: 1.6;
    color: var(--muted);
    background: var(--panel);
    border-top: 1px solid var(--border);
}

/* ── narrow screens: stack the panes ──────────────────────────── */

@media (max-width: 820px) {
    body { overflow: auto; }
    .panes { flex-direction: column; }
    .pane-editor { width: 100% !important; height: 34vh; border-right: 0; border-bottom: 1px solid var(--border); }
    .splitter { display: none; }
    .score-scroll { overflow: visible; }
    .status { max-width: 100%; }
}

/* abcjs marks the character it tripped over inside a warning. */
.parse-messages mark {
    background: #FFE082;
    color: #5D4037;
    padding: 0 2px;
    border-radius: 2px;
    font-weight: 700;
}
