/* Tone builder page. Builds on app.css tokens. */
.brand, a.btn { color: inherit; text-decoration: none; }
.tones-main {
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  grid-template-areas: "assign assign" "editor lib";
}
.assign-card { grid-area: assign; }
.editor-card { grid-area: editor; }
.lib-card { grid-area: lib; }
@media (max-width: 860px) {
  .tones-main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "assign" "editor" "lib"; }
}
/* Side by side, the Library stays in view while the editor scrolls, and
   scrolls on its own. */
@media (min-width: 861px) {
  .lib-card {
    position: sticky; top: calc(var(--top-h, 61px) + 16px); align-self: start;
    max-height: calc(100vh - var(--top-h, 61px) - 32px); overflow-y: auto; overscroll-behavior: contain;
  }
}
.gate { max-width: 420px; width: calc(100% - 32px); margin: 40px auto; }
.loading { text-align: center; margin: 48px 16px; }
.gate-form { display: grid; gap: 10px; margin-top: 12px; }
.gate-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.gate-form input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 38px;
}
.gate-form .error { color: var(--busy); font-size: 13px; margin: 0; min-height: 1em; }
.gate-form .btn { justify-self: start; }
.note.first { margin: -4px 0 12px; }

/* Assignments */
.assign { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 640px) { .assign { grid-template-columns: minmax(0, 1fr); } }
.slot { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: var(--raised); min-width: 0; }
.slot-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.slot-head b { font-size: 14px; }
.slot p { color: var(--muted); font-size: 13px; margin: 2px 0 10px; }
.slot-pick { display: flex; gap: 8px; align-items: center; }
.slot-pick select { flex: 1; min-width: 0; }
.tones-main select, .tones-main input:not([type=range]), .tones-main textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 38px;
}
.switch {
  appearance: none; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 3px 10px 3px 3px; font: inherit; font-size: 12px; font-weight: 700;
}
.switch .knob { width: 30px; height: 18px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; }
.switch .knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.switch[aria-checked="true"] { color: var(--ok); }
.switch[aria-checked="true"] .knob { background: var(--ok); }
.switch[aria-checked="true"] .knob::after { transform: translateX(12px); }
.slot.is-off .slot-pick { opacity: .6; }
.blocked { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--busy); margin: -4px 0 10px; }
.state { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.state.on { color: var(--ok); }
.state.off { color: var(--muted); }

/* Editor */
.roll {
  width: 100%; height: 150px; display: block; border-radius: 12px;
  background: var(--raised); border: 1px solid var(--line);
}
.roll .grid { stroke: var(--line); stroke-width: 1; }
.roll .lbl { fill: var(--muted); font: 10px var(--mono); }
.roll .bar1 { fill: var(--accent); }
.roll .bar2 { fill: var(--rx); }
.roll .rest { fill: var(--line); opacity: .45; }
.roll .bar1.sel, .roll .bar2.sel { stroke: var(--text); stroke-width: 1.5; }
.roll .head { stroke: var(--text); stroke-width: 2; }
.ed-play, .ed-add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; }
.vol { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin-left: auto; }
.vol input { width: 110px; accent-color: var(--accent); }

.steps-wrap { overflow-x: auto; margin: 0 -4px; }
.steps { width: 100%; border-collapse: collapse; font-size: 14px; }
.steps th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px; white-space: nowrap; }
.steps td { padding: 3px 4px; }
.steps td:first-child { color: var(--muted); font-family: var(--mono); width: 1.5em; }
.steps input { width: 100%; min-width: 64px; font-family: var(--mono) !important; padding: 6px 8px !important; min-height: 34px !important; }
.steps tr.sel td { background: var(--rx-box); }
.steps tr.rest input:not(.ms) { opacity: .45; }
.row-acts { display: flex; gap: 2px; white-space: nowrap; }
.row-acts button {
  appearance: none; border: 0; background: none; color: var(--muted); cursor: pointer;
  width: 28px; height: 30px; border-radius: 8px; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
}
.row-acts button:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.row-acts button:hover { background: var(--raised); color: var(--text); }
.row-acts button:disabled { opacity: .3; cursor: default; }
@media (pointer: coarse) {
  .row-acts button { width: 44px; height: 44px; }
  .tone-row .play { width: 44px; height: 44px; }
}

.str { width: 100%; resize: vertical; font-size: 13px; margin-top: 4px; }
.str.bad { border-color: var(--busy); }
.save-row { display: flex; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.save-row input { flex: 1; min-width: 0; }

/* Library */
.filter { width: 100%; margin-bottom: 8px; }
.lib-group { margin-top: 14px; }
.lib-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 4px; display: flex; justify-content: space-between; gap: 8px; }
.lib-group h3 a { text-transform: none; letter-spacing: 0; font-weight: 500; }
.tone-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.tone-row:first-of-type { border-top: 0; }
.tone-row .play {
  appearance: none; border: 1px solid var(--line); background: var(--raised); color: var(--text);
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; flex: none; font-size: 11px;
  display: inline-flex; align-items: center; justify-content: center;
}
.tone-row .play .ic { width: 14px; height: 14px; }
.tone-row .play:hover { border-color: var(--accent); }
.tone-row .nm { flex: 1; min-width: 0; }
.tone-row .nm b { display: block; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tone-row .nm small { color: var(--muted); font-size: 12px; }
.tone-row .mini { width: 64px; height: 22px; flex: none; }
.tone-row .mini rect { fill: var(--accent); }
.tone-row .mini rect.b { fill: var(--rx); }
.tone-row .btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.tag { font-size: 11px; font-weight: 700; color: var(--accent-ink); margin-left: 6px; }
