/* Composer — grand staff notation editor */

:root {
  --composer-ink: #1a1f2c;
  --composer-ink-soft: rgba(26, 31, 44, 0.55);
  --composer-ink-faint: rgba(26, 31, 44, 0.18);
  --composer-paper: #f7f1e4;
  --composer-paper-edge: #e4d8c4;
  --composer-playhead: #c23b3b;
  --composer-note: #1a1f2c;
  --composer-note-active: #2f6fed;
  --composer-select: rgba(47, 111, 237, 0.25);
  --composer-sounding: #c23b3b;
  --composer-blocked: #b02a37;
  --composer-bar: rgba(26, 31, 44, 0.35);
  --composer-beat: rgba(26, 31, 44, 0.08);
}

.composer-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 320px;
  padding: 8px 16px 16px;
}

.notation-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  padding: 4px 16px 10px;
  padding-left: max(16px, 120px);
}

.tool-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.tool-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2, #64748b);
  margin-right: 4px;
}

.tool-btn {
  min-width: 36px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border, var(--hairline-strong));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-1, #fff);
  color: var(--fg, var(--text-1));
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.tool-btn .tool-icon {
  display: block;
  flex-shrink: 0;
}

.tool-btn .dur-rest {
  display: none;
}

.notation-toolbar.is-rest-mode .tool-btn .dur-note {
  display: none;
}

.notation-toolbar.is-rest-mode .tool-btn .dur-rest {
  display: block;
}

.tool-btn:hover {
  border-color: var(--accent, var(--accent-primary));
}

.tool-btn[aria-pressed='true'] {
  background: var(--accent-primary, #2f6fed);
  border-color: transparent;
  color: #fff;
}

.secondary-btn:disabled,
.secondary-btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.tool-btn.dyn {
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
  min-width: 32px;
}

.tool-group select {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border, var(--hairline-strong));
  background: var(--surface-1, #fff);
  color: inherit;
  font: inherit;
  padding: 0 8px;
}

.score-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 12px;
  border: 1px solid var(--composer-paper-edge);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent 40%),
    var(--composer-paper);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  -webkit-overflow-scrolling: touch;
  touch-action: none;
  user-select: none;
}

.score {
  display: block;
  height: min(52vh, 420px);
  min-height: 300px;
  cursor: crosshair;
  touch-action: none;
  color: var(--composer-ink);
}

.score .staff-line {
  stroke: var(--composer-ink);
  stroke-width: 1.5;
  fill: none;
}

.score .ledger-line {
  stroke: var(--composer-ink);
  stroke-width: 1.4;
  fill: none;
}

.score .bar-line {
  stroke: var(--composer-bar);
  fill: none;
}

.score .measure-chrome-hit {
  fill: transparent;
  pointer-events: all;
}

