/* Shared music UI: piano keyboard + staff. Used by music games. */

/* ---------- keyboard ---------- */

.music-keyboard {
  --mk-white: #f7f3ea;
  --mk-white-ink: #2a332e;
  --mk-white-down: #e7d7a8;
  --mk-black: #1d2433;
  --mk-black-ink: #f4f0e8;
  --mk-black-down: #4a5568;
  --mk-lit: #e0b948;
  position: relative;
  width: 100%;
  user-select: none;
  touch-action: none;
  container-type: inline-size;
}

.music-keyboard.is-disabled {
  opacity: 0.72;
  pointer-events: none;
}

.music-keyboard-whites {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0.12rem;
  height: clamp(7.5rem, 28cqw, 11rem);
}

.music-key {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  cursor: pointer;
  touch-action: none;
  font: inherit;
  color: inherit;
  min-width: 0;
}

.music-key:focus-visible {
  outline: 3px solid var(--gold, #b8923a);
  outline-offset: 2px;
  z-index: 5;
}

.music-key.is-white {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.15rem;
  padding-bottom: 0.4rem;
  border-radius: 0 0 6px 6px;
  background:
    linear-gradient(180deg, #fffef9, var(--mk-white) 40%, #ebe4d4);
  color: var(--mk-white-ink);
  box-shadow:
    inset 0 0 0 1px rgba(40, 40, 30, 0.18),
    inset 0 -6px 10px rgba(0, 0, 0, 0.06);
  z-index: 1;
}

.music-key.is-white.is-down,
.music-key.is-white.is-lit {
  background: var(--mk-white-down);
  transform: translateY(2px);
}

.music-key.is-black {
  position: absolute;
  top: 0;
  z-index: 2;
  height: 58%;
  border-radius: 0 0 5px 5px;
  background:
    linear-gradient(180deg, #3a4254, var(--mk-black) 55%, #12171f);
  color: var(--mk-black-ink);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 4px 8px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.1rem;
  padding-bottom: 0.35rem;
}

.music-key.is-black.is-down,
.music-key.is-black.is-lit {
  background: var(--mk-black-down);
  transform: translateY(2px);
}

.music-key.is-lit {
  box-shadow:
    inset 0 0 0 2px var(--mk-lit),
    0 0 0 1px rgba(224, 185, 72, 0.35);
}

.music-key-letter,
.music-key-name {
  pointer-events: none;
  line-height: 1;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  opacity: 0.78;
}

.music-key.is-black .music-key-letter,
.music-key.is-black .music-key-name {
  font-size: 0.64rem;
  opacity: 0.85;
}

.music-keyboard[data-show-labels="0"] .music-key-letter { display: none; }
.music-keyboard[data-show-names="0"] .music-key-name { display: none; }

.music-keyboard-blacks {
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.music-keyboard-blacks .music-key {
  pointer-events: auto;
}

@media (max-width: 640px), (pointer: coarse) {
  .music-keyboard-whites {
    height: clamp(6.8rem, 42vw, 9.5rem);
  }
  .music-key.is-white {
    min-height: var(--tap-min, 44px);
  }
  .music-key-letter,
  .music-key-name {
    font-size: 0.58rem;
  }
}

/* ---------- staff ---------- */

.music-staff {
  width: 100%;
  min-height: 5.5rem;
}

.music-staff-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.music-staff-svg {
  display: block;
  height: clamp(96px, 22vw, 150px);
  width: auto;
  max-width: none;
  overflow: visible;
}

.music-staff-bg {
  fill: color-mix(in srgb, var(--bg-elevated, #fffdf8) 88%, #d9d0bf);
}

.music-staff-line {
  stroke: #5c6a62;
  stroke-width: 1.25;
}

.music-clef path,
.music-clef-dot,
.music-clef circle {
  stroke: #2a332e;
  fill: #2a332e;
}

.music-clef path {
  fill: none;
}

.music-ledger {
  stroke: #5c6a62;
  stroke-width: 1.25;
}

.music-notehead {
  fill: #1d2433;
}

.music-notehead.is-hollow {
  fill: color-mix(in srgb, var(--bg-elevated, #fffdf8) 88%, #d9d0bf);
  stroke: #1d2433;
  stroke-width: 1.6;
}

.music-dot {
  fill: #1d2433;
}

.music-stem,
.music-flag,
.music-accidental line,
.music-accidental path {
  stroke: #1d2433;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.music-note.is-current .music-notehead {
  fill: #b8923a;
}

.music-note.is-current .music-notehead.is-hollow {
  fill: color-mix(in srgb, var(--bg-elevated, #fffdf8) 88%, #d9d0bf);
  stroke: #b8923a;
}

.music-note.is-current .music-stem,
.music-note.is-current .music-flag,
.music-note.is-current .music-accidental line,
.music-note.is-current .music-accidental path {
  stroke: #b8923a;
}

.music-note.is-current .music-dot {
  fill: #b8923a;
}

[data-theme="dark"] .music-staff-bg {
  fill: color-mix(in srgb, var(--bg-elevated, #212b28) 80%, #000);
}

[data-theme="dark"] .music-staff-line,
[data-theme="dark"] .music-ledger {
  stroke: #9aab9f;
}

[data-theme="dark"] .music-clef path,
[data-theme="dark"] .music-clef-dot,
[data-theme="dark"] .music-clef circle,
[data-theme="dark"] .music-notehead,
[data-theme="dark"] .music-dot {
  stroke: #e8ebe6;
  fill: #e8ebe6;
}

[data-theme="dark"] .music-clef path {
  fill: none;
}

[data-theme="dark"] .music-notehead.is-hollow {
  fill: color-mix(in srgb, var(--bg-elevated, #212b28) 80%, #000);
  stroke: #e8ebe6;
}

[data-theme="dark"] .music-stem,
[data-theme="dark"] .music-flag,
[data-theme="dark"] .music-accidental line,
[data-theme="dark"] .music-accidental path {
  stroke: #e8ebe6;
}

[data-theme="dark"] .music-note.is-current .music-notehead {
  fill: #d1a94a;
}

[data-theme="dark"] .music-note.is-current .music-notehead.is-hollow {
  fill: color-mix(in srgb, var(--bg-elevated, #212b28) 80%, #000);
  stroke: #d1a94a;
}

[data-theme="dark"] .music-note.is-current .music-stem,
[data-theme="dark"] .music-note.is-current .music-flag,
[data-theme="dark"] .music-note.is-current .music-accidental line,
[data-theme="dark"] .music-note.is-current .music-accidental path {
  stroke: #d1a94a;
}

[data-theme="dark"] .music-note.is-current .music-dot {
  fill: #d1a94a;
}
