/* This layout loads after the shared workspace rules and affects only the rhythm tool. */
body[data-screen-tool=rhythm] > .rhythm-simple-toolbar {
  display:grid;grid-template-columns:auto minmax(240px,1fr) auto auto;
  align-items:center;gap:18px;padding:8px 12px;direction:ltr;min-width:0;
  background:var(--card-bg);box-shadow:none;backdrop-filter:none;
}
.rhythm-simple-toolbar .engine-playback-group,
.rhythm-simple-toolbar .engine-metronome-group {direction:ltr;gap:8px;padding:0;border:0;min-width:0}
.rhythm-simple-toolbar .engine-playback-group #playBtn {width:100px;min-width:100px;height:38px;font-size:14px;justify-content:center}
.rhythm-simple-toolbar #engine-global-loop {width:36px;height:36px;min-width:36px;padding:0;font-size:24px;justify-content:center}
.rhythm-simple-toolbar .engine-master-volume {padding:0;margin:0}
.rhythm-simple-toolbar .engine-playback-group {justify-self:end}
.rhythm-simple-toolbar .engine-tempo {margin:0;direction:ltr}
.rhythm-simple-toolbar .engine-tempo>span {font-size:10px;line-height:14px;font-weight:500;direction:initial}
.rhythm-simple-toolbar .engine-tempo-knob {width:42px;height:42px;font-size:13px}
.rhythm-simple-toolbar .engine-circle {padding:0 3px}
.rhythm-simple-toolbar .engine-meter-control {padding:0 4px;gap:0}
.rhythm-simple-toolbar .engine-meter-control > label {font-size:10px;line-height:14px}
.rhythm-toolbar-click {display:flex;align-items:center;gap:5px;font-size:12px;white-space:nowrap;cursor:pointer;min-height:36px}
.rhythm-toolbar-click input {width:17px;height:17px;margin:0;accent-color:var(--accent-active)}
.rhythm-toolbar-choices {display:grid;grid-template-columns:minmax(110px,.9fr) minmax(125px,1.1fr);gap:10px;min-width:0;width:100%;max-width:420px;justify-self:center;direction:ltr}
.rhythm-toolbar-field {display:flex;flex-direction:column;gap:3px;min-width:0;color:var(--text-muted);font-size:11px;line-height:14px;text-align:start}
.rhythm-toolbar-field>select {width:100%;max-width:none;min-width:0;height:34px;padding:4px 7px;font-size:12px;color:var(--text-main)}
.rhythm-toolbar-tools {display:flex;align-items:center;gap:7px;direction:ltr}
.rhythm-simple-toolbar .screen-options-open,
.rhythm-simple-toolbar a.engine-shapes-link {display:inline-flex;align-items:center;justify-content:center;gap:5px;min-height:36px;margin:0;padding:5px 9px;font-size:12px;white-space:nowrap}
.rhythm-simple-toolbar :is(button,select,a,input):focus-visible {outline:2px solid var(--accent);outline-offset:3px}
.rhythm-simple-toolbar .engine-info-button {display:none}
#rhythm-toolbar-settings {max-height:calc(100dvh - 80px);overflow:auto}
#rhythm-toolbar-settings .engine-basic-modes[hidden] {display:none!important}
.rhythm-toolbar-settings-section {margin-top:14px;padding-top:12px;border-top:1px solid var(--border-color)}
.rhythm-toolbar-settings-section h2 {font-size:14px;margin:0 0 10px;color:var(--text-main)}
.rhythm-toolbar-settings-section .control-group {display:flex;flex-wrap:wrap;gap:8px}
.rhythm-toolbar-settings-section .engine-click-volume {flex-direction:row;justify-content:flex-start;gap:15px;margin:0;direction:ltr}
.rhythm-toolbar-settings-section .engine-click-options {display:flex;flex-direction:row;align-items:center}