.score .measure-chrome-btns {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.score .measure-chrome:hover .measure-chrome-btns,
.score .measure-chrome:focus-within .measure-chrome-btns {
  opacity: 1;
  pointer-events: auto;
}

@media (hover: none), (pointer: coarse) {
  .score .measure-chrome-btns {
    opacity: 0.85;
    pointer-events: auto;
  }
}

.score .measure-btn {
  cursor: pointer;
}

.score .measure-btn-bg {
  fill: var(--composer-paper, #f7f1e4);
  stroke: var(--composer-ink-soft, rgba(26, 31, 44, 0.45));
  stroke-width: 1.25;
}

.score .measure-btn:hover .measure-btn-bg {
  stroke: var(--composer-note-active, #2f6fed);
  fill: #fff;
}

.score .measure-btn-label {
  fill: var(--composer-ink);
  font-family: system-ui, sans-serif;
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
  user-select: none;
}

.score .beat-guide {
  stroke: var(--composer-beat);
  stroke-width: 1;
  fill: none;
}

.score .brace {
  stroke: var(--composer-ink);
  fill: none;
}

.score .clef {
  fill: var(--composer-ink);
  font-family: Georgia, 'Times New Roman', serif;
  dominant-baseline: middle;
}

.score .time-sig {
  fill: var(--composer-ink);
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 700;
  font-size: 22px;
  text-anchor: middle;
}

.score .accidental-sig,
.score .accidental {
  fill: var(--composer-ink);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 18px;
  text-anchor: middle;
}

.score .note-head {
  fill: var(--composer-note);
  stroke: none;
  cursor: grab;
}

.score .note-head.open {
  fill: var(--composer-paper);
  stroke: var(--composer-note);
  stroke-width: 1.6;
}

.score .note.is-selected .note-head,
.score .rest.is-selected .rest-glyph,
.score .rest.is-selected .rest-block,
.score .rest.is-selected .rest-dot {
  fill: var(--composer-note-active);
}

.score .rest.is-selected .rest-path,
.score .rest.is-selected .rest-block path {
  stroke: var(--composer-note-active);
}

.score .note.is-selected .note-head.open {
  stroke: var(--composer-note-active);
  fill: var(--composer-paper);
}

.score .note.is-selected .hit-proxy,
.score .rest.is-selected .hit-proxy {
  fill: var(--composer-select);
}

.score .note-stem,
.score .note-flag {
  stroke: var(--composer-note);
  stroke-width: 1.6;
  fill: none;
  pointer-events: none;
}

.score .note.is-selected .note-stem,
.score .note.is-selected .note-flag {
  stroke: var(--composer-note-active);
}

/* Note currently sounding under the playhead — distinct from blue selection. */
.score .note.is-sounding .note-head {
  fill: var(--composer-sounding);
}

.score .note.is-sounding .note-head.open {
  stroke: var(--composer-sounding);
  fill: var(--composer-paper);
}

.score .note.is-sounding .note-stem,
.score .note.is-sounding .note-flag {
  stroke: var(--composer-sounding);
}

.score .note.is-shadow,
.score .rest.is-shadow {
  opacity: 0.4;
  pointer-events: none;
}

.score .note.is-shadow .note-head {
  fill: var(--composer-note-active);
}

.score .note.is-shadow .note-head.open {
  stroke: var(--composer-note-active);
  fill: var(--composer-paper);
}

.score .note.is-shadow .note-stem,
.score .note.is-shadow .note-flag {
  stroke: var(--composer-note-active);
}

.score .rest.is-shadow .rest-block,
.score .rest.is-shadow .rest-glyph,
.score .rest.is-shadow .rest-dot {
  fill: var(--composer-note-active);
}

.score .rest.is-shadow .rest-path,
.score .rest.is-shadow .rest-block path {
  stroke: var(--composer-note-active);
}

/* Shadow over an occupied slot — a click here would be rejected. */
.score .note.is-shadow.is-blocked,
.score .rest.is-shadow.is-blocked {
  opacity: 0.55;
}

.score .note.is-shadow.is-blocked .note-head {
  fill: var(--composer-blocked);
}

.score .note.is-shadow.is-blocked .note-head.open {
  stroke: var(--composer-blocked);
  fill: var(--composer-paper);
}

.score .note.is-shadow.is-blocked .note-stem,
.score .note.is-shadow.is-blocked .note-flag {
  stroke: var(--composer-blocked);
}

.score .note-dot {
  fill: var(--composer-note);
  pointer-events: none;
}

.score .hit-proxy {
  fill: transparent;
  cursor: grab;
}

.score .rest-glyph {
  fill: var(--composer-ink);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 28px;
}

.score .rest-block {
  fill: var(--composer-ink);
}

.score .rest-path {
  stroke: var(--composer-ink);
}

.score .rest-dot {
  fill: var(--composer-ink);
}

.score .beam {
  fill: var(--composer-ink);
  stroke: none;
  pointer-events: none;
}

.score .tie {
  stroke: var(--composer-ink);
  stroke-width: 1.5;
  pointer-events: none;
}

.score .dynamic {
  fill: var(--composer-ink);
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
  font-size: 16px;
  text-anchor: middle;
  pointer-events: none;
}

.score .playhead {
  stroke: var(--composer-playhead);
  stroke-width: 2;
  fill: none;
  pointer-events: none;
}

.score .playhead-cap {
  fill: var(--composer-playhead);
  pointer-events: none;
}

.score .playhead-hit {
  fill: transparent;
  cursor: ew-resize;
  pointer-events: all;
}

.score.is-scrubbing {
  cursor: ew-resize;
}

.control-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}

.control-more {
  position: relative;
  align-self: end;
  z-index: 25;
}

.control-more > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  height: 1.75rem;
  padding: 0 0.65rem;
}

.control-more > summary::-webkit-details-marker {
  display: none;
}

.more-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 11rem;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--composer-paper-edge);
  background: var(--composer-paper, #f7f1e4);
  box-shadow: 0 10px 28px rgba(26, 31, 44, 0.18);
}

