#dialog[data-kind="rhythm-creator"] {
  width: min(94vw, 890px, calc(100% - var(--phone-left, 0px) - var(--phone-right, 0px)));
  max-height: min(94dvh, calc(100dvh - var(--safe-top) - var(--safe-bottom) - 8px));
  border: 2px solid #34323d;
  border-radius: 16px;
  background: #f1e8d6;
  box-shadow: 0 5px #3b3640, 0 18px 64px #18182755;
}
#dialog[data-kind="rhythm-creator"] .dialog-content { padding: 0; }
.rhythm-creator {
  --ink: #32343b;
  --muted: #54605d;
  color: var(--ink);
  padding: clamp(12px,2vw,23px);
  background: linear-gradient(142deg,#fff5de,#ece3cf 72%,#e5dcce);
  font-variant-numeric: tabular-nums;
}
.rhythm-creator button {
  min-width: 44px;
  min-height: 44px;
  line-height: 1.2;
  touch-action: manipulation;
  font-weight: 800;
}
.rhythm-creator button:focus-visible, .rhythm-creator-door:focus-visible {
  outline: 3px solid #704484;
  outline-offset: 1px;
  z-index: 1;
}
.creator-header { display: flex; align-items: center; gap: clamp(7px,1.3vw,16px); margin-bottom: 16px; }
.creator-back { display: grid; place-items: center; border-radius: 7px; background: #e5dcca; border: 1px solid #a79f8d; }
.creator-back .glyph { width: 20px; height: 20px; transform: rotate(180deg); }
.creator-title { margin-right: auto; }
.dialog-content .creator-title h2 { color: var(--ink); font-size: clamp(22px,2.6vw,32px); margin: 0; line-height: 1.05; letter-spacing: -.04em; }
.dialog-content .creator-title p { color: var(--muted); margin: 5px 0 0; font-size: 12px; line-height: 1.2; }
.creator-sections, .creator-tempo { display: inline-flex; align-items: stretch; flex: none; }
.creator-sections { gap: 5px; }
.creator-section {
  display: flex; gap: 8px; align-items: center; justify-content: center; padding: 4px 9px;
  background: #e5ddce; color: #57605c; border: 1px solid #a89e89; border-radius: 7px;
}
.creator-section b { font: 800 17px/1 ui-monospace,monospace; }
.creator-section[aria-pressed="true"] { background: #374e4e; color: #fff1cc; border-color: #2b4041; box-shadow: inset 0 -3px #243b3b; }
.creator-thumbnail {
  --off: #b7b3a5;
  --on: #657b70;
  display: grid; grid-template-columns: repeat(8,minmax(2px,4px)); align-items: end; gap: 1px;
  height: 19px; padding-bottom: 2px;
}
.creator-section[aria-pressed="true"] .creator-thumbnail { --off: #61736c; --on: #e1cda2; }
.creator-thumbnail i { display: block; height: 3px; border-radius: 1px 1px 0 0; background: var(--off); }
.creator-thumbnail i:is([data-mask="1"],[data-mask="2"],[data-mask="4"]) { height: 7px; background: var(--on); }
.creator-thumbnail i:is([data-mask="3"],[data-mask="5"],[data-mask="6"]) { height: 12px; background: var(--on); }
.creator-thumbnail i[data-mask="7"] { height: 16px; background: var(--on); }
.creator-thumbnail i[data-current] { outline: 1px solid #b55e47; background: #f2ab73; }
.creator-section[aria-pressed="true"] .creator-thumbnail i[data-current] { outline-color: #ffe5bc; }
.creator-tempo { background: #ddd8c8; border: 1px solid #aaa18e; border-radius: 7px; overflow: hidden; }
.creator-tempo button { padding: 0; font: 700 24px/1 system-ui,sans-serif; color: #355151; }
.creator-speed {
  min-width: 57px; align-self: stretch; display: grid; place-content: center; justify-items: center; gap: 2px;
  color: #e8f3c7; background: #37474a; border-inline: 1px solid #626b60;
}
.creator-speed strong { font: 700 23px/.9 ui-monospace,monospace; }
.creator-speed small { color: #c5d3bb; font: 700 9px/1 system-ui,sans-serif; letter-spacing: .12em; }
.creator-console {
  padding: clamp(6px,1.1vw,12px);
  border: 2px solid #343c45; border-radius: 10px; background: linear-gradient(112deg,#2e4047,#252d39 74%);
  box-shadow: inset 0 2px #56605f, inset 0 -2px #171e29;
}
.creator-staff {
  --transposed: 0;
  display: grid; align-items: stretch; grid-template-columns: clamp(53px,7.6vw,86px) repeat(8,minmax(44px,1fr));
  grid-template-rows: 22px repeat(3,clamp(50px,7.6dvh,76px)); gap: 5px;
}
.creator-meter, .creator-beat {
  align-self: center; justify-self: center; color: #c8d1c7; font: 720 13px/1.1 ui-monospace,monospace;
}
.creator-meter { grid-column: 1; grid-row: 1; color: #9db3b1; letter-spacing: .08em; }
.creator-beat { grid-column: calc(var(--step) + 2); grid-row: 1; }
.creator-beat:nth-of-type(odd) { color: #90a6a4; font-size: 11px; }
.creator-beat[data-current] { color: #fff2be; }
.creator-staff [data-lane="0"] { --lane-light: #fac580; --lane-edge: #aa7852; --lane-shadow: #805a3f; }
.creator-staff [data-lane="1"] { --lane-light: #8de5d4; --lane-edge: #589f97; --lane-shadow: #3d7773; }
.creator-staff [data-lane="2"] { --lane-light: #e2a6e2; --lane-edge: #a578ac; --lane-shadow: #795982; }
.creator-lane {
  display: grid; grid-template-columns: 12px auto; align-content: center; gap: 3px 6px; justify-content: center; align-items: center;
  grid-column: 1; grid-row: calc(var(--lane) + 2); color: #f2eddd; font-size: clamp(12px,1.4vw,15px);
}
.creator-lane strong { white-space: nowrap; line-height: 1.15; }
.creator-lane kbd { grid-column: 2; color: #36454b; font: 700 10px/1.1 ui-monospace,monospace; }
.creator-lane i, .creator-cell i { display: block; width: 10px; height: 10px; background: var(--lane-light); border-radius: 1px; }
.creator-staff [data-lane="1"] i { transform: rotate(45deg) scale(.79); }
.creator-staff [data-lane="2"] i { clip-path: polygon(34% 0,66% 0,66% 34%,100% 34%,100% 66%,66% 66%,66% 100%,34% 100%,34% 66%,0 66%,0 34%,34% 34%); }
.creator-cell {
  display: grid; place-items: stretch;
  grid-column: calc(var(--step) + 2); grid-row: calc(var(--lane) + 2); padding: 0;
  border-radius: 6px; -webkit-user-select: none; user-select: none;
}
.creator-cell > span {
  position: relative; display: grid; place-items: center; border-radius: 5px; border: 1px solid #677476;
  background: linear-gradient(150deg,#526267,#445158);
  box-shadow: inset 0 1px #6d7d7e66, inset 0 -3px #313d45, 0 2px #161e29;
}
.creator-cell:is([data-step="1"],[data-step="3"],[data-step="5"],[data-step="7"]) > span {
  background: linear-gradient(150deg,#45555d,#39454f); border-color: #59666d;
}
.creator-cell i { width: 4px; height: 4px; border-radius: 50%; background: #8a9999; }
.creator-cell[aria-pressed="false"] i { transform: none; clip-path: none; }
.creator-cell[aria-pressed="true"] > span {
  background: linear-gradient(145deg,color-mix(in srgb,var(--lane-light) 84%,#fff),var(--lane-light));
  border-color: var(--lane-edge); box-shadow: inset 0 1px #fff8, inset 0 -4px var(--lane-edge), 0 2px #161e29;
}
.creator-cell[aria-pressed="true"] i { width: 13px; height: 13px; border-radius: 1px; background: var(--lane-shadow); }
.creator-cell[data-current] > span::after {
  content: ''; position: absolute; inset: 2px; border: 2px solid #ffe8a5; border-radius: 3px; pointer-events: none;
}
.creator-cell:active > span { transform: translateY(1px); }
.creator-cell:focus-visible { outline-color: #fff3bc!important; }
.creator-readout {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  margin: 9px 1px 12px; font-size: 12px; font-weight: 700; line-height: 1.3; color: #4f6058;
}
.creator-saved, .creator-transport-state { display: inline-flex; align-items: center; gap: 5px; }
.creator-saved .glyph { width: 14px; height: 14px; }
.creator-transport-state i { width: 6px; height: 6px; border-radius: 50%; background: #8c9688; }
.rhythm-creator[data-playing] .creator-transport-state i { background: #609d81; box-shadow: 0 0 0 2px #679d7c32; }
.creator-footer, .creator-tools, .creator-transport { display: flex; align-items: stretch; flex-wrap: wrap; gap: 6px; }
.creator-footer { justify-content: space-between; }
.creator-footer button { display: inline-flex; gap: 4px; align-items: center; justify-content: center; padding: 6px 10px; border-radius: 7px; font-size: 13px; }
.creator-tools button { color: #4f5554; border: 1px solid #a69e8f; background: #e7dfcf; }
.creator-transport button { border: 1px solid #47645e; background: #d9e9db; color: #2e514a; }
.creator-transport button[aria-pressed="true"] { color: #fff5db; background: #3f655b; }
.creator-transport [data-action="rhythm-creator-play"] { border-color: #8f6448; color: #3f382f; background: #efb579; box-shadow: inset 0 -2px #cf9566; }
.rhythm-creator button:disabled { opacity: .48; }
.rhythm-creator button:disabled .glyph { opacity: .8; }

.rhythm-creator-door {
  display: grid; grid-template-columns: 62px minmax(0,1fr) auto; align-items: center; gap: 10px; width: 100%; margin: 0 0 11px; min-height: 54px;
  padding: 7px 12px; border: 1px solid #52716a; border-radius: 8px; text-align: left;
  color: #eef2d9; background: linear-gradient(115deg,#3d5656,#30454c); box-shadow: inset 0 1px #72918a;
}
.rhythm-creator-door strong { color: #ffdf9e; font-weight: 850; }
.rhythm-creator-door small { color: #d4e4d4; font-size: 12px; }
.rhythm-creator-door .glyph { color: #ffdc9a; }
.rhythm-creator-door > span:nth-child(2) { display: grid; gap: 2px; }
.rhythm-creator-door-art {
  display: grid; grid-template-columns: repeat(8,1fr); align-items: end; gap: 2px; height: 30px;
  padding: 4px; background: #25393c; border: 1px solid #70857d; border-radius: 4px; box-shadow: inset 0 1px #1b2b33;
}
.rhythm-creator-door-art i { height: 9px; background: #f2c183; border-radius: 1px; }
.rhythm-creator-door-art i:nth-child(2n) { height: 4px; background: #96c9b9; }
.rhythm-creator-door-art i:nth-child(3n) { height: 14px; background: #d4a5d1; }
.rhythm-creator-door-art i:nth-child(5) { height: 18px; }
.rhythm-creator-door-action { padding-left: 5px; font-size: 13px; font-weight: 800; white-space: nowrap; }
.rhythm-creator-door-action::after { content: ' →'; color: #ffdc9a; }

@media (hover: hover) {
  .creator-footer button:hover:not(:disabled), .creator-header button:hover:not(:disabled), .rhythm-creator-door:hover { filter: brightness(1.05); }
  .creator-cell:hover > span { border-color: #bdc9b9; }
}
@media (orientation: landscape) and (max-height: 450px) {
  #dialog[data-kind="rhythm-creator"] { width: min(840px,calc(100% - var(--phone-left,8px) - var(--phone-right,8px))); border-radius: 10px; }
  .rhythm-creator { padding: 9px 12px; }
  .creator-header { gap: 8px; margin-bottom: 7px; }
  .dialog-content .creator-title h2 { font-size: 23px; }
  .dialog-content .creator-title p { font-size: 11px; margin-top: 3px; }
  .creator-section { padding: 3px 7px; gap: 5px; }
  .creator-speed { min-width: 48px; }
  .creator-console { padding: 5px 7px 8px; }
  .creator-staff { grid-template-columns: 52px repeat(8,minmax(44px,1fr)); grid-template-rows: 14px repeat(3,clamp(44px,13.2dvh,55px)); gap: 3px; }
  .creator-readout { margin: 4px 1px 5px; font-size: 11px; }
  .creator-footer button { font-size: 12px; }
  .rhythm-creator-door { min-height: 44px; margin-bottom: 7px; padding-block: 4px; }
}
@media (orientation: landscape) and (max-height: 320px) {
  #dialog[data-kind="rhythm-creator"] { inset-block: max(3px,var(--safe-top)) max(4px,var(--safe-bottom)); max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 7px); }
  .rhythm-creator { padding: 2px 8px; }
  .creator-header { margin-bottom: 2px; }
  .creator-staff { gap: 2px; }
  .creator-console { padding: 2px 6px 3px; }
  .creator-readout { margin-block: 1px; font-size: 10px; }
}
@media (max-width: 615px) and (orientation: portrait) {
  #dialog[data-kind="rhythm-creator"] { width: min(96vw,475px); max-height: 95dvh; }
  .rhythm-creator { padding: 11px; }
  .creator-header { display: grid; grid-template-columns: 44px 1fr auto; gap: 7px; margin-bottom: 8px; }
  .creator-title { margin: 0; }
  .creator-sections { grid-column: 1/4; grid-row: 2; }
  .creator-section { flex: 1; }
  .creator-tempo { grid-column: 3; grid-row: 1; }
  .creator-speed { min-width: 42px; }
  .creator-staff { --transposed: 1; grid-template-columns: 26px repeat(3,minmax(44px,1fr)); grid-template-rows: 24px repeat(8,minmax(44px,5.5dvh)); gap: 3px; }
  .creator-lane { display: flex; justify-content: center; gap: 5px; grid-row: 1; grid-column: calc(var(--lane) + 2); }
  .creator-beat { grid-column: 1; grid-row: calc(var(--step) + 2); }
  .creator-cell { grid-column: calc(var(--lane) + 2); grid-row: calc(var(--step) + 2); }
  .creator-console { padding: 5px; }
  .creator-readout { margin: 5px 1px; }
  .creator-footer { gap: 5px; }
  .creator-tools, .creator-transport { flex: 1 1 100%; }
  .creator-footer button { flex: 1; }
}