body[data-screen-tool=rhythm] .rhythm-equal-workspace {
  display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:repeat(2,minmax(0,1fr));
  grid-template-areas:'notation' 'editor';gap:8px;min-height:0;min-width:0;
}
.rhythm-equal-workspace > .engine-notation-with-circles {grid-area:notation;height:100%;min-height:0!important;min-width:0}
.rhythm-equal-workspace > .rhythm-grid-workspace {grid-area:editor;display:flex;flex-direction:column;gap:4px;min-height:0;min-width:0}
.rhythm-equal-workspace .rhythm-grid-workspace > #barsContainer {
  display:grid;grid-template-columns:repeat(2,minmax(0,1fr));grid-auto-rows:minmax(min-content,1fr);
  align-content:stretch;flex:1;min-height:0;width:100%;height:auto;overflow:auto;margin:0;gap:8px;zoom:1;direction:ltr;
}
.rhythm-equal-workspace #barsContainer .bar-card {
  display:grid;grid-template-columns:repeat(2,minmax(0,1fr));
  grid-template-rows:auto repeat(var(--rhythm-beat-rows,2),minmax(48px,1fr));
  align-content:stretch;min-height:min-content;height:auto;padding:6px;gap:5px;direction:ltr;
}
.rhythm-equal-workspace #barsContainer .beat-row {display:flex;flex-direction:column;height:auto!important;padding:4px!important;min-height:48px}
.rhythm-equal-workspace #barsContainer .beat-header {height:auto!important;min-height:28px;margin-bottom:5px;flex:none;align-items:center;flex-wrap:wrap;gap:6px}
.rhythm-equal-workspace #barsContainer .beat-header>span:not(.engine-note-menu-wrapper) {
  display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;
  min-height:28px;padding:3px 8px;border-radius:5px;white-space:nowrap;
  font-size:14px;line-height:1.2;font-weight:800;
  color:oklch(20% .025 250);background:var(--beat-color,#82b7ff);
}
.rhythm-equal-workspace #barsContainer .beat-header>.engine-note-menu-wrapper {flex:1 1 70px;width:auto;min-width:0}
.rhythm-equal-workspace #barsContainer .subdivisions-grid {flex:1;min-height:18px;direction:ltr}
.rhythm-equal-workspace #barsContainer .sub-step {height:100%;min-height:18px}
.rhythm-equal-workspace #barsContainer .bar-header {height:auto!important;min-height:25px;margin:0!important}
.rhythm-equal-workspace #barsContainer .bar-title {font-size:13px}
.rhythm-equal-workspace #barsContainer .bar-header button {min-height:26px;font-size:11px;padding:3px 6px}
.rhythm-equal-workspace #barsContainer .sound-select-wrapper {height:auto!important;min-height:28px}
.rhythm-equal-workspace #barsContainer .sound-select-wrapper select {height:28px!important;min-height:28px!important}
.rhythm-equal-workspace #barsContainer .engine-double-editor {display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto repeat(2,minmax(min-content,1fr));gap:4px;min-height:min-content}
.rhythm-equal-workspace #barsContainer .engine-double-editor > .bar-card {grid-template-rows:repeat(var(--rhythm-beat-rows,2),minmax(48px,1fr))}
.rhythm-equal-workspace[data-edit-compact=true] .rhythm-grid-workspace > #barsContainer {display:grid;grid-template-columns:minmax(0,1fr)}
.rhythm-equal-workspace[data-edit-compact=true] .rhythm-grid-workspace > .rhythm-edit-choice {display:flex;flex:none;min-height:30px}
.rhythm-equal-workspace[data-edit-compact=true] #barsContainer .engine-double-editor {grid-template-rows:auto repeat(2,minmax(min-content,1fr))}

.rhythm-equal-workspace .engine-live-circles .engine-live-circle > .engine-part-title {font-size:14px;line-height:1.3;font-weight:800;white-space:nowrap}
body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .staff-title {font-size:16px;letter-spacing:0}
body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .beat-num-label {font-size:18px;line-height:1.2;opacity:1}

