:root {
  --panel-bg: var(--fx-midnight-veil-strong);
  --panel-border: var(--fx-outline-soft);
  --accent: var(--gold-400);
  --text-muted: var(--mist-200);
  --staff-height: 320px;
  --staff-padding: 32px;
  --note-slot-gap: 1rem;
  --note-stem: var(--mist-050);
}

body {
  font-family: "Space Grotesk", "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, var(--fx-midnight-veil-soft), var(--neutral-900) 60%);
  min-height: 100vh;
  color: var(--mist-050);
}

.app-header {
  height: 60px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 1.25rem 1.5rem 0;
  position: relative;
}

.app-header .title {
  margin: 0;
}

.app-header .logo img {
  width: 56px;
  height: auto;
  display: block;
}

.menu-btn {
  align-self: stretch;
  background: transparent;
  border: 1px solid var(--fx-outline-mid);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  color: inherit;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.menu-btn:focus-visible {
  outline: 2px solid var(--gold-300);
  outline-offset: 4px;
}

.drawer {
  display: none;
  position: absolute;
  top: 100%;
  right: 1.5rem;
  margin-top: 0.5rem;
  min-width: 220px;
  padding: 1rem;
  border-radius: 16px;
  background: var(--fx-midnight-veil-strong);
  border: 1px solid var(--fx-outline-mid);
  box-shadow: 0 24px 50px var(--fx-shadow-strong);
  z-index: 10;
}

.drawer.is-open {
  display: block;
}

.drawer a {
  display: block;
  color: var(--mist-200);
  text-decoration: none;
  padding: 0.4rem 0.25rem;
  border-radius: 8px;
  font-weight: 600;
}

.drawer a:hover,
.drawer a:focus-visible {
  background: var(--fx-outline-soft);
}

.app-main {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: 0 15px 40px var(--fx-shadow-mid);
  backdrop-filter: blur(16px);
}

.settings-score-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(240px, 280px) minmax(320px, 1fr);
  gap: 1.5rem;
  align-items: stretch;
}

/* .settings-score-row .score-panel {
  width: 100%;
} */

/* .settings-score-row .settings-panel {
  width: 100%;
} */

@media (max-width: 900px) {
  .settings-score-row {
    grid-template-columns: 1fr;
  }
}

.staff-header {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.staff-header__group {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  align-items: flex-start;
}

.staff-header__title {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.staff-header__cta {
  padding: 0.5rem 1.25rem;
  font-size: 0.9rem;
}

.staff-header #statusMessage {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.4;
  max-width: 320px;
}

.staff-status {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-align: right;
}

.staff-status__label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.staff-status__value {
  font-size: 1rem;
  font-weight: 600;
}

.panel-header {
  display: flex;
  flex-direction: row;
  gap: 0.15rem;
  margin-bottom: 0.75rem;
  justify-content: space-between;
  padding: 0 8px;
}

.panel-label {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.panel-title {
  font-size: 1.4rem;
  margin: 0;
}

.control-group+.control-group {
  margin-top: 1rem;
}

.control-group--tempo {
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 1rem;
}

.control-group--tempo .range-field {
  margin-top: 0.35rem;
}

.range-field {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.range-field output {
  min-width: 90px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

select,
input[type="range"],
button,
output {
  font: inherit;
}

select,
input[type="range"] {
  width: 100%;
}

#intervallHelper {
  max-width: 300px;
}

select option.select-help-option {
  font-style: italic;
  color: var(--text-muted);
  white-space: normal;
  word-break: break-word;
  text-overflow: clip;
}

button {
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.25rem;
  background: var(--fx-outline-soft);
  color: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(120deg, var(--gold-400), var(--gold-900));
  color: var(--neutral-900);
  font-weight: 600;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--fx-outline-mid);
}

button:not(:disabled):hover {
  transform: translateY(-1px);
}

.help-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.35rem 0 0;
}

.score-row {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
}

.score-row strong {
  display: block;
  font-size: 2rem;
  margin-top: 0.25rem;
}

.penalty-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 1rem 0 0;
}

