:root {
  --bg: #121316;
  --bg-soft: #1b1d22;
  --surface: #23262d;
  --border: #353a44;
  --text: #e8eaf0;
  --muted: #8b93a5;
  --green: #4caf50;
  --yellow: #e0b537;
  --gray: #5a606d;
  --accent: #6c8cff;
  --red: #e05252;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.25rem 1rem 0.5rem;
  text-align: center;
}

.header-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0;
}

.header-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.25rem 0 0;
}

.staff-board {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: center;
  padding: 0.5rem 1rem;
}

.staff-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 36rem;
}

.clef {
  flex: 0 0 auto;
  font-size: 4.6rem;
  line-height: 0.9;
  color: var(--muted);
  user-select: none;
}

.staff {
  position: relative;
  flex: 1;
  height: 122px;
}

.staff-lines {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--staff-bottom) - 4 * var(--staff-spacing));
  height: calc(4 * var(--staff-spacing) + 1px);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--border) 0,
    var(--border) 1px,
    transparent 1px,
    transparent var(--staff-spacing)
  );
}

.bin-hit {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  cursor: pointer;
}

.ledger {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 1.5px;
  background: var(--border);
  z-index: 2;
  pointer-events: none;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  opacity: 0.9;
  transform: translateX(-50%);
  z-index: 4;
  pointer-events: none;
  box-shadow: 0 0 8px var(--accent);
}

.note {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  z-index: 3;
  pointer-events: none;
}

.note.draft { color: var(--text); }
.note.green { color: var(--green); }
.note.yellow { color: var(--yellow); }
.note.gray { color: var(--gray); }
.note.cursor { color: var(--accent); }

.note .sharp {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  margin-right: 2px;
}

.note .head {
  position: relative;
  display: inline-block;
  width: 14px;
  height: 10px;
}

.note .head::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: currentColor;
  transform: rotate(-18deg);
}

.note .head::after {
  content: "";
  position: absolute;
  width: 2px;
  height: 28px;
  background: currentColor;
}

.note.up .head::after {
  right: -1px;
  bottom: 50%;
}

.note.down .head::after {
  left: -1px;
  top: 50%;
}

.note.cursor .head::before {
  background: transparent;
  border: 2px solid currentColor;
}

.note.cursor .head::after {
  display: none;
}

.keyboard {
  position: relative;
  display: flex;
  max-width: 40rem;
  margin: 1rem auto 2rem;
  height: 11rem;
  user-select: none;
  touch-action: manipulation;
}

.key {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.key:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.key.white {
  flex: 1 1 0;
  background: #f2f3f6;
  color: #1a1c21;
  border: 1px solid var(--border);
  border-bottom-left-radius: 0.4rem;
  border-bottom-right-radius: 0.4rem;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
}

.key.white:hover:not(:disabled),
.key.white:active:not(:disabled) {
  background: var(--accent);
  color: #0b0c0e;
}

.key.black {
  position: absolute;
  top: 0;
  height: 62%;
  background: #0b0c0e;
  color: var(--text);
  border: 1px solid #000;
  border-bottom-left-radius: 0.3rem;
  border-bottom-right-radius: 0.3rem;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0.3rem;
  font-size: 0.6rem;
  font-weight: 600;
}

.key.black:hover:not(:disabled),
.key.black:active:not(:disabled) {
  background: var(--accent);
  color: #0b0c0e;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0c0e;
}

.btn-primary:hover:not(:disabled) {
  background: #7d9aff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0.5rem 1rem 1.5rem;
}

.msg {
  text-align: center;
  min-height: 1.5rem;
  padding: 0.25rem 1rem;
  color: var(--muted);
}

.msg-error {
  color: var(--red);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  padding: 1rem;
  z-index: 50;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 1.75rem 1.5rem;
  max-width: 24rem;
  width: 100%;
  text-align: center;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0 0 0.5rem;
}

.modal-body {
  color: var(--muted);
  margin: 0 0 1.25rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

@media (max-width: 480px) {
  .keyboard {
    height: 8.5rem;
  }

  .key.white {
    font-size: 0.6rem;
  }

  .key.black {
    font-size: 0.52rem;
  }

  .staff-row {
    gap: 0.35rem;
  }

  .clef {
    font-size: 3.6rem;
  }
}

.tie-arc {
  position: absolute;
  height: 0.6em;
  transform: translateX(-50%);
  border: 2px solid var(--text);
  border-bottom: none;
  border-left: none;
  border-right: none;
  border-top-left-radius: 100% 200%;
  border-top-right-radius: 100% 200%;
  pointer-events: none;
}

.tie-arc.green {
  border-color: var(--green);
}

.tie-arc.yellow,
.tie-arc.gray {
  border-color: var(--muted);
}