/* Both editing rows share the same right edge. The circles use the full side column. */
@media(min-width:1001px) and (min-height:620px) {
  body[data-screen-tool=rhythm] .rhythm-equal-workspace {
    --rhythm-sidebar:clamp(300px,26vw,390px);
    --rhythm-circle-size:calc(var(--rhythm-sidebar) - 132px);
    grid-template-columns:minmax(0,1fr) var(--rhythm-sidebar);
    grid-template-areas:'notation circles' 'editor circles';direction:ltr;
  }
  .rhythm-equal-workspace > .engine-notation-with-circles {display:contents}
  .rhythm-equal-workspace .engine-notation-with-circles > .visualizers-wrapper {grid-area:notation;width:100%;height:100%;min-width:0;min-height:0;flex:initial}
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circles {
    grid-area:circles;width:100%;height:100%;min-width:0;min-height:0;
    display:grid;grid-template-rows:repeat(2,minmax(0,1fr));gap:8px;
  }
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle {
    position:relative;display:grid;grid-template-columns:minmax(0,1fr) 38px;grid-template-rows:none;grid-auto-rows:auto;
    align-content:center;gap:5px;padding:38px 10px 8px calc(var(--rhythm-circle-size) + 16px);direction:ltr;
  }
  /* Absolute children must use the card, rather than the legacy grid cells, as their containing block. */
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > :is(svg.engine-circle-preview,.engine-part-title,.engine-info-button,.engine-circle-sounds-button) {grid-area:auto!important}
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > .engine-part-title {
    position:absolute;inset:8px 10px auto 64px;width:auto;margin:0;padding:0;
    font-size:20px;line-height:26px;text-align:center;
  }
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > svg.engine-circle-preview {
    position:absolute;left:8px;right:auto;top:calc(50% + 12px);bottom:auto;width:var(--rhythm-circle-size);height:calc(100% - 50px);
    min-height:0;max-height:none;transform:translateY(-50%);
  }
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > :is(select,input,.engine-note-menu-wrapper,.engine-circle-count) {
    position:static!important;grid-column:1/-1;grid-row:auto!important;width:100%!important;max-width:none!important;
    min-width:0;font-size:12px!important;line-height:1.25!important;margin:0;padding:2px 4px!important;
  }
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > :is(select,input,.engine-note-menu-wrapper) {height:28px!important;min-height:28px!important}
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle .engine-note-select-button {height:28px;min-height:28px;font-size:12px}
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > .engine-inline-named-shape {grid-column:1}
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > .engine-inline-vertices {grid-column:2}
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > .engine-circle-count {font-size:13px!important;line-height:18px!important;text-align:center}
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > .engine-shape-icon {display:none}
}
@media(min-width:1001px) and (min-height:620px) and (max-height:720px) {
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle {gap:2px;padding-bottom:6px}
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle > :is(select,input,.engine-note-menu-wrapper) {height:24px!important;min-height:24px!important}
  body[data-screen-tool=rhythm] .rhythm-equal-workspace .engine-live-circle .engine-note-select-button {height:24px;min-height:24px}
}

/* One bar reads as one continuous timeline, across the entire editor. */
body[data-rhythm-structure=single] .rhythm-equal-workspace .engine-live-circles {grid-template-rows:minmax(0,1fr)!important}
body[data-rhythm-structure=single] .rhythm-equal-workspace .engine-live-circle[data-part="2"] {display:none!important}
body[data-rhythm-structure=single] .rhythm-equal-workspace .rhythm-grid-workspace > #barsContainer {grid-template-columns:minmax(0,1fr)}
body[data-rhythm-structure=single] .rhythm-equal-workspace #barsContainer .bar-card {
  grid-template-columns:repeat(var(--rhythm-beats,4),minmax(72px,1fr));
  grid-template-rows:auto minmax(48px,1fr);
}

