body {
  text-align: center;
  font-family: Arial, sans-serif;
  background: #f0f0f0;
  touch-action: manipulation; /* double-tap 확대 방지 */
  -webkit-user-select: none; /* 텍스트 선택도 방지 */
  user-select: none;
  -webkit-tap-highlight-color: transparent; /* 탭시 파란 효과 제거 */
  margin: 8px 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.keyboard-mode,
.size-mode {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  cursor: pointer;
}

.piano-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  column-gap: 16px;
}

.size-mode select {
  font: inherit;
}

.keyboard-mode input {
  appearance: none;
  display: grid;
  align-items: center;
  width: 40px;
  height: 24px;
  margin: 0;
  padding: 2px;
  border: 1px solid #626262;
  border-radius: 12px;
  background: #767676;
  cursor: pointer;
}

.keyboard-mode input::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
}

.keyboard-mode input:checked {
  background: #245e9b;
  border-color: #245e9b;
}

.keyboard-mode input:checked::before {
  justify-self: end;
}

.keyboard-mode input:focus-visible {
  outline: 2px solid #245e9b;
  outline-offset: 3px;
}

@media (forced-colors: active) {
  .keyboard-mode input {
    appearance: auto;
    display: revert;
  }

  .keyboard-mode input::before {
    content: none;
  }
}

.piano {
  --white-key-width: min(60px, (100vw - 24px) / 7);
  --black-key-offset: 5px;
  --white-key-length: calc(var(--white-key-width) * 150 / 23);
  --black-key-length: calc(var(--white-key-width) * 95 / 23);
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  margin: 40px auto;
  width: calc(7 * var(--white-key-width));
}

body:has(#piano-size option[value="simple"]:checked) .piano {
  --white-key-length: 200px;
  --black-key-length: 120px;
}

.octave {
  display: flex;
  width: max-content;
  position: relative;
  height: var(--white-key-length);
}

.piano > .octave:first-child {
  align-self: flex-end;
}

.piano > .octave:last-child {
  align-self: flex-start;
}

.key {
  border: 1px solid #333;
  cursor: pointer;
  position: relative;
  touch-action: manipulation; /* double-tap 확대 방지 */
  -webkit-user-select: none; /* 텍스트 선택도 방지 */
  user-select: none;
  -webkit-tap-highlight-color: transparent; /* 탭시 파란 효과 제거 */
}

.white {
  flex: none;
  width: var(--white-key-width);
  background: white;
  z-index: 1;
}

.black {
  width: calc(var(--white-key-width) * 0.48);
  height: var(--black-key-length);
  background: black;
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  z-index: 2;
}

.black[data-note^="C#"] {
  left: calc(var(--white-key-width) - var(--black-key-offset));
}

.black[data-note^="D#"] {
  left: calc(2 * var(--white-key-width) + var(--black-key-offset));
}

.black[data-note^="F#"] {
  left: calc(4 * var(--white-key-width) - var(--black-key-offset));
}

.black[data-note^="G#"] {
  left: calc(5 * var(--white-key-width));
}

.black[data-note^="A#"] {
  left: calc(6 * var(--white-key-width) + var(--black-key-offset));
}

.note-label {
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  color: #333;
  pointer-events: none;
}

.black[data-note="A#0"] {
  left: calc(var(--white-key-width) + var(--black-key-offset));
}

.white.active {
  background: #b9d9ff;
}

.black.active {
  background: #316aab;
}