.more-label {
  font-size: 0.75rem;
  color: var(--composer-ink-soft);
}

.more-panel select,
.more-panel .secondary-btn {
  width: 100%;
}

/* Tempo: collapsed BPM chip; vertical slider below on hover/focus */
.control-tempo {
  position: relative;
  align-self: end;
  z-index: 30;
}

.tempo-face {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.25rem;
  height: 1.75rem;
  padding: 0 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border, var(--composer-paper-edge));
  background: var(--surface-1, #fff);
  color: var(--fg, var(--composer-ink));
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: center;
  line-height: 1;
}

.tempo-face:hover,
.control-tempo:focus-within .tempo-face {
  border-color: var(--composer-note-active);
}

.tempo-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.tempo-value::after {
  content: ' BPM';
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--composer-ink-soft);
}

.tempo-flyout {
  position: absolute;
  left: 50%;
  top: calc(100% - 2px);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  width: 2.75rem;
  padding: 0.55rem 0.35rem;
  margin: 0;
  border-radius: 10px;
  border: 1px solid var(--border, var(--composer-paper-edge));
  background: var(--surface-1, #fff);
  box-shadow: 0 10px 28px rgba(26, 31, 44, 0.18);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%) translateY(-4px);
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
}

.tempo-flyout::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -0.65rem;
  height: 0.65rem;
}

.control-tempo:hover .tempo-flyout,
.control-tempo:focus-within .tempo-flyout {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.tempo-flyout-min,
.tempo-flyout-max {
  font-size: 0.62rem;
  color: var(--composer-ink-soft);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.tempo-flyout input[type='range'] {
  writing-mode: vertical-lr;
  direction: rtl;
  appearance: slider-vertical;
  width: 1.35rem;
  height: 6.5rem;
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  accent-color: var(--composer-note-active);
  cursor: pointer;
}

.tempo-flyout input[type='range']::-webkit-slider-runnable-track {
  width: 0.35rem;
  border-radius: 999px;
  background: var(--composer-ink-faint);
}

.tempo-flyout input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 0.9rem;
  height: 0.9rem;
  margin-left: -0.28rem;
  border-radius: 50%;
  background: var(--composer-note-active);
  border: none;
  cursor: grab;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease,
    transform 100ms ease;
}

.primary-btn {
  min-width: 110px;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: color-mix(in srgb, var(--pure-white) 12%, transparent);
  color: var(--pure-white);
  box-shadow: 0 6px 18px -8px rgba(47, 111, 237, 0.55);
}

.primary-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.primary-btn:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.primary-btn[aria-pressed='true'] {
  background: linear-gradient(135deg, var(--composer-playhead), #e07a3a);
  box-shadow: 0 6px 18px -8px rgba(194, 59, 59, 0.55);
}

.secondary-btn {
  background: var(--surface-1);
  color: var(--fg);
}

.secondary-btn:hover {
  border-color: var(--accent);
}

.secondary-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.secondary-btn[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--pure-white);
}

.bars-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.bars-row input[type='number'] {
  width: 3.2rem;
  text-align: center;
}

.bars-step {
  min-width: 2rem;
  padding: 0.25rem 0.45rem;
  justify-content: center;
}

.control #measures,
.control select {
  width: 64px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border, var(--hairline-strong));
  background: var(--surface-1, #fff);
  color: inherit;
  font: inherit;
}

.control #time-sig,
.control #key-sig {
  width: auto;
  min-width: 88px;
}

@media (max-width: 640px) {
  .composer-stage {
    padding: 4px 10px 12px;
  }

  .notation-toolbar {
    padding-left: 10px;
  }

  .score {
    height: min(48vh, 360px);
    min-height: 260px;
  }
}