@media(max-width:1100px) {
  body[data-screen-tool=rhythm] > .rhythm-simple-toolbar {grid-template-columns:minmax(0,1fr) auto;gap:8px 16px}
  .rhythm-simple-toolbar .engine-playback-group {grid-column:2;grid-row:1}
  .rhythm-simple-toolbar .engine-metronome-group {grid-column:1;grid-row:1}
  .rhythm-toolbar-choices {grid-column:1;grid-row:2}
  .rhythm-toolbar-tools {grid-column:2;grid-row:2;justify-content:flex-end}
}
@media(max-width:600px) {
  body[data-screen-tool=rhythm] > .rhythm-simple-toolbar {gap:7px 6px;padding:7px}
  .rhythm-simple-toolbar .engine-playback-group {gap:6px}
  .rhythm-toolbar-tools {grid-column:1;grid-row:1;justify-content:flex-start;gap:5px}
  .rhythm-simple-toolbar .screen-options-open {font-size:0;width:36px;padding:0}
  .rhythm-simple-toolbar .screen-options-open::before {content:'⚙';font:20px/1 system-ui}
  .rhythm-simple-toolbar a.engine-shapes-link {width:36px;padding:0}
  .rhythm-simple-toolbar a.engine-shapes-link span {display:none}
  .rhythm-simple-toolbar .engine-metronome-group {grid-column:1/-1;grid-row:2;justify-content:center;gap:12px}
  .rhythm-toolbar-choices {grid-column:1/-1;grid-row:3;gap:8px}
}
@media(max-height:560px) and (min-width:701px) {
  body[data-screen-tool=rhythm] .rhythm-equal-workspace {grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:minmax(0,1fr);grid-template-areas:'notation editor';direction:ltr}
  .rhythm-equal-workspace .rhythm-grid-workspace {direction:initial}
}

/* Comparison modes: each row is one part, across notation, steps and its circle. */
@media(min-width:1001px) and (min-height:620px) {
  body:is([data-rhythm-structure=loop12],[data-rhythm-structure=phrase2bar]) .rhythm-equal-workspace {
    grid-template-columns:repeat(2,minmax(0,1fr)) var(--rhythm-sidebar);
    grid-template-rows:minmax(0,1fr);grid-template-areas:'notation editor circles';
  }
  body:is([data-rhythm-structure=loop12],[data-rhythm-structure=phrase2bar]) .rhythm-equal-workspace .visualizers-wrapper {
    grid-template-rows:repeat(2,minmax(0,1fr));grid-auto-rows:minmax(0,1fr);row-gap:8px;direction:ltr;
  }
  body[data-rhythm-structure=loop12] .rhythm-equal-workspace .visualizers-wrapper {grid-template-columns:minmax(0,1fr)}
  body[data-rhythm-structure=loop12] .rhythm-equal-workspace #staffContainer0 {grid-area:1/1}
  body[data-rhythm-structure=loop12] .rhythm-equal-workspace #staffContainer1 {grid-area:2/1}
  body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .visualizers-wrapper {grid-template-columns:repeat(2,minmax(0,1fr));column-gap:0}
  body:is([data-rhythm-structure=loop12],[data-rhythm-structure=phrase2bar]) .rhythm-equal-workspace .rhythm-grid-workspace {height:100%;min-height:0}
  body:is([data-rhythm-structure=loop12],[data-rhythm-structure=phrase2bar]) .rhythm-equal-workspace .rhythm-edit-choice {display:none!important}
  body:is([data-rhythm-structure=loop12],[data-rhythm-structure=phrase2bar]) .rhythm-equal-workspace .rhythm-grid-workspace > #barsContainer {
    display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:repeat(2,minmax(0,1fr));grid-auto-rows:minmax(0,1fr);
    height:100%;min-height:0;gap:8px;
  }
  body[data-rhythm-structure=loop12] .rhythm-equal-workspace #barsContainer > :is(#bar-card-1,#bar-card-2) {
    display:grid!important;min-height:0;height:100%;overflow:auto;
  }
  body[data-rhythm-structure=loop12] .rhythm-equal-workspace #bar-card-1 {grid-row:1}
  body[data-rhythm-structure=loop12] .rhythm-equal-workspace #bar-card-2 {grid-row:2}
  body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .rhythm-grid-workspace #barsContainer > .engine-double-editor {
    display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:auto minmax(0,1fr);
    min-height:0;height:100%;overflow:auto;align-content:stretch;
  }
  body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .engine-double-editor > .rhythm-pair-toolbar {grid-column:1/-1}
  body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .rhythm-grid-workspace #barsContainer .bar-card {
    display:grid!important;grid-row:2;min-height:0;height:100%;overflow:auto;
  }
  body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .rhythm-grid-workspace #barsContainer .engine-double-editor > .bar-card {grid-column:1}
  body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .rhythm-grid-workspace #barsContainer .engine-double-editor > .bar-card:last-of-type {grid-column:2}
  body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .engine-double-editor[data-part="1"] {grid-row:1}
  body[data-rhythm-structure=phrase2bar] .rhythm-equal-workspace .engine-double-editor[data-part="2"] {grid-row:2}
}