.penalty-list dt {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.penalty-list dd {
  margin: 0.2rem 0 0;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

.staff-panel {
  grid-column: 1 / -1;
}

.staff-board {
  position: relative;
  width: 100%;
  height: var(--staff-height);
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--fx-outline-mid);
  background: var(--mist-050);
}

.staff-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.note-grid-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.note-grid-viewport {
  position: absolute;
  inset: 0 100px;
  overflow: hidden;
  scrollbar-width: none;
  pointer-events: auto;
}

.note-grid-viewport--scrollable {
  overflow-x: auto;
}

.note-grid-viewport--scrollable::-webkit-scrollbar {
  display: none;
}

.note-scroll {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 56px;
  border: none;
  border-radius: 16px;
  background: rgba(11, 16, 32, 0.55);
  color: var(--mist-050);
  cursor: pointer;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  pointer-events: auto;
}

.note-scroll--left {
  left: 4px;
}

.note-scroll--right {
  right: 4px;
}

.note-scroll[hidden] {
  display: none;
}

.note-grid {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--tone-columns, 4), minmax(0, 1fr));
  gap: var(--note-slot-gap);
  padding: 0 var(--note-slot-gap);
}

.note-grid.note-grid--scrollable {
  grid-template-columns: repeat(var(--tone-columns, 4), minmax(120px, 1fr));
}

.note-slot {
  position: relative;
}

.note-slot.is-hover {
  outline: 2px dashed var(--fx-outline-mid);
  outline-offset: -2px;
}

.note-slot::after {
  content: attr(data-label);
  position: absolute;
  bottom: 0.35rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.note-token {
  position: absolute;
  top: var(--note-y, 50%);
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 120px;
  background: none;
  padding: 0;
  cursor: default;
  touch-action: none;
  pointer-events: none;
  color: var(--neutral-900);
}

.note-token .note-body {
  --note-body-shift: -36px;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  transform: translateY(var(--note-body-shift)) scale(0.8);
  transform-origin: center top;
  z-index: 1;
  pointer-events: none;
}

.note-token.stem-up .note-body {
  --note-body-shift: -12px;
}

.note-token.stem-down .note-body {
  --note-body-shift: 58px;
}

.note-token--solution {
  background-color: var(--red-100);
  opacity: 0.2;
  z-index: 2;
}

.note-token.is-pending {
  opacity: 0.4;
}

.note-token--starter .note-body {
  opacity: 0.85;
}

.note-token .note-ledger {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--ledger-offset, 0px) - 2px);
  width: 46px;
  height: 3px;
  background: currentColor;
  transform: translate(calc(-50% - 2px), -50%);
  z-index: 2;
  pointer-events: none;
}

.note-token .note-accidental {
  position: absolute;
  left: -4px;
  top: 60%;
  width: 26px;
  height: 50px;
  background-size: auto 100%;
  background-repeat: no-repeat;
  background-position: center;
  display: none;
  z-index: 2;
  transform: translate(calc(-100% - 4px), -50%);
}

.note-token--accidental-flat .note-accidental {
  display: block;
  background-image: url('./assets/images/b-flat.svg');
  top: 46%;
  transform: translate(calc(-100% - 4px), -50%);
}

.note-token--accidental-sharp .note-accidental {
  display: block;
  background-image: url('./assets/images/sharp.svg');
}

.note-token--accidental-natural .note-accidental {
  display: block;
  background-image: url('./assets/images/natural.svg');
}

.accidental-menu {
  position: absolute;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.45rem;
  padding: 0.65rem;
  border-radius: 18px;
  background: var(--mist-050);
  border: 1px solid var(--fx-outline-mid);
  box-shadow: 0 12px 24px rgba(10, 16, 30, 0.35);
  pointer-events: auto;
  z-index: 5;
}

.accidental-menu__option {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.accidental-menu__option img {
  max-height: 80%;
  width: auto;
}

.accidental-menu__option.is-active {
  border-color: var(--gold-400);
  background: rgba(0, 0, 0, 0.08);
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.status-panel {
  grid-column: 1 / -1;
}

#statusMessage {
  margin: 0;
  font-size: 1rem;
  color: var(--text-muted);
}

.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;
}

@media (max-width: 900px) {
  .staff-board {
    --staff-height: 260px;
  }

  .action-bar {
    flex-direction: column;
  }

  .note-grid {
    gap: 0.5rem;
  }
}

.control-group--interval {
  position: relative;
}

.control-label-with-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.info-btn {
  padding: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--fx-outline-mid);
  background: var(--blue-300);
  color: var(--mist-050);
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.info-btn:focus-visible {
  outline: 2px solid var(--gold-300);
  outline-offset: 2px;
}

.select-wrapper {
  position: relative;
  margin-top: 0.5rem;
}

.select-helper {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.45rem 0.6rem;
  border-radius: 12px;
  background: rgba(15, 20, 34, 0.78);
  border: 1px solid var(--fx-outline-mid);
  color: var(--mist-050);
  font-size: 0.78rem;
  line-height: 1.35;
  box-shadow: 0 12px 20px rgba(11, 16, 30, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 3;
}

.select-helper.is-visible {
  opacity: 1;
  pointer-events: auto;
}
