.rhythm {
  --rhythm-tint: color-mix(in srgb, var(--accent, #785ca5) 12%, var(--surface, #fbf8ef));
  --rhythm-tint-strong: color-mix(in srgb, var(--accent, #785ca5) 22%, var(--surface, #fbf8ef));
  --rhythm-editor-bg: color-mix(in srgb, var(--surface, #fbf8ef) 92%, var(--accent, #785ca5));
  --rhythm-border: var(--line, #ddd3e2);
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.rhythm-header h1,
.rhythm-editor h2,
.rhythm-measure h3 {
  margin: 0;
  color: var(--ink, #2f243d);
}

.rhythm-header h1 {
  font-size: clamp(1.75rem, 3.8vw, 2.6rem);
  font-weight: 750;
  line-height: 1.15;
}

.rhythm-header p,
.rhythm-editor-head p {
  margin: .45rem 0 0;
  color: var(--muted, #5e506a);
  line-height: 1.55;
}

.rhythm-panel {
  min-width: 0;
  border: 1px solid var(--rhythm-border);
  border-radius: 1.25rem;
  background: var(--surface, #fbf8ef);
  padding: clamp(.85rem, 2.2vw, 1.5rem);
}

.rhythm-tempo,
.rhythm-tempo-settings,
.rhythm-metronome {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .8rem 1.1rem;
}

.rhythm-tempo {
  justify-content: space-between;
}

.rhythm-tempo-number,
.rhythm-count,
.rhythm-edit-actions {
  display: flex;
  align-items: center;
  gap: .45rem;
}

.rhythm-bpm-label {
  display: grid;
  justify-items: center;
  color: var(--muted, #5e506a);
  font-size: .875rem;
  font-weight: 650;
  letter-spacing: .05em;
}

.rhythm-bpm-label input {
  appearance: textfield;
  width: 4.2rem;
  padding: 0;
  border: 0;
  border-radius: .45rem;
  background: none;
  color: var(--ink, #2f243d);
  font: inherit;
  font-size: 2rem;
  font-weight: 750;
  line-height: 1.2;
  text-align: center;
}

.rhythm-bpm-label input::-webkit-inner-spin-button,
.rhythm-bpm-label input::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.rhythm-step,
.rhythm-button,
.rhythm-tool,
.rhythm-remove,
.rhythm-beat,
.rhythm-item {
  cursor: pointer;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.rhythm-step,
.rhythm-button,
.rhythm-tool,
.rhythm-select-label select,
.rhythm-grid-label select {
  min-height: 3rem;
  border: 1px solid var(--rhythm-border);
  border-radius: .8rem;
  background: var(--rhythm-tint);
  color: var(--ink, #2f243d);
  font-weight: 650;
}

.rhythm-step {
  min-width: 3rem;
  padding: 0;
  font-size: 1.55rem;
  line-height: 1;
}

.rhythm-button {
  padding: .65rem 1rem;
  white-space: nowrap;
}

.rhythm-primary {
  border-color: transparent;
  background: var(--rhythm-tint-strong);
}

.rhythm-primary[aria-pressed="true"],
.rhythm-secondary[aria-pressed="true"] {
  border-color: var(--accent, #785ca5);
  background: var(--rhythm-tint-strong);
}

.rhythm-button:disabled {
  opacity: .48;
  cursor: default;
}

.rhythm-select-label {
  display: grid;
  gap: .25rem;
  color: var(--muted, #5e506a);
  font-size: .875rem;
  font-weight: 650;
}

.rhythm-select-label select,
.rhythm-grid-label select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.05rem) 50%, calc(100% - .75rem) 50%;
  background-size: .3rem .3rem, .3rem .3rem;
  background-repeat: no-repeat;
  font: inherit;
  font-size: 1rem;
  padding: .55rem 1.7rem .55rem .7rem;
}

.rhythm-count span {
  display: grid;
  width: 1.85rem;
  height: 1.85rem;
  place-items: center;
  border: 1px solid var(--rhythm-border);
  border-radius: 50%;
  color: var(--muted, #5e506a);
  font-size: .875rem;
  font-weight: 750;
}

.rhythm-count .rhythm-pulse-active {
  border-color: var(--accent, #785ca5);
  background: var(--rhythm-tint-strong);
  color: var(--ink, #2f243d);
}

.rhythm-editor {
  display: grid;
  gap: .85rem;
}

.rhythm-editor-head {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem 1rem;
  align-items: center;
  justify-content: space-between;
}

.rhythm-editor h2 {
  font-size: clamp(1.2rem, 3vw, 1.55rem);
  line-height: 1.22;
}

.rhythm-editor-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .85rem;
  color: var(--muted, #5e506a);
  font-size: .95rem;
}

.rhythm-meter {
  font-weight: 750;
}

.rhythm-toggle,
.rhythm-grid-label {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  min-height: 3rem;
}

.rhythm-toggle {
  cursor: pointer;
}

.rhythm-toggle input {
  width: 1.2rem;
  height: 1.2rem;
  margin: 0;
  accent-color: var(--accent, #785ca5);
}

.rhythm-grid-label select {
  min-height: 2.75rem;
}

.rhythm-palettes {
  display: grid;
  gap: .4rem;
}

.rhythm-palette {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.rhythm-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-width: 3.55rem;
  padding: .45rem .6rem;
  touch-action: none;
  user-select: none;
}

.rhythm-tool[aria-pressed="true"] {
  border-color: var(--accent, #785ca5);
  background: var(--rhythm-tint-strong);
}

.rhythm-tool-icon {
  font-family: "Noto Music", "Segoe UI Symbol", "Apple Symbols", sans-serif;
  font-size: 1.2em;
  line-height: 1;
}

.rhythm-message {
  min-height: 1.35em;
  margin: 0;
  color: var(--muted, #5e506a);
  font-size: .9rem;
  line-height: 1.35;
}

.rhythm-measures {
  display: grid;
  gap: .55rem;
}

.rhythm-measure {
  min-width: 0;
}

.rhythm-measure-head {
  display: flex;
  min-height: 2.75rem;
  justify-content: space-between;
  align-items: center;
}

.rhythm-measure h3 {
  font-size: 1rem;
  font-weight: 700;
}

.rhythm-remove {
  min-height: 2.75rem;
  min-width: 3rem;
  border: 0;
  border-radius: .6rem;
  background: transparent;
  color: var(--muted, #5e506a);
  font-size: .875rem;
}

.rhythm-track {
  position: relative;
  min-width: 0;
  height: 5.4rem;
  border: 1px solid var(--rhythm-border);
  border-radius: .8rem;
  background: var(--rhythm-editor-bg);
  isolation: isolate;
}

.rhythm-show-grid .rhythm-track {
  background-image: repeating-linear-gradient(to right, transparent 0, transparent calc(var(--rhythm-grid-step) - 1px), var(--rhythm-border) calc(var(--rhythm-grid-step) - 1px), var(--rhythm-border) var(--rhythm-grid-step));
}

.rhythm-drop-target {
  outline: 2px dashed var(--accent, #785ca5);
  outline-offset: 2px;
}

.rhythm-track-beats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
}

.rhythm-beat {
  display: flex;
  align-items: flex-start;
  padding: .25rem .45rem 0;
  border: 0;
  border-right: 1px solid var(--rhythm-border);
  background: transparent;
  color: var(--muted, #5e506a);
  font-size: .875rem;
  font-weight: 650;
  text-align: start;
}

.rhythm-beat:last-child {
  border-right: 0;
}

.rhythm-beat-active {
  background: var(--rhythm-tint-strong);
}

.rhythm-item {
  position: absolute;
  top: 1.5rem;
  bottom: .3rem;
  left: calc(var(--rhythm-start) + 2px);
  width: calc(var(--rhythm-size) - 4px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .24rem;
  border: 1px solid color-mix(in srgb, var(--accent, #785ca5) 32%, var(--rhythm-border));
  border-radius: .55rem;
  background: var(--rhythm-tint-strong);
  padding: 0 .1rem;
  color: var(--ink, #2f243d);
  font-size: clamp(.7rem, 1.7vw, .95rem);
  font-weight: 750;
  white-space: nowrap;
  touch-action: none;
  user-select: none;
}

.rhythm-item-icon, .rhythm-hold {
  font-family: "Noto Music", "Segoe UI Symbol", "Apple Symbols", sans-serif;
  font-size: 1.12em;
}

.rhythm-hold {
  position: absolute;
  top: .2rem;
  right: .2rem;
  color: var(--accent, #785ca5);
  line-height: 1;
}

.rhythm-rest {
  border-style: dashed;
  background: var(--rhythm-tint);
}

.rhythm-tied {
  border-bottom: 3px solid var(--accent, #785ca5);
}

.rhythm-dragging {
  opacity: .55;
}

.rhythm-edit-actions {
  flex-wrap: wrap;
}

.rhythm button:focus-visible,
.rhythm input:focus-visible,
.rhythm select:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--accent, #785ca5);
  outline-offset: 2px;
}

.rhythm .rhythm-item:focus-visible {
  position: absolute;
}

@media (max-width: 550px) {
  .rhythm-tempo-settings,
  .rhythm-metronome {
    justify-content: space-between;
    width: 100%;
  }

  .rhythm-tempo {
    gap: .95rem;
  }

  .rhythm-item-icon {
    display: none;
  }
}

@media (max-width: 360px) {
  .rhythm-tool,
  .rhythm-button {
    padding-inline: .5rem;
  }

  .rhythm-step {
    min-width: 2.75rem;
  }

  .rhythm-bpm-label input {
    width: 3.5rem;
  }

  .rhythm-select-label select {
    max-width: 9rem;
  }
}