/* One control strip for each part, shared by single bars and two-bar parts. */
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar {
  grid-column:1/-1;grid-row:1;display:flex;align-items:center;gap:12px;
  min-width:0;min-height:36px;padding:2px 0;direction:ltr;overflow-x:auto;
  container-type:inline-size;container-name:rhythm-part;
  border-bottom:1px solid var(--border-color);
}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar .bar-header {
  display:flex;align-items:center;gap:8px;flex:0 0 auto;flex-wrap:nowrap!important;
  padding:0!important;margin:0!important;border:0;
}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar :is(.bar-title,h2) {font-size:16px;font-weight:750;line-height:1.3;white-space:nowrap;margin:0;flex:none;unicode-bidi:plaintext}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar h2 {display:block}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar :is(.bar-title>span,.rhythm-part-meta) {font-size:13px!important;font-weight:500}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar .bar-controls {display:flex;align-items:center;flex-wrap:nowrap!important;gap:4px;direction:ltr;flex:none}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar button {display:inline-flex;align-items:center;justify-content:center;gap:5px;min-height:32px;padding:4px 7px;font-size:14px;white-space:nowrap;flex:none}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar .rhythm-control-icon {font-size:17px;line-height:1}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar .btn-random {font-size:18px;min-width:32px}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar .engine-info-button {width:32px;min-width:32px;height:32px;padding:0;font-size:17px}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar .sound-select-wrapper {
  display:flex!important;align-items:center;justify-content:flex-end;flex-wrap:nowrap!important;gap:10px!important;
  min-height:32px;height:auto!important;min-width:0;margin:0!important;flex:1;
}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar .sound-select-wrapper>div {flex:1;min-width:0;gap:6px!important}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar label {font-size:14px;white-space:nowrap}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar select {width:100%;min-width:64px;max-width:180px;height:32px!important;min-height:32px!important;padding:4px 6px!important;font-size:14px;line-height:1.3}
.rhythm-equal-workspace #barsContainer .rhythm-part-toolbar .engine-pair-controls {display:flex!important;align-items:center;justify-content:flex-start;flex-wrap:nowrap!important;gap:8px;flex:1;min-width:0;padding:0!important;border:0;direction:ltr}
.rhythm-equal-workspace #barsContainer .engine-double-editor>.bar-card>.rhythm-part-toolbar {display:none}
.rhythm-equal-workspace #barsContainer .rhythm-pair-toolbar h2 {color:var(--accent-warning)}
@container rhythm-part (max-width:680px) {
  .rhythm-part-toolbar .rhythm-control-text,
  .rhythm-part-toolbar .bar-title>span,
  .rhythm-part-toolbar .rhythm-part-meta,
  .rhythm-part-toolbar .sound-select-wrapper>div>label {display:none}
}
